Skip to content

Commit

Permalink
chore: Update rollup-plugin-visualizer to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed May 10, 2021
1 parent 3f1c9e6 commit 9fdb5b1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/wmr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"resolve.exports": "^1.0.2",
"rollup": "^2.43.1",
"rollup-plugin-preserve-shebang": "^1.0.1",
"rollup-plugin-visualizer": "^4.2.2",
"rollup-plugin-visualizer": "5.5.0",
"sade": "^1.7.3",
"semver": "^7.3.2",
"simple-code-frame": "^1.1.1",
Expand Down
35 changes: 16 additions & 19 deletions packages/wmr/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,23 @@ const config = {
// rather than bundleds as fs.readFile()
name: 'fix-visualizer',
transform(code, id) {
if (/rollup-plugin-visualizer[/\\]plugin[/\\]build-stats\.js$/.test(id)) {
code = code.replace(
/fs\.readFile\(path\.join\(__dirname,\s*(.+?)\)\s*,\s*"utf8"\s*\)/g,
(str, stringifiedJoin) => {
const path = require('path');
const fs = require('fs');
const filePathParts = stringifiedJoin
.replace(/['"`]+/g, '')
.replace(/\$\{template\}/g, 'treemap')
.split(', ');
const filepath = path.resolve(path.dirname(id), ...filePathParts);
try {
const text = fs.readFileSync(filepath, 'utf-8');
return `Promise.resolve(${JSON.stringify(text)})`;
} catch (err) {
this.warn(`Failed to inline ${filepath} into ${id}:\n${err.message}`);
return `Promise.reject(Error(${JSON.stringify(err.message)}))`;
}
if (/rollup-plugin-visualizer[/\\]dist[/\\]plugin[/\\]build-stats\.js$/.test(id)) {
code = code.replace(/fs.*readFile.*\(__dirname,\s*(.+?)\)\s*,\s*"utf8"\s*\)/g, (_str, stringifiedJoin) => {
const path = require('path');
const fs = require('fs');
const filePathParts = stringifiedJoin
.replace(/['"`]+/g, '')
.replace(/\$\{template\}/g, 'treemap')
.split(', ');
const filepath = path.resolve(path.dirname(id), ...filePathParts);
try {
const text = fs.readFileSync(filepath, 'utf-8');
return `Promise.resolve(${JSON.stringify(text)})`;
} catch (err) {
this.warn(`Failed to inline ${filepath} into ${id}:\n${err.message}`);
return `Promise.reject(Error(${JSON.stringify(err.message)}))`;
}
);
});
return { code, map: null };
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wmr/src/lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ export function getPlugins(options) {
production && optimizeGraphPlugin({ publicPath }),
minify && minifyCssPlugin({ sourcemap }),
production && copyAssetsPlugin({ cwd }),
production && visualize && visualizer({ open: true, gzipSize: true, brotliSize: true })
production && visualize && visualizer.default({ open: true, gzipSize: true, brotliSize: true })
].filter(Boolean);
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7797,10 +7797,10 @@ rollup-plugin-preserve-shebang@^1.0.1:
dependencies:
magic-string "^0.25.7"

rollup-plugin-visualizer@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/rollup-plugin-visualizer/-/rollup-plugin-visualizer-4.2.2.tgz#edeb8b3fc6f49b3c95f6cc668f4eba57c6112099"
integrity sha512-10/TsugsaQL5rdynl0lrklBngTtkRBESZdxUJy+3fN+xKqNdg5cr7JQU1OoPx4p5mhQ+nspa6EvX3qc8SsBvnA==
rollup-plugin-visualizer@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-visualizer/-/rollup-plugin-visualizer-5.5.0.tgz#dbe9daa3a46576fb697eb62b19ed251112b85d1e"
integrity sha512-QUd0ZHGYn6rgogS+yzG08AvMk9J4kR1lO1cpLJCIAQhbyIGSBdqCddKWtxDsdmsxhkY/GCGw8CvoSB3MwMQOIQ==
dependencies:
nanoid "^3.1.22"
open "^7.4.2"
Expand Down

0 comments on commit 9fdb5b1

Please sign in to comment.