@pix3/vite-plugin 0.0.0-stage → 2.0.0-alpha.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.
- package/LICENSE +201 -0
- package/README.md +38 -3
- package/dist/build/bundle-hooks.d.ts +23 -0
- package/dist/build/bundle-hooks.js +79 -0
- package/dist/build/classic-script.d.ts +11 -0
- package/dist/build/classic-script.js +46 -0
- package/dist/build/compress.d.ts +29 -0
- package/dist/build/compress.js +63 -0
- package/dist/build/dependency-imports.d.ts +53 -0
- package/dist/build/dependency-imports.js +239 -0
- package/dist/build/dev-manifest.d.ts +10 -0
- package/dist/build/dev-manifest.js +25 -0
- package/dist/build/editor-flush.d.ts +42 -0
- package/dist/build/editor-flush.js +91 -0
- package/dist/build/finish.d.ts +11 -0
- package/dist/build/finish.js +126 -0
- package/dist/build/output-plugins.d.ts +26 -0
- package/dist/build/output-plugins.js +88 -0
- package/dist/build/plan.d.ts +75 -0
- package/dist/build/plan.js +162 -0
- package/dist/build/player-modules.d.ts +99 -0
- package/dist/build/player-modules.js +204 -0
- package/dist/build/project-manifest.d.ts +57 -0
- package/dist/build/project-manifest.js +169 -0
- package/dist/build/record.d.ts +25 -0
- package/dist/build/record.js +14 -0
- package/dist/build/report.d.ts +114 -0
- package/dist/build/report.js +102 -0
- package/dist/build/scan.d.ts +84 -0
- package/dist/build/scan.js +375 -0
- package/dist/build/strip-decision.d.ts +27 -0
- package/dist/build/strip-decision.js +82 -0
- package/dist/build/strippable-runtime-modules.d.ts +85 -0
- package/dist/build/strippable-runtime-modules.js +309 -0
- package/dist/build/zip.d.ts +6 -0
- package/dist/build/zip.js +28 -0
- package/dist/client/host-files.d.ts +96 -0
- package/dist/client/host-files.js +169 -0
- package/dist/client/index.d.ts +218 -0
- package/dist/client/index.js +381 -0
- package/dist/dev-info.d.ts +55 -0
- package/dist/dev-info.js +116 -0
- package/dist/dev-server.d.ts +28 -0
- package/dist/dev-server.js +139 -0
- package/dist/editor-page.d.ts +31 -0
- package/dist/editor-page.js +74 -0
- package/dist/files/changeset.d.ts +84 -0
- package/dist/files/changeset.js +321 -0
- package/dist/files/content-type.d.ts +1 -0
- package/dist/files/content-type.js +56 -0
- package/dist/files/history.d.ts +67 -0
- package/dist/files/history.js +162 -0
- package/dist/files/paths.d.ts +41 -0
- package/dist/files/paths.js +144 -0
- package/dist/files/project-files.d.ts +208 -0
- package/dist/files/project-files.js +1062 -0
- package/dist/files/scan.d.ts +71 -0
- package/dist/files/scan.js +252 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +278 -0
- package/dist/module-paths.d.ts +13 -0
- package/dist/module-paths.js +32 -0
- package/dist/player/index.d.ts +31 -0
- package/dist/player/index.js +102 -0
- package/dist/server/editor-socket.d.ts +53 -0
- package/dist/server/editor-socket.js +134 -0
- package/dist/server/guard.d.ts +61 -0
- package/dist/server/guard.js +165 -0
- package/dist/server/http.d.ts +24 -0
- package/dist/server/http.js +70 -0
- package/dist/server/image-keys.d.ts +46 -0
- package/dist/server/image-keys.js +118 -0
- package/dist/server/image-proxy.d.ts +32 -0
- package/dist/server/image-proxy.js +124 -0
- package/dist/server/router.d.ts +54 -0
- package/dist/server/router.js +147 -0
- package/dist/sync/barrier.d.ts +69 -0
- package/dist/sync/barrier.js +240 -0
- package/dist/sync/hot-update.d.ts +16 -0
- package/dist/sync/hot-update.js +58 -0
- package/dist/sync/script-graph.d.ts +79 -0
- package/dist/sync/script-graph.js +214 -0
- package/dist/vite-config.d.ts +12 -0
- package/dist/vite-config.js +62 -0
- package/package.json +60 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Igor Gritsenko
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @pix3/vite-plugin
|
|
2
|
+
|
|
3
|
+
`pix3({ resRoot = '.', editor = true, build = 'html' | 'zip' | false, strip = true | false | { keep }, entryScene, compress = false, allowRemote = false, imageGen: { home, upstreams } })` — serves the Pix3 editor at `/__pix3/` on the project's Vite dev server, with the file API (`/__pix3/api/*`), the sync barrier, `virtual:pix3/*` modules, the player and the playable build. Design: plan `pix3/.plans/pix3-core.md` §B; the record of the player/build port is `.plans/player-build.md`. `pix3()` returns a plugin array (`plugins: [pix3()]`).
|
|
4
|
+
|
|
5
|
+
Source layout: `src/index.ts` wires the hooks; `src/vite-config.ts` (the `config` hook), `src/dev-server.ts` (`configureServer`: file API, socket, barrier, image-gen proxy, `.pix3/dev.json`), `src/server/` (routes, guard), `src/files/` (the file table, changesets, the journal), `src/sync/` (script graph, barrier, `hotUpdate`), `src/build/` (`plan.ts` — flush, scan and strip decision in `buildStart`; `bundle-hooks.ts`, `output-plugins.ts`, `finish.ts` — report and record), `src/client/` (the page's `EditorHost`), `player/`.
|
|
6
|
+
|
|
7
|
+
## Player
|
|
8
|
+
|
|
9
|
+
`src/main.ts` of a project is `import { startGame } from '@pix3/vite-plugin/player'; startGame('#app');`. The player (`player/index.ts`, emitted to `dist/player/`) boots `@pix3/runtime` on the `virtual:pix3/*` modules the plugin generates: `scene-manifest` (from `pix3project.yaml`: entry scene, scene list, viewport, quality, fonts, locales), `embedded-assets` (`{}` in dev and zip, every asset as base64 in an html build), `project-scripts` (eager glob of `scripts/` and `src/scripts/`, registered as `user:<Export>`), `spine` / `postprocessing` / `network` (static imports in a build that uses them, no-ops otherwise). The entry scene is `pix3({ entryScene })`, else `defaultExportScenePath`, else `scenes/main.pix3scene`, else the first non-prefab scene, in dev and in a build alike (one function, `resolveEntryScene` in `src/build/scan.ts`; a named scene that does not exist is skipped with a warning). In dev `ResourceManager('/<resRoot>/')` fetches from the dev server; a build uses `./`. `window.__PIX3_PLAYER__ = { status, frames, errors, scene, runner }` is what a check reads.
|
|
10
|
+
|
|
11
|
+
## Build (`vite build`)
|
|
12
|
+
|
|
13
|
+
- `build: 'html'` (default): one self-contained `dist/index.html` — `vite-plugin-singlefile`, then DeepCore's classic-script rewrite (no `type="module"`, script at the end of `<body>`, no `import.meta`), so it runs from `file://` and inside a sandboxed iframe. `build: 'zip'`: the plain build with the assets beside `index.html` under their `res://` paths, archived to `dist/<projectName>.zip` (`fflate`) — for hosting: its `index.html` is a module script that loads chunks and fetches assets, which `file://` refuses. `build: false`: `vite build` is left alone (the player's modules still generate).
|
|
14
|
+
- `compress: true` (html only): the bundle is built as an `iife`, gzip'd and base64'd into the page behind a bootstrap that inflates it with `DecompressionStream` and injects the text as a classic `<script>` (`src/build/compress.ts`; never a blob/`data:` URL or `eval`, which sandboxed containers refuse). About two thirds off the file (the budget ad networks measure); over a gzip channel it is a wash, over brotli +21% — CLAUDE.md «Playable export size». Needs Chrome 80+ / Safari 16.4+ / Firefox 113+.
|
|
15
|
+
- `buildStart` scans every text source outside `node_modules`/`dist`/`.pix3` (`src/build/scan.ts`; `.vue`/`.svelte`/`.astro` included), plus every source of a dependency that declares `@pix3/runtime`: `mentionedNames`, the import specifiers, the asset set (every scene and prefab, `res://` references, directories, Spine atlas pages, declared locale tables and their sprites, manifest fonts), and whether Spine / `postprocessing` (a `PostProcess` node, or an `import` of the package) / the network are used.
|
|
16
|
+
- Strip (`src/build/strippable-runtime-modules.ts`): runtime modules nothing mentions — neither a keep-name of the table nor any of the module's value exports (`pointInPolygon` keeps `collision-shapes-2d`) — are replaced by throwing stubs in the `load` hook (module ids compared by real path, so `resolve.preserveSymlinks` changes nothing). For the runtime's own importers only, `postprocessing` resolves to a stub in an html build with no `PostProcess` node and no import of it; `three/examples/jsm/loaders/GLTFLoader.js` to a stub when no scene, script, library or asset names a `.glb`/`.gltf` (any case); and `yaml` to `{ parse: JSON.parse }` while every scene and prefab ships as JSON (`src/build/player-modules.ts`; a project module or a dependency importing any of the three itself gets the real one, and JSON is YAML). On by default; `strip: false` keeps everything, `strip: true` strips regardless of dependencies. The table is guarded by `strippable-runtime-modules.spec.ts` against the runtime's import graph.
|
|
17
|
+
- Dependencies that import the runtime (N11, `src/build/dependency-imports.ts`): every project dependency that declares `@pix3/runtime` is parsed before the strip decision (the bundler's `this.parse`, TypeScript lowered with Vite's own transform) and its named imports keep their modules. `import * as`, a dynamic `import('@pix3/runtime')`, `export *`, `require` or a parse error is opaque: strip goes off with a message naming `pix3({ strip: { keep: ['GeometryMesh', …] } })`, which names what the library uses and keeps strip on. A `transform`-hook net checks every `node_modules` module the bundle pulls in (a transitive or undeclared dependency): a named import of a stripped module fails the build with the same fix.
|
|
18
|
+
- Before reading the disk, a build asks the dev server named by `.pix3/dev.json` to flush the editor's unsaved scenes (`POST /__pix3/api/flush`, 15 s); a live editor that cannot flush, or a server that accepts the connection but does not answer `hello` within 2 s, fails the build with `E_EDITOR_UNSYNCED`; a refused connection is a stale `dev.json` (logged); `PIX3_NO_SYNC=1` skips it (as `pix3 check --no-sync` does).
|
|
19
|
+
- Vite 7 and 8: single-chunk output is `inlineDynamicImports` (rollup) or `codeSplitting: false` (rolldown), chosen by `this.meta.rolldownVersion`; stable hooks only.
|
|
20
|
+
- The result is recorded in `.pix3/build.json` (format, path, bytes, sha256, entry scene, assets, stripped modules, warnings, the report's path) and explained in `dist/<name>.report.json` beside the artifact (`src/build/report.ts`): bytes and gzip bytes of the artifact, the compression numbers, code by group (`three`, `runtime`, `player`, `project`, `assets`, `dependencies` by package — rendered bytes per the bundler's module map and an estimate of each group's minified share), the largest modules, the strip decision with what the dependencies import, how each optional library was resolved (`yaml`, `GLTFLoader`, `postprocessing`, `spine`, `network`), every embedded asset with raw and base64 bytes. The answer to "why is it this big" without a rebuild.
|
|
21
|
+
- The build is run by whoever owns the terminal (`npm run build` — the coding agent, the user, CI), never from the editor: the dev server has no build route (owner decision 2026-10-10, `.plans/player-build.md`).
|
|
22
|
+
- Not yet: WebP re-encoding of embedded images (optional `sharp`, P2+). Not at all: the 1.x `pix3project.yaml` `export:` block (no build reads it; `pix3 validate` warns `W_MANIFEST_EXPORT`) and a pre-packed `assets/.atlas/` (nothing in 2.x writes one; the player does not probe for it).
|
|
23
|
+
|
|
24
|
+
Done (P1, dev side):
|
|
25
|
+
|
|
26
|
+
- editor page at `/__pix3/` as raw HTML (variant B: no `/@vite/client`), own WebSocket `/__pix3/ws`;
|
|
27
|
+
- file API ported from `packages/cli/src/serve/` without token/lease: `file` GET/HEAD/PUT with sha256 ETag, `If-Match` → 412, `manifest`, `hash`, `mkdir|delete|move`, `X-Mutation-Id` replay, `hello`;
|
|
28
|
+
- write guard: Host check (`localhost`, a literal 127.0.0.0/8 / `::1` address, `server.allowedHosts`, and any IP literal under `allowRemote`), loopback peers unless `allowRemote`, `X-Pix3: 1` + own `Origin` for mutations and the socket;
|
|
29
|
+
- writer hand-over `handover/claim` under the write mutex, `409 writer_superseded`;
|
|
30
|
+
- changeset `POST /__pix3/api/changeset` (plan §C.4): several files as one transaction under the same mutex — preflight of every `If-Match`/`createOnly` (412 names the file), staging in `.pix3/tx/<id>/{new,old}/<n>` + `intent.json` with fsync, renames, one `pix3:fs` frame; a failed rename rolls back from `old/`, a crash is rolled forward (complete staging) or back at the next start;
|
|
31
|
+
- version journal `.pix3/history/<path>/{index.jsonl,<stamp>-<hash8>}` for `*.pix3scene`, `*.prefab`, `pix3project.yaml` (200 versions / 7 days per path, the newest always kept): authors `editor` (PUT, changeset), `external` (watcher, rescans, a start-up snapshot of what changed while no server ran), `restore`, `rejected-draft` (posted by any tab); routes `history`, `history/version`, `history/record`, `history/restore` (a restore is broadcast as `external`, so the editor follows it like an agent's change);
|
|
32
|
+
- `pix3:fs` events (two scans 300 ms apart, `author: editor|external`);
|
|
33
|
+
- sync barrier `POST /__pix3/api/sync` (rescan → hard-invalidate roots → `environment.reloadModule` → page ack with executed-content stamps), `POST /__pix3/api/flush`;
|
|
34
|
+
- `virtual:pix3/{editor-host,editor-scripts,bot-policies,spine-loader}`; `.pix3/dev.json`; version gate;
|
|
35
|
+
- image-generation keys and proxy (plan §B.1, `src/server/image-{keys,proxy}.ts`): `GET|PUT /__pix3/api/keys` (status `{set, last4?}` per provider; a key is written, never read back) and `POST /__pix3/api/proxy/{gemini,openai}/…` (only `v1beta/models/<m>:generateContent` and `v1/images/{generations,edits}`; the plugin adds `x-goog-api-key` / `Authorization: Bearer`, drops whatever credential the page sent, replaces the key by `[key]` should an upstream echo it, and logs provider, path, status and size only). Keys live in `~/.pix3/keys.json` (`PIX3_HOME`; 0600 in a 0700 directory), or `.pix3/local/keys.json` when the home refuses the write; no URL with a `.pix3` segment is served (root, `/@fs/`, any spelling). Both routes answer the editor page only: `X-Pix3: 1`, own `Origin`, `Sec-Fetch-Site: same-origin`, a `Referer` under `/__pix3/` and `X-Pix3-Session` — a per-server token embedded in the editor page only for a top-level navigation (`Sec-Fetch-Dest: document`; the game's `fetch('/__pix3/')` or an iframe gets none), read and removed by the page client; the page is served with `Cross-Origin-Opener-Policy: same-origin-allow-popups`, so a `window.open` from the game gets no handle into it. `imageGen.upstreams` / `PIX3_PROXY_{GEMINI,OPENAI}_URL` point the proxy at a mock;
|
|
36
|
+
- the page client is the editor's `EditorHost` (`src/client/`, conformance in `host-contract.spec.ts`); `/__pix3/editor.css` and `optimizeDeps.include` come from the installed `@pix3/editor-core/dist`.
|
|
37
|
+
|
|
38
|
+
Specs: `src/plugin.spec.ts`, `src/server/image-proxy.spec.ts` (keys and proxy against a local upstream), `src/files/changeset.spec.ts`, `src/files/history.spec.ts` (real Vite on a free port, fake tab over the socket; crash/recovery cases drive `ProjectFiles` directly with its `faults` hook); `src/build/build.spec.ts` (a real `vite build` of the inline fixture in `src/test-support/build-fixture.ts`: html, zip, `build: false`, strip, `compress`, the report, the yaml/GLTFLoader stubs, the N11 libraries — named import kept, `import * as` turns strip off with the message, an undeclared dependency fails the build), `src/build/dependency-imports.spec.ts`, `src/build/scan.spec.ts`, `src/build/strippable-runtime-modules.spec.ts`. The artifact itself is checked in headless Chrome by `../pix3-core-spikes/build-check/run.mjs` (`vite preview`, `file://`, a sandboxed iframe; `--compress`, `--vite 7|8`, `--lib named|namespace`).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Rollup } from 'vite';
|
|
2
|
+
import { type BuildState } from './plan.ts';
|
|
3
|
+
/** Every chunk's per-module rendered sizes, for the report. */
|
|
4
|
+
export declare const recordModuleSizes: (build: BuildState, bundle: Rollup.OutputBundle) => void;
|
|
5
|
+
/** `build: 'zip'`: every asset beside `index.html`, under its `res://` path. */
|
|
6
|
+
export declare const emitZipAssets: (build: BuildState, options: {
|
|
7
|
+
readonly root: string;
|
|
8
|
+
readonly resRoot: string;
|
|
9
|
+
readonly emit: (fileName: string, source: Buffer) => void;
|
|
10
|
+
readonly warn: (line: string) => void;
|
|
11
|
+
}) => void;
|
|
12
|
+
/**
|
|
13
|
+
* The N11 safety net (`transform`): a `node_modules` module the bundle pulls in (a transitive
|
|
14
|
+
* dependency, one that does not declare the runtime) or a file outside the project importing
|
|
15
|
+
* something this build stripped. Returns the error to raise, or null; a forced strip only warns.
|
|
16
|
+
*/
|
|
17
|
+
export declare const strippedImportError: (build: BuildState, code: string, id: string, options: {
|
|
18
|
+
readonly root: string;
|
|
19
|
+
readonly packageDir: string;
|
|
20
|
+
readonly forced: boolean;
|
|
21
|
+
readonly parse: (code: string) => unknown;
|
|
22
|
+
readonly warn: (line: string) => void;
|
|
23
|
+
}) => string | null;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { isUnder, realFileOf } from "../module-paths.js";
|
|
3
|
+
import { collectRuntimeImports, RUNTIME_SPECIFIER } from "./dependency-imports.js";
|
|
4
|
+
import { shippedBytes } from "./plan.js";
|
|
5
|
+
import { largestFirst } from "./player-modules.js";
|
|
6
|
+
import { resToAbsolute } from "./project-manifest.js";
|
|
7
|
+
import { classifyModule, displayId } from "./report.js";
|
|
8
|
+
import { KEEP_HINT } from "./strip-decision.js";
|
|
9
|
+
/** Every chunk's per-module rendered sizes, for the report. */
|
|
10
|
+
export const recordModuleSizes = (build, bundle) => {
|
|
11
|
+
for (const output of Object.values(bundle)) {
|
|
12
|
+
if (output.type !== 'chunk')
|
|
13
|
+
continue;
|
|
14
|
+
build.bundleBytes += Buffer.byteLength(output.code, 'utf8');
|
|
15
|
+
for (const [id, rendered] of Object.entries(output.modules)) {
|
|
16
|
+
const { group, package: pkg } = classifyModule(id, build.classifier);
|
|
17
|
+
build.moduleSizes.push({
|
|
18
|
+
id: displayId(id, build.classifier),
|
|
19
|
+
group,
|
|
20
|
+
package: pkg,
|
|
21
|
+
renderedBytes: rendered.renderedLength,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/** `build: 'zip'`: every asset beside `index.html`, under its `res://` path. */
|
|
27
|
+
export const emitZipAssets = (build, options) => {
|
|
28
|
+
const entries = [];
|
|
29
|
+
for (const resPath of build.scan.assetPaths) {
|
|
30
|
+
const file = readFileSync(resToAbsolute(options.root, options.resRoot, resPath));
|
|
31
|
+
const source = shippedBytes(build, resPath, file, options.warn);
|
|
32
|
+
entries.push({ path: resPath, rawBytes: source.byteLength, base64Bytes: 0 });
|
|
33
|
+
options.emit(resPath, source);
|
|
34
|
+
}
|
|
35
|
+
build.assets = {
|
|
36
|
+
source: '',
|
|
37
|
+
count: entries.length,
|
|
38
|
+
rawBytes: entries.reduce((sum, entry) => sum + entry.rawBytes, 0),
|
|
39
|
+
base64Bytes: 0,
|
|
40
|
+
entries: entries.sort(largestFirst),
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The N11 safety net (`transform`): a `node_modules` module the bundle pulls in (a transitive
|
|
45
|
+
* dependency, one that does not declare the runtime) or a file outside the project importing
|
|
46
|
+
* something this build stripped. Returns the error to raise, or null; a forced strip only warns.
|
|
47
|
+
*/
|
|
48
|
+
export const strippedImportError = (build, code, id, options) => {
|
|
49
|
+
if (!build.stripEnabled || id.startsWith('\0') || !code.includes(RUNTIME_SPECIFIER))
|
|
50
|
+
return null;
|
|
51
|
+
const file = realFileOf(id);
|
|
52
|
+
if (isUnder(file, build.runtimeSrc) || isUnder(file, realFileOf(options.packageDir)))
|
|
53
|
+
return null;
|
|
54
|
+
if (!id.includes('/node_modules/') && isUnder(file, realFileOf(options.root)))
|
|
55
|
+
return null;
|
|
56
|
+
const label = displayId(id, build.classifier);
|
|
57
|
+
let findings;
|
|
58
|
+
try {
|
|
59
|
+
findings = collectRuntimeImports(options.parse(code), label);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null; // not JS the bundler can parse here (it will say so itself)
|
|
63
|
+
}
|
|
64
|
+
const hits = [...findings.names].filter(name => build.stubbedNames.has(name)).sort();
|
|
65
|
+
if (hits.length > 0) {
|
|
66
|
+
const message = `${label} imports ${hits.join(', ')} from ${RUNTIME_SPECIFIER}, which this build ` +
|
|
67
|
+
`stripped (nothing in the project mentions ${hits.length > 1 ? 'them' : 'it'}). ` +
|
|
68
|
+
`Add ${hits.map(name => `'${name}'`).join(', ')} to pix3({ strip: { keep } })` +
|
|
69
|
+
(options.forced ? '' : ', or pass strip: false');
|
|
70
|
+
if (!options.forced)
|
|
71
|
+
return message;
|
|
72
|
+
options.warn(message);
|
|
73
|
+
}
|
|
74
|
+
if (findings.opaque.length > 0 && !build.stripConfigured) {
|
|
75
|
+
return (`${findings.opaque[0]} — the build cannot see which runtime modules it reaches. ` +
|
|
76
|
+
`Name them with ${KEEP_HINT}, or pass strip: false`);
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite a single-file build's HTML so it runs as a classic script (port of DeepCore's
|
|
3
|
+
* `classicScriptCompatibilityPlugin`, plan §B.6 item 5). Playables run inside sandboxed /
|
|
4
|
+
* opaque-origin iframes and MRAID webviews, where a `<script type="module">` with `crossorigin`
|
|
5
|
+
* is refused or deferred past the point the container expects a frame: the inlined module tag
|
|
6
|
+
* becomes a plain `<script>` at the end of `<body>` (so `#app` exists when it runs), and the
|
|
7
|
+
* ESM-only expressions a bundle may carry are rewritten: `import.meta.url` becomes
|
|
8
|
+
* `document.baseURI`, `import.meta.resolve` (Vite 8's preload helper probes it) `undefined`, and
|
|
9
|
+
* any other `import.meta` an empty object — a classic script cannot even parse `import.meta`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const toClassicScriptHtml: (html: string) => string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite a single-file build's HTML so it runs as a classic script (port of DeepCore's
|
|
3
|
+
* `classicScriptCompatibilityPlugin`, plan §B.6 item 5). Playables run inside sandboxed /
|
|
4
|
+
* opaque-origin iframes and MRAID webviews, where a `<script type="module">` with `crossorigin`
|
|
5
|
+
* is refused or deferred past the point the container expects a frame: the inlined module tag
|
|
6
|
+
* becomes a plain `<script>` at the end of `<body>` (so `#app` exists when it runs), and the
|
|
7
|
+
* ESM-only expressions a bundle may carry are rewritten: `import.meta.url` becomes
|
|
8
|
+
* `document.baseURI`, `import.meta.resolve` (Vite 8's preload helper probes it) `undefined`, and
|
|
9
|
+
* any other `import.meta` an empty object — a classic script cannot even parse `import.meta`.
|
|
10
|
+
*/
|
|
11
|
+
export const toClassicScriptHtml = (html) => {
|
|
12
|
+
let out = html
|
|
13
|
+
.replace(/<script\b([^>]*)>/gi, (_match, attrs) => {
|
|
14
|
+
const cleaned = attrs
|
|
15
|
+
.replace(/\s+type=(['"])module\1/gi, '')
|
|
16
|
+
.replace(/\s+crossorigin(?:=(['"]).*?\1)?/gi, '');
|
|
17
|
+
return `<script${cleaned}>`;
|
|
18
|
+
})
|
|
19
|
+
.replace(/\bimport\.meta\.url\b/g, 'document.baseURI')
|
|
20
|
+
.replace(/\bimport\.meta\.resolve\b/g, 'undefined')
|
|
21
|
+
.replace(/\bimport\.meta\b/g, '({})');
|
|
22
|
+
const headOpen = /<head\b[^>]*>/i.exec(out);
|
|
23
|
+
const headClose = /<\/head>/i.exec(out);
|
|
24
|
+
const bodyOpen = /<body\b[^>]*>/i.exec(out);
|
|
25
|
+
if (!headOpen || !headClose || !bodyOpen)
|
|
26
|
+
return out;
|
|
27
|
+
const headStart = headOpen.index + headOpen[0].length;
|
|
28
|
+
const headEnd = headClose.index;
|
|
29
|
+
const bodyClose = out.toLowerCase().indexOf('</body>', bodyOpen.index + bodyOpen[0].length);
|
|
30
|
+
if (bodyClose < 0)
|
|
31
|
+
throw new Error('Failed to locate </body> while rewriting classic script output.');
|
|
32
|
+
const headContent = out.slice(headStart, headEnd);
|
|
33
|
+
const headScripts = headContent.match(/<script\b[\s\S]*?<\/script>/gi) ?? [];
|
|
34
|
+
if (headScripts.length === 0)
|
|
35
|
+
return out;
|
|
36
|
+
let nextHead = headContent;
|
|
37
|
+
for (const tag of headScripts)
|
|
38
|
+
nextHead = nextHead.replace(tag, '');
|
|
39
|
+
out =
|
|
40
|
+
out.slice(0, headStart) +
|
|
41
|
+
nextHead +
|
|
42
|
+
out.slice(headEnd, bodyClose) +
|
|
43
|
+
`${headScripts.join('\n')}\n` +
|
|
44
|
+
out.slice(bodyClose);
|
|
45
|
+
return out;
|
|
46
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pix3({ compress: true })` (plan §B.6 item 5; port of the 1.x `renderCompressedHtmlDocument`):
|
|
3
|
+
* the single-file page's bundle — already one classic script at the end of `<body>` — is gzip'd,
|
|
4
|
+
* base64'd and replaced by a bootstrap that inflates it with `DecompressionStream` and runs it by
|
|
5
|
+
* injecting the text as a classic `<script>`'s `textContent`.
|
|
6
|
+
*
|
|
7
|
+
* Deliberately not a blob URL, a `data:` URL, `eval` or `new Function`: playables run inside
|
|
8
|
+
* sandboxed / opaque-origin iframes and MRAID webviews, where module and blob fetches and
|
|
9
|
+
* `unsafe-eval` are what gets refused; injected script text needs nothing the bootstrap itself
|
|
10
|
+
* did not already need. The bundle is built as `iife` so the injected text declares nothing in
|
|
11
|
+
* the page's global scope. base64's alphabet has no `<`, so the payload cannot contain
|
|
12
|
+
* `</script>`.
|
|
13
|
+
*
|
|
14
|
+
* What it buys and costs is measured in CLAUDE.md «Playable export size»: the file shrinks by
|
|
15
|
+
* about two thirds (the budget ad networks measure); over a gzip channel it is a wash, over
|
|
16
|
+
* brotli +21%.
|
|
17
|
+
*/
|
|
18
|
+
export interface CompressedHtml {
|
|
19
|
+
readonly html: string;
|
|
20
|
+
/** The script text that was compressed (UTF-8 bytes). */
|
|
21
|
+
readonly bundleBytes: number;
|
|
22
|
+
/** The gzip payload before base64. */
|
|
23
|
+
readonly gzipBytes: number;
|
|
24
|
+
/** The base64 text embedded in the page. */
|
|
25
|
+
readonly base64Bytes: number;
|
|
26
|
+
}
|
|
27
|
+
export declare const bootstrapScript: (base64: string) => string;
|
|
28
|
+
/** Replace the page's bundle script by the gzip payload and its bootstrap. */
|
|
29
|
+
export declare const toCompressedHtml: (html: string) => CompressedHtml;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { gzipSync } from 'node:zlib';
|
|
2
|
+
const BUNDLE_SCRIPT = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
3
|
+
/** The inline script that carries the bundle: the largest one with no `src`. */
|
|
4
|
+
const findBundleScript = (html) => {
|
|
5
|
+
let best = null;
|
|
6
|
+
for (const match of html.matchAll(BUNDLE_SCRIPT)) {
|
|
7
|
+
if (/\bsrc\s*=/i.test(match[1]))
|
|
8
|
+
continue;
|
|
9
|
+
if (!best || match[2].length > best[2].length)
|
|
10
|
+
best = match;
|
|
11
|
+
}
|
|
12
|
+
return best;
|
|
13
|
+
};
|
|
14
|
+
export const bootstrapScript = (base64) => [
|
|
15
|
+
'(function () {',
|
|
16
|
+
` var payload = "${base64}";`,
|
|
17
|
+
' function fail(message) {',
|
|
18
|
+
" var box = document.createElement('pre');",
|
|
19
|
+
" box.id = 'pix3-boot-error';",
|
|
20
|
+
" box.style.cssText = 'color:#eee;font:14px/1.5 monospace;padding:16px;white-space:pre-wrap';",
|
|
21
|
+
' box.textContent = message;',
|
|
22
|
+
' document.body.appendChild(box);',
|
|
23
|
+
" if (window.__PIX3_PLAYER__) { window.__PIX3_PLAYER__.status = 'failed'; window.__PIX3_PLAYER__.errors.push(message); }",
|
|
24
|
+
' }',
|
|
25
|
+
" if (typeof DecompressionStream !== 'function') {",
|
|
26
|
+
" fail('This build is gzip-compressed and needs a browser with DecompressionStream ' +",
|
|
27
|
+
" '(Chrome 80+, Safari 16.4+, Firefox 113+). Build without pix3({ compress }) ' +",
|
|
28
|
+
" 'to support older browsers.');",
|
|
29
|
+
' return;',
|
|
30
|
+
' }',
|
|
31
|
+
' try {',
|
|
32
|
+
' var binary = atob(payload);',
|
|
33
|
+
' var bytes = new Uint8Array(binary.length);',
|
|
34
|
+
' for (var i = 0; i < binary.length; i++) { bytes[i] = binary.charCodeAt(i); }',
|
|
35
|
+
" var stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'));",
|
|
36
|
+
' new Response(stream).text().then(function (code) {',
|
|
37
|
+
" var script = document.createElement('script');",
|
|
38
|
+
' script.textContent = code;',
|
|
39
|
+
' document.body.appendChild(script);',
|
|
40
|
+
' }).catch(function (error) {',
|
|
41
|
+
" fail('Failed to unpack the game bundle: ' + error);",
|
|
42
|
+
' });',
|
|
43
|
+
' } catch (error) {',
|
|
44
|
+
" fail('Failed to unpack the game bundle: ' + error);",
|
|
45
|
+
' }',
|
|
46
|
+
'})();',
|
|
47
|
+
].join('\n');
|
|
48
|
+
/** Replace the page's bundle script by the gzip payload and its bootstrap. */
|
|
49
|
+
export const toCompressedHtml = (html) => {
|
|
50
|
+
const script = findBundleScript(html);
|
|
51
|
+
if (!script)
|
|
52
|
+
throw new Error('compress: no inline bundle script found in index.html');
|
|
53
|
+
const code = script[2];
|
|
54
|
+
const gzip = gzipSync(Buffer.from(code, 'utf8'), { level: 9 });
|
|
55
|
+
const base64 = gzip.toString('base64');
|
|
56
|
+
const replaced = `<script>\n${bootstrapScript(base64)}\n</script>`;
|
|
57
|
+
return {
|
|
58
|
+
html: html.slice(0, script.index) + replaced + html.slice(script.index + script[0].length),
|
|
59
|
+
bundleBytes: Buffer.byteLength(code, 'utf8'),
|
|
60
|
+
gzipBytes: gzip.byteLength,
|
|
61
|
+
base64Bytes: base64.length,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type SourceMentions } from './scan.ts';
|
|
2
|
+
/**
|
|
3
|
+
* N11 (plan §B.6 item 2): what a project dependency imports from `@pix3/runtime`. The scan of
|
|
4
|
+
* `mentionedNames` reads the project's own text sources, never `node_modules`, so a library with
|
|
5
|
+
* `import { GeometryMesh } from '@pix3/runtime'` would otherwise get the stub — the barrel
|
|
6
|
+
* re-exports it and the stub's importer is internal. Every package the project depends on that
|
|
7
|
+
* itself declares `@pix3/runtime` is parsed here before the build decides what to strip:
|
|
8
|
+
*
|
|
9
|
+
* - a named import (or `export { X } from`) adds `X` to the names that keep modules;
|
|
10
|
+
* - `import * as`, a dynamic `import('@pix3/runtime')`, `export * from`, `require(…)` or a file
|
|
11
|
+
* that does not parse is **opaque**: the build cannot see which modules the package reaches,
|
|
12
|
+
* so strip goes off with a message naming `pix3({ strip: { keep } })`.
|
|
13
|
+
*
|
|
14
|
+
* The AST comes from the bundler's own parser (`this.parse` in a hook; `parseAst` in a spec).
|
|
15
|
+
* TypeScript sources (a workspace package, a library shipping `.ts`) are lowered to JS first
|
|
16
|
+
* with Vite's own transform (`transformWithOxc` under Vite 8, `transformWithEsbuild` under 7).
|
|
17
|
+
* A `transform`-hook safety net in the plugin runs the same walk over every `node_modules`
|
|
18
|
+
* module the bundle actually pulls in, for packages this pre-scan did not know about.
|
|
19
|
+
*/
|
|
20
|
+
export declare const RUNTIME_SPECIFIER = "@pix3/runtime";
|
|
21
|
+
export interface RuntimeImportFindings {
|
|
22
|
+
/** Named imports of the runtime barrel: the identifiers that keep modules in the bundle. */
|
|
23
|
+
readonly names: Set<string>;
|
|
24
|
+
/** Imports the build cannot follow, each a sentence naming the file and the form. */
|
|
25
|
+
readonly opaque: string[];
|
|
26
|
+
}
|
|
27
|
+
/** Walk one module's AST for what it takes from `@pix3/runtime`; `file` names it in messages. */
|
|
28
|
+
export declare const collectRuntimeImports: (ast: unknown, file: string, findings?: RuntimeImportFindings) => RuntimeImportFindings;
|
|
29
|
+
/** Every parseable source of a package, as absolute paths (sorted; nested packages excluded). */
|
|
30
|
+
export declare const listPackageSources: (packageDir: string) => string[];
|
|
31
|
+
/** TypeScript / JSX → plain JS, with whichever transform the installed Vite ships. */
|
|
32
|
+
export declare const lowerToJs: (code: string, filename: string) => Promise<string>;
|
|
33
|
+
export interface DependencyScanOptions {
|
|
34
|
+
readonly root: string;
|
|
35
|
+
/** Package names (from `runtimeDependents`). */
|
|
36
|
+
readonly packages: readonly string[];
|
|
37
|
+
/** The bundler's parser (`this.parse` of a hook). */
|
|
38
|
+
readonly parse: (code: string) => unknown;
|
|
39
|
+
}
|
|
40
|
+
export interface DependencyScan extends RuntimeImportFindings, SourceMentions {
|
|
41
|
+
/** `package → files parsed`, for the log and the report. */
|
|
42
|
+
readonly parsed: Record<string, number>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse every source of the given packages that mentions `@pix3/runtime` at all (a cheap text
|
|
46
|
+
* test first: three's one file is a megabyte). Opaque findings carry the package name and the
|
|
47
|
+
* path relative to it.
|
|
48
|
+
*
|
|
49
|
+
* Every source read is also scanned the way the project's own are (`mentionedNames`, the import
|
|
50
|
+
* specifiers): a library script that imports only `Script` and calls `this.scene.tween`,
|
|
51
|
+
* `.physics2d`, `juice.trail()` or `addComponent('core:Fade')` reaches modules no import names.
|
|
52
|
+
*/
|
|
53
|
+
export declare const scanDependencyImports: (options: DependencyScanOptions) => Promise<DependencyScan>;
|