jiek 1.1.4 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
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.3";
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",
@@ -350,126 +352,135 @@ const require$1 = node_module.createRequire((typeof document === 'undefined' ? r
350
352
  const description = `
351
353
  Build the package according to the 'exports' field in the package.json.
352
354
  `.trim();
353
- commander.program.command("build").description(description).option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("-v, --verbose", "Display debug logs.").action(async ({
355
+ commander.program.command("build").description(description).option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("--without-js", "Do not output js files.").option("--without-dts", "Do not output dts files.").option("-v, --verbose", "Display debug logs.").action(async ({
354
356
  silent,
355
357
  entries,
356
- verbose
358
+ verbose,
359
+ withoutJs,
360
+ withoutDts
357
361
  }) => {
358
362
  actionRestore();
359
363
  const { build } = loadConfig();
360
364
  silent = silent ?? build?.silent ?? false;
361
- const {
362
- wd,
363
- value = {}
364
- } = await getSelectedProjectsGraph() ?? {};
365
- if (Object.keys(value).length === 0) {
366
- throw new Error("no package found");
367
- }
368
- const wdNodeModules = path__default.default.resolve(wd, "node_modules");
369
- if (!fs__default.default.existsSync(wdNodeModules)) {
370
- fs__default.default.mkdirSync(wdNodeModules);
371
- }
372
- const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
373
- if (!fs__default.default.existsSync(jiekTempDir())) {
374
- fs__default.default.mkdirSync(jiekTempDir());
375
- }
376
- const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
377
365
  const multiBars = new cliProgress.MultiBar({
378
366
  clearOnComplete: false,
379
367
  hideCursor: true,
380
- format: "- {bar} | {status} | {input} | {message}"
368
+ format: "- {bar} | {status} | {pkgName} | {input} | {message}"
381
369
  }, cliProgress.Presets.shades_classic);
382
- let i = 0;
383
- await Promise.all(
384
- Object.entries(value).map(async ([dir, manifest]) => {
385
- const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
386
- const configFile = jiekTempDir(
387
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
388
- );
389
- fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
390
- let prefix = "";
391
- if (tsRegisterName) {
392
- prefix = `node -r ${tsRegisterName} `;
393
- }
394
- const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
395
- const child = execa.execaCommand(command, {
396
- ipc: true,
397
- cwd: dir,
398
- env: {
399
- ...process.env,
400
- JIEK_ROOT: wd,
401
- JIEK_ENTRIES: entries
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} `;
402
397
  }
403
- });
404
- const bars = {};
405
- let inputMaxLen = 10;
406
- child.on("message", (e) => {
407
- if (e.type === "debug")
408
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
409
- });
410
- !silent && child.on("message", (e) => {
411
- if (e.type === "init") {
412
- const { leafMap, targetsLength } = e.data;
413
- const leafs = Array.from(leafMap.entries()).flatMap(
414
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
415
- 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 {
416
446
  path: path2,
417
- conditions
418
- }))
419
- );
420
- console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
421
- leafs.forEach(({ input }) => {
422
- inputMaxLen = Math.max(inputMaxLen, input.length);
423
- });
424
- leafs.forEach(({ input, path: path2 }) => {
425
- const key = `${input}:${path2}`;
426
- if (bars[key])
447
+ tags,
448
+ input,
449
+ event,
450
+ message
451
+ } = e.data;
452
+ const bar = bars[`${input}:${path2}`];
453
+ if (!bar)
427
454
  return;
428
- bars[key] = multiBars.create(50, 0, {
429
- input: input.padEnd(inputMaxLen),
430
- status: "waiting".padEnd(10)
431
- }, {
432
- barsize: 20,
433
- linewrap: true
434
- });
435
- });
436
- }
437
- if (e.type === "progress") {
438
- const {
439
- path: path2,
440
- tags,
441
- input,
442
- event,
443
- message
444
- } = e.data;
445
- const bar = bars[`${input}:${path2}`];
446
- if (!bar)
447
- return;
448
- bar.update(
449
- {
450
- start: 0,
451
- resolve: 20,
452
- end: 50
453
- }[event ?? "start"] ?? 0,
454
- {
455
- input: input.padEnd(inputMaxLen),
456
- status: event?.padEnd(10),
457
- message: `${tags?.join(", ")}: ${message}`
458
- }
459
- );
460
- }
461
- });
462
- await new Promise((resolve, reject) => {
463
- let errorStr = "";
464
- child.stderr?.on("data", (data) => {
465
- 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
+ }
466
468
  });
467
- 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:
468
475
  ${errorStr}`)));
469
- verbose && child.stdout?.pipe(process.stdout);
470
- });
471
- })
472
- ).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(() => {
473
484
  multiBars.stop();
474
485
  });
475
486
  actionDone();
package/dist/cli.d.cts CHANGED
@@ -13,6 +13,7 @@ interface ConfigGenerateContext {
13
13
  pkgIsModule: boolean;
14
14
  conditionals: string[];
15
15
  }
16
+ type OutputControl = boolean | ((context: ConfigGenerateContext) => boolean);
16
17
  interface TemplateOptions {
17
18
  /**
18
19
  * When the user configures type: module, the generated output from entry points that don't
@@ -37,6 +38,8 @@ interface TemplateOptions {
37
38
  dir?: Mapping2ROO<'dir'>;
38
39
  sourcemap?: Mapping2ROO<'sourcemap'>;
39
40
  strict?: Mapping2ROO<'strict'>;
41
+ js?: OutputControl;
42
+ dts?: OutputControl;
40
43
  };
41
44
  plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
42
45
  js: InputPluginOption;
package/dist/cli.d.ts CHANGED
@@ -13,6 +13,7 @@ interface ConfigGenerateContext {
13
13
  pkgIsModule: boolean;
14
14
  conditionals: string[];
15
15
  }
16
+ type OutputControl = boolean | ((context: ConfigGenerateContext) => boolean);
16
17
  interface TemplateOptions {
17
18
  /**
18
19
  * When the user configures type: module, the generated output from entry points that don't
@@ -37,6 +38,8 @@ interface TemplateOptions {
37
38
  dir?: Mapping2ROO<'dir'>;
38
39
  sourcemap?: Mapping2ROO<'sourcemap'>;
39
40
  strict?: Mapping2ROO<'strict'>;
41
+ js?: OutputControl;
42
+ dts?: OutputControl;
40
43
  };
41
44
  plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
42
45
  js: InputPluginOption;
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.3";
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",
@@ -319,126 +321,135 @@ const require = createRequire(import.meta.url);
319
321
  const description = `
320
322
  Build the package according to the 'exports' field in the package.json.
321
323
  `.trim();
322
- program.command("build").description(description).option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("-v, --verbose", "Display debug logs.").action(async ({
324
+ program.command("build").description(description).option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("--without-js", "Do not output js files.").option("--without-dts", "Do not output dts files.").option("-v, --verbose", "Display debug logs.").action(async ({
323
325
  silent,
324
326
  entries,
325
- verbose
327
+ verbose,
328
+ withoutJs,
329
+ withoutDts
326
330
  }) => {
327
331
  actionRestore();
328
332
  const { build } = loadConfig();
329
333
  silent = silent ?? build?.silent ?? false;
330
- const {
331
- wd,
332
- value = {}
333
- } = await getSelectedProjectsGraph() ?? {};
334
- if (Object.keys(value).length === 0) {
335
- throw new Error("no package found");
336
- }
337
- const wdNodeModules = path.resolve(wd, "node_modules");
338
- if (!fs.existsSync(wdNodeModules)) {
339
- fs.mkdirSync(wdNodeModules);
340
- }
341
- const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
342
- if (!fs.existsSync(jiekTempDir())) {
343
- fs.mkdirSync(jiekTempDir());
344
- }
345
- const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
346
334
  const multiBars = new MultiBar({
347
335
  clearOnComplete: false,
348
336
  hideCursor: true,
349
- format: "- {bar} | {status} | {input} | {message}"
337
+ format: "- {bar} | {status} | {pkgName} | {input} | {message}"
350
338
  }, Presets.shades_classic);
351
- let i = 0;
352
- await Promise.all(
353
- Object.entries(value).map(async ([dir, manifest]) => {
354
- const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
355
- const configFile = jiekTempDir(
356
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
357
- );
358
- fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
359
- let prefix = "";
360
- if (tsRegisterName) {
361
- prefix = `node -r ${tsRegisterName} `;
362
- }
363
- const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
364
- const child = execaCommand(command, {
365
- ipc: true,
366
- cwd: dir,
367
- env: {
368
- ...process.env,
369
- JIEK_ROOT: wd,
370
- JIEK_ENTRIES: entries
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} `;
371
366
  }
372
- });
373
- const bars = {};
374
- let inputMaxLen = 10;
375
- child.on("message", (e) => {
376
- if (e.type === "debug")
377
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
378
- });
379
- !silent && child.on("message", (e) => {
380
- if (e.type === "init") {
381
- const { leafMap, targetsLength } = e.data;
382
- const leafs = Array.from(leafMap.entries()).flatMap(
383
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
384
- 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 {
385
415
  path: path2,
386
- conditions
387
- }))
388
- );
389
- console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
390
- leafs.forEach(({ input }) => {
391
- inputMaxLen = Math.max(inputMaxLen, input.length);
392
- });
393
- leafs.forEach(({ input, path: path2 }) => {
394
- const key = `${input}:${path2}`;
395
- if (bars[key])
416
+ tags,
417
+ input,
418
+ event,
419
+ message
420
+ } = e.data;
421
+ const bar = bars[`${input}:${path2}`];
422
+ if (!bar)
396
423
  return;
397
- bars[key] = multiBars.create(50, 0, {
398
- input: input.padEnd(inputMaxLen),
399
- status: "waiting".padEnd(10)
400
- }, {
401
- barsize: 20,
402
- linewrap: true
403
- });
404
- });
405
- }
406
- if (e.type === "progress") {
407
- const {
408
- path: path2,
409
- tags,
410
- input,
411
- event,
412
- message
413
- } = e.data;
414
- const bar = bars[`${input}:${path2}`];
415
- if (!bar)
416
- return;
417
- bar.update(
418
- {
419
- start: 0,
420
- resolve: 20,
421
- end: 50
422
- }[event ?? "start"] ?? 0,
423
- {
424
- input: input.padEnd(inputMaxLen),
425
- status: event?.padEnd(10),
426
- message: `${tags?.join(", ")}: ${message}`
427
- }
428
- );
429
- }
430
- });
431
- await new Promise((resolve, reject) => {
432
- let errorStr = "";
433
- child.stderr?.on("data", (data) => {
434
- 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
+ }
435
437
  });
436
- 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:
437
444
  ${errorStr}`)));
438
- verbose && child.stdout?.pipe(process.stdout);
439
- });
440
- })
441
- ).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(() => {
442
453
  multiBars.stop();
443
454
  });
444
455
  actionDone();