From 8fc6b37aa0c3336965fba7b21f38fec60a4f2358 Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Wed, 6 Dec 2023 15:04:31 +0900 Subject: [PATCH 01/16] Fix key to registered in ModuleManager#_scriptCaches --- src/ModuleManager.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index c94511c62..8b34e17a4 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -87,12 +87,20 @@ export class ModuleManager { return this._scriptCaches[resolvedPath]._cachedValue(); } else if (this._scriptCaches.hasOwnProperty(resolvedPath + ".js")) { return this._scriptCaches[resolvedPath + ".js"]._cachedValue(); + } else if (this._scriptCaches.hasOwnProperty(resolvedPath + "/index.js")) { + return this._scriptCaches[resolvedPath + "/index.js"]._cachedValue(); } // 2.a. LOAD_AS_FILE(Y + X) - if (!targetScriptAsset) targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); + if (!targetScriptAsset) { + targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); + if (targetScriptAsset && liveAssetVirtualPathTable.hasOwnProperty(resolvedPath + ".js")) resolvedPath += ".js"; + } // 2.b. LOAD_AS_DIRECTORY(Y + X) - if (!targetScriptAsset) targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); + if (!targetScriptAsset) { + targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); + if (targetScriptAsset && liveAssetVirtualPathTable.hasOwnProperty(resolvedPath + "/index.js")) resolvedPath += "/index.js"; + } } else { // 3. LOAD_NODE_MODULES(X, dirname(Y)) // `path` は node module の名前であると仮定して探す @@ -110,13 +118,18 @@ export class ModuleManager { const dir = dirs[i]; resolvedPath = PathUtil.resolvePath(dir, path); targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); - if (targetScriptAsset) break; + if (targetScriptAsset) { + if (liveAssetVirtualPathTable.hasOwnProperty(resolvedPath + ".js")) resolvedPath += ".js"; + break; + } targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); - if (targetScriptAsset) break; + if (targetScriptAsset) { + if (liveAssetVirtualPathTable.hasOwnProperty(resolvedPath + "/index.js")) resolvedPath += "/index.js"; + break; + } } } } - if (targetScriptAsset) { // @ts-ignore if (this._scriptCaches.hasOwnProperty(resolvedPath)) return this._scriptCaches[resolvedPath]._cachedValue(); From 67d228ade29f5dabf9d0206dc8aae1ab01f57f4d Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Wed, 6 Dec 2023 15:06:37 +0900 Subject: [PATCH 02/16] Fix ModuleSpec --- src/__tests__/ModuleSpec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/__tests__/ModuleSpec.ts b/src/__tests__/ModuleSpec.ts index 096f75879..4541a488d 100644 --- a/src/__tests__/ModuleSpec.ts +++ b/src/__tests__/ModuleSpec.ts @@ -655,6 +655,16 @@ describe("test Module", () => { expect(libraryA.thisModule.loaded).toBe(true); expect(moduleUsesALibraryA).not.toBe(libraryA); + + const keys = Object.keys(manager._scriptCaches); + // require("./foo") は require("./foo/index.js") で登録されること + expect(keys.includes("script/useA.js")).toBeTruthy(); + expect(keys.includes("node_modules/moduleUsesA/index.js")).toBeTruthy(); + expect(keys.includes("node_modules/moduleUsesA/node_modules/libraryA/index.js")).toBeTruthy(); + expect(keys.includes("node_modules/moduleUsesA/node_modules/libraryA/lib/foo/foo.js")).toBeTruthy(); + expect(keys.includes("node_modules/libraryA/index.js")).toBeTruthy(); + expect(keys.includes("node_modules/libraryA")).toBeFalsy(); + done(); }); game._startLoadingGlobalAssets(); From 983fe3008c55bd4c68db70eb5d09e965a962607b Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Wed, 6 Dec 2023 15:07:01 +0900 Subject: [PATCH 03/16] Mod CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52ff15f63..5b5f837da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # ChangeLog +## Unreleased Changes +不具合修正 + * `ModuleManager#_scriptCaches` に登録するキーが `require("./foo")`と`require("./foo/index")`で別になる問題を修正 + ## 3.16.1 不具合修正 * スナップショットからの復元時、 `g.game._idx` が復元できないことがある問題を修正 From 0b809f0f4ea70c57385a44a245bed26c8377867e Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Wed, 6 Dec 2023 15:14:07 +0900 Subject: [PATCH 04/16] Fix CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b5f837da..4e66b3c3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased Changes 不具合修正 - * `ModuleManager#_scriptCaches` に登録するキーが `require("./foo")`と`require("./foo/index")`で別になる問題を修正 + * `ModuleManager#_scriptCaches` に登録するキーが同一のものを指すが別キーとして登録される問題を修正 ## 3.16.1 不具合修正 From 244aa7234e7b2cb34aac98f74c3d3cf267560ed5 Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Wed, 6 Dec 2023 15:16:46 +0900 Subject: [PATCH 05/16] Remove unnecessary fixes --- src/ModuleManager.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index 8b34e17a4..f141dc4e9 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -130,6 +130,7 @@ export class ModuleManager { } } } + if (targetScriptAsset) { // @ts-ignore if (this._scriptCaches.hasOwnProperty(resolvedPath)) return this._scriptCaches[resolvedPath]._cachedValue(); From a8490ebd5900a99bc267278043aca0e6b5f47797 Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Thu, 7 Dec 2023 18:05:56 +0900 Subject: [PATCH 06/16] Fix ModuleManager#_require() --- src/ModuleManager.ts | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index f141dc4e9..08fd4d7c9 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -68,6 +68,11 @@ export class ModuleManager { } } + if (!resolvedPath) { + resolvedPath = this._resolvePath(path, currentModule); + if (/^\//.test(resolvedPath)) resolvedPath = resolvedPath.slice(1); + } + // 1. If X is a core module, // (何もしない。コアモジュールには対応していない。ゲーム開発者は自分でコアモジュールへの依存を解決する必要がある) @@ -77,29 +82,23 @@ export class ModuleManager { if (currentModule) { if (!currentModule._virtualDirname) throw ExceptionFactory.createAssertionError("g._require: require from modules without virtualPath is not supported"); - resolvedPath = PathUtil.resolvePath(currentModule._virtualDirname, path); } else { if (!/^\.\//.test(path)) throw ExceptionFactory.createAssertionError("g._require: entry point path must start with './'"); - resolvedPath = path.substring(2); } if (this._scriptCaches.hasOwnProperty(resolvedPath)) { return this._scriptCaches[resolvedPath]._cachedValue(); } else if (this._scriptCaches.hasOwnProperty(resolvedPath + ".js")) { return this._scriptCaches[resolvedPath + ".js"]._cachedValue(); - } else if (this._scriptCaches.hasOwnProperty(resolvedPath + "/index.js")) { - return this._scriptCaches[resolvedPath + "/index.js"]._cachedValue(); } // 2.a. LOAD_AS_FILE(Y + X) if (!targetScriptAsset) { targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); - if (targetScriptAsset && liveAssetVirtualPathTable.hasOwnProperty(resolvedPath + ".js")) resolvedPath += ".js"; } // 2.b. LOAD_AS_DIRECTORY(Y + X) if (!targetScriptAsset) { targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); - if (targetScriptAsset && liveAssetVirtualPathTable.hasOwnProperty(resolvedPath + "/index.js")) resolvedPath += "/index.js"; } } else { // 3. LOAD_NODE_MODULES(X, dirname(Y)) @@ -107,7 +106,6 @@ export class ModuleManager { // akashic-engine独自仕様: 対象の `path` が `moduleMainScripts` に指定されていたらそちらを参照する if (moduleMainScripts[path]) { - resolvedPath = moduleMainScripts[path]; targetScriptAsset = liveAssetVirtualPathTable[resolvedPath]; } @@ -115,18 +113,11 @@ export class ModuleManager { const dirs = currentModule ? currentModule.paths : []; dirs.push("node_modules"); for (let i = 0; i < dirs.length; ++i) { - const dir = dirs[i]; - resolvedPath = PathUtil.resolvePath(dir, path); targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); - if (targetScriptAsset) { - if (liveAssetVirtualPathTable.hasOwnProperty(resolvedPath + ".js")) resolvedPath += ".js"; - break; - } + if (targetScriptAsset) break; + targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); - if (targetScriptAsset) { - if (liveAssetVirtualPathTable.hasOwnProperty(resolvedPath + "/index.js")) resolvedPath += "/index.js"; - break; - } + if (targetScriptAsset) break; } } } @@ -311,7 +302,7 @@ export class ModuleManager { if (pkg && typeof pkg.main === "string") { const targetPath = this._resolveAbsolutePathAsFile(PathUtil.resolvePath(resolvedPath, pkg.main), liveAssetPathTable); if (targetPath) { - return "/" + targetPath; + return /^\//.test(targetPath) ? targetPath : "/" + targetPath; } } } From a482e850bbb3012c6c8747df73cdd78b9aa60d1d Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Thu, 7 Dec 2023 18:12:53 +0900 Subject: [PATCH 07/16] Remove unnecessary fixes --- src/ModuleManager.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index 08fd4d7c9..fc1c3ba24 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -93,13 +93,9 @@ export class ModuleManager { } // 2.a. LOAD_AS_FILE(Y + X) - if (!targetScriptAsset) { - targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); - } + if (!targetScriptAsset) targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); // 2.b. LOAD_AS_DIRECTORY(Y + X) - if (!targetScriptAsset) { - targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); - } + if (!targetScriptAsset) targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); } else { // 3. LOAD_NODE_MODULES(X, dirname(Y)) // `path` は node module の名前であると仮定して探す @@ -115,7 +111,6 @@ export class ModuleManager { for (let i = 0; i < dirs.length; ++i) { targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); if (targetScriptAsset) break; - targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); if (targetScriptAsset) break; } @@ -302,7 +297,7 @@ export class ModuleManager { if (pkg && typeof pkg.main === "string") { const targetPath = this._resolveAbsolutePathAsFile(PathUtil.resolvePath(resolvedPath, pkg.main), liveAssetPathTable); if (targetPath) { - return /^\//.test(targetPath) ? targetPath : "/" + targetPath; + return targetPath; } } } From ac5149e748cc17245f70815939b069eb1359f72e Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Thu, 7 Dec 2023 19:42:30 +0900 Subject: [PATCH 08/16] Fix ModuleManager --- src/ModuleManager.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index fc1c3ba24..e2d170697 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -175,7 +175,10 @@ export class ModuleManager { } resolvedPath = PathUtil.resolvePath(currentModule._virtualDirname, path); } else { - throw ExceptionFactory.createAssertionError("g._require.resolve: couldn't resolve the moudle without currentModule"); + if (!/^\.\//.test(path)) { + throw ExceptionFactory.createAssertionError("g._require.resolve: couldn't resolve the moudle without currentModule"); + } + resolvedPath = path.substring(2); } // 2.a. LOAD_AS_FILE(Y + X) From b55db12b37751d436c8c873e92d16841ed0e72ba Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Tue, 12 Dec 2023 11:22:15 +0900 Subject: [PATCH 09/16] Add comment --- src/ModuleManager.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index e2d170697..8b3aeeef4 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -69,6 +69,7 @@ export class ModuleManager { } if (!resolvedPath) { + // _scriptCaches のキーが "foo", と "foo/index" が別扱いされないようにするため、絶対パスでキーを確定する resolvedPath = this._resolvePath(path, currentModule); if (/^\//.test(resolvedPath)) resolvedPath = resolvedPath.slice(1); } @@ -176,6 +177,7 @@ export class ModuleManager { resolvedPath = PathUtil.resolvePath(currentModule._virtualDirname, path); } else { if (!/^\.\//.test(path)) { + // エントリーポイント以外 throw ExceptionFactory.createAssertionError("g._require.resolve: couldn't resolve the moudle without currentModule"); } resolvedPath = path.substring(2); From e49892c0ba79fae0637664997c6fb1890c679ca1 Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Mon, 18 Dec 2023 18:29:12 +0900 Subject: [PATCH 10/16] Fix ModuleManager --- src/ModuleManager.ts | 59 ++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 43 deletions(-) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index 8b3aeeef4..342361f7d 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -69,52 +69,28 @@ export class ModuleManager { } if (!resolvedPath) { - // _scriptCaches のキーが "foo", と "foo/index" が別扱いされないようにするため、絶対パスでキーを確定する + // _scriptCaches のキーが "foo", と "foo/index" が別扱いされないようにするため絶対パスでキーを確定する resolvedPath = this._resolvePath(path, currentModule); if (/^\//.test(resolvedPath)) resolvedPath = resolvedPath.slice(1); } - // 1. If X is a core module, - // (何もしない。コアモジュールには対応していない。ゲーム開発者は自分でコアモジュールへの依存を解決する必要がある) - - if (/^\.\/|^\.\.\/|^\//.test(path)) { - // 2. If X begins with './' or '/' or '../' - - if (currentModule) { - if (!currentModule._virtualDirname) - throw ExceptionFactory.createAssertionError("g._require: require from modules without virtualPath is not supported"); - } else { - if (!/^\.\//.test(path)) throw ExceptionFactory.createAssertionError("g._require: entry point path must start with './'"); - } - - if (this._scriptCaches.hasOwnProperty(resolvedPath)) { - return this._scriptCaches[resolvedPath]._cachedValue(); - } else if (this._scriptCaches.hasOwnProperty(resolvedPath + ".js")) { - return this._scriptCaches[resolvedPath + ".js"]._cachedValue(); - } + if (this._scriptCaches.hasOwnProperty(resolvedPath)) { + return this._scriptCaches[resolvedPath]._cachedValue(); + } - // 2.a. LOAD_AS_FILE(Y + X) - if (!targetScriptAsset) targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); - // 2.b. LOAD_AS_DIRECTORY(Y + X) - if (!targetScriptAsset) targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); + // akashic-engine独自仕様: 対象の `path` が `moduleMainScripts` に指定されていたらそちらを参照する + if (moduleMainScripts[path]) { + targetScriptAsset = liveAssetVirtualPathTable[resolvedPath]; } else { - // 3. LOAD_NODE_MODULES(X, dirname(Y)) - // `path` は node module の名前であると仮定して探す - - // akashic-engine独自仕様: 対象の `path` が `moduleMainScripts` に指定されていたらそちらを参照する - if (moduleMainScripts[path]) { - targetScriptAsset = liveAssetVirtualPathTable[resolvedPath]; - } + targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); + } - if (!targetScriptAsset) { - const dirs = currentModule ? currentModule.paths : []; - dirs.push("node_modules"); - for (let i = 0; i < dirs.length; ++i) { - targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); - if (targetScriptAsset) break; - targetScriptAsset = this._findAssetByPathAsDirectory(resolvedPath, liveAssetVirtualPathTable); - if (targetScriptAsset) break; - } + if (!targetScriptAsset) { + const dirs = currentModule ? currentModule.paths : []; + dirs.push("node_modules"); + for (let i = 0; i < dirs.length; ++i) { + targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); + if (targetScriptAsset) break; } } @@ -176,10 +152,7 @@ export class ModuleManager { } resolvedPath = PathUtil.resolvePath(currentModule._virtualDirname, path); } else { - if (!/^\.\//.test(path)) { - // エントリーポイント以外 - throw ExceptionFactory.createAssertionError("g._require.resolve: couldn't resolve the moudle without currentModule"); - } + if (!/^\.\//.test(path)) throw ExceptionFactory.createAssertionError("g._require: entry point path must start with './'"); resolvedPath = path.substring(2); } From 7b87b6863580367c2a24266bbcb7c66e3506999c Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Wed, 20 Dec 2023 14:44:09 +0900 Subject: [PATCH 11/16] Fix ModuleManager --- src/ModuleManager.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index 342361f7d..a772a3fc7 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -69,8 +69,8 @@ export class ModuleManager { } if (!resolvedPath) { - // _scriptCaches のキーが "foo", と "foo/index" が別扱いされないようにするため絶対パスでキーを確定する resolvedPath = this._resolvePath(path, currentModule); + // 戻り値は先頭に "/" が付くので削除している。( moduleMainScripts を参照して返される値には先頭に "/" は付かない) if (/^\//.test(resolvedPath)) resolvedPath = resolvedPath.slice(1); } @@ -85,15 +85,6 @@ export class ModuleManager { targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); } - if (!targetScriptAsset) { - const dirs = currentModule ? currentModule.paths : []; - dirs.push("node_modules"); - for (let i = 0; i < dirs.length; ++i) { - targetScriptAsset = this._findAssetByPathAsFile(resolvedPath, liveAssetVirtualPathTable); - if (targetScriptAsset) break; - } - } - if (targetScriptAsset) { // @ts-ignore if (this._scriptCaches.hasOwnProperty(resolvedPath)) return this._scriptCaches[resolvedPath]._cachedValue(); From c2edc5a3e666bb7e4f879012c67fd3c7691e1618 Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Wed, 20 Dec 2023 14:46:14 +0900 Subject: [PATCH 12/16] Fix ModuleSpec --- src/__tests__/ModuleSpec.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/__tests__/ModuleSpec.ts b/src/__tests__/ModuleSpec.ts index 4541a488d..65175c839 100644 --- a/src/__tests__/ModuleSpec.ts +++ b/src/__tests__/ModuleSpec.ts @@ -946,4 +946,35 @@ describe("test Module", () => { } }); }); + + it("_resolveAbsolutePathAsDirectory", done => { + const game = new Game({ width: 320, height: 320, main: "", assets: {} }); + const pkgJsonAsset = game.resourceFactory.createTextAsset("foopackagejson", "foo/package.json"); + const liveAssetPathTable = { + "foo/root.js": game.resourceFactory.createScriptAsset("root", "/foo/root.js"), + "foo/package.json": pkgJsonAsset, + "bar/index.js": game.resourceFactory.createScriptAsset("barindex", "/bar/index.js"), + "zoo/roo/notMain.js": game.resourceFactory.createScriptAsset("zooRooNotMain", "/zoo/roo/notMain.js") + }; + const manager = game._moduleManager; + game.resourceFactory.scriptContents = { + "foo/package.json": '{ "main": "root.js" }' + }; + + pkgJsonAsset._load({ + _onAssetError: e => { + throw e; + }, + _onAssetLoad: () => { + try { + expect(manager._resolveAbsolutePathAsDirectory("foo", liveAssetPathTable)).toBe("/foo/root.js"); + expect(manager._resolveAbsolutePathAsDirectory("bar", liveAssetPathTable)).toBe("/bar/index.js"); + expect(manager._resolveAbsolutePathAsDirectory("zoo/roo", liveAssetPathTable)).toBeNull(); + expect(manager._resolveAbsolutePathAsDirectory("hoge", liveAssetPathTable)).toBeNull(); + } finally { + done(); + } + } + }); + }); }); From 8cbdb62ad579ad1d89075730b3f0be447a4dea4f Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Thu, 21 Dec 2023 13:03:30 +0900 Subject: [PATCH 13/16] Fix ModuleManager, ModuleSpec --- src/ModuleManager.ts | 4 +++- src/__tests__/ModuleSpec.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index a772a3fc7..17770f6b8 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -143,7 +143,9 @@ export class ModuleManager { } resolvedPath = PathUtil.resolvePath(currentModule._virtualDirname, path); } else { - if (!/^\.\//.test(path)) throw ExceptionFactory.createAssertionError("g._require: entry point path must start with './'"); + if (!/^\.\//.test(path)) { + throw ExceptionFactory.createAssertionError("g._require.resolve: entry point path must start with './'"); + } resolvedPath = path.substring(2); } diff --git a/src/__tests__/ModuleSpec.ts b/src/__tests__/ModuleSpec.ts index 65175c839..28f948e21 100644 --- a/src/__tests__/ModuleSpec.ts +++ b/src/__tests__/ModuleSpec.ts @@ -657,12 +657,12 @@ describe("test Module", () => { expect(moduleUsesALibraryA).not.toBe(libraryA); const keys = Object.keys(manager._scriptCaches); - // require("./foo") は require("./foo/index.js") で登録されること expect(keys.includes("script/useA.js")).toBeTruthy(); expect(keys.includes("node_modules/moduleUsesA/index.js")).toBeTruthy(); expect(keys.includes("node_modules/moduleUsesA/node_modules/libraryA/index.js")).toBeTruthy(); expect(keys.includes("node_modules/moduleUsesA/node_modules/libraryA/lib/foo/foo.js")).toBeTruthy(); expect(keys.includes("node_modules/libraryA/index.js")).toBeTruthy(); + // node_modules/libraryA が node_modules/libraryA/index.js として登録されていることを確認 expect(keys.includes("node_modules/libraryA")).toBeFalsy(); done(); From f23e10f09c84ed290f22383813d890202bfab0b9 Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Thu, 21 Dec 2023 13:07:42 +0900 Subject: [PATCH 14/16] Bump patch version, Mod CHANGELOG --- CHANGELOG.md | 4 ++-- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a008e13..6b8fd8734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # ChangeLog -## Unreleased Changes +## 3.16.4 不具合修正 - * `ModuleManager#_scriptCaches` に登録するキーが同一のものを指すが別キーとして登録される問題を修正 + * `ModuleManager#_scriptCaches` に登録するキーが `require("./foo")` と `require("./foo/index")` のように同一のものを指すが別キーとして登録される問題を修正 ## 3.16.3 * 3.16.2 の不具合回避のため 3.16.1 と同じ内容にリバート diff --git a/package-lock.json b/package-lock.json index 5fab1a9bb..fe7ed94b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@akashic/akashic-engine", - "version": "3.16.3", + "version": "3.16.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@akashic/akashic-engine", - "version": "3.16.3", + "version": "3.16.4", "license": "MIT", "dependencies": { "@akashic/game-configuration": "~2.0.0", diff --git a/package.json b/package.json index 690f49c91..2eb0094aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@akashic/akashic-engine", - "version": "3.16.3", + "version": "3.16.4", "description": "The core library of Akashic Engine", "main": "index.js", "dependencies": { From a555d1d2ca7e026e7beff57300ed68e584282535 Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Tue, 26 Dec 2023 13:02:27 +0900 Subject: [PATCH 15/16] Remove unused _findAssetByPathAsDirectory() --- src/ModuleManager.ts | 28 ---------------------------- src/__tests__/ModuleSpec.ts | 31 ------------------------------- 2 files changed, 59 deletions(-) diff --git a/src/ModuleManager.ts b/src/ModuleManager.ts index 17770f6b8..2e1cb0dbb 100644 --- a/src/ModuleManager.ts +++ b/src/ModuleManager.ts @@ -205,34 +205,6 @@ export class ModuleManager { return undefined; } - /** - * 与えられたパス文字列がディレクトリパスであると仮定して、対応するアセットを探す。 - * 見つかった場合そのアセットを、そうでない場合 `undefined` を返す。 - * 通常、ゲーム開発者がファイルパスを扱うことはなく、このメソッドを呼び出す必要はない。 - * ディレクトリ内に package.json が存在する場合、package.json 自体もアセットとして - * `liveAssetPathTable` から参照可能でなければならないことに注意。 - * - * @ignore - * @param resolvedPath パス文字列 - * @param liveAssetPathTable パス文字列のプロパティに対応するアセットを格納したオブジェクト - */ - _findAssetByPathAsDirectory(resolvedPath: string, liveAssetPathTable: { [key: string]: OneOfAsset }): OneOfAsset | undefined { - let path: string; - path = resolvedPath + "/package.json"; - const pkgJsonAsset = liveAssetPathTable[path]; - // liveAssetPathTable[path] != null だけではpathと同名のprototypeプロパティがある場合trueになってしまうので hasOwnProperty() を利用 - if (liveAssetPathTable.hasOwnProperty(path) && pkgJsonAsset.type === "text") { - const pkg = JSON.parse(pkgJsonAsset.data); - if (pkg && typeof pkg.main === "string") { - const asset = this._findAssetByPathAsFile(PathUtil.resolvePath(resolvedPath, pkg.main), liveAssetPathTable); - if (asset) return asset; - } - } - path = resolvedPath + "/index.js"; - if (liveAssetPathTable.hasOwnProperty(path)) return liveAssetPathTable[path]; - return undefined; - } - /** * 与えられたパス文字列がファイルパスであると仮定して、対応するアセットの絶対パスを解決する。 * アセットが存在した場合はそのパスを、そうでない場合 `null` を返す。 diff --git a/src/__tests__/ModuleSpec.ts b/src/__tests__/ModuleSpec.ts index 28f948e21..ca75d7ba0 100644 --- a/src/__tests__/ModuleSpec.ts +++ b/src/__tests__/ModuleSpec.ts @@ -916,37 +916,6 @@ describe("test Module", () => { expect(manager._findAssetByPathAsFile("zoo/roo.js", liveAssetPathTable)).toBe(undefined); }); - it("_findAssetByPathDirectory", done => { - const game = new Game({ width: 320, height: 320, main: "", assets: {} }); - const pkgJsonAsset = game.resourceFactory.createTextAsset("foopackagejson", "foo/package.json"); - const liveAssetPathTable = { - "foo/root.js": game.resourceFactory.createScriptAsset("root", "/foo/root.js"), - "foo/package.json": pkgJsonAsset, - "foo/index.js": game.resourceFactory.createScriptAsset("fooindex", "/foo/index.js"), - "bar/index.js": game.resourceFactory.createScriptAsset("barindex", "/bar/index.js"), - "zoo/roo/notMain.js": game.resourceFactory.createScriptAsset("zooRooNotMain", "/zoo/roo/notMain.js") - }; - const manager = game._moduleManager; - game.resourceFactory.scriptContents = { - "foo/package.json": '{ "main": "root.js" }' - }; - pkgJsonAsset._load({ - _onAssetError: e => { - throw e; - }, - _onAssetLoad: () => { - try { - expect(manager._findAssetByPathAsDirectory("foo", liveAssetPathTable)).toBe(liveAssetPathTable["foo/root.js"]); - expect(manager._findAssetByPathAsDirectory("bar", liveAssetPathTable)).toBe(liveAssetPathTable["bar/index.js"]); - expect(manager._findAssetByPathAsDirectory("zoo/roo", liveAssetPathTable)).toBe(undefined); - expect(manager._findAssetByPathAsDirectory("tee", liveAssetPathTable)).toBe(undefined); - } finally { - done(); - } - } - }); - }); - it("_resolveAbsolutePathAsDirectory", done => { const game = new Game({ width: 320, height: 320, main: "", assets: {} }); const pkgJsonAsset = game.resourceFactory.createTextAsset("foopackagejson", "foo/package.json"); From 274e2c85c2e6994ebbd8bbb635f4b2d37d9de2a2 Mon Sep 17 00:00:00 2001 From: shinobu-takahashi Date: Tue, 26 Dec 2023 13:03:29 +0900 Subject: [PATCH 16/16] Mod CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b8fd8734..6bb2b081a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 3.16.4 不具合修正 - * `ModuleManager#_scriptCaches` に登録するキーが `require("./foo")` と `require("./foo/index")` のように同一のものを指すが別キーとして登録される問題を修正 + * `require()` で末尾の "index" や "index.js" を省略する表記としない表記を混在させた時、スクリプトが複数回評価される問題を修正 ## 3.16.3 * 3.16.2 の不具合回避のため 3.16.1 と同じ内容にリバート