@serenity-is/tsbuild 8.8.7 → 9.1.0

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014-present Volkan Ceylan, https://serenity.is
3
+ Copyright (c) 2014-present Volkan Ceylan, and the Serenity project authors (https://serenity.is)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
package/dist/index.d.ts CHANGED
@@ -32,6 +32,9 @@ export interface TSBuildOptions {
32
32
  /** True to enable minification. Default is true. */
33
33
  minify?: boolean;
34
34
 
35
+ /** False to not call npmCopy automatically for entries in appsettings.bundles.json that start with `~/npm/`. Default is true.*/
36
+ npmCopy?: boolean;
37
+
35
38
  /** Base directory for calculating output file locations in output directory. Default is "./" */
36
39
  outbase?: string;
37
40
 
@@ -58,4 +61,5 @@ export interface TSBuildOptions {
58
61
  export const esbuildOptions: (opt: TSBuildOptions) => any;
59
62
  export const build: (opt: TSBuildOptions) => Promise<void>;
60
63
  export function importAsGlobalsPlugin(mapping: Record<string, string>): any;
61
- export function cleanPlugin(): any;
64
+ export function cleanPlugin(): any;
65
+ 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,23 @@ 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
+
145
+ delete opt?.npmCopy;
146
+
130
147
  opt = esbuildOptions(opt);
131
148
 
132
149
  if (opt.watch) {
@@ -228,4 +245,43 @@ export function writeIfChanged() {
228
245
  });
229
246
  }
230
247
  };
248
+ }
249
+
250
+ export function npmCopy(paths) {
251
+ paths.forEach(path => {
252
+ const srcFile = join("node_modules", path);
253
+ const dstfile = join("wwwroot/npm", path);
254
+ if (!existsSync(srcFile)) {
255
+ console.warn(`Source file not found: ${srcFile}`);
256
+ return;
257
+ }
258
+
259
+ (function() {
260
+ const srcContent = readFileSync(srcFile);
261
+ if (existsSync(dstfile)) {
262
+ if (readFileSync(dstfile).equals(srcContent))
263
+ return;
264
+ }
265
+ else {
266
+ mkdirSync(dirname(dstfile), { recursive: true });
267
+ }
268
+ console.log(`Copying ${srcFile} to ${dstfile}`);
269
+ writeFileSync(dstfile, srcContent);
270
+ })();
271
+
272
+ const js = path.endsWith(".js");
273
+ if ((js && !path.endsWith(".min.js")) ||
274
+ (path.endsWith(".css") && !path.endsWith(".min.css"))) {
275
+ const ext = js ? ".min.js" : ".min.css";
276
+ const srcMinFile = srcFile.substring(0, srcFile.length - (js ? 3 : 4)) + ext;
277
+ const dstMinFile = dstfile.substring(0, dstfile.length - (js ? 3 : 4)) + ext;
278
+ if (existsSync(srcMinFile)) {
279
+ const srcMinContent = readFileSync(srcMinFile);
280
+ if (existsSync(dstMinFile) && readFileSync(dstMinFile).equals(srcMinContent))
281
+ return;
282
+ console.log(`Copying ${srcMinFile} to ${dstMinFile}`);
283
+ writeFileSync(dstMinFile, srcMinContent);
284
+ }
285
+ }
286
+ });
231
287
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@serenity-is/tsbuild",
3
- "version": "8.8.7",
3
+ "version": "9.1.0",
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.27.0",
9
9
  "glob": "11.0.3"
10
10
  },
11
11
  "exports": {