Skip to content

Commit

Permalink
Faster test builds (#2457)
Browse files Browse the repository at this point in the history
* Do not create browser builds in tests; use bootstrap build for publishing

* Test that the command object can be modified in the config file
  • Loading branch information
lukastaegert committed Sep 16, 2018
1 parent d9b479d commit d5a910d
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 84 deletions.
13 changes: 6 additions & 7 deletions package.json
Expand Up @@ -10,25 +10,24 @@
"rollup": "./bin/rollup"
},
"scripts": {
"build": "git rev-parse HEAD > .commithash && rollup -c && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x bin/rollup",
"build": "shx rm -rf dist && git rev-parse HEAD > .commithash && rollup -c && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x bin/rollup",
"build:test": "shx rm -rf dist && rollup -c --noBrowser && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x bin/rollup",
"build:bootstrap": "bin/rollup -c && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x bin/rollup",
"build:clean": "del-cli dist",
"ci:coverage": "npm run test:coverage",
"ci:lint": "npm run lint:nofix && npm run security",
"ci:test": "npm run test && npm run build:bootstrap && npm run test:only",
"lint": "tslint --project . --fix && eslint --fix test/test.js test/*/index.js test/utils.js test/**/_config.js",
"lint:nofix": "tslint --project . && eslint test/test.js test/*/index.js test/utils.js test/**/_config.js",
"perf": "npm run build && node --expose-gc scripts/perf.js",
"perf": "npm run build:test && node --expose-gc scripts/perf.js",
"perf:debug": "node --inspect-brk scripts/perf-debug.js",
"perf:init": "node scripts/perf-init.js",
"postcommit": "git reset",
"posttest:coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist",
"prebuild": "shx rm -rf dist",
"precommit": "lint-staged",
"prepare": "npm run build",
"prepublishOnly": "npm run lint && npm run test",
"pretest": "npm run build",
"pretest:coverage": "npm run build",
"prepublishOnly": "npm run lint:nofix && npm run security && npm run build && npm run build:bootstrap && npm run test:only && npm run test:typescript && npm run test:leak",
"pretest": "npm run build:test",
"pretest:coverage": "npm run build:test",
"pretest:typescript": "shx rm -rf test/typescript/dist && shx cp -r dist test/typescript/",
"security": "npm audit",
"test": "npm run test:only && npm run test:typescript && npm run test:leak",
Expand Down
147 changes: 77 additions & 70 deletions rollup.config.js
Expand Up @@ -65,77 +65,84 @@ function resolveTypescript() {
};
}

export default [
/* rollup.js and rollup.es.js */
{
input: 'src/node-entry.ts',
onwarn,
plugins: [
json(),
resolveTypescript(),
typescript({
typescript: require('typescript')
}),
resolve(),
commonjs()
],
external: ['fs', 'path', 'events', 'module', 'util', 'crypto'],
output: [
{ file: 'dist/rollup.js', format: 'cjs', sourcemap: true, banner },
{ file: 'dist/rollup.es.js', format: 'es', sourcemap: true, banner }
]
},

/* rollup.browser.js and rollup.browser.mjs */
{
input: 'src/browser-entry.ts',
onwarn,
plugins: [
json(),
{
load: id => {
if (~id.indexOf('fs.ts')) return fs.readFileSync('browser/fs.ts', 'utf-8');
if (~id.indexOf('path.ts')) return fs.readFileSync('browser/path.ts', 'utf-8');
export default command => {
const nodeBuilds = [
/* Rollup core node builds */
{
input: 'src/node-entry.ts',
onwarn,
plugins: [
json(),
resolveTypescript(),
typescript({
typescript: require('typescript')
}),
resolve(),
commonjs()
],
external: ['fs', 'path', 'events', 'module', 'util', 'crypto'],
output: [
{ file: 'dist/rollup.js', format: 'cjs', sourcemap: true, banner },
{ file: 'dist/rollup.es.js', format: 'es', sourcemap: true, banner }
]
},
/* Rollup CLI */
{
input: 'bin/src/index.ts',
onwarn,
plugins: [
string({ include: '**/*.md' }),
json(),
resolveTypescript(),
typescript({
typescript: require('typescript')
}),
commonjs({
include: 'node_modules/**'
}),
resolve()
],
external: ['fs', 'path', 'module', 'events', 'rollup', 'assert', 'os', 'util'],
output: {
file: 'bin/rollup',
format: 'cjs',
banner: '#!/usr/bin/env node',
paths: {
rollup: '../dist/rollup.js'
}
},
resolveTypescript(),
typescript({
typescript: require('typescript')
}),
resolve({ browser: true }),
commonjs(),
terser({ module: true, output: { comments: 'some' } })
],
output: [
{ file: 'dist/rollup.browser.js', format: 'umd', name: 'rollup', sourcemap: true, banner },
{ file: 'dist/rollup.browser.mjs', format: 'es', sourcemap: true, banner }
]
},

/* bin/rollup */
{
input: 'bin/src/index.ts',
onwarn,
plugins: [
string({ include: '**/*.md' }),
json(),
resolveTypescript(),
typescript({
typescript: require('typescript')
}),
commonjs({
include: 'node_modules/**'
}),
resolve()
],
external: ['fs', 'path', 'module', 'events', 'rollup', 'assert', 'os', 'util'],
output: {
file: 'bin/rollup',
format: 'cjs',
banner: '#!/usr/bin/env node',
paths: {
rollup: '../dist/rollup.js'
}
}
];

if (command.noBrowser) {
delete command.noBrowser;
return nodeBuilds;
}
];
return nodeBuilds.concat([
/* Rollup core browser builds */
{
input: 'src/browser-entry.ts',
onwarn,
plugins: [
json(),
{
load: id => {
if (~id.indexOf('fs.ts')) return fs.readFileSync('browser/fs.ts', 'utf-8');
if (~id.indexOf('path.ts')) return fs.readFileSync('browser/path.ts', 'utf-8');
}
},
resolveTypescript(),
typescript({
typescript: require('typescript')
}),
resolve({ browser: true }),
commonjs(),
terser({ module: true, output: { comments: 'some' } })
],
output: [
{ file: 'dist/rollup.browser.js', format: 'umd', name: 'rollup', sourcemap: true, banner },
{ file: 'dist/rollup.browser.mjs', format: 'es', sourcemap: true, banner }
]
}
]);
};
5 changes: 5 additions & 0 deletions test/cli/samples/config-function-modify-command/_config.js
@@ -0,0 +1,5 @@
module.exports = {
description: 'allows cleaning up and modifying the command args in the config file',
command: 'rollup --config rollup.config.js --some-option="foo" --another-option=42',
execute: true
};
7 changes: 7 additions & 0 deletions test/cli/samples/config-function-modify-command/main.js
@@ -0,0 +1,7 @@
assert.deepEqual(COMMAND_OPTIONS, {
_: [],
config: 'rollup.config.js',
c: 'rollup.config.js',
'some-option': 'foo',
'another-option': 42
});
15 changes: 15 additions & 0 deletions test/cli/samples/config-function-modify-command/rollup.config.js
@@ -0,0 +1,15 @@
import replace from 'rollup-plugin-replace';

export default commandOptions => {
const COMMAND_OPTIONS = JSON.stringify(commandOptions);
delete commandOptions['some-option'];
delete commandOptions['another-option'];
commandOptions.format = 'cjs';
return {
input: 'main.js',
onwarn(warning) {
throw new Error(`Unexpected warning: ${warning.message}`);
},
plugins: [replace({ COMMAND_OPTIONS })]
};
};
5 changes: 3 additions & 2 deletions test/cli/samples/config-function/_config.js
@@ -1,5 +1,6 @@
module.exports = {
description: 'if config returns a function then this will be called with command args',
command: 'rollup --config rollup.config.js --silent --some-option="foo" --another-option=42',
description:
'if the config file returns a function then this will be called with the command args',
command: 'rollup --config rollup.config.js --silent',
execute: true
};
4 changes: 1 addition & 3 deletions test/cli/samples/config-function/main.js
Expand Up @@ -2,7 +2,5 @@ assert.deepEqual(COMMAND_OPTIONS, {
_: [],
config: 'rollup.config.js',
c: 'rollup.config.js',
silent: true,
'some-option': 'foo',
'another-option': 42
silent: true
});
9 changes: 7 additions & 2 deletions test/cli/samples/config-function/rollup.config.js
@@ -1,11 +1,16 @@
var replace = require( 'rollup-plugin-replace' );
import assert from 'assert';
import replace from 'rollup-plugin-replace';

module.exports = function(commandOptions) {
export default commandOptions => {
assert.equal(commandOptions.silent, true);
return {
input: 'main.js',
output: {
format: 'cjs'
},
onwarn(warning) {
throw new Error(`Unexpected warning: ${warning.message}`);
},
plugins: [
replace( { 'COMMAND_OPTIONS': JSON.stringify(commandOptions) } )
]
Expand Down

0 comments on commit d5a910d

Please sign in to comment.