jiek 1.1.13 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +34 -84
- package/bin/jiek-build.js +16 -0
- package/dist/cli-only-build.cjs +743 -0
- package/dist/cli-only-build.d.cts +91 -0
- package/dist/cli-only-build.d.ts +91 -0
- package/dist/cli-only-build.js +735 -0
- package/dist/cli.cjs +211 -560
- package/dist/cli.d.cts +0 -69
- package/dist/cli.d.ts +0 -69
- package/dist/cli.js +211 -560
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/rollup/index.cjs +86 -46
- package/dist/rollup/index.js +86 -44
- package/package.json +54 -11
- package/src/cli-only-build.ts +7 -0
- package/src/cli.ts +1 -7
- package/src/commands/base.ts +13 -3
- package/src/commands/build.ts +197 -39
- package/src/commands/descriptions.ts +12 -0
- package/src/commands/meta.ts +5 -0
- package/src/rollup/base.ts +40 -0
- package/src/rollup/index.ts +106 -37
- package/src/utils/filterSupport.ts +2 -6
package/dist/cli.js
CHANGED
@@ -1,572 +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.13";
|
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.2.1",
|
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
|
-
const require$2 = createRequire(import.meta.url);
|
238
|
-
function packageIsExist(name) {
|
239
|
-
try {
|
240
|
-
require$2.resolve(name);
|
241
|
-
return true;
|
242
|
-
} catch (e) {
|
243
|
-
return false;
|
244
|
-
}
|
245
|
-
}
|
246
|
-
let tsRegisterName;
|
247
|
-
const registers = [
|
248
|
-
process.env.JIEK_TS_REGISTER,
|
249
|
-
"esbuild-register",
|
250
|
-
"@swc-node/register",
|
251
|
-
"ts-node/register"
|
252
|
-
].filter(Boolean);
|
253
|
-
for (const register of registers) {
|
254
|
-
if (packageIsExist(register)) {
|
255
|
-
tsRegisterName = register;
|
256
|
-
break;
|
257
|
-
}
|
258
|
-
}
|
259
|
-
|
260
|
-
const require$1 = createRequire(import.meta.url);
|
261
|
-
let configName = "jiek.config";
|
262
|
-
function getConfigPath(root, dir) {
|
263
|
-
const isSupportTsLoader = !!tsRegisterName;
|
264
|
-
function configWithExtIsExist(ext) {
|
265
|
-
const filenames = [
|
266
|
-
path.resolve(process.cwd(), `${configName}.${ext}`),
|
267
|
-
path.resolve(process.cwd(), `.${configName}.${ext}`),
|
268
|
-
path.resolve(root, `${configName}.${ext}`),
|
269
|
-
path.resolve(root, `.${configName}.${ext}`)
|
270
|
-
];
|
271
|
-
if (dir) {
|
272
|
-
filenames.unshift(...[
|
273
|
-
path.resolve(dir, `${configName}.${ext}`),
|
274
|
-
path.resolve(dir, `.${configName}.${ext}`)
|
275
|
-
]);
|
276
|
-
}
|
277
|
-
for (const filename of filenames) {
|
278
|
-
if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
|
279
|
-
return filename;
|
280
|
-
}
|
281
|
-
}
|
282
|
-
return;
|
283
|
-
}
|
284
|
-
configName = configWithExtIsExist("js") ?? configName;
|
285
|
-
configName = configWithExtIsExist("json") ?? configName;
|
286
|
-
configName = configWithExtIsExist("yaml") ?? configName;
|
287
|
-
if (isSupportTsLoader) {
|
288
|
-
configName = configWithExtIsExist("ts") ?? configName;
|
289
|
-
}
|
290
|
-
return path.resolve(root, configName);
|
291
|
-
}
|
292
|
-
function loadConfig(dirOrOptions) {
|
293
|
-
let dir;
|
294
|
-
let root;
|
295
|
-
if (typeof dirOrOptions === "object") {
|
296
|
-
dir = dirOrOptions.dir;
|
297
|
-
root = dirOrOptions.root ?? getWD().wd;
|
298
|
-
} else {
|
299
|
-
dir = dirOrOptions;
|
300
|
-
root = getWD().wd;
|
301
|
-
}
|
302
|
-
let configPath = program.getOptionValue("configPath");
|
303
|
-
if (!configPath) {
|
304
|
-
configPath = getConfigPath(root, dir);
|
305
|
-
} else {
|
306
|
-
if (!fs.existsSync(configPath)) {
|
307
|
-
throw new Error(`config file not found: ${configPath}`);
|
308
|
-
}
|
309
|
-
if (!path.isAbsolute(configPath)) {
|
310
|
-
configPath = path.resolve(root, configPath);
|
311
|
-
}
|
312
|
-
}
|
313
|
-
const ext = path.extname(configPath);
|
314
|
-
let module;
|
315
|
-
switch (ext) {
|
316
|
-
case ".js":
|
317
|
-
module = require$1(configPath);
|
318
|
-
break;
|
319
|
-
case ".json":
|
320
|
-
return require$1(configPath);
|
321
|
-
case ".yaml":
|
322
|
-
return load(fs.readFileSync(configPath, "utf-8"));
|
323
|
-
case ".ts":
|
324
|
-
if (tsRegisterName) {
|
325
|
-
require$1(tsRegisterName);
|
326
|
-
module = require$1(configPath);
|
327
|
-
break;
|
328
|
-
}
|
329
|
-
throw new Error(
|
330
|
-
"ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
|
331
|
-
);
|
332
|
-
case ".config":
|
333
|
-
module = {};
|
334
|
-
break;
|
335
|
-
default:
|
336
|
-
throw new Error(`unsupported config file type: ${ext}`);
|
337
|
-
}
|
338
|
-
if (!module)
|
339
|
-
throw new Error("config file is empty");
|
340
|
-
return module.default ?? module;
|
341
|
-
}
|
342
|
-
|
343
|
-
const outdirDescription = `
|
344
|
-
The output directory of the build, which relative to the target subpackage root directory.
|
345
|
-
Support with variables: 'PKG_NAME',
|
346
|
-
.e.g. 'dist/{{PKG_NAME}}'.
|
347
|
-
`.trim();
|
348
|
-
|
349
|
-
const FILE_TEMPLATE = (manifest) => `
|
350
|
-
module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
|
351
|
-
`.trimStart();
|
352
|
-
const require = createRequire(import.meta.url);
|
353
|
-
const description = `
|
354
|
-
Build the package according to the 'exports' field in the package.json.
|
355
|
-
If you want to rewrite the rollup command options, you can pass the options after '--'.
|
356
|
-
e.g. \`jiek build -- --watch\`
|
357
|
-
`.trim();
|
358
|
-
function parseBoolean(v) {
|
359
|
-
if (v === void 0)
|
360
|
-
return true;
|
361
|
-
return Boolean(v);
|
362
|
-
}
|
363
|
-
program.command("build").description(description).option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option(
|
364
|
-
"-e, --entries <ENTRIES>",
|
365
|
-
"Specify the build entry-points of the package.json's 'exports' field.(support glob)"
|
366
|
-
).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(
|
367
|
-
"-om, --onlyMin",
|
368
|
-
"Only output minify files, but dts files will still be output, it only replaces the js files.",
|
369
|
-
parseBoolean
|
370
|
-
).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async ({
|
371
|
-
outdir,
|
372
|
-
silent,
|
373
|
-
entries,
|
374
|
-
external,
|
375
|
-
verbose,
|
376
|
-
noJs: withoutJs,
|
377
|
-
noDts: withoutDts,
|
378
|
-
noMin: withoutMin,
|
379
|
-
noClean,
|
380
|
-
onlyMin
|
381
|
-
}) => {
|
382
|
-
let shouldPassThrough = false;
|
383
|
-
const passThroughOptions = program.parseOptions(process.argv).unknown.reduce(
|
384
|
-
(acc, value) => {
|
385
|
-
if (shouldPassThrough) {
|
386
|
-
acc.push(value);
|
387
|
-
}
|
388
|
-
if (value === "--") {
|
389
|
-
shouldPassThrough = true;
|
390
|
-
}
|
391
|
-
return acc;
|
392
|
-
},
|
393
|
-
[]
|
394
|
-
);
|
395
|
-
const { build } = loadConfig();
|
396
|
-
silent = silent ?? build?.silent ?? false;
|
397
|
-
if (withoutMin && onlyMin) {
|
398
|
-
throw new Error("Cannot use both --without-minify and --only-minify");
|
399
|
-
}
|
400
|
-
if (onlyMin && withoutJs) {
|
401
|
-
throw new Error("Cannot use --without-js and --only-minify at the same time");
|
402
|
-
}
|
403
|
-
const env = {
|
404
|
-
...process.env,
|
405
|
-
JIEK_OUT_DIR: outdir,
|
406
|
-
JIEK_CLEAN: String(!noClean),
|
407
|
-
JIEK_ENTRIES: entries,
|
408
|
-
JIEK_EXTERNAL: external,
|
409
|
-
JIEK_WITHOUT_JS: String(withoutJs),
|
410
|
-
JIEK_WITHOUT_DTS: String(withoutDts),
|
411
|
-
JIEK_WITHOUT_MINIFY: String(withoutMin),
|
412
|
-
JIEK_ONLY_MINIFY: String(onlyMin)
|
413
|
-
};
|
414
|
-
const multiBars = new MultiBar({
|
415
|
-
clearOnComplete: false,
|
416
|
-
hideCursor: true,
|
417
|
-
format: "- {bar} | {status} | {pkgName} | {input} | {message}"
|
418
|
-
}, Presets.shades_classic);
|
419
|
-
const buildPackage = async ({
|
420
|
-
wd,
|
421
|
-
value = {}
|
422
|
-
}) => {
|
423
|
-
if (Object.keys(value).length === 0) {
|
424
|
-
throw new Error("no package found");
|
425
|
-
}
|
426
|
-
const wdNodeModules = path.resolve(wd, "node_modules");
|
427
|
-
if (!fs.existsSync(wdNodeModules)) {
|
428
|
-
fs.mkdirSync(wdNodeModules);
|
429
|
-
}
|
430
|
-
const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
|
431
|
-
if (!fs.existsSync(jiekTempDir())) {
|
432
|
-
fs.mkdirSync(jiekTempDir());
|
433
|
-
}
|
434
|
-
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
435
|
-
let i = 0;
|
436
|
-
await Promise.all(
|
437
|
-
Object.entries(value).map(async ([dir, manifest]) => {
|
438
|
-
if (!manifest.name) {
|
439
|
-
throw new Error("package.json must have a name field");
|
440
|
-
}
|
441
|
-
const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
|
442
|
-
const configFile = jiekTempDir(
|
443
|
-
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
444
|
-
);
|
445
|
-
fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
446
|
-
let prefix = "";
|
447
|
-
if (tsRegisterName) {
|
448
|
-
prefix = `node -r ${tsRegisterName} `;
|
449
|
-
}
|
450
|
-
const command = [`${prefix}${rollupBinaryPath} --silent -c ${configFile}`, ...passThroughOptions].join(" ");
|
451
|
-
const child = execaCommand(command, {
|
452
|
-
ipc: true,
|
453
|
-
cwd: dir,
|
454
|
-
env: {
|
455
|
-
...env,
|
456
|
-
JIEK_NAME: manifest.name,
|
457
|
-
JIEK_ROOT: wd
|
458
|
-
}
|
459
|
-
});
|
460
|
-
const bars = {};
|
461
|
-
const times = {};
|
462
|
-
const locks = {};
|
463
|
-
let inputMaxLen = 10;
|
464
|
-
child.on("message", (e) => {
|
465
|
-
if (e.type === "debug")
|
466
|
-
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
467
|
-
});
|
468
|
-
!silent && child.on("message", (e) => {
|
469
|
-
if (e.type === "init") {
|
470
|
-
const { leafMap, targetsLength } = e.data;
|
471
|
-
const leafs = Array.from(leafMap.entries()).flatMap(
|
472
|
-
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
473
|
-
input,
|
474
|
-
path: path2,
|
475
|
-
conditions
|
476
|
-
}))
|
477
|
-
);
|
478
|
-
console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
|
479
|
-
leafs.forEach(({ input }) => {
|
480
|
-
inputMaxLen = Math.max(inputMaxLen, input.length);
|
481
|
-
});
|
482
|
-
leafs.forEach(({ input, path: path2 }) => {
|
483
|
-
const key = `${input}:${path2}`;
|
484
|
-
if (bars[key])
|
485
|
-
return;
|
486
|
-
bars[key] = multiBars.create(50, 0, {
|
487
|
-
pkgName: manifest.name,
|
488
|
-
input: input.padEnd(inputMaxLen + 5),
|
489
|
-
status: "waiting".padEnd(10)
|
490
|
-
}, {
|
491
|
-
barsize: 20,
|
492
|
-
linewrap: true
|
493
|
-
});
|
494
|
-
});
|
495
|
-
}
|
496
|
-
if (e.type === "progress") {
|
497
|
-
const {
|
498
|
-
path: path2,
|
499
|
-
tags,
|
500
|
-
input,
|
501
|
-
event,
|
502
|
-
message
|
503
|
-
} = e.data;
|
504
|
-
const bar = bars[`${input}:${path2}`];
|
505
|
-
if (!bar)
|
506
|
-
return;
|
507
|
-
const time = times[`${input}:${path2}`];
|
508
|
-
bar.update(
|
509
|
-
{
|
510
|
-
start: 0,
|
511
|
-
resolve: 20,
|
512
|
-
end: 50
|
513
|
-
}[event ?? "start"] ?? 0,
|
514
|
-
{
|
515
|
-
input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
|
516
|
-
status: event?.padEnd(10),
|
517
|
-
message: `${tags?.join(", ")}: ${message}`
|
518
|
-
}
|
519
|
-
);
|
520
|
-
}
|
521
|
-
if (e.type === "watchChange") {
|
522
|
-
const {
|
523
|
-
path: path2,
|
524
|
-
input
|
525
|
-
} = e.data;
|
526
|
-
const key = `${input}:${path2}`;
|
527
|
-
const bar = bars[key];
|
528
|
-
if (!bar)
|
529
|
-
return;
|
530
|
-
let time = times[key] ?? 1;
|
531
|
-
if (!locks[key]) {
|
532
|
-
time += 1;
|
533
|
-
times[key] = time;
|
534
|
-
setTimeout(() => {
|
535
|
-
locks[key] = false;
|
536
|
-
}, 100);
|
537
|
-
bar.update(0, {
|
538
|
-
input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
|
539
|
-
status: "watching".padEnd(10),
|
540
|
-
message: "watching..."
|
541
|
-
});
|
542
|
-
}
|
543
|
-
locks[key] = true;
|
544
|
-
}
|
545
|
-
});
|
546
|
-
await new Promise((resolve, reject) => {
|
547
|
-
let errorStr = "";
|
548
|
-
child.stderr?.on("data", (data) => {
|
549
|
-
errorStr += data;
|
550
|
-
});
|
551
|
-
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
|
552
|
-
${errorStr}`)));
|
553
|
-
verbose && child.stdout?.pipe(process.stdout);
|
554
|
-
});
|
555
|
-
})
|
556
|
-
);
|
557
|
-
};
|
558
|
-
const filters = program.getOptionValue("filter")?.split(",");
|
559
|
-
try {
|
560
|
-
if (filters) {
|
561
|
-
const packages = await filterPackagesGraph(filters);
|
562
|
-
await Promise.all(packages.map(buildPackage));
|
563
|
-
} else {
|
564
|
-
await buildPackage(await getSelectedProjectsGraph());
|
565
|
-
}
|
566
|
-
} finally {
|
567
|
-
multiBars.stop();
|
568
|
-
}
|
569
|
-
});
|
16
|
+
import 'jiek/cli-only-build';
|
570
17
|
|
571
18
|
var utils$1 = {};
|
572
19
|
|
@@ -4674,6 +4121,206 @@ function requireMicromatch () {
|
|
4674
4121
|
|
4675
4122
|
var micromatchExports = requireMicromatch();
|
4676
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
|
+
|
4677
4324
|
const PACKAGE_JSON_TEMPLATE = `{
|
4678
4325
|
"name": "",
|
4679
4326
|
"version": "0.0.1",
|
@@ -5048,6 +4695,12 @@ function getExports({
|
|
5048
4695
|
];
|
5049
4696
|
}
|
5050
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
|
+
|
5051
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 }) => {
|
5052
4705
|
actionRestore();
|
5053
4706
|
const { value = {} } = await getSelectedProjectsGraph() ?? {};
|
@@ -5202,5 +4855,3 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
|
|
5202
4855
|
}
|
5203
4856
|
actionDone();
|
5204
4857
|
});
|
5205
|
-
|
5206
|
-
program.parse(process.argv);
|