Skip to content

Commit

Permalink
fix for #207 windows cmdshim problem
Browse files Browse the repository at this point in the history
  • Loading branch information
bholloway committed Aug 16, 2019
1 parent d01b12c commit 2818eb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
10 changes: 6 additions & 4 deletions src/utils/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ function stripExtension(filePath: string) {
}

async function cmdShim(src: string, dest: string) {
const currentShimTarget = path.resolve(
path.dirname(src),
await readCmdShim(src)
);
// If not a symlink we default to the actual src file
// https://github.com/npm/npm/blob/d081cc6c8d73f2aa698aab36605377c95e916224/lib/utils/gently-rm.js#L273
let relativeShimTarget = await readlink(src);
let currentShimTarget = relativeShimTarget
? path.resolve(path.dirname(src), relativeShimTarget)
: src;
await promisify(cb => _cmdShim(currentShimTarget, stripExtension(dest), cb));
}

Expand Down
29 changes: 13 additions & 16 deletions src/utils/symlinkPackageDependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default async function symlinkPackageDependencies(

/*********************************************************************
* Calculate all the external dependencies that need to be symlinked *
**********************************************************************/
*********************************************************************/

directoriesToCreate.push(pkg.nodeModules, pkg.nodeModulesBin);

Expand Down Expand Up @@ -87,7 +87,7 @@ export default async function symlinkPackageDependencies(

/*********************************************************************
* Calculate all the internal dependencies that need to be symlinked *
**********************************************************************/
*********************************************************************/

for (let dependency of internalDeps) {
let depWorkspace = dependencyGraph.get(dependency) || {};
Expand All @@ -101,9 +101,9 @@ export default async function symlinkPackageDependencies(
throw new BoltError('Cannot symlink invalid set of dependencies.');
}

/********************************************************
/*********************************************************
* Calculate all the bin files that need to be symlinked *
*********************************************************/
*********************************************************/
let projectBinFiles = await fs.readdirSafe(project.pkg.nodeModulesBin);

// TODO: For now, we'll search through each of the bin files in the Project and find which ones are
Expand All @@ -118,14 +118,11 @@ export default async function symlinkPackageDependencies(
// read the symlink to find the actual bin file (path will be relative to the symlink)
let actualBinFileRelative = await fs.readlink(binPath);

if (!actualBinFileRelative) {
throw new BoltError(`${binName} is not a symlink`);
}

let actualBinFile = path.join(
project.pkg.nodeModulesBin,
actualBinFileRelative
);
// If not a symlink we default to the actual src file
// https://github.com/npm/npm/blob/d081cc6c8d73f2aa698aab36605377c95e916224/lib/utils/gently-rm.js#L273
let actualBinFile = actualBinFileRelative
? path.join(project.pkg.nodeModulesBin, actualBinFileRelative)
: binPath;

// To find the name of the dep that created the bin we'll get its path from node_modules and
// use the first one or two parts (two if the package is scoped)
Expand All @@ -149,9 +146,9 @@ export default async function symlinkPackageDependencies(
});
}

/*****************************************************************
/******************************************************************
* Calculate all the internal bin files that need to be symlinked *
******************************************************************/
******************************************************************/

// TODO: Same as above, we should really be making sure we get all the transitive bins as well

Expand Down Expand Up @@ -192,9 +189,9 @@ export default async function symlinkPackageDependencies(
}
}

/**********************************
/***********************************
* Create directories and symlinks *
***********************************/
***********************************/

await yarn.runIfExists(pkg, 'preinstall');

Expand Down

0 comments on commit 2818eb8

Please sign in to comment.