update to rollup babel 5.3.0 and improve browser test coverage code

This commit is contained in:
Rene
2021-02-16 22:20:35 +01:00
parent 1f35a6dc5a
commit d6da015835
3 changed files with 50 additions and 69 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
"@babel/plugin-transform-runtime": "^7.11.0", "@babel/plugin-transform-runtime": "^7.11.0",
"@babel/preset-env": "^7.11.0", "@babel/preset-env": "^7.11.0",
"@babel/preset-typescript": "^7.10.4", "@babel/preset-typescript": "^7.10.4",
"@rollup/plugin-babel": "^5.2.2", "@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-html": "^0.2.0", "@rollup/plugin-html": "^0.2.0",
"@rollup/plugin-inject": "^4.0.2", "@rollup/plugin-inject": "^4.0.2",
+12 -31
View File
@@ -12,7 +12,6 @@ const chalk = require('chalk');
const resolve = require('./resolve.config.json'); const resolve = require('./resolve.config.json');
const isTestEnv = process.env.NODE_ENV === 'test'; const isTestEnv = process.env.NODE_ENV === 'test';
const sizeSnapshotFilename = 'rollup.sizeSnapshot.json';
const rollupConfigDefaults = { const rollupConfigDefaults = {
input: './src/index', input: './src/index',
@@ -57,19 +56,16 @@ const esmBabelConfig = {
], ],
}; };
// workaround for https://github.com/rollup/plugins/issues/774
const rollupBabelIstanbulSourceMaps = {};
const rollupBabelIstanbulGenerateKey = (filename) => (filename ? filename.replace(/[\\/]+/g, '') : '');
const rollupBabelPlugin = isTestEnv const rollupBabelPlugin = isTestEnv
? createBabelInputPluginFactory(() => { ? createBabelInputPluginFactory(() => {
return { return {
config(cfg) { config(cfg) {
const { options } = cfg; const { options } = cfg;
const { filename, plugins } = options; const { plugins } = options;
const istanbulSourceMap = rollupBabelIstanbulSourceMaps[rollupBabelIstanbulGenerateKey(filename)];
if (istanbulSourceMap) { return this.meta.watchMode
return { ? options
: {
...options, ...options,
plugins: [ plugins: [
...(plugins || []), ...(plugins || []),
@@ -77,14 +73,11 @@ const rollupBabelPlugin = isTestEnv
'babel-plugin-istanbul', 'babel-plugin-istanbul',
{ {
useInlineSourceMaps: false, useInlineSourceMaps: false,
inputSourceMap: istanbulSourceMap, inputSourceMap: { ...this.getCombinedSourcemap() },
}, },
], ],
], ],
}; };
} else {
return options;
}
}, },
}; };
}) })
@@ -229,20 +222,7 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
sourceMap: sourcemap, sourceMap: sourcemap,
extensions: resolve.extensions, extensions: resolve.extensions,
}), }),
babel: [ babel: rollupBabelPlugin({
isTestEnv
? {
name: 'collect-bable-plugin-istanbul-input-source-maps',
transform(code, filename) {
rollupBabelIstanbulSourceMaps[rollupBabelIstanbulGenerateKey(filename)] = { ...this.getCombinedSourcemap() };
return {
code,
map: null,
};
},
}
: {},
rollupBabelPlugin({
...(esm ? esmBabelConfig : legacyBabelConfig), ...(esm ? esmBabelConfig : legacyBabelConfig),
babelHelpers: 'runtime', babelHelpers: 'runtime',
extensions: resolve.extensions, extensions: resolve.extensions,
@@ -251,7 +231,6 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
name: 'babel-rollup-build', name: 'babel-rollup-build',
}, },
}), }),
],
}; };
const output = genOutputConfig(esm); const output = genOutputConfig(esm);
@@ -259,7 +238,8 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
input: inputPath, input: inputPath,
output: [output].concat( output: [output].concat(
minVersions minVersions
? { ? [
{
...output, ...output,
compact: true, compact: true,
file: output.file.replace('.js', '.min.js'), file: output.file.replace('.js', '.min.js'),
@@ -277,8 +257,9 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
}, },
}), }),
], ],
} },
: {} ]
: []
), ),
external: [...Object.keys(devDependencies), ...Object.keys(peerDependencies), ...((Array.isArray(external) && external) || [])], external: [...Object.keys(devDependencies), ...Object.keys(peerDependencies), ...((Array.isArray(external) && external) || [])],
plugins: pipeline.reduce((arr, item) => { plugins: pipeline.reduce((arr, item) => {
@@ -304,7 +285,7 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
.filter((build) => build !== null) .filter((build) => build !== null)
.map((build, index, buildsArr) => { .map((build, index, buildsArr) => {
if (index === 0) { if (index === 0) {
existingDistFilesStats = { ...readFilesStats(distPath) }; existingDistFilesStats = readFilesStats(distPath);
buildsArr.forEach((build) => { buildsArr.forEach((build) => {
const { output } = build; const { output } = build;
outputs += Array.isArray(output) ? output.length : 1; outputs += Array.isArray(output) ? output.length : 1;
+4 -4
View File
@@ -1221,10 +1221,10 @@
"@nodelib/fs.scandir" "2.1.3" "@nodelib/fs.scandir" "2.1.3"
fastq "^1.6.0" fastq "^1.6.0"
"@rollup/plugin-babel@^5.2.2": "@rollup/plugin-babel@^5.3.0":
version "5.2.2" version "5.3.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-5.2.2.tgz#e5623a01dd8e37e004ba87f2de218c611727d9b2" resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-5.3.0.tgz#9cb1c5146ddd6a4968ad96f209c50c62f92f9879"
integrity sha512-MjmH7GvFT4TW8xFdIeFS3wqIX646y5tACdxkTO+khbHvS3ZcVJL6vkAHLw2wqPmkhwCfWHoNsp15VYNwW6JEJA== integrity sha512-9uIC8HZOnVLrLHxayq/PTzw+uS25E14KPUBh5ktF+18Mjo5yK0ToMMx6epY0uEgkjwJw0aBW4x2horYXh8juWw==
dependencies: dependencies:
"@babel/helper-module-imports" "^7.10.4" "@babel/helper-module-imports" "^7.10.4"
"@rollup/pluginutils" "^3.1.0" "@rollup/pluginutils" "^3.1.0"