jiek 2.0.0 → 2.0.2-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +35 -6
- package/README.md +0 -78
- package/bin/jiek-build.js +0 -16
- package/bin/jiek.js +0 -13
- package/dist/cli-only-build.cjs +0 -716
- package/dist/cli-only-build.d.cts +0 -91
- package/dist/cli-only-build.d.ts +0 -91
- package/dist/cli-only-build.js +0 -708
- package/dist/cli.cjs +0 -4888
- package/dist/cli.d.cts +0 -67
- package/dist/cli.d.ts +0 -67
- package/dist/cli.js +0 -4857
- package/dist/index.cjs +0 -5
- package/dist/index.d.cts +0 -165
- package/dist/index.d.ts +0 -165
- package/dist/index.js +0 -3
- package/dist/rollup/index.cjs +0 -4893
- package/dist/rollup/index.d.cts +0 -10
- package/dist/rollup/index.d.ts +0 -10
- package/dist/rollup/index.js +0 -4880
- package/src/cli-only-build.ts +0 -7
- package/src/cli.ts +0 -3
- package/src/commands/base.ts +0 -18
- package/src/commands/build.ts +0 -462
- package/src/commands/descriptions.ts +0 -17
- package/src/commands/init.ts +0 -373
- package/src/commands/meta.ts +0 -5
- package/src/commands/publish.ts +0 -204
- package/src/index.ts +0 -8
- package/src/inner.ts +0 -11
- package/src/rollup/base.ts +0 -137
- package/src/rollup/index.ts +0 -565
- package/src/rollup/plugins/progress.ts +0 -26
- package/src/rollup/plugins/skip.ts +0 -21
- package/src/rollup/utils/commonOptions.ts +0 -9
- package/src/rollup/utils/externalResolver.ts +0 -35
- package/src/rollup/utils/globalResolver.ts +0 -13
- package/src/rollup/utils/withMinify.ts +0 -18
- package/src/utils/filterSupport.ts +0 -91
- package/src/utils/getExports.ts +0 -140
- package/src/utils/getRoot.ts +0 -16
- package/src/utils/getWD.ts +0 -31
- package/src/utils/loadConfig.ts +0 -111
- package/src/utils/recusiveListFiles.ts +0 -13
- package/src/utils/ts.ts +0 -94
- package/src/utils/tsRegister.ts +0 -26
package/dist/cli-only-build.js
DELETED
@@ -1,708 +0,0 @@
|
|
1
|
-
import fs from 'node:fs';
|
2
|
-
import { createRequire } from 'node:module';
|
3
|
-
import path from 'node:path';
|
4
|
-
import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages';
|
5
|
-
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
|
-
|
11
|
-
let root;
|
12
|
-
function getRoot() {
|
13
|
-
if (root)
|
14
|
-
return root;
|
15
|
-
const rootOption = program.getOptionValue("root");
|
16
|
-
root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
|
17
|
-
return root;
|
18
|
-
}
|
19
|
-
|
20
|
-
let wd;
|
21
|
-
let notWorkspace$1 = false;
|
22
|
-
function getWD() {
|
23
|
-
if (wd)
|
24
|
-
return { wd, notWorkspace: notWorkspace$1 };
|
25
|
-
const root = getRoot();
|
26
|
-
if (root !== void 0) {
|
27
|
-
const isWorkspace = isWorkspaceDir(root, type$1);
|
28
|
-
notWorkspace$1 = !isWorkspace;
|
29
|
-
wd = root;
|
30
|
-
return { wd, notWorkspace: notWorkspace$1 };
|
31
|
-
}
|
32
|
-
try {
|
33
|
-
wd = getWorkspaceDir(type$1);
|
34
|
-
} catch (e) {
|
35
|
-
if ("message" in e && e.message === "workspace root not found") {
|
36
|
-
wd = root;
|
37
|
-
notWorkspace$1 = true;
|
38
|
-
} else {
|
39
|
-
throw e;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
return { wd, notWorkspace: notWorkspace$1 };
|
43
|
-
}
|
44
|
-
|
45
|
-
let type$1 = "";
|
46
|
-
try {
|
47
|
-
const require = createRequire(import.meta.url);
|
48
|
-
require.resolve("@pnpm/filter-workspace-packages");
|
49
|
-
type$1 = "pnpm";
|
50
|
-
} catch {
|
51
|
-
}
|
52
|
-
function filterPackagesGraph(filters) {
|
53
|
-
return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
|
54
|
-
}
|
55
|
-
async function getSelectedProjectsGraph(filter = program.getOptionValue("filter")) {
|
56
|
-
let root = getRoot();
|
57
|
-
const { wd, notWorkspace } = getWD();
|
58
|
-
if (notWorkspace) {
|
59
|
-
return {
|
60
|
-
wd,
|
61
|
-
root,
|
62
|
-
value: {
|
63
|
-
[wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
|
64
|
-
}
|
65
|
-
};
|
66
|
-
}
|
67
|
-
if (type$1 === "pnpm") {
|
68
|
-
const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
|
69
|
-
const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
|
70
|
-
const pnpmWorkspace = load(pnpmWorkspaceFileContent);
|
71
|
-
if (root === wd && !filter) {
|
72
|
-
throw new Error("root path is workspace root, please provide a filter");
|
73
|
-
}
|
74
|
-
if (root === void 0) {
|
75
|
-
root = process.cwd();
|
76
|
-
}
|
77
|
-
if (root !== wd && !filter) {
|
78
|
-
const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
|
79
|
-
if (!packageJSONIsExist) {
|
80
|
-
throw new Error("root path is not workspace root, please provide a filter");
|
81
|
-
}
|
82
|
-
const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
|
83
|
-
if (!packageJSON.name) {
|
84
|
-
throw new Error("root path is not workspace root, please provide a filter");
|
85
|
-
}
|
86
|
-
filter = packageJSON.name;
|
87
|
-
}
|
88
|
-
const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
|
89
|
-
filter: filter ?? "",
|
90
|
-
followProdDepsOnly: true
|
91
|
-
}], {
|
92
|
-
prefix: root,
|
93
|
-
workspaceDir: wd,
|
94
|
-
patterns: pnpmWorkspace.packages
|
95
|
-
});
|
96
|
-
return {
|
97
|
-
wd,
|
98
|
-
root,
|
99
|
-
value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
|
100
|
-
acc[key] = value.package.manifest;
|
101
|
-
return acc;
|
102
|
-
}, {})
|
103
|
-
};
|
104
|
-
}
|
105
|
-
throw new Error(`not supported package manager ${type$1}`);
|
106
|
-
}
|
107
|
-
|
108
|
-
var name = "jiek";
|
109
|
-
var type = "module";
|
110
|
-
var version = "2.0.0";
|
111
|
-
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
112
|
-
var author = "YiJie <yijie4188@gmail.com>";
|
113
|
-
var repository = {
|
114
|
-
url: "nwylzw/jiek",
|
115
|
-
directory: "packages/jiek"
|
116
|
-
};
|
117
|
-
var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
|
118
|
-
var bugs = "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek";
|
119
|
-
var bin = {
|
120
|
-
jiek: "bin/jiek.js",
|
121
|
-
jk: "bin/jiek.js",
|
122
|
-
"jiek-build": "bin/jiek-build.js",
|
123
|
-
jb: "bin/jiek-build.js"
|
124
|
-
};
|
125
|
-
var files = [
|
126
|
-
"dist",
|
127
|
-
"src",
|
128
|
-
"bin",
|
129
|
-
"LICENSE",
|
130
|
-
"README.md"
|
131
|
-
];
|
132
|
-
var scripts = {
|
133
|
-
prepublish: "jb --noMin"
|
134
|
-
};
|
135
|
-
var exports = {
|
136
|
-
"./package.json": "./package.json",
|
137
|
-
".": "./src/index.ts",
|
138
|
-
"./cli": "./src/cli.ts",
|
139
|
-
"./cli-only-build": "./src/cli-only-build.ts",
|
140
|
-
"./rollup": "./src/rollup/index.ts"
|
141
|
-
};
|
142
|
-
var imports = {
|
143
|
-
"#~/*": "./src/*"
|
144
|
-
};
|
145
|
-
var dependencies = {
|
146
|
-
"@jiek/pkger": "workspace:^",
|
147
|
-
"@jiek/rollup-plugin-dts": "^6.2.1",
|
148
|
-
"@jiek/utils": "workspace:^",
|
149
|
-
"@rollup/plugin-commonjs": "^28.0.0",
|
150
|
-
"@rollup/plugin-json": "^6.0.1",
|
151
|
-
"@rollup/plugin-node-resolve": "^15.3.0",
|
152
|
-
"cli-progress": "^3.12.0",
|
153
|
-
commander: "^12.0.0",
|
154
|
-
"detect-indent": "^6.1.0",
|
155
|
-
execa: "9.3.1",
|
156
|
-
inquirer: "^8.2.6",
|
157
|
-
"js-yaml": "^4.1.0",
|
158
|
-
"jsonc-parser": "^3.2.1",
|
159
|
-
rollup: "4.13.2"
|
160
|
-
};
|
161
|
-
var optionalDependencies = {
|
162
|
-
"@rollup/plugin-terser": "^0.4.4",
|
163
|
-
"@pnpm/filter-workspace-packages": "^7.2.13",
|
164
|
-
"esbuild-register": "^3.5.0",
|
165
|
-
postcss: "^8.4.47",
|
166
|
-
"rollup-plugin-postcss": "^4.0.2",
|
167
|
-
"rollup-plugin-esbuild": "^6.1.0",
|
168
|
-
"rollup-plugin-swc3": "^0.12.1",
|
169
|
-
typescript: "^4.0.0||^5.0.0"
|
170
|
-
};
|
171
|
-
var devDependencies = {
|
172
|
-
"@npm/types": "^1.0.2",
|
173
|
-
"@pnpm/filter-workspace-packages": "^7.2.13",
|
174
|
-
"@pnpm/workspace.pkgs-graph": "^2.0.15",
|
175
|
-
"@rollup/plugin-terser": "^0.4.4",
|
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
|
-
"rollup-plugin-esbuild": "^6.1.0",
|
186
|
-
"rollup-plugin-swc3": "^0.12.1"
|
187
|
-
};
|
188
|
-
var publishConfig = {
|
189
|
-
exports: {
|
190
|
-
"./package.json": "./package.json",
|
191
|
-
".": {
|
192
|
-
source: "./src/index.ts",
|
193
|
-
require: "./dist/index.cjs",
|
194
|
-
"default": "./dist/index.js"
|
195
|
-
},
|
196
|
-
"./cli": {
|
197
|
-
source: "./src/cli.ts",
|
198
|
-
require: "./dist/cli.cjs",
|
199
|
-
"default": "./dist/cli.js"
|
200
|
-
},
|
201
|
-
"./cli-only-build": {
|
202
|
-
source: "./src/cli-only-build.ts",
|
203
|
-
require: "./dist/cli-only-build.cjs",
|
204
|
-
"default": "./dist/cli-only-build.js"
|
205
|
-
},
|
206
|
-
"./rollup": {
|
207
|
-
source: "./src/rollup/index.ts",
|
208
|
-
require: "./dist/rollup/index.cjs",
|
209
|
-
"default": "./dist/rollup/index.js"
|
210
|
-
}
|
211
|
-
},
|
212
|
-
main: "./dist/index.cjs",
|
213
|
-
module: "./dist/index.js",
|
214
|
-
typesVersions: {
|
215
|
-
"<5.0": {
|
216
|
-
"*": [
|
217
|
-
"*",
|
218
|
-
"./dist/*",
|
219
|
-
"./dist/*/index.d.ts",
|
220
|
-
"./dist/*/index.d.mts",
|
221
|
-
"./dist/*/index.d.cts"
|
222
|
-
]
|
223
|
-
}
|
224
|
-
}
|
225
|
-
};
|
226
|
-
var pkg = {
|
227
|
-
name: name,
|
228
|
-
type: type,
|
229
|
-
version: version,
|
230
|
-
description: description$1,
|
231
|
-
author: author,
|
232
|
-
repository: repository,
|
233
|
-
homepage: homepage,
|
234
|
-
bugs: bugs,
|
235
|
-
bin: bin,
|
236
|
-
files: files,
|
237
|
-
scripts: scripts,
|
238
|
-
exports: exports,
|
239
|
-
imports: imports,
|
240
|
-
dependencies: dependencies,
|
241
|
-
optionalDependencies: optionalDependencies,
|
242
|
-
devDependencies: devDependencies,
|
243
|
-
publishConfig: publishConfig
|
244
|
-
};
|
245
|
-
|
246
|
-
const entriesDescription = `
|
247
|
-
Specify the build entry-points of the package.json's 'exports' field.
|
248
|
-
Support glob pattern and array.
|
249
|
-
.e.g. '.', './*', './sub/*', './a,./b'.
|
250
|
-
`.trim();
|
251
|
-
const filterDescription = `
|
252
|
-
Filter the packages from the workspace.
|
253
|
-
Support fuzzy match and array.
|
254
|
-
.e.g. 'core,utils'.
|
255
|
-
`.trim();
|
256
|
-
const outdirDescription = `
|
257
|
-
The output directory of the build, which relative to the target subpackage root directory.
|
258
|
-
Support with variables: 'PKG_NAME',
|
259
|
-
.e.g. 'dist/{{PKG_NAME}}'.
|
260
|
-
`.trim();
|
261
|
-
|
262
|
-
const { notWorkspace } = getWD();
|
263
|
-
const IS_WORKSPACE = !notWorkspace;
|
264
|
-
|
265
|
-
program.name("jk/jiek").version(pkg.version).description(`${pkg.description} - Version ${pkg.version}`).option("--root <root>", "The root path of the project").option("-c, --config-path <configPath>", "Custom jiek config path");
|
266
|
-
if (type$1 !== "" && IS_WORKSPACE) {
|
267
|
-
program.option("-f, --filter <filter>", filterDescription);
|
268
|
-
}
|
269
|
-
|
270
|
-
const require$2 = createRequire(import.meta.url);
|
271
|
-
function packageIsExist(name) {
|
272
|
-
try {
|
273
|
-
require$2.resolve(name);
|
274
|
-
return true;
|
275
|
-
} catch (e) {
|
276
|
-
return false;
|
277
|
-
}
|
278
|
-
}
|
279
|
-
let tsRegisterName;
|
280
|
-
const registers = [
|
281
|
-
process.env.JIEK_TS_REGISTER,
|
282
|
-
"esbuild-register",
|
283
|
-
"@swc-node/register",
|
284
|
-
"ts-node/register"
|
285
|
-
].filter(Boolean);
|
286
|
-
for (const register of registers) {
|
287
|
-
if (packageIsExist(register)) {
|
288
|
-
tsRegisterName = register;
|
289
|
-
break;
|
290
|
-
}
|
291
|
-
}
|
292
|
-
|
293
|
-
const require$1 = createRequire(import.meta.url);
|
294
|
-
let configName = "jiek.config";
|
295
|
-
function getConfigPath(root, dir) {
|
296
|
-
const isSupportTsLoader = !!tsRegisterName;
|
297
|
-
function configWithExtIsExist(ext) {
|
298
|
-
const filenames = [
|
299
|
-
path.resolve(process.cwd(), `${configName}.${ext}`),
|
300
|
-
path.resolve(process.cwd(), `.${configName}.${ext}`),
|
301
|
-
path.resolve(root, `${configName}.${ext}`),
|
302
|
-
path.resolve(root, `.${configName}.${ext}`)
|
303
|
-
];
|
304
|
-
if (dir) {
|
305
|
-
filenames.unshift(...[
|
306
|
-
path.resolve(dir, `${configName}.${ext}`),
|
307
|
-
path.resolve(dir, `.${configName}.${ext}`)
|
308
|
-
]);
|
309
|
-
}
|
310
|
-
for (const filename of filenames) {
|
311
|
-
if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
|
312
|
-
return filename;
|
313
|
-
}
|
314
|
-
}
|
315
|
-
return;
|
316
|
-
}
|
317
|
-
configName = configWithExtIsExist("js") ?? configName;
|
318
|
-
configName = configWithExtIsExist("json") ?? configName;
|
319
|
-
configName = configWithExtIsExist("yaml") ?? configName;
|
320
|
-
if (isSupportTsLoader) {
|
321
|
-
configName = configWithExtIsExist("ts") ?? configName;
|
322
|
-
}
|
323
|
-
return path.resolve(root, configName);
|
324
|
-
}
|
325
|
-
function loadConfig(dirOrOptions) {
|
326
|
-
let dir;
|
327
|
-
let root;
|
328
|
-
if (typeof dirOrOptions === "object") {
|
329
|
-
dir = dirOrOptions.dir;
|
330
|
-
root = dirOrOptions.root ?? getWD().wd;
|
331
|
-
} else {
|
332
|
-
dir = dirOrOptions;
|
333
|
-
root = getWD().wd;
|
334
|
-
}
|
335
|
-
let configPath = program.getOptionValue("configPath");
|
336
|
-
if (!configPath) {
|
337
|
-
configPath = getConfigPath(root, dir);
|
338
|
-
} else {
|
339
|
-
if (!fs.existsSync(configPath)) {
|
340
|
-
throw new Error(`config file not found: ${configPath}`);
|
341
|
-
}
|
342
|
-
if (!path.isAbsolute(configPath)) {
|
343
|
-
configPath = path.resolve(root, configPath);
|
344
|
-
}
|
345
|
-
}
|
346
|
-
const ext = path.extname(configPath);
|
347
|
-
let module;
|
348
|
-
switch (ext) {
|
349
|
-
case ".js":
|
350
|
-
module = require$1(configPath);
|
351
|
-
break;
|
352
|
-
case ".json":
|
353
|
-
return require$1(configPath);
|
354
|
-
case ".yaml":
|
355
|
-
return load(fs.readFileSync(configPath, "utf-8"));
|
356
|
-
case ".ts":
|
357
|
-
if (tsRegisterName) {
|
358
|
-
require$1(tsRegisterName);
|
359
|
-
module = require$1(configPath);
|
360
|
-
break;
|
361
|
-
}
|
362
|
-
throw new Error(
|
363
|
-
"ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
|
364
|
-
);
|
365
|
-
case ".config":
|
366
|
-
module = {};
|
367
|
-
break;
|
368
|
-
default:
|
369
|
-
throw new Error(`unsupported config file type: ${ext}`);
|
370
|
-
}
|
371
|
-
if (!module)
|
372
|
-
throw new Error("config file is empty");
|
373
|
-
return module.default ?? module;
|
374
|
-
}
|
375
|
-
|
376
|
-
const BUILDER_TYPES = ["esbuild", "swc"];
|
377
|
-
const BUILDER_TYPE_PACKAGE_NAME_MAP = {
|
378
|
-
esbuild: "rollup-plugin-esbuild",
|
379
|
-
swc: "rollup-plugin-swc3"
|
380
|
-
};
|
381
|
-
|
382
|
-
const FILE_TEMPLATE = (manifest) => `
|
383
|
-
module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
|
384
|
-
`.trimStart();
|
385
|
-
const require = createRequire(import.meta.url);
|
386
|
-
const isDefault = process.env.JIEK_IS_ONLY_BUILD === "true";
|
387
|
-
const description = `
|
388
|
-
Build the package according to the 'exports' field from the package.json.
|
389
|
-
If you want to rewrite the \`rollup\` command options, you can pass the options after '--'.
|
390
|
-
${isDefault ? "This command is the default command." : ""}
|
391
|
-
`.trim();
|
392
|
-
async function checkDependency(dependency) {
|
393
|
-
try {
|
394
|
-
require.resolve(dependency);
|
395
|
-
} catch (e) {
|
396
|
-
console.error(`The package '${dependency}' is not installed, please install it first.`);
|
397
|
-
const answer = prompt("Do you want to install it now? (Y/n)", "Y");
|
398
|
-
const { notWorkspace } = getWD();
|
399
|
-
if (answer === "Y") {
|
400
|
-
await execaCommand(`pnpm install -${notWorkspace ? "" : "w"}D ${dependency}`);
|
401
|
-
} else {
|
402
|
-
return;
|
403
|
-
}
|
404
|
-
}
|
405
|
-
}
|
406
|
-
let DEFAULT_BUILDER_TYPE;
|
407
|
-
Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
408
|
-
try {
|
409
|
-
require.resolve(packageName);
|
410
|
-
DEFAULT_BUILDER_TYPE = type;
|
411
|
-
} catch {
|
412
|
-
}
|
413
|
-
});
|
414
|
-
if (!DEFAULT_BUILDER_TYPE) {
|
415
|
-
DEFAULT_BUILDER_TYPE = "esbuild";
|
416
|
-
}
|
417
|
-
function parseBoolean(v) {
|
418
|
-
if (v === void 0)
|
419
|
-
return true;
|
420
|
-
return Boolean(v);
|
421
|
-
}
|
422
|
-
const buildFilterDescription = `
|
423
|
-
${filterDescription}
|
424
|
-
If you pass the --filter option, it will merge into the filters of the command.
|
425
|
-
`.trim();
|
426
|
-
const buildEntriesDescription = `
|
427
|
-
${entriesDescription}
|
428
|
-
If you pass the --entries option, it will merge into the entries of the command.
|
429
|
-
`.trim();
|
430
|
-
const command = isDefault ? program.name("jb/jiek-build").helpCommand(false) : program;
|
431
|
-
if (IS_WORKSPACE) {
|
432
|
-
if (isDefault) {
|
433
|
-
command.argument("[filters]", buildFilterDescription);
|
434
|
-
} else {
|
435
|
-
command.command("build [filters]");
|
436
|
-
}
|
437
|
-
} else {
|
438
|
-
if (isDefault) {
|
439
|
-
command.argument("[entries]", buildEntriesDescription);
|
440
|
-
} else {
|
441
|
-
command.command("build [entries]");
|
442
|
-
}
|
443
|
-
}
|
444
|
-
command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
|
445
|
-
if (!BUILDER_TYPES.includes(v)) {
|
446
|
-
throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
|
447
|
-
}
|
448
|
-
return String(v);
|
449
|
-
}, "esbuild").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", entriesDescription).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(
|
450
|
-
"--minType <MINTYPE>",
|
451
|
-
'The type of minify, support "builder" and "terser".',
|
452
|
-
(v) => {
|
453
|
-
if (!["builder", "terser"].includes(v)) {
|
454
|
-
throw new Error('The value of `minType` must be "builder" or "terser"');
|
455
|
-
}
|
456
|
-
return String(v);
|
457
|
-
}
|
458
|
-
).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
|
459
|
-
"-om, --onlyMin",
|
460
|
-
"Only output minify files, but dts files will still be output, it only replaces the js files.",
|
461
|
-
parseBoolean
|
462
|
-
).option("--tsconfig <TSCONFIG>", "The path of the tsconfig file which is used to generate js and dts files.", String).option("--dtsconfig <DTSCONFIG>", "The path of the tsconfig file which is used to generate dts files.", String).option("-w, --watch", "Watch the file changes.", parseBoolean).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async (commandFiltersOrEntries, options) => {
|
463
|
-
let {
|
464
|
-
type,
|
465
|
-
outdir,
|
466
|
-
watch,
|
467
|
-
silent,
|
468
|
-
verbose,
|
469
|
-
entries: optionEntries,
|
470
|
-
external,
|
471
|
-
noJs: withoutJs,
|
472
|
-
noDts: withoutDts,
|
473
|
-
noMin: withoutMin,
|
474
|
-
minType: minifyType,
|
475
|
-
noClean,
|
476
|
-
onlyMin,
|
477
|
-
tsconfig,
|
478
|
-
dtsconfig
|
479
|
-
} = options;
|
480
|
-
const resolvedType = type ?? DEFAULT_BUILDER_TYPE;
|
481
|
-
if (!withoutJs) {
|
482
|
-
await checkDependency(BUILDER_TYPE_PACKAGE_NAME_MAP[resolvedType]);
|
483
|
-
if (minifyType === "builder") {
|
484
|
-
minifyType = resolvedType;
|
485
|
-
}
|
486
|
-
}
|
487
|
-
if (!withoutMin) {
|
488
|
-
await checkDependency(
|
489
|
-
{
|
490
|
-
...BUILDER_TYPE_PACKAGE_NAME_MAP,
|
491
|
-
terser: "@rollup/plugin-terser"
|
492
|
-
}[resolvedType]
|
493
|
-
);
|
494
|
-
}
|
495
|
-
let shouldPassThrough = false;
|
496
|
-
const passThroughOptions = process.argv.reduce(
|
497
|
-
(acc, value) => {
|
498
|
-
if (shouldPassThrough) {
|
499
|
-
acc.push(value);
|
500
|
-
}
|
501
|
-
if (value === "--") {
|
502
|
-
shouldPassThrough = true;
|
503
|
-
}
|
504
|
-
return acc;
|
505
|
-
},
|
506
|
-
[]
|
507
|
-
);
|
508
|
-
const { build } = loadConfig();
|
509
|
-
silent = silent ?? build?.silent ?? false;
|
510
|
-
if (withoutMin && onlyMin) {
|
511
|
-
throw new Error("Cannot use both --without-minify and --only-minify");
|
512
|
-
}
|
513
|
-
if (onlyMin && withoutJs) {
|
514
|
-
throw new Error("Cannot use --without-js and --only-minify at the same time");
|
515
|
-
}
|
516
|
-
let entries = [
|
517
|
-
optionEntries,
|
518
|
-
IS_WORKSPACE ? void 0 : commandFiltersOrEntries
|
519
|
-
].filter(Boolean).join(",");
|
520
|
-
if (entries.length === 0) {
|
521
|
-
entries = void 0;
|
522
|
-
}
|
523
|
-
const env = {
|
524
|
-
...process.env,
|
525
|
-
JIEK_BUILDER: type,
|
526
|
-
JIEK_OUT_DIR: outdir,
|
527
|
-
JIEK_CLEAN: String(!noClean),
|
528
|
-
JIEK_ENTRIES: entries,
|
529
|
-
JIEK_EXTERNAL: external,
|
530
|
-
JIEK_WITHOUT_JS: String(withoutJs),
|
531
|
-
JIEK_WITHOUT_DTS: String(withoutDts),
|
532
|
-
JIEK_WITHOUT_MINIFY: String(withoutMin),
|
533
|
-
JIEK_ONLY_MINIFY: String(onlyMin),
|
534
|
-
JIEK_MINIFY_TYPE: minifyType,
|
535
|
-
JIEK_TSCONFIG: tsconfig,
|
536
|
-
JIEK_DTSCONFIG: dtsconfig
|
537
|
-
};
|
538
|
-
const multiBars = new MultiBar({
|
539
|
-
clearOnComplete: false,
|
540
|
-
hideCursor: true,
|
541
|
-
format: "- {bar} | {status} | {pkgName} | {input} | {message}"
|
542
|
-
}, Presets.shades_classic);
|
543
|
-
const buildPackage = async ({
|
544
|
-
wd,
|
545
|
-
value = {}
|
546
|
-
}) => {
|
547
|
-
if (Object.keys(value).length === 0) {
|
548
|
-
throw new Error("no package found");
|
549
|
-
}
|
550
|
-
const wdNodeModules = path.resolve(wd, "node_modules");
|
551
|
-
if (!fs.existsSync(wdNodeModules)) {
|
552
|
-
fs.mkdirSync(wdNodeModules);
|
553
|
-
}
|
554
|
-
const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
|
555
|
-
if (!fs.existsSync(jiekTempDir())) {
|
556
|
-
fs.mkdirSync(jiekTempDir());
|
557
|
-
}
|
558
|
-
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
559
|
-
let i = 0;
|
560
|
-
await Promise.all(
|
561
|
-
Object.entries(value).map(async ([dir, manifest]) => {
|
562
|
-
if (!manifest.name) {
|
563
|
-
throw new Error("package.json must have a name field");
|
564
|
-
}
|
565
|
-
const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
|
566
|
-
const configFile = jiekTempDir(
|
567
|
-
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
568
|
-
);
|
569
|
-
fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
570
|
-
const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
|
571
|
-
if (tsRegisterName) {
|
572
|
-
command2.unshift(`node -r ${tsRegisterName}`);
|
573
|
-
}
|
574
|
-
if (watch) {
|
575
|
-
command2.push("--watch");
|
576
|
-
}
|
577
|
-
command2.push(...passThroughOptions);
|
578
|
-
const child = execaCommand(command2.join(" "), {
|
579
|
-
ipc: true,
|
580
|
-
cwd: dir,
|
581
|
-
env: {
|
582
|
-
...env,
|
583
|
-
JIEK_NAME: manifest.name,
|
584
|
-
JIEK_ROOT: wd
|
585
|
-
}
|
586
|
-
});
|
587
|
-
const bars = {};
|
588
|
-
const times = {};
|
589
|
-
const locks = {};
|
590
|
-
let inputMaxLen = 10;
|
591
|
-
child.on("message", (e) => {
|
592
|
-
if (e.type === "debug")
|
593
|
-
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
594
|
-
});
|
595
|
-
!silent && child.on("message", (e) => {
|
596
|
-
if (e.type === "init") {
|
597
|
-
const { leafMap, targetsLength } = e.data;
|
598
|
-
const leafs = Array.from(leafMap.entries()).flatMap(
|
599
|
-
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
600
|
-
input,
|
601
|
-
path: path2,
|
602
|
-
conditions
|
603
|
-
}))
|
604
|
-
);
|
605
|
-
let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
|
606
|
-
if (watch) {
|
607
|
-
initMessage += " and watching...";
|
608
|
-
}
|
609
|
-
console.log(initMessage);
|
610
|
-
leafs.forEach(({ input }) => {
|
611
|
-
inputMaxLen = Math.max(inputMaxLen, input.length);
|
612
|
-
});
|
613
|
-
leafs.forEach(({ input, path: path2 }) => {
|
614
|
-
const key = `${input}:${path2}`;
|
615
|
-
if (bars[key])
|
616
|
-
return;
|
617
|
-
bars[key] = multiBars.create(50, 0, {
|
618
|
-
pkgName: manifest.name,
|
619
|
-
input: input.padEnd(inputMaxLen + 5),
|
620
|
-
status: "waiting".padEnd(10)
|
621
|
-
}, {
|
622
|
-
barsize: 20,
|
623
|
-
linewrap: true
|
624
|
-
});
|
625
|
-
});
|
626
|
-
}
|
627
|
-
if (e.type === "progress") {
|
628
|
-
const {
|
629
|
-
path: path2,
|
630
|
-
tags,
|
631
|
-
input,
|
632
|
-
event,
|
633
|
-
message
|
634
|
-
} = e.data;
|
635
|
-
const bar = bars[`${input}:${path2}`];
|
636
|
-
if (!bar)
|
637
|
-
return;
|
638
|
-
const time = times[`${input}:${path2}`];
|
639
|
-
bar.update(
|
640
|
-
{
|
641
|
-
start: 0,
|
642
|
-
resolve: 20,
|
643
|
-
end: 50
|
644
|
-
}[event ?? "start"] ?? 0,
|
645
|
-
{
|
646
|
-
input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
|
647
|
-
status: event?.padEnd(10),
|
648
|
-
message: `${tags?.join(", ")}: ${message}`
|
649
|
-
}
|
650
|
-
);
|
651
|
-
}
|
652
|
-
if (e.type === "watchChange") {
|
653
|
-
const {
|
654
|
-
path: path2,
|
655
|
-
input
|
656
|
-
} = e.data;
|
657
|
-
const key = `${input}:${path2}`;
|
658
|
-
const bar = bars[key];
|
659
|
-
if (!bar)
|
660
|
-
return;
|
661
|
-
let time = times[key] ?? 1;
|
662
|
-
if (!locks[key]) {
|
663
|
-
time += 1;
|
664
|
-
times[key] = time;
|
665
|
-
setTimeout(() => {
|
666
|
-
locks[key] = false;
|
667
|
-
}, 100);
|
668
|
-
bar.update(0, {
|
669
|
-
input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
|
670
|
-
status: "watching".padEnd(10),
|
671
|
-
message: "watching..."
|
672
|
-
});
|
673
|
-
}
|
674
|
-
locks[key] = true;
|
675
|
-
}
|
676
|
-
});
|
677
|
-
await new Promise((resolve, reject) => {
|
678
|
-
let errorStr = "";
|
679
|
-
child.stderr?.on("data", (data) => {
|
680
|
-
errorStr += data;
|
681
|
-
});
|
682
|
-
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
|
683
|
-
${errorStr}`)));
|
684
|
-
verbose && child.stdout?.pipe(process.stdout);
|
685
|
-
});
|
686
|
-
})
|
687
|
-
);
|
688
|
-
};
|
689
|
-
const commandFilters = IS_WORKSPACE ? commandFiltersOrEntries : void 0;
|
690
|
-
const filters = [
|
691
|
-
.../* @__PURE__ */ new Set([
|
692
|
-
...program.getOptionValue("filter")?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? [],
|
693
|
-
...commandFilters?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? []
|
694
|
-
])
|
695
|
-
];
|
696
|
-
try {
|
697
|
-
if (filters.length > 0) {
|
698
|
-
const packages = await filterPackagesGraph(filters);
|
699
|
-
await Promise.all(packages.map(buildPackage));
|
700
|
-
} else {
|
701
|
-
await buildPackage(await getSelectedProjectsGraph());
|
702
|
-
}
|
703
|
-
} finally {
|
704
|
-
multiBars.stop();
|
705
|
-
}
|
706
|
-
});
|
707
|
-
|
708
|
-
program.parse(process.argv);
|