Skip to content

Commit eba6f06

Browse files
authoredApr 3, 2020
feat: support scoped rollup plugin (fix #275) (#320)
1 parent f3f1be7 commit eba6f06

File tree

7 files changed

+84
-1
lines changed

7 files changed

+84
-1
lines changed
 

‎docs/plugins.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
}
1111
```
1212

13-
The name should be the package name of the plugin, without the `rollup-plugin-` prefix.
13+
If the package name starts with `rollup-plugin-`, the key should without the `rollup-plugin-` prefix. However, if the package name starts with `@rollup/`, use the full package name.
1414

1515
The value will be used as its options, passing `true` is equivalent to an empty object, `false` is used to disable built-in plugins.
1616

‎src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ export class Bundler {
332332
? nodeResolvePlugin
333333
: name === 'progress'
334334
? progressPlugin
335+
: name.startsWith('@rollup/')
336+
? this.localRequire(name)
335337
: isBuiltIn
336338
? require(`rollup-plugin-${name}`)
337339
: this.localRequire(`rollup-plugin-${name}`)

‎test/__snapshots__/index.test.ts.snap

+19
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,25 @@ module.exports = index;
242242
"
243243
`;
244244

245+
exports[`scoped rollup plugin: scoped rollup plugin dist/index.js 1`] = `
246+
"'use strict';
247+
248+
Object.defineProperty(exports, '__esModule', { value: true });
249+
250+
const tt = 'is there anything?';
251+
252+
function afun() {
253+
return tt;
254+
}
255+
256+
function another() {
257+
return afun();
258+
}
259+
260+
exports.another = another;
261+
"
262+
`;
263+
245264
exports[`target:browser: target:browser dist/index.js 1`] = `
246265
"'use strict';
247266

‎test/fixtures/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"private": true,
33
"dependencies": {
4+
"@rollup/plugin-strip": "^1.3.2",
45
"rollup-plugin-prettier": "^0.5.0",
56
"rollup-plugin-strip": "^1.2.0",
67
"rollup-plugin-typescript2": "^0.18.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const data = { foo: 'bar' }
2+
3+
const tt = 'is there anything?'
4+
5+
function afun() {
6+
console.log('test')
7+
return tt
8+
}
9+
10+
export function another() {
11+
console.log('two')
12+
return afun()
13+
}

‎test/fixtures/yarn.lock

+33
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
# yarn lockfile v1
33

44

5+
"@rollup/plugin-strip@^1.3.2":
6+
version "1.3.2"
7+
resolved "https://registry.npmjs.org/@rollup/plugin-strip/-/plugin-strip-1.3.2.tgz#9f52e99add99b835a4a3c14e02385f3726514923"
8+
integrity sha512-dByULCvYdklJRJ50XqmA/ntyvVuVnnxOrgZ6cIIMBLLzQrsm9Ui15VD+6I8a11w8Ob9R7ySwYjFck9YCMzseKA==
9+
dependencies:
10+
"@rollup/pluginutils" "^3.0.4"
11+
estree-walker "^1.0.1"
12+
magic-string "^0.25.5"
13+
14+
"@rollup/pluginutils@^3.0.4":
15+
version "3.0.8"
16+
resolved "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.0.8.tgz#4e94d128d94b90699e517ef045422960d18c8fde"
17+
integrity sha512-rYGeAc4sxcZ+kPG/Tw4/fwJODC3IXHYDH4qusdN/b6aLw5LPUbzpecYbEJh4sVQGPFJxd2dBU4kc1H3oy9/bnw==
18+
dependencies:
19+
estree-walker "^1.0.1"
20+
521
"@vue/component-compiler-utils@^2.1.0":
622
version "2.3.0"
723
resolved "https://registry.yarnpkg.com/@vue/component-compiler-utils/-/component-compiler-utils-2.3.0.tgz#4f580f1b28fc7685859d87ea0e92a1c0271c93da"
@@ -180,6 +196,11 @@ estree-walker@^0.5.2:
180196
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.5.2.tgz#d3850be7529c9580d815600b53126515e146dd39"
181197
integrity sha512-XpCnW/AE10ws/kDAs37cngSkvgIR8aN3G0MS85m7dUpuK2EREo9VJ00uvw6Dg/hXEpfsE1I1TvJOJr+Z+TL+ig==
182198

199+
estree-walker@^1.0.1:
200+
version "1.0.1"
201+
resolved "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700"
202+
integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==
203+
183204
expand-brackets@^0.1.4:
184205
version "0.1.5"
185206
resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-0.1.5.tgz#df07284e342a807cd733ac5af72411e581d1177b"
@@ -449,6 +470,13 @@ magic-string@0.25.1, magic-string@^0.25.1:
449470
dependencies:
450471
sourcemap-codec "^1.4.1"
451472

473+
magic-string@^0.25.5:
474+
version "0.25.7"
475+
resolved "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051"
476+
integrity sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==
477+
dependencies:
478+
sourcemap-codec "^1.4.4"
479+
452480
math-random@^1.0.1:
453481
version "1.0.1"
454482
resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.1.tgz#8b3aac588b8a66e4975e3cdea67f7bb329601fac"
@@ -737,6 +765,11 @@ sourcemap-codec@^1.4.1:
737765
resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.3.tgz#0ba615b73ec35112f63c2f2d9e7c3f87282b0e33"
738766
integrity sha512-vFrY/x/NdsD7Yc8mpTJXuao9S8lq08Z/kOITHz6b7YbfI9xL8Spe5EvSQUHOI7SbpY8bRPr0U3kKSsPuqEGSfA==
739767

768+
sourcemap-codec@^1.4.4:
769+
version "1.4.8"
770+
resolved "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4"
771+
integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==
772+
740773
string-hash@^1.1.0:
741774
version "1.1.3"
742775
resolved "https://registry.yarnpkg.com/string-hash/-/string-hash-1.1.3.tgz#e8aafc0ac1855b4666929ed7dd1275df5d6c811b"

‎test/index.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,21 @@ snapshot(
213213
}
214214
)
215215

216+
snapshot(
217+
{
218+
title: 'scoped rollup plugin',
219+
input: 'index.js',
220+
cwd: fixture('scoped-rollup-plugin')
221+
},
222+
{
223+
plugins: {
224+
'@rollup/plugin-strip': {
225+
functions: ['console.log']
226+
}
227+
}
228+
}
229+
)
230+
216231
snapshot(
217232
{
218233
title: 'target:browser',

0 commit comments

Comments
 (0)
Please sign in to comment.