pax_global_header00006660000000000000000000000064134610743250014517gustar00rootroot0000000000000052 comment=5b732738ffe1220fe93748726c98d41a76a6caa3 import-cwd-3.0.0/000077500000000000000000000000001346107432500136045ustar00rootroot00000000000000import-cwd-3.0.0/.editorconfig000066400000000000000000000002571346107432500162650ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 import-cwd-3.0.0/.gitattributes000066400000000000000000000000231346107432500164720ustar00rootroot00000000000000* text=auto eol=lf import-cwd-3.0.0/.gitignore000066400000000000000000000000271346107432500155730ustar00rootroot00000000000000node_modules yarn.lock import-cwd-3.0.0/.npmrc000066400000000000000000000000231346107432500147170ustar00rootroot00000000000000package-lock=false import-cwd-3.0.0/.travis.yml000066400000000000000000000000651346107432500157160ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' import-cwd-3.0.0/fixture/000077500000000000000000000000001346107432500152725ustar00rootroot00000000000000import-cwd-3.0.0/fixture/fixture.js000066400000000000000000000000521346107432500173130ustar00rootroot00000000000000'use strict'; module.exports = 'unicorn'; import-cwd-3.0.0/index.d.ts000066400000000000000000000023311346107432500155040ustar00rootroot00000000000000declare const importCwd: { /** Import a module like with [`require()`](https://nodejs.org/api/globals.html#globals_require) but from the current working directory. @param moduleId - What you would use in `require()`. @throws Like `require()`, throws when the module can't be found. @example ``` import importCwd = require('import-cwd'); // Target module is at '/Users/sindresorhus/unicorn/foo.js' console.log(__dirname); //=> '/Users/sindresorhus/rainbow' console.log(process.cwd()); //=> '/Users/sindresorhus/unicorn' const foo = importCwd('./foo'); ``` */ (moduleId: string): unknown; /** Import a module like with [`require()`](https://nodejs.org/api/globals.html#globals_require) but from the current working directory. @param moduleId - What you would use in `require()`. @returns `undefined` instead of throwing when the module can't be found. @example ``` import importCwd = require('import-cwd'); // '/Users/sindresorhus/empty/' is empty console.log(__dirname); //=> '/Users/sindresorhus/rainbow' console.log(process.cwd()); //=> '/Users/sindresorhus/empty' const foo = importCwd.silent('./nonexistent'); //=> undefined ``` */ silent(moduleId: string): unknown; }; export = importCwd; import-cwd-3.0.0/index.js000066400000000000000000000003141346107432500152470ustar00rootroot00000000000000'use strict'; const importFrom = require('import-from'); module.exports = moduleId => importFrom(process.cwd(), moduleId); module.exports.silent = moduleId => importFrom.silent(process.cwd(), moduleId); import-cwd-3.0.0/index.test-d.ts000066400000000000000000000001211346107432500164540ustar00rootroot00000000000000import importCwd = require('.'); importCwd('./foo'); importCwd.silent('./foo'); import-cwd-3.0.0/license000066400000000000000000000021251346107432500151510ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (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. import-cwd-3.0.0/package.json000066400000000000000000000013161346107432500160730ustar00rootroot00000000000000{ "name": "import-cwd", "version": "3.0.0", "description": "Import a module like with `require()` but from the current working directory", "license": "MIT", "repository": "sindresorhus/import-cwd", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "require", "resolve", "path", "module", "from", "like", "cwd", "current", "working", "directory", "import" ], "dependencies": { "import-from": "^3.0.0" }, "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.2", "xo": "^0.24.0" } } import-cwd-3.0.0/readme.md000066400000000000000000000031021346107432500153570ustar00rootroot00000000000000# import-cwd [![Build Status](https://travis-ci.org/sindresorhus/import-cwd.svg?branch=master)](https://travis-ci.org/sindresorhus/import-cwd) > Import a module like with [`require()`](https://nodejs.org/api/globals.html#globals_require) but from the current working directory ## Install ``` $ npm install import-cwd ``` ## Usage ```js const importCwd = require('import-cwd'); // Target module is at '/Users/sindresorhus/unicorn/foo.js' console.log(__dirname); //=> '/Users/sindresorhus/rainbow' console.log(process.cwd()); //=> '/Users/sindresorhus/unicorn' const foo = importCwd('./foo'); ``` ## API ### importCwd(moduleId) Like `require()`, throws when the module can't be found. ### importCwd.silent(moduleId) Returns `undefined` instead of throwing when the module can't be found. #### moduleId Type: `string` What you would use in `require()`. ## Related - [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path - [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 ## License MIT © [Sindre Sorhus](https://sindresorhus.com) import-cwd-3.0.0/test.js000066400000000000000000000005321346107432500151210ustar00rootroot00000000000000import test from 'ava'; import importCwd from '.'; process.chdir('fixture'); test('importCwd()', t => { t.is(importCwd('./fixture'), 'unicorn'); t.throws(() => { importCwd('./nonexistent'); }); }); test('importCwd.silent()', t => { t.is(importCwd.silent('./fixture'), 'unicorn'); t.is(importCwd.silent('./nonexistent'), undefined); });