diff --git a/package.json b/package.json index e4c561a..7b8f405 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "serve": "tsx scripts/build.ts --serve", "watch": "tsx scripts/build.ts --watch", "lint": "eslint ./src --ext .js,.jsx,.ts,.tsx --ignore-pattern src/*", - "prepublishOnly": "if [ -d lib ]; then rm -r lib; fi && tsc && cp package.json lib && cp LICENSE lib && cp README.md lib" + "prepublishOnly": "tsx scripts/prepare.ts" }, "repository": { "type": "git", diff --git a/scripts/build.ts b/scripts/build.ts index 655795d..0dfe7e0 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -75,32 +75,6 @@ try { }); } }, - { - name: "typeMapper", - setup: async build => { - let defContent = ""; - - build.onLoad({ filter: /\.[jt]sx?/ }, async args => { - const filePath = path.relative(rootDirname, args.path); - if (filePath?.startsWith("src/core")) { - let aliased = "@pyoncord/" + filePath.slice(9, -path.extname(filePath).length); - if (aliased.endsWith("/index")) aliased = aliased.slice(0, -6); - - defContent += [ - `declare module "${aliased}" {`, - `\texport * from "./${filePath.slice(4, -path.extname(filePath).length)}";`, - "}" - ].join("\n") + "\n"; - } - - return null; - }); - - build.onEnd(async () => { - // await writeFile("./lib/defs.d.ts", defContent); - }); - } - }, { name: "swc", setup(build) { diff --git a/scripts/publish.ts b/scripts/prepare.ts similarity index 84% rename from scripts/publish.ts rename to scripts/prepare.ts index 5f0015b..5ea2ef0 100644 --- a/scripts/publish.ts +++ b/scripts/prepare.ts @@ -1,3 +1,5 @@ +// WARNING! ENTER AT YOUR OWN PERIL +// do not read the code import esbuild from "esbuild"; import { existsSync } from "fs"; import { appendFile, cp, mkdir, rm } from "fs/promises"; @@ -28,12 +30,8 @@ for (const file of [ ); } -const setup = async build => { - // const pathMap = [] as Array<{ - // alias: string, - // path: string; - // }>; - +// oh no, this is very bad +const pluginSetup = async build => { build.onLoad({ filter: /\.[jt]sx?/ }, async args => { const filePath = path.relative(rootDirname, args.path); @@ -41,11 +39,6 @@ const setup = async build => { let trimmedPath = filePath.slice(12, -path.extname(filePath).length); if (trimmedPath.endsWith("/index")) trimmedPath = trimmedPath.slice(0, -6); - // pathMap.push({ - // alias: "@pyoncord/" + trimmedPath, - // path: "core" + trimmedPath - // }); - const declarationContents = [ `declare module "${"@pyoncord/" + trimmedPath}" {`, ` export * from "./${"core/" + trimmedPath}";`, @@ -63,7 +56,6 @@ const setup = async build => { }); }; - await esbuild.build({ entryPoints: ["src/entry.js"], write: false, @@ -71,7 +63,7 @@ await esbuild.build({ external: ["~*", "*.png"], plugins: [{ name: "typeMapper", - setup + setup: pluginSetup }] });