@reactunity/renderer 0.27.0 → 0.27.2

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/vite.d.mts CHANGED
@@ -29,11 +29,12 @@ interface ReactUnityOptions {
29
29
  */
30
30
  tailwind?: boolean;
31
31
  /**
32
- * Serve the previewer -- a hosted Unity WebGL player running this app -- at `previewer/` on the
33
- * dev server, and send a browser that opens the root there. Default `true`. A project's own
34
- * `public/previewer/index.html` is served in its place.
32
+ * Serve the previewer -- a Unity WebGL player running this app -- at `previewer/` on the dev
33
+ * server, and send a browser that opens the root there. Default `true`, which uses the hosted
34
+ * player unless a `previewer/index.html` of your own sits next to the Vite root. A string names
35
+ * that folder instead, relative to the root; `false` turns the previewer off.
35
36
  */
36
- previewer?: boolean;
37
+ previewer?: boolean | string;
37
38
  }
38
39
  /**
39
40
  * Vite preset for a ReactUnity app: React Fast Refresh, output into the Unity project's
package/dist/vite.mjs CHANGED
@@ -125,9 +125,10 @@ function previewerHtml() {
125
125
  </p>
126
126
  <p>
127
127
  To work offline, or to preview your own Unity scene instead, build a scene with a
128
- <code>ReactRendererUGUI</code> whose source is the URL <code>/index.js</code>, and put the
129
- output in <code>public/previewer</code>, so that <code>public/previewer/index.html</code> exists.
130
- The dev server serves that in place of this page.
128
+ <code>ReactRendererUGUI</code> whose source is the URL <code>/index.js</code> for WebGL, and
129
+ put the output in a <code>previewer</code> folder next to your Vite config, so that
130
+ <code>previewer/index.html</code> exists. The dev server serves that in place of this page.
131
+ The preset's <code>previewer</code> option can name a different folder.
131
132
  </p>
132
133
  </div>
133
134
  </div>
@@ -237,35 +238,60 @@ function reactUnity(options = {}) {
237
238
  reactOptions === false ? null : react(reactOptions),
238
239
  reactUnityConfig(options),
239
240
  reactUnityClean(options),
240
- options.previewer === false ? null : reactUnityPreviewer()
241
+ options.previewer === false ? null : reactUnityPreviewer(options.previewer)
241
242
  ];
242
243
  }
243
- function reactUnityPreviewer() {
244
+ const PREVIEWER_CONTENT_TYPES = {
245
+ ".html": "text/html; charset=utf-8",
246
+ ".js": "text/javascript; charset=utf-8",
247
+ ".css": "text/css; charset=utf-8",
248
+ ".json": "application/json",
249
+ ".wasm": "application/wasm",
250
+ ".png": "image/png",
251
+ ".ico": "image/x-icon"
252
+ };
253
+ /** Sends a file from a WebGL build, or a 404 -- never the app, which Vite would answer with. */
254
+ function sendPreviewerFile(dir, relative, res) {
255
+ let file = path.resolve(dir, decodeURIComponent(relative));
256
+ if (file !== dir && !file.startsWith(dir + path.sep)) file = "";
257
+ else if (fs.existsSync(file) && fs.statSync(file).isDirectory()) file = path.join(file, "index.html");
258
+ if (!file || !fs.existsSync(file)) {
259
+ res.statusCode = 404;
260
+ res.end();
261
+ return;
262
+ }
263
+ const encoding = file.endsWith(".gz") ? "gzip" : file.endsWith(".br") ? "br" : void 0;
264
+ const name = encoding ? file.slice(0, file.lastIndexOf(".")) : file;
265
+ if (encoding) res.setHeader("Content-Encoding", encoding);
266
+ res.setHeader("Content-Type", PREVIEWER_CONTENT_TYPES[path.extname(name)] ?? "application/octet-stream");
267
+ fs.createReadStream(file).pipe(res);
268
+ }
269
+ function reactUnityPreviewer(folder) {
244
270
  let base = "/";
245
- let custom = false;
271
+ let dir = "";
246
272
  return {
247
273
  name: "reactunity:previewer",
248
274
  apply: "serve",
249
275
  configResolved(config) {
250
276
  base = config.base;
251
- custom = !!config.publicDir && fs.existsSync(path.join(config.publicDir, "previewer/", "index.html"));
277
+ dir = path.resolve(config.root, typeof folder === "string" ? folder : "previewer");
252
278
  },
253
279
  configureServer(server) {
254
280
  const page = base + PREVIEWER_PATH;
281
+ const custom = () => fs.existsSync(path.join(dir, "index.html"));
282
+ if (typeof folder === "string" && !custom()) server.config.logger.warn(`[reactunity] no index.html in the previewer folder ${dir}, so the hosted previewer is served.`);
255
283
  server.middlewares.use((req, res, next) => {
256
- const url = req.url?.split("?")[0];
284
+ const url = req.url?.split("?")[0] ?? "";
257
285
  if (url === page.slice(0, -1)) {
258
286
  res.statusCode = 302;
259
287
  res.setHeader("Location", page);
260
288
  res.end();
261
- } else if (url !== page && url !== `${page}index.html`) next();
262
- else if (custom) {
263
- req.url = `${page}index.html`;
264
- next();
265
- } else {
289
+ } else if (!url.startsWith(page)) next();
290
+ else if (custom()) sendPreviewerFile(dir, url.slice(page.length), res);
291
+ else if (url === page || url === `${page}index.html`) {
266
292
  res.setHeader("Content-Type", "text/html; charset=utf-8");
267
293
  res.end(previewerHtml());
268
- }
294
+ } else next();
269
295
  });
270
296
  const printUrls = server.printUrls;
271
297
  server.printUrls = () => {
package/dist/vite.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.mjs","names":[],"sources":["../src/vite/clean.ts","../src/vite/previewer.ts","../src/vite/unity-project.ts","../src/vite/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nconst META = '.meta';\n\n/**\n * Empties the output directory but keeps every `.meta` file.\n *\n * Unity writes a `.meta` beside each asset and the GUID inside it is what scenes,\n * prefabs and asset references point at. Deleting one makes Unity mint a new GUID for\n * the file that replaces it, which silently breaks every reference to it -- so a build\n * clears the output it produced last time and leaves the metas for the files coming back.\n * The ones nothing comes back for are dropped afterwards by `removeOrphanMetaFiles`.\n */\nexport function cleanOutDir(outDir: string, preserve: readonly string[] = []): void {\n if (!fs.existsSync(outDir)) return;\n\n const keep = new Set(preserve.map((entry) => path.resolve(outDir, entry)));\n cleanDir(outDir, keep);\n}\n\n// Returns whether anything survived, so the caller can drop a directory that did not.\nfunction cleanDir(dir: string, keep: Set<string>): boolean {\n let survivors = 0;\n\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name);\n\n if (keep.has(full) || entry.name.endsWith(META)) {\n survivors++;\n continue;\n }\n\n if (entry.isDirectory()) {\n // A directory holding metas (or something preserved) has to stay for them.\n if (cleanDir(full, keep)) survivors++;\n else fs.rmSync(full, { recursive: true, force: true });\n } else {\n fs.rmSync(full, { force: true });\n }\n }\n\n return survivors > 0;\n}\n\n/**\n * Drops the `.meta` files whose asset did not come back, and the directories the build\n * left empty. Run after the bundle is written, so what remains describes only real files.\n */\nexport function removeOrphanMetaFiles(outDir: string): void {\n if (!fs.existsSync(outDir)) return;\n sweep(outDir, true);\n}\n\n// Returns whether the directory is still wanted.\nfunction sweep(dir: string, isRoot: boolean): boolean {\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n if (sweep(full, false)) continue;\n\n // A directory's own meta lives in its parent, and goes with it.\n fs.rmSync(full, { recursive: true, force: true });\n fs.rmSync(full + META, { force: true });\n } else if (entry.name.endsWith(META) && !fs.existsSync(full.slice(0, -META.length))) {\n fs.rmSync(full, { force: true });\n }\n }\n\n return isRoot || fs.readdirSync(dir).length > 0;\n}\n\n/**\n * Describes why `outDir` must not be cleaned, or nothing when it is safe.\n *\n * The clean deletes everything it finds, so it refuses anything that is not plausibly a\n * build output folder: a Unity project root, a package, or the sources themselves.\n */\nexport function unsafeOutDirReason(outDir: string, root: string): string | undefined {\n const dir = path.resolve(outDir);\n\n if (path.dirname(dir) === dir) return 'it is a filesystem root';\n\n // `Assets` itself rather than a folder inside it: no marker below would catch that one.\n if (path.basename(dir) === 'Assets') return 'it is a Unity Assets folder';\n\n const relative = path.relative(dir, path.resolve(root));\n if (!relative || (!relative.startsWith('..') && !path.isAbsolute(relative))) return 'the project root is inside it';\n\n for (const marker of ['package.json', '.git', 'ProjectSettings']) {\n if (fs.existsSync(path.join(dir, marker))) return `it contains ${marker}`;\n }\n\n return undefined;\n}\n","/**\n * The hosted previewer build, by the release it ships in. Each build gets its own directory on\n * reactunity.github.io and none is overwritten, so a new build is uploaded first and bumped here\n * second. `packages/scripts/config/public/index.html` loads the same build and pins it too.\n */\nexport const PREVIEWER_VERSION = '0.27.0';\n\nconst PREVIEWER_BASE = `https://reactunity.github.io/Unity/previewer/${PREVIEWER_VERSION}/Build/`;\n\n/** Where the dev server serves the previewer, under Vite's `base`. */\nexport const PREVIEWER_PATH = 'previewer/';\n\n/**\n * Sends a browser that opens the dev server's root to the previewer. Unity runs this page's\n * scripts too, and has `Globals`; a browser does not, and would otherwise run the app against\n * no Unity at all and fail on it.\n */\nexport function previewerRedirect(base: string): string {\n const page = JSON.stringify(base + PREVIEWER_PATH);\n // Never from the previewer itself, so a misrouted previewer cannot become a redirect loop.\n return `if (typeof Globals === 'undefined' && location.pathname.indexOf(${page}) !== 0) location.replace(${page});`;\n}\n\n/** The previewer page: the hosted WebGL player, loading `/index.js` from this dev server. */\nexport function previewerHtml(): string {\n return `<!DOCTYPE html>\n<html lang=\"en-us\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>ReactUnity Previewer</title>\n <style>\n html, body { font-size: 0; margin: 0; height: 100%; overflow: hidden; }\n #unity-canvas { height: 100%; width: 100%; background: #231F20; }\n .loader-center { position: absolute; left: 0; right: 0; top: 50%; height: 0; overflow: visible; pointer-events: none; user-select: none; }\n .loader { position: absolute; height: 50px; top: -25px; left: 50px; right: 50px; background: #c5cae9; border-radius: 10px; overflow: hidden; }\n .loader-bar { height: 100%; background: #3f51b5; width: 0; }\n #error { display: none; position: absolute; inset: 0; overflow: auto; padding: 3rem 1.5rem; background: #fff; color: #231F20; font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }\n #error > div { max-width: 40rem; margin: 0 auto; }\n #error h1 { font-size: 1.5rem; margin: 0 0 1rem; }\n #error code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #f1f1f4; padding: .1em .3em; border-radius: 3px; }\n </style>\n</head>\n<body>\n <canvas id=\"unity-canvas\"></canvas>\n <div class=\"loader-center\" id=\"loader-root\"><div class=\"loader\"><div class=\"loader-bar\" id=\"loader-bar\"></div></div></div>\n <div id=\"error\">\n <div>\n <h1>Couldn't load the previewer</h1>\n <p>\n The previewer's Unity WebGL build is hosted rather than bundled, so the first load needs\n network access. It is cached by the browser afterwards.\n </p>\n <p>\n To work offline, or to preview your own Unity scene instead, build a scene with a\n <code>ReactRendererUGUI</code> whose source is the URL <code>/index.js</code>, and put the\n output in <code>public/previewer</code>, so that <code>public/previewer/index.html</code> exists.\n The dev server serves that in place of this page.\n </p>\n </div>\n </div>\n <script>\n var base = ${JSON.stringify(PREVIEWER_BASE)};\n\n function fail() {\n document.getElementById('loader-root').style.display = 'none';\n document.getElementById('error').style.display = 'block';\n }\n\n function onProgress(progress) {\n document.getElementById('loader-bar').style.width = (progress * 100) + '%';\n document.getElementById('loader-root').style.display = progress < 1 ? 'block' : 'none';\n }\n\n // Unity's loader defines a global createUnityInstance, so it is appended rather than imported.\n var loader = document.createElement('script');\n loader.src = base + 'Previewer.loader.js';\n loader.onerror = fail;\n loader.onload = function () {\n if (typeof createUnityInstance !== 'function') return fail();\n\n createUnityInstance(document.getElementById('unity-canvas'), {\n dataUrl: base + 'Previewer.data.unityweb',\n frameworkUrl: base + 'Previewer.framework.js.unityweb',\n codeUrl: base + 'Previewer.wasm.unityweb',\n // Absolute, or it would resolve against this dev server, which has none to serve.\n streamingAssetsUrl: base + '../StreamingAssets',\n companyName: 'reactunity',\n productName: 'dev-sample',\n productVersion: ${JSON.stringify(PREVIEWER_VERSION)},\n }, onProgress).catch(fail);\n };\n document.head.appendChild(loader);\n </script>\n</body>\n</html>\n`;\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\n\n// How far up the tree to look before giving up. Deep enough for any sane layout, shallow\n// enough that a React app outside a Unity project does not walk to the filesystem root.\nconst MAX_DEPTH = 10;\n\n/**\n * A folder is a Unity project when it has an `Assets` directory beside a\n * `ProjectSettings/ProjectVersion.txt`. The version stamp is what tells a real project\n * from any folder that happens to be called `Assets`.\n */\nexport function isUnityProject(dir: string): boolean {\n return isDirectory(path.join(dir, 'Assets')) && fs.existsSync(path.join(dir, 'ProjectSettings', 'ProjectVersion.txt'));\n}\n\n/**\n * Finds the Unity project a React app belongs to, starting at `from` and walking up.\n *\n * Each ancestor is tested itself and then one level down, so both documented layouts are\n * found: the app inside the project (`MyGame/react`) and the app beside it\n * (`workspace/{MyGame,ui}`).\n */\nexport function findUnityProject(from: string): string | undefined {\n let dir = path.resolve(from);\n\n for (let depth = 0; depth < MAX_DEPTH; depth++) {\n if (isUnityProject(dir)) return dir;\n\n const nested = findUnityProjectIn(dir);\n if (nested) return nested;\n\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n return undefined;\n}\n\nfunction findUnityProjectIn(dir: string): string | undefined {\n for (const entry of readDir(dir)) {\n // node_modules and dot-directories cannot hold a Unity project, and both are large.\n if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === 'node_modules') continue;\n\n const candidate = path.join(dir, entry.name);\n if (isUnityProject(candidate)) return candidate;\n }\n\n return undefined;\n}\n\nfunction readDir(dir: string): fs.Dirent[] {\n try {\n return fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n // Unreadable directories are simply not the project we are looking for.\n return [];\n }\n}\n\nfunction isDirectory(dir: string): boolean {\n try {\n return fs.statSync(dir).isDirectory();\n } catch {\n return false;\n }\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport react from '@vitejs/plugin-react';\nimport type { Plugin, PluginOption, UserConfig } from 'vite';\nimport { cleanOutDir, removeOrphanMetaFiles, unsafeOutDirReason } from './clean.ts';\nimport { PREVIEWER_PATH, previewerHtml, previewerRedirect } from './previewer.ts';\nimport { findUnityProject } from './unity-project.ts';\n\ntype ReactOptions = Parameters<typeof react>[0];\n\nconst DEFAULT_ASSET_PATH = 'Assets/Resources/react';\n\nexport interface ReactUnityOptions {\n /**\n * The Unity project to build into, absolute or relative to the Vite root. Discovered by\n * walking up from the Vite root when omitted.\n */\n unityProject?: string;\n\n /** Output folder inside the Unity project. Defaults to `Assets/Resources/react`. */\n assetPath?: string;\n\n /** Empty the output directory before each build, keeping its `.meta` files. Default `true`. */\n clean?: boolean;\n\n /** Paths inside the output directory, relative to it, that the clean never deletes. */\n preserve?: readonly string[];\n\n /**\n * Content hashes in output filenames. Default `false`: a hash renames the file on every\n * build, which costs it its `.meta` and so its Unity GUID.\n */\n hashFileNames?: boolean;\n\n /** Options for `@vitejs/plugin-react`, or `false` to add the React plugin yourself. */\n react?: ReactOptions | false;\n\n /**\n * Resolve a bare `@import \"tailwindcss\"` to `@reactunity/renderer/tailwind.css`, which is the\n * same thing with a Preflight written for what ReactUnity renders. Default `true`; `false`\n * leaves the import alone. Only the bare specifier is aliased -- `tailwindcss/theme.css` and\n * the rest keep resolving to the package, which is where that entry gets them from.\n */\n tailwind?: boolean;\n\n /**\n * Serve the previewer -- a hosted Unity WebGL player running this app -- at `previewer/` on the\n * dev server, and send a browser that opens the root there. Default `true`. A project's own\n * `public/previewer/index.html` is served in its place.\n */\n previewer?: boolean;\n}\n\nconst TAILWIND_ENTRY = '@reactunity/renderer/tailwind.css';\n\n/**\n * Vite preset for a ReactUnity app: React Fast Refresh, output into the Unity project's\n * `Assets/Resources/react`, a clean that keeps Unity's `.meta` files, and a Tailwind entry with\n * ReactUnity's Preflight in place of the browser one.\n *\n * ```ts\n * export default defineConfig({ plugins: [reactUnity()] });\n * ```\n */\nexport function reactUnity(options: ReactUnityOptions = {}): PluginOption[] {\n const reactOptions = options.react ?? {};\n\n return [\n reactOptions === false ? null : react(reactOptions),\n reactUnityConfig(options),\n reactUnityClean(options),\n options.previewer === false ? null : reactUnityPreviewer(),\n ];\n}\n\nfunction reactUnityPreviewer(): Plugin {\n let base = '/';\n let custom = false;\n\n return {\n name: 'reactunity:previewer',\n apply: 'serve',\n\n configResolved(config) {\n base = config.base;\n // The way a `previewer/` folder replaced the hosted one under react-unity-scripts.\n custom = !!config.publicDir && fs.existsSync(path.join(config.publicDir, PREVIEWER_PATH, 'index.html'));\n },\n\n configureServer(server) {\n const page = base + PREVIEWER_PATH;\n\n server.middlewares.use((req, res, next) => {\n const url = req.url?.split('?')[0];\n if (url === page.slice(0, -1)) {\n res.statusCode = 302;\n res.setHeader('Location', page);\n res.end();\n } else if (url !== page && url !== `${page}index.html`) {\n next();\n } else if (custom) {\n // Vite serves a public file but not a folder's index, and would answer the folder with the app.\n req.url = `${page}index.html`;\n next();\n } else {\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\n res.end(previewerHtml());\n }\n });\n\n const printUrls = server.printUrls;\n server.printUrls = () => {\n printUrls();\n for (const url of server.resolvedUrls?.local ?? [])\n server.config.logger.info(` ➜ Previewer: ${new URL(PREVIEWER_PATH, url).href}`);\n };\n },\n\n transformIndexHtml() {\n return [{ tag: 'script', children: previewerRedirect(base), injectTo: 'head-prepend' }];\n },\n };\n}\n\n// Lightning CSS's `Features`. The package is Vite's dependency rather than ours, so the flags are\n// spelled out; both have held these values since the features were added.\nconst LIGHTNINGCSS_LOGICAL_PROPERTIES = 1 << 19;\nconst LIGHTNINGCSS_LIGHT_DARK = 1 << 20;\n\nfunction reactUnityConfig(options: ReactUnityOptions): Plugin {\n const assetPath = options.assetPath ?? DEFAULT_ASSET_PATH;\n let message: { level: 'info' | 'warn'; text: string } | undefined;\n\n return {\n name: 'reactunity',\n\n config(config) {\n const patch: UserConfig = {};\n\n // Neither has anything to render against: Unity is not a browser, and an error\n // overlay drawn into a page nobody looks at only hides the console message.\n if (config.devtools === undefined) patch.devtools = false;\n\n const hmr = config.server?.hmr;\n if (hmr !== false && (hmr === undefined || (typeof hmr === 'object' && hmr.overlay === undefined))) {\n patch.server = { hmr: { overlay: false } };\n }\n\n // Tailwind's own Preflight resets a document, and there is no document here. Aliasing the\n // entry is what lets an app write the one line its docs tell it to. `@tailwindcss/vite`\n // resolves `@import` through Vite's resolver, so it sees this the way an app's own CSS does.\n if (options.tailwind !== false) {\n patch.resolve = { alias: [{ find: /^tailwindcss$/, replacement: TAILWIND_ENTRY }] };\n }\n\n const build: UserConfig['build'] = {};\n\n if (config.build?.outDir === undefined) {\n const root = path.resolve(config.root ?? process.cwd());\n const project = options.unityProject ? path.resolve(root, options.unityProject) : findUnityProject(root);\n\n if (project) {\n build.outDir = path.join(project, assetPath);\n message = { level: 'info', text: `[reactunity] Unity output directory: ${build.outDir}` };\n } else {\n message = {\n level: 'warn',\n text: '[reactunity] no Unity project found above the Vite root. Set the unityProject option or build.outDir.',\n };\n }\n }\n\n // Unity resolves an asset URL through its own loaders, and a small file inlined as a\n // data: URI never reaches them the same way -- react-unity-scripts pinned the same\n // limit to 0 rather than take CRA's 10 kB.\n if (config.build?.assetsInlineLimit === undefined) build.assetsInlineLimit = 0;\n\n // ReactUnity's CSS subset is roughly a 2020 browser: no oklch, color-mix or nesting.\n // Naming an old target is what makes Lightning CSS lower them on the way out.\n if (config.build?.cssTarget === undefined) build.cssTarget = ['chrome87'];\n\n // Two things that target lowers which ReactUnity reads itself. light-dark()'s lowered form\n // only works next to a color-scheme declaration in the same sheet; a logical property becomes\n // a `:-webkit-any(:lang(ae),:lang(ar),...)` pair naming every RTL language, which parses here\n // as a custom state and so never matches -- where `border-start-start-radius` is resolved\n // against the element's own direction. Only the radii reach that lowering at chrome87, the\n // rest of the logical properties being older than it.\n if (config.css?.lightningcss?.exclude === undefined) {\n patch.css = { lightningcss: { exclude: LIGHTNINGCSS_LIGHT_DARK | LIGHTNINGCSS_LOGICAL_PROPERTIES } };\n }\n\n // Vite's own emptying would take the .meta files with it, and warns about an outDir\n // outside the root besides. The clean plugin below does the job instead.\n if (options.clean !== false && config.build?.emptyOutDir === undefined) build.emptyOutDir = false;\n\n // Library mode names its own output, and an entryFileNames here would override it.\n const output = config.build?.rolldownOptions?.output ?? config.build?.rollupOptions?.output;\n if (!options.hashFileNames && output === undefined && !config.build?.lib) {\n const dir = config.build?.assetsDir ?? 'assets';\n build.rolldownOptions = {\n output: {\n entryFileNames: `${dir}/[name].js`,\n chunkFileNames: `${dir}/[name].js`,\n // Doubled on purpose. Unity keys a resource on its path minus the last extension, so\n // index.js and index.css both answer to `assets/index` and asking for one can hand you\n // the other. index.css.css keeps its type in the name it is looked up by.\n assetFileNames: `${dir}/[name][extname][extname]`,\n },\n };\n }\n\n if (Object.keys(build).length) patch.build = build;\n\n return patch;\n },\n\n configResolved(config) {\n // The config hook has no logger, so anything it decided is reported from here.\n if (message) config.logger[message.level](message.text);\n message = undefined;\n },\n };\n}\n\nfunction reactUnityClean(options: ReactUnityOptions): Plugin {\n const cleaned = new Set<string>();\n let written = false;\n let outDir = '';\n let root = '';\n let write = true;\n let logger: { warn: (message: string) => void } | undefined;\n\n return {\n name: 'reactunity:clean',\n apply: 'build',\n\n configResolved(config) {\n root = config.root;\n logger = config.logger;\n write = config.build.write !== false;\n outDir = path.resolve(config.root, config.build.outDir);\n },\n\n // Before renderStart, which is where Vite empties the outDir and copies publicDir\n // into it -- cleaning any later would delete files this build had just put there.\n buildStart() {\n if (options.clean === false || !write || cleaned.has(outDir)) return;\n cleaned.add(outDir);\n\n const unsafe = unsafeOutDirReason(outDir, root);\n if (unsafe) {\n logger?.warn(`[reactunity] not cleaning ${outDir} because ${unsafe}.`);\n return;\n }\n\n cleanOutDir(outDir, options.preserve);\n },\n\n // Only on success: closeBundle runs after a failed build too, and sweeping then\n // would delete every meta the clean had just set aside -- losing the GUIDs of files\n // the next successful build brings straight back.\n writeBundle() {\n written = true;\n },\n\n closeBundle() {\n // Cleared rather than kept, so a watch rebuild cleans again.\n cleaned.delete(outDir);\n const succeeded = written;\n written = false;\n if (options.clean === false || !write || !succeeded) return;\n\n removeOrphanMetaFiles(outDir);\n },\n };\n}\n\nexport default reactUnity;\n"],"mappings":";;;;AAGA,MAAM,OAAO;;;;;;;;;;AAWb,SAAgB,YAAY,QAAgB,WAA8B,CAAC,GAAS;CAClF,IAAI,CAAC,GAAG,WAAW,MAAM,GAAG;CAG5B,SAAS,QAAQ,IADA,IAAI,SAAS,KAAK,UAAU,KAAK,QAAQ,QAAQ,KAAK,CAAC,CACpD,CAAC;AACvB;AAGA,SAAS,SAAS,KAAa,MAA4B;CACzD,IAAI,YAAY;CAEhB,KA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O,MAAM,OAAO,MAAM,MAAM;EACxD;EAIA,aAAa;GACX,IAAI,QAAQ,UAAU,SAAS,CAAC,SAAS,QAAQ,IAAI,MAAM,GAAG;GAC9D,QAAQ,IAAI,MAAM;GAElB,MAAM,SAAS,mBAAmB,QAAQ,IAAI;GAC9C,IAAI,QAAQ;IACV,QAAQ,KAAK,6BAA6B,OAAO,WAAW,OAAO,EAAE;IACrE;GACF;GAEA,YAAY,QAAQ,QAAQ,QAAQ;EACtC;EAKA,cAAc;GACZ,UAAU;EACZ;EAEA,cAAc;GAEZ,QAAQ,OAAO,MAAM;GACrB,MAAM,YAAY;GAClB,UAAU;GACV,IAAI,QAAQ,UAAU,SAAS,CAAC,SAAS,CAAC,WAAW;GAErD,sBAAsB,MAAM;EAC9B;CACF;AACF"}
1
+ {"version":3,"file":"vite.mjs","names":[],"sources":["../src/vite/clean.ts","../src/vite/previewer.ts","../src/vite/unity-project.ts","../src/vite/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nconst META = '.meta';\n\n/**\n * Empties the output directory but keeps every `.meta` file.\n *\n * Unity writes a `.meta` beside each asset and the GUID inside it is what scenes,\n * prefabs and asset references point at. Deleting one makes Unity mint a new GUID for\n * the file that replaces it, which silently breaks every reference to it -- so a build\n * clears the output it produced last time and leaves the metas for the files coming back.\n * The ones nothing comes back for are dropped afterwards by `removeOrphanMetaFiles`.\n */\nexport function cleanOutDir(outDir: string, preserve: readonly string[] = []): void {\n if (!fs.existsSync(outDir)) return;\n\n const keep = new Set(preserve.map((entry) => path.resolve(outDir, entry)));\n cleanDir(outDir, keep);\n}\n\n// Returns whether anything survived, so the caller can drop a directory that did not.\nfunction cleanDir(dir: string, keep: Set<string>): boolean {\n let survivors = 0;\n\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name);\n\n if (keep.has(full) || entry.name.endsWith(META)) {\n survivors++;\n continue;\n }\n\n if (entry.isDirectory()) {\n // A directory holding metas (or something preserved) has to stay for them.\n if (cleanDir(full, keep)) survivors++;\n else fs.rmSync(full, { recursive: true, force: true });\n } else {\n fs.rmSync(full, { force: true });\n }\n }\n\n return survivors > 0;\n}\n\n/**\n * Drops the `.meta` files whose asset did not come back, and the directories the build\n * left empty. Run after the bundle is written, so what remains describes only real files.\n */\nexport function removeOrphanMetaFiles(outDir: string): void {\n if (!fs.existsSync(outDir)) return;\n sweep(outDir, true);\n}\n\n// Returns whether the directory is still wanted.\nfunction sweep(dir: string, isRoot: boolean): boolean {\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n if (sweep(full, false)) continue;\n\n // A directory's own meta lives in its parent, and goes with it.\n fs.rmSync(full, { recursive: true, force: true });\n fs.rmSync(full + META, { force: true });\n } else if (entry.name.endsWith(META) && !fs.existsSync(full.slice(0, -META.length))) {\n fs.rmSync(full, { force: true });\n }\n }\n\n return isRoot || fs.readdirSync(dir).length > 0;\n}\n\n/**\n * Describes why `outDir` must not be cleaned, or nothing when it is safe.\n *\n * The clean deletes everything it finds, so it refuses anything that is not plausibly a\n * build output folder: a Unity project root, a package, or the sources themselves.\n */\nexport function unsafeOutDirReason(outDir: string, root: string): string | undefined {\n const dir = path.resolve(outDir);\n\n if (path.dirname(dir) === dir) return 'it is a filesystem root';\n\n // `Assets` itself rather than a folder inside it: no marker below would catch that one.\n if (path.basename(dir) === 'Assets') return 'it is a Unity Assets folder';\n\n const relative = path.relative(dir, path.resolve(root));\n if (!relative || (!relative.startsWith('..') && !path.isAbsolute(relative))) return 'the project root is inside it';\n\n for (const marker of ['package.json', '.git', 'ProjectSettings']) {\n if (fs.existsSync(path.join(dir, marker))) return `it contains ${marker}`;\n }\n\n return undefined;\n}\n","/**\n * The hosted previewer build, by the release it ships in. Each build gets its own directory on\n * reactunity.github.io and none is overwritten, so a new build is uploaded first and bumped here\n * second. `packages/scripts/config/public/index.html` loads the same build and pins it too.\n */\nexport const PREVIEWER_VERSION = '0.27.0';\n\nconst PREVIEWER_BASE = `https://reactunity.github.io/Unity/previewer/${PREVIEWER_VERSION}/Build/`;\n\n/** Where the dev server serves the previewer, under Vite's `base`. */\nexport const PREVIEWER_PATH = 'previewer/';\n\n/**\n * Sends a browser that opens the dev server's root to the previewer. Unity runs this page's\n * scripts too, and has `Globals`; a browser does not, and would otherwise run the app against\n * no Unity at all and fail on it.\n */\nexport function previewerRedirect(base: string): string {\n const page = JSON.stringify(base + PREVIEWER_PATH);\n // Never from the previewer itself, so a misrouted previewer cannot become a redirect loop.\n return `if (typeof Globals === 'undefined' && location.pathname.indexOf(${page}) !== 0) location.replace(${page});`;\n}\n\n/** The previewer page: the hosted WebGL player, loading `/index.js` from this dev server. */\nexport function previewerHtml(): string {\n return `<!DOCTYPE html>\n<html lang=\"en-us\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>ReactUnity Previewer</title>\n <style>\n html, body { font-size: 0; margin: 0; height: 100%; overflow: hidden; }\n #unity-canvas { height: 100%; width: 100%; background: #231F20; }\n .loader-center { position: absolute; left: 0; right: 0; top: 50%; height: 0; overflow: visible; pointer-events: none; user-select: none; }\n .loader { position: absolute; height: 50px; top: -25px; left: 50px; right: 50px; background: #c5cae9; border-radius: 10px; overflow: hidden; }\n .loader-bar { height: 100%; background: #3f51b5; width: 0; }\n #error { display: none; position: absolute; inset: 0; overflow: auto; padding: 3rem 1.5rem; background: #fff; color: #231F20; font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }\n #error > div { max-width: 40rem; margin: 0 auto; }\n #error h1 { font-size: 1.5rem; margin: 0 0 1rem; }\n #error code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #f1f1f4; padding: .1em .3em; border-radius: 3px; }\n </style>\n</head>\n<body>\n <canvas id=\"unity-canvas\"></canvas>\n <div class=\"loader-center\" id=\"loader-root\"><div class=\"loader\"><div class=\"loader-bar\" id=\"loader-bar\"></div></div></div>\n <div id=\"error\">\n <div>\n <h1>Couldn't load the previewer</h1>\n <p>\n The previewer's Unity WebGL build is hosted rather than bundled, so the first load needs\n network access. It is cached by the browser afterwards.\n </p>\n <p>\n To work offline, or to preview your own Unity scene instead, build a scene with a\n <code>ReactRendererUGUI</code> whose source is the URL <code>/index.js</code> for WebGL, and\n put the output in a <code>previewer</code> folder next to your Vite config, so that\n <code>previewer/index.html</code> exists. The dev server serves that in place of this page.\n The preset's <code>previewer</code> option can name a different folder.\n </p>\n </div>\n </div>\n <script>\n var base = ${JSON.stringify(PREVIEWER_BASE)};\n\n function fail() {\n document.getElementById('loader-root').style.display = 'none';\n document.getElementById('error').style.display = 'block';\n }\n\n function onProgress(progress) {\n document.getElementById('loader-bar').style.width = (progress * 100) + '%';\n document.getElementById('loader-root').style.display = progress < 1 ? 'block' : 'none';\n }\n\n // Unity's loader defines a global createUnityInstance, so it is appended rather than imported.\n var loader = document.createElement('script');\n loader.src = base + 'Previewer.loader.js';\n loader.onerror = fail;\n loader.onload = function () {\n if (typeof createUnityInstance !== 'function') return fail();\n\n createUnityInstance(document.getElementById('unity-canvas'), {\n dataUrl: base + 'Previewer.data.unityweb',\n frameworkUrl: base + 'Previewer.framework.js.unityweb',\n codeUrl: base + 'Previewer.wasm.unityweb',\n // Absolute, or it would resolve against this dev server, which has none to serve.\n streamingAssetsUrl: base + '../StreamingAssets',\n companyName: 'reactunity',\n productName: 'dev-sample',\n productVersion: ${JSON.stringify(PREVIEWER_VERSION)},\n }, onProgress).catch(fail);\n };\n document.head.appendChild(loader);\n </script>\n</body>\n</html>\n`;\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\n\n// How far up the tree to look before giving up. Deep enough for any sane layout, shallow\n// enough that a React app outside a Unity project does not walk to the filesystem root.\nconst MAX_DEPTH = 10;\n\n/**\n * A folder is a Unity project when it has an `Assets` directory beside a\n * `ProjectSettings/ProjectVersion.txt`. The version stamp is what tells a real project\n * from any folder that happens to be called `Assets`.\n */\nexport function isUnityProject(dir: string): boolean {\n return isDirectory(path.join(dir, 'Assets')) && fs.existsSync(path.join(dir, 'ProjectSettings', 'ProjectVersion.txt'));\n}\n\n/**\n * Finds the Unity project a React app belongs to, starting at `from` and walking up.\n *\n * Each ancestor is tested itself and then one level down, so both documented layouts are\n * found: the app inside the project (`MyGame/react`) and the app beside it\n * (`workspace/{MyGame,ui}`).\n */\nexport function findUnityProject(from: string): string | undefined {\n let dir = path.resolve(from);\n\n for (let depth = 0; depth < MAX_DEPTH; depth++) {\n if (isUnityProject(dir)) return dir;\n\n const nested = findUnityProjectIn(dir);\n if (nested) return nested;\n\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n\n return undefined;\n}\n\nfunction findUnityProjectIn(dir: string): string | undefined {\n for (const entry of readDir(dir)) {\n // node_modules and dot-directories cannot hold a Unity project, and both are large.\n if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === 'node_modules') continue;\n\n const candidate = path.join(dir, entry.name);\n if (isUnityProject(candidate)) return candidate;\n }\n\n return undefined;\n}\n\nfunction readDir(dir: string): fs.Dirent[] {\n try {\n return fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n // Unreadable directories are simply not the project we are looking for.\n return [];\n }\n}\n\nfunction isDirectory(dir: string): boolean {\n try {\n return fs.statSync(dir).isDirectory();\n } catch {\n return false;\n }\n}\n","import fs from 'node:fs';\nimport type { ServerResponse } from 'node:http';\nimport path from 'node:path';\nimport react from '@vitejs/plugin-react';\nimport type { Plugin, PluginOption, UserConfig } from 'vite';\nimport { cleanOutDir, removeOrphanMetaFiles, unsafeOutDirReason } from './clean.ts';\nimport { PREVIEWER_PATH, previewerHtml, previewerRedirect } from './previewer.ts';\nimport { findUnityProject } from './unity-project.ts';\n\ntype ReactOptions = Parameters<typeof react>[0];\n\nconst DEFAULT_ASSET_PATH = 'Assets/Resources/react';\n\nexport interface ReactUnityOptions {\n /**\n * The Unity project to build into, absolute or relative to the Vite root. Discovered by\n * walking up from the Vite root when omitted.\n */\n unityProject?: string;\n\n /** Output folder inside the Unity project. Defaults to `Assets/Resources/react`. */\n assetPath?: string;\n\n /** Empty the output directory before each build, keeping its `.meta` files. Default `true`. */\n clean?: boolean;\n\n /** Paths inside the output directory, relative to it, that the clean never deletes. */\n preserve?: readonly string[];\n\n /**\n * Content hashes in output filenames. Default `false`: a hash renames the file on every\n * build, which costs it its `.meta` and so its Unity GUID.\n */\n hashFileNames?: boolean;\n\n /** Options for `@vitejs/plugin-react`, or `false` to add the React plugin yourself. */\n react?: ReactOptions | false;\n\n /**\n * Resolve a bare `@import \"tailwindcss\"` to `@reactunity/renderer/tailwind.css`, which is the\n * same thing with a Preflight written for what ReactUnity renders. Default `true`; `false`\n * leaves the import alone. Only the bare specifier is aliased -- `tailwindcss/theme.css` and\n * the rest keep resolving to the package, which is where that entry gets them from.\n */\n tailwind?: boolean;\n\n /**\n * Serve the previewer -- a Unity WebGL player running this app -- at `previewer/` on the dev\n * server, and send a browser that opens the root there. Default `true`, which uses the hosted\n * player unless a `previewer/index.html` of your own sits next to the Vite root. A string names\n * that folder instead, relative to the root; `false` turns the previewer off.\n */\n previewer?: boolean | string;\n}\n\nconst TAILWIND_ENTRY = '@reactunity/renderer/tailwind.css';\n\n/**\n * Vite preset for a ReactUnity app: React Fast Refresh, output into the Unity project's\n * `Assets/Resources/react`, a clean that keeps Unity's `.meta` files, and a Tailwind entry with\n * ReactUnity's Preflight in place of the browser one.\n *\n * ```ts\n * export default defineConfig({ plugins: [reactUnity()] });\n * ```\n */\nexport function reactUnity(options: ReactUnityOptions = {}): PluginOption[] {\n const reactOptions = options.react ?? {};\n\n return [\n reactOptions === false ? null : react(reactOptions),\n reactUnityConfig(options),\n reactUnityClean(options),\n options.previewer === false ? null : reactUnityPreviewer(options.previewer),\n ];\n}\n\nconst PREVIEWER_CONTENT_TYPES: Record<string, string> = {\n '.html': 'text/html; charset=utf-8',\n '.js': 'text/javascript; charset=utf-8',\n '.css': 'text/css; charset=utf-8',\n '.json': 'application/json',\n '.wasm': 'application/wasm',\n '.png': 'image/png',\n '.ico': 'image/x-icon',\n};\n\n/** Sends a file from a WebGL build, or a 404 -- never the app, which Vite would answer with. */\nfunction sendPreviewerFile(dir: string, relative: string, res: ServerResponse) {\n let file = path.resolve(dir, decodeURIComponent(relative));\n if (file !== dir && !file.startsWith(dir + path.sep)) file = '';\n else if (fs.existsSync(file) && fs.statSync(file).isDirectory()) file = path.join(file, 'index.html');\n\n if (!file || !fs.existsSync(file)) {\n res.statusCode = 404;\n res.end();\n return;\n }\n\n // A Unity build compressed without its decompression fallback needs the header said for it.\n const encoding = file.endsWith('.gz') ? 'gzip' : file.endsWith('.br') ? 'br' : undefined;\n const name = encoding ? file.slice(0, file.lastIndexOf('.')) : file;\n if (encoding) res.setHeader('Content-Encoding', encoding);\n res.setHeader('Content-Type', PREVIEWER_CONTENT_TYPES[path.extname(name)] ?? 'application/octet-stream');\n fs.createReadStream(file).pipe(res);\n}\n\nfunction reactUnityPreviewer(folder: true | string | undefined): Plugin {\n let base = '/';\n let dir = '';\n\n return {\n name: 'reactunity:previewer',\n apply: 'serve',\n\n configResolved(config) {\n base = config.base;\n // Beside the app rather than in public/, which a build would copy into the Unity project.\n dir = path.resolve(config.root, typeof folder === 'string' ? folder : 'previewer');\n },\n\n configureServer(server) {\n const page = base + PREVIEWER_PATH;\n // Looked up per request, so a build dropped in while the server runs is picked up.\n const custom = () => fs.existsSync(path.join(dir, 'index.html'));\n\n if (typeof folder === 'string' && !custom()) {\n server.config.logger.warn(`[reactunity] no index.html in the previewer folder ${dir}, so the hosted previewer is served.`);\n }\n\n server.middlewares.use((req, res, next) => {\n const url = req.url?.split('?')[0] ?? '';\n if (url === page.slice(0, -1)) {\n res.statusCode = 302;\n res.setHeader('Location', page);\n res.end();\n } else if (!url.startsWith(page)) {\n next();\n } else if (custom()) {\n sendPreviewerFile(dir, url.slice(page.length), res);\n } else if (url === page || url === `${page}index.html`) {\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\n res.end(previewerHtml());\n } else {\n next();\n }\n });\n\n const printUrls = server.printUrls;\n server.printUrls = () => {\n printUrls();\n for (const url of server.resolvedUrls?.local ?? [])\n server.config.logger.info(` ➜ Previewer: ${new URL(PREVIEWER_PATH, url).href}`);\n };\n },\n\n transformIndexHtml() {\n return [{ tag: 'script', children: previewerRedirect(base), injectTo: 'head-prepend' }];\n },\n };\n}\n\n// Lightning CSS's `Features`. The package is Vite's dependency rather than ours, so the flags are\n// spelled out; both have held these values since the features were added.\nconst LIGHTNINGCSS_LOGICAL_PROPERTIES = 1 << 19;\nconst LIGHTNINGCSS_LIGHT_DARK = 1 << 20;\n\nfunction reactUnityConfig(options: ReactUnityOptions): Plugin {\n const assetPath = options.assetPath ?? DEFAULT_ASSET_PATH;\n let message: { level: 'info' | 'warn'; text: string } | undefined;\n\n return {\n name: 'reactunity',\n\n config(config) {\n const patch: UserConfig = {};\n\n // Neither has anything to render against: Unity is not a browser, and an error\n // overlay drawn into a page nobody looks at only hides the console message.\n if (config.devtools === undefined) patch.devtools = false;\n\n const hmr = config.server?.hmr;\n if (hmr !== false && (hmr === undefined || (typeof hmr === 'object' && hmr.overlay === undefined))) {\n patch.server = { hmr: { overlay: false } };\n }\n\n // Tailwind's own Preflight resets a document, and there is no document here. Aliasing the\n // entry is what lets an app write the one line its docs tell it to. `@tailwindcss/vite`\n // resolves `@import` through Vite's resolver, so it sees this the way an app's own CSS does.\n if (options.tailwind !== false) {\n patch.resolve = { alias: [{ find: /^tailwindcss$/, replacement: TAILWIND_ENTRY }] };\n }\n\n const build: UserConfig['build'] = {};\n\n if (config.build?.outDir === undefined) {\n const root = path.resolve(config.root ?? process.cwd());\n const project = options.unityProject ? path.resolve(root, options.unityProject) : findUnityProject(root);\n\n if (project) {\n build.outDir = path.join(project, assetPath);\n message = { level: 'info', text: `[reactunity] Unity output directory: ${build.outDir}` };\n } else {\n message = {\n level: 'warn',\n text: '[reactunity] no Unity project found above the Vite root. Set the unityProject option or build.outDir.',\n };\n }\n }\n\n // Unity resolves an asset URL through its own loaders, and a small file inlined as a\n // data: URI never reaches them the same way -- react-unity-scripts pinned the same\n // limit to 0 rather than take CRA's 10 kB.\n if (config.build?.assetsInlineLimit === undefined) build.assetsInlineLimit = 0;\n\n // ReactUnity's CSS subset is roughly a 2020 browser: no oklch, color-mix or nesting.\n // Naming an old target is what makes Lightning CSS lower them on the way out.\n if (config.build?.cssTarget === undefined) build.cssTarget = ['chrome87'];\n\n // Two things that target lowers which ReactUnity reads itself. light-dark()'s lowered form\n // only works next to a color-scheme declaration in the same sheet; a logical property becomes\n // a `:-webkit-any(:lang(ae),:lang(ar),...)` pair naming every RTL language, which parses here\n // as a custom state and so never matches -- where `border-start-start-radius` is resolved\n // against the element's own direction. Only the radii reach that lowering at chrome87, the\n // rest of the logical properties being older than it.\n if (config.css?.lightningcss?.exclude === undefined) {\n patch.css = { lightningcss: { exclude: LIGHTNINGCSS_LIGHT_DARK | LIGHTNINGCSS_LOGICAL_PROPERTIES } };\n }\n\n // Vite's own emptying would take the .meta files with it, and warns about an outDir\n // outside the root besides. The clean plugin below does the job instead.\n if (options.clean !== false && config.build?.emptyOutDir === undefined) build.emptyOutDir = false;\n\n // Library mode names its own output, and an entryFileNames here would override it.\n const output = config.build?.rolldownOptions?.output ?? config.build?.rollupOptions?.output;\n if (!options.hashFileNames && output === undefined && !config.build?.lib) {\n const dir = config.build?.assetsDir ?? 'assets';\n build.rolldownOptions = {\n output: {\n entryFileNames: `${dir}/[name].js`,\n chunkFileNames: `${dir}/[name].js`,\n // Doubled on purpose. Unity keys a resource on its path minus the last extension, so\n // index.js and index.css both answer to `assets/index` and asking for one can hand you\n // the other. index.css.css keeps its type in the name it is looked up by.\n assetFileNames: `${dir}/[name][extname][extname]`,\n },\n };\n }\n\n if (Object.keys(build).length) patch.build = build;\n\n return patch;\n },\n\n configResolved(config) {\n // The config hook has no logger, so anything it decided is reported from here.\n if (message) config.logger[message.level](message.text);\n message = undefined;\n },\n };\n}\n\nfunction reactUnityClean(options: ReactUnityOptions): Plugin {\n const cleaned = new Set<string>();\n let written = false;\n let outDir = '';\n let root = '';\n let write = true;\n let logger: { warn: (message: string) => void } | undefined;\n\n return {\n name: 'reactunity:clean',\n apply: 'build',\n\n configResolved(config) {\n root = config.root;\n logger = config.logger;\n write = config.build.write !== false;\n outDir = path.resolve(config.root, config.build.outDir);\n },\n\n // Before renderStart, which is where Vite empties the outDir and copies publicDir\n // into it -- cleaning any later would delete files this build had just put there.\n buildStart() {\n if (options.clean === false || !write || cleaned.has(outDir)) return;\n cleaned.add(outDir);\n\n const unsafe = unsafeOutDirReason(outDir, root);\n if (unsafe) {\n logger?.warn(`[reactunity] not cleaning ${outDir} because ${unsafe}.`);\n return;\n }\n\n cleanOutDir(outDir, options.preserve);\n },\n\n // Only on success: closeBundle runs after a failed build too, and sweeping then\n // would delete every meta the clean had just set aside -- losing the GUIDs of files\n // the next successful build brings straight back.\n writeBundle() {\n written = true;\n },\n\n closeBundle() {\n // Cleared rather than kept, so a watch rebuild cleans again.\n cleaned.delete(outDir);\n const succeeded = written;\n written = false;\n if (options.clean === false || !write || !succeeded) return;\n\n removeOrphanMetaFiles(outDir);\n },\n };\n}\n\nexport default reactUnity;\n"],"mappings":";;;;AAGA,MAAM,OAAO;;;;;;;;;;AAWb,SAAgB,YAAY,QAAgB,WAA8B,CAAC,GAAS;CAClF,IAAI,CAAC,GAAG,WAAW,MAAM,GAAG;CAG5B,SAAS,QAAQ,IADA,IAAI,SAAS,KAAK,UAAU,KAAK,QAAQ,QAAQ,KAAK,CAAC,CACpD,CAAC;AACvB;AAGA,SAAS,SAAS,KAAa,MAA4B;CACzD,IAAI,YAAY;CAEhB,KAAK,MAAM,SAAS,GAAG,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAAG;EAChE,MAAM,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI;EAEtC,IAAI,KAAK,IAAI,IAAI,KAAK,MAAM,KAAK,SAA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AAO,MAAM;GACrB,MAAM,YAAY;GAClB,UAAU;GACV,IAAI,QAAQ,UAAU,SAAS,CAAC,SAAS,CAAC,WAAW;GAErD,sBAAsB,MAAM;EAC9B;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactunity/renderer",
3
- "version": "0.27.0",
3
+ "version": "0.27.2",
4
4
  "description": "React renderer for Unity3D",
5
5
  "types": "dist/index.d.ts",
6
6
  "typings": "dist/index.d.ts",
@@ -65,7 +65,7 @@
65
65
  }
66
66
  },
67
67
  "devDependencies": {
68
- "@reactunity/scripts": "^0.27.0",
68
+ "@reactunity/scripts": "^0.27.2",
69
69
  "@types/node": "^26.4.1",
70
70
  "@types/react-reconciler": "^0.33.0",
71
71
  "react-unity-webgl": "^10.2.0",