From a1c3aebb3cddff5725887ea22c9aa8ff627d2b7e Mon Sep 17 00:00:00 2001 From: Daniel Poindexter Date: Tue, 15 Nov 2016 12:18:48 -0600 Subject: [PATCH 1/3] Resolve scoped package paths during linking on Windows --- src/util/fs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/fs.js b/src/util/fs.js index b5e9d25ed8..27e30d0321 100644 --- a/src/util/fs.js +++ b/src/util/fs.js @@ -117,7 +117,7 @@ async function buildActionsForCopy( const {src, dest} = data; const onFresh = data.onFresh || noop; const onDone = data.onDone || noop; - files.add(dest); + files.add(path.normalize(dest)); if (events.ignoreBasenames.indexOf(path.basename(src)) >= 0) { // ignored file @@ -191,7 +191,7 @@ async function buildActionsForCopy( } else if (srcStat.isDirectory()) { await mkdirp(dest); - const destParts = dest.split(path.sep); + const destParts = path.normalize(dest).split(path.sep); while (destParts.length) { files.add(destParts.join(path.sep)); destParts.pop(); From 7fca0c82666ce212783959e942a9cd5ecacb58ce Mon Sep 17 00:00:00 2001 From: Daniel Poindexter Date: Thu, 17 Nov 2016 15:01:00 -0600 Subject: [PATCH 2/3] Normalize file copy destination when creating hoist manifests --- __tests__/package-hoister.js | 34 ++++++++++++++++++++++++++++++++++ src/package-hoister.js | 2 +- src/util/fs.js | 4 ++-- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 __tests__/package-hoister.js diff --git a/__tests__/package-hoister.js b/__tests__/package-hoister.js new file mode 100644 index 0000000000..394f42a10e --- /dev/null +++ b/__tests__/package-hoister.js @@ -0,0 +1,34 @@ +/* @flow */ + +import path from 'path'; +import PackageHoister, {HoistManifest} from '../src/package-hoister.js'; + +const mockConfig = { + cwd: __dirname, + getFolder(): string { + return 'node_modules'; + }, +}; + +test('Produces valid destination paths for scoped modules', () => { + const expected = path.join(__dirname, './node_modules/@scoped/dep'); + const scopedPackageName = '@scoped/dep'; + + const key = scopedPackageName; + const parts = [scopedPackageName]; + const pkg = {_reference: {}}; + const loc = null; + const info = new HoistManifest(key, parts, pkg, loc); + + const tree = new Map([ + ['@scoped/dep', info], + ]); + + const packageHoister = new PackageHoister(mockConfig); + packageHoister.tree = tree; + + const result = packageHoister.init(); + const [actual] = result[0]; + + expect(actual).toEqual(expected); +}); diff --git a/src/package-hoister.js b/src/package-hoister.js index ab1c3630f9..c09af00b9c 100644 --- a/src/package-hoister.js +++ b/src/package-hoister.js @@ -369,7 +369,7 @@ export default class PackageHoister { parts.unshift(this.config.cwd); } - const loc = parts.join(path.sep); + const loc = path.join(...parts); flatTree.push([loc, info]); } diff --git a/src/util/fs.js b/src/util/fs.js index 27e30d0321..b5e9d25ed8 100644 --- a/src/util/fs.js +++ b/src/util/fs.js @@ -117,7 +117,7 @@ async function buildActionsForCopy( const {src, dest} = data; const onFresh = data.onFresh || noop; const onDone = data.onDone || noop; - files.add(path.normalize(dest)); + files.add(dest); if (events.ignoreBasenames.indexOf(path.basename(src)) >= 0) { // ignored file @@ -191,7 +191,7 @@ async function buildActionsForCopy( } else if (srcStat.isDirectory()) { await mkdirp(dest); - const destParts = path.normalize(dest).split(path.sep); + const destParts = dest.split(path.sep); while (destParts.length) { files.add(destParts.join(path.sep)); destParts.pop(); From 3e99572deb2a59bafe5de82d55d17a2ed3c9f3ef Mon Sep 17 00:00:00 2001 From: Daniel Poindexter Date: Thu, 17 Nov 2016 20:41:43 -0600 Subject: [PATCH 3/3] Add flow types to package-hoister unit tests --- __tests__/package-hoister.js | 32 +++++++++++++++++++++----------- src/package-hoister.js | 8 +++++--- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/__tests__/package-hoister.js b/__tests__/package-hoister.js index 394f42a10e..3dfa965be0 100644 --- a/__tests__/package-hoister.js +++ b/__tests__/package-hoister.js @@ -1,30 +1,40 @@ /* @flow */ -import path from 'path'; 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 mockConfig = { - cwd: __dirname, - getFolder(): string { - return 'node_modules'; - }, -}; +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: {}}; - const loc = null; - const info = new HoistManifest(key, parts, pkg, loc); + + 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(mockConfig); + const packageHoister = new PackageHoister(config, resolver, false); packageHoister.tree = tree; const result = packageHoister.init(); diff --git a/src/package-hoister.js b/src/package-hoister.js index c09af00b9c..19f524e009 100644 --- a/src/package-hoister.js +++ b/src/package-hoister.js @@ -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 = []; const keyParts = key.split('#'); for (let i = 0; i < keyParts.length; i++) { const key = keyParts.slice(0, i + 1).join('#'); @@ -363,10 +363,12 @@ 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 = path.join(...parts);