From 3b9fafc53ef8c881a61c3e567aa047fd58a0d8c8 Mon Sep 17 00:00:00 2001 From: Ben Heidemann Date: Sun, 4 Apr 2021 02:17:01 +0100 Subject: [PATCH] style: fix linting issues in webpack plugin --- src/webpack-plugin/plugin.js | 138 +++++++++++++++---------------- src/webpack-plugin/processors.js | 52 ++++++------ src/webpack-plugin/schema.js | 48 +++++------ src/webpack-plugin/utils.js | 26 +++--- 4 files changed, 132 insertions(+), 132 deletions(-) diff --git a/src/webpack-plugin/plugin.js b/src/webpack-plugin/plugin.js index b1cb334..f9fbc10 100644 --- a/src/webpack-plugin/plugin.js +++ b/src/webpack-plugin/plugin.js @@ -8,81 +8,81 @@ const OPTIONS_PROCESSORS = require('./processors'); module.exports = class FilerWebpackPlugin { - constructor(options = {}) { - utils.validateOptions(options, OPTIONS_SCHEMA); - this.options = utils.processOptions(options, OPTIONS_PROCESSORS); - } + constructor(options = {}) { + utils.validateOptions(options, OPTIONS_SCHEMA); + this.options = utils.processOptions(options, OPTIONS_PROCESSORS); + } - apply(compiler) { - compiler.hooks.normalModuleFactory.tap( - PLUGIN_NAME, - (factory) => { - factory.hooks.resolve.tap( - PLUGIN_NAME, - (resolveData) => { - // Resolve fsProvider if required - if ( - resolveData.request === 'fsProvider' + apply(compiler) { + compiler.hooks.normalModuleFactory.tap( + PLUGIN_NAME, + (factory) => { + factory.hooks.resolve.tap( + PLUGIN_NAME, + (resolveData) => { + // Resolve fsProvider if required + if ( + resolveData.request === 'fsProvider' && resolveData.context === this.options.shimsDir - ) { - return this.resolveFsProvider(resolveData); - } + ) { + return this.resolveFsProvider(resolveData); + } - // Ignore filer files (these should resolve modules normally) - if (resolveData.context.startsWith(this.options.filerDir)) return; + // Ignore filer files (these should resolve modules normally) + if (resolveData.context.startsWith(this.options.filerDir)) return; - // Apply fs, path and buffer shims if required - switch (resolveData.request) { - case 'fs': - if (!this.options.shimFs) return; - return this.applyFsShim(resolveData); - case 'path': - if (!this.options.shimPath) return; - return this.applyPathShim(resolveData); - case 'buffer': - if (!this.options.shimBuffer) return; - return this.applyBufferShim(resolveData); - default: - return; - } - } - ); - }, - ) - } - - resolveFsProvider(resolveData) { - switch (this.options.fsProvider) { - case 'default': - resolveData.request = path.join(this.options.fsProviderDir, 'default.js'); - break; - case 'indexeddb': - resolveData.request = path.join(this.options.fsProviderDir, 'indexeddb.js'); - break; - case 'memory': - resolveData.request = path.join(this.options.fsProviderDir, 'memory.js'); - break; - case 'custom': - resolveData.request = path.join(this.options.fsProviderDir, 'custom.js'); - break; + // Apply fs, path and buffer shims if required + switch (resolveData.request) { + case 'fs': + if (!this.options.shimFs) return; + return this.applyFsShim(resolveData); + case 'path': + if (!this.options.shimPath) return; + return this.applyPathShim(resolveData); + case 'buffer': + if (!this.options.shimBuffer) return; + return this.applyBufferShim(resolveData); default: - throw new Error([ - `Invalid option for fsProvider.`, - `fsProvider must be one of 'default', 'indexeddb', 'memory' or 'custom'.`, - `If using a custom fsProvider, you must also provide the fsProviderDir option.` - ].join(' ')); - } - } + return; + } + } + ); + }, + ); + } - applyFsShim(resolveData) { - resolveData.request = path.join(this.options.shimsDir, 'fs.js'); + resolveFsProvider(resolveData) { + switch (this.options.fsProvider) { + case 'default': + resolveData.request = path.join(this.options.fsProviderDir, 'default.js'); + break; + case 'indexeddb': + resolveData.request = path.join(this.options.fsProviderDir, 'indexeddb.js'); + break; + case 'memory': + resolveData.request = path.join(this.options.fsProviderDir, 'memory.js'); + break; + case 'custom': + resolveData.request = path.join(this.options.fsProviderDir, 'custom.js'); + break; + default: + throw new Error([ + 'Invalid option for fsProvider.', + 'fsProvider must be one of \'default\', \'indexeddb\', \'memory\' or \'custom\'.', + 'If using a custom fsProvider, you must also provide the fsProviderDir option.' + ].join(' ')); } + } + + applyFsShim(resolveData) { + resolveData.request = path.join(this.options.shimsDir, 'fs.js'); + } - applyPathShim(resolveData) { - resolveData.request = path.join(this.options.shimsDir, 'path.js'); - } + applyPathShim(resolveData) { + resolveData.request = path.join(this.options.shimsDir, 'path.js'); + } - applyBufferShim(resolveData) { - resolveData.request = path.join(this.options.shimsDir, 'buffer.js'); - } -} + applyBufferShim(resolveData) { + resolveData.request = path.join(this.options.shimsDir, 'buffer.js'); + } +}; diff --git a/src/webpack-plugin/processors.js b/src/webpack-plugin/processors.js index 69b8810..22754e5 100644 --- a/src/webpack-plugin/processors.js +++ b/src/webpack-plugin/processors.js @@ -2,32 +2,32 @@ const ROOT_DIR_TAG = ''; const CWD = process.cwd(); module.exports = { - filerDir: { - process: function(value) { - if (!value) { - return path.join(CWD, 'node_modules', 'filer'); - } - return value.replace(ROOT_DIR_TAG, CWD); - }, + filerDir: { + process: function(value) { + if (!value) { + return path.join(CWD, 'node_modules', 'filer'); + } + return value.replace(ROOT_DIR_TAG, CWD); }, - shimsDir: { - process: function(value) { - if (!value) { - return path.join(CWD, 'node_modules', 'filer', 'shims'); - } - return value.replace(ROOT_DIR_TAG, CWD); - } - }, - shimFs: { default: true }, - shimPath: { default: true}, - shimBuffer: { default: true}, - fsProvider: { default: 'default'}, - fsProviderDir: { - process: function(value) { - if (!value) { - return path.join(CWD, 'node_modules', 'filer', 'shims', 'providers'); - } - return value.replace(ROOT_DIR_TAG, CWD); - }, + }, + shimsDir: { + process: function(value) { + if (!value) { + return path.join(CWD, 'node_modules', 'filer', 'shims'); + } + return value.replace(ROOT_DIR_TAG, CWD); + } + }, + shimFs: { default: true }, + shimPath: { default: true}, + shimBuffer: { default: true}, + fsProvider: { default: 'default'}, + fsProviderDir: { + process: function(value) { + if (!value) { + return path.join(CWD, 'node_modules', 'filer', 'shims', 'providers'); + } + return value.replace(ROOT_DIR_TAG, CWD); }, + }, }; diff --git a/src/webpack-plugin/schema.js b/src/webpack-plugin/schema.js index 40e57ac..0a6a4b7 100644 --- a/src/webpack-plugin/schema.js +++ b/src/webpack-plugin/schema.js @@ -1,26 +1,26 @@ module.exports = { - type: 'object', - properties: { - filerDir: { - type: 'string', - }, - shimsDir: { - type: 'string', - }, - shimFs: { - type: 'boolean', - }, - shimPath: { - type: 'boolean', - }, - shimBuffer: { - type: 'boolean', - }, - fsProvider: { - type: 'string', - }, - fsProviderDir: { - type: 'string', - }, - } + type: 'object', + properties: { + filerDir: { + type: 'string', + }, + shimsDir: { + type: 'string', + }, + shimFs: { + type: 'boolean', + }, + shimPath: { + type: 'boolean', + }, + shimBuffer: { + type: 'boolean', + }, + fsProvider: { + type: 'string', + }, + fsProviderDir: { + type: 'string', + }, + } }; diff --git a/src/webpack-plugin/utils.js b/src/webpack-plugin/utils.js index 79954cb..9137ec9 100644 --- a/src/webpack-plugin/utils.js +++ b/src/webpack-plugin/utils.js @@ -1,26 +1,26 @@ var { validate } = require('schema-utils'); function validateOptions(options, schema) { - validate(schema, options); + validate(schema, options); } function processOptions(options, processors) { - const processedOptions = {}; + const processedOptions = {}; - for (const [property, processor] of Object.entries(processors)) { - processedOptions[property] = options[property]; - if (processedOptions[property] === undefined) { - processedOptions[property] = processor.default; - } - if (processor.process) { - processedOptions[property] = processor.process(processedOptions[property]); - } + for (const [property, processor] of Object.entries(processors)) { + processedOptions[property] = options[property]; + if (processedOptions[property] === undefined) { + processedOptions[property] = processor.default; } + if (processor.process) { + processedOptions[property] = processor.process(processedOptions[property]); + } + } - return processedOptions; + return processedOptions; } module.exports = { - validateOptions, - processOptions, + validateOptions, + processOptions, };