jiek 1.1.10 → 1.1.12

Sign up to get free protection for your applications and to get access to all the features.
package/dist/cli.cjs CHANGED
@@ -149,7 +149,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
149
149
 
150
150
  var name = "jiek";
151
151
  var type = "module";
152
- var version = "1.1.10";
152
+ var version = "1.1.12";
153
153
  var description$1 = "YiJie's personal kits.";
154
154
  var bin = {
155
155
  jiek: "bin/jiek.js",
@@ -391,6 +391,8 @@ module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null
391
391
  const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
392
392
  const description = `
393
393
  Build the package according to the 'exports' field in the package.json.
394
+ If you want to rewrite the rollup command options, you can pass the options after '--'.
395
+ e.g. \`jiek build -- --watch\`
394
396
  `.trim();
395
397
  function parseBoolean(v) {
396
398
  if (v === void 0)
@@ -412,6 +414,19 @@ commander.program.command("build").description(description).option("-o, --outdir
412
414
  noClean,
413
415
  onlyMin
414
416
  }) => {
417
+ let shouldPassThrough = false;
418
+ const passThroughOptions = commander.program.parseOptions(process.argv).unknown.reduce(
419
+ (acc, value) => {
420
+ if (shouldPassThrough) {
421
+ acc.push(value);
422
+ }
423
+ if (value === "--") {
424
+ shouldPassThrough = true;
425
+ }
426
+ return acc;
427
+ },
428
+ []
429
+ );
415
430
  actionRestore();
416
431
  const { build } = loadConfig();
417
432
  silent = silent ?? build?.silent ?? false;
@@ -467,7 +482,7 @@ commander.program.command("build").description(description).option("-o, --outdir
467
482
  if (tsRegisterName) {
468
483
  prefix = `node -r ${tsRegisterName} `;
469
484
  }
470
- const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
485
+ const command = [`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, ...passThroughOptions].join(" ");
471
486
  const child = execa.execaCommand(command, {
472
487
  ipc: true,
473
488
  cwd: dir,
@@ -478,6 +493,8 @@ commander.program.command("build").description(description).option("-o, --outdir
478
493
  }
479
494
  });
480
495
  const bars = {};
496
+ const times = {};
497
+ const locks = {};
481
498
  let inputMaxLen = 10;
482
499
  child.on("message", (e) => {
483
500
  if (e.type === "debug")
@@ -503,7 +520,7 @@ commander.program.command("build").description(description).option("-o, --outdir
503
520
  return;
504
521
  bars[key] = multiBars.create(50, 0, {
505
522
  pkgName: manifest.name,
506
- input: input.padEnd(inputMaxLen),
523
+ input: input.padEnd(inputMaxLen + 5),
507
524
  status: "waiting".padEnd(10)
508
525
  }, {
509
526
  barsize: 20,
@@ -522,6 +539,7 @@ commander.program.command("build").description(description).option("-o, --outdir
522
539
  const bar = bars[`${input}:${path2}`];
523
540
  if (!bar)
524
541
  return;
542
+ const time = times[`${input}:${path2}`];
525
543
  bar.update(
526
544
  {
527
545
  start: 0,
@@ -529,12 +547,36 @@ commander.program.command("build").description(description).option("-o, --outdir
529
547
  end: 50
530
548
  }[event ?? "start"] ?? 0,
531
549
  {
532
- input: input.padEnd(inputMaxLen),
550
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
533
551
  status: event?.padEnd(10),
534
552
  message: `${tags?.join(", ")}: ${message}`
535
553
  }
536
554
  );
537
555
  }
556
+ if (e.type === "watchChange") {
557
+ const {
558
+ path: path2,
559
+ input
560
+ } = e.data;
561
+ const key = `${input}:${path2}`;
562
+ const bar = bars[key];
563
+ if (!bar)
564
+ return;
565
+ let time = times[key] ?? 1;
566
+ if (!locks[key]) {
567
+ time += 1;
568
+ times[key] = time;
569
+ setTimeout(() => {
570
+ locks[key] = false;
571
+ }, 100);
572
+ bar.update(0, {
573
+ input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
574
+ status: "watching".padEnd(10),
575
+ message: "watching..."
576
+ });
577
+ }
578
+ locks[key] = true;
579
+ }
538
580
  });
539
581
  await new Promise((resolve, reject) => {
540
582
  let errorStr = "";
package/dist/cli.js CHANGED
@@ -118,7 +118,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
118
118
 
119
119
  var name = "jiek";
120
120
  var type = "module";
121
- var version = "1.1.10";
121
+ var version = "1.1.12";
122
122
  var description$1 = "YiJie's personal kits.";
123
123
  var bin = {
124
124
  jiek: "bin/jiek.js",
@@ -360,6 +360,8 @@ module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null
360
360
  const require = createRequire(import.meta.url);
361
361
  const description = `
362
362
  Build the package according to the 'exports' field in the package.json.
363
+ If you want to rewrite the rollup command options, you can pass the options after '--'.
364
+ e.g. \`jiek build -- --watch\`
363
365
  `.trim();
364
366
  function parseBoolean(v) {
365
367
  if (v === void 0)
@@ -381,6 +383,19 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
381
383
  noClean,
382
384
  onlyMin
383
385
  }) => {
386
+ let shouldPassThrough = false;
387
+ const passThroughOptions = program.parseOptions(process.argv).unknown.reduce(
388
+ (acc, value) => {
389
+ if (shouldPassThrough) {
390
+ acc.push(value);
391
+ }
392
+ if (value === "--") {
393
+ shouldPassThrough = true;
394
+ }
395
+ return acc;
396
+ },
397
+ []
398
+ );
384
399
  actionRestore();
385
400
  const { build } = loadConfig();
386
401
  silent = silent ?? build?.silent ?? false;
@@ -436,7 +451,7 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
436
451
  if (tsRegisterName) {
437
452
  prefix = `node -r ${tsRegisterName} `;
438
453
  }
439
- const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
454
+ const command = [`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, ...passThroughOptions].join(" ");
440
455
  const child = execaCommand(command, {
441
456
  ipc: true,
442
457
  cwd: dir,
@@ -447,6 +462,8 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
447
462
  }
448
463
  });
449
464
  const bars = {};
465
+ const times = {};
466
+ const locks = {};
450
467
  let inputMaxLen = 10;
451
468
  child.on("message", (e) => {
452
469
  if (e.type === "debug")
@@ -472,7 +489,7 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
472
489
  return;
473
490
  bars[key] = multiBars.create(50, 0, {
474
491
  pkgName: manifest.name,
475
- input: input.padEnd(inputMaxLen),
492
+ input: input.padEnd(inputMaxLen + 5),
476
493
  status: "waiting".padEnd(10)
477
494
  }, {
478
495
  barsize: 20,
@@ -491,6 +508,7 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
491
508
  const bar = bars[`${input}:${path2}`];
492
509
  if (!bar)
493
510
  return;
511
+ const time = times[`${input}:${path2}`];
494
512
  bar.update(
495
513
  {
496
514
  start: 0,
@@ -498,12 +516,36 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
498
516
  end: 50
499
517
  }[event ?? "start"] ?? 0,
500
518
  {
501
- input: input.padEnd(inputMaxLen),
519
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
502
520
  status: event?.padEnd(10),
503
521
  message: `${tags?.join(", ")}: ${message}`
504
522
  }
505
523
  );
506
524
  }
525
+ if (e.type === "watchChange") {
526
+ const {
527
+ path: path2,
528
+ input
529
+ } = e.data;
530
+ const key = `${input}:${path2}`;
531
+ const bar = bars[key];
532
+ if (!bar)
533
+ return;
534
+ let time = times[key] ?? 1;
535
+ if (!locks[key]) {
536
+ time += 1;
537
+ times[key] = time;
538
+ setTimeout(() => {
539
+ locks[key] = false;
540
+ }, 100);
541
+ bar.update(0, {
542
+ input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
543
+ status: "watching".padEnd(10),
544
+ message: "watching..."
545
+ });
546
+ }
547
+ locks[key] = true;
548
+ }
507
549
  });
508
550
  await new Promise((resolve, reject) => {
509
551
  let errorStr = "";
@@ -4652,6 +4652,7 @@ const generateConfigs = (context, options = {}) => {
4652
4652
  const tsOutputSuffix = jsOutputSuffix.replace(/(\.[cm]?)js$/, ".d$1ts");
4653
4653
  const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output);
4654
4654
  const rollupOptions = [];
4655
+ const commonPlugins = [];
4655
4656
  if (jsOutput && !WITHOUT_JS) {
4656
4657
  rollupOptions.push({
4657
4658
  input: inputObj,
@@ -4668,6 +4669,7 @@ const generateConfigs = (context, options = {}) => {
4668
4669
  })
4669
4670
  ],
4670
4671
  plugins: [
4672
+ ...commonPlugins,
4671
4673
  pluginNodeResolve.nodeResolve({ exportConditions }),
4672
4674
  import('rollup-plugin-postcss').then(
4673
4675
  ({ default: postcss }) => postcss({
@@ -4704,6 +4706,7 @@ const generateConfigs = (context, options = {}) => {
4704
4706
  }
4705
4707
  ],
4706
4708
  plugins: [
4709
+ ...commonPlugins,
4707
4710
  pluginNodeResolve.nodeResolve({ exportConditions }),
4708
4711
  skip({ patterns: [STYLE_REGEXP] }),
4709
4712
  rollupPluginDts.dts({
@@ -4733,6 +4736,18 @@ const generateConfigs = (context, options = {}) => {
4733
4736
  ]
4734
4737
  });
4735
4738
  }
4739
+ rollupOptions[0].plugins = [
4740
+ {
4741
+ name: "jiek-plugin-watcher",
4742
+ watchChange: (id) => execa.sendMessage(
4743
+ {
4744
+ type: "watchChange",
4745
+ data: { id, name: JIEK_NAME, path: path$1, input }
4746
+ }
4747
+ )
4748
+ },
4749
+ ...rollupOptions[0].plugins
4750
+ ];
4736
4751
  return rollupOptions;
4737
4752
  };
4738
4753
  function template(packageJSON) {
@@ -4637,6 +4637,7 @@ const generateConfigs = (context, options = {}) => {
4637
4637
  const tsOutputSuffix = jsOutputSuffix.replace(/(\.[cm]?)js$/, ".d$1ts");
4638
4638
  const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output);
4639
4639
  const rollupOptions = [];
4640
+ const commonPlugins = [];
4640
4641
  if (jsOutput && !WITHOUT_JS) {
4641
4642
  rollupOptions.push({
4642
4643
  input: inputObj,
@@ -4653,6 +4654,7 @@ const generateConfigs = (context, options = {}) => {
4653
4654
  })
4654
4655
  ],
4655
4656
  plugins: [
4657
+ ...commonPlugins,
4656
4658
  nodeResolve({ exportConditions }),
4657
4659
  import('rollup-plugin-postcss').then(
4658
4660
  ({ default: postcss }) => postcss({
@@ -4689,6 +4691,7 @@ const generateConfigs = (context, options = {}) => {
4689
4691
  }
4690
4692
  ],
4691
4693
  plugins: [
4694
+ ...commonPlugins,
4692
4695
  nodeResolve({ exportConditions }),
4693
4696
  skip({ patterns: [STYLE_REGEXP] }),
4694
4697
  dts({
@@ -4718,6 +4721,18 @@ const generateConfigs = (context, options = {}) => {
4718
4721
  ]
4719
4722
  });
4720
4723
  }
4724
+ rollupOptions[0].plugins = [
4725
+ {
4726
+ name: "jiek-plugin-watcher",
4727
+ watchChange: (id) => sendMessage(
4728
+ {
4729
+ type: "watchChange",
4730
+ data: { id, name: JIEK_NAME, path, input }
4731
+ }
4732
+ )
4733
+ },
4734
+ ...rollupOptions[0].plugins
4735
+ ];
4721
4736
  return rollupOptions;
4722
4737
  };
4723
4738
  function template(packageJSON) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "1.1.10",
4
+ "version": "1.1.12",
5
5
  "description": "YiJie's personal kits.",
6
6
  "bin": {
7
7
  "jiek": "bin/jiek.js",
@@ -35,6 +35,8 @@ const require = createRequire(import.meta.url)
35
35
 
36
36
  const description = `
37
37
  Build the package according to the 'exports' field in the package.json.
38
+ If you want to rewrite the rollup command options, you can pass the options after '--'.
39
+ e.g. \`jiek build -- --watch\`
38
40
  `.trim()
39
41
 
40
42
  interface BuildOptions extends Record<string, unknown> {
@@ -91,6 +93,23 @@ program
91
93
  noClean,
92
94
  onlyMin: onlyMin
93
95
  }: BuildOptions) => {
96
+ let shouldPassThrough = false
97
+
98
+ const passThroughOptions = program
99
+ .parseOptions(process.argv)
100
+ .unknown
101
+ .reduce(
102
+ (acc, value) => {
103
+ if (shouldPassThrough) {
104
+ acc.push(value)
105
+ }
106
+ if (value === '--') {
107
+ shouldPassThrough = true
108
+ }
109
+ return acc
110
+ },
111
+ [] as string[]
112
+ )
94
113
  actionRestore()
95
114
  const { build } = loadConfig()
96
115
  silent = silent ?? build?.silent ?? false
@@ -154,7 +173,7 @@ program
154
173
  if (tsRegisterName) {
155
174
  prefix = `node -r ${tsRegisterName} `
156
175
  }
157
- const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`
176
+ const command = [`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, ...passThroughOptions].join(' ')
158
177
  const child = execaCommand(command, {
159
178
  ipc: true,
160
179
  cwd: dir,
@@ -165,6 +184,8 @@ program
165
184
  }
166
185
  })
167
186
  const bars: Record<string, ReturnType<typeof multiBars.create>> = {}
187
+ const times: Record<string, number> = {}
188
+ const locks: Record<string, boolean> = {}
168
189
  let inputMaxLen = 10
169
190
  child.on('message', (e: RollupProgressEvent) => {
170
191
  if (e.type === 'debug') console.log(...(Array.isArray(e.data) ? e.data : [e.data]))
@@ -190,7 +211,7 @@ program
190
211
  if (bars[key]) return
191
212
  bars[key] = multiBars.create(50, 0, {
192
213
  pkgName: manifest.name,
193
- input: input.padEnd(inputMaxLen),
214
+ input: input.padEnd(inputMaxLen + 5),
194
215
  status: 'waiting'.padEnd(10)
195
216
  }, {
196
217
  barsize: 20,
@@ -208,6 +229,7 @@ program
208
229
  } = e.data
209
230
  const bar = bars[`${input}:${path}`]
210
231
  if (!bar) return
232
+ const time = times[`${input}:${path}`]
211
233
  bar.update(
212
234
  {
213
235
  start: 0,
@@ -215,12 +237,39 @@ program
215
237
  end: 50
216
238
  }[event ?? 'start'] ?? 0,
217
239
  {
218
- input: input.padEnd(inputMaxLen),
240
+ input: (
241
+ time
242
+ ? `${input}(x${time.toString().padStart(2, '0')})`
243
+ : input
244
+ ).padEnd(inputMaxLen + 5),
219
245
  status: event?.padEnd(10),
220
246
  message: `${tags?.join(', ')}: ${message}`
221
247
  }
222
248
  )
223
249
  }
250
+ if (e.type === 'watchChange') {
251
+ const {
252
+ path,
253
+ input
254
+ } = e.data
255
+ const key = `${input}:${path}`
256
+ const bar = bars[key]
257
+ if (!bar) return
258
+ let time = times[key] ?? 1
259
+ if (!locks[key]) {
260
+ time += 1
261
+ times[key] = time
262
+ setTimeout(() => {
263
+ locks[key] = false
264
+ }, 100)
265
+ bar.update(0, {
266
+ input: `${input}(x${time.toString().padStart(2, '0')})`.padEnd(inputMaxLen + 5),
267
+ status: 'watching'.padEnd(10),
268
+ message: 'watching...'
269
+ })
270
+ }
271
+ locks[key] = true
272
+ }
224
273
  })
225
274
  await new Promise<void>((resolve, reject) => {
226
275
  let errorStr = ''
@@ -65,6 +65,15 @@ export type RollupProgressEvent =
65
65
  targetsLength: number
66
66
  }
67
67
  }
68
+ | {
69
+ type: 'watchChange'
70
+ data: {
71
+ id: string
72
+ name: string
73
+ path: string
74
+ input: string
75
+ }
76
+ }
68
77
  | {
69
78
  type: 'debug'
70
79
  data: unknown
@@ -11,7 +11,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'
11
11
  import terser from '@rollup/plugin-terser'
12
12
  import { sendMessage } from 'execa'
13
13
  import { isMatch } from 'micromatch'
14
- import type { InputPluginOption, OutputOptions, OutputPlugin, RollupOptions } from 'rollup'
14
+ import type { InputPluginOption, OutputOptions, OutputPlugin, Plugin, RollupOptions } from 'rollup'
15
15
  import esbuild from 'rollup-plugin-esbuild'
16
16
  import ts from 'typescript'
17
17
 
@@ -245,6 +245,8 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
245
245
  const tsOutputSuffix = jsOutputSuffix.replace(/(\.[cm]?)js$/, '.d$1ts')
246
246
  const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output)
247
247
  const rollupOptions: RollupOptions[] = []
248
+
249
+ const commonPlugins: Plugin[] = []
248
250
  if (jsOutput && !WITHOUT_JS) {
249
251
  rollupOptions.push({
250
252
  input: inputObj,
@@ -277,6 +279,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
277
279
  })
278
280
  ],
279
281
  plugins: [
282
+ ...commonPlugins,
280
283
  nodeResolve({ exportConditions }),
281
284
  import('rollup-plugin-postcss')
282
285
  .then(({ default: postcss }) =>
@@ -303,6 +306,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
303
306
  ]
304
307
  })
305
308
  }
309
+
306
310
  if (dtsOutput && !WITHOUT_DTS) {
307
311
  rollupOptions.push({
308
312
  input: inputObj,
@@ -328,6 +332,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
328
332
  }
329
333
  ],
330
334
  plugins: [
335
+ ...commonPlugins,
331
336
  nodeResolve({ exportConditions }),
332
337
  skip({ patterns: [STYLE_REGEXP] }),
333
338
  dts({
@@ -358,6 +363,20 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
358
363
  ]
359
364
  })
360
365
  }
366
+ // only push the first one a watcher plugin
367
+ rollupOptions[0].plugins = [
368
+ {
369
+ name: 'jiek-plugin-watcher',
370
+ watchChange: (id) =>
371
+ sendMessage(
372
+ {
373
+ type: 'watchChange',
374
+ data: { id, name: JIEK_NAME!, path, input }
375
+ } satisfies RollupProgressEvent
376
+ )
377
+ },
378
+ ...(rollupOptions[0].plugins as any)
379
+ ]
361
380
  return rollupOptions
362
381
  }
363
382