@serenity-is/tsbuild 8.6.5 → 8.6.6
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.d.ts +60 -59
- package/dist/index.js +210 -204
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,60 +1,61 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
clean
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
splitting
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
plugins
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
target
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
watch
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export const
|
|
59
|
-
export
|
|
1
|
+
export const defaultEntryPoints: string[];
|
|
2
|
+
export const importAsGlobalsMapping: Record<string, string>;
|
|
3
|
+
|
|
4
|
+
export interface TSBuildOptions {
|
|
5
|
+
/** Enable bundling of dependencies, default is true */
|
|
6
|
+
bundle?: boolean;
|
|
7
|
+
|
|
8
|
+
/** Chunk names to generate when code splitting is enabled. Default is '_chunks/[name]-[hash]' */
|
|
9
|
+
chunkNames?: string[];
|
|
10
|
+
|
|
11
|
+
/** True to enable the clean plugin. Default is true if splitting is true. */
|
|
12
|
+
clean?: boolean;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Determines the set of entry points that should be passed to the esbuild.
|
|
16
|
+
* Only use to specify full paths of entry points manually if you calculated them yourself.
|
|
17
|
+
* Prefer specifying entry point globs in sergen.json under TSBuild:EntryPoints which supports
|
|
18
|
+
* globs and defaults to ['Modules/** /*Page.ts', 'Modules/** /*Page.tsx', 'Modules/** /ScriptInit.ts'] */
|
|
19
|
+
entryPoints?: string[];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A set of mappings to pass to the importAsGlobalsPlugin. If this is undefined or any object and the plugins
|
|
23
|
+
* is not specified, importAsGlobals plugin is enabled */
|
|
24
|
+
importAsGlobals?: Record<string, string>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* True to enable metafile generation by esbuild. Default is true.
|
|
28
|
+
* If this is false, clean plugin won't work properly.
|
|
29
|
+
*/
|
|
30
|
+
metafile?: boolean;
|
|
31
|
+
|
|
32
|
+
/** True to enable minification. Default is true. */
|
|
33
|
+
minify?: boolean;
|
|
34
|
+
|
|
35
|
+
/** Base directory for calculating output file locations in output directory. Default is "./" */
|
|
36
|
+
outbase?: string;
|
|
37
|
+
|
|
38
|
+
/** Base output directory. Default is wwwroot/esm */
|
|
39
|
+
outdir?: boolean;
|
|
40
|
+
|
|
41
|
+
/** True to enable code splitting. Default is true unless --nosplit is passed in process arguments. */
|
|
42
|
+
splitting?: boolean;
|
|
43
|
+
|
|
44
|
+
/** Set of plugins for esbuild */
|
|
45
|
+
plugins?: any[];
|
|
46
|
+
|
|
47
|
+
/** Should source maps be generated. Default is true. */
|
|
48
|
+
sourcemap?: boolean;
|
|
49
|
+
|
|
50
|
+
/* Javascript target for output files. Default is es6. */
|
|
51
|
+
target?: string;
|
|
52
|
+
|
|
53
|
+
/** True to watch, default is calculated from process args and true if it contains --watch */
|
|
54
|
+
watch?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Processes passed options and converts it to options suitable for esbuild */
|
|
58
|
+
export const esbuildOptions: (opt: TSBuildOptions) => any;
|
|
59
|
+
export const build: (opt: TSBuildOptions) => Promise<void>;
|
|
60
|
+
export function importAsGlobalsPlugin(mapping: Record<string, string>): any;
|
|
60
61
|
export function cleanPlugin(): any;
|
package/dist/index.js
CHANGED
|
@@ -1,205 +1,211 @@
|
|
|
1
|
-
import esbuild from "esbuild";
|
|
2
|
-
import { existsSync, readdirSync, statSync, mkdirSync, writeFileSync, rmSync, readFileSync } from "fs";
|
|
3
|
-
import { join, relative, resolve } from "path";
|
|
4
|
-
import { exit } from "process";
|
|
5
|
-
import { globSync } from "glob";
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"@serenity-is/
|
|
24
|
-
"@serenity-is/corelib
|
|
25
|
-
"@serenity-is/
|
|
26
|
-
"@serenity-is/
|
|
27
|
-
"@serenity-is/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
cfg
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
exclude.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
build.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
1
|
+
import esbuild from "esbuild";
|
|
2
|
+
import { existsSync, readdirSync, statSync, mkdirSync, writeFileSync, rmSync, readFileSync } from "fs";
|
|
3
|
+
import { join, relative, resolve } from "path";
|
|
4
|
+
import { exit } from "process";
|
|
5
|
+
import { globSync } from "glob";
|
|
6
|
+
|
|
7
|
+
export const defaultEntryPointGlobs = ['Modules/**/*Page.ts', 'Modules/**/*Page.tsx', 'Modules/**/ScriptInit.ts'];
|
|
8
|
+
|
|
9
|
+
export function checkIfTrigger() {
|
|
10
|
+
if (process.argv.slice(2).some(x => x == "--trigger")) {
|
|
11
|
+
if (existsSync('typings/serenity.corelib/_trigger.ts'))
|
|
12
|
+
rmSync('typings/serenity.corelib/_trigger.ts')
|
|
13
|
+
else {
|
|
14
|
+
if (!existsSync('typings/serenity.corelib/'))
|
|
15
|
+
mkdirSync('typings/serenity.corelib/');
|
|
16
|
+
writeFileSync('typings/serenity.corelib/_trigger.ts', '// for triggering build');
|
|
17
|
+
}
|
|
18
|
+
exit(0);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const importAsGlobalsMapping = {
|
|
23
|
+
"@serenity-is/base": "Serenity",
|
|
24
|
+
"@serenity-is/corelib": "Serenity",
|
|
25
|
+
"@serenity-is/corelib/q": "Q",
|
|
26
|
+
"@serenity-is/corelib/slick": "Slick",
|
|
27
|
+
"@serenity-is/sleekgrid": "Slick",
|
|
28
|
+
"@serenity-is/extensions": "Serenity.Extensions",
|
|
29
|
+
"@serenity-is/pro.extensions": "Serenity"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const esbuildOptions = (opt) => {
|
|
33
|
+
|
|
34
|
+
opt = Object.assign({}, opt);
|
|
35
|
+
|
|
36
|
+
var entryPointsRegEx;
|
|
37
|
+
if (opt.entryPointsRegEx !== undefined) {
|
|
38
|
+
entryPointsRegEx = opt.entryPointsRegEx;
|
|
39
|
+
delete opt.entryPointsRegEx;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var entryPointRoots = ['Modules'];
|
|
43
|
+
if (opt.entryPointRoots !== undefined) {
|
|
44
|
+
entryPointRoots = opt.entryPointRoots;
|
|
45
|
+
delete opt.entryPointRoots;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
var entryPoints = opt.entryPoints;
|
|
50
|
+
if (entryPoints === void 0) {
|
|
51
|
+
let globs;
|
|
52
|
+
if (existsSync('sergen.json')) {
|
|
53
|
+
var json = readFileSync('sergen.json', 'utf8').trim();
|
|
54
|
+
var cfg = JSON.parse(json || {});
|
|
55
|
+
globs = cfg?.TSBuild?.EntryPoints;
|
|
56
|
+
if (globs === void 0 &&
|
|
57
|
+
cfg.Extends &&
|
|
58
|
+
existsSync(cfg.Extends)) {
|
|
59
|
+
json = readFileSync(cfg.Extends, 'utf8').trim();
|
|
60
|
+
cfg = JSON.parse(json || {});
|
|
61
|
+
globs = cfg?.TSBuild?.EntryPoints;
|
|
62
|
+
if (globs != null && globs[0] === '+') {
|
|
63
|
+
globs = [...defaultEntryPointGlobs, ...globs.slice(1)];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (globs == null && !entryPointsRegEx) {
|
|
69
|
+
globs = defaultEntryPointGlobs;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (globs != null) {
|
|
73
|
+
var include = globs.filter(x => !x.startsWith('!'));
|
|
74
|
+
var exclude = globs.filter(x => x.startsWith('!')).map(x => x.substring(1));
|
|
75
|
+
exclude.push(".git/**");
|
|
76
|
+
exclude.push("App_Data/**");
|
|
77
|
+
exclude.push("bin/**");
|
|
78
|
+
exclude.push("obj/**");
|
|
79
|
+
exclude.push("node_modules/**");
|
|
80
|
+
exclude.push("**/node_modules/**");
|
|
81
|
+
|
|
82
|
+
entryPoints = globSync(include, {
|
|
83
|
+
ignore: exclude,
|
|
84
|
+
nodir: true,
|
|
85
|
+
matchBase: true
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
entryPoints = [];
|
|
90
|
+
entryPointRoots.forEach(root =>
|
|
91
|
+
scanDir(root)
|
|
92
|
+
.filter(p => p.match(entryPointsRegEx))
|
|
93
|
+
.forEach(p => entryPoints.push(root + '/' + p)));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var splitting = opt.splitting;
|
|
98
|
+
if (splitting === undefined)
|
|
99
|
+
splitting = !process.argv.slice(2).some(x => x == "--nosplit");
|
|
100
|
+
|
|
101
|
+
var plugins = opt.plugins;
|
|
102
|
+
if (plugins === undefined) {
|
|
103
|
+
plugins = [];
|
|
104
|
+
if ((opt.clean === undefined && splitting) || opt.clean)
|
|
105
|
+
plugins.push(cleanPlugin());
|
|
106
|
+
if (opt.importAsGlobals === undefined || opt.importAsGlobals)
|
|
107
|
+
plugins.push(importAsGlobalsPlugin(opt.importAsGlobals ?? importAsGlobalsMapping));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
delete opt.clean;
|
|
111
|
+
delete opt.importAsGlobals;
|
|
112
|
+
|
|
113
|
+
return Object.assign({
|
|
114
|
+
absWorkingDir: resolve('./'),
|
|
115
|
+
bundle: true,
|
|
116
|
+
chunkNames: '_chunks/[name]-[hash]',
|
|
117
|
+
color: true,
|
|
118
|
+
entryPoints: entryPoints,
|
|
119
|
+
format: 'esm',
|
|
120
|
+
keepNames: true,
|
|
121
|
+
logLevel: 'info',
|
|
122
|
+
metafile: true,
|
|
123
|
+
minify: true,
|
|
124
|
+
outbase: "./",
|
|
125
|
+
outdir: 'wwwroot/esm',
|
|
126
|
+
plugins,
|
|
127
|
+
sourcemap: true,
|
|
128
|
+
splitting: splitting,
|
|
129
|
+
target: 'es2017',
|
|
130
|
+
watch: process.argv.slice(2).some(x => x == "--watch"),
|
|
131
|
+
}, opt);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const build = async (opt) => {
|
|
135
|
+
opt = esbuildOptions(opt);
|
|
136
|
+
|
|
137
|
+
if (opt.watch) {
|
|
138
|
+
// this somehow resolves the issue that when debugging is stopped
|
|
139
|
+
// in Visual Studio, the node process stays alive
|
|
140
|
+
setInterval(() => {
|
|
141
|
+
process.stdout.write("");
|
|
142
|
+
}, 5000);
|
|
143
|
+
|
|
144
|
+
delete opt.watch;
|
|
145
|
+
const context = await esbuild.context(opt);
|
|
146
|
+
await context.watch();
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
delete opt.watch;
|
|
150
|
+
await esbuild.build(opt);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
function scanDir(dir, org) {
|
|
155
|
+
return readdirSync(dir).reduce((files, file) => {
|
|
156
|
+
const absolute = join(dir, file);
|
|
157
|
+
return [...files, ...(statSync(absolute).isDirectory()
|
|
158
|
+
? scanDir(absolute, org || dir)
|
|
159
|
+
: [relative(org || dir, absolute)])]
|
|
160
|
+
}, []);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// https://github.com/evanw/esbuild/issues/337
|
|
164
|
+
export function importAsGlobalsPlugin(mapping) {
|
|
165
|
+
const escRe = (s) => s.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
166
|
+
const filter = new RegExp(Object.keys(mapping).map((mod) =>
|
|
167
|
+
`^${escRe(mod)}$`).join("|"));
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
name: "global-imports",
|
|
171
|
+
setup(build) {
|
|
172
|
+
build.onResolve({ filter }, (args) => {
|
|
173
|
+
if (!mapping[args.path])
|
|
174
|
+
throw new Error("Unknown global: " + args.path);
|
|
175
|
+
return { path: mapping[args.path], namespace: "external-global" };
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
build.onLoad({ filter: /.*/, namespace: "external-global" },
|
|
179
|
+
async (args) => {
|
|
180
|
+
return { contents: `module.exports = ${args.path};`, loader: "js" };
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function cleanPlugin() {
|
|
187
|
+
return {
|
|
188
|
+
name: 'clean',
|
|
189
|
+
setup(build) {
|
|
190
|
+
build.onEnd(result => {
|
|
191
|
+
try {
|
|
192
|
+
const { outputs } = result.metafile ?? {};
|
|
193
|
+
if (!outputs || !existsSync(build.initialOptions.outdir))
|
|
194
|
+
return;
|
|
195
|
+
|
|
196
|
+
const outputFiles = new Set(Object.keys(outputs));
|
|
197
|
+
scanDir(build.initialOptions.outdir).forEach(file => {
|
|
198
|
+
if (!file.endsWith('.js') && !file.endsWith('.js.map'))
|
|
199
|
+
return;
|
|
200
|
+
if (!outputFiles.has(join(build.initialOptions.outdir, file).replace(/\\/g, '/'))) {
|
|
201
|
+
console.log('esbuild clean: deleting extra file ' + file);
|
|
202
|
+
rmSync(join(build.initialOptions.outdir, file));
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
} catch (e) {
|
|
206
|
+
console.error(`esbuild clean: ${e}`);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
205
211
|
}
|