File tree 3 files changed +50
-2
lines changed
3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,8 @@ const UseFilePlugin = require("./UseFilePlugin");
50
50
/** @typedef {string|string[]|false } AliasOptionNewRequest */
51
51
/** @typedef {{[k: string]: AliasOptionNewRequest} } AliasOptions */
52
52
/** @typedef {{[k: string]: string|string[] } } ExtensionAliasOptions */
53
- /** @typedef {{apply: function(Resolver): void} | function(this: Resolver, Resolver): void } Plugin */
53
+ /** @typedef {false | 0 | "" | null | undefined } Falsy */
54
+ /** @typedef {{apply: function(Resolver): void} | (function(this: Resolver, Resolver): void) | Falsy } Plugin */
54
55
55
56
/**
56
57
* @typedef {Object } UserResolveOptions
@@ -657,7 +658,7 @@ exports.createResolver = function (options) {
657
658
if ( typeof plugin === "function" ) {
658
659
/** @type {function(this: Resolver, Resolver): void } */
659
660
( plugin ) . call ( resolver , resolver ) ;
660
- } else {
661
+ } else if ( plugin ) {
661
662
plugin . apply ( resolver ) ;
662
663
}
663
664
}
Original file line number Diff line number Diff line change @@ -33,4 +33,46 @@ describe("plugins", function () {
33
33
}
34
34
) ;
35
35
} ) ;
36
+
37
+ it ( "should ignore 'false'/'null'/'undefined' plugins" , done => {
38
+ const FailedPlugin = class {
39
+ apply ( ) {
40
+ throw new Error ( "FailedPlugin" ) ;
41
+ }
42
+ } ;
43
+ const falsy = false ;
44
+ const resolver = ResolverFactory . createResolver ( {
45
+ fileSystem : require ( "fs" ) ,
46
+ plugins : [
47
+ 0 ,
48
+ "" ,
49
+ false ,
50
+ null ,
51
+ undefined ,
52
+ falsy && new FailedPlugin ( ) ,
53
+ new CloneBasenamePlugin (
54
+ "after-existing-directory" ,
55
+ "undescribed-raw-file"
56
+ )
57
+ ]
58
+ } ) ;
59
+
60
+ resolver . resolve (
61
+ { } ,
62
+ __dirname ,
63
+ "./fixtures/directory-default" ,
64
+ { } ,
65
+ function ( err , result ) {
66
+ if ( err ) return done ( err ) ;
67
+ if ( ! result ) return done ( new Error ( "No result" ) ) ;
68
+ expect ( result ) . toEqual (
69
+ path . resolve (
70
+ __dirname ,
71
+ "fixtures/directory-default/directory-default.js"
72
+ )
73
+ ) ;
74
+ done ( ) ;
75
+ }
76
+ ) ;
77
+ } ) ;
36
78
} ) ;
Original file line number Diff line number Diff line change @@ -281,6 +281,11 @@ declare interface ParsedIdentifier {
281
281
internal : boolean ;
282
282
}
283
283
type Plugin =
284
+ | undefined
285
+ | null
286
+ | false
287
+ | ""
288
+ | 0
284
289
| { apply : ( arg0 : Resolver ) => void }
285
290
| ( ( this : Resolver , arg1 : Resolver ) => void ) ;
286
291
declare interface PnpApiImpl {
You can’t perform that action at this time.
0 commit comments