add sidebar with logo

This commit is contained in:
2023-11-25 22:13:57 -05:00
parent 6ef22d88f9
commit 0190a553ba
30496 changed files with 579293 additions and 3701404 deletions
-31
View File
@@ -1,31 +0,0 @@
declare const resolveFrom: {
/**
Resolve the path of a module like [`require.resolve()`](https://nodejs.org/api/globals.html#globals_require_resolve) but from a given path.
@param fromDirectory - Directory to resolve from.
@param moduleId - What you would use in `require()`.
@returns Resolved module path. Throws when the module can't be found.
@example
```
import resolveFrom = require('resolve-from');
// There is a file at `./foo/bar.js`
resolveFrom('foo', './bar');
//=> '/Users/sindresorhus/dev/test/foo/bar.js'
```
*/
(fromDirectory: string, moduleId: string): string;
/**
Resolve the path of a module like [`require.resolve()`](https://nodejs.org/api/globals.html#globals_require_resolve) but from a given path.
@param fromDirectory - Directory to resolve from.
@param moduleId - What you would use in `require()`.
@returns Resolved module path or `undefined` when the module can't be found.
*/
silent(fromDirectory: string, moduleId: string): string | undefined;
};
export = resolveFrom;
+15 -15
View File
@@ -3,9 +3,9 @@ const path = require('path');
const Module = require('module');
const fs = require('fs');
const resolveFrom = (fromDirectory, moduleId, silent) => {
if (typeof fromDirectory !== 'string') {
throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDirectory}\``);
const resolveFrom = (fromDir, moduleId, silent) => {
if (typeof fromDir !== 'string') {
throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
}
if (typeof moduleId !== 'string') {
@@ -13,35 +13,35 @@ const resolveFrom = (fromDirectory, moduleId, silent) => {
}
try {
fromDirectory = fs.realpathSync(fromDirectory);
} catch (error) {
if (error.code === 'ENOENT') {
fromDirectory = path.resolve(fromDirectory);
fromDir = fs.realpathSync(fromDir);
} catch (err) {
if (err.code === 'ENOENT') {
fromDir = path.resolve(fromDir);
} else if (silent) {
return;
return null;
} else {
throw error;
throw err;
}
}
const fromFile = path.join(fromDirectory, 'noop.js');
const fromFile = path.join(fromDir, 'noop.js');
const resolveFileName = () => Module._resolveFilename(moduleId, {
id: fromFile,
filename: fromFile,
paths: Module._nodeModulePaths(fromDirectory)
paths: Module._nodeModulePaths(fromDir)
});
if (silent) {
try {
return resolveFileName();
} catch (error) {
return;
} catch (err) {
return null;
}
}
return resolveFileName();
};
module.exports = (fromDirectory, moduleId) => resolveFrom(fromDirectory, moduleId);
module.exports.silent = (fromDirectory, moduleId) => resolveFrom(fromDirectory, moduleId, true);
module.exports = (fromDir, moduleId) => resolveFrom(fromDir, moduleId);
module.exports.silent = (fromDir, moduleId) => resolveFrom(fromDir, moduleId, true);
+6 -8
View File
@@ -1,6 +1,6 @@
{
"name": "resolve-from",
"version": "5.0.0",
"version": "4.0.0",
"description": "Resolve the path of a module like `require.resolve()` but from a given path",
"license": "MIT",
"repository": "sindresorhus/resolve-from",
@@ -10,14 +10,13 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=4"
},
"scripts": {
"test": "xo && ava && tsd"
"test": "xo && ava"
},
"files": [
"index.js",
"index.d.ts"
"index.js"
],
"keywords": [
"require",
@@ -29,8 +28,7 @@
"import"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "*",
"xo": "*"
}
}
+5 -5
View File
@@ -24,15 +24,15 @@ resolveFrom('foo', './bar');
## API
### resolveFrom(fromDirectory, moduleId)
### resolveFrom(fromDir, moduleId)
Like `require()`, throws when the module can't be found.
### resolveFrom.silent(fromDirectory, moduleId)
### resolveFrom.silent(fromDir, moduleId)
Returns `undefined` instead of throwing when the module can't be found.
Returns `null` instead of throwing when the module can't be found.
#### fromDirectory
#### fromDir
Type: `string`
@@ -47,7 +47,7 @@ What you would use in `require()`.
## Tip
Create a partial using a bound function if you want to resolve from the same `fromDirectory` multiple times:
Create a partial using a bound function if you want to resolve from the same `fromDir` multiple times:
```js
const resolveFromFoo = resolveFrom.bind(null, 'foo');