From b26c2458afd5a02db517e2dd9bd40a0f98a22f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 29 Jul 2024 16:01:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E8=A6=81=E6=89=8B=E5=8A=A8=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E4=BD=BF=E7=94=A8=E9=83=A8=E5=88=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 2 +- src/launchGame.ts | 1 + src/plugin/plugin.ts | 14 ++++++++++---- webpack.config.js | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 90f70a3..5dea2e8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,7 +14,7 @@ "--extensionDevelopmentPath=${workspaceFolder}" ], "outFiles": [ - "${workspaceFolder}/out/**/*.js" + "${workspaceFolder}/dist/*.js" ], "preLaunchTask": "${defaultBuildTask}" }, diff --git a/src/launchGame.ts b/src/launchGame.ts index 5b11338..43aea93 100644 --- a/src/launchGame.ts +++ b/src/launchGame.ts @@ -17,6 +17,7 @@ export class GameLauncher { } return true; } + return true; } public async launch(luaArgs?: {[key: string]: string|number|boolean}): Promise { diff --git a/src/plugin/plugin.ts b/src/plugin/plugin.ts index 24880f8..d994f3a 100644 --- a/src/plugin/plugin.ts +++ b/src/plugin/plugin.ts @@ -201,13 +201,19 @@ export class PluginManager extends vscode.Disposable { } } + private static requireCache: Record = { + 'y3-helper': y3, + 'os': require('os'), + 'path': require('path'), + 'fs': require('fs'), + 'util': require('util'), + 'vscode': vscode, + }; + private makeSandbox() { const sandBox = { require: (name: string) => { - if (name === 'y3-helper') { - return y3; - } - return require(name); + return PluginManager.requireCache[name] ?? require(name); }, module: { exports: {} }, }; diff --git a/webpack.config.js b/webpack.config.js index d927fb0..f09062e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -27,7 +27,7 @@ const config = { }, resolve: { // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader extensions: ['.ts', '.js'], - plugins: [new TsconfigPathsPlugin.TsconfigPathsPlugin({ configFile: path.resolve(__dirname, './tsconfig.json') })] + plugins: [new TsconfigPathsPlugin.TsconfigPathsPlugin({ configFile: path.resolve(__dirname, './tsconfig.json') })], }, module: { rules: [{