Skip to content
This repository was archived by the owner on May 17, 2025. It is now read-only.

Commit 3b07a4e

Browse files
chore: Run the code through prettier for less conflicts
1 parent 6311b9f commit 3b07a4e

33 files changed

+382
-275
lines changed

src/common/fetch-node.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ function sourceResponse(buffer: string | Buffer) {
4141
return JSON.parse(buffer.toString());
4242
},
4343
arrayBuffer() {
44-
if (typeof buffer === 'string')
44+
if (typeof buffer === "string")
4545
return new TextEncoder().encode(buffer.toString()).buffer;
46-
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
46+
return new Uint8Array(
47+
buffer.buffer,
48+
buffer.byteOffset,
49+
buffer.byteLength
50+
);
4751
},
4852
};
4953
}

src/common/wrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//@ts-ignore
2-
import { fetch } from '#fetch';
3-
import { parse, init } from 'es-module-lexer';
2+
import { fetch } from "#fetch";
3+
import { parse, init } from "es-module-lexer";
44

5-
export async function getMaybeWrapperUrl (moduleUrl, fetchOpts) {
5+
export async function getMaybeWrapperUrl(moduleUrl, fetchOpts) {
66
await init;
77
const source = await (await fetch(moduleUrl, fetchOpts)).text();
8-
const [imports,, facade] = parse(source);
8+
const [imports, , facade] = parse(source);
99
if (facade && imports.length) {
1010
try {
1111
return new URL(imports[0].n, moduleUrl).href;

src/generator.ts

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { LockResolutions } from "./install/lock.js";
4343
import { getDefaultProviderStrings, type Provider } from "./providers/index.js";
4444
import * as nodemodules from "./providers/nodemodules.js";
4545
import { Resolver } from "./trace/resolver.js";
46-
import { getMaybeWrapperUrl } from './common/wrapper.js';
46+
import { getMaybeWrapperUrl } from "./common/wrapper.js";
4747

4848
// Utility exports for users:
4949
export { analyzeHtml };
@@ -297,7 +297,7 @@ export interface GeneratorOptions {
297297
* Disabled by default.
298298
*/
299299
commonJS?: boolean;
300-
300+
301301
/**
302302
* Support tracing TypeScript dependencies when generating the import map.
303303
* Disabled by default.
@@ -311,7 +311,14 @@ export interface GeneratorOptions {
311311
}
312312

313313
export interface ModuleAnalysis {
314-
format: "commonjs" | "esm" | "system" | "json" | "css" | "typescript" | "wasm";
314+
format:
315+
| "commonjs"
316+
| "esm"
317+
| "system"
318+
| "json"
319+
| "css"
320+
| "typescript"
321+
| "wasm";
315322
staticDeps: string[];
316323
dynamicDeps: string[];
317324
cjsLazyDeps: string[] | null;
@@ -417,11 +424,9 @@ export class Generator {
417424
timeout: 10000,
418425
...fetchOptions,
419426
headers: { "Accept-Encoding": "gzip, br" },
420-
}
421-
if (cache === "offline")
422-
fetchOpts.cache = "force-cache"
423-
else if (!cache)
424-
fetchOpts.cache = "no-store";
427+
};
428+
if (cache === "offline") fetchOpts.cache = "force-cache";
429+
else if (!cache) fetchOpts.cache = "no-store";
425430

426431
// Default logic for the mapUrl, baseUrl and rootUrl:
427432
if (mapUrl && !baseUrl) {
@@ -461,7 +466,14 @@ export class Generator {
461466
this.integrity = integrity;
462467

463468
// Initialise the resolver:
464-
const resolver = new Resolver({ env, log, fetchOpts, preserveSymlinks: true, traceCjs: commonJS, traceTs: typeScript });
469+
const resolver = new Resolver({
470+
env,
471+
log,
472+
fetchOpts,
473+
preserveSymlinks: true,
474+
traceCjs: commonJS,
475+
traceTs: typeScript,
476+
});
465477
if (customProviders) {
466478
for (const provider of Object.keys(customProviders)) {
467479
resolver.addCustomProvider(provider, customProviders[provider]);
@@ -495,16 +507,15 @@ export class Generator {
495507
providers,
496508
ignore,
497509
resolutions,
498-
commonJS
510+
commonJS,
499511
},
500512
log,
501513
resolver
502514
);
503515

504516
// Reconstruct constraints and locks from the input map:
505517
this.map = new ImportMap({ mapUrl: this.mapUrl, rootUrl: this.rootUrl });
506-
if (!integrity)
507-
this.map.integrity = {};
518+
if (!integrity) this.map.integrity = {};
508519
if (inputMap) this.addMappings(inputMap);
509520
}
510521

@@ -669,9 +680,7 @@ export class Generator {
669680
" Generated by @jspm/generator - https://github.com/jspm/generator ";
670681
if (typeof htmlUrl === "string") htmlUrl = new URL(htmlUrl);
671682
if (this.installCnt !== 0)
672-
throw new JspmError(
673-
"htmlInject cannot run alongside other install ops"
674-
);
683+
throw new JspmError("htmlInject cannot run alongside other install ops");
675684

676685
const analysis = analyzeHtml(html, htmlUrl);
677686

@@ -696,13 +705,16 @@ export class Generator {
696705
);
697706
}
698707

699-
const preloadDeps = preload === "all" ? [...new Set([...staticDeps, ...dynamicDeps])] : staticDeps;
708+
const preloadDeps =
709+
preload === "all"
710+
? [...new Set([...staticDeps, ...dynamicDeps])]
711+
: staticDeps;
700712

701713
const newlineTab = !whitespace
702714
? analysis.newlineTab
703715
: analysis.newlineTab.includes("\n")
704-
? analysis.newlineTab
705-
: "\n" + analysis.newlineTab;
716+
? analysis.newlineTab
717+
: "\n" + analysis.newlineTab;
706718

707719
const replacer = new Replacer(html);
708720

@@ -740,7 +752,10 @@ export class Generator {
740752
)) + "dist/es-module-shims.js";
741753

742754
// detect esmsUrl as a wrapper URL
743-
esmsUrl = await getMaybeWrapperUrl(esmsUrl, this.traceMap.resolver.fetchOpts);
755+
esmsUrl = await getMaybeWrapperUrl(
756+
esmsUrl,
757+
this.traceMap.resolver.fetchOpts
758+
);
744759

745760
if (htmlUrl || rootUrl)
746761
esmsUrl = relativeUrl(
@@ -749,12 +764,17 @@ export class Generator {
749764
!!rootUrl
750765
);
751766

752-
esms = `<script async src="${esmsUrl}" crossorigin="anonymous"${integrity
753-
? ` integrity="${getIntegrity(
754-
new Uint8Array(await (await fetch(esmsUrl, this.traceMap.resolver.fetchOpts)).arrayBuffer())
755-
)}"`
756-
: ""
757-
}></script>${newlineTab}`;
767+
esms = `<script async src="${esmsUrl}" crossorigin="anonymous"${
768+
integrity
769+
? ` integrity="${getIntegrity(
770+
new Uint8Array(
771+
await (
772+
await fetch(esmsUrl, this.traceMap.resolver.fetchOpts)
773+
).arrayBuffer()
774+
)
775+
)}"`
776+
: ""
777+
}></script>${newlineTab}`;
758778

759779
if (analysis.esModuleShims)
760780
replacer.remove(
@@ -774,14 +794,11 @@ export class Generator {
774794
for (let dep of preloadDeps.sort()) {
775795
if (first || whitespace) preloads += newlineTab;
776796
if (first) first = false;
777-
preloads += `<link rel="modulepreload" href="${rootUrl || htmlUrl
778-
? relativeUrl(
779-
new URL(dep),
780-
new URL(rootUrl || htmlUrl),
781-
!!rootUrl
782-
)
783-
: dep
784-
}" />`;
797+
preloads += `<link rel="modulepreload" href="${
798+
rootUrl || htmlUrl
799+
? relativeUrl(new URL(dep), new URL(rootUrl || htmlUrl), !!rootUrl)
800+
: dep
801+
}" />`;
785802
}
786803
}
787804

@@ -800,17 +817,17 @@ export class Generator {
800817
analysis.map.start,
801818
analysis.map.end,
802819
(comment ? "<!--" + comment + "-->" + newlineTab : "") +
803-
esms +
804-
'<script type="importmap">' +
805-
(whitespace ? newlineTab : "") +
806-
JSON.stringify(map, null, whitespace ? 2 : 0).replace(
807-
/\n/g,
808-
newlineTab
809-
) +
810-
(whitespace ? newlineTab : "") +
811-
"</script>" +
812-
preloads +
813-
(analysis.map.newScript ? newlineTab : "")
820+
esms +
821+
'<script type="importmap">' +
822+
(whitespace ? newlineTab : "") +
823+
JSON.stringify(map, null, whitespace ? 2 : 0).replace(
824+
/\n/g,
825+
newlineTab
826+
) +
827+
(whitespace ? newlineTab : "") +
828+
"</script>" +
829+
preloads +
830+
(analysis.map.newScript ? newlineTab : "")
814831
);
815832

816833
return replacer.source;
@@ -850,7 +867,6 @@ export class Generator {
850867
install?: string | Install | (string | Install)[],
851868
mode?: InstallMode
852869
): Promise<void | { staticDeps: string[]; dynamicDeps: string[] }> {
853-
854870
// If there are no arguments, then we reinstall all the top-level locks:
855871
if (install === null || install === undefined) {
856872
await this.traceMap.processInputMap;
@@ -1097,7 +1113,8 @@ export class Generator {
10971113
}
10981114
this.traceMap.pins = pins;
10991115
if (--this.installCnt === 0) {
1100-
const { staticDeps, dynamicDeps, map } = await this.traceMap.finishInstall(this.traceMap.pins, this.integrity);
1116+
const { staticDeps, dynamicDeps, map } =
1117+
await this.traceMap.finishInstall(this.traceMap.pins, this.integrity);
11011118
this.map = map;
11021119
return { staticDeps, dynamicDeps };
11031120
}
@@ -1112,7 +1129,7 @@ export class Generator {
11121129
if (typeof mapUrl === "string") mapUrl = new URL(mapUrl, this.baseUrl);
11131130
if (typeof rootUrl === "string") rootUrl = new URL(rootUrl, this.baseUrl);
11141131
if (!Array.isArray(pins)) pins = [pins];
1115-
if (typeof integrity !== 'boolean') integrity = this.integrity;
1132+
if (typeof integrity !== "boolean") integrity = this.integrity;
11161133
if (this.installCnt++ !== 0)
11171134
throw new JspmError(`Cannot run extract map during installs`);
11181135
this.traceMap.startInstall();
@@ -1374,10 +1391,12 @@ async function installToTarget(
13741391
(install.subpath !== "." && !install.subpath.startsWith("./")))
13751392
)
13761393
throw new Error(
1377-
`Install subpath "${install.subpath
1378-
}" must be a string equal to "." or starting with "./".${typeof install.subpath === "string"
1379-
? `\nTry setting the subpath to "./${install.subpath}"`
1380-
: ""
1394+
`Install subpath "${
1395+
install.subpath
1396+
}" must be a string equal to "." or starting with "./".${
1397+
typeof install.subpath === "string"
1398+
? `\nTry setting the subpath to "./${install.subpath}"`
1399+
: ""
13811400
}`
13821401
);
13831402

src/install/installer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export type InstallMode =
6161

6262
export type InstallTarget = {
6363
pkgTarget: PackageTarget | URL;
64-
installSubpath: null | '.' | `./${string}`;
64+
installSubpath: null | "." | `./${string}`;
6565
};
6666

6767
export interface InstallerOptions {

src/install/lock.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export interface VersionConstraints {
5252

5353
export interface InstalledResolution {
5454
installUrl: `${string}/`;
55-
installSubpath: '.' | `./${string}` | null;
55+
installSubpath: "." | `./${string}` | null;
5656
}
5757

5858
export interface FlatInstalledResolution {
@@ -126,7 +126,7 @@ export function setResolution(
126126
name: string,
127127
installUrl: `${string}/`,
128128
pkgScope: `${string}/` | null = null,
129-
installSubpath: '.' | `./${string}` | null = null
129+
installSubpath: "." | `./${string}` | null = null
130130
) {
131131
if (pkgScope && !pkgScope.endsWith("/")) throwInternalError(pkgScope);
132132
if (pkgScope === null) {
@@ -513,7 +513,7 @@ export async function extractLockConstraintsAndMap(
513513

514514
// In the case of subpaths having diverging versions, we force convergence on one version
515515
// Only scopes permit unpacking
516-
let installSubpath: null | '.' | './' | `./${string}/` | false = null;
516+
let installSubpath: null | "." | "./" | `./${string}/` | false = null;
517517
if (parsedKey.subpath !== exportSubpath) {
518518
if (parsedKey.subpath === ".") {
519519
installSubpath = exportSubpath as `./${string}/`;

src/providers/esmsh.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export async function pkgToUrl(pkg: ExactPackage): Promise<`${string}/`> {
1313
return `${cdnUrl}*${pkg.name}@${pkg.version}/`;
1414
}
1515

16-
const exactPkgRegEx = /^(?:v\d+\/)?\*?((?:@[^/\\%@]+\/)?[^./\\%@][^/\\%@]*)@([^\/]+)(\/.*)?$/;
16+
const exactPkgRegEx =
17+
/^(?:v\d+\/)?\*?((?:@[^/\\%@]+\/)?[^./\\%@][^/\\%@]*)@([^\/]+)(\/.*)?$/;
1718

1819
export function parseUrlPkg(url: string) {
1920
if (!url.startsWith(cdnUrl)) return;
@@ -54,17 +55,16 @@ export async function getPackageConfig(
5455
if (pcfg.exports) {
5556
// in the conditional expoort case, paths seem to work?
5657
// so go with that
57-
if (Object.keys(pcfg.exports).every(key => !key.startsWith('./'))) {
58-
pcfg.exports['.'] = pcfg.exports;
59-
}
60-
else {
58+
if (Object.keys(pcfg.exports).every((key) => !key.startsWith("./"))) {
59+
pcfg.exports["."] = pcfg.exports;
60+
} else {
6161
// let esm.sh resolve conditions
6262
for (const key of Object.keys(pcfg.exports)) {
6363
pcfg.exports[key] = key;
6464
}
6565
}
6666
// wildcard key for esmsh to do its own fallback resolution too
67-
pcfg.exports['./*'] = './*';
67+
pcfg.exports["./*"] = "./*";
6868
}
6969
if (pcfg.imports) {
7070
for (const key of Object.keys(pcfg.imports)) {

src/providers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const defaultProviders: Record<string, Provider> = {
5959
skypack,
6060
unpkg,
6161
"esm.sh": esmsh,
62-
"jspm.io": jspm
62+
"jspm.io": jspm,
6363
};
6464

6565
export function getProvider(name: string, providers: Record<string, Provider>) {

src/providers/jspm.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ async function lookupRange(
284284
);
285285
default:
286286
throw new JspmError(
287-
`Invalid status code ${res.status} looking up "${registry}:${name}" from ${url} - ${
287+
`Invalid status code ${
288+
res.status
289+
} looking up "${registry}:${name}" from ${url} - ${
288290
res.statusText
289291
}${importedFrom(parentUrl)}`
290292
);

src/providers/node.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ export function resolveBuiltin(
105105
}
106106

107107
// Strip the subpath for subpathed builtins
108-
if (builtin.includes('/'))
109-
builtin = builtin.split('/')[0];
108+
if (builtin.includes("/")) builtin = builtin.split("/")[0];
110109

111110
return {
112111
target: {

0 commit comments

Comments
 (0)