@normed/bundle 4.0.0 → 4.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.
@@ -0,0 +1,3 @@
1
+ import type * as esbuild from "esbuild";
2
+ declare const plugin: esbuild.Plugin;
3
+ export default plugin;
package/bundles/index.js CHANGED
@@ -69049,33 +69049,49 @@ async function loadAsText2(_filepath) {
69049
69049
  // as well - its probably faster than us doing it in JS.
69050
69050
  };
69051
69051
  }
69052
- async function loadAsJS2(filepath) {
69052
+ async function loadAsJS2(filepath, options) {
69053
69053
  const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
69054
- const contents = "export default " + import_pug.default.compileClient(fileData, { name: "render" });
69054
+ const contents = "export default " + import_pug.default.compileClient(fileData, {
69055
+ name: "render",
69056
+ filename: filepath,
69057
+ basedir: options.outbase
69058
+ });
69055
69059
  return {
69056
69060
  contents,
69057
69061
  loader: "js"
69058
69062
  };
69059
69063
  }
69060
- async function loadAsHtml(filepath) {
69064
+ async function loadAsHtml(filepath, options) {
69061
69065
  const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
69062
- const contents = import_pug.default.render(fileData, { name: "render" });
69066
+ const contents = import_pug.default.render(fileData, {
69067
+ name: "render",
69068
+ filename: filepath,
69069
+ basedir: options.outbase
69070
+ });
69063
69071
  return {
69064
69072
  contents,
69065
69073
  loader: "js"
69066
69074
  };
69067
69075
  }
69068
- async function loadAsCopy(filepath) {
69076
+ async function loadAsCopy(filepath, options) {
69069
69077
  const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
69070
- const contents = import_pug.default.render(fileData, { name: "render" });
69078
+ const contents = import_pug.default.render(fileData, {
69079
+ filename: filepath,
69080
+ basedir: options.outbase,
69081
+ name: "render"
69082
+ });
69071
69083
  return {
69072
69084
  contents,
69073
69085
  loader: "copy"
69074
69086
  };
69075
69087
  }
69076
- async function loadAsFile(filepath) {
69088
+ async function loadAsFile(filepath, options) {
69077
69089
  const fileData = await import_fs4.default.promises.readFile(filepath, "utf8");
69078
- const contents = import_pug.default.render(fileData, { name: "render" });
69090
+ const contents = import_pug.default.render(fileData, {
69091
+ name: "render",
69092
+ filename: filepath,
69093
+ basedir: options.outbase
69094
+ });
69079
69095
  return {
69080
69096
  contents,
69081
69097
  loader: "file"
@@ -69114,7 +69130,7 @@ var plugin2 = {
69114
69130
  }) => {
69115
69131
  const isEntryPoint = pluginData?.[name2]?.entrypoint;
69116
69132
  if (isEntryPoint) {
69117
- return loadAsCopy(filepath);
69133
+ return loadAsCopy(filepath, build2.initialOptions);
69118
69134
  }
69119
69135
  const type = withArg?.["type"] ?? "js";
69120
69136
  switch (type) {
@@ -69122,7 +69138,7 @@ var plugin2 = {
69122
69138
  // This gives a string of the pug already rendered to html
69123
69139
  // TODO: could support passing options to pug.render via the with clause
69124
69140
  case "html":
69125
- return loadAsHtml(filepath);
69141
+ return loadAsHtml(filepath, build2.initialOptions);
69126
69142
  // Load pug as a text file by doing "import template from './file.pug' with { type: 'text' }"
69127
69143
  // This gives a string of the raw pug file, which can be used as pug - e.g. as a template string
69128
69144
  case "pug":
@@ -69131,12 +69147,12 @@ var plugin2 = {
69131
69147
  // Load pug as a render function by doing "import render from './file.pug' with { type: 'js' }"
69132
69148
  // This is the default behaviour if no with clause is used, or no type is specified.
69133
69149
  case "js":
69134
- return loadAsJS2(filepath);
69150
+ return loadAsJS2(filepath, build2.initialOptions);
69135
69151
  // Load pug as a file by doing "import template from './file.pug' with { type: 'file' }"
69136
69152
  // This will render the pug file to a file, and return the path to that file.
69137
69153
  // The path is going to contain a hash, so it is not going to be the same as the original file.
69138
69154
  case "file":
69139
- return loadAsFile(filepath);
69155
+ return loadAsFile(filepath, build2.initialOptions);
69140
69156
  // In the case that the type is not recognised, throw an error
69141
69157
  default:
69142
69158
  throw new Error(`Unsupported type: ${type}`);
@@ -69304,7 +69320,9 @@ var esbuilder = {
69304
69320
  entryPoints: build2.map(({ infile }) => infile.absolute),
69305
69321
  outdir,
69306
69322
  outbase: indir,
69307
- write: false
69323
+ write: false,
69324
+ logLevel: "silent"
69325
+ // TODO: add a specific variable for this
69308
69326
  };
69309
69327
  log_default.debug(
69310
69328
  `Final config:`,
@@ -69315,6 +69333,13 @@ var esbuilder = {
69315
69333
  )
69316
69334
  );
69317
69335
  const codeBuild = esbuild.build(finalConfig).then(async (result) => {
69336
+ if (result.errors.length || result.warnings.length) {
69337
+ log_default.info(`Build completed with errors or warnings:`, {
69338
+ errors: result.errors.length,
69339
+ warnings: result.warnings.length
69340
+ });
69341
+ throw result;
69342
+ }
69318
69343
  log_default.debug(
69319
69344
  `Got output files:`,
69320
69345
  result.outputFiles.map((f) => import_path7.default.relative(outdir, f.path))
@@ -69383,6 +69408,20 @@ var esbuilder = {
69383
69408
  }
69384
69409
  }
69385
69410
  await Promise.all(writers);
69411
+ }).catch((err) => {
69412
+ const errors = err.errors || [];
69413
+ const warnings = err.warnings || [];
69414
+ if (!errors.length && !warnings.length) {
69415
+ log_default.error(
69416
+ `Build failed with no errors or warnings, but an unknown error occurred.`
69417
+ );
69418
+ throw err;
69419
+ } else {
69420
+ log_default.error(
69421
+ `Build failed with ${errors.length} errors and ${warnings.length} warnings.`
69422
+ );
69423
+ throw [...errors, ...warnings];
69424
+ }
69386
69425
  });
69387
69426
  promises.push(codeBuild);
69388
69427
  if (exampleFile.entryconfig.declarations) {
@@ -70512,7 +70551,7 @@ async function bundle(options = {}) {
70512
70551
  })().catch((e) => e)
70513
70552
  )
70514
70553
  );
70515
- const errors = results.filter((e) => e instanceof Error).concat(missingBuilders);
70554
+ const errors = results.filter(Boolean).concat(missingBuilders);
70516
70555
  if (errors.length) return Promise.reject(errors);
70517
70556
  return;
70518
70557
  }