Enforces module path case sensitivity in Webpack
npx @tessl/cli install tessl/npm-case-sensitive-paths-webpack-plugin@2.4.0A Webpack plugin that enforces case-sensitive module path matching across all platforms. Prevents build failures caused by incorrect file path casing that works on case-insensitive filesystems (like Windows/macOS) but fails on case-sensitive systems (like Linux).
npm install --save-dev case-sensitive-paths-webpack-pluginconst CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');Add the plugin to your Webpack configuration:
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
module.exports = {
plugins: [
new CaseSensitivePathsPlugin()
]
};With configuration options:
module.exports = {
plugins: [
new CaseSensitivePathsPlugin({
debug: true,
logger: console,
useBeforeEmitHook: false
})
]
};The CaseSensitivePathsPlugin is built around several key architectural components:
Map<string, string[]> stores directory contents to minimize filesystem readsCreates a new instance of the case-sensitive paths plugin for Webpack.
/**
* Creates a new CaseSensitivePathsPlugin instance
* @param {Object} options - Configuration options
* @param {boolean} options.debug - Enable debug logging (default: false)
* @param {Object} options.logger - Custom logger with .log() method (default: console)
* @param {boolean} options.useBeforeEmitHook - Use emit hook instead of normal module factory hook (default: false)
*/
function CaseSensitivePathsPlugin(options);Usage Examples:
// Basic usage with no options
const plugin = new CaseSensitivePathsPlugin();
// With debug enabled
const plugin = new CaseSensitivePathsPlugin({
debug: true
});
// With custom logger
const plugin = new CaseSensitivePathsPlugin({
debug: true,
logger: {
log: (message) => console.log(`[PLUGIN] ${message}`)
}
});The main Webpack plugin interface method that registers the plugin with the compiler.
/**
* Registers the plugin with the Webpack compiler
* @param {Object} compiler - Webpack compiler instance
*/
CaseSensitivePathsPlugin.prototype.apply(compiler);Resets the plugin's internal state including path cache and filesystem operation counter.
/**
* Resets internal state including path cache and filesystem operation counter
*/
CaseSensitivePathsPlugin.prototype.reset();Internal methods for validating file path case sensitivity.
/**
* Reads directory contents with caching
* @param {string} dir - Directory path to read
* @param {Function} callback - Callback function to receive file list
*/
CaseSensitivePathsPlugin.prototype.getFilenamesInDir(dir, callback);
/**
* Recursively checks if a file path exists with correct case sensitivity
* @param {string} filepath - File path to check
* @param {Function} callback - Callback function to receive result
*/
CaseSensitivePathsPlugin.prototype.fileExistsWithCase(filepath, callback);
/**
* Initializes the path cache with the current working directory
* @param {Function} callback - Callback function called when priming is complete
*/
CaseSensitivePathsPlugin.prototype.primeCache(callback);interface PluginOptions {
/** Enable debug logging to show directory reads and filesystem operations count */
debug?: boolean;
/** Custom logger object with .log() method for debug output */
logger?: { log: (message: string) => void };
/** Use the emit hook instead of the normal module factory hook for checking paths */
useBeforeEmitHook?: boolean;
}The plugin integrates with Webpack's error reporting system:
[CaseSensitivePathsPlugin] \incorrect-path` does not match the corresponding path on disk `correct-path``Example Error Output:
ERROR in [CaseSensitivePathsPlugin] `/src/Components/Button.js` does not match the corresponding path on disk `/src/components/button.js`// Main plugin class
class CaseSensitivePathsPlugin {
constructor(options?: PluginOptions);
apply(compiler: Object): void;
reset(): void;
// Internal properties
options: PluginOptions;
logger: Object;
pathCache: Map<string, string[]>;
compiler: Object;
fsOperations: number;
primed: boolean;
}
// Configuration options interface
interface PluginOptions {
debug?: boolean;
logger?: { log: (message: string) => void };
useBeforeEmitHook?: boolean;
}