@serenity-is/tsbuild 10.0.3 → 10.0.9
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/dist/index.js +135 -7
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { init as esmlInit, parse as esmlParse } from "es-module-lexer";
|
|
1
2
|
import esbuild from "esbuild";
|
|
2
3
|
import { createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
3
4
|
import { globSync } from "glob";
|
|
@@ -60,6 +61,7 @@ export const tsbuildDefaults = {
|
|
|
60
61
|
format: "esm",
|
|
61
62
|
jsxSideEffects: true,
|
|
62
63
|
keepNames: true,
|
|
64
|
+
lineLimit: 1000,
|
|
63
65
|
loader: {
|
|
64
66
|
".woff2": "file",
|
|
65
67
|
".woff": "file",
|
|
@@ -73,12 +75,15 @@ export const tsbuildDefaults = {
|
|
|
73
75
|
".webp": "file"
|
|
74
76
|
},
|
|
75
77
|
logLevel: "info",
|
|
78
|
+
logOverride: {
|
|
79
|
+
"empty-glob": "silent"
|
|
80
|
+
},
|
|
76
81
|
metafile: true,
|
|
77
82
|
minify: true,
|
|
78
83
|
outbase: "./",
|
|
79
84
|
outdir: "wwwroot/esm",
|
|
80
85
|
sourcemap: true,
|
|
81
|
-
target: "
|
|
86
|
+
target: "es2022"
|
|
82
87
|
};
|
|
83
88
|
|
|
84
89
|
function isSplittingEnabled(opt) {
|
|
@@ -89,9 +94,9 @@ function isSplittingEnabled(opt) {
|
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
function cleanPluginOptions(opt) {
|
|
92
|
-
if (opt.plugins
|
|
97
|
+
if (opt.plugins !== void 0)
|
|
93
98
|
return null;
|
|
94
|
-
if (opt.clean === void 0 && isSplittingEnabled(opt) || opt.clean)
|
|
99
|
+
if ((opt.clean === void 0 && isSplittingEnabled(opt)) || opt.clean)
|
|
95
100
|
return opt.clean === true ? {} : opt.clean ?? {};
|
|
96
101
|
return null;
|
|
97
102
|
}
|
|
@@ -134,18 +139,30 @@ export const esbuildOptions = (opt) => {
|
|
|
134
139
|
}
|
|
135
140
|
const splitting = isSplittingEnabled(opt);
|
|
136
141
|
let plugins = opt.plugins;
|
|
142
|
+
|
|
137
143
|
if (plugins === void 0) {
|
|
138
144
|
plugins = [];
|
|
145
|
+
|
|
146
|
+
// clean and import plugins are only added if user didn't provide custom plugins
|
|
139
147
|
const cleanOpt = cleanPluginOptions(opt);
|
|
140
148
|
if (cleanOpt != null)
|
|
141
149
|
plugins.push(cleanPlugin(cleanOpt));
|
|
150
|
+
|
|
142
151
|
if (opt.importAsGlobals === void 0 || opt.importAsGlobals)
|
|
143
152
|
plugins.push(importAsGlobalsPlugin(opt.importAsGlobals ?? importAsGlobalsMapping));
|
|
144
153
|
}
|
|
145
|
-
|
|
154
|
+
else {
|
|
155
|
+
if (opt.clean)
|
|
156
|
+
console.warn("TSBuildOptions.clean is ignored when custom plugins are provided.");
|
|
157
|
+
if (opt.importAsGlobals)
|
|
158
|
+
console.warn("TSBuildOptions.importAsGlobals is ignored when custom plugins are provided.");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if ((opt.write === void 0 && opt.writeIfChanged === void 0) || opt.writeIfChanged) {
|
|
146
162
|
plugins.push(writeIfChanged(opt.compress));
|
|
147
163
|
opt.write = false;
|
|
148
164
|
}
|
|
165
|
+
|
|
149
166
|
delete opt.compress;
|
|
150
167
|
delete opt.clean;
|
|
151
168
|
delete opt.importAsGlobals;
|
|
@@ -173,10 +190,16 @@ export const esbuildOptions = (opt) => {
|
|
|
173
190
|
|
|
174
191
|
export const tsbuildGlobalBundleDefaults = {
|
|
175
192
|
entryPoints: [
|
|
193
|
+
"Modules/Common/bundles/*.bundle.ts",
|
|
176
194
|
"Modules/Common/bundles/*-bundle.ts",
|
|
195
|
+
"Modules/Common/bundles/*.bundle.css",
|
|
177
196
|
"Modules/Common/bundles/*-bundle.css",
|
|
197
|
+
"Modules/Common/bundles/*.bundle.rtl.css",
|
|
178
198
|
"Modules/Common/bundles/*-bundle.rtl.css"
|
|
179
199
|
],
|
|
200
|
+
external: [
|
|
201
|
+
"@serenity-is/tiptap"
|
|
202
|
+
],
|
|
180
203
|
format: "iife",
|
|
181
204
|
importAsGlobals: null,
|
|
182
205
|
outdir: "wwwroot/esm/bundles/",
|
|
@@ -232,20 +255,125 @@ export const build = async (opt) => {
|
|
|
232
255
|
}
|
|
233
256
|
};
|
|
234
257
|
|
|
258
|
+
const serenityModuleTest = {
|
|
259
|
+
"@serenity-is/corelib": "PropertyGrid",
|
|
260
|
+
"@serenity-is/domwise": "observeSignal",
|
|
261
|
+
"@serenity-is/domwise/jsx-runtime": "jsx",
|
|
262
|
+
"@serenity-is/extensions": "GridEditorBase",
|
|
263
|
+
"@serenity-is/pro.extensions": "EnhancedLayout",
|
|
264
|
+
"@serenity-is/sleekgrid": "SleekGrid"
|
|
265
|
+
}
|
|
266
|
+
|
|
235
267
|
export function importAsGlobalsPlugin(mapping) {
|
|
236
268
|
const escRe = (s) => s.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
237
269
|
const filter = new RegExp(Object.keys(mapping).map((mod) => `^${escRe(mod)}$`).join("|"));
|
|
270
|
+
let serenityModuleContents;
|
|
238
271
|
return {
|
|
239
272
|
name: "global-imports",
|
|
240
|
-
setup(
|
|
241
|
-
|
|
273
|
+
setup(build) {
|
|
274
|
+
build.onResolve({ filter }, (args) => {
|
|
275
|
+
if (args.namespace === "skip-external-global") {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
242
278
|
if (!mapping[args.path])
|
|
243
279
|
throw new Error("Unknown global: " + args.path);
|
|
244
280
|
return { path: mapping[args.path], namespace: "external-global" };
|
|
245
281
|
});
|
|
246
|
-
|
|
282
|
+
build.onLoad(
|
|
247
283
|
{ filter: /.*/, namespace: "external-global" },
|
|
248
284
|
async (args) => {
|
|
285
|
+
if (args.path === "Serenity") {
|
|
286
|
+
if (serenityModuleContents === void 0) {
|
|
287
|
+
const initOpt = build?.initialOptions || {};
|
|
288
|
+
const absWorkingDir = initOpt.absWorkingDir || process.cwd();
|
|
289
|
+
const allNames = new Set();
|
|
290
|
+
const nameByModule = {};
|
|
291
|
+
const moduleTest = {};
|
|
292
|
+
try {
|
|
293
|
+
await esmlInit;
|
|
294
|
+
for (const [mod, ns] of Object.entries(mapping)) {
|
|
295
|
+
if (ns === "Serenity") {
|
|
296
|
+
const resResult = await build.resolve(mod, {
|
|
297
|
+
resolveDir: absWorkingDir,
|
|
298
|
+
kind: "import-statement",
|
|
299
|
+
namespace: "skip-external-global"
|
|
300
|
+
});
|
|
301
|
+
if (resResult?.errors?.length || !resResult?.path)
|
|
302
|
+
continue;
|
|
303
|
+
|
|
304
|
+
let path = resResult.path;
|
|
305
|
+
if (resResult.external) {
|
|
306
|
+
path = null;
|
|
307
|
+
let currentPath = absWorkingDir;
|
|
308
|
+
const actualMod = mod == "@serenity-is/domwise/jsx-runtime" ? "@serenity-is/domwise" : mod;
|
|
309
|
+
const actualFile = mod == "@serenity-is/domwise/jsx-runtime" ? "dist/jsx-runtime.js" : "dist/index.js";
|
|
310
|
+
let tries = 0;
|
|
311
|
+
while (tries++ < 100) {
|
|
312
|
+
const nmPath = join(currentPath, "node_modules", actualMod, actualFile);
|
|
313
|
+
if (existsSync(nmPath)) {
|
|
314
|
+
path = nmPath;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
currentPath = dirname(currentPath);
|
|
318
|
+
if (!currentPath.length)
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (!path)
|
|
323
|
+
continue;
|
|
324
|
+
const source = readFileSync(path, "utf8");
|
|
325
|
+
const [_, exports] = esmlParse(source);
|
|
326
|
+
nameByModule[mod] ??= new Set();
|
|
327
|
+
if (!moduleTest[mod] && serenityModuleTest[mod]) {
|
|
328
|
+
moduleTest[mod] = serenityModuleTest[mod];
|
|
329
|
+
}
|
|
330
|
+
for (const exp of exports) {
|
|
331
|
+
if (exp.n !== "default" && exp.n && exp.n.length > 0) {
|
|
332
|
+
allNames.add(exp.n);
|
|
333
|
+
nameByModule[mod].add(exp.n);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (allNames.size > 0) {
|
|
340
|
+
const exportNames = Array.from(allNames).sort().join(", ");
|
|
341
|
+
const sb = [];
|
|
342
|
+
sb.push(`if (typeof Serenity === "undefined") globalThis.Serenity = Object.create(null);`);
|
|
343
|
+
if (initOpt.format === "esm" && Object.keys(moduleTest).length > 0) {
|
|
344
|
+
sb.push(`
|
|
345
|
+
const t = ${JSON.stringify(moduleTest)};
|
|
346
|
+
for (const [k, v] of Object.entries(t)) {
|
|
347
|
+
if (v in Serenity) continue;
|
|
348
|
+
try {
|
|
349
|
+
const m = await import(k);
|
|
350
|
+
for (const n of Object.keys(m)) {
|
|
351
|
+
if (!(n in Serenity)) Serenity[n] = m[n];
|
|
352
|
+
}
|
|
353
|
+
} catch (e) { console.warn(e); }
|
|
354
|
+
}`);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
sb.push(`const { ${exportNames} } = Serenity;`);
|
|
358
|
+
sb.push(`export { ${exportNames} };`);
|
|
359
|
+
serenityModuleContents = sb.join("\n");
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
console.warn(`esbuild external-globals plugin: failed to parse exports for global import`, e);
|
|
364
|
+
serenityModuleContents = null;
|
|
365
|
+
// continue with commonjs export
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (serenityModuleContents) {
|
|
370
|
+
return {
|
|
371
|
+
contents: serenityModuleContents,
|
|
372
|
+
loader: "js"
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
249
377
|
return { contents: `module.exports = ${args.path};`, loader: "js" };
|
|
250
378
|
}
|
|
251
379
|
);
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-is/tsbuild",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.9",
|
|
4
4
|
"author": "Serenity (https://serenity.is)",
|
|
5
5
|
"bugs": "https://github.com/serenity-is/serenity/issues",
|
|
6
6
|
"description": "Serenity ESBuild functions",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"esbuild": "0.27.
|
|
8
|
+
"esbuild": "0.27.2",
|
|
9
|
+
"es-module-lexer": "2.0.0",
|
|
9
10
|
"glob": "13.0.0"
|
|
10
11
|
},
|
|
11
12
|
"exports": {
|