diff --git a/packages/napcat-plugin-builtin/package.json b/packages/napcat-plugin-builtin/package.json index 3d3f379f..bae9f649 100644 --- a/packages/napcat-plugin-builtin/package.json +++ b/packages/napcat-plugin-builtin/package.json @@ -6,7 +6,7 @@ "description": "NapCat 内置插件", "author": "NapNeko", "dependencies": { - "napcat-types": "0.0.2" + "napcat-types": "0.0.3" }, "devDependencies": { "@types/node": "^22.0.1" diff --git a/packages/napcat-plugin-builtin/vite.config.ts b/packages/napcat-plugin-builtin/vite.config.ts index be122e8d..36ab2c48 100644 --- a/packages/napcat-plugin-builtin/vite.config.ts +++ b/packages/napcat-plugin-builtin/vite.config.ts @@ -68,14 +68,7 @@ export default defineConfig({ entry: 'index.ts', formats: ['es'], fileName: () => 'index.mjs', - }, - rollupOptions: { - external: (id) => { - if (nodeModules.includes(id)) return true; - if (id.startsWith('napcat-')) return true; - return false; - }, - }, + } }, plugins: [nodeResolve(), copyToShellPlugin()], }); diff --git a/packages/napcat-types/package.json b/packages/napcat-types/package.json index b450c63f..166ea7f3 100644 --- a/packages/napcat-types/package.json +++ b/packages/napcat-types/package.json @@ -8,7 +8,7 @@ "dist/**/*" ], "scripts": { - "build": "tsc --project tsconfig.json && tsc-alias --project tsconfig.json --outDir dist && node ./scripts/copy-dist.mjs", + "build": "tsc --project tsconfig.json && tsc-alias --project tsconfig.json --outDir dist && node ./scripts/post-build.mjs && node ./scripts/copy-dist.mjs", "test": "pnpm -s exec tsc --project tsconfig.json --noEmit", "publish": "cd dist && npm publish" }, diff --git a/packages/napcat-types/package.public.json b/packages/napcat-types/package.public.json index 6e9a45e7..73ecb86f 100644 --- a/packages/napcat-types/package.public.json +++ b/packages/napcat-types/package.public.json @@ -1,6 +1,6 @@ { "name": "napcat-types", - "version": "0.0.2", + "version": "0.0.3", "private": false, "type": "module", "types": "./napcat-types/index.d.ts", diff --git a/packages/napcat-types/scripts/copy-dist.mjs b/packages/napcat-types/scripts/copy-dist.mjs index 4cf85167..b97159bc 100644 --- a/packages/napcat-types/scripts/copy-dist.mjs +++ b/packages/napcat-types/scripts/copy-dist.mjs @@ -1,4 +1,4 @@ -// 复制 cp README.md dist/ && cp package.public.json dist/package.json +// 复制 cp README.md dist/ && cp package.public.json dist/package.json && cp external-shims.d.ts dist/ import { copyFile } from 'node:fs/promises'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -10,4 +10,8 @@ await copyFile( await copyFile( join(__dirname, 'README.md'), join(__dirname, 'dist', 'README.md') +); +await copyFile( + join(__dirname, 'external-shims.d.ts'), + join(__dirname, 'dist', 'external-shims.d.ts') ); \ No newline at end of file diff --git a/packages/napcat-types/scripts/post-build.mjs b/packages/napcat-types/scripts/post-build.mjs new file mode 100644 index 00000000..981bf0aa --- /dev/null +++ b/packages/napcat-types/scripts/post-build.mjs @@ -0,0 +1,41 @@ +import { readdir, readFile, writeFile, rename } from 'node:fs/promises'; +import { join, extname, basename } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = fileURLToPath(new URL('../', import.meta.url)); +const distDir = join(__dirname, 'dist'); + +async function traverseDirectory (dir) { + const entries = await readdir(dir, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = join(dir, entry.name); + + if (entry.isDirectory()) { + await traverseDirectory(fullPath); + } else if (entry.isFile() && entry.name.endsWith('.d.ts')) { + await processFile(fullPath); + } + } +} + +async function processFile (filePath) { + // Read file content + let content = await readFile(filePath, 'utf-8'); + + // Replace "export declare enum" with "export enum" + content = content.replace(/export declare enum/g, 'export enum'); + + // Write back the modified content + await writeFile(filePath, content, 'utf-8'); + + // Rename .d.ts to .ts + const newPath = filePath.replace(/\.d\.ts$/, '.ts'); + await rename(filePath, newPath); + + console.log(`Processed: ${basename(filePath)} -> ${basename(newPath)}`); +} + +console.log('Starting post-build processing...'); +await traverseDirectory(distDir); +console.log('Post-build processing completed!'); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c63e3922..b46fe594 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -223,8 +223,8 @@ importers: packages/napcat-plugin-builtin: dependencies: napcat-types: - specifier: 0.0.2 - version: 0.0.2 + specifier: 0.0.3 + version: 0.0.3 devDependencies: '@types/node': specifier: ^22.0.1 @@ -5445,8 +5445,8 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true - napcat-types@0.0.2: - resolution: {integrity: sha512-CXcuUbK8/iGTf9qeG8juCOQjVzgmudjdQi6stlxTMLv7TzYIpeAg7TAOtAdlpvL+tnFieZ2H1AYrecdlB9l68A==} + napcat-types@0.0.3: + resolution: {integrity: sha512-YZVBvtIw7N2TRck+JcVAoZJRqcoKf9PbKhHggZ/EcQzTkqGLgu8iIgMfQnCYscgXRglYBPexpb78piaEwlVcjQ==} napcat.protobuf@1.1.4: resolution: {integrity: sha512-z7XtLSBJ/PxmYb0VD/w+eYr/X3LyGz+SZ2QejFTOczwt6zWNxy2yV1mTMTvJoc3BWkI3ESVFRxkuT6+pj1tb1Q==} @@ -12816,7 +12816,7 @@ snapshots: nanoid@3.3.11: {} - napcat-types@0.0.2: + napcat-types@0.0.3: dependencies: '@types/cors': 2.8.19 '@types/express': 4.17.25