jiek 1.1.12 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -1,22 +1,21 @@
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
- var filterWorkspacePackages = require('@pnpm/filter-workspace-packages');
7
5
  var commander = require('commander');
8
- var jsYaml = require('js-yaml');
9
- var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
10
- var cliProgress = require('cli-progress');
11
- var execa = require('execa');
12
6
  var detectIndent = require('detect-indent');
13
7
  var inquirer = require('inquirer');
14
8
  var jsoncParser = require('jsonc-parser');
15
9
  var require$$0 = require('util');
16
10
  var require$$0$1 = require('path');
11
+ var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
12
+ var node_module = require('node:module');
13
+ var filterWorkspacePackages = require('@pnpm/filter-workspace-packages');
14
+ var jsYaml = require('js-yaml');
17
15
  var childProcess = require('node:child_process');
18
16
  var bumper = require('@jiek/utils/bumper');
19
17
  var entrypoints = require('@jiek/pkger/entrypoints');
18
+ require('jiek/cli-only-build');
20
19
 
21
20
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
22
21
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -47,563 +46,6 @@ var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
47
46
  var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
48
47
  var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
49
48
 
50
- let root;
51
- function getRoot() {
52
- if (root)
53
- return root;
54
- const rootOption = commander.program.getOptionValue("root");
55
- root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
56
- return root;
57
- }
58
-
59
- let wd;
60
- let notWorkspace = false;
61
- function getWD() {
62
- if (wd)
63
- return { wd, notWorkspace };
64
- const root = getRoot();
65
- if (root !== void 0) {
66
- const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type$1);
67
- notWorkspace = !isWorkspace;
68
- wd = root;
69
- return { wd, notWorkspace };
70
- }
71
- try {
72
- wd = getWorkspaceDir.getWorkspaceDir(type$1);
73
- } catch (e) {
74
- if ("message" in e && e.message === "workspace root not found") {
75
- wd = root;
76
- notWorkspace = true;
77
- } else {
78
- throw e;
79
- }
80
- }
81
- return { wd, notWorkspace };
82
- }
83
-
84
- let type$1 = "";
85
- try {
86
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
87
- require$1.resolve("@pnpm/filter-workspace-packages");
88
- type$1 = "pnpm";
89
- } catch {
90
- }
91
- if (type$1 !== "") {
92
- commander.program.option("-f, --filter <filter>", "filter packages, support fuzzy match and array. e.g. -f core,utils");
93
- }
94
- function filterPackagesGraph(filters) {
95
- return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
96
- }
97
- async function getSelectedProjectsGraph(filter = commander.program.getOptionValue("filter")) {
98
- let root = getRoot();
99
- const { wd, notWorkspace } = getWD();
100
- if (notWorkspace) {
101
- return {
102
- wd,
103
- root,
104
- value: {
105
- [wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
106
- }
107
- };
108
- }
109
- if (type$1 === "pnpm") {
110
- const pnpmWorkspaceFilePath = path__default.default.resolve(wd, "pnpm-workspace.yaml");
111
- const pnpmWorkspaceFileContent = fs__default.default.readFileSync(pnpmWorkspaceFilePath, "utf-8");
112
- const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
113
- if (root === wd && !filter) {
114
- throw new Error("root path is workspace root, please provide a filter");
115
- }
116
- if (root === void 0) {
117
- root = process.cwd();
118
- }
119
- if (root !== wd && !filter) {
120
- const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
121
- if (!packageJSONIsExist) {
122
- throw new Error("root path is not workspace root, please provide a filter");
123
- }
124
- const packageJSON = JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(root, "package.json"), "utf-8"));
125
- if (!packageJSON.name) {
126
- throw new Error("root path is not workspace root, please provide a filter");
127
- }
128
- filter = packageJSON.name;
129
- }
130
- const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
131
- filter: filter ?? "",
132
- followProdDepsOnly: true
133
- }], {
134
- prefix: root,
135
- workspaceDir: wd,
136
- patterns: pnpmWorkspace.packages
137
- });
138
- return {
139
- wd,
140
- root,
141
- value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
142
- acc[key] = value.package.manifest;
143
- return acc;
144
- }, {})
145
- };
146
- }
147
- throw new Error(`not supported package manager ${type$1}`);
148
- }
149
-
150
- var name = "jiek";
151
- var type = "module";
152
- var version = "1.1.12";
153
- var description$1 = "YiJie's personal kits.";
154
- var bin = {
155
- jiek: "bin/jiek.js",
156
- jk: "bin/jiek.js"
157
- };
158
- var files = [
159
- "dist",
160
- "src",
161
- "bin",
162
- "LICENSE",
163
- "README.md"
164
- ];
165
- var scripts = {
166
- prepublish: "jk build --noMin"
167
- };
168
- var exports$1 = {
169
- "./package.json": "./package.json",
170
- ".": "./src/index.ts",
171
- "./cli": "./src/cli.ts",
172
- "./rollup": "./src/rollup/index.ts"
173
- };
174
- var imports = {
175
- "#~/*": "./src/*"
176
- };
177
- var dependencies = {
178
- "@jiek/pkger": "workspace:^",
179
- "@jiek/rollup-plugin-dts": "^6.1.2",
180
- "@jiek/utils": "workspace:^",
181
- "@rollup/plugin-commonjs": "^28.0.0",
182
- "@rollup/plugin-json": "^6.0.1",
183
- "@rollup/plugin-node-resolve": "^15.3.0",
184
- "@rollup/plugin-terser": "^0.4.4",
185
- autoprefixer: "^10.4.16",
186
- "cli-progress": "^3.12.0",
187
- commander: "^12.0.0",
188
- "detect-indent": "^6.1.0",
189
- execa: "9.3.1",
190
- inquirer: "^8.2.6",
191
- "js-yaml": "^4.1.0",
192
- "jsonc-parser": "^3.2.1",
193
- rollup: "4.13.2",
194
- "rollup-plugin-esbuild": "^6.1.0",
195
- typescript: "^5.0.0"
196
- };
197
- var optionalDependencies = {
198
- "@pnpm/filter-workspace-packages": "^7.2.13",
199
- "esbuild-register": "^3.5.0",
200
- postcss: "^8.4.47",
201
- "rollup-plugin-postcss": "^4.0.2"
202
- };
203
- var devDependencies = {
204
- "@npm/types": "^1.0.2",
205
- "@pnpm/filter-workspace-packages": "^7.2.13",
206
- "@pnpm/workspace.pkgs-graph": "^2.0.15",
207
- "@types/cli-progress": "^3.11.5",
208
- "@types/inquirer": "^9.0.7",
209
- "@types/js-yaml": "^4.0.9",
210
- "@types/micromatch": "^4.0.6",
211
- "esbuild-register": "^3.5.0",
212
- micromatch: "^4.0.5",
213
- "node-sass": "^9.0.0",
214
- postcss: "^8.4.47",
215
- "rollup-plugin-postcss": "^4.0.2"
216
- };
217
- var publishConfig = {
218
- exports: {
219
- "./package.json": "./package.json",
220
- ".": {
221
- source: "./src/index.ts",
222
- require: "./dist/index.cjs",
223
- "default": "./dist/index.js"
224
- },
225
- "./cli": {
226
- source: "./src/cli.ts",
227
- require: "./dist/cli.cjs",
228
- "default": "./dist/cli.js"
229
- },
230
- "./rollup": {
231
- source: "./src/rollup/index.ts",
232
- require: "./dist/rollup/index.cjs",
233
- "default": "./dist/rollup/index.js"
234
- }
235
- },
236
- main: "./dist/index.cjs",
237
- module: "./dist/index.js",
238
- typesVersions: {
239
- "<5.0": {
240
- "*": [
241
- "*",
242
- "./dist/*",
243
- "./dist/*/index.d.ts",
244
- "./dist/*/index.d.mts",
245
- "./dist/*/index.d.cts"
246
- ]
247
- }
248
- }
249
- };
250
- var pkg = {
251
- name: name,
252
- type: type,
253
- version: version,
254
- description: description$1,
255
- bin: bin,
256
- files: files,
257
- scripts: scripts,
258
- exports: exports$1,
259
- imports: imports,
260
- dependencies: dependencies,
261
- optionalDependencies: optionalDependencies,
262
- devDependencies: devDependencies,
263
- publishConfig: publishConfig
264
- };
265
-
266
- commander.program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
267
-
268
- let resolve;
269
- function actionDone() {
270
- resolve();
271
- }
272
- function actionRestore() {
273
- new Promise((r) => resolve = r);
274
- }
275
-
276
- const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
277
- function packageIsExist(name) {
278
- try {
279
- require$3.resolve(name);
280
- return true;
281
- } catch (e) {
282
- return false;
283
- }
284
- }
285
- let tsRegisterName;
286
- const registers = [
287
- process.env.JIEK_TS_REGISTER,
288
- "esbuild-register",
289
- "@swc-node/register",
290
- "ts-node/register"
291
- ].filter(Boolean);
292
- for (const register of registers) {
293
- if (packageIsExist(register)) {
294
- tsRegisterName = register;
295
- break;
296
- }
297
- }
298
-
299
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
300
- let configName = "jiek.config";
301
- function getConfigPath(root, dir) {
302
- const isSupportTsLoader = !!tsRegisterName;
303
- function configWithExtIsExist(ext) {
304
- const filenames = [
305
- path__default.default.resolve(process.cwd(), `${configName}.${ext}`),
306
- path__default.default.resolve(process.cwd(), `.${configName}.${ext}`),
307
- path__default.default.resolve(root, `${configName}.${ext}`),
308
- path__default.default.resolve(root, `.${configName}.${ext}`)
309
- ];
310
- if (dir) {
311
- filenames.unshift(...[
312
- path__default.default.resolve(dir, `${configName}.${ext}`),
313
- path__default.default.resolve(dir, `.${configName}.${ext}`)
314
- ]);
315
- }
316
- for (const filename of filenames) {
317
- if (fs__default.default.existsSync(filename) && fs__default.default.lstatSync(filename).isFile()) {
318
- return filename;
319
- }
320
- }
321
- return;
322
- }
323
- configName = configWithExtIsExist("js") ?? configName;
324
- configName = configWithExtIsExist("json") ?? configName;
325
- configName = configWithExtIsExist("yaml") ?? configName;
326
- if (isSupportTsLoader) {
327
- configName = configWithExtIsExist("ts") ?? configName;
328
- }
329
- return path__default.default.resolve(root, configName);
330
- }
331
- function loadConfig(dirOrOptions) {
332
- let dir;
333
- let root;
334
- if (typeof dirOrOptions === "object") {
335
- dir = dirOrOptions.dir;
336
- root = dirOrOptions.root ?? getWD().wd;
337
- } else {
338
- dir = dirOrOptions;
339
- root = getWD().wd;
340
- }
341
- let configPath = commander.program.getOptionValue("configPath");
342
- if (!configPath) {
343
- configPath = getConfigPath(root, dir);
344
- } else {
345
- if (!fs__default.default.existsSync(configPath)) {
346
- throw new Error(`config file not found: ${configPath}`);
347
- }
348
- if (!path__default.default.isAbsolute(configPath)) {
349
- configPath = path__default.default.resolve(root, configPath);
350
- }
351
- }
352
- const ext = path__default.default.extname(configPath);
353
- let module;
354
- switch (ext) {
355
- case ".js":
356
- module = require$2(configPath);
357
- break;
358
- case ".json":
359
- return require$2(configPath);
360
- case ".yaml":
361
- return jsYaml.load(fs__default.default.readFileSync(configPath, "utf-8"));
362
- case ".ts":
363
- if (tsRegisterName) {
364
- require$2(tsRegisterName);
365
- module = require$2(configPath);
366
- break;
367
- }
368
- throw new Error(
369
- "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
370
- );
371
- case ".config":
372
- module = {};
373
- break;
374
- default:
375
- throw new Error(`unsupported config file type: ${ext}`);
376
- }
377
- if (!module)
378
- throw new Error("config file is empty");
379
- return module.default ?? module;
380
- }
381
-
382
- const outdirDescription = `
383
- The output directory of the build, which relative to the target subpackage root directory.
384
- Support with variables: 'PKG_NAME',
385
- .e.g. 'dist/{{PKG_NAME}}'.
386
- `.trim();
387
-
388
- const FILE_TEMPLATE = (manifest) => `
389
- module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
390
- `.trimStart();
391
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
392
- const description = `
393
- Build the package according to the 'exports' field in the package.json.
394
- If you want to rewrite the rollup command options, you can pass the options after '--'.
395
- e.g. \`jiek build -- --watch\`
396
- `.trim();
397
- function parseBoolean(v) {
398
- if (v === void 0)
399
- return true;
400
- return Boolean(v);
401
- }
402
- commander.program.command("build").description(description).option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
403
- "-om, --onlyMin",
404
- "Only output minify files, but dts files will still be output, it only replaces the js files.",
405
- parseBoolean
406
- ).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async ({
407
- outdir,
408
- silent,
409
- entries,
410
- verbose,
411
- noJs: withoutJs,
412
- noDts: withoutDts,
413
- noMin: withoutMin,
414
- noClean,
415
- onlyMin
416
- }) => {
417
- let shouldPassThrough = false;
418
- const passThroughOptions = commander.program.parseOptions(process.argv).unknown.reduce(
419
- (acc, value) => {
420
- if (shouldPassThrough) {
421
- acc.push(value);
422
- }
423
- if (value === "--") {
424
- shouldPassThrough = true;
425
- }
426
- return acc;
427
- },
428
- []
429
- );
430
- actionRestore();
431
- const { build } = loadConfig();
432
- silent = silent ?? build?.silent ?? false;
433
- if (withoutMin && onlyMin) {
434
- throw new Error("Cannot use both --without-minify and --only-minify");
435
- }
436
- if (onlyMin && withoutJs) {
437
- throw new Error("Cannot use --without-js and --only-minify at the same time");
438
- }
439
- const env = {
440
- ...process.env,
441
- JIEK_OUT_DIR: outdir,
442
- JIEK_CLEAN: String(!noClean),
443
- JIEK_ENTRIES: entries,
444
- JIEK_WITHOUT_JS: String(withoutJs),
445
- JIEK_WITHOUT_DTS: String(withoutDts),
446
- JIEK_WITHOUT_MINIFY: String(withoutMin),
447
- JIEK_ONLY_MINIFY: String(onlyMin)
448
- };
449
- const multiBars = new cliProgress.MultiBar({
450
- clearOnComplete: false,
451
- hideCursor: true,
452
- format: "- {bar} | {status} | {pkgName} | {input} | {message}"
453
- }, cliProgress.Presets.shades_classic);
454
- const buildPackage = async ({
455
- wd,
456
- value = {}
457
- }) => {
458
- if (Object.keys(value).length === 0) {
459
- throw new Error("no package found");
460
- }
461
- const wdNodeModules = path__default.default.resolve(wd, "node_modules");
462
- if (!fs__default.default.existsSync(wdNodeModules)) {
463
- fs__default.default.mkdirSync(wdNodeModules);
464
- }
465
- const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
466
- if (!fs__default.default.existsSync(jiekTempDir())) {
467
- fs__default.default.mkdirSync(jiekTempDir());
468
- }
469
- const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
470
- let i = 0;
471
- await Promise.all(
472
- Object.entries(value).map(async ([dir, manifest]) => {
473
- if (!manifest.name) {
474
- throw new Error("package.json must have a name field");
475
- }
476
- const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
477
- const configFile = jiekTempDir(
478
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
479
- );
480
- fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
481
- let prefix = "";
482
- if (tsRegisterName) {
483
- prefix = `node -r ${tsRegisterName} `;
484
- }
485
- const command = [`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, ...passThroughOptions].join(" ");
486
- const child = execa.execaCommand(command, {
487
- ipc: true,
488
- cwd: dir,
489
- env: {
490
- ...env,
491
- JIEK_NAME: manifest.name,
492
- JIEK_ROOT: wd
493
- }
494
- });
495
- const bars = {};
496
- const times = {};
497
- const locks = {};
498
- let inputMaxLen = 10;
499
- child.on("message", (e) => {
500
- if (e.type === "debug")
501
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
502
- });
503
- !silent && child.on("message", (e) => {
504
- if (e.type === "init") {
505
- const { leafMap, targetsLength } = e.data;
506
- const leafs = Array.from(leafMap.entries()).flatMap(
507
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
508
- input,
509
- path: path2,
510
- conditions
511
- }))
512
- );
513
- console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
514
- leafs.forEach(({ input }) => {
515
- inputMaxLen = Math.max(inputMaxLen, input.length);
516
- });
517
- leafs.forEach(({ input, path: path2 }) => {
518
- const key = `${input}:${path2}`;
519
- if (bars[key])
520
- return;
521
- bars[key] = multiBars.create(50, 0, {
522
- pkgName: manifest.name,
523
- input: input.padEnd(inputMaxLen + 5),
524
- status: "waiting".padEnd(10)
525
- }, {
526
- barsize: 20,
527
- linewrap: true
528
- });
529
- });
530
- }
531
- if (e.type === "progress") {
532
- const {
533
- path: path2,
534
- tags,
535
- input,
536
- event,
537
- message
538
- } = e.data;
539
- const bar = bars[`${input}:${path2}`];
540
- if (!bar)
541
- return;
542
- const time = times[`${input}:${path2}`];
543
- bar.update(
544
- {
545
- start: 0,
546
- resolve: 20,
547
- end: 50
548
- }[event ?? "start"] ?? 0,
549
- {
550
- input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
551
- status: event?.padEnd(10),
552
- message: `${tags?.join(", ")}: ${message}`
553
- }
554
- );
555
- }
556
- if (e.type === "watchChange") {
557
- const {
558
- path: path2,
559
- input
560
- } = e.data;
561
- const key = `${input}:${path2}`;
562
- const bar = bars[key];
563
- if (!bar)
564
- return;
565
- let time = times[key] ?? 1;
566
- if (!locks[key]) {
567
- time += 1;
568
- times[key] = time;
569
- setTimeout(() => {
570
- locks[key] = false;
571
- }, 100);
572
- bar.update(0, {
573
- input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
574
- status: "watching".padEnd(10),
575
- message: "watching..."
576
- });
577
- }
578
- locks[key] = true;
579
- }
580
- });
581
- await new Promise((resolve, reject) => {
582
- let errorStr = "";
583
- child.stderr?.on("data", (data) => {
584
- errorStr += data;
585
- });
586
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
587
- ${errorStr}`)));
588
- verbose && child.stdout?.pipe(process.stdout);
589
- });
590
- })
591
- );
592
- };
593
- const filters = commander.program.getOptionValue("filter")?.split(",");
594
- try {
595
- if (filters) {
596
- const packages = await filterPackagesGraph(filters);
597
- await Promise.all(packages.map(buildPackage));
598
- } else {
599
- await buildPackage(await getSelectedProjectsGraph());
600
- }
601
- } finally {
602
- multiBars.stop();
603
- }
604
- actionDone();
605
- });
606
-
607
49
  var utils$1 = {};
608
50
 
609
51
  var hasRequiredUtils$1;
@@ -4710,6 +4152,206 @@ function requireMicromatch () {
4710
4152
 
4711
4153
  var micromatchExports = requireMicromatch();
4712
4154
 
4155
+ let root;
4156
+ function getRoot() {
4157
+ if (root)
4158
+ return root;
4159
+ const rootOption = commander.program.getOptionValue("root");
4160
+ root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
4161
+ return root;
4162
+ }
4163
+
4164
+ let type = "";
4165
+ try {
4166
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
4167
+ require$1.resolve("@pnpm/filter-workspace-packages");
4168
+ type = "pnpm";
4169
+ } catch {
4170
+ }
4171
+ async function getSelectedProjectsGraph(filter = commander.program.getOptionValue("filter")) {
4172
+ let root = getRoot();
4173
+ const { wd, notWorkspace } = getWD();
4174
+ if (notWorkspace) {
4175
+ return {
4176
+ wd,
4177
+ root,
4178
+ value: {
4179
+ [wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
4180
+ }
4181
+ };
4182
+ }
4183
+ if (type === "pnpm") {
4184
+ const pnpmWorkspaceFilePath = path__default.default.resolve(wd, "pnpm-workspace.yaml");
4185
+ const pnpmWorkspaceFileContent = fs__default.default.readFileSync(pnpmWorkspaceFilePath, "utf-8");
4186
+ const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
4187
+ if (root === wd && !filter) {
4188
+ throw new Error("root path is workspace root, please provide a filter");
4189
+ }
4190
+ if (root === void 0) {
4191
+ root = process.cwd();
4192
+ }
4193
+ if (root !== wd && !filter) {
4194
+ const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
4195
+ if (!packageJSONIsExist) {
4196
+ throw new Error("root path is not workspace root, please provide a filter");
4197
+ }
4198
+ const packageJSON = JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(root, "package.json"), "utf-8"));
4199
+ if (!packageJSON.name) {
4200
+ throw new Error("root path is not workspace root, please provide a filter");
4201
+ }
4202
+ filter = packageJSON.name;
4203
+ }
4204
+ const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
4205
+ filter: filter ?? "",
4206
+ followProdDepsOnly: true
4207
+ }], {
4208
+ prefix: root,
4209
+ workspaceDir: wd,
4210
+ patterns: pnpmWorkspace.packages
4211
+ });
4212
+ return {
4213
+ wd,
4214
+ root,
4215
+ value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
4216
+ acc[key] = value.package.manifest;
4217
+ return acc;
4218
+ }, {})
4219
+ };
4220
+ }
4221
+ throw new Error(`not supported package manager ${type}`);
4222
+ }
4223
+
4224
+ let wd;
4225
+ let notWorkspace = false;
4226
+ function getWD() {
4227
+ if (wd)
4228
+ return { wd, notWorkspace };
4229
+ const root = getRoot();
4230
+ if (root !== void 0) {
4231
+ const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type);
4232
+ notWorkspace = !isWorkspace;
4233
+ wd = root;
4234
+ return { wd, notWorkspace };
4235
+ }
4236
+ try {
4237
+ wd = getWorkspaceDir.getWorkspaceDir(type);
4238
+ } catch (e) {
4239
+ if ("message" in e && e.message === "workspace root not found") {
4240
+ wd = root;
4241
+ notWorkspace = true;
4242
+ } else {
4243
+ throw e;
4244
+ }
4245
+ }
4246
+ return { wd, notWorkspace };
4247
+ }
4248
+
4249
+ const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
4250
+ function packageIsExist(name) {
4251
+ try {
4252
+ require$2.resolve(name);
4253
+ return true;
4254
+ } catch (e) {
4255
+ return false;
4256
+ }
4257
+ }
4258
+ let tsRegisterName;
4259
+ const registers = [
4260
+ process.env.JIEK_TS_REGISTER,
4261
+ "esbuild-register",
4262
+ "@swc-node/register",
4263
+ "ts-node/register"
4264
+ ].filter(Boolean);
4265
+ for (const register of registers) {
4266
+ if (packageIsExist(register)) {
4267
+ tsRegisterName = register;
4268
+ break;
4269
+ }
4270
+ }
4271
+
4272
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
4273
+ let configName = "jiek.config";
4274
+ function getConfigPath(root, dir) {
4275
+ const isSupportTsLoader = !!tsRegisterName;
4276
+ function configWithExtIsExist(ext) {
4277
+ const filenames = [
4278
+ path__default.default.resolve(process.cwd(), `${configName}.${ext}`),
4279
+ path__default.default.resolve(process.cwd(), `.${configName}.${ext}`),
4280
+ path__default.default.resolve(root, `${configName}.${ext}`),
4281
+ path__default.default.resolve(root, `.${configName}.${ext}`)
4282
+ ];
4283
+ if (dir) {
4284
+ filenames.unshift(...[
4285
+ path__default.default.resolve(dir, `${configName}.${ext}`),
4286
+ path__default.default.resolve(dir, `.${configName}.${ext}`)
4287
+ ]);
4288
+ }
4289
+ for (const filename of filenames) {
4290
+ if (fs__default.default.existsSync(filename) && fs__default.default.lstatSync(filename).isFile()) {
4291
+ return filename;
4292
+ }
4293
+ }
4294
+ return;
4295
+ }
4296
+ configName = configWithExtIsExist("js") ?? configName;
4297
+ configName = configWithExtIsExist("json") ?? configName;
4298
+ configName = configWithExtIsExist("yaml") ?? configName;
4299
+ if (isSupportTsLoader) {
4300
+ configName = configWithExtIsExist("ts") ?? configName;
4301
+ }
4302
+ return path__default.default.resolve(root, configName);
4303
+ }
4304
+ function loadConfig(dirOrOptions) {
4305
+ let dir;
4306
+ let root;
4307
+ if (typeof dirOrOptions === "object") {
4308
+ dir = dirOrOptions.dir;
4309
+ root = dirOrOptions.root ?? getWD().wd;
4310
+ } else {
4311
+ dir = dirOrOptions;
4312
+ root = getWD().wd;
4313
+ }
4314
+ let configPath = commander.program.getOptionValue("configPath");
4315
+ if (!configPath) {
4316
+ configPath = getConfigPath(root, dir);
4317
+ } else {
4318
+ if (!fs__default.default.existsSync(configPath)) {
4319
+ throw new Error(`config file not found: ${configPath}`);
4320
+ }
4321
+ if (!path__default.default.isAbsolute(configPath)) {
4322
+ configPath = path__default.default.resolve(root, configPath);
4323
+ }
4324
+ }
4325
+ const ext = path__default.default.extname(configPath);
4326
+ let module;
4327
+ switch (ext) {
4328
+ case ".js":
4329
+ module = require$1(configPath);
4330
+ break;
4331
+ case ".json":
4332
+ return require$1(configPath);
4333
+ case ".yaml":
4334
+ return jsYaml.load(fs__default.default.readFileSync(configPath, "utf-8"));
4335
+ case ".ts":
4336
+ if (tsRegisterName) {
4337
+ require$1(tsRegisterName);
4338
+ module = require$1(configPath);
4339
+ break;
4340
+ }
4341
+ throw new Error(
4342
+ "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
4343
+ );
4344
+ case ".config":
4345
+ module = {};
4346
+ break;
4347
+ default:
4348
+ throw new Error(`unsupported config file type: ${ext}`);
4349
+ }
4350
+ if (!module)
4351
+ throw new Error("config file is empty");
4352
+ return module.default ?? module;
4353
+ }
4354
+
4713
4355
  const PACKAGE_JSON_TEMPLATE = `{
4714
4356
  "name": "",
4715
4357
  "version": "0.0.1",
@@ -4986,6 +4628,14 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
4986
4628
  fs__default.default.writeFileSync(readmeFilePath, readmeContent);
4987
4629
  });
4988
4630
 
4631
+ let resolve;
4632
+ function actionDone() {
4633
+ resolve();
4634
+ }
4635
+ function actionRestore() {
4636
+ new Promise((r) => resolve = r);
4637
+ }
4638
+
4989
4639
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4990
4640
  const {
4991
4641
  JIEK_OUT_DIR
@@ -5076,6 +4726,12 @@ function getExports({
5076
4726
  ];
5077
4727
  }
5078
4728
 
4729
+ const outdirDescription = `
4730
+ The output directory of the build, which relative to the target subpackage root directory.
4731
+ Support with variables: 'PKG_NAME',
4732
+ .e.g. 'dist/{{PKG_NAME}}'.
4733
+ `.trim();
4734
+
5079
4735
  commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-s, --silent", "no output").option("-p, --preview", "preview publish").action(async ({ outdir, preview, silent, bumper: bumper$1, ...options }) => {
5080
4736
  actionRestore();
5081
4737
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
@@ -5230,5 +4886,3 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
5230
4886
  }
5231
4887
  actionDone();
5232
4888
  });
5233
-
5234
- commander.program.parse(process.argv);