@serenity-is/tsbuild 8.8.7 → 8.8.8

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 CHANGED
@@ -58,4 +58,5 @@ export interface TSBuildOptions {
58
58
  export const esbuildOptions: (opt: TSBuildOptions) => any;
59
59
  export const build: (opt: TSBuildOptions) => Promise<void>;
60
60
  export function importAsGlobalsPlugin(mapping: Record<string, string>): any;
61
- export function cleanPlugin(): any;
61
+ export function cleanPlugin(): any;
62
+ export function npmCopy(paths: string[], outdir?: string): void;
package/dist/index.js CHANGED
@@ -82,7 +82,7 @@ export const esbuildOptions = (opt) => {
82
82
  .forEach(p => entryPoints.push(root + '/' + p)));
83
83
  }
84
84
  }
85
-
85
+
86
86
  var splitting = opt.splitting;
87
87
  if (splitting === undefined)
88
88
  splitting = !process.argv.slice(2).some(x => x == "--nosplit");
@@ -127,6 +127,21 @@ export const esbuildOptions = (opt) => {
127
127
  }
128
128
 
129
129
  export const build = async (opt) => {
130
+ if (opt?.npmCopy !== false &&
131
+ existsSync('appsettings.bundles.json')) {
132
+ const bundlesJson = readFileSync('appsettings.bundles.json', 'utf8').trim();
133
+ const bundlesCfg = JSON.parse(bundlesJson || {});
134
+ const bundles = Object.values(bundlesCfg?.CssBundling?.Bundles || {}).concat(Object.values(bundlesCfg?.ScriptBundling?.Bundles || {}));
135
+ let paths = [];
136
+ Object.values(bundles).filter(x => x?.length).forEach(bundle => {
137
+ paths.push(...bundle.filter(f => f?.startsWith('~/npm/')).map(f => f.substring(5)));
138
+ });
139
+ paths = paths.filter((v, i, a) => a.indexOf(v) === i); // unique
140
+ if (paths.length) {
141
+ npmCopy(paths);
142
+ }
143
+ }
144
+
130
145
  opt = esbuildOptions(opt);
131
146
 
132
147
  if (opt.watch) {
@@ -228,4 +243,43 @@ export function writeIfChanged() {
228
243
  });
229
244
  }
230
245
  };
246
+ }
247
+
248
+ export function npmCopy(paths) {
249
+ paths.forEach(path => {
250
+ const srcFile = join("node_modules", path);
251
+ const dstfile = join("wwwroot/npm", path);
252
+ if (!existsSync(srcFile)) {
253
+ console.warn(`Source file not found: ${srcFile}`);
254
+ return;
255
+ }
256
+
257
+ (function() {
258
+ const srcContent = readFileSync(srcFile);
259
+ if (existsSync(dstfile)) {
260
+ if (readFileSync(dstfile).equals(srcContent))
261
+ return;
262
+ }
263
+ else {
264
+ mkdirSync(dirname(dstfile), { recursive: true });
265
+ }
266
+ console.log(`Copying ${srcFile} to ${dstfile}`);
267
+ writeFileSync(dstfile, srcContent);
268
+ })();
269
+
270
+ const js = path.endsWith(".js");
271
+ if ((js && !path.endsWith(".min.js")) ||
272
+ (path.endsWith(".css") && !path.endsWith(".min.css"))) {
273
+ const ext = js ? ".min.js" : ".min.css";
274
+ const srcMinFile = srcFile.substring(0, srcFile.length - (js ? 3 : 4)) + ext;
275
+ const dstMinFile = dstfile.substring(0, dstfile.length - (js ? 3 : 4)) + ext;
276
+ if (existsSync(srcMinFile)) {
277
+ const srcMinContent = readFileSync(srcMinFile);
278
+ if (existsSync(dstMinFile) && readFileSync(dstMinFile).equals(srcMinContent))
279
+ return;
280
+ console.log(`Copying ${srcMinFile} to ${dstMinFile}`);
281
+ writeFileSync(dstMinFile, srcMinContent);
282
+ }
283
+ }
284
+ });
231
285
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@serenity-is/tsbuild",
3
- "version": "8.8.7",
3
+ "version": "8.8.8",
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.25.6",
8
+ "esbuild": "0.25.9",
9
9
  "glob": "11.0.3"
10
10
  },
11
11
  "exports": {