Skip to content

Commit

Permalink
fix(S3UploadPlugin): do not upload files if compilation finished with…
Browse files Browse the repository at this point in the history
… errors (#111)
  • Loading branch information
ValeraS authored Jan 3, 2024
1 parent 2bd0bb1 commit e6d63e1
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/common/s3-upload/webpack-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ export class S3UploadPlugin {
}

apply(compiler: Compiler) {
compiler.hooks.done.tapPromise('S3UploadPlugin', async ({compilation}) => {
let fileNames = Object.keys(compilation.assets);
compiler.hooks.done.tapPromise('s3-upload-plugin', async (stats) => {
if (stats.hasErrors()) {
stats.compilation.warnings.push(
new WebpackError(
's3-upload-plugin: skipped upload to s3 due to compilation errors',
),
);
return;
}

let fileNames = Object.keys(stats.compilation.assets);

if (this.options.additionalPattern) {
const additionalFiles = globSync(this.options.additionalPattern, {
cwd: compilation.outputOptions.path,
cwd: stats.compilation.outputOptions.path,
});
fileNames = fileNames.concat(additionalFiles);
}

fileNames = fileNames.filter((name) => {
const fullPath = compilation.outputOptions.path + '/' + name;
const fullPath = stats.compilation.outputOptions.path + '/' + name;
return this.isIncludeAndNotExclude(fullPath);
});

Expand All @@ -44,12 +53,14 @@ export class S3UploadPlugin {
compress: this.options.compress,
options: {
...this.options.s3UploadOptions,
sourcePath: compilation.outputOptions.path ?? '',
sourcePath: stats.compilation.outputOptions.path ?? '',
},
});
} catch (e) {
const error = new WebpackError(`${e instanceof Error ? e.message : e}`);
compilation.errors.push(error);
const error = new WebpackError(
`s3-upload-plugin: ${e instanceof Error ? e.message : e}`,
);
stats.compilation.errors.push(error);
}
});
}
Expand Down

0 comments on commit e6d63e1

Please sign in to comment.