@serenity-is/tsbuild 6.2.7 → 6.2.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.
Files changed (2) hide show
  1. package/dist/index.js +32 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -26,7 +26,9 @@ export const importAsGlobalsMapping = {
26
26
  }
27
27
 
28
28
  export const esbuildOptions = (opt) => {
29
-
29
+
30
+ opt = Object.assign({}, opt);
31
+
30
32
  var entryPointsRegEx = /(Page|ScriptInit)\.ts$/;
31
33
  if (opt.entryPointsRegEx !== undefined) {
32
34
  entryPointsRegEx = opt.entryPointsRegEx;
@@ -42,12 +44,28 @@ export const esbuildOptions = (opt) => {
42
44
  var entryPoints = opt.entryPoints;
43
45
  if (entryPoints === undefined) {
44
46
  entryPoints = [];
45
- entryPointRoots.forEach(root =>
47
+ entryPointRoots.forEach(root =>
46
48
  scanDir(root)
47
49
  .filter(p => p.match(entryPointsRegEx))
48
50
  .forEach(p => entryPoints.push(root + '/' + p)));
49
51
  }
50
-
52
+
53
+ var splitting = opt.splitting;
54
+ if (splitting === undefined)
55
+ splitting = !process.argv.slice(2).some(x => x == "--nosplit");
56
+
57
+ var plugins = opt.plugins;
58
+ if (plugins === undefined) {
59
+ plugins = [];
60
+ if ((opt.clean === undefined && splitting) || opt.clean)
61
+ plugins.push(cleanPlugin());
62
+ if (opt.importAsGlobals === undefined || opt.importAsGlobals)
63
+ plugins.push(importAsGlobalsPlugin(opt.importAsGlobals ?? importAsGlobalsMapping));
64
+ }
65
+
66
+ delete opt.clean;
67
+ delete opt.importAsGlobals;
68
+
51
69
  return Object.assign({
52
70
  absWorkingDir: resolve('./'),
53
71
  bundle: true,
@@ -61,18 +79,17 @@ export const esbuildOptions = (opt) => {
61
79
  minify: true,
62
80
  outbase: "./",
63
81
  outdir: 'wwwroot/esm',
82
+ plugins,
64
83
  sourcemap: true,
65
- splitting: !process.argv.slice(2).some(x => x == "--nosplit"),
84
+ splitting: splitting,
66
85
  target: 'es6',
67
86
  watch: process.argv.slice(2).some(x => x == "--watch"),
68
- plugins: [
69
- cleanPlugin(),
70
- importAsGlobalsPlugin(opt.importAsGlobalsMapping ?? importAsGlobalsMapping)
71
- ]
72
87
  }, opt);
73
88
  }
74
89
 
75
90
  export const build = async (opt) => {
91
+ var opt = esbuildOptions(opt);
92
+
76
93
  if (opt.watch) {
77
94
  // this somehow resolves the issue that when debugging is stopped
78
95
  // in Visual Studio, the node process stays alive
@@ -80,7 +97,7 @@ export const build = async (opt) => {
80
97
  process.stdout.write("");
81
98
  }, 5000);
82
99
  }
83
-
100
+
84
101
  await esbuild.build(esbuildOptions(opt));
85
102
  };
86
103
 
@@ -103,7 +120,7 @@ export function importAsGlobalsPlugin(mapping) {
103
120
  name: "global-imports",
104
121
  setup(build) {
105
122
  build.onResolve({ filter }, (args) => {
106
- if (!mapping[args.path])
123
+ if (!mapping[args.path])
107
124
  throw new Error("Unknown global: " + args.path);
108
125
  return { path: args.path, namespace: "external-global" };
109
126
  });
@@ -129,8 +146,12 @@ export function cleanPlugin() {
129
146
 
130
147
  const outputFiles = new Set(Object.keys(outputs));
131
148
  scanDir(build.initialOptions.outdir).forEach(file => {
132
- if (!outputFiles.has(join(build.initialOptions.outdir, file).replace(/\\/g, '/')))
149
+ if (!file.endsWith('.js') && !file.endsWith('.js.map'))
150
+ return;
151
+ if (!outputFiles.has(join(build.initialOptions.outdir, file).replace(/\\/g, '/'))) {
152
+ console.log('esbuild clean: deleting extra file ' + file);
133
153
  rmSync(join(build.initialOptions.outdir, file));
154
+ }
134
155
  });
135
156
  } catch (e) {
136
157
  console.error(`esbuild clean: ${e}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serenity-is/tsbuild",
3
- "version": "6.2.7",
3
+ "version": "6.2.9",
4
4
  "author": "Serenity (https://serenity.is)",
5
5
  "bugs": "https://github.com/serenity-is/serenity/issues",
6
6
  "description": "Serenity ESBuild functions",