Skip to content

Commit

Permalink
Merge pull request #1493 from embroider-build/realpath
Browse files Browse the repository at this point in the history
Fix rewritten-package-cache when app has symlink to node_modules
  • Loading branch information
ef4 authored Jun 30, 2023
2 parents 0128902 + 1457ed7 commit 53de9f9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/shared-internals/src/rewritten-package-cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PackageCache from './package-cache';
import Package from './package';
import { existsSync, readJSONSync } from 'fs-extra';
import { ensureDirSync, existsSync, readJSONSync, realpathSync } from 'fs-extra';
import { resolve } from 'path';
import { getOrCreate } from './get-or-create';
import { locateEmbroiderWorkingDir } from './working-dir';
Expand Down Expand Up @@ -143,13 +143,25 @@ export class RewrittenPackageCache implements PublicAPI<PackageCache> {
};
}

// this directory is a bit special because RewrittenPackageCache needs to
// exist before this dir has been produced. But the dir appears preemptively
// in our index, and we don't want that to blow up during the realpath
// below.
ensureDirSync(resolve(addonsDir, '..', 'rewritten-app'));

let { packages, extraResolutions } = readJSONSync(indexFile) as RewrittenPackageIndex;
return {
oldToNew: new Map(
Object.entries(packages).map(([oldRoot, newRoot]) => [resolve(addonsDir, oldRoot), resolve(addonsDir, newRoot)])
Object.entries(packages).map(([oldRoot, newRoot]) => [
realpathSync(resolve(addonsDir, oldRoot)),
realpathSync(resolve(addonsDir, newRoot)),
])
),
newToOld: new Map(
Object.entries(packages).map(([oldRoot, newRoot]) => [resolve(addonsDir, newRoot), resolve(addonsDir, oldRoot)])
Object.entries(packages).map(([oldRoot, newRoot]) => [
realpathSync(resolve(addonsDir, newRoot)),
realpathSync(resolve(addonsDir, oldRoot)),
])
),
extraResolutions: new Map(
Object.entries(extraResolutions).map(([fromRoot, toRoots]) => [
Expand Down

0 comments on commit 53de9f9

Please sign in to comment.