@storm-software/unbuild 0.23.1 → 0.24.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.
Files changed (58) hide show
  1. package/README.md +1 -1
  2. package/bin/unbuild.js +47614 -7629
  3. package/bin/unbuild.mjs +47605 -7624
  4. package/dist/build.js +14 -7
  5. package/dist/build.mjs +13 -6
  6. package/dist/chunk-26H2BQTK.mjs +2446 -0
  7. package/dist/{chunk-T5JY3PDF.js → chunk-27VOTZLA.js} +6 -3
  8. package/dist/chunk-45FJ3WQ6.js +7528 -0
  9. package/dist/chunk-4HFICKAT.js +451 -0
  10. package/dist/chunk-4IU7LXNH.mjs +4054 -0
  11. package/dist/{chunk-K7L2WB3G.mjs → chunk-4QTKZ7Y7.mjs} +4 -1
  12. package/dist/chunk-AMTVM7UD.js +4054 -0
  13. package/dist/{chunk-SLC5BBLC.js → chunk-D4WJVAJM.js} +5 -3
  14. package/dist/chunk-DIRFSBOA.mjs +84 -0
  15. package/dist/chunk-EGCWTBMT.mjs +1120 -0
  16. package/dist/chunk-EKTZK3IJ.mjs +765 -0
  17. package/dist/chunk-FAXWFK7Q.mjs +7528 -0
  18. package/dist/chunk-J3DIENOH.mjs +3056 -0
  19. package/dist/{chunk-67M6JMGM.mjs → chunk-JLKG5B52.mjs} +3 -1
  20. package/dist/chunk-K5SQO3GD.mjs +451 -0
  21. package/dist/{chunk-TAHELANG.js → chunk-L76UPCDF.js} +4 -2
  22. package/dist/chunk-NMYL4VJJ.js +84 -0
  23. package/dist/{chunk-OUDNDBMR.mjs → chunk-NXZFF473.mjs} +3 -1
  24. package/dist/{chunk-LYYHOUCS.js → chunk-QPMFJ7G7.js} +4 -2
  25. package/dist/chunk-RM7SW35Z.js +1120 -0
  26. package/dist/{chunk-5A3XPRPO.js → chunk-RNM4JSUG.js} +6 -6
  27. package/dist/chunk-S532A3LO.js +510 -0
  28. package/dist/{chunk-XPX5NQ4D.mjs → chunk-TCARWZKA.mjs} +3 -3
  29. package/dist/{chunk-AQ2MDNLT.mjs → chunk-UT4OJQUT.mjs} +3 -1
  30. package/dist/chunk-VJI72AA6.mjs +510 -0
  31. package/dist/chunk-W7YS7HE5.js +765 -0
  32. package/dist/chunk-X6Y2OZGW.js +3056 -0
  33. package/dist/chunk-YXF5LOZH.js +2449 -0
  34. package/dist/clean.js +3 -2
  35. package/dist/clean.mjs +2 -1
  36. package/dist/config.js +6 -5
  37. package/dist/config.mjs +5 -4
  38. package/dist/dist-JWSUGJW5.js +17571 -0
  39. package/dist/dist-LXRVOZWD.mjs +17570 -0
  40. package/dist/esm-2JSYGY2W.js +1716 -0
  41. package/dist/esm-2LICJFKF.mjs +1716 -0
  42. package/dist/execa-2KYLC5PR.mjs +2424 -0
  43. package/dist/execa-QRX32ES4.js +2424 -0
  44. package/dist/index.js +14 -7
  45. package/dist/index.mjs +13 -6
  46. package/dist/json5-JI6Y4EBT.mjs +10 -0
  47. package/dist/json5-ZRUT32KA.js +10 -0
  48. package/dist/jsonc-2MC7UMCL.js +15 -0
  49. package/dist/jsonc-PDDMSRDH.mjs +15 -0
  50. package/dist/multipart-parser-FQDS23TV.mjs +187 -0
  51. package/dist/multipart-parser-IX66WIWH.js +187 -0
  52. package/dist/toml-IHKP66UV.mjs +10 -0
  53. package/dist/toml-MDHAEB3G.js +10 -0
  54. package/dist/yaml-GMY56OHD.mjs +10 -0
  55. package/dist/yaml-UTMAXQ2T.js +10 -0
  56. package/package.json +4 -4
  57. package/dist/chunk-NA6OVNJI.js +0 -287
  58. package/dist/chunk-Q6WN55YR.mjs +0 -287
@@ -1,287 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } }
2
-
3
- var _chunkT5JY3PDFjs = require('./chunk-T5JY3PDF.js');
4
-
5
-
6
- var _chunk5A3XPRPOjs = require('./chunk-5A3XPRPO.js');
7
-
8
-
9
- var _chunkTAHELANGjs = require('./chunk-TAHELANG.js');
10
-
11
-
12
-
13
- var _chunkRBSVNX4Wjs = require('./chunk-RBSVNX4W.js');
14
-
15
- // src/build.ts
16
- _chunkRBSVNX4Wjs.init_cjs_shims.call(void 0, );
17
- var _devkit = require('@nx/devkit');
18
- var _js = require('@nx/js');
19
- var _buildablelibsutils = require('@nx/js/src/utils/buildable-libs-utils');
20
- var _buildtools = require('@storm-software/build-tools');
21
- var _createstormconfig = require('@storm-software/config-tools/create-storm-config');
22
- var _console = require('@storm-software/config-tools/logger/console');
23
- var _getloglevel = require('@storm-software/config-tools/logger/get-log-level');
24
- var _types = require('@storm-software/config-tools/types');
25
- var _correctpaths = require('@storm-software/config-tools/utilities/correct-paths');
26
- var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu);
27
- var _jiti = require('jiti');
28
- var _fs = require('fs');
29
- var _promises = require('fs/promises');
30
- var _path = require('path');
31
- var _findworkspaceroot = require('nx/src/utils/find-workspace-root');
32
- async function resolveOptions(options) {
33
- const projectRoot = options.projectRoot;
34
- if (!projectRoot) {
35
- throw new Error("Cannot find project root");
36
- }
37
- const outputPath = options.outputPath || _correctpaths.joinPaths.call(void 0, "dist", projectRoot);
38
- const workspaceRoot = _findworkspaceroot.findWorkspaceRoot.call(void 0, projectRoot);
39
- if (!workspaceRoot) {
40
- throw new Error("Cannot find workspace root");
41
- }
42
- const config = await _createstormconfig.loadStormConfig.call(void 0, workspaceRoot.dir);
43
- _console.writeDebug.call(void 0, " \u2699\uFE0F Resolving build options", config);
44
- const stopwatch = _console.getStopwatch.call(void 0, "Build options resolution");
45
- if (options.configPath) {
46
- const configFile = await _chunkTAHELANGjs.loadConfig.call(void 0, options.configPath);
47
- if (configFile) {
48
- options = _defu2.default.call(void 0, options, configFile);
49
- }
50
- }
51
- const projectGraph = _devkit.readCachedProjectGraph.call(void 0, );
52
- const projectJsonPath = _correctpaths.joinPaths.call(void 0, config.workspaceRoot, projectRoot, "project.json");
53
- if (!_fs.existsSync.call(void 0, projectJsonPath)) {
54
- throw new Error("Cannot find project.json configuration");
55
- }
56
- const projectJsonContent = await _promises.readFile.call(void 0, projectJsonPath, "utf8");
57
- const projectJson = JSON.parse(projectJsonContent);
58
- const projectName = projectJson.name;
59
- const packageJsonPath = _correctpaths.joinPaths.call(void 0, workspaceRoot.dir, projectRoot, "package.json");
60
- if (!_fs.existsSync.call(void 0, packageJsonPath)) {
61
- throw new Error("Cannot find package.json configuration");
62
- }
63
- const packageJsonContent = await _promises.readFile.call(void 0, packageJsonPath, "utf8");
64
- const packageJson = JSON.parse(packageJsonContent);
65
- let tsconfig = options.tsconfig;
66
- if (!tsconfig) {
67
- tsconfig = _correctpaths.joinPaths.call(void 0, workspaceRoot.dir, projectRoot, "tsconfig.json");
68
- }
69
- if (!_fs.existsSync.call(void 0, tsconfig)) {
70
- throw new Error("Cannot find tsconfig.json configuration");
71
- }
72
- let sourceRoot = projectJson.sourceRoot;
73
- if (!sourceRoot) {
74
- sourceRoot = _correctpaths.joinPaths.call(void 0, projectRoot, "src");
75
- }
76
- if (!_fs.existsSync.call(void 0, sourceRoot)) {
77
- throw new Error("Cannot find sourceRoot directory");
78
- }
79
- const result = _buildablelibsutils.calculateProjectBuildableDependencies.call(void 0, void 0, projectGraph, workspaceRoot.dir, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
80
- let dependencies = result.dependencies;
81
- const tsLibDependency = _js.getHelperDependency.call(void 0, _js.HelperDependency.tsc, tsconfig, dependencies, projectGraph, true);
82
- if (tsLibDependency) {
83
- dependencies = dependencies.filter((deps) => deps.name !== tsLibDependency.name);
84
- dependencies.push(tsLibDependency);
85
- }
86
- const jiti = _jiti.createJiti.call(void 0, config.workspaceRoot, {
87
- fsCache: config.skipCache ? false : _correctpaths.joinPaths.call(void 0, config.directories.cache || "node_modules/.cache/storm", "jiti"),
88
- interopDefault: true
89
- });
90
- const resolvedOptions = {
91
- name: projectName,
92
- config,
93
- projectRoot,
94
- sourceRoot,
95
- projectName,
96
- tsconfig,
97
- jiti,
98
- clean: false,
99
- entries: [
100
- {
101
- builder: "mkdist",
102
- input: `.${sourceRoot.replace(projectRoot, "")}`,
103
- outDir: _correctpaths.joinPaths.call(void 0, _path.relative.call(void 0, _correctpaths.joinPaths.call(void 0, config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
104
- declaration: options.emitTypes !== false,
105
- format: "esm"
106
- },
107
- {
108
- builder: "mkdist",
109
- input: `.${sourceRoot.replace(projectRoot, "")}`,
110
- outDir: _correctpaths.joinPaths.call(void 0, _path.relative.call(void 0, _correctpaths.joinPaths.call(void 0, config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
111
- declaration: options.emitTypes !== false,
112
- format: "cjs",
113
- ext: "cjs"
114
- }
115
- ],
116
- declaration: options.emitTypes !== false ? "compatible" : false,
117
- failOnWarn: false,
118
- sourcemap: _nullishCoalesce(options.sourcemap, () => ( !!options.debug)),
119
- outDir: outputPath,
120
- parallel: true,
121
- stub: false,
122
- stubOptions: {
123
- jiti: {}
124
- },
125
- externals: _nullishCoalesce(options.external, () => ( [])),
126
- dependencies: [],
127
- peerDependencies: [],
128
- devDependencies: [],
129
- hooks: {},
130
- alias: {},
131
- replace: {},
132
- rollup: {
133
- replace: {},
134
- alias: {},
135
- json: {},
136
- commonjs: {
137
- sourceMap: _nullishCoalesce(options.sourcemap, () => ( true))
138
- },
139
- emitCJS: true,
140
- cjsBridge: true,
141
- dts: {
142
- respectExternal: true,
143
- tsconfig
144
- },
145
- output: {
146
- banner: options.banner || `
147
- // \u26A1 Built by Storm Software
148
- `,
149
- footer: options.footer
150
- },
151
- resolve: {
152
- preferBuiltins: true,
153
- extensions: [
154
- ".cjs",
155
- ".mjs",
156
- ".js",
157
- ".jsx",
158
- ".ts",
159
- ".tsx",
160
- ".json"
161
- ]
162
- },
163
- esbuild: {
164
- minify: options.minify !== false,
165
- splitting: options.splitting !== false,
166
- treeShaking: options.treeShaking !== false,
167
- color: true,
168
- logLevel: config.logLevel === _types.LogLevelLabel.FATAL ? _types.LogLevelLabel.ERROR : _getloglevel.isVerbose.call(void 0, ) ? "verbose" : config.logLevel
169
- }
170
- }
171
- };
172
- dependencies = dependencies.filter((dep) => dep.node.type === "npm" || dep.node.type === "lib" || dep.node.type === "app");
173
- if (dependencies.length > 0) {
174
- resolvedOptions.dependencies = dependencies.map((dep) => dep.name);
175
- }
176
- if (packageJson.devDependencies) {
177
- resolvedOptions.devDependencies = Object.keys(packageJson.devDependencies);
178
- }
179
- if (packageJson.peerDependencies) {
180
- resolvedOptions.peerDependencies = Object.keys(packageJson.peerDependencies);
181
- }
182
- if (options.rollup) {
183
- let rollup = {};
184
- if (typeof options.rollup === "string") {
185
- const rollupFile = await _chunkTAHELANGjs.loadConfig.call(void 0, options.rollup);
186
- if (rollupFile) {
187
- rollup = rollupFile;
188
- }
189
- } else {
190
- rollup = options.rollup;
191
- }
192
- resolvedOptions.rollup = _defu2.default.call(void 0, _nullishCoalesce(resolvedOptions.rollup, () => ( {})), rollup);
193
- }
194
- resolvedOptions.hooks = {
195
- "rollup:options": /* @__PURE__ */ _chunkRBSVNX4Wjs.__name.call(void 0, async (ctx, opts) => {
196
- opts.plugins = await _asyncNullishCoalesce(options.plugins, async () => ( await _chunk5A3XPRPOjs.getDefaultBuildPlugins.call(void 0, options, resolvedOptions)));
197
- }, "rollup:options")
198
- };
199
- stopwatch();
200
- return resolvedOptions;
201
- }
202
- _chunkRBSVNX4Wjs.__name.call(void 0, resolveOptions, "resolveOptions");
203
- async function generatePackageJson(options) {
204
- if (options.generatePackageJson !== false && _fs.existsSync.call(void 0, _correctpaths.joinPaths.call(void 0, options.projectRoot, "package.json"))) {
205
- _console.writeDebug.call(void 0, " \u270D\uFE0F Writing package.json file", options.config);
206
- const stopwatch = _console.getStopwatch.call(void 0, "Write package.json file");
207
- const packageJsonPath = _correctpaths.joinPaths.call(void 0, options.projectRoot, "project.json");
208
- if (!_fs.existsSync.call(void 0, packageJsonPath)) {
209
- throw new Error("Cannot find package.json configuration");
210
- }
211
- let packageJsonContent = await _promises.readFile.call(void 0, _correctpaths.joinPaths.call(void 0, options.config.workspaceRoot, options.projectRoot, "package.json"), "utf8");
212
- if (!packageJsonContent) {
213
- throw new Error("Cannot find package.json configuration file");
214
- }
215
- let packageJson = JSON.parse(packageJsonContent);
216
- packageJson = await _buildtools.addPackageDependencies.call(void 0, options.config.workspaceRoot, options.projectRoot, options.projectName, packageJson);
217
- packageJson = await _buildtools.addWorkspacePackageJsonFields.call(void 0, options.config, options.projectRoot, options.sourceRoot, options.projectName, false, packageJson);
218
- await _devkit.writeJsonFile.call(void 0, _correctpaths.joinPaths.call(void 0, options.outDir, "package.json"), await _buildtools.addPackageJsonExports.call(void 0, options.sourceRoot, packageJson));
219
- stopwatch();
220
- }
221
- return options;
222
- }
223
- _chunkRBSVNX4Wjs.__name.call(void 0, generatePackageJson, "generatePackageJson");
224
- async function resolveUnbuild(options) {
225
- _console.writeTrace.call(void 0, `Resolving Unbuild package with Jiti`, options.config);
226
- try {
227
- return options.jiti.import("unbuild");
228
- } catch (error) {
229
- _console.writeError.call(void 0, " \u274C An error occurred while resolving the Unbuild package", options.config);
230
- throw new Error("An error occurred while resolving the Unbuild package", {
231
- cause: error
232
- });
233
- }
234
- }
235
- _chunkRBSVNX4Wjs.__name.call(void 0, resolveUnbuild, "resolveUnbuild");
236
- async function executeUnbuild(options) {
237
- _console.writeDebug.call(void 0, ` \u{1F680} Running ${options.name} (${options.projectRoot}) build`, options.config);
238
- const stopwatch = _console.getStopwatch.call(void 0, `${options.name} (${options.projectRoot}) build`);
239
- try {
240
- const unbuild = await resolveUnbuild(options);
241
- await unbuild.build(options.projectRoot, false, {
242
- ...options,
243
- rootDir: options.projectRoot
244
- });
245
- } finally {
246
- stopwatch();
247
- }
248
- return options;
249
- }
250
- _chunkRBSVNX4Wjs.__name.call(void 0, executeUnbuild, "executeUnbuild");
251
- async function copyBuildAssets(options) {
252
- _console.writeDebug.call(void 0, ` \u{1F4CB} Copying asset files to output directory: ${options.outDir}`, options.config);
253
- const stopwatch = _console.getStopwatch.call(void 0, `${options.name} asset copy`);
254
- await _buildtools.copyAssets.call(void 0, options.config, _nullishCoalesce(options.assets, () => ( [])), options.outDir, options.projectRoot, options.projectName, options.sourceRoot, options.generatePackageJson, options.includeSrc);
255
- stopwatch();
256
- return options;
257
- }
258
- _chunkRBSVNX4Wjs.__name.call(void 0, copyBuildAssets, "copyBuildAssets");
259
- async function cleanOutputPath(options) {
260
- if (options.clean !== false && options.outDir) {
261
- await _chunkT5JY3PDFjs.clean.call(void 0, options.name, options.outDir, options.config);
262
- }
263
- return options;
264
- }
265
- _chunkRBSVNX4Wjs.__name.call(void 0, cleanOutputPath, "cleanOutputPath");
266
- async function build(options) {
267
- _console.writeDebug.call(void 0, ` \u26A1 Executing Storm Unbuild pipeline`);
268
- const stopwatch = _console.getStopwatch.call(void 0, "Unbuild pipeline");
269
- try {
270
- const resolvedOptions = await resolveOptions(options);
271
- await cleanOutputPath(resolvedOptions);
272
- await generatePackageJson(resolvedOptions);
273
- await executeUnbuild(resolvedOptions);
274
- await copyBuildAssets(resolvedOptions);
275
- _console.writeSuccess.call(void 0, ` \u{1F3C1} The ${resolvedOptions.name} build completed successfully`, resolvedOptions.config);
276
- } catch (error) {
277
- _console.writeFatal.call(void 0, " \u274C Fatal errors occurred during the build that could not be recovered from. The build process has been terminated.");
278
- throw error;
279
- } finally {
280
- stopwatch();
281
- }
282
- }
283
- _chunkRBSVNX4Wjs.__name.call(void 0, build, "build");
284
-
285
-
286
-
287
- exports.build = build;
@@ -1,287 +0,0 @@
1
- import {
2
- clean
3
- } from "./chunk-K7L2WB3G.mjs";
4
- import {
5
- getDefaultBuildPlugins
6
- } from "./chunk-XPX5NQ4D.mjs";
7
- import {
8
- loadConfig
9
- } from "./chunk-67M6JMGM.mjs";
10
- import {
11
- __name,
12
- init_esm_shims
13
- } from "./chunk-3TNHGERR.mjs";
14
-
15
- // src/build.ts
16
- init_esm_shims();
17
- import { readCachedProjectGraph, writeJsonFile } from "@nx/devkit";
18
- import { getHelperDependency, HelperDependency } from "@nx/js";
19
- import { calculateProjectBuildableDependencies } from "@nx/js/src/utils/buildable-libs-utils";
20
- import { addPackageDependencies, addPackageJsonExports, addWorkspacePackageJsonFields, copyAssets } from "@storm-software/build-tools";
21
- import { loadStormConfig } from "@storm-software/config-tools/create-storm-config";
22
- import { getStopwatch, writeDebug, writeError, writeFatal, writeSuccess, writeTrace } from "@storm-software/config-tools/logger/console";
23
- import { isVerbose } from "@storm-software/config-tools/logger/get-log-level";
24
- import { LogLevelLabel } from "@storm-software/config-tools/types";
25
- import { joinPaths } from "@storm-software/config-tools/utilities/correct-paths";
26
- import defu from "defu";
27
- import { createJiti } from "jiti";
28
- import { existsSync } from "node:fs";
29
- import { readFile } from "node:fs/promises";
30
- import { relative } from "node:path";
31
- import { findWorkspaceRoot } from "nx/src/utils/find-workspace-root";
32
- async function resolveOptions(options) {
33
- const projectRoot = options.projectRoot;
34
- if (!projectRoot) {
35
- throw new Error("Cannot find project root");
36
- }
37
- const outputPath = options.outputPath || joinPaths("dist", projectRoot);
38
- const workspaceRoot = findWorkspaceRoot(projectRoot);
39
- if (!workspaceRoot) {
40
- throw new Error("Cannot find workspace root");
41
- }
42
- const config = await loadStormConfig(workspaceRoot.dir);
43
- writeDebug(" \u2699\uFE0F Resolving build options", config);
44
- const stopwatch = getStopwatch("Build options resolution");
45
- if (options.configPath) {
46
- const configFile = await loadConfig(options.configPath);
47
- if (configFile) {
48
- options = defu(options, configFile);
49
- }
50
- }
51
- const projectGraph = readCachedProjectGraph();
52
- const projectJsonPath = joinPaths(config.workspaceRoot, projectRoot, "project.json");
53
- if (!existsSync(projectJsonPath)) {
54
- throw new Error("Cannot find project.json configuration");
55
- }
56
- const projectJsonContent = await readFile(projectJsonPath, "utf8");
57
- const projectJson = JSON.parse(projectJsonContent);
58
- const projectName = projectJson.name;
59
- const packageJsonPath = joinPaths(workspaceRoot.dir, projectRoot, "package.json");
60
- if (!existsSync(packageJsonPath)) {
61
- throw new Error("Cannot find package.json configuration");
62
- }
63
- const packageJsonContent = await readFile(packageJsonPath, "utf8");
64
- const packageJson = JSON.parse(packageJsonContent);
65
- let tsconfig = options.tsconfig;
66
- if (!tsconfig) {
67
- tsconfig = joinPaths(workspaceRoot.dir, projectRoot, "tsconfig.json");
68
- }
69
- if (!existsSync(tsconfig)) {
70
- throw new Error("Cannot find tsconfig.json configuration");
71
- }
72
- let sourceRoot = projectJson.sourceRoot;
73
- if (!sourceRoot) {
74
- sourceRoot = joinPaths(projectRoot, "src");
75
- }
76
- if (!existsSync(sourceRoot)) {
77
- throw new Error("Cannot find sourceRoot directory");
78
- }
79
- const result = calculateProjectBuildableDependencies(void 0, projectGraph, workspaceRoot.dir, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
80
- let dependencies = result.dependencies;
81
- const tsLibDependency = getHelperDependency(HelperDependency.tsc, tsconfig, dependencies, projectGraph, true);
82
- if (tsLibDependency) {
83
- dependencies = dependencies.filter((deps) => deps.name !== tsLibDependency.name);
84
- dependencies.push(tsLibDependency);
85
- }
86
- const jiti = createJiti(config.workspaceRoot, {
87
- fsCache: config.skipCache ? false : joinPaths(config.directories.cache || "node_modules/.cache/storm", "jiti"),
88
- interopDefault: true
89
- });
90
- const resolvedOptions = {
91
- name: projectName,
92
- config,
93
- projectRoot,
94
- sourceRoot,
95
- projectName,
96
- tsconfig,
97
- jiti,
98
- clean: false,
99
- entries: [
100
- {
101
- builder: "mkdist",
102
- input: `.${sourceRoot.replace(projectRoot, "")}`,
103
- outDir: joinPaths(relative(joinPaths(config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
104
- declaration: options.emitTypes !== false,
105
- format: "esm"
106
- },
107
- {
108
- builder: "mkdist",
109
- input: `.${sourceRoot.replace(projectRoot, "")}`,
110
- outDir: joinPaths(relative(joinPaths(config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
111
- declaration: options.emitTypes !== false,
112
- format: "cjs",
113
- ext: "cjs"
114
- }
115
- ],
116
- declaration: options.emitTypes !== false ? "compatible" : false,
117
- failOnWarn: false,
118
- sourcemap: options.sourcemap ?? !!options.debug,
119
- outDir: outputPath,
120
- parallel: true,
121
- stub: false,
122
- stubOptions: {
123
- jiti: {}
124
- },
125
- externals: options.external ?? [],
126
- dependencies: [],
127
- peerDependencies: [],
128
- devDependencies: [],
129
- hooks: {},
130
- alias: {},
131
- replace: {},
132
- rollup: {
133
- replace: {},
134
- alias: {},
135
- json: {},
136
- commonjs: {
137
- sourceMap: options.sourcemap ?? true
138
- },
139
- emitCJS: true,
140
- cjsBridge: true,
141
- dts: {
142
- respectExternal: true,
143
- tsconfig
144
- },
145
- output: {
146
- banner: options.banner || `
147
- // \u26A1 Built by Storm Software
148
- `,
149
- footer: options.footer
150
- },
151
- resolve: {
152
- preferBuiltins: true,
153
- extensions: [
154
- ".cjs",
155
- ".mjs",
156
- ".js",
157
- ".jsx",
158
- ".ts",
159
- ".tsx",
160
- ".json"
161
- ]
162
- },
163
- esbuild: {
164
- minify: options.minify !== false,
165
- splitting: options.splitting !== false,
166
- treeShaking: options.treeShaking !== false,
167
- color: true,
168
- logLevel: config.logLevel === LogLevelLabel.FATAL ? LogLevelLabel.ERROR : isVerbose() ? "verbose" : config.logLevel
169
- }
170
- }
171
- };
172
- dependencies = dependencies.filter((dep) => dep.node.type === "npm" || dep.node.type === "lib" || dep.node.type === "app");
173
- if (dependencies.length > 0) {
174
- resolvedOptions.dependencies = dependencies.map((dep) => dep.name);
175
- }
176
- if (packageJson.devDependencies) {
177
- resolvedOptions.devDependencies = Object.keys(packageJson.devDependencies);
178
- }
179
- if (packageJson.peerDependencies) {
180
- resolvedOptions.peerDependencies = Object.keys(packageJson.peerDependencies);
181
- }
182
- if (options.rollup) {
183
- let rollup = {};
184
- if (typeof options.rollup === "string") {
185
- const rollupFile = await loadConfig(options.rollup);
186
- if (rollupFile) {
187
- rollup = rollupFile;
188
- }
189
- } else {
190
- rollup = options.rollup;
191
- }
192
- resolvedOptions.rollup = defu(resolvedOptions.rollup ?? {}, rollup);
193
- }
194
- resolvedOptions.hooks = {
195
- "rollup:options": /* @__PURE__ */ __name(async (ctx, opts) => {
196
- opts.plugins = options.plugins ?? await getDefaultBuildPlugins(options, resolvedOptions);
197
- }, "rollup:options")
198
- };
199
- stopwatch();
200
- return resolvedOptions;
201
- }
202
- __name(resolveOptions, "resolveOptions");
203
- async function generatePackageJson(options) {
204
- if (options.generatePackageJson !== false && existsSync(joinPaths(options.projectRoot, "package.json"))) {
205
- writeDebug(" \u270D\uFE0F Writing package.json file", options.config);
206
- const stopwatch = getStopwatch("Write package.json file");
207
- const packageJsonPath = joinPaths(options.projectRoot, "project.json");
208
- if (!existsSync(packageJsonPath)) {
209
- throw new Error("Cannot find package.json configuration");
210
- }
211
- let packageJsonContent = await readFile(joinPaths(options.config.workspaceRoot, options.projectRoot, "package.json"), "utf8");
212
- if (!packageJsonContent) {
213
- throw new Error("Cannot find package.json configuration file");
214
- }
215
- let packageJson = JSON.parse(packageJsonContent);
216
- packageJson = await addPackageDependencies(options.config.workspaceRoot, options.projectRoot, options.projectName, packageJson);
217
- packageJson = await addWorkspacePackageJsonFields(options.config, options.projectRoot, options.sourceRoot, options.projectName, false, packageJson);
218
- await writeJsonFile(joinPaths(options.outDir, "package.json"), await addPackageJsonExports(options.sourceRoot, packageJson));
219
- stopwatch();
220
- }
221
- return options;
222
- }
223
- __name(generatePackageJson, "generatePackageJson");
224
- async function resolveUnbuild(options) {
225
- writeTrace(`Resolving Unbuild package with Jiti`, options.config);
226
- try {
227
- return options.jiti.import("unbuild");
228
- } catch (error) {
229
- writeError(" \u274C An error occurred while resolving the Unbuild package", options.config);
230
- throw new Error("An error occurred while resolving the Unbuild package", {
231
- cause: error
232
- });
233
- }
234
- }
235
- __name(resolveUnbuild, "resolveUnbuild");
236
- async function executeUnbuild(options) {
237
- writeDebug(` \u{1F680} Running ${options.name} (${options.projectRoot}) build`, options.config);
238
- const stopwatch = getStopwatch(`${options.name} (${options.projectRoot}) build`);
239
- try {
240
- const unbuild = await resolveUnbuild(options);
241
- await unbuild.build(options.projectRoot, false, {
242
- ...options,
243
- rootDir: options.projectRoot
244
- });
245
- } finally {
246
- stopwatch();
247
- }
248
- return options;
249
- }
250
- __name(executeUnbuild, "executeUnbuild");
251
- async function copyBuildAssets(options) {
252
- writeDebug(` \u{1F4CB} Copying asset files to output directory: ${options.outDir}`, options.config);
253
- const stopwatch = getStopwatch(`${options.name} asset copy`);
254
- await copyAssets(options.config, options.assets ?? [], options.outDir, options.projectRoot, options.projectName, options.sourceRoot, options.generatePackageJson, options.includeSrc);
255
- stopwatch();
256
- return options;
257
- }
258
- __name(copyBuildAssets, "copyBuildAssets");
259
- async function cleanOutputPath(options) {
260
- if (options.clean !== false && options.outDir) {
261
- await clean(options.name, options.outDir, options.config);
262
- }
263
- return options;
264
- }
265
- __name(cleanOutputPath, "cleanOutputPath");
266
- async function build(options) {
267
- writeDebug(` \u26A1 Executing Storm Unbuild pipeline`);
268
- const stopwatch = getStopwatch("Unbuild pipeline");
269
- try {
270
- const resolvedOptions = await resolveOptions(options);
271
- await cleanOutputPath(resolvedOptions);
272
- await generatePackageJson(resolvedOptions);
273
- await executeUnbuild(resolvedOptions);
274
- await copyBuildAssets(resolvedOptions);
275
- writeSuccess(` \u{1F3C1} The ${resolvedOptions.name} build completed successfully`, resolvedOptions.config);
276
- } catch (error) {
277
- writeFatal(" \u274C Fatal errors occurred during the build that could not be recovered from. The build process has been terminated.");
278
- throw error;
279
- } finally {
280
- stopwatch();
281
- }
282
- }
283
- __name(build, "build");
284
-
285
- export {
286
- build
287
- };