Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

refactor: upgrade to webpack-defaults #51

Merged
merged 9 commits into from Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions .babelrc
@@ -0,0 +1,35 @@
{
"presets": [
[
"env",
{
"useBuiltIns": true,
"targets": {
"node": "4.3"
},
"exclude": [
"transform-async-to-generator",
"transform-regenerator"
]
}
]
],
"plugins": [
[
"transform-object-rest-spread",
{
"useBuiltIns": true
}
]
],
"env": {
"test": {
"presets": [
"env"
],
"plugins": [
"transform-object-rest-spread"
]
}
}
}
13 changes: 7 additions & 6 deletions .editorconfig
@@ -1,13 +1,14 @@
; editorconfig.org
# editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
trim_trailing_whitespace = true

[*.{json,yml,md}]
indent_size = 2
[.md]
insert_final_newline = false
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
/node_modules
/dist
3 changes: 3 additions & 0 deletions .eslintrc
@@ -0,0 +1,3 @@
{
"extends": "webpack"
}
3 changes: 3 additions & 0 deletions .gitattributes
@@ -0,0 +1,3 @@
yarn.lock -diff
* text=auto
bin/* eol=lf
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE.md
@@ -0,0 +1,7 @@
<!--
1. Check the version of package you are using. If it's not the newest version, update and try again (see changelog while updating!).
2. If the issue is still there, write a minimal project showing the problem and expected output.
3. Link to the project and mention Node version and OS in your report.
**IMPORTANT! You should use [Stack Overflow](https://stackoverflow.com/) for support related questions.**
-->
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,5 @@
<!--
1. [Read and sign the CLA](https://cla.js.foundation/webpack/webpack.js.org). This needs to be done only once. PRs that haven't signed it won't be accepted.
2. Check out the [development guide](https://webpack.js.org/development/) for the API and development guidelines.
3. Read through the PR diff carefully as sometimes this can reveal issues. The work will be reviewed, but this can save some effort.
-->
15 changes: 15 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,18 @@ tmp/
*.sublime-*
*.log
.DS_Store

logs
npm-debug.log*
yarn-debug.log*
.eslintcache
/coverage
/dist
/local
/reports
/node_modules
Thumbs.db
.idea
.vscode
*.sublime-project
*.sublime-workspace
32 changes: 32 additions & 0 deletions .travis.yml
@@ -0,0 +1,32 @@
sudo: false
language: node_js
branches:
only:
- master
matrix:
fast_finish: true
include:
- os: linux
node_js: '7'
env: WEBPACK_VERSION="2.2.0" JOB_PART=lint
- os: linux
node_js: '4.3'
env: WEBPACK_VERSION="2.2.0" JOB_PART=test
- os: linux
node_js: '6'
env: WEBPACK_VERSION="2.2.0" JOB_PART=test
- os: linux
node_js: '7'
env: WEBPACK_VERSION="2.2.0" JOB_PART=coverage
before_install:
- nvm --version
- node --version
before_script:
- |-
if [ "$WEBPACK_VERSION" ]; then
yarn add webpack@^$WEBPACK_VERSION
fi
script:
- 'yarn run travis:$JOB_PART'
after_success:
- 'bash <(curl -s https://codecov.io/bash)'
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,3 @@
# Change Log

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
86 changes: 77 additions & 9 deletions README.md
@@ -1,19 +1,29 @@
## Istanbul instrumenter loader for [webpack](https://webpack.js.org/)

[![npm](http://img.shields.io/npm/v/istanbul-instrumenter-loader.svg?style=flat-square)](https://www.npmjs.org/package/istanbul-instrumenter-loader)
[![deps](http://img.shields.io/david/deepsweet/istanbul-instrumenter-loader.svg?style=flat-square)](https://david-dm.org/deepsweet/istanbul-instrumenter-loader#info=dependencies)
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]

<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="200" height="200"
src="https://webpack.js.org/assets/icon-square-big.svg">
</a>
<h1>Istanbul Instrumenter Loader</h1>
</div>

Instrument JS files with [istanbul-lib-instrument](https://github.com/istanbuljs/istanbul-lib-instrument) for subsequent code coverage reporting.

### Install
<h2 align="center">Install</h2>

```sh
```bash
npm install --save-dev istanbul-instrumenter-loader
# or
yarn add --dev istanbul-instrumenter-loader
```

### Setup
<h2 align="center">Usage</h2>

#### References

Expand Down Expand Up @@ -94,5 +104,63 @@ config.set({
#### Options
The loader supports all options supported by [istanbul-lib-instrument](https://github.com/istanbuljs/istanbul-lib-instrument/blob/master/api.md#instrumenter).

### License
MIT
<h2 align="center">Contributing</h2>

Don't hesitate to create a pull request. Every contribution is appreciated. In development you can start the tests by calling `npm test`.

<h2 align="center">Maintainers</h2>

<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars.githubusercontent.com/u/266822?v=3&s=150">
</br>
<a href="https://github.com/deepsweet">Kir Belevich</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/166921?v=3&s=150">
</br>
<a href="https://github.com/bebraw">Juho Vepsäläinen</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars2.githubusercontent.com/u/8420490?v=3&s=150">
</br>
<a href="https://github.com/d3viant0ne">Joshua Wiens</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/533616?v=3&s=150">
</br>
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/3408176?v=3&s=150">
</br>
<a href="https://github.com/TheLarkInn">Sean Larkin</a>
</td>
</tr>
<tbody>
</table>

[npm]: https://img.shields.io/npm/v/istanbul-instrumenter-loader.svg
[npm-url]: https://npmjs.com/package/istanbul-instrumenter-loader

[node]: https://img.shields.io/node/v/istanbul-instrumenter-loader.svg
[node-url]: https://nodejs.org

[deps]: https://david-dm.org/webpack-contrib/istanbul-instrumenter-loader.svg
[deps-url]: https://david-dm.org/webpack-contrib/istanbul-instrumenter-loader

[tests]: http://img.shields.io/travis/webpack-contrib/istanbul-instrumenter-loader.svg
[tests-url]: https://travis-ci.org/webpack-contrib/istanbul-instrumenter-loader

[cover]: https://codecov.io/gh/webpack-contrib/istanbul-instrumenter-loader/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/istanbul-instrumenter-loader

[chat]: https://badges.gitter.im/webpack/webpack.svg
[chat-url]: https://gitter.im/webpack/webpack
28 changes: 0 additions & 28 deletions index.js

This file was deleted.

65 changes: 55 additions & 10 deletions package.json
Expand Up @@ -8,21 +8,66 @@
"istanbul",
"coverage"
],
"homepage": "https://github.com/deepsweet/istanbul-instrumenter-loader",
"repository": "deepsweet/istanbul-instrumenter-loader",
"author": "Kir Belevich <kir@soulshine.in> (https://github.com/deepsweet)",
"main": "index.js",
"homepage": "https://github.com/webpack-contrib/istanbul-instrumenter-loader",
"repository": "https://github.com/webpack-contrib/istanbul-instrumenter-loader.git",
"author": "Kir Belevich (@deepsweet)",
"main": "dist/cjs.js",
"files": [
"index.js"
"dist"
],
"dependencies": {
"convert-source-map": "^1.3.0",
"istanbul-lib-instrument": "^1.1.3",
"loader-utils": "^0.2.16",
"object-assign": "^4.1.0"
"loader-utils": "^1.1.0"
},
"engines": {
"node": ">=0.12.0"
"node": ">= 4.3 < 5.0.0 || >= 5.10"
},
"license": "MIT"
}
"license": "MIT",
"scripts": {
"webpack-defaults": "webpack-defaults",
"start": "yarn run build -- -w",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'",
"clean:dist": "del-cli dist",
"lint": "eslint --cache src test",
"lint-staged": "lint-staged",
"prebuild": "yarn run clean",
"prepublish": "yarn run build",
"release": "yarn run standard-version",
"security": "nsp check",
"serve:dev": "nodemon $2 --exec babel-node",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"travis:coverage": "yarn run test:coverage",
"travis:lint": "yarn run lint && yarn run security",
"travis:test": "yarn run test",
"clean": "del-cli dist"
},
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-jest": "^19.0.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.2.2",
"cross-env": "^3.2.4",
"del-cli": "^0.2.1",
"eslint": "^3.18.0",
"eslint-config-webpack": "^1.1.1",
"eslint-plugin-import": "^2.2.0",
"jest": "^19.0.2",
"lint-staged": "^3.4.0",
"nodemon": "^1.11.0",
"nsp": "^2.6.3",
"pre-commit": "^1.2.2",
"standard-version": "^4.0.0",
"webpack-defaults": "^1.0.1"
},
"pre-commit": "lint-staged",
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
}
}
1 change: 1 addition & 0 deletions src/cjs.js
@@ -0,0 +1 @@
module.exports = require('./index').default;
21 changes: 21 additions & 0 deletions src/index.js
@@ -0,0 +1,21 @@
import istanbulLibInstrument from 'istanbul-lib-instrument';
import loaderUtils from 'loader-utils';
import convert from 'convert-source-map';

export default function (source, sourceMap) {
let srcMap = sourceMap;
// use inline source map, if any
const inlineSourceMap = convert.fromSource(source);
if (!srcMap && inlineSourceMap) {
srcMap = inlineSourceMap.sourcemap;
}

const userOptions = loaderUtils.parseQuery(this.query);
const instrumenter = istanbulLibInstrument.createInstrumenter(
Object.assign({ produceSourceMap: this.srcMap }, userOptions),
);

return instrumenter.instrument(source, this.resourcePath, (error, source) => {
this.callback(error, source, instrumenter.lastSourceMap());
}, srcMap);
}