@motion-script/vite-plugin 0.1.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/dist/index.js +46 -24
- package/dist/plugin-app/public/jetbeans-mono.ttf +0 -0
- package/dist/src/plugin.d.ts +5 -2
- package/package.json +45 -43
package/dist/index.js
CHANGED
|
@@ -157,44 +157,63 @@ async function b(e, t = []) {
|
|
|
157
157
|
}
|
|
158
158
|
//#endregion
|
|
159
159
|
//#region src/plugin.ts
|
|
160
|
-
var x = e.dirname(n(import.meta.url)), S = [
|
|
161
|
-
|
|
162
|
-
"react-dom",
|
|
163
|
-
"react/jsx-runtime",
|
|
164
|
-
"react/jsx-dev-runtime"
|
|
165
|
-
], C = "~asset-manifest", w = "\0~asset-manifest", T = e.resolve(x, "plugin-app", "public");
|
|
166
|
-
function E() {
|
|
167
|
-
let n = r(import.meta.url);
|
|
160
|
+
var x = e.dirname(n(import.meta.url)), S = ["react", "react-dom"], C = r(import.meta.url);
|
|
161
|
+
function w(e) {
|
|
168
162
|
try {
|
|
169
|
-
|
|
170
|
-
return t.existsSync(r) ? r : null;
|
|
163
|
+
return C.resolve(e);
|
|
171
164
|
} catch {
|
|
172
165
|
return null;
|
|
173
166
|
}
|
|
174
167
|
}
|
|
175
|
-
function
|
|
168
|
+
function T() {
|
|
169
|
+
let n;
|
|
170
|
+
try {
|
|
171
|
+
n = C.resolve("@motion-script/player/package.json");
|
|
172
|
+
} catch {
|
|
173
|
+
throw Error("[vite-plugin-motion-script] Could not resolve @motion-script/player. It is a dependency of this plugin — ensure it is installed.");
|
|
174
|
+
}
|
|
175
|
+
let r = e.dirname(n), i = JSON.parse(t.readFileSync(n, "utf8")), a = i.exports?.["."], o = typeof a == "string" ? a : a?.import, s = i.exports?.["./style.css"], c = typeof s == "string" ? s : s?.import;
|
|
176
|
+
if (!o || !c) throw Error("[vite-plugin-motion-script] @motion-script/player is missing its \".\" or \"./style.css\" export. The installed player package may be incompatible.");
|
|
177
|
+
let l = e.resolve(r, o), u = e.resolve(r, c);
|
|
178
|
+
if (!t.existsSync(l) || !t.existsSync(u)) throw Error(`[vite-plugin-motion-script] @motion-script/player resolved but its built files are missing (looked for ${l}). Build the player before running.`);
|
|
179
|
+
return {
|
|
180
|
+
root: r,
|
|
181
|
+
entry: l,
|
|
182
|
+
style: u
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
var E = "~asset-manifest", D = "\0~asset-manifest", O = e.resolve(x, "plugin-app", "public");
|
|
186
|
+
function k() {
|
|
187
|
+
try {
|
|
188
|
+
let n = e.join(e.dirname(C.resolve("@motion-script/canvaskit/package.json")), "canvaskit.wasm");
|
|
189
|
+
return t.existsSync(n) ? n : null;
|
|
190
|
+
} catch {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function A(n) {
|
|
176
195
|
let r = null;
|
|
177
196
|
return [i(), {
|
|
178
197
|
name: "vite-plugin-motion-script",
|
|
179
198
|
resolveId(e) {
|
|
180
|
-
return e ===
|
|
199
|
+
return e === E ? D : null;
|
|
181
200
|
},
|
|
182
201
|
async load(t) {
|
|
183
|
-
if (t !==
|
|
184
|
-
let n = await b(e.resolve(process.cwd(), "public"), [
|
|
202
|
+
if (t !== D) return null;
|
|
203
|
+
let n = await b(e.resolve(process.cwd(), "public"), [O]);
|
|
185
204
|
return `export default ${JSON.stringify(n)};`;
|
|
186
205
|
},
|
|
187
206
|
configureServer(n) {
|
|
188
207
|
let r = process.cwd(), i = e.resolve(x, "plugin-app"), a = e.resolve(r, "public");
|
|
189
208
|
t.existsSync(a) && n.watcher.add(a);
|
|
190
209
|
let o = () => {
|
|
191
|
-
let e = n.moduleGraph.getModuleById(
|
|
210
|
+
let e = n.moduleGraph.getModuleById(D);
|
|
192
211
|
e && (n.moduleGraph.invalidateModule(e), n.ws.send({ type: "full-reload" }));
|
|
193
212
|
}, s = (e) => {
|
|
194
213
|
e.startsWith(a) && o();
|
|
195
214
|
};
|
|
196
215
|
n.watcher.on("add", s), n.watcher.on("change", s), n.watcher.on("unlink", s);
|
|
197
|
-
let c =
|
|
216
|
+
let c = k();
|
|
198
217
|
if (c) {
|
|
199
218
|
let e = c;
|
|
200
219
|
n.middlewares.use("/canvaskit.wasm", (n, r) => {
|
|
@@ -217,7 +236,10 @@ function D(n) {
|
|
|
217
236
|
"src/main.tsx",
|
|
218
237
|
"src/main.js",
|
|
219
238
|
"src/main.jsx"
|
|
220
|
-
].find((n) => t.existsSync(e.resolve(i, n))), s = ["src/project.ts", "src/project.js"].find((n) => t.existsSync(e.resolve(i, n))), c = e.resolve(x, "..", "node_modules"),
|
|
239
|
+
].find((n) => t.existsSync(e.resolve(i, n))), s = ["src/project.ts", "src/project.js"].find((n) => t.existsSync(e.resolve(i, n))), c = e.resolve(x, "..", "node_modules"), { entry: l, style: u, root: d } = T(), f = Object.fromEntries(S.map((t) => {
|
|
240
|
+
let n = w(`${t}/package.json`);
|
|
241
|
+
return [t, n ? e.dirname(n) : e.resolve(c, t)];
|
|
242
|
+
}));
|
|
221
243
|
return {
|
|
222
244
|
root: a,
|
|
223
245
|
envDir: i,
|
|
@@ -226,12 +248,12 @@ function D(n) {
|
|
|
226
248
|
i,
|
|
227
249
|
a,
|
|
228
250
|
c,
|
|
229
|
-
|
|
251
|
+
d
|
|
230
252
|
] } },
|
|
231
253
|
resolve: { alias: {
|
|
232
|
-
...
|
|
233
|
-
"@motion-script/player/style.css":
|
|
234
|
-
"@motion-script/player":
|
|
254
|
+
...f,
|
|
255
|
+
"@motion-script/player/style.css": u,
|
|
256
|
+
"@motion-script/player": l,
|
|
235
257
|
"~user-script": o ? e.resolve(i, o) : e.resolve(a, "src/empty-fallback.js"),
|
|
236
258
|
"~user-project": s ? e.resolve(i, s) : e.resolve(a, "src/empty-project.ts")
|
|
237
259
|
} },
|
|
@@ -248,8 +270,8 @@ function D(n) {
|
|
|
248
270
|
closeBundle() {
|
|
249
271
|
if (!r) return;
|
|
250
272
|
t.mkdirSync(r, { recursive: !0 });
|
|
251
|
-
let n =
|
|
252
|
-
n && t.copyFileSync(n, e.join(r, "canvaskit.wasm")), t.existsSync(
|
|
273
|
+
let n = k();
|
|
274
|
+
n && t.copyFileSync(n, e.join(r, "canvaskit.wasm")), t.existsSync(O) && t.cpSync(O, r, {
|
|
253
275
|
recursive: !0,
|
|
254
276
|
force: !1,
|
|
255
277
|
errorOnExist: !1
|
|
@@ -258,4 +280,4 @@ function D(n) {
|
|
|
258
280
|
}];
|
|
259
281
|
}
|
|
260
282
|
//#endregion
|
|
261
|
-
export {
|
|
283
|
+
export { A as default };
|
|
Binary file
|
package/dist/src/plugin.d.ts
CHANGED
|
@@ -21,8 +21,11 @@ export interface MotionScriptOptions {
|
|
|
21
21
|
* - Generates a virtual asset manifest (`~asset-manifest`) describing the
|
|
22
22
|
* user's `public/` directory plus plugin-app's bundled defaults, with HMR
|
|
23
23
|
* invalidation when the user's assets change.
|
|
24
|
-
* - Aliases React
|
|
25
|
-
* correctly even when the user's project doesn't depend on React
|
|
24
|
+
* - Aliases React (resolved from wherever it's installed) so plugin-app
|
|
25
|
+
* resolves correctly even when the user's project doesn't depend on React.
|
|
26
|
+
* - Aliases `@motion-script/player` to its installed, prebuilt dist, resolved
|
|
27
|
+
* via Node module resolution so it works from an npm install, not just the
|
|
28
|
+
* monorepo.
|
|
26
29
|
*
|
|
27
30
|
* Returns a `PluginOption[]` (rather than a single plugin object) because it
|
|
28
31
|
* also needs `@vitejs/plugin-react` to be active for plugin-app's JSX.
|
package/package.json
CHANGED
|
@@ -1,44 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@motion-script/vite-plugin",
|
|
3
|
-
"description": "Vite plugin that bootstraps a Motion Script project: it serves a preview app, resolves the user's scene as the entry point, and ships CanvasKit assets with the build.",
|
|
4
|
-
"license": "Apache-2.0",
|
|
5
|
-
"version": "0.1
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"publishConfig": {
|
|
10
|
-
"access": "public"
|
|
11
|
-
},
|
|
12
|
-
"exports": {
|
|
13
|
-
".": {
|
|
14
|
-
"import": "./dist/index.js",
|
|
15
|
-
"types": "./dist/index.d.ts"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"files": [
|
|
19
|
-
"dist"
|
|
20
|
-
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "vite build",
|
|
23
|
-
"clean": "rimraf dist .turbo && tsc -b --clean"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"@types/
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@motion-script/vite-plugin",
|
|
3
|
+
"description": "Vite plugin that bootstraps a Motion Script project: it serves a preview app, resolves the user's scene as the entry point, and ships CanvasKit assets with the build.",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"version": "0.2.1",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "vite build",
|
|
23
|
+
"clean": "rimraf dist .turbo && tsc -b --clean"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@motion-script/canvaskit": "^0.2.0",
|
|
27
|
+
"@motion-script/player": "^0.2.0",
|
|
28
|
+
"@vitejs/plugin-react": "^6.0.0",
|
|
29
|
+
"fontkit": "^2.0.4",
|
|
30
|
+
"image-size": "^2.0.2",
|
|
31
|
+
"music-metadata": "^11.8.3",
|
|
32
|
+
"react": "catalog:",
|
|
33
|
+
"react-dom": "catalog:"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"vite": "catalog:"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "catalog:",
|
|
40
|
+
"@types/react": "^19.0.0",
|
|
41
|
+
"@types/react-dom": "^19.0.0",
|
|
42
|
+
"typescript": "catalog:",
|
|
43
|
+
"vite": "catalog:",
|
|
44
|
+
"vite-plugin-dts": "catalog:"
|
|
45
|
+
}
|
|
44
46
|
}
|