dewdrop-sdk 0.6.0 → 0.7.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/package.json +1 -1
- package/src/build.js +10 -0
- package/src/vite.js +8 -5
package/package.json
CHANGED
package/src/build.js
CHANGED
|
@@ -15,6 +15,16 @@ export const BACKEND_FILE = 'backend.js';
|
|
|
15
15
|
// The page a browser would open, as the build emits it beside the entry.
|
|
16
16
|
export const PAGE_FILE = 'index.html';
|
|
17
17
|
|
|
18
|
+
// The build's record beside the entry, naming the SDK that built it.
|
|
19
|
+
// Dewdrop holds every breaking change to it: a game keeps the behavior of
|
|
20
|
+
// the SDK version it names until it is built with a newer one, and a game
|
|
21
|
+
// without a record, built before 0.7.0, keeps the behavior from before
|
|
22
|
+
// every change. So each release that breaks what a game sees is a new
|
|
23
|
+
// version, and the change is the one that version names.
|
|
24
|
+
export const BUILD_RECORD_FILE = 'dewdrop-build.json';
|
|
25
|
+
const { version: SDK_VERSION } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
26
|
+
export const buildRecord = () => `${JSON.stringify({ sdk: SDK_VERSION })}\n`;
|
|
27
|
+
|
|
18
28
|
// Where Vite writes the files it emits — the stylesheets a game imports,
|
|
19
29
|
// and the images, fonts, and models it imports above the inline limit —
|
|
20
30
|
// `ui/`, where what the page shows must be on Dewdrop.
|
package/src/vite.js
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
// SDK left as imports for Dewdrop to supply, one chunk of ES modules with
|
|
3
3
|
// dynamic imports folded in, written as `main.js` at the top of the
|
|
4
4
|
// output, no module preload, a root base, the files Vite emits under
|
|
5
|
-
// `ui/`,
|
|
6
|
-
//
|
|
5
|
+
// `ui/`, the built page opened in the document by the entry, and the
|
|
6
|
+
// build's record beside it, `dewdrop-build.json`; a game with a backend
|
|
7
|
+
// gets a second chunk beside it, `backend.js`. Vite's dev
|
|
7
8
|
// server is refused, since a game plays on Dewdrop alone: the refusal
|
|
8
9
|
// says where. The plugin imports nothing from Vite itself, so it works
|
|
9
10
|
// linked from a checkout as well as installed, on Vite 3 through 8.
|
|
10
11
|
import { existsSync } from 'node:fs';
|
|
11
12
|
import { resolve } from 'node:path';
|
|
12
|
-
import { ASSETS_DIR, BACKEND_FILE, ENTRY_FILE, PAGE_FILE, detectViteMajor, openPage, outputOptions } from './build.js';
|
|
13
|
+
import { ASSETS_DIR, BACKEND_FILE, BUILD_RECORD_FILE, ENTRY_FILE, PAGE_FILE, buildRecord, detectViteMajor, openPage, outputOptions } from './build.js';
|
|
13
14
|
import { ON_DEWDROP } from './message.js';
|
|
14
15
|
|
|
15
16
|
// The imports Dewdrop supplies, left in the output: three and the paths
|
|
@@ -78,13 +79,15 @@ export default function dew() {
|
|
|
78
79
|
return config;
|
|
79
80
|
},
|
|
80
81
|
// The built page, its URLs rewritten and its stylesheets linked as Vite
|
|
81
|
-
// made it for a browser, is opened at the top of the entry
|
|
82
|
-
//
|
|
82
|
+
// made it for a browser, is opened at the top of the entry, and the
|
|
83
|
+
// build's record is written beside it. Last of the hooks, since Vite
|
|
84
|
+
// emits the page in its own generateBundle.
|
|
83
85
|
generateBundle: {
|
|
84
86
|
order: 'post',
|
|
85
87
|
handler(_options, bundle) {
|
|
86
88
|
const chunk = bundle[ENTRY_FILE];
|
|
87
89
|
if (chunk === undefined || chunk.type !== 'chunk') return;
|
|
90
|
+
this.emitFile({ type: 'asset', fileName: BUILD_RECORD_FILE, source: buildRecord() });
|
|
88
91
|
const page = bundle[PAGE_FILE];
|
|
89
92
|
if (page?.type !== 'asset') return;
|
|
90
93
|
const html = page.source instanceof Uint8Array ? new TextDecoder().decode(page.source) : String(page.source);
|