diff --git a/package.json b/package.json index ba87ca1..393d786 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup-plugin-javascript-confuser", - "version": "1.0.0", + "version": "1.0.1", "description": "A Rollup Plugin for js-confuser", "main": "dist/index.cjs.js", "module": "dist/index.es.js", @@ -47,6 +47,8 @@ "tslib": "^2.8.1", "typescript": "^5.8.3" }, - "files": ["dist"], + "files": [ + "dist" + ], "packageManager": "pnpm@10.11.0" } diff --git a/src/index.ts b/src/index.ts index d94a8a5..6d6c3af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ +import anymatch, { type Matcher } from "anymatch"; import type { Plugin } from "rollup"; import Obfuscator, { type ObfuscateOptions } from "js-confuser"; -import anymatch, { type Matcher } from "anymatch"; import { defaultExcludeMatcher, defaultIncludeMatcher, @@ -13,21 +13,29 @@ export type Config = { /** * (Array|String|RegExp|Function) String to be directly matched, string with glob patterns, regular expression test, function that takes the testString as an argument and returns a truthy value if it should be matched. default: ```[/\.(jsx?|tsx?|cjs|mjs)$/]``` * [See more](https://github.com/micromatch/anymatch) - */ + + @default [/\.(jsx?|tsx?|cjs|mjs)$/] + */ include?: Matcher; /** * (Array|String|RegExp|Function) String to be directly matched, string with glob patterns, regular expression test, function that takes the testString as an argument and returns a truthy value if it should be matched. default: ```[/node_modules/, /\.nuxt/]``` * [See more](https://github.com/micromatch/anymatch) - */ + + @default [/node_modules/] + */ exclude?: Matcher; /** - * Your js-confuser options - * [See more options](https://js-confuser.com/docs/options) - */ + * Your js-confuser options + * [See more options](https://js-confuser.com/docs/options) + + @default { target: "browser", preset: "low" } + */ options?: ObfuscateOptions; /** - * Used for debugging, Print out the path of matching or excluding files - */ + * Used for debugging, Print out the path of matching or excluding files + + @default false + */ debugger?: boolean; }; @@ -54,28 +62,7 @@ export default function obfuscatorPlugin(obOptions?: Config) { return { name: "rollup-plugin-javascript-confuser", enforce: "post", - /* - async transform(src: string, id: string) { - if (anymatch(excludeMatcher, id, { dot: true })) { - consoleLog("[::plugin-javascript-confuser]::exclude", id); - return; - } - - if (anymatch(includeMatcher, id)) { - consoleLog("[::plugin-javascript-confuser]::include matched", id); - - const obfuscationResult = await obfuscate(src, options); - const result = { code: obfuscationResult.code } as { - code: string; - }; - - return result; - } - - consoleLog("[::plugin-javascript-confuser]::not matched", id); - }, - */ async generateBundle(bundleOptions, bundleObj) { for (const bundleKey of Object.keys(bundleObj)) { const bundle = bundleObj[bundleKey]; diff --git a/src/matcher.ts b/src/matcher.ts index ec67c52..5c24517 100644 --- a/src/matcher.ts +++ b/src/matcher.ts @@ -1,24 +1,14 @@ -import type { Matcher } from "anymatch"; -import anymatch from "anymatch"; import { resolve } from "node:path"; +import type { Matcher } from "anymatch"; export const defaultIncludeMatcher = [/\.(jsx?|tsx?|cjs|mjs)$/]; -export const defaultExcludeMatcher = [/node_modules/, /\.nuxt/]; +export const defaultExcludeMatcher = [/node_modules/]; export function handleMatcher(matcher: Matcher) { const matcherA = Array.isArray(matcher) ? matcher : [matcher]; - return matcherA.map((matcher) => { - if (typeof matcher !== 'string') return matcher - - return resolve('.', matcher).replace(/\\/g, "/") - }) - - // return matcherA.map((matcher: Matcher): Matcher => { - // if (typeof matcher !== "string") { - // return matcher; - // } - // return resolve(".", matcher).replace(/\\/g, "/"); - // }); + return matcherA.map((matcher) => { + if (typeof matcher !== "string") return matcher; + return resolve(".", matcher).replace(/\\/g, "/"); + }); } -