jiek 2.2.3 → 2.2.4

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');
@@ -9,10 +8,10 @@ var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
9
8
  var process$1 = require('node:process');
10
9
  var cliProgress = require('cli-progress');
11
10
  var execa = require('execa');
11
+ var node_child_process = require('node:child_process');
12
12
  var prompts = require('@inquirer/prompts');
13
13
  var Koa = require('koa');
14
14
 
15
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
16
15
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
16
 
18
17
  var fs__default = /*#__PURE__*/_interopDefault(fs);
@@ -20,6 +19,8 @@ var path__default = /*#__PURE__*/_interopDefault(path);
20
19
  var process__default = /*#__PURE__*/_interopDefault(process$1);
21
20
  var Koa__default = /*#__PURE__*/_interopDefault(Koa);
22
21
 
22
+ var require$1 = require;
23
+
23
24
  let root;
24
25
  function getRoot() {
25
26
  if (root) return root;
@@ -54,7 +55,6 @@ function getWD() {
54
55
 
55
56
  let type$1 = "";
56
57
  try {
57
- 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)));
58
58
  require$1.resolve("@pnpm/filter-workspace-packages");
59
59
  type$1 = "pnpm";
60
60
  } catch {
@@ -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.2";
121
+ var version = "2.2.3-alpha.5";
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";
@@ -176,7 +176,7 @@ var scripts = {
176
176
  test: "vitest run"
177
177
  };
178
178
  var peerDependencies = {
179
- "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
179
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
180
180
  "@rollup/plugin-terser": "^0.4.4",
181
181
  "esbuild-register": "^3.5.0",
182
182
  postcss: "^8.4.47",
@@ -187,7 +187,7 @@ var peerDependencies = {
187
187
  "vite-bundle-analyzer": "0.16.0-beta.1"
188
188
  };
189
189
  var dependencies = {
190
- "@inquirer/prompts": "^7.1.0",
190
+ "@inquirer/prompts": "^7.2.0",
191
191
  "@jiek/pkger": "workspace:^",
192
192
  "@jiek/rollup-plugin-dts": "^6.2.1",
193
193
  "@jiek/utils": "workspace:^",
@@ -195,7 +195,6 @@ var dependencies = {
195
195
  "@rollup/plugin-inject": "^5.0.5",
196
196
  "@rollup/plugin-json": "^6.0.1",
197
197
  "@rollup/plugin-node-resolve": "^15.3.0",
198
- "@rollup/plugin-replace": "^6.0.1",
199
198
  "cli-progress": "^3.12.0",
200
199
  commander: "^12.0.0",
201
200
  "detect-indent": "^6.1.0",
@@ -378,13 +377,17 @@ function parseBoolean(v) {
378
377
 
379
378
  async function checkDependency(dependency) {
380
379
  try {
381
- require.resolve(dependency);
380
+ require$1.resolve(dependency);
382
381
  } catch {
383
382
  console.error(`The package '${dependency}' is not installed, please install it first.`);
384
383
  const { notWorkspace } = getWD();
385
- const command = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
386
- if (await prompts.confirm({ message: "Do you want to install it now?" })) {
387
- await execa.execaCommand(command);
384
+ const command = `pnpm add -${notWorkspace ? "" : "w"}D ${dependency}`;
385
+ if (await prompts.confirm({ message: `Do you want to add 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
+ });
388
391
  } else {
389
392
  console.warn(`You can run the command '${command}' to install it manually.`);
390
393
  process__default.default.exit(1);
@@ -501,10 +504,9 @@ const createServer = (port, host) => {
501
504
  };
502
505
  };
503
506
 
504
- 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)));
505
507
  function packageIsExist(name) {
506
508
  try {
507
- require$3.resolve(name);
509
+ require$1.resolve(name);
508
510
  return true;
509
511
  } catch (e) {
510
512
  return false;
@@ -524,7 +526,6 @@ for (const register of registers) {
524
526
  }
525
527
  }
526
528
 
527
- 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)));
528
529
  let configName = "jiek.config";
529
530
  function getConfigPath(root, dir) {
530
531
  const isSupportTsLoader = !!tsRegisterName;
@@ -578,16 +579,16 @@ function loadConfig(dirOrOptions) {
578
579
  let module;
579
580
  switch (ext) {
580
581
  case ".js":
581
- module = require$2(configPath);
582
+ module = require$1(configPath);
582
583
  break;
583
584
  case ".json":
584
- return require$2(configPath);
585
+ return require$1(configPath);
585
586
  case ".yaml":
586
587
  return jsYaml.load(fs__default.default.readFileSync(configPath, "utf-8"));
587
588
  case ".ts":
588
589
  if (tsRegisterName) {
589
- require$2(tsRegisterName);
590
- module = require$2(configPath);
590
+ require$1(tsRegisterName);
591
+ module = require$1(configPath);
591
592
  break;
592
593
  }
593
594
  throw new Error(
@@ -606,7 +607,6 @@ function loadConfig(dirOrOptions) {
606
607
  const FILE_TEMPLATE = (manifest) => `
607
608
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
608
609
  `.trimStart();
609
- 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)));
610
610
  const isDefault = process__default.default.env.JIEK_IS_ONLY_BUILD === "true";
611
611
  const description = `
612
612
  Build the package according to the 'exports' field from the package.json.
@@ -689,13 +689,8 @@ command.action(async (commandFiltersOrEntries, options) => {
689
689
  minifyType = resolvedType;
690
690
  }
691
691
  }
692
- if (!withoutMin) {
693
- await checkDependency(
694
- {
695
- ...BUILDER_TYPE_PACKAGE_NAME_MAP,
696
- terser: "@rollup/plugin-terser"
697
- }[resolvedType]
698
- );
692
+ if (!withoutMin && minifyType === "terser") {
693
+ await checkDependency("@rollup/plugin-terser");
699
694
  }
700
695
  let shouldPassThrough = false;
701
696
  const passThroughOptions = process__default.default.argv.reduce(
@@ -918,12 +913,15 @@ command.action(async (commandFiltersOrEntries, options) => {
918
913
  }
919
914
  });
920
915
  await new Promise((resolve, reject) => {
921
- let errorStr = "";
916
+ let errorStr = `rollup build failed
917
+ package name: ${manifest.name}
918
+ cwd: ${pkgCWD}
919
+
920
+ `;
922
921
  child.stderr?.on("data", (data) => {
923
922
  errorStr += data;
924
923
  });
925
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
926
- ${errorStr}`)));
924
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
927
925
  verbose && child.stdout?.pipe(process__default.default.stdout);
928
926
  });
929
927
  })
@@ -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,9 +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 { execSync } from 'node:child_process';
10
11
  import { confirm } from '@inquirer/prompts';
11
12
  import Koa from 'koa';
12
13
 
14
+ var require = /* @__PURE__ */ createRequire(import.meta.url);
15
+
13
16
  let root;
14
17
  function getRoot() {
15
18
  if (root) return root;
@@ -44,7 +47,6 @@ function getWD() {
44
47
 
45
48
  let type$1 = "";
46
49
  try {
47
- const require = createRequire(import.meta.url);
48
50
  require.resolve("@pnpm/filter-workspace-packages");
49
51
  type$1 = "pnpm";
50
52
  } catch {
@@ -108,7 +110,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
108
110
 
109
111
  var name = "jiek";
110
112
  var type = "module";
111
- var version = "2.2.2";
113
+ var version = "2.2.3-alpha.5";
112
114
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
113
115
  var author = "YiJie <yijie4188@gmail.com>";
114
116
  var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
@@ -166,7 +168,7 @@ var scripts = {
166
168
  test: "vitest run"
167
169
  };
168
170
  var peerDependencies = {
169
- "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
171
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
170
172
  "@rollup/plugin-terser": "^0.4.4",
171
173
  "esbuild-register": "^3.5.0",
172
174
  postcss: "^8.4.47",
@@ -177,7 +179,7 @@ var peerDependencies = {
177
179
  "vite-bundle-analyzer": "0.16.0-beta.1"
178
180
  };
179
181
  var dependencies = {
180
- "@inquirer/prompts": "^7.1.0",
182
+ "@inquirer/prompts": "^7.2.0",
181
183
  "@jiek/pkger": "workspace:^",
182
184
  "@jiek/rollup-plugin-dts": "^6.2.1",
183
185
  "@jiek/utils": "workspace:^",
@@ -185,7 +187,6 @@ var dependencies = {
185
187
  "@rollup/plugin-inject": "^5.0.5",
186
188
  "@rollup/plugin-json": "^6.0.1",
187
189
  "@rollup/plugin-node-resolve": "^15.3.0",
188
- "@rollup/plugin-replace": "^6.0.1",
189
190
  "cli-progress": "^3.12.0",
190
191
  commander: "^12.0.0",
191
192
  "detect-indent": "^6.1.0",
@@ -372,9 +373,13 @@ async function checkDependency(dependency) {
372
373
  } catch {
373
374
  console.error(`The package '${dependency}' is not installed, please install it first.`);
374
375
  const { notWorkspace } = getWD();
375
- const command = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
376
- if (await confirm({ message: "Do you want to install it now?" })) {
377
- await execaCommand(command);
376
+ const command = `pnpm add -${notWorkspace ? "" : "w"}D ${dependency}`;
377
+ if (await confirm({ message: `Do you want to add it now? (${command})` })) {
378
+ execSync(command, {
379
+ stdio: "inherit",
380
+ cwd: process$1.cwd(),
381
+ env: process$1.env
382
+ });
378
383
  } else {
379
384
  console.warn(`You can run the command '${command}' to install it manually.`);
380
385
  process$1.exit(1);
@@ -491,10 +496,9 @@ const createServer = (port, host) => {
491
496
  };
492
497
  };
493
498
 
494
- const require$3 = createRequire(import.meta.url);
495
499
  function packageIsExist(name) {
496
500
  try {
497
- require$3.resolve(name);
501
+ require.resolve(name);
498
502
  return true;
499
503
  } catch (e) {
500
504
  return false;
@@ -514,7 +518,6 @@ for (const register of registers) {
514
518
  }
515
519
  }
516
520
 
517
- const require$2 = createRequire(import.meta.url);
518
521
  let configName = "jiek.config";
519
522
  function getConfigPath(root, dir) {
520
523
  const isSupportTsLoader = !!tsRegisterName;
@@ -568,16 +571,16 @@ function loadConfig(dirOrOptions) {
568
571
  let module;
569
572
  switch (ext) {
570
573
  case ".js":
571
- module = require$2(configPath);
574
+ module = require(configPath);
572
575
  break;
573
576
  case ".json":
574
- return require$2(configPath);
577
+ return require(configPath);
575
578
  case ".yaml":
576
579
  return load(fs.readFileSync(configPath, "utf-8"));
577
580
  case ".ts":
578
581
  if (tsRegisterName) {
579
- require$2(tsRegisterName);
580
- module = require$2(configPath);
582
+ require(tsRegisterName);
583
+ module = require(configPath);
581
584
  break;
582
585
  }
583
586
  throw new Error(
@@ -596,7 +599,6 @@ function loadConfig(dirOrOptions) {
596
599
  const FILE_TEMPLATE = (manifest) => `
597
600
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
598
601
  `.trimStart();
599
- const require$1 = createRequire(import.meta.url);
600
602
  const isDefault = process$1.env.JIEK_IS_ONLY_BUILD === "true";
601
603
  const description = `
602
604
  Build the package according to the 'exports' field from the package.json.
@@ -606,7 +608,7 @@ ${isDefault ? "This command is the default command." : ""}
606
608
  let DEFAULT_BUILDER_TYPE;
607
609
  Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
608
610
  try {
609
- require$1.resolve(packageName);
611
+ require.resolve(packageName);
610
612
  DEFAULT_BUILDER_TYPE = type;
611
613
  } catch {
612
614
  }
@@ -679,13 +681,8 @@ command.action(async (commandFiltersOrEntries, options) => {
679
681
  minifyType = resolvedType;
680
682
  }
681
683
  }
682
- if (!withoutMin) {
683
- await checkDependency(
684
- {
685
- ...BUILDER_TYPE_PACKAGE_NAME_MAP,
686
- terser: "@rollup/plugin-terser"
687
- }[resolvedType]
688
- );
684
+ if (!withoutMin && minifyType === "terser") {
685
+ await checkDependency("@rollup/plugin-terser");
689
686
  }
690
687
  let shouldPassThrough = false;
691
688
  const passThroughOptions = process$1.argv.reduce(
@@ -763,7 +760,7 @@ command.action(async (commandFiltersOrEntries, options) => {
763
760
  } catch {
764
761
  }
765
762
  }
766
- 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");
767
764
  let i = 0;
768
765
  await Promise.all(
769
766
  Object.entries(value).map(async ([pkgCWD, manifest]) => {
@@ -908,12 +905,15 @@ command.action(async (commandFiltersOrEntries, options) => {
908
905
  }
909
906
  });
910
907
  await new Promise((resolve, reject) => {
911
- let errorStr = "";
908
+ let errorStr = `rollup build failed
909
+ package name: ${manifest.name}
910
+ cwd: ${pkgCWD}
911
+
912
+ `;
912
913
  child.stderr?.on("data", (data) => {
913
914
  errorStr += data;
914
915
  });
915
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
916
- ${errorStr}`)));
916
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
917
917
  verbose && child.stdout?.pipe(process$1.stdout);
918
918
  });
919
919
  })
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 {
@@ -4311,14 +4310,24 @@ function getExports({
4311
4310
  }
4312
4311
  );
4313
4312
  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
4313
+ import: (opts) => {
4314
+ if (pkgIsModule) return false;
4315
+ if (opts.src.endsWith(".cts")) return false;
4316
+ if (intersection(
4317
+ new Set(opts.conditionals),
4318
+ /* @__PURE__ */ new Set(["import", "module"])
4319
+ ).size !== 0) return false;
4320
+ return opts.dist.replace(/\.js$/, ".mjs");
4321
+ },
4322
+ require: (opts) => {
4323
+ if (!pkgIsModule) return false;
4324
+ if (opts.src.endsWith(".mts")) return false;
4325
+ if (intersection(
4326
+ new Set(opts.conditionals),
4327
+ /* @__PURE__ */ new Set(["require", "node"])
4328
+ ).size !== 0) return false;
4329
+ return opts.dist.replace(/\.js$/, ".cjs");
4330
+ }
4322
4331
  } : {};
4323
4332
  return [
4324
4333
  filteredResolvedEntrypoints,
@@ -4335,10 +4344,9 @@ function getExports({
4335
4344
  ];
4336
4345
  }
4337
4346
 
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
4347
  function packageIsExist(name) {
4340
4348
  try {
4341
- require$2.resolve(name);
4349
+ require$1.resolve(name);
4342
4350
  return true;
4343
4351
  } catch (e) {
4344
4352
  return false;
@@ -4358,7 +4366,6 @@ for (const register of registers) {
4358
4366
  }
4359
4367
  }
4360
4368
 
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
4369
  let configName = "jiek.config";
4363
4370
  function getConfigPath(root, dir) {
4364
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 {
@@ -4280,14 +4281,24 @@ function getExports({
4280
4281
  }
4281
4282
  );
4282
4283
  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
4284
+ import: (opts) => {
4285
+ if (pkgIsModule) return false;
4286
+ if (opts.src.endsWith(".cts")) return false;
4287
+ if (intersection(
4288
+ new Set(opts.conditionals),
4289
+ /* @__PURE__ */ new Set(["import", "module"])
4290
+ ).size !== 0) return false;
4291
+ return opts.dist.replace(/\.js$/, ".mjs");
4292
+ },
4293
+ require: (opts) => {
4294
+ if (!pkgIsModule) return false;
4295
+ if (opts.src.endsWith(".mts")) return false;
4296
+ if (intersection(
4297
+ new Set(opts.conditionals),
4298
+ /* @__PURE__ */ new Set(["require", "node"])
4299
+ ).size !== 0) return false;
4300
+ return opts.dist.replace(/\.js$/, ".cjs");
4301
+ }
4291
4302
  } : {};
4292
4303
  return [
4293
4304
  filteredResolvedEntrypoints,
@@ -4304,10 +4315,9 @@ function getExports({
4304
4315
  ];
4305
4316
  }
4306
4317
 
4307
- const require$1 = createRequire(import.meta.url);
4308
4318
  function packageIsExist(name) {
4309
4319
  try {
4310
- require$1.resolve(name);
4320
+ require.resolve(name);
4311
4321
  return true;
4312
4322
  } catch (e) {
4313
4323
  return false;
@@ -4327,7 +4337,6 @@ for (const register of registers) {
4327
4337
  }
4328
4338
  }
4329
4339
 
4330
- const require = createRequire(import.meta.url);
4331
4340
  let configName = "jiek.config";
4332
4341
  function getConfigPath(root, dir) {
4333
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
 
@@ -4253,14 +4250,24 @@ function getExports({
4253
4250
  }
4254
4251
  );
4255
4252
  const crossModuleWithConditional = crossModuleConvertor ? {
4256
- import: (opts) => !pkgIsModule && intersection(
4257
- new Set(opts.conditionals),
4258
- /* @__PURE__ */ new Set(["import", "module"])
4259
- ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4260
- require: (opts) => pkgIsModule && intersection(
4261
- new Set(opts.conditionals),
4262
- /* @__PURE__ */ new Set(["require", "node"])
4263
- ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4253
+ import: (opts) => {
4254
+ if (pkgIsModule) return false;
4255
+ if (opts.src.endsWith(".cts")) return false;
4256
+ if (intersection(
4257
+ new Set(opts.conditionals),
4258
+ /* @__PURE__ */ new Set(["import", "module"])
4259
+ ).size !== 0) return false;
4260
+ return opts.dist.replace(/\.js$/, ".mjs");
4261
+ },
4262
+ require: (opts) => {
4263
+ if (!pkgIsModule) return false;
4264
+ if (opts.src.endsWith(".mts")) return false;
4265
+ if (intersection(
4266
+ new Set(opts.conditionals),
4267
+ /* @__PURE__ */ new Set(["require", "node"])
4268
+ ).size !== 0) return false;
4269
+ return opts.dist.replace(/\.js$/, ".cjs");
4270
+ }
4264
4271
  } : {};
4265
4272
  return [
4266
4273
  filteredResolvedEntrypoints,
@@ -4277,6 +4284,8 @@ function getExports({
4277
4284
  ];
4278
4285
  }
4279
4286
 
4287
+ var require$1 = require;
4288
+
4280
4289
  let root;
4281
4290
  function getRoot() {
4282
4291
  if (root) return root;
@@ -4287,7 +4296,6 @@ function getRoot() {
4287
4296
 
4288
4297
  let type = "";
4289
4298
  try {
4290
- 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)));
4291
4299
  require$1.resolve("@pnpm/filter-workspace-packages");
4292
4300
  type = "pnpm";
4293
4301
  } catch {
@@ -4317,10 +4325,9 @@ function getWD() {
4317
4325
  return { wd, notWorkspace };
4318
4326
  }
4319
4327
 
4320
- 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)));
4321
4328
  function packageIsExist(name) {
4322
4329
  try {
4323
- require$2.resolve(name);
4330
+ require$1.resolve(name);
4324
4331
  return true;
4325
4332
  } catch (e) {
4326
4333
  return false;
@@ -4340,7 +4347,6 @@ for (const register of registers) {
4340
4347
  }
4341
4348
  }
4342
4349
 
4343
- 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)));
4344
4350
  let configName = "jiek.config";
4345
4351
  function getConfigPath(root, dir) {
4346
4352
  const isSupportTsLoader = !!tsRegisterName;
@@ -4470,8 +4476,8 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4470
4476
  if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i))) return;
4471
4477
  if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0) return;
4472
4478
  let isInclude = false;
4473
- isInclude ||= files.length > 0 && files.includes(filePath);
4474
- isInclude ||= include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i));
4479
+ isInclude || (isInclude = files.length > 0 && files.includes(filePath));
4480
+ isInclude || (isInclude = include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i)));
4475
4481
  if (isInclude) {
4476
4482
  return tsconfig.compilerOptions ?? {};
4477
4483
  } else {
@@ -4485,43 +4491,16 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4485
4491
  return tsconfig.compilerOptions;
4486
4492
  };
4487
4493
 
4488
- const virtualModuleName = "jiek:create-require";
4489
- const isEsmVariableName = `IS_ESM${Math.random().toString(36).slice(2)}`;
4490
- const INSERT_STR = `
4491
- import { createRequire } from 'node:module'
4492
-
4493
- export default (
4494
- ${isEsmVariableName}
4495
- ? /* @__PURE__ */ createRequire(import.meta.url)
4496
- : require
4497
- )
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"}
4498
4498
  `.trim();
4499
- var createRequire = () => ({
4500
- ...inject__default.default({
4501
- require: virtualModuleName
4502
- }),
4499
+ var createRequire = (isEsm) => ({
4503
4500
  name: "create-require",
4504
- resolveId: (source) => source === virtualModuleName ? source : null,
4505
- load: (id) => {
4506
- if (id !== virtualModuleName) {
4507
- return null;
4508
- }
4509
- return INSERT_STR;
4510
- }
4501
+ resolveId: (id) => id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME ? id : null,
4502
+ load: (id) => id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME ? INSERT_STR(isEsm) : null
4511
4503
  });
4512
- const isFormatEsm = (isEsm) => {
4513
- const handler = replace__default.default({
4514
- [isEsmVariableName]: isEsm
4515
- }).renderChunk;
4516
- return {
4517
- name: "create-require-insert-format",
4518
- // Pick out renderChunk because it's used as an output plugin
4519
- renderChunk: {
4520
- order: "pre",
4521
- handler: typeof handler === "function" ? handler : handler.handler
4522
- }
4523
- };
4524
- };
4525
4504
 
4526
4505
  var progress = (options = {}) => {
4527
4506
  const { onEvent } = options;
@@ -4814,7 +4793,16 @@ const generateConfigs = (context, options = {}) => {
4814
4793
  ({ default: esbuild }) => esbuild({
4815
4794
  sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4816
4795
  tsconfig: buildTSConfigPath,
4817
- target: "node22",
4796
+ loaders: {
4797
+ cts: "ts",
4798
+ ctsx: "tsx",
4799
+ mts: "ts",
4800
+ mtsx: "tsx",
4801
+ cjs: "js",
4802
+ cjsx: "jsx",
4803
+ mjs: "js",
4804
+ mjsx: "jsx"
4805
+ },
4818
4806
  ...noTypeResolvedBuilderOptions,
4819
4807
  supported: {
4820
4808
  "import-attributes": features.keepImportAttributes !== false,
@@ -4831,6 +4819,12 @@ const generateConfigs = (context, options = {}) => {
4831
4819
  ...noTypeResolvedBuilderOptions,
4832
4820
  jsc: {
4833
4821
  ...resolvedBuilderOptions.jsc,
4822
+ parser: resolvedBuilderOptions.jsc?.parser ? resolvedBuilderOptions.jsc?.parser : {
4823
+ syntax: "typescript",
4824
+ tsx: true,
4825
+ decorators: true,
4826
+ dynamicImport: true
4827
+ },
4834
4828
  experimental: {
4835
4829
  ...resolvedBuilderOptions.jsc?.experimental,
4836
4830
  keepImportAttributes: features.keepImportAttributes !== false
@@ -4856,9 +4850,7 @@ const generateConfigs = (context, options = {}) => {
4856
4850
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4857
4851
  externalImportAttributes: features.keepImportAttributes !== false,
4858
4852
  importAttributesKey: features.keepImportAttributes === false || features.keepImportAttributes === void 0 ? void 0 : features.keepImportAttributes === true ? "with" : features.keepImportAttributes,
4859
- plugins: [
4860
- isFormatEsm(format === "esm")
4861
- ]
4853
+ plugins: []
4862
4854
  }, onlyOncePlugins)
4863
4855
  ],
4864
4856
  plugins: [
@@ -4870,8 +4862,12 @@ const generateConfigs = (context, options = {}) => {
4870
4862
  })
4871
4863
  ).catch(() => void 0),
4872
4864
  commonjs__default.default(),
4873
- createRequire(),
4874
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"),
4875
4871
  ana,
4876
4872
  progress({
4877
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
 
@@ -4237,14 +4236,24 @@ function getExports({
4237
4236
  }
4238
4237
  );
4239
4238
  const crossModuleWithConditional = crossModuleConvertor ? {
4240
- import: (opts) => !pkgIsModule && intersection(
4241
- new Set(opts.conditionals),
4242
- /* @__PURE__ */ new Set(["import", "module"])
4243
- ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
4244
- require: (opts) => pkgIsModule && intersection(
4245
- new Set(opts.conditionals),
4246
- /* @__PURE__ */ new Set(["require", "node"])
4247
- ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
4239
+ import: (opts) => {
4240
+ if (pkgIsModule) return false;
4241
+ if (opts.src.endsWith(".cts")) return false;
4242
+ if (intersection(
4243
+ new Set(opts.conditionals),
4244
+ /* @__PURE__ */ new Set(["import", "module"])
4245
+ ).size !== 0) return false;
4246
+ return opts.dist.replace(/\.js$/, ".mjs");
4247
+ },
4248
+ require: (opts) => {
4249
+ if (!pkgIsModule) return false;
4250
+ if (opts.src.endsWith(".mts")) return false;
4251
+ if (intersection(
4252
+ new Set(opts.conditionals),
4253
+ /* @__PURE__ */ new Set(["require", "node"])
4254
+ ).size !== 0) return false;
4255
+ return opts.dist.replace(/\.js$/, ".cjs");
4256
+ }
4248
4257
  } : {};
4249
4258
  return [
4250
4259
  filteredResolvedEntrypoints,
@@ -4261,6 +4270,8 @@ function getExports({
4261
4270
  ];
4262
4271
  }
4263
4272
 
4273
+ var require = /* @__PURE__ */ createRequire$1(import.meta.url);
4274
+
4264
4275
  let root;
4265
4276
  function getRoot() {
4266
4277
  if (root) return root;
@@ -4271,7 +4282,6 @@ function getRoot() {
4271
4282
 
4272
4283
  let type = "";
4273
4284
  try {
4274
- const require = createRequire$1(import.meta.url);
4275
4285
  require.resolve("@pnpm/filter-workspace-packages");
4276
4286
  type = "pnpm";
4277
4287
  } catch {
@@ -4301,10 +4311,9 @@ function getWD() {
4301
4311
  return { wd, notWorkspace };
4302
4312
  }
4303
4313
 
4304
- const require$1 = createRequire$1(import.meta.url);
4305
4314
  function packageIsExist(name) {
4306
4315
  try {
4307
- require$1.resolve(name);
4316
+ require.resolve(name);
4308
4317
  return true;
4309
4318
  } catch (e) {
4310
4319
  return false;
@@ -4324,7 +4333,6 @@ for (const register of registers) {
4324
4333
  }
4325
4334
  }
4326
4335
 
4327
- const require = createRequire$1(import.meta.url);
4328
4336
  let configName = "jiek.config";
4329
4337
  function getConfigPath(root, dir) {
4330
4338
  const isSupportTsLoader = !!tsRegisterName;
@@ -4454,8 +4462,8 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4454
4462
  if (exclude.length > 0 && exclude.some((i) => micromatchExports.isMatch(filePath, i))) return;
4455
4463
  if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0) return;
4456
4464
  let isInclude = false;
4457
- isInclude ||= files.length > 0 && files.includes(filePath);
4458
- isInclude ||= include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i));
4465
+ isInclude || (isInclude = files.length > 0 && files.includes(filePath));
4466
+ isInclude || (isInclude = include.length > 0 && include.some((i) => micromatchExports.isMatch(filePath, i)));
4459
4467
  if (isInclude) {
4460
4468
  return tsconfig.compilerOptions ?? {};
4461
4469
  } else {
@@ -4469,43 +4477,16 @@ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
4469
4477
  return tsconfig.compilerOptions;
4470
4478
  };
4471
4479
 
4472
- const virtualModuleName = "jiek:create-require";
4473
- const isEsmVariableName = `IS_ESM${Math.random().toString(36).slice(2)}`;
4474
- const INSERT_STR = `
4475
- import { createRequire } from 'node:module'
4476
-
4477
- export default (
4478
- ${isEsmVariableName}
4479
- ? /* @__PURE__ */ createRequire(import.meta.url)
4480
- : require
4481
- )
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"}
4482
4484
  `.trim();
4483
- var createRequire = () => ({
4484
- ...inject({
4485
- require: virtualModuleName
4486
- }),
4485
+ var createRequire = (isEsm) => ({
4487
4486
  name: "create-require",
4488
- resolveId: (source) => source === virtualModuleName ? source : null,
4489
- load: (id) => {
4490
- if (id !== virtualModuleName) {
4491
- return null;
4492
- }
4493
- return INSERT_STR;
4494
- }
4487
+ resolveId: (id) => id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME ? id : null,
4488
+ load: (id) => id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME ? INSERT_STR(isEsm) : null
4495
4489
  });
4496
- const isFormatEsm = (isEsm) => {
4497
- const handler = replace({
4498
- [isEsmVariableName]: isEsm
4499
- }).renderChunk;
4500
- return {
4501
- name: "create-require-insert-format",
4502
- // Pick out renderChunk because it's used as an output plugin
4503
- renderChunk: {
4504
- order: "pre",
4505
- handler: typeof handler === "function" ? handler : handler.handler
4506
- }
4507
- };
4508
- };
4509
4490
 
4510
4491
  var progress = (options = {}) => {
4511
4492
  const { onEvent } = options;
@@ -4798,7 +4779,16 @@ const generateConfigs = (context, options = {}) => {
4798
4779
  ({ default: esbuild }) => esbuild({
4799
4780
  sourceMap: sourcemap === "hidden" ? false : !!sourcemap,
4800
4781
  tsconfig: buildTSConfigPath,
4801
- target: "node22",
4782
+ loaders: {
4783
+ cts: "ts",
4784
+ ctsx: "tsx",
4785
+ mts: "ts",
4786
+ mtsx: "tsx",
4787
+ cjs: "js",
4788
+ cjsx: "jsx",
4789
+ mjs: "js",
4790
+ mjsx: "jsx"
4791
+ },
4802
4792
  ...noTypeResolvedBuilderOptions,
4803
4793
  supported: {
4804
4794
  "import-attributes": features.keepImportAttributes !== false,
@@ -4815,6 +4805,12 @@ const generateConfigs = (context, options = {}) => {
4815
4805
  ...noTypeResolvedBuilderOptions,
4816
4806
  jsc: {
4817
4807
  ...resolvedBuilderOptions.jsc,
4808
+ parser: resolvedBuilderOptions.jsc?.parser ? resolvedBuilderOptions.jsc?.parser : {
4809
+ syntax: "typescript",
4810
+ tsx: true,
4811
+ decorators: true,
4812
+ dynamicImport: true
4813
+ },
4818
4814
  experimental: {
4819
4815
  ...resolvedBuilderOptions.jsc?.experimental,
4820
4816
  keepImportAttributes: features.keepImportAttributes !== false
@@ -4840,9 +4836,7 @@ const generateConfigs = (context, options = {}) => {
4840
4836
  strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict,
4841
4837
  externalImportAttributes: features.keepImportAttributes !== false,
4842
4838
  importAttributesKey: features.keepImportAttributes === false || features.keepImportAttributes === void 0 ? void 0 : features.keepImportAttributes === true ? "with" : features.keepImportAttributes,
4843
- plugins: [
4844
- isFormatEsm(format === "esm")
4845
- ]
4839
+ plugins: []
4846
4840
  }, onlyOncePlugins)
4847
4841
  ],
4848
4842
  plugins: [
@@ -4854,8 +4848,12 @@ const generateConfigs = (context, options = {}) => {
4854
4848
  })
4855
4849
  ).catch(() => void 0),
4856
4850
  commonjs(),
4857
- createRequire(),
4858
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"),
4859
4857
  ana,
4860
4858
  progress({
4861
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",
4
+ "version": "2.2.4",
5
5
  "description": "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.",
6
6
  "author": "YiJie <yijie4188@gmail.com>",
7
7
  "homepage": "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme",
@@ -61,7 +61,7 @@
61
61
  "jb": "bin/jiek-build.js"
62
62
  },
63
63
  "peerDependencies": {
64
- "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
64
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
65
65
  "@rollup/plugin-terser": "^0.4.4",
66
66
  "esbuild-register": "^3.5.0",
67
67
  "postcss": "^8.4.47",
@@ -72,13 +72,12 @@
72
72
  "vite-bundle-analyzer": "0.16.0-beta.1"
73
73
  },
74
74
  "dependencies": {
75
- "@inquirer/prompts": "^7.1.0",
75
+ "@inquirer/prompts": "^7.2.0",
76
76
  "@jiek/rollup-plugin-dts": "^6.2.1",
77
77
  "@rollup/plugin-commonjs": "^28.0.0",
78
78
  "@rollup/plugin-inject": "^5.0.5",
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",
@@ -87,8 +86,8 @@
87
86
  "jsonc-parser": "^3.2.1",
88
87
  "koa": "^2.15.3",
89
88
  "rollup": "^4.0.0",
90
- "@jiek/pkger": "^0.2.1",
91
- "@jiek/utils": "^0.2.3"
89
+ "@jiek/utils": "^0.2.3",
90
+ "@jiek/pkger": "^0.2.1"
92
91
  },
93
92
  "peerDependenciesMeta": {
94
93
  "@pnpm/filter-workspace-packages": {
@@ -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 = `
@@ -214,13 +211,8 @@ command
214
211
  minifyType = resolvedType
215
212
  }
216
213
  }
217
- if (!withoutMin) {
218
- await checkDependency(
219
- {
220
- ...BUILDER_TYPE_PACKAGE_NAME_MAP,
221
- terser: '@rollup/plugin-terser'
222
- }[resolvedType]
223
- )
214
+ if (!withoutMin && minifyType === 'terser') {
215
+ await checkDependency('@rollup/plugin-terser')
224
216
  }
225
217
  let shouldPassThrough = false
226
218
 
@@ -471,14 +463,16 @@ command
471
463
  }
472
464
  })
473
465
  await new Promise<void>((resolve, reject) => {
474
- let errorStr = ''
466
+ let errorStr = `rollup build failed\n`
467
+ + `package name: ${manifest.name}\n`
468
+ + `cwd: ${pkgCWD}\n\n`
475
469
  child.stderr?.on('data', (data) => {
476
470
  errorStr += data
477
471
  })
478
472
  child.once('exit', (code) =>
479
473
  code === 0
480
474
  ? resolve()
481
- : reject(new Error(`rollup build failed:\n${errorStr}`)))
475
+ : reject(new Error(errorStr)))
482
476
  verbose && child.stdout?.pipe(process.stdout)
483
477
  })
484
478
  })
@@ -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'
@@ -389,7 +390,16 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
389
390
  esbuild({
390
391
  sourceMap: sourcemap === 'hidden' ? false : !!sourcemap,
391
392
  tsconfig: buildTSConfigPath,
392
- target: 'node22',
393
+ loaders: {
394
+ cts: 'ts',
395
+ ctsx: 'tsx',
396
+ mts: 'ts',
397
+ mtsx: 'tsx',
398
+ cjs: 'js',
399
+ cjsx: 'jsx',
400
+ mjs: 'js',
401
+ mjsx: 'jsx'
402
+ },
393
403
  ...noTypeResolvedBuilderOptions,
394
404
  supported: {
395
405
  'import-attributes': features.keepImportAttributes !== false,
@@ -411,6 +421,14 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
411
421
  ...noTypeResolvedBuilderOptions,
412
422
  jsc: {
413
423
  ...resolvedBuilderOptions.jsc,
424
+ parser: resolvedBuilderOptions.jsc?.parser
425
+ ? resolvedBuilderOptions.jsc?.parser
426
+ : {
427
+ syntax: 'typescript',
428
+ tsx: true,
429
+ decorators: true,
430
+ dynamicImport: true
431
+ },
414
432
  experimental: {
415
433
  ...resolvedBuilderOptions.jsc?.experimental,
416
434
  keepImportAttributes: features.keepImportAttributes !== false
@@ -451,9 +469,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
451
469
  : features.keepImportAttributes === true
452
470
  ? 'with'
453
471
  : features.keepImportAttributes,
454
- plugins: [
455
- isFormatEsm(format === 'esm')
456
- ]
472
+ plugins: []
457
473
  }, onlyOncePlugins)
458
474
  ],
459
475
  plugins: [
@@ -467,8 +483,12 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
467
483
  )
468
484
  .catch(() => void 0),
469
485
  commonjs(),
470
- createRequire(),
471
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'),
472
492
  ana,
473
493
  progress({
474
494
  onEvent: (event, message) => void publishInEntry('progress', { event, message, tags: ['js'] })
@@ -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,7 +1,7 @@
1
+ import { execSync } from 'node:child_process'
1
2
  import process from 'node:process'
2
3
 
3
4
  import { confirm } from '@inquirer/prompts'
4
- import { execaCommand } from 'execa'
5
5
 
6
6
  import { getWD } from '#~/utils/getWD.ts'
7
7
 
@@ -11,9 +11,13 @@ export async function checkDependency(dependency: string) {
11
11
  } catch {
12
12
  console.error(`The package '${dependency}' is not installed, please install it first.`)
13
13
  const { notWorkspace } = getWD()
14
- const command = `pnpm install -${notWorkspace ? '' : 'w'}D ${dependency}`
15
- if (await confirm({ message: 'Do you want to install it now?' })) {
16
- await execaCommand(command)
14
+ const command = `pnpm add -${notWorkspace ? '' : 'w'}D ${dependency}`
15
+ if (await confirm({ message: `Do you want to add 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,11 +1,11 @@
1
1
  import { isAbsolute, relative, resolve } from 'node:path'
2
2
 
3
3
  import {
4
+ type Entrypoints2ExportsOptions,
5
+ type RecursiveRecord,
4
6
  DEFAULT_SKIP_VALUES,
5
7
  entrypoints2Exports,
6
- type Entrypoints2ExportsOptions,
7
8
  filterLeafs,
8
- type RecursiveRecord,
9
9
  resolveEntrypoints
10
10
  } from '@jiek/pkger/entrypoints'
11
11
  import type { Config } from 'jiek'
@@ -109,20 +109,30 @@ export function getExports({
109
109
  )
110
110
  const crossModuleWithConditional: Entrypoints2ExportsOptions['withConditional'] = crossModuleConvertor
111
111
  ? {
112
- import: opts =>
113
- !pkgIsModule && intersection(
114
- new Set(opts.conditionals),
115
- new Set(['import', 'module'])
116
- ).size === 0
117
- ? opts.dist.replace(/\.js$/, '.mjs')
118
- : false,
119
- require: opts =>
120
- pkgIsModule && intersection(
121
- new Set(opts.conditionals),
122
- new Set(['require', 'node'])
123
- ).size === 0
124
- ? opts.dist.replace(/\.js$/, '.cjs')
125
- : false
112
+ import: opts => {
113
+ if (pkgIsModule) return false
114
+ if (opts.src.endsWith('.cts')) return false
115
+ if (
116
+ intersection(
117
+ new Set(opts.conditionals),
118
+ new Set(['import', 'module'])
119
+ ).size !== 0
120
+ ) return false
121
+
122
+ return opts.dist.replace(/\.js$/, '.mjs')
123
+ },
124
+ require: opts => {
125
+ if (!pkgIsModule) return false
126
+ if (opts.src.endsWith('.mts')) return false
127
+ if (
128
+ intersection(
129
+ new Set(opts.conditionals),
130
+ new Set(['require', 'node'])
131
+ ).size !== 0
132
+ ) return false
133
+
134
+ return opts.dist.replace(/\.js$/, '.cjs')
135
+ }
126
136
  }
127
137
  : {}
128
138
  return [
@@ -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)