@storm-software/unbuild 0.22.0 → 0.23.0
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/README.md +1 -1
- package/bin/unbuild.js +184 -1599
- package/bin/unbuild.mjs +184 -1595
- package/dist/build.d.mts +1 -0
- package/dist/build.d.ts +1 -0
- package/dist/build.js +10 -10
- package/dist/build.mjs +1 -1
- package/dist/chunk-3GQAWCBQ.js +13 -0
- package/dist/{chunk-E73BVQF5.js → chunk-3OJD7CO4.js} +5 -5
- package/dist/chunk-AW52DUNE.mjs +1043 -0
- package/dist/chunk-AYRYNROK.js +27 -0
- package/dist/{chunk-B2WY6JG2.js → chunk-DFIGNXGY.js} +1035 -1035
- package/dist/{chunk-UUI4UWA4.js → chunk-OQPSH7GE.js} +37 -37
- package/dist/{chunk-RUNO4F6F.js → chunk-RCEWRXM5.js} +2 -2
- package/dist/chunk-T2OTJN2D.js +1043 -0
- package/dist/{chunk-BMAXMHJB.js → chunk-WPOEGALQ.js} +5 -5
- package/dist/{chunk-6KE6SIPQ.js → chunk-XEAFTDQ7.js} +5 -5
- package/dist/clean.js +4 -4
- package/dist/config.d.mts +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +8 -8
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -10
- package/dist/index.mjs +1 -1
- package/dist/types.d.mts +2 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +0 -1
- package/package.json +190 -1
- package/dist/chunk-2Q67L63A.js +0 -2456
- package/dist/chunk-4WKFVYTI.js +0 -18
- package/dist/chunk-J5YBLOB7.js +0 -27
- package/dist/chunk-SGIQJ2OU.mjs +0 -2455
package/dist/chunk-SGIQJ2OU.mjs
DELETED
|
@@ -1,2455 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
clean
|
|
3
|
-
} from "./chunk-IIVTCNH5.mjs";
|
|
4
|
-
import {
|
|
5
|
-
getDefaultBuildPlugins
|
|
6
|
-
} from "./chunk-T5NKX2EJ.mjs";
|
|
7
|
-
import {
|
|
8
|
-
loadConfig
|
|
9
|
-
} from "./chunk-AICX43E6.mjs";
|
|
10
|
-
import {
|
|
11
|
-
COLOR_KEYS,
|
|
12
|
-
LogLevel,
|
|
13
|
-
LogLevelLabel,
|
|
14
|
-
STORM_DEFAULT_DOCS,
|
|
15
|
-
STORM_DEFAULT_HOMEPAGE,
|
|
16
|
-
STORM_DEFAULT_LICENSING,
|
|
17
|
-
correctPaths,
|
|
18
|
-
findWorkspaceRoot,
|
|
19
|
-
formatLogMessage,
|
|
20
|
-
getDefaultConfig,
|
|
21
|
-
getLogLevel,
|
|
22
|
-
getLogLevelLabel,
|
|
23
|
-
getStopwatch,
|
|
24
|
-
isVerbose,
|
|
25
|
-
joinPaths,
|
|
26
|
-
writeDebug,
|
|
27
|
-
writeFatal,
|
|
28
|
-
writeSuccess,
|
|
29
|
-
writeSystem,
|
|
30
|
-
writeTrace,
|
|
31
|
-
writeWarning
|
|
32
|
-
} from "./chunk-B5GGHMTB.mjs";
|
|
33
|
-
import {
|
|
34
|
-
__name
|
|
35
|
-
} from "./chunk-LPEX4YW6.mjs";
|
|
36
|
-
|
|
37
|
-
// src/build.ts
|
|
38
|
-
import { readCachedProjectGraph as readCachedProjectGraph3, writeJsonFile } from "@nx/devkit";
|
|
39
|
-
import { getHelperDependency, HelperDependency } from "@nx/js";
|
|
40
|
-
import { calculateProjectBuildableDependencies as calculateProjectBuildableDependencies2 } from "@nx/js/src/utils/buildable-libs-utils";
|
|
41
|
-
|
|
42
|
-
// ../build-tools/src/plugins/swc.ts
|
|
43
|
-
import { transform } from "@swc/core";
|
|
44
|
-
|
|
45
|
-
// ../build-tools/src/plugins/ts-resolve.ts
|
|
46
|
-
import fs from "node:fs";
|
|
47
|
-
import { builtinModules } from "node:module";
|
|
48
|
-
import path from "node:path";
|
|
49
|
-
import _resolve from "resolve";
|
|
50
|
-
|
|
51
|
-
// ../build-tools/src/plugins/type-definitions.ts
|
|
52
|
-
import { stripIndents } from "@nx/devkit";
|
|
53
|
-
import { relative } from "path";
|
|
54
|
-
|
|
55
|
-
// ../build-tools/src/utilities/copy-assets.ts
|
|
56
|
-
import { readCachedProjectGraph, readProjectsConfigurationFromProjectGraph } from "@nx/devkit";
|
|
57
|
-
import { copyAssets as copyAssetsBase } from "@nx/js";
|
|
58
|
-
import { glob } from "glob";
|
|
59
|
-
import { readFile as readFile2, writeFile } from "node:fs/promises";
|
|
60
|
-
|
|
61
|
-
// ../config-tools/src/config-file/get-config-file.ts
|
|
62
|
-
import { loadConfig as loadConfig2 } from "c12";
|
|
63
|
-
import defu from "defu";
|
|
64
|
-
var getConfigFileByName = /* @__PURE__ */ __name(async (fileName, filePath, options = {}) => {
|
|
65
|
-
const workspacePath = filePath || findWorkspaceRoot(filePath);
|
|
66
|
-
let config = await loadConfig2({
|
|
67
|
-
cwd: workspacePath,
|
|
68
|
-
packageJson: true,
|
|
69
|
-
name: fileName,
|
|
70
|
-
envName: fileName?.toUpperCase(),
|
|
71
|
-
jitiOptions: {
|
|
72
|
-
debug: false,
|
|
73
|
-
fsCache: process.env.STORM_SKIP_CACHE === "true" ? false : joinPaths(process.env.STORM_CACHE_DIR || "node_modules/.cache/storm", "config")
|
|
74
|
-
},
|
|
75
|
-
...options
|
|
76
|
-
});
|
|
77
|
-
if (!config || Object.keys(config).length === 0) {
|
|
78
|
-
config = await loadConfig2({
|
|
79
|
-
cwd: workspacePath,
|
|
80
|
-
packageJson: true,
|
|
81
|
-
name: fileName,
|
|
82
|
-
envName: fileName?.toUpperCase(),
|
|
83
|
-
jitiOptions: {
|
|
84
|
-
debug: false,
|
|
85
|
-
fsCache: process.env.STORM_SKIP_CACHE === "true" ? false : joinPaths(process.env.STORM_CACHE_DIR || "node_modules/.cache/storm", "config")
|
|
86
|
-
},
|
|
87
|
-
configFile: fileName,
|
|
88
|
-
...options
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return config;
|
|
92
|
-
}, "getConfigFileByName");
|
|
93
|
-
var getConfigFile = /* @__PURE__ */ __name(async (filePath, additionalFileNames = []) => {
|
|
94
|
-
const workspacePath = filePath ? filePath : findWorkspaceRoot(filePath);
|
|
95
|
-
const result = await getConfigFileByName("storm", workspacePath);
|
|
96
|
-
let config = result.config;
|
|
97
|
-
const configFile = result.configFile;
|
|
98
|
-
if (config && configFile && Object.keys(config).length > 0) {
|
|
99
|
-
writeSystem(`Found Storm configuration file "${configFile.includes(`${workspacePath}/`) ? configFile.replace(`${workspacePath}/`, "") : configFile}" at "${workspacePath}"`, {
|
|
100
|
-
logLevel: "all"
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
if (additionalFileNames && additionalFileNames.length > 0) {
|
|
104
|
-
const results = await Promise.all(additionalFileNames.map((fileName) => getConfigFileByName(fileName, workspacePath)));
|
|
105
|
-
for (const result2 of results) {
|
|
106
|
-
if (result2?.config && result2?.configFile && Object.keys(result2.config).length > 0) {
|
|
107
|
-
writeSystem(`Found alternative configuration file "${result2.configFile.includes(`${workspacePath}/`) ? result2.configFile.replace(`${workspacePath}/`, "") : result2.configFile}" at "${workspacePath}"`, {
|
|
108
|
-
logLevel: "all"
|
|
109
|
-
});
|
|
110
|
-
config = defu(result2.config ?? {}, config ?? {});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (!config) {
|
|
115
|
-
return void 0;
|
|
116
|
-
}
|
|
117
|
-
config.configFile = configFile;
|
|
118
|
-
return config;
|
|
119
|
-
}, "getConfigFile");
|
|
120
|
-
|
|
121
|
-
// ../config-tools/src/create-storm-config.ts
|
|
122
|
-
import defu2 from "defu";
|
|
123
|
-
|
|
124
|
-
// ../config-tools/src/env/get-env.ts
|
|
125
|
-
var getConfigEnv = /* @__PURE__ */ __name(() => {
|
|
126
|
-
const prefix = "STORM_";
|
|
127
|
-
let config = {
|
|
128
|
-
extends: process.env[`${prefix}EXTENDS`] || void 0,
|
|
129
|
-
name: process.env[`${prefix}NAME`] || void 0,
|
|
130
|
-
namespace: process.env[`${prefix}NAMESPACE`] || void 0,
|
|
131
|
-
owner: process.env[`${prefix}OWNER`] || void 0,
|
|
132
|
-
bot: {
|
|
133
|
-
name: process.env[`${prefix}BOT_NAME`] || void 0,
|
|
134
|
-
email: process.env[`${prefix}BOT_EMAIL`] || void 0
|
|
135
|
-
},
|
|
136
|
-
organization: process.env[`${prefix}ORGANIZATION`] || void 0,
|
|
137
|
-
packageManager: process.env[`${prefix}PACKAGE_MANAGER`] || void 0,
|
|
138
|
-
license: process.env[`${prefix}LICENSE`] || void 0,
|
|
139
|
-
homepage: process.env[`${prefix}HOMEPAGE`] || void 0,
|
|
140
|
-
docs: process.env[`${prefix}DOCS`] || void 0,
|
|
141
|
-
licensing: process.env[`${prefix}LICENSING`] || void 0,
|
|
142
|
-
timezone: process.env[`${prefix}TIMEZONE`] || process.env.TZ || void 0,
|
|
143
|
-
locale: process.env[`${prefix}LOCALE`] || process.env.LOCALE || void 0,
|
|
144
|
-
configFile: process.env[`${prefix}CONFIG_FILE`] ? correctPaths(process.env[`${prefix}CONFIG_FILE`]) : void 0,
|
|
145
|
-
workspaceRoot: process.env[`${prefix}WORKSPACE_ROOT`] ? correctPaths(process.env[`${prefix}WORKSPACE_ROOT`]) : void 0,
|
|
146
|
-
directories: {
|
|
147
|
-
cache: process.env[`${prefix}CACHE_DIR`] ? correctPaths(process.env[`${prefix}CACHE_DIR`]) : void 0,
|
|
148
|
-
data: process.env[`${prefix}DATA_DIR`] ? correctPaths(process.env[`${prefix}DATA_DIR`]) : void 0,
|
|
149
|
-
config: process.env[`${prefix}CONFIG_DIR`] ? correctPaths(process.env[`${prefix}CONFIG_DIR`]) : void 0,
|
|
150
|
-
temp: process.env[`${prefix}TEMP_DIR`] ? correctPaths(process.env[`${prefix}TEMP_DIR`]) : void 0,
|
|
151
|
-
log: process.env[`${prefix}LOG_DIR`] ? correctPaths(process.env[`${prefix}LOG_DIR`]) : void 0,
|
|
152
|
-
build: process.env[`${prefix}BUILD_DIR`] ? correctPaths(process.env[`${prefix}BUILD_DIR`]) : void 0
|
|
153
|
-
},
|
|
154
|
-
skipCache: process.env[`${prefix}SKIP_CACHE`] !== void 0 ? Boolean(process.env[`${prefix}SKIP_CACHE`]) : void 0,
|
|
155
|
-
env: (process.env[`${prefix}ENV`] ?? process.env.NODE_ENV ?? process.env.ENVIRONMENT) || void 0,
|
|
156
|
-
// ci:
|
|
157
|
-
// process.env[`${prefix}CI`] !== undefined
|
|
158
|
-
// ? Boolean(
|
|
159
|
-
// process.env[`${prefix}CI`] ??
|
|
160
|
-
// process.env.CI ??
|
|
161
|
-
// process.env.CONTINUOUS_INTEGRATION
|
|
162
|
-
// )
|
|
163
|
-
// : undefined,
|
|
164
|
-
repository: process.env[`${prefix}REPOSITORY`] || void 0,
|
|
165
|
-
branch: process.env[`${prefix}BRANCH`] || void 0,
|
|
166
|
-
preid: process.env[`${prefix}PRE_ID`] || void 0,
|
|
167
|
-
externalPackagePatterns: process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] ? JSON.parse(process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`]) : [],
|
|
168
|
-
registry: {
|
|
169
|
-
github: process.env[`${prefix}REGISTRY_GITHUB`] || void 0,
|
|
170
|
-
npm: process.env[`${prefix}REGISTRY_NPM`] || void 0,
|
|
171
|
-
cargo: process.env[`${prefix}REGISTRY_CARGO`] || void 0,
|
|
172
|
-
cyclone: process.env[`${prefix}REGISTRY_CYCLONE`] || void 0,
|
|
173
|
-
container: process.env[`${prefix}REGISTRY_CONTAINER`] || void 0
|
|
174
|
-
},
|
|
175
|
-
logLevel: process.env[`${prefix}LOG_LEVEL`] !== null && process.env[`${prefix}LOG_LEVEL`] !== void 0 ? process.env[`${prefix}LOG_LEVEL`] && Number.isSafeInteger(Number.parseInt(process.env[`${prefix}LOG_LEVEL`])) ? getLogLevelLabel(Number.parseInt(process.env[`${prefix}LOG_LEVEL`])) : process.env[`${prefix}LOG_LEVEL`] : void 0
|
|
176
|
-
};
|
|
177
|
-
const themeNames = Object.keys(process.env).filter((envKey) => envKey.startsWith(`${prefix}COLOR_`) && COLOR_KEYS.every((colorKey) => !envKey.startsWith(`${prefix}COLOR_LIGHT_${colorKey}`) && !envKey.startsWith(`${prefix}COLOR_DARK_${colorKey}`)));
|
|
178
|
-
config.colors = themeNames.length > 0 ? themeNames.reduce((ret, themeName) => {
|
|
179
|
-
ret[themeName] = getThemeColorConfigEnv(prefix, themeName);
|
|
180
|
-
return ret;
|
|
181
|
-
}, {}) : getThemeColorConfigEnv(prefix);
|
|
182
|
-
if (config.docs === STORM_DEFAULT_DOCS) {
|
|
183
|
-
if (config.homepage === STORM_DEFAULT_HOMEPAGE) {
|
|
184
|
-
config.docs = `${STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/docs`;
|
|
185
|
-
} else {
|
|
186
|
-
config.docs = `${config.homepage}/docs`;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (config.licensing === STORM_DEFAULT_LICENSING) {
|
|
190
|
-
if (config.homepage === STORM_DEFAULT_HOMEPAGE) {
|
|
191
|
-
config.licensing = `${STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/licensing`;
|
|
192
|
-
} else {
|
|
193
|
-
config.licensing = `${config.homepage}/docs`;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const serializedConfig = process.env[`${prefix}CONFIG`];
|
|
197
|
-
if (serializedConfig) {
|
|
198
|
-
const parsed = JSON.parse(serializedConfig);
|
|
199
|
-
config = {
|
|
200
|
-
...config,
|
|
201
|
-
...parsed,
|
|
202
|
-
colors: {
|
|
203
|
-
...config.colors,
|
|
204
|
-
...parsed.colors
|
|
205
|
-
},
|
|
206
|
-
extensions: {
|
|
207
|
-
...config.extensions,
|
|
208
|
-
...parsed.extensions
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
return config;
|
|
213
|
-
}, "getConfigEnv");
|
|
214
|
-
var getThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, theme) => {
|
|
215
|
-
const themeName = `COLOR_${theme && theme !== "base" ? `${theme}_` : ""}`.toUpperCase();
|
|
216
|
-
return process.env[`${prefix}${themeName}LIGHT_BRAND`] || process.env[`${prefix}${themeName}DARK_BRAND`] ? getMultiThemeColorConfigEnv(prefix + themeName) : getSingleThemeColorConfigEnv(prefix + themeName);
|
|
217
|
-
}, "getThemeColorConfigEnv");
|
|
218
|
-
var getSingleThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
|
|
219
|
-
return {
|
|
220
|
-
dark: process.env[`${prefix}DARK`],
|
|
221
|
-
light: process.env[`${prefix}LIGHT`],
|
|
222
|
-
brand: process.env[`${prefix}BRAND`],
|
|
223
|
-
alternate: process.env[`${prefix}ALTERNATE`],
|
|
224
|
-
accent: process.env[`${prefix}ACCENT`],
|
|
225
|
-
link: process.env[`${prefix}LINK`],
|
|
226
|
-
help: process.env[`${prefix}HELP`],
|
|
227
|
-
success: process.env[`${prefix}SUCCESS`],
|
|
228
|
-
info: process.env[`${prefix}INFO`],
|
|
229
|
-
warning: process.env[`${prefix}WARNING`],
|
|
230
|
-
danger: process.env[`${prefix}DANGER`],
|
|
231
|
-
fatal: process.env[`${prefix}FATAL`],
|
|
232
|
-
positive: process.env[`${prefix}POSITIVE`],
|
|
233
|
-
negative: process.env[`${prefix}NEGATIVE`]
|
|
234
|
-
};
|
|
235
|
-
}, "getSingleThemeColorConfigEnv");
|
|
236
|
-
var getMultiThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
|
|
237
|
-
return {
|
|
238
|
-
light: getBaseThemeColorConfigEnv(`${prefix}_LIGHT_`),
|
|
239
|
-
dark: getBaseThemeColorConfigEnv(`${prefix}_DARK_`)
|
|
240
|
-
};
|
|
241
|
-
}, "getMultiThemeColorConfigEnv");
|
|
242
|
-
var getBaseThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
|
|
243
|
-
return {
|
|
244
|
-
foreground: process.env[`${prefix}FOREGROUND`],
|
|
245
|
-
background: process.env[`${prefix}BACKGROUND`],
|
|
246
|
-
brand: process.env[`${prefix}BRAND`],
|
|
247
|
-
alternate: process.env[`${prefix}ALTERNATE`],
|
|
248
|
-
accent: process.env[`${prefix}ACCENT`],
|
|
249
|
-
link: process.env[`${prefix}LINK`],
|
|
250
|
-
help: process.env[`${prefix}HELP`],
|
|
251
|
-
success: process.env[`${prefix}SUCCESS`],
|
|
252
|
-
info: process.env[`${prefix}INFO`],
|
|
253
|
-
warning: process.env[`${prefix}WARNING`],
|
|
254
|
-
danger: process.env[`${prefix}DANGER`],
|
|
255
|
-
fatal: process.env[`${prefix}FATAL`],
|
|
256
|
-
positive: process.env[`${prefix}POSITIVE`],
|
|
257
|
-
negative: process.env[`${prefix}NEGATIVE`]
|
|
258
|
-
};
|
|
259
|
-
}, "getBaseThemeColorConfigEnv");
|
|
260
|
-
|
|
261
|
-
// ../config-tools/src/env/set-env.ts
|
|
262
|
-
var setExtensionEnv = /* @__PURE__ */ __name((extensionName, extension) => {
|
|
263
|
-
for (const key of Object.keys(extension ?? {})) {
|
|
264
|
-
if (extension[key]) {
|
|
265
|
-
const result = key?.replace(/([A-Z])+/g, (input) => input ? input[0]?.toUpperCase() + input.slice(1) : "").split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
|
|
266
|
-
let extensionKey;
|
|
267
|
-
if (result.length === 0) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
if (result.length === 1) {
|
|
271
|
-
extensionKey = result[0]?.toUpperCase() ?? "";
|
|
272
|
-
} else {
|
|
273
|
-
extensionKey = result.reduce((ret, part) => {
|
|
274
|
-
return `${ret}_${part.toLowerCase()}`;
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
process.env[`STORM_EXTENSION_${extensionName.toUpperCase()}_${extensionKey.toUpperCase()}`] = extension[key];
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}, "setExtensionEnv");
|
|
281
|
-
var setConfigEnv = /* @__PURE__ */ __name((config) => {
|
|
282
|
-
const prefix = "STORM_";
|
|
283
|
-
if (config.extends) {
|
|
284
|
-
process.env[`${prefix}EXTENDS`] = config.extends;
|
|
285
|
-
}
|
|
286
|
-
if (config.name) {
|
|
287
|
-
process.env[`${prefix}NAME`] = config.name;
|
|
288
|
-
}
|
|
289
|
-
if (config.namespace) {
|
|
290
|
-
process.env[`${prefix}NAMESPACE`] = config.namespace;
|
|
291
|
-
}
|
|
292
|
-
if (config.owner) {
|
|
293
|
-
process.env[`${prefix}OWNER`] = config.owner;
|
|
294
|
-
}
|
|
295
|
-
if (config.bot) {
|
|
296
|
-
process.env[`${prefix}BOT_NAME`] = config.bot.name;
|
|
297
|
-
process.env[`${prefix}BOT_EMAIL`] = config.bot.email;
|
|
298
|
-
}
|
|
299
|
-
if (config.organization) {
|
|
300
|
-
process.env[`${prefix}ORGANIZATION`] = config.organization;
|
|
301
|
-
}
|
|
302
|
-
if (config.packageManager) {
|
|
303
|
-
process.env[`${prefix}PACKAGE_MANAGER`] = config.packageManager;
|
|
304
|
-
}
|
|
305
|
-
if (config.license) {
|
|
306
|
-
process.env[`${prefix}LICENSE`] = config.license;
|
|
307
|
-
}
|
|
308
|
-
if (config.homepage) {
|
|
309
|
-
process.env[`${prefix}HOMEPAGE`] = config.homepage;
|
|
310
|
-
}
|
|
311
|
-
if (config.docs) {
|
|
312
|
-
process.env[`${prefix}DOCS`] = config.docs;
|
|
313
|
-
}
|
|
314
|
-
if (config.licensing) {
|
|
315
|
-
process.env[`${prefix}LICENSING`] = config.licensing;
|
|
316
|
-
}
|
|
317
|
-
if (config.timezone) {
|
|
318
|
-
process.env[`${prefix}TIMEZONE`] = config.timezone;
|
|
319
|
-
process.env.TZ = config.timezone;
|
|
320
|
-
process.env.DEFAULT_TIMEZONE = config.timezone;
|
|
321
|
-
}
|
|
322
|
-
if (config.locale) {
|
|
323
|
-
process.env[`${prefix}LOCALE`] = config.locale;
|
|
324
|
-
process.env.LOCALE = config.locale;
|
|
325
|
-
process.env.DEFAULT_LOCALE = config.locale;
|
|
326
|
-
process.env.LANG = config.locale ? `${config.locale.replaceAll("-", "_")}.UTF-8` : "en_US.UTF-8";
|
|
327
|
-
}
|
|
328
|
-
if (config.configFile) {
|
|
329
|
-
process.env[`${prefix}CONFIG_FILE`] = correctPaths(config.configFile);
|
|
330
|
-
}
|
|
331
|
-
if (config.workspaceRoot) {
|
|
332
|
-
process.env[`${prefix}WORKSPACE_ROOT`] = correctPaths(config.workspaceRoot);
|
|
333
|
-
process.env.NX_WORKSPACE_ROOT = correctPaths(config.workspaceRoot);
|
|
334
|
-
process.env.NX_WORKSPACE_ROOT_PATH = correctPaths(config.workspaceRoot);
|
|
335
|
-
}
|
|
336
|
-
if (config.directories) {
|
|
337
|
-
if (!config.skipCache && config.directories.cache) {
|
|
338
|
-
process.env[`${prefix}CACHE_DIR`] = correctPaths(config.directories.cache);
|
|
339
|
-
}
|
|
340
|
-
if (config.directories.data) {
|
|
341
|
-
process.env[`${prefix}DATA_DIR`] = correctPaths(config.directories.data);
|
|
342
|
-
}
|
|
343
|
-
if (config.directories.config) {
|
|
344
|
-
process.env[`${prefix}CONFIG_DIR`] = correctPaths(config.directories.config);
|
|
345
|
-
}
|
|
346
|
-
if (config.directories.temp) {
|
|
347
|
-
process.env[`${prefix}TEMP_DIR`] = correctPaths(config.directories.temp);
|
|
348
|
-
}
|
|
349
|
-
if (config.directories.log) {
|
|
350
|
-
process.env[`${prefix}LOG_DIR`] = correctPaths(config.directories.log);
|
|
351
|
-
}
|
|
352
|
-
if (config.directories.build) {
|
|
353
|
-
process.env[`${prefix}BUILD_DIR`] = correctPaths(config.directories.build);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (config.skipCache !== void 0) {
|
|
357
|
-
process.env[`${prefix}SKIP_CACHE`] = String(config.skipCache);
|
|
358
|
-
if (config.skipCache) {
|
|
359
|
-
process.env.NX_SKIP_NX_CACHE ??= String(config.skipCache);
|
|
360
|
-
process.env.NX_CACHE_PROJECT_GRAPH ??= String(config.skipCache);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
if (config.env) {
|
|
364
|
-
process.env[`${prefix}ENV`] = config.env;
|
|
365
|
-
process.env.NODE_ENV = config.env;
|
|
366
|
-
process.env.ENVIRONMENT = config.env;
|
|
367
|
-
}
|
|
368
|
-
if (config.colors?.base?.light || config.colors?.base?.dark) {
|
|
369
|
-
for (const key of Object.keys(config.colors)) {
|
|
370
|
-
setThemeColorConfigEnv(`${prefix}COLOR_${key}_`, config.colors[key]);
|
|
371
|
-
}
|
|
372
|
-
} else {
|
|
373
|
-
setThemeColorConfigEnv(`${prefix}COLOR_`, config.colors);
|
|
374
|
-
}
|
|
375
|
-
if (config.repository) {
|
|
376
|
-
process.env[`${prefix}REPOSITORY`] = config.repository;
|
|
377
|
-
}
|
|
378
|
-
if (config.branch) {
|
|
379
|
-
process.env[`${prefix}BRANCH`] = config.branch;
|
|
380
|
-
}
|
|
381
|
-
if (config.preid) {
|
|
382
|
-
process.env[`${prefix}PRE_ID`] = String(config.preid);
|
|
383
|
-
}
|
|
384
|
-
if (config.externalPackagePatterns) {
|
|
385
|
-
process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] = JSON.stringify(config.externalPackagePatterns);
|
|
386
|
-
}
|
|
387
|
-
if (config.registry) {
|
|
388
|
-
if (config.registry.github) {
|
|
389
|
-
process.env[`${prefix}REGISTRY_GITHUB`] = String(config.registry.github);
|
|
390
|
-
}
|
|
391
|
-
if (config.registry.npm) {
|
|
392
|
-
process.env[`${prefix}REGISTRY_NPM`] = String(config.registry.npm);
|
|
393
|
-
}
|
|
394
|
-
if (config.registry.cargo) {
|
|
395
|
-
process.env[`${prefix}REGISTRY_CARGO`] = String(config.registry.cargo);
|
|
396
|
-
}
|
|
397
|
-
if (config.registry.cyclone) {
|
|
398
|
-
process.env[`${prefix}REGISTRY_CYCLONE`] = String(config.registry.cyclone);
|
|
399
|
-
}
|
|
400
|
-
if (config.registry.container) {
|
|
401
|
-
process.env[`${prefix}REGISTRY_CONTAINER`] = String(config.registry.cyclone);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
if (config.logLevel) {
|
|
405
|
-
process.env[`${prefix}LOG_LEVEL`] = String(config.logLevel);
|
|
406
|
-
process.env.LOG_LEVEL = String(config.logLevel);
|
|
407
|
-
process.env.NX_VERBOSE_LOGGING = String(getLogLevel(config.logLevel) >= LogLevel.DEBUG ? true : false);
|
|
408
|
-
process.env.RUST_BACKTRACE = getLogLevel(config.logLevel) >= LogLevel.DEBUG ? "full" : "none";
|
|
409
|
-
}
|
|
410
|
-
process.env[`${prefix}CONFIG`] = JSON.stringify(config);
|
|
411
|
-
for (const key of Object.keys(config.extensions ?? {})) {
|
|
412
|
-
config.extensions[key] && Object.keys(config.extensions[key]) && setExtensionEnv(key, config.extensions[key]);
|
|
413
|
-
}
|
|
414
|
-
}, "setConfigEnv");
|
|
415
|
-
var setThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
|
|
416
|
-
return config?.light?.brand || config?.dark?.brand ? setMultiThemeColorConfigEnv(prefix, config) : setSingleThemeColorConfigEnv(prefix, config);
|
|
417
|
-
}, "setThemeColorConfigEnv");
|
|
418
|
-
var setSingleThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
|
|
419
|
-
if (config.dark) {
|
|
420
|
-
process.env[`${prefix}DARK`] = config.dark;
|
|
421
|
-
}
|
|
422
|
-
if (config.light) {
|
|
423
|
-
process.env[`${prefix}LIGHT`] = config.light;
|
|
424
|
-
}
|
|
425
|
-
if (config.brand) {
|
|
426
|
-
process.env[`${prefix}BRAND`] = config.brand;
|
|
427
|
-
}
|
|
428
|
-
if (config.alternate) {
|
|
429
|
-
process.env[`${prefix}ALTERNATE`] = config.alternate;
|
|
430
|
-
}
|
|
431
|
-
if (config.accent) {
|
|
432
|
-
process.env[`${prefix}ACCENT`] = config.accent;
|
|
433
|
-
}
|
|
434
|
-
if (config.link) {
|
|
435
|
-
process.env[`${prefix}LINK`] = config.link;
|
|
436
|
-
}
|
|
437
|
-
if (config.help) {
|
|
438
|
-
process.env[`${prefix}HELP`] = config.help;
|
|
439
|
-
}
|
|
440
|
-
if (config.success) {
|
|
441
|
-
process.env[`${prefix}SUCCESS`] = config.success;
|
|
442
|
-
}
|
|
443
|
-
if (config.info) {
|
|
444
|
-
process.env[`${prefix}INFO`] = config.info;
|
|
445
|
-
}
|
|
446
|
-
if (config.warning) {
|
|
447
|
-
process.env[`${prefix}WARNING`] = config.warning;
|
|
448
|
-
}
|
|
449
|
-
if (config.danger) {
|
|
450
|
-
process.env[`${prefix}DANGER`] = config.danger;
|
|
451
|
-
}
|
|
452
|
-
if (config.fatal) {
|
|
453
|
-
process.env[`${prefix}FATAL`] = config.fatal;
|
|
454
|
-
}
|
|
455
|
-
if (config.positive) {
|
|
456
|
-
process.env[`${prefix}POSITIVE`] = config.positive;
|
|
457
|
-
}
|
|
458
|
-
if (config.negative) {
|
|
459
|
-
process.env[`${prefix}NEGATIVE`] = config.negative;
|
|
460
|
-
}
|
|
461
|
-
}, "setSingleThemeColorConfigEnv");
|
|
462
|
-
var setMultiThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
|
|
463
|
-
return {
|
|
464
|
-
light: setBaseThemeColorConfigEnv(`${prefix}LIGHT_`, config.light),
|
|
465
|
-
dark: setBaseThemeColorConfigEnv(`${prefix}DARK_`, config.dark)
|
|
466
|
-
};
|
|
467
|
-
}, "setMultiThemeColorConfigEnv");
|
|
468
|
-
var setBaseThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
|
|
469
|
-
if (config.foreground) {
|
|
470
|
-
process.env[`${prefix}FOREGROUND`] = config.foreground;
|
|
471
|
-
}
|
|
472
|
-
if (config.background) {
|
|
473
|
-
process.env[`${prefix}BACKGROUND`] = config.background;
|
|
474
|
-
}
|
|
475
|
-
if (config.brand) {
|
|
476
|
-
process.env[`${prefix}BRAND`] = config.brand;
|
|
477
|
-
}
|
|
478
|
-
if (config.alternate) {
|
|
479
|
-
process.env[`${prefix}ALTERNATE`] = config.alternate;
|
|
480
|
-
}
|
|
481
|
-
if (config.accent) {
|
|
482
|
-
process.env[`${prefix}ACCENT`] = config.accent;
|
|
483
|
-
}
|
|
484
|
-
if (config.link) {
|
|
485
|
-
process.env[`${prefix}LINK`] = config.link;
|
|
486
|
-
}
|
|
487
|
-
if (config.help) {
|
|
488
|
-
process.env[`${prefix}HELP`] = config.help;
|
|
489
|
-
}
|
|
490
|
-
if (config.success) {
|
|
491
|
-
process.env[`${prefix}SUCCESS`] = config.success;
|
|
492
|
-
}
|
|
493
|
-
if (config.info) {
|
|
494
|
-
process.env[`${prefix}INFO`] = config.info;
|
|
495
|
-
}
|
|
496
|
-
if (config.warning) {
|
|
497
|
-
process.env[`${prefix}WARNING`] = config.warning;
|
|
498
|
-
}
|
|
499
|
-
if (config.danger) {
|
|
500
|
-
process.env[`${prefix}DANGER`] = config.danger;
|
|
501
|
-
}
|
|
502
|
-
if (config.fatal) {
|
|
503
|
-
process.env[`${prefix}FATAL`] = config.fatal;
|
|
504
|
-
}
|
|
505
|
-
if (config.positive) {
|
|
506
|
-
process.env[`${prefix}POSITIVE`] = config.positive;
|
|
507
|
-
}
|
|
508
|
-
if (config.negative) {
|
|
509
|
-
process.env[`${prefix}NEGATIVE`] = config.negative;
|
|
510
|
-
}
|
|
511
|
-
}, "setBaseThemeColorConfigEnv");
|
|
512
|
-
|
|
513
|
-
// ../config-tools/src/create-storm-config.ts
|
|
514
|
-
var _static_cache = void 0;
|
|
515
|
-
var loadStormConfig = /* @__PURE__ */ __name(async (workspaceRoot) => {
|
|
516
|
-
let config = {};
|
|
517
|
-
if (_static_cache?.data && _static_cache?.timestamp && _static_cache.timestamp >= Date.now() + 3e4) {
|
|
518
|
-
writeTrace(`Configuration cache hit - ${_static_cache.timestamp}`, _static_cache.data);
|
|
519
|
-
return _static_cache.data;
|
|
520
|
-
}
|
|
521
|
-
let _workspaceRoot = workspaceRoot;
|
|
522
|
-
if (!_workspaceRoot) {
|
|
523
|
-
_workspaceRoot = findWorkspaceRoot();
|
|
524
|
-
}
|
|
525
|
-
const configFile = await getConfigFile(_workspaceRoot);
|
|
526
|
-
if (!configFile) {
|
|
527
|
-
writeWarning("No Storm config file found in the current workspace. Please ensure this is the expected behavior - you can add a `storm.json` file to the root of your workspace if it is not.\n", {
|
|
528
|
-
logLevel: "all"
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
config = defu2(getConfigEnv(), configFile, getDefaultConfig(_workspaceRoot));
|
|
532
|
-
setConfigEnv(config);
|
|
533
|
-
writeTrace(`\u2699\uFE0F Using Storm configuration:
|
|
534
|
-
${formatLogMessage(config)}`, config);
|
|
535
|
-
return config;
|
|
536
|
-
}, "loadStormConfig");
|
|
537
|
-
|
|
538
|
-
// ../build-tools/src/utilities/read-nx-config.ts
|
|
539
|
-
import { existsSync } from "node:fs";
|
|
540
|
-
import { readFile } from "node:fs/promises";
|
|
541
|
-
var readNxConfig = /* @__PURE__ */ __name(async (workspaceRoot) => {
|
|
542
|
-
let rootDir = workspaceRoot;
|
|
543
|
-
if (!rootDir) {
|
|
544
|
-
const config = await loadStormConfig();
|
|
545
|
-
rootDir = config.workspaceRoot;
|
|
546
|
-
}
|
|
547
|
-
const nxJsonPath = joinPaths(rootDir, "nx.json");
|
|
548
|
-
if (!existsSync(nxJsonPath)) {
|
|
549
|
-
throw new Error("Cannot find project.json configuration");
|
|
550
|
-
}
|
|
551
|
-
const configContent = await readFile(nxJsonPath, "utf8");
|
|
552
|
-
return JSON.parse(configContent);
|
|
553
|
-
}, "readNxConfig");
|
|
554
|
-
|
|
555
|
-
// ../build-tools/src/utilities/copy-assets.ts
|
|
556
|
-
var copyAssets = /* @__PURE__ */ __name(async (config, assets, outputPath, projectRoot, projectName, sourceRoot, generatePackageJson2 = true, includeSrc = false, banner, footer) => {
|
|
557
|
-
const pendingAssets = Array.from(assets ?? []);
|
|
558
|
-
if (!pendingAssets?.some((asset) => asset?.glob === "*.md")) {
|
|
559
|
-
pendingAssets.push({
|
|
560
|
-
input: projectRoot,
|
|
561
|
-
glob: "*.md",
|
|
562
|
-
output: "/"
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
if (generatePackageJson2 === false) {
|
|
566
|
-
pendingAssets.push({
|
|
567
|
-
input: sourceRoot,
|
|
568
|
-
glob: "package.json",
|
|
569
|
-
output: "."
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
if (!pendingAssets?.some((asset) => asset?.glob === "LICENSE")) {
|
|
573
|
-
pendingAssets.push({
|
|
574
|
-
input: "",
|
|
575
|
-
glob: "LICENSE",
|
|
576
|
-
output: "."
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
if (includeSrc === true) {
|
|
580
|
-
pendingAssets.push({
|
|
581
|
-
input: sourceRoot,
|
|
582
|
-
glob: "**/{*.ts,*.tsx,*.js,*.jsx}",
|
|
583
|
-
output: "src/"
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
const nxJson = readNxConfig(config.workspaceRoot);
|
|
587
|
-
const projectGraph = readCachedProjectGraph();
|
|
588
|
-
const projectsConfigurations = readProjectsConfigurationFromProjectGraph(projectGraph);
|
|
589
|
-
if (!projectsConfigurations?.projects?.[projectName]) {
|
|
590
|
-
throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
|
|
591
|
-
}
|
|
592
|
-
const buildTarget = projectsConfigurations.projects[projectName].targets?.build;
|
|
593
|
-
if (!buildTarget) {
|
|
594
|
-
throw new Error(`The Build process failed because the project does not have a valid build target in the project.json file. Check if the file exists in the root of the project at ${joinPaths(projectRoot, "project.json")}`);
|
|
595
|
-
}
|
|
596
|
-
const result = await copyAssetsBase({
|
|
597
|
-
assets,
|
|
598
|
-
watch: false,
|
|
599
|
-
outputPath
|
|
600
|
-
}, {
|
|
601
|
-
root: config.workspaceRoot,
|
|
602
|
-
targetName: "build",
|
|
603
|
-
target: buildTarget,
|
|
604
|
-
projectName,
|
|
605
|
-
projectGraph,
|
|
606
|
-
projectsConfigurations,
|
|
607
|
-
nxJsonConfiguration: nxJson,
|
|
608
|
-
cwd: config.workspaceRoot,
|
|
609
|
-
isVerbose: isVerbose(config.logLevel)
|
|
610
|
-
});
|
|
611
|
-
if (!result.success) {
|
|
612
|
-
throw new Error("The Build process failed trying to copy assets");
|
|
613
|
-
}
|
|
614
|
-
if (includeSrc === true) {
|
|
615
|
-
writeDebug(`\u{1F4DD} Adding banner and writing source files: ${joinPaths(outputPath, "src")}`, config);
|
|
616
|
-
const files = await glob([
|
|
617
|
-
joinPaths(config.workspaceRoot, outputPath, "src/**/*.ts"),
|
|
618
|
-
joinPaths(config.workspaceRoot, outputPath, "src/**/*.tsx"),
|
|
619
|
-
joinPaths(config.workspaceRoot, outputPath, "src/**/*.js"),
|
|
620
|
-
joinPaths(config.workspaceRoot, outputPath, "src/**/*.jsx")
|
|
621
|
-
]);
|
|
622
|
-
await Promise.allSettled(files.map(async (file) => writeFile(file, `${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""}
|
|
623
|
-
|
|
624
|
-
${await readFile2(file, "utf8")}
|
|
625
|
-
|
|
626
|
-
${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}`)));
|
|
627
|
-
}
|
|
628
|
-
}, "copyAssets");
|
|
629
|
-
|
|
630
|
-
// ../build-tools/src/utilities/generate-package-json.ts
|
|
631
|
-
import { calculateProjectBuildableDependencies } from "@nx/js/src/utils/buildable-libs-utils";
|
|
632
|
-
import { Glob } from "glob";
|
|
633
|
-
import { existsSync as existsSync2 } from "node:fs";
|
|
634
|
-
import { readFile as readFile3 } from "node:fs/promises";
|
|
635
|
-
import { readCachedProjectGraph as readCachedProjectGraph2 } from "nx/src/project-graph/project-graph";
|
|
636
|
-
var addPackageDependencies = /* @__PURE__ */ __name(async (workspaceRoot, projectRoot, projectName, packageJson) => {
|
|
637
|
-
const projectDependencies = calculateProjectBuildableDependencies(void 0, readCachedProjectGraph2(), workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
|
|
638
|
-
const localPackages = [];
|
|
639
|
-
for (const project of projectDependencies.dependencies.filter((dep) => dep.node.type === "lib" && dep.node.data.root !== projectRoot && dep.node.data.root !== workspaceRoot)) {
|
|
640
|
-
const projectNode = project.node;
|
|
641
|
-
if (projectNode.data.root) {
|
|
642
|
-
const projectPackageJsonPath = joinPaths(workspaceRoot, projectNode.data.root, "package.json");
|
|
643
|
-
if (existsSync2(projectPackageJsonPath)) {
|
|
644
|
-
const projectPackageJsonContent = await readFile3(projectPackageJsonPath, "utf8");
|
|
645
|
-
const projectPackageJson = JSON.parse(projectPackageJsonContent);
|
|
646
|
-
if (projectPackageJson.private !== false) {
|
|
647
|
-
localPackages.push(projectPackageJson);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
if (localPackages.length > 0) {
|
|
653
|
-
writeTrace(`\u{1F4E6} Adding local packages to package.json: ${localPackages.map((p) => p.name).join(", ")}`);
|
|
654
|
-
packageJson.peerDependencies = localPackages.reduce((ret, localPackage) => {
|
|
655
|
-
if (!ret[localPackage.name]) {
|
|
656
|
-
ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
|
|
657
|
-
}
|
|
658
|
-
return ret;
|
|
659
|
-
}, packageJson.peerDependencies ?? {});
|
|
660
|
-
packageJson.peerDependenciesMeta = localPackages.reduce((ret, localPackage) => {
|
|
661
|
-
if (!ret[localPackage.name]) {
|
|
662
|
-
ret[localPackage.name] = {
|
|
663
|
-
optional: false
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
return ret;
|
|
667
|
-
}, packageJson.peerDependenciesMeta ?? {});
|
|
668
|
-
packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
|
|
669
|
-
if (!ret[localPackage.name]) {
|
|
670
|
-
ret[localPackage.name] = localPackage.version || "0.0.1";
|
|
671
|
-
}
|
|
672
|
-
return ret;
|
|
673
|
-
}, packageJson.peerDependencies ?? {});
|
|
674
|
-
} else {
|
|
675
|
-
writeTrace("\u{1F4E6} No local packages dependencies to add to package.json");
|
|
676
|
-
}
|
|
677
|
-
return packageJson;
|
|
678
|
-
}, "addPackageDependencies");
|
|
679
|
-
var addWorkspacePackageJsonFields = /* @__PURE__ */ __name(async (config, projectRoot, sourceRoot, projectName, includeSrc = false, packageJson) => {
|
|
680
|
-
const workspaceRoot = config.workspaceRoot ? config.workspaceRoot : findWorkspaceRoot();
|
|
681
|
-
const workspacePackageJsonContent = await readFile3(joinPaths(workspaceRoot, "package.json"), "utf8");
|
|
682
|
-
const workspacePackageJson = JSON.parse(workspacePackageJsonContent);
|
|
683
|
-
packageJson.type ??= "module";
|
|
684
|
-
packageJson.sideEffects ??= false;
|
|
685
|
-
if (includeSrc === true) {
|
|
686
|
-
let distSrc = sourceRoot.replace(projectRoot, "");
|
|
687
|
-
if (distSrc.startsWith("/")) {
|
|
688
|
-
distSrc = distSrc.substring(1);
|
|
689
|
-
}
|
|
690
|
-
packageJson.source ??= `${joinPaths(distSrc, "index.ts").replaceAll("\\", "/")}`;
|
|
691
|
-
}
|
|
692
|
-
packageJson.files ??= [
|
|
693
|
-
"dist/**/*"
|
|
694
|
-
];
|
|
695
|
-
if (includeSrc === true && !packageJson.files.includes("src")) {
|
|
696
|
-
packageJson.files.push("src/**/*");
|
|
697
|
-
}
|
|
698
|
-
packageJson.publishConfig ??= {
|
|
699
|
-
access: "public"
|
|
700
|
-
};
|
|
701
|
-
packageJson.description ??= workspacePackageJson.description;
|
|
702
|
-
packageJson.homepage ??= workspacePackageJson.homepage;
|
|
703
|
-
packageJson.bugs ??= workspacePackageJson.bugs;
|
|
704
|
-
packageJson.license ??= workspacePackageJson.license;
|
|
705
|
-
packageJson.keywords ??= workspacePackageJson.keywords;
|
|
706
|
-
packageJson.funding ??= workspacePackageJson.funding;
|
|
707
|
-
packageJson.author ??= workspacePackageJson.author;
|
|
708
|
-
packageJson.maintainers ??= workspacePackageJson.maintainers;
|
|
709
|
-
if (!packageJson.maintainers && packageJson.author) {
|
|
710
|
-
packageJson.maintainers = [
|
|
711
|
-
packageJson.author
|
|
712
|
-
];
|
|
713
|
-
}
|
|
714
|
-
packageJson.contributors ??= workspacePackageJson.contributors;
|
|
715
|
-
if (!packageJson.contributors && packageJson.author) {
|
|
716
|
-
packageJson.contributors = [
|
|
717
|
-
packageJson.author
|
|
718
|
-
];
|
|
719
|
-
}
|
|
720
|
-
packageJson.repository ??= workspacePackageJson.repository;
|
|
721
|
-
packageJson.repository.directory ??= projectRoot ? projectRoot : joinPaths("packages", projectName);
|
|
722
|
-
return packageJson;
|
|
723
|
-
}, "addWorkspacePackageJsonFields");
|
|
724
|
-
var addPackageJsonExport = /* @__PURE__ */ __name((file, type = "module", sourceRoot) => {
|
|
725
|
-
let entry = file.replaceAll("\\", "/");
|
|
726
|
-
if (sourceRoot) {
|
|
727
|
-
entry = entry.replace(sourceRoot, "");
|
|
728
|
-
}
|
|
729
|
-
return {
|
|
730
|
-
"import": {
|
|
731
|
-
"types": `./dist/${entry}.d.${type === "module" ? "ts" : "mts"}`,
|
|
732
|
-
"default": `./dist/${entry}.${type === "module" ? "js" : "mjs"}`
|
|
733
|
-
},
|
|
734
|
-
"require": {
|
|
735
|
-
"types": `./dist/${entry}.d.${type === "commonjs" ? "ts" : "cts"}`,
|
|
736
|
-
"default": `./dist/${entry}.${type === "commonjs" ? "js" : "cjs"}`
|
|
737
|
-
},
|
|
738
|
-
"default": {
|
|
739
|
-
"types": `./dist/${entry}.d.ts`,
|
|
740
|
-
"default": `./dist/${entry}.js`
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
}, "addPackageJsonExport");
|
|
744
|
-
var addPackageJsonExports = /* @__PURE__ */ __name(async (sourceRoot, packageJson) => {
|
|
745
|
-
packageJson.exports ??= {};
|
|
746
|
-
const files = await new Glob("**/*.{ts,tsx}", {
|
|
747
|
-
absolute: false,
|
|
748
|
-
cwd: sourceRoot,
|
|
749
|
-
root: sourceRoot
|
|
750
|
-
}).walk();
|
|
751
|
-
files.forEach((file) => {
|
|
752
|
-
addPackageJsonExport(file, packageJson.type, sourceRoot);
|
|
753
|
-
const split = file.split(".");
|
|
754
|
-
split.pop();
|
|
755
|
-
const entry = split.join(".").replaceAll("\\", "/");
|
|
756
|
-
packageJson.exports[`./${entry}`] ??= addPackageJsonExport(entry, packageJson.type, sourceRoot);
|
|
757
|
-
});
|
|
758
|
-
packageJson.main = packageJson.type === "commonjs" ? "./dist/index.js" : "./dist/index.cjs";
|
|
759
|
-
packageJson.module = packageJson.type === "module" ? "./dist/index.js" : "./dist/index.mjs";
|
|
760
|
-
packageJson.types = "./dist/index.d.ts";
|
|
761
|
-
packageJson.exports ??= {};
|
|
762
|
-
packageJson.exports = Object.keys(packageJson.exports).reduce((ret, key) => {
|
|
763
|
-
if (key.endsWith("/index") && !ret[key.replace("/index", "")]) {
|
|
764
|
-
ret[key.replace("/index", "")] = packageJson.exports[key];
|
|
765
|
-
}
|
|
766
|
-
return ret;
|
|
767
|
-
}, packageJson.exports);
|
|
768
|
-
packageJson.exports["./package.json"] ??= "./package.json";
|
|
769
|
-
packageJson.exports["."] = packageJson.exports["."] ?? addPackageJsonExport("index", packageJson.type, sourceRoot);
|
|
770
|
-
return packageJson;
|
|
771
|
-
}, "addPackageJsonExports");
|
|
772
|
-
|
|
773
|
-
// ../build-tools/src/utilities/get-entry-points.ts
|
|
774
|
-
import { glob as glob2 } from "glob";
|
|
775
|
-
|
|
776
|
-
// ../build-tools/src/utilities/task-graph.ts
|
|
777
|
-
import { createTaskGraph, mapTargetDefaultsToDependencies } from "nx/src/tasks-runner/create-task-graph";
|
|
778
|
-
|
|
779
|
-
// src/build.ts
|
|
780
|
-
import defu4 from "defu";
|
|
781
|
-
import { existsSync as existsSync4 } from "node:fs";
|
|
782
|
-
import { readFile as readFile4 } from "node:fs/promises";
|
|
783
|
-
import { relative as relative3 } from "node:path";
|
|
784
|
-
import { findWorkspaceRoot as findWorkspaceRoot2 } from "nx/src/utils/find-workspace-root";
|
|
785
|
-
|
|
786
|
-
// ../../node_modules/.pnpm/unbuild@3.3.1_sass@1.83.4_typescript@5.7.3/node_modules/unbuild/dist/shared/unbuild.B2_7OVir.mjs
|
|
787
|
-
import Module from "node:module";
|
|
788
|
-
import { existsSync as existsSync3, readdirSync, statSync, promises } from "node:fs";
|
|
789
|
-
import { join, resolve, normalize, dirname, relative as relative2, extname, isAbsolute } from "pathe";
|
|
790
|
-
import { colors } from "consola/utils";
|
|
791
|
-
import consola$1, { consola } from "consola";
|
|
792
|
-
import { defu as defu3 } from "defu";
|
|
793
|
-
import { createHooks } from "hookable";
|
|
794
|
-
import prettyBytes from "pretty-bytes";
|
|
795
|
-
import { glob as glob3 } from "tinyglobby";
|
|
796
|
-
import fsp, { mkdir, writeFile as writeFile2 } from "node:fs/promises";
|
|
797
|
-
import { createJiti } from "jiti";
|
|
798
|
-
import { watch, rollup } from "rollup";
|
|
799
|
-
import dts from "rollup-plugin-dts";
|
|
800
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
801
|
-
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
802
|
-
import alias from "@rollup/plugin-alias";
|
|
803
|
-
import replace from "@rollup/plugin-replace";
|
|
804
|
-
import { resolveAlias } from "pathe/utils";
|
|
805
|
-
import { findStaticImports, parseNodeModulePath, fileURLToPath, resolvePath, resolveModuleExportNames } from "mlly";
|
|
806
|
-
import { transform as transform2 } from "esbuild";
|
|
807
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
808
|
-
import rollupJSONPlugin from "@rollup/plugin-json";
|
|
809
|
-
import MagicString from "magic-string";
|
|
810
|
-
import { resolveSchema, generateMarkdown, generateTypes } from "untyped";
|
|
811
|
-
import untypedPlugin from "untyped/babel-plugin";
|
|
812
|
-
import { pascalCase } from "scule";
|
|
813
|
-
import { mkdist } from "mkdist";
|
|
814
|
-
function definePreset(preset) {
|
|
815
|
-
return preset;
|
|
816
|
-
}
|
|
817
|
-
__name(definePreset, "definePreset");
|
|
818
|
-
var autoPreset = definePreset(() => {
|
|
819
|
-
return {
|
|
820
|
-
hooks: {
|
|
821
|
-
"build:prepare"(ctx) {
|
|
822
|
-
if (!ctx.pkg || ctx.options.entries.length > 0) {
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
825
|
-
const sourceFiles = listRecursively(join(ctx.options.rootDir, "src"));
|
|
826
|
-
const res = inferEntries(ctx.pkg, sourceFiles, ctx.options.rootDir);
|
|
827
|
-
for (const message of res.warnings) {
|
|
828
|
-
warn(ctx, message);
|
|
829
|
-
}
|
|
830
|
-
ctx.options.entries.push(...res.entries);
|
|
831
|
-
if (res.cjs) {
|
|
832
|
-
ctx.options.rollup.emitCJS = true;
|
|
833
|
-
}
|
|
834
|
-
if (ctx.options.declaration === void 0) {
|
|
835
|
-
ctx.options.declaration = res.dts ? "compatible" : false;
|
|
836
|
-
}
|
|
837
|
-
consola.info(
|
|
838
|
-
"Automatically detected entries:",
|
|
839
|
-
colors.cyan(
|
|
840
|
-
ctx.options.entries.map(
|
|
841
|
-
(e) => colors.bold(
|
|
842
|
-
e.input.replace(ctx.options.rootDir + "/", "").replace(/\/$/, "/*")
|
|
843
|
-
)
|
|
844
|
-
).join(", ")
|
|
845
|
-
),
|
|
846
|
-
colors.gray(
|
|
847
|
-
["esm", res.cjs && "cjs", res.dts && "dts"].filter(Boolean).map((tag) => `[${tag}]`).join(" ")
|
|
848
|
-
)
|
|
849
|
-
);
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
});
|
|
854
|
-
function inferEntries(pkg, sourceFiles, rootDir) {
|
|
855
|
-
const warnings = [];
|
|
856
|
-
sourceFiles.sort((a, b) => a.split("/").length - b.split("/").length);
|
|
857
|
-
const outputs = extractExportFilenames(pkg.exports);
|
|
858
|
-
if (pkg.bin) {
|
|
859
|
-
const binaries = typeof pkg.bin === "string" ? [pkg.bin] : Object.values(pkg.bin);
|
|
860
|
-
for (const file of binaries) {
|
|
861
|
-
outputs.push({ file });
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
if (pkg.main) {
|
|
865
|
-
outputs.push({ file: pkg.main });
|
|
866
|
-
}
|
|
867
|
-
if (pkg.module) {
|
|
868
|
-
outputs.push({ type: "esm", file: pkg.module });
|
|
869
|
-
}
|
|
870
|
-
if (pkg.types || pkg.typings) {
|
|
871
|
-
outputs.push({ file: pkg.types || pkg.typings });
|
|
872
|
-
}
|
|
873
|
-
const isESMPkg = pkg.type === "module";
|
|
874
|
-
for (const output of outputs.filter((o) => !o.type)) {
|
|
875
|
-
const isJS = output.file.endsWith(".js");
|
|
876
|
-
if (isESMPkg && isJS || output.file.endsWith(".mjs")) {
|
|
877
|
-
output.type = "esm";
|
|
878
|
-
} else if (!isESMPkg && isJS || output.file.endsWith(".cjs")) {
|
|
879
|
-
output.type = "cjs";
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
let cjs = false;
|
|
883
|
-
let dts2 = false;
|
|
884
|
-
const entries = [];
|
|
885
|
-
for (const output of outputs) {
|
|
886
|
-
const outputSlug = output.file.replace(
|
|
887
|
-
/(\*[^/\\]*|\.d\.(m|c)?ts|\.\w+)$/,
|
|
888
|
-
""
|
|
889
|
-
);
|
|
890
|
-
const isDir = outputSlug.endsWith("/");
|
|
891
|
-
if (isDir && ["./", "/"].includes(outputSlug)) {
|
|
892
|
-
continue;
|
|
893
|
-
}
|
|
894
|
-
const possiblePaths = getEntrypointPaths(outputSlug);
|
|
895
|
-
const input = possiblePaths.reduce((source, d) => {
|
|
896
|
-
if (source) {
|
|
897
|
-
return source;
|
|
898
|
-
}
|
|
899
|
-
const SOURCE_RE = new RegExp(
|
|
900
|
-
`(?<=/|$)${d}${isDir ? "" : String.raw`\.\w+`}$`
|
|
901
|
-
);
|
|
902
|
-
return sourceFiles.find((i) => SOURCE_RE.test(i))?.replace(/(\.d\.(m|c)?ts|\.\w+)$/, "");
|
|
903
|
-
}, void 0);
|
|
904
|
-
if (!input) {
|
|
905
|
-
if (!existsSync3(resolve(rootDir || ".", output.file))) {
|
|
906
|
-
warnings.push(`Could not find entrypoint for \`${output.file}\``);
|
|
907
|
-
}
|
|
908
|
-
continue;
|
|
909
|
-
}
|
|
910
|
-
if (output.type === "cjs") {
|
|
911
|
-
cjs = true;
|
|
912
|
-
}
|
|
913
|
-
const entry = entries.find((i) => i.input === input) || entries[entries.push({ input }) - 1];
|
|
914
|
-
if (/\.d\.(m|c)?ts$/.test(output.file)) {
|
|
915
|
-
dts2 = true;
|
|
916
|
-
}
|
|
917
|
-
if (isDir) {
|
|
918
|
-
entry.outDir = outputSlug;
|
|
919
|
-
entry.format = output.type;
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
return { entries, cjs, dts: dts2, warnings };
|
|
923
|
-
}
|
|
924
|
-
__name(inferEntries, "inferEntries");
|
|
925
|
-
var getEntrypointPaths = /* @__PURE__ */ __name((path2) => {
|
|
926
|
-
const segments = normalize(path2).split("/");
|
|
927
|
-
return segments.map((_, index) => segments.slice(index).join("/")).filter(Boolean);
|
|
928
|
-
}, "getEntrypointPaths");
|
|
929
|
-
async function ensuredir(path2) {
|
|
930
|
-
await fsp.mkdir(dirname(path2), { recursive: true });
|
|
931
|
-
}
|
|
932
|
-
__name(ensuredir, "ensuredir");
|
|
933
|
-
function warn(ctx, message) {
|
|
934
|
-
if (ctx.warnings.has(message)) {
|
|
935
|
-
return;
|
|
936
|
-
}
|
|
937
|
-
consola.debug("[unbuild] [warn]", message);
|
|
938
|
-
ctx.warnings.add(message);
|
|
939
|
-
}
|
|
940
|
-
__name(warn, "warn");
|
|
941
|
-
async function symlink(from, to, force = true) {
|
|
942
|
-
await ensuredir(to);
|
|
943
|
-
if (force) {
|
|
944
|
-
await fsp.unlink(to).catch(() => {
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
await fsp.symlink(from, to, "junction");
|
|
948
|
-
}
|
|
949
|
-
__name(symlink, "symlink");
|
|
950
|
-
function dumpObject(obj) {
|
|
951
|
-
return "{ " + Object.keys(obj).map((key) => `${key}: ${JSON.stringify(obj[key])}`).join(", ") + " }";
|
|
952
|
-
}
|
|
953
|
-
__name(dumpObject, "dumpObject");
|
|
954
|
-
function getpkg(id = "") {
|
|
955
|
-
const s = id.split("/");
|
|
956
|
-
return s[0][0] === "@" ? `${s[0]}/${s[1]}` : s[0];
|
|
957
|
-
}
|
|
958
|
-
__name(getpkg, "getpkg");
|
|
959
|
-
async function rmdir(dir) {
|
|
960
|
-
await fsp.unlink(dir).catch(() => {
|
|
961
|
-
});
|
|
962
|
-
await fsp.rm(dir, { recursive: true, force: true }).catch(() => {
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
__name(rmdir, "rmdir");
|
|
966
|
-
function listRecursively(path2) {
|
|
967
|
-
const filenames = /* @__PURE__ */ new Set();
|
|
968
|
-
const walk = /* @__PURE__ */ __name((path22) => {
|
|
969
|
-
const files = readdirSync(path22);
|
|
970
|
-
for (const file of files) {
|
|
971
|
-
const fullPath = resolve(path22, file);
|
|
972
|
-
if (statSync(fullPath).isDirectory()) {
|
|
973
|
-
filenames.add(fullPath + "/");
|
|
974
|
-
walk(fullPath);
|
|
975
|
-
} else {
|
|
976
|
-
filenames.add(fullPath);
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
}, "walk");
|
|
980
|
-
walk(path2);
|
|
981
|
-
return [...filenames];
|
|
982
|
-
}
|
|
983
|
-
__name(listRecursively, "listRecursively");
|
|
984
|
-
async function resolvePreset(preset, rootDir) {
|
|
985
|
-
if (preset === "auto") {
|
|
986
|
-
preset = autoPreset;
|
|
987
|
-
} else if (typeof preset === "string") {
|
|
988
|
-
preset = await createJiti(rootDir, { interopDefault: true }).import(preset, {
|
|
989
|
-
default: true
|
|
990
|
-
}) || {};
|
|
991
|
-
}
|
|
992
|
-
if (typeof preset === "function") {
|
|
993
|
-
preset = preset();
|
|
994
|
-
}
|
|
995
|
-
return preset;
|
|
996
|
-
}
|
|
997
|
-
__name(resolvePreset, "resolvePreset");
|
|
998
|
-
function inferExportType(condition, previousConditions = [], filename = "") {
|
|
999
|
-
if (filename) {
|
|
1000
|
-
if (filename.endsWith(".d.ts")) {
|
|
1001
|
-
return "esm";
|
|
1002
|
-
}
|
|
1003
|
-
if (filename.endsWith(".mjs")) {
|
|
1004
|
-
return "esm";
|
|
1005
|
-
}
|
|
1006
|
-
if (filename.endsWith(".cjs")) {
|
|
1007
|
-
return "cjs";
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
switch (condition) {
|
|
1011
|
-
case "import": {
|
|
1012
|
-
return "esm";
|
|
1013
|
-
}
|
|
1014
|
-
case "require": {
|
|
1015
|
-
return "cjs";
|
|
1016
|
-
}
|
|
1017
|
-
default: {
|
|
1018
|
-
if (previousConditions.length === 0) {
|
|
1019
|
-
return "esm";
|
|
1020
|
-
}
|
|
1021
|
-
const [newCondition, ...rest] = previousConditions;
|
|
1022
|
-
return inferExportType(newCondition, rest, filename);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
__name(inferExportType, "inferExportType");
|
|
1027
|
-
function extractExportFilenames(exports, conditions = []) {
|
|
1028
|
-
if (!exports) {
|
|
1029
|
-
return [];
|
|
1030
|
-
}
|
|
1031
|
-
if (typeof exports === "string") {
|
|
1032
|
-
return [{ file: exports, type: "esm" }];
|
|
1033
|
-
}
|
|
1034
|
-
return Object.entries(exports).filter(([subpath]) => !subpath.endsWith(".json")).flatMap(
|
|
1035
|
-
([condition, exports2]) => typeof exports2 === "string" ? {
|
|
1036
|
-
file: exports2,
|
|
1037
|
-
type: inferExportType(condition, conditions, exports2)
|
|
1038
|
-
} : extractExportFilenames(exports2, [...conditions, condition])
|
|
1039
|
-
);
|
|
1040
|
-
}
|
|
1041
|
-
__name(extractExportFilenames, "extractExportFilenames");
|
|
1042
|
-
function arrayIncludes(arr, searchElement) {
|
|
1043
|
-
return arr.some(
|
|
1044
|
-
(entry) => entry instanceof RegExp ? entry.test(searchElement) : entry === searchElement
|
|
1045
|
-
);
|
|
1046
|
-
}
|
|
1047
|
-
__name(arrayIncludes, "arrayIncludes");
|
|
1048
|
-
function removeExtension(filename) {
|
|
1049
|
-
return filename.replace(/\.(js|mjs|cjs|ts|mts|cts|json|jsx|tsx)$/, "");
|
|
1050
|
-
}
|
|
1051
|
-
__name(removeExtension, "removeExtension");
|
|
1052
|
-
function inferPkgExternals(pkg) {
|
|
1053
|
-
const externals = [
|
|
1054
|
-
...Object.keys(pkg.dependencies || {}),
|
|
1055
|
-
...Object.keys(pkg.peerDependencies || {}),
|
|
1056
|
-
...Object.keys(pkg.devDependencies || {}).filter(
|
|
1057
|
-
(dep) => dep.startsWith("@types/")
|
|
1058
|
-
),
|
|
1059
|
-
...Object.keys(pkg.optionalDependencies || {})
|
|
1060
|
-
];
|
|
1061
|
-
if (pkg.name) {
|
|
1062
|
-
externals.push(pkg.name);
|
|
1063
|
-
if (pkg.exports) {
|
|
1064
|
-
for (const subpath of Object.keys(pkg.exports)) {
|
|
1065
|
-
if (subpath.startsWith("./")) {
|
|
1066
|
-
externals.push(pathToRegex(`${pkg.name}/${subpath.slice(2)}`));
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
if (pkg.imports) {
|
|
1072
|
-
for (const importName of Object.keys(pkg.imports)) {
|
|
1073
|
-
if (importName.startsWith("#")) {
|
|
1074
|
-
externals.push(pathToRegex(importName));
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
return [...new Set(externals)];
|
|
1079
|
-
}
|
|
1080
|
-
__name(inferPkgExternals, "inferPkgExternals");
|
|
1081
|
-
function pathToRegex(path2) {
|
|
1082
|
-
return path2.includes("*") ? new RegExp(
|
|
1083
|
-
`^${path2.replace(/\./g, String.raw`\.`).replace(/\*/g, ".*")}$`
|
|
1084
|
-
) : path2;
|
|
1085
|
-
}
|
|
1086
|
-
__name(pathToRegex, "pathToRegex");
|
|
1087
|
-
function withTrailingSlash(path2) {
|
|
1088
|
-
return path2.endsWith("/") ? path2 : `${path2}/`;
|
|
1089
|
-
}
|
|
1090
|
-
__name(withTrailingSlash, "withTrailingSlash");
|
|
1091
|
-
function validateDependencies(ctx) {
|
|
1092
|
-
const usedDependencies = /* @__PURE__ */ new Set();
|
|
1093
|
-
const unusedDependencies = new Set(
|
|
1094
|
-
Object.keys(ctx.pkg.dependencies || {})
|
|
1095
|
-
);
|
|
1096
|
-
const implicitDependencies = /* @__PURE__ */ new Set();
|
|
1097
|
-
for (const id of ctx.usedImports) {
|
|
1098
|
-
unusedDependencies.delete(id);
|
|
1099
|
-
usedDependencies.add(id);
|
|
1100
|
-
}
|
|
1101
|
-
if (Array.isArray(ctx.options.dependencies)) {
|
|
1102
|
-
for (const id of ctx.options.dependencies) {
|
|
1103
|
-
unusedDependencies.delete(id);
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
for (const id of usedDependencies) {
|
|
1107
|
-
if (!arrayIncludes(ctx.options.externals, id) && !id.startsWith("chunks/") && !ctx.options.dependencies.includes(getpkg(id)) && !ctx.options.peerDependencies.includes(getpkg(id))) {
|
|
1108
|
-
implicitDependencies.add(id);
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
if (unusedDependencies.size > 0) {
|
|
1112
|
-
warn(
|
|
1113
|
-
ctx,
|
|
1114
|
-
"Potential unused dependencies found: " + [...unusedDependencies].map((id) => colors.cyan(id)).join(", ")
|
|
1115
|
-
);
|
|
1116
|
-
}
|
|
1117
|
-
if (implicitDependencies.size > 0 && !ctx.options.rollup.inlineDependencies) {
|
|
1118
|
-
warn(
|
|
1119
|
-
ctx,
|
|
1120
|
-
"Potential implicit dependencies found: " + [...implicitDependencies].map((id) => colors.cyan(id)).join(", ")
|
|
1121
|
-
);
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
__name(validateDependencies, "validateDependencies");
|
|
1125
|
-
function validatePackage(pkg, rootDir, ctx) {
|
|
1126
|
-
if (!pkg) {
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1129
|
-
const filenames = new Set(
|
|
1130
|
-
[
|
|
1131
|
-
...typeof pkg.bin === "string" ? [pkg.bin] : Object.values(pkg.bin || {}),
|
|
1132
|
-
pkg.main,
|
|
1133
|
-
pkg.module,
|
|
1134
|
-
pkg.types,
|
|
1135
|
-
pkg.typings,
|
|
1136
|
-
...extractExportFilenames(pkg.exports).map((i) => i.file)
|
|
1137
|
-
].map((i) => i && resolve(rootDir, i.replace(/\/[^/]*\*.*$/, "")))
|
|
1138
|
-
);
|
|
1139
|
-
const missingOutputs = [];
|
|
1140
|
-
for (const filename of filenames) {
|
|
1141
|
-
if (filename && !filename.includes("*") && !existsSync3(filename)) {
|
|
1142
|
-
missingOutputs.push(filename.replace(rootDir + "/", ""));
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
if (missingOutputs.length > 0) {
|
|
1146
|
-
warn(
|
|
1147
|
-
ctx,
|
|
1148
|
-
`Potential missing package.json files: ${missingOutputs.map((o) => colors.cyan(o)).join(", ")}`
|
|
1149
|
-
);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
__name(validatePackage, "validatePackage");
|
|
1153
|
-
var SHEBANG_RE = /^#![^\n]*/;
|
|
1154
|
-
function shebangPlugin() {
|
|
1155
|
-
return {
|
|
1156
|
-
name: "unbuild-shebang",
|
|
1157
|
-
async writeBundle(options, bundle) {
|
|
1158
|
-
for (const [fileName, output] of Object.entries(bundle)) {
|
|
1159
|
-
if (output.type !== "chunk") {
|
|
1160
|
-
continue;
|
|
1161
|
-
}
|
|
1162
|
-
if (output.code?.match(SHEBANG_RE)) {
|
|
1163
|
-
const outFile = resolve(options.dir, fileName);
|
|
1164
|
-
await makeExecutable(outFile);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
};
|
|
1169
|
-
}
|
|
1170
|
-
__name(shebangPlugin, "shebangPlugin");
|
|
1171
|
-
function removeShebangPlugin() {
|
|
1172
|
-
return {
|
|
1173
|
-
name: "unbuild-remove-shebang",
|
|
1174
|
-
renderChunk(code) {
|
|
1175
|
-
return code.replace(SHEBANG_RE, "");
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1178
|
-
}
|
|
1179
|
-
__name(removeShebangPlugin, "removeShebangPlugin");
|
|
1180
|
-
async function makeExecutable(filePath) {
|
|
1181
|
-
await promises.chmod(
|
|
1182
|
-
filePath,
|
|
1183
|
-
493
|
|
1184
|
-
/* rwx r-x r-x */
|
|
1185
|
-
).catch(() => {
|
|
1186
|
-
});
|
|
1187
|
-
}
|
|
1188
|
-
__name(makeExecutable, "makeExecutable");
|
|
1189
|
-
function getShebang(code, append = "\n") {
|
|
1190
|
-
const m = code.match(SHEBANG_RE);
|
|
1191
|
-
return m ? m + append : "";
|
|
1192
|
-
}
|
|
1193
|
-
__name(getShebang, "getShebang");
|
|
1194
|
-
var DefaultLoaders = {
|
|
1195
|
-
".js": "js",
|
|
1196
|
-
".mjs": "js",
|
|
1197
|
-
".cjs": "js",
|
|
1198
|
-
".ts": "ts",
|
|
1199
|
-
".mts": "ts",
|
|
1200
|
-
".cts": "ts",
|
|
1201
|
-
".tsx": "tsx",
|
|
1202
|
-
".jsx": "jsx"
|
|
1203
|
-
};
|
|
1204
|
-
function esbuild(options) {
|
|
1205
|
-
const {
|
|
1206
|
-
include = new RegExp(Object.keys(DefaultLoaders).join("|")),
|
|
1207
|
-
exclude = /node_modules/,
|
|
1208
|
-
loaders: loaderOptions,
|
|
1209
|
-
...esbuildOptions
|
|
1210
|
-
} = options;
|
|
1211
|
-
const loaders = { ...DefaultLoaders };
|
|
1212
|
-
if (loaderOptions) {
|
|
1213
|
-
for (const [key, value] of Object.entries(loaderOptions)) {
|
|
1214
|
-
if (typeof value === "string") {
|
|
1215
|
-
loaders[key] = value;
|
|
1216
|
-
} else if (value === false) {
|
|
1217
|
-
delete loaders[key];
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
const getLoader = /* @__PURE__ */ __name((id = "") => {
|
|
1222
|
-
return loaders[extname(id)];
|
|
1223
|
-
}, "getLoader");
|
|
1224
|
-
const filter = createFilter(include, exclude);
|
|
1225
|
-
return {
|
|
1226
|
-
name: "esbuild",
|
|
1227
|
-
async transform(code, id) {
|
|
1228
|
-
if (!filter(id)) {
|
|
1229
|
-
return null;
|
|
1230
|
-
}
|
|
1231
|
-
const loader = getLoader(id);
|
|
1232
|
-
if (!loader) {
|
|
1233
|
-
return null;
|
|
1234
|
-
}
|
|
1235
|
-
const result = await transform2(code, {
|
|
1236
|
-
...esbuildOptions,
|
|
1237
|
-
loader,
|
|
1238
|
-
sourcefile: id
|
|
1239
|
-
});
|
|
1240
|
-
printWarnings(id, result, this);
|
|
1241
|
-
return {
|
|
1242
|
-
code: result.code || "",
|
|
1243
|
-
map: result.map || null
|
|
1244
|
-
};
|
|
1245
|
-
},
|
|
1246
|
-
async renderChunk(code, { fileName }) {
|
|
1247
|
-
if (!options.minify) {
|
|
1248
|
-
return null;
|
|
1249
|
-
}
|
|
1250
|
-
if (/\.d\.(c|m)?tsx?$/.test(fileName)) {
|
|
1251
|
-
return null;
|
|
1252
|
-
}
|
|
1253
|
-
const loader = getLoader(fileName);
|
|
1254
|
-
if (!loader) {
|
|
1255
|
-
return null;
|
|
1256
|
-
}
|
|
1257
|
-
const result = await transform2(code, {
|
|
1258
|
-
...esbuildOptions,
|
|
1259
|
-
loader,
|
|
1260
|
-
sourcefile: fileName,
|
|
1261
|
-
minify: true
|
|
1262
|
-
});
|
|
1263
|
-
return {
|
|
1264
|
-
code: result.code || "",
|
|
1265
|
-
map: result.map || null
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
};
|
|
1269
|
-
}
|
|
1270
|
-
__name(esbuild, "esbuild");
|
|
1271
|
-
function printWarnings(id, result, plugin) {
|
|
1272
|
-
if (result.warnings) {
|
|
1273
|
-
for (const warning of result.warnings) {
|
|
1274
|
-
let message = "[esbuild]";
|
|
1275
|
-
if (warning.location) {
|
|
1276
|
-
message += ` (${relative2(process.cwd(), id)}:${warning.location.line}:${warning.location.column})`;
|
|
1277
|
-
}
|
|
1278
|
-
message += ` ${warning.text}`;
|
|
1279
|
-
plugin.warn(message);
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
__name(printWarnings, "printWarnings");
|
|
1284
|
-
var EXPORT_DEFAULT = "export default ";
|
|
1285
|
-
function JSONPlugin(options) {
|
|
1286
|
-
const plugin = rollupJSONPlugin(options);
|
|
1287
|
-
return {
|
|
1288
|
-
...plugin,
|
|
1289
|
-
name: "unbuild-json",
|
|
1290
|
-
transform(code, id) {
|
|
1291
|
-
const res = plugin.transform.call(this, code, id);
|
|
1292
|
-
if (res && typeof res !== "string" && "code" in res && res.code && res.code.startsWith(EXPORT_DEFAULT)) {
|
|
1293
|
-
res.code = res.code.replace(EXPORT_DEFAULT, "module.exports = ");
|
|
1294
|
-
}
|
|
1295
|
-
return res;
|
|
1296
|
-
}
|
|
1297
|
-
};
|
|
1298
|
-
}
|
|
1299
|
-
__name(JSONPlugin, "JSONPlugin");
|
|
1300
|
-
var defaults = {
|
|
1301
|
-
include: [/\.(md|txt|css|htm|html)$/],
|
|
1302
|
-
exclude: []
|
|
1303
|
-
};
|
|
1304
|
-
function rawPlugin(opts = {}) {
|
|
1305
|
-
opts = { ...opts, ...defaults };
|
|
1306
|
-
const filter = createFilter(opts.include, opts.exclude);
|
|
1307
|
-
return {
|
|
1308
|
-
name: "unbuild-raw",
|
|
1309
|
-
transform(code, id) {
|
|
1310
|
-
if (filter(id)) {
|
|
1311
|
-
return {
|
|
1312
|
-
code: `export default ${JSON.stringify(code)}`,
|
|
1313
|
-
map: null
|
|
1314
|
-
};
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
};
|
|
1318
|
-
}
|
|
1319
|
-
__name(rawPlugin, "rawPlugin");
|
|
1320
|
-
function cjsPlugin(_opts) {
|
|
1321
|
-
return {
|
|
1322
|
-
name: "unbuild-cjs",
|
|
1323
|
-
renderChunk(code, _chunk, opts) {
|
|
1324
|
-
if (opts.format === "es") {
|
|
1325
|
-
return CJSToESM(code);
|
|
1326
|
-
}
|
|
1327
|
-
return null;
|
|
1328
|
-
}
|
|
1329
|
-
};
|
|
1330
|
-
}
|
|
1331
|
-
__name(cjsPlugin, "cjsPlugin");
|
|
1332
|
-
function fixCJSExportTypePlugin() {
|
|
1333
|
-
return {
|
|
1334
|
-
name: "unbuild-fix-cjs-export-type",
|
|
1335
|
-
renderChunk(code, info, opts) {
|
|
1336
|
-
if (info.type !== "chunk" || !info.fileName.endsWith(".d.cts") || !info.isEntry || info.exports?.length !== 1 || info.exports[0] !== "default") {
|
|
1337
|
-
return;
|
|
1338
|
-
}
|
|
1339
|
-
return code.replace(
|
|
1340
|
-
/(?<=(?<=[;}]|^)\s*export\s*){\s*([\w$]+)\s*as\s+default\s*}/,
|
|
1341
|
-
`= $1`
|
|
1342
|
-
);
|
|
1343
|
-
}
|
|
1344
|
-
};
|
|
1345
|
-
}
|
|
1346
|
-
__name(fixCJSExportTypePlugin, "fixCJSExportTypePlugin");
|
|
1347
|
-
var CJSyntaxRe = /__filename|__dirname|require\(|require\.resolve\(/;
|
|
1348
|
-
var CJSShim = `
|
|
1349
|
-
|
|
1350
|
-
// -- Unbuild CommonJS Shims --
|
|
1351
|
-
import __cjs_url__ from 'url';
|
|
1352
|
-
import __cjs_path__ from 'path';
|
|
1353
|
-
import __cjs_mod__ from 'module';
|
|
1354
|
-
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
1355
|
-
const __dirname = __cjs_path__.dirname(__filename);
|
|
1356
|
-
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
1357
|
-
`;
|
|
1358
|
-
function CJSToESM(code) {
|
|
1359
|
-
if (code.includes(CJSShim) || !CJSyntaxRe.test(code)) {
|
|
1360
|
-
return null;
|
|
1361
|
-
}
|
|
1362
|
-
const lastESMImport = findStaticImports(code).pop();
|
|
1363
|
-
const indexToAppend = lastESMImport ? lastESMImport.end : 0;
|
|
1364
|
-
const s = new MagicString(code);
|
|
1365
|
-
s.appendRight(indexToAppend, CJSShim);
|
|
1366
|
-
return {
|
|
1367
|
-
code: s.toString(),
|
|
1368
|
-
map: s.generateMap()
|
|
1369
|
-
};
|
|
1370
|
-
}
|
|
1371
|
-
__name(CJSToESM, "CJSToESM");
|
|
1372
|
-
var DEFAULT_EXTENSIONS = [
|
|
1373
|
-
".ts",
|
|
1374
|
-
".tsx",
|
|
1375
|
-
".mts",
|
|
1376
|
-
".cts",
|
|
1377
|
-
".mjs",
|
|
1378
|
-
".cjs",
|
|
1379
|
-
".js",
|
|
1380
|
-
".jsx",
|
|
1381
|
-
".json"
|
|
1382
|
-
];
|
|
1383
|
-
function resolveAliases(ctx) {
|
|
1384
|
-
const aliases = {
|
|
1385
|
-
[ctx.pkg.name]: ctx.options.rootDir,
|
|
1386
|
-
...ctx.options.alias
|
|
1387
|
-
};
|
|
1388
|
-
if (ctx.options.rollup.alias) {
|
|
1389
|
-
if (Array.isArray(ctx.options.rollup.alias.entries)) {
|
|
1390
|
-
Object.assign(
|
|
1391
|
-
aliases,
|
|
1392
|
-
Object.fromEntries(
|
|
1393
|
-
ctx.options.rollup.alias.entries.map((entry) => {
|
|
1394
|
-
return [entry.find, entry.replacement];
|
|
1395
|
-
})
|
|
1396
|
-
)
|
|
1397
|
-
);
|
|
1398
|
-
} else {
|
|
1399
|
-
Object.assign(
|
|
1400
|
-
aliases,
|
|
1401
|
-
ctx.options.rollup.alias.entries || ctx.options.rollup.alias
|
|
1402
|
-
);
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
return aliases;
|
|
1406
|
-
}
|
|
1407
|
-
__name(resolveAliases, "resolveAliases");
|
|
1408
|
-
function getChunkFilename(ctx, chunk, ext) {
|
|
1409
|
-
if (chunk.isDynamicEntry) {
|
|
1410
|
-
return `chunks/[name].${ext}`;
|
|
1411
|
-
}
|
|
1412
|
-
return `shared/${ctx.options.name}.[hash].${ext}`;
|
|
1413
|
-
}
|
|
1414
|
-
__name(getChunkFilename, "getChunkFilename");
|
|
1415
|
-
function getRollupOptions(ctx) {
|
|
1416
|
-
const _aliases = resolveAliases(ctx);
|
|
1417
|
-
return {
|
|
1418
|
-
input: Object.fromEntries(
|
|
1419
|
-
ctx.options.entries.filter((entry) => entry.builder === "rollup").map((entry) => [
|
|
1420
|
-
entry.name,
|
|
1421
|
-
resolve(ctx.options.rootDir, entry.input)
|
|
1422
|
-
])
|
|
1423
|
-
),
|
|
1424
|
-
output: [
|
|
1425
|
-
ctx.options.rollup.emitCJS && {
|
|
1426
|
-
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
1427
|
-
entryFileNames: "[name].cjs",
|
|
1428
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "cjs"), "chunkFileNames"),
|
|
1429
|
-
format: "cjs",
|
|
1430
|
-
exports: "auto",
|
|
1431
|
-
interop: "compat",
|
|
1432
|
-
generatedCode: { constBindings: true },
|
|
1433
|
-
externalLiveBindings: false,
|
|
1434
|
-
freeze: false,
|
|
1435
|
-
sourcemap: ctx.options.sourcemap,
|
|
1436
|
-
...ctx.options.rollup.output
|
|
1437
|
-
},
|
|
1438
|
-
{
|
|
1439
|
-
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
1440
|
-
entryFileNames: "[name].mjs",
|
|
1441
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "mjs"), "chunkFileNames"),
|
|
1442
|
-
format: "esm",
|
|
1443
|
-
exports: "auto",
|
|
1444
|
-
generatedCode: { constBindings: true },
|
|
1445
|
-
externalLiveBindings: false,
|
|
1446
|
-
freeze: false,
|
|
1447
|
-
sourcemap: ctx.options.sourcemap,
|
|
1448
|
-
...ctx.options.rollup.output
|
|
1449
|
-
}
|
|
1450
|
-
].filter(Boolean),
|
|
1451
|
-
external(originalId) {
|
|
1452
|
-
const resolvedId = resolveAlias(originalId, _aliases);
|
|
1453
|
-
const pkgName = parseNodeModulePath(resolvedId)?.name || parseNodeModulePath(originalId)?.name || getpkg(originalId);
|
|
1454
|
-
if (arrayIncludes(ctx.options.externals, pkgName) || arrayIncludes(ctx.options.externals, originalId) || arrayIncludes(ctx.options.externals, resolvedId)) {
|
|
1455
|
-
return true;
|
|
1456
|
-
}
|
|
1457
|
-
for (const id of [originalId, resolvedId]) {
|
|
1458
|
-
if (id[0] === "." || isAbsolute(id) || /src[/\\]/.test(id) || id.startsWith(ctx.pkg.name)) {
|
|
1459
|
-
return false;
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
if (ctx.options.rollup.inlineDependencies === true || Array.isArray(ctx.options.rollup.inlineDependencies) && (arrayIncludes(ctx.options.rollup.inlineDependencies, pkgName) || arrayIncludes(ctx.options.rollup.inlineDependencies, originalId) || arrayIncludes(ctx.options.rollup.inlineDependencies, resolvedId))) {
|
|
1463
|
-
return false;
|
|
1464
|
-
}
|
|
1465
|
-
warn(ctx, `Implicitly bundling "${originalId}"`);
|
|
1466
|
-
return false;
|
|
1467
|
-
},
|
|
1468
|
-
onwarn(warning, rollupWarn) {
|
|
1469
|
-
if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
|
|
1470
|
-
rollupWarn(warning);
|
|
1471
|
-
}
|
|
1472
|
-
},
|
|
1473
|
-
plugins: [
|
|
1474
|
-
ctx.options.rollup.replace && replace({
|
|
1475
|
-
...ctx.options.rollup.replace,
|
|
1476
|
-
values: {
|
|
1477
|
-
...ctx.options.replace,
|
|
1478
|
-
...ctx.options.rollup.replace.values
|
|
1479
|
-
}
|
|
1480
|
-
}),
|
|
1481
|
-
ctx.options.rollup.alias && alias({
|
|
1482
|
-
...ctx.options.rollup.alias,
|
|
1483
|
-
entries: _aliases
|
|
1484
|
-
}),
|
|
1485
|
-
ctx.options.rollup.resolve && nodeResolve({
|
|
1486
|
-
extensions: DEFAULT_EXTENSIONS,
|
|
1487
|
-
exportConditions: ["production"],
|
|
1488
|
-
...ctx.options.rollup.resolve
|
|
1489
|
-
}),
|
|
1490
|
-
ctx.options.rollup.json && JSONPlugin({
|
|
1491
|
-
...ctx.options.rollup.json
|
|
1492
|
-
}),
|
|
1493
|
-
shebangPlugin(),
|
|
1494
|
-
ctx.options.rollup.esbuild && esbuild({
|
|
1495
|
-
sourcemap: ctx.options.sourcemap,
|
|
1496
|
-
...ctx.options.rollup.esbuild
|
|
1497
|
-
}),
|
|
1498
|
-
ctx.options.rollup.commonjs && commonjs({
|
|
1499
|
-
extensions: DEFAULT_EXTENSIONS,
|
|
1500
|
-
...ctx.options.rollup.commonjs
|
|
1501
|
-
}),
|
|
1502
|
-
ctx.options.rollup.preserveDynamicImports && {
|
|
1503
|
-
renderDynamicImport() {
|
|
1504
|
-
return { left: "import(", right: ")" };
|
|
1505
|
-
}
|
|
1506
|
-
},
|
|
1507
|
-
ctx.options.rollup.cjsBridge && cjsPlugin(),
|
|
1508
|
-
rawPlugin()
|
|
1509
|
-
].filter(Boolean)
|
|
1510
|
-
};
|
|
1511
|
-
}
|
|
1512
|
-
__name(getRollupOptions, "getRollupOptions");
|
|
1513
|
-
async function rollupStub(ctx) {
|
|
1514
|
-
const babelPlugins = ctx.options.stubOptions.jiti.transformOptions?.babel?.plugins;
|
|
1515
|
-
const importedBabelPlugins = [];
|
|
1516
|
-
const serializedJitiOptions = JSON.stringify(
|
|
1517
|
-
{
|
|
1518
|
-
...ctx.options.stubOptions.jiti,
|
|
1519
|
-
alias: {
|
|
1520
|
-
...resolveAliases(ctx),
|
|
1521
|
-
...ctx.options.stubOptions.jiti.alias
|
|
1522
|
-
},
|
|
1523
|
-
transformOptions: {
|
|
1524
|
-
...ctx.options.stubOptions.jiti.transformOptions,
|
|
1525
|
-
babel: {
|
|
1526
|
-
...ctx.options.stubOptions.jiti.transformOptions?.babel,
|
|
1527
|
-
plugins: "__$BABEL_PLUGINS"
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
},
|
|
1531
|
-
null,
|
|
1532
|
-
2
|
|
1533
|
-
).replace(
|
|
1534
|
-
'"__$BABEL_PLUGINS"',
|
|
1535
|
-
Array.isArray(babelPlugins) ? "[" + babelPlugins.map((plugin, i) => {
|
|
1536
|
-
if (Array.isArray(plugin)) {
|
|
1537
|
-
const [name, ...args] = plugin;
|
|
1538
|
-
importedBabelPlugins.push(name);
|
|
1539
|
-
return `[` + [
|
|
1540
|
-
`plugin${i}`,
|
|
1541
|
-
...args.map((val) => JSON.stringify(val))
|
|
1542
|
-
].join(", ") + "]";
|
|
1543
|
-
} else {
|
|
1544
|
-
importedBabelPlugins.push(plugin);
|
|
1545
|
-
return `plugin${i}`;
|
|
1546
|
-
}
|
|
1547
|
-
}).join(",") + "]" : "[]"
|
|
1548
|
-
);
|
|
1549
|
-
for (const entry of ctx.options.entries.filter(
|
|
1550
|
-
(entry2) => entry2.builder === "rollup"
|
|
1551
|
-
)) {
|
|
1552
|
-
const output = resolve(
|
|
1553
|
-
ctx.options.rootDir,
|
|
1554
|
-
ctx.options.outDir,
|
|
1555
|
-
entry.name
|
|
1556
|
-
);
|
|
1557
|
-
const isESM = ctx.pkg.type === "module";
|
|
1558
|
-
const resolvedEntry = fileURLToPath(ctx.jiti.esmResolve(entry.input));
|
|
1559
|
-
const resolvedEntryWithoutExt = resolvedEntry.slice(
|
|
1560
|
-
0,
|
|
1561
|
-
Math.max(0, resolvedEntry.length - extname(resolvedEntry).length)
|
|
1562
|
-
);
|
|
1563
|
-
const resolvedEntryForTypeImport = isESM ? `${resolvedEntry.replace(/(\.m?)(ts)$/, "$1js")}` : resolvedEntryWithoutExt;
|
|
1564
|
-
const code = await promises.readFile(resolvedEntry, "utf8");
|
|
1565
|
-
const shebang = getShebang(code);
|
|
1566
|
-
await mkdir(dirname(output), { recursive: true });
|
|
1567
|
-
if (ctx.options.rollup.emitCJS) {
|
|
1568
|
-
const jitiCJSPath = relative2(
|
|
1569
|
-
dirname(output),
|
|
1570
|
-
await resolvePath("jiti", {
|
|
1571
|
-
url: import.meta.url,
|
|
1572
|
-
conditions: ["node", "require"]
|
|
1573
|
-
})
|
|
1574
|
-
);
|
|
1575
|
-
await writeFile2(
|
|
1576
|
-
output + ".cjs",
|
|
1577
|
-
shebang + [
|
|
1578
|
-
`const { createJiti } = require(${JSON.stringify(jitiCJSPath)})`,
|
|
1579
|
-
...importedBabelPlugins.map(
|
|
1580
|
-
(plugin, i) => `const plugin${i} = require(${JSON.stringify(plugin)})`
|
|
1581
|
-
),
|
|
1582
|
-
"",
|
|
1583
|
-
`const jiti = createJiti(__filename, ${serializedJitiOptions})`,
|
|
1584
|
-
"",
|
|
1585
|
-
`/** @type {import(${JSON.stringify(
|
|
1586
|
-
resolvedEntryForTypeImport
|
|
1587
|
-
)})} */`,
|
|
1588
|
-
`module.exports = jiti(${JSON.stringify(resolvedEntry)})`
|
|
1589
|
-
].join("\n")
|
|
1590
|
-
);
|
|
1591
|
-
}
|
|
1592
|
-
const namedExports = await resolveModuleExportNames(
|
|
1593
|
-
resolvedEntry,
|
|
1594
|
-
{
|
|
1595
|
-
extensions: DEFAULT_EXTENSIONS
|
|
1596
|
-
}
|
|
1597
|
-
).catch((error) => {
|
|
1598
|
-
warn(ctx, `Cannot analyze ${resolvedEntry} for exports:` + error);
|
|
1599
|
-
return [];
|
|
1600
|
-
});
|
|
1601
|
-
const hasDefaultExport = namedExports.includes("default") || namedExports.length === 0;
|
|
1602
|
-
const jitiESMPath = relative2(
|
|
1603
|
-
dirname(output),
|
|
1604
|
-
await resolvePath("jiti", {
|
|
1605
|
-
url: import.meta.url,
|
|
1606
|
-
conditions: ["node", "import"]
|
|
1607
|
-
})
|
|
1608
|
-
);
|
|
1609
|
-
await writeFile2(
|
|
1610
|
-
output + ".mjs",
|
|
1611
|
-
shebang + [
|
|
1612
|
-
`import { createJiti } from ${JSON.stringify(jitiESMPath)};`,
|
|
1613
|
-
...importedBabelPlugins.map(
|
|
1614
|
-
(plugin, i) => `import plugin${i} from ${JSON.stringify(plugin)}`
|
|
1615
|
-
),
|
|
1616
|
-
"",
|
|
1617
|
-
`const jiti = createJiti(import.meta.url, ${serializedJitiOptions})`,
|
|
1618
|
-
"",
|
|
1619
|
-
`/** @type {import(${JSON.stringify(resolvedEntryForTypeImport)})} */`,
|
|
1620
|
-
`const _module = await jiti.import(${JSON.stringify(
|
|
1621
|
-
resolvedEntry
|
|
1622
|
-
)});`,
|
|
1623
|
-
hasDefaultExport ? "\nexport default _module?.default ?? _module;" : "",
|
|
1624
|
-
...namedExports.filter((name) => name !== "default").map((name) => `export const ${name} = _module.${name};`)
|
|
1625
|
-
].join("\n")
|
|
1626
|
-
);
|
|
1627
|
-
if (ctx.options.declaration) {
|
|
1628
|
-
const dtsContent = [
|
|
1629
|
-
`export * from ${JSON.stringify(resolvedEntryForTypeImport)};`,
|
|
1630
|
-
hasDefaultExport ? `export { default } from ${JSON.stringify(resolvedEntryForTypeImport)};` : ""
|
|
1631
|
-
].join("\n");
|
|
1632
|
-
await writeFile2(output + ".d.cts", dtsContent);
|
|
1633
|
-
await writeFile2(output + ".d.mts", dtsContent);
|
|
1634
|
-
if (ctx.options.declaration === "compatible" || ctx.options.declaration === true) {
|
|
1635
|
-
await writeFile2(output + ".d.ts", dtsContent);
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
if (shebang) {
|
|
1639
|
-
await makeExecutable(output + ".cjs");
|
|
1640
|
-
await makeExecutable(output + ".mjs");
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
__name(rollupStub, "rollupStub");
|
|
1645
|
-
function rollupWatch(rollupOptions) {
|
|
1646
|
-
const watcher = watch(rollupOptions);
|
|
1647
|
-
let inputs;
|
|
1648
|
-
if (Array.isArray(rollupOptions.input)) {
|
|
1649
|
-
inputs = rollupOptions.input;
|
|
1650
|
-
} else if (typeof rollupOptions.input === "string") {
|
|
1651
|
-
inputs = [rollupOptions.input];
|
|
1652
|
-
} else {
|
|
1653
|
-
inputs = Object.keys(rollupOptions.input || {});
|
|
1654
|
-
}
|
|
1655
|
-
consola$1.info(
|
|
1656
|
-
`[unbuild] [rollup] Starting watchers for entries: ${inputs.map((input) => "./" + relative2(process.cwd(), input)).join(", ")}`
|
|
1657
|
-
);
|
|
1658
|
-
consola$1.warn(
|
|
1659
|
-
"[unbuild] [rollup] Watch mode is experimental and may be unstable"
|
|
1660
|
-
);
|
|
1661
|
-
watcher.on("change", (id, { event }) => {
|
|
1662
|
-
consola$1.info(`${colors.cyan(relative2(".", id))} was ${event}d`);
|
|
1663
|
-
});
|
|
1664
|
-
watcher.on("restart", () => {
|
|
1665
|
-
consola$1.info(colors.gray("[unbuild] [rollup] Rebuilding bundle"));
|
|
1666
|
-
});
|
|
1667
|
-
watcher.on("event", (event) => {
|
|
1668
|
-
if (event.code === "END") {
|
|
1669
|
-
consola$1.success(colors.green("[unbuild] [rollup] Rebuild finished\n"));
|
|
1670
|
-
}
|
|
1671
|
-
});
|
|
1672
|
-
}
|
|
1673
|
-
__name(rollupWatch, "rollupWatch");
|
|
1674
|
-
async function rollupBuild(ctx) {
|
|
1675
|
-
if (ctx.options.stub) {
|
|
1676
|
-
await rollupStub(ctx);
|
|
1677
|
-
await ctx.hooks.callHook("rollup:done", ctx);
|
|
1678
|
-
return;
|
|
1679
|
-
}
|
|
1680
|
-
const rollupOptions = getRollupOptions(ctx);
|
|
1681
|
-
await ctx.hooks.callHook("rollup:options", ctx, rollupOptions);
|
|
1682
|
-
if (Object.keys(rollupOptions.input).length === 0) {
|
|
1683
|
-
await ctx.hooks.callHook("rollup:done", ctx);
|
|
1684
|
-
return;
|
|
1685
|
-
}
|
|
1686
|
-
const buildResult = await rollup(rollupOptions);
|
|
1687
|
-
await ctx.hooks.callHook("rollup:build", ctx, buildResult);
|
|
1688
|
-
const allOutputOptions = rollupOptions.output;
|
|
1689
|
-
for (const outputOptions of allOutputOptions) {
|
|
1690
|
-
const { output } = await buildResult.write(outputOptions);
|
|
1691
|
-
const chunkFileNames = /* @__PURE__ */ new Set();
|
|
1692
|
-
const outputChunks = output.filter(
|
|
1693
|
-
(e) => e.type === "chunk"
|
|
1694
|
-
);
|
|
1695
|
-
for (const entry of outputChunks) {
|
|
1696
|
-
chunkFileNames.add(entry.fileName);
|
|
1697
|
-
for (const id of entry.imports) {
|
|
1698
|
-
ctx.usedImports.add(id);
|
|
1699
|
-
}
|
|
1700
|
-
if (entry.isEntry) {
|
|
1701
|
-
ctx.buildEntries.push({
|
|
1702
|
-
chunks: entry.imports.filter(
|
|
1703
|
-
(i) => outputChunks.find((c) => c.fileName === i)
|
|
1704
|
-
),
|
|
1705
|
-
modules: Object.entries(entry.modules).map(([id, mod]) => ({
|
|
1706
|
-
id,
|
|
1707
|
-
bytes: mod.renderedLength
|
|
1708
|
-
})),
|
|
1709
|
-
path: entry.fileName,
|
|
1710
|
-
bytes: Buffer.byteLength(entry.code, "utf8"),
|
|
1711
|
-
exports: entry.exports
|
|
1712
|
-
});
|
|
1713
|
-
}
|
|
1714
|
-
}
|
|
1715
|
-
for (const chunkFileName of chunkFileNames) {
|
|
1716
|
-
ctx.usedImports.delete(chunkFileName);
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
if (ctx.options.watch) {
|
|
1720
|
-
rollupWatch(rollupOptions);
|
|
1721
|
-
if (ctx.options.declaration && ctx.options.watch) {
|
|
1722
|
-
consola$1.warn("`rollup` DTS builder does not support watch mode yet.");
|
|
1723
|
-
}
|
|
1724
|
-
return;
|
|
1725
|
-
}
|
|
1726
|
-
if (ctx.options.declaration) {
|
|
1727
|
-
rollupOptions.plugins = [
|
|
1728
|
-
...rollupOptions.plugins,
|
|
1729
|
-
dts(ctx.options.rollup.dts),
|
|
1730
|
-
removeShebangPlugin(),
|
|
1731
|
-
ctx.options.rollup.emitCJS && fixCJSExportTypePlugin()
|
|
1732
|
-
].filter(Boolean);
|
|
1733
|
-
await ctx.hooks.callHook("rollup:dts:options", ctx, rollupOptions);
|
|
1734
|
-
const typesBuild2 = await rollup(rollupOptions);
|
|
1735
|
-
await ctx.hooks.callHook("rollup:dts:build", ctx, typesBuild2);
|
|
1736
|
-
if (ctx.options.rollup.emitCJS) {
|
|
1737
|
-
await typesBuild2.write({
|
|
1738
|
-
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
1739
|
-
entryFileNames: "[name].d.cts",
|
|
1740
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "d.cts"), "chunkFileNames")
|
|
1741
|
-
});
|
|
1742
|
-
}
|
|
1743
|
-
await typesBuild2.write({
|
|
1744
|
-
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
1745
|
-
entryFileNames: "[name].d.mts",
|
|
1746
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "d.mts"), "chunkFileNames")
|
|
1747
|
-
});
|
|
1748
|
-
if (ctx.options.declaration === true || ctx.options.declaration === "compatible") {
|
|
1749
|
-
await typesBuild2.write({
|
|
1750
|
-
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
1751
|
-
entryFileNames: "[name].d.ts",
|
|
1752
|
-
chunkFileNames: /* @__PURE__ */ __name((chunk) => getChunkFilename(ctx, chunk, "d.ts"), "chunkFileNames")
|
|
1753
|
-
});
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
await ctx.hooks.callHook("rollup:done", ctx);
|
|
1757
|
-
}
|
|
1758
|
-
__name(rollupBuild, "rollupBuild");
|
|
1759
|
-
async function typesBuild(ctx) {
|
|
1760
|
-
const entries = ctx.options.entries.filter(
|
|
1761
|
-
(entry) => entry.builder === "untyped"
|
|
1762
|
-
);
|
|
1763
|
-
await ctx.hooks.callHook("untyped:entries", ctx, entries);
|
|
1764
|
-
for (const entry of entries) {
|
|
1765
|
-
const options = {
|
|
1766
|
-
jiti: {
|
|
1767
|
-
interopDefault: true,
|
|
1768
|
-
transformOptions: {
|
|
1769
|
-
babel: {
|
|
1770
|
-
plugins: [untypedPlugin]
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
};
|
|
1775
|
-
await ctx.hooks.callHook("untyped:entry:options", ctx, entry, options);
|
|
1776
|
-
const untypedJiti = createJiti(ctx.options.rootDir, options.jiti);
|
|
1777
|
-
const distDir = entry.outDir;
|
|
1778
|
-
let rawSchema = await untypedJiti.import(resolve(ctx.options.rootDir, entry.input), {
|
|
1779
|
-
try: true
|
|
1780
|
-
}) || {};
|
|
1781
|
-
const rawSchemaKeys = Object.keys(rawSchema);
|
|
1782
|
-
if (rawSchemaKeys.length === 1 && rawSchemaKeys[0] === "default") {
|
|
1783
|
-
rawSchema = rawSchema.default;
|
|
1784
|
-
}
|
|
1785
|
-
const defaults2 = entry.defaults || {};
|
|
1786
|
-
const schema = await resolveSchema(rawSchema, defaults2);
|
|
1787
|
-
await ctx.hooks.callHook("untyped:entry:schema", ctx, entry, schema);
|
|
1788
|
-
const outputs = {
|
|
1789
|
-
markdown: {
|
|
1790
|
-
fileName: resolve(distDir, `${entry.name}.md`),
|
|
1791
|
-
contents: generateMarkdown(schema)
|
|
1792
|
-
},
|
|
1793
|
-
schema: {
|
|
1794
|
-
fileName: `${entry.name}.schema.json`,
|
|
1795
|
-
contents: JSON.stringify(schema, null, 2)
|
|
1796
|
-
},
|
|
1797
|
-
defaults: {
|
|
1798
|
-
fileName: `${entry.name}.defaults.json`,
|
|
1799
|
-
contents: JSON.stringify(defaults2, null, 2)
|
|
1800
|
-
},
|
|
1801
|
-
declaration: entry.declaration ? {
|
|
1802
|
-
fileName: `${entry.name}.d.ts`,
|
|
1803
|
-
contents: generateTypes(schema, {
|
|
1804
|
-
interfaceName: pascalCase(entry.name + "-schema")
|
|
1805
|
-
})
|
|
1806
|
-
} : void 0
|
|
1807
|
-
};
|
|
1808
|
-
await ctx.hooks.callHook("untyped:entry:outputs", ctx, entry, outputs);
|
|
1809
|
-
for (const output of Object.values(outputs)) {
|
|
1810
|
-
if (!output) continue;
|
|
1811
|
-
await writeFile2(
|
|
1812
|
-
resolve(distDir, output.fileName),
|
|
1813
|
-
output.contents,
|
|
1814
|
-
"utf8"
|
|
1815
|
-
);
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
await ctx.hooks.callHook("untyped:done", ctx);
|
|
1819
|
-
if (entries.length > 0 && ctx.options.watch) {
|
|
1820
|
-
consola$1.warn("`untyped` builder does not support watch mode yet.");
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
__name(typesBuild, "typesBuild");
|
|
1824
|
-
async function mkdistBuild(ctx) {
|
|
1825
|
-
const entries = ctx.options.entries.filter(
|
|
1826
|
-
(e) => e.builder === "mkdist"
|
|
1827
|
-
);
|
|
1828
|
-
await ctx.hooks.callHook("mkdist:entries", ctx, entries);
|
|
1829
|
-
for (const entry of entries) {
|
|
1830
|
-
const distDir = entry.outDir;
|
|
1831
|
-
if (ctx.options.stub) {
|
|
1832
|
-
await rmdir(distDir);
|
|
1833
|
-
await symlink(entry.input, distDir);
|
|
1834
|
-
} else {
|
|
1835
|
-
const mkdistOptions = {
|
|
1836
|
-
rootDir: ctx.options.rootDir,
|
|
1837
|
-
srcDir: entry.input,
|
|
1838
|
-
distDir,
|
|
1839
|
-
cleanDist: false,
|
|
1840
|
-
...entry
|
|
1841
|
-
};
|
|
1842
|
-
await ctx.hooks.callHook(
|
|
1843
|
-
"mkdist:entry:options",
|
|
1844
|
-
ctx,
|
|
1845
|
-
entry,
|
|
1846
|
-
mkdistOptions
|
|
1847
|
-
);
|
|
1848
|
-
const output = await mkdist(mkdistOptions);
|
|
1849
|
-
ctx.buildEntries.push({
|
|
1850
|
-
path: distDir,
|
|
1851
|
-
chunks: output.writtenFiles.map((p) => relative2(ctx.options.outDir, p))
|
|
1852
|
-
});
|
|
1853
|
-
await ctx.hooks.callHook("mkdist:entry:build", ctx, entry, output);
|
|
1854
|
-
if (output.errors) {
|
|
1855
|
-
for (const error of output.errors) {
|
|
1856
|
-
warn(
|
|
1857
|
-
ctx,
|
|
1858
|
-
`mkdist build failed for \`${relative2(ctx.options.rootDir, error.filename)}\`:
|
|
1859
|
-
${error.errors.map((e) => ` - ${e}`).join("\n")}`
|
|
1860
|
-
);
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
await ctx.hooks.callHook("mkdist:done", ctx);
|
|
1866
|
-
if (entries.length > 0 && ctx.options.watch) {
|
|
1867
|
-
consola$1.warn("`mkdist` builder does not support watch mode yet.");
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
__name(mkdistBuild, "mkdistBuild");
|
|
1871
|
-
var copy = promises.cp || promises.copyFile;
|
|
1872
|
-
async function copyBuild(ctx) {
|
|
1873
|
-
const entries = ctx.options.entries.filter(
|
|
1874
|
-
(e) => e.builder === "copy"
|
|
1875
|
-
);
|
|
1876
|
-
await ctx.hooks.callHook("copy:entries", ctx, entries);
|
|
1877
|
-
for (const entry of entries) {
|
|
1878
|
-
const distDir = entry.outDir;
|
|
1879
|
-
if (ctx.options.stub) {
|
|
1880
|
-
await rmdir(distDir);
|
|
1881
|
-
await symlink(entry.input, distDir);
|
|
1882
|
-
} else {
|
|
1883
|
-
const patterns = Array.isArray(entry.pattern) ? entry.pattern : [entry.pattern || "**"];
|
|
1884
|
-
const paths = await glob3(patterns, {
|
|
1885
|
-
cwd: resolve(ctx.options.rootDir, entry.input),
|
|
1886
|
-
absolute: false
|
|
1887
|
-
});
|
|
1888
|
-
const outputList = await Promise.allSettled(
|
|
1889
|
-
paths.map(async (path2) => {
|
|
1890
|
-
const src = resolve(ctx.options.rootDir, entry.input, path2);
|
|
1891
|
-
const dist = resolve(ctx.options.rootDir, distDir, path2);
|
|
1892
|
-
await copy(src, dist);
|
|
1893
|
-
return dist;
|
|
1894
|
-
})
|
|
1895
|
-
);
|
|
1896
|
-
for (const output of outputList) {
|
|
1897
|
-
if (output.status === "rejected") {
|
|
1898
|
-
warn(ctx, output.reason);
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
ctx.buildEntries.push({
|
|
1902
|
-
path: distDir,
|
|
1903
|
-
chunks: outputList.filter(({ status }) => status === "fulfilled").map(
|
|
1904
|
-
(p) => relative2(
|
|
1905
|
-
ctx.options.outDir,
|
|
1906
|
-
p.value
|
|
1907
|
-
)
|
|
1908
|
-
)
|
|
1909
|
-
});
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
await ctx.hooks.callHook("copy:done", ctx);
|
|
1913
|
-
if (entries.length > 0 && ctx.options.watch) {
|
|
1914
|
-
consola$1.warn("`untyped` builder does not support watch mode yet.");
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
__name(copyBuild, "copyBuild");
|
|
1918
|
-
async function build(rootDir, stub, inputConfig = {}) {
|
|
1919
|
-
rootDir = resolve(process.cwd(), rootDir || ".");
|
|
1920
|
-
const jiti = createJiti(rootDir);
|
|
1921
|
-
const _buildConfig = await jiti.import(inputConfig?.config || "./build.config", {
|
|
1922
|
-
try: !inputConfig.config,
|
|
1923
|
-
default: true
|
|
1924
|
-
}) || {};
|
|
1925
|
-
const buildConfigs = (Array.isArray(_buildConfig) ? _buildConfig : [_buildConfig]).filter(Boolean);
|
|
1926
|
-
const pkg = await jiti.import("./package.json", {
|
|
1927
|
-
try: true,
|
|
1928
|
-
default: true
|
|
1929
|
-
}) || {};
|
|
1930
|
-
const cleanedDirs = [];
|
|
1931
|
-
const _watchMode = inputConfig.watch === true;
|
|
1932
|
-
const _stubMode = !_watchMode && (stub || inputConfig.stub === true);
|
|
1933
|
-
for (const buildConfig of buildConfigs) {
|
|
1934
|
-
await _build(
|
|
1935
|
-
rootDir,
|
|
1936
|
-
inputConfig,
|
|
1937
|
-
buildConfig,
|
|
1938
|
-
pkg,
|
|
1939
|
-
cleanedDirs,
|
|
1940
|
-
_stubMode,
|
|
1941
|
-
_watchMode
|
|
1942
|
-
);
|
|
1943
|
-
}
|
|
1944
|
-
}
|
|
1945
|
-
__name(build, "build");
|
|
1946
|
-
async function _build(rootDir, inputConfig = {}, buildConfig, pkg, cleanedDirs, _stubMode, _watchMode) {
|
|
1947
|
-
const preset = await resolvePreset(
|
|
1948
|
-
buildConfig.preset || pkg.unbuild?.preset || pkg.build?.preset || inputConfig.preset || "auto",
|
|
1949
|
-
rootDir
|
|
1950
|
-
);
|
|
1951
|
-
const options = defu3(
|
|
1952
|
-
buildConfig,
|
|
1953
|
-
pkg.unbuild || pkg.build,
|
|
1954
|
-
inputConfig,
|
|
1955
|
-
preset,
|
|
1956
|
-
{
|
|
1957
|
-
name: (pkg?.name || "").split("/").pop() || "default",
|
|
1958
|
-
rootDir,
|
|
1959
|
-
entries: [],
|
|
1960
|
-
clean: true,
|
|
1961
|
-
declaration: void 0,
|
|
1962
|
-
outDir: "dist",
|
|
1963
|
-
stub: _stubMode,
|
|
1964
|
-
stubOptions: {
|
|
1965
|
-
/**
|
|
1966
|
-
* See https://github.com/unjs/jiti#%EF%B8%8F-options
|
|
1967
|
-
*/
|
|
1968
|
-
jiti: {
|
|
1969
|
-
interopDefault: true,
|
|
1970
|
-
alias: {}
|
|
1971
|
-
}
|
|
1972
|
-
},
|
|
1973
|
-
watch: _watchMode,
|
|
1974
|
-
watchOptions: _watchMode ? {
|
|
1975
|
-
exclude: "node_modules/**",
|
|
1976
|
-
include: "src/**"
|
|
1977
|
-
} : void 0,
|
|
1978
|
-
externals: [
|
|
1979
|
-
...Module.builtinModules,
|
|
1980
|
-
...Module.builtinModules.map((m) => "node:" + m)
|
|
1981
|
-
],
|
|
1982
|
-
dependencies: [],
|
|
1983
|
-
devDependencies: [],
|
|
1984
|
-
peerDependencies: [],
|
|
1985
|
-
alias: {},
|
|
1986
|
-
replace: {},
|
|
1987
|
-
failOnWarn: true,
|
|
1988
|
-
sourcemap: false,
|
|
1989
|
-
rollup: {
|
|
1990
|
-
emitCJS: false,
|
|
1991
|
-
watch: false,
|
|
1992
|
-
cjsBridge: false,
|
|
1993
|
-
inlineDependencies: false,
|
|
1994
|
-
preserveDynamicImports: true,
|
|
1995
|
-
output: {
|
|
1996
|
-
// https://v8.dev/features/import-attributes
|
|
1997
|
-
importAttributesKey: "with"
|
|
1998
|
-
},
|
|
1999
|
-
// Plugins
|
|
2000
|
-
replace: {
|
|
2001
|
-
preventAssignment: true
|
|
2002
|
-
},
|
|
2003
|
-
alias: {},
|
|
2004
|
-
resolve: {
|
|
2005
|
-
preferBuiltins: true
|
|
2006
|
-
},
|
|
2007
|
-
json: {
|
|
2008
|
-
preferConst: true
|
|
2009
|
-
},
|
|
2010
|
-
commonjs: {
|
|
2011
|
-
ignoreTryCatch: true
|
|
2012
|
-
},
|
|
2013
|
-
esbuild: { target: "esnext" },
|
|
2014
|
-
dts: {
|
|
2015
|
-
// https://github.com/Swatinem/rollup-plugin-dts/issues/143
|
|
2016
|
-
compilerOptions: { preserveSymlinks: false },
|
|
2017
|
-
respectExternal: true
|
|
2018
|
-
}
|
|
2019
|
-
},
|
|
2020
|
-
parallel: false
|
|
2021
|
-
}
|
|
2022
|
-
);
|
|
2023
|
-
options.outDir = resolve(options.rootDir, options.outDir);
|
|
2024
|
-
const jiti = createJiti(options.rootDir, { interopDefault: true });
|
|
2025
|
-
const ctx = {
|
|
2026
|
-
options,
|
|
2027
|
-
jiti,
|
|
2028
|
-
warnings: /* @__PURE__ */ new Set(),
|
|
2029
|
-
pkg,
|
|
2030
|
-
buildEntries: [],
|
|
2031
|
-
usedImports: /* @__PURE__ */ new Set(),
|
|
2032
|
-
hooks: createHooks()
|
|
2033
|
-
};
|
|
2034
|
-
if (preset.hooks) {
|
|
2035
|
-
ctx.hooks.addHooks(preset.hooks);
|
|
2036
|
-
}
|
|
2037
|
-
if (inputConfig.hooks) {
|
|
2038
|
-
ctx.hooks.addHooks(inputConfig.hooks);
|
|
2039
|
-
}
|
|
2040
|
-
if (buildConfig.hooks) {
|
|
2041
|
-
ctx.hooks.addHooks(buildConfig.hooks);
|
|
2042
|
-
}
|
|
2043
|
-
await ctx.hooks.callHook("build:prepare", ctx);
|
|
2044
|
-
options.entries = options.entries.map(
|
|
2045
|
-
(entry) => typeof entry === "string" ? { input: entry } : entry
|
|
2046
|
-
);
|
|
2047
|
-
for (const entry of options.entries) {
|
|
2048
|
-
if (typeof entry.name !== "string") {
|
|
2049
|
-
let relativeInput = isAbsolute(entry.input) ? relative2(rootDir, entry.input) : normalize(entry.input);
|
|
2050
|
-
if (relativeInput.startsWith("./")) {
|
|
2051
|
-
relativeInput = relativeInput.slice(2);
|
|
2052
|
-
}
|
|
2053
|
-
entry.name = removeExtension(relativeInput.replace(/^src\//, ""));
|
|
2054
|
-
}
|
|
2055
|
-
if (!entry.input) {
|
|
2056
|
-
throw new Error("Missing entry input: " + dumpObject(entry));
|
|
2057
|
-
}
|
|
2058
|
-
if (!entry.builder) {
|
|
2059
|
-
entry.builder = entry.input.endsWith("/") ? "mkdist" : "rollup";
|
|
2060
|
-
}
|
|
2061
|
-
if (options.declaration !== void 0 && entry.declaration === void 0) {
|
|
2062
|
-
entry.declaration = options.declaration;
|
|
2063
|
-
}
|
|
2064
|
-
entry.input = resolve(options.rootDir, entry.input);
|
|
2065
|
-
entry.outDir = resolve(options.rootDir, entry.outDir || options.outDir);
|
|
2066
|
-
}
|
|
2067
|
-
options.dependencies = Object.keys(pkg.dependencies || {});
|
|
2068
|
-
options.peerDependencies = Object.keys(pkg.peerDependencies || {});
|
|
2069
|
-
options.devDependencies = Object.keys(pkg.devDependencies || {});
|
|
2070
|
-
options.externals.push(...inferPkgExternals(pkg));
|
|
2071
|
-
options.externals = [...new Set(options.externals)];
|
|
2072
|
-
await ctx.hooks.callHook("build:before", ctx);
|
|
2073
|
-
consola.info(
|
|
2074
|
-
colors.cyan(`${options.stub ? "Stubbing" : "Building"} ${options.name}`)
|
|
2075
|
-
);
|
|
2076
|
-
if (process.env.DEBUG) {
|
|
2077
|
-
consola.info(`${colors.bold("Root dir:")} ${options.rootDir}
|
|
2078
|
-
${colors.bold("Entries:")}
|
|
2079
|
-
${options.entries.map((entry) => " " + dumpObject(entry)).join("\n ")}
|
|
2080
|
-
`);
|
|
2081
|
-
}
|
|
2082
|
-
if (options.clean) {
|
|
2083
|
-
for (const dir of new Set(
|
|
2084
|
-
options.entries.map((e) => e.outDir).filter(Boolean).sort()
|
|
2085
|
-
)) {
|
|
2086
|
-
if (dir === options.rootDir || options.rootDir.startsWith(withTrailingSlash(dir)) || cleanedDirs.some((c) => dir.startsWith(c))) {
|
|
2087
|
-
continue;
|
|
2088
|
-
}
|
|
2089
|
-
cleanedDirs.push(dir);
|
|
2090
|
-
consola.info(
|
|
2091
|
-
`Cleaning dist directory: \`./${relative2(process.cwd(), dir)}\``
|
|
2092
|
-
);
|
|
2093
|
-
await rmdir(dir);
|
|
2094
|
-
await promises.mkdir(dir, { recursive: true });
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
const buildTasks = [
|
|
2098
|
-
typesBuild,
|
|
2099
|
-
// untyped
|
|
2100
|
-
mkdistBuild,
|
|
2101
|
-
// mkdist
|
|
2102
|
-
rollupBuild,
|
|
2103
|
-
// rollup
|
|
2104
|
-
copyBuild
|
|
2105
|
-
// copy
|
|
2106
|
-
];
|
|
2107
|
-
if (options.parallel) {
|
|
2108
|
-
await Promise.all(buildTasks.map((task) => task(ctx)));
|
|
2109
|
-
} else {
|
|
2110
|
-
for (const task of buildTasks) {
|
|
2111
|
-
await task(ctx);
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
if (options.stub || options.watch) {
|
|
2115
|
-
await ctx.hooks.callHook("build:done", ctx);
|
|
2116
|
-
return;
|
|
2117
|
-
}
|
|
2118
|
-
consola.success(colors.green("Build succeeded for " + options.name));
|
|
2119
|
-
const outFiles = await glob3(["**"], { cwd: options.outDir });
|
|
2120
|
-
for (const file of outFiles) {
|
|
2121
|
-
let entry = ctx.buildEntries.find((e) => e.path === file);
|
|
2122
|
-
if (!entry) {
|
|
2123
|
-
entry = {
|
|
2124
|
-
path: file,
|
|
2125
|
-
chunk: true
|
|
2126
|
-
};
|
|
2127
|
-
ctx.buildEntries.push(entry);
|
|
2128
|
-
}
|
|
2129
|
-
if (!entry.bytes) {
|
|
2130
|
-
const stat = await promises.stat(resolve(options.outDir, file));
|
|
2131
|
-
entry.bytes = stat.size;
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
const rPath = /* @__PURE__ */ __name((p) => relative2(process.cwd(), resolve(options.outDir, p)), "rPath");
|
|
2135
|
-
for (const entry of ctx.buildEntries.filter((e) => !e.chunk)) {
|
|
2136
|
-
let totalBytes = entry.bytes || 0;
|
|
2137
|
-
for (const chunk of entry.chunks || []) {
|
|
2138
|
-
totalBytes += ctx.buildEntries.find((e) => e.path === chunk)?.bytes || 0;
|
|
2139
|
-
}
|
|
2140
|
-
let line = ` ${colors.bold(rPath(entry.path))} (` + [
|
|
2141
|
-
totalBytes && `total size: ${colors.cyan(prettyBytes(totalBytes))}`,
|
|
2142
|
-
entry.bytes && `chunk size: ${colors.cyan(prettyBytes(entry.bytes))}`,
|
|
2143
|
-
entry.exports?.length && `exports: ${colors.gray(entry.exports.join(", "))}`
|
|
2144
|
-
].filter(Boolean).join(", ") + ")";
|
|
2145
|
-
if (entry.chunks?.length) {
|
|
2146
|
-
line += "\n" + entry.chunks.map((p) => {
|
|
2147
|
-
const chunk = ctx.buildEntries.find((e) => e.path === p) || {};
|
|
2148
|
-
return colors.gray(
|
|
2149
|
-
" \u2514\u2500 " + rPath(p) + colors.bold(
|
|
2150
|
-
chunk.bytes ? ` (${prettyBytes(chunk?.bytes)})` : ""
|
|
2151
|
-
)
|
|
2152
|
-
);
|
|
2153
|
-
}).join("\n");
|
|
2154
|
-
}
|
|
2155
|
-
if (entry.modules?.length) {
|
|
2156
|
-
line += "\n" + entry.modules.filter((m) => m.id.includes("node_modules")).sort((a, b) => (b.bytes || 0) - (a.bytes || 0)).map((m) => {
|
|
2157
|
-
return colors.gray(
|
|
2158
|
-
" \u{1F4E6} " + rPath(m.id) + colors.bold(m.bytes ? ` (${prettyBytes(m.bytes)})` : "")
|
|
2159
|
-
);
|
|
2160
|
-
}).join("\n");
|
|
2161
|
-
}
|
|
2162
|
-
consola.log(entry.chunk ? colors.gray(line) : line);
|
|
2163
|
-
}
|
|
2164
|
-
console.log(
|
|
2165
|
-
"\u03A3 Total dist size (byte size):",
|
|
2166
|
-
colors.cyan(
|
|
2167
|
-
prettyBytes(ctx.buildEntries.reduce((a, e) => a + (e.bytes || 0), 0))
|
|
2168
|
-
)
|
|
2169
|
-
);
|
|
2170
|
-
validateDependencies(ctx);
|
|
2171
|
-
validatePackage(pkg, rootDir, ctx);
|
|
2172
|
-
await ctx.hooks.callHook("build:done", ctx);
|
|
2173
|
-
consola.log("");
|
|
2174
|
-
if (ctx.warnings.size > 0) {
|
|
2175
|
-
consola.warn(
|
|
2176
|
-
"Build is done with some warnings:\n\n" + [...ctx.warnings].map((msg) => "- " + msg).join("\n")
|
|
2177
|
-
);
|
|
2178
|
-
if (ctx.options.failOnWarn) {
|
|
2179
|
-
consola.error(
|
|
2180
|
-
"Exiting with code (1). You can change this behavior by setting `failOnWarn: false` ."
|
|
2181
|
-
);
|
|
2182
|
-
process.exit(1);
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
|
-
__name(_build, "_build");
|
|
2187
|
-
|
|
2188
|
-
// ../../node_modules/.pnpm/unbuild@3.3.1_sass@1.83.4_typescript@5.7.3/node_modules/unbuild/dist/index.mjs
|
|
2189
|
-
import "node:module";
|
|
2190
|
-
import "node:fs";
|
|
2191
|
-
import "pathe";
|
|
2192
|
-
import "consola/utils";
|
|
2193
|
-
import "consola";
|
|
2194
|
-
import "defu";
|
|
2195
|
-
import "hookable";
|
|
2196
|
-
import "pretty-bytes";
|
|
2197
|
-
import "tinyglobby";
|
|
2198
|
-
import "node:fs/promises";
|
|
2199
|
-
import "jiti";
|
|
2200
|
-
import "rollup";
|
|
2201
|
-
import "rollup-plugin-dts";
|
|
2202
|
-
import "@rollup/plugin-commonjs";
|
|
2203
|
-
import "@rollup/plugin-node-resolve";
|
|
2204
|
-
import "@rollup/plugin-alias";
|
|
2205
|
-
import "@rollup/plugin-replace";
|
|
2206
|
-
import "pathe/utils";
|
|
2207
|
-
import "mlly";
|
|
2208
|
-
import "esbuild";
|
|
2209
|
-
import "@rollup/pluginutils";
|
|
2210
|
-
import "@rollup/plugin-json";
|
|
2211
|
-
import "magic-string";
|
|
2212
|
-
import "untyped";
|
|
2213
|
-
import "untyped/babel-plugin";
|
|
2214
|
-
import "scule";
|
|
2215
|
-
import "mkdist";
|
|
2216
|
-
|
|
2217
|
-
// src/build.ts
|
|
2218
|
-
async function resolveOptions(options) {
|
|
2219
|
-
const projectRoot = options.projectRoot;
|
|
2220
|
-
if (!projectRoot) {
|
|
2221
|
-
throw new Error("Cannot find project root");
|
|
2222
|
-
}
|
|
2223
|
-
const outputPath = options.outputPath || joinPaths("dist", projectRoot);
|
|
2224
|
-
const workspaceRoot = findWorkspaceRoot2(projectRoot);
|
|
2225
|
-
if (!workspaceRoot) {
|
|
2226
|
-
throw new Error("Cannot find workspace root");
|
|
2227
|
-
}
|
|
2228
|
-
const config = await loadStormConfig(workspaceRoot.dir);
|
|
2229
|
-
writeDebug(" \u2699\uFE0F Resolving build options", config);
|
|
2230
|
-
const stopwatch = getStopwatch("Build options resolution");
|
|
2231
|
-
if (options.configPath) {
|
|
2232
|
-
const configFile = await loadConfig(options.configPath);
|
|
2233
|
-
if (configFile) {
|
|
2234
|
-
options = defu4(options, configFile);
|
|
2235
|
-
}
|
|
2236
|
-
}
|
|
2237
|
-
const projectGraph = readCachedProjectGraph3();
|
|
2238
|
-
const projectJsonPath = joinPaths(config.workspaceRoot, projectRoot, "project.json");
|
|
2239
|
-
if (!existsSync4(projectJsonPath)) {
|
|
2240
|
-
throw new Error("Cannot find project.json configuration");
|
|
2241
|
-
}
|
|
2242
|
-
const projectJsonContent = await readFile4(projectJsonPath, "utf8");
|
|
2243
|
-
const projectJson = JSON.parse(projectJsonContent);
|
|
2244
|
-
const projectName = projectJson.name;
|
|
2245
|
-
const packageJsonPath = joinPaths(workspaceRoot.dir, projectRoot, "package.json");
|
|
2246
|
-
if (!existsSync4(packageJsonPath)) {
|
|
2247
|
-
throw new Error("Cannot find package.json configuration");
|
|
2248
|
-
}
|
|
2249
|
-
const packageJsonContent = await readFile4(packageJsonPath, "utf8");
|
|
2250
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
2251
|
-
let tsconfig = options.tsconfig;
|
|
2252
|
-
if (!tsconfig) {
|
|
2253
|
-
tsconfig = joinPaths(workspaceRoot.dir, projectRoot, "tsconfig.json");
|
|
2254
|
-
}
|
|
2255
|
-
if (!existsSync4(tsconfig)) {
|
|
2256
|
-
throw new Error("Cannot find tsconfig.json configuration");
|
|
2257
|
-
}
|
|
2258
|
-
let sourceRoot = projectJson.sourceRoot;
|
|
2259
|
-
if (!sourceRoot) {
|
|
2260
|
-
sourceRoot = joinPaths(projectRoot, "src");
|
|
2261
|
-
}
|
|
2262
|
-
if (!existsSync4(sourceRoot)) {
|
|
2263
|
-
throw new Error("Cannot find sourceRoot directory");
|
|
2264
|
-
}
|
|
2265
|
-
const result = calculateProjectBuildableDependencies2(void 0, projectGraph, workspaceRoot.dir, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
|
|
2266
|
-
let dependencies = result.dependencies;
|
|
2267
|
-
const tsLibDependency = getHelperDependency(HelperDependency.tsc, tsconfig, dependencies, projectGraph, true);
|
|
2268
|
-
if (tsLibDependency) {
|
|
2269
|
-
dependencies = dependencies.filter((deps) => deps.name !== tsLibDependency.name);
|
|
2270
|
-
dependencies.push(tsLibDependency);
|
|
2271
|
-
}
|
|
2272
|
-
const resolvedOptions = {
|
|
2273
|
-
name: projectName,
|
|
2274
|
-
config,
|
|
2275
|
-
projectRoot,
|
|
2276
|
-
sourceRoot,
|
|
2277
|
-
projectName,
|
|
2278
|
-
tsconfig,
|
|
2279
|
-
clean: false,
|
|
2280
|
-
entries: [
|
|
2281
|
-
{
|
|
2282
|
-
builder: "mkdist",
|
|
2283
|
-
input: `.${sourceRoot.replace(projectRoot, "")}`,
|
|
2284
|
-
outDir: joinPaths(relative3(joinPaths(config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
|
|
2285
|
-
declaration: options.emitTypes !== false,
|
|
2286
|
-
format: "esm"
|
|
2287
|
-
},
|
|
2288
|
-
{
|
|
2289
|
-
builder: "mkdist",
|
|
2290
|
-
input: `.${sourceRoot.replace(projectRoot, "")}`,
|
|
2291
|
-
outDir: joinPaths(relative3(joinPaths(config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
|
|
2292
|
-
declaration: options.emitTypes !== false,
|
|
2293
|
-
format: "cjs",
|
|
2294
|
-
ext: "cjs"
|
|
2295
|
-
}
|
|
2296
|
-
],
|
|
2297
|
-
declaration: options.emitTypes !== false ? "compatible" : false,
|
|
2298
|
-
failOnWarn: false,
|
|
2299
|
-
sourcemap: options.sourcemap ?? !!options.debug,
|
|
2300
|
-
outDir: outputPath,
|
|
2301
|
-
parallel: true,
|
|
2302
|
-
stub: false,
|
|
2303
|
-
stubOptions: {
|
|
2304
|
-
jiti: {}
|
|
2305
|
-
},
|
|
2306
|
-
externals: options.external ?? [],
|
|
2307
|
-
dependencies: [],
|
|
2308
|
-
peerDependencies: [],
|
|
2309
|
-
devDependencies: [],
|
|
2310
|
-
hooks: {},
|
|
2311
|
-
alias: {},
|
|
2312
|
-
replace: {},
|
|
2313
|
-
rollup: {
|
|
2314
|
-
replace: {},
|
|
2315
|
-
alias: {},
|
|
2316
|
-
json: {},
|
|
2317
|
-
commonjs: {
|
|
2318
|
-
sourceMap: options.sourcemap ?? true
|
|
2319
|
-
},
|
|
2320
|
-
emitCJS: true,
|
|
2321
|
-
cjsBridge: true,
|
|
2322
|
-
dts: {
|
|
2323
|
-
respectExternal: true,
|
|
2324
|
-
tsconfig
|
|
2325
|
-
},
|
|
2326
|
-
output: {
|
|
2327
|
-
banner: options.banner || `
|
|
2328
|
-
// \u26A1 Built by Storm Software
|
|
2329
|
-
`,
|
|
2330
|
-
footer: options.footer
|
|
2331
|
-
},
|
|
2332
|
-
resolve: {
|
|
2333
|
-
preferBuiltins: true,
|
|
2334
|
-
extensions: [
|
|
2335
|
-
".cjs",
|
|
2336
|
-
".mjs",
|
|
2337
|
-
".js",
|
|
2338
|
-
".jsx",
|
|
2339
|
-
".ts",
|
|
2340
|
-
".tsx",
|
|
2341
|
-
".json"
|
|
2342
|
-
]
|
|
2343
|
-
},
|
|
2344
|
-
esbuild: {
|
|
2345
|
-
minify: !!options.minify,
|
|
2346
|
-
splitting: options.splitting !== false,
|
|
2347
|
-
treeShaking: options.treeShaking !== false,
|
|
2348
|
-
color: true,
|
|
2349
|
-
logLevel: config.logLevel === LogLevelLabel.FATAL ? LogLevelLabel.ERROR : isVerbose() ? "verbose" : config.logLevel
|
|
2350
|
-
}
|
|
2351
|
-
}
|
|
2352
|
-
};
|
|
2353
|
-
dependencies = dependencies.filter((dep) => dep.node.type === "npm" || dep.node.type === "lib" || dep.node.type === "app");
|
|
2354
|
-
if (dependencies.length > 0) {
|
|
2355
|
-
resolvedOptions.dependencies = dependencies.map((dep) => dep.name);
|
|
2356
|
-
}
|
|
2357
|
-
if (packageJson.devDependencies) {
|
|
2358
|
-
resolvedOptions.devDependencies = Object.keys(packageJson.devDependencies);
|
|
2359
|
-
}
|
|
2360
|
-
if (packageJson.peerDependencies) {
|
|
2361
|
-
resolvedOptions.peerDependencies = Object.keys(packageJson.peerDependencies);
|
|
2362
|
-
}
|
|
2363
|
-
if (options.rollup) {
|
|
2364
|
-
let rollup2 = {};
|
|
2365
|
-
if (typeof options.rollup === "string") {
|
|
2366
|
-
const rollupFile = await loadConfig(options.rollup);
|
|
2367
|
-
if (rollupFile) {
|
|
2368
|
-
rollup2 = rollupFile;
|
|
2369
|
-
}
|
|
2370
|
-
} else {
|
|
2371
|
-
rollup2 = options.rollup;
|
|
2372
|
-
}
|
|
2373
|
-
resolvedOptions.rollup = defu4(resolvedOptions.rollup ?? {}, rollup2);
|
|
2374
|
-
}
|
|
2375
|
-
resolvedOptions.hooks = {
|
|
2376
|
-
"rollup:options": /* @__PURE__ */ __name(async (ctx, opts) => {
|
|
2377
|
-
opts.plugins = options.plugins ?? await getDefaultBuildPlugins(options, resolvedOptions);
|
|
2378
|
-
}, "rollup:options")
|
|
2379
|
-
};
|
|
2380
|
-
stopwatch();
|
|
2381
|
-
return resolvedOptions;
|
|
2382
|
-
}
|
|
2383
|
-
__name(resolveOptions, "resolveOptions");
|
|
2384
|
-
async function generatePackageJson(options) {
|
|
2385
|
-
if (options.generatePackageJson !== false && existsSync4(joinPaths(options.projectRoot, "package.json"))) {
|
|
2386
|
-
writeDebug(" \u270D\uFE0F Writing package.json file", options.config);
|
|
2387
|
-
const stopwatch = getStopwatch("Write package.json file");
|
|
2388
|
-
const packageJsonPath = joinPaths(options.projectRoot, "project.json");
|
|
2389
|
-
if (!existsSync4(packageJsonPath)) {
|
|
2390
|
-
throw new Error("Cannot find package.json configuration");
|
|
2391
|
-
}
|
|
2392
|
-
let packageJsonContent = await readFile4(joinPaths(options.config.workspaceRoot, options.projectRoot, "package.json"), "utf8");
|
|
2393
|
-
if (!packageJsonContent) {
|
|
2394
|
-
throw new Error("Cannot find package.json configuration file");
|
|
2395
|
-
}
|
|
2396
|
-
let packageJson = JSON.parse(packageJsonContent);
|
|
2397
|
-
packageJson = await addPackageDependencies(options.config.workspaceRoot, options.projectRoot, options.projectName, packageJson);
|
|
2398
|
-
packageJson = await addWorkspacePackageJsonFields(options.config, options.projectRoot, options.sourceRoot, options.projectName, false, packageJson);
|
|
2399
|
-
await writeJsonFile(joinPaths(options.outDir, "package.json"), await addPackageJsonExports(options.sourceRoot, packageJson));
|
|
2400
|
-
stopwatch();
|
|
2401
|
-
}
|
|
2402
|
-
return options;
|
|
2403
|
-
}
|
|
2404
|
-
__name(generatePackageJson, "generatePackageJson");
|
|
2405
|
-
async function executeUnbuild(options) {
|
|
2406
|
-
writeDebug(` \u{1F680} Running ${options.name} (${options.projectRoot}) build`, options.config);
|
|
2407
|
-
const stopwatch = getStopwatch(`${options.name} (${options.projectRoot}) build`);
|
|
2408
|
-
try {
|
|
2409
|
-
await build(options.projectRoot, false, {
|
|
2410
|
-
...options,
|
|
2411
|
-
rootDir: options.projectRoot
|
|
2412
|
-
});
|
|
2413
|
-
} finally {
|
|
2414
|
-
stopwatch();
|
|
2415
|
-
}
|
|
2416
|
-
return options;
|
|
2417
|
-
}
|
|
2418
|
-
__name(executeUnbuild, "executeUnbuild");
|
|
2419
|
-
async function copyBuildAssets(options) {
|
|
2420
|
-
writeDebug(` \u{1F4CB} Copying asset files to output directory: ${options.outDir}`, options.config);
|
|
2421
|
-
const stopwatch = getStopwatch(`${options.name} asset copy`);
|
|
2422
|
-
await copyAssets(options.config, options.assets ?? [], options.outDir, options.projectRoot, options.projectName, options.sourceRoot, options.generatePackageJson, options.includeSrc);
|
|
2423
|
-
stopwatch();
|
|
2424
|
-
return options;
|
|
2425
|
-
}
|
|
2426
|
-
__name(copyBuildAssets, "copyBuildAssets");
|
|
2427
|
-
async function cleanOutputPath(options) {
|
|
2428
|
-
if (options.clean !== false && options.outDir) {
|
|
2429
|
-
await clean(options.name, options.outDir, options.config);
|
|
2430
|
-
}
|
|
2431
|
-
return options;
|
|
2432
|
-
}
|
|
2433
|
-
__name(cleanOutputPath, "cleanOutputPath");
|
|
2434
|
-
async function build2(options) {
|
|
2435
|
-
writeDebug(` \u26A1 Executing Storm Unbuild pipeline`);
|
|
2436
|
-
const stopwatch = getStopwatch("Unbuild pipeline");
|
|
2437
|
-
try {
|
|
2438
|
-
const resolvedOptions = await resolveOptions(options);
|
|
2439
|
-
await cleanOutputPath(resolvedOptions);
|
|
2440
|
-
await generatePackageJson(resolvedOptions);
|
|
2441
|
-
await executeUnbuild(resolvedOptions);
|
|
2442
|
-
await copyBuildAssets(resolvedOptions);
|
|
2443
|
-
writeSuccess(` \u{1F3C1} The ${resolvedOptions.name} build completed successfully`, resolvedOptions.config);
|
|
2444
|
-
} catch (error) {
|
|
2445
|
-
writeFatal(" \u274C Fatal errors occurred during the build that could not be recovered from. The build process has been terminated.");
|
|
2446
|
-
throw error;
|
|
2447
|
-
} finally {
|
|
2448
|
-
stopwatch();
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
__name(build2, "build");
|
|
2452
|
-
|
|
2453
|
-
export {
|
|
2454
|
-
build2 as build
|
|
2455
|
-
};
|