Update napcat-types usage and config in plugin
Changed napcat-plugin-builtin to use workspace reference for napcat-types instead of a fixed version. Updated tsconfig to use bundler module resolution and improved Vite config plugin resolution. Enhanced napcat-types package.json exports for better type support.
This commit is contained in:
1 parent
28c9761e3d
commit
f588fdae0f
7 files changed
+55
-17
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
"description": "NapCat 内置插件",
|
"description": "NapCat 内置插件",
|
||||||
"author": "NapNeko",
|
"author": "NapNeko",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"napcat-types": "0.0.2"
|
"napcat-types": "0.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.0.1"
|
"@types/node": "^22.0.1"
|
||||||
|
|||||||
@@ -68,14 +68,7 @@ export default defineConfig({
|
|||||||
entry: 'index.ts',
|
entry: 'index.ts',
|
||||||
formats: ['es'],
|
formats: ['es'],
|
||||||
fileName: () => 'index.mjs',
|
fileName: () => 'index.mjs',
|
||||||
},
|
}
|
||||||
rollupOptions: {
|
|
||||||
external: (id) => {
|
|
||||||
if (nodeModules.includes(id)) return true;
|
|
||||||
if (id.startsWith('napcat-')) return true;
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
plugins: [nodeResolve(), copyToShellPlugin()],
|
plugins: [nodeResolve(), copyToShellPlugin()],
|
||||||
});
|
});
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"dist/**/*"
|
"dist/**/*"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"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",
|
"test": "pnpm -s exec tsc --project tsconfig.json --noEmit",
|
||||||
"publish": "cd dist && npm publish"
|
"publish": "cd dist && npm publish"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "napcat-types",
|
"name": "napcat-types",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"private": false,
|
"private": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "./napcat-types/index.d.ts",
|
"types": "./napcat-types/index.d.ts",
|
||||||
|
|||||||
@@ -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 { copyFile } from 'node:fs/promises';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
@@ -10,4 +10,8 @@ await copyFile(
|
|||||||
await copyFile(
|
await copyFile(
|
||||||
join(__dirname, 'README.md'),
|
join(__dirname, 'README.md'),
|
||||||
join(__dirname, 'dist', 'README.md')
|
join(__dirname, 'dist', 'README.md')
|
||||||
|
);
|
||||||
|
await copyFile(
|
||||||
|
join(__dirname, 'external-shims.d.ts'),
|
||||||
|
join(__dirname, 'dist', 'external-shims.d.ts')
|
||||||
);
|
);
|
||||||
@@ -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!');
|
||||||
Generated
+5
-5
@@ -223,8 +223,8 @@ importers:
|
|||||||
packages/napcat-plugin-builtin:
|
packages/napcat-plugin-builtin:
|
||||||
dependencies:
|
dependencies:
|
||||||
napcat-types:
|
napcat-types:
|
||||||
specifier: 0.0.2
|
specifier: 0.0.3
|
||||||
version: 0.0.2
|
version: 0.0.3
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^22.0.1
|
specifier: ^22.0.1
|
||||||
@@ -5445,8 +5445,8 @@ packages:
|
|||||||
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
napcat-types@0.0.2:
|
napcat-types@0.0.3:
|
||||||
resolution: {integrity: sha512-CXcuUbK8/iGTf9qeG8juCOQjVzgmudjdQi6stlxTMLv7TzYIpeAg7TAOtAdlpvL+tnFieZ2H1AYrecdlB9l68A==}
|
resolution: {integrity: sha512-YZVBvtIw7N2TRck+JcVAoZJRqcoKf9PbKhHggZ/EcQzTkqGLgu8iIgMfQnCYscgXRglYBPexpb78piaEwlVcjQ==}
|
||||||
|
|
||||||
napcat.protobuf@1.1.4:
|
napcat.protobuf@1.1.4:
|
||||||
resolution: {integrity: sha512-z7XtLSBJ/PxmYb0VD/w+eYr/X3LyGz+SZ2QejFTOczwt6zWNxy2yV1mTMTvJoc3BWkI3ESVFRxkuT6+pj1tb1Q==}
|
resolution: {integrity: sha512-z7XtLSBJ/PxmYb0VD/w+eYr/X3LyGz+SZ2QejFTOczwt6zWNxy2yV1mTMTvJoc3BWkI3ESVFRxkuT6+pj1tb1Q==}
|
||||||
@@ -12816,7 +12816,7 @@ snapshots:
|
|||||||
|
|
||||||
nanoid@3.3.11: {}
|
nanoid@3.3.11: {}
|
||||||
|
|
||||||
napcat-types@0.0.2:
|
napcat-types@0.0.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/cors': 2.8.19
|
'@types/cors': 2.8.19
|
||||||
'@types/express': 4.17.25
|
'@types/express': 4.17.25
|
||||||
|
|||||||
Reference in new issue
Block a user