jiek 1.1.11 → 1.1.13

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,47 +1,35 @@
1
1
  # Jiek
2
2
 
3
- 为什么没有一个在 `monorepo` 下面足够现代又足够简单的构建工具呢?恭喜你发现了宝藏~
3
+ | zh-Hans | [en](./.about/en/README.md) |
4
4
 
5
- ## 为什么不使用 X?
5
+ [![npm version](https://img.shields.io/npm/v/jiek)](https://npmjs.com/package/jiek)
6
+ [![npm downloads](https://img.shields.io/npm/dm/jiek)](https://npm.chart.dev/jiek)
6
7
 
7
- - Q: [`tsup`](https://github.com/egoist/tsup)
8
- - A: `tsup` 基于 esbuild 与 rollup,是他们上层的一个 no-config 构建工具
9
- - 关于类型编译的支持并不足够智能,无法自动找到对应的 `tsconfig.json`,在 `monorepo` 下面会遇到相关的问题
10
- - 虽然它是声称 no-config,但是在多入口,以及其他的复杂情况下的产物时,仍需要编写相关配置
11
- - 偏向于使用 cli 中的相关参数,以及配置文件,不够自然
12
- - 在 `monorepo` 的场景下使用起来进行开发时,在复杂依赖关系的情况下需要管理复杂的构建依赖关系
13
- - 老牌工具,符合时代背景下的相关需求;沉淀时间久,功能相对来说较为完善;生态较为丰富,网络上的资源较多
14
-
15
- - Q: [`unbuild`](https://github.com/unjs/unbuild)
16
- - A: 该工具的底座技术与 `tsup` 也是极为一致,与其不同的便是他的 config 实际上是可以基于 package.json 生成的。
17
- - 该工具与 `tsup` 一样,存在对:「`monorepo` 支持不好」、「不支持 Project Reference」这些问题
18
- - 使用的时候你需要根据模版声明输出,再反向根据约定好的规则去创建相关的入口文件,不够自然,也不够灵活过于死板
19
- - 不过该工具在无配置化上也前进了较大一步,对于一些简单的项目来说,是一个不错的选择
20
-
21
- - Q: [`bunchee`](https://github.com/huozhi/bunchee)
22
- - A: 换成了 `swc` + `rollup`,嗯。
23
- - 同样在 `monorepo` 下有着相关问题,同样没办法处理 Project Reference
24
- - 定义了一定的 exports 产物到输入文件的规则,能实现一定的灵活性,但是编写导出规则时会过于冗长
25
- - 没办法在 monorepo 的复杂依赖关系场景中去减轻开发负担
8
+ > 基于 `package.json` 元数据并适用于 `Monorepo` 的**轻便**工具库编译管理套件。
26
9
 
27
- ## 安装
10
+ - 自动推断:基于 `package.json` 的相关字段自动推断出构建规则
11
+ - `exports`:根据入口文件推断构建目标与类型
12
+ - `type: module`:当开启时智能决定输出文件后缀,不需要考虑 `cjs` 与 `esm` 的适配问题
13
+ - `dependencies`、`peerDependencies`、`optionalDependencies`:自动将符合规则的依赖标记为 `external`
14
+ - `devDependencies`:将标记为开发依赖的 bundle 进对应的最终产物之中
15
+ - 工作空间友好:支持在 pnpm 下的工作空间
16
+ - 类型定义文件:支持聚合生成类型定义文件
17
+ - 监听模式:适配 rollup 的监听模式
18
+ - 发布适配:支持同构生成 `package.json` 等相关字段
28
19
 
29
- 目前只支持 pnpm,因为 workspace 的相关机制在 pnpm 的支持是最好的(主要也没时间支持别的工具了)。
20
+ ## 安装
30
21
 
31
22
  ```bash
32
- pnpm install -D jiek
23
+ npm i -D jiek
24
+ # or
25
+ pnpm i -D jiek
26
+ # or
27
+ yarn add -D jiek
33
28
  ```
34
29
 
35
- ## Features
36
-
37
- 有啥好用的?
38
-
39
- - 简化你的导出规则,不需要去写一些能够自动化生成的代码
40
- - 自然而然的对你的输入进行构建,按照统一的规则你可以几乎不用去写多余的配置
41
- - 在构建的时候不再依赖预构建目标的依赖或者是整体的全量构建,每一次构建只需要关注自己的目标
42
- - 预集成了一套完整的构建工具链,自动根据需求激活相关的插件进行工作
30
+ ## 使用
43
31
 
44
- ### build
32
+ ### 构建
45
33
 
46
34
  写构建脚本一直不是一件简单的事情,那么怎么把一个复杂的事情变简单呢?我们可以回到需求的本身,那就是「定义什么便构建什么」。在这里我们用自然的方式来定义构建产物,而不需要去多写一行多余的代码。
47
35
 
@@ -125,7 +113,16 @@ export default defineConfig({
125
113
  - [ ] 支持更多的 PM
126
114
  - [ ] 工作空间构建流
127
115
  - [ ] 依赖分析工具
128
- - 本次构建哪些在 pacakge 中声明的依赖没用用到,可以移除(提供配置关闭该警告)
116
+ - 本次构建哪些在 package 中声明的依赖没用用到,可以移除(提供配置关闭该警告)
129
117
  - 针对构建产物的依赖关系生成关系图(可配置颗粒度为文件或者导出方法)
130
118
 
131
- ### publish
119
+ ### 发布
120
+
121
+ ## 为什么不使用 X?
122
+
123
+ 在这里与 `jiek` 类似的工具有:[`tsup`](https://github.com/egoist/tsup)、[`unbuild`](https://github.com/unjs/unbuild)、[`bunchee`](https://github.com/huozhi/bunchee)、[`pkgroll`](https://github.com/privatenumber/pkgroll)、[`tsdown`](https://github.com/sxzz/tsdown)。但是他们都有着一些共同问题没有解决,我们来看看:
124
+
125
+ - `monorepo` 的支持存在一定的问题,在依赖工作空间其他的包时必须重新编译相关依赖
126
+ - 编写入口文件的规则过于繁琐,不够自然
127
+ - 无法处理 `tsconfig.json` 中的 `Project Reference` 相关问题
128
+ - 根据`conditions`
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.11";
152
+ var version = "1.1.13";
153
153
  var description$1 = "YiJie's personal kits.";
154
154
  var bin = {
155
155
  jiek: "bin/jiek.js",
@@ -176,7 +176,7 @@ var imports = {
176
176
  };
177
177
  var dependencies = {
178
178
  "@jiek/pkger": "workspace:^",
179
- "@jiek/rollup-plugin-dts": "^6.1.2",
179
+ "@jiek/rollup-plugin-dts": "^6.2.1",
180
180
  "@jiek/utils": "workspace:^",
181
181
  "@rollup/plugin-commonjs": "^28.0.0",
182
182
  "@rollup/plugin-json": "^6.0.1",
@@ -265,14 +265,6 @@ var pkg = {
265
265
 
266
266
  commander.program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
267
267
 
268
- let resolve;
269
- function actionDone() {
270
- resolve();
271
- }
272
- function actionRestore() {
273
- new Promise((r) => resolve = r);
274
- }
275
-
276
268
  const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
277
269
  function packageIsExist(name) {
278
270
  try {
@@ -399,7 +391,10 @@ function parseBoolean(v) {
399
391
  return true;
400
392
  return Boolean(v);
401
393
  }
402
- commander.program.command("build").description(description).option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
394
+ commander.program.command("build").description(description).option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option(
395
+ "-e, --entries <ENTRIES>",
396
+ "Specify the build entry-points of the package.json's 'exports' field.(support glob)"
397
+ ).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
403
398
  "-om, --onlyMin",
404
399
  "Only output minify files, but dts files will still be output, it only replaces the js files.",
405
400
  parseBoolean
@@ -407,6 +402,7 @@ commander.program.command("build").description(description).option("-o, --outdir
407
402
  outdir,
408
403
  silent,
409
404
  entries,
405
+ external,
410
406
  verbose,
411
407
  noJs: withoutJs,
412
408
  noDts: withoutDts,
@@ -427,7 +423,6 @@ commander.program.command("build").description(description).option("-o, --outdir
427
423
  },
428
424
  []
429
425
  );
430
- actionRestore();
431
426
  const { build } = loadConfig();
432
427
  silent = silent ?? build?.silent ?? false;
433
428
  if (withoutMin && onlyMin) {
@@ -441,6 +436,7 @@ commander.program.command("build").description(description).option("-o, --outdir
441
436
  JIEK_OUT_DIR: outdir,
442
437
  JIEK_CLEAN: String(!noClean),
443
438
  JIEK_ENTRIES: entries,
439
+ JIEK_EXTERNAL: external,
444
440
  JIEK_WITHOUT_JS: String(withoutJs),
445
441
  JIEK_WITHOUT_DTS: String(withoutDts),
446
442
  JIEK_WITHOUT_MINIFY: String(withoutMin),
@@ -493,6 +489,8 @@ commander.program.command("build").description(description).option("-o, --outdir
493
489
  }
494
490
  });
495
491
  const bars = {};
492
+ const times = {};
493
+ const locks = {};
496
494
  let inputMaxLen = 10;
497
495
  child.on("message", (e) => {
498
496
  if (e.type === "debug")
@@ -518,7 +516,7 @@ commander.program.command("build").description(description).option("-o, --outdir
518
516
  return;
519
517
  bars[key] = multiBars.create(50, 0, {
520
518
  pkgName: manifest.name,
521
- input: input.padEnd(inputMaxLen),
519
+ input: input.padEnd(inputMaxLen + 5),
522
520
  status: "waiting".padEnd(10)
523
521
  }, {
524
522
  barsize: 20,
@@ -537,6 +535,7 @@ commander.program.command("build").description(description).option("-o, --outdir
537
535
  const bar = bars[`${input}:${path2}`];
538
536
  if (!bar)
539
537
  return;
538
+ const time = times[`${input}:${path2}`];
540
539
  bar.update(
541
540
  {
542
541
  start: 0,
@@ -544,12 +543,36 @@ commander.program.command("build").description(description).option("-o, --outdir
544
543
  end: 50
545
544
  }[event ?? "start"] ?? 0,
546
545
  {
547
- input: input.padEnd(inputMaxLen),
546
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
548
547
  status: event?.padEnd(10),
549
548
  message: `${tags?.join(", ")}: ${message}`
550
549
  }
551
550
  );
552
551
  }
552
+ if (e.type === "watchChange") {
553
+ const {
554
+ path: path2,
555
+ input
556
+ } = e.data;
557
+ const key = `${input}:${path2}`;
558
+ const bar = bars[key];
559
+ if (!bar)
560
+ return;
561
+ let time = times[key] ?? 1;
562
+ if (!locks[key]) {
563
+ time += 1;
564
+ times[key] = time;
565
+ setTimeout(() => {
566
+ locks[key] = false;
567
+ }, 100);
568
+ bar.update(0, {
569
+ input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
570
+ status: "watching".padEnd(10),
571
+ message: "watching..."
572
+ });
573
+ }
574
+ locks[key] = true;
575
+ }
553
576
  });
554
577
  await new Promise((resolve, reject) => {
555
578
  let errorStr = "";
@@ -574,7 +597,6 @@ ${errorStr}`)));
574
597
  } finally {
575
598
  multiBars.stop();
576
599
  }
577
- actionDone();
578
600
  });
579
601
 
580
602
  var utils$1 = {};
@@ -4959,6 +4981,14 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
4959
4981
  fs__default.default.writeFileSync(readmeFilePath, readmeContent);
4960
4982
  });
4961
4983
 
4984
+ let resolve;
4985
+ function actionDone() {
4986
+ resolve();
4987
+ }
4988
+ function actionRestore() {
4989
+ new Promise((r) => resolve = r);
4990
+ }
4991
+
4962
4992
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4963
4993
  const {
4964
4994
  JIEK_OUT_DIR
package/dist/cli.d.cts CHANGED
@@ -41,6 +41,10 @@ interface TemplateOptions {
41
41
  js?: OutputControl;
42
42
  dts?: OutputControl;
43
43
  };
44
+ /**
45
+ * Set the external dependencies of the package.
46
+ */
47
+ external?: (string | RegExp)[];
44
48
  plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
45
49
  js: InputPluginOption;
46
50
  dts?: InputPluginOption;
package/dist/cli.d.ts CHANGED
@@ -41,6 +41,10 @@ interface TemplateOptions {
41
41
  js?: OutputControl;
42
42
  dts?: OutputControl;
43
43
  };
44
+ /**
45
+ * Set the external dependencies of the package.
46
+ */
47
+ external?: (string | RegExp)[];
44
48
  plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
45
49
  js: InputPluginOption;
46
50
  dts?: InputPluginOption;
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.11";
121
+ var version = "1.1.13";
122
122
  var description$1 = "YiJie's personal kits.";
123
123
  var bin = {
124
124
  jiek: "bin/jiek.js",
@@ -145,7 +145,7 @@ var imports = {
145
145
  };
146
146
  var dependencies = {
147
147
  "@jiek/pkger": "workspace:^",
148
- "@jiek/rollup-plugin-dts": "^6.1.2",
148
+ "@jiek/rollup-plugin-dts": "^6.2.1",
149
149
  "@jiek/utils": "workspace:^",
150
150
  "@rollup/plugin-commonjs": "^28.0.0",
151
151
  "@rollup/plugin-json": "^6.0.1",
@@ -234,14 +234,6 @@ var pkg = {
234
234
 
235
235
  program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
236
236
 
237
- let resolve;
238
- function actionDone() {
239
- resolve();
240
- }
241
- function actionRestore() {
242
- new Promise((r) => resolve = r);
243
- }
244
-
245
237
  const require$2 = createRequire(import.meta.url);
246
238
  function packageIsExist(name) {
247
239
  try {
@@ -368,7 +360,10 @@ function parseBoolean(v) {
368
360
  return true;
369
361
  return Boolean(v);
370
362
  }
371
- program.command("build").description(description).option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
363
+ program.command("build").description(description).option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option(
364
+ "-e, --entries <ENTRIES>",
365
+ "Specify the build entry-points of the package.json's 'exports' field.(support glob)"
366
+ ).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
372
367
  "-om, --onlyMin",
373
368
  "Only output minify files, but dts files will still be output, it only replaces the js files.",
374
369
  parseBoolean
@@ -376,6 +371,7 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
376
371
  outdir,
377
372
  silent,
378
373
  entries,
374
+ external,
379
375
  verbose,
380
376
  noJs: withoutJs,
381
377
  noDts: withoutDts,
@@ -396,7 +392,6 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
396
392
  },
397
393
  []
398
394
  );
399
- actionRestore();
400
395
  const { build } = loadConfig();
401
396
  silent = silent ?? build?.silent ?? false;
402
397
  if (withoutMin && onlyMin) {
@@ -410,6 +405,7 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
410
405
  JIEK_OUT_DIR: outdir,
411
406
  JIEK_CLEAN: String(!noClean),
412
407
  JIEK_ENTRIES: entries,
408
+ JIEK_EXTERNAL: external,
413
409
  JIEK_WITHOUT_JS: String(withoutJs),
414
410
  JIEK_WITHOUT_DTS: String(withoutDts),
415
411
  JIEK_WITHOUT_MINIFY: String(withoutMin),
@@ -462,6 +458,8 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
462
458
  }
463
459
  });
464
460
  const bars = {};
461
+ const times = {};
462
+ const locks = {};
465
463
  let inputMaxLen = 10;
466
464
  child.on("message", (e) => {
467
465
  if (e.type === "debug")
@@ -487,7 +485,7 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
487
485
  return;
488
486
  bars[key] = multiBars.create(50, 0, {
489
487
  pkgName: manifest.name,
490
- input: input.padEnd(inputMaxLen),
488
+ input: input.padEnd(inputMaxLen + 5),
491
489
  status: "waiting".padEnd(10)
492
490
  }, {
493
491
  barsize: 20,
@@ -506,6 +504,7 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
506
504
  const bar = bars[`${input}:${path2}`];
507
505
  if (!bar)
508
506
  return;
507
+ const time = times[`${input}:${path2}`];
509
508
  bar.update(
510
509
  {
511
510
  start: 0,
@@ -513,12 +512,36 @@ program.command("build").description(description).option("-o, --outdir <OUTDIR>"
513
512
  end: 50
514
513
  }[event ?? "start"] ?? 0,
515
514
  {
516
- input: input.padEnd(inputMaxLen),
515
+ input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
517
516
  status: event?.padEnd(10),
518
517
  message: `${tags?.join(", ")}: ${message}`
519
518
  }
520
519
  );
521
520
  }
521
+ if (e.type === "watchChange") {
522
+ const {
523
+ path: path2,
524
+ input
525
+ } = e.data;
526
+ const key = `${input}:${path2}`;
527
+ const bar = bars[key];
528
+ if (!bar)
529
+ return;
530
+ let time = times[key] ?? 1;
531
+ if (!locks[key]) {
532
+ time += 1;
533
+ times[key] = time;
534
+ setTimeout(() => {
535
+ locks[key] = false;
536
+ }, 100);
537
+ bar.update(0, {
538
+ input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
539
+ status: "watching".padEnd(10),
540
+ message: "watching..."
541
+ });
542
+ }
543
+ locks[key] = true;
544
+ }
522
545
  });
523
546
  await new Promise((resolve, reject) => {
524
547
  let errorStr = "";
@@ -543,7 +566,6 @@ ${errorStr}`)));
543
566
  } finally {
544
567
  multiBars.stop();
545
568
  }
546
- actionDone();
547
569
  });
548
570
 
549
571
  var utils$1 = {};
@@ -4928,6 +4950,14 @@ program.command("init [name]").option("-t, --template <template>", "the package.
4928
4950
  fs.writeFileSync(readmeFilePath, readmeContent);
4929
4951
  });
4930
4952
 
4953
+ let resolve;
4954
+ function actionDone() {
4955
+ resolve();
4956
+ }
4957
+ function actionRestore() {
4958
+ new Promise((r) => resolve = r);
4959
+ }
4960
+
4931
4961
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4932
4962
  const {
4933
4963
  JIEK_OUT_DIR
package/dist/index.d.cts CHANGED
@@ -41,6 +41,10 @@ interface TemplateOptions {
41
41
  js?: OutputControl;
42
42
  dts?: OutputControl;
43
43
  };
44
+ /**
45
+ * Set the external dependencies of the package.
46
+ */
47
+ external?: (string | RegExp)[];
44
48
  plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
45
49
  js: InputPluginOption;
46
50
  dts?: InputPluginOption;
package/dist/index.d.ts CHANGED
@@ -41,6 +41,10 @@ interface TemplateOptions {
41
41
  js?: OutputControl;
42
42
  dts?: OutputControl;
43
43
  };
44
+ /**
45
+ * Set the external dependencies of the package.
46
+ */
47
+ external?: (string | RegExp)[];
44
48
  plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
45
49
  js: InputPluginOption;
46
50
  dts?: InputPluginOption;
@@ -4504,12 +4504,15 @@ const {
4504
4504
  JIEK_ROOT,
4505
4505
  JIEK_NAME,
4506
4506
  JIEK_ENTRIES,
4507
+ JIEK_EXTERNAL,
4507
4508
  JIEK_WITHOUT_JS,
4508
4509
  JIEK_WITHOUT_DTS,
4509
4510
  JIEK_WITHOUT_MINIFY,
4510
4511
  JIEK_NO_CLEAN,
4511
4512
  JIEK_ONLY_MINIFY
4512
4513
  } = process.env;
4514
+ const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({ "index": "." })[e] ?? e);
4515
+ const commandExternal = JIEK_EXTERNAL?.split(",").map((e) => e.trim()).map((e) => new RegExp(`^${e}$`)) ?? [];
4513
4516
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir.getWorkspaceDir();
4514
4517
  const COMMON_OPTIONS = {};
4515
4518
  const COMMON_PLUGINS = [
@@ -4601,10 +4604,11 @@ const generateConfigs = (context, options = {}) => {
4601
4604
  name,
4602
4605
  input,
4603
4606
  output,
4604
- external,
4607
+ external: inputExternal,
4605
4608
  pkgIsModule,
4606
4609
  conditionals
4607
4610
  } = context;
4611
+ const external = [...inputExternal, ...options.external ?? [], ...commandExternal];
4608
4612
  const isModule = conditionals.includes("import");
4609
4613
  const isCommonJS = conditionals.includes("require");
4610
4614
  const isBrowser = conditionals.includes("browser");
@@ -4612,12 +4616,22 @@ const generateConfigs = (context, options = {}) => {
4612
4616
  resolveWorkspacePath("tsconfig.json"),
4613
4617
  resolveWorkspacePath("tsconfig.dts.json")
4614
4618
  ];
4619
+ const buildTSConfigPaths = [
4620
+ ...dtsTSConfigPaths,
4621
+ resolveWorkspacePath("tsconfig.build.json")
4622
+ ];
4615
4623
  let dtsTSConfigPath;
4616
4624
  dtsTSConfigPaths.forEach((p) => {
4617
4625
  if (fs__default.default.existsSync(p) && fs__default.default.statSync(p).isFile()) {
4618
4626
  dtsTSConfigPath = p;
4619
4627
  }
4620
4628
  });
4629
+ let buildTSConfigPath;
4630
+ buildTSConfigPaths.forEach((p) => {
4631
+ if (fs__default.default.existsSync(p) && fs__default.default.statSync(p).isFile()) {
4632
+ buildTSConfigPath = p;
4633
+ }
4634
+ });
4621
4635
  let compilerOptions = {};
4622
4636
  if (dtsTSConfigPath) {
4623
4637
  const jsonCompilerOptions = getCompilerOptionsByFilePath(dtsTSConfigPath, path.resolve(input));
@@ -4652,7 +4666,9 @@ const generateConfigs = (context, options = {}) => {
4652
4666
  const tsOutputSuffix = jsOutputSuffix.replace(/(\.[cm]?)js$/, ".d$1ts");
4653
4667
  const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output);
4654
4668
  const rollupOptions = [];
4669
+ const commonPlugins = [];
4655
4670
  if (jsOutput && !WITHOUT_JS) {
4671
+ const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
4656
4672
  rollupOptions.push({
4657
4673
  input: inputObj,
4658
4674
  external,
@@ -4662,12 +4678,13 @@ const generateConfigs = (context, options = {}) => {
4662
4678
  name,
4663
4679
  interop: "auto",
4664
4680
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4665
- sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap,
4681
+ sourcemap,
4666
4682
  format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4667
4683
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
4668
4684
  })
4669
4685
  ],
4670
4686
  plugins: [
4687
+ ...commonPlugins,
4671
4688
  pluginNodeResolve.nodeResolve({ exportConditions }),
4672
4689
  import('rollup-plugin-postcss').then(
4673
4690
  ({ default: postcss }) => postcss({
@@ -4676,7 +4693,8 @@ const generateConfigs = (context, options = {}) => {
4676
4693
  })
4677
4694
  ).catch(() => void 0),
4678
4695
  esbuild__default.default({
4679
- tsconfig: dtsTSConfigPath
4696
+ sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4697
+ tsconfig: buildTSConfigPath
4680
4698
  }),
4681
4699
  commonjs__default.default(),
4682
4700
  progress({
@@ -4704,12 +4722,12 @@ const generateConfigs = (context, options = {}) => {
4704
4722
  }
4705
4723
  ],
4706
4724
  plugins: [
4725
+ ...commonPlugins,
4707
4726
  pluginNodeResolve.nodeResolve({ exportConditions }),
4708
4727
  skip({ patterns: [STYLE_REGEXP] }),
4709
4728
  rollupPluginDts.dts({
4710
4729
  respectExternal: true,
4711
4730
  compilerOptions: {
4712
- ...compilerOptions,
4713
4731
  // temp directory, it not affect the output
4714
4732
  // but if the user not set it and `declaration`, inputs can't generate any dts files when the input relative imports of `package.json`
4715
4733
  outDir: "dist",
@@ -4719,7 +4737,8 @@ const generateConfigs = (context, options = {}) => {
4719
4737
  // Expected '{', got 'type' (Note that you need plugins to import files that are not JavaScript)
4720
4738
  // https://github.com/Swatinem/rollup-plugin-dts/issues/96
4721
4739
  noEmit: false
4722
- }
4740
+ },
4741
+ tsconfig: dtsTSConfigPath
4723
4742
  }),
4724
4743
  progress({
4725
4744
  onEvent: (event, message) => execa.sendMessage(
@@ -4733,6 +4752,18 @@ const generateConfigs = (context, options = {}) => {
4733
4752
  ]
4734
4753
  });
4735
4754
  }
4755
+ rollupOptions[0].plugins = [
4756
+ {
4757
+ name: "jiek-plugin-watcher",
4758
+ watchChange: (id) => execa.sendMessage(
4759
+ {
4760
+ type: "watchChange",
4761
+ data: { id, name: JIEK_NAME, path: path$1, input }
4762
+ }
4763
+ )
4764
+ },
4765
+ ...rollupOptions[0].plugins
4766
+ ];
4736
4767
  return rollupOptions;
4737
4768
  };
4738
4769
  function template(packageJSON) {
@@ -4742,9 +4773,6 @@ function template(packageJSON) {
4742
4773
  throw new Error("package.json name is required");
4743
4774
  if (!entrypoints$1)
4744
4775
  throw new Error("package.json exports is required");
4745
- const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({
4746
- "index": "."
4747
- })[e] ?? e);
4748
4776
  const packageName = pascalCase(name);
4749
4777
  const external = externalResolver(packageJSON);
4750
4778
  const [filteredResolvedEntrypoints, exports] = getExports({
@@ -4489,12 +4489,15 @@ const {
4489
4489
  JIEK_ROOT,
4490
4490
  JIEK_NAME,
4491
4491
  JIEK_ENTRIES,
4492
+ JIEK_EXTERNAL,
4492
4493
  JIEK_WITHOUT_JS,
4493
4494
  JIEK_WITHOUT_DTS,
4494
4495
  JIEK_WITHOUT_MINIFY,
4495
4496
  JIEK_NO_CLEAN,
4496
4497
  JIEK_ONLY_MINIFY
4497
4498
  } = process.env;
4499
+ const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({ "index": "." })[e] ?? e);
4500
+ const commandExternal = JIEK_EXTERNAL?.split(",").map((e) => e.trim()).map((e) => new RegExp(`^${e}$`)) ?? [];
4498
4501
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir();
4499
4502
  const COMMON_OPTIONS = {};
4500
4503
  const COMMON_PLUGINS = [
@@ -4586,10 +4589,11 @@ const generateConfigs = (context, options = {}) => {
4586
4589
  name,
4587
4590
  input,
4588
4591
  output,
4589
- external,
4592
+ external: inputExternal,
4590
4593
  pkgIsModule,
4591
4594
  conditionals
4592
4595
  } = context;
4596
+ const external = [...inputExternal, ...options.external ?? [], ...commandExternal];
4593
4597
  const isModule = conditionals.includes("import");
4594
4598
  const isCommonJS = conditionals.includes("require");
4595
4599
  const isBrowser = conditionals.includes("browser");
@@ -4597,12 +4601,22 @@ const generateConfigs = (context, options = {}) => {
4597
4601
  resolveWorkspacePath("tsconfig.json"),
4598
4602
  resolveWorkspacePath("tsconfig.dts.json")
4599
4603
  ];
4604
+ const buildTSConfigPaths = [
4605
+ ...dtsTSConfigPaths,
4606
+ resolveWorkspacePath("tsconfig.build.json")
4607
+ ];
4600
4608
  let dtsTSConfigPath;
4601
4609
  dtsTSConfigPaths.forEach((p) => {
4602
4610
  if (fs.existsSync(p) && fs.statSync(p).isFile()) {
4603
4611
  dtsTSConfigPath = p;
4604
4612
  }
4605
4613
  });
4614
+ let buildTSConfigPath;
4615
+ buildTSConfigPaths.forEach((p) => {
4616
+ if (fs.existsSync(p) && fs.statSync(p).isFile()) {
4617
+ buildTSConfigPath = p;
4618
+ }
4619
+ });
4606
4620
  let compilerOptions = {};
4607
4621
  if (dtsTSConfigPath) {
4608
4622
  const jsonCompilerOptions = getCompilerOptionsByFilePath(dtsTSConfigPath, resolve(input));
@@ -4637,7 +4651,9 @@ const generateConfigs = (context, options = {}) => {
4637
4651
  const tsOutputSuffix = jsOutputSuffix.replace(/(\.[cm]?)js$/, ".d$1ts");
4638
4652
  const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output);
4639
4653
  const rollupOptions = [];
4654
+ const commonPlugins = [];
4640
4655
  if (jsOutput && !WITHOUT_JS) {
4656
+ const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
4641
4657
  rollupOptions.push({
4642
4658
  input: inputObj,
4643
4659
  external,
@@ -4647,12 +4663,13 @@ const generateConfigs = (context, options = {}) => {
4647
4663
  name,
4648
4664
  interop: "auto",
4649
4665
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4650
- sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap,
4666
+ sourcemap,
4651
4667
  format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4652
4668
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
4653
4669
  })
4654
4670
  ],
4655
4671
  plugins: [
4672
+ ...commonPlugins,
4656
4673
  nodeResolve({ exportConditions }),
4657
4674
  import('rollup-plugin-postcss').then(
4658
4675
  ({ default: postcss }) => postcss({
@@ -4661,7 +4678,8 @@ const generateConfigs = (context, options = {}) => {
4661
4678
  })
4662
4679
  ).catch(() => void 0),
4663
4680
  esbuild({
4664
- tsconfig: dtsTSConfigPath
4681
+ sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4682
+ tsconfig: buildTSConfigPath
4665
4683
  }),
4666
4684
  commonjs(),
4667
4685
  progress({
@@ -4689,12 +4707,12 @@ const generateConfigs = (context, options = {}) => {
4689
4707
  }
4690
4708
  ],
4691
4709
  plugins: [
4710
+ ...commonPlugins,
4692
4711
  nodeResolve({ exportConditions }),
4693
4712
  skip({ patterns: [STYLE_REGEXP] }),
4694
4713
  dts({
4695
4714
  respectExternal: true,
4696
4715
  compilerOptions: {
4697
- ...compilerOptions,
4698
4716
  // temp directory, it not affect the output
4699
4717
  // but if the user not set it and `declaration`, inputs can't generate any dts files when the input relative imports of `package.json`
4700
4718
  outDir: "dist",
@@ -4704,7 +4722,8 @@ const generateConfigs = (context, options = {}) => {
4704
4722
  // Expected '{', got 'type' (Note that you need plugins to import files that are not JavaScript)
4705
4723
  // https://github.com/Swatinem/rollup-plugin-dts/issues/96
4706
4724
  noEmit: false
4707
- }
4725
+ },
4726
+ tsconfig: dtsTSConfigPath
4708
4727
  }),
4709
4728
  progress({
4710
4729
  onEvent: (event, message) => sendMessage(
@@ -4718,6 +4737,18 @@ const generateConfigs = (context, options = {}) => {
4718
4737
  ]
4719
4738
  });
4720
4739
  }
4740
+ rollupOptions[0].plugins = [
4741
+ {
4742
+ name: "jiek-plugin-watcher",
4743
+ watchChange: (id) => sendMessage(
4744
+ {
4745
+ type: "watchChange",
4746
+ data: { id, name: JIEK_NAME, path, input }
4747
+ }
4748
+ )
4749
+ },
4750
+ ...rollupOptions[0].plugins
4751
+ ];
4721
4752
  return rollupOptions;
4722
4753
  };
4723
4754
  function template(packageJSON) {
@@ -4727,9 +4758,6 @@ function template(packageJSON) {
4727
4758
  throw new Error("package.json name is required");
4728
4759
  if (!entrypoints)
4729
4760
  throw new Error("package.json exports is required");
4730
- const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({
4731
- "index": "."
4732
- })[e] ?? e);
4733
4761
  const packageName = pascalCase(name);
4734
4762
  const external = externalResolver(packageJSON);
4735
4763
  const [filteredResolvedEntrypoints, exports] = getExports({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "1.1.11",
4
+ "version": "1.1.13",
5
5
  "description": "YiJie's personal kits.",
6
6
  "bin": {
7
7
  "jiek": "bin/jiek.js",
@@ -36,7 +36,7 @@
36
36
  "#~/*": "./src/*"
37
37
  },
38
38
  "dependencies": {
39
- "@jiek/rollup-plugin-dts": "^6.1.2",
39
+ "@jiek/rollup-plugin-dts": "^6.2.1",
40
40
  "@rollup/plugin-commonjs": "^28.0.0",
41
41
  "@rollup/plugin-json": "^6.0.1",
42
42
  "@rollup/plugin-node-resolve": "^15.3.0",
@@ -6,7 +6,6 @@ import { MultiBar, Presets } from 'cli-progress'
6
6
  import { program } from 'commander'
7
7
  import { execaCommand } from 'execa'
8
8
 
9
- import { actionDone, actionRestore } from '../inner'
10
9
  import type { RollupProgressEvent, TemplateOptions } from '../rollup/base'
11
10
  import type { ProjectsGraph } from '../utils/filterSupport'
12
11
  import { filterPackagesGraph, getSelectedProjectsGraph } from '../utils/filterSupport'
@@ -49,7 +48,8 @@ interface BuildOptions extends Record<string, unknown> {
49
48
  */
50
49
  outdir: string
51
50
  silent: boolean
52
- entries: string
51
+ entries?: string
52
+ external?: string
53
53
  verbose: boolean
54
54
  noJs: boolean
55
55
  noDts: boolean
@@ -70,7 +70,11 @@ program
70
70
  .command('build')
71
71
  .description(description)
72
72
  .option('-o, --outdir <OUTDIR>', outdirDescription, String, 'dist')
73
- .option('-e, --entries <ENTRIES>', "Specify the entries of the package.json's 'exports' field.(support glob)")
73
+ .option(
74
+ '-e, --entries <ENTRIES>',
75
+ "Specify the build entry-points of the package.json's 'exports' field.(support glob)"
76
+ )
77
+ .option('--external <EXTERNAL>', 'Specify the external dependencies of the package.', String)
74
78
  .option('-nj, --noJs', 'Do not output js files.', parseBoolean)
75
79
  .option('-nd, --noDts', 'Do not output dts files.', parseBoolean)
76
80
  .option('-nm, --noMin', 'Do not output minify files.', parseBoolean)
@@ -86,6 +90,7 @@ program
86
90
  outdir,
87
91
  silent,
88
92
  entries,
93
+ external,
89
94
  verbose,
90
95
  noJs: withoutJs,
91
96
  noDts: withoutDts,
@@ -110,7 +115,6 @@ program
110
115
  },
111
116
  [] as string[]
112
117
  )
113
- actionRestore()
114
118
  const { build } = loadConfig()
115
119
  silent = silent ?? build?.silent ?? false
116
120
 
@@ -126,6 +130,7 @@ program
126
130
  JIEK_OUT_DIR: outdir,
127
131
  JIEK_CLEAN: String(!noClean),
128
132
  JIEK_ENTRIES: entries,
133
+ JIEK_EXTERNAL: external,
129
134
  JIEK_WITHOUT_JS: String(withoutJs),
130
135
  JIEK_WITHOUT_DTS: String(withoutDts),
131
136
  JIEK_WITHOUT_MINIFY: String(withoutMin),
@@ -184,6 +189,8 @@ program
184
189
  }
185
190
  })
186
191
  const bars: Record<string, ReturnType<typeof multiBars.create>> = {}
192
+ const times: Record<string, number> = {}
193
+ const locks: Record<string, boolean> = {}
187
194
  let inputMaxLen = 10
188
195
  child.on('message', (e: RollupProgressEvent) => {
189
196
  if (e.type === 'debug') console.log(...(Array.isArray(e.data) ? e.data : [e.data]))
@@ -209,7 +216,7 @@ program
209
216
  if (bars[key]) return
210
217
  bars[key] = multiBars.create(50, 0, {
211
218
  pkgName: manifest.name,
212
- input: input.padEnd(inputMaxLen),
219
+ input: input.padEnd(inputMaxLen + 5),
213
220
  status: 'waiting'.padEnd(10)
214
221
  }, {
215
222
  barsize: 20,
@@ -227,6 +234,7 @@ program
227
234
  } = e.data
228
235
  const bar = bars[`${input}:${path}`]
229
236
  if (!bar) return
237
+ const time = times[`${input}:${path}`]
230
238
  bar.update(
231
239
  {
232
240
  start: 0,
@@ -234,12 +242,39 @@ program
234
242
  end: 50
235
243
  }[event ?? 'start'] ?? 0,
236
244
  {
237
- input: input.padEnd(inputMaxLen),
245
+ input: (
246
+ time
247
+ ? `${input}(x${time.toString().padStart(2, '0')})`
248
+ : input
249
+ ).padEnd(inputMaxLen + 5),
238
250
  status: event?.padEnd(10),
239
251
  message: `${tags?.join(', ')}: ${message}`
240
252
  }
241
253
  )
242
254
  }
255
+ if (e.type === 'watchChange') {
256
+ const {
257
+ path,
258
+ input
259
+ } = e.data
260
+ const key = `${input}:${path}`
261
+ const bar = bars[key]
262
+ if (!bar) return
263
+ let time = times[key] ?? 1
264
+ if (!locks[key]) {
265
+ time += 1
266
+ times[key] = time
267
+ setTimeout(() => {
268
+ locks[key] = false
269
+ }, 100)
270
+ bar.update(0, {
271
+ input: `${input}(x${time.toString().padStart(2, '0')})`.padEnd(inputMaxLen + 5),
272
+ status: 'watching'.padEnd(10),
273
+ message: 'watching...'
274
+ })
275
+ }
276
+ locks[key] = true
277
+ }
243
278
  })
244
279
  await new Promise<void>((resolve, reject) => {
245
280
  let errorStr = ''
@@ -266,6 +301,4 @@ program
266
301
  } finally {
267
302
  multiBars.stop()
268
303
  }
269
-
270
- actionDone()
271
304
  })
@@ -44,6 +44,10 @@ export interface TemplateOptions {
44
44
  js?: OutputControl
45
45
  dts?: OutputControl
46
46
  }
47
+ /**
48
+ * Set the external dependencies of the package.
49
+ */
50
+ external?: (string | RegExp)[]
47
51
  plugins?:
48
52
  | InputPluginOption
49
53
  | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption)
@@ -65,6 +69,15 @@ export type RollupProgressEvent =
65
69
  targetsLength: number
66
70
  }
67
71
  }
72
+ | {
73
+ type: 'watchChange'
74
+ data: {
75
+ id: string
76
+ name: string
77
+ path: string
78
+ input: string
79
+ }
80
+ }
68
81
  | {
69
82
  type: 'debug'
70
83
  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
 
@@ -35,12 +35,25 @@ const {
35
35
  JIEK_ROOT,
36
36
  JIEK_NAME,
37
37
  JIEK_ENTRIES,
38
+ JIEK_EXTERNAL,
38
39
  JIEK_WITHOUT_JS,
39
40
  JIEK_WITHOUT_DTS,
40
41
  JIEK_WITHOUT_MINIFY,
41
42
  JIEK_NO_CLEAN,
42
43
  JIEK_ONLY_MINIFY
43
44
  } = process.env
45
+
46
+ const entries = JIEK_ENTRIES
47
+ ?.split(',')
48
+ .map(e => e.trim())
49
+ .map(e => ({ 'index': '.' }[e] ?? e))
50
+
51
+ const commandExternal = JIEK_EXTERNAL
52
+ ?.split(',')
53
+ .map(e => e.trim())
54
+ .map(e => new RegExp(`^${e}$`))
55
+ ?? []
56
+
44
57
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir()
45
58
  const COMMON_OPTIONS = {} satisfies RollupOptions
46
59
  const COMMON_PLUGINS = [
@@ -182,10 +195,11 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
182
195
  name,
183
196
  input,
184
197
  output,
185
- external,
198
+ external: inputExternal,
186
199
  pkgIsModule,
187
200
  conditionals
188
201
  } = context
202
+ const external = [...inputExternal, ...(options.external ?? []), ...commandExternal]
189
203
  const isModule = conditionals.includes('import')
190
204
  const isCommonJS = conditionals.includes('require')
191
205
  const isBrowser = conditionals.includes('browser')
@@ -193,12 +207,22 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
193
207
  resolveWorkspacePath('tsconfig.json'),
194
208
  resolveWorkspacePath('tsconfig.dts.json')
195
209
  ]
210
+ const buildTSConfigPaths = [
211
+ ...dtsTSConfigPaths,
212
+ resolveWorkspacePath('tsconfig.build.json')
213
+ ]
196
214
  let dtsTSConfigPath: string | undefined
197
215
  dtsTSConfigPaths.forEach(p => {
198
216
  if (fs.existsSync(p) && fs.statSync(p).isFile()) {
199
217
  dtsTSConfigPath = p
200
218
  }
201
219
  })
220
+ let buildTSConfigPath: string | undefined
221
+ buildTSConfigPaths.forEach(p => {
222
+ if (fs.existsSync(p) && fs.statSync(p).isFile()) {
223
+ buildTSConfigPath = p
224
+ }
225
+ })
202
226
  let compilerOptions: ts.CompilerOptions = {}
203
227
  if (dtsTSConfigPath) {
204
228
  const jsonCompilerOptions = getCompilerOptionsByFilePath(dtsTSConfigPath, resolve(input))
@@ -245,7 +269,12 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
245
269
  const tsOutputSuffix = jsOutputSuffix.replace(/(\.[cm]?)js$/, '.d$1ts')
246
270
  const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output)
247
271
  const rollupOptions: RollupOptions[] = []
272
+
273
+ const commonPlugins: Plugin[] = []
248
274
  if (jsOutput && !WITHOUT_JS) {
275
+ const sourcemap = typeof options?.output?.sourcemap === 'object'
276
+ ? options.output.sourcemap.js
277
+ : options?.output?.sourcemap
249
278
  rollupOptions.push({
250
279
  input: inputObj,
251
280
  external,
@@ -261,9 +290,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
261
290
  .replace(/(\.[cm]?)ts$/, jsOutputSuffix)
262
291
  : output.replace(`${jsOutdir}/`, '')
263
292
  ),
264
- sourcemap: typeof options?.output?.sourcemap === 'object'
265
- ? options.output.sourcemap.js
266
- : options?.output?.sourcemap,
293
+ sourcemap,
267
294
  format: isModule ? 'esm' : (
268
295
  isCommonJS ? 'cjs' : (
269
296
  isBrowser ? 'umd' : (
@@ -277,6 +304,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
277
304
  })
278
305
  ],
279
306
  plugins: [
307
+ ...commonPlugins,
280
308
  nodeResolve({ exportConditions }),
281
309
  import('rollup-plugin-postcss')
282
310
  .then(({ default: postcss }) =>
@@ -287,7 +315,8 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
287
315
  )
288
316
  .catch(() => void 0),
289
317
  esbuild({
290
- tsconfig: dtsTSConfigPath
318
+ sourceMap: sourcemap === 'hidden' ? false : !!sourcemap,
319
+ tsconfig: buildTSConfigPath
291
320
  }),
292
321
  commonjs(),
293
322
  progress({
@@ -303,6 +332,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
303
332
  ]
304
333
  })
305
334
  }
335
+
306
336
  if (dtsOutput && !WITHOUT_DTS) {
307
337
  rollupOptions.push({
308
338
  input: inputObj,
@@ -328,12 +358,12 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
328
358
  }
329
359
  ],
330
360
  plugins: [
361
+ ...commonPlugins,
331
362
  nodeResolve({ exportConditions }),
332
363
  skip({ patterns: [STYLE_REGEXP] }),
333
364
  dts({
334
365
  respectExternal: true,
335
366
  compilerOptions: {
336
- ...compilerOptions,
337
367
  // temp directory, it not affect the output
338
368
  // but if the user not set it and `declaration`, inputs can't generate any dts files when the input relative imports of `package.json`
339
369
  outDir: 'dist',
@@ -343,7 +373,8 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
343
373
  // Expected '{', got 'type' (Note that you need plugins to import files that are not JavaScript)
344
374
  // https://github.com/Swatinem/rollup-plugin-dts/issues/96
345
375
  noEmit: false
346
- }
376
+ },
377
+ tsconfig: dtsTSConfigPath
347
378
  }),
348
379
  progress({
349
380
  onEvent: (event, message) =>
@@ -358,6 +389,20 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
358
389
  ]
359
390
  })
360
391
  }
392
+ // only push the first one a watcher plugin
393
+ rollupOptions[0].plugins = [
394
+ {
395
+ name: 'jiek-plugin-watcher',
396
+ watchChange: (id) =>
397
+ sendMessage(
398
+ {
399
+ type: 'watchChange',
400
+ data: { id, name: JIEK_NAME!, path, input }
401
+ } satisfies RollupProgressEvent
402
+ )
403
+ },
404
+ ...(rollupOptions[0].plugins as any)
405
+ ]
361
406
  return rollupOptions
362
407
  }
363
408
 
@@ -367,13 +412,6 @@ export function template(packageJSON: PackageJSON): RollupOptions[] {
367
412
  if (!name) throw new Error('package.json name is required')
368
413
  if (!entrypoints) throw new Error('package.json exports is required')
369
414
 
370
- const entries = JIEK_ENTRIES
371
- ?.split(',')
372
- .map(e => e.trim())
373
- .map(e => ({
374
- 'index': '.'
375
- }[e] ?? e))
376
-
377
415
  const packageName = pascalCase(name)
378
416
 
379
417
  const external = externalResolver(packageJSON as Record<string, unknown>)
@@ -1,34 +0,0 @@
1
- import type { Plugin, PluginImpl } from 'rollup'
2
-
3
- import globalResolver from '../utils/globalResolver'
4
-
5
- interface GlobalsOptions {
6
- external?: (string | RegExp)[]
7
- }
8
-
9
- export function createGlobalsLinkage() {
10
- let globals = {}
11
- const dependencies = new Set<string>([])
12
- return [
13
- (({ external } = {}) => {
14
- return {
15
- name: 'globals',
16
- resolveId(id) {
17
- if (external?.some(dep => dep instanceof RegExp ? dep.test(id) : dep === id)) {
18
- dependencies.add(id)
19
- return { id, external: true }
20
- }
21
- return null
22
- },
23
- outputOptions(options) {
24
- globals = [...dependencies].reduce((acc, value) => ({
25
- ...acc,
26
- [value]: globalResolver(value)
27
- }), {})
28
- return { ...options, globals }
29
- }
30
- }
31
- }) as PluginImpl<GlobalsOptions>,
32
- { outputOptions: options => ({ ...options, globals }) } as Plugin
33
- ] as const
34
- }