Last active
January 30, 2017 16:56
-
-
Save pllearns/bda3e18207f55df173216fff0f39bef1 to your computer and use it in GitHub Desktop.
webpack/enhanced-resolve-es6-refactor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"root": true, | |
"plugins": ["node", "eslint-plugin-node"], | |
"extends": ["eslint:recommended", "plugin:node/recommended"], | |
"env": { | |
"node": true, | |
"es6": true | |
}, | |
"rules": { | |
"quotes": ["error", "double"], | |
"no-undef": "error", | |
"no-extra-semi": "error", | |
"semi": "error", | |
"no-template-curly-in-string": "error", | |
"no-caller": "error", | |
"yoda": "error", | |
"eqeqeq": "error", | |
"global-require": "off", | |
"brace-style": "error", | |
"eol-last": "error", | |
"indent": ["error", "tab", { "SwitchCase": 1 }], | |
"no-extra-bind": "warn", | |
"no-empty": "off", | |
"no-multiple-empty-lines": "error", | |
"no-multi-spaces": "error", | |
"no-process-exit": "warn", | |
"space-in-parens": "error", | |
"no-trailing-spaces": "error", | |
"no-use-before-define": "off", | |
"no-unused-vars": ["error", {"args": "none"}], | |
"key-spacing": "error", | |
"space-infix-ops": "error", | |
"no-unsafe-negation": "error", | |
"no-loop-func": "warn", | |
"space-before-function-paren": ["error", "never"], | |
"space-before-blocks": "error", | |
"object-curly-spacing": ["error", "always"], | |
"keyword-spacing": ["error", { | |
"after": false, | |
"overrides": { | |
"try": {"after": true}, | |
"else": {"after": true}, | |
"throw": {"after": true}, | |
"case": {"after": true}, | |
"return": {"after": true}, | |
"finally": {"after": true}, | |
"do": {"after": true} | |
} | |
}], | |
"no-console": "off", | |
"valid-jsdoc": "error" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
/* | |
MIT License http://www.opensource.org/licenses/mit-license.php | |
Author Tobias Koppers @sokra | |
*/ | |
const createInnerCallback = require("./createInnerCallback"); | |
const DescriptionFileUtils = require("./DescriptionFileUtils"); | |
class DescriptionFilePlugin { | |
constructor(source, filenames, target) { | |
this.source = source; | |
this.filenames = [].concat(filenames); | |
this.target = target; | |
} | |
apply(resolver) { | |
const filenames = this.filenames; | |
const target = this.target; | |
resolver.plugin(this.source, (request, callback) => { | |
const directory = request.path; | |
DescriptionFileUtils.loadDescriptionFile(resolver, directory, filenames, ((err, result) => { | |
if(err) return callback(err); | |
if(!result) { | |
if(callback.missing) { | |
filenames.forEach((filename) => { | |
callback.missing.push(resolver.join(directory, filename)); | |
}); | |
} | |
if(callback.log) callback.log("No description file found"); | |
return callback(); | |
} | |
const relativePath = "." + request.path.substr(result.directory.length).replace(/\\/g, "/"); | |
const obj = Object.assign({}, request, { | |
descriptionFilePath: result.path, | |
descriptionFileData: result.content, | |
descriptionFileRoot: result.directory, | |
relativePath: relativePath | |
}); | |
resolver.doResolve(target, obj, "using description file: " + result.path + " (relative path: " + relativePath + ")", createInnerCallback((err, result) => { | |
if(err) return callback(err); | |
if(result) return callback(null, result); | |
// Don't allow other description files or none at all | |
callback(null, null); | |
}, callback)); | |
})); | |
}); | |
} | |
} | |
module.exports = DescriptionFilePlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
/* | |
MIT License http://www.opensource.org/licenses/mit-license.php | |
Author Tobias Koppers @sokra | |
*/ | |
const assign = require("object-assign"); //eslint-disable-line | |
const forEachBail = require("./forEachBail"); | |
const loadDescriptionFile = (resolver, directory, filenames, callback) => { | |
(function findDescriptionFile() { | |
forEachBail(filenames, function(filename, callback) { | |
var descriptionFilePath = resolver.join(directory, filename); | |
if(resolver.fileSystem.readJson) { | |
resolver.fileSystem.readJson(descriptionFilePath, ((err, content) => { | |
if(err) { | |
if(typeof err.code !== "undefined") return callback(); | |
return onJson(err); | |
} | |
onJson(null, content); | |
})); | |
} else { | |
resolver.fileSystem.readFile(descriptionFilePath, ((err, content) => { | |
if(err) return callback(); | |
try { | |
var json = JSON.parse(content); | |
} catch(e) { | |
onJson(e); | |
} | |
onJson(null, json); | |
})); | |
} | |
function onJson(err, content) { | |
if(err) { | |
if(callback.log) | |
callback.log(descriptionFilePath + " (directory description file): " + err); | |
else | |
err.message = descriptionFilePath + " (directory description file): " + err; | |
return callback(err); | |
} | |
callback(null, { | |
content: content, | |
directory: directory, | |
path: descriptionFilePath | |
}); | |
} | |
}, ((err, result) => { | |
if(err) return callback(err); | |
if(result) { | |
return callback(null, result); | |
} else { | |
directory = cdUp(directory); | |
if(!directory) { | |
return callback(); | |
} else { | |
return findDescriptionFile(); | |
} | |
} | |
})); | |
}()); | |
}; | |
const getField = (content, field) => { | |
if(!content) return undefined; | |
if(Array.isArray(field)) { | |
var current = content; | |
for(var j = 0; j < field.length; j++) { | |
if(current === null || typeof current !== "object") { | |
current = null; | |
break; | |
} | |
current = current[field[j]]; | |
} | |
if(typeof current === "object") { | |
return current; | |
} | |
} else { | |
if(typeof content[field] === "object") { | |
return content[field]; | |
} | |
} | |
}; | |
const cdUp = (directory) => { | |
if(directory === "/") return null; | |
var i = directory.lastIndexOf("/"), | |
j = directory.lastIndexOf("\\"); | |
var p = i < 0 ? j : j < 0 ? i : i < j ? j : i; | |
if(p < 0) return null; | |
return directory.substr(0, p || 1); | |
}; | |
exports.loadDescriptionFile = loadDescriptionFile; | |
exports.getField = getField; | |
exports.cdUp = cdUp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
MIT License http://www.opensource.org/licenses/mit-license.php | |
Author Tobias Koppers @sokra | |
*/ | |
const assign = require("object-assign") | |
class FileKindPlugin { | |
constructor(source, target) { | |
this.source = source | |
this.target = target | |
} | |
apply(resolver) { | |
const target = this.target | |
resolver.plugin((this.source, (request, callback) => { | |
if(request.directory) return callback() | |
var obj = assign({}, request) | |
delete obj.directory | |
resolver.doResolve(target, obj, null, callback) | |
})) | |
} | |
} | |
module.exports = FileKindPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "enhanced-resolve", | |
"version": "3.0.3", | |
"author": "Tobias Koppers @sokra", | |
"description": "Offers a async require.resolve function. It's highly configurable.", | |
"files": [ | |
"lib" | |
], | |
"dependencies": { | |
"graceful-fs": "^4.1.2", | |
"memory-fs": "^0.4.0", | |
"object-assign": "^4.0.1", | |
"tapable": "^0.2.5" | |
}, | |
"licenses": [ | |
{ | |
"type": "MIT", | |
"url": "http://www.opensource.org/licenses/mit-license.php" | |
} | |
], | |
"devDependencies": { | |
"beautify-lint": "^1.0.3", | |
"codecov.io": "^0.1.6", | |
"coveralls": "^2.11.6", | |
"eslint": "^3.14.1", | |
"eslint-plugin-node": "^3.0.5", | |
"eslint-plugin-nodeca": "^1.0.3", | |
"istanbul": "^0.4.1", | |
"js-beautify": "^1.5.10", | |
"mocha": "^2.3.4", | |
"should": "^8.0.2" | |
}, | |
"engines": { | |
"node": ">=4.3.0 <5.0.0 || >=5.10" | |
}, | |
"main": "lib/node.js", | |
"homepage": "http://github.com/webpack/enhanced-resolve", | |
"scripts": { | |
"beautify-lint": "beautify-lint lib/**.js test/*.js", | |
"beautify": "beautify-rewrite lib/**.js test/*.js", | |
"lint": "eslint lib", | |
"pretest": "npm run lint && npm run beautify-lint", | |
"test": "mocha --full-trace --check-leaks", | |
"precover": "npm run lint && npm run beautify-lint", | |
"cover": "istanbul cover node_modules/mocha/bin/_mocha", | |
"travis": "npm run cover -- --report lcovonly" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git://github.com/webpack/enhanced-resolve.git" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment