jspm 4.0.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +102 -36
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2326,7 +2326,7 @@ async function writeHtmlOutput(mapFile, generator, pins, env2, flags, silent = f
|
|
|
2326
2326
|
htmlUrl: generator.mapUrl,
|
|
2327
2327
|
// URL of the output map
|
|
2328
2328
|
rootUrl: generator.rootUrl,
|
|
2329
|
-
preload: getPreloadMode(flags),
|
|
2329
|
+
preload: flags.release ? true : getPreloadMode(flags),
|
|
2330
2330
|
integrity: flags.integrity,
|
|
2331
2331
|
whitespace: !flags.compact,
|
|
2332
2332
|
comment: false
|
|
@@ -2403,8 +2403,8 @@ async function getGenerator(flags, configOverride = null, inputMap) {
|
|
|
2403
2403
|
rootUrl,
|
|
2404
2404
|
inputMap: inputMap || await getInputMap(flags),
|
|
2405
2405
|
env: await getEnv(flags),
|
|
2406
|
-
flattenScopes: flags.flattenScopes,
|
|
2407
|
-
combineSubpaths: flags.combineSubpaths,
|
|
2406
|
+
flattenScopes: flags.flattenScopes === false ? false : flags.release || flags.flattenScopes,
|
|
2407
|
+
combineSubpaths: flags.combineSubpaths === false ? false : flags.release || flags.combineSubpaths,
|
|
2408
2408
|
defaultProvider,
|
|
2409
2409
|
resolutions: getResolutions(flags),
|
|
2410
2410
|
cache: getCacheMode(flags),
|
|
@@ -2494,19 +2494,23 @@ function getInputPath(flags, fallbackDefaultMap = defaultMapPath) {
|
|
|
2494
2494
|
if (mapPath) {
|
|
2495
2495
|
return resolve(mapPath);
|
|
2496
2496
|
}
|
|
2497
|
-
|
|
2498
|
-
|
|
2497
|
+
const defaultMapPathResolved = resolve(flags.dir ?? ".", defaultMapPath);
|
|
2498
|
+
if (exists(defaultMapPathResolved)) {
|
|
2499
|
+
return defaultMapPathResolved;
|
|
2499
2500
|
}
|
|
2500
|
-
|
|
2501
|
+
const fallbackDefaultMapResolved = resolve(flags.dir ?? ".", fallbackDefaultMap);
|
|
2502
|
+
return fallbackDefaultMapResolved;
|
|
2501
2503
|
}
|
|
2502
2504
|
function getOutputPath(flags) {
|
|
2503
2505
|
if (flags.out || flags.map) {
|
|
2504
2506
|
return resolve(flags.out || flags.map);
|
|
2505
2507
|
}
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
+
const defaultMapPathResolved = resolve(flags.dir ?? ".", defaultMapPath);
|
|
2509
|
+
if (defaultMapPathResolved) {
|
|
2510
|
+
return defaultMapPathResolved;
|
|
2508
2511
|
}
|
|
2509
|
-
|
|
2512
|
+
const fallbackDefaultMapResolved = resolve(flags.dir ?? ".", defaultMapPath);
|
|
2513
|
+
return fallbackDefaultMapResolved;
|
|
2510
2514
|
}
|
|
2511
2515
|
function getOutputMapUrl(flags) {
|
|
2512
2516
|
return pathToFileURL(getOutputPath(flags));
|
|
@@ -2539,9 +2543,8 @@ function addEnvs(env2, newEnvs) {
|
|
|
2539
2543
|
return env2.sort();
|
|
2540
2544
|
}
|
|
2541
2545
|
async function getEnv(flags) {
|
|
2542
|
-
const inputMap = await getInputMap(flags);
|
|
2543
2546
|
const envFlags = Array.isArray(flags?.conditions) ? flags.conditions : (flags.conditions || "").split(",").map((e) => e.trim()).filter(Boolean);
|
|
2544
|
-
let env2 =
|
|
2547
|
+
let env2 = ["browser", "module", flags.release ? "production" : "development"];
|
|
2545
2548
|
env2 = removeEnvs(
|
|
2546
2549
|
env2,
|
|
2547
2550
|
envFlags.filter((env3) => env3.startsWith("no-")).map((env3) => env3.slice(3))
|
|
@@ -3378,7 +3381,7 @@ ${c6.green("Ok:")} Initialization complete.`);
|
|
|
3378
3381
|
}
|
|
3379
3382
|
}
|
|
3380
3383
|
async function initProject(flags) {
|
|
3381
|
-
const directory =
|
|
3384
|
+
const directory = process.cwd();
|
|
3382
3385
|
if (!await isDirectory(directory)) {
|
|
3383
3386
|
throw new JspmError(`Directory does not exist: ${directory}`);
|
|
3384
3387
|
}
|
|
@@ -29205,7 +29208,7 @@ async function build(flags) {
|
|
|
29205
29208
|
format: "esm",
|
|
29206
29209
|
assetFileNames: "[name][extname]",
|
|
29207
29210
|
entryFileNames: "[name]",
|
|
29208
|
-
chunkFileNames: "[name]",
|
|
29211
|
+
chunkFileNames: "lib/[name]-[hash:8].js",
|
|
29209
29212
|
sourcemap: true,
|
|
29210
29213
|
compact: flags.minify
|
|
29211
29214
|
});
|
|
@@ -29219,7 +29222,18 @@ async function build(flags) {
|
|
|
29219
29222
|
await writeFile3(`${outPath}.map`, JSON.stringify(chunk.map));
|
|
29220
29223
|
}
|
|
29221
29224
|
}
|
|
29222
|
-
const
|
|
29225
|
+
const projectBase = `${pathToFileURL4(projectConfig.projectPath).href}/`;
|
|
29226
|
+
const generatedFiles = /* @__PURE__ */ new Set();
|
|
29227
|
+
for (const chunk of output) {
|
|
29228
|
+
generatedFiles.add(chunk.fileName);
|
|
29229
|
+
if (chunk.type === "chunk") {
|
|
29230
|
+
for (const refFile of chunk.moduleIds) {
|
|
29231
|
+
if (refFile.startsWith(projectBase)) {
|
|
29232
|
+
generatedFiles.add(relative3(projectBase, refFile).replace(/\\/g, "/"));
|
|
29233
|
+
}
|
|
29234
|
+
}
|
|
29235
|
+
}
|
|
29236
|
+
}
|
|
29223
29237
|
{
|
|
29224
29238
|
const pjson = JSON.parse(
|
|
29225
29239
|
readFileSync2(join3(projectConfig.projectPath, "package.json"), "utf8")
|
|
@@ -29244,8 +29258,44 @@ async function build(flags) {
|
|
|
29244
29258
|
}
|
|
29245
29259
|
}
|
|
29246
29260
|
stopSpinner();
|
|
29261
|
+
if (flags.install !== false) {
|
|
29262
|
+
if (!flags.quiet) {
|
|
29263
|
+
console.log(`${c11.cyan("Info:")} Generating import map in build directory...`);
|
|
29264
|
+
}
|
|
29265
|
+
const map = getInputPath(flags);
|
|
29266
|
+
process.chdir(flags.out);
|
|
29267
|
+
const installFlags = {
|
|
29268
|
+
...flags,
|
|
29269
|
+
// use local map as source of truth for resolutions
|
|
29270
|
+
map,
|
|
29271
|
+
// output to default importmap.js in build dir
|
|
29272
|
+
out: getOutputPath({}),
|
|
29273
|
+
dir: void 0,
|
|
29274
|
+
release: true,
|
|
29275
|
+
quiet: true
|
|
29276
|
+
};
|
|
29277
|
+
try {
|
|
29278
|
+
await install(installFlags);
|
|
29279
|
+
if (!flags.quiet) {
|
|
29280
|
+
console.log(`${c11.green("\u2713")} Import map generated in ${c11.cyan(flags.out)}`);
|
|
29281
|
+
}
|
|
29282
|
+
} catch (error2) {
|
|
29283
|
+
if (!flags.quiet) {
|
|
29284
|
+
console.warn(`${c11.yellow("Warning:")} Failed to generate import map: ${error2.message}`);
|
|
29285
|
+
}
|
|
29286
|
+
}
|
|
29287
|
+
}
|
|
29247
29288
|
if (!flags.quiet) {
|
|
29248
|
-
|
|
29289
|
+
const infoMsg = flags.install !== false ? `${c11.green("\u2713")} Built ${c11.cyan(projectConfig.name)} to ${c11.cyan(
|
|
29290
|
+
flags.out
|
|
29291
|
+
)} with import map.` : `${c11.green("\u2713")} Built ${c11.cyan(projectConfig.name)} to ${c11.cyan(
|
|
29292
|
+
flags.out
|
|
29293
|
+
)}.
|
|
29294
|
+
|
|
29295
|
+
${c11.cyan("Info:")} Run ${c11.bold(
|
|
29296
|
+
`jspm -d ${flags.out} install --release`
|
|
29297
|
+
)} to create a production import map.`;
|
|
29298
|
+
console.log(infoMsg);
|
|
29249
29299
|
}
|
|
29250
29300
|
} catch (e) {
|
|
29251
29301
|
stopSpinner();
|
|
@@ -32311,12 +32361,12 @@ ${error2.snippet}`
|
|
|
32311
32361
|
file: relativePath2,
|
|
32312
32362
|
name: `Bare module specifier import ${c15.bold(
|
|
32313
32363
|
c15.cyan(`'${module}'`)
|
|
32314
|
-
)} is not mapped by the import map
|
|
32364
|
+
)} is not mapped by the import map. Either update the package.json "name" or update the HTML to use an import of "jspm" or "jspm/...".`,
|
|
32315
32365
|
description: `Only bare specifiers matching the project name ${c15.cyan(
|
|
32316
32366
|
c15.bold(`'${projectConfig.name}'`)
|
|
32317
32367
|
)} are mapped.`,
|
|
32318
32368
|
code: {
|
|
32319
|
-
title: "
|
|
32369
|
+
title: "Correct JSPM HTML Script:",
|
|
32320
32370
|
snippet: `<script type="module">import '${projectConfig.name}';</script>`
|
|
32321
32371
|
}
|
|
32322
32372
|
});
|
|
@@ -32750,31 +32800,33 @@ ${c16.yellow("...")}${c16.bold(remainingCount)} more ${remainingCount === 1 ? "i
|
|
|
32750
32800
|
init_init();
|
|
32751
32801
|
var { version: version2 } = JSON.parse(readFileSync3(new URL("../package.json", import.meta.url), "utf8"));
|
|
32752
32802
|
var cli = dist_default(c17.yellow("jspm"));
|
|
32753
|
-
var generateOpts = (cac2,
|
|
32803
|
+
var generateOpts = (cac2, release = false) => cac2.option(
|
|
32754
32804
|
"-m, --map <file>",
|
|
32755
32805
|
"File containing initial import map (defaults to importmap.json, supports .js with a JSON import map embedded, or HTML with an inline import map)",
|
|
32756
32806
|
{}
|
|
32757
32807
|
).option("-C, --conditions <environments>", "Comma-separated environment condition overrides", {
|
|
32758
|
-
default:
|
|
32808
|
+
default: []
|
|
32759
32809
|
}).option("-r, --resolution <resolutions>", "Comma-separated dependency resolution overrides", {}).option(
|
|
32760
32810
|
"-p, --provider <provider>",
|
|
32761
32811
|
`Default module provider. Available providers: ${availableProviders.join(", ")}`,
|
|
32762
32812
|
{}
|
|
32763
32813
|
).option("--cache <mode>", "Cache mode for fetches (online, offline, no-cache)", {
|
|
32764
32814
|
default: "online"
|
|
32765
|
-
})
|
|
32766
|
-
|
|
32767
|
-
"-
|
|
32768
|
-
"Flatten import map scopes into smaller single top-level scope per origin",
|
|
32815
|
+
}).option(
|
|
32816
|
+
"--release",
|
|
32817
|
+
"Enable release mode (--flatten-scopes, --combine-subpaths, --C=production)",
|
|
32769
32818
|
{
|
|
32770
|
-
default:
|
|
32819
|
+
default: release
|
|
32771
32820
|
}
|
|
32821
|
+
);
|
|
32822
|
+
var outputOpts = (cac2) => cac2.option("--integrity", "Add module integrity attributes to the import map", {}).option("--preload [mode]", "Add module preloads to HTML output (default: static, dynamic)", {}).option("--root <url>", "URL to treat as server root, i.e. rebase import maps against", {}).option(
|
|
32823
|
+
"-f, --flatten-scopes",
|
|
32824
|
+
"Flatten import map scopes into smaller single top-level scope per origin",
|
|
32825
|
+
{}
|
|
32772
32826
|
).option(
|
|
32773
32827
|
"-s, --combine-subpaths",
|
|
32774
32828
|
"Combine import map subpaths under folder maps (ending in /)",
|
|
32775
|
-
{
|
|
32776
|
-
default: production
|
|
32777
|
-
}
|
|
32829
|
+
{}
|
|
32778
32830
|
).option("-c, --compact", "Output a compact import map", { default: false }).option("--stdout", "Output the import map to stdout", { default: false }).option(
|
|
32779
32831
|
"-o, --out <file>",
|
|
32780
32832
|
"File to inject the final import map into (default: --map / importmap.js). For JS files outputs an injection wrapper script, for JSON files, the import map only, and for HTML files embeds the import map.",
|
|
@@ -32982,7 +33034,7 @@ Start a server that uses importmap.json as the import map.
|
|
|
32982
33034
|
`
|
|
32983
33035
|
).example(
|
|
32984
33036
|
(name) => `
|
|
32985
|
-
$ ${name} serve --
|
|
33037
|
+
$ ${name} serve --static
|
|
32986
33038
|
|
|
32987
33039
|
Start a server that does not generate the import map on startup, perform type stripping or provide a hot reload watcher
|
|
32988
33040
|
`
|
|
@@ -33016,12 +33068,16 @@ the same options as the 'jspm install' command with no arguments.
|
|
|
33016
33068
|
`
|
|
33017
33069
|
).action(wrapCommand(serve));
|
|
33018
33070
|
generateOpts(
|
|
33019
|
-
|
|
33020
|
-
|
|
33021
|
-
|
|
33022
|
-
|
|
33023
|
-
|
|
33024
|
-
|
|
33071
|
+
outputOpts(
|
|
33072
|
+
cli.command("build", "Build package").option("--no-minify", "Disable build minification", {
|
|
33073
|
+
default: true
|
|
33074
|
+
}).option("-o, --out <dir>", "Path to the output directory for the build", {
|
|
33075
|
+
default: "dist"
|
|
33076
|
+
}).option("--install", "Generate import map after build completes", {
|
|
33077
|
+
default: true
|
|
33078
|
+
}),
|
|
33079
|
+
true
|
|
33080
|
+
)
|
|
33025
33081
|
).example(
|
|
33026
33082
|
(name) => `
|
|
33027
33083
|
$ ${name} build
|
|
@@ -33054,8 +33110,19 @@ Uses RollupJS under the hood to create optimized bundles.
|
|
|
33054
33110
|
|
|
33055
33111
|
The package entry points as defined in the package.json "exports" field are built, with the
|
|
33056
33112
|
entire package copied into the output directory. As such, it is a whole-package transformation.
|
|
33113
|
+
|
|
33114
|
+
Build externals are taken from the package.json "dependencies" to form a roughly configurationless
|
|
33115
|
+
build workflow (dependencies in "devDependencies" or otherwise are inlined into the build).
|
|
33116
|
+
|
|
33057
33117
|
Includes and ignores can be specified using the package.json "files" and "ignore" fields,
|
|
33058
33118
|
optionally using the JSPM overrides for these via the "jspm" property in the package.json.
|
|
33119
|
+
|
|
33120
|
+
Any build import map shoud be generated separately via a subsequent install operation on the
|
|
33121
|
+
build folder, for example like:
|
|
33122
|
+
|
|
33123
|
+
${c17.bold("jspm install -d dist -C production --flatten-scopes --combine-subpaths")}
|
|
33124
|
+
|
|
33125
|
+
to generate an optimized production map.
|
|
33059
33126
|
`
|
|
33060
33127
|
).action(wrapCommand(build));
|
|
33061
33128
|
outputOpts(
|
|
@@ -33078,8 +33145,7 @@ outputOpts(
|
|
|
33078
33145
|
{}
|
|
33079
33146
|
).option("--eject <package>", "Eject a published package instead of publishing", {}),
|
|
33080
33147
|
true
|
|
33081
|
-
)
|
|
33082
|
-
true
|
|
33148
|
+
)
|
|
33083
33149
|
).example(
|
|
33084
33150
|
(name) => `
|
|
33085
33151
|
$ ${name} publish
|