File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Expand file tree Collapse file tree 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");
5050/** @typedef {string|string[]|false } AliasOptionNewRequest */
5151/** @typedef {{[k: string]: AliasOptionNewRequest} } AliasOptions */
5252/** @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 */
5455
5556/**
5657 * @typedef {Object } UserResolveOptions
@@ -657,7 +658,7 @@ exports.createResolver = function (options) {
657658 if ( typeof plugin === "function" ) {
658659 /** @type {function(this: Resolver, Resolver): void } */
659660 ( plugin ) . call ( resolver , resolver ) ;
660- } else {
661+ } else if ( plugin ) {
661662 plugin . apply ( resolver ) ;
662663 }
663664 }
Original file line number Diff line number Diff line change @@ -33,4 +33,46 @@ describe("plugins", function () {
3333 }
3434 ) ;
3535 } ) ;
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+ } ) ;
3678} ) ;
Original file line number Diff line number Diff line change @@ -281,6 +281,11 @@ declare interface ParsedIdentifier {
281281 internal : boolean ;
282282}
283283type Plugin =
284+ | undefined
285+ | null
286+ | false
287+ | ""
288+ | 0
284289 | { apply : ( arg0 : Resolver ) => void }
285290 | ( ( this : Resolver , arg1 : Resolver ) => void ) ;
286291declare interface PnpApiImpl {
You can’t perform that action at this time.
0 commit comments