jiek 1.1.13 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,558 +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.13";
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.2.1",
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
- 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)));
269
- function packageIsExist(name) {
270
- try {
271
- require$3.resolve(name);
272
- return true;
273
- } catch (e) {
274
- return false;
275
- }
276
- }
277
- let tsRegisterName;
278
- const registers = [
279
- process.env.JIEK_TS_REGISTER,
280
- "esbuild-register",
281
- "@swc-node/register",
282
- "ts-node/register"
283
- ].filter(Boolean);
284
- for (const register of registers) {
285
- if (packageIsExist(register)) {
286
- tsRegisterName = register;
287
- break;
288
- }
289
- }
290
-
291
- 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)));
292
- let configName = "jiek.config";
293
- function getConfigPath(root, dir) {
294
- const isSupportTsLoader = !!tsRegisterName;
295
- function configWithExtIsExist(ext) {
296
- const filenames = [
297
- path__default.default.resolve(process.cwd(), `${configName}.${ext}`),
298
- path__default.default.resolve(process.cwd(), `.${configName}.${ext}`),
299
- path__default.default.resolve(root, `${configName}.${ext}`),
300
- path__default.default.resolve(root, `.${configName}.${ext}`)
301
- ];
302
- if (dir) {
303
- filenames.unshift(...[
304
- path__default.default.resolve(dir, `${configName}.${ext}`),
305
- path__default.default.resolve(dir, `.${configName}.${ext}`)
306
- ]);
307
- }
308
- for (const filename of filenames) {
309
- if (fs__default.default.existsSync(filename) && fs__default.default.lstatSync(filename).isFile()) {
310
- return filename;
311
- }
312
- }
313
- return;
314
- }
315
- configName = configWithExtIsExist("js") ?? configName;
316
- configName = configWithExtIsExist("json") ?? configName;
317
- configName = configWithExtIsExist("yaml") ?? configName;
318
- if (isSupportTsLoader) {
319
- configName = configWithExtIsExist("ts") ?? configName;
320
- }
321
- return path__default.default.resolve(root, configName);
322
- }
323
- function loadConfig(dirOrOptions) {
324
- let dir;
325
- let root;
326
- if (typeof dirOrOptions === "object") {
327
- dir = dirOrOptions.dir;
328
- root = dirOrOptions.root ?? getWD().wd;
329
- } else {
330
- dir = dirOrOptions;
331
- root = getWD().wd;
332
- }
333
- let configPath = commander.program.getOptionValue("configPath");
334
- if (!configPath) {
335
- configPath = getConfigPath(root, dir);
336
- } else {
337
- if (!fs__default.default.existsSync(configPath)) {
338
- throw new Error(`config file not found: ${configPath}`);
339
- }
340
- if (!path__default.default.isAbsolute(configPath)) {
341
- configPath = path__default.default.resolve(root, configPath);
342
- }
343
- }
344
- const ext = path__default.default.extname(configPath);
345
- let module;
346
- switch (ext) {
347
- case ".js":
348
- module = require$2(configPath);
349
- break;
350
- case ".json":
351
- return require$2(configPath);
352
- case ".yaml":
353
- return jsYaml.load(fs__default.default.readFileSync(configPath, "utf-8"));
354
- case ".ts":
355
- if (tsRegisterName) {
356
- require$2(tsRegisterName);
357
- module = require$2(configPath);
358
- break;
359
- }
360
- throw new Error(
361
- "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
362
- );
363
- case ".config":
364
- module = {};
365
- break;
366
- default:
367
- throw new Error(`unsupported config file type: ${ext}`);
368
- }
369
- if (!module)
370
- throw new Error("config file is empty");
371
- return module.default ?? module;
372
- }
373
-
374
- const outdirDescription = `
375
- The output directory of the build, which relative to the target subpackage root directory.
376
- Support with variables: 'PKG_NAME',
377
- .e.g. 'dist/{{PKG_NAME}}'.
378
- `.trim();
379
-
380
- const FILE_TEMPLATE = (manifest) => `
381
- module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
382
- `.trimStart();
383
- 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)));
384
- const description = `
385
- Build the package according to the 'exports' field in the package.json.
386
- If you want to rewrite the rollup command options, you can pass the options after '--'.
387
- e.g. \`jiek build -- --watch\`
388
- `.trim();
389
- function parseBoolean(v) {
390
- if (v === void 0)
391
- return true;
392
- return Boolean(v);
393
- }
394
- commander.program.command("build").description(description).option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option(
395
- "-e, --entries <ENTRIES>",
396
- "Specify the build entry-points of the package.json's 'exports' field.(support glob)"
397
- ).option("--external <EXTERNAL>", "Specify the external dependencies of the package.", String).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(
398
- "-om, --onlyMin",
399
- "Only output minify files, but dts files will still be output, it only replaces the js files.",
400
- parseBoolean
401
- ).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async ({
402
- outdir,
403
- silent,
404
- entries,
405
- external,
406
- verbose,
407
- noJs: withoutJs,
408
- noDts: withoutDts,
409
- noMin: withoutMin,
410
- noClean,
411
- onlyMin
412
- }) => {
413
- let shouldPassThrough = false;
414
- const passThroughOptions = commander.program.parseOptions(process.argv).unknown.reduce(
415
- (acc, value) => {
416
- if (shouldPassThrough) {
417
- acc.push(value);
418
- }
419
- if (value === "--") {
420
- shouldPassThrough = true;
421
- }
422
- return acc;
423
- },
424
- []
425
- );
426
- const { build } = loadConfig();
427
- silent = silent ?? build?.silent ?? false;
428
- if (withoutMin && onlyMin) {
429
- throw new Error("Cannot use both --without-minify and --only-minify");
430
- }
431
- if (onlyMin && withoutJs) {
432
- throw new Error("Cannot use --without-js and --only-minify at the same time");
433
- }
434
- const env = {
435
- ...process.env,
436
- JIEK_OUT_DIR: outdir,
437
- JIEK_CLEAN: String(!noClean),
438
- JIEK_ENTRIES: entries,
439
- JIEK_EXTERNAL: external,
440
- JIEK_WITHOUT_JS: String(withoutJs),
441
- JIEK_WITHOUT_DTS: String(withoutDts),
442
- JIEK_WITHOUT_MINIFY: String(withoutMin),
443
- JIEK_ONLY_MINIFY: String(onlyMin)
444
- };
445
- const multiBars = new cliProgress.MultiBar({
446
- clearOnComplete: false,
447
- hideCursor: true,
448
- format: "- {bar} | {status} | {pkgName} | {input} | {message}"
449
- }, cliProgress.Presets.shades_classic);
450
- const buildPackage = async ({
451
- wd,
452
- value = {}
453
- }) => {
454
- if (Object.keys(value).length === 0) {
455
- throw new Error("no package found");
456
- }
457
- const wdNodeModules = path__default.default.resolve(wd, "node_modules");
458
- if (!fs__default.default.existsSync(wdNodeModules)) {
459
- fs__default.default.mkdirSync(wdNodeModules);
460
- }
461
- const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
462
- if (!fs__default.default.existsSync(jiekTempDir())) {
463
- fs__default.default.mkdirSync(jiekTempDir());
464
- }
465
- const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
466
- let i = 0;
467
- await Promise.all(
468
- Object.entries(value).map(async ([dir, manifest]) => {
469
- if (!manifest.name) {
470
- throw new Error("package.json must have a name field");
471
- }
472
- const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
473
- const configFile = jiekTempDir(
474
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
475
- );
476
- fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
477
- let prefix = "";
478
- if (tsRegisterName) {
479
- prefix = `node -r ${tsRegisterName} `;
480
- }
481
- const command = [`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, ...passThroughOptions].join(" ");
482
- const child = execa.execaCommand(command, {
483
- ipc: true,
484
- cwd: dir,
485
- env: {
486
- ...env,
487
- JIEK_NAME: manifest.name,
488
- JIEK_ROOT: wd
489
- }
490
- });
491
- const bars = {};
492
- const times = {};
493
- const locks = {};
494
- let inputMaxLen = 10;
495
- child.on("message", (e) => {
496
- if (e.type === "debug")
497
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
498
- });
499
- !silent && child.on("message", (e) => {
500
- if (e.type === "init") {
501
- const { leafMap, targetsLength } = e.data;
502
- const leafs = Array.from(leafMap.entries()).flatMap(
503
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
504
- input,
505
- path: path2,
506
- conditions
507
- }))
508
- );
509
- console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
510
- leafs.forEach(({ input }) => {
511
- inputMaxLen = Math.max(inputMaxLen, input.length);
512
- });
513
- leafs.forEach(({ input, path: path2 }) => {
514
- const key = `${input}:${path2}`;
515
- if (bars[key])
516
- return;
517
- bars[key] = multiBars.create(50, 0, {
518
- pkgName: manifest.name,
519
- input: input.padEnd(inputMaxLen + 5),
520
- status: "waiting".padEnd(10)
521
- }, {
522
- barsize: 20,
523
- linewrap: true
524
- });
525
- });
526
- }
527
- if (e.type === "progress") {
528
- const {
529
- path: path2,
530
- tags,
531
- input,
532
- event,
533
- message
534
- } = e.data;
535
- const bar = bars[`${input}:${path2}`];
536
- if (!bar)
537
- return;
538
- const time = times[`${input}:${path2}`];
539
- bar.update(
540
- {
541
- start: 0,
542
- resolve: 20,
543
- end: 50
544
- }[event ?? "start"] ?? 0,
545
- {
546
- input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
547
- status: event?.padEnd(10),
548
- message: `${tags?.join(", ")}: ${message}`
549
- }
550
- );
551
- }
552
- if (e.type === "watchChange") {
553
- const {
554
- path: path2,
555
- input
556
- } = e.data;
557
- const key = `${input}:${path2}`;
558
- const bar = bars[key];
559
- if (!bar)
560
- return;
561
- let time = times[key] ?? 1;
562
- if (!locks[key]) {
563
- time += 1;
564
- times[key] = time;
565
- setTimeout(() => {
566
- locks[key] = false;
567
- }, 100);
568
- bar.update(0, {
569
- input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
570
- status: "watching".padEnd(10),
571
- message: "watching..."
572
- });
573
- }
574
- locks[key] = true;
575
- }
576
- });
577
- await new Promise((resolve, reject) => {
578
- let errorStr = "";
579
- child.stderr?.on("data", (data) => {
580
- errorStr += data;
581
- });
582
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
583
- ${errorStr}`)));
584
- verbose && child.stdout?.pipe(process.stdout);
585
- });
586
- })
587
- );
588
- };
589
- const filters = commander.program.getOptionValue("filter")?.split(",");
590
- try {
591
- if (filters) {
592
- const packages = await filterPackagesGraph(filters);
593
- await Promise.all(packages.map(buildPackage));
594
- } else {
595
- await buildPackage(await getSelectedProjectsGraph());
596
- }
597
- } finally {
598
- multiBars.stop();
599
- }
600
- });
601
-
602
49
  var utils$1 = {};
603
50
 
604
51
  var hasRequiredUtils$1;
@@ -4705,6 +4152,206 @@ function requireMicromatch () {
4705
4152
 
4706
4153
  var micromatchExports = requireMicromatch();
4707
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
+
4708
4355
  const PACKAGE_JSON_TEMPLATE = `{
4709
4356
  "name": "",
4710
4357
  "version": "0.0.1",
@@ -5079,6 +4726,12 @@ function getExports({
5079
4726
  ];
5080
4727
  }
5081
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
+
5082
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 }) => {
5083
4736
  actionRestore();
5084
4737
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
@@ -5233,5 +4886,3 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
5233
4886
  }
5234
4887
  actionDone();
5235
4888
  });
5236
-
5237
- commander.program.parse(process.argv);