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