@puzzmo/sdk 1.0.82 → 1.0.84
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/dist/bundleChecks.d.ts +48 -0
- package/dist/bundleChecks.d.ts.map +1 -0
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/vite.cjs +9 -5
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +194 -73
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -6,8 +6,121 @@ import { build as i } from "vite";
|
|
|
6
6
|
import a from "path";
|
|
7
7
|
import o from "fs";
|
|
8
8
|
import { execFileSync as s } from "child_process";
|
|
9
|
+
var c = 1024;
|
|
10
|
+
/** The limits for a bundle Puzzmo loads into its own pages, where every byte is on a player's page load */
|
|
11
|
+
const l = (e) => ({
|
|
12
|
+
loadedOn: e,
|
|
13
|
+
warnBytes: 200 * c,
|
|
14
|
+
maxBytes: 500 * c,
|
|
15
|
+
bannedPackages: [
|
|
16
|
+
"react",
|
|
17
|
+
"react-dom",
|
|
18
|
+
"scheduler",
|
|
19
|
+
"redux",
|
|
20
|
+
"react-redux",
|
|
21
|
+
"@reduxjs/toolkit"
|
|
22
|
+
]
|
|
23
|
+
}), u = (e, t) => {
|
|
24
|
+
var n;
|
|
25
|
+
let r = [], i = [], a = g(e), o = Buffer.byteLength(e.code), s = t.maxBytes !== void 0 && o > t.maxBytes, c = t.warnBytes !== void 0 && o > t.warnBytes;
|
|
26
|
+
if (s || c) {
|
|
27
|
+
let n = s ? t.maxBytes : t.warnBytes, c = t.loadedOn ? ` for a bundle loaded on ${t.loadedOn}` : "", l = Object.entries(e.modules).sort(([, e], [, t]) => t.size - e.size).slice(0, 5).map(([e, { size: t }]) => ` ${v(t).padStart(7)} ${a.module(e)}\n ${a.chain(e)}`), u = `${e.fileName} is ${v(o)}, over the ${v(n)} limit${c}. Its largest modules:\n${l.join("\n")}`;
|
|
28
|
+
(s ? r : i).push(u);
|
|
29
|
+
}
|
|
30
|
+
let l = new Set((n = t.bannedPackages) == null ? [] : n), u = /* @__PURE__ */ new Set();
|
|
31
|
+
for (let t of Object.keys(e.modules)) {
|
|
32
|
+
let n = _(t);
|
|
33
|
+
!n || !l.has(n) || u.has(n) || (u.add(n), r.push(`${n} can't be in ${e.fileName}, as Puzzmo calls it for strings and data. Imported by:\n ${a.chain(t)}`));
|
|
34
|
+
}
|
|
35
|
+
let d = p(e.code, e.modules);
|
|
36
|
+
if (d.length) {
|
|
37
|
+
let t = d.map(({ usage: e, count: t, moduleID: n }) => {
|
|
38
|
+
let r = t > 1 ? ` (x${t})` : "";
|
|
39
|
+
return n ? ` ${e}${r} in ${a.module(n)}\n ${a.chain(n)}` : ` ${e}${r}`;
|
|
40
|
+
});
|
|
41
|
+
i.push(`${e.fileName} uses Node globals, which don't exist where Puzzmo runs it, so each throws if reached:\n${t.join("\n")}`);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
errors: r,
|
|
45
|
+
warnings: i
|
|
46
|
+
};
|
|
47
|
+
}, d = (e, t) => {
|
|
48
|
+
let n = process.cwd(), r = {};
|
|
49
|
+
return {
|
|
50
|
+
name: "puzzmo-bundle-checks",
|
|
51
|
+
api: r,
|
|
52
|
+
configResolved(e) {
|
|
53
|
+
n = e.root;
|
|
54
|
+
},
|
|
55
|
+
generateBundle(i, a) {
|
|
56
|
+
let o = Object.values(a).find((e) => e.type === "chunk" && e.isEntry);
|
|
57
|
+
if ((o == null ? void 0 : o.type) !== "chunk" || !o.facadeModuleId) return;
|
|
58
|
+
let s = Object.fromEntries(Object.entries(o.modules).map(([e, t]) => [e, {
|
|
59
|
+
size: t.renderedLength,
|
|
60
|
+
code: t.code
|
|
61
|
+
}])), c = h(o.facadeModuleId, (e) => this.getModuleInfo(e)), { errors: l, warnings: d } = u({
|
|
62
|
+
fileName: e,
|
|
63
|
+
code: o.code,
|
|
64
|
+
modules: s,
|
|
65
|
+
chains: c,
|
|
66
|
+
root: n
|
|
67
|
+
}, t);
|
|
68
|
+
for (let e of d) this.warn(e);
|
|
69
|
+
l.length && (r.failure = l.join("\n\n"), this.error(r.failure));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
/** A Node-only global in use: `process.env.X`, `Buffer.from`, `require(`, never `obj.process.x` or `__require(` */
|
|
74
|
+
var f = /* @__PURE__ */ RegExp("(?<![\\w$.])(?:(?:process|global|Buffer)(?:\\.[\\w$]+){1,2}|require\\s*\\(|new\\s+Buffer\\s*\\(|__dirname\\b|__filename\\b)", "g"), p = (e, t) => {
|
|
75
|
+
let n = m(e), r = [];
|
|
76
|
+
for (let [e, i] of Object.entries(t)) if (i.code) for (let [t, a] of m(i.code)) n.has(t) && r.push({
|
|
77
|
+
usage: t,
|
|
78
|
+
count: a,
|
|
79
|
+
moduleID: e
|
|
80
|
+
});
|
|
81
|
+
let i = new Set(r.map(({ usage: e }) => e));
|
|
82
|
+
for (let [e, t] of n) i.has(e) || r.push({
|
|
83
|
+
usage: e,
|
|
84
|
+
count: t
|
|
85
|
+
});
|
|
86
|
+
return r;
|
|
87
|
+
}, m = (e) => {
|
|
88
|
+
let t = /* @__PURE__ */ new Map();
|
|
89
|
+
for (let r of e.matchAll(f)) {
|
|
90
|
+
var n;
|
|
91
|
+
let i = r[0].match(/process|global|Buffer|require|__dirname|__filename/)[0], a = e.slice(Math.max(0, r.index - 200), r.index);
|
|
92
|
+
if (/typeof\s+$/.test(a) || RegExp(`typeof\\s+${i}\\b`).test(a)) continue;
|
|
93
|
+
let o = r[0].replace(/\s*\($/, "(").replace(/\s+/g, " ");
|
|
94
|
+
t.set(o, ((n = t.get(o)) == null ? 0 : n) + 1);
|
|
95
|
+
}
|
|
96
|
+
return t;
|
|
97
|
+
}, h = (e, t) => {
|
|
98
|
+
let n = new Map([[e, [e]]]), r = [e];
|
|
99
|
+
for (let e = 0; e < r.length; e++) {
|
|
100
|
+
let i = t(r[e]);
|
|
101
|
+
if (i) for (let t of [...i.importedIds, ...i.dynamicallyImportedIds]) n.has(t) || (n.set(t, [...n.get(r[e]), t]), r.push(t));
|
|
102
|
+
}
|
|
103
|
+
return n;
|
|
104
|
+
}, g = ({ root: e, chains: t }) => {
|
|
105
|
+
let n = (t) => {
|
|
106
|
+
let n = t.replace(/^\0/, "").replace(/\?.*$/, ""), r = y(n.split("/node_modules/"));
|
|
107
|
+
return r === n ? a.isAbsolute(n) ? a.relative(e, n) : n : r;
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
module: n,
|
|
111
|
+
chain: (e) => {
|
|
112
|
+
var r;
|
|
113
|
+
return ((r = t.get(e)) == null ? [e] : r).map(n).join(" > ");
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}, _ = (e) => {
|
|
117
|
+
let t = e.split("/node_modules/");
|
|
118
|
+
if (t.length < 2) return;
|
|
119
|
+
let n = y(t).split("/");
|
|
120
|
+
return n[0].startsWith("@") ? `${n[0]}/${n[1]}` : n[0];
|
|
121
|
+
}, v = (e) => `${Math.round(e / c)}KB`, y = (e) => e[e.length - 1];
|
|
9
122
|
/** @internal Finds the PICO-8 game served by the page in `dir`, if there is one. */
|
|
10
|
-
function
|
|
123
|
+
function b(e, t = {}) {
|
|
11
124
|
var n;
|
|
12
125
|
let r;
|
|
13
126
|
if (t.cart) r = a.resolve(e, t.cart);
|
|
@@ -31,7 +144,7 @@ function c(e, t = {}) {
|
|
|
31
144
|
* Turns PICO-8's exported page into a Puzzmo game's page. PICO-8's shell is a thousand lines of globals and handlers
|
|
32
145
|
* its runtime expects to find, and it changes between versions, so rather than keep a copy we adjust theirs.
|
|
33
146
|
*/
|
|
34
|
-
function
|
|
147
|
+
function x(e, t, n) {
|
|
35
148
|
let r = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), i = RegExp(`((?:\\.src\\s*=\\s*|\\ssrc=)["'])[^"']*${r}\\.js(["'])`);
|
|
36
149
|
if (!i.test(e)) throw Error(`[puzzmo-pico8] couldn't find where PICO-8's page loads ${t}.js`);
|
|
37
150
|
e = e.replace(i, `$1./${t}.js$2`), e = e.replace(/var\s+p8_autoplay\s*=\s*false/, "var p8_autoplay = true"), /var\s+pico8_gpio\s*=/.test(e) || (e = e.replace(/<head>/i, "<head>\n<script>var pico8_gpio = new Array(128)<\/script>")), e = e.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/gi, (e, t, n, r) => t + n.replace(/<!--|-->/g, "").replace(/^[ \t]*-repeat[^;\n]*;[ \t]*$/gm, "") + r), e = e.replace(/ (?!;)/g, " ");
|
|
@@ -40,11 +153,11 @@ function l(e, t, n) {
|
|
|
40
153
|
return e.slice(0, a) + n.join("\n") + "\n" + e.slice(a);
|
|
41
154
|
}
|
|
42
155
|
/** Where PICO-8's own installers put it, for people who never added it to their PATH. */
|
|
43
|
-
var
|
|
156
|
+
var S = [
|
|
44
157
|
"/Applications/PICO-8.app/Contents/MacOS/pico8",
|
|
45
158
|
"C:\\Program Files (x86)\\PICO-8\\pico8.exe",
|
|
46
159
|
"C:\\Program Files\\PICO-8\\pico8.exe"
|
|
47
|
-
],
|
|
160
|
+
], C = (e) => {
|
|
48
161
|
var t, n;
|
|
49
162
|
if (e.includes("/") || e.includes("\\")) return o.existsSync(e) ? e : null;
|
|
50
163
|
for (let n of ((t = process.env.PATH) == null ? "" : t).split(a.delimiter)) for (let t of process.platform === "win32" ? [
|
|
@@ -55,8 +168,8 @@ var u = [
|
|
|
55
168
|
let r = a.join(n, e + t);
|
|
56
169
|
if (o.existsSync(r)) return r;
|
|
57
170
|
}
|
|
58
|
-
return e === "pico8" ? (n =
|
|
59
|
-
},
|
|
171
|
+
return e === "pico8" ? (n = S.find((e) => o.existsSync(e))) == null ? null : n : null;
|
|
172
|
+
}, w = (e) => o.existsSync(e) ? o.statSync(e).mtimeMs : 0;
|
|
60
173
|
/**
|
|
61
174
|
* Vite plugin for games written as PICO-8 carts. Your `index.html` only needs your own script tag, the plugin swaps
|
|
62
175
|
* in PICO-8's exported page around it, serves the PICO-8 runtime next to it, and copies it into the build.
|
|
@@ -64,16 +177,16 @@ var u = [
|
|
|
64
177
|
* When PICO-8 is installed it also re-exports the cart whenever it (or a `.lua` file next to it) changes, and reloads
|
|
65
178
|
* the page, so saving in PICO-8 is enough to see the change in the simulator.
|
|
66
179
|
*/
|
|
67
|
-
function
|
|
180
|
+
function T(e = {}) {
|
|
68
181
|
var t, n;
|
|
69
|
-
let i,
|
|
182
|
+
let i, c = /* @__PURE__ */ new Map(), l = e.pico8 === !1 ? null : (t = (n = e.pico8) == null ? process.env.PICO8 : n) == null ? "pico8" : t, u = (e) => i.logger.info(`\x1b[33m\x1b[1m PICO-8 \x1b[22m\x1b[39m${e}`), d = (t) => {
|
|
70
183
|
if (e.writeLua === !1) return;
|
|
71
184
|
let n = a.join(a.dirname(t.cart), "puzzmo.lua");
|
|
72
|
-
o.existsSync(n) && o.readFileSync(n, "utf8") === r || (o.writeFileSync(n, r),
|
|
73
|
-
},
|
|
74
|
-
let t = a.dirname(e.cart), n = Math.max(...o.readdirSync(t).filter((e) => /\.(p8|lua)$/.test(e)).map((e) =>
|
|
75
|
-
if (o.existsSync(e.exportJS) &&
|
|
76
|
-
let r =
|
|
185
|
+
o.existsSync(n) && o.readFileSync(n, "utf8") === r || (o.writeFileSync(n, r), u(`wrote ${a.relative(i.root, n)}`));
|
|
186
|
+
}, f = (e) => {
|
|
187
|
+
let t = a.dirname(e.cart), n = Math.max(...o.readdirSync(t).filter((e) => /\.(p8|lua)$/.test(e)).map((e) => w(a.join(t, e))));
|
|
188
|
+
if (o.existsSync(e.exportJS) && w(e.exportJS) >= n) return;
|
|
189
|
+
let r = l ? C(l) : null;
|
|
77
190
|
if (!r) {
|
|
78
191
|
if (o.existsSync(e.exportHTML)) {
|
|
79
192
|
i.logger.warn(`[puzzmo-pico8] ${a.relative(i.root, e.cart)} is newer than its export, and PICO-8 isn't around to re-export it. Using the old export.`);
|
|
@@ -82,9 +195,9 @@ function p(e = {}) {
|
|
|
82
195
|
throw Error(`[puzzmo-pico8] there's no export of ${a.relative(i.root, e.cart)} yet, and PICO-8 isn't on your PATH to make one.\nExport it inside PICO-8 with EXPORT ${e.name}.html into ${a.relative(i.root, a.dirname(e.exportHTML))}/, or set PICO8=/path/to/pico8.`);
|
|
83
196
|
}
|
|
84
197
|
o.mkdirSync(a.dirname(e.exportHTML), { recursive: !0 });
|
|
85
|
-
let c =
|
|
198
|
+
let c = w(e.exportJS), d = "";
|
|
86
199
|
try {
|
|
87
|
-
|
|
200
|
+
d = s(r, [
|
|
88
201
|
e.cart,
|
|
89
202
|
"-export",
|
|
90
203
|
e.exportHTML
|
|
@@ -98,22 +211,22 @@ function p(e = {}) {
|
|
|
98
211
|
]
|
|
99
212
|
});
|
|
100
213
|
} catch (e) {
|
|
101
|
-
var
|
|
102
|
-
|
|
214
|
+
var f;
|
|
215
|
+
d = String((f = e.stdout) == null ? e : f);
|
|
103
216
|
}
|
|
104
|
-
if (
|
|
105
|
-
let t = /label/i.test(
|
|
106
|
-
throw Error(`[puzzmo-pico8] PICO-8 didn't export ${a.relative(i.root, e.cart)}:\n${
|
|
217
|
+
if (w(e.exportJS) === c) {
|
|
218
|
+
let t = /label/i.test(d) ? "\nHTML exports need a label: run the cart in PICO-8, press CTRL-7, and save." : "";
|
|
219
|
+
throw Error(`[puzzmo-pico8] PICO-8 didn't export ${a.relative(i.root, e.cart)}:\n${d.trim()}${t}`);
|
|
107
220
|
}
|
|
108
|
-
|
|
109
|
-
},
|
|
221
|
+
u(`exported ${a.relative(i.root, e.cart)}`);
|
|
222
|
+
}, p = (t) => {
|
|
110
223
|
let n = a.dirname(t);
|
|
111
|
-
if (!
|
|
112
|
-
let t =
|
|
224
|
+
if (!c.has(n)) {
|
|
225
|
+
let t = b(n, e);
|
|
113
226
|
if (!t) return null;
|
|
114
|
-
|
|
227
|
+
c.set(n, t);
|
|
115
228
|
}
|
|
116
|
-
return
|
|
229
|
+
return c.get(n);
|
|
117
230
|
};
|
|
118
231
|
return {
|
|
119
232
|
name: "puzzmo-pico8",
|
|
@@ -129,11 +242,11 @@ function p(e = {}) {
|
|
|
129
242
|
order: "pre",
|
|
130
243
|
handler(e, t) {
|
|
131
244
|
var n;
|
|
132
|
-
let r =
|
|
245
|
+
let r = p(t.filename);
|
|
133
246
|
if (!r) return;
|
|
134
|
-
|
|
247
|
+
d(r), f(r);
|
|
135
248
|
let i = (n = e.match(/<script\b[^>]*type=["']module["'][^>]*>[\s\S]*?<\/script>/gi)) == null ? [] : n;
|
|
136
|
-
return
|
|
249
|
+
return x(o.readFileSync(r.exportHTML, "utf8"), r.name, i);
|
|
137
250
|
}
|
|
138
251
|
},
|
|
139
252
|
configureServer(e) {
|
|
@@ -141,13 +254,13 @@ function p(e = {}) {
|
|
|
141
254
|
var r;
|
|
142
255
|
let s = decodeURIComponent(((r = e.url) == null ? "" : r).split("?")[0]);
|
|
143
256
|
if (!s.endsWith(".js")) return n();
|
|
144
|
-
let
|
|
145
|
-
if (!
|
|
146
|
-
t.setHeader("Content-Type", "text/javascript"), t.end(o.readFileSync(
|
|
257
|
+
let l = [...c.values()].find((e) => s === "/" + a.relative(i.root, a.join(e.dir, `${e.name}.js`)).split(a.sep).join("/"));
|
|
258
|
+
if (!l || !o.existsSync(l.exportJS)) return n();
|
|
259
|
+
t.setHeader("Content-Type", "text/javascript"), t.end(o.readFileSync(l.exportJS));
|
|
147
260
|
}), e.watcher.on("change", (t) => {
|
|
148
|
-
let n = [...
|
|
261
|
+
let n = [...c.values()].find((e) => a.dirname(t) === a.dirname(e.cart) && /\.(p8|lua)$/.test(t));
|
|
149
262
|
if (!(!n || a.basename(t) === "puzzmo.lua")) try {
|
|
150
|
-
|
|
263
|
+
f(n), e.ws.send({ type: "full-reload" });
|
|
151
264
|
} catch (t) {
|
|
152
265
|
let n = t instanceof Error ? t.message : String(t);
|
|
153
266
|
i.logger.error(n), e.ws.send({
|
|
@@ -161,7 +274,7 @@ function p(e = {}) {
|
|
|
161
274
|
});
|
|
162
275
|
},
|
|
163
276
|
generateBundle() {
|
|
164
|
-
for (let e of
|
|
277
|
+
for (let e of c.values()) {
|
|
165
278
|
let t = a.relative(i.root, a.join(e.dir, `${e.name}.js`)).split(a.sep).join("/");
|
|
166
279
|
this.emitFile({
|
|
167
280
|
type: "asset",
|
|
@@ -172,14 +285,14 @@ function p(e = {}) {
|
|
|
172
285
|
}
|
|
173
286
|
};
|
|
174
287
|
}
|
|
175
|
-
var
|
|
288
|
+
var E = ["fixturesGlob", "viewFactories"], D = "/@puzzmo-simulator-init.js", O = "virtual:puzzmo-simulator";
|
|
176
289
|
/**
|
|
177
290
|
* Discover all games from puzzmo.json files under a root directory.
|
|
178
291
|
*
|
|
179
292
|
* @internal
|
|
180
293
|
*/
|
|
181
|
-
function
|
|
182
|
-
let t = /* @__PURE__ */ new Map(), n =
|
|
294
|
+
function k(e) {
|
|
295
|
+
let t = /* @__PURE__ */ new Map(), n = U(e, 3);
|
|
183
296
|
o.existsSync(a.join(e, "puzzmo.json")) && n.unshift(e);
|
|
184
297
|
for (let i of n) try {
|
|
185
298
|
var r;
|
|
@@ -190,8 +303,8 @@ function _(e) {
|
|
|
190
303
|
dir: i,
|
|
191
304
|
slug: n.game.slug,
|
|
192
305
|
displayName: n.game.displayName,
|
|
193
|
-
appBundlePath:
|
|
194
|
-
pmmgBundlePath:
|
|
306
|
+
appBundlePath: F(e, I(i, "src/appBundle")),
|
|
307
|
+
pmmgBundlePath: F(e, I(i, "src/pmmgBundle")),
|
|
195
308
|
integrations: s
|
|
196
309
|
});
|
|
197
310
|
} catch (e) {}
|
|
@@ -202,7 +315,7 @@ function _(e) {
|
|
|
202
315
|
*
|
|
203
316
|
* @internal
|
|
204
317
|
*/
|
|
205
|
-
function
|
|
318
|
+
function A(e, t, n) {
|
|
206
319
|
if (e) try {
|
|
207
320
|
let r = new URL(e).pathname;
|
|
208
321
|
for (let e of t.values()) {
|
|
@@ -217,42 +330,42 @@ function v(e, t, n) {
|
|
|
217
330
|
*
|
|
218
331
|
* @internal
|
|
219
332
|
*/
|
|
220
|
-
function
|
|
221
|
-
let { fixturesGlob: i, viewFactories: a } = n, o = e(n,
|
|
333
|
+
function j(n, r) {
|
|
334
|
+
let { fixturesGlob: i, viewFactories: a } = n, o = e(n, E), s = i === !1 ? null : i == null ? "/fixtures/puzzles/**/*.{json,toml}" : i, c = ["import { createSimulator } from \"@puzzmo/sdk/simulator\""];
|
|
222
335
|
for (let e of a == null ? [] : a) c.push(`import { ${e.export} } from ${JSON.stringify(e.module)}`);
|
|
223
336
|
s && c.push(`const fixtures = import.meta.glob(${JSON.stringify(s)}, { query: "?raw", import: "default", eager: true })`), r != null && r.appBundlePath && (c.push(`import(${JSON.stringify(r.appBundlePath)}).then(m => {`), c.push(" if (m.renderThumbnail) globalThis.renderThumbnail = m.renderThumbnail"), c.push(" if (m.getShareString) globalThis.getShareString = m.getShareString"), c.push("}).catch(() => {})"));
|
|
224
337
|
let l = t(t(t({}, o), r != null && r.slug ? { slug: r.slug } : {}), r != null && r.integrations ? { integrations: r.integrations } : {}), u = Object.entries(l).filter(([, e]) => e !== void 0).map(([e, t]) => `${e}: ${JSON.stringify(t)}`);
|
|
225
338
|
return s && u.push("fixtures"), r != null && r.pmmgBundlePath && u.push(`pmmgBundle: () => import(${JSON.stringify(r.pmmgBundlePath)})`), a != null && a.length && u.push(`views: [${a.map((e) => `${e.export}()`).join(", ")}]`), c.push(`createSimulator({ ${u.join(", ")} })`), c.join("\n");
|
|
226
339
|
}
|
|
227
340
|
/** Vite plugin that injects the Puzzmo simulator in dev mode and handles OAuth callbacks. */
|
|
228
|
-
function
|
|
341
|
+
function M(e = {}) {
|
|
229
342
|
let t = /* @__PURE__ */ new Map(), r;
|
|
230
343
|
return {
|
|
231
344
|
name: "puzzmo-simulator",
|
|
232
345
|
apply: "serve",
|
|
233
346
|
configResolved(e) {
|
|
234
|
-
if (r = e.root, t =
|
|
347
|
+
if (r = e.root, t = k(r), t.size === 0) e.logger.info("\x1B[33m\x1B[1m PUZZMO \x1B[22m\x1B[39m\x1B[2m no puzzmo.json files found\x1B[22m");
|
|
235
348
|
else {
|
|
236
349
|
let n = [...t.values()].map((e) => `\x1b[36m${e.slug}\x1b[39m`), r = t.size === 1 ? "game" : "games";
|
|
237
350
|
e.logger.info(`\x1b[33m\x1b[1m PUZZMO \x1b[22m\x1b[39m found ${t.size} ${r}: ${n.join("\x1B[2m, \x1B[22m")}`);
|
|
238
351
|
}
|
|
239
352
|
},
|
|
240
353
|
resolveId(e) {
|
|
241
|
-
if (e ===
|
|
354
|
+
if (e === O || e.startsWith(O + "?")) return "\0" + e;
|
|
242
355
|
},
|
|
243
356
|
load(n) {
|
|
244
|
-
if (!n.startsWith("\0" +
|
|
357
|
+
if (!n.startsWith("\0" + O)) return;
|
|
245
358
|
let r = new URLSearchParams(n.split("?")[1] || "").get("game");
|
|
246
|
-
return
|
|
359
|
+
return j(e, r ? t.get(r) : t.size === 1 ? t.values().next().value : void 0);
|
|
247
360
|
},
|
|
248
361
|
configureServer(e) {
|
|
249
362
|
for (let n of t.values()) e.watcher.add(a.join(n.dir, "puzzmo.json"));
|
|
250
363
|
e.watcher.on("change", (n) => {
|
|
251
364
|
if (a.basename(n) === "puzzmo.json") {
|
|
252
|
-
t =
|
|
365
|
+
t = k(r);
|
|
253
366
|
for (let t of e.moduleGraph.idToModuleMap.values()) {
|
|
254
367
|
var i;
|
|
255
|
-
(i = t.id) != null && i.startsWith("\0" +
|
|
368
|
+
(i = t.id) != null && i.startsWith("\0" + O) && e.moduleGraph.invalidateModule(t);
|
|
256
369
|
}
|
|
257
370
|
e.ws.send({ type: "full-reload" });
|
|
258
371
|
}
|
|
@@ -261,8 +374,8 @@ function b(e = {}) {
|
|
|
261
374
|
}), e.middlewares.use(function() {
|
|
262
375
|
var i = n(function* (n, i, a) {
|
|
263
376
|
var o;
|
|
264
|
-
if (((o = n.url) == null ? void 0 : o.split("?")[0]) !==
|
|
265
|
-
let s =
|
|
377
|
+
if (((o = n.url) == null ? void 0 : o.split("?")[0]) !== D) return a();
|
|
378
|
+
let s = A(n.headers.referer, t, r), c = O + (s ? `?game=${s.slug}` : ""), l = yield e.transformRequest(c);
|
|
266
379
|
if (!l) return a();
|
|
267
380
|
i.setHeader("Content-Type", "application/javascript"), i.end(l.code);
|
|
268
381
|
});
|
|
@@ -276,39 +389,41 @@ function b(e = {}) {
|
|
|
276
389
|
tag: "script",
|
|
277
390
|
attrs: {
|
|
278
391
|
type: "module",
|
|
279
|
-
src:
|
|
392
|
+
src: D
|
|
280
393
|
},
|
|
281
394
|
injectTo: "head"
|
|
282
395
|
}];
|
|
283
396
|
}
|
|
284
397
|
};
|
|
285
398
|
}
|
|
286
|
-
function
|
|
287
|
-
return (
|
|
288
|
-
let { entry:
|
|
399
|
+
function N(e, r, o = {}) {
|
|
400
|
+
return (s = {}) => {
|
|
401
|
+
let { entry: c, outputFile: l, outDir: u } = t(t({}, r), s), f = a.relative(process.cwd(), a.resolve(u, l));
|
|
289
402
|
return {
|
|
290
403
|
name: e,
|
|
291
404
|
apply: "build",
|
|
292
405
|
closeBundle() {
|
|
293
406
|
return n(function* () {
|
|
294
407
|
var t;
|
|
295
|
-
let n =
|
|
408
|
+
let n = s.entry ? a.isAbsolute(c) ? c : a.resolve(process.cwd(), c) : (t = I(process.cwd(), P(c))) == null ? a.resolve(process.cwd(), c) : t, r = d(f, o);
|
|
296
409
|
try {
|
|
297
410
|
yield i({
|
|
298
411
|
configFile: !1,
|
|
299
412
|
logLevel: "warn",
|
|
413
|
+
define: W,
|
|
414
|
+
plugins: [r],
|
|
300
415
|
build: {
|
|
301
416
|
lib: {
|
|
302
417
|
entry: n,
|
|
303
418
|
formats: ["es"],
|
|
304
|
-
fileName: () =>
|
|
419
|
+
fileName: () => l
|
|
305
420
|
},
|
|
306
|
-
outDir:
|
|
421
|
+
outDir: u,
|
|
307
422
|
emptyOutDir: !1
|
|
308
423
|
}
|
|
309
424
|
});
|
|
310
425
|
} catch (t) {
|
|
311
|
-
throw console.error(`[${e}] build failed:`, t), t;
|
|
426
|
+
throw r.api.failure ? G(`[${e}] ${r.api.failure}`) : (console.error(`[${e}] build failed:`, t), t);
|
|
312
427
|
}
|
|
313
428
|
})();
|
|
314
429
|
}
|
|
@@ -316,7 +431,7 @@ function x(e, r) {
|
|
|
316
431
|
};
|
|
317
432
|
}
|
|
318
433
|
/** Strip the trailing extension from a default entry path so we can probe siblings. */
|
|
319
|
-
var
|
|
434
|
+
var P = (e) => e.replace(/\.[jt]sx?$/i, ""), F = (e, t) => t ? "/" + a.relative(e, t).split(a.sep).join("/") : null, I = (e, t) => {
|
|
320
435
|
for (let n of [
|
|
321
436
|
".js",
|
|
322
437
|
".ts",
|
|
@@ -335,20 +450,20 @@ var S = (e) => e.replace(/\.[jt]sx?$/i, ""), C = (e, t) => t ? "/" + a.relative(
|
|
|
335
450
|
* returning the SVG and its dimensions (`{ svg, width, height }`), used by the Puzzmo
|
|
336
451
|
* platform for puzzle previews.
|
|
337
452
|
*/
|
|
338
|
-
const
|
|
453
|
+
const L = N("app-bundle", {
|
|
339
454
|
entry: "src/appBundle.js",
|
|
340
455
|
outputFile: "app-bundle.js",
|
|
341
456
|
outDir: "dist"
|
|
342
|
-
}),
|
|
457
|
+
}, l("Puzzmo's pages wherever the game's thumbnails show")), R = N("server-bundle", {
|
|
343
458
|
entry: "src/serverBundle.js",
|
|
344
459
|
outputFile: "server-bundle.js",
|
|
345
460
|
outDir: "dist-server"
|
|
346
461
|
});
|
|
347
|
-
var
|
|
462
|
+
var z = N("pmmg-bundle", {
|
|
348
463
|
entry: "src/pmmgBundle.js",
|
|
349
464
|
outputFile: "pmmg-bundle.js",
|
|
350
465
|
outDir: "dist"
|
|
351
|
-
});
|
|
466
|
+
}, l("Puzzmo's pages for every board at the table"));
|
|
352
467
|
/**
|
|
353
468
|
* Vite plugins for the game's pmmg bundle (see `PmmgBundle`), such as its boards at the table. After the main build
|
|
354
469
|
* they produce dist/pmmg-bundle.js, which is public and served with the rest of `dist`. In dev, `/pmmg-bundle.js` on
|
|
@@ -358,7 +473,7 @@ var D = x("pmmg-bundle", {
|
|
|
358
473
|
* Puzzmo imports it from an opaque-origin sandbox, so that one response answers any origin. It's a whole build rather
|
|
359
474
|
* than the dev server's modules, since letting `Origin: null` read those would let any page read the game's source.
|
|
360
475
|
*/
|
|
361
|
-
const
|
|
476
|
+
const B = (e = {}) => [z(e), {
|
|
362
477
|
name: "pmmg-bundle-dev",
|
|
363
478
|
apply: "serve",
|
|
364
479
|
configureServer(t) {
|
|
@@ -366,9 +481,9 @@ const O = (e = {}) => [D(e), {
|
|
|
366
481
|
t.middlewares.use((r, i, o) => {
|
|
367
482
|
var s;
|
|
368
483
|
if (!/^\/pmmg-bundle\.js(?:\?.*)?$/.test(r.url || "")) return o();
|
|
369
|
-
let c = (s = e.entry) == null ?
|
|
484
|
+
let c = (s = e.entry) == null ? I(t.config.root, "src/pmmgBundle") : s;
|
|
370
485
|
if (!c) return o();
|
|
371
|
-
n != null || (n =
|
|
486
|
+
n != null || (n = V(a.resolve(t.config.root, c)).finally(() => n = void 0)), n.then((e) => {
|
|
372
487
|
i.setHeader("Content-Type", "text/javascript"), i.setHeader("Access-Control-Allow-Origin", "*"), i.setHeader("Cache-Control", "no-store"), i.end(e);
|
|
373
488
|
}, (e) => {
|
|
374
489
|
var n;
|
|
@@ -376,11 +491,12 @@ const O = (e = {}) => [D(e), {
|
|
|
376
491
|
});
|
|
377
492
|
});
|
|
378
493
|
}
|
|
379
|
-
}],
|
|
494
|
+
}], V = function() {
|
|
380
495
|
var e = n(function* (e) {
|
|
381
496
|
let t = yield i({
|
|
382
497
|
configFile: !1,
|
|
383
498
|
logLevel: "warn",
|
|
499
|
+
define: W,
|
|
384
500
|
build: {
|
|
385
501
|
write: !1,
|
|
386
502
|
copyPublicDir: !1,
|
|
@@ -400,11 +516,11 @@ const O = (e = {}) => [D(e), {
|
|
|
400
516
|
return function(t) {
|
|
401
517
|
return e.apply(this, arguments);
|
|
402
518
|
};
|
|
403
|
-
}(),
|
|
519
|
+
}(), H = N("editor-bundle", {
|
|
404
520
|
entry: "src/editorBundle.js",
|
|
405
521
|
outputFile: "editor-bundle.js",
|
|
406
522
|
outDir: "dist"
|
|
407
|
-
}),
|
|
523
|
+
}), U = (e, t, n = 0) => {
|
|
408
524
|
if (n >= t) return [];
|
|
409
525
|
let r = [], i;
|
|
410
526
|
try {
|
|
@@ -415,10 +531,15 @@ const O = (e = {}) => [D(e), {
|
|
|
415
531
|
for (let s of i) {
|
|
416
532
|
if (!s.isDirectory() || s.name.startsWith(".") || s.name === "node_modules") continue;
|
|
417
533
|
let i = a.join(e, s.name);
|
|
418
|
-
o.existsSync(a.join(i, "puzzmo.json")) && r.push(i), r.push(...
|
|
534
|
+
o.existsSync(a.join(i, "puzzmo.json")) && r.push(i), r.push(...U(i, t, n + 1));
|
|
419
535
|
}
|
|
420
536
|
return r;
|
|
421
537
|
};
|
|
422
|
-
|
|
538
|
+
/**
|
|
539
|
+
* Lib mode leaves `process.env.*` for a consumer's bundler to replace, but these bundles are run as-is in browsers and
|
|
540
|
+
* isolates with no `process`, so a dependency's `NODE_ENV` check (immer, reselect, React) would throw on load
|
|
541
|
+
*/
|
|
542
|
+
var W = { "process.env.NODE_ENV": JSON.stringify("production") }, G = (e) => Object.assign(Error(e), { stack: e });
|
|
543
|
+
export { L as appBundlePlugin, V as buildPmmgBundleSource, k as discoverGames, H as editorBundlePlugin, U as findPuzzmoJsonDirs, j as generateSimulatorCode, B as pmmgBundlePlugin, T as puzzmoPico8, M as puzzmoSimulator, A as resolveGameFromReferer, R as serverBundlePlugin };
|
|
423
544
|
|
|
424
545
|
//# sourceMappingURL=vite.js.map
|