فهرست منبع

Fixed require of external user config file

sanex3339 7 سال پیش
والد
کامیت
856ba39f86
6فایلهای تغییر یافته به همراه45 افزوده شده و 5 حذف شده
  1. 0 0
      dist/index.js
  2. 1 0
      package.json
  3. 3 3
      src/cli/JavaScriptObfuscatorCLI.ts
  4. 12 0
      src/cli/utils/CLIUtils.ts
  5. 23 0
      test/unit-tests/cli/utils/CLIUtils.spec.ts
  6. 6 2
      yarn.lock

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/index.js


+ 1 - 0
package.json

@@ -51,6 +51,7 @@
     "@types/node": "8.0.17",
     "@types/node": "8.0.17",
     "@types/sinon": "2.3.3",
     "@types/sinon": "2.3.3",
     "@types/string-template": "1.0.2",
     "@types/string-template": "1.0.2",
+    "@types/webpack-env": "1.13.0",
     "awesome-typescript-loader": "3.2.2",
     "awesome-typescript-loader": "3.2.2",
     "babel-cli": "6.24.1",
     "babel-cli": "6.24.1",
     "babel-loader": "7.1.1",
     "babel-loader": "7.1.1",

+ 3 - 3
src/cli/JavaScriptObfuscatorCLI.ts

@@ -51,10 +51,10 @@ export class JavaScriptObfuscatorCLI {
     }
     }
 
 
     /**
     /**
-     * @param options
+     * @param {Object} options
      * @returns {TInputOptions}
      * @returns {TInputOptions}
      */
      */
-    private static sanitizeOptions (options: {[key: string]: any}): TInputOptions {
+    private static sanitizeOptions (options: Object): TInputOptions {
         const filteredOptions: TInputOptions = {};
         const filteredOptions: TInputOptions = {};
         const availableOptions: string[] = Object.keys(DEFAULT_PRESET);
         const availableOptions: string[] = Object.keys(DEFAULT_PRESET);
 
 
@@ -99,7 +99,7 @@ export class JavaScriptObfuscatorCLI {
             ? path.resolve(this.commands.config, '.')
             ? path.resolve(this.commands.config, '.')
             : '';
             : '';
         const configFileOptions: TInputOptions = configFileLocation
         const configFileOptions: TInputOptions = configFileLocation
-            ? JavaScriptObfuscatorCLI.sanitizeOptions(require(configFileLocation))
+            ? JavaScriptObfuscatorCLI.sanitizeOptions(CLIUtils.getUserConfig(configFileLocation))
             : {};
             : {};
 
 
         return {
         return {

+ 12 - 0
src/cli/utils/CLIUtils.ts

@@ -73,6 +73,18 @@ export class CLIUtils {
         );
         );
     }
     }
 
 
+    /**
+     * @param {string} configPath
+     * @returns {Object}
+     */
+    public static getUserConfig (configPath: string): Object {
+        const nativeRequire: Function = typeof __non_webpack_require__ === 'function'
+            ? __non_webpack_require__
+            : require;
+
+        return nativeRequire(configPath);
+    }
+
     /**
     /**
      * @param {string} filePath
      * @param {string} filePath
      * @returns {boolean}
      * @returns {boolean}

+ 23 - 0
test/unit-tests/cli/utils/CLIUtils.spec.ts

@@ -3,6 +3,8 @@ import * as mkdirp from 'mkdirp';
 
 
 import { assert } from 'chai';
 import { assert } from 'chai';
 
 
+import { TInputOptions } from '../../../../src/types/options/TInputOptions';
+
 import { CLIUtils } from '../../../../src/cli/utils/CLIUtils';
 import { CLIUtils } from '../../../../src/cli/utils/CLIUtils';
 
 
 describe('CLIUtils', () => {
 describe('CLIUtils', () => {
@@ -46,6 +48,27 @@ describe('CLIUtils', () => {
         });
         });
     });
     });
 
 
+    describe('getUserConfig (configPath: string): Object', () => {
+        const configDirName: string = 'test/fixtures';
+        const configFileName: string = 'config.js';
+        const configFilePath: string = `../../../${configDirName}/${configFileName}`;
+        const expectedResult: TInputOptions = {
+            compact: true,
+            selfDefending: false,
+            sourceMap: true
+        };
+
+        let result: Object;
+
+        before(() => {
+            result = CLIUtils.getUserConfig(configFilePath);
+        });
+
+        it('should return object with user configuration', () => {
+            assert.deepEqual(result, expectedResult);
+        });
+    });
+
     describe('validateInputPath (inputPath: string): void', () => {
     describe('validateInputPath (inputPath: string): void', () => {
         describe('`inputPath` is a valid path', () => {
         describe('`inputPath` is a valid path', () => {
             const tmpFileName: string = 'test.js';
             const tmpFileName: string = 'test.js';

+ 6 - 2
yarn.lock

@@ -6,7 +6,7 @@
   version "4.0.1"
   version "4.0.1"
   resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.0.1.tgz#37fea779617cfec3fd2b19a0247e8bbdd5133bf6"
   resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.0.1.tgz#37fea779617cfec3fd2b19a0247e8bbdd5133bf6"
 
 
-"@types/chalk@^0.4.31":
+"@types/[email protected]":
   version "0.4.31"
   version "0.4.31"
   resolved "https://registry.yarnpkg.com/@types/chalk/-/chalk-0.4.31.tgz#a31d74241a6b1edbb973cf36d97a2896834a51f9"
   resolved "https://registry.yarnpkg.com/@types/chalk/-/chalk-0.4.31.tgz#a31d74241a6b1edbb973cf36d97a2896834a51f9"
 
 
@@ -68,6 +68,10 @@
   version "1.0.2"
   version "1.0.2"
   resolved "https://registry.yarnpkg.com/@types/string-template/-/string-template-1.0.2.tgz#363b273c9b456705e3111e3571e9248f6474eba4"
   resolved "https://registry.yarnpkg.com/@types/string-template/-/string-template-1.0.2.tgz#363b273c9b456705e3111e3571e9248f6474eba4"
 
 
+"@types/webpack-env@^1.13.0":
+  version "1.13.0"
+  resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.0.tgz#3044381647e11ee973c5af2e925323930f691d80"
+
 abbrev@1, [email protected]:
 abbrev@1, [email protected]:
   version "1.0.9"
   version "1.0.9"
   resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
   resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
@@ -933,7 +937,7 @@ [email protected], chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1:
     strip-ansi "^3.0.0"
     strip-ansi "^3.0.0"
     supports-color "^2.0.0"
     supports-color "^2.0.0"
 
 
-chalk@^2.0.0, chalk@^2.0.1:
+chalk@2.0.1, chalk@^2.0.0:
   version "2.0.1"
   version "2.0.1"
   resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.0.1.tgz#dbec49436d2ae15f536114e76d14656cdbc0f44d"
   resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.0.1.tgz#dbec49436d2ae15f536114e76d14656cdbc0f44d"
   dependencies:
   dependencies:

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است