jiek 2.1.11 → 2.1.12

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/bin-helper.cjs ADDED
@@ -0,0 +1,18 @@
1
+ const {
2
+ JIEK_BIN__FILEPATH: binFilePath
3
+ } = process.env
4
+
5
+ const {
6
+ basename,
7
+ dirname
8
+ } = require('node:path')
9
+
10
+ const packageDir = dirname(dirname(binFilePath))
11
+ const binFilename = basename(binFilePath).replace(/(\.[cm]?)js$/, '$1ts')
12
+
13
+ process.env.JIEK_PACKAGE_DIR = packageDir
14
+ process.env.JIEK_BIN__FILENAME = binFilename
15
+ process.env.JIEK_BIN__FILEPATH = binFilePath
16
+
17
+ require('esbuild-register')
18
+ require(`${packageDir}/src/bin/${binFilename}`)
package/bin-helper.js ADDED
@@ -0,0 +1,3 @@
1
+ import { createRequire } from 'node:module'
2
+
3
+ createRequire(import.meta.url)('./bin-helper.cjs')
@@ -6,6 +6,7 @@ var path = require('node:path');
6
6
  var commander = require('commander');
7
7
  var jsYaml = require('js-yaml');
8
8
  var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
9
+ var process$1 = require('node:process');
9
10
  var prompts = require('@inquirer/prompts');
10
11
  var cliProgress = require('cli-progress');
11
12
  var execa = require('execa');
@@ -15,6 +16,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
16
 
16
17
  var fs__default = /*#__PURE__*/_interopDefault(fs);
17
18
  var path__default = /*#__PURE__*/_interopDefault(path);
19
+ var process__default = /*#__PURE__*/_interopDefault(process$1);
18
20
 
19
21
  let root;
20
22
  function getRoot() {
@@ -52,7 +54,7 @@ function getWD() {
52
54
 
53
55
  let type$1 = "";
54
56
  try {
55
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
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)));
56
58
  require$1.resolve("@pnpm/filter-workspace-packages");
57
59
  type$1 = "pnpm";
58
60
  } catch {
@@ -116,15 +118,29 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
116
118
 
117
119
  var name = "jiek";
118
120
  var type = "module";
119
- var version = "2.1.10";
121
+ var version = "2.1.11";
120
122
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
121
123
  var author = "YiJie <yijie4188@gmail.com>";
124
+ var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
122
125
  var repository = {
123
126
  url: "nwylzw/jiek",
124
127
  directory: "packages/jiek"
125
128
  };
126
- var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
127
129
  var bugs = "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek";
130
+ var exports$1 = {
131
+ "./package.json": "./package.json",
132
+ ".": "./src/index.ts",
133
+ "./bin-helper": {
134
+ require: "./bin-helper.cjs",
135
+ "default": "./bin-helper.js"
136
+ },
137
+ "./cli": "./src/cli.ts",
138
+ "./cli-only-build": "./src/cli-only-build.ts",
139
+ "./rollup": "./src/rollup/index.ts"
140
+ };
141
+ var imports = {
142
+ "#~/*": "./src/*"
143
+ };
128
144
  var bin = {
129
145
  jiek: "bin/jiek.js",
130
146
  jk: "bin/jiek.js",
@@ -132,52 +148,47 @@ var bin = {
132
148
  jb: "bin/jiek-build.js"
133
149
  };
134
150
  var files = [
135
- "dist",
136
- "src",
137
- "bin",
138
151
  "LICENSE",
139
- "README.md"
152
+ "README.md",
153
+ "bin",
154
+ "bin-helper.cjs",
155
+ "bin-helper.js",
156
+ "dist",
157
+ "src"
140
158
  ];
141
159
  var scripts = {
142
160
  prepublish: "jb -nm && jk",
143
161
  postpublish: "jk",
144
162
  test: "vitest run"
145
163
  };
146
- var exports$1 = {
147
- "./package.json": "./package.json",
148
- ".": "./src/index.ts",
149
- "./cli": "./src/cli.ts",
150
- "./cli-only-build": "./src/cli-only-build.ts",
151
- "./rollup": "./src/rollup/index.ts"
152
- };
153
- var imports = {
154
- "#~/*": "./src/*"
164
+ var peerDependencies = {
165
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
166
+ "@rollup/plugin-terser": "^0.4.4",
167
+ "esbuild-register": "^3.5.0",
168
+ postcss: "^8.4.47",
169
+ "rollup-plugin-esbuild": "^6.1.0",
170
+ "rollup-plugin-postcss": "^4.0.2",
171
+ "rollup-plugin-swc3": "^0.12.1",
172
+ typescript: "^4.0.0||^5.0.0",
173
+ "vite-bundle-analyzer": "^0.15.1"
155
174
  };
156
175
  var dependencies = {
176
+ "@inquirer/prompts": "^7.1.0",
157
177
  "@jiek/pkger": "workspace:^",
158
178
  "@jiek/rollup-plugin-dts": "^6.2.1",
159
179
  "@jiek/utils": "workspace:^",
160
- "@inquirer/prompts": "^7.1.0",
161
180
  "@rollup/plugin-commonjs": "^28.0.0",
181
+ "@rollup/plugin-inject": "^5.0.5",
162
182
  "@rollup/plugin-json": "^6.0.1",
163
183
  "@rollup/plugin-node-resolve": "^15.3.0",
184
+ "@rollup/plugin-replace": "^6.0.1",
164
185
  "cli-progress": "^3.12.0",
165
186
  commander: "^12.0.0",
166
187
  "detect-indent": "^6.1.0",
167
- execa: "9.3.1",
188
+ execa: "~9.3.1",
168
189
  "js-yaml": "^4.1.0",
169
190
  "jsonc-parser": "^3.2.1",
170
- rollup: "4.13.2"
171
- };
172
- var peerDependencies = {
173
- "@rollup/plugin-terser": "^0.4.4",
174
- "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
175
- "esbuild-register": "^3.5.0",
176
- postcss: "^8.4.47",
177
- "rollup-plugin-postcss": "^4.0.2",
178
- "rollup-plugin-esbuild": "^6.1.0",
179
- "rollup-plugin-swc3": "^0.12.1",
180
- typescript: "^4.0.0||^5.0.0"
191
+ rollup: "^4.0.0"
181
192
  };
182
193
  var devDependencies = {
183
194
  "@npm/types": "^1.0.2",
@@ -192,9 +203,10 @@ var devDependencies = {
192
203
  micromatch: "^4.0.5",
193
204
  "node-sass": "^9.0.0",
194
205
  postcss: "^8.4.47",
195
- "rollup-plugin-postcss": "^4.0.2",
196
206
  "rollup-plugin-esbuild": "^6.1.0",
197
- "rollup-plugin-swc3": "^0.12.1"
207
+ "rollup-plugin-postcss": "^4.0.2",
208
+ "rollup-plugin-swc3": "^0.12.1",
209
+ "vite-bundle-analyzer": "^0.15.1"
198
210
  };
199
211
  var pkg = {
200
212
  name: name,
@@ -202,16 +214,16 @@ var pkg = {
202
214
  version: version,
203
215
  description: description$1,
204
216
  author: author,
205
- repository: repository,
206
217
  homepage: homepage,
218
+ repository: repository,
207
219
  bugs: bugs,
220
+ exports: exports$1,
221
+ imports: imports,
208
222
  bin: bin,
209
223
  files: files,
210
224
  scripts: scripts,
211
- exports: exports$1,
212
- imports: imports,
213
- dependencies: dependencies,
214
225
  peerDependencies: peerDependencies,
226
+ dependencies: dependencies,
215
227
  devDependencies: devDependencies
216
228
  };
217
229
 
@@ -234,12 +246,12 @@ Support with variables: 'PKG_NAME',
234
246
  const { notWorkspace } = getWD();
235
247
  const IS_WORKSPACE = !notWorkspace;
236
248
 
237
- commander.program.name("jk/jiek").version(pkg.version).description(`${pkg.description} - Version ${pkg.version}`).option("-c, --config-path <configPath>", "Custom jiek config path");
249
+ commander.program.name("jk/jiek").version(pkg.version).description(`${pkg.description} - Version ${pkg.version}`).option("-c, --config-path <configPath>", "Custom jiek config path").option("--env.<name>=<value>", "Set the environment variable.");
238
250
  if (type$1 !== "" && IS_WORKSPACE) {
239
251
  commander.program.option("-f, --filter <filter>", filterDescription);
240
252
  }
241
253
 
242
- const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
254
+ 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)));
243
255
  function packageIsExist(name) {
244
256
  try {
245
257
  require$3.resolve(name);
@@ -262,7 +274,7 @@ for (const register of registers) {
262
274
  }
263
275
  }
264
276
 
265
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
277
+ 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)));
266
278
  let configName = "jiek.config";
267
279
  function getConfigPath(root, dir) {
268
280
  const isSupportTsLoader = !!tsRegisterName;
@@ -297,10 +309,7 @@ function getConfigPath(root, dir) {
297
309
  function loadConfig(dirOrOptions) {
298
310
  let dir;
299
311
  let root;
300
- if (typeof dirOrOptions === "object") {
301
- dir = dirOrOptions.dir;
302
- root = dirOrOptions.root ?? getWD().wd;
303
- } else {
312
+ {
304
313
  dir = dirOrOptions;
305
314
  root = getWD().wd;
306
315
  }
@@ -354,8 +363,8 @@ const BUILDER_TYPE_PACKAGE_NAME_MAP = {
354
363
  const FILE_TEMPLATE = (manifest) => `
355
364
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
356
365
  `.trimStart();
357
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli-only-build.cjs', document.baseURI).href)));
358
- const isDefault = process.env.JIEK_IS_ONLY_BUILD === "true";
366
+ 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)));
367
+ const isDefault = process__default.default.env.JIEK_IS_ONLY_BUILD === "true";
359
368
  const description = `
360
369
  Build the package according to the 'exports' field from the package.json.
361
370
  If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
@@ -364,7 +373,7 @@ ${isDefault ? "This command is the default command." : ""}
364
373
  async function checkDependency(dependency) {
365
374
  try {
366
375
  require$1.resolve(dependency);
367
- } catch (e) {
376
+ } catch {
368
377
  console.error(`The package '${dependency}' is not installed, please install it first.`);
369
378
  const { notWorkspace } = getWD();
370
379
  const command2 = `pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`;
@@ -372,7 +381,7 @@ async function checkDependency(dependency) {
372
381
  await execa.execaCommand(command2);
373
382
  } else {
374
383
  console.warn(`You can run the command '${command2}' to install it manually.`);
375
- process.exit(1);
384
+ process__default.default.exit(1);
376
385
  }
377
386
  }
378
387
  }
@@ -400,7 +409,7 @@ const buildEntriesDescription = `
400
409
  ${entriesDescription}
401
410
  If you pass the --entries option, it will merge into the entries of the command.
402
411
  `.trim();
403
- const command = isDefault ? (() => {
412
+ let command = isDefault ? (() => {
404
413
  const c = commander.program.name("jb/jiek-build").helpCommand(false);
405
414
  if (IS_WORKSPACE) {
406
415
  c.argument("[filters]", buildFilterDescription);
@@ -409,7 +418,7 @@ const command = isDefault ? (() => {
409
418
  }
410
419
  return c;
411
420
  })() : commander.program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
412
- command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
421
+ command = command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
413
422
  if (!BUILDER_TYPES.includes(v)) {
414
423
  throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
415
424
  }
@@ -427,7 +436,16 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
427
436
  "-om, --onlyMin",
428
437
  "Only output minify files, but dts files will still be output, it only replaces the js files.",
429
438
  parseBoolean
430
- ).option("--tsconfig <TSCONFIG>", "The path of the tsconfig file which is used to generate js and dts files.", String).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String).option("-w, --watch", "Watch the file changes.", parseBoolean).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async (commandFiltersOrEntries, options) => {
439
+ );
440
+ command = command.option("--tsconfig <TSCONFIG>", "The path of the tsconfig file which is used to generate js and dts files.", String).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String);
441
+ command = command.option("-w, --watch", "Watch the file changes.", parseBoolean);
442
+ command = command.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option("--ana.mode <MODE>", 'The mode of the bundle analyzer, support "static", "json" and "server".', "server").option("--ana.port <PORT>", "The port of the bundle analyzer.", Number.parseInt).option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
443
+ "--ana.size <SIZE>",
444
+ 'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
445
+ "parsed"
446
+ );
447
+ command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
448
+ command.action(async (commandFiltersOrEntries, options) => {
431
449
  let {
432
450
  type,
433
451
  outdir,
@@ -461,7 +479,7 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
461
479
  );
462
480
  }
463
481
  let shouldPassThrough = false;
464
- const passThroughOptions = process.argv.reduce(
482
+ const passThroughOptions = process__default.default.argv.reduce(
465
483
  (acc, value) => {
466
484
  if (shouldPassThrough) {
467
485
  acc.push(value);
@@ -473,6 +491,16 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
473
491
  },
474
492
  []
475
493
  );
494
+ const analyzer = options.ana ? {
495
+ dir: options["ana.dir"],
496
+ mode: options["ana.mode"],
497
+ port: options["ana.port"],
498
+ open: options["ana.open"],
499
+ size: options["ana.size"]
500
+ } : void 0;
501
+ if (analyzer) {
502
+ await checkDependency("vite-bundle-analyzer");
503
+ }
476
504
  const { build } = loadConfig();
477
505
  silent = silent ?? build?.silent ?? false;
478
506
  if (withoutMin && onlyMin) {
@@ -489,7 +517,7 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
489
517
  entries = void 0;
490
518
  }
491
519
  const env = {
492
- ...process.env,
520
+ JIEK_ANALYZER: analyzer && JSON.stringify(analyzer),
493
521
  JIEK_BUILDER: type,
494
522
  JIEK_OUT_DIR: outdir,
495
523
  JIEK_CLEAN: String(!noClean),
@@ -501,7 +529,8 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
501
529
  JIEK_ONLY_MINIFY: String(onlyMin),
502
530
  JIEK_MINIFY_TYPE: minifyType,
503
531
  JIEK_TSCONFIG: tsconfig,
504
- JIEK_DTSCONFIG: dtsconfig
532
+ JIEK_DTSCONFIG: dtsconfig,
533
+ ...process__default.default.env
505
534
  };
506
535
  const multiBars = new cliProgress.MultiBar({
507
536
  clearOnComplete: false,
@@ -527,16 +556,33 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
527
556
  let i = 0;
528
557
  await Promise.all(
529
558
  Object.entries(value).map(async ([dir, manifest]) => {
530
- if (!manifest.name) {
559
+ if (manifest.name == null) {
531
560
  throw new Error("package.json must have a name field");
532
561
  }
562
+ if (analyzer) {
563
+ const anaDir = path__default.default.resolve(dir, analyzer.dir);
564
+ if (!fs.existsSync(anaDir)) {
565
+ fs__default.default.mkdirSync(anaDir, { recursive: true });
566
+ }
567
+ const gitIgnorePath = path__default.default.resolve(anaDir, ".gitignore");
568
+ if (!fs.existsSync(gitIgnorePath)) {
569
+ fs__default.default.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
570
+ }
571
+ const npmIgnorePath = path__default.default.resolve(anaDir, ".npmignore");
572
+ if (!fs.existsSync(npmIgnorePath)) {
573
+ fs__default.default.writeFileSync(npmIgnorePath, "*\n");
574
+ }
575
+ if (!fs.statSync(anaDir).isDirectory()) {
576
+ throw new Error(`The directory '${anaDir}' is not a directory.`);
577
+ }
578
+ }
533
579
  const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
534
580
  const configFile = jiekTempDir(
535
581
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
536
582
  );
537
583
  fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
538
584
  const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
539
- if (tsRegisterName) {
585
+ if (tsRegisterName != null) {
540
586
  command2.unshift(`node -r ${tsRegisterName}`);
541
587
  }
542
588
  if (watch) {
@@ -649,7 +695,7 @@ command.description(description).option("-t, --type <TYPE>", `The type of build,
649
695
  });
650
696
  child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
651
697
  ${errorStr}`)));
652
- verbose && child.stdout?.pipe(process.stdout);
698
+ verbose && child.stdout?.pipe(process__default.default.stdout);
653
699
  });
654
700
  })
655
701
  );
@@ -673,8 +719,29 @@ ${errorStr}`)));
673
719
  }
674
720
  });
675
721
 
676
- if (process.env.JIEK_IS_ONLY_BUILD === "true") {
677
- import('commander').then(({ program }) => {
678
- program.parse(process.argv);
679
- });
722
+ const { argv } = process__default.default;
723
+ const env = {};
724
+ let isPassThrough = false;
725
+ const newArgv = argv.filter((arg) => {
726
+ if (isPassThrough) {
727
+ return true;
728
+ }
729
+ if (arg === "--") {
730
+ isPassThrough = true;
731
+ return false;
732
+ }
733
+ const m = /^--env\.(\w+)=(.*)$/.exec(arg);
734
+ if (m) {
735
+ env[m[1]] = m[2];
736
+ return false;
737
+ }
738
+ return true;
739
+ });
740
+ for (const [key, value] of Object.entries(env)) {
741
+ process__default.default.env[key] = value;
742
+ }
743
+ var parseArgv = () => commander.program.parse(newArgv);
744
+
745
+ if (process__default.default.env.JIEK_IS_ONLY_BUILD === "true") {
746
+ parseArgv();
680
747
  }