Skip to content

Commit

Permalink
Fix ignoring scoped packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed May 24, 2019
1 parent a1d7e1a commit cdc608f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
let escapeRegexp = require('escape-string-regexp')
let OptimizeCss = require('optimize-css-assets-webpack-plugin')
let Compression = require('compression-webpack-plugin')
let Analyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
Expand Down Expand Up @@ -99,8 +98,13 @@ function getConfig (files, opts) {
}

if (opts.ignore && opts.ignore.length !== 0) {
let escaped = opts.ignore.map(i => escapeRegexp(i))
config.externals = new RegExp(`^(${ escaped.join('|') })($|/)`)
config.externals = (context, request, callback) => {
if (opts.ignore.some(i => request.startsWith(i))) {
callback(null, 'root a')
} else {
callback()
}
}
}

if (opts.analyzer) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"cosmiconfig": "^5.2.0",
"css-loader": "^2.1.1",
"del": "^4.1.1",
"escape-string-regexp": "^2.0.0",
"estimo": "^0.1.9",
"file-loader": "^3.0.1",
"globby": "^9.2.0",
Expand All @@ -42,6 +41,7 @@
"devDependencies": {
"@babel/runtime": "^7.4.4",
"@logux/eslint-config": "^28.2.1",
"@storeon/crosstab": "^0.4.0",
"clean-publish": "^1.1.2",
"cross-spawn": "^6.0.5",
"eslint": "^5.16.0",
Expand Down
4 changes: 2 additions & 2 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ it('supports absolute path', async () => {

it('ignores peerDependencies', async () => {
let { out, code } = await run([], { cwd: fixture('peer') })
expect(out).toContain('Package size: 22 B')
expect(out).toContain('Package size: 9 B')
expect(code).toEqual(0)
})

it('supports ignore option', async () => {
let { out, code } = await run([], { cwd: fixture('ignore') })
expect(out).toContain('Package size: 22 B')
expect(out).toContain('Package size: 9 B')
expect(code).toEqual(0)
})

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/peer/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require('redux')
require('redux/lib/redux')
require('@storeon/crosstab')
3 changes: 2 additions & 1 deletion test/fixtures/peer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"private": true,
"peerDependencies": {
"redux": "*"
"redux": "*",
"@storeon/crosstab": "*"
},
"size-limit": [
{
Expand Down
6 changes: 4 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ it('removes non-production code', async () => {
})

it('ignores dependencies on request', async () => {
let size = await getSize(fixture('peer/index'), { ignore: ['redux'] })
expect(size.parsed).toEqual(83)
let size = await getSize(fixture('peer/index'), {
ignore: ['redux', '@storeon/crosstab']
})
expect(size.parsed).toEqual(43)
})

it('disables webpack on request', async () => {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@
dependencies:
any-observable "^0.3.0"

"@storeon/crosstab@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@storeon/crosstab/-/crosstab-0.4.0.tgz#bf2eecf6c420bd111a0519c47c863f86cccf8736"
integrity sha512-GkENg8YbWIYpEom54ChvZNSTd9T60evGF5NbSkpYNWTogUbj7TjAISrjT+fEY9RYF5NANcDZOReocMx1wzj38w==

"@types/babel__core@^7.1.0":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.1.tgz#ce9a9e5d92b7031421e1d0d74ae59f572ba48be6"
Expand Down Expand Up @@ -2302,11 +2307,6 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.4, escape-string-regexp@^
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=

escape-string-regexp@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344"
integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==

escodegen@^1.9.1:
version "1.11.1"
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.11.1.tgz#c485ff8d6b4cdb89e27f4a856e91f118401ca510"
Expand Down

0 comments on commit cdc608f

Please sign in to comment.