jiek 2.1.12 → 2.1.13
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 +221 -96
- package/dist/cli-only-build.js +221 -97
- package/dist/rollup/index.cjs +75 -94
- package/dist/rollup/index.js +76 -95
- package/package.json +13 -2
- package/src/bridge.ts +42 -0
- package/src/commands/build.ts +207 -99
- package/src/rollup/base.ts +0 -35
- package/src/rollup/bundle-analyzer.ts +62 -0
- package/src/rollup/index.ts +43 -117
- package/src/server.ts +22 -0
package/dist/cli-only-build.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import fs, { existsSync, statSync } from 'node:fs';
|
1
|
+
import fs, { existsSync, mkdirSync, writeFileSync, statSync } from 'node:fs';
|
2
2
|
import { createRequire } from 'node:module';
|
3
3
|
import path from 'node:path';
|
4
4
|
import { program } from 'commander';
|
@@ -8,6 +8,7 @@ import process$1 from 'node:process';
|
|
8
8
|
import { confirm } from '@inquirer/prompts';
|
9
9
|
import { MultiBar, Presets } from 'cli-progress';
|
10
10
|
import { execaCommand } from 'execa';
|
11
|
+
import Koa from 'koa';
|
11
12
|
|
12
13
|
let root;
|
13
14
|
function getRoot() {
|
@@ -109,7 +110,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
|
|
109
110
|
|
110
111
|
var name = "jiek";
|
111
112
|
var type = "module";
|
112
|
-
var version = "2.1.
|
113
|
+
var version = "2.1.12";
|
113
114
|
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
114
115
|
var author = "YiJie <yijie4188@gmail.com>";
|
115
116
|
var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
|
@@ -118,6 +119,16 @@ var repository = {
|
|
118
119
|
directory: "packages/jiek"
|
119
120
|
};
|
120
121
|
var bugs = "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek";
|
122
|
+
var keywords = [
|
123
|
+
"cli",
|
124
|
+
"zero-config",
|
125
|
+
"bundler",
|
126
|
+
"library",
|
127
|
+
"monorepo",
|
128
|
+
"builder",
|
129
|
+
"rollup",
|
130
|
+
"workspace"
|
131
|
+
];
|
121
132
|
var exports = {
|
122
133
|
"./package.json": "./package.json",
|
123
134
|
".": "./src/index.ts",
|
@@ -161,7 +172,7 @@ var peerDependencies = {
|
|
161
172
|
"rollup-plugin-postcss": "^4.0.2",
|
162
173
|
"rollup-plugin-swc3": "^0.12.1",
|
163
174
|
typescript: "^4.0.0||^5.0.0",
|
164
|
-
"vite-bundle-analyzer": "^0.15.
|
175
|
+
"vite-bundle-analyzer": "^0.15.2"
|
165
176
|
};
|
166
177
|
var dependencies = {
|
167
178
|
"@inquirer/prompts": "^7.1.0",
|
@@ -179,6 +190,7 @@ var dependencies = {
|
|
179
190
|
execa: "~9.3.1",
|
180
191
|
"js-yaml": "^4.1.0",
|
181
192
|
"jsonc-parser": "^3.2.1",
|
193
|
+
koa: "^2.15.3",
|
182
194
|
rollup: "^4.0.0"
|
183
195
|
};
|
184
196
|
var devDependencies = {
|
@@ -189,6 +201,7 @@ var devDependencies = {
|
|
189
201
|
"@types/cli-progress": "^3.11.5",
|
190
202
|
"@types/inquirer": "^9.0.7",
|
191
203
|
"@types/js-yaml": "^4.0.9",
|
204
|
+
"@types/koa": "^2.15.0",
|
192
205
|
"@types/micromatch": "^4.0.6",
|
193
206
|
"esbuild-register": "^3.5.0",
|
194
207
|
micromatch: "^4.0.5",
|
@@ -197,7 +210,7 @@ var devDependencies = {
|
|
197
210
|
"rollup-plugin-esbuild": "^6.1.0",
|
198
211
|
"rollup-plugin-postcss": "^4.0.2",
|
199
212
|
"rollup-plugin-swc3": "^0.12.1",
|
200
|
-
"vite-bundle-analyzer": "^0.15.
|
213
|
+
"vite-bundle-analyzer": "^0.15.2"
|
201
214
|
};
|
202
215
|
var pkg = {
|
203
216
|
name: name,
|
@@ -208,6 +221,7 @@ var pkg = {
|
|
208
221
|
homepage: homepage,
|
209
222
|
repository: repository,
|
210
223
|
bugs: bugs,
|
224
|
+
keywords: keywords,
|
211
225
|
exports: exports,
|
212
226
|
imports: imports,
|
213
227
|
bin: bin,
|
@@ -242,6 +256,32 @@ if (type$1 !== "" && IS_WORKSPACE) {
|
|
242
256
|
program.option("-f, --filter <filter>", filterDescription);
|
243
257
|
}
|
244
258
|
|
259
|
+
const BUILDER_TYPES = ["esbuild", "swc"];
|
260
|
+
const BUILDER_TYPE_PACKAGE_NAME_MAP = {
|
261
|
+
esbuild: "rollup-plugin-esbuild",
|
262
|
+
swc: "rollup-plugin-swc3"
|
263
|
+
};
|
264
|
+
|
265
|
+
const createServer = (port, host) => {
|
266
|
+
const app = new Koa();
|
267
|
+
app.listen(port, host);
|
268
|
+
const streams = /* @__PURE__ */ new Map();
|
269
|
+
app.use(async (ctx) => {
|
270
|
+
const stream = streams.get(ctx.path);
|
271
|
+
if (stream != null) {
|
272
|
+
ctx.body = stream;
|
273
|
+
}
|
274
|
+
});
|
275
|
+
return {
|
276
|
+
port,
|
277
|
+
host,
|
278
|
+
rootUrl: `http://${host}:${port}`,
|
279
|
+
renderTo: async (path, stream) => {
|
280
|
+
streams.set(path, stream);
|
281
|
+
}
|
282
|
+
};
|
283
|
+
};
|
284
|
+
|
245
285
|
const require$2 = createRequire(import.meta.url);
|
246
286
|
function packageIsExist(name) {
|
247
287
|
try {
|
@@ -345,12 +385,6 @@ function loadConfig(dirOrOptions) {
|
|
345
385
|
return module.default ?? module;
|
346
386
|
}
|
347
387
|
|
348
|
-
const BUILDER_TYPES = ["esbuild", "swc"];
|
349
|
-
const BUILDER_TYPE_PACKAGE_NAME_MAP = {
|
350
|
-
esbuild: "rollup-plugin-esbuild",
|
351
|
-
swc: "rollup-plugin-swc3"
|
352
|
-
};
|
353
|
-
|
354
388
|
const FILE_TEMPLATE = (manifest) => `
|
355
389
|
module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
|
356
390
|
`.trimStart();
|
@@ -429,8 +463,8 @@ command = command.description(description).option("-t, --type <TYPE>", `The type
|
|
429
463
|
parseBoolean
|
430
464
|
);
|
431
465
|
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);
|
432
|
-
command = command.option("-w, --watch", "Watch the file changes.", parseBoolean);
|
433
|
-
command = command.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option("--ana.mode <MODE>", 'The mode of the bundle analyzer, support "static", "json" and "server".', "server").option("--ana.
|
466
|
+
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.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option("--ana.mode <MODE>", 'The mode of the bundle analyzer, support "static", "json" and "server".', "server").option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
|
434
468
|
"--ana.size <SIZE>",
|
435
469
|
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
436
470
|
"parsed"
|
@@ -482,16 +516,43 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
482
516
|
},
|
483
517
|
[]
|
484
518
|
);
|
519
|
+
const modules = [];
|
520
|
+
const cjsModules = [];
|
521
|
+
const esmModules = [];
|
522
|
+
let render;
|
485
523
|
const analyzer = options.ana ? {
|
486
524
|
dir: options["ana.dir"],
|
487
525
|
mode: options["ana.mode"],
|
488
|
-
port: options["ana.port"],
|
489
526
|
open: options["ana.open"],
|
490
527
|
size: options["ana.size"]
|
491
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");
|
492
537
|
if (analyzer) {
|
493
538
|
await checkDependency("vite-bundle-analyzer");
|
539
|
+
const { renderView } = await import('vite-bundle-analyzer');
|
540
|
+
render = renderView;
|
494
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
|
+
};
|
495
556
|
const { build } = loadConfig();
|
496
557
|
silent = silent ?? build?.silent ?? false;
|
497
558
|
if (withoutMin && onlyMin) {
|
@@ -536,12 +597,12 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
536
597
|
throw new Error("no package found");
|
537
598
|
}
|
538
599
|
const wdNodeModules = path.resolve(wd, "node_modules");
|
539
|
-
if (!
|
540
|
-
|
600
|
+
if (!existsSync(wdNodeModules)) {
|
601
|
+
mkdirSync(wdNodeModules);
|
541
602
|
}
|
542
603
|
const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
|
543
|
-
if (!
|
544
|
-
|
604
|
+
if (!existsSync(jiekTempDir())) {
|
605
|
+
mkdirSync(jiekTempDir());
|
545
606
|
}
|
546
607
|
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
547
608
|
let i = 0;
|
@@ -553,15 +614,15 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
553
614
|
if (analyzer) {
|
554
615
|
const anaDir = path.resolve(dir, analyzer.dir);
|
555
616
|
if (!existsSync(anaDir)) {
|
556
|
-
|
617
|
+
mkdirSync(anaDir, { recursive: true });
|
557
618
|
}
|
558
619
|
const gitIgnorePath = path.resolve(anaDir, ".gitignore");
|
559
620
|
if (!existsSync(gitIgnorePath)) {
|
560
|
-
|
621
|
+
writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
561
622
|
}
|
562
623
|
const npmIgnorePath = path.resolve(anaDir, ".npmignore");
|
563
624
|
if (!existsSync(npmIgnorePath)) {
|
564
|
-
|
625
|
+
writeFileSync(npmIgnorePath, "*\n");
|
565
626
|
}
|
566
627
|
if (!statSync(anaDir).isDirectory()) {
|
567
628
|
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
@@ -571,7 +632,7 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
571
632
|
const configFile = jiekTempDir(
|
572
633
|
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
573
634
|
);
|
574
|
-
|
635
|
+
writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
575
636
|
const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
|
576
637
|
if (tsRegisterName != null) {
|
577
638
|
command2.unshift(`node -r ${tsRegisterName}`);
|
@@ -594,89 +655,141 @@ command.action(async (commandFiltersOrEntries, options) => {
|
|
594
655
|
const locks = {};
|
595
656
|
let inputMaxLen = 10;
|
596
657
|
child.on("message", (e) => {
|
597
|
-
if (
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
658
|
+
if (silent && [
|
659
|
+
"init",
|
660
|
+
"progress",
|
661
|
+
"watchChange"
|
662
|
+
].includes(e.type))
|
663
|
+
return;
|
664
|
+
switch (e.type) {
|
665
|
+
case "init": {
|
666
|
+
const { leafMap, targetsLength } = e.data;
|
667
|
+
const leafs = Array.from(leafMap.entries()).flatMap(
|
668
|
+
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
669
|
+
input,
|
670
|
+
path: path2,
|
671
|
+
conditions
|
672
|
+
}))
|
673
|
+
);
|
674
|
+
let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
|
675
|
+
if (watch) {
|
676
|
+
initMessage += " and watching...";
|
677
|
+
}
|
678
|
+
console.log(initMessage);
|
679
|
+
leafs.forEach(({ input }) => {
|
680
|
+
inputMaxLen = Math.max(inputMaxLen, input.length);
|
681
|
+
});
|
682
|
+
leafs.forEach(({ input, path: path2 }) => {
|
683
|
+
const key = `${input}:${path2}`;
|
684
|
+
if (bars[key])
|
685
|
+
return;
|
686
|
+
bars[key] = multiBars.create(50, 0, {
|
687
|
+
pkgName: manifest.name,
|
688
|
+
input: input.padEnd(inputMaxLen + 5),
|
689
|
+
status: "waiting".padEnd(10)
|
690
|
+
}, {
|
691
|
+
barsize: 20,
|
692
|
+
linewrap: true
|
693
|
+
});
|
694
|
+
});
|
695
|
+
break;
|
696
|
+
}
|
697
|
+
case "progress": {
|
698
|
+
const {
|
606
699
|
path: path2,
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
700
|
+
tags,
|
701
|
+
input,
|
702
|
+
event,
|
703
|
+
message
|
704
|
+
} = e.data;
|
705
|
+
const bar = bars[`${input}:${path2}`];
|
706
|
+
if (!bar)
|
707
|
+
return;
|
708
|
+
const time = times[`${input}:${path2}`];
|
709
|
+
bar.update(
|
710
|
+
{
|
711
|
+
start: 0,
|
712
|
+
resolve: 20,
|
713
|
+
end: 50
|
714
|
+
}[event ?? "start"] ?? 0,
|
715
|
+
{
|
716
|
+
input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
|
717
|
+
status: event?.padEnd(10),
|
718
|
+
message: `${tags?.join(", ")}: ${message}`
|
719
|
+
}
|
720
|
+
);
|
721
|
+
break;
|
613
722
|
}
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
723
|
+
case "watchChange": {
|
724
|
+
const {
|
725
|
+
path: path2,
|
726
|
+
input
|
727
|
+
} = e.data;
|
619
728
|
const key = `${input}:${path2}`;
|
620
|
-
|
729
|
+
const bar = bars[key];
|
730
|
+
if (!bar)
|
621
731
|
return;
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
path: path2,
|
635
|
-
tags,
|
636
|
-
input,
|
637
|
-
event,
|
638
|
-
message
|
639
|
-
} = e.data;
|
640
|
-
const bar = bars[`${input}:${path2}`];
|
641
|
-
if (!bar)
|
642
|
-
return;
|
643
|
-
const time = times[`${input}:${path2}`];
|
644
|
-
bar.update(
|
645
|
-
{
|
646
|
-
start: 0,
|
647
|
-
resolve: 20,
|
648
|
-
end: 50
|
649
|
-
}[event ?? "start"] ?? 0,
|
650
|
-
{
|
651
|
-
input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
|
652
|
-
status: event?.padEnd(10),
|
653
|
-
message: `${tags?.join(", ")}: ${message}`
|
732
|
+
let time = times[key] ?? 1;
|
733
|
+
if (!locks[key]) {
|
734
|
+
time += 1;
|
735
|
+
times[key] = time;
|
736
|
+
setTimeout(() => {
|
737
|
+
locks[key] = false;
|
738
|
+
}, 100);
|
739
|
+
bar.update(0, {
|
740
|
+
input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
|
741
|
+
status: "watching".padEnd(10),
|
742
|
+
message: "watching..."
|
743
|
+
});
|
654
744
|
}
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
745
|
+
locks[key] = true;
|
746
|
+
break;
|
747
|
+
}
|
748
|
+
case "modulesAnalyze": {
|
749
|
+
const {
|
750
|
+
data: {
|
751
|
+
type: type2,
|
752
|
+
path: path2,
|
753
|
+
modules: pkgModules
|
754
|
+
}
|
755
|
+
} = e;
|
756
|
+
pkgModules.forEach((m) => {
|
757
|
+
const newM = {
|
758
|
+
...m,
|
759
|
+
filename: `${manifest.name}/${m.filename}`,
|
760
|
+
label: `${manifest.name}/${m.label}`
|
761
|
+
};
|
762
|
+
const pushOrReplace = (arr) => {
|
763
|
+
const index = arr.findIndex(({ filename }) => filename === newM.filename);
|
764
|
+
if (index === -1) {
|
765
|
+
arr.push(newM);
|
766
|
+
} else {
|
767
|
+
arr[index] = newM;
|
768
|
+
}
|
769
|
+
};
|
770
|
+
pushOrReplace(modules);
|
771
|
+
if (type2 === "esm") {
|
772
|
+
pushOrReplace(esmModules);
|
773
|
+
}
|
774
|
+
if (type2 === "cjs") {
|
775
|
+
pushOrReplace(cjsModules);
|
776
|
+
}
|
677
777
|
});
|
778
|
+
void refreshAnalyzer();
|
779
|
+
void refreshAnalyzer(
|
780
|
+
`/${type2}`,
|
781
|
+
{
|
782
|
+
cjs: cjsModules,
|
783
|
+
esm: esmModules
|
784
|
+
}[type2]
|
785
|
+
);
|
786
|
+
void refreshAnalyzer(`/${type2}/${manifest.name}/${path2.slice(2)}`, pkgModules);
|
787
|
+
break;
|
788
|
+
}
|
789
|
+
case "debug": {
|
790
|
+
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
791
|
+
break;
|
678
792
|
}
|
679
|
-
locks[key] = true;
|
680
793
|
}
|
681
794
|
});
|
682
795
|
await new Promise((resolve, reject) => {
|
@@ -707,6 +820,17 @@ ${errorStr}`)));
|
|
707
820
|
}
|
708
821
|
} finally {
|
709
822
|
multiBars.stop();
|
823
|
+
let message = "The build is complete";
|
824
|
+
if (analyzer) {
|
825
|
+
message += ` and the analyzer is running at http://localhost:${options.port}/ana in ${analyzer.mode} mode.
|
826
|
+
`;
|
827
|
+
message += analyzer.open ? " The browser will open automatically.\n" : "";
|
828
|
+
if (anaPaths.size > 0) {
|
829
|
+
message += `The analyzer has ${anaPaths.size} pages:
|
830
|
+
${Array.from(anaPaths).map((p) => `http://localhost:${options.port}${p}`).join("\n")}`;
|
831
|
+
}
|
832
|
+
}
|
833
|
+
!silent && console.log(message);
|
710
834
|
}
|
711
835
|
});
|
712
836
|
|