diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 083ce51..0000000 --- a/.npmignore +++ /dev/null @@ -1,136 +0,0 @@ -# Decrease NPM bunlde size -src_old/ -test/ -docs/ -babel.config.js -babel.register.js - - -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -coverage/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test - -# parcel-bundler cache (https://parceljs.org/) -.cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and *not* Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# VS Code prettier ignore list -.prettierignore - -dev.error.js -dev.input.js -dev.output.js -dev.ts -dev.profile.json - -package-lock.json - -Cash.output.js - -ES6.output.js - -.vscode/ - -src/dev.ts - -.DS_Store - diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index b186652..0000000 --- a/babel.config.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - presets: [ - "@babel/preset-env", // For handling ES6+ syntax - "@babel/preset-typescript", // For handling TypeScript syntax - ], - plugins: [ - [ - "replace-import-extension", - { - extMapping: { ".ts": ".js" }, - }, - ], - ], -}; diff --git a/babel.register.js b/babel.register.js deleted file mode 100644 index 13ec1a6..0000000 --- a/babel.register.js +++ /dev/null @@ -1,7 +0,0 @@ -require("@babel/register")({ - extensions: [".ts", ".tsx", ".js", ".jsx"], - // Automatically merges babel.config.js for us -}); - -// Now run the main TypeScript file -require("./dev.ts"); diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 3ecbe5f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -// Export all the types from the index file -export * from "./src/index"; -export { default } from "./src/index"; - -// Export useful types -export type { - ObfuscateOptions, - ProbabilityMap, - CustomLock, - CustomStringEncoding, -} from "./src/options"; -export type { - ObfuscationResult, - ProfileData, - ProfilerCallback, - ProfilerLog, -} from "./src/obfuscationResult"; diff --git a/jest.config.js b/jest.config.js index df5f804..2e40357 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,5 @@ +const transform = require("ts-jest").createDefaultPreset().transform; + const options = [ "minify", "renameVariables", @@ -43,6 +45,7 @@ module.exports = { // Main suite: all tests except the test/features folder { displayName: "main", + transform, testPathIgnorePatterns: [ "/node_modules/", "/test/features/", @@ -52,6 +55,7 @@ module.exports = { // Feature suites: one project per OPTIONS_MATRIX entry ...OPTIONS_MATRIX.map(({ displayName, OPTIONS }) => ({ displayName: `features:${displayName}`, + transform, testMatch: ["/test/features/**/*.test.ts?(x)"], globals: { OPTIONS }, })), diff --git a/package.json b/package.json index 1b74a2e..71178f6 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,15 @@ "name": "js-confuser", "version": "2.1.2", "description": "JavaScript Obfuscation Tool.", - "main": "dist/index.js", - "types": "index.d.ts", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", "scripts": { - "build": "tsc --noEmit && babel src --out-dir dist --extensions \".ts,.tsx\"", - "dev": "node babel.register.js", + "build": "npm run typecheck && tsdown", + "dev": "tsx dev.ts", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest", "test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --coverageReporters=html", "typecheck": "tsc --noEmit", - "prepublishOnly": "npm run typecheck && npm run test && npm run build" + "prepublishOnly": "npm run test && npm run build" }, "keywords": [ "obfuscator", @@ -30,24 +30,20 @@ "lz-string": "^1.5.0" }, "devDependencies": { - "@babel/cli": "^7.24.8", - "@babel/plugin-proposal-class-properties": "^7.18.6", - "@babel/plugin-proposal-decorators": "^7.24.7", - "@babel/plugin-proposal-private-methods": "^7.18.6", - "@babel/preset-env": "^7.25.3", - "@babel/preset-typescript": "^7.24.7", - "@babel/register": "^7.24.6", - "@eslint/js": "^9.9.0", - "@types/babel__core": "^7.20.5", - "@types/jest": "^29.5.14", + "@types/jest": "^30.0.0", "@types/node": "^22.2.0", - "babel-plugin-replace-import-extension": "^1.1.5", "cross-env": "^10.1.0", "globals": "^15.9.0", - "jest": "^29.7.0", + "jest": "^30.4.2", + "ts-jest": "^29.4.11", + "tsdown": "^0.22.2", + "tsx": "^4.22.4", "typescript": "^5.5.4", "typescript-eslint": "^8.1.0" }, + "files": [ + "dist" + ], "repository": { "type": "git", "url": "https://github.com/MichaelXF/js-confuser" diff --git a/test/code/AES.test.js b/test/code/AES.test.ts similarity index 96% rename from test/code/AES.test.js rename to test/code/AES.test.ts index 2767362..634c244 100644 --- a/test/code/AES.test.js +++ b/test/code/AES.test.ts @@ -1,4 +1,4 @@ -import { readFileSync, writeFileSync } from "fs"; +import { readFileSync } from "fs"; import { join } from "path"; import JsConfuser from "../../src/index"; import { ok } from "assert"; @@ -21,7 +21,7 @@ test("Variant #1: AES-JS on 'High' Preset", async () => { eval(code); // Module.exports is now AES-JS - var aesjs = module.exports; + var aesjs = module.exports as Record; // Ensure that the module is properly loaded expect(typeof aesjs).toStrictEqual("object"); diff --git a/test/code/ES6.test.ts b/test/code/ES6.test.ts index aeae1c7..fde5d0e 100644 --- a/test/code/ES6.test.ts +++ b/test/code/ES6.test.ts @@ -1,4 +1,4 @@ -import { readFileSync, writeFileSync } from "fs"; +import { readFileSync } from "fs"; import { join } from "path"; import JsConfuser from "../../src/index"; @@ -38,7 +38,7 @@ test("Variant #1: ES6 code on High Preset", async () => { preserveFunctionLength: true, }); - const TEST_OUTPUT = {}; + let TEST_OUTPUT = {}; eval(code); expect(TEST_OUTPUT).toStrictEqual(EXPECTED_RESULT); }); @@ -61,7 +61,7 @@ test("Variant #2: ES6 code on High Preset + RGF + Self Defending + Tamper Protec // let newCode = `var TEST_OUTPUT;\n${code}\n\nconsole.log(TEST_OUTPUT);`; // writeFileSync("./dev.output.js", newCode, "utf-8"); - const TEST_OUTPUT = {}; + let TEST_OUTPUT = {}; eval(code); expect(TEST_OUTPUT).toStrictEqual(EXPECTED_RESULT); }); diff --git a/test/code/StrictMode.test.js b/test/code/StrictMode.test.ts similarity index 80% rename from test/code/StrictMode.test.js rename to test/code/StrictMode.test.ts index d5229a6..fd06173 100644 --- a/test/code/StrictMode.test.js +++ b/test/code/StrictMode.test.ts @@ -2,13 +2,13 @@ import { readFileSync } from "fs"; import { join } from "path"; import JsConfuser from "../../src/index"; -var StrictMode_JS = readFileSync( +const StrictMode_JS = readFileSync( join(__dirname, "./StrictMode.src.js"), "utf-8" ); test("Variant #1: StrictMode on High Preset", async () => { - var { code: output } = await JsConfuser.obfuscate(StrictMode_JS, { + const { code: output } = await JsConfuser.obfuscate(StrictMode_JS, { target: "node", preset: "high", pack: true, @@ -18,9 +18,7 @@ test("Variant #1: StrictMode on High Preset", async () => { globalConcealing: (globalName) => globalName != "TEST_OUTPUT", }); - //writeFileSync("./dev.output.js", output); - - var TEST_OUTPUT = {}; + const TEST_OUTPUT = {} as Record; eval(output); diff --git a/tsconfig.json b/tsconfig.json index afbebf7..3a18ec9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,10 +3,10 @@ "target": "esnext", "module": "nodenext", "outDir": "./dist", - "rootDir": "./", "strict": false, - "noEmit": true, "types": ["node", "jest"], - "allowImportingTsExtensions": true - } + "allowImportingTsExtensions": true, + "isolatedModules": true + }, + "include": ["./src/**/*"] } diff --git a/tsdown.config.ts b/tsdown.config.ts new file mode 100644 index 0000000..28b5cb9 --- /dev/null +++ b/tsdown.config.ts @@ -0,0 +1,7 @@ +module.exports = require("tsdown").defineConfig({ + format: ["cjs"], + outExtensions: () => ({ js: ".js" }), + outputOptions: { + exports: "named", + }, +});