Skip to content

Commit

Permalink
Resolve scoped package paths during linking on Windows (#1866)
Browse files Browse the repository at this point in the history
* Resolve scoped package paths during linking on Windows

* Normalize file copy destination when creating hoist manifests

* Add flow types to package-hoister unit tests
  • Loading branch information
dpoindexter authored and bestander committed Nov 19, 2016
1 parent c9500ab commit d047b18
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
44 changes: 44 additions & 0 deletions __tests__/package-hoister.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* @flow */

import PackageHoister, {HoistManifest} from '../src/package-hoister.js';
import type PackageResolver from '../src/package-resolver.js';
import type PackageReference from '../src/package-reference.js';
import type Config from '../src/config.js';
import type {Manifest} from '../src/types.js';

const path = require('path');

test('Produces valid destination paths for scoped modules', () => {
const expected = path.join(__dirname, './node_modules/@scoped/dep');
const scopedPackageName = '@scoped/dep';

const config = (({
cwd: __dirname,
getFolder(): string {
return 'node_modules';
},
}: any): Config);

const resolver = (({}: any): PackageResolver);

const key = scopedPackageName;
const parts = [scopedPackageName];

const pkg = (({
_reference: (({}: any): PackageReference),
}: any): Manifest);

const info = new HoistManifest(key, parts, pkg, '');

const tree = new Map([
['@scoped/dep', info],
]);

const packageHoister = new PackageHoister(config, resolver, false);
packageHoister.tree = tree;

const result = packageHoister.init();
const [actual] = result[0];

expect(actual).toEqual(expected);
});
10 changes: 6 additions & 4 deletions src/package-hoister.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export default class PackageHoister {
for (const [key, info] of this.tree.entries()) {
// decompress the location and push it to the flat tree. this path could be made
// up of modules from different registries so we need to handle this specially
const parts = [];
const parts: Array<string> = [];
const keyParts = key.split('#');
for (let i = 0; i < keyParts.length; i++) {
const key = keyParts.slice(0, i + 1).join('#');
Expand All @@ -363,13 +363,15 @@ export default class PackageHoister {
// remove the first part which will be the folder name and replace it with a
// hardcoded modules folder
parts.shift();
parts.unshift(this.config.modulesFolder);
const modulesFolder = (this.config.modulesFolder == null) ? '' : this.config.modulesFolder;
parts.unshift(modulesFolder);
} else {
// first part will be the registry-specific module folder
parts.unshift(this.config.cwd);
const cwd = (this.config.cwd == null) ? '' : this.config.cwd;
parts.unshift(cwd);
}

const loc = parts.join(path.sep);
const loc = path.join(...parts);
flatTree.push([loc, info]);
}

Expand Down

0 comments on commit d047b18

Please sign in to comment.