@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
40 lines (38 loc) • 1.95 kB
JavaScript
import path from 'path';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
import { needleLog } from './logging.js';
import { getErrMessage } from '../common/errors.js';
/**
* Make sure we dont have vite 4.4.x installed when needle engine is used locally
* @param {import('../types').userSettings} userSettings
*/
export function vite_4_4_hack(command, config, userSettings) {
if (userSettings.vite44Hack === false) return;
return {
name: "needle-vite-4.4-hack",
async configureServer(server) {
try {
const dir = process.cwd();
const packageJsonPath = path.join(dir, "package.json");
if (!existsSync(packageJsonPath)) return;
const currentPackageJson = readFileSync(packageJsonPath, "utf8");
if (currentPackageJson.includes('"vite": "^4.3.4"')) {
// see https://github.com/vitejs/vite/issues/13736
needleLog("needle-vite-4.4-hack", "Detected problematic vite version: Vite 4.4.x does currently have problems with typescript decorators. Switching to 4.3.9...");
const newPackageJson = currentPackageJson.replace('"vite": "^4.3.4"', '"vite": "<= 4.3.9"');
writeFileSync(packageJsonPath, newPackageJson, "utf8");
// stop current server
await server.close();
// re-install with the limited package version
execSync("npm install", { stdio: "inherit", cwd: dir });
// start again
execSync("npm start", { stdio: "inherit", cwd: dir });
}
}
catch (err) {
needleLog("needle-vite-4.4-hack", "Could not apply Vite 4.4 compatibility workaround: " + getErrMessage(err), "warn", { dimBody: false });
}
},
}
}