From 722ae1228428c0e930bf2d60bba886111ccacb5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 26 Jun 2024 21:56:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=88=E4=BA=8E=E8=83=BD=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 13 +++++++++++++ package.json | 2 ++ src/editorTable/EXCEL/excelExporter.ts | 15 ++++++++------- src/extension.ts | 7 +++++++ tsconfig.json | 16 +++++++--------- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 149b7f3..6a716e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "fs-extra": "^11.2.0", "iconv-lite": "^0.6.3", "jszip": "^3.10.1", + "module-alias": "2.2.3", "uuid": "^9.0.1", "winreg": "^1.2.5" }, @@ -22,6 +23,7 @@ "@types/exceljs": "^1.3.0", "@types/fs-extra": "^11.0.4", "@types/mocha": "^10.0.3", + "@types/module-alias": "^2.0.4", "@types/node": "^18.19.18", "@types/uuid": "^9.0.8", "@types/vscode": "^1.83.0", @@ -299,6 +301,12 @@ "integrity": "sha512-RsOPImTriV/OE4A9qKjMtk2MnXiuLLbcO3nCXK+kvq4nr0iMfFgpjaX3MPLb6f7+EL1FGSelYvuJMV6REH+ZPQ==", "dev": true }, + "node_modules/@types/module-alias": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@types/module-alias/-/module-alias-2.0.4.tgz", + "integrity": "sha512-5+G/QXO/DvHZw60FjvbDzO4JmlD/nG5m2/vVGt25VN1eeP3w2bCoks1Wa7VuptMPM1TxJdx6RjO70N9Fw0nZPA==", + "dev": true + }, "node_modules/@types/node": { "version": "18.19.18", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.18.tgz", @@ -2472,6 +2480,11 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, + "node_modules/module-alias": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.3.tgz", + "integrity": "sha512-23g5BFj4zdQL/b6tor7Ji+QY4pEfNH784BMslY9Qb0UnJWRAt+lQGLYmRaM0KDBwIG23ffEBELhZDP2rhi9f/Q==" + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", diff --git a/package.json b/package.json index ca09a32..8dc7d0b 100644 --- a/package.json +++ b/package.json @@ -452,6 +452,7 @@ "fs-extra": "^11.2.0", "iconv-lite": "^0.6.3", "jszip": "^3.10.1", + "module-alias": "2.2.3", "uuid": "^9.0.1", "winreg": "^1.2.5" }, @@ -459,6 +460,7 @@ "@types/exceljs": "^1.3.0", "@types/fs-extra": "^11.0.4", "@types/mocha": "^10.0.3", + "@types/module-alias": "^2.0.4", "@types/node": "^18.19.18", "@types/uuid": "^9.0.8", "@types/vscode": "^1.83.0", diff --git a/src/editorTable/EXCEL/excelExporter.ts b/src/editorTable/EXCEL/excelExporter.ts index d400c8d..1070295 100644 --- a/src/editorTable/EXCEL/excelExporter.ts +++ b/src/editorTable/EXCEL/excelExporter.ts @@ -94,14 +94,15 @@ export class excelExporter extends tableExpoter{ try { this.importRules = []; // 读取目录中的所有.mjs文件 - const files = fs.readdirSync(this.rulePath.fsPath).filter(file => file.endsWith('.mjs')); + const files = fs.readdirSync(this.rulePath.fsPath).filter(file => file.endsWith('.js')); for (const file of files) { let src = vscode.Uri.joinPath(this.rulePath, file); - let tar = vscode.Uri.joinPath(vscode.Uri.file(__dirname+'../../EXCEL'), file); - fs.copySync(src.fsPath, tar.fsPath, { overwrite: true }); - let filePath = './' + file; - const dynamicPath = `${filePath}?t=${new Date().getTime()}`; // 使用不同的动态路径 - let ImportRulesModule = await import(dynamicPath); + //let tar = vscode.Uri.joinPath(vscode.Uri.file(__dirname+'../../EXCEL'), file); + //fs.copySync(src.fsPath, tar.fsPath, { overwrite: true }); + //let filePath = './' + file; + //const dynamicPath = `${filePath}?t=${new Date().getTime()}`; // 使用不同的动态路径 + delete require.cache[src.fsPath]; + let ImportRulesModule = require(src.fsPath); for(let ruleName in ImportRulesModule){ if(ImportRulesModule[ruleName] instanceof ImportRule){ this.importRules.push(ImportRulesModule[ruleName]); @@ -122,4 +123,4 @@ export class excelExporter extends tableExpoter{ } return {}; } -} \ No newline at end of file +} diff --git a/src/extension.ts b/src/extension.ts index 019de09..a8dccf7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,3 +1,9 @@ +import moduleAlias from 'module-alias'; + +moduleAlias.addAliases({ + 'y3helper': __dirname + '/y3helper' +}); + import * as fs from 'fs'; import * as tools from "./tools"; import * as vscode from 'vscode'; @@ -22,6 +28,7 @@ import { excelExporter } from './editorTable/EXCEL/excelExporter'; import * as debug from './debug'; import { EditorLauncher } from './launchEditor'; + class Helper { private context: vscode.ExtensionContext; diff --git a/tsconfig.json b/tsconfig.json index ee519b5..20cc107 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,20 +7,18 @@ "lib": [ "ES2022" ], + "baseUrl": ".", "sourceMap": true, "rootDir": "src", - "strict": true /* enable all strict type-checking options */ - /* Additional Checks */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ + "strict": true, + "paths": { + "y3helper": ["./src/y3helper"], + }, }, - //"include": [ - // "src/**/*.ts" - //] // 忽略对template/excel/importRules.ts的编译 因为它只是个模板 生成给用户用 "exclude": [ - "template/excel" + "template", + "tmp", ] }