Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Pitching loaders and more complete loader support #15

Merged
merged 20 commits into from
Apr 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .babelrc

This file was deleted.

7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
*.gnumeric
/node_modules
/.happypack
node_modules
.happypack
/examples/**/dist
/tmp
!/tmp/.gitkeep
/npm-debug.log
/npm-debug.log
/coverage
11 changes: 11 additions & 0 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
instrumentation:
root: lib
excludes:
- "*.test.js"
- "HappyTestUtils.js"
- "__tests__/fixtures/**/*"
extensions:
- .js
reporting:
reports:
- html
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v5.9.1
18 changes: 12 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
language: node_js
env:
- HAPPY_TEST_TIMEOUT=60000
node_js:
- "stable"
- "iojs"
- "4.1"
- "4.0"
- "0.12"
- "0.11"
- "0.10"
# - "4.0"
# - "0.12"
# - "0.11"
# - "0.10"
install: npm install --ignore-scripts
script: npm run prepublish
script:
- npm run lint
- npm run test
- npm run test-examples
after_success:
- npm run coverage_ci
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# HappyPack (beta) [![Build Status](https://travis-ci.org/amireh/happypack.svg)](https://travis-ci.org/amireh/happypack)
# HappyPack (beta) [![Build Status](https://travis-ci.org/amireh/happypack.svg?branch=master)](https://travis-ci.org/amireh/happypack) [![codecov.io](https://codecov.io/github/amireh/happypack/coverage.svg?branch=master)](https://codecov.io/github/amireh/happypack?branch=master)

Make working with webpack against large code-bases a happier experience.

Expand All @@ -12,8 +12,8 @@ See "How it works" below for more details.
## Motivation

- webpack initial build times are horrifying in large codebases (3k+ modules)
- something that works against both a one-time build (e.g. for a CI) and with
persistent processes (`--watch` during development)
- something that works against both a one-time build (e.g. for a CI) and
continuous builds (i.e. `--watch` during development)

## Usage

Expand All @@ -39,8 +39,8 @@ exports.plugins = [
];
```

Now you replace your current JS loaders with HappyPack's (possibly use an env
variable to enable HappyPack):
Now you replace your current loaders with HappyPack's loader (possibly use an
env variable to enable HappyPack):

```javascript
exports.module = {
Expand All @@ -55,7 +55,7 @@ exports.module = {
```

That's it. Now sources that match `.js$` will be handed off to happypack which
will use the loaders you specified to transform them.
will transform them in parallel using the loaders you specified.

## Configuration

Expand Down Expand Up @@ -151,17 +151,6 @@ as HappyPack will switch into a synchronous mode afterwards (i.e. in `watch`
mode.) Also, if we're using the cache and the compiled versions are indeed
cached, the threads will be idle.

### `installExitHandler: Boolean`

Whether we should intercept the process's `SIGINT` and clean up when it is
received. This is needed because webpack's CLI does not expose any hook for
cleaning up when it is going down, so it's a good idea to hook into it.

You can turn this off if you don't want this functionality or it gives you
trouble.

Defaults to: `true`

## How it works

![A diagram showing the flow between HappyPack's components](doc/HappyPack_Workflow.png)
Expand Down
8 changes: 8 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- [ ] ~~stop serializing options and instead accept webpack config file path and populate fake loader context with that so that worker loaders get access to external options~~
- [x] pitching loader applier
- [ ] pass loader options found on the compiler by the loader name to the loader, like `options.transform` or `options.sassLoader`
- [ ] accept modified `resourcePath` from pitching phase and re-read the source
- [ ] delay reading the source file until the very point where we need it; pitch
- [ ] replay loader RPCs for items cached by loaders like `tslint-loader` where the output is actually RPCs like `this.emitWarning` and `this.emitError`
- [ ] better coverage for background loader failures
- [ ]
Binary file modified doc/design.xmind
Binary file not shown.
1 change: 1 addition & 0 deletions examples/babel-loader/lib/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const B = require('./b');
12 changes: 12 additions & 0 deletions examples/babel-loader/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "happypack-examples__babel-loader",
"version": "1.0.0",
"description": "",
"main": "index.js",
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.3.26",
"babel-loader": "^6.2.0"
}
}
20 changes: 20 additions & 0 deletions examples/babel-loader/webpack.config--raw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var path = require('path');

module.exports = {
entry: path.resolve(__dirname, 'lib/a.js'),

output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].raw.js'
},

module: {
loaders: [
{
test: /\.js$/,
include: [ path.resolve(__dirname, 'lib') ],
loader: 'babel'
}
]
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var path = require('path');
var HappyPack = require('../../');

module.exports = {
entry: path.resolve(__dirname, 'a.js'),
entry: path.resolve(__dirname, 'lib/a.js'),

output: {
path: path.resolve(__dirname, 'dist'),
Expand All @@ -11,15 +11,8 @@ module.exports = {

plugins: [
new HappyPack({
loaders: [
{
path: path.resolve(__dirname, '../../node_modules/babel-loader/index.js'),
query: '?presets[]=es2015,presets[]=react'
},
{
path: path.resolve(__dirname, '../identity-loader.js')
}
],
cache: process.env.HAPPY_CACHE === '1',
loaders: [ 'babel' ],
threads: 2
})
],
Expand All @@ -28,6 +21,7 @@ module.exports = {
loaders: [
{
test: /\.js$/,
include: [ path.resolve(__dirname, 'lib') ],
loader: path.resolve(__dirname, '../../loader')
}
]
Expand Down
96 changes: 79 additions & 17 deletions examples/build-all.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/usr/bin/env bash
#
# Downstream integration tests.

if [ ! -d examples ]; then
echo "You must run this from happypack root."
exit 1
fi

WEBPACK_BIN="$(pwd)/node_modules/.bin/webpack"

function run_task {
task=$@
echo -e "\n[$task] STARTING $(date)"
Expand All @@ -21,30 +25,88 @@ function run_task {
fi

echo -e "[$task] FINISHED $(date)\n"
}

function setup_example {
EXAMPLE_DIR=$@

[ -d $EXAMPLE_DIR/dist ] && rm -r $EXAMPLE_DIR/dist
[ -f $EXAMPLE_DIR/package.json ] && (cd $EXAMPLE_DIR; npm install)
}

function babel_loader {
echo "Testing HappyPack with babel-loader"
echo "-----------------------------------"

setup_example "examples/babel-loader"

(
cd examples/babel-loader;
$WEBPACK_BIN --bail &&
$WEBPACK_BIN --bail --config webpack.config--raw.js &&
diff dist/main.js dist/main.raw.js &&
grep "success" dist/main.js
)
}

# exit $exit_status
function sass_loader {
echo "Testing HappyPack using sass + css + style loaders."
echo "---------------------------------------------------"

setup_example "examples/sass-loader"

(
cd examples/sass-loader;
$WEBPACK_BIN --bail &&
$WEBPACK_BIN --bail --config webpack.config--raw.js &&
diff dist/main.js dist/main.raw.js &&
grep "background-color: yellow" dist/main.js
)
}

function single_loader {
rm -r examples/single-loader/dist
function tslint_loader {
echo "Testing HappyPack using ts-linter (typescript linter)"
echo "-----------------------------------------------------"

setup_example "examples/tslint-loader"

./node_modules/.bin/webpack \
--bail \
--config examples/single-loader/webpack.config.js &&
grep "success" ./examples/single-loader/dist/main.js
(cd examples/tslint-loader; $WEBPACK_BIN --bail) | grep "forbidden var keyword"
}

function multi_loader {
rm -r examples/multi-loader/dist
function transform_loader {
echo "Testing HappyPack with transform-loader (coffeeify & brfs)"
echo "----------------------------------------------------------"

./node_modules/.bin/webpack \
--bail \
--config examples/multi-loader/webpack.config.js &&
grep "success" ./examples/multi-loader/dist/main.js
setup_example "examples/transform-loader"

(
cd examples/transform-loader;
$WEBPACK_BIN --bail &&
$WEBPACK_BIN --bail --config webpack.config--raw.js &&
diff dist/main.js dist/main.raw.js
)
}

echo "Testing HappyPack using a single loader."
run_task single_loader
# purge the cache and previous build artifacts
find examples -maxdepth 2 -type d -name '.happypack' | xargs rm -r
find examples -maxdepth 2 -type d -name 'dist' | xargs rm -r

export HAPPY_CACHE=1

run_task babel_loader
run_task sass_loader
run_task tslint_loader
run_task transform_loader

echo "Re-running previous examples with cached sources..."
echo "---------------------------------------------------"

run_task babel_loader
run_task sass_loader

# doesn't work right now, we need to replay all loader RPCs on cache load as
# this loader simply does emitWarning/emitError calls
#
# run_task tslint_loader

echo "Testing HappyPack using multiple loaders."
run_task multi_loader
run_task transform_loader
2 changes: 2 additions & 0 deletions examples/dependency/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// index.js
require('./b');
2 changes: 2 additions & 0 deletions examples/dependency/lib/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// other.js
//
7 changes: 7 additions & 0 deletions examples/dependency/loader-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function(s) {
return s;
};

module.exports.pitch = function(x, o) {
console.log('[a] in pitch!!\n [remaining] => %s\n [preceding] => %s', x, o)
};
7 changes: 7 additions & 0 deletions examples/dependency/loader-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function(s) {
return s;
};

module.exports.pitch = function(x, o) {
console.log('[b] in pitch!!\n [remaining] => %s\n [preceding] => %s', x, o)
};
7 changes: 7 additions & 0 deletions examples/dependency/loader-c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function(s) {
return s;
};

module.exports.pitch = function(x, o) {
console.log('[c] in pitch!!\n [remaining] => %s\n [preceding] => %s', x, o)
};
24 changes: 24 additions & 0 deletions examples/dependency/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var path = require('path');

module.exports = {
entry: path.resolve(__dirname, 'lib/index.js'),

output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},

module: {
loaders: [
{
test: /\.js$/,
include: [ path.resolve(__dirname, 'lib') ],
loaders: [
path.resolve(__dirname, 'loader-c.js'),
path.resolve(__dirname, 'loader-b.js'),
path.resolve(__dirname, 'loader-a.js'),
],
},
]
},
};
5 changes: 0 additions & 5 deletions examples/multi-loader/a.js

This file was deleted.

Loading