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