jiek 2.2.2 → 2.2.3-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
9
9
  var process$1 = require('node:process');
10
10
  var cliProgress = require('cli-progress');
11
11
  var execa = require('execa');
12
+ var node_child_process = require('node:child_process');
12
13
  var prompts = require('@inquirer/prompts');
13
14
  var Koa = require('koa');
14
15
 
@@ -22,8 +23,7 @@ var Koa__default = /*#__PURE__*/_interopDefault(Koa);
22
23
 
23
24
  let root;
24
25
  function getRoot() {
25
- if (root)
26
- return root;
26
+ if (root) return root;
27
27
  const rootOption = process.env.JIEK_ROOT;
28
28
  root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
29
29
  return root;
@@ -32,8 +32,7 @@ function getRoot() {
32
32
  let wd;
33
33
  let notWorkspace$1 = false;
34
34
  function getWD() {
35
- if (wd)
36
- return { wd, notWorkspace: notWorkspace$1 };
35
+ if (wd) return { wd, notWorkspace: notWorkspace$1 };
37
36
  const root = getRoot();
38
37
  if (root !== void 0) {
39
38
  const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type$1);
@@ -120,7 +119,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
120
119
 
121
120
  var name = "jiek";
122
121
  var type = "module";
123
- var version = "2.2.1";
122
+ var version = "2.2.3-alpha.1";
124
123
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
125
124
  var author = "YiJie <yijie4188@gmail.com>";
126
125
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -178,7 +177,7 @@ var scripts = {
178
177
  test: "vitest run"
179
178
  };
180
179
  var peerDependencies = {
181
- "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
180
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
182
181
  "@rollup/plugin-terser": "^0.4.4",
183
182
  "esbuild-register": "^3.5.0",
184
183
  postcss: "^8.4.47",
@@ -189,7 +188,7 @@ var peerDependencies = {
189
188
  "vite-bundle-analyzer": "0.16.0-beta.1"
190
189
  };
191
190
  var dependencies = {
192
- "@inquirer/prompts": "^7.1.0",
191
+ "@inquirer/prompts": "^7.2.0",
193
192
  "@jiek/pkger": "workspace:^",
194
193
  "@jiek/rollup-plugin-dts": "^6.2.1",
195
194
  "@jiek/utils": "workspace:^",
@@ -300,14 +299,12 @@ function Main() {
300
299
  }, [path, filterModules]);
301
300
  useEffect(() => {
302
301
  const offGraphClick = listen("graph:click", ({ detail }) => {
303
- if (!detail)
304
- return;
302
+ if (!detail) return;
305
303
  let root = detail.node;
306
304
  while (root.parent) {
307
305
  root = root.parent;
308
306
  }
309
- if (root.filename === path)
310
- return;
307
+ if (root.filename === path) return;
311
308
  push(root.filename);
312
309
  });
313
310
  return () => {
@@ -376,8 +373,7 @@ const CLIENT_CUSTOM_RENDER_SCRIPT = [
376
373
  ].join("\n");
377
374
 
378
375
  function parseBoolean(v) {
379
- if (v === void 0)
380
- return true;
376
+ if (v === void 0) return true;
381
377
  return Boolean(v);
382
378
  }
383
379
 
@@ -389,7 +385,7 @@ async function checkDependency(dependency) {
389
385
  const { notWorkspace } = getWD();
390
386
  const command = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
391
387
  if (await prompts.confirm({ message: "Do you want to install it now?" })) {
392
- await execa.execaCommand(command);
388
+ node_child_process.spawnSync(command);
393
389
  } else {
394
390
  console.warn(`You can run the command '${command}' to install it manually.`);
395
391
  process__default.default.exit(1);
@@ -427,8 +423,7 @@ const useAnalyzer = async (options, server) => {
427
423
  bundleAnalyzerModule = await import('vite-bundle-analyzer');
428
424
  }
429
425
  const refreshAnalyzer = async (cwd, applyModules) => {
430
- if (!(analyzer && server && bundleAnalyzerModule))
431
- return;
426
+ if (!(analyzer && server && bundleAnalyzerModule)) return;
432
427
  if (analyzer.mode === "json") {
433
428
  const anaDir = path__default.default.resolve(cwd, analyzer.dir);
434
429
  if (!fs.existsSync(anaDir)) {
@@ -605,8 +600,7 @@ function loadConfig(dirOrOptions) {
605
600
  default:
606
601
  throw new Error(`unsupported config file type: ${ext}`);
607
602
  }
608
- if (!module)
609
- throw new Error("config file is empty");
603
+ if (!module) throw new Error("config file is empty");
610
604
  return module.default ?? module;
611
605
  }
612
606
 
@@ -818,8 +812,7 @@ command.action(async (commandFiltersOrEntries, options) => {
818
812
  "init",
819
813
  "progress",
820
814
  "watchChange"
821
- ].includes(e.type))
822
- return;
815
+ ].includes(e.type)) return;
823
816
  switch (e.type) {
824
817
  case "init": {
825
818
  const { leafMap, targetsLength } = e.data;
@@ -840,8 +833,7 @@ command.action(async (commandFiltersOrEntries, options) => {
840
833
  });
841
834
  leafs.forEach(({ input, path: path2 }) => {
842
835
  const key = `${input}:${path2}`;
843
- if (bars[key])
844
- return;
836
+ if (bars[key]) return;
845
837
  bars[key] = multiBars.create(50, 0, {
846
838
  pkgName: manifest.name,
847
839
  input: input.padEnd(inputMaxLen + 5),
@@ -862,8 +854,7 @@ command.action(async (commandFiltersOrEntries, options) => {
862
854
  message
863
855
  } = e.data;
864
856
  const bar = bars[`${input}:${path2}`];
865
- if (!bar)
866
- return;
857
+ if (!bar) return;
867
858
  const time = times[`${input}:${path2}`];
868
859
  bar.update(
869
860
  {
@@ -886,8 +877,7 @@ command.action(async (commandFiltersOrEntries, options) => {
886
877
  } = e.data;
887
878
  const key = `${input}:${path2}`;
888
879
  const bar = bars[key];
889
- if (!bar)
890
- return;
880
+ if (!bar) return;
891
881
  let time = times[key] ?? 1;
892
882
  if (!locks[key]) {
893
883
  time += 1;
@@ -929,12 +919,15 @@ command.action(async (commandFiltersOrEntries, options) => {
929
919
  }
930
920
  });
931
921
  await new Promise((resolve, reject) => {
932
- let errorStr = "";
922
+ let errorStr = `rollup build failed
923
+ package name: ${manifest.name}
924
+ cwd: ${pkgCWD}
925
+
926
+ `;
933
927
  child.stderr?.on("data", (data) => {
934
928
  errorStr += data;
935
929
  });
936
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
937
- ${errorStr}`)));
930
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
938
931
  verbose && child.stdout?.pipe(process__default.default.stdout);
939
932
  });
940
933
  })
@@ -40,6 +40,17 @@ interface TemplateOptions {
40
40
  } & rollup_plugin_esbuild.Options) | ({
41
41
  type: 'swc';
42
42
  } & rollup_plugin_swc3.PluginOptions);
43
+ features?: {
44
+ /**
45
+ * When use esbuild type builder, it will inject `supported.import-attributes` option.
46
+ * When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
47
+ *
48
+ * And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
49
+ *
50
+ * @default true
51
+ */
52
+ keepImportAttributes?: boolean | 'assert';
53
+ };
43
54
  output?: {
44
55
  /**
45
56
  * @default true
@@ -40,6 +40,17 @@ interface TemplateOptions {
40
40
  } & rollup_plugin_esbuild.Options) | ({
41
41
  type: 'swc';
42
42
  } & rollup_plugin_swc3.PluginOptions);
43
+ features?: {
44
+ /**
45
+ * When use esbuild type builder, it will inject `supported.import-attributes` option.
46
+ * When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
47
+ *
48
+ * And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
49
+ *
50
+ * @default true
51
+ */
52
+ keepImportAttributes?: boolean | 'assert';
53
+ };
43
54
  output?: {
44
55
  /**
45
56
  * @default true
@@ -7,13 +7,13 @@ import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
7
7
  import process$1 from 'node:process';
8
8
  import { MultiBar, Presets } from 'cli-progress';
9
9
  import { execaCommand } from 'execa';
10
+ import { spawnSync } from 'node:child_process';
10
11
  import { confirm } from '@inquirer/prompts';
11
12
  import Koa from 'koa';
12
13
 
13
14
  let root;
14
15
  function getRoot() {
15
- if (root)
16
- return root;
16
+ if (root) return root;
17
17
  const rootOption = process.env.JIEK_ROOT;
18
18
  root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
19
19
  return root;
@@ -22,8 +22,7 @@ function getRoot() {
22
22
  let wd;
23
23
  let notWorkspace$1 = false;
24
24
  function getWD() {
25
- if (wd)
26
- return { wd, notWorkspace: notWorkspace$1 };
25
+ if (wd) return { wd, notWorkspace: notWorkspace$1 };
27
26
  const root = getRoot();
28
27
  if (root !== void 0) {
29
28
  const isWorkspace = isWorkspaceDir(root, type$1);
@@ -110,7 +109,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
110
109
 
111
110
  var name = "jiek";
112
111
  var type = "module";
113
- var version = "2.2.1";
112
+ var version = "2.2.3-alpha.1";
114
113
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
115
114
  var author = "YiJie <yijie4188@gmail.com>";
116
115
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -168,7 +167,7 @@ var scripts = {
168
167
  test: "vitest run"
169
168
  };
170
169
  var peerDependencies = {
171
- "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
170
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
172
171
  "@rollup/plugin-terser": "^0.4.4",
173
172
  "esbuild-register": "^3.5.0",
174
173
  postcss: "^8.4.47",
@@ -179,7 +178,7 @@ var peerDependencies = {
179
178
  "vite-bundle-analyzer": "0.16.0-beta.1"
180
179
  };
181
180
  var dependencies = {
182
- "@inquirer/prompts": "^7.1.0",
181
+ "@inquirer/prompts": "^7.2.0",
183
182
  "@jiek/pkger": "workspace:^",
184
183
  "@jiek/rollup-plugin-dts": "^6.2.1",
185
184
  "@jiek/utils": "workspace:^",
@@ -290,14 +289,12 @@ function Main() {
290
289
  }, [path, filterModules]);
291
290
  useEffect(() => {
292
291
  const offGraphClick = listen("graph:click", ({ detail }) => {
293
- if (!detail)
294
- return;
292
+ if (!detail) return;
295
293
  let root = detail.node;
296
294
  while (root.parent) {
297
295
  root = root.parent;
298
296
  }
299
- if (root.filename === path)
300
- return;
297
+ if (root.filename === path) return;
301
298
  push(root.filename);
302
299
  });
303
300
  return () => {
@@ -366,8 +363,7 @@ const CLIENT_CUSTOM_RENDER_SCRIPT = [
366
363
  ].join("\n");
367
364
 
368
365
  function parseBoolean(v) {
369
- if (v === void 0)
370
- return true;
366
+ if (v === void 0) return true;
371
367
  return Boolean(v);
372
368
  }
373
369
 
@@ -379,7 +375,7 @@ async function checkDependency(dependency) {
379
375
  const { notWorkspace } = getWD();
380
376
  const command = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
381
377
  if (await confirm({ message: "Do you want to install it now?" })) {
382
- await execaCommand(command);
378
+ spawnSync(command);
383
379
  } else {
384
380
  console.warn(`You can run the command '${command}' to install it manually.`);
385
381
  process$1.exit(1);
@@ -417,8 +413,7 @@ const useAnalyzer = async (options, server) => {
417
413
  bundleAnalyzerModule = await import('vite-bundle-analyzer');
418
414
  }
419
415
  const refreshAnalyzer = async (cwd, applyModules) => {
420
- if (!(analyzer && server && bundleAnalyzerModule))
421
- return;
416
+ if (!(analyzer && server && bundleAnalyzerModule)) return;
422
417
  if (analyzer.mode === "json") {
423
418
  const anaDir = path.resolve(cwd, analyzer.dir);
424
419
  if (!existsSync(anaDir)) {
@@ -595,8 +590,7 @@ function loadConfig(dirOrOptions) {
595
590
  default:
596
591
  throw new Error(`unsupported config file type: ${ext}`);
597
592
  }
598
- if (!module)
599
- throw new Error("config file is empty");
593
+ if (!module) throw new Error("config file is empty");
600
594
  return module.default ?? module;
601
595
  }
602
596
 
@@ -808,8 +802,7 @@ command.action(async (commandFiltersOrEntries, options) => {
808
802
  "init",
809
803
  "progress",
810
804
  "watchChange"
811
- ].includes(e.type))
812
- return;
805
+ ].includes(e.type)) return;
813
806
  switch (e.type) {
814
807
  case "init": {
815
808
  const { leafMap, targetsLength } = e.data;
@@ -830,8 +823,7 @@ command.action(async (commandFiltersOrEntries, options) => {
830
823
  });
831
824
  leafs.forEach(({ input, path: path2 }) => {
832
825
  const key = `${input}:${path2}`;
833
- if (bars[key])
834
- return;
826
+ if (bars[key]) return;
835
827
  bars[key] = multiBars.create(50, 0, {
836
828
  pkgName: manifest.name,
837
829
  input: input.padEnd(inputMaxLen + 5),
@@ -852,8 +844,7 @@ command.action(async (commandFiltersOrEntries, options) => {
852
844
  message
853
845
  } = e.data;
854
846
  const bar = bars[`${input}:${path2}`];
855
- if (!bar)
856
- return;
847
+ if (!bar) return;
857
848
  const time = times[`${input}:${path2}`];
858
849
  bar.update(
859
850
  {
@@ -876,8 +867,7 @@ command.action(async (commandFiltersOrEntries, options) => {
876
867
  } = e.data;
877
868
  const key = `${input}:${path2}`;
878
869
  const bar = bars[key];
879
- if (!bar)
880
- return;
870
+ if (!bar) return;
881
871
  let time = times[key] ?? 1;
882
872
  if (!locks[key]) {
883
873
  time += 1;
@@ -919,12 +909,15 @@ command.action(async (commandFiltersOrEntries, options) => {
919
909
  }
920
910
  });
921
911
  await new Promise((resolve, reject) => {
922
- let errorStr = "";
912
+ let errorStr = `rollup build failed
913
+ package name: ${manifest.name}
914
+ cwd: ${pkgCWD}
915
+
916
+ `;
923
917
  child.stderr?.on("data", (data) => {
924
918
  errorStr += data;
925
919
  });
926
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
927
- ${errorStr}`)));
920
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
928
921
  verbose && child.stdout?.pipe(process$1.stdout);
929
922
  });
930
923
  })
package/dist/cli.cjs CHANGED
@@ -47,8 +47,7 @@ var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
47
47
 
48
48
  let root;
49
49
  function getRoot() {
50
- if (root)
51
- return root;
50
+ if (root) return root;
52
51
  const rootOption = process.env.JIEK_ROOT;
53
52
  root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
54
53
  return root;
@@ -57,8 +56,7 @@ function getRoot() {
57
56
  let wd;
58
57
  let notWorkspace = false;
59
58
  function getWD() {
60
- if (wd)
61
- return { wd, notWorkspace };
59
+ if (wd) return { wd, notWorkspace };
62
60
  const root = getRoot();
63
61
  if (root !== void 0) {
64
62
  const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type);
@@ -4313,14 +4311,24 @@ function getExports({
4313
4311
  }
4314
4312
  );
4315
4313
  const crossModuleWithConditional = crossModuleConvertor ? {
4316
- import: (opts) => !pkgIsModule && intersection(
4317
- new Set(opts.conditionals),
4318
- /* @__PURE__ */ new Set(["import", "module"])
4319
- ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4320
- require: (opts) => pkgIsModule && intersection(
4321
- new Set(opts.conditionals),
4322
- /* @__PURE__ */ new Set(["require", "node"])
4323
- ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4314
+ import: (opts) => {
4315
+ if (pkgIsModule) return false;
4316
+ if (opts.src.endsWith(".cts")) return false;
4317
+ if (intersection(
4318
+ new Set(opts.conditionals),
4319
+ /* @__PURE__ */ new Set(["import", "module"])
4320
+ ).size !== 0) return false;
4321
+ return opts.dist.replace(/\.js$/, ".mjs");
4322
+ },
4323
+ require: (opts) => {
4324
+ if (!pkgIsModule) return false;
4325
+ if (opts.src.endsWith(".mts")) return false;
4326
+ if (intersection(
4327
+ new Set(opts.conditionals),
4328
+ /* @__PURE__ */ new Set(["require", "node"])
4329
+ ).size !== 0) return false;
4330
+ return opts.dist.replace(/\.js$/, ".cjs");
4331
+ }
4324
4332
  } : {};
4325
4333
  return [
4326
4334
  filteredResolvedEntrypoints,
@@ -4438,8 +4446,7 @@ function loadConfig(dirOrOptions) {
4438
4446
  default:
4439
4447
  throw new Error(`unsupported config file type: ${ext}`);
4440
4448
  }
4441
- if (!module)
4442
- throw new Error("config file is empty");
4449
+ if (!module) throw new Error("config file is empty");
4443
4450
  return module.default ?? module;
4444
4451
  }
4445
4452
 
@@ -4551,10 +4558,8 @@ async function prepublish({ bumper: bumper$1 } = {}) {
4551
4558
  )
4552
4559
  );
4553
4560
  for (const [key, value] of Object.entries(manifest)) {
4554
- if (key === "version")
4555
- continue;
4556
- if (JSON.stringify(value) === JSON.stringify(oldJSON[key]))
4557
- continue;
4561
+ if (key === "version") continue;
4562
+ if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue;
4558
4563
  if (key !== "exports") {
4559
4564
  newJSONString = jsoncParser.applyEdits(
4560
4565
  newJSONString,
@@ -4593,8 +4598,7 @@ async function prepublish({ bumper: bumper$1 } = {}) {
4593
4598
  }
4594
4599
  }
4595
4600
  for (const [k, v] of Object.entries(indexPublishConfig)) {
4596
- if (v === void 0)
4597
- continue;
4601
+ if (v === void 0) continue;
4598
4602
  newJSONString = jsoncParser.applyEdits(
4599
4603
  newJSONString,
4600
4604
  jsoncParser.modify(
package/dist/cli.js CHANGED
@@ -16,8 +16,7 @@ import 'jiek/cli-only-build';
16
16
 
17
17
  let root;
18
18
  function getRoot() {
19
- if (root)
20
- return root;
19
+ if (root) return root;
21
20
  const rootOption = process.env.JIEK_ROOT;
22
21
  root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
23
22
  return root;
@@ -26,8 +25,7 @@ function getRoot() {
26
25
  let wd;
27
26
  let notWorkspace = false;
28
27
  function getWD() {
29
- if (wd)
30
- return { wd, notWorkspace };
28
+ if (wd) return { wd, notWorkspace };
31
29
  const root = getRoot();
32
30
  if (root !== void 0) {
33
31
  const isWorkspace = isWorkspaceDir(root, type);
@@ -4282,14 +4280,24 @@ function getExports({
4282
4280
  }
4283
4281
  );
4284
4282
  const crossModuleWithConditional = crossModuleConvertor ? {
4285
- import: (opts) => !pkgIsModule && intersection(
4286
- new Set(opts.conditionals),
4287
- /* @__PURE__ */ new Set(["import", "module"])
4288
- ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4289
- require: (opts) => pkgIsModule && intersection(
4290
- new Set(opts.conditionals),
4291
- /* @__PURE__ */ new Set(["require", "node"])
4292
- ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4283
+ import: (opts) => {
4284
+ if (pkgIsModule) return false;
4285
+ if (opts.src.endsWith(".cts")) return false;
4286
+ if (intersection(
4287
+ new Set(opts.conditionals),
4288
+ /* @__PURE__ */ new Set(["import", "module"])
4289
+ ).size !== 0) return false;
4290
+ return opts.dist.replace(/\.js$/, ".mjs");
4291
+ },
4292
+ require: (opts) => {
4293
+ if (!pkgIsModule) return false;
4294
+ if (opts.src.endsWith(".mts")) return false;
4295
+ if (intersection(
4296
+ new Set(opts.conditionals),
4297
+ /* @__PURE__ */ new Set(["require", "node"])
4298
+ ).size !== 0) return false;
4299
+ return opts.dist.replace(/\.js$/, ".cjs");
4300
+ }
4293
4301
  } : {};
4294
4302
  return [
4295
4303
  filteredResolvedEntrypoints,
@@ -4407,8 +4415,7 @@ function loadConfig(dirOrOptions) {
4407
4415
  default:
4408
4416
  throw new Error(`unsupported config file type: ${ext}`);
4409
4417
  }
4410
- if (!module)
4411
- throw new Error("config file is empty");
4418
+ if (!module) throw new Error("config file is empty");
4412
4419
  return module.default ?? module;
4413
4420
  }
4414
4421
 
@@ -4520,10 +4527,8 @@ async function prepublish({ bumper } = {}) {
4520
4527
  )
4521
4528
  );
4522
4529
  for (const [key, value] of Object.entries(manifest)) {
4523
- if (key === "version")
4524
- continue;
4525
- if (JSON.stringify(value) === JSON.stringify(oldJSON[key]))
4526
- continue;
4530
+ if (key === "version") continue;
4531
+ if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue;
4527
4532
  if (key !== "exports") {
4528
4533
  newJSONString = applyEdits(
4529
4534
  newJSONString,
@@ -4562,8 +4567,7 @@ async function prepublish({ bumper } = {}) {
4562
4567
  }
4563
4568
  }
4564
4569
  for (const [k, v] of Object.entries(indexPublishConfig)) {
4565
- if (v === void 0)
4566
- continue;
4570
+ if (v === void 0) continue;
4567
4571
  newJSONString = applyEdits(
4568
4572
  newJSONString,
4569
4573
  modify(
package/dist/index.d.cts CHANGED
@@ -40,6 +40,17 @@ interface TemplateOptions {
40
40
  } & rollup_plugin_esbuild.Options) | ({
41
41
  type: 'swc';
42
42
  } & rollup_plugin_swc3.PluginOptions);
43
+ features?: {
44
+ /**
45
+ * When use esbuild type builder, it will inject `supported.import-attributes` option.
46
+ * When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
47
+ *
48
+ * And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
49
+ *
50
+ * @default true
51
+ */
52
+ keepImportAttributes?: boolean | 'assert';
53
+ };
43
54
  output?: {
44
55
  /**
45
56
  * @default true
package/dist/index.d.ts CHANGED
@@ -40,6 +40,17 @@ interface TemplateOptions {
40
40
  } & rollup_plugin_esbuild.Options) | ({
41
41
  type: 'swc';
42
42
  } & rollup_plugin_swc3.PluginOptions);
43
+ features?: {
44
+ /**
45
+ * When use esbuild type builder, it will inject `supported.import-attributes` option.
46
+ * When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
47
+ *
48
+ * And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
49
+ *
50
+ * @default true
51
+ */
52
+ keepImportAttributes?: boolean | 'assert';
53
+ };
43
54
  output?: {
44
55
  /**
45
56
  * @default true
@@ -4171,8 +4171,7 @@ function bundleAnalyzer(modulesResolved) {
4171
4171
  return {
4172
4172
  name: "jiek:bundle-analyzer",
4173
4173
  async closeBundle(...args) {
4174
- if (typeof ana.closeBundle !== "function")
4175
- return;
4174
+ if (typeof ana.closeBundle !== "function") return;
4176
4175
  return ana.closeBundle?.call(this, ...args);
4177
4176
  }
4178
4177
  };
@@ -4254,14 +4253,24 @@ function getExports({
4254
4253
  }
4255
4254
  );
4256
4255
  const crossModuleWithConditional = crossModuleConvertor ? {
4257
- import: (opts) => !pkgIsModule && intersection(
4258
- new Set(opts.conditionals),
4259
- /* @__PURE__ */ new Set(["import", "module"])
4260
- ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4261
- require: (opts) => pkgIsModule && intersection(
4262
- new Set(opts.conditionals),
4263
- /* @__PURE__ */ new Set(["require", "node"])
4264
- ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4256
+ import: (opts) => {
4257
+ if (pkgIsModule) return false;
4258
+ if (opts.src.endsWith(".cts")) return false;
4259
+ if (intersection(
4260
+ new Set(opts.conditionals),
4261
+ /* @__PURE__ */ new Set(["import", "module"])
4262
+ ).size !== 0) return false;
4263
+ return opts.dist.replace(/\.js$/, ".mjs");
4264
+ },
4265
+ require: (opts) => {
4266
+ if (!pkgIsModule) return false;
4267
+ if (opts.src.endsWith(".mts")) return false;
4268
+ if (intersection(
4269
+ new Set(opts.conditionals),
4270
+ /* @__PURE__ */ new Set(["require", "node"])
4271
+ ).size !== 0) return false;
4272
+ return opts.dist.replace(/\.js$/, ".cjs");
4273
+ }
4265
4274
  } : {};
4266
4275
  return [
4267
4276
  filteredResolvedEntrypoints,
@@ -4280,8 +4289,7 @@ function getExports({
4280
4289
 
4281
4290
  let root;
4282
4291
  function getRoot() {
4283
- if (root)
4284
- return root;
4292
+ if (root) return root;
4285
4293
  const rootOption = process.env.JIEK_ROOT;
4286
4294
  root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
4287
4295
  return root;
@@ -4298,8 +4306,7 @@ try {
4298
4306
  let wd;
4299
4307
  let notWorkspace = false;
4300
4308
  function getWD() {
4301
- if (wd)
4302
- return { wd, notWorkspace };
4309
+ if (wd) return { wd, notWorkspace };
4303
4310
  const root = getRoot();
4304
4311
  if (root !== void 0) {
4305
4312
  const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type);
@@ -4421,16 +4428,14 @@ function loadConfig(dirOrOptions) {
4421
4428
  default:
4422
4429
  throw new Error(`unsupported config file type: ${ext}`);
4423
4430
  }
4424
- if (!module)
4425
- throw new Error("config file is empty");
4431
+ if (!module) throw new Error("config file is empty");
4426
4432
  return module.default ?? module;
4427
4433
  }
4428
4434
 
4429
4435
  const recusiveListFiles = (dir) => fs__default.default.readdirSync(dir).reduce((acc, file) => {
4430
4436
  const filePath = path.resolve(dir, file);
4431
4437
  if (fs__default.default.statSync(filePath).isDirectory()) {
4432
- if (filePath.endsWith("/node_modules"))
4433
- return acc;
4438
+ if (filePath.endsWith("/node_modules")) return acc;
4434
4439
  return [...acc, ...recusiveListFiles(filePath)];
4435
4440
  }
4436
4441
  return [...acc, filePath];
@@ -4445,8 +4450,7 @@ const getExtendTSConfig = (tsconfigPath) => {
4445
4450
  const extendsPaths = resolvePaths(
4446
4451
  exts !== void 0 ? Array.isArray(exts) ? exts : [exts] : []
4447
4452
  );
4448
- if (extendsPaths.length === 0)
4449
- return tsconfig;
4453
+ if (extendsPaths.length === 0) return tsconfig;
4450
4454
  return extendsPaths.map(getExtendTSConfig).concat(tsconfig).reduce((acc, { compilerOptions = {}, references: _, ...curr }) => ({
4451
4455
  ...acc,
4452
4456
  ...curr,
@@ -4473,24 +4477,20 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4473
4477
  tsconfig.include,
4474
4478
  tsconfig.exclude
4475
4479
  ].map(resolvePaths);
4476
- if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i)))
4477
- return;
4478
- if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0)
4479
- return;
4480
+ if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i))) return;
4481
+ if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0) return;
4480
4482
  let isInclude = false;
4481
4483
  isInclude || (isInclude = files.length > 0 && files.includes(filePath));
4482
4484
  isInclude || (isInclude = include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i)));
4483
4485
  if (isInclude) {
4484
4486
  return tsconfig.compilerOptions ?? {};
4485
4487
  } else {
4486
- if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0)
4487
- return;
4488
+ if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0) return;
4488
4489
  }
4489
4490
  references.reverse();
4490
4491
  for (const ref of references) {
4491
4492
  const compilerOptions = getCompilerOptionsByFilePath(ref, filePath);
4492
- if (compilerOptions)
4493
- return compilerOptions;
4493
+ if (compilerOptions) return compilerOptions;
4494
4494
  }
4495
4495
  return tsconfig.compilerOptions;
4496
4496
  };
@@ -4669,10 +4669,8 @@ const resolveOutputControls = (context, output) => ({
4669
4669
  const resolveWorkspacePath = (p) => path.resolve(WORKSPACE_ROOT, p);
4670
4670
  const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
4671
4671
  const reveal = (obj, keys) => keys.reduce((acc, key) => {
4672
- if (typeof acc === "string")
4673
- throw new Error("key not found in exports");
4674
- if (!(key in acc))
4675
- throw new Error(`key ${key} not found in exports`);
4672
+ if (typeof acc === "string") throw new Error("key not found in exports");
4673
+ if (!(key in acc)) throw new Error(`key ${key} not found in exports`);
4676
4674
  return acc[key];
4677
4675
  }, obj);
4678
4676
  const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
@@ -4819,11 +4817,28 @@ const generateConfigs = (context, options = {}) => {
4819
4817
  ];
4820
4818
  if (jsOutput && !WITHOUT_JS) {
4821
4819
  const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
4820
+ const features = Object.assign({
4821
+ keepImportAttributes: true
4822
+ }, build.features);
4822
4823
  const builder = resolvedBuilderOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(
4823
4824
  ({ default: esbuild }) => esbuild({
4824
4825
  sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4825
4826
  tsconfig: buildTSConfigPath,
4826
- ...noTypeResolvedBuilderOptions
4827
+ loaders: {
4828
+ cts: "ts",
4829
+ ctsx: "tsx",
4830
+ mts: "ts",
4831
+ mtsx: "tsx",
4832
+ cjs: "js",
4833
+ cjsx: "jsx",
4834
+ mjs: "js",
4835
+ mjsx: "jsx"
4836
+ },
4837
+ ...noTypeResolvedBuilderOptions,
4838
+ supported: {
4839
+ "import-attributes": features.keepImportAttributes !== false,
4840
+ ...resolvedBuilderOptions.supported
4841
+ }
4827
4842
  })
4828
4843
  ) : import('rollup-plugin-swc3').then(
4829
4844
  ({ default: swc }) => swc({
@@ -4832,7 +4847,20 @@ const generateConfigs = (context, options = {}) => {
4832
4847
  inline: "inline"
4833
4848
  }[sourcemap] ?? void 0,
4834
4849
  tsconfig: buildTSConfigPath,
4835
- ...noTypeResolvedBuilderOptions
4850
+ ...noTypeResolvedBuilderOptions,
4851
+ jsc: {
4852
+ ...resolvedBuilderOptions.jsc,
4853
+ parser: resolvedBuilderOptions.jsc?.parser ? resolvedBuilderOptions.jsc?.parser : {
4854
+ syntax: "typescript",
4855
+ tsx: true,
4856
+ decorators: true,
4857
+ dynamicImport: true
4858
+ },
4859
+ experimental: {
4860
+ ...resolvedBuilderOptions.jsc?.experimental,
4861
+ keepImportAttributes: features.keepImportAttributes !== false
4862
+ }
4863
+ }
4836
4864
  })
4837
4865
  );
4838
4866
  const [ana, anaOutputPlugin] = bundleAnalyzer((modules) => void publishInEntry("modulesAnalyze", { modules }));
@@ -4851,6 +4879,8 @@ const generateConfigs = (context, options = {}) => {
4851
4879
  sourcemap,
4852
4880
  format,
4853
4881
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4882
+ externalImportAttributes: features.keepImportAttributes !== false,
4883
+ importAttributesKey: features.keepImportAttributes === false || features.keepImportAttributes === void 0 ? void 0 : features.keepImportAttributes === true ? "with" : features.keepImportAttributes,
4854
4884
  plugins: [
4855
4885
  isFormatEsm(format === "esm")
4856
4886
  ]
@@ -4926,10 +4956,8 @@ const generateConfigs = (context, options = {}) => {
4926
4956
  function template(packageJSON) {
4927
4957
  const { name, type, exports: entrypoints$1 } = packageJSON;
4928
4958
  const pkgIsModule = type === "module";
4929
- if (!name)
4930
- throw new Error("package.json name is required");
4931
- if (!entrypoints$1)
4932
- throw new Error("package.json exports is required");
4959
+ if (!name) throw new Error("package.json name is required");
4960
+ if (!entrypoints$1) throw new Error("package.json exports is required");
4933
4961
  const packageName = pascalCase(name);
4934
4962
  const external = externalResolver(packageJSON);
4935
4963
  const [filteredResolvedEntrypoints, exports] = getExports({
@@ -4949,6 +4977,7 @@ function template(packageJSON) {
4949
4977
  }
4950
4978
  return false;
4951
4979
  });
4980
+ console.log(exports);
4952
4981
  const configs = [];
4953
4982
  leafMap.forEach(
4954
4983
  (keysArr, input) => keysArr.forEach((keys) => {
@@ -4155,8 +4155,7 @@ function bundleAnalyzer(modulesResolved) {
4155
4155
  return {
4156
4156
  name: "jiek:bundle-analyzer",
4157
4157
  async closeBundle(...args) {
4158
- if (typeof ana.closeBundle !== "function")
4159
- return;
4158
+ if (typeof ana.closeBundle !== "function") return;
4160
4159
  return ana.closeBundle?.call(this, ...args);
4161
4160
  }
4162
4161
  };
@@ -4238,14 +4237,24 @@ function getExports({
4238
4237
  }
4239
4238
  );
4240
4239
  const crossModuleWithConditional = crossModuleConvertor ? {
4241
- import: (opts) => !pkgIsModule && intersection(
4242
- new Set(opts.conditionals),
4243
- /* @__PURE__ */ new Set(["import", "module"])
4244
- ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4245
- require: (opts) => pkgIsModule && intersection(
4246
- new Set(opts.conditionals),
4247
- /* @__PURE__ */ new Set(["require", "node"])
4248
- ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4240
+ import: (opts) => {
4241
+ if (pkgIsModule) return false;
4242
+ if (opts.src.endsWith(".cts")) return false;
4243
+ if (intersection(
4244
+ new Set(opts.conditionals),
4245
+ /* @__PURE__ */ new Set(["import", "module"])
4246
+ ).size !== 0) return false;
4247
+ return opts.dist.replace(/\.js$/, ".mjs");
4248
+ },
4249
+ require: (opts) => {
4250
+ if (!pkgIsModule) return false;
4251
+ if (opts.src.endsWith(".mts")) return false;
4252
+ if (intersection(
4253
+ new Set(opts.conditionals),
4254
+ /* @__PURE__ */ new Set(["require", "node"])
4255
+ ).size !== 0) return false;
4256
+ return opts.dist.replace(/\.js$/, ".cjs");
4257
+ }
4249
4258
  } : {};
4250
4259
  return [
4251
4260
  filteredResolvedEntrypoints,
@@ -4264,8 +4273,7 @@ function getExports({
4264
4273
 
4265
4274
  let root;
4266
4275
  function getRoot() {
4267
- if (root)
4268
- return root;
4276
+ if (root) return root;
4269
4277
  const rootOption = process.env.JIEK_ROOT;
4270
4278
  root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
4271
4279
  return root;
@@ -4282,8 +4290,7 @@ try {
4282
4290
  let wd;
4283
4291
  let notWorkspace = false;
4284
4292
  function getWD() {
4285
- if (wd)
4286
- return { wd, notWorkspace };
4293
+ if (wd) return { wd, notWorkspace };
4287
4294
  const root = getRoot();
4288
4295
  if (root !== void 0) {
4289
4296
  const isWorkspace = isWorkspaceDir(root, type);
@@ -4405,16 +4412,14 @@ function loadConfig(dirOrOptions) {
4405
4412
  default:
4406
4413
  throw new Error(`unsupported config file type: ${ext}`);
4407
4414
  }
4408
- if (!module)
4409
- throw new Error("config file is empty");
4415
+ if (!module) throw new Error("config file is empty");
4410
4416
  return module.default ?? module;
4411
4417
  }
4412
4418
 
4413
4419
  const recusiveListFiles = (dir) => fs.readdirSync(dir).reduce((acc, file) => {
4414
4420
  const filePath = resolve(dir, file);
4415
4421
  if (fs.statSync(filePath).isDirectory()) {
4416
- if (filePath.endsWith("/node_modules"))
4417
- return acc;
4422
+ if (filePath.endsWith("/node_modules")) return acc;
4418
4423
  return [...acc, ...recusiveListFiles(filePath)];
4419
4424
  }
4420
4425
  return [...acc, filePath];
@@ -4429,8 +4434,7 @@ const getExtendTSConfig = (tsconfigPath) => {
4429
4434
  const extendsPaths = resolvePaths(
4430
4435
  exts !== void 0 ? Array.isArray(exts) ? exts : [exts] : []
4431
4436
  );
4432
- if (extendsPaths.length === 0)
4433
- return tsconfig;
4437
+ if (extendsPaths.length === 0) return tsconfig;
4434
4438
  return extendsPaths.map(getExtendTSConfig).concat(tsconfig).reduce((acc, { compilerOptions = {}, references: _, ...curr }) => ({
4435
4439
  ...acc,
4436
4440
  ...curr,
@@ -4457,24 +4461,20 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4457
4461
  tsconfig.include,
4458
4462
  tsconfig.exclude
4459
4463
  ].map(resolvePaths);
4460
- if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i)))
4461
- return;
4462
- if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0)
4463
- return;
4464
+ if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i))) return;
4465
+ if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0) return;
4464
4466
  let isInclude = false;
4465
4467
  isInclude || (isInclude = files.length > 0 && files.includes(filePath));
4466
4468
  isInclude || (isInclude = include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i)));
4467
4469
  if (isInclude) {
4468
4470
  return tsconfig.compilerOptions ?? {};
4469
4471
  } else {
4470
- if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0)
4471
- return;
4472
+ if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0) return;
4472
4473
  }
4473
4474
  references.reverse();
4474
4475
  for (const ref of references) {
4475
4476
  const compilerOptions = getCompilerOptionsByFilePath(ref, filePath);
4476
- if (compilerOptions)
4477
- return compilerOptions;
4477
+ if (compilerOptions) return compilerOptions;
4478
4478
  }
4479
4479
  return tsconfig.compilerOptions;
4480
4480
  };
@@ -4653,10 +4653,8 @@ const resolveOutputControls = (context, output) => ({
4653
4653
  const resolveWorkspacePath = (p) => resolve(WORKSPACE_ROOT, p);
4654
4654
  const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
4655
4655
  const reveal = (obj, keys) => keys.reduce((acc, key) => {
4656
- if (typeof acc === "string")
4657
- throw new Error("key not found in exports");
4658
- if (!(key in acc))
4659
- throw new Error(`key ${key} not found in exports`);
4656
+ if (typeof acc === "string") throw new Error("key not found in exports");
4657
+ if (!(key in acc)) throw new Error(`key ${key} not found in exports`);
4660
4658
  return acc[key];
4661
4659
  }, obj);
4662
4660
  const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
@@ -4803,11 +4801,28 @@ const generateConfigs = (context, options = {}) => {
4803
4801
  ];
4804
4802
  if (jsOutput && !WITHOUT_JS) {
4805
4803
  const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap;
4804
+ const features = Object.assign({
4805
+ keepImportAttributes: true
4806
+ }, build.features);
4806
4807
  const builder = resolvedBuilderOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(
4807
4808
  ({ default: esbuild }) => esbuild({
4808
4809
  sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4809
4810
  tsconfig: buildTSConfigPath,
4810
- ...noTypeResolvedBuilderOptions
4811
+ loaders: {
4812
+ cts: "ts",
4813
+ ctsx: "tsx",
4814
+ mts: "ts",
4815
+ mtsx: "tsx",
4816
+ cjs: "js",
4817
+ cjsx: "jsx",
4818
+ mjs: "js",
4819
+ mjsx: "jsx"
4820
+ },
4821
+ ...noTypeResolvedBuilderOptions,
4822
+ supported: {
4823
+ "import-attributes": features.keepImportAttributes !== false,
4824
+ ...resolvedBuilderOptions.supported
4825
+ }
4811
4826
  })
4812
4827
  ) : import('rollup-plugin-swc3').then(
4813
4828
  ({ default: swc }) => swc({
@@ -4816,7 +4831,20 @@ const generateConfigs = (context, options = {}) => {
4816
4831
  inline: "inline"
4817
4832
  }[sourcemap] ?? void 0,
4818
4833
  tsconfig: buildTSConfigPath,
4819
- ...noTypeResolvedBuilderOptions
4834
+ ...noTypeResolvedBuilderOptions,
4835
+ jsc: {
4836
+ ...resolvedBuilderOptions.jsc,
4837
+ parser: resolvedBuilderOptions.jsc?.parser ? resolvedBuilderOptions.jsc?.parser : {
4838
+ syntax: "typescript",
4839
+ tsx: true,
4840
+ decorators: true,
4841
+ dynamicImport: true
4842
+ },
4843
+ experimental: {
4844
+ ...resolvedBuilderOptions.jsc?.experimental,
4845
+ keepImportAttributes: features.keepImportAttributes !== false
4846
+ }
4847
+ }
4820
4848
  })
4821
4849
  );
4822
4850
  const [ana, anaOutputPlugin] = bundleAnalyzer((modules) => void publishInEntry("modulesAnalyze", { modules }));
@@ -4835,6 +4863,8 @@ const generateConfigs = (context, options = {}) => {
4835
4863
  sourcemap,
4836
4864
  format,
4837
4865
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4866
+ externalImportAttributes: features.keepImportAttributes !== false,
4867
+ importAttributesKey: features.keepImportAttributes === false || features.keepImportAttributes === void 0 ? void 0 : features.keepImportAttributes === true ? "with" : features.keepImportAttributes,
4838
4868
  plugins: [
4839
4869
  isFormatEsm(format === "esm")
4840
4870
  ]
@@ -4910,10 +4940,8 @@ const generateConfigs = (context, options = {}) => {
4910
4940
  function template(packageJSON) {
4911
4941
  const { name, type, exports: entrypoints } = packageJSON;
4912
4942
  const pkgIsModule = type === "module";
4913
- if (!name)
4914
- throw new Error("package.json name is required");
4915
- if (!entrypoints)
4916
- throw new Error("package.json exports is required");
4943
+ if (!name) throw new Error("package.json name is required");
4944
+ if (!entrypoints) throw new Error("package.json exports is required");
4917
4945
  const packageName = pascalCase(name);
4918
4946
  const external = externalResolver(packageJSON);
4919
4947
  const [filteredResolvedEntrypoints, exports] = getExports({
@@ -4933,6 +4961,7 @@ function template(packageJSON) {
4933
4961
  }
4934
4962
  return false;
4935
4963
  });
4964
+ console.log(exports);
4936
4965
  const configs = [];
4937
4966
  leafMap.forEach(
4938
4967
  (keysArr, input) => keysArr.forEach((keys) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "2.2.2",
4
+ "version": "2.2.3-alpha.2",
5
5
  "description": "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.",
6
6
  "author": "YiJie <yijie4188@gmail.com>",
7
7
  "homepage": "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme",
@@ -61,7 +61,7 @@
61
61
  "jb": "bin/jiek-build.js"
62
62
  },
63
63
  "peerDependencies": {
64
- "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
64
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
65
65
  "@rollup/plugin-terser": "^0.4.4",
66
66
  "esbuild-register": "^3.5.0",
67
67
  "postcss": "^8.4.47",
@@ -72,7 +72,7 @@
72
72
  "vite-bundle-analyzer": "0.16.0-beta.1"
73
73
  },
74
74
  "dependencies": {
75
- "@inquirer/prompts": "^7.1.0",
75
+ "@inquirer/prompts": "^7.2.0",
76
76
  "@jiek/rollup-plugin-dts": "^6.2.1",
77
77
  "@rollup/plugin-commonjs": "^28.0.0",
78
78
  "@rollup/plugin-inject": "^5.0.5",
@@ -471,14 +471,16 @@ command
471
471
  }
472
472
  })
473
473
  await new Promise<void>((resolve, reject) => {
474
- let errorStr = ''
474
+ let errorStr = `rollup build failed\n`
475
+ + `package name: ${manifest.name}\n`
476
+ + `cwd: ${pkgCWD}\n\n`
475
477
  child.stderr?.on('data', (data) => {
476
478
  errorStr += data
477
479
  })
478
480
  child.once('exit', (code) =>
479
481
  code === 0
480
482
  ? resolve()
481
- : reject(new Error(`rollup build failed:\n${errorStr}`)))
483
+ : reject(new Error(errorStr)))
482
484
  verbose && child.stdout?.pipe(process.stdout)
483
485
  })
484
486
  })
@@ -49,6 +49,17 @@ export interface TemplateOptions {
49
49
  | ({
50
50
  type: 'swc'
51
51
  } & import('rollup-plugin-swc3').PluginOptions)
52
+ features?: {
53
+ /**
54
+ * When use esbuild type builder, it will inject `supported.import-attributes` option.
55
+ * When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
56
+ *
57
+ * And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
58
+ *
59
+ * @default true
60
+ */
61
+ keepImportAttributes?: boolean | 'assert'
62
+ }
52
63
  output?: {
53
64
  /**
54
65
  * @default true
@@ -381,12 +381,29 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
381
381
  const sourcemap = typeof options?.output?.sourcemap === 'object'
382
382
  ? options.output.sourcemap.js
383
383
  : options?.output?.sourcemap
384
+ const features = Object.assign({
385
+ keepImportAttributes: true
386
+ }, build.features)
384
387
  const builder = resolvedBuilderOptions.type === 'esbuild'
385
388
  ? import('rollup-plugin-esbuild').then(({ default: esbuild }) =>
386
389
  esbuild({
387
390
  sourceMap: sourcemap === 'hidden' ? false : !!sourcemap,
388
391
  tsconfig: buildTSConfigPath,
389
- ...noTypeResolvedBuilderOptions
392
+ loaders: {
393
+ cts: 'ts',
394
+ ctsx: 'tsx',
395
+ mts: 'ts',
396
+ mtsx: 'tsx',
397
+ cjs: 'js',
398
+ cjsx: 'jsx',
399
+ mjs: 'js',
400
+ mjsx: 'jsx'
401
+ },
402
+ ...noTypeResolvedBuilderOptions,
403
+ supported: {
404
+ 'import-attributes': features.keepImportAttributes !== false,
405
+ ...resolvedBuilderOptions.supported
406
+ }
390
407
  })
391
408
  )
392
409
  : import('rollup-plugin-swc3').then(({ default: swc }) =>
@@ -400,7 +417,22 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
400
417
  inline: 'inline'
401
418
  } as const)[sourcemap] ?? undefined,
402
419
  tsconfig: buildTSConfigPath,
403
- ...noTypeResolvedBuilderOptions
420
+ ...noTypeResolvedBuilderOptions,
421
+ jsc: {
422
+ ...resolvedBuilderOptions.jsc,
423
+ parser: resolvedBuilderOptions.jsc?.parser
424
+ ? resolvedBuilderOptions.jsc?.parser
425
+ : {
426
+ syntax: 'typescript',
427
+ tsx: true,
428
+ decorators: true,
429
+ dynamicImport: true
430
+ },
431
+ experimental: {
432
+ ...resolvedBuilderOptions.jsc?.experimental,
433
+ keepImportAttributes: features.keepImportAttributes !== false
434
+ }
435
+ }
404
436
  })
405
437
  )
406
438
  const [ana, anaOutputPlugin] = bundleAnalyzer(modules => void publishInEntry('modulesAnalyze', { modules }))
@@ -427,6 +459,15 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
427
459
  strict: typeof options?.output?.strict === 'object'
428
460
  ? options.output.strict.js
429
461
  : options?.output?.strict,
462
+ externalImportAttributes: features.keepImportAttributes !== false,
463
+ importAttributesKey: (
464
+ features.keepImportAttributes === false
465
+ || features.keepImportAttributes === undefined
466
+ )
467
+ ? undefined
468
+ : features.keepImportAttributes === true
469
+ ? 'with'
470
+ : features.keepImportAttributes,
430
471
  plugins: [
431
472
  isFormatEsm(format === 'esm')
432
473
  ]
@@ -545,6 +586,7 @@ export function template(packageJSON: PackageJSON): RollupOptions[] {
545
586
  return false
546
587
  })
547
588
 
589
+ console.log(exports)
548
590
  const configs: RollupOptions[] = []
549
591
  leafMap.forEach((keysArr, input) =>
550
592
  keysArr.forEach((keys) => {
@@ -1,7 +1,7 @@
1
+ import { spawnSync } from 'node:child_process'
1
2
  import process from 'node:process'
2
3
 
3
4
  import { confirm } from '@inquirer/prompts'
4
- import { execaCommand } from 'execa'
5
5
 
6
6
  import { getWD } from '#~/utils/getWD.ts'
7
7
 
@@ -13,7 +13,7 @@ export async function checkDependency(dependency: string) {
13
13
  const { notWorkspace } = getWD()
14
14
  const command = `pnpm install -${notWorkspace ? '' : 'w'}D ${dependency}`
15
15
  if (await confirm({ message: 'Do you want to install it now?' })) {
16
- await execaCommand(command)
16
+ spawnSync(command)
17
17
  } else {
18
18
  console.warn(`You can run the command '${command}' to install it manually.`)
19
19
  process.exit(1)
@@ -1,11 +1,11 @@
1
1
  import { isAbsolute, relative, resolve } from 'node:path'
2
2
 
3
3
  import {
4
+ type Entrypoints2ExportsOptions,
5
+ type RecursiveRecord,
4
6
  DEFAULT_SKIP_VALUES,
5
7
  entrypoints2Exports,
6
- type Entrypoints2ExportsOptions,
7
8
  filterLeafs,
8
- type RecursiveRecord,
9
9
  resolveEntrypoints
10
10
  } from '@jiek/pkger/entrypoints'
11
11
  import type { Config } from 'jiek'
@@ -109,20 +109,30 @@ export function getExports({
109
109
  )
110
110
  const crossModuleWithConditional: Entrypoints2ExportsOptions['withConditional'] = crossModuleConvertor
111
111
  ? {
112
- import: opts =>
113
- !pkgIsModule && intersection(
114
- new Set(opts.conditionals),
115
- new Set(['import', 'module'])
116
- ).size === 0
117
- ? opts.dist.replace(/\.js$/, '.mjs')
118
- : false,
119
- require: opts =>
120
- pkgIsModule && intersection(
121
- new Set(opts.conditionals),
122
- new Set(['require', 'node'])
123
- ).size === 0
124
- ? opts.dist.replace(/\.js$/, '.cjs')
125
- : false
112
+ import: opts => {
113
+ if (pkgIsModule) return false
114
+ if (opts.src.endsWith('.cts')) return false
115
+ if (
116
+ intersection(
117
+ new Set(opts.conditionals),
118
+ new Set(['import', 'module'])
119
+ ).size !== 0
120
+ ) return false
121
+
122
+ return opts.dist.replace(/\.js$/, '.mjs')
123
+ },
124
+ require: opts => {
125
+ if (!pkgIsModule) return false
126
+ if (opts.src.endsWith('.mts')) return false
127
+ if (
128
+ intersection(
129
+ new Set(opts.conditionals),
130
+ new Set(['require', 'node'])
131
+ ).size !== 0
132
+ ) return false
133
+
134
+ return opts.dist.replace(/\.js$/, '.cjs')
135
+ }
126
136
  }
127
137
  : {}
128
138
  return [