Needle Engine

Changes between version 3.7.5-beta and 3.7.6-beta
Files changed (4) hide show
  1. plugins/vite/index.js +4 -1
  2. src/engine-components/AnimationUtils.ts +1 -1
  3. plugins/types/userconfig.d.ts +3 -0
  4. plugins/vite/vite-4.4-hack.js +30 -0
plugins/vite/index.js CHANGED
@@ -37,7 +37,9 @@
37
37
  import { needleDependencyWatcher } from "./dependency-watcher.js";
38
38
  export { needleDependencyWatcher } from "./dependency-watcher.js";
39
39
 
40
+ import { vite_4_4_hack } from "./vite-4.4-hack.js";
40
41
 
42
+
41
43
  export * from "./gzip.js";
42
44
  export * from "./config.js";
43
45
 
@@ -65,7 +67,8 @@
65
67
  needleTransformCodegen(command, config, userSettings),
66
68
  needleDrop(command, config, userSettings),
67
69
  needlePeerjs(command, config, userSettings),
68
- needleDependencyWatcher(command, config, userSettings)
70
+ needleDependencyWatcher(command, config, userSettings),
71
+ vite_4_4_hack(command, config, userSettings)
69
72
  ];
70
73
  array.push(await editorConnection(command, config, userSettings, array));
71
74
  return array;
src/engine-components/AnimationUtils.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  import { Animator } from "./Animator";
5
5
  import { Animation } from "./Animation";
6
6
  import { GameObject } from "./Component";
7
- import { PlayableDirector } from "./api";
7
+ import { PlayableDirector } from "./timeline/PlayableDirector";
8
8
 
9
9
  ContextRegistry.registerCallback(ContextEvent.ContextCreated, args => {
10
10
  const autoplay = args.context.domElement.getAttribute("autoplay");
plugins/types/userconfig.d.ts CHANGED
@@ -22,6 +22,9 @@
22
22
  noReload: boolean;
23
23
  noCodegenTransform: boolean;
24
24
 
25
+ /** required for @serializable https://github.com/vitejs/vite/issues/13736 */
26
+ vite44Hack: boolean;
27
+
25
28
  /** set to true to disable poster generation */
26
29
  noPoster?: boolean;
27
30
  // posterFormat?: "image/webp";// | "image/png";
plugins/vite/vite-4.4-hack.js ADDED
@@ -0,0 +1,30 @@
1
+ import path from 'path';
2
+ import { readFileSync, writeFileSync } from 'fs';
3
+ import { exec, execSync } from 'child_process';
4
+
5
+ /**
6
+ * @param {import('../types').userSettings} userSettings
7
+ */
8
+ export const vite_4_4_hack = (command, config, userSettings) => {
9
+ if (userSettings.vite44Hack !== true) return;
10
+ return {
11
+ name: "needle-vite-4.4-hack",
12
+ async configureServer(server) {
13
+ const dir = process.cwd();
14
+ const packageJsonPath = path.join(dir, "package.json");
15
+ const currentPackageJson = readFileSync(packageJsonPath, "utf8");
16
+ if (currentPackageJson.includes('"vite": "^4.3.4"')) {
17
+ // see https://github.com/vitejs/vite/issues/13736
18
+ console.log("Detected problematic vite version: Vite 4.4.x does currently have problems with typescript decorators. Switching to 4.3.9...")
19
+ const newPackageJson = currentPackageJson.replace('"vite": "^4.3.4"', '"vite": "<= 4.3.9"');
20
+ writeFileSync(packageJsonPath, newPackageJson, "utf8");
21
+ // stop current server
22
+ await server.close();
23
+ // re-install with the limited package version
24
+ execSync("npm install", { stdio: "inherit", cwd: dir });
25
+ // start again
26
+ execSync("npm start", { stdio: "inherit", cwd: dir });
27
+ }
28
+ },
29
+ }
30
+ }