jiek 2.2.3 → 2.2.5-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
@@ -8,7 +8,6 @@ var bumper = require('@jiek/utils/bumper');
8
8
  var commander = require('commander');
9
9
  var detectIndent = require('detect-indent');
10
10
  var jsoncParser = require('jsonc-parser');
11
- var node_module = require('node:module');
12
11
  var jsYaml = require('js-yaml');
13
12
  var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
14
13
  var entrypoints = require('@jiek/pkger/entrypoints');
@@ -16,7 +15,6 @@ var require$$0 = require('util');
16
15
  var require$$0$1 = require('path');
17
16
  require('jiek/cli-only-build');
18
17
 
19
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
20
18
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
21
19
 
22
20
  function _interopNamespace(e) {
@@ -45,6 +43,8 @@ var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
45
43
  var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
46
44
  var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
47
45
 
46
+ var require$1 = require;
47
+
48
48
  let root;
49
49
  function getRoot() {
50
50
  if (root) return root;
@@ -79,7 +79,6 @@ function getWD() {
79
79
 
80
80
  let type = "";
81
81
  try {
82
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
83
82
  require$1.resolve("@pnpm/filter-workspace-packages");
84
83
  type = "pnpm";
85
84
  } catch {
@@ -4246,11 +4245,13 @@ var micromatchExports = requireMicromatch();
4246
4245
 
4247
4246
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4248
4247
  const {
4249
- JIEK_OUT_DIR
4250
- } = process.env;
4248
+ JIEK_OUT_DIR,
4249
+ JIEK_CROSS_MODULE_CONVERTOR
4250
+ } = process__default.default.env;
4251
4251
  const OUTDIR = JIEK_OUT_DIR ?? "dist";
4252
+ const crossModuleConvertorDefault = JIEK_CROSS_MODULE_CONVERTOR === void 0 ? true : JIEK_CROSS_MODULE_CONVERTOR === "true";
4252
4253
  function getOutDirs({
4253
- cwd = process.cwd(),
4254
+ cwd = process__default.default.cwd(),
4254
4255
  defaultOutdir = OUTDIR,
4255
4256
  config,
4256
4257
  pkgName
@@ -4290,7 +4291,7 @@ function getExports({
4290
4291
  } = {}
4291
4292
  } = config ?? {};
4292
4293
  const {
4293
- crossModuleConvertor = true
4294
+ crossModuleConvertor = crossModuleConvertorDefault
4294
4295
  } = build;
4295
4296
  const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
4296
4297
  if (entries) {
@@ -4311,14 +4312,24 @@ function getExports({
4311
4312
  }
4312
4313
  );
4313
4314
  const crossModuleWithConditional = crossModuleConvertor ? {
4314
- import: (opts) => !pkgIsModule && intersection(
4315
- new Set(opts.conditionals),
4316
- /* @__PURE__ */ new Set(["import", "module"])
4317
- ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4318
- require: (opts) => pkgIsModule && intersection(
4319
- new Set(opts.conditionals),
4320
- /* @__PURE__ */ new Set(["require", "node"])
4321
- ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4315
+ import: (opts) => {
4316
+ if (pkgIsModule) return false;
4317
+ if (opts.src.endsWith(".cts")) return false;
4318
+ if (intersection(
4319
+ new Set(opts.conditionals),
4320
+ /* @__PURE__ */ new Set(["import", "module"])
4321
+ ).size !== 0) return false;
4322
+ return opts.dist.replace(/\.js$/, ".mjs");
4323
+ },
4324
+ require: (opts) => {
4325
+ if (!pkgIsModule) return false;
4326
+ if (opts.src.endsWith(".mts")) return false;
4327
+ if (intersection(
4328
+ new Set(opts.conditionals),
4329
+ /* @__PURE__ */ new Set(["require", "node"])
4330
+ ).size !== 0) return false;
4331
+ return opts.dist.replace(/\.js$/, ".cjs");
4332
+ }
4322
4333
  } : {};
4323
4334
  return [
4324
4335
  filteredResolvedEntrypoints,
@@ -4335,10 +4346,9 @@ function getExports({
4335
4346
  ];
4336
4347
  }
4337
4348
 
4338
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
4339
4349
  function packageIsExist(name) {
4340
4350
  try {
4341
- require$2.resolve(name);
4351
+ require$1.resolve(name);
4342
4352
  return true;
4343
4353
  } catch (e) {
4344
4354
  return false;
@@ -4358,7 +4368,6 @@ for (const register of registers) {
4358
4368
  }
4359
4369
  }
4360
4370
 
4361
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
4362
4371
  let configName = "jiek.config";
4363
4372
  function getConfigPath(root, dir) {
4364
4373
  const isSupportTsLoader = !!tsRegisterName;
@@ -4686,33 +4695,51 @@ async function prepublish({ bumper: bumper$1 } = {}) {
4686
4695
  fs__default.default.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
4687
4696
  fs__default.default.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
4688
4697
  const allBuildFiles = fs__default.default.readdirSync(resolveByDir(resolvedOutdir), { recursive: true }).filter((file) => typeof file === "string").filter((file) => file !== "package.json");
4689
- for (const file of allBuildFiles) {
4690
- const filepath = resolveByDir(resolvedOutdir, file);
4691
- const stat = fs__default.default.statSync(filepath);
4692
- if (stat.isDirectory()) {
4693
- const existsIndexFile = allBuildFiles.some(
4694
- (f) => [
4695
- path__default.default.join(file, "index.js"),
4696
- path__default.default.join(file, "index.mjs"),
4697
- path__default.default.join(file, "index.cjs")
4698
- ].includes(f)
4699
- );
4700
- if (existsIndexFile) {
4701
- const cpDistPath = resolveByDir(resolvedOutdir, resolvedOutdir, file);
4702
- const pkgJSONPath = resolveByDir(resolvedOutdir, file, "package.json");
4703
- const relativePath = path__default.default.relative(filepath, cpDistPath);
4704
- const { type } = manifest;
4705
- fs__default.default.writeFileSync(
4706
- pkgJSONPath,
4707
- JSON.stringify({
4708
- type,
4709
- main: [relativePath, `index.${type === "module" ? "c" : ""}js`].join("/"),
4710
- module: [relativePath, `index.${type === "module" ? "" : "m"}js`].join("/")
4711
- })
4712
- );
4713
- }
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("/");
4714
4728
  }
4715
- }
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
+ });
4716
4743
  fs__default.default.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir));
4717
4744
  for (const file of allBuildFiles) {
4718
4745
  const filepath = resolveByDir(resolvedOutdir, file);
@@ -4767,12 +4794,15 @@ async function prepublish({ bumper: bumper$1 } = {}) {
4767
4794
  async function postpublish() {
4768
4795
  await forEachSelectedProjectsGraphEntries((dir) => {
4769
4796
  const jiekTempDir = path__default.default.resolve(dir, "node_modules/.jiek/.tmp");
4770
- const packageJSON = path__default.default.resolve(dir, "package.json");
4771
- const jiekTempPackageJSON = path__default.default.resolve(jiekTempDir, "package.json");
4772
- if (fs__default.default.existsSync(jiekTempPackageJSON)) {
4773
- fs__default.default.copyFileSync(jiekTempPackageJSON, packageJSON);
4774
- fs__default.default.rmSync(jiekTempPackageJSON);
4797
+ const packageJSONPath = path__default.default.resolve(dir, "package.json");
4798
+ const { name, version } = JSON.parse(fs__default.default.readFileSync(packageJSONPath, "utf-8"));
4799
+ const jiekTempPackageJSONPath = path__default.default.resolve(jiekTempDir, "package.json");
4800
+ if (fs__default.default.existsSync(jiekTempPackageJSONPath)) {
4801
+ fs__default.default.copyFileSync(jiekTempPackageJSONPath, packageJSONPath);
4802
+ fs__default.default.rmSync(jiekTempPackageJSONPath);
4775
4803
  console.log(`${dir}/package.json has been restored`);
4804
+ console.log(`if you want to check the compatibility of the package, you can visit:`);
4805
+ console.log(`https://arethetypeswrong.github.io/?p=${name}%40${version}`);
4776
4806
  } else {
4777
4807
  throw new Error(
4778
4808
  `jiek temp \`${dir}/package.json\` not found, please confirm the jiek pre-publish command has been executed`
package/dist/cli.js CHANGED
@@ -14,6 +14,8 @@ import require$$0 from 'util';
14
14
  import require$$0$1 from 'path';
15
15
  import 'jiek/cli-only-build';
16
16
 
17
+ var require = /* @__PURE__ */ createRequire(import.meta.url);
18
+
17
19
  let root;
18
20
  function getRoot() {
19
21
  if (root) return root;
@@ -48,7 +50,6 @@ function getWD() {
48
50
 
49
51
  let type = "";
50
52
  try {
51
- const require = createRequire(import.meta.url);
52
53
  require.resolve("@pnpm/filter-workspace-packages");
53
54
  type = "pnpm";
54
55
  } catch {
@@ -4215,11 +4216,13 @@ var micromatchExports = requireMicromatch();
4215
4216
 
4216
4217
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4217
4218
  const {
4218
- JIEK_OUT_DIR
4219
- } = process.env;
4219
+ JIEK_OUT_DIR,
4220
+ JIEK_CROSS_MODULE_CONVERTOR
4221
+ } = process$1.env;
4220
4222
  const OUTDIR = JIEK_OUT_DIR ?? "dist";
4223
+ const crossModuleConvertorDefault = JIEK_CROSS_MODULE_CONVERTOR === void 0 ? true : JIEK_CROSS_MODULE_CONVERTOR === "true";
4221
4224
  function getOutDirs({
4222
- cwd = process.cwd(),
4225
+ cwd = process$1.cwd(),
4223
4226
  defaultOutdir = OUTDIR,
4224
4227
  config,
4225
4228
  pkgName
@@ -4259,7 +4262,7 @@ function getExports({
4259
4262
  } = {}
4260
4263
  } = config ?? {};
4261
4264
  const {
4262
- crossModuleConvertor = true
4265
+ crossModuleConvertor = crossModuleConvertorDefault
4263
4266
  } = build;
4264
4267
  const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints);
4265
4268
  if (entries) {
@@ -4280,14 +4283,24 @@ function getExports({
4280
4283
  }
4281
4284
  );
4282
4285
  const crossModuleWithConditional = crossModuleConvertor ? {
4283
- import: (opts) => !pkgIsModule && intersection(
4284
- new Set(opts.conditionals),
4285
- /* @__PURE__ */ new Set(["import", "module"])
4286
- ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4287
- require: (opts) => pkgIsModule && intersection(
4288
- new Set(opts.conditionals),
4289
- /* @__PURE__ */ new Set(["require", "node"])
4290
- ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4286
+ import: (opts) => {
4287
+ if (pkgIsModule) return false;
4288
+ if (opts.src.endsWith(".cts")) return false;
4289
+ if (intersection(
4290
+ new Set(opts.conditionals),
4291
+ /* @__PURE__ */ new Set(["import", "module"])
4292
+ ).size !== 0) return false;
4293
+ return opts.dist.replace(/\.js$/, ".mjs");
4294
+ },
4295
+ require: (opts) => {
4296
+ if (!pkgIsModule) return false;
4297
+ if (opts.src.endsWith(".mts")) return false;
4298
+ if (intersection(
4299
+ new Set(opts.conditionals),
4300
+ /* @__PURE__ */ new Set(["require", "node"])
4301
+ ).size !== 0) return false;
4302
+ return opts.dist.replace(/\.js$/, ".cjs");
4303
+ }
4291
4304
  } : {};
4292
4305
  return [
4293
4306
  filteredResolvedEntrypoints,
@@ -4304,10 +4317,9 @@ function getExports({
4304
4317
  ];
4305
4318
  }
4306
4319
 
4307
- const require$1 = createRequire(import.meta.url);
4308
4320
  function packageIsExist(name) {
4309
4321
  try {
4310
- require$1.resolve(name);
4322
+ require.resolve(name);
4311
4323
  return true;
4312
4324
  } catch (e) {
4313
4325
  return false;
@@ -4327,7 +4339,6 @@ for (const register of registers) {
4327
4339
  }
4328
4340
  }
4329
4341
 
4330
- const require = createRequire(import.meta.url);
4331
4342
  let configName = "jiek.config";
4332
4343
  function getConfigPath(root, dir) {
4333
4344
  const isSupportTsLoader = !!tsRegisterName;
@@ -4655,33 +4666,51 @@ async function prepublish({ bumper } = {}) {
4655
4666
  fs.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
4656
4667
  fs.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
4657
4668
  const allBuildFiles = fs.readdirSync(resolveByDir(resolvedOutdir), { recursive: true }).filter((file) => typeof file === "string").filter((file) => file !== "package.json");
4658
- for (const file of allBuildFiles) {
4659
- const filepath = resolveByDir(resolvedOutdir, file);
4660
- const stat = fs.statSync(filepath);
4661
- if (stat.isDirectory()) {
4662
- const existsIndexFile = allBuildFiles.some(
4663
- (f) => [
4664
- path.join(file, "index.js"),
4665
- path.join(file, "index.mjs"),
4666
- path.join(file, "index.cjs")
4667
- ].includes(f)
4668
- );
4669
- if (existsIndexFile) {
4670
- const cpDistPath = resolveByDir(resolvedOutdir, resolvedOutdir, file);
4671
- const pkgJSONPath = resolveByDir(resolvedOutdir, file, "package.json");
4672
- const relativePath = path.relative(filepath, cpDistPath);
4673
- const { type } = manifest;
4674
- fs.writeFileSync(
4675
- pkgJSONPath,
4676
- JSON.stringify({
4677
- type,
4678
- main: [relativePath, `index.${type === "module" ? "c" : ""}js`].join("/"),
4679
- module: [relativePath, `index.${type === "module" ? "" : "m"}js`].join("/")
4680
- })
4681
- );
4682
- }
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("/");
4683
4699
  }
4684
- }
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
+ });
4685
4714
  fs.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir));
4686
4715
  for (const file of allBuildFiles) {
4687
4716
  const filepath = resolveByDir(resolvedOutdir, file);
@@ -4736,12 +4765,15 @@ async function prepublish({ bumper } = {}) {
4736
4765
  async function postpublish() {
4737
4766
  await forEachSelectedProjectsGraphEntries((dir) => {
4738
4767
  const jiekTempDir = path.resolve(dir, "node_modules/.jiek/.tmp");
4739
- const packageJSON = path.resolve(dir, "package.json");
4740
- const jiekTempPackageJSON = path.resolve(jiekTempDir, "package.json");
4741
- if (fs.existsSync(jiekTempPackageJSON)) {
4742
- fs.copyFileSync(jiekTempPackageJSON, packageJSON);
4743
- fs.rmSync(jiekTempPackageJSON);
4768
+ const packageJSONPath = path.resolve(dir, "package.json");
4769
+ const { name, version } = JSON.parse(fs.readFileSync(packageJSONPath, "utf-8"));
4770
+ const jiekTempPackageJSONPath = path.resolve(jiekTempDir, "package.json");
4771
+ if (fs.existsSync(jiekTempPackageJSONPath)) {
4772
+ fs.copyFileSync(jiekTempPackageJSONPath, packageJSONPath);
4773
+ fs.rmSync(jiekTempPackageJSONPath);
4744
4774
  console.log(`${dir}/package.json has been restored`);
4775
+ console.log(`if you want to check the compatibility of the package, you can visit:`);
4776
+ console.log(`https://arethetypeswrong.github.io/?p=${name}%40${version}`);
4745
4777
  } else {
4746
4778
  throw new Error(
4747
4779
  `jiek temp \`${dir}/package.json\` not found, please confirm the jiek pre-publish command has been executed`
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' {