jiek 2.2.1 → 2.2.3-alpha.1
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-only-build.cjs +250 -145
- package/dist/cli-only-build.d.cts +11 -0
- package/dist/cli-only-build.d.ts +11 -0
- package/dist/cli-only-build.js +260 -155
- package/dist/cli.cjs +24 -20
- package/dist/cli.js +24 -20
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/rollup/index.cjs +80 -41
- package/dist/rollup/index.js +80 -41
- package/package.json +10 -6
- package/src/commands/build/analyzer.ts +122 -0
- package/src/commands/build/client/analyzer.tsx +121 -0
- package/src/commands/build/client/index.ts +28 -0
- package/src/commands/build.ts +29 -155
- package/src/commands/utils/optionParser.ts +4 -0
- package/src/rollup/base.ts +11 -0
- package/src/rollup/index.ts +54 -4
- package/src/server.ts +9 -1
- package/src/utils/checkDependency.ts +22 -0
- package/src/utils/getExports.ts +26 -16
- package/src/utils/ts.ts +3 -3
package/dist/cli-only-build.cjs
CHANGED
@@ -7,9 +7,10 @@ var commander = require('commander');
|
|
7
7
|
var jsYaml = require('js-yaml');
|
8
8
|
var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
|
9
9
|
var process$1 = require('node:process');
|
10
|
-
var prompts = require('@inquirer/prompts');
|
11
10
|
var cliProgress = require('cli-progress');
|
12
11
|
var execa = require('execa');
|
12
|
+
var node_child_process = require('node:child_process');
|
13
|
+
var prompts = require('@inquirer/prompts');
|
13
14
|
var Koa = require('koa');
|
14
15
|
|
15
16
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
@@ -22,8 +23,7 @@ var Koa__default = /*#__PURE__*/_interopDefault(Koa);
|
|
22
23
|
|
23
24
|
let root;
|
24
25
|
function getRoot() {
|
25
|
-
if (root)
|
26
|
-
return root;
|
26
|
+
if (root) return root;
|
27
27
|
const rootOption = process.env.JIEK_ROOT;
|
28
28
|
root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
|
29
29
|
return root;
|
@@ -32,8 +32,7 @@ function getRoot() {
|
|
32
32
|
let wd;
|
33
33
|
let notWorkspace$1 = false;
|
34
34
|
function getWD() {
|
35
|
-
if (wd)
|
36
|
-
return { wd, notWorkspace: notWorkspace$1 };
|
35
|
+
if (wd) return { wd, notWorkspace: notWorkspace$1 };
|
37
36
|
const root = getRoot();
|
38
37
|
if (root !== void 0) {
|
39
38
|
const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type$1);
|
@@ -120,7 +119,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
|
|
120
119
|
|
121
120
|
var name = "jiek";
|
122
121
|
var type = "module";
|
123
|
-
var version = "2.2.
|
122
|
+
var version = "2.2.3";
|
124
123
|
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
125
124
|
var author = "YiJie <yijie4188@gmail.com>";
|
126
125
|
var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
|
@@ -151,7 +150,11 @@ var exports$1 = {
|
|
151
150
|
"./rollup": "./src/rollup/index.ts"
|
152
151
|
};
|
153
152
|
var imports = {
|
154
|
-
"#~/*":
|
153
|
+
"#~/*": [
|
154
|
+
"./src/*",
|
155
|
+
"./src/*/index.ts",
|
156
|
+
"./src/*/index.tsx"
|
157
|
+
]
|
155
158
|
};
|
156
159
|
var bin = {
|
157
160
|
jiek: "bin/jiek.js",
|
@@ -174,7 +177,7 @@ var scripts = {
|
|
174
177
|
test: "vitest run"
|
175
178
|
};
|
176
179
|
var peerDependencies = {
|
177
|
-
"@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
|
180
|
+
"@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
|
178
181
|
"@rollup/plugin-terser": "^0.4.4",
|
179
182
|
"esbuild-register": "^3.5.0",
|
180
183
|
postcss: "^8.4.47",
|
@@ -182,7 +185,7 @@ var peerDependencies = {
|
|
182
185
|
"rollup-plugin-postcss": "^4.0.2",
|
183
186
|
"rollup-plugin-swc3": "^0.12.1",
|
184
187
|
typescript: "^4.0.0||^5.0.0",
|
185
|
-
"vite-bundle-analyzer": "
|
188
|
+
"vite-bundle-analyzer": "0.16.0-beta.1"
|
186
189
|
};
|
187
190
|
var dependencies = {
|
188
191
|
"@inquirer/prompts": "^7.1.0",
|
@@ -213,6 +216,7 @@ var devDependencies = {
|
|
213
216
|
"@types/js-yaml": "^4.0.9",
|
214
217
|
"@types/koa": "^2.15.0",
|
215
218
|
"@types/micromatch": "^4.0.6",
|
219
|
+
"@types/react": "^18.3.14",
|
216
220
|
"esbuild-register": "^3.5.0",
|
217
221
|
micromatch: "^4.0.5",
|
218
222
|
"node-sass": "^9.0.0",
|
@@ -220,7 +224,7 @@ var devDependencies = {
|
|
220
224
|
"rollup-plugin-esbuild": "^6.1.0",
|
221
225
|
"rollup-plugin-postcss": "^4.0.2",
|
222
226
|
"rollup-plugin-swc3": "^0.12.1",
|
223
|
-
"vite-bundle-analyzer": "
|
227
|
+
"vite-bundle-analyzer": "0.16.0-beta.1"
|
224
228
|
};
|
225
229
|
var pkg = {
|
226
230
|
name: name,
|
@@ -266,6 +270,208 @@ if (type$1 !== "" && IS_WORKSPACE) {
|
|
266
270
|
commander.program.option("-f, --filter <filter>", filterDescription);
|
267
271
|
}
|
268
272
|
|
273
|
+
function Main() {
|
274
|
+
const { useState, useMemo, useEffect, useCallback } = React;
|
275
|
+
const [path, setPath] = useState(() => location.pathname.replace(/^\/ana\/?/, ""));
|
276
|
+
const [pkgName, entry] = useMemo(() => {
|
277
|
+
const pkgName2 = /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(path)?.[1];
|
278
|
+
return [
|
279
|
+
pkgName2,
|
280
|
+
pkgName2 != null ? path.replace(`${pkgName2}/`, "") : void 0
|
281
|
+
];
|
282
|
+
}, [path]);
|
283
|
+
const push = useCallback((newPath) => {
|
284
|
+
setPath(newPath);
|
285
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${newPath}`;
|
286
|
+
history.pushState(null, "", `/ana/${newPath}`);
|
287
|
+
}, []);
|
288
|
+
const filterModules = useCallback((startWith) => {
|
289
|
+
const modules = analyzeModule.filter((m) => m.filename.startsWith(startWith));
|
290
|
+
dispatchEvent(new CustomEvent("send:filter", { detail: { analyzeModule: modules } }));
|
291
|
+
}, []);
|
292
|
+
useEffect(() => {
|
293
|
+
if (path !== "") {
|
294
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${path}`;
|
295
|
+
} else {
|
296
|
+
document.title = document.title.replace(/ - \/.*/, "");
|
297
|
+
}
|
298
|
+
filterModules(path);
|
299
|
+
}, [path, filterModules]);
|
300
|
+
useEffect(() => {
|
301
|
+
const offGraphClick = listen("graph:click", ({ detail }) => {
|
302
|
+
if (!detail) return;
|
303
|
+
let root = detail.node;
|
304
|
+
while (root.parent) {
|
305
|
+
root = root.parent;
|
306
|
+
}
|
307
|
+
if (root.filename === path) return;
|
308
|
+
push(root.filename);
|
309
|
+
});
|
310
|
+
return () => {
|
311
|
+
offGraphClick();
|
312
|
+
};
|
313
|
+
}, [push]);
|
314
|
+
function listen(type, listener) {
|
315
|
+
window.addEventListener(type, listener);
|
316
|
+
return () => {
|
317
|
+
window.removeEventListener(type, listener);
|
318
|
+
};
|
319
|
+
}
|
320
|
+
return /* @__PURE__ */ React.createElement(
|
321
|
+
"div",
|
322
|
+
{
|
323
|
+
style: {
|
324
|
+
padding: "12px 55px"
|
325
|
+
}
|
326
|
+
},
|
327
|
+
"/",
|
328
|
+
/* @__PURE__ */ React.createElement(
|
329
|
+
"select",
|
330
|
+
{
|
331
|
+
style: {
|
332
|
+
appearance: "none",
|
333
|
+
border: "none",
|
334
|
+
background: "none"
|
335
|
+
},
|
336
|
+
value: pkgName,
|
337
|
+
onChange: (e) => push(e.target.value)
|
338
|
+
},
|
339
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
340
|
+
analyzeModule.map((m) => /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(m.filename)?.[1]).filter((v, i, a) => a.indexOf(v) === i).map((v) => /* @__PURE__ */ React.createElement("option", { key: v, value: v }, v))
|
341
|
+
),
|
342
|
+
pkgName != null && /* @__PURE__ */ React.createElement(React.Fragment, null, "/", /* @__PURE__ */ React.createElement(
|
343
|
+
"select",
|
344
|
+
{
|
345
|
+
style: {
|
346
|
+
appearance: "none",
|
347
|
+
border: "none",
|
348
|
+
background: "none"
|
349
|
+
},
|
350
|
+
value: entry,
|
351
|
+
onChange: (e) => push(`${pkgName}/${e.target.value}`)
|
352
|
+
},
|
353
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
354
|
+
analyzeModule.filter((m) => m.filename.startsWith(`${pkgName}/`)).map((m) => m.filename.replace(`${pkgName}/`, "")).filter((v, i, a) => a.indexOf(v) === i).map((v) => /* @__PURE__ */ React.createElement("option", { key: v, value: v }, v))
|
355
|
+
))
|
356
|
+
);
|
357
|
+
}
|
358
|
+
|
359
|
+
function render() {
|
360
|
+
CUSTOM_SIDE_BAR = true;
|
361
|
+
window.addEventListener("client:ready", () => setTimeout(() => {
|
362
|
+
window.dispatchEvent(
|
363
|
+
new CustomEvent("send:ui", {
|
364
|
+
detail: { type: "Main", Component: __REPLACE_INJECT__ }
|
365
|
+
})
|
366
|
+
);
|
367
|
+
}, 0));
|
368
|
+
}
|
369
|
+
const CLIENT_CUSTOM_RENDER_SCRIPT = [
|
370
|
+
Main.toString(),
|
371
|
+
render.toString().replace("__REPLACE_INJECT__", Main.name),
|
372
|
+
`(${render.name})()`
|
373
|
+
].join("\n");
|
374
|
+
|
375
|
+
function parseBoolean(v) {
|
376
|
+
if (v === void 0) return true;
|
377
|
+
return Boolean(v);
|
378
|
+
}
|
379
|
+
|
380
|
+
async function checkDependency(dependency) {
|
381
|
+
try {
|
382
|
+
require.resolve(dependency);
|
383
|
+
} catch {
|
384
|
+
console.error(`The package '${dependency}' is not installed, please install it first.`);
|
385
|
+
const { notWorkspace } = getWD();
|
386
|
+
const command = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
|
387
|
+
if (await prompts.confirm({ message: "Do you want to install it now?" })) {
|
388
|
+
node_child_process.spawnSync(command);
|
389
|
+
} else {
|
390
|
+
console.warn(`You can run the command '${command}' to install it manually.`);
|
391
|
+
process__default.default.exit(1);
|
392
|
+
}
|
393
|
+
}
|
394
|
+
}
|
395
|
+
|
396
|
+
const registerAnalyzerCommandOptions = (command) => command.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option(
|
397
|
+
"--ana.mode <MODE>",
|
398
|
+
'The mode of the bundle analyzer, support "static", "json" and "server".',
|
399
|
+
"server"
|
400
|
+
).option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
|
401
|
+
"--ana.size <SIZE>",
|
402
|
+
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
403
|
+
"parsed"
|
404
|
+
);
|
405
|
+
const useAnalyzer = async (options, server) => {
|
406
|
+
const modules = [];
|
407
|
+
let bundleAnalyzerModule;
|
408
|
+
const analyzer = options.ana ? {
|
409
|
+
dir: options["ana.dir"],
|
410
|
+
mode: options["ana.mode"],
|
411
|
+
open: options["ana.open"],
|
412
|
+
size: options["ana.size"]
|
413
|
+
} : void 0;
|
414
|
+
if (options.ana && ![
|
415
|
+
"stat",
|
416
|
+
"parsed",
|
417
|
+
"gzip"
|
418
|
+
].includes(analyzer?.size ?? "")) {
|
419
|
+
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
420
|
+
}
|
421
|
+
if (analyzer) {
|
422
|
+
await checkDependency("vite-bundle-analyzer");
|
423
|
+
bundleAnalyzerModule = await import('vite-bundle-analyzer');
|
424
|
+
}
|
425
|
+
const refreshAnalyzer = async (cwd, applyModules) => {
|
426
|
+
if (!(analyzer && server && bundleAnalyzerModule)) return;
|
427
|
+
if (analyzer.mode === "json") {
|
428
|
+
const anaDir = path__default.default.resolve(cwd, analyzer.dir);
|
429
|
+
if (!fs.existsSync(anaDir)) {
|
430
|
+
fs.mkdirSync(anaDir, { recursive: true });
|
431
|
+
}
|
432
|
+
const gitIgnorePath = path__default.default.resolve(anaDir, ".gitignore");
|
433
|
+
if (!fs.existsSync(gitIgnorePath)) {
|
434
|
+
fs.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
435
|
+
}
|
436
|
+
const npmIgnorePath = path__default.default.resolve(anaDir, ".npmignore");
|
437
|
+
if (!fs.existsSync(npmIgnorePath)) {
|
438
|
+
fs.writeFileSync(npmIgnorePath, "*\n");
|
439
|
+
}
|
440
|
+
if (!fs.statSync(anaDir).isDirectory()) {
|
441
|
+
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
442
|
+
}
|
443
|
+
}
|
444
|
+
const { renderView, injectHTMLTag } = bundleAnalyzerModule;
|
445
|
+
applyModules.forEach((m) => {
|
446
|
+
const index = modules.findIndex(({ filename }) => filename === m.filename);
|
447
|
+
if (index === -1) {
|
448
|
+
modules.push(m);
|
449
|
+
} else {
|
450
|
+
modules[index] = m;
|
451
|
+
}
|
452
|
+
});
|
453
|
+
let html = await renderView(modules, {
|
454
|
+
title: `Jiek Analyzer`,
|
455
|
+
mode: analyzer.size
|
456
|
+
});
|
457
|
+
html = injectHTMLTag({
|
458
|
+
html,
|
459
|
+
injectTo: "body",
|
460
|
+
descriptors: [
|
461
|
+
{ kind: "script", text: CLIENT_CUSTOM_RENDER_SCRIPT }
|
462
|
+
]
|
463
|
+
});
|
464
|
+
void server.renderTo("/ana", html);
|
465
|
+
};
|
466
|
+
return {
|
467
|
+
modules,
|
468
|
+
refreshAnalyzer,
|
469
|
+
ANALYZER_ENV: {
|
470
|
+
JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : void 0
|
471
|
+
}
|
472
|
+
};
|
473
|
+
};
|
474
|
+
|
269
475
|
const BUILDER_TYPES = ["esbuild", "swc"];
|
270
476
|
const BUILDER_TYPE_PACKAGE_NAME_MAP = {
|
271
477
|
esbuild: "rollup-plugin-esbuild",
|
@@ -277,7 +483,11 @@ const createServer = (port, host) => {
|
|
277
483
|
app.listen(port, host);
|
278
484
|
const streams = /* @__PURE__ */ new Map();
|
279
485
|
app.use(async (ctx) => {
|
280
|
-
|
486
|
+
let stream = streams.get(ctx.path);
|
487
|
+
if (stream == null) {
|
488
|
+
const maybeKey = streams.keys().find((p) => ctx.path.startsWith(p));
|
489
|
+
stream = maybeKey != null ? streams.get(maybeKey) : void 0;
|
490
|
+
}
|
281
491
|
if (stream != null) {
|
282
492
|
ctx.body = stream;
|
283
493
|
}
|
@@ -390,8 +600,7 @@ function loadConfig(dirOrOptions) {
|
|
390
600
|
default:
|
391
601
|
throw new Error(`unsupported config file type: ${ext}`);
|
392
602
|
}
|
393
|
-
if (!module)
|
394
|
-
throw new Error("config file is empty");
|
603
|
+
if (!module) throw new Error("config file is empty");
|
395
604
|
return module.default ?? module;
|
396
605
|
}
|
397
606
|
|
@@ -405,21 +614,6 @@ Build the package according to the 'exports' field from the package.json.
|
|
405
614
|
If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
|
406
615
|
${isDefault ? "This command is the default command." : ""}
|
407
616
|
`.trim();
|
408
|
-
async function checkDependency(dependency) {
|
409
|
-
try {
|
410
|
-
require$1.resolve(dependency);
|
411
|
-
} catch {
|
412
|
-
console.error(`The package '${dependency}' is not installed, please install it first.`);
|
413
|
-
const { notWorkspace } = getWD();
|
414
|
-
const command2 = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
|
415
|
-
if (await prompts.confirm({ message: "Do you want to install it now?" })) {
|
416
|
-
await execa.execaCommand(command2);
|
417
|
-
} else {
|
418
|
-
console.warn(`You can run the command '${command2}' to install it manually.`);
|
419
|
-
process__default.default.exit(1);
|
420
|
-
}
|
421
|
-
}
|
422
|
-
}
|
423
617
|
let DEFAULT_BUILDER_TYPE;
|
424
618
|
Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
425
619
|
try {
|
@@ -431,11 +625,6 @@ Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
|
431
625
|
if (!DEFAULT_BUILDER_TYPE) {
|
432
626
|
DEFAULT_BUILDER_TYPE = "esbuild";
|
433
627
|
}
|
434
|
-
function parseBoolean(v) {
|
435
|
-
if (v === void 0)
|
436
|
-
return true;
|
437
|
-
return Boolean(v);
|
438
|
-
}
|
439
628
|
const buildFilterDescription = `
|
440
629
|
${filterDescription}
|
441
630
|
If you pass the --filter option, it will merge into the filters of the command.
|
@@ -474,11 +663,7 @@ command = command.description(description).option("-t, --type <TYPE>", `The type
|
|
474
663
|
);
|
475
664
|
command = command.option("--tsconfig <TSCONFIG>", "The path of the tsconfig file which is used to generate js and dts files.", String).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String);
|
476
665
|
command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
|
477
|
-
command = command
|
478
|
-
"--ana.size <SIZE>",
|
479
|
-
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
480
|
-
"parsed"
|
481
|
-
);
|
666
|
+
command = registerAnalyzerCommandOptions(command);
|
482
667
|
command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
|
483
668
|
command.action(async (commandFiltersOrEntries, options) => {
|
484
669
|
let {
|
@@ -526,43 +711,14 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
526
711
|
},
|
527
712
|
[]
|
528
713
|
);
|
529
|
-
const
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
const
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
size: options["ana.size"]
|
538
|
-
} : void 0;
|
539
|
-
if (options.ana && ![
|
540
|
-
"stat",
|
541
|
-
"parsed",
|
542
|
-
"gzip"
|
543
|
-
].includes(analyzer?.size ?? "")) {
|
544
|
-
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
545
|
-
}
|
546
|
-
const server = analyzer && createServer(options.port, "localhost");
|
547
|
-
if (analyzer) {
|
548
|
-
await checkDependency("vite-bundle-analyzer");
|
549
|
-
const { renderView } = await import('vite-bundle-analyzer');
|
550
|
-
render = renderView;
|
551
|
-
}
|
552
|
-
const anaPaths = /* @__PURE__ */ new Set();
|
553
|
-
const refreshAnalyzer = async (subPath = "", renderModules = modules) => {
|
554
|
-
if (!(analyzer && server && render))
|
555
|
-
return;
|
556
|
-
const p = `/ana${subPath}`;
|
557
|
-
anaPaths.add(p);
|
558
|
-
void server.renderTo(
|
559
|
-
p,
|
560
|
-
await render(renderModules, {
|
561
|
-
title: `Jiek Analyzer - ${subPath}`,
|
562
|
-
mode: analyzer.size
|
563
|
-
})
|
564
|
-
);
|
565
|
-
};
|
714
|
+
const shouldCreateServer = [
|
715
|
+
options.ana === true && options["ana.mode"] === "server"
|
716
|
+
].some(Boolean);
|
717
|
+
const server = shouldCreateServer ? createServer(options.port, "localhost") : void 0;
|
718
|
+
const {
|
719
|
+
ANALYZER_ENV,
|
720
|
+
refreshAnalyzer
|
721
|
+
} = await useAnalyzer(options, server);
|
566
722
|
const { build } = loadConfig();
|
567
723
|
silent = silent ?? build?.silent ?? false;
|
568
724
|
if (withoutMin && onlyMin) {
|
@@ -579,7 +735,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
579
735
|
entries = void 0;
|
580
736
|
}
|
581
737
|
const env = {
|
582
|
-
|
738
|
+
...ANALYZER_ENV,
|
583
739
|
JIEK_BUILDER: type,
|
584
740
|
JIEK_OUT_DIR: outdir,
|
585
741
|
JIEK_CLEAN: String(!noClean),
|
@@ -621,27 +777,10 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
621
777
|
const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
622
778
|
let i = 0;
|
623
779
|
await Promise.all(
|
624
|
-
Object.entries(value).map(async ([
|
780
|
+
Object.entries(value).map(async ([pkgCWD, manifest]) => {
|
625
781
|
if (manifest.name == null) {
|
626
782
|
throw new Error("package.json must have a name field");
|
627
783
|
}
|
628
|
-
if (analyzer) {
|
629
|
-
const anaDir = path__default.default.resolve(dir, analyzer.dir);
|
630
|
-
if (!fs.existsSync(anaDir)) {
|
631
|
-
fs.mkdirSync(anaDir, { recursive: true });
|
632
|
-
}
|
633
|
-
const gitIgnorePath = path__default.default.resolve(anaDir, ".gitignore");
|
634
|
-
if (!fs.existsSync(gitIgnorePath)) {
|
635
|
-
fs.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
636
|
-
}
|
637
|
-
const npmIgnorePath = path__default.default.resolve(anaDir, ".npmignore");
|
638
|
-
if (!fs.existsSync(npmIgnorePath)) {
|
639
|
-
fs.writeFileSync(npmIgnorePath, "*\n");
|
640
|
-
}
|
641
|
-
if (!fs.statSync(anaDir).isDirectory()) {
|
642
|
-
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
643
|
-
}
|
644
|
-
}
|
645
784
|
const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
|
646
785
|
const configFile = resolveByJiekTemp(
|
647
786
|
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
@@ -657,7 +796,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
657
796
|
command2.push(...passThroughOptions);
|
658
797
|
const child = execa.execaCommand(command2.join(" "), {
|
659
798
|
ipc: true,
|
660
|
-
cwd:
|
799
|
+
cwd: pkgCWD,
|
661
800
|
env: {
|
662
801
|
...env,
|
663
802
|
JIEK_NAME: manifest.name,
|
@@ -673,8 +812,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
673
812
|
"init",
|
674
813
|
"progress",
|
675
814
|
"watchChange"
|
676
|
-
].includes(e.type))
|
677
|
-
return;
|
815
|
+
].includes(e.type)) return;
|
678
816
|
switch (e.type) {
|
679
817
|
case "init": {
|
680
818
|
const { leafMap, targetsLength } = e.data;
|
@@ -695,8 +833,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
695
833
|
});
|
696
834
|
leafs.forEach(({ input, path: path2 }) => {
|
697
835
|
const key = `${input}:${path2}`;
|
698
|
-
if (bars[key])
|
699
|
-
return;
|
836
|
+
if (bars[key]) return;
|
700
837
|
bars[key] = multiBars.create(50, 0, {
|
701
838
|
pkgName: manifest.name,
|
702
839
|
input: input.padEnd(inputMaxLen + 5),
|
@@ -717,8 +854,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
717
854
|
message
|
718
855
|
} = e.data;
|
719
856
|
const bar = bars[`${input}:${path2}`];
|
720
|
-
if (!bar)
|
721
|
-
return;
|
857
|
+
if (!bar) return;
|
722
858
|
const time = times[`${input}:${path2}`];
|
723
859
|
bar.update(
|
724
860
|
{
|
@@ -741,8 +877,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
741
877
|
} = e.data;
|
742
878
|
const key = `${input}:${path2}`;
|
743
879
|
const bar = bars[key];
|
744
|
-
if (!bar)
|
745
|
-
return;
|
880
|
+
if (!bar) return;
|
746
881
|
let time = times[key] ?? 1;
|
747
882
|
if (!locks[key]) {
|
748
883
|
time += 1;
|
@@ -763,41 +898,18 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
763
898
|
const {
|
764
899
|
data: {
|
765
900
|
type: type2,
|
766
|
-
path: path2,
|
767
901
|
modules: pkgModules
|
768
902
|
}
|
769
903
|
} = e;
|
770
|
-
|
771
|
-
|
904
|
+
void refreshAnalyzer(
|
905
|
+
pkgCWD,
|
906
|
+
pkgModules.map((m) => ({
|
772
907
|
...m,
|
908
|
+
type: type2,
|
773
909
|
filename: `${manifest.name}/${m.filename}`,
|
774
910
|
label: `${manifest.name}/${m.label}`
|
775
|
-
}
|
776
|
-
const pushOrReplace = (arr) => {
|
777
|
-
const index = arr.findIndex(({ filename }) => filename === newM.filename);
|
778
|
-
if (index === -1) {
|
779
|
-
arr.push(newM);
|
780
|
-
} else {
|
781
|
-
arr[index] = newM;
|
782
|
-
}
|
783
|
-
};
|
784
|
-
pushOrReplace(modules);
|
785
|
-
if (type2 === "esm") {
|
786
|
-
pushOrReplace(esmModules);
|
787
|
-
}
|
788
|
-
if (type2 === "cjs") {
|
789
|
-
pushOrReplace(cjsModules);
|
790
|
-
}
|
791
|
-
});
|
792
|
-
void refreshAnalyzer();
|
793
|
-
void refreshAnalyzer(
|
794
|
-
`/${type2}`,
|
795
|
-
{
|
796
|
-
cjs: cjsModules,
|
797
|
-
esm: esmModules
|
798
|
-
}[type2]
|
911
|
+
}))
|
799
912
|
);
|
800
|
-
void refreshAnalyzer(`/${type2}/${manifest.name}/${path2.slice(2)}`, pkgModules);
|
801
913
|
break;
|
802
914
|
}
|
803
915
|
case "debug": {
|
@@ -807,12 +919,15 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
807
919
|
}
|
808
920
|
});
|
809
921
|
await new Promise((resolve, reject) => {
|
810
|
-
let errorStr =
|
922
|
+
let errorStr = `rollup build failed
|
923
|
+
package name: ${manifest.name}
|
924
|
+
cwd: ${pkgCWD}
|
925
|
+
|
926
|
+
`;
|
811
927
|
child.stderr?.on("data", (data) => {
|
812
928
|
errorStr += data;
|
813
929
|
});
|
814
|
-
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(
|
815
|
-
${errorStr}`)));
|
930
|
+
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
|
816
931
|
verbose && child.stdout?.pipe(process__default.default.stdout);
|
817
932
|
});
|
818
933
|
})
|
@@ -834,17 +949,7 @@ ${errorStr}`)));
|
|
834
949
|
}
|
835
950
|
} finally {
|
836
951
|
multiBars.stop();
|
837
|
-
|
838
|
-
if (analyzer) {
|
839
|
-
message += ` and the analyzer is running at http://localhost:${options.port}/ana in ${analyzer.mode} mode.
|
840
|
-
`;
|
841
|
-
message += analyzer.open ? " The browser will open automatically.\n" : "";
|
842
|
-
if (anaPaths.size > 0) {
|
843
|
-
message += `The analyzer has ${anaPaths.size} pages:
|
844
|
-
${Array.from(anaPaths).map((p) => `http://localhost:${options.port}${p}`).join("\n")}`;
|
845
|
-
}
|
846
|
-
}
|
847
|
-
!silent && console.log(message);
|
952
|
+
!silent && console.log("Build complete");
|
848
953
|
}
|
849
954
|
});
|
850
955
|
|
@@ -40,6 +40,17 @@ interface TemplateOptions {
|
|
40
40
|
} & rollup_plugin_esbuild.Options) | ({
|
41
41
|
type: 'swc';
|
42
42
|
} & rollup_plugin_swc3.PluginOptions);
|
43
|
+
features?: {
|
44
|
+
/**
|
45
|
+
* When use esbuild type builder, it will inject `supported.import-attributes` option.
|
46
|
+
* When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
|
47
|
+
*
|
48
|
+
* And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
|
49
|
+
*
|
50
|
+
* @default true
|
51
|
+
*/
|
52
|
+
keepImportAttributes?: boolean | 'assert';
|
53
|
+
};
|
43
54
|
output?: {
|
44
55
|
/**
|
45
56
|
* @default true
|
package/dist/cli-only-build.d.ts
CHANGED
@@ -40,6 +40,17 @@ interface TemplateOptions {
|
|
40
40
|
} & rollup_plugin_esbuild.Options) | ({
|
41
41
|
type: 'swc';
|
42
42
|
} & rollup_plugin_swc3.PluginOptions);
|
43
|
+
features?: {
|
44
|
+
/**
|
45
|
+
* When use esbuild type builder, it will inject `supported.import-attributes` option.
|
46
|
+
* When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
|
47
|
+
*
|
48
|
+
* And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
|
49
|
+
*
|
50
|
+
* @default true
|
51
|
+
*/
|
52
|
+
keepImportAttributes?: boolean | 'assert';
|
53
|
+
};
|
43
54
|
output?: {
|
44
55
|
/**
|
45
56
|
* @default true
|