jiek 2.2.6 → 2.2.7-alpha.1

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.
Files changed (136) hide show
  1. package/bin/build.cjs +2 -0
  2. package/bin/index.cjs +2 -0
  3. package/bin-helper/index.cjs +31 -0
  4. package/bin-helper/index.d.cts +1 -0
  5. package/bin-helper/index.d.ts +1 -0
  6. package/bin-helper/package.json +5 -1
  7. package/dist/.internal/+/bin/parseArgv.cjs +33 -0
  8. package/dist/.internal/+/bin/parseArgv.d.cts +5 -0
  9. package/dist/.internal/+/bin/parseArgv.d.ts +5 -0
  10. package/dist/.internal/+/bin/parseArgv.js +27 -0
  11. package/dist/.internal/+/bridge.cjs +12 -0
  12. package/dist/.internal/+/bridge.d.cts +39 -0
  13. package/dist/.internal/+/bridge.d.ts +39 -0
  14. package/dist/.internal/+/bridge.js +9 -0
  15. package/dist/.internal/+/commands/build/analyzer.cjs +201 -0
  16. package/dist/.internal/+/commands/build/analyzer.d.cts +30 -0
  17. package/dist/.internal/+/commands/build/analyzer.d.ts +30 -0
  18. package/dist/.internal/+/commands/build/analyzer.js +195 -0
  19. package/dist/.internal/+/commands/descriptions.cjs +21 -0
  20. package/dist/.internal/+/commands/descriptions.d.cts +5 -0
  21. package/dist/.internal/+/commands/descriptions.d.ts +5 -0
  22. package/dist/.internal/+/commands/descriptions.js +17 -0
  23. package/dist/.internal/+/commands/meta.cjs +16 -0
  24. package/dist/.internal/+/commands/meta.d.cts +3 -0
  25. package/dist/.internal/+/commands/meta.d.ts +3 -0
  26. package/dist/.internal/+/commands/meta.js +15 -0
  27. package/dist/.internal/+/commands/utils/optionParser.cjs +8 -0
  28. package/dist/.internal/+/commands/utils/optionParser.d.cts +3 -0
  29. package/dist/.internal/+/commands/utils/optionParser.d.ts +3 -0
  30. package/dist/.internal/+/commands/utils/optionParser.js +6 -0
  31. package/dist/.internal/+/rollup/base.cjs +10 -0
  32. package/dist/{cli-only-build.d.cts → .internal/+/rollup/base.d.cts} +8 -15
  33. package/dist/{cli-only-build.d.ts → .internal/+/rollup/base.d.ts} +8 -15
  34. package/dist/.internal/+/rollup/base.js +7 -0
  35. package/dist/.internal/+/rollup/bundle-analyzer.cjs +51 -0
  36. package/dist/.internal/+/rollup/bundle-analyzer.d.cts +92 -0
  37. package/dist/.internal/+/rollup/bundle-analyzer.d.ts +92 -0
  38. package/dist/.internal/+/rollup/bundle-analyzer.js +45 -0
  39. package/dist/.internal/+/server.cjs +33 -0
  40. package/dist/.internal/+/server.d.cts +8 -0
  41. package/dist/.internal/+/server.d.ts +8 -0
  42. package/dist/.internal/+/server.js +27 -0
  43. package/dist/.internal/+/utils/checkDependency.cjs +39 -0
  44. package/dist/.internal/+/utils/checkDependency.d.cts +3 -0
  45. package/dist/.internal/+/utils/checkDependency.d.ts +3 -0
  46. package/dist/.internal/+/utils/checkDependency.js +34 -0
  47. package/dist/.internal/+/utils/filterSupport.cjs +20 -0
  48. package/dist/.internal/+/utils/filterSupport.d.cts +15 -0
  49. package/dist/.internal/+/utils/filterSupport.d.ts +15 -0
  50. package/dist/.internal/+/utils/filterSupport.js +10 -0
  51. package/dist/.internal/+/utils/getInternalModuleName.cjs +5 -0
  52. package/dist/.internal/+/utils/getInternalModuleName.d.cts +3 -0
  53. package/dist/.internal/+/utils/getInternalModuleName.d.ts +3 -0
  54. package/dist/.internal/+/utils/getInternalModuleName.js +3 -0
  55. package/dist/.internal/+/utils/getRoot.cjs +17 -0
  56. package/dist/.internal/+/utils/getRoot.d.cts +3 -0
  57. package/dist/.internal/+/utils/getRoot.d.ts +3 -0
  58. package/dist/.internal/+/utils/getRoot.js +11 -0
  59. package/dist/.internal/+/utils/getWD.cjs +15 -0
  60. package/dist/.internal/+/utils/getWD.d.cts +6 -0
  61. package/dist/.internal/+/utils/getWD.d.ts +6 -0
  62. package/dist/.internal/+/utils/getWD.js +10 -0
  63. package/dist/.internal/+/utils/intersection.cjs +5 -0
  64. package/dist/.internal/+/utils/intersection.d.cts +3 -0
  65. package/dist/.internal/+/utils/intersection.d.ts +3 -0
  66. package/dist/.internal/+/utils/intersection.js +3 -0
  67. package/dist/.internal/+/utils/loadConfig.cjs +100 -0
  68. package/dist/.internal/+/utils/loadConfig.d.cts +10 -0
  69. package/dist/.internal/+/utils/loadConfig.d.ts +10 -0
  70. package/dist/.internal/+/utils/loadConfig.js +94 -0
  71. package/dist/.internal/+/utils/recursiveListFiles.cjs +19 -0
  72. package/dist/.internal/+/utils/recursiveListFiles.d.cts +3 -0
  73. package/dist/.internal/+/utils/recursiveListFiles.d.ts +3 -0
  74. package/dist/.internal/+/utils/recursiveListFiles.js +13 -0
  75. package/dist/.internal/+/utils/resolveExports.cjs +118 -0
  76. package/dist/.internal/+/utils/resolveExports.d.cts +26 -0
  77. package/dist/.internal/+/utils/resolveExports.d.ts +26 -0
  78. package/dist/.internal/+/utils/resolveExports.js +111 -0
  79. package/dist/.internal/+/utils/ts.cjs +68 -0
  80. package/dist/.internal/+/utils/ts.d.cts +3 -0
  81. package/dist/.internal/+/utils/ts.d.ts +3 -0
  82. package/dist/.internal/+/utils/ts.js +62 -0
  83. package/dist/.internal/+/utils/tsRegister.cjs +25 -0
  84. package/dist/.internal/+/utils/tsRegister.d.cts +3 -0
  85. package/dist/.internal/+/utils/tsRegister.d.ts +3 -0
  86. package/dist/.internal/+/utils/tsRegister.js +26 -0
  87. package/dist/.internal/getWD-BRJ3PK1S.js +105 -0
  88. package/dist/.internal/getWD-Cmxzjf-f.js +95 -0
  89. package/dist/{cli.js → .internal/index-B6RQz1DZ.js} +1 -735
  90. package/dist/{cli.cjs → .internal/index-DlHFuTjM.js} +1 -757
  91. package/dist/.internal/jiek_create-require-CWFWNQHj.js +5 -0
  92. package/dist/.internal/jiek_create-require-CxSGbkTB.js +5 -0
  93. package/dist/.internal/package.json +10 -0
  94. package/dist/bin/build.cjs +505 -0
  95. package/dist/bin/index.cjs +488 -0
  96. package/dist/index.d.cts +1 -113
  97. package/dist/index.d.ts +1 -113
  98. package/dist/rollup/index.cjs +282 -4569
  99. package/dist/rollup/index.d.cts +7 -1
  100. package/dist/rollup/index.d.ts +7 -1
  101. package/dist/rollup/index.js +270 -4554
  102. package/package.json +25 -28
  103. package/src/bin/build.cts +11 -0
  104. package/src/bin/index.cts +6 -0
  105. package/src/bridge.ts +1 -1
  106. package/src/commands/base.ts +3 -3
  107. package/src/commands/build/analyzer.ts +5 -5
  108. package/src/commands/build/client/analyzer.tsx +1 -1
  109. package/src/commands/build/client/index.ts +5 -7
  110. package/src/commands/build.ts +218 -209
  111. package/src/commands/meta.ts +1 -1
  112. package/src/commands/publish.ts +87 -25
  113. package/src/rollup/base.ts +2 -2
  114. package/src/rollup/index.ts +309 -115
  115. package/src/rollup/plugins/with-external.ts +23 -0
  116. package/src/rollup/utils/externalResolver.ts +20 -8
  117. package/src/utils/checkDependency.ts +1 -1
  118. package/src/utils/filterSupport.ts +17 -16
  119. package/src/utils/getInternalModuleName.ts +5 -0
  120. package/src/utils/intersection.ts +1 -0
  121. package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
  122. package/src/utils/{getExports.ts → resolveExports.ts} +16 -14
  123. package/bin/jiek-build.js +0 -16
  124. package/bin/jiek.js +0 -13
  125. package/bin-helper.cjs +0 -43
  126. package/cli/package.json +0 -1
  127. package/cli-only-build/package.json +0 -1
  128. package/dist/cli-only-build.cjs +0 -977
  129. package/dist/cli-only-build.js +0 -969
  130. package/dist/cli.d.cts +0 -14
  131. package/dist/cli.d.ts +0 -14
  132. package/src/bin/build.ts +0 -0
  133. package/src/cli-only-build.ts +0 -11
  134. package/src/cli.ts +0 -6
  135. /package/{bin-helper.js → bin-helper/index.js} +0 -0
  136. /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
package/bin/build.cjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('jiek/bin-helper')
package/bin/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('jiek/bin-helper')
@@ -0,0 +1,31 @@
1
+ const fs = require('node:fs')
2
+ const {
3
+ basename,
4
+ dirname,
5
+ resolve
6
+ } = require('node:path')
7
+ const process = require('node:process')
8
+
9
+ /**
10
+ * @type {string | undefined}
11
+ */
12
+ const binFilePath = process.env.JIEK_BIN__FILEPATH ?? module.parent.filename ?? require.main.filename
13
+
14
+ const packageDir = dirname(dirname(binFilePath))
15
+ const binFilename = basename(binFilePath)
16
+
17
+ process.env.JIEK_PACKAGE_DIR = packageDir
18
+ process.env.JIEK_BIN__FILENAME = binFilename
19
+ process.env.JIEK_BIN__FILEPATH = binFilePath
20
+
21
+ const resolveByPKG = (...paths) => resolve(packageDir, ...paths)
22
+ const isProduction = fs.existsSync(resolveByPKG(`./.jiek-production-tag`))
23
+
24
+ if (!isProduction) {
25
+ require('esbuild-register')
26
+ }
27
+
28
+ const binPath = isProduction
29
+ ? resolveByPKG(`./dist/bin/${binFilename}`)
30
+ : resolveByPKG(`./src/bin/${binFilename.replace(/(\.[cm]?)js$/, '$1ts')}`)
31
+ require(binPath)
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1 @@
1
+ export {}
@@ -1 +1,5 @@
1
- {"type":"module","module":"../bin-helper.js","main":"../bin-helper.cjs"}
1
+ {
2
+ "type": "module",
3
+ "main": "./index.cjs",
4
+ "module": "./index.js"
5
+ }
@@ -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,5 @@
1
+ import * as commander from 'commander';
2
+
3
+ declare const _default: () => commander.Command;
4
+
5
+ export { _default as default };
@@ -0,0 +1,5 @@
1
+ import * as commander from 'commander';
2
+
3
+ declare const _default: () => commander.Command;
4
+
5
+ export { _default as default };
@@ -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('../../../jiek_create-require-CWFWNQHj.js');
8
+ require('node:child_process');
9
+ require('node:process');
10
+ require('@inquirer/prompts');
11
+ require('../../../getWD-BRJ3PK1S.js');
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 };