vue-cli-plugin-javascript-obfuscator 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +73 -73
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,92 +1,92 @@
1
1
  // @ts-nocheck
2
2
  const JavaScriptObfuscator = require('javascript-obfuscator')
3
3
 
4
- module.exports = (api) => {
5
- api.chainWebpack((config) => {
4
+ module.exports = (api, options) => {
5
+ api.chainWebpack((webpackConfig) => {
6
6
  // Get user-configured options from vue.config.js
7
- const options =
8
- api.service.projectOptions.pluginOptions.javascriptObfuscator || {}
7
+ const opts = options.pluginOptions && options.pluginOptions.javascriptObfuscator
9
8
 
10
9
  // Default values for the plugin options
11
- const assetsDir = options.assetsDir || 'static'
12
- const includes = Array.isArray(options.includes)
13
- ? options.includes
14
- : [options.includes || []]
15
- const excludes = Array.isArray(options.excludes)
16
- ? options.excludes
17
- : [options.excludes || []]
18
- const obfuscatorOptions = options.obfuscatorOptions || {}
10
+ const assetsDir = opts.assetsDir || 'static'
11
+ const includes = Array.isArray(opts.includes)
12
+ ? opts.includes
13
+ : [opts.includes || []]
14
+ const excludes = Array.isArray(opts.excludes)
15
+ ? opts.excludes
16
+ : [opts.excludes || []]
17
+ const obfuscatorOptions = opts.obfuscatorOptions || {}
19
18
 
20
- function JavascriptObfuscatorPlugin(compiler) {
21
- compiler.hooks.emit.tapAsync(
22
- 'JavascriptObfuscatorPlugin',
23
- async (compilation, callback) => {
24
- const promises = []
19
+ const JavascriptObfuscatorPlugin = {
20
+ apply: (compiler) => {
21
+ compiler.hooks.emit.tapAsync(
22
+ 'JavascriptObfuscatorPlugin',
23
+ async (compilation, callback) => {
24
+ const promises = []
25
25
 
26
- // Generate regex patterns from includes and excludes
27
- const includePatterns = includes.map((pattern) =>
28
- typeof pattern === 'string'
29
- ? new RegExp(pattern.replace('static', assetsDir))
30
- : pattern
31
- )
32
- const excludePatterns = excludes.map((pattern) =>
33
- typeof pattern === 'string'
34
- ? new RegExp(pattern.replace('static', assetsDir))
35
- : pattern
36
- )
26
+ // Generate regex patterns from includes and excludes
27
+ const includePatterns = includes.map((pattern) =>
28
+ typeof pattern === 'string'
29
+ ? new RegExp(pattern.replace('static', assetsDir))
30
+ : pattern
31
+ )
32
+ const excludePatterns = excludes.map((pattern) =>
33
+ typeof pattern === 'string'
34
+ ? new RegExp(pattern.replace('static', assetsDir))
35
+ : pattern
36
+ )
37
+
38
+ Object.keys(compilation.assets).forEach((assetName) => {
39
+ // Skip assets that don't match the include or match any of the exclude patterns
40
+ if (
41
+ includePatterns.length &&
42
+ !includePatterns.some((pattern) => pattern.test(assetName))
43
+ ) {
44
+ return
45
+ }
37
46
 
38
- Object.keys(compilation.assets).forEach((assetName) => {
39
- // Skip assets that don't match the include or match any of the exclude patterns
40
- if (
41
- includePatterns.length &&
42
- !includePatterns.some((pattern) => pattern.test(assetName))
43
- ) {
44
- return
45
- }
47
+ if (excludePatterns.some((pattern) => pattern.test(assetName))) {
48
+ console.log(`Skipping obfuscation for: ${assetName}`)
49
+ return
50
+ }
46
51
 
47
- if (excludePatterns.some((pattern) => pattern.test(assetName))) {
48
- console.log(`Skipping obfuscation for: ${assetName}`)
49
- return
50
- }
52
+ console.log(`Obfuscating: ${assetName}`)
53
+ const asset = compilation.assets[assetName]
54
+ promises.push(
55
+ new Promise((resolve, reject) => {
56
+ try {
57
+ const obfuscated = JavaScriptObfuscator.obfuscate(
58
+ asset.source(),
59
+ {
60
+ compact: true,
61
+ disableConsoleOutput: false,
62
+ rotateStringArray: true,
63
+ identifierNamesGenerator: 'hexadecimal',
64
+ selfDefending: true,
65
+ ...obfuscatorOptions // Spread any additional options
66
+ }
67
+ ).getObfuscatedCode()
51
68
 
52
- console.log(`Obfuscating: ${assetName}`)
53
- const asset = compilation.assets[assetName]
54
- promises.push(
55
- new Promise((resolve, reject) => {
56
- try {
57
- const obfuscated = JavaScriptObfuscator.obfuscate(
58
- asset.source(),
59
- {
60
- compact: true,
61
- disableConsoleOutput: false,
62
- rotateStringArray: true,
63
- identifierNamesGenerator: 'hexadecimal',
64
- selfDefending: true,
65
- ...obfuscatorOptions // Spread any additional options
69
+ compilation.assets[assetName] = {
70
+ source: () => obfuscated,
71
+ size: () => obfuscated.length
66
72
  }
67
- ).getObfuscatedCode()
68
73
 
69
- compilation.assets[assetName] = {
70
- source: () => obfuscated,
71
- size: () => obfuscated.length
74
+ resolve()
75
+ } catch (err) {
76
+ console.error(`Failed to obfuscate ${assetName}:`, err)
77
+ reject(err) // Reject if there's an error in obfuscation
72
78
  }
79
+ })
80
+ )
81
+ })
73
82
 
74
- resolve()
75
- } catch (err) {
76
- console.error(`Failed to obfuscate ${assetName}:`, err)
77
- reject(err) // Reject if there's an error in obfuscation
78
- }
79
- })
80
- )
81
- })
82
-
83
- // Wait for all files to be processed
84
- await Promise.all(promises)
85
- callback()
86
- }
87
- )
83
+ // Wait for all files to be processed
84
+ await Promise.all(promises)
85
+ callback()
86
+ }
87
+ )
88
+ }
88
89
  }
89
-
90
90
  // Instantiate and apply the plugin to the Webpack config
91
91
  config.plugin('javascript-obfuscator').use(JavascriptObfuscatorPlugin)
92
92
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-cli-plugin-javascript-obfuscator",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Vue CLI plugin for JavaScript obfuscation using javascript-obfuscator@4.x",
5
5
  "main": "index.js",
6
6
  "scripts": {