Skip to content

Commit c435a7b

Browse files
committed
Use fallback for fetching metas
1 parent 4146154 commit c435a7b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

packages/app/src/sandbox/eval/npm/fetch-npm-module.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,26 @@ const ALIAS_REGEX = /\/\d*\.\d*\.\d*.*?(\/|$)/;
181181
async function getMeta(
182182
name: string,
183183
packageJSONPath: string | null,
184-
version: string
184+
version: string,
185+
useFallback = false
185186
) {
186187
const nameWithoutAlias = name.replace(ALIAS_REGEX, '');
187188
const id = `${packageJSONPath || name}@${version}`;
188189
if (metas[id]) {
189190
return metas[id];
190191
}
191192

192-
const protocol = getFetchProtocol(version);
193+
const protocol = getFetchProtocol(version, useFallback);
193194

194195
metas[id] = protocol
195196
.meta(nameWithoutAlias, version)
196197
.then(fetchWithRetries)
197-
.then(x => x.json());
198+
.then(x => x.json())
199+
.catch(e => {
200+
delete metas[id];
201+
202+
throw e;
203+
});
198204

199205
return metas[id];
200206
}
@@ -470,9 +476,18 @@ export default async function fetchModule(
470476

471477
const { packageJSONPath, version } = versionInfo;
472478

473-
const meta = await getMeta(dependencyName, packageJSONPath, version);
479+
let meta: Meta;
480+
let normalizeFunction: typeof normalize;
481+
482+
try {
483+
normalizeFunction = getFetchProtocol(version).normalizeMeta;
484+
meta = await getMeta(dependencyName, packageJSONPath, version);
485+
} catch (e) {
486+
// Use fallback
487+
meta = await getMeta(dependencyName, packageJSONPath, version, true);
488+
normalizeFunction = getFetchProtocol(version, true).normalizeMeta;
489+
}
474490

475-
const normalizeFunction = getFetchProtocol(version).normalizeMeta;
476491
const rootPath = packageJSONPath
477492
? pathUtils.dirname(packageJSONPath)
478493
: pathUtils.join('/node_modules', dependencyName);

0 commit comments

Comments
 (0)