mirror of https://github.com/webpack/webpack.git
add missingDependencies
This commit is contained in:
parent
ada334b199
commit
c81107ae59
|
@ -260,6 +260,8 @@ class DotenvPlugin {
|
|||
|
||||
/** @type {string[] | undefined} */
|
||||
let fileDependenciesCache;
|
||||
/** @type {string[] | undefined} */
|
||||
let missingDependenciesCache;
|
||||
|
||||
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (_params, callback) => {
|
||||
const inputFileSystem = /** @type {InputFileSystem} */ (
|
||||
|
@ -272,7 +274,7 @@ class DotenvPlugin {
|
|||
inputFileSystem,
|
||||
mode,
|
||||
context,
|
||||
(err, env, fileDependencies) => {
|
||||
(err, env, fileDependencies, missingDependencies) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
const definitions = envToDefinitions(env || {});
|
||||
|
@ -281,6 +283,8 @@ class DotenvPlugin {
|
|||
definePlugin.definitions = definitions;
|
||||
// update the file dependencies
|
||||
fileDependenciesCache = fileDependencies;
|
||||
// update the missing dependencies
|
||||
missingDependenciesCache = missingDependencies;
|
||||
|
||||
callback();
|
||||
}
|
||||
|
@ -289,6 +293,7 @@ class DotenvPlugin {
|
|||
|
||||
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
||||
compilation.fileDependencies.addAll(fileDependenciesCache || []);
|
||||
compilation.missingDependencies.addAll(missingDependenciesCache || []);
|
||||
});
|
||||
|
||||
definePlugin.apply(compiler);
|
||||
|
@ -321,7 +326,7 @@ class DotenvPlugin {
|
|||
* @param {InputFileSystem} fs the input file system
|
||||
* @param {string | undefined} mode the mode
|
||||
* @param {string} context the compiler context
|
||||
* @param {(err: Error | null, env?: Record<string, string>, fileDependencies?: string[]) => void} callback callback function
|
||||
* @param {(err: Error | null, env?: Record<string, string>, fileDependencies?: string[], missingDependencies?: string[]) => void} callback callback function
|
||||
* @returns {void}
|
||||
*/
|
||||
loadEnv(fs, mode, context, callback) {
|
||||
|
@ -353,17 +358,21 @@ class DotenvPlugin {
|
|||
const envFiles = this.getEnvFilesForMode(fs, dir, mode);
|
||||
/** @type {string[]} */
|
||||
const fileDependencies = [];
|
||||
/** @type {string[]} */
|
||||
const missingDependencies = [];
|
||||
|
||||
// Read all files
|
||||
const readPromises = envFiles.map((filePath) =>
|
||||
this.loadFile(fs, filePath).then(
|
||||
(content) => {
|
||||
fileDependencies.push(filePath);
|
||||
return { content, filePath };
|
||||
return { content, filePath, exists: true };
|
||||
},
|
||||
() =>
|
||||
// File doesn't exist, skip it (this is normal)
|
||||
({ content: "", filePath })
|
||||
() => {
|
||||
// File doesn't exist, add to missingDependencies (this is normal)
|
||||
missingDependencies.push(filePath);
|
||||
return { content: "", filePath, exists: false };
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -403,7 +412,7 @@ class DotenvPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
callback(null, env, fileDependencies);
|
||||
callback(null, env, fileDependencies, missingDependencies);
|
||||
})
|
||||
.catch((err) => {
|
||||
callback(err);
|
||||
|
|
Loading…
Reference in New Issue