@needle-tools/engine 3.0.1-alpha.1 → 3.0.1-alpha.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/CHANGELOG.md CHANGED
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [3.0.1-alpha] - 2023-04-11
8
8
  - Change: store static Context.Current in globalThis
9
+ - Change: alias resolve imports `@needle-tools/engine/engine` and `@needle-tools/engine/src` to lib folder
9
10
 
10
11
  ## [3.0.0-alpha] - 2023-04-05
11
12
  - Add: vite alias plugin
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "@needle-tools/engine",
3
- "version": "3.0.1-alpha.1",
3
+ "version": "3.0.1-alpha.2",
4
4
  "description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development, and can be deployed anywhere. It is flexible, extensible, and collaboration and XR come naturally.",
5
5
  "main": "dist/needle-engine.umd.cjs",
6
- "module": "lib/needle-engine.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./lib/needle-engine.js",
9
+ "require": "./dist/needle-engine.umd.cjs"
10
+ },
11
+ "./package.json": "./package.json",
12
+ "./plugins/vite/index.js": "./plugins/vite/index.js"
13
+ },
7
14
  "type": "module",
8
15
  "repository": {
9
16
  "type": "git",
@@ -102,6 +109,7 @@
102
109
  "quiet": false
103
110
  }
104
111
  },
112
+ "module": "lib/needle-engine.js",
105
113
  "typings": "lib/needle-engine.d.ts",
106
114
  "types": "lib/needle-engine.d.ts"
107
115
  }
@@ -3,12 +3,26 @@ import path from 'path';
3
3
 
4
4
  const projectDir = process.cwd() + "/";
5
5
 
6
+ /** these are alias callbacks as in the vite.alias dictionary
7
+ * the first argument is the already resoled absolute path (it is only invoked if the path was found in node_modules)
8
+ * the 2,3,4 args are the same as in vite.alias (packageName, index, path);
9
+ */
6
10
  const packages_to_resolve = {
7
- 'three': {},
8
- '@needle-tools/engine': {},
9
- 'peerjs': {},
10
- 'websocket-ts': {},
11
- 'md5': {},
11
+ // Handle all previous imports where users did import using @needle-engine/src
12
+ '@needle-tools/engine/src': (res, packageName, index, path) => {
13
+ return res + "/../lib";
14
+ },
15
+ '@needle-tools/engine': (res, packageName, index, path) => {
16
+ // Check if the import is something like @needle-tools/engine/engine/engine_utils
17
+ // in which case we want to resolve into the lib directory
18
+ if (path.startsWith("@needle-tools/engine/engine")) {
19
+ return res + "/lib";
20
+ }
21
+ },
22
+ 'three': null,
23
+ 'peerjs': null,
24
+ 'websocket-ts': null,
25
+ 'md5': null,
12
26
  }
13
27
 
14
28
  export const needleViteAlias = (command, config, userSettings) => {
@@ -28,18 +42,26 @@ export const needleViteAlias = (command, config, userSettings) => {
28
42
  const aliasDict = config.resolve.alias;
29
43
  for (const name in packages_to_resolve) {
30
44
  if (!aliasDict[name]) {
31
- addPathResolver(name, aliasDict);
45
+ addPathResolver(name, aliasDict, packages_to_resolve[name]);
32
46
  }
33
47
  }
34
48
  }
35
49
  }
36
50
 
37
- function addPathResolver(name, aliasList) {
51
+ function addPathResolver(name, aliasDict, cb) {
38
52
  // If a package at the node_modules path exist we resolve the request there
39
53
  // introduced in 89a50718c38940abb99ee16c5e029065e41d7d65
40
54
  const res = path.resolve(projectDir, 'node_modules', name);
55
+ if (typeof cb !== "function") cb = null;
41
56
  if (existsSync(res)) {
42
- aliasList[name] = () => res;
57
+ aliasDict[name] = (packageName, index, path) => {
58
+ if (cb !== null) {
59
+ const overrideResult = cb(res, packageName, index, path);
60
+ if (overrideResult !== undefined)
61
+ return overrideResult;
62
+ }
63
+ return res;
64
+ }
43
65
  }
44
66
  }
45
67
  };