jiek 2.2.1 → 2.2.3
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 +242 -141
- package/dist/cli-only-build.d.cts +11 -0
- package/dist/cli-only-build.d.ts +11 -0
- package/dist/cli-only-build.js +252 -151
- package/dist/cli.cjs +6 -12
- package/dist/cli.js +6 -12
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/rollup/index.cjs +54 -35
- package/dist/rollup/index.js +54 -35
- package/package.json +9 -5
- 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 +25 -153
- package/src/commands/utils/optionParser.ts +4 -0
- package/src/rollup/base.ts +11 -0
- package/src/rollup/index.ts +44 -4
- package/src/server.ts +9 -1
- package/src/utils/checkDependency.ts +22 -0
- package/src/utils/ts.ts +3 -3
package/dist/cli-only-build.js
CHANGED
@@ -5,15 +5,14 @@ import { program } from 'commander';
|
|
5
5
|
import { load } from 'js-yaml';
|
6
6
|
import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
|
7
7
|
import process$1 from 'node:process';
|
8
|
-
import { confirm } from '@inquirer/prompts';
|
9
8
|
import { MultiBar, Presets } from 'cli-progress';
|
10
9
|
import { execaCommand } from 'execa';
|
10
|
+
import { confirm } from '@inquirer/prompts';
|
11
11
|
import Koa from 'koa';
|
12
12
|
|
13
13
|
let root;
|
14
14
|
function getRoot() {
|
15
|
-
if (root)
|
16
|
-
return root;
|
15
|
+
if (root) return root;
|
17
16
|
const rootOption = process.env.JIEK_ROOT;
|
18
17
|
root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
|
19
18
|
return root;
|
@@ -22,8 +21,7 @@ function getRoot() {
|
|
22
21
|
let wd;
|
23
22
|
let notWorkspace$1 = false;
|
24
23
|
function getWD() {
|
25
|
-
if (wd)
|
26
|
-
return { wd, notWorkspace: notWorkspace$1 };
|
24
|
+
if (wd) return { wd, notWorkspace: notWorkspace$1 };
|
27
25
|
const root = getRoot();
|
28
26
|
if (root !== void 0) {
|
29
27
|
const isWorkspace = isWorkspaceDir(root, type$1);
|
@@ -110,7 +108,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
|
|
110
108
|
|
111
109
|
var name = "jiek";
|
112
110
|
var type = "module";
|
113
|
-
var version = "2.2.
|
111
|
+
var version = "2.2.2";
|
114
112
|
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
115
113
|
var author = "YiJie <yijie4188@gmail.com>";
|
116
114
|
var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
|
@@ -141,7 +139,11 @@ var exports = {
|
|
141
139
|
"./rollup": "./src/rollup/index.ts"
|
142
140
|
};
|
143
141
|
var imports = {
|
144
|
-
"#~/*":
|
142
|
+
"#~/*": [
|
143
|
+
"./src/*",
|
144
|
+
"./src/*/index.ts",
|
145
|
+
"./src/*/index.tsx"
|
146
|
+
]
|
145
147
|
};
|
146
148
|
var bin = {
|
147
149
|
jiek: "bin/jiek.js",
|
@@ -172,7 +174,7 @@ var peerDependencies = {
|
|
172
174
|
"rollup-plugin-postcss": "^4.0.2",
|
173
175
|
"rollup-plugin-swc3": "^0.12.1",
|
174
176
|
typescript: "^4.0.0||^5.0.0",
|
175
|
-
"vite-bundle-analyzer": "
|
177
|
+
"vite-bundle-analyzer": "0.16.0-beta.1"
|
176
178
|
};
|
177
179
|
var dependencies = {
|
178
180
|
"@inquirer/prompts": "^7.1.0",
|
@@ -203,6 +205,7 @@ var devDependencies = {
|
|
203
205
|
"@types/js-yaml": "^4.0.9",
|
204
206
|
"@types/koa": "^2.15.0",
|
205
207
|
"@types/micromatch": "^4.0.6",
|
208
|
+
"@types/react": "^18.3.14",
|
206
209
|
"esbuild-register": "^3.5.0",
|
207
210
|
micromatch: "^4.0.5",
|
208
211
|
"node-sass": "^9.0.0",
|
@@ -210,7 +213,7 @@ var devDependencies = {
|
|
210
213
|
"rollup-plugin-esbuild": "^6.1.0",
|
211
214
|
"rollup-plugin-postcss": "^4.0.2",
|
212
215
|
"rollup-plugin-swc3": "^0.12.1",
|
213
|
-
"vite-bundle-analyzer": "
|
216
|
+
"vite-bundle-analyzer": "0.16.0-beta.1"
|
214
217
|
};
|
215
218
|
var pkg = {
|
216
219
|
name: name,
|
@@ -256,6 +259,208 @@ if (type$1 !== "" && IS_WORKSPACE) {
|
|
256
259
|
program.option("-f, --filter <filter>", filterDescription);
|
257
260
|
}
|
258
261
|
|
262
|
+
function Main() {
|
263
|
+
const { useState, useMemo, useEffect, useCallback } = React;
|
264
|
+
const [path, setPath] = useState(() => location.pathname.replace(/^\/ana\/?/, ""));
|
265
|
+
const [pkgName, entry] = useMemo(() => {
|
266
|
+
const pkgName2 = /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(path)?.[1];
|
267
|
+
return [
|
268
|
+
pkgName2,
|
269
|
+
pkgName2 != null ? path.replace(`${pkgName2}/`, "") : void 0
|
270
|
+
];
|
271
|
+
}, [path]);
|
272
|
+
const push = useCallback((newPath) => {
|
273
|
+
setPath(newPath);
|
274
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${newPath}`;
|
275
|
+
history.pushState(null, "", `/ana/${newPath}`);
|
276
|
+
}, []);
|
277
|
+
const filterModules = useCallback((startWith) => {
|
278
|
+
const modules = analyzeModule.filter((m) => m.filename.startsWith(startWith));
|
279
|
+
dispatchEvent(new CustomEvent("send:filter", { detail: { analyzeModule: modules } }));
|
280
|
+
}, []);
|
281
|
+
useEffect(() => {
|
282
|
+
if (path !== "") {
|
283
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${path}`;
|
284
|
+
} else {
|
285
|
+
document.title = document.title.replace(/ - \/.*/, "");
|
286
|
+
}
|
287
|
+
filterModules(path);
|
288
|
+
}, [path, filterModules]);
|
289
|
+
useEffect(() => {
|
290
|
+
const offGraphClick = listen("graph:click", ({ detail }) => {
|
291
|
+
if (!detail) return;
|
292
|
+
let root = detail.node;
|
293
|
+
while (root.parent) {
|
294
|
+
root = root.parent;
|
295
|
+
}
|
296
|
+
if (root.filename === path) return;
|
297
|
+
push(root.filename);
|
298
|
+
});
|
299
|
+
return () => {
|
300
|
+
offGraphClick();
|
301
|
+
};
|
302
|
+
}, [push]);
|
303
|
+
function listen(type, listener) {
|
304
|
+
window.addEventListener(type, listener);
|
305
|
+
return () => {
|
306
|
+
window.removeEventListener(type, listener);
|
307
|
+
};
|
308
|
+
}
|
309
|
+
return /* @__PURE__ */ React.createElement(
|
310
|
+
"div",
|
311
|
+
{
|
312
|
+
style: {
|
313
|
+
padding: "12px 55px"
|
314
|
+
}
|
315
|
+
},
|
316
|
+
"/",
|
317
|
+
/* @__PURE__ */ React.createElement(
|
318
|
+
"select",
|
319
|
+
{
|
320
|
+
style: {
|
321
|
+
appearance: "none",
|
322
|
+
border: "none",
|
323
|
+
background: "none"
|
324
|
+
},
|
325
|
+
value: pkgName,
|
326
|
+
onChange: (e) => push(e.target.value)
|
327
|
+
},
|
328
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
329
|
+
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))
|
330
|
+
),
|
331
|
+
pkgName != null && /* @__PURE__ */ React.createElement(React.Fragment, null, "/", /* @__PURE__ */ React.createElement(
|
332
|
+
"select",
|
333
|
+
{
|
334
|
+
style: {
|
335
|
+
appearance: "none",
|
336
|
+
border: "none",
|
337
|
+
background: "none"
|
338
|
+
},
|
339
|
+
value: entry,
|
340
|
+
onChange: (e) => push(`${pkgName}/${e.target.value}`)
|
341
|
+
},
|
342
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
343
|
+
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))
|
344
|
+
))
|
345
|
+
);
|
346
|
+
}
|
347
|
+
|
348
|
+
function render() {
|
349
|
+
CUSTOM_SIDE_BAR = true;
|
350
|
+
window.addEventListener("client:ready", () => setTimeout(() => {
|
351
|
+
window.dispatchEvent(
|
352
|
+
new CustomEvent("send:ui", {
|
353
|
+
detail: { type: "Main", Component: __REPLACE_INJECT__ }
|
354
|
+
})
|
355
|
+
);
|
356
|
+
}, 0));
|
357
|
+
}
|
358
|
+
const CLIENT_CUSTOM_RENDER_SCRIPT = [
|
359
|
+
Main.toString(),
|
360
|
+
render.toString().replace("__REPLACE_INJECT__", Main.name),
|
361
|
+
`(${render.name})()`
|
362
|
+
].join("\n");
|
363
|
+
|
364
|
+
function parseBoolean(v) {
|
365
|
+
if (v === void 0) return true;
|
366
|
+
return Boolean(v);
|
367
|
+
}
|
368
|
+
|
369
|
+
async function checkDependency(dependency) {
|
370
|
+
try {
|
371
|
+
require.resolve(dependency);
|
372
|
+
} catch {
|
373
|
+
console.error(`The package '${dependency}' is not installed, please install it first.`);
|
374
|
+
const { notWorkspace } = getWD();
|
375
|
+
const command = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
|
376
|
+
if (await confirm({ message: "Do you want to install it now?" })) {
|
377
|
+
await execaCommand(command);
|
378
|
+
} else {
|
379
|
+
console.warn(`You can run the command '${command}' to install it manually.`);
|
380
|
+
process$1.exit(1);
|
381
|
+
}
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
const registerAnalyzerCommandOptions = (command) => command.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option(
|
386
|
+
"--ana.mode <MODE>",
|
387
|
+
'The mode of the bundle analyzer, support "static", "json" and "server".',
|
388
|
+
"server"
|
389
|
+
).option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
|
390
|
+
"--ana.size <SIZE>",
|
391
|
+
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
392
|
+
"parsed"
|
393
|
+
);
|
394
|
+
const useAnalyzer = async (options, server) => {
|
395
|
+
const modules = [];
|
396
|
+
let bundleAnalyzerModule;
|
397
|
+
const analyzer = options.ana ? {
|
398
|
+
dir: options["ana.dir"],
|
399
|
+
mode: options["ana.mode"],
|
400
|
+
open: options["ana.open"],
|
401
|
+
size: options["ana.size"]
|
402
|
+
} : void 0;
|
403
|
+
if (options.ana && ![
|
404
|
+
"stat",
|
405
|
+
"parsed",
|
406
|
+
"gzip"
|
407
|
+
].includes(analyzer?.size ?? "")) {
|
408
|
+
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
409
|
+
}
|
410
|
+
if (analyzer) {
|
411
|
+
await checkDependency("vite-bundle-analyzer");
|
412
|
+
bundleAnalyzerModule = await import('vite-bundle-analyzer');
|
413
|
+
}
|
414
|
+
const refreshAnalyzer = async (cwd, applyModules) => {
|
415
|
+
if (!(analyzer && server && bundleAnalyzerModule)) return;
|
416
|
+
if (analyzer.mode === "json") {
|
417
|
+
const anaDir = path.resolve(cwd, analyzer.dir);
|
418
|
+
if (!existsSync(anaDir)) {
|
419
|
+
mkdirSync(anaDir, { recursive: true });
|
420
|
+
}
|
421
|
+
const gitIgnorePath = path.resolve(anaDir, ".gitignore");
|
422
|
+
if (!existsSync(gitIgnorePath)) {
|
423
|
+
writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
424
|
+
}
|
425
|
+
const npmIgnorePath = path.resolve(anaDir, ".npmignore");
|
426
|
+
if (!existsSync(npmIgnorePath)) {
|
427
|
+
writeFileSync(npmIgnorePath, "*\n");
|
428
|
+
}
|
429
|
+
if (!statSync(anaDir).isDirectory()) {
|
430
|
+
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
431
|
+
}
|
432
|
+
}
|
433
|
+
const { renderView, injectHTMLTag } = bundleAnalyzerModule;
|
434
|
+
applyModules.forEach((m) => {
|
435
|
+
const index = modules.findIndex(({ filename }) => filename === m.filename);
|
436
|
+
if (index === -1) {
|
437
|
+
modules.push(m);
|
438
|
+
} else {
|
439
|
+
modules[index] = m;
|
440
|
+
}
|
441
|
+
});
|
442
|
+
let html = await renderView(modules, {
|
443
|
+
title: `Jiek Analyzer`,
|
444
|
+
mode: analyzer.size
|
445
|
+
});
|
446
|
+
html = injectHTMLTag({
|
447
|
+
html,
|
448
|
+
injectTo: "body",
|
449
|
+
descriptors: [
|
450
|
+
{ kind: "script", text: CLIENT_CUSTOM_RENDER_SCRIPT }
|
451
|
+
]
|
452
|
+
});
|
453
|
+
void server.renderTo("/ana", html);
|
454
|
+
};
|
455
|
+
return {
|
456
|
+
modules,
|
457
|
+
refreshAnalyzer,
|
458
|
+
ANALYZER_ENV: {
|
459
|
+
JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : void 0
|
460
|
+
}
|
461
|
+
};
|
462
|
+
};
|
463
|
+
|
259
464
|
const BUILDER_TYPES = ["esbuild", "swc"];
|
260
465
|
const BUILDER_TYPE_PACKAGE_NAME_MAP = {
|
261
466
|
esbuild: "rollup-plugin-esbuild",
|
@@ -267,7 +472,11 @@ const createServer = (port, host) => {
|
|
267
472
|
app.listen(port, host);
|
268
473
|
const streams = /* @__PURE__ */ new Map();
|
269
474
|
app.use(async (ctx) => {
|
270
|
-
|
475
|
+
let stream = streams.get(ctx.path);
|
476
|
+
if (stream == null) {
|
477
|
+
const maybeKey = streams.keys().find((p) => ctx.path.startsWith(p));
|
478
|
+
stream = maybeKey != null ? streams.get(maybeKey) : void 0;
|
479
|
+
}
|
271
480
|
if (stream != null) {
|
272
481
|
ctx.body = stream;
|
273
482
|
}
|
@@ -282,10 +491,10 @@ const createServer = (port, host) => {
|
|
282
491
|
};
|
283
492
|
};
|
284
493
|
|
285
|
-
const require$
|
494
|
+
const require$3 = createRequire(import.meta.url);
|
286
495
|
function packageIsExist(name) {
|
287
496
|
try {
|
288
|
-
require$
|
497
|
+
require$3.resolve(name);
|
289
498
|
return true;
|
290
499
|
} catch (e) {
|
291
500
|
return false;
|
@@ -305,7 +514,7 @@ for (const register of registers) {
|
|
305
514
|
}
|
306
515
|
}
|
307
516
|
|
308
|
-
const require$
|
517
|
+
const require$2 = createRequire(import.meta.url);
|
309
518
|
let configName = "jiek.config";
|
310
519
|
function getConfigPath(root, dir) {
|
311
520
|
const isSupportTsLoader = !!tsRegisterName;
|
@@ -359,16 +568,16 @@ function loadConfig(dirOrOptions) {
|
|
359
568
|
let module;
|
360
569
|
switch (ext) {
|
361
570
|
case ".js":
|
362
|
-
module = require$
|
571
|
+
module = require$2(configPath);
|
363
572
|
break;
|
364
573
|
case ".json":
|
365
|
-
return require$
|
574
|
+
return require$2(configPath);
|
366
575
|
case ".yaml":
|
367
576
|
return load(fs.readFileSync(configPath, "utf-8"));
|
368
577
|
case ".ts":
|
369
578
|
if (tsRegisterName) {
|
370
|
-
require$
|
371
|
-
module = require$
|
579
|
+
require$2(tsRegisterName);
|
580
|
+
module = require$2(configPath);
|
372
581
|
break;
|
373
582
|
}
|
374
583
|
throw new Error(
|
@@ -380,40 +589,24 @@ function loadConfig(dirOrOptions) {
|
|
380
589
|
default:
|
381
590
|
throw new Error(`unsupported config file type: ${ext}`);
|
382
591
|
}
|
383
|
-
if (!module)
|
384
|
-
throw new Error("config file is empty");
|
592
|
+
if (!module) throw new Error("config file is empty");
|
385
593
|
return module.default ?? module;
|
386
594
|
}
|
387
595
|
|
388
596
|
const FILE_TEMPLATE = (manifest) => `
|
389
597
|
module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
|
390
598
|
`.trimStart();
|
391
|
-
const require = createRequire(import.meta.url);
|
599
|
+
const require$1 = createRequire(import.meta.url);
|
392
600
|
const isDefault = process$1.env.JIEK_IS_ONLY_BUILD === "true";
|
393
601
|
const description = `
|
394
602
|
Build the package according to the 'exports' field from the package.json.
|
395
603
|
If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
|
396
604
|
${isDefault ? "This command is the default command." : ""}
|
397
605
|
`.trim();
|
398
|
-
async function checkDependency(dependency) {
|
399
|
-
try {
|
400
|
-
require.resolve(dependency);
|
401
|
-
} catch {
|
402
|
-
console.error(`The package '${dependency}' is not installed, please install it first.`);
|
403
|
-
const { notWorkspace } = getWD();
|
404
|
-
const command2 = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
|
405
|
-
if (await confirm({ message: "Do you want to install it now?" })) {
|
406
|
-
await execaCommand(command2);
|
407
|
-
} else {
|
408
|
-
console.warn(`You can run the command '${command2}' to install it manually.`);
|
409
|
-
process$1.exit(1);
|
410
|
-
}
|
411
|
-
}
|
412
|
-
}
|
413
606
|
let DEFAULT_BUILDER_TYPE;
|
414
607
|
Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
415
608
|
try {
|
416
|
-
require.resolve(packageName);
|
609
|
+
require$1.resolve(packageName);
|
417
610
|
DEFAULT_BUILDER_TYPE = type;
|
418
611
|
} catch {
|
419
612
|
}
|
@@ -421,11 +614,6 @@ Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
|
421
614
|
if (!DEFAULT_BUILDER_TYPE) {
|
422
615
|
DEFAULT_BUILDER_TYPE = "esbuild";
|
423
616
|
}
|
424
|
-
function parseBoolean(v) {
|
425
|
-
if (v === void 0)
|
426
|
-
return true;
|
427
|
-
return Boolean(v);
|
428
|
-
}
|
429
617
|
const buildFilterDescription = `
|
430
618
|
${filterDescription}
|
431
619
|
If you pass the --filter option, it will merge into the filters of the command.
|
@@ -464,11 +652,7 @@ command = command.description(description).option("-t, --type <TYPE>", `The type
|
|
464
652
|
);
|
465
653
|
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);
|
466
654
|
command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
|
467
|
-
command = command
|
468
|
-
"--ana.size <SIZE>",
|
469
|
-
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
470
|
-
"parsed"
|
471
|
-
);
|
655
|
+
command = registerAnalyzerCommandOptions(command);
|
472
656
|
command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
|
473
657
|
command.action(async (commandFiltersOrEntries, options) => {
|
474
658
|
let {
|
@@ -516,43 +700,14 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
516
700
|
},
|
517
701
|
[]
|
518
702
|
);
|
519
|
-
const
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
const
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
size: options["ana.size"]
|
528
|
-
} : void 0;
|
529
|
-
if (options.ana && ![
|
530
|
-
"stat",
|
531
|
-
"parsed",
|
532
|
-
"gzip"
|
533
|
-
].includes(analyzer?.size ?? "")) {
|
534
|
-
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
535
|
-
}
|
536
|
-
const server = analyzer && createServer(options.port, "localhost");
|
537
|
-
if (analyzer) {
|
538
|
-
await checkDependency("vite-bundle-analyzer");
|
539
|
-
const { renderView } = await import('vite-bundle-analyzer');
|
540
|
-
render = renderView;
|
541
|
-
}
|
542
|
-
const anaPaths = /* @__PURE__ */ new Set();
|
543
|
-
const refreshAnalyzer = async (subPath = "", renderModules = modules) => {
|
544
|
-
if (!(analyzer && server && render))
|
545
|
-
return;
|
546
|
-
const p = `/ana${subPath}`;
|
547
|
-
anaPaths.add(p);
|
548
|
-
void server.renderTo(
|
549
|
-
p,
|
550
|
-
await render(renderModules, {
|
551
|
-
title: `Jiek Analyzer - ${subPath}`,
|
552
|
-
mode: analyzer.size
|
553
|
-
})
|
554
|
-
);
|
555
|
-
};
|
703
|
+
const shouldCreateServer = [
|
704
|
+
options.ana === true && options["ana.mode"] === "server"
|
705
|
+
].some(Boolean);
|
706
|
+
const server = shouldCreateServer ? createServer(options.port, "localhost") : void 0;
|
707
|
+
const {
|
708
|
+
ANALYZER_ENV,
|
709
|
+
refreshAnalyzer
|
710
|
+
} = await useAnalyzer(options, server);
|
556
711
|
const { build } = loadConfig();
|
557
712
|
silent = silent ?? build?.silent ?? false;
|
558
713
|
if (withoutMin && onlyMin) {
|
@@ -569,7 +724,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
569
724
|
entries = void 0;
|
570
725
|
}
|
571
726
|
const env = {
|
572
|
-
|
727
|
+
...ANALYZER_ENV,
|
573
728
|
JIEK_BUILDER: type,
|
574
729
|
JIEK_OUT_DIR: outdir,
|
575
730
|
JIEK_CLEAN: String(!noClean),
|
@@ -608,30 +763,13 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
608
763
|
} catch {
|
609
764
|
}
|
610
765
|
}
|
611
|
-
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
766
|
+
const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
612
767
|
let i = 0;
|
613
768
|
await Promise.all(
|
614
|
-
Object.entries(value).map(async ([
|
769
|
+
Object.entries(value).map(async ([pkgCWD, manifest]) => {
|
615
770
|
if (manifest.name == null) {
|
616
771
|
throw new Error("package.json must have a name field");
|
617
772
|
}
|
618
|
-
if (analyzer) {
|
619
|
-
const anaDir = path.resolve(dir, analyzer.dir);
|
620
|
-
if (!existsSync(anaDir)) {
|
621
|
-
mkdirSync(anaDir, { recursive: true });
|
622
|
-
}
|
623
|
-
const gitIgnorePath = path.resolve(anaDir, ".gitignore");
|
624
|
-
if (!existsSync(gitIgnorePath)) {
|
625
|
-
writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
626
|
-
}
|
627
|
-
const npmIgnorePath = path.resolve(anaDir, ".npmignore");
|
628
|
-
if (!existsSync(npmIgnorePath)) {
|
629
|
-
writeFileSync(npmIgnorePath, "*\n");
|
630
|
-
}
|
631
|
-
if (!statSync(anaDir).isDirectory()) {
|
632
|
-
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
633
|
-
}
|
634
|
-
}
|
635
773
|
const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
|
636
774
|
const configFile = resolveByJiekTemp(
|
637
775
|
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
@@ -647,7 +785,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
647
785
|
command2.push(...passThroughOptions);
|
648
786
|
const child = execaCommand(command2.join(" "), {
|
649
787
|
ipc: true,
|
650
|
-
cwd:
|
788
|
+
cwd: pkgCWD,
|
651
789
|
env: {
|
652
790
|
...env,
|
653
791
|
JIEK_NAME: manifest.name,
|
@@ -663,8 +801,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
663
801
|
"init",
|
664
802
|
"progress",
|
665
803
|
"watchChange"
|
666
|
-
].includes(e.type))
|
667
|
-
return;
|
804
|
+
].includes(e.type)) return;
|
668
805
|
switch (e.type) {
|
669
806
|
case "init": {
|
670
807
|
const { leafMap, targetsLength } = e.data;
|
@@ -685,8 +822,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
685
822
|
});
|
686
823
|
leafs.forEach(({ input, path: path2 }) => {
|
687
824
|
const key = `${input}:${path2}`;
|
688
|
-
if (bars[key])
|
689
|
-
return;
|
825
|
+
if (bars[key]) return;
|
690
826
|
bars[key] = multiBars.create(50, 0, {
|
691
827
|
pkgName: manifest.name,
|
692
828
|
input: input.padEnd(inputMaxLen + 5),
|
@@ -707,8 +843,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
707
843
|
message
|
708
844
|
} = e.data;
|
709
845
|
const bar = bars[`${input}:${path2}`];
|
710
|
-
if (!bar)
|
711
|
-
return;
|
846
|
+
if (!bar) return;
|
712
847
|
const time = times[`${input}:${path2}`];
|
713
848
|
bar.update(
|
714
849
|
{
|
@@ -731,8 +866,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
731
866
|
} = e.data;
|
732
867
|
const key = `${input}:${path2}`;
|
733
868
|
const bar = bars[key];
|
734
|
-
if (!bar)
|
735
|
-
return;
|
869
|
+
if (!bar) return;
|
736
870
|
let time = times[key] ?? 1;
|
737
871
|
if (!locks[key]) {
|
738
872
|
time += 1;
|
@@ -753,41 +887,18 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
753
887
|
const {
|
754
888
|
data: {
|
755
889
|
type: type2,
|
756
|
-
path: path2,
|
757
890
|
modules: pkgModules
|
758
891
|
}
|
759
892
|
} = e;
|
760
|
-
|
761
|
-
|
893
|
+
void refreshAnalyzer(
|
894
|
+
pkgCWD,
|
895
|
+
pkgModules.map((m) => ({
|
762
896
|
...m,
|
897
|
+
type: type2,
|
763
898
|
filename: `${manifest.name}/${m.filename}`,
|
764
899
|
label: `${manifest.name}/${m.label}`
|
765
|
-
}
|
766
|
-
const pushOrReplace = (arr) => {
|
767
|
-
const index = arr.findIndex(({ filename }) => filename === newM.filename);
|
768
|
-
if (index === -1) {
|
769
|
-
arr.push(newM);
|
770
|
-
} else {
|
771
|
-
arr[index] = newM;
|
772
|
-
}
|
773
|
-
};
|
774
|
-
pushOrReplace(modules);
|
775
|
-
if (type2 === "esm") {
|
776
|
-
pushOrReplace(esmModules);
|
777
|
-
}
|
778
|
-
if (type2 === "cjs") {
|
779
|
-
pushOrReplace(cjsModules);
|
780
|
-
}
|
781
|
-
});
|
782
|
-
void refreshAnalyzer();
|
783
|
-
void refreshAnalyzer(
|
784
|
-
`/${type2}`,
|
785
|
-
{
|
786
|
-
cjs: cjsModules,
|
787
|
-
esm: esmModules
|
788
|
-
}[type2]
|
900
|
+
}))
|
789
901
|
);
|
790
|
-
void refreshAnalyzer(`/${type2}/${manifest.name}/${path2.slice(2)}`, pkgModules);
|
791
902
|
break;
|
792
903
|
}
|
793
904
|
case "debug": {
|
@@ -824,17 +935,7 @@ ${errorStr}`)));
|
|
824
935
|
}
|
825
936
|
} finally {
|
826
937
|
multiBars.stop();
|
827
|
-
|
828
|
-
if (analyzer) {
|
829
|
-
message += ` and the analyzer is running at http://localhost:${options.port}/ana in ${analyzer.mode} mode.
|
830
|
-
`;
|
831
|
-
message += analyzer.open ? " The browser will open automatically.\n" : "";
|
832
|
-
if (anaPaths.size > 0) {
|
833
|
-
message += `The analyzer has ${anaPaths.size} pages:
|
834
|
-
${Array.from(anaPaths).map((p) => `http://localhost:${options.port}${p}`).join("\n")}`;
|
835
|
-
}
|
836
|
-
}
|
837
|
-
!silent && console.log(message);
|
938
|
+
!silent && console.log("Build complete");
|
838
939
|
}
|
839
940
|
});
|
840
941
|
|
package/dist/cli.cjs
CHANGED
@@ -47,8 +47,7 @@ var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
|
|
47
47
|
|
48
48
|
let root;
|
49
49
|
function getRoot() {
|
50
|
-
if (root)
|
51
|
-
return root;
|
50
|
+
if (root) return root;
|
52
51
|
const rootOption = process.env.JIEK_ROOT;
|
53
52
|
root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
|
54
53
|
return root;
|
@@ -57,8 +56,7 @@ function getRoot() {
|
|
57
56
|
let wd;
|
58
57
|
let notWorkspace = false;
|
59
58
|
function getWD() {
|
60
|
-
if (wd)
|
61
|
-
return { wd, notWorkspace };
|
59
|
+
if (wd) return { wd, notWorkspace };
|
62
60
|
const root = getRoot();
|
63
61
|
if (root !== void 0) {
|
64
62
|
const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type);
|
@@ -4438,8 +4436,7 @@ function loadConfig(dirOrOptions) {
|
|
4438
4436
|
default:
|
4439
4437
|
throw new Error(`unsupported config file type: ${ext}`);
|
4440
4438
|
}
|
4441
|
-
if (!module)
|
4442
|
-
throw new Error("config file is empty");
|
4439
|
+
if (!module) throw new Error("config file is empty");
|
4443
4440
|
return module.default ?? module;
|
4444
4441
|
}
|
4445
4442
|
|
@@ -4551,10 +4548,8 @@ async function prepublish({ bumper: bumper$1 } = {}) {
|
|
4551
4548
|
)
|
4552
4549
|
);
|
4553
4550
|
for (const [key, value] of Object.entries(manifest)) {
|
4554
|
-
if (key === "version")
|
4555
|
-
|
4556
|
-
if (JSON.stringify(value) === JSON.stringify(oldJSON[key]))
|
4557
|
-
continue;
|
4551
|
+
if (key === "version") continue;
|
4552
|
+
if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue;
|
4558
4553
|
if (key !== "exports") {
|
4559
4554
|
newJSONString = jsoncParser.applyEdits(
|
4560
4555
|
newJSONString,
|
@@ -4593,8 +4588,7 @@ async function prepublish({ bumper: bumper$1 } = {}) {
|
|
4593
4588
|
}
|
4594
4589
|
}
|
4595
4590
|
for (const [k, v] of Object.entries(indexPublishConfig)) {
|
4596
|
-
if (v === void 0)
|
4597
|
-
continue;
|
4591
|
+
if (v === void 0) continue;
|
4598
4592
|
newJSONString = jsoncParser.applyEdits(
|
4599
4593
|
newJSONString,
|
4600
4594
|
jsoncParser.modify(
|