jiek 2.2.1 → 2.2.3-alpha.1

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.
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];
@@ -4443,10 +4448,9 @@ const getExtendTSConfig = (tsconfigPath) => {
4443
4448
  const { extends: exts, ...tsconfig } = getTSConfig(tsconfigPath);
4444
4449
  const resolvePaths = (paths) => paths?.map((p) => path.resolve(tsconfigPathDirname, p)) ?? [];
4445
4450
  const extendsPaths = resolvePaths(
4446
- exts ? Array.isArray(exts) ? exts : [exts] : []
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" };
@@ -4692,7 +4690,7 @@ const withMinify = (output, onlyOncePlugins = []) => {
4692
4690
  const minifyPlugin = resolvedMinifyOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(({ minify: minify2 }) => minify2(noTypeResolvedMinifyOptions)) : resolvedMinifyOptions.type === "swc" ? import('rollup-plugin-swc3').then(({ minify: minify2 }) => minify2(noTypeResolvedMinifyOptions)) : import('@rollup/plugin-terser').then(({ default: minify2 }) => minify2(noTypeResolvedMinifyOptions));
4693
4691
  return minify === "only-minify" ? [{
4694
4692
  ...output,
4695
- // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
4693
+ // TODO replace suffix when publish to npm and the `build.output.minify` is 'only-minify'
4696
4694
  // TODO resolve dts output file name
4697
4695
  entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo) : (() => {
4698
4696
  throw new Error("entryFileNames must be a function");
@@ -4799,15 +4797,48 @@ const generateConfigs = (context, options = {}) => {
4799
4797
  const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output);
4800
4798
  const rollupOptions = [];
4801
4799
  const commonPlugins = [
4802
- pluginNodeResolve.nodeResolve({ exportConditions })
4800
+ pluginNodeResolve.nodeResolve({
4801
+ exportConditions,
4802
+ extensions: [
4803
+ ".js",
4804
+ ".cjs",
4805
+ ".mjs",
4806
+ ".jsx",
4807
+ ".cjsx",
4808
+ ".mjsx",
4809
+ ".ts",
4810
+ ".cts",
4811
+ ".mts",
4812
+ ".tsx",
4813
+ ".ctsx",
4814
+ ".mtsx"
4815
+ ]
4816
+ })
4803
4817
  ];
4804
4818
  if (jsOutput && !WITHOUT_JS) {
4805
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);
4806
4823
  const builder = resolvedBuilderOptions.type === "esbuild" ? import('rollup-plugin-esbuild').then(
4807
4824
  ({ default: esbuild }) => esbuild({
4808
4825
  sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4809
4826
  tsconfig: buildTSConfigPath,
4810
- ...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
+ }
4811
4842
  })
4812
4843
  ) : import('rollup-plugin-swc3').then(
4813
4844
  ({ default: swc }) => swc({
@@ -4816,7 +4847,14 @@ const generateConfigs = (context, options = {}) => {
4816
4847
  inline: "inline"
4817
4848
  }[sourcemap] ?? void 0,
4818
4849
  tsconfig: buildTSConfigPath,
4819
- ...noTypeResolvedBuilderOptions
4850
+ ...noTypeResolvedBuilderOptions,
4851
+ jsc: {
4852
+ ...resolvedBuilderOptions.jsc,
4853
+ experimental: {
4854
+ ...resolvedBuilderOptions.jsc?.experimental,
4855
+ keepImportAttributes: features.keepImportAttributes !== false
4856
+ }
4857
+ }
4820
4858
  })
4821
4859
  );
4822
4860
  const [ana, anaOutputPlugin] = bundleAnalyzer((modules) => void publishInEntry("modulesAnalyze", { modules }));
@@ -4835,6 +4873,8 @@ const generateConfigs = (context, options = {}) => {
4835
4873
  sourcemap,
4836
4874
  format,
4837
4875
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4876
+ externalImportAttributes: features.keepImportAttributes !== false,
4877
+ importAttributesKey: features.keepImportAttributes === false || features.keepImportAttributes === void 0 ? void 0 : features.keepImportAttributes === true ? "with" : features.keepImportAttributes,
4838
4878
  plugins: [
4839
4879
  isFormatEsm(format === "esm")
4840
4880
  ]
@@ -4910,10 +4950,8 @@ const generateConfigs = (context, options = {}) => {
4910
4950
  function template(packageJSON) {
4911
4951
  const { name, type, exports: entrypoints$1 } = packageJSON;
4912
4952
  const pkgIsModule = type === "module";
4913
- if (!name)
4914
- throw new Error("package.json name is required");
4915
- if (!entrypoints$1)
4916
- throw new Error("package.json exports is required");
4953
+ if (!name) throw new Error("package.json name is required");
4954
+ if (!entrypoints$1) throw new Error("package.json exports is required");
4917
4955
  const packageName = pascalCase(name);
4918
4956
  const external = externalResolver(packageJSON);
4919
4957
  const [filteredResolvedEntrypoints, exports] = getExports({
@@ -4933,6 +4971,7 @@ function template(packageJSON) {
4933
4971
  }
4934
4972
  return false;
4935
4973
  });
4974
+ console.log(exports);
4936
4975
  const configs = [];
4937
4976
  leafMap.forEach(
4938
4977
  (keysArr, input) => keysArr.forEach((keys) => {