Skip to content

Commit

Permalink
Normalize file copy destination when creating hoist manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
dpoindexter committed Nov 17, 2016
1 parent a1c3aeb commit 7fca0c8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions __tests__/package-hoister.js
Original file line number Diff line number Diff line change
@@ -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);
});
2 changes: 1 addition & 1 deletion src/package-hoister.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 7fca0c8

Please sign in to comment.