Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow committed Aug 23, 2021
1 parent a0e39df commit 6b8d9aa
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions snowpack/src/sources/local.ts
Expand Up @@ -499,9 +499,17 @@ export class PackageSourceLocal implements PackageSource {
let packageFormatted = spec + colors.dim('@' + packageVersion);
const existingImportMapLoc = path.join(installDest, 'import-map.json');
let existingImportMap: ImportMap | undefined = memoizedImportMap[packageName];
if (!existingImportMap && existsSync(existingImportMapLoc)) {
existingImportMap = JSON.parse(await fs.readFile(existingImportMapLoc, 'utf8'));
memoizedImportMap[packageName] = existingImportMap as ImportMap;
if (!existingImportMap) {
// note: this must happen BEFORE the check on disk to prevent a race condition.
// If two lookups occur at once from different sources, then we mark this as “taken” immediately and finish the lookup async
memoizedImportMap[packageName] = {imports: {}}; // TODO: this may not exist; should we throw an error?
const importMapHandle = await fs.open(existingImportMapLoc, 'r+').catch(() => null);
if (importMapHandle) {
const importMapData = await importMapHandle.readFile('utf-8');
existingImportMap = importMapData ? JSON.parse(importMapData) : null;
memoizedImportMap[packageName] = existingImportMap as ImportMap;
await importMapHandle.close();
}
}

// Kick off a build, if needed.
Expand Down

0 comments on commit 6b8d9aa

Please sign in to comment.