diff --git a/packages/core/src/app/makeProject.ts b/packages/core/src/app/makeProject.ts index 35779d94..888e82da 100644 --- a/packages/core/src/app/makeProject.ts +++ b/packages/core/src/app/makeProject.ts @@ -62,19 +62,10 @@ export function makeProject(project: UserProject): Project { settings: convertedSettings, plugins: [], logger: new Logger(), - versions: createVersionObject('0.10.4'), - }; -} - -export async function addEditorToProject(project: Project) { - const url = '/@id/@revideo/2d/editor'; - const imported = await import( - /* webpackIgnore: true */ /* @vite-ignore */ url - ); - const plugin = imported.default(); - - return { - ...project, - plugins: [...project.plugins, plugin], + // Placeholder only. The real, per-package versions are resolved from the + // installed `package.json` files and injected by the vite-plugin's editor + // entry (the sole consumer, the editor footer). They are never used during + // a headless render, so we don't try to resolve them here in core. + versions: createVersionObject('0.0.0'), }; } diff --git a/packages/create/examples b/packages/create/examples index 61e05ee7..1c9dff8c 160000 --- a/packages/create/examples +++ b/packages/create/examples @@ -1 +1 @@ -Subproject commit 61e05ee71d471aeb2e47855509838846c466234c +Subproject commit 1c9dff8c027195201846741735376d62e04cc983 diff --git a/packages/template/tsconfig.json b/packages/template/tsconfig.json index d5b7dffb..a5d91886 100644 --- a/packages/template/tsconfig.json +++ b/packages/template/tsconfig.json @@ -5,7 +5,8 @@ "noEmit": false, "outDir": "dist", "rootDir": "./src", - "module": "CommonJS", + "module": "NodeNext", + "moduleResolution": "NodeNext", "skipLibCheck": true }, "include": ["src"] diff --git a/packages/vite-plugin/src/partials/editor.ts b/packages/vite-plugin/src/partials/editor.ts index 1d8b9aa7..7abe3d57 100644 --- a/packages/vite-plugin/src/partials/editor.ts +++ b/packages/vite-plugin/src/partials/editor.ts @@ -2,6 +2,7 @@ import fs from 'fs'; import path from 'path'; import type {Plugin} from 'vite'; import type {Projects} from '../utils'; +import {getVersions} from '../versions'; interface EditorPluginConfig { editor: string; @@ -19,6 +20,43 @@ export function editorPlugin({editor, projects}: EditorPluginConfig): Plugin { const resolvedEditorId = '\0virtual:editor'; + /** + * Generate the editor entry module for a single project. + * + * Editor plugins are declared per-scene as module specifiers (e.g. + * `'@revideo/2d/editor'`). We load them here, in the dev-server-only entry, + * and inject them into the project before handing it to the editor. This + * keeps the dynamic import — and the Vite-internal `/@id/` prefix used to + * resolve it — out of `@revideo/core`, so it never leaks into a headless + * render bundle. + * + * The real package versions (resolved from the installed `package.json` + * files) are injected here too — they're only ever shown in the editor + * footer, so this is the one place that has both the project and access to + * the file system. + */ + const editorEntry = (projectUrl: string) => { + const versions = JSON.stringify(getVersions()); + /* language=typescript */ + return `\ +import {editor} from '${editor}'; +import project from '/@fs/${path.resolve(projectUrl)}'; +const specifiers = [ + ...new Set((project.scenes ?? []).flatMap(scene => scene.plugins ?? [])), +]; +const plugins = await Promise.all( + specifiers.map(specifier => + import(/* @vite-ignore */ '/@id/' + specifier).then(mod => mod.default()), + ), +); +editor({ + ...project, + versions: ${versions}, + plugins: [...project.plugins, ...plugins], +}); +`; + }; + return { name: 'revideo:editor', @@ -27,26 +65,14 @@ export function editorPlugin({editor, projects}: EditorPluginConfig): Plugin { if (id.startsWith(resolvedEditorId)) { if (projects.list.length === 1) { - /* language=typescript */ - return `\ -import {editor} from '${editor}'; -import project from '/@fs/${path.resolve(projects.list[0].url)}'; -import {addEditorToProject} from '@revideo/core'; -editor(await addEditorToProject(project)); -`; + return editorEntry(projects.list[0].url); } if (query) { const params = new URLSearchParams(query); const name = params.get('project'); if (name && projects.lookup.has(name)) { - /* language=typescript */ - return `\ -import {editor} from '${editor}'; -import project from '/@fs/${path.resolve(projects.lookup.get(name)!.url)}'; -import {addEditorToProject} from '@revideo/core'; -editor(await addEditorToProject(project)); -`; + return editorEntry(projects.lookup.get(name)!.url); } } diff --git a/packages/vite-plugin/src/versions.ts b/packages/vite-plugin/src/versions.ts index 34d9c27f..192aba81 100644 --- a/packages/vite-plugin/src/versions.ts +++ b/packages/vite-plugin/src/versions.ts @@ -6,7 +6,7 @@ export function getVersions() { core: loadVersion('@revideo/core'), two: loadVersion('@revideo/2d'), ui: loadVersion('@revideo/ui'), - vitePlugin: loadVersion('..'), + vitePlugin: loadVersion('@revideo/vite-plugin'), }; }