This commit is contained in:
tatianamac
2019-11-26 14:50:43 -08:00
parent 8a55660ed0
commit 6d5445ecc5
13894 changed files with 2233957 additions and 0 deletions

42
node_modules/module-lookup-amd/Readme.md generated vendored Normal file
View File

@ -0,0 +1,42 @@
### module-lookup-amd [![npm](http://img.shields.io/npm/v/module-lookup-amd.svg)](https://npmjs.org/package/module-lookup-amd) [![npm](http://img.shields.io/npm/dm/module-lookup-amd.svg)](https://npmjs.org/package/module-lookup-amd)
> Resolve AMD dependency paths to an absolute path on the filesystem
This module takes in a partial and *synchronously* gives back its absolute path on the filesystem.
I built this for [Dependents'](https://sublime.wbond.net/packages/Dependents) [jump to dependency](https://github.com/mrjoelkemp/Dependents#jump-to-a-dependency) feature that lets you click on a module name
and open the relevant file.
`npm install module-lookup-amd`
### Usage
```js
var lookup = require('module-lookup-amd');
var realPath = lookup({
partial: 'someModule',
filename: 'file/containing/partial',
directory: 'path/to/all/js/files', // optional
config: 'path/to/my/requirejs/config', // optional
fileSystem: {} // optional
});
```
* `partial`: the dependency that you want to lookup
* `filename`: the path of the file that contains the dependency (i.e., parent module)
* `directory`: Used to resolve files if you're not using a requirejs config
* `config`: the path to your RequireJS configuration file
* As an optimization, you can provide a pre-parsed config object (the contents of the RequireJS config in object form)
as `config`. You are then required to provide a `directory` argument which is assumed to be the location where your config would have been.
* `fileSystem`: An alternative `fs` implementation to use for filesystem interactions. Defaults to node's `fs` implementation if not supplied.
### Shell usage
*Assumes a global `-g` installation*
`lookup-amd -c path/to/my/config.js -f path/to/file/containing/dependency -d path/containing/all/files my/dependency/name`
### License
MIT

25
node_modules/module-lookup-amd/bin/cli.js generated vendored Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env node
'use strict';
const lookup = require('../');
const program = require('commander');
program
.version(require('../package.json').version)
.usage('[options] <path>')
.option('-c, --config <path>', 'location of a RequireJS config file for AMD')
.option('-f, --filename <path>', 'file containing the dependency')
.option('-d, --directory <path>', 'directory containing all files')
.parse(process.argv);
const config = program.config;
const filename = program.filename;
const partial = program.args[0];
console.log(lookup({
config: config,
filename: filename,
partial: partial
}));

159
node_modules/module-lookup-amd/index.js generated vendored Normal file
View File

@ -0,0 +1,159 @@
'use strict';
const {ConfigFile} = require('requirejs-config-file');
const fs = require('fs');
const path = require('path');
const debug = require('debug')('lookup');
const find = require('find');
const fileExists = require('file-exists-dazinatorfork');
const requirejs = require('requirejs');
/**
* Determines the real path of a potentially aliased dependency path
* via the paths section of a require config
*
* @param {Object} options - Pass a loaded config object if you'd like to avoid rereading the config
* @param {String} options.partial - The dependency name
* @param {String} options.filename - The file containing the dependency
* @param {String} [options.directory] - The directory to use for resolving absolute paths (when no config is used)
* @param {String|Object} [options.config] - Pass a loaded config object if you'd like to avoid rereading the config
* @param {String|Object} [options.configPath] - The location of the config file used to create the preparsed config object
* @param {Object} [options.fileSystem] An alternative filesystem / fs implementation to use for locating files.
*
* @return {String}
*/
module.exports = function(options) {
var configPath = options.configPath;
var config = options.config || {};
var depPath = options.partial;
var filename = options.filename;
var fileSystem = options.fileSystem || fs;
debug('config: ', config);
debug('partial: ', depPath);
debug('filename: ', filename);
if (typeof config === 'string') {
configPath = path.dirname(config);
config = module.exports._readConfig(config, fileSystem);
debug('converting given config file ' + configPath + ' to an object:\n', config);
}
if (configPath && !fileSystem.statSync(configPath).isDirectory()) {
configPath = path.dirname(configPath);
}
debug('configPath: ', configPath);
if (!config.baseUrl) {
config.baseUrl = './';
debug('set baseUrl to ' + config.baseUrl);
}
let resolutionDirectory;
if (configPath) {
resolutionDirectory = configPath;
debug('module resolution directory (based on configPath): ' + resolutionDirectory);
} else if (options.directory && depPath[0] !== '.') {
resolutionDirectory = options.directory;
debug('module resolution directory (based on directory): ' + resolutionDirectory);
} else {
resolutionDirectory = path.dirname(options.filename);
debug('module resolution directory (based on filename): ' + resolutionDirectory);
}
if (config.baseUrl[0] === '/') {
debug('baseUrl with a leading slash detected');
resolutionDirectory = resolutionDirectory.replace(config.baseUrl, '');
debug('new resolution directory: ' + resolutionDirectory);
}
requirejs.config(config);
depPath = stripLoader(depPath);
let normalizedModuleId = requirejs.toUrl(depPath);
debug('requirejs normalized module id: ' + normalizedModuleId);
if (normalizedModuleId.includes('...')) {
debug('detected a nested subdirectory resolution that needs to be expanded');
normalizedModuleId = normalizedModuleId.replace('.../', '../../');
debug('expanded module id: ' + normalizedModuleId);
}
const resolved = path.join(resolutionDirectory, normalizedModuleId);
debug('resolved url: ' + resolved);
// No need to search for a file that already has an extension
// Need to guard against jquery.min being treated as a real file
if (path.extname(resolved) && fileExists.sync(resolved, {fileSystem: fileSystem})) {
debug(resolved + ' already has an extension and is a real file');
return resolved;
}
const foundFile = findFileLike(fileSystem, normalizedModuleId, resolved) || '';
if (foundFile) {
debug('found file like ' + resolved + ': ' + foundFile);
} else {
debug('could not find any file like ' + resolved);
}
return foundFile;
};
function findFileLike(fileSystem, partial, resolved) {
const fileDir = path.dirname(resolved);
const pattern = escapeRegExp(resolved + '.');
debug('looking for file like ' + pattern);
debug('within ' + fileDir);
try {
const results = find.use({fs: fileSystem})
.fileSync(new RegExp(pattern), fileDir);
debug('found the following matches: ', results.join('\n'));
// Not great if there are multiple matches, but the pattern should be
// specific enough to prevent multiple results
return results[0];
} catch (e) {
debug('error when looking for a match: ' + e.message);
return '';
}
}
function stripLoader(partial) {
const exclamationLocation = partial.indexOf('!');
if (exclamationLocation !== -1) {
debug('stripping off the plugin loader from ' + partial);
partial = partial.slice(exclamationLocation + 1);
debug('partial is now ' + partial);
}
return partial;
}
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}
/**
* Exposed for testing
*
* @private
* @param {String} configPath
* @param {Object} fileSystem api to use.
* @return {Object}
*/
module.exports._readConfig = function(configPath, fileSystem) {
return new ConfigFile(configPath, fileSystem).read();
};

77
node_modules/module-lookup-amd/package.json generated vendored Normal file
View File

@ -0,0 +1,77 @@
{
"_args": [
[
"module-lookup-amd@6.2.0",
"/Users/tatiana/selfdefined"
]
],
"_from": "module-lookup-amd@6.2.0",
"_id": "module-lookup-amd@6.2.0",
"_inBundle": false,
"_integrity": "sha512-uxHCj5Pw9psZiC1znjU2qPsubt6haCSsN9m7xmIdoTciEgfxUkE1vhtDvjHPuOXEZrVJhjKgkmkP+w73rRuelQ==",
"_location": "/module-lookup-amd",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "module-lookup-amd@6.2.0",
"name": "module-lookup-amd",
"escapedName": "module-lookup-amd",
"rawSpec": "6.2.0",
"saveSpec": null,
"fetchSpec": "6.2.0"
},
"_requiredBy": [
"/filing-cabinet"
],
"_resolved": "https://registry.npmjs.org/module-lookup-amd/-/module-lookup-amd-6.2.0.tgz",
"_spec": "6.2.0",
"_where": "/Users/tatiana/selfdefined",
"author": {
"name": "Joel Kemp",
"email": "joel@mrjoelkemp.com"
},
"bin": {
"lookup-amd": "bin/cli.js"
},
"bugs": {
"url": "https://github.com/mrjoelkemp/node-module-lookup-amd/issues"
},
"dependencies": {
"commander": "^2.8.1",
"debug": "^4.1.0",
"file-exists-dazinatorfork": "^1.0.2",
"find": "^0.3.0",
"requirejs": "^2.3.5",
"requirejs-config-file": "^3.1.1"
},
"description": "Resolve aliased dependency paths using a RequireJS config",
"devDependencies": {
"jscs": "~2.11.0",
"jscs-preset-mrjoelkemp": "~1.0.0",
"mocha": "^5.2.0",
"rewire": "^4.0.1",
"sinon": "^7.2.0"
},
"engines": {
"node": ">=6.0.0"
},
"homepage": "https://github.com/mrjoelkemp/node-module-lookup-amd",
"keywords": [
"amd",
"module",
"lookup",
"alias"
],
"license": "MIT",
"main": "index.js",
"name": "module-lookup-amd",
"repository": {
"type": "git",
"url": "git+https://github.com/mrjoelkemp/node-module-lookup-amd.git"
},
"scripts": {
"test": "jscs index.js test bin && mocha test/test.js"
},
"version": "6.2.0"
}