Skip to content

Commit cdfe779

Browse files
authored
Merge pull request #31 from Codefend/develop
Develop
2 parents 56dae08 + 99da5d7 commit cdfe779

23 files changed

+6144
-1155
lines changed

.cspell.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "0.1",
3+
"language": "en",
4+
"words": ["codefend", "Bundlephobia", "tsup"],
5+
"ignorePaths": [
6+
"package.json",
7+
"package-lock.json",
8+
"tsconfig.json",
9+
"node_modules/**",
10+
"examples/**/node_modules/**"
11+
]
12+
}

.eslintrc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": ["@typescript-eslint"],
5+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
6+
"rules": {},
7+
"overrides": [
8+
{
9+
"files": ["*.ts"],
10+
"rules": {
11+
"@typescript-eslint/explicit-function-return-type": 2
12+
}
13+
}
14+
]
15+
}

.github/workflows/ci.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: CI
2+
run-name: CI Workflow
3+
4+
on: [push]
5+
6+
jobs:
7+
lint:
8+
name: ⬣ ESLint
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
- uses: bahmutov/npm-install@v1
14+
- name: ⬣ ESLint
15+
run: npm run lint:check
16+
17+
audit:
18+
name: 🛡️ Audit
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-node@v4
23+
- name: 🛡️ Audit
24+
run: npm audit --audit-level=high
25+
26+
spell:
27+
name: 🈸 Spellcheck
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: actions/setup-node@v4
32+
- uses: bahmutov/npm-install@v1
33+
- name: 🈸 Spellcheck
34+
run: npm run spell:check
35+
36+
type:
37+
name: ʦ Typecheck
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: actions/setup-node@v4
42+
- uses: bahmutov/npm-install@v1
43+
- name: ʦ Typecheck
44+
run: npm run type:check
45+
46+
test:
47+
name: ⚡ Tests
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v4
51+
- uses: actions/setup-node@v4
52+
- uses: bahmutov/npm-install@v1
53+
- name: ⚡ Tests
54+
run: npm run test
55+
56+
build:
57+
name: 🚀 Build
58+
needs: [lint, audit, spell, type, test]
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v4
62+
- uses: actions/setup-node@v4
63+
- uses: bahmutov/npm-install@v1
64+
- name: 🔨 Build
65+
run: npm run build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.local
12
node_modules
23
DS_Store
34
/lib

README.md

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
# webpack-plugin-codefend
66

7+
![NPM](https://img.shields.io/npm/dt/webpack-plugin-codefend)
8+
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Codefend/webpack-plugin-codefend/ci.yaml?branch=main)
9+
![Bundlephobia](https://img.shields.io/bundlephobia/min/webpack-plugin-codefend)
10+
![Node version](https://img.shields.io/node/v/webpack-plugin-codefend)
11+
![NPM](https://img.shields.io/npm/l/webpack-plugin-codefend)
12+
713
Webpack plugin for code obfuscation based on [Codefend](https://www.npmjs.com/package/codefend)
814

915
## Installation
@@ -40,55 +46,32 @@ export default {
4046
output: ...,
4147
plugins: [
4248
new WebpackPluginCodefend({
43-
/** stats: boolean
44-
* Displays detailed stats about the obfuscated words:
45-
* e.g:
46-
* Ignored node_modules (5 times)
47-
* Predefined l_Hello -> l_Hi (2 times)
48-
* Encrypted l_a -> Ox0 (15 times)
49-
*/
50-
stats: true,
51-
52-
53-
/** prefix: string
54-
* the prefix of each variable generated.
55-
* note: the first letter of the prefix must be either an alphabet or "_" so that the variable generated be valid.
56-
*/
57-
prefix: "Ox",
58-
59-
/** predefinedWords: Array<{originalWord:string, targetWord:string}>
60-
* words that you want to obfuscate them in a static way (determined output)
61-
* {"originalWord":"l_secretVar" , "targetWord": "123456"}
62-
* note: the original word must have a prefix 'l_' to be detected in the first place so that it gets replaced.
63-
*/
64-
predefinedWords: [
65-
{
66-
originalWord: "predefined_secretword",
67-
targetWord: "123456",
68-
},
69-
],
70-
71-
/** ignoredWords: Array<string>
72-
* Words that matches the pattern to be obfuscated but should be kept as is without being obfuscated.
73-
* useful for words that are being obfuscated and causing errors when running or building the code
74-
*/
75-
ignoredWords: ["node_modules"],
76-
77-
/** regexList: Array<{name:string,value:string,flag:string}>
78-
* Regex for detecting the words to be obfuscated
79-
*/
80-
regexList: [
81-
{
82-
name: "main",
83-
value: "([a-zA-Z]+(_[a-zA-Z0-9]+)+)",
84-
flag: "g",
85-
},
86-
],
49+
transformation:{
50+
// the prefix to use for each obfuscated variable
51+
prefix: "Ox",
52+
53+
// control how a specific variable should be obfuscated
54+
static: [
55+
{
56+
from: "predefined_secret",
57+
to: "123456",
58+
},
59+
],
60+
61+
//will skip obfuscation for the following words
62+
ignore: ["node_modules"],
63+
},
64+
debug: {
65+
// to display detailed stats about the words that have been obfuscated
66+
stats: true,
67+
},
8768
}),
8869
],
8970
};
9071
```
9172

73+
For a more detailed explanation, refer to the [configuration](https://codefend.github.io/docs/references/configuration) section of the `codefend` docs.
74+
9275
### `Step 2`: Naming convention
9376

9477
In your code, `add prefixes to the words that you want Codefend to encrypt.`
@@ -102,6 +85,8 @@ In your code, `add prefixes to the words that you want Codefend to encrypt.`
10285
class l_Calculator {
10386
l_sum(l_a, l_b) {
10487
const l_results = l_a + l_b;
88+
console.log("node_modules");
89+
console.log("predefined_secret");
10590
return l_results;
10691
}
10792
}
@@ -111,6 +96,8 @@ class l_Calculator {
11196
class Ox0 {
11297
Ox1(Ox2, Ox3) {
11398
const Ox4 = Ox2 + Ox3;
99+
console.log("node_modules"); // has not been obfuscated
100+
console.log("123456"); // has transformed from "predefined_secret" to "123456"
114101
return Ox4;
115102
}
116103
}

examples/nodejs/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ npm run build
1717
node dist/bundle.js
1818
```
1919

20-
1. "node_module" has not changed as it was added to [ignoredWords](../../README.md#custom-options)
21-
2. "l_secret" became "123456" as was added to [predefinedWords](../../README.md#custom-options)
20+
1. "node_module" has not changed as it was added to [ignore](https://codefend.github.io/docs/references/configuration)
21+
2. "l_secret" became "123456" as was added to [static](https://codefend.github.io/docs/references/configuration)
2222

2323
<img src="/public/img/nodejs/run.PNG">
2424

@@ -44,7 +44,11 @@ To check the encrypted variables in the output: <kbd>Ctrl</kbd> + <kbd>f</kbd> *
4444
/*!***************************!*\
4545
!*** ./src/calculator.js ***!
4646
\***************************/
47-
/***/ (__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
47+
/***/ (
48+
__unused_webpack_module,
49+
__webpack_exports__,
50+
__webpack_require__
51+
) => {
4852
eval(
4953
'__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ "Ox4": () => (/* binding */ Ox4)\n/* harmony export */ });\nclass Ox4 {\r\n Ox5(Ox6, Ox7) {\r\n const Ox8 = Ox6 + Ox7;\r\n return Ox8;\r\n }\r\n}\r\n\n\n//# sourceURL=webpack://webpack-plugin-codefend-example/./src/calculator.js?'
5054
);
@@ -56,7 +60,11 @@ To check the encrypted variables in the output: <kbd>Ctrl</kbd> + <kbd>f</kbd> *
5660
/*!*********************!*\
5761
!*** ./src/main.js ***!
5862
\*********************/
59-
/***/ (__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
63+
/***/ (
64+
__unused_webpack_module,
65+
__webpack_exports__,
66+
__webpack_require__
67+
) => {
6068
eval(
6169
'__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ "default": () => (/* binding */ main)\n/* harmony export */ });\n/* harmony import */ var _calculator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./calculator */ "./src/calculator.js");\n\r\n\r\nconst secret = "123456";\r\nconst node_modules = "node_modules";\r\n\r\nfunction main() {\r\n const Ox12 = new _calculator__WEBPACK_IMPORTED_MODULE_0__.Ox4();\r\n const Ox8 = Ox12.Ox5(2, 3);\r\n\r\n /* 123456 -> 123456 : defined in predefinedWords inside webpack.config.js */\r\n console.log("secret: ", secret);\r\n\r\n /* node_modules -> node_modules : defined in ignoredWords inside webpack.config.js */\r\n console.log("node_modules:", node_modules);\r\n\r\n /* Ox8 -> Ox4: with prefix l_ will be obfuscated */\r\n console.log("results: ", Ox8);\r\n}\r\n\r\nmain();\r\n\n\n//# sourceURL=webpack://webpack-plugin-codefend-example/./src/main.js?'
6270
);

0 commit comments

Comments
 (0)