Skip to content

Commit

Permalink
Fix missing bin link for namespaced links
Browse files Browse the repository at this point in the history
  • Loading branch information
lettertwo committed Jan 20, 2023
1 parent ab0a470 commit cf226fb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/core/integration-tests/test/parcel-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ describe('@parcel/link', () => {
let fs = await createFS('/app')`
yarn.lock:
node_modules
.bin/parcel:
@namespace
parcel
parcel-core`;
Expand All @@ -221,6 +222,11 @@ describe('@parcel/link', () => {

assert(fs.existsSync('.parcel-link'));

assert.equal(
fs.realpathSync('node_modules/.bin/parcel'),
path.resolve(__dirname, '../../parcel/src/bin.js'),
);

assert.equal(
fs.realpathSync('node_modules/@namespace/parcel-core'),
path.resolve(__dirname, '../../core'),
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/parcel-link/src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {CmdOptions} from './utils';
import {
findParcelPackages,
mapNamespacePackageAliases,
cleanupBin,
cleanupNodeModules,
fsWrite,
fsSymlink,
Expand Down Expand Up @@ -40,6 +41,7 @@ export async function link(
// --------------------------------------------------------------------------------

for (let nodeModules of nodeModulesPaths) {
await cleanupBin(nodeModules, opts);
await cleanupNodeModules(
nodeModules,
packageName => parcelPackages.has(packageName),
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/parcel-link/src/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {ParcelLinkConfig} from './ParcelLinkConfig';
import type {CmdOptions} from './utils';

import {
cleanupBin,
cleanupNodeModules,
execSync,
findParcelPackages,
Expand Down Expand Up @@ -41,6 +42,7 @@ export async function unlink(
// --------------------------------------------------------------------------------

for (let nodeModules of nodeModulesPaths) {
await cleanupBin(nodeModules, opts);
await cleanupNodeModules(
nodeModules,
packageName => parcelPackages.has(packageName),
Expand Down
20 changes: 11 additions & 9 deletions packages/dev/parcel-link/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,25 @@ export function mapNamespacePackageAliases(
return aliasesToParcelPackages;
}

export async function cleanupBin(root: string, opts: CmdOptions) {
let {fs} = opts;
let binSymlink = path.join(root, '.bin/parcel');
try {
await fsDelete(binSymlink, opts);
} catch (e) {
// noop
}
}

export async function cleanupNodeModules(
root: string,
predicate: (filepath: string) => boolean,
opts: CmdOptions,
): Promise<void> {
let {fs} = opts;
for (let dirName of fs.readdirSync(root)) {
if (dirName === '.bin') continue;
let dirPath = path.join(root, dirName);
if (dirName === '.bin') {
let binSymlink = path.join(root, '.bin/parcel');
try {
await fsDelete(binSymlink, opts);
} catch (e) {
// noop
}
continue;
}
if (dirName[0].startsWith('@')) {
await cleanupNodeModules(dirPath, predicate, opts);
continue;
Expand Down

0 comments on commit cf226fb

Please sign in to comment.