jiek 2.2.3-alpha.3 → 2.2.3-alpha.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.
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var fs = require('node:fs');
4
- var node_module = require('node:module');
5
4
  var path = require('node:path');
6
5
  var commander = require('commander');
7
6
  var jsYaml = require('js-yaml');
@@ -13,7 +12,6 @@ var node_child_process = require('node:child_process');
13
12
  var prompts = require('@inquirer/prompts');
14
13
  var Koa = require('koa');
15
14
 
16
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
17
15
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
16
 
19
17
  var fs__default = /*#__PURE__*/_interopDefault(fs);
@@ -21,6 +19,8 @@ var path__default = /*#__PURE__*/_interopDefault(path);
21
19
  var process__default = /*#__PURE__*/_interopDefault(process$1);
22
20
  var Koa__default = /*#__PURE__*/_interopDefault(Koa);
23
21
 
22
+ var require$1 = require;
23
+
24
24
  let root;
25
25
  function getRoot() {
26
26
  if (root) return root;
@@ -55,7 +55,6 @@ function getWD() {
55
55
 
56
56
  let type$1 = "";
57
57
  try {
58
- 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-only-build.cjs', document.baseURI).href)));
59
58
  require$1.resolve("@pnpm/filter-workspace-packages");
60
59
  type$1 = "pnpm";
61
60
  } catch {
@@ -119,7 +118,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
119
118
 
120
119
  var name = "jiek";
121
120
  var type = "module";
122
- var version = "2.2.3-alpha.2";
121
+ var version = "2.2.3-alpha.4";
123
122
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
124
123
  var author = "YiJie <yijie4188@gmail.com>";
125
124
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -196,7 +195,6 @@ var dependencies = {
196
195
  "@rollup/plugin-inject": "^5.0.5",
197
196
  "@rollup/plugin-json": "^6.0.1",
198
197
  "@rollup/plugin-node-resolve": "^15.3.0",
199
- "@rollup/plugin-replace": "^6.0.1",
200
198
  "cli-progress": "^3.12.0",
201
199
  commander: "^12.0.0",
202
200
  "detect-indent": "^6.1.0",
@@ -379,13 +377,17 @@ function parseBoolean(v) {
379
377
 
380
378
  async function checkDependency(dependency) {
381
379
  try {
382
- require.resolve(dependency);
380
+ require$1.resolve(dependency);
383
381
  } catch {
384
382
  console.error(`The package '${dependency}' is not installed, please install it first.`);
385
383
  const { notWorkspace } = getWD();
386
384
  const command = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
387
- if (await prompts.confirm({ message: "Do you want to install it now?" })) {
388
- node_child_process.spawnSync(command);
385
+ if (await prompts.confirm({ message: `Do you want to install it now? (${command})` })) {
386
+ node_child_process.execSync(command, {
387
+ stdio: "inherit",
388
+ cwd: process__default.default.cwd(),
389
+ env: process__default.default.env
390
+ });
389
391
  } else {
390
392
  console.warn(`You can run the command '${command}' to install it manually.`);
391
393
  process__default.default.exit(1);
@@ -502,10 +504,9 @@ const createServer = (port, host) => {
502
504
  };
503
505
  };
504
506
 
505
- const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
506
507
  function packageIsExist(name) {
507
508
  try {
508
- require$3.resolve(name);
509
+ require$1.resolve(name);
509
510
  return true;
510
511
  } catch (e) {
511
512
  return false;
@@ -525,7 +526,6 @@ for (const register of registers) {
525
526
  }
526
527
  }
527
528
 
528
- 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-only-build.cjs', document.baseURI).href)));
529
529
  let configName = "jiek.config";
530
530
  function getConfigPath(root, dir) {
531
531
  const isSupportTsLoader = !!tsRegisterName;
@@ -579,16 +579,16 @@ function loadConfig(dirOrOptions) {
579
579
  let module;
580
580
  switch (ext) {
581
581
  case ".js":
582
- module = require$2(configPath);
582
+ module = require$1(configPath);
583
583
  break;
584
584
  case ".json":
585
- return require$2(configPath);
585
+ return require$1(configPath);
586
586
  case ".yaml":
587
587
  return jsYaml.load(fs__default.default.readFileSync(configPath, "utf-8"));
588
588
  case ".ts":
589
589
  if (tsRegisterName) {
590
- require$2(tsRegisterName);
591
- module = require$2(configPath);
590
+ require$1(tsRegisterName);
591
+ module = require$1(configPath);
592
592
  break;
593
593
  }
594
594
  throw new Error(
@@ -607,7 +607,6 @@ function loadConfig(dirOrOptions) {
607
607
  const FILE_TEMPLATE = (manifest) => `
608
608
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
609
609
  `.trimStart();
610
- 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-only-build.cjs', document.baseURI).href)));
611
610
  const isDefault = process__default.default.env.JIEK_IS_ONLY_BUILD === "true";
612
611
  const description = `
613
612
  Build the package according to the 'exports' field from the package.json.
@@ -1,5 +1,5 @@
1
- import fs, { existsSync, mkdirSync, writeFileSync, statSync } from 'node:fs';
2
1
  import { createRequire } from 'node:module';
2
+ import fs, { existsSync, mkdirSync, writeFileSync, statSync } from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { program } from 'commander';
5
5
  import { load } from 'js-yaml';
@@ -7,10 +7,12 @@ 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
+ import { execSync } from 'node:child_process';
11
11
  import { confirm } from '@inquirer/prompts';
12
12
  import Koa from 'koa';
13
13
 
14
+ var require = /* @__PURE__ */ createRequire(import.meta.url);
15
+
14
16
  let root;
15
17
  function getRoot() {
16
18
  if (root) return root;
@@ -45,7 +47,6 @@ function getWD() {
45
47
 
46
48
  let type$1 = "";
47
49
  try {
48
- const require = createRequire(import.meta.url);
49
50
  require.resolve("@pnpm/filter-workspace-packages");
50
51
  type$1 = "pnpm";
51
52
  } catch {
@@ -109,7 +110,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
109
110
 
110
111
  var name = "jiek";
111
112
  var type = "module";
112
- var version = "2.2.3-alpha.2";
113
+ var version = "2.2.3-alpha.4";
113
114
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
114
115
  var author = "YiJie <yijie4188@gmail.com>";
115
116
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -186,7 +187,6 @@ var dependencies = {
186
187
  "@rollup/plugin-inject": "^5.0.5",
187
188
  "@rollup/plugin-json": "^6.0.1",
188
189
  "@rollup/plugin-node-resolve": "^15.3.0",
189
- "@rollup/plugin-replace": "^6.0.1",
190
190
  "cli-progress": "^3.12.0",
191
191
  commander: "^12.0.0",
192
192
  "detect-indent": "^6.1.0",
@@ -374,8 +374,12 @@ async function checkDependency(dependency) {
374
374
  console.error(`The package '${dependency}' is not installed, please install it first.`);
375
375
  const { notWorkspace } = getWD();
376
376
  const command = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
377
- if (await confirm({ message: "Do you want to install it now?" })) {
378
- spawnSync(command);
377
+ if (await confirm({ message: `Do you want to install it now? (${command})` })) {
378
+ execSync(command, {
379
+ stdio: "inherit",
380
+ cwd: process$1.cwd(),
381
+ env: process$1.env
382
+ });
379
383
  } else {
380
384
  console.warn(`You can run the command '${command}' to install it manually.`);
381
385
  process$1.exit(1);
@@ -492,10 +496,9 @@ const createServer = (port, host) => {
492
496
  };
493
497
  };
494
498
 
495
- const require$3 = createRequire(import.meta.url);
496
499
  function packageIsExist(name) {
497
500
  try {
498
- require$3.resolve(name);
501
+ require.resolve(name);
499
502
  return true;
500
503
  } catch (e) {
501
504
  return false;
@@ -515,7 +518,6 @@ for (const register of registers) {
515
518
  }
516
519
  }
517
520
 
518
- const require$2 = createRequire(import.meta.url);
519
521
  let configName = "jiek.config";
520
522
  function getConfigPath(root, dir) {
521
523
  const isSupportTsLoader = !!tsRegisterName;
@@ -569,16 +571,16 @@ function loadConfig(dirOrOptions) {
569
571
  let module;
570
572
  switch (ext) {
571
573
  case ".js":
572
- module = require$2(configPath);
574
+ module = require(configPath);
573
575
  break;
574
576
  case ".json":
575
- return require$2(configPath);
577
+ return require(configPath);
576
578
  case ".yaml":
577
579
  return load(fs.readFileSync(configPath, "utf-8"));
578
580
  case ".ts":
579
581
  if (tsRegisterName) {
580
- require$2(tsRegisterName);
581
- module = require$2(configPath);
582
+ require(tsRegisterName);
583
+ module = require(configPath);
582
584
  break;
583
585
  }
584
586
  throw new Error(
@@ -597,7 +599,6 @@ function loadConfig(dirOrOptions) {
597
599
  const FILE_TEMPLATE = (manifest) => `
598
600
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
599
601
  `.trimStart();
600
- const require$1 = createRequire(import.meta.url);
601
602
  const isDefault = process$1.env.JIEK_IS_ONLY_BUILD === "true";
602
603
  const description = `
603
604
  Build the package according to the 'exports' field from the package.json.
@@ -607,7 +608,7 @@ ${isDefault ? "This command is the default command." : ""}
607
608
  let DEFAULT_BUILDER_TYPE;
608
609
  Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
609
610
  try {
610
- require$1.resolve(packageName);
611
+ require.resolve(packageName);
611
612
  DEFAULT_BUILDER_TYPE = type;
612
613
  } catch {
613
614
  }
@@ -759,7 +760,7 @@ command.action(async (commandFiltersOrEntries, options) => {
759
760
  } catch {
760
761
  }
761
762
  }
762
- const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
763
+ const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
763
764
  let i = 0;
764
765
  await Promise.all(
765
766
  Object.entries(value).map(async ([pkgCWD, manifest]) => {
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 {
@@ -4345,10 +4344,9 @@ function getExports({
4345
4344
  ];
4346
4345
  }
4347
4346
 
4348
- 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)));
4349
4347
  function packageIsExist(name) {
4350
4348
  try {
4351
- require$2.resolve(name);
4349
+ require$1.resolve(name);
4352
4350
  return true;
4353
4351
  } catch (e) {
4354
4352
  return false;
@@ -4368,7 +4366,6 @@ for (const register of registers) {
4368
4366
  }
4369
4367
  }
4370
4368
 
4371
- 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)));
4372
4369
  let configName = "jiek.config";
4373
4370
  function getConfigPath(root, dir) {
4374
4371
  const isSupportTsLoader = !!tsRegisterName;
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 {
@@ -4314,10 +4315,9 @@ function getExports({
4314
4315
  ];
4315
4316
  }
4316
4317
 
4317
- const require$1 = createRequire(import.meta.url);
4318
4318
  function packageIsExist(name) {
4319
4319
  try {
4320
- require$1.resolve(name);
4320
+ require.resolve(name);
4321
4321
  return true;
4322
4322
  } catch (e) {
4323
4323
  return false;
@@ -4337,7 +4337,6 @@ for (const register of registers) {
4337
4337
  }
4338
4338
  }
4339
4339
 
4340
- const require = createRequire(import.meta.url);
4341
4340
  let configName = "jiek.config";
4342
4341
  function getConfigPath(root, dir) {
4343
4342
  const isSupportTsLoader = !!tsRegisterName;
@@ -7,32 +7,29 @@ var entrypoints = require('@jiek/pkger/entrypoints');
7
7
  var rollupPluginDts = require('@jiek/rollup-plugin-dts');
8
8
  var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
9
9
  var commonjs = require('@rollup/plugin-commonjs');
10
+ var inject = require('@rollup/plugin-inject');
10
11
  var json = require('@rollup/plugin-json');
11
12
  var pluginNodeResolve = require('@rollup/plugin-node-resolve');
12
13
  var require$$0 = require('util');
13
14
  var require$$0$1 = require('path');
14
15
  var ts = require('typescript');
15
16
  var execa = require('execa');
16
- var node_module = require('node:module');
17
17
  var commander = require('commander');
18
18
  var jsYaml = require('js-yaml');
19
19
  var jsoncParser = require('jsonc-parser');
20
- var inject = require('@rollup/plugin-inject');
21
- var replace = require('@rollup/plugin-replace');
20
+ var node_module = require('node:module');
22
21
 
23
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
24
22
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
25
23
 
26
24
  var fs__default = /*#__PURE__*/_interopDefault(fs);
27
25
  var path__default = /*#__PURE__*/_interopDefault(path);
28
26
  var process__default = /*#__PURE__*/_interopDefault(process$1);
29
27
  var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
28
+ var inject__default = /*#__PURE__*/_interopDefault(inject);
30
29
  var json__default = /*#__PURE__*/_interopDefault(json);
31
30
  var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
32
31
  var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
33
32
  var ts__default = /*#__PURE__*/_interopDefault(ts);
34
- var inject__default = /*#__PURE__*/_interopDefault(inject);
35
- var replace__default = /*#__PURE__*/_interopDefault(replace);
36
33
 
37
34
  var utils$1 = {};
38
35
 
@@ -4287,6 +4284,8 @@ function getExports({
4287
4284
  ];
4288
4285
  }
4289
4286
 
4287
+ var require$1 = require;
4288
+
4290
4289
  let root;
4291
4290
  function getRoot() {
4292
4291
  if (root) return root;
@@ -4297,7 +4296,6 @@ function getRoot() {
4297
4296
 
4298
4297
  let type = "";
4299
4298
  try {
4300
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4301
4299
  require$1.resolve("@pnpm/filter-workspace-packages");
4302
4300
  type = "pnpm";
4303
4301
  } catch {
@@ -4327,10 +4325,9 @@ function getWD() {
4327
4325
  return { wd, notWorkspace };
4328
4326
  }
4329
4327
 
4330
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4331
4328
  function packageIsExist(name) {
4332
4329
  try {
4333
- require$2.resolve(name);
4330
+ require$1.resolve(name);
4334
4331
  return true;
4335
4332
  } catch (e) {
4336
4333
  return false;
@@ -4350,7 +4347,6 @@ for (const register of registers) {
4350
4347
  }
4351
4348
  }
4352
4349
 
4353
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('rollup/index.cjs', document.baseURI).href)));
4354
4350
  let configName = "jiek.config";
4355
4351
  function getConfigPath(root, dir) {
4356
4352
  const isSupportTsLoader = !!tsRegisterName;
@@ -4495,43 +4491,16 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4495
4491
  return tsconfig.compilerOptions;
4496
4492
  };
4497
4493
 
4498
- const virtualModuleName = "jiek:create-require";
4499
- const isEsmVariableName = `IS_ESM${Math.random().toString(36).slice(2)}`;
4500
- const INSERT_STR = `
4501
- import { createRequire } from 'node:module'
4502
-
4503
- export default (
4504
- ${isEsmVariableName}
4505
- ? /* @__PURE__ */ createRequire(import.meta.url)
4506
- : require
4507
- )
4494
+ const CREATE_REQUIRE_VIRTUAL_MODULE_NAME = "jiek:create-require";
4495
+ const INSERT_STR = (isESM) => `
4496
+ ${isESM ? `import { createRequire } from 'node:module'` : ""}
4497
+ export default ${isESM ? "/* @__PURE__ */ createRequire(import.meta.url)" : "require"}
4508
4498
  `.trim();
4509
- var createRequire = () => ({
4510
- ...inject__default.default({
4511
- require: virtualModuleName
4512
- }),
4499
+ var createRequire = (isEsm) => ({
4513
4500
  name: "create-require",
4514
- resolveId: (source) => source === virtualModuleName ? source : null,
4515
- load: (id) => {
4516
- if (id !== virtualModuleName) {
4517
- return null;
4518
- }
4519
- return INSERT_STR;
4520
- }
4501
+ resolveId: (id) => id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME ? id : null,
4502
+ load: (id) => id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME ? INSERT_STR(isEsm) : null
4521
4503
  });
4522
- const isFormatEsm = (isEsm) => {
4523
- const handler = replace__default.default({
4524
- [isEsmVariableName]: isEsm
4525
- }).renderChunk;
4526
- return {
4527
- name: "create-require-insert-format",
4528
- // Pick out renderChunk because it's used as an output plugin
4529
- renderChunk: {
4530
- order: "pre",
4531
- handler: typeof handler === "function" ? handler : handler.handler
4532
- }
4533
- };
4534
- };
4535
4504
 
4536
4505
  var progress = (options = {}) => {
4537
4506
  const { onEvent } = options;
@@ -4881,9 +4850,7 @@ const generateConfigs = (context, options = {}) => {
4881
4850
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4882
4851
  externalImportAttributes: features.keepImportAttributes !== false,
4883
4852
  importAttributesKey: features.keepImportAttributes === false || features.keepImportAttributes === void 0 ? void 0 : features.keepImportAttributes === true ? "with" : features.keepImportAttributes,
4884
- plugins: [
4885
- isFormatEsm(format === "esm")
4886
- ]
4853
+ plugins: []
4887
4854
  }, onlyOncePlugins)
4888
4855
  ],
4889
4856
  plugins: [
@@ -4895,8 +4862,12 @@ const generateConfigs = (context, options = {}) => {
4895
4862
  })
4896
4863
  ).catch(() => void 0),
4897
4864
  commonjs__default.default(),
4898
- createRequire(),
4899
4865
  builder,
4866
+ // inject plugin can't resolve `import type`, so we should register it after the builder plugin
4867
+ inject__default.default({
4868
+ require: CREATE_REQUIRE_VIRTUAL_MODULE_NAME
4869
+ }),
4870
+ createRequire(format === "esm"),
4900
4871
  ana,
4901
4872
  progress({
4902
4873
  onEvent: (event, message) => void publishInEntry("progress", { event, message, tags: ["js"] })
@@ -5,6 +5,7 @@ import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Expor
5
5
  import { dts } from '@jiek/rollup-plugin-dts';
6
6
  import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
7
7
  import commonjs from '@rollup/plugin-commonjs';
8
+ import inject from '@rollup/plugin-inject';
8
9
  import json from '@rollup/plugin-json';
9
10
  import { nodeResolve } from '@rollup/plugin-node-resolve';
10
11
  import require$$0 from 'util';
@@ -15,8 +16,6 @@ import { createRequire as createRequire$1, builtinModules } from 'node:module';
15
16
  import { program } from 'commander';
16
17
  import { load } from 'js-yaml';
17
18
  import { parse } from 'jsonc-parser';
18
- import inject from '@rollup/plugin-inject';
19
- import replace from '@rollup/plugin-replace';
20
19
 
21
20
  var utils$1 = {};
22
21
 
@@ -4271,6 +4270,8 @@ function getExports({
4271
4270
  ];
4272
4271
  }
4273
4272
 
4273
+ var require = /* @__PURE__ */ createRequire$1(import.meta.url);
4274
+
4274
4275
  let root;
4275
4276
  function getRoot() {
4276
4277
  if (root) return root;
@@ -4281,7 +4282,6 @@ function getRoot() {
4281
4282
 
4282
4283
  let type = "";
4283
4284
  try {
4284
- const require = createRequire$1(import.meta.url);
4285
4285
  require.resolve("@pnpm/filter-workspace-packages");
4286
4286
  type = "pnpm";
4287
4287
  } catch {
@@ -4311,10 +4311,9 @@ function getWD() {
4311
4311
  return { wd, notWorkspace };
4312
4312
  }
4313
4313
 
4314
- const require$1 = createRequire$1(import.meta.url);
4315
4314
  function packageIsExist(name) {
4316
4315
  try {
4317
- require$1.resolve(name);
4316
+ require.resolve(name);
4318
4317
  return true;
4319
4318
  } catch (e) {
4320
4319
  return false;
@@ -4334,7 +4333,6 @@ for (const register of registers) {
4334
4333
  }
4335
4334
  }
4336
4335
 
4337
- const require = createRequire$1(import.meta.url);
4338
4336
  let configName = "jiek.config";
4339
4337
  function getConfigPath(root, dir) {
4340
4338
  const isSupportTsLoader = !!tsRegisterName;
@@ -4479,43 +4477,16 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4479
4477
  return tsconfig.compilerOptions;
4480
4478
  };
4481
4479
 
4482
- const virtualModuleName = "jiek:create-require";
4483
- const isEsmVariableName = `IS_ESM${Math.random().toString(36).slice(2)}`;
4484
- const INSERT_STR = `
4485
- import { createRequire } from 'node:module'
4486
-
4487
- export default (
4488
- ${isEsmVariableName}
4489
- ? /* @__PURE__ */ createRequire(import.meta.url)
4490
- : require
4491
- )
4480
+ const CREATE_REQUIRE_VIRTUAL_MODULE_NAME = "jiek:create-require";
4481
+ const INSERT_STR = (isESM) => `
4482
+ ${isESM ? `import { createRequire } from 'node:module'` : ""}
4483
+ export default ${isESM ? "/* @__PURE__ */ createRequire(import.meta.url)" : "require"}
4492
4484
  `.trim();
4493
- var createRequire = () => ({
4494
- ...inject({
4495
- require: virtualModuleName
4496
- }),
4485
+ var createRequire = (isEsm) => ({
4497
4486
  name: "create-require",
4498
- resolveId: (source) => source === virtualModuleName ? source : null,
4499
- load: (id) => {
4500
- if (id !== virtualModuleName) {
4501
- return null;
4502
- }
4503
- return INSERT_STR;
4504
- }
4487
+ resolveId: (id) => id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME ? id : null,
4488
+ load: (id) => id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME ? INSERT_STR(isEsm) : null
4505
4489
  });
4506
- const isFormatEsm = (isEsm) => {
4507
- const handler = replace({
4508
- [isEsmVariableName]: isEsm
4509
- }).renderChunk;
4510
- return {
4511
- name: "create-require-insert-format",
4512
- // Pick out renderChunk because it's used as an output plugin
4513
- renderChunk: {
4514
- order: "pre",
4515
- handler: typeof handler === "function" ? handler : handler.handler
4516
- }
4517
- };
4518
- };
4519
4490
 
4520
4491
  var progress = (options = {}) => {
4521
4492
  const { onEvent } = options;
@@ -4865,9 +4836,7 @@ const generateConfigs = (context, options = {}) => {
4865
4836
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4866
4837
  externalImportAttributes: features.keepImportAttributes !== false,
4867
4838
  importAttributesKey: features.keepImportAttributes === false || features.keepImportAttributes === void 0 ? void 0 : features.keepImportAttributes === true ? "with" : features.keepImportAttributes,
4868
- plugins: [
4869
- isFormatEsm(format === "esm")
4870
- ]
4839
+ plugins: []
4871
4840
  }, onlyOncePlugins)
4872
4841
  ],
4873
4842
  plugins: [
@@ -4879,8 +4848,12 @@ const generateConfigs = (context, options = {}) => {
4879
4848
  })
4880
4849
  ).catch(() => void 0),
4881
4850
  commonjs(),
4882
- createRequire(),
4883
4851
  builder,
4852
+ // inject plugin can't resolve `import type`, so we should register it after the builder plugin
4853
+ inject({
4854
+ require: CREATE_REQUIRE_VIRTUAL_MODULE_NAME
4855
+ }),
4856
+ createRequire(format === "esm"),
4884
4857
  ana,
4885
4858
  progress({
4886
4859
  onEvent: (event, message) => void publishInEntry("progress", { event, message, tags: ["js"] })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "2.2.3-alpha.3",
4
+ "version": "2.2.3-alpha.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",
@@ -78,7 +78,6 @@
78
78
  "@rollup/plugin-inject": "^5.0.5",
79
79
  "@rollup/plugin-json": "^6.0.1",
80
80
  "@rollup/plugin-node-resolve": "^15.3.0",
81
- "@rollup/plugin-replace": "^6.0.1",
82
81
  "cli-progress": "^3.12.0",
83
82
  "commander": "^12.0.0",
84
83
  "detect-indent": "^6.1.0",
@@ -1,5 +1,4 @@
1
1
  import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
2
- import { createRequire } from 'node:module'
3
2
  import path from 'node:path'
4
3
  import process from 'node:process'
5
4
 
@@ -39,8 +38,6 @@ const FILE_TEMPLATE = (manifest: unknown) => (`
39
38
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
40
39
  `.trimStart())
41
40
 
42
- const require = createRequire(import.meta.url)
43
-
44
41
  const isDefault = process.env.JIEK_IS_ONLY_BUILD === 'true'
45
42
 
46
43
  const description = `
@@ -8,6 +8,7 @@ import { getAllLeafs } from '@jiek/pkger/entrypoints'
8
8
  import { dts } from '@jiek/rollup-plugin-dts'
9
9
  import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'
10
10
  import commonjs from '@rollup/plugin-commonjs'
11
+ import inject from '@rollup/plugin-inject'
11
12
  import json from '@rollup/plugin-json'
12
13
  import { nodeResolve } from '@rollup/plugin-node-resolve'
13
14
  import { isMatch } from 'micromatch'
@@ -23,7 +24,7 @@ import { recusiveListFiles } from '#~/utils/recusiveListFiles.ts'
23
24
  import { getCompilerOptionsByFilePath } from '#~/utils/ts.ts'
24
25
 
25
26
  import type { ConfigGenerateContext, TemplateOptions } from './base'
26
- import createRequire, { isFormatEsm } from './plugins/create-require'
27
+ import createRequire, { CREATE_REQUIRE_VIRTUAL_MODULE_NAME } from './plugins/create-require'
27
28
  import progress from './plugins/progress'
28
29
  import skip from './plugins/skip'
29
30
  import externalResolver from './utils/externalResolver'
@@ -468,9 +469,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
468
469
  : features.keepImportAttributes === true
469
470
  ? 'with'
470
471
  : features.keepImportAttributes,
471
- plugins: [
472
- isFormatEsm(format === 'esm')
473
- ]
472
+ plugins: []
474
473
  }, onlyOncePlugins)
475
474
  ],
476
475
  plugins: [
@@ -484,8 +483,12 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
484
483
  )
485
484
  .catch(() => void 0),
486
485
  commonjs(),
487
- createRequire(),
488
486
  builder,
487
+ // inject plugin can't resolve `import type`, so we should register it after the builder plugin
488
+ inject({
489
+ require: CREATE_REQUIRE_VIRTUAL_MODULE_NAME
490
+ }),
491
+ createRequire(format === 'esm'),
489
492
  ana,
490
493
  progress({
491
494
  onEvent: (event, message) => void publishInEntry('progress', { event, message, tags: ['js'] })
@@ -586,7 +589,6 @@ export function template(packageJSON: PackageJSON): RollupOptions[] {
586
589
  return false
587
590
  })
588
591
 
589
- // console.log(exports)
590
592
  const configs: RollupOptions[] = []
591
593
  leafMap.forEach((keysArr, input) =>
592
594
  keysArr.forEach((keys) => {
@@ -1,74 +1,23 @@
1
- // https://github.com/privatenumber/pkgroll/blob/73559f8864203a50a5aa12c0a6503ceed3690aff/src/utils/rollup-plugins/create-require.ts#L1
2
- // Thanks to @privatenumber for the snippet
3
-
4
- import inject from '@rollup/plugin-inject'
5
- import replace from '@rollup/plugin-replace'
6
1
  import type { Plugin } from 'rollup'
7
2
 
8
- const virtualModuleName = 'jiek:create-require'
9
-
10
- /**
11
- * Since rollup is bundled by rollup, it needs to add a run-time
12
- * suffix so that this doesn't get replaced.
13
- */
14
- const isEsmVariableName = `IS_ESM${Math.random().toString(36).slice(2)}`
15
-
16
- const INSERT_STR = `
17
- import { createRequire } from 'node:module'
3
+ export const CREATE_REQUIRE_VIRTUAL_MODULE_NAME = 'jiek:create-require'
18
4
 
19
- export default (
20
- ${isEsmVariableName}
21
- ? /* @__PURE__ */ createRequire(import.meta.url)
22
- : require
23
- )
5
+ const INSERT_STR = (isESM: boolean) =>
6
+ `
7
+ ${isESM ? `import { createRequire } from 'node:module'` : ''}
8
+ export default ${isESM ? '/* @__PURE__ */ createRequire(import.meta.url)' : 'require'}
24
9
  `.trim()
25
10
 
26
- /**
27
- * Plugin to seamlessly allow usage of `require`
28
- * across CJS and ESM modules.
29
- *
30
- * This is usually nor a problem for CJS outputs,
31
- * but for ESM outputs, it must be used via
32
- * createRequire.
33
- *
34
- * This plugin automatically injects it for ESM.
35
- */
36
- export default (): Plugin => ({
37
- ...inject({
38
- require: virtualModuleName
39
- }),
40
-
11
+ export default (isEsm: boolean): Plugin => ({
41
12
  name: 'create-require',
42
-
43
- resolveId: source => (
44
- (source === virtualModuleName)
45
- ? source
13
+ resolveId: id => (
14
+ id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME
15
+ ? id
46
16
  : null
47
17
  ),
48
-
49
- load: (id) => {
50
- if (id !== virtualModuleName) {
51
- return null
52
- }
53
-
54
- return INSERT_STR
55
- }
18
+ load: id => (
19
+ id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME
20
+ ? INSERT_STR(isEsm)
21
+ : null
22
+ )
56
23
  })
57
-
58
- export const isFormatEsm = (
59
- isEsm: boolean
60
- ): Plugin => {
61
- const handler = replace({
62
- [isEsmVariableName]: isEsm
63
- }).renderChunk!
64
-
65
- return ({
66
- name: 'create-require-insert-format',
67
-
68
- // Pick out renderChunk because it's used as an output plugin
69
- renderChunk: {
70
- order: 'pre',
71
- handler: typeof handler === 'function' ? handler : handler.handler
72
- }
73
- })
74
- }
@@ -1,4 +1,4 @@
1
- import { spawnSync } from 'node:child_process'
1
+ import { execSync } from 'node:child_process'
2
2
  import process from 'node:process'
3
3
 
4
4
  import { confirm } from '@inquirer/prompts'
@@ -12,8 +12,12 @@ export async function checkDependency(dependency: string) {
12
12
  console.error(`The package '${dependency}' is not installed, please install it first.`)
13
13
  const { notWorkspace } = getWD()
14
14
  const command = `pnpm install -${notWorkspace ? '' : 'w'}D ${dependency}`
15
- if (await confirm({ message: 'Do you want to install it now?' })) {
16
- spawnSync(command)
15
+ if (await confirm({ message: `Do you want to install it now? (${command})` })) {
16
+ execSync(command, {
17
+ stdio: 'inherit',
18
+ cwd: process.cwd(),
19
+ env: process.env
20
+ })
17
21
  } else {
18
22
  console.warn(`You can run the command '${command}' to install it manually.`)
19
23
  process.exit(1)
@@ -1,5 +1,4 @@
1
1
  import fs from 'node:fs'
2
- import { createRequire } from 'node:module'
3
2
  import path from 'node:path'
4
3
 
5
4
  import { program } from 'commander'
@@ -11,7 +10,6 @@ import { getWD } from '#~/utils/getWD.ts'
11
10
  export let type = ''
12
11
 
13
12
  try {
14
- const require = createRequire(import.meta.url)
15
13
  require.resolve('@pnpm/filter-workspace-packages')
16
14
  type = 'pnpm'
17
15
  } catch { /* empty */ }
@@ -1,5 +1,4 @@
1
1
  import fs from 'node:fs'
2
- import { createRequire } from 'node:module'
3
2
  import path from 'node:path'
4
3
 
5
4
  import { program } from 'commander'
@@ -9,8 +8,6 @@ import { load } from 'js-yaml'
9
8
  import { getWD } from './getWD'
10
9
  import { tsRegisterName } from './tsRegister'
11
10
 
12
- const require = createRequire(import.meta.url)
13
-
14
11
  let configName = 'jiek.config'
15
12
 
16
13
  function getConfigPath(root: string, dir?: string) {
@@ -1,7 +1,3 @@
1
- import { createRequire } from 'node:module'
2
-
3
- const require = createRequire(import.meta.url)
4
-
5
1
  function packageIsExist(name: string) {
6
2
  try {
7
3
  require.resolve(name)