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
@@ -0,0 +1,33 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var commander = require('commander');
|
4
|
+
var process = require('node:process');
|
5
|
+
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
7
|
+
|
8
|
+
var process__default = /*#__PURE__*/_interopDefault(process);
|
9
|
+
|
10
|
+
const { argv } = process__default.default;
|
11
|
+
const env = {};
|
12
|
+
let isPassThrough = false;
|
13
|
+
const newArgv = argv.filter((arg) => {
|
14
|
+
if (isPassThrough) {
|
15
|
+
return true;
|
16
|
+
}
|
17
|
+
if (arg === "--") {
|
18
|
+
isPassThrough = true;
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
const m = /^--env\.(\w+)=(.*)$/.exec(arg);
|
22
|
+
if (m) {
|
23
|
+
env[m[1]] = m[2];
|
24
|
+
return false;
|
25
|
+
}
|
26
|
+
return true;
|
27
|
+
});
|
28
|
+
for (const [key, value] of Object.entries(env)) {
|
29
|
+
process__default.default.env[key] = value;
|
30
|
+
}
|
31
|
+
var parseArgv = () => commander.program.parse(newArgv);
|
32
|
+
|
33
|
+
module.exports = parseArgv;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { program } from 'commander';
|
2
|
+
import process from 'node:process';
|
3
|
+
|
4
|
+
const { argv } = process;
|
5
|
+
const env = {};
|
6
|
+
let isPassThrough = false;
|
7
|
+
const newArgv = argv.filter((arg) => {
|
8
|
+
if (isPassThrough) {
|
9
|
+
return true;
|
10
|
+
}
|
11
|
+
if (arg === "--") {
|
12
|
+
isPassThrough = true;
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
const m = /^--env\.(\w+)=(.*)$/.exec(arg);
|
16
|
+
if (m) {
|
17
|
+
env[m[1]] = m[2];
|
18
|
+
return false;
|
19
|
+
}
|
20
|
+
return true;
|
21
|
+
});
|
22
|
+
for (const [key, value] of Object.entries(env)) {
|
23
|
+
process.env[key] = value;
|
24
|
+
}
|
25
|
+
var parseArgv = () => program.parse(newArgv);
|
26
|
+
|
27
|
+
export { parseArgv as default };
|
@@ -0,0 +1,12 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var execa = require('execa');
|
4
|
+
|
5
|
+
const bridgeDisabledRef = { value: false };
|
6
|
+
const publish = async (type, data) => {
|
7
|
+
if (bridgeDisabledRef.value) return Promise.resolve();
|
8
|
+
return execa.sendMessage({ type, data });
|
9
|
+
};
|
10
|
+
|
11
|
+
exports.bridgeDisabledRef = bridgeDisabledRef;
|
12
|
+
exports.publish = publish;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { Module } from './rollup/bundle-analyzer.cjs';
|
2
|
+
import 'rollup';
|
3
|
+
import 'vite-bundle-analyzer';
|
4
|
+
|
5
|
+
declare const bridgeDisabledRef: {
|
6
|
+
value: boolean;
|
7
|
+
};
|
8
|
+
interface RollupBuildEntryCtx {
|
9
|
+
type: 'esm' | 'cjs';
|
10
|
+
name: string;
|
11
|
+
path: string;
|
12
|
+
exportConditions: string[];
|
13
|
+
input: string;
|
14
|
+
}
|
15
|
+
interface RollupBuildEventMap {
|
16
|
+
init: {
|
17
|
+
leafMap: Map<string, string[][]>;
|
18
|
+
targetsLength: number;
|
19
|
+
};
|
20
|
+
progress: RollupBuildEntryCtx & {
|
21
|
+
tags?: string[];
|
22
|
+
event?: string;
|
23
|
+
message?: string;
|
24
|
+
};
|
25
|
+
watchChange: RollupBuildEntryCtx & {
|
26
|
+
id: string;
|
27
|
+
};
|
28
|
+
modulesAnalyze: RollupBuildEntryCtx & {
|
29
|
+
modules: Module[];
|
30
|
+
};
|
31
|
+
debug: unknown;
|
32
|
+
}
|
33
|
+
type RollupBuildEvent = keyof RollupBuildEventMap extends infer K ? K extends infer Item extends keyof RollupBuildEventMap ? {
|
34
|
+
type: Item;
|
35
|
+
data: RollupBuildEventMap[Item];
|
36
|
+
} : never : never;
|
37
|
+
declare const publish: <K extends keyof RollupBuildEventMap>(type: K, data: RollupBuildEventMap[K]) => Promise<void>;
|
38
|
+
|
39
|
+
export { type RollupBuildEntryCtx, type RollupBuildEvent, type RollupBuildEventMap, bridgeDisabledRef, publish };
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { Module } from './rollup/bundle-analyzer.js';
|
2
|
+
import 'rollup';
|
3
|
+
import 'vite-bundle-analyzer';
|
4
|
+
|
5
|
+
declare const bridgeDisabledRef: {
|
6
|
+
value: boolean;
|
7
|
+
};
|
8
|
+
interface RollupBuildEntryCtx {
|
9
|
+
type: 'esm' | 'cjs';
|
10
|
+
name: string;
|
11
|
+
path: string;
|
12
|
+
exportConditions: string[];
|
13
|
+
input: string;
|
14
|
+
}
|
15
|
+
interface RollupBuildEventMap {
|
16
|
+
init: {
|
17
|
+
leafMap: Map<string, string[][]>;
|
18
|
+
targetsLength: number;
|
19
|
+
};
|
20
|
+
progress: RollupBuildEntryCtx & {
|
21
|
+
tags?: string[];
|
22
|
+
event?: string;
|
23
|
+
message?: string;
|
24
|
+
};
|
25
|
+
watchChange: RollupBuildEntryCtx & {
|
26
|
+
id: string;
|
27
|
+
};
|
28
|
+
modulesAnalyze: RollupBuildEntryCtx & {
|
29
|
+
modules: Module[];
|
30
|
+
};
|
31
|
+
debug: unknown;
|
32
|
+
}
|
33
|
+
type RollupBuildEvent = keyof RollupBuildEventMap extends infer K ? K extends infer Item extends keyof RollupBuildEventMap ? {
|
34
|
+
type: Item;
|
35
|
+
data: RollupBuildEventMap[Item];
|
36
|
+
} : never : never;
|
37
|
+
declare const publish: <K extends keyof RollupBuildEventMap>(type: K, data: RollupBuildEventMap[K]) => Promise<void>;
|
38
|
+
|
39
|
+
export { type RollupBuildEntryCtx, type RollupBuildEvent, type RollupBuildEventMap, bridgeDisabledRef, publish };
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { sendMessage } from 'execa';
|
2
|
+
|
3
|
+
const bridgeDisabledRef = { value: false };
|
4
|
+
const publish = async (type, data) => {
|
5
|
+
if (bridgeDisabledRef.value) return Promise.resolve();
|
6
|
+
return sendMessage({ type, data });
|
7
|
+
};
|
8
|
+
|
9
|
+
export { bridgeDisabledRef, publish };
|
@@ -0,0 +1,201 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var optionParser = require('../utils/optionParser.cjs');
|
4
|
+
var checkDependency = require('../../utils/checkDependency.cjs');
|
5
|
+
var fs = require('node:fs');
|
6
|
+
var path = require('node:path');
|
7
|
+
require('../../.chunks/jiek_create-require.CWFWNQHj.cjs');
|
8
|
+
require('node:child_process');
|
9
|
+
require('node:process');
|
10
|
+
require('@inquirer/prompts');
|
11
|
+
require('../../.chunks/getWD.ZF0avqDB.cjs');
|
12
|
+
require('@jiek/utils/getWorkspaceDir');
|
13
|
+
require('commander');
|
14
|
+
require('js-yaml');
|
15
|
+
require('../../utils/getRoot.cjs');
|
16
|
+
|
17
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
18
|
+
|
19
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
20
|
+
|
21
|
+
function Main() {
|
22
|
+
const { useState, useMemo, useEffect, useCallback } = React;
|
23
|
+
const [path, setPath] = useState(() => location.pathname.replace(/^\/ana\/?/, ""));
|
24
|
+
const [pkgName, entry] = useMemo(() => {
|
25
|
+
const pkgName2 = /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(path)?.[1];
|
26
|
+
return [
|
27
|
+
pkgName2,
|
28
|
+
pkgName2 != null ? path.replace(`${pkgName2}/`, "") : void 0
|
29
|
+
];
|
30
|
+
}, [path]);
|
31
|
+
const push = useCallback((newPath) => {
|
32
|
+
setPath(newPath);
|
33
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${newPath}`;
|
34
|
+
history.pushState(null, "", `/ana/${newPath}`);
|
35
|
+
}, []);
|
36
|
+
const filterModules = useCallback((startWith) => {
|
37
|
+
const modules = analyzeModule.filter((m) => m.filename.startsWith(startWith));
|
38
|
+
dispatchEvent(new CustomEvent("send:filter", { detail: { analyzeModule: modules } }));
|
39
|
+
}, []);
|
40
|
+
useEffect(() => {
|
41
|
+
if (path !== "") {
|
42
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${path}`;
|
43
|
+
} else {
|
44
|
+
document.title = document.title.replace(/ - \/.*/, "");
|
45
|
+
}
|
46
|
+
filterModules(path);
|
47
|
+
}, [path, filterModules]);
|
48
|
+
useEffect(() => {
|
49
|
+
const offGraphClick = listen("graph:click", ({ detail }) => {
|
50
|
+
if (!detail) return;
|
51
|
+
let root = detail.node;
|
52
|
+
while (root.parent) {
|
53
|
+
root = root.parent;
|
54
|
+
}
|
55
|
+
if (root.filename === path) return;
|
56
|
+
push(root.filename);
|
57
|
+
});
|
58
|
+
return () => {
|
59
|
+
offGraphClick();
|
60
|
+
};
|
61
|
+
}, [push]);
|
62
|
+
function listen(type, listener) {
|
63
|
+
window.addEventListener(type, listener);
|
64
|
+
return () => {
|
65
|
+
window.removeEventListener(type, listener);
|
66
|
+
};
|
67
|
+
}
|
68
|
+
return /* @__PURE__ */ React.createElement(
|
69
|
+
"div",
|
70
|
+
{
|
71
|
+
style: {
|
72
|
+
padding: "12px 55px"
|
73
|
+
}
|
74
|
+
},
|
75
|
+
"/",
|
76
|
+
/* @__PURE__ */ React.createElement(
|
77
|
+
"select",
|
78
|
+
{
|
79
|
+
style: {
|
80
|
+
appearance: "none",
|
81
|
+
border: "none",
|
82
|
+
background: "none"
|
83
|
+
},
|
84
|
+
value: pkgName,
|
85
|
+
onChange: (e) => push(e.target.value)
|
86
|
+
},
|
87
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
88
|
+
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))
|
89
|
+
),
|
90
|
+
pkgName != null && /* @__PURE__ */ React.createElement(React.Fragment, null, "/", /* @__PURE__ */ React.createElement(
|
91
|
+
"select",
|
92
|
+
{
|
93
|
+
style: {
|
94
|
+
appearance: "none",
|
95
|
+
border: "none",
|
96
|
+
background: "none"
|
97
|
+
},
|
98
|
+
value: entry,
|
99
|
+
onChange: (e) => push(`${pkgName}/${e.target.value}`)
|
100
|
+
},
|
101
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
102
|
+
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))
|
103
|
+
))
|
104
|
+
);
|
105
|
+
}
|
106
|
+
|
107
|
+
function render() {
|
108
|
+
CUSTOM_SIDE_BAR = true;
|
109
|
+
window.addEventListener("client:ready", () => window.dispatchEvent(
|
110
|
+
new CustomEvent("send:ui", {
|
111
|
+
detail: { type: "Main", Component: __REPLACE_INJECT__ }
|
112
|
+
})
|
113
|
+
));
|
114
|
+
}
|
115
|
+
const CLIENT_CUSTOM_RENDER_SCRIPT = [
|
116
|
+
Main.toString(),
|
117
|
+
render.toString().replace("__REPLACE_INJECT__", Main.name),
|
118
|
+
`(${render.name})()`
|
119
|
+
].join("\n");
|
120
|
+
|
121
|
+
const registerAnalyzerCommandOptions = (command) => command.option("--ana", "Enable the bundle analyzer.", optionParser.parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option(
|
122
|
+
"--ana.mode <MODE>",
|
123
|
+
'The mode of the bundle analyzer, support "static", "json" and "server".',
|
124
|
+
"server"
|
125
|
+
).option("--ana.open", "Open the bundle analyzer in the browser.", optionParser.parseBoolean).option(
|
126
|
+
"--ana.size <SIZE>",
|
127
|
+
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
128
|
+
"parsed"
|
129
|
+
);
|
130
|
+
const useAnalyzer = async (options, server) => {
|
131
|
+
const modules = [];
|
132
|
+
let bundleAnalyzerModule;
|
133
|
+
const analyzer = options.ana ? {
|
134
|
+
dir: options["ana.dir"],
|
135
|
+
mode: options["ana.mode"],
|
136
|
+
open: options["ana.open"],
|
137
|
+
size: options["ana.size"]
|
138
|
+
} : void 0;
|
139
|
+
if (options.ana && ![
|
140
|
+
"stat",
|
141
|
+
"parsed",
|
142
|
+
"gzip"
|
143
|
+
].includes(analyzer?.size ?? "")) {
|
144
|
+
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
145
|
+
}
|
146
|
+
if (analyzer) {
|
147
|
+
await checkDependency.checkDependency("vite-bundle-analyzer");
|
148
|
+
bundleAnalyzerModule = await import('vite-bundle-analyzer');
|
149
|
+
}
|
150
|
+
const refreshAnalyzer = async (cwd, applyModules) => {
|
151
|
+
if (!(analyzer && server && bundleAnalyzerModule)) return;
|
152
|
+
if (analyzer.mode === "json") {
|
153
|
+
const anaDir = path__default.default.resolve(cwd, analyzer.dir);
|
154
|
+
if (!fs.existsSync(anaDir)) {
|
155
|
+
fs.mkdirSync(anaDir, { recursive: true });
|
156
|
+
}
|
157
|
+
const gitIgnorePath = path__default.default.resolve(anaDir, ".gitignore");
|
158
|
+
if (!fs.existsSync(gitIgnorePath)) {
|
159
|
+
fs.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
160
|
+
}
|
161
|
+
const npmIgnorePath = path__default.default.resolve(anaDir, ".npmignore");
|
162
|
+
if (!fs.existsSync(npmIgnorePath)) {
|
163
|
+
fs.writeFileSync(npmIgnorePath, "*\n");
|
164
|
+
}
|
165
|
+
if (!fs.statSync(anaDir).isDirectory()) {
|
166
|
+
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
const { renderView, injectHTMLTag } = bundleAnalyzerModule;
|
170
|
+
applyModules.forEach((m) => {
|
171
|
+
const index = modules.findIndex(({ filename }) => filename === m.filename);
|
172
|
+
if (index === -1) {
|
173
|
+
modules.push(m);
|
174
|
+
} else {
|
175
|
+
modules[index] = m;
|
176
|
+
}
|
177
|
+
});
|
178
|
+
let html = await renderView(modules, {
|
179
|
+
title: `Jiek Analyzer`,
|
180
|
+
mode: analyzer.size
|
181
|
+
});
|
182
|
+
html = injectHTMLTag({
|
183
|
+
html,
|
184
|
+
injectTo: "body",
|
185
|
+
descriptors: [
|
186
|
+
{ kind: "script", text: CLIENT_CUSTOM_RENDER_SCRIPT }
|
187
|
+
]
|
188
|
+
});
|
189
|
+
void server.renderTo("/ana", html);
|
190
|
+
};
|
191
|
+
return {
|
192
|
+
modules,
|
193
|
+
refreshAnalyzer,
|
194
|
+
ANALYZER_ENV: {
|
195
|
+
JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : void 0
|
196
|
+
}
|
197
|
+
};
|
198
|
+
};
|
199
|
+
|
200
|
+
exports.registerAnalyzerCommandOptions = registerAnalyzerCommandOptions;
|
201
|
+
exports.useAnalyzer = useAnalyzer;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import * as vite_bundle_analyzer from 'vite-bundle-analyzer';
|
2
|
+
import { Command } from 'commander';
|
3
|
+
import { createServer } from '../../server.cjs';
|
4
|
+
|
5
|
+
interface AnalyzerBuildOptions {
|
6
|
+
ana?: boolean;
|
7
|
+
/**
|
8
|
+
* @default '.jk-analyses'
|
9
|
+
*/
|
10
|
+
'ana.dir': string;
|
11
|
+
/**
|
12
|
+
* @default 'server'
|
13
|
+
*/
|
14
|
+
'ana.mode': string;
|
15
|
+
'ana.open'?: boolean;
|
16
|
+
/**
|
17
|
+
* @default 'parsed'
|
18
|
+
*/
|
19
|
+
'ana.size': string;
|
20
|
+
}
|
21
|
+
declare const registerAnalyzerCommandOptions: (command: Command) => Command;
|
22
|
+
declare const useAnalyzer: (options: AnalyzerBuildOptions, server?: ReturnType<typeof createServer>) => Promise<{
|
23
|
+
modules: vite_bundle_analyzer.Module[];
|
24
|
+
refreshAnalyzer: (cwd: string, applyModules: vite_bundle_analyzer.Module[]) => Promise<void>;
|
25
|
+
ANALYZER_ENV: {
|
26
|
+
JIEK_ANALYZER: string | undefined;
|
27
|
+
};
|
28
|
+
}>;
|
29
|
+
|
30
|
+
export { type AnalyzerBuildOptions, registerAnalyzerCommandOptions, useAnalyzer };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import * as vite_bundle_analyzer from 'vite-bundle-analyzer';
|
2
|
+
import { Command } from 'commander';
|
3
|
+
import { createServer } from '../../server.js';
|
4
|
+
|
5
|
+
interface AnalyzerBuildOptions {
|
6
|
+
ana?: boolean;
|
7
|
+
/**
|
8
|
+
* @default '.jk-analyses'
|
9
|
+
*/
|
10
|
+
'ana.dir': string;
|
11
|
+
/**
|
12
|
+
* @default 'server'
|
13
|
+
*/
|
14
|
+
'ana.mode': string;
|
15
|
+
'ana.open'?: boolean;
|
16
|
+
/**
|
17
|
+
* @default 'parsed'
|
18
|
+
*/
|
19
|
+
'ana.size': string;
|
20
|
+
}
|
21
|
+
declare const registerAnalyzerCommandOptions: (command: Command) => Command;
|
22
|
+
declare const useAnalyzer: (options: AnalyzerBuildOptions, server?: ReturnType<typeof createServer>) => Promise<{
|
23
|
+
modules: vite_bundle_analyzer.Module[];
|
24
|
+
refreshAnalyzer: (cwd: string, applyModules: vite_bundle_analyzer.Module[]) => Promise<void>;
|
25
|
+
ANALYZER_ENV: {
|
26
|
+
JIEK_ANALYZER: string | undefined;
|
27
|
+
};
|
28
|
+
}>;
|
29
|
+
|
30
|
+
export { type AnalyzerBuildOptions, registerAnalyzerCommandOptions, useAnalyzer };
|
@@ -0,0 +1,195 @@
|
|
1
|
+
import { parseBoolean } from '../utils/optionParser.js';
|
2
|
+
import { checkDependency } from '../../utils/checkDependency.js';
|
3
|
+
import { existsSync, mkdirSync, writeFileSync, statSync } from 'node:fs';
|
4
|
+
import path from 'node:path';
|
5
|
+
import '../../.chunks/jiek_create-require.CxSGbkTB.js';
|
6
|
+
import 'node:module';
|
7
|
+
import 'node:child_process';
|
8
|
+
import 'node:process';
|
9
|
+
import '@inquirer/prompts';
|
10
|
+
import '../../.chunks/getWD.D6wq8Qc2.js';
|
11
|
+
import '@jiek/utils/getWorkspaceDir';
|
12
|
+
import 'commander';
|
13
|
+
import 'js-yaml';
|
14
|
+
import '../../utils/getRoot.js';
|
15
|
+
|
16
|
+
function Main() {
|
17
|
+
const { useState, useMemo, useEffect, useCallback } = React;
|
18
|
+
const [path, setPath] = useState(() => location.pathname.replace(/^\/ana\/?/, ""));
|
19
|
+
const [pkgName, entry] = useMemo(() => {
|
20
|
+
const pkgName2 = /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(path)?.[1];
|
21
|
+
return [
|
22
|
+
pkgName2,
|
23
|
+
pkgName2 != null ? path.replace(`${pkgName2}/`, "") : void 0
|
24
|
+
];
|
25
|
+
}, [path]);
|
26
|
+
const push = useCallback((newPath) => {
|
27
|
+
setPath(newPath);
|
28
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${newPath}`;
|
29
|
+
history.pushState(null, "", `/ana/${newPath}`);
|
30
|
+
}, []);
|
31
|
+
const filterModules = useCallback((startWith) => {
|
32
|
+
const modules = analyzeModule.filter((m) => m.filename.startsWith(startWith));
|
33
|
+
dispatchEvent(new CustomEvent("send:filter", { detail: { analyzeModule: modules } }));
|
34
|
+
}, []);
|
35
|
+
useEffect(() => {
|
36
|
+
if (path !== "") {
|
37
|
+
document.title = `${document.title.replace(/ - \/.*/, "")} - /${path}`;
|
38
|
+
} else {
|
39
|
+
document.title = document.title.replace(/ - \/.*/, "");
|
40
|
+
}
|
41
|
+
filterModules(path);
|
42
|
+
}, [path, filterModules]);
|
43
|
+
useEffect(() => {
|
44
|
+
const offGraphClick = listen("graph:click", ({ detail }) => {
|
45
|
+
if (!detail) return;
|
46
|
+
let root = detail.node;
|
47
|
+
while (root.parent) {
|
48
|
+
root = root.parent;
|
49
|
+
}
|
50
|
+
if (root.filename === path) return;
|
51
|
+
push(root.filename);
|
52
|
+
});
|
53
|
+
return () => {
|
54
|
+
offGraphClick();
|
55
|
+
};
|
56
|
+
}, [push]);
|
57
|
+
function listen(type, listener) {
|
58
|
+
window.addEventListener(type, listener);
|
59
|
+
return () => {
|
60
|
+
window.removeEventListener(type, listener);
|
61
|
+
};
|
62
|
+
}
|
63
|
+
return /* @__PURE__ */ React.createElement(
|
64
|
+
"div",
|
65
|
+
{
|
66
|
+
style: {
|
67
|
+
padding: "12px 55px"
|
68
|
+
}
|
69
|
+
},
|
70
|
+
"/",
|
71
|
+
/* @__PURE__ */ React.createElement(
|
72
|
+
"select",
|
73
|
+
{
|
74
|
+
style: {
|
75
|
+
appearance: "none",
|
76
|
+
border: "none",
|
77
|
+
background: "none"
|
78
|
+
},
|
79
|
+
value: pkgName,
|
80
|
+
onChange: (e) => push(e.target.value)
|
81
|
+
},
|
82
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
83
|
+
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))
|
84
|
+
),
|
85
|
+
pkgName != null && /* @__PURE__ */ React.createElement(React.Fragment, null, "/", /* @__PURE__ */ React.createElement(
|
86
|
+
"select",
|
87
|
+
{
|
88
|
+
style: {
|
89
|
+
appearance: "none",
|
90
|
+
border: "none",
|
91
|
+
background: "none"
|
92
|
+
},
|
93
|
+
value: entry,
|
94
|
+
onChange: (e) => push(`${pkgName}/${e.target.value}`)
|
95
|
+
},
|
96
|
+
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
97
|
+
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))
|
98
|
+
))
|
99
|
+
);
|
100
|
+
}
|
101
|
+
|
102
|
+
function render() {
|
103
|
+
CUSTOM_SIDE_BAR = true;
|
104
|
+
window.addEventListener("client:ready", () => window.dispatchEvent(
|
105
|
+
new CustomEvent("send:ui", {
|
106
|
+
detail: { type: "Main", Component: __REPLACE_INJECT__ }
|
107
|
+
})
|
108
|
+
));
|
109
|
+
}
|
110
|
+
const CLIENT_CUSTOM_RENDER_SCRIPT = [
|
111
|
+
Main.toString(),
|
112
|
+
render.toString().replace("__REPLACE_INJECT__", Main.name),
|
113
|
+
`(${render.name})()`
|
114
|
+
].join("\n");
|
115
|
+
|
116
|
+
const registerAnalyzerCommandOptions = (command) => command.option("--ana", "Enable the bundle analyzer.", parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option(
|
117
|
+
"--ana.mode <MODE>",
|
118
|
+
'The mode of the bundle analyzer, support "static", "json" and "server".',
|
119
|
+
"server"
|
120
|
+
).option("--ana.open", "Open the bundle analyzer in the browser.", parseBoolean).option(
|
121
|
+
"--ana.size <SIZE>",
|
122
|
+
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
123
|
+
"parsed"
|
124
|
+
);
|
125
|
+
const useAnalyzer = async (options, server) => {
|
126
|
+
const modules = [];
|
127
|
+
let bundleAnalyzerModule;
|
128
|
+
const analyzer = options.ana ? {
|
129
|
+
dir: options["ana.dir"],
|
130
|
+
mode: options["ana.mode"],
|
131
|
+
open: options["ana.open"],
|
132
|
+
size: options["ana.size"]
|
133
|
+
} : void 0;
|
134
|
+
if (options.ana && ![
|
135
|
+
"stat",
|
136
|
+
"parsed",
|
137
|
+
"gzip"
|
138
|
+
].includes(analyzer?.size ?? "")) {
|
139
|
+
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
140
|
+
}
|
141
|
+
if (analyzer) {
|
142
|
+
await checkDependency("vite-bundle-analyzer");
|
143
|
+
bundleAnalyzerModule = await import('vite-bundle-analyzer');
|
144
|
+
}
|
145
|
+
const refreshAnalyzer = async (cwd, applyModules) => {
|
146
|
+
if (!(analyzer && server && bundleAnalyzerModule)) return;
|
147
|
+
if (analyzer.mode === "json") {
|
148
|
+
const anaDir = path.resolve(cwd, analyzer.dir);
|
149
|
+
if (!existsSync(anaDir)) {
|
150
|
+
mkdirSync(anaDir, { recursive: true });
|
151
|
+
}
|
152
|
+
const gitIgnorePath = path.resolve(anaDir, ".gitignore");
|
153
|
+
if (!existsSync(gitIgnorePath)) {
|
154
|
+
writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
155
|
+
}
|
156
|
+
const npmIgnorePath = path.resolve(anaDir, ".npmignore");
|
157
|
+
if (!existsSync(npmIgnorePath)) {
|
158
|
+
writeFileSync(npmIgnorePath, "*\n");
|
159
|
+
}
|
160
|
+
if (!statSync(anaDir).isDirectory()) {
|
161
|
+
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
const { renderView, injectHTMLTag } = bundleAnalyzerModule;
|
165
|
+
applyModules.forEach((m) => {
|
166
|
+
const index = modules.findIndex(({ filename }) => filename === m.filename);
|
167
|
+
if (index === -1) {
|
168
|
+
modules.push(m);
|
169
|
+
} else {
|
170
|
+
modules[index] = m;
|
171
|
+
}
|
172
|
+
});
|
173
|
+
let html = await renderView(modules, {
|
174
|
+
title: `Jiek Analyzer`,
|
175
|
+
mode: analyzer.size
|
176
|
+
});
|
177
|
+
html = injectHTMLTag({
|
178
|
+
html,
|
179
|
+
injectTo: "body",
|
180
|
+
descriptors: [
|
181
|
+
{ kind: "script", text: CLIENT_CUSTOM_RENDER_SCRIPT }
|
182
|
+
]
|
183
|
+
});
|
184
|
+
void server.renderTo("/ana", html);
|
185
|
+
};
|
186
|
+
return {
|
187
|
+
modules,
|
188
|
+
refreshAnalyzer,
|
189
|
+
ANALYZER_ENV: {
|
190
|
+
JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : void 0
|
191
|
+
}
|
192
|
+
};
|
193
|
+
};
|
194
|
+
|
195
|
+
export { registerAnalyzerCommandOptions, useAnalyzer };
|
@@ -0,0 +1,21 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const entriesDescription = `
|
4
|
+
Specify the build entry-points of the package.json's 'exports' field.
|
5
|
+
Support glob pattern and array.
|
6
|
+
.e.g. '.', './*', './sub/*', './a,./b'.
|
7
|
+
`.trim();
|
8
|
+
const filterDescription = `
|
9
|
+
Filter the packages from the workspace.
|
10
|
+
Support fuzzy match and array.
|
11
|
+
.e.g. 'core,utils'.
|
12
|
+
`.trim();
|
13
|
+
const outdirDescription = `
|
14
|
+
The output directory of the build, which relative to the target subpackage root directory.
|
15
|
+
Support with variables: 'PKG_NAME',
|
16
|
+
.e.g. 'dist/{{PKG_NAME}}'.
|
17
|
+
`.trim();
|
18
|
+
|
19
|
+
exports.entriesDescription = entriesDescription;
|
20
|
+
exports.filterDescription = filterDescription;
|
21
|
+
exports.outdirDescription = outdirDescription;
|