jiek 2.2.4 → 2.2.5

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.
@@ -0,0 +1 @@
1
+ {"type":"module","module":"../bin-helper.js","main":"../bin-helper.cjs"}
@@ -0,0 +1 @@
1
+ {"type":"module","module":"../dist/cli.js","main":"../dist/cli.cjs"}
@@ -0,0 +1 @@
1
+ {"type":"module","module":"../dist/cli-only-build.js","main":"../dist/cli-only-build.cjs"}
@@ -59,7 +59,7 @@ try {
59
59
  type$1 = "pnpm";
60
60
  } catch {
61
61
  }
62
- function filterPackagesGraph(filters) {
62
+ async function filterPackagesGraph(filters) {
63
63
  return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
64
64
  }
65
65
  async function getSelectedProjectsGraph(filter = commander.program.getOptionValue("filter")) {
@@ -118,7 +118,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
118
118
 
119
119
  var name = "jiek";
120
120
  var type = "module";
121
- var version = "2.2.3-alpha.5";
121
+ var version = "2.2.4";
122
122
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
123
123
  var author = "YiJie <yijie4188@gmail.com>";
124
124
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -646,7 +646,7 @@ command = command.description(description).option("-t, --type <TYPE>", `The type
646
646
  throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
647
647
  }
648
648
  return String(v);
649
- }, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).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(
649
+ }, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("--noConvert", "Specify the `crossModuleConvertor` option to false.", parseBoolean).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(
650
650
  "--minType <MINTYPE>",
651
651
  'The type of minify, support "builder" and "terser".',
652
652
  (v) => {
@@ -673,6 +673,7 @@ command.action(async (commandFiltersOrEntries, options) => {
673
673
  verbose,
674
674
  entries: optionEntries,
675
675
  external,
676
+ noConvert,
676
677
  noJs: withoutJs,
677
678
  noDts: withoutDts,
678
679
  noMin: withoutMin,
@@ -735,6 +736,7 @@ command.action(async (commandFiltersOrEntries, options) => {
735
736
  JIEK_CLEAN: String(!noClean),
736
737
  JIEK_ENTRIES: entries,
737
738
  JIEK_EXTERNAL: external,
739
+ JIEK_CROSS_MODULE_CONVERTOR: String(!noConvert),
738
740
  JIEK_WITHOUT_JS: String(withoutJs),
739
741
  JIEK_WITHOUT_DTS: String(withoutDts),
740
742
  JIEK_WITHOUT_MINIFY: String(withoutMin),
@@ -86,6 +86,30 @@ interface TemplateOptions {
86
86
  js?: InputPluginOption;
87
87
  dts: InputPluginOption;
88
88
  };
89
+ /**
90
+ * https://www.npmjs.com/package/@rollup/plugin-inject#usage
91
+ *
92
+ * @example
93
+ * ```js
94
+ * {
95
+ * // import { Promise } from 'es6-promise'
96
+ * Promise: [ 'es6-promise', 'Promise' ],
97
+ *
98
+ * // import { Promise as P } from 'es6-promise'
99
+ * P: [ 'es6-promise', 'Promise' ],
100
+ *
101
+ * // import $ from 'jquery'
102
+ * $: 'jquery',
103
+ *
104
+ * // import * as fs from 'fs'
105
+ * fs: [ 'fs', '*' ],
106
+ *
107
+ * // use a local module instead of a third-party one
108
+ * 'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
109
+ * }
110
+ * ```
111
+ */
112
+ injects?: Record<string, string | [string, string]>;
89
113
  }
90
114
 
91
115
  declare module 'jiek' {
@@ -86,6 +86,30 @@ interface TemplateOptions {
86
86
  js?: InputPluginOption;
87
87
  dts: InputPluginOption;
88
88
  };
89
+ /**
90
+ * https://www.npmjs.com/package/@rollup/plugin-inject#usage
91
+ *
92
+ * @example
93
+ * ```js
94
+ * {
95
+ * // import { Promise } from 'es6-promise'
96
+ * Promise: [ 'es6-promise', 'Promise' ],
97
+ *
98
+ * // import { Promise as P } from 'es6-promise'
99
+ * P: [ 'es6-promise', 'Promise' ],
100
+ *
101
+ * // import $ from 'jquery'
102
+ * $: 'jquery',
103
+ *
104
+ * // import * as fs from 'fs'
105
+ * fs: [ 'fs', '*' ],
106
+ *
107
+ * // use a local module instead of a third-party one
108
+ * 'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
109
+ * }
110
+ * ```
111
+ */
112
+ injects?: Record<string, string | [string, string]>;
89
113
  }
90
114
 
91
115
  declare module 'jiek' {
@@ -51,7 +51,7 @@ try {
51
51
  type$1 = "pnpm";
52
52
  } catch {
53
53
  }
54
- function filterPackagesGraph(filters) {
54
+ async function filterPackagesGraph(filters) {
55
55
  return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
56
56
  }
57
57
  async function getSelectedProjectsGraph(filter = program.getOptionValue("filter")) {
@@ -110,7 +110,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
110
110
 
111
111
  var name = "jiek";
112
112
  var type = "module";
113
- var version = "2.2.3-alpha.5";
113
+ var version = "2.2.4";
114
114
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
115
115
  var author = "YiJie <yijie4188@gmail.com>";
116
116
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -638,7 +638,7 @@ command = command.description(description).option("-t, --type <TYPE>", `The type
638
638
  throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
639
639
  }
640
640
  return String(v);
641
- }, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).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(
641
+ }, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).option("--noConvert", "Specify the `crossModuleConvertor` option to false.", parseBoolean).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(
642
642
  "--minType <MINTYPE>",
643
643
  'The type of minify, support "builder" and "terser".',
644
644
  (v) => {
@@ -665,6 +665,7 @@ command.action(async (commandFiltersOrEntries, options) => {
665
665
  verbose,
666
666
  entries: optionEntries,
667
667
  external,
668
+ noConvert,
668
669
  noJs: withoutJs,
669
670
  noDts: withoutDts,
670
671
  noMin: withoutMin,
@@ -727,6 +728,7 @@ command.action(async (commandFiltersOrEntries, options) => {
727
728
  JIEK_CLEAN: String(!noClean),
728
729
  JIEK_ENTRIES: entries,
729
730
  JIEK_EXTERNAL: external,
731
+ JIEK_CROSS_MODULE_CONVERTOR: String(!noConvert),
730
732
  JIEK_WITHOUT_JS: String(withoutJs),
731
733
  JIEK_WITHOUT_DTS: String(withoutDts),
732
734
  JIEK_WITHOUT_MINIFY: String(withoutMin),
package/dist/cli.cjs CHANGED
@@ -4245,11 +4245,13 @@ var micromatchExports = requireMicromatch();
4245
4245
 
4246
4246
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4247
4247
  const {
4248
- JIEK_OUT_DIR
4249
- } = process.env;
4248
+ JIEK_OUT_DIR,
4249
+ JIEK_CROSS_MODULE_CONVERTOR
4250
+ } = process__default.default.env;
4250
4251
  const OUTDIR = JIEK_OUT_DIR ?? "dist";
4252
+ const crossModuleConvertorDefault = JIEK_CROSS_MODULE_CONVERTOR === void 0 ? true : JIEK_CROSS_MODULE_CONVERTOR === "true";
4251
4253
  function getOutDirs({
4252
- cwd = process.cwd(),
4254
+ cwd = process__default.default.cwd(),
4253
4255
  defaultOutdir = OUTDIR,
4254
4256
  config,
4255
4257
  pkgName
@@ -4289,7 +4291,7 @@ function getExports({
4289
4291
  } = {}
4290
4292
  } = config ?? {};
4291
4293
  const {
4292
- crossModuleConvertor = true
4294
+ crossModuleConvertor = crossModuleConvertorDefault
4293
4295
  } = build;
4294
4296
  const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
4295
4297
  if (entries) {
@@ -4693,33 +4695,51 @@ async function prepublish({ bumper: bumper$1 } = {}) {
4693
4695
  fs__default.default.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
4694
4696
  fs__default.default.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
4695
4697
  const allBuildFiles = fs__default.default.readdirSync(resolveByDir(resolvedOutdir), { recursive: true }).filter((file) => typeof file === "string").filter((file) => file !== "package.json");
4696
- for (const file of allBuildFiles) {
4697
- const filepath = resolveByDir(resolvedOutdir, file);
4698
- const stat = fs__default.default.statSync(filepath);
4699
- if (stat.isDirectory()) {
4700
- const existsIndexFile = allBuildFiles.some(
4701
- (f) => [
4702
- path__default.default.join(file, "index.js"),
4703
- path__default.default.join(file, "index.mjs"),
4704
- path__default.default.join(file, "index.cjs")
4705
- ].includes(f)
4706
- );
4707
- if (existsIndexFile) {
4708
- const cpDistPath = resolveByDir(resolvedOutdir, resolvedOutdir, file);
4709
- const pkgJSONPath = resolveByDir(resolvedOutdir, file, "package.json");
4710
- const relativePath = path__default.default.relative(filepath, cpDistPath);
4711
- const { type } = manifest;
4712
- fs__default.default.writeFileSync(
4713
- pkgJSONPath,
4714
- JSON.stringify({
4715
- type,
4716
- main: [relativePath, `index.${type === "module" ? "c" : ""}js`].join("/"),
4717
- module: [relativePath, `index.${type === "module" ? "" : "m"}js`].join("/")
4718
- })
4719
- );
4720
- }
4698
+ const resolvedExports = manifest.exports;
4699
+ Object.keys(resolvedExports).forEach((key) => {
4700
+ if (key === ".") return;
4701
+ if (/\.[cm]?js$/.test(key)) return;
4702
+ const resourceFileSuffixes = [
4703
+ ".d.ts",
4704
+ ".d.mts",
4705
+ ".d.cts",
4706
+ ".css",
4707
+ ".scss",
4708
+ ".sass",
4709
+ ".less",
4710
+ ".styl",
4711
+ ".stylus",
4712
+ ".json",
4713
+ ".json5"
4714
+ ];
4715
+ if (resourceFileSuffixes.find((suffix) => key.endsWith(suffix))) return;
4716
+ const value = resolvedExports[key];
4717
+ const filepath = resolveByDir(resolvedOutdir, key);
4718
+ fs__default.default.mkdirSync(filepath, { recursive: true });
4719
+ const pkgJSONPath = resolveByDir(resolvedOutdir, key, "package.json");
4720
+ const relativePath = Array.from({ length: key.split("/").length - 1 }, () => "..").join("/");
4721
+ const { type } = manifest;
4722
+ const pkgJSON = { type };
4723
+ if ("default" in value) {
4724
+ pkgJSON[type === "module" ? "module" : "main"] = [
4725
+ relativePath,
4726
+ value.default?.replace(/^\.\//, "")
4727
+ ].join("/");
4721
4728
  }
4722
- }
4729
+ if ("import" in value) {
4730
+ pkgJSON.module = [
4731
+ relativePath,
4732
+ value.import?.replace(/^\.\//, "")
4733
+ ].join("/");
4734
+ }
4735
+ if ("require" in value) {
4736
+ pkgJSON.main = [
4737
+ relativePath,
4738
+ value.require?.replace(/^\.\//, "")
4739
+ ].join("/");
4740
+ }
4741
+ fs__default.default.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSON));
4742
+ });
4723
4743
  fs__default.default.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir));
4724
4744
  for (const file of allBuildFiles) {
4725
4745
  const filepath = resolveByDir(resolvedOutdir, file);
package/dist/cli.js CHANGED
@@ -4216,11 +4216,13 @@ var micromatchExports = requireMicromatch();
4216
4216
 
4217
4217
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4218
4218
  const {
4219
- JIEK_OUT_DIR
4220
- } = process.env;
4219
+ JIEK_OUT_DIR,
4220
+ JIEK_CROSS_MODULE_CONVERTOR
4221
+ } = process$1.env;
4221
4222
  const OUTDIR = JIEK_OUT_DIR ?? "dist";
4223
+ const crossModuleConvertorDefault = JIEK_CROSS_MODULE_CONVERTOR === void 0 ? true : JIEK_CROSS_MODULE_CONVERTOR === "true";
4222
4224
  function getOutDirs({
4223
- cwd = process.cwd(),
4225
+ cwd = process$1.cwd(),
4224
4226
  defaultOutdir = OUTDIR,
4225
4227
  config,
4226
4228
  pkgName
@@ -4260,7 +4262,7 @@ function getExports({
4260
4262
  } = {}
4261
4263
  } = config ?? {};
4262
4264
  const {
4263
- crossModuleConvertor = true
4265
+ crossModuleConvertor = crossModuleConvertorDefault
4264
4266
  } = build;
4265
4267
  const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints);
4266
4268
  if (entries) {
@@ -4664,33 +4666,51 @@ async function prepublish({ bumper } = {}) {
4664
4666
  fs.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
4665
4667
  fs.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
4666
4668
  const allBuildFiles = fs.readdirSync(resolveByDir(resolvedOutdir), { recursive: true }).filter((file) => typeof file === "string").filter((file) => file !== "package.json");
4667
- for (const file of allBuildFiles) {
4668
- const filepath = resolveByDir(resolvedOutdir, file);
4669
- const stat = fs.statSync(filepath);
4670
- if (stat.isDirectory()) {
4671
- const existsIndexFile = allBuildFiles.some(
4672
- (f) => [
4673
- path.join(file, "index.js"),
4674
- path.join(file, "index.mjs"),
4675
- path.join(file, "index.cjs")
4676
- ].includes(f)
4677
- );
4678
- if (existsIndexFile) {
4679
- const cpDistPath = resolveByDir(resolvedOutdir, resolvedOutdir, file);
4680
- const pkgJSONPath = resolveByDir(resolvedOutdir, file, "package.json");
4681
- const relativePath = path.relative(filepath, cpDistPath);
4682
- const { type } = manifest;
4683
- fs.writeFileSync(
4684
- pkgJSONPath,
4685
- JSON.stringify({
4686
- type,
4687
- main: [relativePath, `index.${type === "module" ? "c" : ""}js`].join("/"),
4688
- module: [relativePath, `index.${type === "module" ? "" : "m"}js`].join("/")
4689
- })
4690
- );
4691
- }
4669
+ const resolvedExports = manifest.exports;
4670
+ Object.keys(resolvedExports).forEach((key) => {
4671
+ if (key === ".") return;
4672
+ if (/\.[cm]?js$/.test(key)) return;
4673
+ const resourceFileSuffixes = [
4674
+ ".d.ts",
4675
+ ".d.mts",
4676
+ ".d.cts",
4677
+ ".css",
4678
+ ".scss",
4679
+ ".sass",
4680
+ ".less",
4681
+ ".styl",
4682
+ ".stylus",
4683
+ ".json",
4684
+ ".json5"
4685
+ ];
4686
+ if (resourceFileSuffixes.find((suffix) => key.endsWith(suffix))) return;
4687
+ const value = resolvedExports[key];
4688
+ const filepath = resolveByDir(resolvedOutdir, key);
4689
+ fs.mkdirSync(filepath, { recursive: true });
4690
+ const pkgJSONPath = resolveByDir(resolvedOutdir, key, "package.json");
4691
+ const relativePath = Array.from({ length: key.split("/").length - 1 }, () => "..").join("/");
4692
+ const { type } = manifest;
4693
+ const pkgJSON = { type };
4694
+ if ("default" in value) {
4695
+ pkgJSON[type === "module" ? "module" : "main"] = [
4696
+ relativePath,
4697
+ value.default?.replace(/^\.\//, "")
4698
+ ].join("/");
4692
4699
  }
4693
- }
4700
+ if ("import" in value) {
4701
+ pkgJSON.module = [
4702
+ relativePath,
4703
+ value.import?.replace(/^\.\//, "")
4704
+ ].join("/");
4705
+ }
4706
+ if ("require" in value) {
4707
+ pkgJSON.main = [
4708
+ relativePath,
4709
+ value.require?.replace(/^\.\//, "")
4710
+ ].join("/");
4711
+ }
4712
+ fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSON));
4713
+ });
4694
4714
  fs.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir));
4695
4715
  for (const file of allBuildFiles) {
4696
4716
  const filepath = resolveByDir(resolvedOutdir, file);
package/dist/index.d.cts CHANGED
@@ -86,6 +86,30 @@ interface TemplateOptions {
86
86
  js?: InputPluginOption;
87
87
  dts: InputPluginOption;
88
88
  };
89
+ /**
90
+ * https://www.npmjs.com/package/@rollup/plugin-inject#usage
91
+ *
92
+ * @example
93
+ * ```js
94
+ * {
95
+ * // import { Promise } from 'es6-promise'
96
+ * Promise: [ 'es6-promise', 'Promise' ],
97
+ *
98
+ * // import { Promise as P } from 'es6-promise'
99
+ * P: [ 'es6-promise', 'Promise' ],
100
+ *
101
+ * // import $ from 'jquery'
102
+ * $: 'jquery',
103
+ *
104
+ * // import * as fs from 'fs'
105
+ * fs: [ 'fs', '*' ],
106
+ *
107
+ * // use a local module instead of a third-party one
108
+ * 'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
109
+ * }
110
+ * ```
111
+ */
112
+ injects?: Record<string, string | [string, string]>;
89
113
  }
90
114
 
91
115
  declare module 'jiek' {
package/dist/index.d.ts CHANGED
@@ -86,6 +86,30 @@ interface TemplateOptions {
86
86
  js?: InputPluginOption;
87
87
  dts: InputPluginOption;
88
88
  };
89
+ /**
90
+ * https://www.npmjs.com/package/@rollup/plugin-inject#usage
91
+ *
92
+ * @example
93
+ * ```js
94
+ * {
95
+ * // import { Promise } from 'es6-promise'
96
+ * Promise: [ 'es6-promise', 'Promise' ],
97
+ *
98
+ * // import { Promise as P } from 'es6-promise'
99
+ * P: [ 'es6-promise', 'Promise' ],
100
+ *
101
+ * // import $ from 'jquery'
102
+ * $: 'jquery',
103
+ *
104
+ * // import * as fs from 'fs'
105
+ * fs: [ 'fs', '*' ],
106
+ *
107
+ * // use a local module instead of a third-party one
108
+ * 'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
109
+ * }
110
+ * ```
111
+ */
112
+ injects?: Record<string, string | [string, string]>;
89
113
  }
90
114
 
91
115
  declare module 'jiek' {
@@ -4185,11 +4185,13 @@ function bundleAnalyzer(modulesResolved) {
4185
4185
 
4186
4186
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4187
4187
  const {
4188
- JIEK_OUT_DIR
4189
- } = process.env;
4188
+ JIEK_OUT_DIR,
4189
+ JIEK_CROSS_MODULE_CONVERTOR
4190
+ } = process__default.default.env;
4190
4191
  const OUTDIR = JIEK_OUT_DIR ?? "dist";
4192
+ const crossModuleConvertorDefault = JIEK_CROSS_MODULE_CONVERTOR === void 0 ? true : JIEK_CROSS_MODULE_CONVERTOR === "true";
4191
4193
  function getOutDirs({
4192
- cwd = process.cwd(),
4194
+ cwd = process__default.default.cwd(),
4193
4195
  defaultOutdir = OUTDIR,
4194
4196
  config,
4195
4197
  pkgName
@@ -4229,7 +4231,7 @@ function getExports({
4229
4231
  } = {}
4230
4232
  } = config ?? {};
4231
4233
  const {
4232
- crossModuleConvertor = true
4234
+ crossModuleConvertor = crossModuleConvertorDefault
4233
4235
  } = build;
4234
4236
  const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
4235
4237
  if (entries) {
@@ -4865,7 +4867,11 @@ const generateConfigs = (context, options = {}) => {
4865
4867
  builder,
4866
4868
  // inject plugin can't resolve `import type`, so we should register it after the builder plugin
4867
4869
  inject__default.default({
4868
- require: CREATE_REQUIRE_VIRTUAL_MODULE_NAME
4870
+ sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4871
+ modules: {
4872
+ ...build.injects ?? {},
4873
+ require: CREATE_REQUIRE_VIRTUAL_MODULE_NAME
4874
+ }
4869
4875
  }),
4870
4876
  createRequire(format === "esm"),
4871
4877
  ana,
@@ -4877,13 +4883,14 @@ const generateConfigs = (context, options = {}) => {
4877
4883
  });
4878
4884
  }
4879
4885
  if (dtsOutput && !WITHOUT_DTS) {
4886
+ const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap;
4880
4887
  rollupOptions.push({
4881
4888
  input: inputObj,
4882
4889
  external,
4883
4890
  output: [
4884
4891
  {
4885
4892
  dir: dtsOutdir,
4886
- sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap,
4893
+ sourcemap,
4887
4894
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process__default.default.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, tsOutputSuffix) : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, tsOutputSuffix),
4888
4895
  strict: typeof options?.output?.strict === "object" ? options.output.strict.dts : options?.output?.strict
4889
4896
  }
@@ -4171,11 +4171,13 @@ function bundleAnalyzer(modulesResolved) {
4171
4171
 
4172
4172
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4173
4173
  const {
4174
- JIEK_OUT_DIR
4175
- } = process.env;
4174
+ JIEK_OUT_DIR,
4175
+ JIEK_CROSS_MODULE_CONVERTOR
4176
+ } = process$1.env;
4176
4177
  const OUTDIR = JIEK_OUT_DIR ?? "dist";
4178
+ const crossModuleConvertorDefault = JIEK_CROSS_MODULE_CONVERTOR === void 0 ? true : JIEK_CROSS_MODULE_CONVERTOR === "true";
4177
4179
  function getOutDirs({
4178
- cwd = process.cwd(),
4180
+ cwd = process$1.cwd(),
4179
4181
  defaultOutdir = OUTDIR,
4180
4182
  config,
4181
4183
  pkgName
@@ -4215,7 +4217,7 @@ function getExports({
4215
4217
  } = {}
4216
4218
  } = config ?? {};
4217
4219
  const {
4218
- crossModuleConvertor = true
4220
+ crossModuleConvertor = crossModuleConvertorDefault
4219
4221
  } = build;
4220
4222
  const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints);
4221
4223
  if (entries) {
@@ -4851,7 +4853,11 @@ const generateConfigs = (context, options = {}) => {
4851
4853
  builder,
4852
4854
  // inject plugin can't resolve `import type`, so we should register it after the builder plugin
4853
4855
  inject({
4854
- require: CREATE_REQUIRE_VIRTUAL_MODULE_NAME
4856
+ sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4857
+ modules: {
4858
+ ...build.injects ?? {},
4859
+ require: CREATE_REQUIRE_VIRTUAL_MODULE_NAME
4860
+ }
4855
4861
  }),
4856
4862
  createRequire(format === "esm"),
4857
4863
  ana,
@@ -4863,13 +4869,14 @@ const generateConfigs = (context, options = {}) => {
4863
4869
  });
4864
4870
  }
4865
4871
  if (dtsOutput && !WITHOUT_DTS) {
4872
+ const sourcemap = typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap;
4866
4873
  rollupOptions.push({
4867
4874
  input: inputObj,
4868
4875
  external,
4869
4876
  output: [
4870
4877
  {
4871
4878
  dir: dtsOutdir,
4872
- sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap,
4879
+ sourcemap,
4873
4880
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process$1.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, tsOutputSuffix) : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, tsOutputSuffix),
4874
4881
  strict: typeof options?.output?.strict === "object" ? options.output.strict.dts : options?.output?.strict
4875
4882
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "2.2.4",
4
+ "version": "2.2.5",
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",
@@ -86,8 +86,8 @@
86
86
  "jsonc-parser": "^3.2.1",
87
87
  "koa": "^2.15.3",
88
88
  "rollup": "^4.0.0",
89
- "@jiek/utils": "^0.2.3",
90
- "@jiek/pkger": "^0.2.1"
89
+ "@jiek/pkger": "^0.2.1",
90
+ "@jiek/utils": "^0.2.3"
91
91
  },
92
92
  "peerDependenciesMeta": {
93
93
  "@pnpm/filter-workspace-packages": {
@@ -1 +1 @@
1
- {"type":"module","main":"../dist/rollup/index.cjs","module":"../dist/rollup/index.js"}
1
+ {"type":"module","module":"../dist/rollup/index.js","main":"../dist/rollup/index.cjs"}
@@ -72,6 +72,7 @@ interface BuildOptions extends AnalyzerBuildOptions {
72
72
  verbose: boolean
73
73
  entries?: string
74
74
  external?: string
75
+ noConvert: boolean
75
76
  noJs: boolean
76
77
  noDts: boolean
77
78
  noMin: boolean
@@ -151,6 +152,7 @@ command = command
151
152
  .option('-o, --outdir <OUTDIR>', outdirDescription, String, 'dist')
152
153
  .option('-e, --entries <ENTRIES>', entriesDescription)
153
154
  .option('--external <EXTERNAL>', 'Specify the external dependencies of the package.', String)
155
+ .option('--noConvert', 'Specify the `crossModuleConvertor` option to false.', parseBoolean)
154
156
  .option('-nj, --noJs', 'Do not output js files.', parseBoolean)
155
157
  .option('-nd, --noDts', 'Do not output dts files.', parseBoolean)
156
158
  .option('-nm, --noMin', 'Do not output minify files.', parseBoolean)
@@ -195,6 +197,7 @@ command
195
197
  verbose,
196
198
  entries: optionEntries,
197
199
  external,
200
+ noConvert,
198
201
  noJs: withoutJs,
199
202
  noDts: withoutDts,
200
203
  noMin: withoutMin,
@@ -266,6 +269,7 @@ command
266
269
  JIEK_CLEAN: String(!noClean),
267
270
  JIEK_ENTRIES: entries,
268
271
  JIEK_EXTERNAL: external,
272
+ JIEK_CROSS_MODULE_CONVERTOR: String(!noConvert),
269
273
  JIEK_WITHOUT_JS: String(withoutJs),
270
274
  JIEK_WITHOUT_DTS: String(withoutDts),
271
275
  JIEK_WITHOUT_MINIFY: String(withoutMin),
@@ -324,34 +324,63 @@ async function prepublish({ bumper }: {
324
324
  .readdirSync(resolveByDir(resolvedOutdir), { recursive: true })
325
325
  .filter(file => typeof file === 'string')
326
326
  .filter(file => file !== 'package.json')
327
- for (const file of allBuildFiles) {
328
- const filepath = resolveByDir(resolvedOutdir, file)
329
- const stat = fs.statSync(filepath)
330
- if (stat.isDirectory()) {
331
- const existsIndexFile = allBuildFiles
332
- .some(f =>
333
- [
334
- path.join(file, 'index.js'),
335
- path.join(file, 'index.mjs'),
336
- path.join(file, 'index.cjs')
337
- ].includes(f)
338
- )
339
- if (existsIndexFile) {
340
- const cpDistPath = resolveByDir(resolvedOutdir, resolvedOutdir, file)
341
- const pkgJSONPath = resolveByDir(resolvedOutdir, file, 'package.json')
342
- const relativePath = path.relative(filepath, cpDistPath)
343
- const { type } = manifest
344
- fs.writeFileSync(
345
- pkgJSONPath,
346
- JSON.stringify({
347
- type,
348
- main: [relativePath, `index.${type === 'module' ? 'c' : ''}js`].join('/'),
349
- module: [relativePath, `index.${type === 'module' ? '' : 'm'}js`].join('/')
350
- })
351
- )
327
+ const resolvedExports = manifest.exports as Record<string, unknown>
328
+ Object
329
+ .keys(resolvedExports)
330
+ .forEach(key => {
331
+ if (key === '.') return
332
+ if (/\.[cm]?js$/.test(key)) return
333
+ // resource file suffix
334
+ const resourceFileSuffixes = [
335
+ '.d.ts',
336
+ '.d.mts',
337
+ '.d.cts',
338
+ '.css',
339
+ '.scss',
340
+ '.sass',
341
+ '.less',
342
+ '.styl',
343
+ '.stylus',
344
+ '.json',
345
+ '.json5'
346
+ ]
347
+ if (resourceFileSuffixes.find(suffix => key.endsWith(suffix))) return
348
+
349
+ const value = resolvedExports[key] as {
350
+ import?: string
351
+ require?: string
352
+ default?: string
352
353
  }
353
- }
354
- }
354
+
355
+ const filepath = resolveByDir(resolvedOutdir, key)
356
+
357
+ fs.mkdirSync(filepath, { recursive: true })
358
+ const pkgJSONPath = resolveByDir(resolvedOutdir, key, 'package.json')
359
+ const relativePath = Array.from({ length: key.split('/').length - 1 }, () => '..').join('/')
360
+ const { type } = manifest
361
+ const pkgJSON: Record<string, unknown> = { type }
362
+ if ('default' in value) {
363
+ pkgJSON[
364
+ type === 'module' ? 'module' : 'main'
365
+ ] = [
366
+ relativePath,
367
+ value.default?.replace(/^\.\//, '')
368
+ ].join('/')
369
+ }
370
+ if ('import' in value) {
371
+ pkgJSON.module = [
372
+ relativePath,
373
+ value.import?.replace(/^\.\//, '')
374
+ ].join('/')
375
+ }
376
+ if ('require' in value) {
377
+ pkgJSON.main = [
378
+ relativePath,
379
+ value.require?.replace(/^\.\//, '')
380
+ ].join('/')
381
+ }
382
+ fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSON))
383
+ })
355
384
  fs.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir))
356
385
  for (const file of allBuildFiles) {
357
386
  const filepath = resolveByDir(resolvedOutdir, file)
@@ -110,4 +110,28 @@ export interface TemplateOptions {
110
110
  js?: InputPluginOption
111
111
  dts: InputPluginOption
112
112
  }
113
+ /**
114
+ * https://www.npmjs.com/package/@rollup/plugin-inject#usage
115
+ *
116
+ * @example
117
+ * ```js
118
+ * {
119
+ * // import { Promise } from 'es6-promise'
120
+ * Promise: [ 'es6-promise', 'Promise' ],
121
+ *
122
+ * // import { Promise as P } from 'es6-promise'
123
+ * P: [ 'es6-promise', 'Promise' ],
124
+ *
125
+ * // import $ from 'jquery'
126
+ * $: 'jquery',
127
+ *
128
+ * // import * as fs from 'fs'
129
+ * fs: [ 'fs', '*' ],
130
+ *
131
+ * // use a local module instead of a third-party one
132
+ * 'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
133
+ * }
134
+ * ```
135
+ */
136
+ injects?: Record<string, string | [string, string]>
113
137
  }
@@ -486,7 +486,11 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
486
486
  builder,
487
487
  // inject plugin can't resolve `import type`, so we should register it after the builder plugin
488
488
  inject({
489
- require: CREATE_REQUIRE_VIRTUAL_MODULE_NAME
489
+ sourceMap: sourcemap === 'hidden' ? false : !!sourcemap,
490
+ modules: {
491
+ ...build.injects ?? {},
492
+ require: CREATE_REQUIRE_VIRTUAL_MODULE_NAME
493
+ }
490
494
  }),
491
495
  createRequire(format === 'esm'),
492
496
  ana,
@@ -499,15 +503,16 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
499
503
  }
500
504
 
501
505
  if (dtsOutput && !WITHOUT_DTS) {
506
+ const sourcemap = typeof options?.output?.sourcemap === 'object'
507
+ ? options.output.sourcemap.dts
508
+ : options?.output?.sourcemap
502
509
  rollupOptions.push({
503
510
  input: inputObj,
504
511
  external,
505
512
  output: [
506
513
  {
507
514
  dir: dtsOutdir,
508
- sourcemap: typeof options?.output?.sourcemap === 'object'
509
- ? options.output.sourcemap.dts
510
- : options?.output?.sourcemap,
515
+ sourcemap,
511
516
  entryFileNames: (chunkInfo) => (
512
517
  Array.isArray(inputObj)
513
518
  ? chunkInfo.facadeModuleId!.replace(`${process.cwd()}/`, '')
@@ -24,7 +24,7 @@ export interface ProjectsGraph {
24
24
  }>
25
25
  }
26
26
 
27
- export function filterPackagesGraph(filters: string[]): Promise<ProjectsGraph[]> {
27
+ export async function filterPackagesGraph(filters: string[]): Promise<ProjectsGraph[]> {
28
28
  return Promise.all(filters.map(async filter => getSelectedProjectsGraph(filter)))
29
29
  }
30
30
 
@@ -1,4 +1,5 @@
1
1
  import { isAbsolute, relative, resolve } from 'node:path'
2
+ import process from 'node:process'
2
3
 
3
4
  import {
4
5
  type Entrypoints2ExportsOptions,
@@ -14,10 +15,14 @@ import { isMatch } from 'micromatch'
14
15
  const intersection = <T>(a: Set<T>, b: Set<T>) => new Set([...a].filter(i => b.has(i)))
15
16
 
16
17
  const {
17
- JIEK_OUT_DIR
18
+ JIEK_OUT_DIR,
19
+ JIEK_CROSS_MODULE_CONVERTOR
18
20
  } = process.env
19
21
 
20
22
  const OUTDIR = JIEK_OUT_DIR ?? 'dist'
23
+ const crossModuleConvertorDefault = JIEK_CROSS_MODULE_CONVERTOR === undefined
24
+ ? true
25
+ : JIEK_CROSS_MODULE_CONVERTOR === 'true'
21
26
 
22
27
  export function getOutDirs({
23
28
  cwd = process.cwd(),
@@ -85,7 +90,7 @@ export function getExports({
85
90
  } = {}
86
91
  } = config ?? {}
87
92
  const {
88
- crossModuleConvertor = true
93
+ crossModuleConvertor = crossModuleConvertorDefault
89
94
  } = build
90
95
  const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints)
91
96
  if (entries) {