Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Support Rollup 1.0.0 (#21)
Browse files Browse the repository at this point in the history
Rollup 1.0.0 has been released: https://github.com/rollup/rollup/releases/tag/v1.0.0

This plugin works with the 1.0.0 release from all appearances, so
I expanded the range of versions in the peer dependency. I also updated
the dev dependency to 1.0.0.

The tests required some changes to work with 1.0.0 because the output of
Rollup's bundle generate method has changed.
  • Loading branch information
edsrzf authored and TrySound committed Jan 1, 2019
1 parent 23f3a4c commit 930e59b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
yarn add rollup-plugin-terser --dev
```

*Note: this package requires rollup@0.66 and higher*
*Note: this package requires rollup@0.66 and higher (including rollup@1.0.0)*

## Usage

Expand All @@ -20,7 +20,7 @@ import { rollup } from "rollup";
import { terser } from "rollup-plugin-terser";

rollup({
entry: "main.js",
input: "main.js",
plugins: [terser()]
});
```
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"terser": "^3.8.2"
},
"peerDependencies": {
"rollup": ">=0.66.0 <1"
"rollup": ">=0.66.0 <2"
},
"devDependencies": {
"@babel/core": "^7.0.1",
Expand All @@ -39,6 +39,6 @@
"babel-jest": "^23.6.0",
"jest": "^23.6.0",
"prettier": "^1.14.2",
"rollup": "^0.66.0"
"rollup": "^1.0.0"
}
}
6 changes: 6 additions & 0 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ Object {
"chunk-1.js": Object {
"code": "var chunk1=\\"chunk-1\\";console.log(chunk1);
",
"dynamicImports": Array [],
"exports": Array [],
"fileName": "chunk-1.js",
"imports": Array [],
"isDynamicEntry": false,
"isEntry": true,
"map": null,
"name": "chunk-1",
},
"chunk-2.js": Object {
"code": "var chunk2=\\"chunk-2\\";console.log(chunk2);
",
"dynamicImports": Array [],
"exports": Array [],
"fileName": "chunk-2.js",
"imports": Array [],
"isDynamicEntry": false,
"isEntry": true,
"map": null,
"name": "chunk-2",
},
}
`;
25 changes: 15 additions & 10 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ test("minify", async () => {
plugins: [terser()]
});
const result = await bundle.generate({ format: "cjs" });
expect(result.code).toEqual(
expect(result.output).toHaveLength(1);
const output = result.output[0];
expect(output.code).toEqual(
'"use strict";window.a=5,window.a<3&&console.log(4);\n'
);
expect(result.map).toBeFalsy();
expect(output.map).toBeFalsy();
});

test("minify via terser options", async () => {
Expand All @@ -24,8 +26,10 @@ test("minify via terser options", async () => {
banner: "/* package name */",
format: "cjs"
});
expect(result.code).toEqual('/* package name */\n"use strict";\n');
expect(result.map).toBeFalsy();
expect(result.output).toHaveLength(1);
const output = result.output[0];
expect(output.code).toEqual('/* package name */\n"use strict";\n');
expect(output.map).toBeFalsy();
});

test("minify with sourcemaps", async () => {
Expand All @@ -34,7 +38,8 @@ test("minify with sourcemaps", async () => {
plugins: [terser()]
});
const result = await bundle.generate({ format: "cjs", sourcemap: true });
expect(result.map).toBeTruthy();
expect(result.output).toHaveLength(1);
expect(result.output[0].map).toBeTruthy();
});

test("allow to disable source maps", async () => {
Expand Down Expand Up @@ -78,14 +83,13 @@ test("throw error on terser fail", async () => {
test("works with code splitting", async () => {
const bundle = await rollup({
input: ["test/fixtures/chunk-1.js", "test/fixtures/chunk-2.js"],
experimentalCodeSplitting: true,
plugins: [terser()]
});
const { output } = await bundle.generate({ format: "esm" });
const newOutput = {};
Object.keys(output).forEach(key => {
const { modules, ...value } = output[key];
newOutput[key] = value;
output.forEach(out => {
const { modules, facadeModuleId, ...value } = out;
newOutput[out.fileName] = value;
});
expect(newOutput).toMatchSnapshot();
});
Expand All @@ -96,7 +100,8 @@ test("allow to pass not string values to worker", async () => {
plugins: [terser({ mangle: { properties: { regex: /^_/ } } })]
});
const result = await bundle.generate({ format: "cjs" });
expect(result.code).toEqual(
expect(result.output).toHaveLength(1);
expect(result.output[0].code).toEqual(
'"use strict";window.a=5,window.a<3&&console.log(4);\n'
);
});
13 changes: 10 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,11 @@ acorn@^5.0.0, acorn@^5.1.2:
version "5.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822"

acorn@^6.0.4:
version "6.0.4"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.0.4.tgz#77377e7353b72ec5104550aa2d2097a2fd40b754"
integrity sha512-VY4i5EKSKkofY2I+6QLTbTTN/UvEQPCo6eiwzzSaSWfpaDhOmStMCMod6wmuPciNq+XS0faCglFu2lHZpdHUtg==

ajv@^4.9.1:
version "4.11.8"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.8.tgz#82ffb02b29e662ae53bdc20af15947706739c536"
Expand Down Expand Up @@ -3070,12 +3075,14 @@ rimraf@^2.6.1:
dependencies:
glob "^7.0.5"

rollup@^0.66.0:
version "0.66.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.66.0.tgz#697acc008f4b613695b17222c7626affddf4a506"
rollup@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-1.0.0.tgz#db97a04a15364d1cd3823a0024ae8d8fda530a1c"
integrity sha512-LV6Qz+RkuDAfxr9YopU4k5o5P/QA7YNq9xi2Ug2IqOmhPt9sAm89vh3SkNtFok3bqZHX54eMJZ8F68HPejgqtw==
dependencies:
"@types/estree" "0.0.39"
"@types/node" "*"
acorn "^6.0.4"

safe-buffer@^5.0.1:
version "5.0.1"
Expand Down

0 comments on commit 930e59b

Please sign in to comment.