@normed/bundle 4.6.2 → 4.6.3

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.
@@ -13,6 +13,13 @@ export interface DiscoveredLessReference {
13
13
  originalHref: string;
14
14
  absolutePath: string;
15
15
  }
16
+ /**
17
+ * Discovered JavaScript/TypeScript file reference from HTML.
18
+ */
19
+ export interface DiscoveredScriptReference {
20
+ originalHref: string;
21
+ absolutePath: string;
22
+ }
16
23
  /**
17
24
  * Map of source pug file path to discovered pug references.
18
25
  * This is populated during build and used by the builder to trigger sub-builds.
@@ -23,6 +30,11 @@ export declare const discoveredPugReferences: Map<string, DiscoveredPugReference
23
30
  * This is populated during build and used by the builder to trigger sub-builds.
24
31
  */
25
32
  export declare const discoveredLessReferences: Map<string, DiscoveredLessReference[]>;
33
+ /**
34
+ * Map of source pug file path to discovered JavaScript/TypeScript references.
35
+ * This is populated during build and used by the builder to trigger sub-builds.
36
+ */
37
+ export declare const discoveredScriptReferences: Map<string, DiscoveredScriptReference[]>;
26
38
  /**
27
39
  * Discovered package CSS reference from HTML.
28
40
  * Package CSS files need to go through esbuild's CSS pipeline to handle url() references.
@@ -44,6 +56,10 @@ export declare function clearDiscoveredPugReferences(): void;
44
56
  * Clear discovered less references. Should be called before a new build.
45
57
  */
46
58
  export declare function clearDiscoveredLessReferences(): void;
59
+ /**
60
+ * Clear discovered script references. Should be called before a new build.
61
+ */
62
+ export declare function clearDiscoveredScriptReferences(): void;
47
63
  /**
48
64
  * Clear discovered package CSS references. Should be called before a new build.
49
65
  */
package/bundles/index.js CHANGED
@@ -69186,6 +69186,12 @@ function isPugReference(assetPath) {
69186
69186
  function isLessReference(assetPath) {
69187
69187
  return assetPath.endsWith(".less") && isRelativeAssetPath(assetPath);
69188
69188
  }
69189
+ function isScriptReference(assetPath) {
69190
+ const scriptExtensions = [".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx"];
69191
+ const isScript = scriptExtensions.some((ext) => assetPath.endsWith(ext));
69192
+ const isDeclaration = assetPath.endsWith(".d.ts");
69193
+ return isScript && !isDeclaration && isRelativeAssetPath(assetPath);
69194
+ }
69189
69195
  var PKG_PREFIX = "pkg:";
69190
69196
  function isPackageReference(assetPath) {
69191
69197
  return assetPath.startsWith(PKG_PREFIX);
@@ -69206,6 +69212,7 @@ function resolvePackagePath(packageSpecifier, fromFile) {
69206
69212
  }
69207
69213
  var discoveredPugReferences = /* @__PURE__ */ new Map();
69208
69214
  var discoveredLessReferences = /* @__PURE__ */ new Map();
69215
+ var discoveredScriptReferences = /* @__PURE__ */ new Map();
69209
69216
  var discoveredPackageCssReferences = /* @__PURE__ */ new Map();
69210
69217
  function clearDiscoveredPugReferences() {
69211
69218
  discoveredPugReferences.clear();
@@ -69213,6 +69220,9 @@ function clearDiscoveredPugReferences() {
69213
69220
  function clearDiscoveredLessReferences() {
69214
69221
  discoveredLessReferences.clear();
69215
69222
  }
69223
+ function clearDiscoveredScriptReferences() {
69224
+ discoveredScriptReferences.clear();
69225
+ }
69216
69226
  function clearDiscoveredPackageCssReferences() {
69217
69227
  discoveredPackageCssReferences.clear();
69218
69228
  }
@@ -69227,6 +69237,7 @@ async function processHtmlAssets(html, pugFilePath, options) {
69227
69237
  const assets = [];
69228
69238
  const pugReferences = [];
69229
69239
  const lessReferences = [];
69240
+ const scriptReferences = [];
69230
69241
  const packageCssReferences = [];
69231
69242
  const assetNames = options.assetNames || "[name]-[hash]";
69232
69243
  const outdir = options.outdir || ".";
@@ -69254,6 +69265,7 @@ async function processHtmlAssets(html, pugFilePath, options) {
69254
69265
  }
69255
69266
  const discoveredPugPaths = /* @__PURE__ */ new Set();
69256
69267
  const discoveredLessPaths = /* @__PURE__ */ new Set();
69268
+ const discoveredScriptPaths = /* @__PURE__ */ new Set();
69257
69269
  const discoveredPackageCssPaths = /* @__PURE__ */ new Set();
69258
69270
  for (const { fullMatch, attr, value } of matches) {
69259
69271
  let newValue = value;
@@ -69306,6 +69318,12 @@ async function processHtmlAssets(html, pugFilePath, options) {
69306
69318
  discoveredLessPaths.add(absolutePath);
69307
69319
  lessReferences.push({ originalHref: value, absolutePath });
69308
69320
  }
69321
+ } else if (isScriptReference(value)) {
69322
+ const absolutePath = import_path5.default.resolve(pugDir, value);
69323
+ if (!discoveredScriptPaths.has(absolutePath)) {
69324
+ discoveredScriptPaths.add(absolutePath);
69325
+ scriptReferences.push({ originalHref: value, absolutePath });
69326
+ }
69309
69327
  } else if (isPackageCssReference(value)) {
69310
69328
  const packageSpecifier = getPackageSpecifier(value);
69311
69329
  const absolutePath = resolvePackagePath(packageSpecifier, pugFilePath);
@@ -69358,6 +69376,7 @@ async function processHtmlAssets(html, pugFilePath, options) {
69358
69376
  assets,
69359
69377
  pugReferences,
69360
69378
  lessReferences,
69379
+ scriptReferences,
69361
69380
  packageCssReferences
69362
69381
  };
69363
69382
  }
@@ -69536,6 +69555,7 @@ async function loadAsEntrypoint(filepath, options) {
69536
69555
  assets,
69537
69556
  pugReferences,
69538
69557
  lessReferences,
69558
+ scriptReferences,
69539
69559
  packageCssReferences
69540
69560
  } = await processHtmlAssets(contents, filepath, options);
69541
69561
  contents = processedHtml;
@@ -69545,6 +69565,9 @@ async function loadAsEntrypoint(filepath, options) {
69545
69565
  if (lessReferences.length > 0) {
69546
69566
  discoveredLessReferences.set(filepath, lessReferences);
69547
69567
  }
69568
+ if (scriptReferences.length > 0) {
69569
+ discoveredScriptReferences.set(filepath, scriptReferences);
69570
+ }
69548
69571
  if (packageCssReferences.length > 0) {
69549
69572
  discoveredPackageCssReferences.set(filepath, packageCssReferences);
69550
69573
  }
@@ -69821,6 +69844,18 @@ function rewritePackageCssReferencesInHtml(html, packageCssReferences, packageCs
69821
69844
  }
69822
69845
  return result;
69823
69846
  }
69847
+ function rewriteScriptReferencesInHtml(html, scriptReferences, scriptToOutputPath, htmlOutputDir, outdir) {
69848
+ let result = html;
69849
+ for (const ref of scriptReferences) {
69850
+ const outputPath = scriptToOutputPath.get(ref.absolutePath);
69851
+ if (outputPath) {
69852
+ const absoluteOutputPath = import_path8.default.join(outdir, outputPath);
69853
+ const relativePath = import_path8.default.relative(htmlOutputDir, absoluteOutputPath);
69854
+ result = result.split(ref.originalHref).join(relativePath);
69855
+ }
69856
+ }
69857
+ return result;
69858
+ }
69824
69859
  function outExt(inExt) {
69825
69860
  if (inExt.match(/^((c|m)?sx?|tsx?)$/)) {
69826
69861
  return "js";
@@ -69856,6 +69891,9 @@ var esbuilder = {
69856
69891
  return "css";
69857
69892
  }
69858
69893
  return ext;
69894
+ }, isCssGeneratedAsset = function(filePath) {
69895
+ const ext = import_path8.default.extname(filePath).toLowerCase();
69896
+ return cssAssetExtensions.has(ext);
69859
69897
  };
69860
69898
  const exampleFile = build2[0];
69861
69899
  if (!exampleFile) {
@@ -69927,17 +69965,43 @@ var esbuilder = {
69927
69965
  );
69928
69966
  clearDiscoveredPugReferences();
69929
69967
  clearDiscoveredLessReferences();
69968
+ clearDiscoveredScriptReferences();
69930
69969
  clearDiscoveredPackageCssReferences();
69931
69970
  const pugHtmlOutputs = /* @__PURE__ */ new Map();
69932
69971
  const pugToOutputPath = /* @__PURE__ */ new Map();
69933
69972
  const lessToOutputPath = /* @__PURE__ */ new Map();
69973
+ const scriptToOutputPath = /* @__PURE__ */ new Map();
69934
69974
  const packageCssToOutputPath = /* @__PURE__ */ new Map();
69935
69975
  const processedPugFiles = /* @__PURE__ */ new Set();
69936
69976
  const processedLessFiles = /* @__PURE__ */ new Set();
69977
+ const processedScriptFiles = /* @__PURE__ */ new Set();
69937
69978
  const processedPackageCssFiles = /* @__PURE__ */ new Set();
69938
69979
  const pendingPugFiles = [];
69939
69980
  const pendingLessFiles = [];
69981
+ const pendingScriptFiles = [];
69940
69982
  const pendingPackageCssFiles = [];
69983
+ const cssAssetExtensions = /* @__PURE__ */ new Set([
69984
+ ".png",
69985
+ ".jpg",
69986
+ ".jpeg",
69987
+ ".gif",
69988
+ ".webp",
69989
+ ".svg",
69990
+ ".ico",
69991
+ ".woff",
69992
+ ".woff2",
69993
+ ".ttf",
69994
+ ".eot",
69995
+ ".otf",
69996
+ ".mp4",
69997
+ ".webm",
69998
+ ".ogg",
69999
+ ".mp3",
70000
+ ".wav",
70001
+ ".flac",
70002
+ ".aac",
70003
+ ".avif"
70004
+ ]);
69941
70005
  const processOutputFiles = async (result, currentOutputFilesMap, isDiscoveredBuild) => {
69942
70006
  if (result.errors.length || result.warnings.length) {
69943
70007
  log_default.info(`Build completed with errors or warnings:`, {
@@ -69983,7 +70047,7 @@ var esbuilder = {
69983
70047
  `Build artefact "${relativeFilePath}" was created but not expected.`
69984
70048
  );
69985
70049
  }
69986
- } else if (!isDiscoveredBuild) {
70050
+ } else if (!isDiscoveredBuild && !isCssGeneratedAsset(relativeFilePath)) {
69987
70051
  log_default.warn(
69988
70052
  `Build artefact "${relativeFilePath}" was created but not expected.`
69989
70053
  );
@@ -69998,6 +70062,7 @@ var esbuilder = {
69998
70062
  if (isHtmlOutput && sourcePath) {
69999
70063
  const pugRefs = discoveredPugReferences.get(sourcePath) || [];
70000
70064
  const lessRefs = discoveredLessReferences.get(sourcePath) || [];
70065
+ const scriptRefs = discoveredScriptReferences.get(sourcePath) || [];
70001
70066
  const packageCssRefs = discoveredPackageCssReferences.get(sourcePath) || [];
70002
70067
  pugToOutputPath.set(sourcePath, relativeTarget);
70003
70068
  for (const ref of pugRefs) {
@@ -70028,6 +70093,20 @@ var esbuilder = {
70028
70093
  }
70029
70094
  }
70030
70095
  }
70096
+ for (const ref of scriptRefs) {
70097
+ if (!processedScriptFiles.has(ref.absolutePath) && !pendingScriptFiles.includes(ref.absolutePath)) {
70098
+ if (import_fs7.default.existsSync(ref.absolutePath)) {
70099
+ pendingScriptFiles.push(ref.absolutePath);
70100
+ log_default.debug(
70101
+ `Discovered script reference: ${ref.originalHref} -> ${ref.absolutePath}`
70102
+ );
70103
+ } else {
70104
+ log_default.warn(
70105
+ `Referenced script file not found: ${ref.originalHref} (resolved to ${ref.absolutePath})`
70106
+ );
70107
+ }
70108
+ }
70109
+ }
70031
70110
  for (const ref of packageCssRefs) {
70032
70111
  if (!processedPackageCssFiles.has(ref.absolutePath) && !pendingPackageCssFiles.includes(ref.absolutePath)) {
70033
70112
  if (import_fs7.default.existsSync(ref.absolutePath)) {
@@ -70048,6 +70127,7 @@ var esbuilder = {
70048
70127
  outputPath: import_path8.default.join(outdir, relativeTarget),
70049
70128
  pugReferences: pugRefs,
70050
70129
  lessReferences: lessRefs,
70130
+ scriptReferences: scriptRefs,
70051
70131
  packageCssReferences: packageCssRefs
70052
70132
  });
70053
70133
  } else {
@@ -70171,6 +70251,44 @@ var esbuilder = {
70171
70251
  }
70172
70252
  }
70173
70253
  }
70254
+ while (pendingScriptFiles.length > 0) {
70255
+ const batch = pendingScriptFiles.splice(0);
70256
+ const newEntryPoints = batch.filter(
70257
+ (f) => !processedScriptFiles.has(f)
70258
+ );
70259
+ if (newEntryPoints.length === 0) break;
70260
+ log_default.debug(
70261
+ `Building ${newEntryPoints.length} discovered script file(s):`,
70262
+ newEntryPoints
70263
+ );
70264
+ for (const scriptSourcePath of newEntryPoints) {
70265
+ processedScriptFiles.add(scriptSourcePath);
70266
+ const entryNames = finalConfig.assetNames?.replace("[ext]", "") || "[dir]/[name]-[hash]";
70267
+ const scriptConfig = {
70268
+ ...finalConfig,
70269
+ entryPoints: [scriptSourcePath],
70270
+ entryNames,
70271
+ // Use minifyWhitespace to remove module boundary comments (// path/to/file.js)
70272
+ // These comments contain absolute paths that differ between machines,
70273
+ // causing non-deterministic content hashes. minifyWhitespace removes them
70274
+ // while preserving variable names for debugging.
70275
+ minifyWhitespace: true
70276
+ };
70277
+ const scriptResult = await esbuild.build(scriptConfig);
70278
+ for (const file of scriptResult.outputFiles) {
70279
+ const relativeFilePath = import_path8.default.relative(outdir, file.path);
70280
+ if (relativeFilePath.endsWith(".js")) {
70281
+ scriptToOutputPath.set(scriptSourcePath, relativeFilePath);
70282
+ log_default.debug(
70283
+ `Built script file: ${import_path8.default.relative(indir, scriptSourcePath)} -> ${relativeFilePath}`
70284
+ );
70285
+ }
70286
+ await fileWriter.writeFile(file.path, file.contents, {
70287
+ encoding: "utf-8"
70288
+ });
70289
+ }
70290
+ }
70291
+ }
70174
70292
  while (pendingPackageCssFiles.length > 0) {
70175
70293
  const batch = pendingPackageCssFiles.splice(0);
70176
70294
  const newEntryPoints = batch.filter(
@@ -70205,7 +70323,7 @@ var esbuilder = {
70205
70323
  }
70206
70324
  }
70207
70325
  log_default.debug(
70208
- `Rewriting pug/less references in ${pugHtmlOutputs.size} HTML file(s)`
70326
+ `Rewriting pug/less/script references in ${pugHtmlOutputs.size} HTML file(s)`
70209
70327
  );
70210
70328
  const htmlWriters = [];
70211
70329
  for (const [_sourcePath, output] of pugHtmlOutputs.entries()) {
@@ -70229,6 +70347,15 @@ var esbuilder = {
70229
70347
  outdir
70230
70348
  );
70231
70349
  }
70350
+ if (output.scriptReferences.length > 0) {
70351
+ html = rewriteScriptReferencesInHtml(
70352
+ html,
70353
+ output.scriptReferences,
70354
+ scriptToOutputPath,
70355
+ htmlOutputDir,
70356
+ outdir
70357
+ );
70358
+ }
70232
70359
  if (output.packageCssReferences.length > 0) {
70233
70360
  html = rewritePackageCssReferencesInHtml(
70234
70361
  html,