Skip to content

Commit

Permalink
Merge pull request #1503 from embroider-build/realpath2
Browse files Browse the repository at this point in the history
less aggressive realpathSync
  • Loading branch information
ef4 authored Jul 1, 2023
2 parents 229045b + 0db95e2 commit 5120323
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 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 { ensureDirSync, existsSync, readJSONSync, realpathSync } from 'fs-extra';
import { 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 @@ -133,8 +133,8 @@ export class RewrittenPackageCache implements PublicAPI<PackageCache> {
}

private loadIndex(): RewrittenPackageCache['index'] {
let addonsDir = resolve(locateEmbroiderWorkingDir(this.appRoot), 'rewritten-packages');
let indexFile = resolve(addonsDir, 'index.json');
let workingDir = locateEmbroiderWorkingDir(this.appRoot);
let indexFile = resolve(workingDir, 'rewritten-packages', 'index.json');
if (!existsSync(indexFile)) {
return {
oldToNew: new Map(),
Expand All @@ -143,25 +143,16 @@ 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'));
workingDir = realpathSync(workingDir);
let addonsDir = resolve(workingDir, 'rewritten-packages');

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

0 comments on commit 5120323

Please sign in to comment.