Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve scoped package paths during linking on Windows #1866

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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