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.js CHANGED
@@ -1,577 +1,19 @@
1
1
  import fs from 'node:fs';
2
- import { createRequire } from 'node:module';
3
2
  import path, { isAbsolute, relative, resolve as resolve$1 } from 'node:path';
4
- import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages';
5
3
  import { program } from 'commander';
6
- import { load } from 'js-yaml';
7
- import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
8
- import { MultiBar, Presets } from 'cli-progress';
9
- import { execaCommand } from 'execa';
10
4
  import detectIndent from 'detect-indent';
11
5
  import inquirer from 'inquirer';
12
6
  import { applyEdits, modify } from 'jsonc-parser';
13
7
  import require$$0 from 'util';
14
8
  import require$$0$1 from 'path';
9
+ import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
10
+ import { createRequire } from 'node:module';
11
+ import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages';
12
+ import { load } from 'js-yaml';
15
13
  import * as childProcess from 'node:child_process';
16
14
  import { bump, TAGS } from '@jiek/utils/bumper';
17
15
  import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Exports } from '@jiek/pkger/entrypoints';
18
-
19
- let root;
20
- function getRoot() {
21
- if (root)
22
- return root;
23
- const rootOption = program.getOptionValue("root");
24
- root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
25
- return root;
26
- }
27
-
28
- let wd;
29
- let notWorkspace = false;
30
- function getWD() {
31
- if (wd)
32
- return { wd, notWorkspace };
33
- const root = getRoot();
34
- if (root !== void 0) {
35
- const isWorkspace = isWorkspaceDir(root, type$1);
36
- notWorkspace = !isWorkspace;
37
- wd = root;
38
- return { wd, notWorkspace };
39
- }
40
- try {
41
- wd = getWorkspaceDir(type$1);
42
- } catch (e) {
43
- if ("message" in e && e.message === "workspace root not found") {
44
- wd = root;
45
- notWorkspace = true;
46
- } else {
47
- throw e;
48
- }
49
- }
50
- return { wd, notWorkspace };
51
- }
52
-
53
- let type$1 = "";
54
- try {
55
- const require = createRequire(import.meta.url);
56
- require.resolve("@pnpm/filter-workspace-packages");
57
- type$1 = "pnpm";
58
- } catch {
59
- }
60
- if (type$1 !== "") {
61
- program.option("-f, --filter <filter>", "filter packages, support fuzzy match and array. e.g. -f core,utils");
62
- }
63
- function filterPackagesGraph(filters) {
64
- return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
65
- }
66
- async function getSelectedProjectsGraph(filter = program.getOptionValue("filter")) {
67
- let root = getRoot();
68
- const { wd, notWorkspace } = getWD();
69
- if (notWorkspace) {
70
- return {
71
- wd,
72
- root,
73
- value: {
74
- [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
75
- }
76
- };
77
- }
78
- if (type$1 === "pnpm") {
79
- const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
80
- const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
81
- const pnpmWorkspace = load(pnpmWorkspaceFileContent);
82
- if (root === wd && !filter) {
83
- throw new Error("root path is workspace root, please provide a filter");
84
- }
85
- if (root === void 0) {
86
- root = process.cwd();
87
- }
88
- if (root !== wd && !filter) {
89
- const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
90
- if (!packageJSONIsExist) {
91
- throw new Error("root path is not workspace root, please provide a filter");
92
- }
93
- const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
94
- if (!packageJSON.name) {
95
- throw new Error("root path is not workspace root, please provide a filter");
96
- }
97
- filter = packageJSON.name;
98
- }
99
- const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
100
- filter: filter ?? "",
101
- followProdDepsOnly: true
102
- }], {
103
- prefix: root,
104
- workspaceDir: wd,
105
- patterns: pnpmWorkspace.packages
106
- });
107
- return {
108
- wd,
109
- root,
110
- value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
111
- acc[key] = value.package.manifest;
112
- return acc;
113
- }, {})
114
- };
115
- }
116
- throw new Error(`not supported package manager ${type$1}`);
117
- }
118
-
119
- var name = "jiek";
120
- var type = "module";
121
- var version = "1.1.12";
122
- var description$1 = "YiJie's personal kits.";
123
- var bin = {
124
- jiek: "bin/jiek.js",
125
- jk: "bin/jiek.js"
126
- };
127
- var files = [
128
- "dist",
129
- "src",
130
- "bin",
131
- "LICENSE",
132
- "README.md"
133
- ];
134
- var scripts = {
135
- prepublish: "jk build --noMin"
136
- };
137
- var exports = {
138
- "./package.json": "./package.json",
139
- ".": "./src/index.ts",
140
- "./cli": "./src/cli.ts",
141
- "./rollup": "./src/rollup/index.ts"
142
- };
143
- var imports = {
144
- "#~/*": "./src/*"
145
- };
146
- var dependencies = {
147
- "@jiek/pkger": "workspace:^",
148
- "@jiek/rollup-plugin-dts": "^6.1.2",
149
- "@jiek/utils": "workspace:^",
150
- "@rollup/plugin-commonjs": "^28.0.0",
151
- "@rollup/plugin-json": "^6.0.1",
152
- "@rollup/plugin-node-resolve": "^15.3.0",
153
- "@rollup/plugin-terser": "^0.4.4",
154
- autoprefixer: "^10.4.16",
155
- "cli-progress": "^3.12.0",
156
- commander: "^12.0.0",
157
- "detect-indent": "^6.1.0",
158
- execa: "9.3.1",
159
- inquirer: "^8.2.6",
160
- "js-yaml": "^4.1.0",
161
- "jsonc-parser": "^3.2.1",
162
- rollup: "4.13.2",
163
- "rollup-plugin-esbuild": "^6.1.0",
164
- typescript: "^5.0.0"
165
- };
166
- var optionalDependencies = {
167
- "@pnpm/filter-workspace-packages": "^7.2.13",
168
- "esbuild-register": "^3.5.0",
169
- postcss: "^8.4.47",
170
- "rollup-plugin-postcss": "^4.0.2"
171
- };
172
- var devDependencies = {
173
- "@npm/types": "^1.0.2",
174
- "@pnpm/filter-workspace-packages": "^7.2.13",
175
- "@pnpm/workspace.pkgs-graph": "^2.0.15",
176
- "@types/cli-progress": "^3.11.5",
177
- "@types/inquirer": "^9.0.7",
178
- "@types/js-yaml": "^4.0.9",
179
- "@types/micromatch": "^4.0.6",
180
- "esbuild-register": "^3.5.0",
181
- micromatch: "^4.0.5",
182
- "node-sass": "^9.0.0",
183
- postcss: "^8.4.47",
184
- "rollup-plugin-postcss": "^4.0.2"
185
- };
186
- var publishConfig = {
187
- exports: {
188
- "./package.json": "./package.json",
189
- ".": {
190
- source: "./src/index.ts",
191
- require: "./dist/index.cjs",
192
- "default": "./dist/index.js"
193
- },
194
- "./cli": {
195
- source: "./src/cli.ts",
196
- require: "./dist/cli.cjs",
197
- "default": "./dist/cli.js"
198
- },
199
- "./rollup": {
200
- source: "./src/rollup/index.ts",
201
- require: "./dist/rollup/index.cjs",
202
- "default": "./dist/rollup/index.js"
203
- }
204
- },
205
- main: "./dist/index.cjs",
206
- module: "./dist/index.js",
207
- typesVersions: {
208
- "<5.0": {
209
- "*": [
210
- "*",
211
- "./dist/*",
212
- "./dist/*/index.d.ts",
213
- "./dist/*/index.d.mts",
214
- "./dist/*/index.d.cts"
215
- ]
216
- }
217
- }
218
- };
219
- var pkg = {
220
- name: name,
221
- type: type,
222
- version: version,
223
- description: description$1,
224
- bin: bin,
225
- files: files,
226
- scripts: scripts,
227
- exports: exports,
228
- imports: imports,
229
- dependencies: dependencies,
230
- optionalDependencies: optionalDependencies,
231
- devDependencies: devDependencies,
232
- publishConfig: publishConfig
233
- };
234
-
235
- program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
236
-
237
- let resolve;
238
- function actionDone() {
239
- resolve();
240
- }
241
- function actionRestore() {
242
- new Promise((r) => resolve = r);
243
- }
244
-
245
- const require$2 = createRequire(import.meta.url);
246
- function packageIsExist(name) {
247
- try {
248
- require$2.resolve(name);
249
- return true;
250
- } catch (e) {
251
- return false;
252
- }
253
- }
254
- let tsRegisterName;
255
- const registers = [
256
- process.env.JIEK_TS_REGISTER,
257
- "esbuild-register",
258
- "@swc-node/register",
259
- "ts-node/register"
260
- ].filter(Boolean);
261
- for (const register of registers) {
262
- if (packageIsExist(register)) {
263
- tsRegisterName = register;
264
- break;
265
- }
266
- }
267
-
268
- const require$1 = createRequire(import.meta.url);
269
- let configName = "jiek.config";
270
- function getConfigPath(root, dir) {
271
- const isSupportTsLoader = !!tsRegisterName;
272
- function configWithExtIsExist(ext) {
273
- const filenames = [
274
- path.resolve(process.cwd(), `${configName}.${ext}`),
275
- path.resolve(process.cwd(), `.${configName}.${ext}`),
276
- path.resolve(root, `${configName}.${ext}`),
277
- path.resolve(root, `.${configName}.${ext}`)
278
- ];
279
- if (dir) {
280
- filenames.unshift(...[
281
- path.resolve(dir, `${configName}.${ext}`),
282
- path.resolve(dir, `.${configName}.${ext}`)
283
- ]);
284
- }
285
- for (const filename of filenames) {
286
- if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
287
- return filename;
288
- }
289
- }
290
- return;
291
- }
292
- configName = configWithExtIsExist("js") ?? configName;
293
- configName = configWithExtIsExist("json") ?? configName;
294
- configName = configWithExtIsExist("yaml") ?? configName;
295
- if (isSupportTsLoader) {
296
- configName = configWithExtIsExist("ts") ?? configName;
297
- }
298
- return path.resolve(root, configName);
299
- }
300
- function loadConfig(dirOrOptions) {
301
- let dir;
302
- let root;
303
- if (typeof dirOrOptions === "object") {
304
- dir = dirOrOptions.dir;
305
- root = dirOrOptions.root ?? getWD().wd;
306
- } else {
307
- dir = dirOrOptions;
308
- root = getWD().wd;
309
- }
310
- let configPath = program.getOptionValue("configPath");
311
- if (!configPath) {
312
- configPath = getConfigPath(root, dir);
313
- } else {
314
- if (!fs.existsSync(configPath)) {
315
- throw new Error(`config file not found: ${configPath}`);
316
- }
317
- if (!path.isAbsolute(configPath)) {
318
- configPath = path.resolve(root, configPath);
319
- }
320
- }
321
- const ext = path.extname(configPath);
322
- let module;
323
- switch (ext) {
324
- case ".js":
325
- module = require$1(configPath);
326
- break;
327
- case ".json":
328
- return require$1(configPath);
329
- case ".yaml":
330
- return load(fs.readFileSync(configPath, "utf-8"));
331
- case ".ts":
332
- if (tsRegisterName) {
333
- require$1(tsRegisterName);
334
- module = require$1(configPath);
335
- break;
336
- }
337
- throw new Error(
338
- "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
339
- );
340
- case ".config":
341
- module = {};
342
- break;
343
- default:
344
- throw new Error(`unsupported config file type: ${ext}`);
345
- }
346
- if (!module)
347
- throw new Error("config file is empty");
348
- return module.default ?? module;
349
- }
350
-
351
- const outdirDescription = `
352
- The output directory of the build, which relative to the target subpackage root directory.
353
- Support with variables: 'PKG_NAME',
354
- .e.g. 'dist/{{PKG_NAME}}'.
355
- `.trim();
356
-
357
- const FILE_TEMPLATE = (manifest) => `
358
- module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
359
- `.trimStart();
360
- const require = createRequire(import.meta.url);
361
- const description = `
362
- Build the package according to the 'exports' field in the package.json.
363
- If you want to rewrite the rollup command options, you can pass the options after '--'.
364
- e.g. \`jiek build -- --watch\`
365
- `.trim();
366
- function parseBoolean(v) {
367
- if (v === void 0)
368
- return true;
369
- return Boolean(v);
370
- }
371
- 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(
372
- "-om, --onlyMin",
373
- "Only output minify files, but dts files will still be output, it only replaces the js files.",
374
- parseBoolean
375
- ).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async ({
376
- outdir,
377
- silent,
378
- entries,
379
- verbose,
380
- noJs: withoutJs,
381
- noDts: withoutDts,
382
- noMin: withoutMin,
383
- noClean,
384
- onlyMin
385
- }) => {
386
- let shouldPassThrough = false;
387
- const passThroughOptions = program.parseOptions(process.argv).unknown.reduce(
388
- (acc, value) => {
389
- if (shouldPassThrough) {
390
- acc.push(value);
391
- }
392
- if (value === "--") {
393
- shouldPassThrough = true;
394
- }
395
- return acc;
396
- },
397
- []
398
- );
399
- actionRestore();
400
- const { build } = loadConfig();
401
- silent = silent ?? build?.silent ?? false;
402
- if (withoutMin && onlyMin) {
403
- throw new Error("Cannot use both --without-minify and --only-minify");
404
- }
405
- if (onlyMin && withoutJs) {
406
- throw new Error("Cannot use --without-js and --only-minify at the same time");
407
- }
408
- const env = {
409
- ...process.env,
410
- JIEK_OUT_DIR: outdir,
411
- JIEK_CLEAN: String(!noClean),
412
- JIEK_ENTRIES: entries,
413
- JIEK_WITHOUT_JS: String(withoutJs),
414
- JIEK_WITHOUT_DTS: String(withoutDts),
415
- JIEK_WITHOUT_MINIFY: String(withoutMin),
416
- JIEK_ONLY_MINIFY: String(onlyMin)
417
- };
418
- const multiBars = new MultiBar({
419
- clearOnComplete: false,
420
- hideCursor: true,
421
- format: "- {bar} | {status} | {pkgName} | {input} | {message}"
422
- }, Presets.shades_classic);
423
- const buildPackage = async ({
424
- wd,
425
- value = {}
426
- }) => {
427
- if (Object.keys(value).length === 0) {
428
- throw new Error("no package found");
429
- }
430
- const wdNodeModules = path.resolve(wd, "node_modules");
431
- if (!fs.existsSync(wdNodeModules)) {
432
- fs.mkdirSync(wdNodeModules);
433
- }
434
- const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
435
- if (!fs.existsSync(jiekTempDir())) {
436
- fs.mkdirSync(jiekTempDir());
437
- }
438
- const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
439
- let i = 0;
440
- await Promise.all(
441
- Object.entries(value).map(async ([dir, manifest]) => {
442
- if (!manifest.name) {
443
- throw new Error("package.json must have a name field");
444
- }
445
- const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
446
- const configFile = jiekTempDir(
447
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
448
- );
449
- fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
450
- let prefix = "";
451
- if (tsRegisterName) {
452
- prefix = `node -r ${tsRegisterName} `;
453
- }
454
- const command = [`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, ...passThroughOptions].join(" ");
455
- const child = execaCommand(command, {
456
- ipc: true,
457
- cwd: dir,
458
- env: {
459
- ...env,
460
- JIEK_NAME: manifest.name,
461
- JIEK_ROOT: wd
462
- }
463
- });
464
- const bars = {};
465
- const times = {};
466
- const locks = {};
467
- let inputMaxLen = 10;
468
- child.on("message", (e) => {
469
- if (e.type === "debug")
470
- console.log(...Array.isArray(e.data) ? e.data : [e.data]);
471
- });
472
- !silent && child.on("message", (e) => {
473
- if (e.type === "init") {
474
- const { leafMap, targetsLength } = e.data;
475
- const leafs = Array.from(leafMap.entries()).flatMap(
476
- ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
477
- input,
478
- path: path2,
479
- conditions
480
- }))
481
- );
482
- console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
483
- leafs.forEach(({ input }) => {
484
- inputMaxLen = Math.max(inputMaxLen, input.length);
485
- });
486
- leafs.forEach(({ input, path: path2 }) => {
487
- const key = `${input}:${path2}`;
488
- if (bars[key])
489
- return;
490
- bars[key] = multiBars.create(50, 0, {
491
- pkgName: manifest.name,
492
- input: input.padEnd(inputMaxLen + 5),
493
- status: "waiting".padEnd(10)
494
- }, {
495
- barsize: 20,
496
- linewrap: true
497
- });
498
- });
499
- }
500
- if (e.type === "progress") {
501
- const {
502
- path: path2,
503
- tags,
504
- input,
505
- event,
506
- message
507
- } = e.data;
508
- const bar = bars[`${input}:${path2}`];
509
- if (!bar)
510
- return;
511
- const time = times[`${input}:${path2}`];
512
- bar.update(
513
- {
514
- start: 0,
515
- resolve: 20,
516
- end: 50
517
- }[event ?? "start"] ?? 0,
518
- {
519
- input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
520
- status: event?.padEnd(10),
521
- message: `${tags?.join(", ")}: ${message}`
522
- }
523
- );
524
- }
525
- if (e.type === "watchChange") {
526
- const {
527
- path: path2,
528
- input
529
- } = e.data;
530
- const key = `${input}:${path2}`;
531
- const bar = bars[key];
532
- if (!bar)
533
- return;
534
- let time = times[key] ?? 1;
535
- if (!locks[key]) {
536
- time += 1;
537
- times[key] = time;
538
- setTimeout(() => {
539
- locks[key] = false;
540
- }, 100);
541
- bar.update(0, {
542
- input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
543
- status: "watching".padEnd(10),
544
- message: "watching..."
545
- });
546
- }
547
- locks[key] = true;
548
- }
549
- });
550
- await new Promise((resolve, reject) => {
551
- let errorStr = "";
552
- child.stderr?.on("data", (data) => {
553
- errorStr += data;
554
- });
555
- child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
556
- ${errorStr}`)));
557
- verbose && child.stdout?.pipe(process.stdout);
558
- });
559
- })
560
- );
561
- };
562
- const filters = program.getOptionValue("filter")?.split(",");
563
- try {
564
- if (filters) {
565
- const packages = await filterPackagesGraph(filters);
566
- await Promise.all(packages.map(buildPackage));
567
- } else {
568
- await buildPackage(await getSelectedProjectsGraph());
569
- }
570
- } finally {
571
- multiBars.stop();
572
- }
573
- actionDone();
574
- });
16
+ import 'jiek/cli-only-build';
575
17
 
576
18
  var utils$1 = {};
577
19
 
@@ -4679,6 +4121,206 @@ function requireMicromatch () {
4679
4121
 
4680
4122
  var micromatchExports = requireMicromatch();
4681
4123
 
4124
+ let root;
4125
+ function getRoot() {
4126
+ if (root)
4127
+ return root;
4128
+ const rootOption = program.getOptionValue("root");
4129
+ root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
4130
+ return root;
4131
+ }
4132
+
4133
+ let type = "";
4134
+ try {
4135
+ const require = createRequire(import.meta.url);
4136
+ require.resolve("@pnpm/filter-workspace-packages");
4137
+ type = "pnpm";
4138
+ } catch {
4139
+ }
4140
+ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter")) {
4141
+ let root = getRoot();
4142
+ const { wd, notWorkspace } = getWD();
4143
+ if (notWorkspace) {
4144
+ return {
4145
+ wd,
4146
+ root,
4147
+ value: {
4148
+ [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
4149
+ }
4150
+ };
4151
+ }
4152
+ if (type === "pnpm") {
4153
+ const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
4154
+ const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
4155
+ const pnpmWorkspace = load(pnpmWorkspaceFileContent);
4156
+ if (root === wd && !filter) {
4157
+ throw new Error("root path is workspace root, please provide a filter");
4158
+ }
4159
+ if (root === void 0) {
4160
+ root = process.cwd();
4161
+ }
4162
+ if (root !== wd && !filter) {
4163
+ const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
4164
+ if (!packageJSONIsExist) {
4165
+ throw new Error("root path is not workspace root, please provide a filter");
4166
+ }
4167
+ const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
4168
+ if (!packageJSON.name) {
4169
+ throw new Error("root path is not workspace root, please provide a filter");
4170
+ }
4171
+ filter = packageJSON.name;
4172
+ }
4173
+ const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
4174
+ filter: filter ?? "",
4175
+ followProdDepsOnly: true
4176
+ }], {
4177
+ prefix: root,
4178
+ workspaceDir: wd,
4179
+ patterns: pnpmWorkspace.packages
4180
+ });
4181
+ return {
4182
+ wd,
4183
+ root,
4184
+ value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
4185
+ acc[key] = value.package.manifest;
4186
+ return acc;
4187
+ }, {})
4188
+ };
4189
+ }
4190
+ throw new Error(`not supported package manager ${type}`);
4191
+ }
4192
+
4193
+ let wd;
4194
+ let notWorkspace = false;
4195
+ function getWD() {
4196
+ if (wd)
4197
+ return { wd, notWorkspace };
4198
+ const root = getRoot();
4199
+ if (root !== void 0) {
4200
+ const isWorkspace = isWorkspaceDir(root, type);
4201
+ notWorkspace = !isWorkspace;
4202
+ wd = root;
4203
+ return { wd, notWorkspace };
4204
+ }
4205
+ try {
4206
+ wd = getWorkspaceDir(type);
4207
+ } catch (e) {
4208
+ if ("message" in e && e.message === "workspace root not found") {
4209
+ wd = root;
4210
+ notWorkspace = true;
4211
+ } else {
4212
+ throw e;
4213
+ }
4214
+ }
4215
+ return { wd, notWorkspace };
4216
+ }
4217
+
4218
+ const require$1 = createRequire(import.meta.url);
4219
+ function packageIsExist(name) {
4220
+ try {
4221
+ require$1.resolve(name);
4222
+ return true;
4223
+ } catch (e) {
4224
+ return false;
4225
+ }
4226
+ }
4227
+ let tsRegisterName;
4228
+ const registers = [
4229
+ process.env.JIEK_TS_REGISTER,
4230
+ "esbuild-register",
4231
+ "@swc-node/register",
4232
+ "ts-node/register"
4233
+ ].filter(Boolean);
4234
+ for (const register of registers) {
4235
+ if (packageIsExist(register)) {
4236
+ tsRegisterName = register;
4237
+ break;
4238
+ }
4239
+ }
4240
+
4241
+ const require = createRequire(import.meta.url);
4242
+ let configName = "jiek.config";
4243
+ function getConfigPath(root, dir) {
4244
+ const isSupportTsLoader = !!tsRegisterName;
4245
+ function configWithExtIsExist(ext) {
4246
+ const filenames = [
4247
+ path.resolve(process.cwd(), `${configName}.${ext}`),
4248
+ path.resolve(process.cwd(), `.${configName}.${ext}`),
4249
+ path.resolve(root, `${configName}.${ext}`),
4250
+ path.resolve(root, `.${configName}.${ext}`)
4251
+ ];
4252
+ if (dir) {
4253
+ filenames.unshift(...[
4254
+ path.resolve(dir, `${configName}.${ext}`),
4255
+ path.resolve(dir, `.${configName}.${ext}`)
4256
+ ]);
4257
+ }
4258
+ for (const filename of filenames) {
4259
+ if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
4260
+ return filename;
4261
+ }
4262
+ }
4263
+ return;
4264
+ }
4265
+ configName = configWithExtIsExist("js") ?? configName;
4266
+ configName = configWithExtIsExist("json") ?? configName;
4267
+ configName = configWithExtIsExist("yaml") ?? configName;
4268
+ if (isSupportTsLoader) {
4269
+ configName = configWithExtIsExist("ts") ?? configName;
4270
+ }
4271
+ return path.resolve(root, configName);
4272
+ }
4273
+ function loadConfig(dirOrOptions) {
4274
+ let dir;
4275
+ let root;
4276
+ if (typeof dirOrOptions === "object") {
4277
+ dir = dirOrOptions.dir;
4278
+ root = dirOrOptions.root ?? getWD().wd;
4279
+ } else {
4280
+ dir = dirOrOptions;
4281
+ root = getWD().wd;
4282
+ }
4283
+ let configPath = program.getOptionValue("configPath");
4284
+ if (!configPath) {
4285
+ configPath = getConfigPath(root, dir);
4286
+ } else {
4287
+ if (!fs.existsSync(configPath)) {
4288
+ throw new Error(`config file not found: ${configPath}`);
4289
+ }
4290
+ if (!path.isAbsolute(configPath)) {
4291
+ configPath = path.resolve(root, configPath);
4292
+ }
4293
+ }
4294
+ const ext = path.extname(configPath);
4295
+ let module;
4296
+ switch (ext) {
4297
+ case ".js":
4298
+ module = require(configPath);
4299
+ break;
4300
+ case ".json":
4301
+ return require(configPath);
4302
+ case ".yaml":
4303
+ return load(fs.readFileSync(configPath, "utf-8"));
4304
+ case ".ts":
4305
+ if (tsRegisterName) {
4306
+ require(tsRegisterName);
4307
+ module = require(configPath);
4308
+ break;
4309
+ }
4310
+ throw new Error(
4311
+ "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
4312
+ );
4313
+ case ".config":
4314
+ module = {};
4315
+ break;
4316
+ default:
4317
+ throw new Error(`unsupported config file type: ${ext}`);
4318
+ }
4319
+ if (!module)
4320
+ throw new Error("config file is empty");
4321
+ return module.default ?? module;
4322
+ }
4323
+
4682
4324
  const PACKAGE_JSON_TEMPLATE = `{
4683
4325
  "name": "",
4684
4326
  "version": "0.0.1",
@@ -4955,6 +4597,14 @@ program.command("init [name]").option("-t, --template <template>", "the package.
4955
4597
  fs.writeFileSync(readmeFilePath, readmeContent);
4956
4598
  });
4957
4599
 
4600
+ let resolve;
4601
+ function actionDone() {
4602
+ resolve();
4603
+ }
4604
+ function actionRestore() {
4605
+ new Promise((r) => resolve = r);
4606
+ }
4607
+
4958
4608
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4959
4609
  const {
4960
4610
  JIEK_OUT_DIR
@@ -5045,6 +4695,12 @@ function getExports({
5045
4695
  ];
5046
4696
  }
5047
4697
 
4698
+ const outdirDescription = `
4699
+ The output directory of the build, which relative to the target subpackage root directory.
4700
+ Support with variables: 'PKG_NAME',
4701
+ .e.g. 'dist/{{PKG_NAME}}'.
4702
+ `.trim();
4703
+
5048
4704
  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, ...options }) => {
5049
4705
  actionRestore();
5050
4706
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
@@ -5199,5 +4855,3 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
5199
4855
  }
5200
4856
  actionDone();
5201
4857
  });
5202
-
5203
- program.parse(process.argv);