From 361bd4e457050b76d94d5ab7193780666e786727 Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Mon, 9 Mar 2020 14:42:02 -0700 Subject: [PATCH] feat(rollup): rollup@2 compat (#733) --- package-lock.json | 35 +++++++++++++++---- package.json | 2 +- packages/rollup-rewriter/rewriter.js | 4 +-- packages/rollup/rollup.js | 6 ++-- .../test/__snapshots__/rollup.test.js.snap | 2 +- .../test/__snapshots__/watch.test.js.snap | 14 ++++---- packages/rollup/test/watch.test.js | 2 -- .../expect/toMatchRollupAssetSnapshot.js | 4 +-- .../expect/toMatchRollupCodeSnapshot.js | 4 +-- .../expect/toMatchRollupSnapshot.js | 4 +-- 10 files changed, 47 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 32fe13dc5..017e41374 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2034,6 +2034,7 @@ "@modular-css/browserify": { "version": "file:packages/browserify", "requires": { + "@modular-css/processor": "file:packages/processor", "mkdirp": "^1.0.3", "p-each-series": "^2.0.0", "sink-transform": "^2.0.0", @@ -2043,6 +2044,8 @@ "@modular-css/cli": { "version": "file:packages/cli", "requires": { + "@modular-css/glob": "file:packages/glob", + "@modular-css/processor": "file:packages/processor", "meow": "^6.0.0", "mkdirp": "^1.0.3" }, @@ -2222,6 +2225,7 @@ "@modular-css/glob": { "version": "file:packages/glob", "requires": { + "@modular-css/processor": "file:packages/processor", "globule": "^1.1.0" } }, @@ -2240,6 +2244,7 @@ "@modular-css/postcss": { "version": "file:packages/postcss", "requires": { + "@modular-css/processor": "file:packages/processor", "mkdirp": "^1.0.3", "postcss": "^7.0.0" } @@ -2261,6 +2266,7 @@ "@modular-css/rollup": { "version": "file:packages/rollup", "requires": { + "@modular-css/processor": "file:packages/processor", "dedent": "0.7.0", "esutils": "^2.0.2", "rollup-pluginutils": "^2.0.1", @@ -2284,6 +2290,7 @@ "@modular-css/svelte": { "version": "file:packages/svelte", "requires": { + "@modular-css/processor": "file:packages/processor", "escape-string-regexp": "^2.0.0", "is-url": "^1.2.4", "slash": "^3.0.0" @@ -2296,6 +2303,7 @@ "@modular-css/webpack": { "version": "file:packages/webpack", "requires": { + "@modular-css/processor": "file:packages/processor", "esutils": "^2.0.2", "loader-utils": "^1.1.0", "lodash": "^4.17.0", @@ -2306,6 +2314,10 @@ "version": "file:packages/www", "dev": true, "requires": { + "@modular-css/processor": "file:packages/processor", + "@modular-css/rollup": "file:packages/rollup", + "@modular-css/shortnames": "file:packages/namer", + "@modular-css/svelte": "file:packages/svelte", "@rollup/plugin-alias": "^3.0.1", "@rollup/plugin-commonjs": "^11.0.2", "@rollup/plugin-json": "^4.0.2", @@ -2315,7 +2327,7 @@ "debounce": "^1.2.0", "get-port": "^5.0.0", "lznext": "^0.1.0", - "markdown-it": "^9.1.0", + "markdown-it": "^10.0.0", "markdown-it-anchor": "^5.2.5", "markdown-it-container": "^2.0.0", "markdown-it-include": "^1.0.0", @@ -2355,6 +2367,17 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==" + }, + "rollup": { + "version": "1.32.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.32.1.tgz", + "integrity": "sha512-/2HA0Ec70TvQnXdzynFffkjA6XN+1e2pEv/uKS5Ulca40g2L7KuOE3riasHoNVHOsFD5KKZgDsMk1CP3Tw9s+A==", + "dev": true, + "requires": { + "@types/estree": "*", + "@types/node": "*", + "acorn": "^7.1.0" + } } } }, @@ -13982,14 +14005,12 @@ } }, "rollup": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.32.0.tgz", - "integrity": "sha512-ab2tF5pdDqm2zuI8j02ceyrJSScl9V2C24FgWQ1v1kTFTu1UrG5H0hpP++mDZlEFyZX4k0chtGEHU2i+pAzBgA==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.0.2.tgz", + "integrity": "sha512-99VIc2DHm+HEhdla2ASH/LaomWS3v7RDANamD65w24TQTNVs3vtRM+oiFsP4KvUCri5+p5Q5xoXscUnIdE8gJA==", "dev": true, "requires": { - "@types/estree": "*", - "@types/node": "*", - "acorn": "^7.1.0" + "fsevents": "~2.1.2" } }, "rollup-plugin-hypothetical": { diff --git a/package.json b/package.json index 80ba2fd68..1362e5fa9 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "p-defer": "^3.0.0", "pegjs": "0.10.0", "read-dir-deep": "^7.0.1", - "rollup": "^1.21.3", + "rollup": "^2.0.2", "rollup-plugin-hypothetical": "^2.1.0", "rollup-plugin-svelte": "^5.0.3", "shelljs": "^0.8.3", diff --git a/packages/rollup-rewriter/rewriter.js b/packages/rollup-rewriter/rewriter.js index 80e9ab1e8..66d14498c 100644 --- a/packages/rollup-rewriter/rewriter.js +++ b/packages/rollup-rewriter/rewriter.js @@ -50,9 +50,9 @@ module.exports = (opts = {}) => { const graph = new DepGraph({ circular : true }); Object.entries(chunks).forEach(([ entry, chunk ]) => { - const { isAsset, dynamicImports } = chunk; + const { type, dynamicImports } = chunk; - if(isAsset) { + if(type === "asset") { return; } diff --git a/packages/rollup/rollup.js b/packages/rollup/rollup.js index 2a0572405..fd2b428af 100644 --- a/packages/rollup/rollup.js +++ b/packages/rollup/rollup.js @@ -189,10 +189,10 @@ module.exports = (opts = {}) => { // Walk all bundle entries and add them to the dependency graph Object.entries(bundle).forEach(([ entry, chunk ]) => { - const { isAsset, modules } = chunk; + const { type, modules } = chunk; /* istanbul ignore if */ - if(isAsset) { + if(type === "asset") { return; } @@ -270,7 +270,7 @@ module.exports = (opts = {}) => { }); // Save off the final name of this asset for later use - const dest = this.getAssetFileName(id); + const dest = this.getFileName(id); names.set(node, dest); diff --git a/packages/rollup/test/__snapshots__/rollup.test.js.snap b/packages/rollup/test/__snapshots__/rollup.test.js.snap index 5b3898a31..d846088fe 100644 --- a/packages/rollup/test/__snapshots__/rollup.test.js.snap +++ b/packages/rollup/test/__snapshots__/rollup.test.js.snap @@ -473,7 +473,7 @@ exports[`/rollup.js should write out empty CSS files by default 1`] = `""`; exports[`/rollup.js shouldn't disable sourcemap generation 1`] = ` SourceMap { "file": "simple.js", - "mappings": ";;;;;AAEA,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC", + "mappings": ";;;;;AAEA,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC", "names": Array [], "sources": Array [ "packages/rollup/test/specimens/simple.js", diff --git a/packages/rollup/test/__snapshots__/watch.test.js.snap b/packages/rollup/test/__snapshots__/watch.test.js.snap index 33cda223b..107d03fb9 100644 --- a/packages/rollup/test/__snapshots__/watch.test.js.snap +++ b/packages/rollup/test/__snapshots__/watch.test.js.snap @@ -147,16 +147,14 @@ Snapshot Diff: + Second value @@ --- --- @@ - .mc204ad279_one { - color: red; - }", - "assets/shared.css": "/* packages/rollup/test/output/watch/code-splitting/shared.css */ + Object { + "assets/one.css": "/* packages/rollup/test/output/watch/code-splitting/shared.css */ .mc4002e81f_shared { - color: blue; + color: seafoam; - }", - "assets/two.css": "/* packages/rollup/test/output/watch/code-splitting/two.css */ - .mc3861d3af_two { - color: green; + } + /* packages/rollup/test/output/watch/code-splitting/one.css */ + .mc204ad279_one { + color: red; }", `; diff --git a/packages/rollup/test/watch.test.js b/packages/rollup/test/watch.test.js index 3017db647..54ce2e18f 100644 --- a/packages/rollup/test/watch.test.js +++ b/packages/rollup/test/watch.test.js @@ -392,8 +392,6 @@ describe("/rollup.js", () => { // Start watching watcher = watch({ - experimentalCodeSplitting : true, - input : [ require.resolve(prefix("./output/watch/code-splitting/one.js")), require.resolve(prefix("./output/watch/code-splitting/two.js")), diff --git a/packages/test-utils/expect/toMatchRollupAssetSnapshot.js b/packages/test-utils/expect/toMatchRollupAssetSnapshot.js index d6174df01..ff1d77630 100644 --- a/packages/test-utils/expect/toMatchRollupAssetSnapshot.js +++ b/packages/test-utils/expect/toMatchRollupAssetSnapshot.js @@ -6,8 +6,8 @@ expect.extend({ toMatchRollupAssetSnapshot({ output }) { const assets = new Map(); - output.forEach(({ isAsset, fileName, source }) => { - if(!isAsset) { + output.forEach(({ type, fileName, source }) => { + if(type !== "asset") { return; } diff --git a/packages/test-utils/expect/toMatchRollupCodeSnapshot.js b/packages/test-utils/expect/toMatchRollupCodeSnapshot.js index 7be1a0b00..6cd483be2 100644 --- a/packages/test-utils/expect/toMatchRollupCodeSnapshot.js +++ b/packages/test-utils/expect/toMatchRollupCodeSnapshot.js @@ -6,8 +6,8 @@ expect.extend({ toMatchRollupCodeSnapshot({ output }) { const chunks = new Map(); - output.forEach(({ isAsset, name, code }) => { - if(isAsset) { + output.forEach(({ type, name, code }) => { + if(type === "asset") { return; } diff --git a/packages/test-utils/expect/toMatchRollupSnapshot.js b/packages/test-utils/expect/toMatchRollupSnapshot.js index 01f6e5b3e..aae0412a7 100644 --- a/packages/test-utils/expect/toMatchRollupSnapshot.js +++ b/packages/test-utils/expect/toMatchRollupSnapshot.js @@ -6,9 +6,9 @@ expect.extend({ toMatchRollupSnapshot({ output }, name = "") { const things = new Map(); - output.forEach(({ code, isAsset, fileName, source }) => { + output.forEach(({ code, type, fileName, source }) => { // Leading newline to make diffs easier to read - things.set(fileName, `\n${isAsset ? source : code}`); + things.set(fileName, `\n${type === "asset" ? source : code}`); }); const out = Object.create(null);