Skip to content

Commit

Permalink
Do not fail when a directory doesn't exist
Browse files Browse the repository at this point in the history
Logs a warning and continues compilation
  • Loading branch information
GeKorm committed Sep 1, 2019
1 parent 02cd148 commit ee53953
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
const fs = require('fs');
const FileHound = require('filehound');

const pluginName = 'WebpackPermissionsPlugin';

const warn = (logger, path) => {
const errorMessage = `Directory not found ${path}`;
if (logger) {
logger.warn(errorMessage);
} else {
console.warn(`WebpackPermissionsPlugin: ${errorMessage}`);
}
};

function PermissionsOutputPlugin(options) {
this.options = options;
}

PermissionsOutputPlugin.prototype.apply = function(compiler) {
const changeFilePermissions = () => {
const logger =
compiler.getInfrastructureLogger &&
compiler.getInfrastructureLogger(pluginName);

if (this.options.buildFolders) {
for (const dir of this.options.buildFolders) {
const path = dir.path || dir;
if (!fs.existsSync(dir)) {
warn(logger, path);
return;
}

const dirs = FileHound.create()
.path(dir.path || dir)
.path(path)
.directory()
.findSync();
const files = FileHound.create()
.path(dir.path || dir)
.path(path)
.not()
.directory()
.findSync();
Expand Down Expand Up @@ -45,7 +66,7 @@ PermissionsOutputPlugin.prototype.apply = function(compiler) {
compiler.hooks.done.tap.bind(compiler.hooks.done);

if (webpackTap) {
webpackTap('WebpackPermissionsPlugin', changeFilePermissions);
webpackTap(pluginName, changeFilePermissions);
} else {
compiler.plugin('done', changeFilePermissions);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-permissions-plugin",
"version": "1.0.5",
"version": "1.0.6",
"author": "George Kormaris <[email protected]>",
"description": "A webpack plugin to set permissions for your output files and folders",
"homepage": "https://github.com/GeKorm/webpack-permissions-plugin",
Expand Down

0 comments on commit ee53953

Please sign in to comment.