@opendatacapture/instrument-bundler 2.2.0 → 2.2.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@opendatacapture/instrument-bundler",
3
3
  "type": "module",
4
- "version": "2.2.0",
4
+ "version": "2.2.2",
5
5
  "sideEffects": [
6
6
  "**/cli.ts"
7
7
  ],
@@ -35,12 +35,12 @@
35
35
  "glob": "^11.1.0",
36
36
  "slashes": "^3.0.12",
37
37
  "@opendatacapture/runtime-internal": "0.0.0",
38
- "type-fest": "npm:type-fest__4.x@4.23.0",
38
+ "ts-pattern": "npm:ts-pattern__5.x@5.3.1",
39
39
  "zod": "npm:zod__3.x@3.25.36",
40
- "ts-pattern": "npm:ts-pattern__5.x@5.3.1"
40
+ "type-fest": "npm:type-fest__4.x@4.23.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@opendatacapture/runtime-v1": "2.2.0",
43
+ "@opendatacapture/runtime-v1": "2.2.2",
44
44
  "react-dom": "npm:react-dom__19.x@19.1.0",
45
45
  "react": "npm:react__19.x@19.1.0"
46
46
  },
package/src/build.ts CHANGED
@@ -9,7 +9,7 @@ import * as esbuild from './vendor/esbuild.js';
9
9
 
10
10
  import type { BundlerInput } from './schemas.js';
11
11
  import type { BuildOutput } from './types.js';
12
- import type { BuildResult } from './vendor/esbuild.js';
12
+ import type { BuildFailure, BuildResult } from './vendor/esbuild.js';
13
13
 
14
14
  const DEFAULT_REACT_PACKAGE = 'react@19.x';
15
15
 
@@ -37,6 +37,10 @@ function resolveJsxImportSource(inputs: BundlerInput[]): string {
37
37
  return `/runtime/v1/${packages.values().next().value ?? DEFAULT_REACT_PACKAGE}`;
38
38
  }
39
39
 
40
+ function describeError(err: unknown): string {
41
+ return err instanceof Error ? `${err.name}: ${err.message}` : `${typeof err}: ${String(err)}`;
42
+ }
43
+
40
44
  function parseBuildResult(result: BuildResult): BuildOutput {
41
45
  const cssOutput = result.outputFiles?.find((output) => output.path.endsWith('bundle.css'));
42
46
  const jsOutput = result.outputFiles?.find((output) => output.path.endsWith('bundle.js'));
@@ -95,9 +99,12 @@ export async function build({
95
99
  } catch (err) {
96
100
  const parseResult = await $BuildFailure.safeParseAsync(err);
97
101
  if (parseResult.success) {
98
- throw new InstrumentBundlerError('Unknown Error', { cause: err });
102
+ // the original error, rather than the parsed copy, so that `cause instanceof Error` holds downstream
103
+ throw new InstrumentBundlerError('Failed to Compile', { cause: err as BuildFailure, kind: 'ESBUILD_FAILURE' });
99
104
  }
100
- throw new InstrumentBundlerError('Failed to Compile', { cause: parseResult.error, kind: 'ESBUILD_FAILURE' });
105
+ // anything esbuild did not report as a compilation failure is a fault in the bundler itself, not in the
106
+ // instrument, so name it here rather than leaving the reader with 'Unknown Error' and a stack
107
+ throw new InstrumentBundlerError(`Unexpected error while invoking esbuild: ${describeError(err)}`, { cause: err });
101
108
  }
102
109
  return parseBuildResult(result);
103
110
  }
@@ -1,5 +1,3 @@
1
- /* eslint-disable no-var */
2
-
3
1
  declare module 'esbuild' {
4
2
  // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/consistent-type-definitions
5
3
  export interface BuildResult<ProvidedOptions extends BuildOptions = BuildOptions> {
@@ -14,11 +12,10 @@ declare module 'esbuild-wasm' {
14
12
  }
15
13
  }
16
14
 
17
- if (typeof window === 'undefined') {
18
- var { build, transform } = await import('esbuild');
19
- } else {
20
- var { build, transform } = await import('esbuild-wasm');
21
- }
15
+ // The bindings must be initialized by their own declaration, not by a detached `if`/`else`.
16
+ // This package declares `sideEffects: ['**/cli.ts']`, so a bundler is free to drop a
17
+ // standalone statement here, which silently leaves `build` undeclared in the output.
18
+ const { build, transform } = typeof window === 'undefined' ? await import('esbuild') : await import('esbuild-wasm');
22
19
 
23
20
  export { build, transform };
24
21
  export type { BuildFailure, BuildResult, Loader, Location, Message, Plugin } from 'esbuild';