Skip to content

Commit

Permalink
Allow to pass not string values to worker
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Sep 16, 2018
1 parent 424d773 commit 7d58fda
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
13 changes: 8 additions & 5 deletions index.js
@@ -1,16 +1,19 @@
const { codeFrameColumns } = require("@babel/code-frame");
const Worker = require("jest-worker").default;
const serialize = require("serialize-javascript");

function uglify(userOptions = {}) {
if (userOptions.sourceMap != null) {
throw Error("sourceMap option is removed, use sourcemap instead");
}

const minifierOptions = Object.assign({}, userOptions, {
sourceMap: userOptions.sourcemap !== false,
sourcemap: undefined,
numWorkers: undefined
});
const minifierOptions = serialize(
Object.assign({}, userOptions, {
sourceMap: userOptions.sourcemap !== false,
sourcemap: undefined,
numWorkers: undefined
})
);

return {
name: "uglify",
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@babel/code-frame": "^7.0.0",
"jest-worker": "^23.2.0",
"serialize-javascript": "^1.5.0",
"uglify-js": "^3.4.9"
},
"peerDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Expand Up @@ -90,3 +90,14 @@ test("works with code splitting", async () => {
});
expect(newOutput).toMatchSnapshot();
});

test("allow to pass not string values to worker", async () => {
const bundle = await rollup({
input: "test/fixtures/unminified.js",
plugins: [uglify({ mangle: { properties: { regex: /^_/ } } })]
});
const result = await bundle.generate({ format: "cjs" });
expect(result.code).toEqual(
'"use strict";window.a=5,window.a<3&&console.log(4);\n'
);
});
3 changes: 2 additions & 1 deletion transform.js
@@ -1,6 +1,7 @@
const { minify } = require("uglify-js");

const transform = (code, options) => {
const transform = (code, optionsString) => {
const options = eval(`(${optionsString})`)
const result = minify(code, options);
if (result.error) {
throw result.error;
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Expand Up @@ -3115,6 +3115,10 @@ semver@^5.5.0:
version "5.5.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.1.tgz#7dfdd8814bdb7cabc7be0fb1d734cfb66c940477"

serialize-javascript@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.5.0.tgz#1aa336162c88a890ddad5384baebc93a655161fe"

set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down

0 comments on commit 7d58fda

Please sign in to comment.