jiek 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/jiek.js +1 -1
- package/dist/cli.cjs +116 -109
- package/dist/cli.js +116 -109
- package/dist/cli.min.cjs +4 -4
- package/dist/cli.min.js +3 -3
- package/dist/rollup/index.cjs +1 -1
- package/dist/rollup/index.js +1 -1
- package/dist/rollup/index.min.cjs +4 -4
- package/dist/rollup/index.min.js +3 -3
- package/package.json +3 -3
- package/src/commands/build.ts +120 -111
- package/src/utils/filterSupport.ts +9 -4
package/bin/jiek.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import { existsSync } from 'node:fs'
|
3
|
-
import { resolve, dirname } from 'node:path'
|
4
3
|
import { createRequire } from 'node:module'
|
4
|
+
import { dirname, resolve } from 'node:path'
|
5
5
|
|
6
6
|
const __dirname = dirname(import.meta.url.replace('file://', ''))
|
7
7
|
if (existsSync(resolve(__dirname, '../.jiek-dev-tag'))) {
|
package/dist/cli.cjs
CHANGED
@@ -89,10 +89,12 @@ try {
|
|
89
89
|
} catch {
|
90
90
|
}
|
91
91
|
if (type$1 !== "") {
|
92
|
-
commander.program.option("-f, --filter <filter>", "filter packages");
|
92
|
+
commander.program.option("-f, --filter <filter>", "filter packages, support fuzzy match and array. e.g. -f core,utils");
|
93
93
|
}
|
94
|
-
|
95
|
-
|
94
|
+
function filterPackagesGraph(filters) {
|
95
|
+
return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
|
96
|
+
}
|
97
|
+
async function getSelectedProjectsGraph(filter = commander.program.getOptionValue("filter")) {
|
96
98
|
const root = getRoot();
|
97
99
|
const { wd, notWorkspace } = getWD();
|
98
100
|
if (!notWorkspace && type$1 === "pnpm") {
|
@@ -141,7 +143,7 @@ async function getSelectedProjectsGraph() {
|
|
141
143
|
|
142
144
|
var name = "jiek";
|
143
145
|
var type = "module";
|
144
|
-
var version = "1.1.
|
146
|
+
var version = "1.1.5";
|
145
147
|
var description$1 = "YiJie's personal kits.";
|
146
148
|
var bin = {
|
147
149
|
jiek: "bin/jiek.js",
|
@@ -360,120 +362,125 @@ commander.program.command("build").description(description).option("-s, --silent
|
|
360
362
|
actionRestore();
|
361
363
|
const { build } = loadConfig();
|
362
364
|
silent = silent ?? build?.silent ?? false;
|
363
|
-
const {
|
364
|
-
wd,
|
365
|
-
value = {}
|
366
|
-
} = await getSelectedProjectsGraph() ?? {};
|
367
|
-
if (Object.keys(value).length === 0) {
|
368
|
-
throw new Error("no package found");
|
369
|
-
}
|
370
|
-
const wdNodeModules = path__default.default.resolve(wd, "node_modules");
|
371
|
-
if (!fs__default.default.existsSync(wdNodeModules)) {
|
372
|
-
fs__default.default.mkdirSync(wdNodeModules);
|
373
|
-
}
|
374
|
-
const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
|
375
|
-
if (!fs__default.default.existsSync(jiekTempDir())) {
|
376
|
-
fs__default.default.mkdirSync(jiekTempDir());
|
377
|
-
}
|
378
|
-
const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
379
365
|
const multiBars = new cliProgress.MultiBar({
|
380
366
|
clearOnComplete: false,
|
381
367
|
hideCursor: true,
|
382
|
-
format: "- {bar} | {status} | {input} | {message}"
|
368
|
+
format: "- {bar} | {status} | {pkgName} | {input} | {message}"
|
383
369
|
}, cliProgress.Presets.shades_classic);
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
370
|
+
const buildPackage = async ({
|
371
|
+
wd,
|
372
|
+
value = {}
|
373
|
+
}) => {
|
374
|
+
if (Object.keys(value).length === 0) {
|
375
|
+
throw new Error("no package found");
|
376
|
+
}
|
377
|
+
const wdNodeModules = path__default.default.resolve(wd, "node_modules");
|
378
|
+
if (!fs__default.default.existsSync(wdNodeModules)) {
|
379
|
+
fs__default.default.mkdirSync(wdNodeModules);
|
380
|
+
}
|
381
|
+
const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
|
382
|
+
if (!fs__default.default.existsSync(jiekTempDir())) {
|
383
|
+
fs__default.default.mkdirSync(jiekTempDir());
|
384
|
+
}
|
385
|
+
const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
386
|
+
let i = 0;
|
387
|
+
await Promise.all(
|
388
|
+
Object.entries(value).map(async ([dir, manifest]) => {
|
389
|
+
const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
|
390
|
+
const configFile = jiekTempDir(
|
391
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
392
|
+
);
|
393
|
+
fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
394
|
+
let prefix = "";
|
395
|
+
if (tsRegisterName) {
|
396
|
+
prefix = `node -r ${tsRegisterName} `;
|
406
397
|
}
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
398
|
+
const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
|
399
|
+
const child = execa.execaCommand(command, {
|
400
|
+
ipc: true,
|
401
|
+
cwd: dir,
|
402
|
+
env: {
|
403
|
+
...process.env,
|
404
|
+
JIEK_ROOT: wd,
|
405
|
+
JIEK_ENTRIES: entries,
|
406
|
+
JIEK_WITHOUT_JS: String(withoutJs),
|
407
|
+
JIEK_WITHOUT_DTS: String(withoutDts)
|
408
|
+
}
|
409
|
+
});
|
410
|
+
const bars = {};
|
411
|
+
let inputMaxLen = 10;
|
412
|
+
child.on("message", (e) => {
|
413
|
+
if (e.type === "debug")
|
414
|
+
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
415
|
+
});
|
416
|
+
!silent && child.on("message", (e) => {
|
417
|
+
if (e.type === "init") {
|
418
|
+
const { leafMap, targetsLength } = e.data;
|
419
|
+
const leafs = Array.from(leafMap.entries()).flatMap(
|
420
|
+
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
421
|
+
input,
|
422
|
+
path: path2,
|
423
|
+
conditions
|
424
|
+
}))
|
425
|
+
);
|
426
|
+
console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
|
427
|
+
leafs.forEach(({ input }) => {
|
428
|
+
inputMaxLen = Math.max(inputMaxLen, input.length);
|
429
|
+
});
|
430
|
+
leafs.forEach(({ input, path: path2 }) => {
|
431
|
+
const key = `${input}:${path2}`;
|
432
|
+
if (bars[key])
|
433
|
+
return;
|
434
|
+
bars[key] = multiBars.create(50, 0, {
|
435
|
+
pkgName: manifest.name,
|
436
|
+
input: input.padEnd(inputMaxLen),
|
437
|
+
status: "waiting".padEnd(10)
|
438
|
+
}, {
|
439
|
+
barsize: 20,
|
440
|
+
linewrap: true
|
441
|
+
});
|
442
|
+
});
|
443
|
+
}
|
444
|
+
if (e.type === "progress") {
|
445
|
+
const {
|
420
446
|
path: path2,
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
leafs.forEach(({ input, path: path2 }) => {
|
429
|
-
const key = `${input}:${path2}`;
|
430
|
-
if (bars[key])
|
447
|
+
tags,
|
448
|
+
input,
|
449
|
+
event,
|
450
|
+
message
|
451
|
+
} = e.data;
|
452
|
+
const bar = bars[`${input}:${path2}`];
|
453
|
+
if (!bar)
|
431
454
|
return;
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
input,
|
446
|
-
event,
|
447
|
-
message
|
448
|
-
} = e.data;
|
449
|
-
const bar = bars[`${input}:${path2}`];
|
450
|
-
if (!bar)
|
451
|
-
return;
|
452
|
-
bar.update(
|
453
|
-
{
|
454
|
-
start: 0,
|
455
|
-
resolve: 20,
|
456
|
-
end: 50
|
457
|
-
}[event ?? "start"] ?? 0,
|
458
|
-
{
|
459
|
-
input: input.padEnd(inputMaxLen),
|
460
|
-
status: event?.padEnd(10),
|
461
|
-
message: `${tags?.join(", ")}: ${message}`
|
462
|
-
}
|
463
|
-
);
|
464
|
-
}
|
465
|
-
});
|
466
|
-
await new Promise((resolve, reject) => {
|
467
|
-
let errorStr = "";
|
468
|
-
child.stderr?.on("data", (data) => {
|
469
|
-
errorStr += data;
|
455
|
+
bar.update(
|
456
|
+
{
|
457
|
+
start: 0,
|
458
|
+
resolve: 20,
|
459
|
+
end: 50
|
460
|
+
}[event ?? "start"] ?? 0,
|
461
|
+
{
|
462
|
+
input: input.padEnd(inputMaxLen),
|
463
|
+
status: event?.padEnd(10),
|
464
|
+
message: `${tags?.join(", ")}: ${message}`
|
465
|
+
}
|
466
|
+
);
|
467
|
+
}
|
470
468
|
});
|
471
|
-
|
469
|
+
await new Promise((resolve, reject) => {
|
470
|
+
let errorStr = "";
|
471
|
+
child.stderr?.on("data", (data) => {
|
472
|
+
errorStr += data;
|
473
|
+
});
|
474
|
+
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
|
472
475
|
${errorStr}`)));
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
476
|
+
verbose && child.stdout?.pipe(process.stdout);
|
477
|
+
});
|
478
|
+
})
|
479
|
+
);
|
480
|
+
};
|
481
|
+
const filters = commander.program.getOptionValue("filter").split(",");
|
482
|
+
const packages = await filterPackagesGraph(filters);
|
483
|
+
await Promise.all(packages.map(buildPackage)).finally(() => {
|
477
484
|
multiBars.stop();
|
478
485
|
});
|
479
486
|
actionDone();
|
package/dist/cli.js
CHANGED
@@ -58,10 +58,12 @@ try {
|
|
58
58
|
} catch {
|
59
59
|
}
|
60
60
|
if (type$1 !== "") {
|
61
|
-
program.option("-f, --filter <filter>", "filter packages");
|
61
|
+
program.option("-f, --filter <filter>", "filter packages, support fuzzy match and array. e.g. -f core,utils");
|
62
62
|
}
|
63
|
-
|
64
|
-
|
63
|
+
function filterPackagesGraph(filters) {
|
64
|
+
return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
|
65
|
+
}
|
66
|
+
async function getSelectedProjectsGraph(filter = program.getOptionValue("filter")) {
|
65
67
|
const root = getRoot();
|
66
68
|
const { wd, notWorkspace } = getWD();
|
67
69
|
if (!notWorkspace && type$1 === "pnpm") {
|
@@ -110,7 +112,7 @@ async function getSelectedProjectsGraph() {
|
|
110
112
|
|
111
113
|
var name = "jiek";
|
112
114
|
var type = "module";
|
113
|
-
var version = "1.1.
|
115
|
+
var version = "1.1.5";
|
114
116
|
var description$1 = "YiJie's personal kits.";
|
115
117
|
var bin = {
|
116
118
|
jiek: "bin/jiek.js",
|
@@ -329,120 +331,125 @@ program.command("build").description(description).option("-s, --silent", "Don't
|
|
329
331
|
actionRestore();
|
330
332
|
const { build } = loadConfig();
|
331
333
|
silent = silent ?? build?.silent ?? false;
|
332
|
-
const {
|
333
|
-
wd,
|
334
|
-
value = {}
|
335
|
-
} = await getSelectedProjectsGraph() ?? {};
|
336
|
-
if (Object.keys(value).length === 0) {
|
337
|
-
throw new Error("no package found");
|
338
|
-
}
|
339
|
-
const wdNodeModules = path.resolve(wd, "node_modules");
|
340
|
-
if (!fs.existsSync(wdNodeModules)) {
|
341
|
-
fs.mkdirSync(wdNodeModules);
|
342
|
-
}
|
343
|
-
const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
|
344
|
-
if (!fs.existsSync(jiekTempDir())) {
|
345
|
-
fs.mkdirSync(jiekTempDir());
|
346
|
-
}
|
347
|
-
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
348
334
|
const multiBars = new MultiBar({
|
349
335
|
clearOnComplete: false,
|
350
336
|
hideCursor: true,
|
351
|
-
format: "- {bar} | {status} | {input} | {message}"
|
337
|
+
format: "- {bar} | {status} | {pkgName} | {input} | {message}"
|
352
338
|
}, Presets.shades_classic);
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
339
|
+
const buildPackage = async ({
|
340
|
+
wd,
|
341
|
+
value = {}
|
342
|
+
}) => {
|
343
|
+
if (Object.keys(value).length === 0) {
|
344
|
+
throw new Error("no package found");
|
345
|
+
}
|
346
|
+
const wdNodeModules = path.resolve(wd, "node_modules");
|
347
|
+
if (!fs.existsSync(wdNodeModules)) {
|
348
|
+
fs.mkdirSync(wdNodeModules);
|
349
|
+
}
|
350
|
+
const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
|
351
|
+
if (!fs.existsSync(jiekTempDir())) {
|
352
|
+
fs.mkdirSync(jiekTempDir());
|
353
|
+
}
|
354
|
+
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
355
|
+
let i = 0;
|
356
|
+
await Promise.all(
|
357
|
+
Object.entries(value).map(async ([dir, manifest]) => {
|
358
|
+
const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
|
359
|
+
const configFile = jiekTempDir(
|
360
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
361
|
+
);
|
362
|
+
fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
363
|
+
let prefix = "";
|
364
|
+
if (tsRegisterName) {
|
365
|
+
prefix = `node -r ${tsRegisterName} `;
|
375
366
|
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
367
|
+
const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
|
368
|
+
const child = execaCommand(command, {
|
369
|
+
ipc: true,
|
370
|
+
cwd: dir,
|
371
|
+
env: {
|
372
|
+
...process.env,
|
373
|
+
JIEK_ROOT: wd,
|
374
|
+
JIEK_ENTRIES: entries,
|
375
|
+
JIEK_WITHOUT_JS: String(withoutJs),
|
376
|
+
JIEK_WITHOUT_DTS: String(withoutDts)
|
377
|
+
}
|
378
|
+
});
|
379
|
+
const bars = {};
|
380
|
+
let inputMaxLen = 10;
|
381
|
+
child.on("message", (e) => {
|
382
|
+
if (e.type === "debug")
|
383
|
+
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
384
|
+
});
|
385
|
+
!silent && child.on("message", (e) => {
|
386
|
+
if (e.type === "init") {
|
387
|
+
const { leafMap, targetsLength } = e.data;
|
388
|
+
const leafs = Array.from(leafMap.entries()).flatMap(
|
389
|
+
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
390
|
+
input,
|
391
|
+
path: path2,
|
392
|
+
conditions
|
393
|
+
}))
|
394
|
+
);
|
395
|
+
console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
|
396
|
+
leafs.forEach(({ input }) => {
|
397
|
+
inputMaxLen = Math.max(inputMaxLen, input.length);
|
398
|
+
});
|
399
|
+
leafs.forEach(({ input, path: path2 }) => {
|
400
|
+
const key = `${input}:${path2}`;
|
401
|
+
if (bars[key])
|
402
|
+
return;
|
403
|
+
bars[key] = multiBars.create(50, 0, {
|
404
|
+
pkgName: manifest.name,
|
405
|
+
input: input.padEnd(inputMaxLen),
|
406
|
+
status: "waiting".padEnd(10)
|
407
|
+
}, {
|
408
|
+
barsize: 20,
|
409
|
+
linewrap: true
|
410
|
+
});
|
411
|
+
});
|
412
|
+
}
|
413
|
+
if (e.type === "progress") {
|
414
|
+
const {
|
389
415
|
path: path2,
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
leafs.forEach(({ input, path: path2 }) => {
|
398
|
-
const key = `${input}:${path2}`;
|
399
|
-
if (bars[key])
|
416
|
+
tags,
|
417
|
+
input,
|
418
|
+
event,
|
419
|
+
message
|
420
|
+
} = e.data;
|
421
|
+
const bar = bars[`${input}:${path2}`];
|
422
|
+
if (!bar)
|
400
423
|
return;
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
input,
|
415
|
-
event,
|
416
|
-
message
|
417
|
-
} = e.data;
|
418
|
-
const bar = bars[`${input}:${path2}`];
|
419
|
-
if (!bar)
|
420
|
-
return;
|
421
|
-
bar.update(
|
422
|
-
{
|
423
|
-
start: 0,
|
424
|
-
resolve: 20,
|
425
|
-
end: 50
|
426
|
-
}[event ?? "start"] ?? 0,
|
427
|
-
{
|
428
|
-
input: input.padEnd(inputMaxLen),
|
429
|
-
status: event?.padEnd(10),
|
430
|
-
message: `${tags?.join(", ")}: ${message}`
|
431
|
-
}
|
432
|
-
);
|
433
|
-
}
|
434
|
-
});
|
435
|
-
await new Promise((resolve, reject) => {
|
436
|
-
let errorStr = "";
|
437
|
-
child.stderr?.on("data", (data) => {
|
438
|
-
errorStr += data;
|
424
|
+
bar.update(
|
425
|
+
{
|
426
|
+
start: 0,
|
427
|
+
resolve: 20,
|
428
|
+
end: 50
|
429
|
+
}[event ?? "start"] ?? 0,
|
430
|
+
{
|
431
|
+
input: input.padEnd(inputMaxLen),
|
432
|
+
status: event?.padEnd(10),
|
433
|
+
message: `${tags?.join(", ")}: ${message}`
|
434
|
+
}
|
435
|
+
);
|
436
|
+
}
|
439
437
|
});
|
440
|
-
|
438
|
+
await new Promise((resolve, reject) => {
|
439
|
+
let errorStr = "";
|
440
|
+
child.stderr?.on("data", (data) => {
|
441
|
+
errorStr += data;
|
442
|
+
});
|
443
|
+
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
|
441
444
|
${errorStr}`)));
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
445
|
+
verbose && child.stdout?.pipe(process.stdout);
|
446
|
+
});
|
447
|
+
})
|
448
|
+
);
|
449
|
+
};
|
450
|
+
const filters = program.getOptionValue("filter").split(",");
|
451
|
+
const packages = await filterPackagesGraph(filters);
|
452
|
+
await Promise.all(packages.map(buildPackage)).finally(() => {
|
446
453
|
multiBars.stop();
|
447
454
|
});
|
448
455
|
actionDone();
|