mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-10 21:01:41 +00:00
update
This commit is contained in:
77
node_modules/precinct/Readme.md
generated
vendored
Normal file
77
node_modules/precinct/Readme.md
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
### Precinct [](https://npmjs.org/package/precinct) [](https://npmjs.org/package/precinct)
|
||||
|
||||
> Unleash the detectives
|
||||
|
||||
`npm install --save precinct`
|
||||
|
||||
Uses the appropriate detective to find the dependencies of a file or its AST.
|
||||
|
||||
Supports:
|
||||
|
||||
* JavaScript modules: AMD, CommonJS, and ES6.
|
||||
* Typescript
|
||||
* CSS Preprocessors: Sass, Stylus, and Less
|
||||
* CSS (PostCSS)
|
||||
|
||||
### Usage
|
||||
|
||||
```js
|
||||
var precinct = require('precinct');
|
||||
|
||||
var content = fs.readFileSync('myFile.js', 'utf8');
|
||||
|
||||
// Pass in a file's content or an AST
|
||||
var deps = precinct(content);
|
||||
```
|
||||
|
||||
You may pass options (to individual detectives) based on the module type via an optional second object argument `detective(content, options), for example:
|
||||
|
||||
Example call: `precinct(content, { amd: { skipLazyLoaded: true } });`
|
||||
|
||||
- The supported module type prefixes are `amd`, `commonjs`, `es6`, `sass`, `stylus`, `less`
|
||||
|
||||
Current options:
|
||||
|
||||
* `amd.skipLazyLoaded`: tells the AMD detective to omit lazy-loaded dependencies (i.e., inner requires).
|
||||
* `es6.mixedImports`: allows for all dependencies to be fetched from a file that contains both CJS and ES6 imports.
|
||||
- Note: This will work for any file format that contains an es6 import.
|
||||
* `css.url`: tells the CSS detective to include `url()` references to images, fonts, etc.
|
||||
|
||||
|
||||
Finding non-JavaScript (ex: Sass and Stylus) dependencies:
|
||||
|
||||
```js
|
||||
var content = fs.readFileSync('styles.scss', 'utf8');
|
||||
|
||||
var deps = precinct(content, { type: 'sass' });
|
||||
var deps2 = precinct(content, { type: 'stylus' });
|
||||
```
|
||||
|
||||
Or, if you just want to pass in a filepath and get the dependencies:
|
||||
|
||||
```js
|
||||
var paperwork = require('precinct').paperwork;
|
||||
|
||||
var deps = paperwork('myFile.js');
|
||||
var deps2 = paperwork('styles.scss');
|
||||
```
|
||||
|
||||
###### `precinct.paperwork(filename, options)`
|
||||
|
||||
Supported options:
|
||||
|
||||
* `includeCore`: (default: true) set to `false` to exclude core Node dependencies from the list of dependencies.
|
||||
* `fileSystem`: (default: undefined) set to an alternative `fs` implementation that will be used to read the file path.
|
||||
* You may also pass detective-specific configuration like you would to `precinct(content, options)`.
|
||||
|
||||
#### CLI
|
||||
|
||||
*Assumes a global install of `npm install -g precinct`*
|
||||
|
||||
`precinct [options] path/to/file`
|
||||
|
||||
* Run `precinct --help` to see options
|
||||
|
||||
### License
|
||||
|
||||
MIT
|
30
node_modules/precinct/bin/cli.js
generated
vendored
Executable file
30
node_modules/precinct/bin/cli.js
generated
vendored
Executable file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
var precinct = require('../');
|
||||
var program = require('commander');
|
||||
var fs = require('fs');
|
||||
|
||||
program
|
||||
.version(require('../package.json').version)
|
||||
.usage('[options] <filename>')
|
||||
.option('--es6-mixedImports')
|
||||
.option('-t, --type <type>', 'The type of content being passed in. Useful if you want to use a non-js detective')
|
||||
.parse(process.argv);
|
||||
|
||||
var content = fs.readFileSync(program.args[0], 'utf8');
|
||||
|
||||
var options = {
|
||||
es6: {}
|
||||
};
|
||||
|
||||
if (program['es6MixedImports']) {
|
||||
options.es6.mixedImports = true;
|
||||
}
|
||||
|
||||
if (program.type) {
|
||||
options.type = program.type;
|
||||
}
|
||||
|
||||
console.log(precinct(content, options));
|
184
node_modules/precinct/index.js
generated
vendored
Normal file
184
node_modules/precinct/index.js
generated
vendored
Normal file
@ -0,0 +1,184 @@
|
||||
var getModuleType = require('module-definition');
|
||||
var debug = require('debug')('precinct');
|
||||
var Walker = require('node-source-walk');
|
||||
|
||||
var detectiveCjs = require('detective-cjs');
|
||||
var detectiveAmd = require('detective-amd');
|
||||
var detectiveEs6 = require('detective-es6');
|
||||
var detectiveLess = require('detective-less');
|
||||
var detectivePostcss = require('detective-postcss');
|
||||
var detectiveSass = require('detective-sass');
|
||||
var detectiveScss = require('detective-scss');
|
||||
var detectiveStylus = require('detective-stylus');
|
||||
var detectiveTypeScript = require('detective-typescript');
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var natives = process.binding('natives');
|
||||
|
||||
/**
|
||||
* Finds the list of dependencies for the given file
|
||||
*
|
||||
* @param {String|Object} content - File's content or AST
|
||||
* @param {Object} [options]
|
||||
* @param {String} [options.type] - The type of content being passed in. Useful if you want to use a non-js detective
|
||||
* @return {String[]}
|
||||
*/
|
||||
function precinct(content, options) {
|
||||
options = options || {};
|
||||
var dependencies = [];
|
||||
var ast;
|
||||
var type = options.type;
|
||||
|
||||
// Legacy form backCompat where type was the second parameter
|
||||
if (typeof options === 'string') {
|
||||
type = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
debug('options given: ', options);
|
||||
|
||||
// We assume we're dealing with a JS file
|
||||
if (!type && typeof content !== 'object') {
|
||||
debug('we assume this is JS');
|
||||
var walker = new Walker();
|
||||
|
||||
try {
|
||||
// Parse once and distribute the AST to all detectives
|
||||
ast = walker.parse(content);
|
||||
debug('parsed the file content into an ast');
|
||||
precinct.ast = ast;
|
||||
} catch (e) {
|
||||
// In case a previous call had it populated
|
||||
precinct.ast = null;
|
||||
debug('could not parse content: %s', e.message);
|
||||
return dependencies;
|
||||
}
|
||||
// SASS files shouldn't be parsed by Acorn
|
||||
} else {
|
||||
ast = content;
|
||||
|
||||
if (typeof content === 'object') {
|
||||
precinct.ast = content;
|
||||
}
|
||||
}
|
||||
|
||||
type = type || getModuleType.fromSource(ast);
|
||||
debug('module type: ', type);
|
||||
|
||||
var theDetective;
|
||||
var mixedMode = options.es6 && options.es6.mixedImports;
|
||||
|
||||
switch (type) {
|
||||
case 'commonjs':
|
||||
theDetective = mixedMode ? detectiveEs6Cjs : detectiveCjs;
|
||||
break;
|
||||
case 'css':
|
||||
theDetective = detectivePostcss;
|
||||
break;
|
||||
case 'amd':
|
||||
theDetective = detectiveAmd;
|
||||
break;
|
||||
case 'es6':
|
||||
theDetective = mixedMode ? detectiveEs6Cjs : detectiveEs6;
|
||||
break;
|
||||
case 'sass':
|
||||
theDetective = detectiveSass;
|
||||
break;
|
||||
case 'less':
|
||||
theDetective = detectiveLess;
|
||||
break;
|
||||
case 'scss':
|
||||
theDetective = detectiveScss;
|
||||
break;
|
||||
case 'stylus':
|
||||
theDetective = detectiveStylus;
|
||||
break;
|
||||
case 'ts':
|
||||
theDetective = detectiveTypeScript;
|
||||
break;
|
||||
case 'tsx':
|
||||
theDetective = detectiveTypeScript.tsx;
|
||||
break;
|
||||
}
|
||||
|
||||
if (theDetective) {
|
||||
dependencies = theDetective(ast, options[type]);
|
||||
} else {
|
||||
debug('no detective found for: ' + type);
|
||||
}
|
||||
|
||||
// For non-JS files that we don't parse
|
||||
if (theDetective && theDetective.ast) {
|
||||
precinct.ast = theDetective.ast;
|
||||
}
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
function detectiveEs6Cjs(ast, detectiveOptions) {
|
||||
return detectiveEs6(ast, detectiveOptions).concat(detectiveCjs(ast, detectiveOptions));
|
||||
}
|
||||
|
||||
function assign(o1, o2) {
|
||||
for (var key in o2) {
|
||||
if (o2.hasOwnProperty(key)) {
|
||||
o1[key] = o2[key];
|
||||
}
|
||||
}
|
||||
|
||||
return o1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the dependencies for the given file path
|
||||
*
|
||||
* @param {String} filename
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.includeCore=true] - Whether or not to include core modules in the dependency list
|
||||
* @param {Object} [options.fileSystem=undefined] - An alternative fs implementation to use for reading the file path.
|
||||
* @return {String[]}
|
||||
*/
|
||||
precinct.paperwork = function(filename, options) {
|
||||
options = assign({
|
||||
includeCore: true
|
||||
}, options || {});
|
||||
|
||||
// Note: released with options.fs but intended options.fileSystem for consistency in the community
|
||||
// TODO: Remove options.fs in the next major version update
|
||||
var fileSystem = options.fileSystem || options.fs || fs;
|
||||
var content = fileSystem.readFileSync(filename, 'utf8');
|
||||
var ext = path.extname(filename);
|
||||
var type;
|
||||
|
||||
if (ext === '.styl') {
|
||||
debug('paperwork: converting .styl into the stylus type');
|
||||
type = 'stylus';
|
||||
}
|
||||
// We need to sniff the JS module to find its type, not by extension
|
||||
// Other possible types pass through normally
|
||||
else if (ext !== '.js' && ext !== '.jsx') {
|
||||
debug('paperwork: stripping the dot from the extension to serve as the type');
|
||||
type = ext.replace('.', '');
|
||||
}
|
||||
|
||||
if (type) {
|
||||
debug('paperwork: setting the module type');
|
||||
options.type = type;
|
||||
}
|
||||
|
||||
debug('paperwork: invoking precinct');
|
||||
var deps = precinct(content, options);
|
||||
|
||||
if (!options.includeCore) {
|
||||
return deps.filter(function(d) {
|
||||
return !natives[d];
|
||||
});
|
||||
}
|
||||
|
||||
debug('paperwork: got these results\n', deps);
|
||||
return deps;
|
||||
};
|
||||
|
||||
module.exports = precinct;
|
88
node_modules/precinct/package.json
generated
vendored
Normal file
88
node_modules/precinct/package.json
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"precinct@6.1.2",
|
||||
"/Users/tatiana/selfdefined"
|
||||
]
|
||||
],
|
||||
"_from": "precinct@6.1.2",
|
||||
"_id": "precinct@6.1.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-Mk+oWvR7N2D2EY+5vKNnnXPGor1aU3ZbkcHp2ER68el5PL1nmZsvpq41s69emiNMSuL6TMoIeTabvwfe5w7vNg==",
|
||||
"_location": "/precinct",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "precinct@6.1.2",
|
||||
"name": "precinct",
|
||||
"escapedName": "precinct",
|
||||
"rawSpec": "6.1.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "6.1.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/dependency-tree"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/precinct/-/precinct-6.1.2.tgz",
|
||||
"_spec": "6.1.2",
|
||||
"_where": "/Users/tatiana/selfdefined",
|
||||
"author": {
|
||||
"name": "Joel Kemp",
|
||||
"email": "joel@mrjoelkemp.com"
|
||||
},
|
||||
"bin": {
|
||||
"precinct": "bin/cli.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mrjoelkemp/node-precinct/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": "^2.19.0",
|
||||
"debug": "^4.1.1",
|
||||
"detective-amd": "^3.0.0",
|
||||
"detective-cjs": "^3.1.1",
|
||||
"detective-es6": "^2.0.0",
|
||||
"detective-less": "^1.0.2",
|
||||
"detective-postcss": "^3.0.0",
|
||||
"detective-sass": "^3.0.0",
|
||||
"detective-scss": "^2.0.0",
|
||||
"detective-stylus": "^1.0.0",
|
||||
"detective-typescript": "^5.1.1",
|
||||
"module-definition": "^3.1.0",
|
||||
"node-source-walk": "^4.2.0"
|
||||
},
|
||||
"description": "Unleash the detectives",
|
||||
"devDependencies": {
|
||||
"jscs": "~3.0.7",
|
||||
"jscs-preset-mrjoelkemp": "~2.0.0",
|
||||
"mocha": "^5.2.0",
|
||||
"rewire": "^4.0.1",
|
||||
"sinon": "^6.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/mrjoelkemp/node-precinct",
|
||||
"keywords": [
|
||||
"modules",
|
||||
"amd",
|
||||
"commonjs",
|
||||
"es6",
|
||||
"sass",
|
||||
"less",
|
||||
"detective",
|
||||
"dependencies"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "precinct",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/mrjoelkemp/node-precinct.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jscs index.js test/index.js && mocha test/index.js"
|
||||
},
|
||||
"version": "6.1.2"
|
||||
}
|
Reference in New Issue
Block a user