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.js
CHANGED
@@ -5,15 +5,15 @@ 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 { spawnSync } from 'node:child_process';
|
11
|
+
import { confirm } from '@inquirer/prompts';
|
11
12
|
import Koa from 'koa';
|
12
13
|
|
13
14
|
let root;
|
14
15
|
function getRoot() {
|
15
|
-
if (root)
|
16
|
-
return root;
|
16
|
+
if (root) return root;
|
17
17
|
const rootOption = process.env.JIEK_ROOT;
|
18
18
|
root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
|
19
19
|
return root;
|
@@ -22,8 +22,7 @@ function getRoot() {
|
|
22
22
|
let wd;
|
23
23
|
let notWorkspace$1 = false;
|
24
24
|
function getWD() {
|
25
|
-
if (wd)
|
26
|
-
return { wd, notWorkspace: notWorkspace$1 };
|
25
|
+
if (wd) return { wd, notWorkspace: notWorkspace$1 };
|
27
26
|
const root = getRoot();
|
28
27
|
if (root !== void 0) {
|
29
28
|
const isWorkspace = isWorkspaceDir(root, type$1);
|
@@ -110,7 +109,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
|
|
110
109
|
|
111
110
|
var name = "jiek";
|
112
111
|
var type = "module";
|
113
|
-
var version = "2.2.
|
112
|
+
var version = "2.2.3";
|
114
113
|
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
115
114
|
var author = "YiJie <yijie4188@gmail.com>";
|
116
115
|
var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
|
@@ -141,7 +140,11 @@ var exports = {
|
|
141
140
|
"./rollup": "./src/rollup/index.ts"
|
142
141
|
};
|
143
142
|
var imports = {
|
144
|
-
"#~/*":
|
143
|
+
"#~/*": [
|
144
|
+
"./src/*",
|
145
|
+
"./src/*/index.ts",
|
146
|
+
"./src/*/index.tsx"
|
147
|
+
]
|
145
148
|
};
|
146
149
|
var bin = {
|
147
150
|
jiek: "bin/jiek.js",
|
@@ -164,7 +167,7 @@ var scripts = {
|
|
164
167
|
test: "vitest run"
|
165
168
|
};
|
166
169
|
var peerDependencies = {
|
167
|
-
"@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
|
170
|
+
"@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
|
168
171
|
"@rollup/plugin-terser": "^0.4.4",
|
169
172
|
"esbuild-register": "^3.5.0",
|
170
173
|
postcss: "^8.4.47",
|
@@ -172,7 +175,7 @@ var peerDependencies = {
|
|
172
175
|
"rollup-plugin-postcss": "^4.0.2",
|
173
176
|
"rollup-plugin-swc3": "^0.12.1",
|
174
177
|
typescript: "^4.0.0||^5.0.0",
|
175
|
-
"vite-bundle-analyzer": "
|
178
|
+
"vite-bundle-analyzer": "0.16.0-beta.1"
|
176
179
|
};
|
177
180
|
var dependencies = {
|
178
181
|
"@inquirer/prompts": "^7.1.0",
|
@@ -203,6 +206,7 @@ var devDependencies = {
|
|
203
206
|
"@types/js-yaml": "^4.0.9",
|
204
207
|
"@types/koa": "^2.15.0",
|
205
208
|
"@types/micromatch": "^4.0.6",
|
209
|
+
"@types/react": "^18.3.14",
|
206
210
|
"esbuild-register": "^3.5.0",
|
207
211
|
micromatch: "^4.0.5",
|
208
212
|
"node-sass": "^9.0.0",
|
@@ -210,7 +214,7 @@ var devDependencies = {
|
|
210
214
|
"rollup-plugin-esbuild": "^6.1.0",
|
211
215
|
"rollup-plugin-postcss": "^4.0.2",
|
212
216
|
"rollup-plugin-swc3": "^0.12.1",
|
213
|
-
"vite-bundle-analyzer": "
|
217
|
+
"vite-bundle-analyzer": "0.16.0-beta.1"
|
214
218
|
};
|
215
219
|
var pkg = {
|
216
220
|
name: name,
|
@@ -256,6 +260,208 @@ if (type$1 !== "" && IS_WORKSPACE) {
|
|
256
260
|
program.option("-f, --filter <filter>", filterDescription);
|
257
261
|
}
|
258
262
|
|
263
|
+
function Main() {
|
264
|
+
const { useState, useMemo, useEffect, useCallback } = React;
|
265
|
+
const [path, setPath] = useState(() => location.pathname.replace(/^\/ana\/?/, ""));
|
266
|
+
const [pkgName, entry] = useMemo(() => {
|
267
|
+
const pkgName2 = /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(path)?.[1];
|
268
|
+
return [
|
269
|
+
pkgName2,
|
270
|
+
pkgName2 != null ? path.replace(`${pkgName2}/`, "") : void 0
|
271
|
+
];
|
272
|
+
}, [path]);
|
273
|
+
const push = useCallback((newPath) => {
|
274
|
+
setPath(newPath);
|
275
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${newPath}`;
|
276
|
+
history.pushState(null, "", `/ana/${newPath}`);
|
277
|
+
}, []);
|
278
|
+
const filterModules = useCallback((startWith) => {
|
279
|
+
const modules = analyzeModule.filter((m) => m.filename.startsWith(startWith));
|
280
|
+
dispatchEvent(new CustomEvent("send:filter", { detail: { analyzeModule: modules } }));
|
281
|
+
}, []);
|
282
|
+
useEffect(() => {
|
283
|
+
if (path !== "") {
|
284
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${path}`;
|
285
|
+
} else {
|
286
|
+
document.title = document.title.replace(/ - \/.*/, "");
|
287
|
+
}
|
288
|
+
filterModules(path);
|
289
|
+
}, [path, filterModules]);
|
290
|
+
useEffect(() => {
|
291
|
+
const offGraphClick = listen("graph:click", ({ detail }) => {
|
292
|
+
if (!detail) return;
|
293
|
+
let root = detail.node;
|
294
|
+
while (root.parent) {
|
295
|
+
root = root.parent;
|
296
|
+
}
|
297
|
+
if (root.filename === path) return;
|
298
|
+
push(root.filename);
|
299
|
+
});
|
300
|
+
return () => {
|
301
|
+
offGraphClick();
|
302
|
+
};
|
303
|
+
}, [push]);
|
304
|
+
function listen(type, listener) {
|
305
|
+
window.addEventListener(type, listener);
|
306
|
+
return () => {
|
307
|
+
window.removeEventListener(type, listener);
|
308
|
+
};
|
309
|
+
}
|
310
|
+
return /* @__PURE__ */ React.createElement(
|
311
|
+
"div",
|
312
|
+
{
|
313
|
+
style: {
|
314
|
+
padding: "12px 55px"
|
315
|
+
}
|
316
|
+
},
|
317
|
+
"/",
|
318
|
+
/* @__PURE__ */ React.createElement(
|
319
|
+
"select",
|
320
|
+
{
|
321
|
+
style: {
|
322
|
+
appearance: "none",
|
323
|
+
border: "none",
|
324
|
+
background: "none"
|
325
|
+
},
|
326
|
+
value: pkgName,
|
327
|
+
onChange: (e) => push(e.target.value)
|
328
|
+
},
|
329
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
330
|
+
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))
|
331
|
+
),
|
332
|
+
pkgName != null && /* @__PURE__ */ React.createElement(React.Fragment, null, "/", /* @__PURE__ */ React.createElement(
|
333
|
+
"select",
|
334
|
+
{
|
335
|
+
style: {
|
336
|
+
appearance: "none",
|
337
|
+
border: "none",
|
338
|
+
background: "none"
|
339
|
+
},
|
340
|
+
value: entry,
|
341
|
+
onChange: (e) => push(`${pkgName}/${e.target.value}`)
|
342
|
+
},
|
343
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
344
|
+
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))
|
345
|
+
))
|
346
|
+
);
|
347
|
+
}
|
348
|
+
|
349
|
+
function render() {
|
350
|
+
CUSTOM_SIDE_BAR = true;
|
351
|
+
window.addEventListener("client:ready", () => setTimeout(() => {
|
352
|
+
window.dispatchEvent(
|
353
|
+
new CustomEvent("send:ui", {
|
354
|
+
detail: { type: "Main", Component: __REPLACE_INJECT__ }
|
355
|
+
})
|
356
|
+
);
|
357
|
+
}, 0));
|
358
|
+
}
|
359
|
+
const CLIENT_CUSTOM_RENDER_SCRIPT = [
|
360
|
+
Main.toString(),
|
361
|
+
render.toString().replace("__REPLACE_INJECT__", Main.name),
|
362
|
+
`(${render.name})()`
|
363
|
+
].join("\n");
|
364
|
+
|
365
|
+
function parseBoolean(v) {
|
366
|
+
if (v === void 0) return true;
|
367
|
+
return Boolean(v);
|
368
|
+
}
|
369
|
+
|
370
|
+
async function checkDependency(dependency) {
|
371
|
+
try {
|
372
|
+
require.resolve(dependency);
|
373
|
+
} catch {
|
374
|
+
console.error(`The package '${dependency}' is not installed, please install it first.`);
|
375
|
+
const { notWorkspace } = getWD();
|
376
|
+
const command = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
|
377
|
+
if (await confirm({ message: "Do you want to install it now?" })) {
|
378
|
+
spawnSync(command);
|
379
|
+
} else {
|
380
|
+
console.warn(`You can run the command '${command}' to install it manually.`);
|
381
|
+
process$1.exit(1);
|
382
|
+
}
|
383
|
+
}
|
384
|
+
}
|
385
|
+
|
386
|
+
const registerAnalyzerCommandOptions = (command) => command.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option(
|
387
|
+
"--ana.mode <MODE>",
|
388
|
+
'The mode of the bundle analyzer, support "static", "json" and "server".',
|
389
|
+
"server"
|
390
|
+
).option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
|
391
|
+
"--ana.size <SIZE>",
|
392
|
+
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
393
|
+
"parsed"
|
394
|
+
);
|
395
|
+
const useAnalyzer = async (options, server) => {
|
396
|
+
const modules = [];
|
397
|
+
let bundleAnalyzerModule;
|
398
|
+
const analyzer = options.ana ? {
|
399
|
+
dir: options["ana.dir"],
|
400
|
+
mode: options["ana.mode"],
|
401
|
+
open: options["ana.open"],
|
402
|
+
size: options["ana.size"]
|
403
|
+
} : void 0;
|
404
|
+
if (options.ana && ![
|
405
|
+
"stat",
|
406
|
+
"parsed",
|
407
|
+
"gzip"
|
408
|
+
].includes(analyzer?.size ?? "")) {
|
409
|
+
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
410
|
+
}
|
411
|
+
if (analyzer) {
|
412
|
+
await checkDependency("vite-bundle-analyzer");
|
413
|
+
bundleAnalyzerModule = await import('vite-bundle-analyzer');
|
414
|
+
}
|
415
|
+
const refreshAnalyzer = async (cwd, applyModules) => {
|
416
|
+
if (!(analyzer && server && bundleAnalyzerModule)) return;
|
417
|
+
if (analyzer.mode === "json") {
|
418
|
+
const anaDir = path.resolve(cwd, analyzer.dir);
|
419
|
+
if (!existsSync(anaDir)) {
|
420
|
+
mkdirSync(anaDir, { recursive: true });
|
421
|
+
}
|
422
|
+
const gitIgnorePath = path.resolve(anaDir, ".gitignore");
|
423
|
+
if (!existsSync(gitIgnorePath)) {
|
424
|
+
writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
425
|
+
}
|
426
|
+
const npmIgnorePath = path.resolve(anaDir, ".npmignore");
|
427
|
+
if (!existsSync(npmIgnorePath)) {
|
428
|
+
writeFileSync(npmIgnorePath, "*\n");
|
429
|
+
}
|
430
|
+
if (!statSync(anaDir).isDirectory()) {
|
431
|
+
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
432
|
+
}
|
433
|
+
}
|
434
|
+
const { renderView, injectHTMLTag } = bundleAnalyzerModule;
|
435
|
+
applyModules.forEach((m) => {
|
436
|
+
const index = modules.findIndex(({ filename }) => filename === m.filename);
|
437
|
+
if (index === -1) {
|
438
|
+
modules.push(m);
|
439
|
+
} else {
|
440
|
+
modules[index] = m;
|
441
|
+
}
|
442
|
+
});
|
443
|
+
let html = await renderView(modules, {
|
444
|
+
title: `Jiek Analyzer`,
|
445
|
+
mode: analyzer.size
|
446
|
+
});
|
447
|
+
html = injectHTMLTag({
|
448
|
+
html,
|
449
|
+
injectTo: "body",
|
450
|
+
descriptors: [
|
451
|
+
{ kind: "script", text: CLIENT_CUSTOM_RENDER_SCRIPT }
|
452
|
+
]
|
453
|
+
});
|
454
|
+
void server.renderTo("/ana", html);
|
455
|
+
};
|
456
|
+
return {
|
457
|
+
modules,
|
458
|
+
refreshAnalyzer,
|
459
|
+
ANALYZER_ENV: {
|
460
|
+
JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : void 0
|
461
|
+
}
|
462
|
+
};
|
463
|
+
};
|
464
|
+
|
259
465
|
const BUILDER_TYPES = ["esbuild", "swc"];
|
260
466
|
const BUILDER_TYPE_PACKAGE_NAME_MAP = {
|
261
467
|
esbuild: "rollup-plugin-esbuild",
|
@@ -267,7 +473,11 @@ const createServer = (port, host) => {
|
|
267
473
|
app.listen(port, host);
|
268
474
|
const streams = /* @__PURE__ */ new Map();
|
269
475
|
app.use(async (ctx) => {
|
270
|
-
|
476
|
+
let stream = streams.get(ctx.path);
|
477
|
+
if (stream == null) {
|
478
|
+
const maybeKey = streams.keys().find((p) => ctx.path.startsWith(p));
|
479
|
+
stream = maybeKey != null ? streams.get(maybeKey) : void 0;
|
480
|
+
}
|
271
481
|
if (stream != null) {
|
272
482
|
ctx.body = stream;
|
273
483
|
}
|
@@ -282,10 +492,10 @@ const createServer = (port, host) => {
|
|
282
492
|
};
|
283
493
|
};
|
284
494
|
|
285
|
-
const require$
|
495
|
+
const require$3 = createRequire(import.meta.url);
|
286
496
|
function packageIsExist(name) {
|
287
497
|
try {
|
288
|
-
require$
|
498
|
+
require$3.resolve(name);
|
289
499
|
return true;
|
290
500
|
} catch (e) {
|
291
501
|
return false;
|
@@ -305,7 +515,7 @@ for (const register of registers) {
|
|
305
515
|
}
|
306
516
|
}
|
307
517
|
|
308
|
-
const require$
|
518
|
+
const require$2 = createRequire(import.meta.url);
|
309
519
|
let configName = "jiek.config";
|
310
520
|
function getConfigPath(root, dir) {
|
311
521
|
const isSupportTsLoader = !!tsRegisterName;
|
@@ -359,16 +569,16 @@ function loadConfig(dirOrOptions) {
|
|
359
569
|
let module;
|
360
570
|
switch (ext) {
|
361
571
|
case ".js":
|
362
|
-
module = require$
|
572
|
+
module = require$2(configPath);
|
363
573
|
break;
|
364
574
|
case ".json":
|
365
|
-
return require$
|
575
|
+
return require$2(configPath);
|
366
576
|
case ".yaml":
|
367
577
|
return load(fs.readFileSync(configPath, "utf-8"));
|
368
578
|
case ".ts":
|
369
579
|
if (tsRegisterName) {
|
370
|
-
require$
|
371
|
-
module = require$
|
580
|
+
require$2(tsRegisterName);
|
581
|
+
module = require$2(configPath);
|
372
582
|
break;
|
373
583
|
}
|
374
584
|
throw new Error(
|
@@ -380,40 +590,24 @@ function loadConfig(dirOrOptions) {
|
|
380
590
|
default:
|
381
591
|
throw new Error(`unsupported config file type: ${ext}`);
|
382
592
|
}
|
383
|
-
if (!module)
|
384
|
-
throw new Error("config file is empty");
|
593
|
+
if (!module) throw new Error("config file is empty");
|
385
594
|
return module.default ?? module;
|
386
595
|
}
|
387
596
|
|
388
597
|
const FILE_TEMPLATE = (manifest) => `
|
389
598
|
module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
|
390
599
|
`.trimStart();
|
391
|
-
const require = createRequire(import.meta.url);
|
600
|
+
const require$1 = createRequire(import.meta.url);
|
392
601
|
const isDefault = process$1.env.JIEK_IS_ONLY_BUILD === "true";
|
393
602
|
const description = `
|
394
603
|
Build the package according to the 'exports' field from the package.json.
|
395
604
|
If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
|
396
605
|
${isDefault ? "This command is the default command." : ""}
|
397
606
|
`.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
607
|
let DEFAULT_BUILDER_TYPE;
|
414
608
|
Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
415
609
|
try {
|
416
|
-
require.resolve(packageName);
|
610
|
+
require$1.resolve(packageName);
|
417
611
|
DEFAULT_BUILDER_TYPE = type;
|
418
612
|
} catch {
|
419
613
|
}
|
@@ -421,11 +615,6 @@ Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
|
421
615
|
if (!DEFAULT_BUILDER_TYPE) {
|
422
616
|
DEFAULT_BUILDER_TYPE = "esbuild";
|
423
617
|
}
|
424
|
-
function parseBoolean(v) {
|
425
|
-
if (v === void 0)
|
426
|
-
return true;
|
427
|
-
return Boolean(v);
|
428
|
-
}
|
429
618
|
const buildFilterDescription = `
|
430
619
|
${filterDescription}
|
431
620
|
If you pass the --filter option, it will merge into the filters of the command.
|
@@ -464,11 +653,7 @@ command = command.description(description).option("-t, --type <TYPE>", `The type
|
|
464
653
|
);
|
465
654
|
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
655
|
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
|
-
);
|
656
|
+
command = registerAnalyzerCommandOptions(command);
|
472
657
|
command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
|
473
658
|
command.action(async (commandFiltersOrEntries, options) => {
|
474
659
|
let {
|
@@ -516,43 +701,14 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
516
701
|
},
|
517
702
|
[]
|
518
703
|
);
|
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
|
-
};
|
704
|
+
const shouldCreateServer = [
|
705
|
+
options.ana === true && options["ana.mode"] === "server"
|
706
|
+
].some(Boolean);
|
707
|
+
const server = shouldCreateServer ? createServer(options.port, "localhost") : void 0;
|
708
|
+
const {
|
709
|
+
ANALYZER_ENV,
|
710
|
+
refreshAnalyzer
|
711
|
+
} = await useAnalyzer(options, server);
|
556
712
|
const { build } = loadConfig();
|
557
713
|
silent = silent ?? build?.silent ?? false;
|
558
714
|
if (withoutMin && onlyMin) {
|
@@ -569,7 +725,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
569
725
|
entries = void 0;
|
570
726
|
}
|
571
727
|
const env = {
|
572
|
-
|
728
|
+
...ANALYZER_ENV,
|
573
729
|
JIEK_BUILDER: type,
|
574
730
|
JIEK_OUT_DIR: outdir,
|
575
731
|
JIEK_CLEAN: String(!noClean),
|
@@ -608,30 +764,13 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
608
764
|
} catch {
|
609
765
|
}
|
610
766
|
}
|
611
|
-
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
767
|
+
const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
612
768
|
let i = 0;
|
613
769
|
await Promise.all(
|
614
|
-
Object.entries(value).map(async ([
|
770
|
+
Object.entries(value).map(async ([pkgCWD, manifest]) => {
|
615
771
|
if (manifest.name == null) {
|
616
772
|
throw new Error("package.json must have a name field");
|
617
773
|
}
|
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
774
|
const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
|
636
775
|
const configFile = resolveByJiekTemp(
|
637
776
|
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
@@ -647,7 +786,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
647
786
|
command2.push(...passThroughOptions);
|
648
787
|
const child = execaCommand(command2.join(" "), {
|
649
788
|
ipc: true,
|
650
|
-
cwd:
|
789
|
+
cwd: pkgCWD,
|
651
790
|
env: {
|
652
791
|
...env,
|
653
792
|
JIEK_NAME: manifest.name,
|
@@ -663,8 +802,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
663
802
|
"init",
|
664
803
|
"progress",
|
665
804
|
"watchChange"
|
666
|
-
].includes(e.type))
|
667
|
-
return;
|
805
|
+
].includes(e.type)) return;
|
668
806
|
switch (e.type) {
|
669
807
|
case "init": {
|
670
808
|
const { leafMap, targetsLength } = e.data;
|
@@ -685,8 +823,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
685
823
|
});
|
686
824
|
leafs.forEach(({ input, path: path2 }) => {
|
687
825
|
const key = `${input}:${path2}`;
|
688
|
-
if (bars[key])
|
689
|
-
return;
|
826
|
+
if (bars[key]) return;
|
690
827
|
bars[key] = multiBars.create(50, 0, {
|
691
828
|
pkgName: manifest.name,
|
692
829
|
input: input.padEnd(inputMaxLen + 5),
|
@@ -707,8 +844,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
707
844
|
message
|
708
845
|
} = e.data;
|
709
846
|
const bar = bars[`${input}:${path2}`];
|
710
|
-
if (!bar)
|
711
|
-
return;
|
847
|
+
if (!bar) return;
|
712
848
|
const time = times[`${input}:${path2}`];
|
713
849
|
bar.update(
|
714
850
|
{
|
@@ -731,8 +867,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
731
867
|
} = e.data;
|
732
868
|
const key = `${input}:${path2}`;
|
733
869
|
const bar = bars[key];
|
734
|
-
if (!bar)
|
735
|
-
return;
|
870
|
+
if (!bar) return;
|
736
871
|
let time = times[key] ?? 1;
|
737
872
|
if (!locks[key]) {
|
738
873
|
time += 1;
|
@@ -753,41 +888,18 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
753
888
|
const {
|
754
889
|
data: {
|
755
890
|
type: type2,
|
756
|
-
path: path2,
|
757
891
|
modules: pkgModules
|
758
892
|
}
|
759
893
|
} = e;
|
760
|
-
|
761
|
-
|
894
|
+
void refreshAnalyzer(
|
895
|
+
pkgCWD,
|
896
|
+
pkgModules.map((m) => ({
|
762
897
|
...m,
|
898
|
+
type: type2,
|
763
899
|
filename: `${manifest.name}/${m.filename}`,
|
764
900
|
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]
|
901
|
+
}))
|
789
902
|
);
|
790
|
-
void refreshAnalyzer(`/${type2}/${manifest.name}/${path2.slice(2)}`, pkgModules);
|
791
903
|
break;
|
792
904
|
}
|
793
905
|
case "debug": {
|
@@ -797,12 +909,15 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
797
909
|
}
|
798
910
|
});
|
799
911
|
await new Promise((resolve, reject) => {
|
800
|
-
let errorStr =
|
912
|
+
let errorStr = `rollup build failed
|
913
|
+
package name: ${manifest.name}
|
914
|
+
cwd: ${pkgCWD}
|
915
|
+
|
916
|
+
`;
|
801
917
|
child.stderr?.on("data", (data) => {
|
802
918
|
errorStr += data;
|
803
919
|
});
|
804
|
-
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(
|
805
|
-
${errorStr}`)));
|
920
|
+
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
|
806
921
|
verbose && child.stdout?.pipe(process$1.stdout);
|
807
922
|
});
|
808
923
|
})
|
@@ -824,17 +939,7 @@ ${errorStr}`)));
|
|
824
939
|
}
|
825
940
|
} finally {
|
826
941
|
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);
|
942
|
+
!silent && console.log("Build complete");
|
838
943
|
}
|
839
944
|
});
|
840
945
|
|