@backtickjs/bundler 0.2.1 → 0.2.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.
package/README.md CHANGED
@@ -53,7 +53,18 @@ const { code } = build.generate({ format: "es", sourcemap: "inline" });
53
53
 
54
54
  The modules the client provides, by specifier, each at the exact version of the package it comes from: `"react-dom/client": "19.2.3"`. The server decides which to bundle for: one app version, or the ones each build sends, as [`@backtickjs/core`](https://github.com/backtickjs/backtick/tree/main/packages/core#every-build-in-users-hands) puts them together. Those modules are left out of the bundle, which imports (`es`) or requires (`cjs`) them. `build` rejects a script that imports from any other module, or whose import is typed against a version the one given isn't compatible with: an earlier one, or another major. `19.2.3` for `react` takes any later 19.x.
55
55
 
56
- `supports(modules, specifier, range)` makes the same check, for a server choosing what to draw for a client: `supports(modules, "expo-haptics", "^15")`.
56
+ `supports(specifier, range)` makes the same check, for a server component choosing what to draw for the client the bundler is drawing for: `supports("expo-haptics", "^15")`. It asks about the modules of the build in progress, so it's called in a server component, while `build` runs it; outside one, it throws.
57
+
58
+ A refused import throws `ClientVersionMismatch`, carrying the module (`from`), the export (`imported`), the version it's typed against (`version`) and the one the client provides (`provided`, or `undefined` for none). The client can't change, so a server catches it to answer that client differently, such as with a 426 its app answers with a screen asking to update:
59
+
60
+ ```ts
61
+ try {
62
+ bundle = await bundler.build({ input, modules });
63
+ } catch (error) {
64
+ if (!(error instanceof ClientVersionMismatch)) throw error;
65
+ return context.body(null, 426);
66
+ }
67
+ ```
57
68
 
58
69
  ### What crosses into a script
59
70
 
@@ -72,7 +83,10 @@ Spliced values are written into the bundle as data, never as code. What can't cr
72
83
 
73
84
  - `bundler.build({ input, modules })`: runs the server components in `input` and returns a `Build`. Async.
74
85
  - `Build.generate({ format, sourcemap })`: writes the bundle; returns `{ code, map }`, where `code` is a `Bundle<T>` (from `@backtickjs/core`), typed by what `input` is on the client, and `map` is `null` without a source map.
75
- - Types: `BuildOptions`, `OutputOptions`, `OutputChunk`, `Build`.
86
+ - `supports(specifier, range)`: in a server component, whether the client being drawn for provides `specifier` at a version in `range`.
87
+ - `BundlerError`: what `build` throws when it refuses its input, such as a value it can't splice. An error a server component throws passes through as it is.
88
+ - `ClientVersionMismatch`, a `BundlerError`: what `build` throws for a script's import the client can't run.
89
+ - Types: `BuildOptions`, `OutputOptions`, `OutputChunk`, `Build`, `Modules`.
76
90
 
77
91
  ## Related
78
92
 
@@ -1,4 +1,5 @@
1
1
  import { isClientExec, isClientImport, isClientScript, isJsxElement, } from "@backtickjs/core";
2
+ import { BundlerError } from "../errors.js";
2
3
  import { expandServerComponents } from "./expandServerComponents.js";
3
4
  import { bindingsOf, capturesOf, isValue } from "./params.js";
4
5
  import { sourceName } from "./bindingKey.js";
@@ -188,7 +189,7 @@ export async function buildBundle(spliceable, provided) {
188
189
  // A server component among them, written as a tag: `<$Rule />`.
189
190
  if (typeof spliceable === "function") {
190
191
  const { name } = spliceable;
191
- throw new Error((name === ""
192
+ throw new BundlerError((name === ""
192
193
  ? "Can't splice a host function"
193
194
  : `Can't splice the host function \`${name}\``) +
194
195
  ": it's host code, and only runs on the host. Write a client " +
@@ -197,7 +198,7 @@ export async function buildBundle(spliceable, provided) {
197
198
  `\`{\${<${/^[A-Z]/.test(name) ? name : "Name"} />}}\`.`);
198
199
  }
199
200
  if (typeof spliceable !== "object") {
200
- throw new Error("Can't splice a symbol: a bundle can't write one that is the same " +
201
+ throw new BundlerError("Can't splice a symbol: a bundle can't write one that is the same " +
201
202
  "symbol on the client. Splice a string, and make the symbol from it " +
202
203
  "in a script: cs`Symbol.for($key)`.");
203
204
  }
@@ -209,7 +210,7 @@ export async function buildBundle(spliceable, provided) {
209
210
  const prototype = Object.getPrototypeOf(spliceable);
210
211
  if (prototype !== Object.prototype && prototype !== null) {
211
212
  const name = spliceable.constructor?.name ?? "an unknown class";
212
- throw new Error(`Can't splice this \`${name}\` instance: only plain objects cross into ` +
213
+ throw new BundlerError(`Can't splice this \`${name}\` instance: only plain objects cross into ` +
213
214
  "a client script. Build one with a client function instead.");
214
215
  }
215
216
  const entries = [];
@@ -226,7 +227,7 @@ export async function buildBundle(spliceable, provided) {
226
227
  scope.read.add(key);
227
228
  return displayName(key);
228
229
  }
229
- throw new Error(`Can't thread the capture \`${sourceName(key)}\`: nothing encloses ` +
230
+ throw new BundlerError(`Can't thread the capture \`${sourceName(key)}\`: nothing encloses ` +
230
231
  "this reference to supply it. A fragment carries the bindings it was " +
231
232
  "written under, so this is also what happens when one is spliced " +
232
233
  "somewhere another `" +
@@ -264,11 +265,11 @@ export async function buildBundle(spliceable, provided) {
264
265
  // one) are client code, so on the host they can't be tags: they are tags
265
266
  // in a script.
266
267
  if (typeof type === "string") {
267
- throw new Error(`\`<${type}>\` is drawn by the client, so it belongs in a script: ` +
268
+ throw new BundlerError(`\`<${type}>\` is drawn by the client, so it belongs in a script: ` +
268
269
  `cs\`<${type}>…</${type}>\`.`);
269
270
  }
270
271
  const tag = isClientImport(type) ? `\`<${type.name}>\`` : "A script";
271
- throw new Error(`${tag} is a client component, so it can't be a tag on the host. ` +
272
+ throw new BundlerError(`${tag} is a client component, so it can't be a tag on the host. ` +
272
273
  "Use it as a tag in a script.");
273
274
  };
274
275
  // Every server component first, so siblings run at once; then the drawing,
@@ -1 +1 @@
1
- {"version":3,"file":"buildBundle.js","sourceRoot":"","sources":["../../src/bundle/buildBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,GAEb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,OAAO,EACP,MAAM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erError } from "../errors.js";
2
3
  import { isValue } from "./params.js";
3
4
  const CYCLE_ERROR = "Can't splice a value that contains itself: a bundle writes each value " +
4
5
  "out in full, so a cycle never ends. Break the cycle before splicing it.";
@@ -28,7 +29,7 @@ export async function expandServerComponents(spliceable, ancestors = null, value
28
29
  return spliceable;
29
30
  }
30
31
  if (contains(ancestors, spliceable)) {
31
- throw new Error(CYCLE_ERROR);
32
+ throw new BundlerError(CYCLE_ERROR);
32
33
  }
33
34
  const inside = { value: spliceable, parent: ancestors };
34
35
  const all = (entries) => Promise.all(entries.map((entry) => expandServerComponents(entry, inside, values)));
@@ -1 +1 @@
1
- {"version":3,"file":"expandServerComponents.js","sourceRoot":"","sources":["../../src/bundle/expandServerComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,cAAc,EACd,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,WAAW,GACf,wEAAwE;IACxE,yEAAyE,CAAC;AAS5E,MAAM,QAAQ,GAAG,CAAC,SAA2B,EAAE,KAAa,EAAW,EAAE;IACvE,KAAK,IAAI,EAAE,GAAG,SAAS,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;QACrD,IAAI,EAAE,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,8EAA8E;AAC9E,6EAA6E;AAC7E,0EAA0E;AAC1E,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,2EAA2E;AAC3E,kDAAkD;AAClD,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,gDAAgD;AAChD,qCAAqC;AACrC,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,UAAmB,EACnB,YAA8B,IAAI,EAClC,SAAS,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AAC;IACD,2DAA2D;IAC3D,OAAO,MAAM,CAAC,WAAW,CACvB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CACtD,CAAC;AACJ,CAAC"}
package/dist/bundler.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { buildBundle } from "./bundle/buildBundle.js";
2
+ import { BundlerError } from "./errors.js";
3
+ import { buildingFor } from "./supports.js";
2
4
  import { isModules } from "./modules.js";
3
5
  import { printBundle } from "./print/printBundle.js";
4
6
  /**
@@ -15,11 +17,11 @@ import { printBundle } from "./print/printBundle.js";
15
17
  export const bundler = {
16
18
  async build({ input, modules, }) {
17
19
  if (!isModules(modules)) {
18
- throw new Error(`The modules aren't { specifier: version }: ${JSON.stringify(modules)?.slice(0, 80)}`);
20
+ throw new BundlerError(`The modules aren't { specifier: version }: ${JSON.stringify(modules)?.slice(0, 80)}`);
19
21
  }
20
22
  // Scripts come compiled for their framework when their host was built, so
21
23
  // the bundle is only put together: nothing is compiled or parsed here.
22
- const tree = await buildBundle(input, modules);
24
+ const tree = await buildingFor(modules, () => buildBundle(input, modules));
23
25
  return {
24
26
  generate: ({ format, sourcemap = false }) => {
25
27
  const printed = printBundle(tree, format);
@@ -1 +1 @@
1
- {"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAgB,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAqCrD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,KAAK,CAAC,KAAK,CAA8D,EACvE,KAAK,EACL,OAAO,GACS;QAChB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CA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from "./modules.js";
2
+ /**
3
+ * What the bundler throws when it refuses its input: a value it can't
4
+ * splice, a tag it can't draw, an import the client can't run. An error a
5
+ * server component throws while the bundler runs it passes through as it is.
6
+ */
7
+ export declare class BundlerError extends Error {
8
+ constructor(message: string);
9
+ }
10
+ /**
11
+ * A script's import the client can't run: `imported` from the module `from`,
12
+ * typed against `version`, where the client provides the module at
13
+ * `provided`, a version the import isn't typed for (an earlier one, or
14
+ * another major), or doesn't provide it at all. The client can't change, so
15
+ * the server draws it something else: it catches this to answer differently,
16
+ * or branches with `supports` before drawing.
17
+ */
18
+ export declare class ClientVersionMismatch extends BundlerError {
19
+ readonly from: string;
20
+ readonly imported: string;
21
+ readonly version: string;
22
+ constructor(from: string, imported: string, version: string, modules: Modules);
23
+ readonly provided: string | undefined;
24
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * What the bundler throws when it refuses its input: a value it can't
3
+ * splice, a tag it can't draw, an import the client can't run. An error a
4
+ * server component throws while the bundler runs it passes through as it is.
5
+ */
6
+ export class BundlerError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ // as the class it is, in logs: `ClientVersionMismatch: Can't import …`
10
+ this.name = new.target.name;
11
+ }
12
+ }
13
+ /**
14
+ * A script's import the client can't run: `imported` from the module `from`,
15
+ * typed against `version`, where the client provides the module at
16
+ * `provided`, a version the import isn't typed for (an earlier one, or
17
+ * another major), or doesn't provide it at all. The client can't change, so
18
+ * the server draws it something else: it catches this to answer differently,
19
+ * or branches with `supports` before drawing.
20
+ */
21
+ export class ClientVersionMismatch extends BundlerError {
22
+ from;
23
+ imported;
24
+ version;
25
+ constructor(from, imported, version, modules) {
26
+ const provided = modules[from];
27
+ const listed = Object.entries(modules)
28
+ .map(([specifier, at]) => `${specifier}@${at}`)
29
+ .join(", ");
30
+ const problem = provided === undefined
31
+ ? `the client provides ${listed || "no modules"}`
32
+ : `it's typed against ${version}, and the client provides ${from}@${provided}`;
33
+ const fix = `supports("${from}", "^${version}")`;
34
+ super(`Can't import \`${imported}\` from "${from}": ${problem}. ` +
35
+ `Check \`${fix}\` first.`);
36
+ this.from = from;
37
+ this.imported = imported;
38
+ this.version = version;
39
+ this.provided = provided;
40
+ }
41
+ // the version the client provides, or none
42
+ provided;
43
+ }
44
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,uEAAuE;QACvE,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IAE1C;IACA;IACA;IAHX,YACW,IAAY,EACZ,QAAgB,EAChB,OAAe,EACxB,OAAgB;QAEhB,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;aACnC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,IAAI,EAAE,EAAE,CAAC;aAC9C,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,OAAO,GACX,QAAQ,KAAK,SAAS;YACpB,CAAC,CAAC,uBAAuB,MAAM,IAAI,YAAY,EAAE;YACjD,CAAC,CAAC,sBAAsB,OAAO,6BAA6B,IAAI,IAAI,QAAQ,EAAE,CAAC;QACnF,MAAM,GAAG,GAAG,aAAa,IAAI,QAAQ,OAAO,IAAI,CAAC;QACjD,KAAK,CACH,kBAAkB,QAAQ,YAAY,IAAI,MAAM,OAAO,IAAI;YACzD,WAAW,GAAG,WAAW,CAC5B,CAAC;QAjBO,SAAI,GAAJ,IAAI,CAAQ;QACZ,aAAQ,GAAR,QAAQ,CAAQ;QAChB,YAAO,GAAP,OAAO,CAAQ;QAgBxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,2CAA2C;IAClC,QAAQ,CAAqB;CACvC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { type Build, type BuildOptions, bundler, type OutputChunk, type OutputOptions, } from "./bundler.js";
2
- export { type Modules, supports } from "./modules.js";
2
+ export { BundlerError, ClientVersionMismatch } from "./errors.js";
3
+ export type { Modules } from "./modules.js";
4
+ export { supports } from "./supports.js";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { bundler, } from "./bundler.js";
2
- export { supports } from "./modules.js";
2
+ export { BundlerError, ClientVersionMismatch } from "./errors.js";
3
+ export { supports } from "./supports.js";
3
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,OAAO,GAGR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAgB,QAAQ,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,OAAO,GAGR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
package/dist/modules.d.ts CHANGED
@@ -7,9 +7,3 @@ export type Modules = Readonly<Record<string, string>>;
7
7
  * Whether `value` is `Modules`: often what a client sent, parsed as it came.
8
8
  */
9
9
  export declare function isModules(value: unknown): value is Modules;
10
- /**
11
- * Whether a client with `modules` provides `specifier` at a version in
12
- * `range`: the check a bundle's every import passes, so a server choosing
13
- * what to draw for a client can ask it first.
14
- */
15
- export declare function supports(modules: Modules, specifier: string, range: string): boolean;
package/dist/modules.js CHANGED
@@ -1,4 +1,3 @@
1
- import semver from "semver";
2
1
  /**
3
2
  * Whether `value` is `Modules`: often what a client sent, parsed as it came.
4
3
  */
@@ -8,13 +7,4 @@ export function isModules(value) {
8
7
  !Array.isArray(value) &&
9
8
  Object.values(value).every((version) => typeof version === "string"));
10
9
  }
11
- /**
12
- * Whether a client with `modules` provides `specifier` at a version in
13
- * `range`: the check a bundle's every import passes, so a server choosing
14
- * what to draw for a client can ask it first.
15
- */
16
- export function supports(modules, specifier, range) {
17
- const provided = modules[specifier];
18
- return provided !== undefined && semver.satisfies(provided, range);
19
- }
20
10
  //# sourceMappingURL=modules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAQ5B;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CACrE,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAgB,EAChB,SAAiB,EACjB,KAAa;IAEb,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,OAAO,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACrE,CAAC"}
1
+ {"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CACrE,CAAC;AACJ,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { ClientImport } from "@backtickjs/core";
2
- import { type Modules } from "../modules.js";
2
+ import type { Modules } from "../modules.js";
3
3
  /**
4
4
  * What a bundle imports, keyed by specifier and export, each bound once; and
5
5
  * the modules it may import them from, which the client provides, by version.
@@ -1,4 +1,5 @@
1
- import { supports } from "../modules.js";
1
+ import { ClientVersionMismatch } from "../errors.js";
2
+ import semver from "semver";
2
3
  // What a bundle is written as, and the one place its conventions live: how a
3
4
  // name is written, how a literal escapes, and how an element is written as JSX
4
5
  // for the framework's compiler. Everything is code, as a string.
@@ -53,17 +54,11 @@ function member(key) {
53
54
  /** An export of a module the client provides, imported by the bundle. */
54
55
  export function imported(names, { from, name, version }) {
55
56
  // Where a script's import is written: a plugin's own (a framework's compile
56
- // step) are the plugin's, trusted as it is.
57
+ // step) are the plugin's, trusted as it is. Typed against one version, it
58
+ // works with a later one of the same major.
57
59
  const provided = names.modules[from];
58
- if (provided === undefined) {
59
- const listed = Object.entries(names.modules).map(([specifier, at]) => `${specifier}@${at}`);
60
- throw new Error(`Can't import \`${name}\` from "${from}": the client provides ` +
61
- `${listed.join(", ") || "no modules"}.`);
62
- }
63
- // Typed against one version, it works with a later one of the same major.
64
- if (!supports(names.modules, from, `^${version}`)) {
65
- throw new Error(`Can't import \`${name}\` from "${from}": it's typed against ` +
66
- `${version}, and the client provides ${from}@${provided}.`);
60
+ if (provided === undefined || !semver.satisfies(provided, `^${version}`)) {
61
+ throw new ClientVersionMismatch(from, name, version, names.modules);
67
62
  }
68
63
  const key = `${from}\0${name}`;
69
64
  let entry = names.imports.get(key);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,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,IAAY,EACZ,KAAa;IAEb,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QACjB,OAAO,eAAe,KAAK,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;IACtD,CAAC;IACD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7D,OAAO,YAAY,QAAQ,OAAO,KAAK,WAAW,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;AACpE,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,IAAY,EACZ,KAAa;IAEb,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QACjB,OAAO,SAAS,KAAK,cAAc,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IACtD,CAAC;IACD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7D,OAAO,WAAW,QAAQ,KAAK,KAAK,gBAAgB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;AACvE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Modules } from "./modules.js";
2
+ /** Runs `build` with `modules` as the client's, for `supports`. */
3
+ export declare function buildingFor<T>(modules: Modules, build: () => T): T;
4
+ /**
5
+ * Whether the client the bundler is drawing for provides `specifier` at a
6
+ * version in `range`: the check every import passes, for a server component
7
+ * choosing what to draw for that client. Called while `bundler.build` runs
8
+ * server components; outside one, there's no client to ask about.
9
+ *
10
+ * supports("expo-haptics", "^15") ? cs`…` : cs`…`;
11
+ */
12
+ export declare function supports(specifier: string, range: string): boolean;
@@ -0,0 +1,26 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { BundlerError } from "./errors.js";
3
+ import semver from "semver";
4
+ // The modules of the client a build is for, while it runs server components.
5
+ const building = new AsyncLocalStorage();
6
+ /** Runs `build` with `modules` as the client's, for `supports`. */
7
+ export function buildingFor(modules, build) {
8
+ return building.run(modules, build);
9
+ }
10
+ /**
11
+ * Whether the client the bundler is drawing for provides `specifier` at a
12
+ * version in `range`: the check every import passes, for a server component
13
+ * choosing what to draw for that client. Called while `bundler.build` runs
14
+ * server components; outside one, there's no client to ask about.
15
+ *
16
+ * supports("expo-haptics", "^15") ? cs`…` : cs`…`;
17
+ */
18
+ export function supports(specifier, range) {
19
+ const modules = building.getStore();
20
+ if (modules === undefined) {
21
+ throw new BundlerError(`supports("${specifier}", "${range}") asks about the client a build is for: call it in a server component, while bundler.build runs it.`);
22
+ }
23
+ const provided = modules[specifier];
24
+ return provided !== undefined && semver.satisfies(provided, range);
25
+ }
26
+ //# sourceMappingURL=supports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supports.js","sourceRoot":"","sources":["../src/supports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,6EAA6E;AAC7E,MAAM,QAAQ,GAAG,IAAI,iBAAiB,EAAW,CAAC;AAElD,mEAAmE;AACnE,MAAM,UAAU,WAAW,CAAI,OAAgB,EAAE,KAAc;IAC7D,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAiB,EAAE,KAAa;IACvD,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACpC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,YAAY,CACpB,aAAa,SAAS,OAAO,KAAK,sGAAsG,CACzI,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,OAAO,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACrE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backtickjs/bundler",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Runs Backtick server components and bundles a screen per request: one JavaScript file for the client",
5
5
  "keywords": [
6
6
  "backtick",
@@ -39,7 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@backtickjs/core": "^0.2.1",
42
+ "@backtickjs/core": "^0.2.3",
43
43
  "semver": "^7.8.1"
44
44
  },
45
45
  "devDependencies": {
@@ -8,6 +8,7 @@ import {
8
8
  type JsxElement,
9
9
  } from "@backtickjs/core";
10
10
 
11
+ import { BundlerError } from "../errors.js";
11
12
  import { expandServerComponents } from "./expandServerComponents.js";
12
13
  import { bindingsOf, capturesOf, isValue } from "./params.js";
13
14
  import { sourceName } from "./bindingKey.js";
@@ -253,7 +254,7 @@ export async function buildBundle(
253
254
  // A server component among them, written as a tag: `<$Rule />`.
254
255
  if (typeof spliceable === "function") {
255
256
  const { name } = spliceable;
256
- throw new Error(
257
+ throw new BundlerError(
257
258
  (name === ""
258
259
  ? "Can't splice a host function"
259
260
  : `Can't splice the host function \`${name}\``) +
@@ -264,7 +265,7 @@ export async function buildBundle(
264
265
  );
265
266
  }
266
267
  if (typeof spliceable !== "object") {
267
- throw new Error(
268
+ throw new BundlerError(
268
269
  "Can't splice a symbol: a bundle can't write one that is the same " +
269
270
  "symbol on the client. Splice a string, and make the symbol from it " +
270
271
  "in a script: cs`Symbol.for($key)`.",
@@ -278,7 +279,7 @@ export async function buildBundle(
278
279
  const prototype = Object.getPrototypeOf(spliceable);
279
280
  if (prototype !== Object.prototype && prototype !== null) {
280
281
  const name = spliceable.constructor?.name ?? "an unknown class";
281
- throw new Error(
282
+ throw new BundlerError(
282
283
  `Can't splice this \`${name}\` instance: only plain objects cross into ` +
283
284
  "a client script. Build one with a client function instead.",
284
285
  );
@@ -298,7 +299,7 @@ export async function buildBundle(
298
299
  scope.read.add(key);
299
300
  return displayName(key);
300
301
  }
301
- throw new Error(
302
+ throw new BundlerError(
302
303
  `Can't thread the capture \`${sourceName(key)}\`: nothing encloses ` +
303
304
  "this reference to supply it. A fragment carries the bindings it was " +
304
305
  "written under, so this is also what happens when one is spliced " +
@@ -344,13 +345,13 @@ export async function buildBundle(
344
345
  // one) are client code, so on the host they can't be tags: they are tags
345
346
  // in a script.
346
347
  if (typeof type === "string") {
347
- throw new Error(
348
+ throw new BundlerError(
348
349
  `\`<${type}>\` is drawn by the client, so it belongs in a script: ` +
349
350
  `cs\`<${type}>…</${type}>\`.`,
350
351
  );
351
352
  }
352
353
  const tag = isClientImport(type) ? `\`<${type.name}>\`` : "A script";
353
- throw new Error(
354
+ throw new BundlerError(
354
355
  `${tag} is a client component, so it can't be a tag on the host. ` +
355
356
  "Use it as a tag in a script.",
356
357
  );
@@ -4,6 +4,7 @@ import {
4
4
  isClientScript,
5
5
  isJsxElement,
6
6
  } from "@backtickjs/core";
7
+ import { BundlerError } from "../errors.js";
7
8
  import { isValue } from "./params.js";
8
9
 
9
10
  const CYCLE_ERROR =
@@ -48,7 +49,7 @@ export async function expandServerComponents(
48
49
  return spliceable;
49
50
  }
50
51
  if (contains(ancestors, spliceable)) {
51
- throw new Error(CYCLE_ERROR);
52
+ throw new BundlerError(CYCLE_ERROR);
52
53
  }
53
54
  const inside: Ancestors = { value: spliceable, parent: ancestors };
54
55
  const all = (entries: readonly unknown[]) =>
package/src/bundler.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { Bundle, Spliceable, Spliced, SplicesAs } from "@backtickjs/core";
2
2
  import { buildBundle } from "./bundle/buildBundle.js";
3
+ import { BundlerError } from "./errors.js";
4
+ import { buildingFor } from "./supports.js";
3
5
  import { isModules, type Modules } from "./modules.js";
4
6
  import { printBundle } from "./print/printBundle.js";
5
7
 
@@ -55,13 +57,13 @@ export const bundler = {
55
57
  modules,
56
58
  }: BuildOptions<T>): Promise<Build<Spliced<T>>> {
57
59
  if (!isModules(modules)) {
58
- throw new Error(
60
+ throw new BundlerError(
59
61
  `The modules aren't { specifier: version }: ${JSON.stringify(modules)?.slice(0, 80)}`,
60
62
  );
61
63
  }
62
64
  // Scripts come compiled for their framework when their host was built, so
63
65
  // the bundle is only put together: nothing is compiled or parsed here.
64
- const tree = await buildBundle(input, modules);
66
+ const tree = await buildingFor(modules, () => buildBundle(input, modules));
65
67
  return {
66
68
  generate: ({ format, sourcemap = false }) => {
67
69
  const printed = printBundle(tree, format);
package/src/errors.ts ADDED
@@ -0,0 +1,49 @@
1
+ import type { Modules } from "./modules.js";
2
+
3
+ /**
4
+ * What the bundler throws when it refuses its input: a value it can't
5
+ * splice, a tag it can't draw, an import the client can't run. An error a
6
+ * server component throws while the bundler runs it passes through as it is.
7
+ */
8
+ export class BundlerError extends Error {
9
+ constructor(message: string) {
10
+ super(message);
11
+ // as the class it is, in logs: `ClientVersionMismatch: Can't import …`
12
+ this.name = new.target.name;
13
+ }
14
+ }
15
+
16
+ /**
17
+ * A script's import the client can't run: `imported` from the module `from`,
18
+ * typed against `version`, where the client provides the module at
19
+ * `provided`, a version the import isn't typed for (an earlier one, or
20
+ * another major), or doesn't provide it at all. The client can't change, so
21
+ * the server draws it something else: it catches this to answer differently,
22
+ * or branches with `supports` before drawing.
23
+ */
24
+ export class ClientVersionMismatch extends BundlerError {
25
+ constructor(
26
+ readonly from: string,
27
+ readonly imported: string,
28
+ readonly version: string,
29
+ modules: Modules,
30
+ ) {
31
+ const provided = modules[from];
32
+ const listed = Object.entries(modules)
33
+ .map(([specifier, at]) => `${specifier}@${at}`)
34
+ .join(", ");
35
+ const problem =
36
+ provided === undefined
37
+ ? `the client provides ${listed || "no modules"}`
38
+ : `it's typed against ${version}, and the client provides ${from}@${provided}`;
39
+ const fix = `supports("${from}", "^${version}")`;
40
+ super(
41
+ `Can't import \`${imported}\` from "${from}": ${problem}. ` +
42
+ `Check \`${fix}\` first.`,
43
+ );
44
+ this.provided = provided;
45
+ }
46
+
47
+ // the version the client provides, or none
48
+ readonly provided: string | undefined;
49
+ }
package/src/index.ts CHANGED
@@ -5,4 +5,6 @@ export {
5
5
  type OutputChunk,
6
6
  type OutputOptions,
7
7
  } from "./bundler.js";
8
- export { type Modules, supports } from "./modules.js";
8
+ export { BundlerError, ClientVersionMismatch } from "./errors.js";
9
+ export type { Modules } from "./modules.js";
10
+ export { supports } from "./supports.js";
package/src/modules.ts CHANGED
@@ -1,5 +1,3 @@
1
- import semver from "semver";
2
-
3
1
  /**
4
2
  * The modules a client provides, by specifier, each at the exact version of
5
3
  * the package it comes from: `{ "react/jsx-runtime": "19.2.3" }`.
@@ -17,17 +15,3 @@ export function isModules(value: unknown): value is Modules {
17
15
  Object.values(value).every((version) => typeof version === "string")
18
16
  );
19
17
  }
20
-
21
- /**
22
- * Whether a client with `modules` provides `specifier` at a version in
23
- * `range`: the check a bundle's every import passes, so a server choosing
24
- * what to draw for a client can ask it first.
25
- */
26
- export function supports(
27
- modules: Modules,
28
- specifier: string,
29
- range: string,
30
- ): boolean {
31
- const provided = modules[specifier];
32
- return provided !== undefined && semver.satisfies(provided, range);
33
- }
package/src/print/code.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { ClientImport } from "@backtickjs/core";
2
- import { type Modules, supports } from "../modules.js";
2
+ import { ClientVersionMismatch } from "../errors.js";
3
+ import semver from "semver";
4
+ import type { Modules } from "../modules.js";
3
5
 
4
6
  // What a bundle is written as, and the one place its conventions live: how a
5
7
  // name is written, how a literal escapes, and how an element is written as JSX
@@ -86,23 +88,11 @@ export function imported(
86
88
  { from, name, version }: ClientImport<unknown>,
87
89
  ): string {
88
90
  // Where a script's import is written: a plugin's own (a framework's compile
89
- // step) are the plugin's, trusted as it is.
91
+ // step) are the plugin's, trusted as it is. Typed against one version, it
92
+ // works with a later one of the same major.
90
93
  const provided = names.modules[from];
91
- if (provided === undefined) {
92
- const listed = Object.entries(names.modules).map(
93
- ([specifier, at]) => `${specifier}@${at}`,
94
- );
95
- throw new Error(
96
- `Can't import \`${name}\` from "${from}": the client provides ` +
97
- `${listed.join(", ") || "no modules"}.`,
98
- );
99
- }
100
- // Typed against one version, it works with a later one of the same major.
101
- if (!supports(names.modules, from, `^${version}`)) {
102
- throw new Error(
103
- `Can't import \`${name}\` from "${from}": it's typed against ` +
104
- `${version}, and the client provides ${from}@${provided}.`,
105
- );
94
+ if (provided === undefined || !semver.satisfies(provided, `^${version}`)) {
95
+ throw new ClientVersionMismatch(from, name, version, names.modules);
106
96
  }
107
97
  const key = `${from}\0${name}`;
108
98
  let entry = names.imports.get(key);
@@ -0,0 +1,31 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { BundlerError } from "./errors.js";
3
+ import semver from "semver";
4
+ import type { Modules } from "./modules.js";
5
+
6
+ // The modules of the client a build is for, while it runs server components.
7
+ const building = new AsyncLocalStorage<Modules>();
8
+
9
+ /** Runs `build` with `modules` as the client's, for `supports`. */
10
+ export function buildingFor<T>(modules: Modules, build: () => T): T {
11
+ return building.run(modules, build);
12
+ }
13
+
14
+ /**
15
+ * Whether the client the bundler is drawing for provides `specifier` at a
16
+ * version in `range`: the check every import passes, for a server component
17
+ * choosing what to draw for that client. Called while `bundler.build` runs
18
+ * server components; outside one, there's no client to ask about.
19
+ *
20
+ * supports("expo-haptics", "^15") ? cs`…` : cs`…`;
21
+ */
22
+ export function supports(specifier: string, range: string): boolean {
23
+ const modules = building.getStore();
24
+ if (modules === undefined) {
25
+ throw new BundlerError(
26
+ `supports("${specifier}", "${range}") asks about the client a build is for: call it in a server component, while bundler.build runs it.`,
27
+ );
28
+ }
29
+ const provided = modules[specifier];
30
+ return provided !== undefined && semver.satisfies(provided, range);
31
+ }