diff --git a/package.json b/package.json index 002713ab..07d77c2a 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,10 @@ "@babel/cli": "^7.24.7", "@babel/core": "^7.24.7", "@babel/plugin-syntax-dynamic-import": "^7.8.3", + "@babel/plugin-syntax-top-level-await": "^7.14.5", + "@babel/plugin-transform-async-generator-functions": "^7.24.7", + "@babel/plugin-transform-async-to-generator": "^7.24.7", + "@babel/plugin-transform-modules-commonjs": "^7.24.7", "@babel/preset-env": "^7.24.7", "@babel/preset-typescript": "^7.24.7", "@types/babel__core": "^7.20.5", @@ -54,21 +58,29 @@ "typescript": "^5.4.5" }, "dependencies": { + "@rollup/plugin-commonjs": "^26.0.1", + "@rollup/plugin-json": "^6.1.0", + "@rollup/plugin-node-resolve": "^15.2.3", "@types/socket.io-client": "^3.0.0", "@yao-pkg/pkg": "^5.11.2", "bytes-formatter": "^21.6.12", "chokidar": "^3.6.0", "cli-progress": "^3.12.0", - "concurrently": "^8.2.2", + "concurrently": "^9.0.1", "esbuild": "^0.21.3", + "esbuild-node-externals": "^1.13.1", "figlet": "^1.7.0", "fs-extra": "^11.2.0", - "glob": "^10.3.15", + "glob": "^11.0.0", "gradient-string": "^2.0.2", "javascript-obfuscator": "^4.1.0", "node-fetch": "^3.3.2", "prompts": "^2.4.2", "randomstring": "^1.3.0", + "rollup": "^4.18.0", + "rollup-plugin-esbuild": "^6.1.1", + "rollup-plugin-node-externals": "^7.1.2", + "rollup-plugin-typescript-paths": "^1.5.0", "socket.io-client": "^4.7.5", "sucrase": "^3.34.0", "terser": "^5.31.1", @@ -77,5 +89,8 @@ "tsconfig-paths": "^4.2.0", "tscpaths": "^0.0.9", "yargs": "^17.7.2" + }, + "engines": { + "node": "20.x" } } diff --git a/plugins/plugin_base/src/discord/base/Client.ts b/plugins/plugin_base/src/discord/base/Client.ts index 0dc1b7ac..de73545f 100644 --- a/plugins/plugin_base/src/discord/base/Client.ts +++ b/plugins/plugin_base/src/discord/base/Client.ts @@ -53,7 +53,6 @@ export class Discord { this.timestamp = Date.now() const onAutoComplete = (autoCompleteInteraction: AutocompleteInteraction): void => { - console.log(autoCompleteInteraction.commandName) if (autoCompleteInteraction.commandName === 'config') { const config = Config.all.find((config) => config.name === autoCompleteInteraction.options.getSubcommand()) if (config?.autoComplete !== undefined) config.autoComplete(autoCompleteInteraction) diff --git a/plugins/tickets/src/discord/base/Client.ts b/plugins/tickets/src/discord/base/Client.ts index 0dc1b7ac..de73545f 100644 --- a/plugins/tickets/src/discord/base/Client.ts +++ b/plugins/tickets/src/discord/base/Client.ts @@ -53,7 +53,6 @@ export class Discord { this.timestamp = Date.now() const onAutoComplete = (autoCompleteInteraction: AutocompleteInteraction): void => { - console.log(autoCompleteInteraction.commandName) if (autoCompleteInteraction.commandName === 'config') { const config = Config.all.find((config) => config.name === autoCompleteInteraction.options.getSubcommand()) if (config?.autoComplete !== undefined) config.autoComplete(autoCompleteInteraction) diff --git a/plugins/utils/src/discord/base/Client.ts b/plugins/utils/src/discord/base/Client.ts index 0dc1b7ac..de73545f 100644 --- a/plugins/utils/src/discord/base/Client.ts +++ b/plugins/utils/src/discord/base/Client.ts @@ -53,7 +53,6 @@ export class Discord { this.timestamp = Date.now() const onAutoComplete = (autoCompleteInteraction: AutocompleteInteraction): void => { - console.log(autoCompleteInteraction.commandName) if (autoCompleteInteraction.commandName === 'config') { const config = Config.all.find((config) => config.name === autoCompleteInteraction.options.getSubcommand()) if (config?.autoComplete !== undefined) config.autoComplete(autoCompleteInteraction) diff --git a/release.ts b/release.ts index a7430c55..aa6810cd 100644 --- a/release.ts +++ b/release.ts @@ -12,9 +12,17 @@ import obfuscate from 'javascript-obfuscator' import os from 'os' import path, { basename, dirname, join } from 'path' import { cwd } from 'process' +import { rollup } from 'rollup' import { Readable } from 'stream' import { minify } from 'terser' +import communjs from "@rollup/plugin-commonjs" +import json from "@rollup/plugin-json" +import { nodeResolve } from "@rollup/plugin-node-resolve" +import esbuild from "rollup-plugin-esbuild" +import externals from "rollup-plugin-node-externals" +import { typescriptPaths } from "rollup-plugin-typescript-paths" + const SIGNATURE_LENGTH = 512 interface BuildInfo { @@ -147,9 +155,18 @@ class Build { const data = await readFile(file, { encoding: 'utf-8' }) const result = await babel.transformAsync(data, { presets: ["@babel/preset-env", "@babel/preset-typescript"], - plugins: !file.includes('node_modules') ? ["babel-plugin-transform-import-meta", "@babel/plugin-transform-modules-commonjs", "@babel/plugin-syntax-dynamic-import"] : [['babel-plugin-cjs-esm-interop', { format: 'cjs' }]], + plugins: !file.includes('node_modules') + ? [ + "babel-plugin-transform-import-meta", + "@babel/plugin-transform-modules-commonjs", + "@babel/plugin-syntax-dynamic-import", + "@babel/plugin-transform-async-generator-functions", + "@babel/plugin-syntax-top-level-await" + ] + : [ + ['babel-plugin-cjs-esm-interop', { format: 'cjs' }] + ], filename: fileName, - }); if (typeof result?.code !== 'string') continue @@ -268,6 +285,9 @@ class Build { "node_modules/**/*.node" ] } + packageJson.engines = { + node: "20.x" + } const remove = ['devDependencies', 'scripts', 'keywords', 'repository', 'bugs', 'homepage', 'type'] @@ -280,7 +300,7 @@ class Build { async install(): Promise { console.debug('\n\nInstalando Modulos...') if (existsSync(`${this.options.outBuild}/node_modules`)) execProcess(`cd ${this.options.outBuild} && rm -r node_modules`) - await execProcess(`cd ${this.options.outBuild} && npm i && npm rebuild better_sqlite3 && npm rebuild`) + await execProcess(`cd ${this.options.outBuild} && bun i`) } async clear(): Promise { @@ -299,6 +319,32 @@ class Build { this.progressBar.stop() } + async rollup() { + const bundle = await rollup({ + input: await glob(`${this.options.source}/build/esm/**/*.js`, { ignore: ['**/node_modules/**/*'] }), + logLevel: 'debug', + plugins: [ + esbuild({ target: 'node20' }), + typescriptPaths({ preserveExtensions: false }), + communjs(), + json(), + externals(), + nodeResolve() + ] + }) + + bundle.write({ + dir: 'dist', + format: 'cjs', + exports: 'named', + compact: true, + esModule: false, + dynamicImportInCjs: true, + noConflict: true, + preserveModules: true, + }) + } + async esbuild(options?: { entryPoints: string[], outfile: string }) { const packagePath = path.join(process.cwd(), `${this.options.outBuild}/package.json`) const packageJson = JSON.parse(await readFile(packagePath, { encoding: 'utf-8' })) as Record @@ -306,11 +352,10 @@ class Build { entryPoints: options?.entryPoints ?? [`${this.options.outBuild}/src/app.js`], bundle: true, minify: true, - logLevel: 'silent', + logLevel: 'debug', outfile: options?.outfile ?? `${this.options.outBuild}/bundle.cjs`, platform: 'node', - format: 'cjs' - // plugins: [] + format: 'cjs', }) await rm(path.join(process.cwd(), `${this.options.outBuild}/node_modules`), { recursive: true }) await rm(path.join(process.cwd(), `${this.options.outBuild}/src`), { recursive: true }) @@ -325,6 +370,7 @@ class Build { }) } + async pkgbuild(): Promise { const args = ['.', '--compress', 'Brotli', '--no-bytecode', '--public-packages', '"*"', '--public'] const builds: string[] = [] @@ -456,6 +502,7 @@ const archs = ['arm64', 'x64']; { command: 'compress', alias: ['-c'], rank: 5 }, { command: 'obfuscate', alias: ['-f'], rank: 6 }, { command: 'esbuild', alias: ['-esb'], rank: 7 }, + { command: 'rollup', alias: [''], rank: 7 }, { command: 'pkg', alias: [''], rank: 7 }, { command: 'sing', alias: ['-sn'], rank: 8 }, ] @@ -650,6 +697,10 @@ release [options] buildFunctions.push(async () => { await build.sign(); await build.singCheck() }) break } + case 'rollup': { + buildFunctions.push(() => build.rollup()) + break + } } } if (newArgs.find((arg) => arg.command === 'pkg')?.command !== undefined) buildFunctions.push(() => build.saveManifest()) diff --git a/test.ts b/test.ts deleted file mode 100644 index 6f3d1468..00000000 --- a/test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { readFile } from "fs/promises"; -import { join } from "path"; -import { fileURLToPath } from "url"; - -let code = await readFile('Claim.entry.js', { encoding: 'utf-8' }) -const regex = /require\("(?!\.\/)([^"]+)"\)/g - -let match; -while ((match = regex.exec(code)) !== null) { - const content = match[1]; - console.log(content) - if (content) { - const __dirname = fileURLToPath(import.meta.url) - const replacedPath = `"${join(__dirname, '../../')}node_modules/${content}"`; - const genRegex = new RegExp(`"${content}"`, 'g') - code = code.replace(genRegex, replacedPath); - } -} \ No newline at end of file