jiek 1.1.12 → 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.12";
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),
@@ -601,7 +597,6 @@ ${errorStr}`)));
601
597
  } finally {
602
598
  multiBars.stop();
603
599
  }
604
- actionDone();
605
600
  });
606
601
 
607
602
  var utils$1 = {};
@@ -4986,6 +4981,14 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
4986
4981
  fs__default.default.writeFileSync(readmeFilePath, readmeContent);
4987
4982
  });
4988
4983
 
4984
+ let resolve;
4985
+ function actionDone() {
4986
+ resolve();
4987
+ }
4988
+ function actionRestore() {
4989
+ new Promise((r) => resolve = r);
4990
+ }
4991
+
4989
4992
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4990
4993
  const {
4991
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.12";
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),
@@ -570,7 +566,6 @@ ${errorStr}`)));
570
566
  } finally {
571
567
  multiBars.stop();
572
568
  }
573
- actionDone();
574
569
  });
575
570
 
576
571
  var utils$1 = {};
@@ -4955,6 +4950,14 @@ program.command("init [name]").option("-t, --template <template>", "the package.
4955
4950
  fs.writeFileSync(readmeFilePath, readmeContent);
4956
4951
  });
4957
4952
 
4953
+ let resolve;
4954
+ function actionDone() {
4955
+ resolve();
4956
+ }
4957
+ function actionRestore() {
4958
+ new Promise((r) => resolve = r);
4959
+ }
4960
+
4958
4961
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4959
4962
  const {
4960
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));
@@ -4654,6 +4668,7 @@ const generateConfigs = (context, options = {}) => {
4654
4668
  const rollupOptions = [];
4655
4669
  const commonPlugins = [];
4656
4670
  if (jsOutput && !WITHOUT_JS) {
4671
+ const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
4657
4672
  rollupOptions.push({
4658
4673
  input: inputObj,
4659
4674
  external,
@@ -4663,7 +4678,7 @@ const generateConfigs = (context, options = {}) => {
4663
4678
  name,
4664
4679
  interop: "auto",
4665
4680
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4666
- sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap,
4681
+ sourcemap,
4667
4682
  format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4668
4683
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
4669
4684
  })
@@ -4678,7 +4693,8 @@ const generateConfigs = (context, options = {}) => {
4678
4693
  })
4679
4694
  ).catch(() => void 0),
4680
4695
  esbuild__default.default({
4681
- tsconfig: dtsTSConfigPath
4696
+ sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4697
+ tsconfig: buildTSConfigPath
4682
4698
  }),
4683
4699
  commonjs__default.default(),
4684
4700
  progress({
@@ -4712,7 +4728,6 @@ const generateConfigs = (context, options = {}) => {
4712
4728
  rollupPluginDts.dts({
4713
4729
  respectExternal: true,
4714
4730
  compilerOptions: {
4715
- ...compilerOptions,
4716
4731
  // temp directory, it not affect the output
4717
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`
4718
4733
  outDir: "dist",
@@ -4722,7 +4737,8 @@ const generateConfigs = (context, options = {}) => {
4722
4737
  // Expected '{', got 'type' (Note that you need plugins to import files that are not JavaScript)
4723
4738
  // https://github.com/Swatinem/rollup-plugin-dts/issues/96
4724
4739
  noEmit: false
4725
- }
4740
+ },
4741
+ tsconfig: dtsTSConfigPath
4726
4742
  }),
4727
4743
  progress({
4728
4744
  onEvent: (event, message) => execa.sendMessage(
@@ -4757,9 +4773,6 @@ function template(packageJSON) {
4757
4773
  throw new Error("package.json name is required");
4758
4774
  if (!entrypoints$1)
4759
4775
  throw new Error("package.json exports is required");
4760
- const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({
4761
- "index": "."
4762
- })[e] ?? e);
4763
4776
  const packageName = pascalCase(name);
4764
4777
  const external = externalResolver(packageJSON);
4765
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));
@@ -4639,6 +4653,7 @@ const generateConfigs = (context, options = {}) => {
4639
4653
  const rollupOptions = [];
4640
4654
  const commonPlugins = [];
4641
4655
  if (jsOutput && !WITHOUT_JS) {
4656
+ const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
4642
4657
  rollupOptions.push({
4643
4658
  input: inputObj,
4644
4659
  external,
@@ -4648,7 +4663,7 @@ const generateConfigs = (context, options = {}) => {
4648
4663
  name,
4649
4664
  interop: "auto",
4650
4665
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, jsOutputSuffix) : output.replace(`${jsOutdir}/`, ""),
4651
- sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap,
4666
+ sourcemap,
4652
4667
  format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
4653
4668
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
4654
4669
  })
@@ -4663,7 +4678,8 @@ const generateConfigs = (context, options = {}) => {
4663
4678
  })
4664
4679
  ).catch(() => void 0),
4665
4680
  esbuild({
4666
- tsconfig: dtsTSConfigPath
4681
+ sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4682
+ tsconfig: buildTSConfigPath
4667
4683
  }),
4668
4684
  commonjs(),
4669
4685
  progress({
@@ -4697,7 +4713,6 @@ const generateConfigs = (context, options = {}) => {
4697
4713
  dts({
4698
4714
  respectExternal: true,
4699
4715
  compilerOptions: {
4700
- ...compilerOptions,
4701
4716
  // temp directory, it not affect the output
4702
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`
4703
4718
  outDir: "dist",
@@ -4707,7 +4722,8 @@ const generateConfigs = (context, options = {}) => {
4707
4722
  // Expected '{', got 'type' (Note that you need plugins to import files that are not JavaScript)
4708
4723
  // https://github.com/Swatinem/rollup-plugin-dts/issues/96
4709
4724
  noEmit: false
4710
- }
4725
+ },
4726
+ tsconfig: dtsTSConfigPath
4711
4727
  }),
4712
4728
  progress({
4713
4729
  onEvent: (event, message) => sendMessage(
@@ -4742,9 +4758,6 @@ function template(packageJSON) {
4742
4758
  throw new Error("package.json name is required");
4743
4759
  if (!entrypoints)
4744
4760
  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
4761
  const packageName = pascalCase(name);
4749
4762
  const external = externalResolver(packageJSON);
4750
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.12",
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),
@@ -296,6 +301,4 @@ program
296
301
  } finally {
297
302
  multiBars.stop()
298
303
  }
299
-
300
- actionDone()
301
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)
@@ -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))
@@ -248,6 +272,9 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
248
272
 
249
273
  const commonPlugins: Plugin[] = []
250
274
  if (jsOutput && !WITHOUT_JS) {
275
+ const sourcemap = typeof options?.output?.sourcemap === 'object'
276
+ ? options.output.sourcemap.js
277
+ : options?.output?.sourcemap
251
278
  rollupOptions.push({
252
279
  input: inputObj,
253
280
  external,
@@ -263,9 +290,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
263
290
  .replace(/(\.[cm]?)ts$/, jsOutputSuffix)
264
291
  : output.replace(`${jsOutdir}/`, '')
265
292
  ),
266
- sourcemap: typeof options?.output?.sourcemap === 'object'
267
- ? options.output.sourcemap.js
268
- : options?.output?.sourcemap,
293
+ sourcemap,
269
294
  format: isModule ? 'esm' : (
270
295
  isCommonJS ? 'cjs' : (
271
296
  isBrowser ? 'umd' : (
@@ -290,7 +315,8 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
290
315
  )
291
316
  .catch(() => void 0),
292
317
  esbuild({
293
- tsconfig: dtsTSConfigPath
318
+ sourceMap: sourcemap === 'hidden' ? false : !!sourcemap,
319
+ tsconfig: buildTSConfigPath
294
320
  }),
295
321
  commonjs(),
296
322
  progress({
@@ -338,7 +364,6 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
338
364
  dts({
339
365
  respectExternal: true,
340
366
  compilerOptions: {
341
- ...compilerOptions,
342
367
  // temp directory, it not affect the output
343
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`
344
369
  outDir: 'dist',
@@ -348,7 +373,8 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
348
373
  // Expected '{', got 'type' (Note that you need plugins to import files that are not JavaScript)
349
374
  // https://github.com/Swatinem/rollup-plugin-dts/issues/96
350
375
  noEmit: false
351
- }
376
+ },
377
+ tsconfig: dtsTSConfigPath
352
378
  }),
353
379
  progress({
354
380
  onEvent: (event, message) =>
@@ -386,13 +412,6 @@ export function template(packageJSON: PackageJSON): RollupOptions[] {
386
412
  if (!name) throw new Error('package.json name is required')
387
413
  if (!entrypoints) throw new Error('package.json exports is required')
388
414
 
389
- const entries = JIEK_ENTRIES
390
- ?.split(',')
391
- .map(e => e.trim())
392
- .map(e => ({
393
- 'index': '.'
394
- }[e] ?? e))
395
-
396
415
  const packageName = pascalCase(name)
397
416
 
398
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
- }