Skip to content

Commit 0e7a1b2

Browse files
authored
Merge pull request #16 from yannickoo/fix/15-webpack-5
Make plugin compatible with Webpack 5 #15
2 parents 99380a5 + d571e60 commit 0e7a1b2

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

lib/DrupalLibrariesPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path'),
22
YAML = require('yaml'),
3+
mkdirp = require('mkdirp'),
34
DrupalLibraryEntryGenerator = require('./DrupalLibraryEntryGenerator'),
45
DrupalLibraryFile = require('./DrupalLibraryFile'),
56
DrupalLibraryMetadata = require('./DrupalLibraryMetadata'),
@@ -50,13 +51,13 @@ class DrupalLibrariesPlugin {
5051
apply(compiler) {
5152
// Prevents drupal library dependencies from being included.
5253
compiler.hooks.normalModuleFactory.tap('DrupalLibrariesPlugin', cmf => {
53-
cmf.hooks.factory.tap("DrupalLibrariesPlugin", factory => (data, callback) => {
54+
cmf.hooks.factorize.tapAsync("DrupalLibrariesPlugin", (data, callback) => {
5455
const result = this.opts.requirePattern.exec(data.request)
5556
if (result) {
5657
callback(null, new DrupalLibraryModule(result[1]))
5758
}
5859
else {
59-
factory(data, callback)
60+
return callback()
6061
}
6162
})
6263
})
@@ -155,16 +156,15 @@ class DrupalLibrariesPlugin {
155156
const content = YAML.stringify(file.content),
156157
targetPath = compilation.getPath(file.targetPath)
157158

158-
compiler.outputFileSystem.mkdirp(path.dirname(targetPath), err => {
159-
if (err) {
160-
throw reject(err.message)
161-
}
159+
mkdirp(path.dirname(targetPath)).then(() => {
162160
compiler.outputFileSystem.writeFile(targetPath, content, err => {
163161
if (err) {
164162
throw reject(err.message)
165163
}
166164
accept()
167165
})
166+
}).catch((err) => {
167+
throw reject(err.message)
168168
})
169169
}))
170170
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"webpack"
2121
],
2222
"dependencies": {
23+
"mkdirp": "^1.0.4",
2324
"yaml": "^1.6.0"
2425
},
2526
"devDependencies": {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,6 +3215,11 @@ mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
32153215
dependencies:
32163216
minimist "0.0.8"
32173217

3218+
mkdirp@^1.0.4:
3219+
version "1.0.4"
3220+
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
3221+
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
3222+
32183223
move-concurrently@^1.0.1:
32193224
version "1.0.1"
32203225
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"

0 commit comments

Comments
 (0)