@@ -38,21 +38,27 @@ function NpmInstallPlugin(options) {
38
38
NpmInstallPlugin . prototype . apply = function ( compiler ) {
39
39
this . compiler = compiler ;
40
40
41
+ var plugin = { name : "NpmInstallPlugin" } ;
42
+
41
43
// Recursively install missing dependencies so primary build doesn't fail
42
- compiler . plugin ( "watch-run" , this . preCompile . bind ( this ) ) ;
44
+ compiler . hooks . watchRun . tapAsync ( plugin , this . preCompile . bind ( this ) ) ;
43
45
44
46
// Install externals that wouldn't normally be resolved
45
47
if ( Array . isArray ( compiler . options . externals ) ) {
46
48
compiler . options . externals . unshift ( this . resolveExternal . bind ( this ) ) ;
47
49
}
48
50
49
- compiler . plugin ( "after-resolvers" , function ( compiler ) {
51
+ compiler . hooks . afterResolvers . tap ( plugin , ( compiler ) => {
50
52
// Install loaders on demand
51
- compiler . resolvers . loader . plugin ( "module" , this . resolveLoader . bind ( this ) ) ;
53
+ compiler . resolverFactory . hooks . resolver . tap ( "loader" , plugin , ( resolver ) => {
54
+ resolver . hooks . module . tapAsync ( "NpmInstallPlugin" , this . resolveLoader . bind ( this ) ) ;
55
+ } ) ;
52
56
53
57
// Install project dependencies on demand
54
- compiler . resolvers . normal . plugin ( "module" , this . resolveModule . bind ( this ) ) ;
55
- } . bind ( this ) )
58
+ compiler . resolverFactory . hooks . resolver . tap ( "normal" , plugin , ( resolver ) => {
59
+ resolver . hooks . module . tapAsync ( "NpmInstallPlugin" , this . resolveModule . bind ( this ) ) ;
60
+ } ) ;
61
+ } ) ;
56
62
} ;
57
63
58
64
NpmInstallPlugin . prototype . install = function ( result ) {
@@ -128,27 +134,20 @@ NpmInstallPlugin.prototype.resolve = function(resolver, result, callback) {
128
134
var version = require ( "webpack/package.json" ) . version ;
129
135
var major = version . split ( "." ) . shift ( ) ;
130
136
131
- if ( major === "1" ) {
132
- return this . compiler . resolvers [ resolver ] . resolve (
133
- result . path ,
134
- result . request ,
135
- callback
136
- ) ;
137
- }
138
-
139
- if ( major === "2" || major === "3" ) {
140
- return this . compiler . resolvers [ resolver ] . resolve (
137
+ if ( major === "4" ) {
138
+ return this . compiler . resolverFactory . get ( resolver ) . resolve (
141
139
result . context || { } ,
142
140
result . path ,
143
141
result . request ,
142
+ { } ,
144
143
callback
145
144
) ;
146
145
}
147
146
148
147
throw new Error ( "Unsupported Webpack version: " + version ) ;
149
148
}
150
149
151
- NpmInstallPlugin . prototype . resolveLoader = function ( result , next ) {
150
+ NpmInstallPlugin . prototype . resolveLoader = function ( result , resolveContext , next ) {
152
151
// Only install direct dependencies, not sub-dependencies
153
152
if ( result . path . match ( "node_modules" ) ) {
154
153
return next ( ) ;
@@ -172,7 +171,7 @@ NpmInstallPlugin.prototype.resolveLoader = function(result, next) {
172
171
} . bind ( this ) ) ;
173
172
} ;
174
173
175
- NpmInstallPlugin . prototype . resolveModule = function ( result , next ) {
174
+ NpmInstallPlugin . prototype . resolveModule = function ( result , resolveContext , next ) {
176
175
// Only install direct dependencies, not sub-dependencies
177
176
if ( result . path . match ( "node_modules" ) ) {
178
177
return next ( ) ;
0 commit comments