Skip to content

Commit 2cf23ff

Browse files
Merge pull request #7535 from BitGo/BTC-2732.package-scope-script
fix(scripts): fix dist tags for modules not in package.json
2 parents 1544fb9 + 3fe9548 commit 2cf23ff

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scripts/pack-scoped.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ async function getDistTagsFromPackageJson(
6565
): Promise<Map<string, DistTags>> {
6666
const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf-8'));
6767
return new Map<string, DistTags>(
68-
newModuleNames.map((m) => {
68+
newModuleNames.flatMap((m) => {
6969
const distTags = packageJson.dependencies[m];
7070
if (distTags) {
71-
return [m, { beta: distTags }];
71+
return [[m, { beta: distTags }]];
7272
}
73-
return [m, { beta: '0.0.0' }];
73+
return [];
7474
})
7575
);
7676
}
@@ -86,7 +86,11 @@ async function getDistTagsForModuleNamesCached(
8686
): Promise<Map<string, DistTags>> {
8787
if (params.sourceFile) {
8888
if (params.sourceFile.endsWith('package.json')) {
89-
return getDistTagsFromPackageJson(newModuleNames, params.sourceFile);
89+
const distTagsFromPackageJson = await getDistTagsFromPackageJson(newModuleNames, params.sourceFile);
90+
const remainingNames = newModuleNames.filter((m) => !distTagsFromPackageJson.has(m));
91+
console.log(`Getting dist tags for ${remainingNames.length} modules from npm`);
92+
const distTagsByModuleName = await getDistTagsForModuleNames(remainingNames);
93+
return new Map<string, DistTags>([...distTagsFromPackageJson.entries(), ...distTagsByModuleName.entries()]);
9094
}
9195
}
9296

0 commit comments

Comments
 (0)