Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,21 @@
# Changelog
## 2017-5-30:
### 2.1.1
* Properly support older versions of node. Tested in:
* 4.8.3
* 5.11.1
* 6.10.3
### 2.1.0
* No longer will intercept what should be a standard Webpack "File not found" error.
* This also resolves the issue where the plugin wouldn't recognize when a file was added.
* Hardened tests.
* Cleaned up code and added an 'engines' config to package.json
## 2017-3-31:
### 2.0.0
* Use the compiler filesystem, which helps when other plugins change the 'fs' object being used by the compiler.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Michael Pratt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,56 @@
Case Sensitive Paths - Webpack Plugin
==========
This Webpack plugin enforces the entire path of all required modules match the exact case of the actual path on disk.
Using this plugin helps alleviate cases where developers working on OSX, which does not follow strict path case sensitivity,
will cause conflicts with other developers or build boxes running other operating systems which require correctly cased paths.
[Previous](https://gist.github.com/Morhaus/333579c2a5b4db644bd50) [iterations](https://github.com/dcousineau/force-case-sensitivity-webpack-plugin) on this same idea provide the basis for this plugin, but unfortunately do not properly check case on
the entire path. This plugin fixes that. Example output:
> ERROR in ./src/containers/SearchProducts.js
Module not found: Error: [CaseSensitivePathsPlugin] `/Users/example/yourproject/src/components/searchProducts/searchproducts.js` does not match the corresponding path on disk `/Users/example/yourproject/src/components/searchproducts`
@ ./src/containers/SearchProducts.js 9:22-84
Install
----
npm install --save-dev case-sensitive-paths-webpack-plugin
Usage
----
```JavaScript
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
var webpackConfig = {
plugins: [
new CaseSensitivePathsPlugin()
// other plugins ...
]
// other webpack config ...
}
```
Want more information? Pass ```{debug: true}``` to the plugin like so:
```JavaScript
new CaseSensitivePathsPlugin({debug: true})
```
It will output every directory it reads, as well as a sum total of filesystem operations.
This is mostly useful for internal debugging of the plugin, but if you find it useful, more power to you.
Demo
---
Check the `/demo` directory for a working example of the plugin in action, with tests demonstrating the effect of the plugin. See `/demo/README.md` for more.
Thanks & Credit
----
* [Daniel Cousineau](https://github.com/dcousineau) who wrote an [earlier version](https://github.com/dcousineau/force-case-sensitivity-webpack-plugin) of this case-sensitivity plugin
* [Alexandre Kirszenberg](https://github.com/Morhaus) who's [gist](https://gist.github.com/Morhaus/333579c2a5b4db644bd5) formed the basis of both these plugins.
* [Cameron Brewer](https://github.com/morethanfire) and [Ben Collins](https://github.com/aggieben) who added Windows support.
* [Christian Lilley](https://github.com/xml) who added a demo/test package.
* [Lance Eastgate](https://github.com/NorwegianKiwi) who added some internationalization support
* [Jonathan Kim](https://github.com/jkimbo) and [Dan Abramov](https://github.com/gaearon) who investigated, fixed, and added some tests for a crashing bug.
* [Jason Quense](https://github.com/jquense) who switched it to properly use the webpack-provided fs object.
* [Cesare Soldini](https://github.com/caesarsol) who added a test

View File

@@ -0,0 +1,167 @@
"use strict";
/* This plugin based on https://gist.github.com/Morhaus/333579c2a5b4db644bd5
Original license:
--------
The MIT License (MIT)
Copyright (c) 2015 Alexandre Kirszenberg
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------
And it's NPM-ified version: https://github.com/dcousineau/force-case-sensitivity-webpack-plugin
Author Daniel Cousineau indicated MIT license as well but did not include it
The originals did not properly case-sensitize the entire path, however. This plugin resolves that issue.
This plugin license, also MIT:
--------
The MIT License (MIT)
Copyright (c) 2016 Michael Pratt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------
*/
const path = require('path');
function CaseSensitivePathsPlugin(options) {
this.options = options || {};
this.reset();
}
CaseSensitivePathsPlugin.prototype.reset = function () {
this.pathCache = {};
this.fsOperations = 0;
this.primed = false;
};
CaseSensitivePathsPlugin.prototype.getFilenamesInDir = function (dir, callback) {
const that = this;
const fs = this.compiler.inputFileSystem;
this.fsOperations += 1;
if (Object.prototype.hasOwnProperty.call(this.pathCache, dir)) {
callback(this.pathCache[dir]);
return;
}
if (this.options.debug) {
console.log('[CaseSensitivePathsPlugin] Reading directory', dir);
}
fs.readdir(dir, (err, files) => {
if (err) {
if (that.options.debug) {
console.log('[CaseSensitivePathsPlugin] Failed to read directory', dir, err);
}
callback([]);
return;
}
callback(files.map(f => f.normalize ? f.normalize('NFC') : f));
});
};
// This function based on code found at http://stackoverflow.com/questions/27367261/check-if-file-exists-case-sensitive
// By Patrick McElhaney (No license indicated - Stack Overflow Answer)
// This version will return with the real name of any incorrectly-cased portion of the path, null otherwise.
CaseSensitivePathsPlugin.prototype.fileExistsWithCase = function (filepath, callback) {
// Split filepath into current filename (or directory name) and parent directory tree.
const that = this;
const dir = path.dirname(filepath);
const filename = path.basename(filepath);
const parsedPath = path.parse(dir);
// If we are at the root, or have found a path we already know is good, return.
if (parsedPath.dir === parsedPath.root || dir === '.' || Object.prototype.hasOwnProperty.call(that.pathCache, filepath)) {
callback();
return;
}
// Check all filenames in the current dir against current filename to ensure one of them matches.
// Read from the cache if available, from FS if not.
that.getFilenamesInDir(dir, (filenames) => {
// If the exact match does not exist, attempt to find the correct filename.
if (filenames.indexOf(filename) === -1) {
// Fallback value which triggers us to abort.
let correctFilename = '!nonexistent';
for (let i = 0; i < filenames.length; i += 1) {
if (filenames[i].toLowerCase() === filename.toLowerCase()) {
correctFilename = `\`${filenames[i]}\`.`;
break;
}
}
callback(correctFilename);
return;
}
// If exact match exists, recurse through directory tree until root.
that.fileExistsWithCase(dir, (recurse) => {
// If found an error elsewhere, return that correct filename
// Don't bother caching - we're about to error out anyway.
if (!recurse) {
that.pathCache[dir] = filenames;
}
callback(recurse);
});
});
};
CaseSensitivePathsPlugin.prototype.primeCache = function (callback) {
if (this.primed) {
callback();
return;
}
const that = this;
// Prime the cache with the current directory. We have to assume the current casing is correct,
// as in certain circumstances people can switch into an incorrectly-cased directory.
const currentPath = path.resolve();
that.getFilenamesInDir(currentPath, (files) => {
that.pathCache[currentPath] = files;
that.primed = true;
callback();
});
};
CaseSensitivePathsPlugin.prototype.apply = function (compiler) {
const that = this;
this.compiler = compiler;
compiler.plugin('done', () => {
if (that.options.debug) {
console.log('[CaseSensitivePathsPlugin] Total filesystem reads:', that.fsOperations);
}
that.reset();
});
compiler.plugin('normal-module-factory', (nmf) => {
nmf.plugin('after-resolve', (data, done) => {
that.primeCache(() => {
// Trim ? off, since some loaders add that to the resource they're attemping to load
let pathName = data.resource.split('?')[0];
pathName = pathName.normalize ? pathName.normalize('NFC') : pathName;
that.fileExistsWithCase(pathName, (realName) => {
if (realName) {
if (realName === '!nonexistent') {
// If file does not exist, let Webpack show a more appropriate error.
done(null, data);
} else {
done(new Error(`[CaseSensitivePathsPlugin] \`${pathName}\` does not match the corresponding path on disk ${realName}`));
}
} else {
done(null, data);
}
});
});
});
});
};
module.exports = CaseSensitivePathsPlugin;

View File

@@ -0,0 +1,72 @@
{
"_args": [
[
"case-sensitive-paths-webpack-plugin@2.1.1",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "case-sensitive-paths-webpack-plugin@2.1.1",
"_id": "case-sensitive-paths-webpack-plugin@2.1.1",
"_inBundle": false,
"_integrity": "sha1-PSnO2MHxJL9vU4Rvs/WJRzH9yQk=",
"_location": "/react-scripts/case-sensitive-paths-webpack-plugin",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "case-sensitive-paths-webpack-plugin@2.1.1",
"name": "case-sensitive-paths-webpack-plugin",
"escapedName": "case-sensitive-paths-webpack-plugin",
"rawSpec": "2.1.1",
"saveSpec": null,
"fetchSpec": "2.1.1"
},
"_requiredBy": [
"/react-scripts"
],
"_resolved": "https://registry.npmjs.org/case-sensitive-paths-webpack-plugin/-/case-sensitive-paths-webpack-plugin-2.1.1.tgz",
"_spec": "2.1.1",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Michael Pratt"
},
"bugs": {
"url": "https://github.com/Urthen/case-sensitive-paths-webpack-plugin/issues"
},
"description": "Enforces module path case sensitivity in Webpack",
"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.2.0",
"eslint-plugin-import": "^2.3.0",
"fs-extra": "^2.1.2",
"mocha": "^3.0.1",
"webpack": "^1.13.1"
},
"engines": {
"node": ">4.0"
},
"files": [
"index.js"
],
"homepage": "https://github.com/Urthen/case-sensitive-paths-webpack-plugin#readme",
"keywords": [
"webpack",
"plugin",
"case sensitive",
"import",
"require"
],
"license": "MIT",
"main": "index.js",
"name": "case-sensitive-paths-webpack-plugin",
"repository": {
"type": "git",
"url": "git+https://github.com/Urthen/case-sensitive-paths-webpack-plugin.git"
},
"scripts": {
"lint": "eslint index.js",
"lintfix": "eslint --fix index.js",
"test": "mocha test/"
},
"version": "2.1.1"
}