Skip to content

Commit

Permalink
chore: formatted code and added deploy job
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojz committed Apr 20, 2018
1 parent 3c5f33b commit ea7297e
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 64 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.nycrc
.spec_output
.travis.yml
.npmrc

/rollup.config.js
/webpack.config.js
Expand All @@ -21,3 +22,4 @@ tests
webpack.config.js
temp
fixtures

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
31 changes: 17 additions & 14 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
machine:
node:
version: "6"
version: "8"
environment:
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
general:
branches:
ignore:
- gh-pages
dependencies:
override:
- yarn
cache_directories:
- ~/.cache/yarn
test:
pre:
- yarn run clean
override:
- yarn test
- yarn run lint
- yarn run test
- yarn run coverage:upload
- npm run test
- npm run lint
- npm run test
- npm run coverage:upload
deployment:
release:
tag: /^v[0-9]+(\.[0-9]+)*$/
owner: yeojz
commands:
- yarn run clean
- yarn run build
- echo -e "$NPM_USER\n$NPM_PASS\n$NPM_EMAIL" | npm login
- npx conventional-github-releaser -p angular
- npm run clean
- npm run build
- npm publish
- npm logout
beta:
tag: /^v[0-9]+(\.[0-9]+)*\-[0-9]+$/
owner: yeojz
commands:
- npx conventional-github-releaser -p angular
- npm run clean
- npm run build
- npm publish --tag next

22 changes: 18 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"url": "https://github.com/yeojz/filter-chunk-webpack-plugin/issues"
},
"devDependencies": {
"ajv": "^5.5.2",
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"codecov": "^3.0.0",
Expand Down
18 changes: 12 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ const PLUGIN_NAME = 'FilterChunkWebpackPlugin';

class FilterChunkWebpackPlugin {
constructor(options = {}) {
if (typeof options.patterns !== 'undefined' && !Array.isArray(options.patterns)) {
if (
typeof options.patterns !== 'undefined' &&
!Array.isArray(options.patterns)
) {
throw new Error('The "patterns" option should be an array');
}

this.options = Object.assign({
select: false,
patterns: [],
}, options);
this.options = Object.assign(
{
select: false,
patterns: []
},
options
);
}

apply(compiler) {
const filter = this.options.select === true ? pick : omit;

compiler.hooks.emit.tap(PLUGIN_NAME, (compilation) => {
compiler.hooks.emit.tap(PLUGIN_NAME, compilation => {
if (this.options.patterns.length > 0) {
const files = Object.keys(compilation.assets);
const matchedFiles = multimatch(files, this.options.patterns);
Expand Down
17 changes: 9 additions & 8 deletions src/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import FilterChunkWebpackPlugin from './index';

describe('FilterChunkWebpackPlugin', function () {
describe('FilterChunkWebpackPlugin', function() {
const PATTERN_ERROR = 'The "patterns" option should be an array';

it('should set options from constructor', function () {
it('should set options from constructor', function() {
const plugin = new FilterChunkWebpackPlugin({
select: true,
patterns: ['**/**']
Expand All @@ -13,18 +13,19 @@ describe('FilterChunkWebpackPlugin', function () {
expect(plugin.options.patterns).toEqual(['**/**']);
});

it('should set defaults from constructor', function () {
it('should set defaults from constructor', function() {
const plugin = new FilterChunkWebpackPlugin();

expect(plugin.options.select).toEqual(false);
expect(plugin.options.patterns).toEqual([]);
});

it('should throw an Error when patterns is not array', function () {
const plugin = () => new FilterChunkWebpackPlugin({
patterns: 'test'
});
it('should throw an Error when patterns is not array', function() {
const plugin = () =>
new FilterChunkWebpackPlugin({
patterns: 'test'
});

expect(plugin).toThrow(PATTERN_ERROR)
expect(plugin).toThrow(PATTERN_ERROR);
});
});
58 changes: 26 additions & 32 deletions src/usage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import FilterChunkWebpackPlugin from './index';
const OUTPUT_ROOT = path.join(path.resolve(__dirname), '..', '.spec_output');
const INPUT_ROOT = path.join(path.resolve(__dirname), '..', 'fixtures');

describe('Webpack with FilterChunkWebpackPlugin', function () {
it('[1] should not modify assets by default', function (done) {
describe('Webpack with FilterChunkWebpackPlugin', function() {
it('[1] should not modify assets by default', function(done) {
const config = generateWebpackConfiguration('it-1');

webpack(config, function (err, stats) {
webpack(config, function(err, stats) {
const assets = Object.keys(stats.compilation.assets);

expect(err).toBeFalsy();
Expand All @@ -21,15 +21,12 @@ describe('Webpack with FilterChunkWebpackPlugin', function () {
});
});

it('[2] should omit all relevant matches', function (done) {
it('[2] should omit all relevant matches', function(done) {
const config = generateWebpackConfiguration('it-2', {
patterns: [
'assets/**',
'!assets/css/**'
]
patterns: ['assets/**', '!assets/css/**']
});

webpack(config, function (err, stats) {
webpack(config, function(err, stats) {
const assets = Object.keys(stats.compilation.assets);

expect(err).toBeFalsy();
Expand All @@ -42,16 +39,13 @@ describe('Webpack with FilterChunkWebpackPlugin', function () {
});
});

it('[3] should pick all relevant matches', function (done) {
it('[3] should pick all relevant matches', function(done) {
const config = generateWebpackConfiguration('it-3', {
select: true,
patterns: [
'assets/**',
'!assets/css/**'
]
patterns: ['assets/**', '!assets/css/**']
});

webpack(config, function (err, stats) {
webpack(config, function(err, stats) {
const assets = Object.keys(stats.compilation.assets);

expect(err).toBeFalsy();
Expand All @@ -76,29 +70,29 @@ function generateWebpackConfiguration(outputFolder, options) {
filename: '[name].js'
},
module: {
rules: [{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader"
]
}, {
test: /\.(svg|png)$/,
use: {
loader: 'file-loader',
options: {
name: '[ext].[ext]',
outputPath: 'assets/images/'
rules: [
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.(svg|png)$/,
use: {
loader: 'file-loader',
options: {
name: '[ext].[ext]',
outputPath: 'assets/images/'
}
}
}
}]
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "assets/css/[name].css",
chunkFilename: "assets/css/[id].css"
filename: 'assets/css/[name].css',
chunkFilename: 'assets/css/[id].css'
}),
new FilterChunkWebpackPlugin(options)
]
}
};
}

0 comments on commit ea7297e

Please sign in to comment.