Skip to content

Commit a92b727

Browse files
committed
Remove support for deprecated except option.
1 parent a51b5b4 commit a92b727

File tree

3 files changed

+39
-57
lines changed

3 files changed

+39
-57
lines changed

README.md

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
# rollup-plugin-node-externals
2-
32
A Rollup plugin that automatically declares NodeJS built-in modules as `external`. Can also handle npm dependencies, devDependencies, peerDependencies and optionalDependencies. Works in monorepos too!
43

54
## Why?
5+
By default, Rollup doesn't know a thing about NodeJS, so trying to bundle simple things like `import * as path from 'path'` in your code generates an `Unresolved dependencies` warning.
66

7-
By default, Rollup doesn't know a thing about NodeJS, so trying to bundle simple things like `import * as path from 'path'` in your code generates an `Unresolved dependencies` error. The solution here is twofold:
8-
* Either use some kind of shim like those provided by [rollup-plugin-node-builtins](https://github.com/calvinmetcalf/rollup-plugin-node-builtins).
9-
* Or tell Rollup that the `path` module is in fact `external`: this way, Rollup won't try to bundle it in and rather leave the `import` statement as is (or translate it to a `require()` call if bundling for CommonJS).
7+
The solution here is quite simple: you must tell Rollup that the `path` module is in fact `external`. This way, Rollup won't try to bundle it in and rather leave the `import` statement as is (or translate it to a `require()` call if bundling for CommonJS).
108

11-
However, this must be done for each and every NodeJS built-in: `path`, `os`, `fs`, etc., which can quicky become cumbersome when done manually. So the primary goal of this plugin is simply to automatically declare all NodeJS built-in modules as `external`.
12-
> Note: the list of builtins is obtained via [the builtin-modules package](https://github.com/sindresorhus/builtin-modules) by Sindre Sorhus and should be up-to-date with your current NodeJS version.
9+
However, this must be done for each and every NodeJS built-in that you happen to use in your program: `path`, `os`, `fs`, `url`, etc., which can quicky become cumbersome when done manually.
1310

14-
This plugin will also allow you to declare your dependencies (as declared in your `package.json` file) as `external`. This may come in handy when building an [Electron](https://electronjs.org) app, for example.
11+
So the primary goal of this plugin is simply to automatically declare all NodeJS built-in modules as `external`.
1512

13+
This plugin will also allow you to declare your dependencies (as declared in your `package.json` file) as `external`.
1614

17-
## Install
1815

16+
## Install
1917
```sh
2018
npm install --save-dev rollup-plugin-node-externals
2119
```
2220

2321

2422
## Usage
25-
2623
```js
2724
import externals from 'rollup-plugin-node-externals'
2825

@@ -50,14 +47,11 @@ export default {
5047
// Make pkg.devDependencies external. Optional. Default: true
5148
devDeps: true,
5249

53-
// Modules to exclude from externals. Optional. Default: none
50+
// Modules to exclude from externals. Optional. Default: []
5451
exclude: [],
5552

56-
// Modules to include in externals. Optional. Default: all
57-
include: [],
58-
59-
// Deprecated -- see below
60-
except: []
53+
// Modules to include in externals. Optional. Default: []
54+
include: []
6155
})
6256
]
6357
}
@@ -75,46 +69,28 @@ export default {
7569
}
7670
```
7771

78-
> Note: if you're also using `@rollup/plugin-node-resolve`, make sure this plugin comes before it in the `plugins` array:
79-
```js
80-
import externals from 'rollup-plugin-node-externals'
81-
import resolve from '@rollup/plugin-node-resolve'
82-
// ...
83-
84-
export default {
85-
// ...
86-
plugins: [
87-
externals(),
88-
resolve(),
89-
// other plugins
90-
]
91-
}
92-
```
93-
94-
9572
### Options
96-
9773
By default, the plugin will mark all Node builtin modules and _all_ your `dev-`, `peer-` and `optionalDependencies` as external. Normal `dependencies` are left unmarked so Rollup will still bundle them with your code as expected in most situations.
9874

99-
- **packagePath?: string | string[] = []**
75+
#### packagePath?: string | string[] = []
10076

10177
If you're working with monorepos, the `packagePath` is made for you. It can take a path, or an array of paths, to your package.json file(s). If not specified, the default is to start with the current directory's package.json then go up scan for all package.json files in parent directories recursively until either the root git directory is reached or until no other package.json can be found.
10278

103-
- **builtins?: boolean = true**
104-
- **deps?: boolean = false**
105-
- **devDeps?: boolean = true**
106-
- **peerDeps?: boolean = true**
107-
- **optDeps?: boolean = true**
79+
#### builtins?: boolean = true
80+
#### deps?: boolean = false
81+
#### devDeps?: boolean = true
82+
#### peerDeps?: boolean = true
83+
#### optDeps?: boolean = true
10884

10985
Set the `builtins`, `deps`, `devDeps`, `peerDeps` and/or `optDeps` options to `false` to prevent the corresponding dependencies from being externalized, therefore letting Rollup bundle them with your code. Set them to `true` for Rollup to treat the corresponding dependencies as external.
11086

111-
- **include?: string | RegExp | (string | RegExp)[] = []**
112-
- **exclude?: string | RegExp | (string | RegExp)[] = []**
87+
#### include?: string | RegExp | (string | RegExp)[] = []
88+
#### exclude?: string | RegExp | (string | RegExp)[] = []
11389

11490
Use the `exclude` option to remove certain dependencies from the list of externals, for example:
11591
```js
11692
externals({
117-
deps: true, // Don't bundle dependencies, we'll require() them at runtime instead
93+
deps: true, // Don't bundle dependencies, we'll import/require them at runtime instead
11894
exclude: [
11995
'electron-reload', // Yet we want `electron-reload` bundled in
12096
/^vuex?/ // as well as the VueJS family (vue, vuex, vue-router, etc.)
@@ -125,8 +101,8 @@ externals({
125101
Use the `include` option to force certain dependencies into the list of externals, for example:
126102
```js
127103
externals({
128-
peerDeps: false, // Bundle peerDependencies in
129-
include: /^lodash/ // Except for Lodash
104+
optDeps: false, // Bundle optionalDependencies in
105+
include: /^fsevents/ // Except for fsevents
130106
})
131107
```
132108

@@ -145,6 +121,23 @@ externals({
145121
})
146122
```
147123

124+
> Note3: if you're also using `@rollup/plugin-node-resolve`, make sure this plugin comes before it in the `plugins` array:
125+
```js
126+
import externals from 'rollup-plugin-node-externals'
127+
import resolve from '@rollup/plugin-node-resolve'
128+
// ...
129+
130+
export default {
131+
// ...
132+
plugins: [
133+
externals(),
134+
resolve(),
135+
// other plugins
136+
]
137+
}
138+
```
139+
140+
148141
### Migrating from version 1.x
149142

150143
- In 1.x, normal dependencies were externalized by default. This is no more true, so you'll need to change:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup-plugin-node-externals",
3-
"version": "2.2.0",
3+
"version": "3.0.0",
44
"description": "Automatically declare NodeJS built-in modules and npm dependencies as 'external' in Rollup config",
55
"author": "Stephan Schreiber <[email protected]>",
66
"contributors": [

src/index.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@ export interface ExternalsOptions {
2323
include?: string | RegExp | (string | RegExp)[]
2424
/** Exclude these deps from the list of externals, regardless of other settings. Defaults to `[]` */
2525
exclude?: string | RegExp | (string | RegExp)[]
26-
/** @deprecated Use `exclude` instead. */
27-
except?: string | RegExp | (string | RegExp)[]
2826
}
2927

30-
/** @deprecated Use `ExternalsOptions` instead. */
31-
export type ExternalOptions = ExternalsOptions
32-
3328
/**
3429
* A Rollup plugin that automatically declares NodeJS built-in modules
3530
* and optionally npm dependencies as 'external'.
@@ -52,12 +47,11 @@ export type ExternalOptions = ExternalsOptions
5247
optDeps: true,
5348
include: [],
5449
exclude: [],
55-
except: [],
5650
...options
5751
}
5852

5953
// Map the include and exclude options to arrays of regexes
60-
const [ include, exclude, except ] = [ 'include', 'exclude', 'except' ].map(option => new Array()
54+
const [ include, exclude ] = [ 'include', 'exclude' ].map(option => new Array()
6155
.concat((opts as any)[option])
6256
.map((entry: string | RegExp, index: number): RegExp => {
6357
if (entry instanceof RegExp) {
@@ -75,11 +69,6 @@ export type ExternalOptions = ExternalsOptions
7569
})
7670
)
7771

78-
if (except.length > 0) {
79-
warnings.push("'except' option is deprecated, please use include/exclude instead")
80-
exclude.push(...except)
81-
}
82-
8372
// Build a function to filter out unwanted dependencies
8473
const filterFn: (dep: string) => boolean = dep => !exclude.some(rx => rx.test(dep))
8574

0 commit comments

Comments
 (0)