jiek 1.1.5 → 1.1.6

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/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
- async function getSelectedProjectsGraph() {
95
- let filter = commander.program.getOptionValue("filter");
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.4";
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
- let i = 0;
385
- await Promise.all(
386
- Object.entries(value).map(async ([dir, manifest]) => {
387
- const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
388
- const configFile = jiekTempDir(
389
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
390
- );
391
- fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
392
- let prefix = "";
393
- if (tsRegisterName) {
394
- prefix = `node -r ${tsRegisterName} `;
395
- }
396
- const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
397
- const child = execa.execaCommand(command, {
398
- ipc: true,
399
- cwd: dir,
400
- env: {
401
- ...process.env,
402
- JIEK_ROOT: wd,
403
- JIEK_ENTRIES: entries,
404
- JIEK_WITHOUT_JS: String(withoutJs),
405
- JIEK_WITHOUT_DTS: String(withoutDts)
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
- const bars = {};
409
- let inputMaxLen = 10;
410
- child.on("message", (e) => {
411
- if (e.type === "debug")
412
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
413
- });
414
- !silent && child.on("message", (e) => {
415
- if (e.type === "init") {
416
- const { leafMap, targetsLength } = e.data;
417
- const leafs = Array.from(leafMap.entries()).flatMap(
418
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
419
- input,
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
- conditions
422
- }))
423
- );
424
- console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
425
- leafs.forEach(({ input }) => {
426
- inputMaxLen = Math.max(inputMaxLen, input.length);
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
- bars[key] = multiBars.create(50, 0, {
433
- input: input.padEnd(inputMaxLen),
434
- status: "waiting".padEnd(10)
435
- }, {
436
- barsize: 20,
437
- linewrap: true
438
- });
439
- });
440
- }
441
- if (e.type === "progress") {
442
- const {
443
- path: path2,
444
- tags,
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
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
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
- verbose && child.stdout?.pipe(process.stdout);
474
- });
475
- })
476
- ).finally(() => {
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
- async function getSelectedProjectsGraph() {
64
- let filter = program.getOptionValue("filter");
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.4";
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
- let i = 0;
354
- await Promise.all(
355
- Object.entries(value).map(async ([dir, manifest]) => {
356
- const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
357
- const configFile = jiekTempDir(
358
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
359
- );
360
- fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
361
- let prefix = "";
362
- if (tsRegisterName) {
363
- prefix = `node -r ${tsRegisterName} `;
364
- }
365
- const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
366
- const child = execaCommand(command, {
367
- ipc: true,
368
- cwd: dir,
369
- env: {
370
- ...process.env,
371
- JIEK_ROOT: wd,
372
- JIEK_ENTRIES: entries,
373
- JIEK_WITHOUT_JS: String(withoutJs),
374
- JIEK_WITHOUT_DTS: String(withoutDts)
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
- const bars = {};
378
- let inputMaxLen = 10;
379
- child.on("message", (e) => {
380
- if (e.type === "debug")
381
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
382
- });
383
- !silent && child.on("message", (e) => {
384
- if (e.type === "init") {
385
- const { leafMap, targetsLength } = e.data;
386
- const leafs = Array.from(leafMap.entries()).flatMap(
387
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
388
- input,
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
- conditions
391
- }))
392
- );
393
- console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
394
- leafs.forEach(({ input }) => {
395
- inputMaxLen = Math.max(inputMaxLen, input.length);
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
- bars[key] = multiBars.create(50, 0, {
402
- input: input.padEnd(inputMaxLen),
403
- status: "waiting".padEnd(10)
404
- }, {
405
- barsize: 20,
406
- linewrap: true
407
- });
408
- });
409
- }
410
- if (e.type === "progress") {
411
- const {
412
- path: path2,
413
- tags,
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
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
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
- verbose && child.stdout?.pipe(process.stdout);
443
- });
444
- })
445
- ).finally(() => {
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();