@storm-software/workspace-tools 1.290.10 → 1.291.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/CHANGELOG.md +29 -0
- package/README.md +1 -1
- package/dist/{chunk-MR2J2XDA.js → chunk-3WCQK76E.js} +22 -292
- package/dist/{chunk-KKCNNJUO.mjs → chunk-DVZPBLGA.mjs} +20 -290
- package/dist/chunk-F3NQOV2M.mjs +314 -0
- package/dist/chunk-FSYURQ5X.js +314 -0
- package/dist/chunk-H5NKQQJU.mjs +363 -0
- package/dist/chunk-OTI7QVPG.js +363 -0
- package/dist/executor-4s6Siy2o.d.ts +144 -0
- package/dist/executor-BmxxnfjA.d.mts +144 -0
- package/dist/executors.d.mts +1 -0
- package/dist/executors.d.ts +1 -0
- package/dist/executors.js +11 -6
- package/dist/executors.mjs +13 -8
- package/dist/generators.js +3 -3
- package/dist/generators.mjs +3 -3
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -9
- package/dist/index.mjs +16 -11
- package/dist/src/executors/esbuild/executor.js +3 -2
- package/dist/src/executors/esbuild/executor.mjs +2 -1
- package/dist/src/executors/tsdown/executor.d.mts +5 -0
- package/dist/src/executors/tsdown/executor.d.ts +5 -0
- package/dist/src/executors/tsdown/executor.js +15 -0
- package/dist/src/executors/tsdown/executor.mjs +16 -0
- package/dist/src/executors/tsdown/schema.d.ts +135 -0
- package/dist/src/executors/tsdown/schema.json +174 -0
- package/dist/src/executors/tsdown/untyped.d.mts +5 -0
- package/dist/src/executors/tsdown/untyped.d.ts +5 -0
- package/dist/src/executors/tsdown/untyped.js +18 -0
- package/dist/src/executors/tsdown/untyped.mjs +19 -0
- package/dist/src/plugins/typescript/tsdown.d.mts +9 -0
- package/dist/src/plugins/typescript/tsdown.d.ts +9 -0
- package/dist/src/plugins/typescript/tsdown.js +169 -0
- package/dist/src/plugins/typescript/tsdown.mjs +170 -0
- package/docs/api/executors/tsdown/schema.md +126 -0
- package/package.json +9 -7
- /package/dist/{chunk-7VDOGZYO.js → chunk-3J53KHVV.js} +0 -0
- /package/dist/{chunk-BLX5SLPC.mjs → chunk-V7YZ3666.mjs} +0 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_TARGET,
|
|
3
|
+
addPackageDependencies,
|
|
4
|
+
addPackageJsonExport,
|
|
5
|
+
addWorkspacePackageJsonFields,
|
|
6
|
+
copyAssets,
|
|
7
|
+
getEnv
|
|
8
|
+
} from "./chunk-F3NQOV2M.mjs";
|
|
9
|
+
import {
|
|
10
|
+
withRunExecutor
|
|
11
|
+
} from "./chunk-LUXZM24C.mjs";
|
|
12
|
+
import {
|
|
13
|
+
getWorkspaceConfig
|
|
14
|
+
} from "./chunk-Y4TAQWND.mjs";
|
|
15
|
+
import {
|
|
16
|
+
getStopwatch,
|
|
17
|
+
writeDebug,
|
|
18
|
+
writeFatal,
|
|
19
|
+
writeInfo,
|
|
20
|
+
writeSuccess,
|
|
21
|
+
writeWarning
|
|
22
|
+
} from "./chunk-V44DYGWX.mjs";
|
|
23
|
+
import {
|
|
24
|
+
findWorkspaceRoot
|
|
25
|
+
} from "./chunk-VGJEUOUN.mjs";
|
|
26
|
+
import {
|
|
27
|
+
joinPaths
|
|
28
|
+
} from "./chunk-C26A6BXG.mjs";
|
|
29
|
+
|
|
30
|
+
// ../tsdown/src/build.ts
|
|
31
|
+
import {
|
|
32
|
+
createProjectGraphAsync,
|
|
33
|
+
readProjectsConfigurationFromProjectGraph,
|
|
34
|
+
writeJsonFile
|
|
35
|
+
} from "@nx/devkit";
|
|
36
|
+
import defu from "defu";
|
|
37
|
+
import { existsSync } from "node:fs";
|
|
38
|
+
import hf from "node:fs/promises";
|
|
39
|
+
import { build as tsdown } from "tsdown";
|
|
40
|
+
|
|
41
|
+
// ../tsdown/src/clean.ts
|
|
42
|
+
import { rm } from "node:fs/promises";
|
|
43
|
+
async function cleanDirectories(name = "TSDown", directory, config) {
|
|
44
|
+
await rm(directory, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ../tsdown/src/config.ts
|
|
48
|
+
function getDefaultOptions(config) {
|
|
49
|
+
return {
|
|
50
|
+
entry: ["./src/*.ts"],
|
|
51
|
+
platform: "node",
|
|
52
|
+
target: "esnext",
|
|
53
|
+
mode: "production",
|
|
54
|
+
dts: true,
|
|
55
|
+
unused: {
|
|
56
|
+
level: "error",
|
|
57
|
+
ignore: ["typescript"]
|
|
58
|
+
},
|
|
59
|
+
publint: true,
|
|
60
|
+
fixedExtension: true,
|
|
61
|
+
...config
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function toTSDownFormat(format) {
|
|
65
|
+
if (!format || Array.isArray(format) && format.length === 0) {
|
|
66
|
+
return ["cjs", "es"];
|
|
67
|
+
} else if (format === "esm") {
|
|
68
|
+
return "es";
|
|
69
|
+
} else if (Array.isArray(format)) {
|
|
70
|
+
return format.map((f) => f === "esm" ? "es" : f);
|
|
71
|
+
}
|
|
72
|
+
return format;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ../tsdown/src/build.ts
|
|
76
|
+
var resolveOptions = async (userOptions) => {
|
|
77
|
+
const options = getDefaultOptions(userOptions);
|
|
78
|
+
const workspaceRoot = findWorkspaceRoot(options.projectRoot);
|
|
79
|
+
if (!workspaceRoot) {
|
|
80
|
+
throw new Error("Cannot find Nx workspace root");
|
|
81
|
+
}
|
|
82
|
+
const workspaceConfig = await getWorkspaceConfig(options.debug === true, {
|
|
83
|
+
workspaceRoot
|
|
84
|
+
});
|
|
85
|
+
writeDebug(" \u2699\uFE0F Resolving build options", workspaceConfig);
|
|
86
|
+
const stopwatch = getStopwatch("Build options resolution");
|
|
87
|
+
const projectGraph = await createProjectGraphAsync({
|
|
88
|
+
exitOnError: true
|
|
89
|
+
});
|
|
90
|
+
const projectJsonPath = joinPaths(
|
|
91
|
+
workspaceRoot,
|
|
92
|
+
options.projectRoot,
|
|
93
|
+
"project.json"
|
|
94
|
+
);
|
|
95
|
+
if (!existsSync(projectJsonPath)) {
|
|
96
|
+
throw new Error("Cannot find project.json configuration");
|
|
97
|
+
}
|
|
98
|
+
const projectJsonFile = await hf.readFile(projectJsonPath, "utf8");
|
|
99
|
+
const projectJson = JSON.parse(projectJsonFile);
|
|
100
|
+
const projectName = projectJson.name;
|
|
101
|
+
const projectConfigurations = readProjectsConfigurationFromProjectGraph(projectGraph);
|
|
102
|
+
if (!projectConfigurations?.projects?.[projectName]) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
"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."
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
const packageJsonPath = joinPaths(
|
|
108
|
+
workspaceRoot,
|
|
109
|
+
options.projectRoot,
|
|
110
|
+
"package.json"
|
|
111
|
+
);
|
|
112
|
+
if (!existsSync(packageJsonPath)) {
|
|
113
|
+
throw new Error("Cannot find package.json configuration");
|
|
114
|
+
}
|
|
115
|
+
const debug = options.debug ?? (options.mode || workspaceConfig.mode) === "development";
|
|
116
|
+
const sourceRoot = projectJson.sourceRoot || joinPaths(options.projectRoot, "src");
|
|
117
|
+
const result = {
|
|
118
|
+
name: projectName,
|
|
119
|
+
mode: "production",
|
|
120
|
+
target: DEFAULT_TARGET,
|
|
121
|
+
generatePackageJson: true,
|
|
122
|
+
outDir: joinPaths("dist", options.projectRoot),
|
|
123
|
+
minify: !debug,
|
|
124
|
+
plugins: [],
|
|
125
|
+
assets: [],
|
|
126
|
+
dts: true,
|
|
127
|
+
shims: true,
|
|
128
|
+
silent: !debug,
|
|
129
|
+
logLevel: workspaceConfig.logLevel === "success" || workspaceConfig.logLevel === "debug" || workspaceConfig.logLevel === "trace" || workspaceConfig.logLevel === "all" ? "info" : workspaceConfig.logLevel === "fatal" ? "error" : workspaceConfig.logLevel,
|
|
130
|
+
sourcemap: debug ? "inline" : false,
|
|
131
|
+
clean: false,
|
|
132
|
+
fixedExtension: true,
|
|
133
|
+
nodeProtocol: true,
|
|
134
|
+
tsconfig: joinPaths(options.projectRoot, "tsconfig.json"),
|
|
135
|
+
debug,
|
|
136
|
+
sourceRoot,
|
|
137
|
+
cwd: workspaceConfig.workspaceRoot,
|
|
138
|
+
entry: {
|
|
139
|
+
["index"]: joinPaths(sourceRoot, "index.ts")
|
|
140
|
+
},
|
|
141
|
+
workspace: true,
|
|
142
|
+
...options,
|
|
143
|
+
treeshake: options.treeShaking !== false,
|
|
144
|
+
format: toTSDownFormat(options.format),
|
|
145
|
+
workspaceConfig,
|
|
146
|
+
projectName,
|
|
147
|
+
projectGraph,
|
|
148
|
+
projectConfigurations
|
|
149
|
+
};
|
|
150
|
+
result.env = defu(
|
|
151
|
+
options.env,
|
|
152
|
+
getEnv("tsdown", result)
|
|
153
|
+
);
|
|
154
|
+
stopwatch();
|
|
155
|
+
return result;
|
|
156
|
+
};
|
|
157
|
+
async function generatePackageJson(options) {
|
|
158
|
+
if (options.generatePackageJson !== false && existsSync(joinPaths(options.projectRoot, "package.json"))) {
|
|
159
|
+
writeDebug(" \u270D\uFE0F Writing package.json file", options.workspaceConfig);
|
|
160
|
+
const stopwatch = getStopwatch("Write package.json file");
|
|
161
|
+
const packageJsonPath = joinPaths(options.projectRoot, "project.json");
|
|
162
|
+
if (!existsSync(packageJsonPath)) {
|
|
163
|
+
throw new Error("Cannot find package.json configuration");
|
|
164
|
+
}
|
|
165
|
+
const packageJsonFile = await hf.readFile(
|
|
166
|
+
joinPaths(
|
|
167
|
+
options.workspaceConfig.workspaceRoot,
|
|
168
|
+
options.projectRoot,
|
|
169
|
+
"package.json"
|
|
170
|
+
),
|
|
171
|
+
"utf8"
|
|
172
|
+
);
|
|
173
|
+
if (!packageJsonFile) {
|
|
174
|
+
throw new Error("Cannot find package.json configuration file");
|
|
175
|
+
}
|
|
176
|
+
let packageJson = JSON.parse(packageJsonFile);
|
|
177
|
+
packageJson = await addPackageDependencies(
|
|
178
|
+
options.workspaceConfig.workspaceRoot,
|
|
179
|
+
options.projectRoot,
|
|
180
|
+
options.projectName,
|
|
181
|
+
packageJson
|
|
182
|
+
);
|
|
183
|
+
packageJson = await addWorkspacePackageJsonFields(
|
|
184
|
+
options.workspaceConfig,
|
|
185
|
+
options.projectRoot,
|
|
186
|
+
options.sourceRoot,
|
|
187
|
+
options.projectName,
|
|
188
|
+
false,
|
|
189
|
+
packageJson
|
|
190
|
+
);
|
|
191
|
+
packageJson.exports ??= {};
|
|
192
|
+
packageJson.exports["./package.json"] ??= "./package.json";
|
|
193
|
+
packageJson.exports["."] ??= addPackageJsonExport(
|
|
194
|
+
"index",
|
|
195
|
+
packageJson.type,
|
|
196
|
+
options.sourceRoot
|
|
197
|
+
);
|
|
198
|
+
let entry = [{ in: "./src/index.ts", out: "./src/index.ts" }];
|
|
199
|
+
if (options.entry) {
|
|
200
|
+
if (Array.isArray(options.entry)) {
|
|
201
|
+
entry = options.entry.map(
|
|
202
|
+
(entryPoint) => typeof entryPoint === "string" ? { in: entryPoint, out: entryPoint } : entryPoint
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
for (const entryPoint of entry) {
|
|
206
|
+
const split = entryPoint.out.split(".");
|
|
207
|
+
split.pop();
|
|
208
|
+
const entry2 = split.join(".").replaceAll("\\", "/");
|
|
209
|
+
packageJson.exports[`./${entry2}`] ??= addPackageJsonExport(
|
|
210
|
+
entry2,
|
|
211
|
+
options.fixedExtension ? "fixed" : packageJson.type,
|
|
212
|
+
options.sourceRoot
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
packageJson.main = !options.fixedExtension && packageJson.type === "commonjs" ? "./dist/index.js" : "./dist/index.cjs";
|
|
217
|
+
packageJson.module = !options.fixedExtension && packageJson.type === "module" ? "./dist/index.js" : "./dist/index.mjs";
|
|
218
|
+
packageJson.types = `./dist/index.d.${!options.fixedExtension ? "ts" : "mts"}`;
|
|
219
|
+
packageJson.exports = Object.keys(packageJson.exports).reduce(
|
|
220
|
+
(ret, key) => {
|
|
221
|
+
if (key.endsWith("/index") && !ret[key.replace("/index", "")]) {
|
|
222
|
+
ret[key.replace("/index", "")] = packageJson.exports[key];
|
|
223
|
+
}
|
|
224
|
+
return ret;
|
|
225
|
+
},
|
|
226
|
+
packageJson.exports
|
|
227
|
+
);
|
|
228
|
+
await writeJsonFile(joinPaths(options.outDir, "package.json"), packageJson);
|
|
229
|
+
stopwatch();
|
|
230
|
+
}
|
|
231
|
+
return options;
|
|
232
|
+
}
|
|
233
|
+
async function executeTSDown(options) {
|
|
234
|
+
writeDebug(` \u{1F680} Running ${options.name} build`, options.workspaceConfig);
|
|
235
|
+
const stopwatch = getStopwatch(`${options.name} build`);
|
|
236
|
+
await tsdown({
|
|
237
|
+
...options,
|
|
238
|
+
entry: options.entry,
|
|
239
|
+
config: false
|
|
240
|
+
});
|
|
241
|
+
stopwatch();
|
|
242
|
+
return options;
|
|
243
|
+
}
|
|
244
|
+
async function copyBuildAssets(options) {
|
|
245
|
+
writeDebug(
|
|
246
|
+
` \u{1F4CB} Copying asset files to output directory: ${options.outDir}`,
|
|
247
|
+
options.workspaceConfig
|
|
248
|
+
);
|
|
249
|
+
const stopwatch = getStopwatch(`${options.name} asset copy`);
|
|
250
|
+
await copyAssets(
|
|
251
|
+
options.workspaceConfig,
|
|
252
|
+
options.assets ?? [],
|
|
253
|
+
options.outDir,
|
|
254
|
+
options.projectRoot,
|
|
255
|
+
options.sourceRoot,
|
|
256
|
+
true,
|
|
257
|
+
false
|
|
258
|
+
);
|
|
259
|
+
stopwatch();
|
|
260
|
+
return options;
|
|
261
|
+
}
|
|
262
|
+
async function reportResults(options) {
|
|
263
|
+
writeSuccess(
|
|
264
|
+
` \u{1F4E6} The ${options.name} build completed successfully`,
|
|
265
|
+
options.workspaceConfig
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
async function cleanOutputPath(options) {
|
|
269
|
+
if (options.clean !== false && options.workspaceConfig) {
|
|
270
|
+
writeDebug(
|
|
271
|
+
` \u{1F9F9} Cleaning ${options.name} output path: ${options.workspaceConfig}`,
|
|
272
|
+
options.workspaceConfig
|
|
273
|
+
);
|
|
274
|
+
const stopwatch = getStopwatch(`${options.name} output clean`);
|
|
275
|
+
await cleanDirectories(
|
|
276
|
+
options.name,
|
|
277
|
+
options.outDir,
|
|
278
|
+
options.workspaceConfig
|
|
279
|
+
);
|
|
280
|
+
stopwatch();
|
|
281
|
+
}
|
|
282
|
+
return options;
|
|
283
|
+
}
|
|
284
|
+
async function build(options) {
|
|
285
|
+
writeDebug(` \u26A1 Executing Storm TSDown pipeline`);
|
|
286
|
+
const stopwatch = getStopwatch("TSDown pipeline");
|
|
287
|
+
try {
|
|
288
|
+
const opts = Array.isArray(options) ? options : [options];
|
|
289
|
+
if (opts.length === 0) {
|
|
290
|
+
throw new Error("No build options were provided");
|
|
291
|
+
}
|
|
292
|
+
const resolved = await Promise.all(
|
|
293
|
+
opts.map(async (opt) => await resolveOptions(opt))
|
|
294
|
+
);
|
|
295
|
+
if (resolved.length > 0) {
|
|
296
|
+
await cleanOutputPath(resolved[0]);
|
|
297
|
+
await generatePackageJson(resolved[0]);
|
|
298
|
+
await Promise.all(
|
|
299
|
+
resolved.map(async (opt) => {
|
|
300
|
+
await executeTSDown(opt);
|
|
301
|
+
await copyBuildAssets(opt);
|
|
302
|
+
await reportResults(opt);
|
|
303
|
+
})
|
|
304
|
+
);
|
|
305
|
+
} else {
|
|
306
|
+
writeWarning(
|
|
307
|
+
" \u{1F6A7} No options were passed to TSBuild. Please check the parameters passed to the `build` function."
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
writeSuccess(" \u{1F3C1} TSDown pipeline build completed successfully");
|
|
311
|
+
} catch (error) {
|
|
312
|
+
writeFatal(
|
|
313
|
+
"Fatal errors that the build process could not recover from have occured. The build process has been terminated."
|
|
314
|
+
);
|
|
315
|
+
throw error;
|
|
316
|
+
} finally {
|
|
317
|
+
stopwatch();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// src/executors/tsdown/executor.ts
|
|
322
|
+
async function tsdownExecutorFn(options, context, config) {
|
|
323
|
+
writeInfo("\u{1F4E6} Running Storm TSDown executor on the workspace", config);
|
|
324
|
+
if (!context.projectsConfigurations?.projects || !context.projectName || !context.projectsConfigurations.projects[context.projectName] || !context.projectsConfigurations.projects[context.projectName]?.root) {
|
|
325
|
+
throw new Error(
|
|
326
|
+
"The Build process failed because the context is not valid. Please run this command from a workspace."
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
await build({
|
|
330
|
+
...options,
|
|
331
|
+
projectRoot: (
|
|
332
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
333
|
+
context.projectsConfigurations.projects?.[context.projectName].root
|
|
334
|
+
),
|
|
335
|
+
name: context.projectName,
|
|
336
|
+
sourceRoot: context.projectsConfigurations.projects?.[context.projectName]?.sourceRoot,
|
|
337
|
+
format: options.format,
|
|
338
|
+
platform: options.platform
|
|
339
|
+
});
|
|
340
|
+
return {
|
|
341
|
+
success: true
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
var executor_default = withRunExecutor(
|
|
345
|
+
"Storm TSDown build",
|
|
346
|
+
tsdownExecutorFn,
|
|
347
|
+
{
|
|
348
|
+
skipReadingConfig: false,
|
|
349
|
+
hooks: {
|
|
350
|
+
applyDefaultOptions: async (options) => {
|
|
351
|
+
options.entry ??= ["src/index.ts"];
|
|
352
|
+
options.outputPath ??= "dist/{projectRoot}";
|
|
353
|
+
options.tsconfig ??= "{projectRoot}/tsconfig.json";
|
|
354
|
+
return options;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
export {
|
|
361
|
+
tsdownExecutorFn,
|
|
362
|
+
executor_default
|
|
363
|
+
};
|