jiek 2.2.6 → 2.2.7-alpha.3
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/bin/build.cjs +2 -0
- package/bin/index.cjs +2 -0
- package/bin-helper/index.cjs +31 -0
- package/bin-helper/index.d.cts +1 -0
- package/bin-helper/index.d.ts +1 -0
- package/bin-helper/package.json +5 -1
- package/dist/.internal/.chunks/getWD.D6wq8Qc2.js +95 -0
- package/dist/.internal/.chunks/getWD.ZF0avqDB.cjs +105 -0
- package/dist/{cli.js → .internal/.chunks/index.B6RQz1DZ.js} +1 -735
- package/dist/{cli.cjs → .internal/.chunks/index.DlHFuTjM.cjs} +1 -757
- package/dist/.internal/.chunks/jiek_create-require.CWFWNQHj.cjs +5 -0
- package/dist/.internal/.chunks/jiek_create-require.CxSGbkTB.js +5 -0
- package/dist/.internal/bin/parseArgv.cjs +33 -0
- package/dist/.internal/bin/parseArgv.d.cts +5 -0
- package/dist/.internal/bin/parseArgv.d.ts +5 -0
- package/dist/.internal/bin/parseArgv.js +27 -0
- package/dist/.internal/bridge.cjs +12 -0
- package/dist/.internal/bridge.d.cts +39 -0
- package/dist/.internal/bridge.d.ts +39 -0
- package/dist/.internal/bridge.js +9 -0
- package/dist/.internal/commands/build/analyzer.cjs +201 -0
- package/dist/.internal/commands/build/analyzer.d.cts +30 -0
- package/dist/.internal/commands/build/analyzer.d.ts +30 -0
- package/dist/.internal/commands/build/analyzer.js +195 -0
- package/dist/.internal/commands/descriptions.cjs +21 -0
- package/dist/.internal/commands/descriptions.d.cts +5 -0
- package/dist/.internal/commands/descriptions.d.ts +5 -0
- package/dist/.internal/commands/descriptions.js +17 -0
- package/dist/.internal/commands/meta.cjs +16 -0
- package/dist/.internal/commands/meta.d.cts +3 -0
- package/dist/.internal/commands/meta.d.ts +3 -0
- package/dist/.internal/commands/meta.js +15 -0
- package/dist/.internal/commands/utils/optionParser.cjs +8 -0
- package/dist/.internal/commands/utils/optionParser.d.cts +3 -0
- package/dist/.internal/commands/utils/optionParser.d.ts +3 -0
- package/dist/.internal/commands/utils/optionParser.js +6 -0
- package/dist/.internal/rollup/base.cjs +10 -0
- package/dist/{cli-only-build.d.cts → .internal/rollup/base.d.cts} +8 -15
- package/dist/{cli-only-build.d.ts → .internal/rollup/base.d.ts} +8 -15
- package/dist/.internal/rollup/base.js +7 -0
- package/dist/.internal/rollup/bundle-analyzer.cjs +51 -0
- package/dist/.internal/rollup/bundle-analyzer.d.cts +92 -0
- package/dist/.internal/rollup/bundle-analyzer.d.ts +92 -0
- package/dist/.internal/rollup/bundle-analyzer.js +45 -0
- package/dist/.internal/server.cjs +33 -0
- package/dist/.internal/server.d.cts +8 -0
- package/dist/.internal/server.d.ts +8 -0
- package/dist/.internal/server.js +27 -0
- package/dist/.internal/utils/checkDependency.cjs +39 -0
- package/dist/.internal/utils/checkDependency.d.cts +3 -0
- package/dist/.internal/utils/checkDependency.d.ts +3 -0
- package/dist/.internal/utils/checkDependency.js +34 -0
- package/dist/.internal/utils/filterSupport.cjs +20 -0
- package/dist/.internal/utils/filterSupport.d.cts +15 -0
- package/dist/.internal/utils/filterSupport.d.ts +15 -0
- package/dist/.internal/utils/filterSupport.js +10 -0
- package/dist/.internal/utils/getInternalModuleName.cjs +5 -0
- package/dist/.internal/utils/getInternalModuleName.d.cts +3 -0
- package/dist/.internal/utils/getInternalModuleName.d.ts +3 -0
- package/dist/.internal/utils/getInternalModuleName.js +3 -0
- package/dist/.internal/utils/getRoot.cjs +17 -0
- package/dist/.internal/utils/getRoot.d.cts +3 -0
- package/dist/.internal/utils/getRoot.d.ts +3 -0
- package/dist/.internal/utils/getRoot.js +11 -0
- package/dist/.internal/utils/getWD.cjs +15 -0
- package/dist/.internal/utils/getWD.d.cts +6 -0
- package/dist/.internal/utils/getWD.d.ts +6 -0
- package/dist/.internal/utils/getWD.js +10 -0
- package/dist/.internal/utils/intersection.cjs +5 -0
- package/dist/.internal/utils/intersection.d.cts +3 -0
- package/dist/.internal/utils/intersection.d.ts +3 -0
- package/dist/.internal/utils/intersection.js +3 -0
- package/dist/.internal/utils/loadConfig.cjs +100 -0
- package/dist/.internal/utils/loadConfig.d.cts +10 -0
- package/dist/.internal/utils/loadConfig.d.ts +10 -0
- package/dist/.internal/utils/loadConfig.js +94 -0
- package/dist/.internal/utils/recursiveListFiles.cjs +19 -0
- package/dist/.internal/utils/recursiveListFiles.d.cts +3 -0
- package/dist/.internal/utils/recursiveListFiles.d.ts +3 -0
- package/dist/.internal/utils/recursiveListFiles.js +13 -0
- package/dist/.internal/utils/resolveExports.cjs +118 -0
- package/dist/.internal/utils/resolveExports.d.cts +26 -0
- package/dist/.internal/utils/resolveExports.d.ts +26 -0
- package/dist/.internal/utils/resolveExports.js +111 -0
- package/dist/.internal/utils/ts.cjs +68 -0
- package/dist/.internal/utils/ts.d.cts +3 -0
- package/dist/.internal/utils/ts.d.ts +3 -0
- package/dist/.internal/utils/ts.js +62 -0
- package/dist/.internal/utils/tsRegister.cjs +25 -0
- package/dist/.internal/utils/tsRegister.d.cts +3 -0
- package/dist/.internal/utils/tsRegister.d.ts +3 -0
- package/dist/.internal/utils/tsRegister.js +26 -0
- package/dist/bin/build.cjs +515 -0
- package/dist/bin/index.cjs +497 -0
- package/dist/index.d.cts +12 -114
- package/dist/index.d.ts +12 -114
- package/dist/rollup/index.cjs +280 -4573
- package/dist/rollup/index.d.cts +7 -1
- package/dist/rollup/index.d.ts +7 -1
- package/dist/rollup/index.js +268 -4558
- package/package.json +20 -26
- package/src/bin/build.cts +11 -0
- package/src/bin/index.cts +6 -0
- package/src/bridge.ts +1 -1
- package/src/commands/base.ts +3 -3
- package/src/commands/build/analyzer.ts +5 -5
- package/src/commands/build/client/analyzer.tsx +1 -1
- package/src/commands/build/client/index.ts +5 -7
- package/src/commands/build.ts +226 -211
- package/src/commands/meta.ts +1 -1
- package/src/commands/publish.ts +112 -32
- package/src/index.ts +6 -1
- package/src/rollup/base.ts +2 -2
- package/src/rollup/index.ts +321 -124
- package/src/rollup/plugins/with-external.ts +23 -0
- package/src/rollup/utils/externalResolver.ts +20 -8
- package/src/utils/checkDependency.ts +1 -1
- package/src/utils/filterSupport.ts +17 -16
- package/src/utils/getInternalModuleName.ts +5 -0
- package/src/utils/intersection.ts +1 -0
- package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
- package/src/utils/{getExports.ts → resolveExports.ts} +16 -14
- package/bin/jiek-build.js +0 -16
- package/bin/jiek.js +0 -13
- package/bin-helper.cjs +0 -43
- package/cli/package.json +0 -1
- package/cli-only-build/package.json +0 -1
- package/dist/cli-only-build.cjs +0 -977
- package/dist/cli-only-build.js +0 -969
- package/dist/cli.d.cts +0 -14
- package/dist/cli.d.ts +0 -14
- package/src/bin/build.ts +0 -0
- package/src/cli-only-build.ts +0 -11
- package/src/cli.ts +0 -6
- /package/{bin-helper.js → bin-helper/index.js} +0 -0
- /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
package/dist/cli-only-build.js
DELETED
@@ -1,969 +0,0 @@
|
|
1
|
-
import { createRequire } from 'node:module';
|
2
|
-
import fs, { existsSync, mkdirSync, writeFileSync, statSync } from 'node:fs';
|
3
|
-
import path from 'node:path';
|
4
|
-
import { program } from 'commander';
|
5
|
-
import { load } from 'js-yaml';
|
6
|
-
import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
|
7
|
-
import process$1 from 'node:process';
|
8
|
-
import { MultiBar, Presets } from 'cli-progress';
|
9
|
-
import { execaCommand } from 'execa';
|
10
|
-
import { execSync } from 'node:child_process';
|
11
|
-
import { confirm } from '@inquirer/prompts';
|
12
|
-
import Koa from 'koa';
|
13
|
-
|
14
|
-
var require = /* @__PURE__ */ createRequire(import.meta.url);
|
15
|
-
|
16
|
-
let root;
|
17
|
-
function getRoot() {
|
18
|
-
if (root) return root;
|
19
|
-
const rootOption = process.env.JIEK_ROOT;
|
20
|
-
root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
|
21
|
-
return root;
|
22
|
-
}
|
23
|
-
|
24
|
-
let wd;
|
25
|
-
let notWorkspace$1 = false;
|
26
|
-
function getWD() {
|
27
|
-
if (wd) return { wd, notWorkspace: notWorkspace$1 };
|
28
|
-
const root = getRoot();
|
29
|
-
if (root !== void 0) {
|
30
|
-
const isWorkspace = isWorkspaceDir(root, type$1);
|
31
|
-
notWorkspace$1 = !isWorkspace;
|
32
|
-
wd = root;
|
33
|
-
return { wd, notWorkspace: notWorkspace$1 };
|
34
|
-
}
|
35
|
-
try {
|
36
|
-
wd = getWorkspaceDir(type$1);
|
37
|
-
} catch (e) {
|
38
|
-
if ("message" in e && e.message === "workspace root not found") {
|
39
|
-
wd = root ?? process.cwd();
|
40
|
-
notWorkspace$1 = true;
|
41
|
-
} else {
|
42
|
-
throw e;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
return { wd, notWorkspace: notWorkspace$1 };
|
46
|
-
}
|
47
|
-
|
48
|
-
let type$1 = "";
|
49
|
-
try {
|
50
|
-
require.resolve("@pnpm/filter-workspace-packages");
|
51
|
-
type$1 = "pnpm";
|
52
|
-
} catch {
|
53
|
-
}
|
54
|
-
async function filterPackagesGraph(filters) {
|
55
|
-
return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
|
56
|
-
}
|
57
|
-
async function getSelectedProjectsGraph(filter = program.getOptionValue("filter")) {
|
58
|
-
const { wd, notWorkspace } = getWD();
|
59
|
-
let root = getRoot();
|
60
|
-
if (notWorkspace) {
|
61
|
-
return {
|
62
|
-
wd,
|
63
|
-
root,
|
64
|
-
value: {
|
65
|
-
[wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
|
66
|
-
}
|
67
|
-
};
|
68
|
-
}
|
69
|
-
if (type$1 === "pnpm") {
|
70
|
-
const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
|
71
|
-
const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
|
72
|
-
const pnpmWorkspace = load(pnpmWorkspaceFileContent);
|
73
|
-
if (root === wd && !filter) {
|
74
|
-
throw new Error("root path is workspace root, please provide a filter");
|
75
|
-
}
|
76
|
-
if (root === void 0) {
|
77
|
-
root = process.cwd();
|
78
|
-
}
|
79
|
-
if (root !== wd && !filter) {
|
80
|
-
const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
|
81
|
-
if (!packageJSONIsExist) {
|
82
|
-
throw new Error("root path is not workspace root, please provide a filter");
|
83
|
-
}
|
84
|
-
const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
|
85
|
-
if (!packageJSON.name) {
|
86
|
-
throw new Error("root path is not workspace root, please provide a filter");
|
87
|
-
}
|
88
|
-
filter = packageJSON.name;
|
89
|
-
}
|
90
|
-
const { filterPackagesFromDir } = await import('@pnpm/filter-workspace-packages');
|
91
|
-
const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
|
92
|
-
filter: filter ?? "",
|
93
|
-
followProdDepsOnly: true
|
94
|
-
}], {
|
95
|
-
prefix: root,
|
96
|
-
workspaceDir: wd,
|
97
|
-
patterns: pnpmWorkspace.packages
|
98
|
-
});
|
99
|
-
return {
|
100
|
-
wd,
|
101
|
-
root,
|
102
|
-
value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
|
103
|
-
acc[key] = value.package.manifest;
|
104
|
-
return acc;
|
105
|
-
}, {})
|
106
|
-
};
|
107
|
-
}
|
108
|
-
throw new Error(`not supported package manager ${type$1}`);
|
109
|
-
}
|
110
|
-
|
111
|
-
var name = "jiek";
|
112
|
-
var type = "module";
|
113
|
-
var version = "2.2.5-alpha.1";
|
114
|
-
var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
|
115
|
-
var author = "YiJie <yijie4188@gmail.com>";
|
116
|
-
var homepage = "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme";
|
117
|
-
var repository = {
|
118
|
-
url: "nwylzw/jiek",
|
119
|
-
directory: "packages/jiek"
|
120
|
-
};
|
121
|
-
var bugs = "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek";
|
122
|
-
var keywords = [
|
123
|
-
"cli",
|
124
|
-
"zero-config",
|
125
|
-
"bundler",
|
126
|
-
"library",
|
127
|
-
"monorepo",
|
128
|
-
"builder",
|
129
|
-
"rollup",
|
130
|
-
"workspace"
|
131
|
-
];
|
132
|
-
var exports = {
|
133
|
-
"./package.json": "./package.json",
|
134
|
-
".": "./src/index.ts",
|
135
|
-
"./bin-helper": {
|
136
|
-
require: "./bin-helper.cjs",
|
137
|
-
"default": "./bin-helper.js"
|
138
|
-
},
|
139
|
-
"./cli": "./src/cli.ts",
|
140
|
-
"./cli-only-build": "./src/cli-only-build.ts",
|
141
|
-
"./rollup": "./src/rollup/index.ts"
|
142
|
-
};
|
143
|
-
var imports = {
|
144
|
-
"#~/*": [
|
145
|
-
"./src/*",
|
146
|
-
"./src/*/index.ts",
|
147
|
-
"./src/*/index.tsx"
|
148
|
-
]
|
149
|
-
};
|
150
|
-
var bin = {
|
151
|
-
jiek: "bin/jiek.js",
|
152
|
-
jk: "bin/jiek.js",
|
153
|
-
"jiek-build": "bin/jiek-build.js",
|
154
|
-
jb: "bin/jiek-build.js"
|
155
|
-
};
|
156
|
-
var files = [
|
157
|
-
"LICENSE",
|
158
|
-
"README.md",
|
159
|
-
"bin",
|
160
|
-
"bin-helper.cjs",
|
161
|
-
"bin-helper.js",
|
162
|
-
"dist",
|
163
|
-
"src"
|
164
|
-
];
|
165
|
-
var scripts = {
|
166
|
-
prepublish: "pnpm test && jb -nm && jk",
|
167
|
-
postpublish: "jk",
|
168
|
-
test: "vitest run"
|
169
|
-
};
|
170
|
-
var peerDependencies = {
|
171
|
-
"@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
|
172
|
-
"@rollup/plugin-terser": "^0.4.4",
|
173
|
-
"esbuild-register": "^3.5.0",
|
174
|
-
postcss: "^8.4.47",
|
175
|
-
"rollup-plugin-esbuild": "^6.1.0",
|
176
|
-
"rollup-plugin-postcss": "^4.0.2",
|
177
|
-
"rollup-plugin-swc3": "^0.12.1",
|
178
|
-
typescript: "^4.0.0||^5.0.0",
|
179
|
-
"vite-bundle-analyzer": "0.16.0-beta.1"
|
180
|
-
};
|
181
|
-
var dependencies = {
|
182
|
-
"@inquirer/prompts": "^7.2.0",
|
183
|
-
"@jiek/pkger": "workspace:^",
|
184
|
-
"@jiek/rollup-plugin-dts": "^6.2.1",
|
185
|
-
"@jiek/utils": "workspace:^",
|
186
|
-
"@rollup/plugin-commonjs": "^28.0.0",
|
187
|
-
"@rollup/plugin-inject": "^5.0.5",
|
188
|
-
"@rollup/plugin-json": "^6.0.1",
|
189
|
-
"@rollup/plugin-node-resolve": "^15.3.0",
|
190
|
-
"cli-progress": "^3.12.0",
|
191
|
-
commander: "^12.0.0",
|
192
|
-
"detect-indent": "^6.1.0",
|
193
|
-
execa: "~9.3.1",
|
194
|
-
"js-yaml": "^4.1.0",
|
195
|
-
"jsonc-parser": "^3.2.1",
|
196
|
-
koa: "^2.15.3",
|
197
|
-
rollup: "^4.0.0"
|
198
|
-
};
|
199
|
-
var devDependencies = {
|
200
|
-
"@npm/types": "^1.0.2",
|
201
|
-
"@pnpm/filter-workspace-packages": "^7.2.13",
|
202
|
-
"@pnpm/workspace.pkgs-graph": "^2.0.15",
|
203
|
-
"@rollup/plugin-terser": "^0.4.4",
|
204
|
-
"@types/cli-progress": "^3.11.5",
|
205
|
-
"@types/inquirer": "^9.0.7",
|
206
|
-
"@types/js-yaml": "^4.0.9",
|
207
|
-
"@types/koa": "^2.15.0",
|
208
|
-
"@types/micromatch": "^4.0.6",
|
209
|
-
"@types/react": "^18.3.14",
|
210
|
-
"esbuild-register": "^3.5.0",
|
211
|
-
micromatch: "^4.0.5",
|
212
|
-
"node-sass": "^9.0.0",
|
213
|
-
postcss: "^8.4.47",
|
214
|
-
"rollup-plugin-esbuild": "^6.1.0",
|
215
|
-
"rollup-plugin-postcss": "^4.0.2",
|
216
|
-
"rollup-plugin-swc3": "^0.12.1",
|
217
|
-
"vite-bundle-analyzer": "0.16.0-beta.1"
|
218
|
-
};
|
219
|
-
var pkg = {
|
220
|
-
name: name,
|
221
|
-
type: type,
|
222
|
-
version: version,
|
223
|
-
description: description$1,
|
224
|
-
author: author,
|
225
|
-
homepage: homepage,
|
226
|
-
repository: repository,
|
227
|
-
bugs: bugs,
|
228
|
-
keywords: keywords,
|
229
|
-
exports: exports,
|
230
|
-
imports: imports,
|
231
|
-
bin: bin,
|
232
|
-
files: files,
|
233
|
-
scripts: scripts,
|
234
|
-
peerDependencies: peerDependencies,
|
235
|
-
dependencies: dependencies,
|
236
|
-
devDependencies: devDependencies
|
237
|
-
};
|
238
|
-
|
239
|
-
const entriesDescription = `
|
240
|
-
Specify the build entry-points of the package.json's 'exports' field.
|
241
|
-
Support glob pattern and array.
|
242
|
-
.e.g. '.', './*', './sub/*', './a,./b'.
|
243
|
-
`.trim();
|
244
|
-
const filterDescription = `
|
245
|
-
Filter the packages from the workspace.
|
246
|
-
Support fuzzy match and array.
|
247
|
-
.e.g. 'core,utils'.
|
248
|
-
`.trim();
|
249
|
-
const outdirDescription = `
|
250
|
-
The output directory of the build, which relative to the target subpackage root directory.
|
251
|
-
Support with variables: 'PKG_NAME',
|
252
|
-
.e.g. 'dist/{{PKG_NAME}}'.
|
253
|
-
`.trim();
|
254
|
-
|
255
|
-
const { notWorkspace } = getWD();
|
256
|
-
const IS_WORKSPACE = !notWorkspace;
|
257
|
-
|
258
|
-
program.name("jk/jiek").version(pkg.version).description(`${pkg.description} - Version ${pkg.version}`).option("-c, --config-path <configPath>", "Custom jiek config path").option("--env.<name>=<value>", "Set the environment variable.");
|
259
|
-
if (type$1 !== "" && IS_WORKSPACE) {
|
260
|
-
program.option("-f, --filter <filter>", filterDescription);
|
261
|
-
}
|
262
|
-
|
263
|
-
function Main() {
|
264
|
-
const { useState, useMemo, useEffect, useCallback } = React;
|
265
|
-
const [path, setPath] = useState(() => location.pathname.replace(/^\/ana\/?/, ""));
|
266
|
-
const [pkgName, entry] = useMemo(() => {
|
267
|
-
const pkgName2 = /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(path)?.[1];
|
268
|
-
return [
|
269
|
-
pkgName2,
|
270
|
-
pkgName2 != null ? path.replace(`${pkgName2}/`, "") : void 0
|
271
|
-
];
|
272
|
-
}, [path]);
|
273
|
-
const push = useCallback((newPath) => {
|
274
|
-
setPath(newPath);
|
275
|
-
document.title = `${document.title.replace(/ - \/.*/, "")} - /${newPath}`;
|
276
|
-
history.pushState(null, "", `/ana/${newPath}`);
|
277
|
-
}, []);
|
278
|
-
const filterModules = useCallback((startWith) => {
|
279
|
-
const modules = analyzeModule.filter((m) => m.filename.startsWith(startWith));
|
280
|
-
dispatchEvent(new CustomEvent("send:filter", { detail: { analyzeModule: modules } }));
|
281
|
-
}, []);
|
282
|
-
useEffect(() => {
|
283
|
-
if (path !== "") {
|
284
|
-
document.title = `${document.title.replace(/ - \/.*/, "")} - /${path}`;
|
285
|
-
} else {
|
286
|
-
document.title = document.title.replace(/ - \/.*/, "");
|
287
|
-
}
|
288
|
-
filterModules(path);
|
289
|
-
}, [path, filterModules]);
|
290
|
-
useEffect(() => {
|
291
|
-
const offGraphClick = listen("graph:click", ({ detail }) => {
|
292
|
-
if (!detail) return;
|
293
|
-
let root = detail.node;
|
294
|
-
while (root.parent) {
|
295
|
-
root = root.parent;
|
296
|
-
}
|
297
|
-
if (root.filename === path) return;
|
298
|
-
push(root.filename);
|
299
|
-
});
|
300
|
-
return () => {
|
301
|
-
offGraphClick();
|
302
|
-
};
|
303
|
-
}, [push]);
|
304
|
-
function listen(type, listener) {
|
305
|
-
window.addEventListener(type, listener);
|
306
|
-
return () => {
|
307
|
-
window.removeEventListener(type, listener);
|
308
|
-
};
|
309
|
-
}
|
310
|
-
return /* @__PURE__ */ React.createElement(
|
311
|
-
"div",
|
312
|
-
{
|
313
|
-
style: {
|
314
|
-
padding: "12px 55px"
|
315
|
-
}
|
316
|
-
},
|
317
|
-
"/",
|
318
|
-
/* @__PURE__ */ React.createElement(
|
319
|
-
"select",
|
320
|
-
{
|
321
|
-
style: {
|
322
|
-
appearance: "none",
|
323
|
-
border: "none",
|
324
|
-
background: "none"
|
325
|
-
},
|
326
|
-
value: pkgName,
|
327
|
-
onChange: (e) => push(e.target.value)
|
328
|
-
},
|
329
|
-
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
330
|
-
analyzeModule.map((m) => /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(m.filename)?.[1]).filter((v, i, a) => a.indexOf(v) === i).map((v) => /* @__PURE__ */ React.createElement("option", { key: v, value: v }, v))
|
331
|
-
),
|
332
|
-
pkgName != null && /* @__PURE__ */ React.createElement(React.Fragment, null, "/", /* @__PURE__ */ React.createElement(
|
333
|
-
"select",
|
334
|
-
{
|
335
|
-
style: {
|
336
|
-
appearance: "none",
|
337
|
-
border: "none",
|
338
|
-
background: "none"
|
339
|
-
},
|
340
|
-
value: entry,
|
341
|
-
onChange: (e) => push(`${pkgName}/${e.target.value}`)
|
342
|
-
},
|
343
|
-
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
344
|
-
analyzeModule.filter((m) => m.filename.startsWith(`${pkgName}/`)).map((m) => m.filename.replace(`${pkgName}/`, "")).filter((v, i, a) => a.indexOf(v) === i).map((v) => /* @__PURE__ */ React.createElement("option", { key: v, value: v }, v))
|
345
|
-
))
|
346
|
-
);
|
347
|
-
}
|
348
|
-
|
349
|
-
function render() {
|
350
|
-
CUSTOM_SIDE_BAR = true;
|
351
|
-
window.addEventListener("client:ready", () => setTimeout(() => {
|
352
|
-
window.dispatchEvent(
|
353
|
-
new CustomEvent("send:ui", {
|
354
|
-
detail: { type: "Main", Component: __REPLACE_INJECT__ }
|
355
|
-
})
|
356
|
-
);
|
357
|
-
}, 0));
|
358
|
-
}
|
359
|
-
const CLIENT_CUSTOM_RENDER_SCRIPT = [
|
360
|
-
Main.toString(),
|
361
|
-
render.toString().replace("__REPLACE_INJECT__", Main.name),
|
362
|
-
`(${render.name})()`
|
363
|
-
].join("\n");
|
364
|
-
|
365
|
-
function parseBoolean(v) {
|
366
|
-
if (v === void 0) return true;
|
367
|
-
return Boolean(v);
|
368
|
-
}
|
369
|
-
|
370
|
-
async function checkDependency(dependency) {
|
371
|
-
try {
|
372
|
-
require.resolve(dependency);
|
373
|
-
} catch {
|
374
|
-
console.error(`The package '${dependency}' is not installed, please install it first.`);
|
375
|
-
const { notWorkspace } = getWD();
|
376
|
-
const command = `pnpm add -${notWorkspace ? "" : "w"}D ${dependency}`;
|
377
|
-
if (await confirm({ message: `Do you want to add it now? (${command})` })) {
|
378
|
-
execSync(command, {
|
379
|
-
stdio: "inherit",
|
380
|
-
cwd: process$1.cwd(),
|
381
|
-
env: process$1.env
|
382
|
-
});
|
383
|
-
} else {
|
384
|
-
console.warn(`You can run the command '${command}' to install it manually.`);
|
385
|
-
process$1.exit(1);
|
386
|
-
}
|
387
|
-
}
|
388
|
-
}
|
389
|
-
|
390
|
-
const registerAnalyzerCommandOptions = (command) => command.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option(
|
391
|
-
"--ana.mode <MODE>",
|
392
|
-
'The mode of the bundle analyzer, support "static", "json" and "server".',
|
393
|
-
"server"
|
394
|
-
).option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
|
395
|
-
"--ana.size <SIZE>",
|
396
|
-
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
397
|
-
"parsed"
|
398
|
-
);
|
399
|
-
const useAnalyzer = async (options, server) => {
|
400
|
-
const modules = [];
|
401
|
-
let bundleAnalyzerModule;
|
402
|
-
const analyzer = options.ana ? {
|
403
|
-
dir: options["ana.dir"],
|
404
|
-
mode: options["ana.mode"],
|
405
|
-
open: options["ana.open"],
|
406
|
-
size: options["ana.size"]
|
407
|
-
} : void 0;
|
408
|
-
if (options.ana && ![
|
409
|
-
"stat",
|
410
|
-
"parsed",
|
411
|
-
"gzip"
|
412
|
-
].includes(analyzer?.size ?? "")) {
|
413
|
-
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
414
|
-
}
|
415
|
-
if (analyzer) {
|
416
|
-
await checkDependency("vite-bundle-analyzer");
|
417
|
-
bundleAnalyzerModule = await import('vite-bundle-analyzer');
|
418
|
-
}
|
419
|
-
const refreshAnalyzer = async (cwd, applyModules) => {
|
420
|
-
if (!(analyzer && server && bundleAnalyzerModule)) return;
|
421
|
-
if (analyzer.mode === "json") {
|
422
|
-
const anaDir = path.resolve(cwd, analyzer.dir);
|
423
|
-
if (!existsSync(anaDir)) {
|
424
|
-
mkdirSync(anaDir, { recursive: true });
|
425
|
-
}
|
426
|
-
const gitIgnorePath = path.resolve(anaDir, ".gitignore");
|
427
|
-
if (!existsSync(gitIgnorePath)) {
|
428
|
-
writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
429
|
-
}
|
430
|
-
const npmIgnorePath = path.resolve(anaDir, ".npmignore");
|
431
|
-
if (!existsSync(npmIgnorePath)) {
|
432
|
-
writeFileSync(npmIgnorePath, "*\n");
|
433
|
-
}
|
434
|
-
if (!statSync(anaDir).isDirectory()) {
|
435
|
-
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
436
|
-
}
|
437
|
-
}
|
438
|
-
const { renderView, injectHTMLTag } = bundleAnalyzerModule;
|
439
|
-
applyModules.forEach((m) => {
|
440
|
-
const index = modules.findIndex(({ filename }) => filename === m.filename);
|
441
|
-
if (index === -1) {
|
442
|
-
modules.push(m);
|
443
|
-
} else {
|
444
|
-
modules[index] = m;
|
445
|
-
}
|
446
|
-
});
|
447
|
-
let html = await renderView(modules, {
|
448
|
-
title: `Jiek Analyzer`,
|
449
|
-
mode: analyzer.size
|
450
|
-
});
|
451
|
-
html = injectHTMLTag({
|
452
|
-
html,
|
453
|
-
injectTo: "body",
|
454
|
-
descriptors: [
|
455
|
-
{ kind: "script", text: CLIENT_CUSTOM_RENDER_SCRIPT }
|
456
|
-
]
|
457
|
-
});
|
458
|
-
void server.renderTo("/ana", html);
|
459
|
-
};
|
460
|
-
return {
|
461
|
-
modules,
|
462
|
-
refreshAnalyzer,
|
463
|
-
ANALYZER_ENV: {
|
464
|
-
JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : void 0
|
465
|
-
}
|
466
|
-
};
|
467
|
-
};
|
468
|
-
|
469
|
-
const BUILDER_TYPES = ["esbuild", "swc"];
|
470
|
-
const BUILDER_TYPE_PACKAGE_NAME_MAP = {
|
471
|
-
esbuild: "rollup-plugin-esbuild",
|
472
|
-
swc: "rollup-plugin-swc3"
|
473
|
-
};
|
474
|
-
|
475
|
-
const createServer = (port, host) => {
|
476
|
-
const app = new Koa();
|
477
|
-
app.listen(port, host);
|
478
|
-
const streams = /* @__PURE__ */ new Map();
|
479
|
-
app.use(async (ctx) => {
|
480
|
-
let stream = streams.get(ctx.path);
|
481
|
-
if (stream == null) {
|
482
|
-
const maybeKey = streams.keys().find((p) => ctx.path.startsWith(p));
|
483
|
-
stream = maybeKey != null ? streams.get(maybeKey) : void 0;
|
484
|
-
}
|
485
|
-
if (stream != null) {
|
486
|
-
ctx.body = stream;
|
487
|
-
}
|
488
|
-
});
|
489
|
-
return {
|
490
|
-
port,
|
491
|
-
host,
|
492
|
-
rootUrl: `http://${host}:${port}`,
|
493
|
-
renderTo: async (path, stream) => {
|
494
|
-
streams.set(path, stream);
|
495
|
-
}
|
496
|
-
};
|
497
|
-
};
|
498
|
-
|
499
|
-
function packageIsExist(name) {
|
500
|
-
try {
|
501
|
-
require.resolve(name);
|
502
|
-
return true;
|
503
|
-
} catch (e) {
|
504
|
-
return false;
|
505
|
-
}
|
506
|
-
}
|
507
|
-
let tsRegisterName;
|
508
|
-
const registers = [
|
509
|
-
process.env.JIEK_TS_REGISTER,
|
510
|
-
"esbuild-register",
|
511
|
-
"@swc-node/register",
|
512
|
-
"ts-node/register"
|
513
|
-
].filter(Boolean);
|
514
|
-
for (const register of registers) {
|
515
|
-
if (packageIsExist(register)) {
|
516
|
-
tsRegisterName = register;
|
517
|
-
break;
|
518
|
-
}
|
519
|
-
}
|
520
|
-
|
521
|
-
let configName = "jiek.config";
|
522
|
-
function getConfigPath(root, dir) {
|
523
|
-
const isSupportTsLoader = !!tsRegisterName;
|
524
|
-
function configWithExtIsExist(ext) {
|
525
|
-
const filenames = [
|
526
|
-
path.resolve(process.cwd(), `${configName}.${ext}`),
|
527
|
-
path.resolve(process.cwd(), `.${configName}.${ext}`),
|
528
|
-
path.resolve(root, `${configName}.${ext}`),
|
529
|
-
path.resolve(root, `.${configName}.${ext}`)
|
530
|
-
];
|
531
|
-
if (dir) {
|
532
|
-
filenames.unshift(...[
|
533
|
-
path.resolve(dir, `${configName}.${ext}`),
|
534
|
-
path.resolve(dir, `.${configName}.${ext}`)
|
535
|
-
]);
|
536
|
-
}
|
537
|
-
for (const filename of filenames) {
|
538
|
-
if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
|
539
|
-
return filename;
|
540
|
-
}
|
541
|
-
}
|
542
|
-
return;
|
543
|
-
}
|
544
|
-
configName = configWithExtIsExist("js") ?? configName;
|
545
|
-
configName = configWithExtIsExist("json") ?? configName;
|
546
|
-
configName = configWithExtIsExist("yaml") ?? configName;
|
547
|
-
if (isSupportTsLoader) {
|
548
|
-
configName = configWithExtIsExist("ts") ?? configName;
|
549
|
-
}
|
550
|
-
return path.resolve(root, configName);
|
551
|
-
}
|
552
|
-
function loadConfig(dirOrOptions) {
|
553
|
-
let dir;
|
554
|
-
let root;
|
555
|
-
{
|
556
|
-
dir = dirOrOptions;
|
557
|
-
root = getWD().wd;
|
558
|
-
}
|
559
|
-
let configPath = program.getOptionValue("configPath");
|
560
|
-
if (!configPath) {
|
561
|
-
configPath = getConfigPath(root, dir);
|
562
|
-
} else {
|
563
|
-
if (!fs.existsSync(configPath)) {
|
564
|
-
throw new Error(`config file not found: ${configPath}`);
|
565
|
-
}
|
566
|
-
if (!path.isAbsolute(configPath)) {
|
567
|
-
configPath = path.resolve(root, configPath);
|
568
|
-
}
|
569
|
-
}
|
570
|
-
const ext = path.extname(configPath);
|
571
|
-
let module;
|
572
|
-
switch (ext) {
|
573
|
-
case ".js":
|
574
|
-
module = require(configPath);
|
575
|
-
break;
|
576
|
-
case ".json":
|
577
|
-
return require(configPath);
|
578
|
-
case ".yaml":
|
579
|
-
return load(fs.readFileSync(configPath, "utf-8"));
|
580
|
-
case ".ts":
|
581
|
-
if (tsRegisterName) {
|
582
|
-
require(tsRegisterName);
|
583
|
-
module = require(configPath);
|
584
|
-
break;
|
585
|
-
}
|
586
|
-
throw new Error(
|
587
|
-
"ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
|
588
|
-
);
|
589
|
-
case ".config":
|
590
|
-
module = {};
|
591
|
-
break;
|
592
|
-
default:
|
593
|
-
throw new Error(`unsupported config file type: ${ext}`);
|
594
|
-
}
|
595
|
-
if (!module) throw new Error("config file is empty");
|
596
|
-
return module.default ?? module;
|
597
|
-
}
|
598
|
-
|
599
|
-
const FILE_TEMPLATE = (manifest) => `
|
600
|
-
module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
|
601
|
-
`.trimStart();
|
602
|
-
const isDefault = process$1.env.JIEK_IS_ONLY_BUILD === "true";
|
603
|
-
const description = `
|
604
|
-
Build the package according to the 'exports' field from the package.json.
|
605
|
-
If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
|
606
|
-
${isDefault ? "This command is the default command." : ""}
|
607
|
-
`.trim();
|
608
|
-
let DEFAULT_BUILDER_TYPE;
|
609
|
-
Object.entries(BUILDER_TYPE_PACKAGE_NAME_MAP).forEach(([type, packageName]) => {
|
610
|
-
try {
|
611
|
-
require.resolve(packageName);
|
612
|
-
DEFAULT_BUILDER_TYPE = type;
|
613
|
-
} catch {
|
614
|
-
}
|
615
|
-
});
|
616
|
-
if (!DEFAULT_BUILDER_TYPE) {
|
617
|
-
DEFAULT_BUILDER_TYPE = "esbuild";
|
618
|
-
}
|
619
|
-
const buildFilterDescription = `
|
620
|
-
${filterDescription}
|
621
|
-
If you pass the --filter option, it will merge into the filters of the command.
|
622
|
-
`.trim();
|
623
|
-
const buildEntriesDescription = `
|
624
|
-
${entriesDescription}
|
625
|
-
If you pass the --entries option, it will merge into the entries of the command.
|
626
|
-
`.trim();
|
627
|
-
let command = isDefault ? (() => {
|
628
|
-
const c = program.name("jb/jiek-build").helpCommand(false);
|
629
|
-
if (IS_WORKSPACE) {
|
630
|
-
c.argument("[filters]", buildFilterDescription);
|
631
|
-
} else {
|
632
|
-
c.argument("[entries]", buildEntriesDescription);
|
633
|
-
}
|
634
|
-
return c;
|
635
|
-
})() : program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
|
636
|
-
command = command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
|
637
|
-
if (!BUILDER_TYPES.includes(v)) {
|
638
|
-
throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
|
639
|
-
}
|
640
|
-
return String(v);
|
641
|
-
}, "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("--noConvert", "Specify the `crossModuleConvertor` option to false.", parseBoolean).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(
|
642
|
-
"--minType <MINTYPE>",
|
643
|
-
'The type of minify, support "builder" and "terser".',
|
644
|
-
(v) => {
|
645
|
-
if (!["builder", "terser"].includes(v)) {
|
646
|
-
throw new Error('The value of `minType` must be "builder" or "terser"');
|
647
|
-
}
|
648
|
-
return String(v);
|
649
|
-
}
|
650
|
-
).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
|
651
|
-
"-om, --onlyMin",
|
652
|
-
"Only output minify files, but dts files will still be output, it only replaces the js files.",
|
653
|
-
parseBoolean
|
654
|
-
);
|
655
|
-
command = command.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);
|
656
|
-
command = command.option("-w, --watch", "Watch the file changes.", parseBoolean).option("-p, --port <PORT>", "The port of the server.", Number.parseInt, 8888);
|
657
|
-
command = registerAnalyzerCommandOptions(command);
|
658
|
-
command = command.option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean);
|
659
|
-
command.action(async (commandFiltersOrEntries, options) => {
|
660
|
-
let {
|
661
|
-
type,
|
662
|
-
outdir,
|
663
|
-
watch,
|
664
|
-
silent,
|
665
|
-
verbose,
|
666
|
-
entries: optionEntries,
|
667
|
-
external,
|
668
|
-
noConvert,
|
669
|
-
noJs: withoutJs,
|
670
|
-
noDts: withoutDts,
|
671
|
-
noMin: withoutMin,
|
672
|
-
minType: minifyType,
|
673
|
-
noClean,
|
674
|
-
onlyMin,
|
675
|
-
tsconfig,
|
676
|
-
dtsconfig
|
677
|
-
} = options;
|
678
|
-
const resolvedType = type ?? DEFAULT_BUILDER_TYPE;
|
679
|
-
if (!withoutJs) {
|
680
|
-
await checkDependency(BUILDER_TYPE_PACKAGE_NAME_MAP[resolvedType]);
|
681
|
-
if (minifyType === "builder") {
|
682
|
-
minifyType = resolvedType;
|
683
|
-
}
|
684
|
-
}
|
685
|
-
if (!withoutMin && minifyType === "terser") {
|
686
|
-
await checkDependency("@rollup/plugin-terser");
|
687
|
-
}
|
688
|
-
let shouldPassThrough = false;
|
689
|
-
const passThroughOptions = process$1.argv.reduce(
|
690
|
-
(acc, value) => {
|
691
|
-
if (shouldPassThrough) {
|
692
|
-
acc.push(value);
|
693
|
-
}
|
694
|
-
if (value === "--") {
|
695
|
-
shouldPassThrough = true;
|
696
|
-
}
|
697
|
-
return acc;
|
698
|
-
},
|
699
|
-
[]
|
700
|
-
);
|
701
|
-
const shouldCreateServer = [
|
702
|
-
options.ana === true && options["ana.mode"] === "server"
|
703
|
-
].some(Boolean);
|
704
|
-
const server = shouldCreateServer ? createServer(options.port, "localhost") : void 0;
|
705
|
-
const {
|
706
|
-
ANALYZER_ENV,
|
707
|
-
refreshAnalyzer
|
708
|
-
} = await useAnalyzer(options, server);
|
709
|
-
const { build } = loadConfig();
|
710
|
-
silent = silent ?? build?.silent ?? false;
|
711
|
-
if (withoutMin && onlyMin) {
|
712
|
-
throw new Error("Cannot use both --without-minify and --only-minify");
|
713
|
-
}
|
714
|
-
if (onlyMin && withoutJs) {
|
715
|
-
throw new Error("Cannot use --without-js and --only-minify at the same time");
|
716
|
-
}
|
717
|
-
let entries = [
|
718
|
-
optionEntries,
|
719
|
-
IS_WORKSPACE ? void 0 : commandFiltersOrEntries
|
720
|
-
].filter(Boolean).join(",");
|
721
|
-
if (entries.length === 0) {
|
722
|
-
entries = void 0;
|
723
|
-
}
|
724
|
-
const env = {
|
725
|
-
...ANALYZER_ENV,
|
726
|
-
JIEK_BUILDER: type,
|
727
|
-
JIEK_OUT_DIR: outdir,
|
728
|
-
JIEK_CLEAN: String(!noClean),
|
729
|
-
JIEK_ENTRIES: entries,
|
730
|
-
JIEK_EXTERNAL: external,
|
731
|
-
JIEK_CROSS_MODULE_CONVERTOR: String(!noConvert),
|
732
|
-
JIEK_WITHOUT_JS: String(withoutJs),
|
733
|
-
JIEK_WITHOUT_DTS: String(withoutDts),
|
734
|
-
JIEK_WITHOUT_MINIFY: String(withoutMin),
|
735
|
-
JIEK_ONLY_MINIFY: String(onlyMin),
|
736
|
-
JIEK_MINIFY_TYPE: minifyType,
|
737
|
-
JIEK_TSCONFIG: tsconfig,
|
738
|
-
JIEK_DTSCONFIG: dtsconfig,
|
739
|
-
...process$1.env
|
740
|
-
};
|
741
|
-
const multiBars = new MultiBar({
|
742
|
-
clearOnComplete: false,
|
743
|
-
hideCursor: true,
|
744
|
-
format: "- {bar} | {status} | {pkgName} | {input} | {message}"
|
745
|
-
}, Presets.shades_classic);
|
746
|
-
const buildPackage = async ({
|
747
|
-
wd,
|
748
|
-
value = {}
|
749
|
-
}) => {
|
750
|
-
if (Object.keys(value).length === 0) {
|
751
|
-
throw new Error("no package found");
|
752
|
-
}
|
753
|
-
const wdNodeModules = path.resolve(wd, "node_modules");
|
754
|
-
if (!existsSync(wdNodeModules)) {
|
755
|
-
mkdirSync(wdNodeModules);
|
756
|
-
}
|
757
|
-
const resolveByJiekTemp = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
|
758
|
-
const jiekTemp = resolveByJiekTemp();
|
759
|
-
if (!existsSync(jiekTemp)) {
|
760
|
-
try {
|
761
|
-
mkdirSync(jiekTemp);
|
762
|
-
} catch {
|
763
|
-
}
|
764
|
-
}
|
765
|
-
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
766
|
-
let i = 0;
|
767
|
-
await Promise.all(
|
768
|
-
Object.entries(value).map(async ([pkgCWD, manifest]) => {
|
769
|
-
if (manifest.name == null) {
|
770
|
-
throw new Error("package.json must have a name field");
|
771
|
-
}
|
772
|
-
const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
|
773
|
-
const configFile = resolveByJiekTemp(
|
774
|
-
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
775
|
-
);
|
776
|
-
writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
777
|
-
const command2 = [rollupBinaryPath, "--silent", "-c", configFile];
|
778
|
-
if (tsRegisterName != null) {
|
779
|
-
command2.unshift(`node -r ${tsRegisterName}`);
|
780
|
-
}
|
781
|
-
if (watch) {
|
782
|
-
command2.push("--watch");
|
783
|
-
}
|
784
|
-
command2.push(...passThroughOptions);
|
785
|
-
const child = execaCommand(command2.join(" "), {
|
786
|
-
ipc: true,
|
787
|
-
cwd: pkgCWD,
|
788
|
-
env: {
|
789
|
-
...env,
|
790
|
-
JIEK_NAME: manifest.name,
|
791
|
-
JIEK_ROOT: wd
|
792
|
-
}
|
793
|
-
});
|
794
|
-
const bars = {};
|
795
|
-
const times = {};
|
796
|
-
const locks = {};
|
797
|
-
let inputMaxLen = 10;
|
798
|
-
child.on("message", (e) => {
|
799
|
-
if (silent && [
|
800
|
-
"init",
|
801
|
-
"progress",
|
802
|
-
"watchChange"
|
803
|
-
].includes(e.type)) return;
|
804
|
-
switch (e.type) {
|
805
|
-
case "init": {
|
806
|
-
const { leafMap, targetsLength } = e.data;
|
807
|
-
const leafs = Array.from(leafMap.entries()).flatMap(
|
808
|
-
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
809
|
-
input,
|
810
|
-
path: path2,
|
811
|
-
conditions
|
812
|
-
}))
|
813
|
-
);
|
814
|
-
let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`;
|
815
|
-
if (watch) {
|
816
|
-
initMessage += " and watching...";
|
817
|
-
}
|
818
|
-
console.log(initMessage);
|
819
|
-
leafs.forEach(({ input }) => {
|
820
|
-
inputMaxLen = Math.max(inputMaxLen, input.length);
|
821
|
-
});
|
822
|
-
leafs.forEach(({ input, path: path2 }) => {
|
823
|
-
const key = `${input}:${path2}`;
|
824
|
-
if (bars[key]) return;
|
825
|
-
bars[key] = multiBars.create(50, 0, {
|
826
|
-
pkgName: manifest.name,
|
827
|
-
input: input.padEnd(inputMaxLen + 5),
|
828
|
-
status: "waiting".padEnd(10)
|
829
|
-
}, {
|
830
|
-
barsize: 20,
|
831
|
-
linewrap: true
|
832
|
-
});
|
833
|
-
});
|
834
|
-
break;
|
835
|
-
}
|
836
|
-
case "progress": {
|
837
|
-
const {
|
838
|
-
path: path2,
|
839
|
-
tags,
|
840
|
-
input,
|
841
|
-
event,
|
842
|
-
message
|
843
|
-
} = e.data;
|
844
|
-
const bar = bars[`${input}:${path2}`];
|
845
|
-
if (!bar) return;
|
846
|
-
const time = times[`${input}:${path2}`];
|
847
|
-
bar.update(
|
848
|
-
{
|
849
|
-
start: 0,
|
850
|
-
resolve: 20,
|
851
|
-
end: 50
|
852
|
-
}[event ?? "start"] ?? 0,
|
853
|
-
{
|
854
|
-
input: (time ? `${input}(x${time.toString().padStart(2, "0")})` : input).padEnd(inputMaxLen + 5),
|
855
|
-
status: event?.padEnd(10),
|
856
|
-
message: `${tags?.join(", ")}: ${message}`
|
857
|
-
}
|
858
|
-
);
|
859
|
-
break;
|
860
|
-
}
|
861
|
-
case "watchChange": {
|
862
|
-
const {
|
863
|
-
path: path2,
|
864
|
-
input
|
865
|
-
} = e.data;
|
866
|
-
const key = `${input}:${path2}`;
|
867
|
-
const bar = bars[key];
|
868
|
-
if (!bar) return;
|
869
|
-
let time = times[key] ?? 1;
|
870
|
-
if (!locks[key]) {
|
871
|
-
time += 1;
|
872
|
-
times[key] = time;
|
873
|
-
setTimeout(() => {
|
874
|
-
locks[key] = false;
|
875
|
-
}, 100);
|
876
|
-
bar.update(0, {
|
877
|
-
input: `${input}(x${time.toString().padStart(2, "0")})`.padEnd(inputMaxLen + 5),
|
878
|
-
status: "watching".padEnd(10),
|
879
|
-
message: "watching..."
|
880
|
-
});
|
881
|
-
}
|
882
|
-
locks[key] = true;
|
883
|
-
break;
|
884
|
-
}
|
885
|
-
case "modulesAnalyze": {
|
886
|
-
const {
|
887
|
-
data: {
|
888
|
-
type: type2,
|
889
|
-
modules: pkgModules
|
890
|
-
}
|
891
|
-
} = e;
|
892
|
-
void refreshAnalyzer(
|
893
|
-
pkgCWD,
|
894
|
-
pkgModules.map((m) => ({
|
895
|
-
...m,
|
896
|
-
type: type2,
|
897
|
-
filename: `${manifest.name}/${m.filename}`,
|
898
|
-
label: `${manifest.name}/${m.label}`
|
899
|
-
}))
|
900
|
-
);
|
901
|
-
break;
|
902
|
-
}
|
903
|
-
case "debug": {
|
904
|
-
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
905
|
-
break;
|
906
|
-
}
|
907
|
-
}
|
908
|
-
});
|
909
|
-
await new Promise((resolve, reject) => {
|
910
|
-
let errorStr = `rollup build failed
|
911
|
-
package name: ${manifest.name}
|
912
|
-
cwd: ${pkgCWD}
|
913
|
-
|
914
|
-
`;
|
915
|
-
child.stderr?.on("data", (data) => {
|
916
|
-
errorStr += data;
|
917
|
-
});
|
918
|
-
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(errorStr)));
|
919
|
-
verbose && child.stdout?.pipe(process$1.stdout);
|
920
|
-
});
|
921
|
-
})
|
922
|
-
);
|
923
|
-
};
|
924
|
-
const commandFilters = IS_WORKSPACE ? commandFiltersOrEntries : void 0;
|
925
|
-
const filters = [
|
926
|
-
.../* @__PURE__ */ new Set([
|
927
|
-
...program.getOptionValue("filter")?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? [],
|
928
|
-
...commandFilters?.split(",").map((s) => s.trim()).filter((s) => s.length > 0) ?? []
|
929
|
-
])
|
930
|
-
];
|
931
|
-
try {
|
932
|
-
if (filters.length > 0) {
|
933
|
-
const packages = await filterPackagesGraph(filters);
|
934
|
-
await Promise.all(packages.map(buildPackage));
|
935
|
-
} else {
|
936
|
-
await buildPackage(await getSelectedProjectsGraph());
|
937
|
-
}
|
938
|
-
} finally {
|
939
|
-
multiBars.stop();
|
940
|
-
!silent && console.log("Build complete");
|
941
|
-
}
|
942
|
-
});
|
943
|
-
|
944
|
-
const { argv } = process$1;
|
945
|
-
const env = {};
|
946
|
-
let isPassThrough = false;
|
947
|
-
const newArgv = argv.filter((arg) => {
|
948
|
-
if (isPassThrough) {
|
949
|
-
return true;
|
950
|
-
}
|
951
|
-
if (arg === "--") {
|
952
|
-
isPassThrough = true;
|
953
|
-
return false;
|
954
|
-
}
|
955
|
-
const m = /^--env\.(\w+)=(.*)$/.exec(arg);
|
956
|
-
if (m) {
|
957
|
-
env[m[1]] = m[2];
|
958
|
-
return false;
|
959
|
-
}
|
960
|
-
return true;
|
961
|
-
});
|
962
|
-
for (const [key, value] of Object.entries(env)) {
|
963
|
-
process$1.env[key] = value;
|
964
|
-
}
|
965
|
-
var parseArgv = () => program.parse(newArgv);
|
966
|
-
|
967
|
-
if (process$1.env.JIEK_IS_ONLY_BUILD === "true") {
|
968
|
-
parseArgv();
|
969
|
-
}
|