Installing dependencies.

This commit is contained in:
2025-11-11 06:53:11 -05:00
parent 2c36c04da6
commit 0d2fea3c88
14371 changed files with 2770923 additions and 25 deletions
+41
View File
@@ -0,0 +1,41 @@
declare const importFrom: {
/**
Import a module like with [`require()`](https://nodejs.org/api/modules.html#modules_require_id) but from a given path.
@param fromDirectory - Directory to import from.
@param moduleId - What you would use in `require()`.
@throws Like `require()`, throws when the module can't be found.
@example
```
import importFrom = require('import-from');
try {
const bar = importFrom('foo', './bar');
// Do something with `bar`
} catch (error) {
// `error` is thrown when `./bar` can't be found
}
```
*/
(fromDirectory: string, moduleId: string): unknown;
/**
Import a module like with [`require()`](https://nodejs.org/api/modules.html#modules_require_id) but from a given path.
@param fromDirectory - Directory to import from.
@param moduleId - What you would use in `require()`.
@returns `undefined` instead of throwing when the module can't be found.
@example
```
import importFrom = require('import-from');
const bar = importFrom.silent('foo', './bar');
// Do something with `bar`, may be `undefined` when `./bar` can't be found
```
*/
silent(fromDirectory: string, moduleId: string): unknown;
};
export = importFrom;
+11
View File
@@ -0,0 +1,11 @@
'use strict';
const path = require('path');
const {createRequire} = require('module');
module.exports = (fromDirectory, moduleId) => createRequire(path.resolve(fromDirectory, 'noop.js'))(moduleId);
module.exports.silent = (fromDirectory, moduleId) => {
try {
return createRequire(path.resolve(fromDirectory, 'noop.js'))(moduleId);
} catch {}
};
+9
View File
@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
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.
+38
View File
@@ -0,0 +1,38 @@
{
"name": "import-from",
"version": "4.0.0",
"description": "Import a module like with `require()` but from a given path",
"license": "MIT",
"repository": "sindresorhus/import-from",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=12.2"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"require",
"resolve",
"path",
"module",
"from",
"like",
"import",
"path"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
+61
View File
@@ -0,0 +1,61 @@
# import-from
> Import a module like with [`require()`](https://nodejs.org/api/modules.html#modules_require_id) but from a given path
## Install
```
$ npm install import-from
```
## Usage
```js
const importFrom = require('import-from');
// There is a file at `./foo/bar.js`
importFrom('foo', './bar');
```
## API
### importFrom(fromDirectory, moduleId)
Like `require()`, throws when the module can't be found.
### importFrom.silent(fromDirectory, moduleId)
Returns `undefined` instead of throwing when the module can't be found.
#### fromDirectory
Type: `string`
Directory to import from.
#### moduleId
Type: `string`
What you would use in `require()`.
## Tip
Create a partial using a bound function if you want to import from the same `fromDir` multiple times:
```js
const importFromFoo = importFrom.bind(null, 'foo');
importFromFoo('./bar');
importFromFoo('./baz');
```
## Related
- [import-cwd](https://github.com/sindresorhus/import-cwd) - Import a module from the current working directory
- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path
- [resolve-cwd](https://github.com/sindresorhus/resolve-cwd) - Resolve the path of a module from the current working directory
- [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point
- [import-lazy](https://github.com/sindresorhus/import-lazy) - Import modules lazily
- [import-global](https://github.com/sindresorhus/import-global) - Import a globally installed module