@serenity-is/tsbuild 6.2.5
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 +133 -0
- package/package.json +36 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import esbuild from "esbuild";
|
|
2
|
+
import { existsSync, readdirSync, statSync, mkdirSync, writeFileSync, rmSync } from "fs";
|
|
3
|
+
import { join, relative, resolve } from "path";
|
|
4
|
+
import { exit } from "process";
|
|
5
|
+
|
|
6
|
+
export function checkIfTrigger() {
|
|
7
|
+
if (process.argv.slice(2).some(x => x == "--trigger")) {
|
|
8
|
+
if (existsSync('typings/serenity.corelib/_trigger.ts'))
|
|
9
|
+
rmSync('typings/serenity.corelib/_trigger.ts')
|
|
10
|
+
else {
|
|
11
|
+
if (!existsSync('typings/serenity.corelib/'))
|
|
12
|
+
mkdirSync('typings/serenity.corelib/');
|
|
13
|
+
writeFileSync('typings/serenity.corelib/_trigger.ts', '// for triggering build');
|
|
14
|
+
}
|
|
15
|
+
exit(0);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const importAsGlobalsMapping = {
|
|
20
|
+
"@serenity-is/corelib": "Serenity",
|
|
21
|
+
"@serenity-is/corelib/q": "Q",
|
|
22
|
+
"@serenity-is/corelib/slick": "Slick",
|
|
23
|
+
"@serenity-is/sleekgrid": "Slick",
|
|
24
|
+
"@serenity-is/extensions": "Serenity.Extensions",
|
|
25
|
+
"@serenity-is/pro.extensions": "Serenity"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const esbuildOptions = (opt) => {
|
|
29
|
+
|
|
30
|
+
var entryPointsRegEx = /(Page|ScriptInit)\.ts$/;
|
|
31
|
+
if (opt.entryPointsRegEx !== undefined) {
|
|
32
|
+
entryPointsRegEx = opt.entryPointsRegEx;
|
|
33
|
+
delete opt.entryPointsRegEx;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var entryPointRoots = ['Modules'];
|
|
37
|
+
if (opt.entryPointRoots !== undefined) {
|
|
38
|
+
entryPointRoots = opt.entryPointRoots;
|
|
39
|
+
delete opt.entryPointRoots;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var entryPoints = opt.entryPoints;
|
|
43
|
+
if (entryPoints === undefined) {
|
|
44
|
+
entryPoints = [];
|
|
45
|
+
entryPointRoots.forEach(root =>
|
|
46
|
+
scanDir(root)
|
|
47
|
+
.filter(p => p.match(entryPointsRegEx))
|
|
48
|
+
.forEach(p => entryPoints.push(root + '/' + p)));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return Object.assign({
|
|
52
|
+
absWorkingDir: resolve('./'),
|
|
53
|
+
bundle: true,
|
|
54
|
+
chunkNames: '_chunks/[name]-[hash]',
|
|
55
|
+
color: true,
|
|
56
|
+
entryPoints: entryPoints,
|
|
57
|
+
format: 'esm',
|
|
58
|
+
keepNames: true,
|
|
59
|
+
logLevel: 'info',
|
|
60
|
+
metafile: true,
|
|
61
|
+
minify: true,
|
|
62
|
+
outbase: "./",
|
|
63
|
+
outdir: 'wwwroot/esm',
|
|
64
|
+
sourcemap: true,
|
|
65
|
+
splitting: !process.argv.slice(2).some(x => x == "--nosplit"),
|
|
66
|
+
target: 'es6',
|
|
67
|
+
watch: process.argv.slice(2).some(x => x == "--watch"),
|
|
68
|
+
plugins: [
|
|
69
|
+
cleanPlugin(),
|
|
70
|
+
importAsGlobalsPlugin(opt.importAsGlobalsMapping ?? importAsGlobalsMapping)
|
|
71
|
+
]
|
|
72
|
+
}, opt);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const build = async (opt) => {
|
|
76
|
+
await esbuild.build(esbuildOptions(opt));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function scanDir(dir, org) {
|
|
80
|
+
return readdirSync(dir).reduce((files, file) => {
|
|
81
|
+
const absolute = join(dir, file);
|
|
82
|
+
return [...files, ...(statSync(absolute).isDirectory()
|
|
83
|
+
? scanDir(absolute, org || dir)
|
|
84
|
+
: [relative(org || dir, absolute)])]
|
|
85
|
+
}, []);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// https://github.com/evanw/esbuild/issues/337
|
|
89
|
+
export function importAsGlobalsPlugin(mapping) {
|
|
90
|
+
const escRe = (s) => s.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
91
|
+
const filter = new RegExp(Object.keys(mapping).map((mod) =>
|
|
92
|
+
`^${escRe(mod)}$`).join("|"));
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
name: "global-imports",
|
|
96
|
+
setup(build) {
|
|
97
|
+
build.onResolve({ filter }, (args) => {
|
|
98
|
+
if (!mapping[args.path])
|
|
99
|
+
throw new Error("Unknown global: " + args.path);
|
|
100
|
+
return { path: args.path, namespace: "external-global" };
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
build.onLoad({ filter, namespace: "external-global" },
|
|
104
|
+
async (args) => {
|
|
105
|
+
const global = mapping[args.path];
|
|
106
|
+
return { contents: `module.exports = ${global};`, loader: "js" };
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function cleanPlugin() {
|
|
113
|
+
return {
|
|
114
|
+
name: 'clean',
|
|
115
|
+
setup(build) {
|
|
116
|
+
build.onEnd(result => {
|
|
117
|
+
try {
|
|
118
|
+
const { outputs } = result.metafile ?? {};
|
|
119
|
+
if (!outputs || !existsSync(build.initialOptions.outdir))
|
|
120
|
+
return;
|
|
121
|
+
|
|
122
|
+
const outputFiles = new Set(Object.keys(outputs));
|
|
123
|
+
scanDir(build.initialOptions.outdir).forEach(file => {
|
|
124
|
+
if (!outputFiles.has(join(build.initialOptions.outdir, file).replace(/\\/g, '/')))
|
|
125
|
+
rmSync(join(build.initialOptions.outdir, file));
|
|
126
|
+
});
|
|
127
|
+
} catch (e) {
|
|
128
|
+
console.error(`esbuild clean: ${e}`);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@serenity-is/tsbuild",
|
|
3
|
+
"version": "6.2.5",
|
|
4
|
+
"author": "Serenity (https://serenity.is)",
|
|
5
|
+
"bugs": "https://github.com/serenity-is/serenity/issues",
|
|
6
|
+
"description": "Serenity ESBuild functions",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"esbuild": "0.15.11"
|
|
9
|
+
},
|
|
10
|
+
"optionalDependencies": {
|
|
11
|
+
"fsevents": "2.3.2"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"module": "dist/index.js",
|
|
19
|
+
"main": "dist/index.js",
|
|
20
|
+
"import": "dist/index.js",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/**/*.d.ts",
|
|
23
|
+
"dist/**/*.js"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://github.com/serenity-is/serenity/#readme",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"serenity",
|
|
28
|
+
"business",
|
|
29
|
+
"application",
|
|
30
|
+
"framework",
|
|
31
|
+
"esbuild"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": "https://github.com/serenity-is/serenity/src/Serenity.Scripts/tsbuild",
|
|
35
|
+
"type": "module"
|
|
36
|
+
}
|