@backtickjs/bundler 0.2.0 → 0.2.1
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 +1 -1
- package/dist/bundler.d.ts +1 -1
- package/dist/bundler.js +4 -0
- package/dist/bundler.js.map +1 -1
- package/dist/modules.d.ts +4 -0
- package/dist/modules.js +9 -0
- package/dist/modules.js.map +1 -1
- package/package.json +2 -2
- package/src/bundler.ts +6 -1
- package/src/modules.ts +12 -0
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ const { code } = build.generate({ format: "es", sourcemap: "inline" });
|
|
|
51
51
|
|
|
52
52
|
### `modules`
|
|
53
53
|
|
|
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
|
|
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
56
|
`supports(modules, specifier, range)` makes the same check, for a server choosing what to draw for a client: `supports(modules, "expo-haptics", "^15")`.
|
|
57
57
|
|
package/dist/bundler.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Bundle, Spliceable, Spliced, SplicesAs } from "@backtickjs/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type Modules } from "./modules.js";
|
|
3
3
|
export interface BuildOptions<T = Spliceable> {
|
|
4
4
|
readonly input: T;
|
|
5
5
|
readonly modules: Modules;
|
package/dist/bundler.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { buildBundle } from "./bundle/buildBundle.js";
|
|
2
|
+
import { isModules } from "./modules.js";
|
|
2
3
|
import { printBundle } from "./print/printBundle.js";
|
|
3
4
|
/**
|
|
4
5
|
* What runs your components and hands back what they drew, shaped as Rollup
|
|
@@ -13,6 +14,9 @@ import { printBundle } from "./print/printBundle.js";
|
|
|
13
14
|
*/
|
|
14
15
|
export const bundler = {
|
|
15
16
|
async build({ input, modules, }) {
|
|
17
|
+
if (!isModules(modules)) {
|
|
18
|
+
throw new Error(`The modules aren't { specifier: version }: ${JSON.stringify(modules)?.slice(0, 80)}`);
|
|
19
|
+
}
|
|
16
20
|
// Scripts come compiled for their framework when their host was built, so
|
|
17
21
|
// the bundle is only put together: nothing is compiled or parsed here.
|
|
18
22
|
const tree = await buildBundle(input, modules);
|
package/dist/bundler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
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,CAAC;YACxB,MAAM,IAAI,KAAK,CACb,8CAA8C,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CACtF,CAAC;QACJ,CAAC;QACD,0EAA0E;QAC1E,uEAAuE;QACvE,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/C,OAAO;YACL,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,GAAG,KAAK,EAAE,EAAE,EAAE;gBAC1C,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,IAA0B,CAAC;gBAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;gBACxB,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;oBACxB,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;gBAC7B,CAAC;gBACD,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;oBAC3B,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;gBACvB,CAAC;gBACD,MAAM,GAAG,GAAG,uCAAuC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC7E,OAAO;oBACL,IAAI,EAAE,GAAG,IAAI,0BAA0B,GAAG,EAAwB;oBAClE,GAAG;iBACJ,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/dist/modules.d.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* the package it comes from: `{ "react/jsx-runtime": "19.2.3" }`.
|
|
4
4
|
*/
|
|
5
5
|
export type Modules = Readonly<Record<string, string>>;
|
|
6
|
+
/**
|
|
7
|
+
* Whether `value` is `Modules`: often what a client sent, parsed as it came.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isModules(value: unknown): value is Modules;
|
|
6
10
|
/**
|
|
7
11
|
* Whether a client with `modules` provides `specifier` at a version in
|
|
8
12
|
* `range`: the check a bundle's every import passes, so a server choosing
|
package/dist/modules.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import semver from "semver";
|
|
2
|
+
/**
|
|
3
|
+
* Whether `value` is `Modules`: often what a client sent, parsed as it came.
|
|
4
|
+
*/
|
|
5
|
+
export function isModules(value) {
|
|
6
|
+
return (typeof value === "object" &&
|
|
7
|
+
value !== null &&
|
|
8
|
+
!Array.isArray(value) &&
|
|
9
|
+
Object.values(value).every((version) => typeof version === "string"));
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
12
|
* Whether a client with `modules` provides `specifier` at a version in
|
|
4
13
|
* `range`: the check a bundle's every import passes, so a server choosing
|
package/dist/modules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAQ5B;;;;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":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backtickjs/bundler",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
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.
|
|
42
|
+
"@backtickjs/core": "^0.2.1",
|
|
43
43
|
"semver": "^7.8.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
package/src/bundler.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Bundle, Spliceable, Spliced, SplicesAs } from "@backtickjs/core";
|
|
2
2
|
import { buildBundle } from "./bundle/buildBundle.js";
|
|
3
|
-
import type
|
|
3
|
+
import { isModules, type Modules } from "./modules.js";
|
|
4
4
|
import { printBundle } from "./print/printBundle.js";
|
|
5
5
|
|
|
6
6
|
export interface BuildOptions<T = Spliceable> {
|
|
@@ -54,6 +54,11 @@ export const bundler = {
|
|
|
54
54
|
input,
|
|
55
55
|
modules,
|
|
56
56
|
}: BuildOptions<T>): Promise<Build<Spliced<T>>> {
|
|
57
|
+
if (!isModules(modules)) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`The modules aren't { specifier: version }: ${JSON.stringify(modules)?.slice(0, 80)}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
57
62
|
// Scripts come compiled for their framework when their host was built, so
|
|
58
63
|
// the bundle is only put together: nothing is compiled or parsed here.
|
|
59
64
|
const tree = await buildBundle(input, modules);
|
package/src/modules.ts
CHANGED
|
@@ -6,6 +6,18 @@ import semver from "semver";
|
|
|
6
6
|
*/
|
|
7
7
|
export type Modules = Readonly<Record<string, string>>;
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Whether `value` is `Modules`: often what a client sent, parsed as it came.
|
|
11
|
+
*/
|
|
12
|
+
export function isModules(value: unknown): value is Modules {
|
|
13
|
+
return (
|
|
14
|
+
typeof value === "object" &&
|
|
15
|
+
value !== null &&
|
|
16
|
+
!Array.isArray(value) &&
|
|
17
|
+
Object.values(value).every((version) => typeof version === "string")
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
9
21
|
/**
|
|
10
22
|
* Whether a client with `modules` provides `specifier` at a version in
|
|
11
23
|
* `range`: the check a bundle's every import passes, so a server choosing
|