diff --git a/package-lock.json b/package-lock.json index 5a885e6..681faa1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -926,9 +926,9 @@ } }, "node_modules/@npmcli/fs/node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -1081,9 +1081,9 @@ } }, "node_modules/@swc/cli/node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -1617,9 +1617,9 @@ } }, "node_modules/bin-version-check/node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -4422,9 +4422,9 @@ "integrity": "sha512-2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA==" }, "node_modules/protobufjs": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.2.tgz", - "integrity": "sha512-++PrQIjrom+bFDPpfmqXfAGSQs40116JRrqqyf53dymUMvvb5d/LMRyicRoF1AUKoXVS1/IgJXlEgcpr4gTF3Q==", + "version": "7.2.4", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.4.tgz", + "integrity": "sha512-AT+RJgD2sH8phPmCf7OUZR8xGdcJRga4+1cOaXJ64hvcSkVhNcRHOwIxUatPH15+nj59WAGTDv3LSGZPEQbJaQ==", "hasInstallScript": true, "dependencies": { "@protobufjs/aspromise": "^1.1.2", @@ -4693,9 +4693,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } diff --git a/src/generator.ts b/src/generator.ts index d0be25a..8265eb9 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -156,6 +156,11 @@ export interface GeneratorOptions { */ cache?: "offline" | boolean; + /** + * User-provided fetch options for fetching modules, check https://github.com/npm/make-fetch-happen#extra-options + */ + fetchOptions?: Record; + /** * Custom provider definitions. * @@ -406,6 +411,7 @@ export class Generator { providers, resolutions = {}, cache = true, + fetchOptions = {}, ignore = [], freeze, latest, @@ -425,18 +431,17 @@ export class Generator { } // Initialise the resource fetcher: - let fetchOpts; + let fetchOpts: Record = { + retry: 1, + timeout: 10000, + ...fetchOptions, + headers: { "Accept-Encoding": "gzip, br" }, + } if (cache === "offline") - fetchOpts = { - cache: "force-cache", - headers: { "Accept-Encoding": "gzip, br" }, - }; + fetchOpts.cache = "force-cache" else if (!cache) - fetchOpts = { - cache: "no-store", - headers: { "Accept-Encoding": "gzip, br" }, - }; - else fetchOpts = { headers: { "Accept-Encoding": "gzip, br" } }; + fetchOpts.cache = "no-store"; + if (ipfsAPI) fetchOpts.ipfsAPI = ipfsAPI; // Default logic for the mapUrl, baseUrl and rootUrl: @@ -824,8 +829,8 @@ export class Generator { const newlineTab = !whitespace ? analysis.newlineTab : analysis.newlineTab.includes("\n") - ? analysis.newlineTab - : "\n" + analysis.newlineTab; + ? analysis.newlineTab + : "\n" + analysis.newlineTab; const replacer = new Replacer(html); @@ -868,14 +873,13 @@ export class Generator { !!rootUrl ); - esms = `${newlineTab}`; + esms = `${newlineTab}`; if (analysis.esModuleShims) replacer.remove( @@ -896,28 +900,26 @@ export class Generator { if (first || whitespace) preloads += newlineTab; if (first) first = false; if (integrity) { - preloads += ``; + preloads += ``; } else { - preloads += ``; + preloads += ``; } } } @@ -929,11 +931,11 @@ export class Generator { if (module.attrs.integrity) { replacer.remove( module.attrs.integrity.start - - (replacer.source[ - replacer.idx(module.attrs.integrity.start - 1) - ] === " " - ? 1 - : 0), + (replacer.source[ + replacer.idx(module.attrs.integrity.start - 1) + ] === " " + ? 1 + : 0), module.attrs.integrity.end + 1 ); } @@ -968,17 +970,17 @@ export class Generator { analysis.map.start, analysis.map.end, (comment ? "" + newlineTab : "") + - esms + - '" + - preloads + - (analysis.map.newScript ? newlineTab : "") + esms + + '" + + preloads + + (analysis.map.newScript ? newlineTab : "") ); return replacer.source; @@ -1543,12 +1545,10 @@ async function installToTarget( (install.subpath !== "." && !install.subpath.startsWith("./"))) ) throw new Error( - `Install subpath "${ - install.subpath - }" must be a string equal to "." or starting with "./".${ - typeof install.subpath === "string" - ? `\nTry setting the subpath to "./${install.subpath}"` - : "" + `Install subpath "${install.subpath + }" must be a string equal to "." or starting with "./".${typeof install.subpath === "string" + ? `\nTry setting the subpath to "./${install.subpath}"` + : "" }` );