pax_global_header 0000666 0000000 0000000 00000000064 14173543707 0014525 g ustar 00root root 0000000 0000000 52 comment=b45070ec1341223670e5ed1a106a8686664ea235
ncjsm-4.3.0/ 0000775 0000000 0000000 00000000000 14173543707 0012643 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/.editorconfig 0000664 0000000 0000000 00000000446 14173543707 0015324 0 ustar 00root root 0000000 0000000 # EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
trim_trailing_whitespace = true
[*.{md,yml}]
indent_size = 2
indent_style = space
trim_trailing_whitespace = false
ncjsm-4.3.0/.github/ 0000775 0000000 0000000 00000000000 14173543707 0014203 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/.github/FUNDING.yml 0000664 0000000 0000000 00000000020 14173543707 0016010 0 ustar 00root root 0000000 0000000 github: medikoo
ncjsm-4.3.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14173543707 0016240 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/.github/workflows/integrate.yml 0000664 0000000 0000000 00000013524 14173543707 0020752 0 ustar 00root root 0000000 0000000 # main only
name: Integrate
on:
push:
branches: [main]
env:
FORCE_COLOR: 1
jobs:
linuxNode16:
name: "[Linux] Node.js v16: Unit tests"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v16-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v16-${{ runner.os }}-${{ github.ref }}-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test
windowsNode16:
name: "[Windows] Node.js v16: Unit tests"
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v16-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v16-${{ runner.os }}-${{ github.ref }}-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test
linuxNode17:
name: "[Linux] Node.js 17: Unit tests on npm package"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v17-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v17-${{ runner.os }}-${{ github.ref }}-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 17.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Build local package
run: npm pack
- name: Unit tests on npm package
run: |
NAME=`cat package.json | grep '"name": "' | grep -oE ": .*" | grep -oE '[^: ",]+'`
VERSION=`cat package.json | grep '"version": "' | grep -oE ": .*" | grep -oE '[^: ",]+'`
tar zxf "${NAME}-${VERSION}.tgz"
cp -R test "package"
ln -s "$(pwd)"/node_modules "package/node_modules"
cd "package"
npm test
linuxNode14:
name: "[Linux] Node.js v14: Unit tests with coverage"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v14-${{ runner.os }}-${{ github.ref }}-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm run coverage
- name: Push coverage
run: npx codecov
linuxNode12:
name: "[Linux] Node.js v12: Unit tests"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v12-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v12-${{ runner.os }}-${{ github.ref }}-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test
tagIfNewVersion:
name: Tag if new version
runs-on: ubuntu-latest
needs: [linuxNode16, windowsNode16, linuxNode17, linuxNode14, linuxNode12]
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# Ensure to have complete history of commits pushed with given push operation
# It's loose and imperfect assumption that no more than 30 commits will be pushed at once
fetch-depth: 30
# Tag needs to be pushed with real user token, otherwise pushed tag won't trigger the actions workflow
# Hence we're passing 'serverless-ci' user authentication token
token: ${{ secrets.USER_GITHUB_TOKEN }}
- name: Tag if new version
if: github.event.before != '0000000000000000000000000000000000000000' # Skip on first commit
run: |
NEW_VERSION=`git diff -U0 ${{ github.event.before }} package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
if [ -n "$NEW_VERSION" ];
then
git tag v$NEW_VERSION
git push --tags
fi
ncjsm-4.3.0/.github/workflows/publish.yml 0000664 0000000 0000000 00000003327 14173543707 0020436 0 ustar 00root root 0000000 0000000 # Version tags only
name: Publish
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
env:
# It'll work with secrets.GITHUB_TOKEN (which is provided by GitHub unconditionally)
# Still then release author would be "github-actions"
GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v16-${{ runner.os }}-refs/heads/main-${{ hashFiles('package.json') }}
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 16.x
registry-url: https://registry.npmjs.org
- name: Publish new version
# Note: Setting NODE_AUTH_TOKEN as job|workspace wide env var won't work
# as it appears actions/setup-node sets own value
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish
# Normally we have a guarantee that deps are already there, still it may not be the case when:
# - `main` build for same commit failed (and we still pushed tag manually)
# - We've pushed tag manually before `master` build finalized
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Publish release notes
run: |
TEMP_ARRAY=($(echo $GITHUB_REF | tr "/" "\n"))
TAG=${TEMP_ARRAY[@]: -1}
npx github-release-from-cc-changelog $TAG
ncjsm-4.3.0/.github/workflows/validate.yml 0000664 0000000 0000000 00000012370 14173543707 0020557 0 ustar 00root root 0000000 0000000 # PR's only
name: Validate
on:
pull_request:
branches: [main]
env:
FORCE_COLOR: 1
jobs:
linuxNode16:
name: "[Linux] Node.js v16: Lint, Formatting, Unit tests"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v16-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: |
npm-v16-${{ runner.os }}-${{ github.ref }}-
npm-v16-${{ runner.os }}-refs/heads/main-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Validate Prettier formatting
run: npm run prettier-check:updated
- name: Validate ESLint rules
run: npm run lint:updated
- name: Unit tests
run: npm test
windowsNode16:
name: "[Windows] Node.js v16: Unit tests"
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v16-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: |
npm-v16-${{ runner.os }}-${{ github.ref }}-
npm-v16-${{ runner.os }}-refs/heads/main-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test
linuxNode17:
name: "[Linux] Node.js 17: Unit tests on npm package"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v17-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: |
npm-v17-${{ runner.os }}-${{ github.ref }}-
npm-v17-${{ runner.os }}-refs/heads/main-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 17.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Build local package
run: npm pack
- name: Unit tests on npm package
run: |
NAME=`cat package.json | grep '"name": "' | grep -oE ": .*" | grep -oE '[^: ",]+'`
VERSION=`cat package.json | grep '"version": "' | grep -oE ": .*" | grep -oE '[^: ",]+'`
tar zxf "${NAME}-${VERSION}.tgz"
cp -R test "package"
ln -s "$(pwd)"/node_modules "package/node_modules"
cd "package"
npm test
linuxNode14:
name: "[Linux] Node.js v14: Unit tests with coverage"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: |
npm-v14-${{ runner.os }}-${{ github.ref }}-
npm-v14-${{ runner.os }}-refs/heads/main-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 14.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm run coverage
- name: Push coverage
run: npx codecov
linuxNode12:
name: "[Linux] Node.js v12: Unit tests"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v12-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: |
npm-v12-${{ runner.os }}-${{ github.ref }}-
npm-v12-${{ runner.os }}-refs/heads/main-
- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test
ncjsm-4.3.0/.gitignore 0000664 0000000 0000000 00000000106 14173543707 0014630 0 ustar 00root root 0000000 0000000 /.nyc_output
/coverage
/node_modules
npm-debug.log
/package-lock.json
ncjsm-4.3.0/CHANGELOG.md 0000664 0000000 0000000 00000014754 14173543707 0014467 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [4.3.0](https://github.com/medikoo/ncjsm/compare/v4.2.0...v4.3.0) (2022-01-24)
### Features
- Support async callback in `requireUncached` ([91fdb82](https://github.com/medikoo/ncjsm/commit/91fdb82b171651ff5740a3d6e6a12f632415e0e9))
## [4.2.0](https://github.com/medikoo/ncjsm/compare/v4.1.0...v4.2.0) (2021-04-30)
### Features
- **Require Uncached:** Support clearing all require cache for callback ([75c2229](https://github.com/medikoo/ncjsm/commit/75c2229854885e257fdd061699600208d438b561))
## [4.1.0](https://github.com/medikoo/ncjsm/compare/v4.0.1...v4.1.0) (2020-07-22)
### Features
- `ignoreExternal` option for `getDependencies` ([158075b](https://github.com/medikoo/ncjsm/commit/158075bea3f66ac77bae5341fd474930172047a2))
### [4.0.1](https://github.com/medikoo/ncjsm/compare/v4.0.0...v4.0.1) (2019-10-25)
### Bug Fixes
- Fix main module resolution in case pkg.main leads to broken path ([331dd1c](https://github.com/medikoo/ncjsm/commit/331dd1c))
### Tests
- Add missing test ([2469fe9](https://github.com/medikoo/ncjsm/commit/2469fe9))
## [4.0.0](https://github.com/medikoo/ncjsm/compare/v3.0.0...v4.0.0) (2019-10-08)
### Bug Fixes
- Fix requireUncached moduleIds validation ([eb2e026](https://github.com/medikoo/ncjsm/commit/eb2e026))
### Features
- By default crash resolve with MODULE_NOT_FOUND if module not found ([0e446c4](https://github.com/medikoo/ncjsm/commit/0e446c4))
### BREAKING CHANGES
- `resolve` and `resolve/sync` now by default crash with MODULE_NOT_FOUND error, if module is not found. Old behavior was that `null` was returned.
To maintain old behavior { silent: true } option needs to be passed
## [3.0.0](https://github.com/medikoo/ncjsm/compare/v2.3.0...v3.0.0) (2019-09-02)
### Features
- Change resolve return value format ([747493e](https://github.com/medikoo/ncjsm/commit/747493e))
- Expose realPath on resolve return object ([5ad6b23](https://github.com/medikoo/ncjsm/commit/5ad6b23))
### Tests
- Configure directory links tests ([988c92a](https://github.com/medikoo/ncjsm/commit/988c92a))
- Cover symlink cases in resolve tests ([c97d4a0](https://github.com/medikoo/ncjsm/commit/c97d4a0))
- Fix symlink type ([a371ed0](https://github.com/medikoo/ncjsm/commit/a371ed0))
- Improve naming ([81785d6](https://github.com/medikoo/ncjsm/commit/81785d6))
- Improve var name ([523498a](https://github.com/medikoo/ncjsm/commit/523498a))
- Improve var naming ([e48b5f0](https://github.com/medikoo/ncjsm/commit/e48b5f0))
- Maintain support for Node.js v6 ([3341664](https://github.com/medikoo/ncjsm/commit/3341664))
- Make symlink tests portable to windows ([0b57b2a](https://github.com/medikoo/ncjsm/commit/0b57b2a))
- Refactor to async/await ([6f20188](https://github.com/medikoo/ncjsm/commit/6f20188))
- Rename util ([55a6d6f](https://github.com/medikoo/ncjsm/commit/55a6d6f))
- Skip symlink tests if not capable to create them ([53cc946](https://github.com/medikoo/ncjsm/commit/53cc946))
### BREAKING CHANGES
- 'resolve', and 'resolve/sync' utils now resolve with objects that
expose path on `targetPath` property
(so far path was returned directly)
# [2.3.0](https://github.com/medikoo/ncjsm/compare/v2.2.0...v2.3.0) (2019-04-30)
### Features
- improve validation in isModuleNotFoundError ([8b2e641](https://github.com/medikoo/ncjsm/commit/8b2e641))
# [2.2.0](https://github.com/medikoo/ncjsm/compare/v2.1.0...v2.2.0) (2019-04-30)
### Bug Fixes
- Fix isModuleNotFound crash in Node.js v12 ([c9b9cc8](https://github.com/medikoo/ncjsm/commit/c9b9cc8))
### Features
- Bring ES3 support to isModuleNotFoundError ([e6d0132](https://github.com/medikoo/ncjsm/commit/e6d0132))
# [2.1.0](https://github.com/medikoo/ncjsm/compare/v2.0.1...v2.1.0) (2019-04-18)
### Features
- support ignoreMissing option in getDependencies ([20baf14](https://github.com/medikoo/ncjsm/commit/20baf14))
## [2.0.1](https://github.com/medikoo/ncjsm/compare/v2.0.0...v2.0.1) (2019-03-18)
### Bug Fixes
- ensure ES5 support in requireUncached ([bab908d](https://github.com/medikoo/ncjsm/commit/bab908d))
# [2.0.0](https://github.com/medikoo/ncjsm/compare/v1.6.0...v2.0.0) (2019-03-12)
### Features
- improve resolution of dynamic requires ([fa1457b](https://github.com/medikoo/ncjsm/commit/fa1457b))
### reafactor
- convert to ES2015 ([ed2aa37](https://github.com/medikoo/ncjsm/commit/ed2aa37))
### BREAKING CHANGES
- Drop support for Node.js v4 and below
# [1.6.0](https://github.com/medikoo/ncjsm/compare/v1.5.0...v1.6.0) (2019-02-07)
### Features
- rename cjs-module to ncjsm ([743b95c](https://github.com/medikoo/ncjsm/commit/743b95c))
# [1.5.0](https://github.com/medikoo/cjs-module/compare/v1.4.1...v1.5.0) (2018-12-28)
### Features
- improve error messaging ([ca04d59](https://github.com/medikoo/cjs-module/commit/ca04d59))
## [1.4.1](https://github.com/medikoo/cjs-module/compare/v1.4.0...v1.4.1) (2018-12-28)
# [1.4.0](https://github.com/medikoo/cjs-module/compare/v1.3.1...v1.4.0) (2018-09-14)
### Features
- isModuleNotFoundError util ([130b066](https://github.com/medikoo/cjs-module/commit/130b066))
## [1.3.1](https://github.com/medikoo/cjs-module/compare/v1.3.0...v1.3.1) (2018-07-26)
### Bug Fixes
- ensure full isolation in require-uncached ([090eede](https://github.com/medikoo/cjs-module/commit/090eede))
# [1.3.0](https://github.com/medikoo/cjs-module/compare/v1.2.2...v1.3.0) (2018-05-14)
### Features
- requireUncached util ([1f79012](https://github.com/medikoo/cjs-module/commit/1f79012))
## [1.2.2](https://github.com/medikoo/cjs-module/compare/v1.2.1...v1.2.2) (2017-09-18)
### Bug Fixes
- resolution of dirs referenced in main of package.json ([455ce5a](https://github.com/medikoo/cjs-module/commit/455ce5a))
## [1.2.1](https://github.com/medikoo/cjs-module/compare/v1.2.0...v1.2.1) (2017-06-20)
### Bug Fixes
- ensure to not resolve builtin modules ([1107e40](https://github.com/medikoo/cjs-module/commit/1107e40))
# [1.2.0](https://github.com/medikoo/cjs-module/compare/v1.1.0...v1.2.0) (2017-06-16)
### Features
- getDependencies utility ([af1c3d0](https://github.com/medikoo/cjs-module/commit/af1c3d0))
### Bug Fixes
- ensure proper tests resolution on windows ([4e4960b](https://github.com/medikoo/cjs-module/commit/4e4960b))
## Old Changelog
See `CHANGES`
ncjsm-4.3.0/CHANGES 0000664 0000000 0000000 00000000313 14173543707 0013633 0 ustar 00root root 0000000 0000000 For new changelog see CHANGELOG.md
v1.1.0 -- 2015.09.10
* Added modules:
* isPackageRoot
* resolvePackageRoot
* resolveProjectRoot
* isPathExternal (in utils)
v1.0.0 -- 2015.06.29
* Initial
ncjsm-4.3.0/LICENSE 0000664 0000000 0000000 00000001405 14173543707 0013650 0 ustar 00root root 0000000 0000000 ISC License
Copyright (c) 2015-2022, Mariusz Nowak, @medikoo, medikoo.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
ncjsm-4.3.0/README.md 0000664 0000000 0000000 00000015673 14173543707 0014136 0 ustar 00root root 0000000 0000000 [![Build status][build-image]][build-url]
[![Tests coverage][cov-image]][cov-url]
[![npm version][npm-image]][npm-url]
# ncjsm
## (Node.js) CJS modules resolver
Environment agnostic (Node.js) CJS modules resolver.
It implements a _strict_ version of Node.js modules resolution logic, differences are as follows:
- [Loading from global folders](https://nodejs.org/api/all.html#all_loading_from_the_global_folders) is not supported
- Only Unix path separators (`/`) are supported in require's _path_ arguments (_Background: even though Node.js internally seems to follow Windows path separator in Windows environment, it won't work in \*nix environments, and even in Window env it's [not reliable](https://github.com/nodejs/node/issues/6049) so by all means should be avoided_)
- There's no awareness of node.js [core modules](https://nodejs.org/api/all.html#all_core_modules)
e.g. `resolve(dir, 'fs')` will naturally result with _null_
### Installation
$ npm install ncjsm
### API
#### getResolver(extensions, confirmFile, resolvePackageMain)
For provided configuration, returns a CJS modules resolver:
- **extensions** - List of supported file extensions in order of singificance, e.g. for Node.js it would be `['.js', '.json', '.node']`
- **confirmFile** - a `confirmFile(filepath)` function. Confirms whether there's a module at provided (not normalized, absolute) file path. Returns promise-like object which resolves with either normalized full path of a module or null (if there's no module for given path).
Although result is expected to be a promise-like object, resolution can be synchronous.
- **resolvePackageMain** - a `resolvePackageMain(dirpath)` function. Returns value of _package.json_'s `main` property for given path. Returns promise-like object which resolves with either resolved value, or null, when either `package.json` file was not found, or it didn't have _main_ property.
Same as with `confirmFile` resolution can be synchronous.
#### resolve(dir, path)
_Node.js resolver_
Asynchronously resolves module path against provided directory path.
Returns promise.
If module is found, then promise resolves with an object, containing two properties:
- `targetPath` - A path at which module was resolved
- `realPath` - Real path of resolved module (if targetPath involves symlinks then realPath will be different)
If no matching module was found, promise is rejected with `MODULE_NOT_FOUND` error (unless `silent: true` is passed with options (passed as third argument), then it resolves with `null`)
```javascript
const resolve = require("ncjsm/resolve");
// Asynchronously resolve path for 'foo' module against current path
resolve(__dirname, "foo").then(
function (pathData) {
// 'foo' module found at fooModulePath
},
function (error) {
if (error.code === "MODULE_NOT_FOUND") {
// 'foo' module doesn't exist
}
}
);
// `silent` option, prevents module not found rejections:
resolve(__dirname, "foo", { silent: true }).then(function (pathData) {
if (pathData) {
// 'foo' module found at fooModulePath
} else {
// 'foo' module doesn't exist
}
});
```
#### resolveSync(dir, path)
_Node.js resolver_
Synchronously resolves module path against provided directory path. Otherwise works same as `resolve`
```javascript
const resolveSync = require("ncjsm/resolve/sync");
// Synchronously resolve path for 'foo' module against current path
let fooModulePathData;
try {
fooModulePathData = resolveSync(__dirname, "foo");
// 'foo' module found at fooModulePath
} catch (error) {
if (error.code === "MODULE_NOT_FOUND") {
// 'foo' module doesn't exist
}
}
fooModulePathData = resolveSync(__dirname, "foo", { silent: true });
if (fooModulePathData) {
// 'foo' module found
} else {
// 'foo' module doesn't exist
}
```
#### requireUnached([moduleIds, ]callback)
Create temporary environment where `require` of specific modules will not resolved the eventually cached verions
```javascript
var requireUncached = require("ncjsm/require-uncached");
const firstCopyOfModule1 = require("./module1");
var secondCopyOfModule2 = requireUnached([require.resolve("./module1")], function () {
return require("./module1");
});
console.log(firstCopyOfModule1 === secondCopyOfModule2); // false
```
Alternatively we may resolve callback in completely cleared require cache, for that `moduleIds` argument should be skipped
```javascript
var requireUncached = require("ncjsm/require-uncached");
const firstCopyOfModule1 = require("./module1");
var secondCopyOfModule2 = requireUnached(function () { return require("./module1"); });
console.log(firstCopyOfModule1 === secondCopyOfModule2); // false
```
#### isPackageRoot(dirPath)
Whether provided path is a root of a package
```javascript
var isPackageRoot = require("ncjsm/is-package-root");
isPackageRoot(dirPath).done(function (isRoot) {
if (isRoot) {
// Provided path is package root
}
});
```
#### resolvePackageRoot(dirPath)
Resolve package root path for provided path. It is about resolution of first upper package root
```javascript
var resolvePackageRoot = require("ncjsm/resolve-package-root");
resolvePackageRoot(dirPath).done(function (root) {
if (!root) {
// Provided path is not located in any package
}
});
```
#### resolveProjectRoot(dirPath)
Resolve project root path for provided path. It is about resolution of topmost package root for given path
```javascript
var resolveProjectRoot = require("ncjsm/resolve-project-root");
resolveProjectRoot(dirPath).done(function (root) {
if (!root) {
// Provided path is not located in any project
}
});
```
#### getDependecies(modulePath, options = { ... })
Resolve all module dependencies. Returns promise that resolves with an array of paths, that includes path to input module and paths to all its dependencies (it includes deep dependencies, so also dependencies of the dependencies).
Paths to native Node.js modules are ignored.
```javascript
var getDependencies = require("ncjsm/get-dependencies");
getDependencies(modulePath).done(function (deps) {
console.log(deps); // e.g. [pathToModulePath, pathToDep1, pathToDep2, ...pathToDepn]
});
```
##### Supported `options`
###### `ignoreMissing: false`
If file for given module cannot be found then error is thrown. Set this to `true` to simply ignore not found modules
###### `ignoreExternal: false`
By default all paths to all required modules are resolved. Resolution scope may be narrowed only to modules from same package (referenced via relative path), by settung this option to `true`
## Tests [](https://travis-ci.org/medikoo/ncjsm)
$ npm test
[build-image]: https://github.com/medikoo/ncjsm/workflows/Integrate/badge.svg
[build-url]: https://github.com/medikoo/ncjsm/actions?query=workflow%3AIntegrate
[cov-image]: https://img.shields.io/codecov/c/github/medikoo/ncjsm.svg
[cov-url]: https://codecov.io/gh/medikoo/ncjsm
[npm-image]: https://img.shields.io/npm/v/ncjsm.svg
[npm-url]: https://www.npmjs.com/package/ncjsm
ncjsm-4.3.0/commitlint.config.js 0000664 0000000 0000000 00000001236 14173543707 0016626 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = {
rules: {
"body-leading-blank": [2, "always"],
"body-max-line-length": [2, "always", 72],
"footer-leading-blank": [2, "always"],
"footer-max-line-length": [2, "always", 72],
"header-max-length": [2, "always", 72],
"scope-case": [2, "always", "start-case"],
"scope-enum": [2, "always", [""]],
"subject-case": [2, "always", "sentence-case"],
"subject-empty": [2, "never"],
"subject-full-stop": [2, "never", "."],
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [
2, "always",
["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
]
}
};
ncjsm-4.3.0/get-dependencies.js 0000664 0000000 0000000 00000003437 14173543707 0016413 0 ustar 00root root 0000000 0000000 "use strict";
const uniq = require("es5-ext/array/#/uniq")
, ensureString = require("type/string/ensure")
, isObject = require("type/object/is")
, deferred = require("deferred")
, { dirname, resolve } = require("path")
, readFile = require("fs2/read-file")
, findRequires = require("find-requires")
, builtinModules = new Set(require("builtin-modules"))
, cjsResolve = require("./resolve");
const nonLocalChar = new Set([".", "/"]);
const getDirectDependencies = function (modulePath, options) {
return readFile(modulePath)(content => {
const dir = dirname(modulePath);
return deferred.map(
uniq.call(
findRequires(content, {
setupCode: `var __filename = ${ JSON.stringify(modulePath) }, __dirname = ${
JSON.stringify(dir)
};`
})
),
depPath => {
if (!nonLocalChar.has(depPath[0])) {
if (options.ignoreExternal) return null;
if (builtinModules.has(depPath.split("/")[0])) return null;
}
return cjsResolve(
dir, depPath
)(pathData => {
if (pathData) return pathData.targetPath;
if (options.ignoreMissing) return null;
throw new Error(
`Could not resolve ${ JSON.stringify(depPath) } module, required in ${
JSON.stringify(modulePath)
}`
);
});
}
)(paths => uniq.call(paths).filter(Boolean));
});
};
module.exports = function (programPath, options = {}) {
if (!isObject(options)) options = {};
programPath = resolve(ensureString(programPath));
const paths = Object.create(null);
return (function self(modulePath) {
if (paths[modulePath]) return null;
return (paths[modulePath] = getDirectDependencies(modulePath, options).map(self));
})(programPath)(() => Object.keys(paths));
};
ncjsm-4.3.0/get-resolver/ 0000775 0000000 0000000 00000000000 14173543707 0015261 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/get-resolver/.eslintrc.json 0000664 0000000 0000000 00000000255 14173543707 0020057 0 ustar 00root root 0000000 0000000 {
"extends": "medikoo/es3",
"root": true,
"rules": {
"eqeqeq": ["error", "always", { "null": "ignore" }],
"max-lines-per-function": "off",
"no-eq-null": "off"
}
}
ncjsm-4.3.0/get-resolver/index.js 0000664 0000000 0000000 00000004511 14173543707 0016727 0 ustar 00root root 0000000 0000000 // Returns CJS module (sync or async) path resolver
"use strict";
var dirname = function (path) { return path.slice(0, path.lastIndexOf("/")) || "/"; };
var join = function (path1, path2) { return path1 === "/" ? path1 + path2 : path1 + "/" + path2; };
module.exports = function (extensions, confirmFile, resolvePackageMain) {
var resolveFile = function (path, extIndex) {
var targetPath = path + (extIndex == null ? "" : extensions[extIndex]);
return confirmFile(targetPath).then(function (result) {
if (result) return result;
if (extIndex == null) extIndex = 0;
else ++extIndex;
if (!extensions[extIndex]) return null;
return resolveFile(path, extIndex);
});
};
var resolveDirectory = function (path) {
return resolvePackageMain(path).then(function (result) {
if (result) {
var mainPath = join(path, result);
return resolveFile(mainPath).then(function (mainResult) {
if (mainResult) return mainResult;
return resolveFile(join(mainPath, "index"), 0).then(function (mainDirResult) {
if (mainDirResult) return mainDirResult;
return resolveFile(join(path, "index"), 0);
});
});
}
return resolveFile(join(path, "index"), 0);
});
};
var resolveLocal = function (path) {
var pathChar = path.charAt(path.length - 1);
if (pathChar === "/") return resolveDirectory(path);
if (pathChar === ".") {
pathChar = path.charAt(path.length - 2);
if (pathChar === "/") return resolveDirectory(path);
if (pathChar === ".") {
if (path.charAt(path.length - 3) === "/") return resolveDirectory(path);
}
}
return resolveFile(path).then(function (result) {
return result || resolveDirectory(path);
});
};
var resolveExternal = function (dir, path) {
return resolveLocal(join(dir, "node_modules") + "/" + path).then(function (result) {
if (result) return result;
if (dir === "/") return null;
return resolveExternal(dirname(dir), path);
});
};
return function (dir, path) {
var pathChar;
if (path.charAt(0) === "/") return resolveLocal(path);
if (path.charAt(0) === ".") {
pathChar = path.charAt(1);
if (!pathChar || pathChar === "/") return resolveLocal(join(dir, path));
if (pathChar === ".") {
pathChar = path.charAt(2);
if (!pathChar || pathChar === "/") return resolveLocal(join(dir, path));
}
}
return resolveExternal(dir, path);
};
};
ncjsm-4.3.0/is-module-not-found-error/ 0000775 0000000 0000000 00000000000 14173543707 0017577 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/is-module-not-found-error/.eslintrc.json 0000664 0000000 0000000 00000000053 14173543707 0022371 0 ustar 00root root 0000000 0000000 { "extends": "medikoo/es3", "root": true }
ncjsm-4.3.0/is-module-not-found-error/index.js 0000664 0000000 0000000 00000001326 14173543707 0021246 0 ustar 00root root 0000000 0000000 // Whether given error is an error thrown by require internals in case module
// (at given path) was not found
"use strict";
var ensureString = require("type/string/ensure");
var pathToken = ":path", pattern;
var resolveMessage = function (error) {
var newLineIndex = error.message.indexOf("\n");
return newLineIndex > 0 ? error.message.slice(0, newLineIndex) : error.message;
};
try { require(pathToken); }
catch (error) { pattern = resolveMessage(error); }
module.exports = function (error, path) {
path = ensureString(path);
if (!error || typeof error.message !== "string") return false;
if (error.code !== "MODULE_NOT_FOUND") return false;
return resolveMessage(error) === pattern.replace(pathToken, path);
};
ncjsm-4.3.0/is-package-root.js 0000664 0000000 0000000 00000001074 14173543707 0016170 0 ustar 00root root 0000000 0000000 "use strict";
const ensureString = require("type/string/ensure")
, deferred = require("deferred")
, { resolve } = require("path")
, stat = require("fs2/stat");
module.exports = function (path) {
path = ensureString(path);
return deferred.some([
stat(resolve(path, "package.json"))(
stats => stats.isFile(),
e => {
if (e.code === "ENOENT") return false;
throw e;
}
),
stat(resolve(path, "node_modules"))(
stats => stats.isDirectory(),
e => {
if (e.code === "ENOENT") return false;
throw e;
}
)
]);
};
ncjsm-4.3.0/lib/ 0000775 0000000 0000000 00000000000 14173543707 0013411 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/lib/get-node-resolver.js 0000664 0000000 0000000 00000001635 14173543707 0017315 0 ustar 00root root 0000000 0000000 // Generates module path resolver for Node.js
// Used to generate both sync and async version
"use strict";
const isObject = require("type/object/is")
, ensureString = require("type/string/ensure")
, getResolver = require("../get-resolver")
, { resolve } = require("path");
module.exports = function (confirmFile, resolvePackageMain) {
const resolveModule = getResolver([".js", ".json", ".node"], confirmFile, resolvePackageMain);
return function (dir, path, options = {}) {
if (!isObject(options)) options = {};
dir = resolve(ensureString(dir));
path = ensureString(path);
if (!path) throw new TypeError("Empty string is not a valid require path");
return resolveModule(dir, path).then(result => {
if (result) return result;
if (options.silent) return null;
const error = new Error(`Cannot find module '${ path }'`);
error.code = "MODULE_NOT_FOUND";
throw error;
});
};
};
ncjsm-4.3.0/lib/resolve-root.js 0000664 0000000 0000000 00000001533 14173543707 0016411 0 ustar 00root root 0000000 0000000 // Find root, either first upper or topmost
"use strict";
const ensureValue = require("type/value/ensure")
, deferred = require("deferred")
, stat = require("fs2/stat")
, { resolve, sep } = require("path")
, isPackageRoot = require("../is-package-root");
module.exports = function (path, searchTopMost) {
path = resolve(String(ensureValue(path)));
return stat(path)(stats => {
if (!stats.isDirectory()) throw new Error("Provided path is not a directory path");
const tokens = path.split(sep);
tokens.forEach((token, index) => {
if (!index) return;
tokens[index] = tokens[index - 1] + sep + token;
});
tokens[0] += sep;
if (!searchTopMost) tokens.reverse();
return deferred.find(tokens, dirPath => isPackageRoot(dirPath))(rootPath =>
rootPath === undefined ? null : rootPath
);
});
};
ncjsm-4.3.0/package.json 0000664 0000000 0000000 00000004012 14173543707 0015126 0 ustar 00root root 0000000 0000000 {
"name": "ncjsm",
"version": "4.3.0",
"description": "CJS (Node.js) style modules resolver",
"author": "Mariusz Nowak (http://www.medikoo.com/)",
"keywords": [
"cjs",
"modules",
"bundle",
"browserify",
"webpack"
],
"repository": "medikoo/ncjsm",
"dependencies": {
"builtin-modules": "^3.2.0",
"deferred": "^0.7.11",
"es5-ext": "^0.10.53",
"es6-set": "^0.1.5",
"ext": "^1.6.0",
"find-requires": "^1.0.0",
"fs2": "^0.3.9",
"type": "^2.5.0"
},
"devDependencies": {
"eslint": "^8.7.0",
"eslint-config-medikoo": "^4.1.1",
"git-list-updated": "^1.2.1",
"husky": "^4.3.8",
"lint-staged": "^12.3.1",
"nyc": "^15.1.0",
"prettier-elastic": "^2.2.1",
"tad": "^3.1.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"eslint"
],
"*.{css,html,js,json,md,yaml,yml}": [
"prettier -c"
]
},
"eslintConfig": {
"extends": "medikoo/node/6",
"root": true
},
"eslintIgnore": [
"test/__playground/**/*.js"
],
"prettier": {
"printWidth": 100,
"tabWidth": 4,
"overrides": [
{
"files": [
"*.md",
"*.yml"
],
"options": {
"tabWidth": 2
}
}
]
},
"nyc": {
"all": true,
"exclude": [
".github",
"coverage/**",
"test/**",
"*.config.js"
],
"reporter": [
"lcov",
"html",
"text-summary"
]
},
"scripts": {
"coverage": "nyc npm test",
"lint": "eslint .",
"lint:updated": "pipe-git-updated --ext=js -- eslint --ignore-pattern '!*'",
"prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
"prettier-check:updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier -c",
"prettify": "prettier --write --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
"prettify:updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier --write",
"test": "node node_modules/tad/bin/tad"
},
"license": "ISC"
}
ncjsm-4.3.0/require-uncached/ 0000775 0000000 0000000 00000000000 14173543707 0016067 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/require-uncached/.eslintrc.json 0000664 0000000 0000000 00000000053 14173543707 0020661 0 ustar 00root root 0000000 0000000 { "extends": "medikoo/es5", "root": true }
ncjsm-4.3.0/require-uncached/index.js 0000664 0000000 0000000 00000003051 14173543707 0017533 0 ustar 00root root 0000000 0000000 "use strict";
var objForEach = require("es5-ext/object/for-each")
, clear = require("es5-ext/object/clear")
, isObject = require("type/object/is")
, isPlainFunction = require("type/plain-function/is")
, ensureIterable = require("type/iterable/ensure")
, ensureString = require("type/string/ensure")
, ensurePlainFunction = require("type/plain-function/ensure")
, isThenable = require("type/thenable/is")
, finallyMethod = require("ext/thenable_/finally");
module.exports = function (moduleIds, callback) {
if (isPlainFunction(moduleIds)) {
callback = moduleIds;
moduleIds = null;
} else {
if (isObject(moduleIds)) {
moduleIds = ensureIterable(moduleIds, {
ensureItem: ensureString,
name: "moduleIds",
denyEmpty: true
});
} else {
moduleIds = [ensureString(moduleIds)];
}
callback = ensurePlainFunction(callback, { name: "callback" });
}
var cache = {};
if (moduleIds) {
moduleIds.forEach(function (moduleId) {
cache[moduleId] = require.cache[moduleId];
delete require.cache[moduleId];
});
} else {
Object.assign(cache, require.cache);
clear(require.cache);
}
var restore = function () {
objForEach(cache, function (value, moduleId) {
if (value) require.cache[moduleId] = value;
else delete require.cache[moduleId];
});
};
var result;
try {
result = callback();
} catch (error) {
restore();
throw error;
}
if (!isThenable(result)) {
restore();
return result;
}
return finallyMethod.call(result, restore);
};
ncjsm-4.3.0/resolve-package-root.js 0000664 0000000 0000000 00000000242 14173543707 0017230 0 ustar 00root root 0000000 0000000 // Find top most package root
"use strict";
const resolveRoot = require("./lib/resolve-root");
module.exports = function (path) { return resolveRoot(path); };
ncjsm-4.3.0/resolve-project-root.js 0000664 0000000 0000000 00000000250 14173543707 0017302 0 ustar 00root root 0000000 0000000 // Find top most package root
"use strict";
const resolveRoot = require("./lib/resolve-root");
module.exports = function (path) { return resolveRoot(path, true); };
ncjsm-4.3.0/resolve/ 0000775 0000000 0000000 00000000000 14173543707 0014322 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/resolve/index.js 0000664 0000000 0000000 00000001507 14173543707 0015772 0 ustar 00root root 0000000 0000000 // Async module resolver
"use strict";
const getResolver = require("../lib/get-node-resolver")
, { resolve } = require("path")
, stat = require("fs2/stat")
, readFile = require("fs2/read-file")
, realpath = require("fs2/realpath");
const { parse } = JSON;
module.exports = getResolver(
targetPath => {
targetPath = resolve(targetPath);
return stat(targetPath)
.then(stats => {
if (!stats.isFile()) return null;
return realpath(targetPath).then(realPath => ({ targetPath, realPath }));
})
.catch(e => {
if (e.code === "ENOENT") return null;
throw e;
});
},
path =>
readFile(resolve(path, "package.json"))(
data => {
try { return parse(data).main; }
catch (e) { return null; }
},
e => {
if (e.code === "ENOENT") return null;
throw e;
}
)
);
ncjsm-4.3.0/resolve/sync.js 0000664 0000000 0000000 00000002003 14173543707 0015627 0 ustar 00root root 0000000 0000000 // Sync module resolver
"use strict";
const { resolve } = require("path")
, PassThru = require("../utils/pass-thru")
, getResolver = require("../lib/get-node-resolver");
const { statSync: stat, readFileSync: readFile, realpathSync: realpath } = require("fs");
const { parse } = JSON;
const resolver = getResolver(
targetPath => {
let stats;
targetPath = resolve(targetPath);
try {
stats = stat(targetPath);
} catch (e) {
if (e.code === "ENOENT") return new PassThru(null);
throw e;
}
if (stats.isFile()) return new PassThru({ targetPath, realPath: realpath(targetPath) });
return new PassThru(null);
},
path => {
let data, result;
try {
data = readFile(resolve(path, "package.json"));
} catch (e) {
if (e.code === "ENOENT") return new PassThru(null);
throw e;
}
try { result = parse(data).main; }
catch (e) { result = null; }
return new PassThru(result);
}
);
module.exports = function (dir, path, options = {}) { return resolver(dir, path, options).value; };
ncjsm-4.3.0/test/ 0000775 0000000 0000000 00000000000 14173543707 0013622 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/ 0000775 0000000 0000000 00000000000 14173543707 0016304 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/deep-dir-link-target/ 0000775 0000000 0000000 00000000000 14173543707 0022214 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/deep-dir-link-target/index.js 0000664 0000000 0000000 00000000000 14173543707 0023647 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/deep-file-link-target.js 0000664 0000000 0000000 00000000000 14173543707 0022701 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/dir-link-target/ 0000775 0000000 0000000 00000000000 14173543707 0021301 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/dir-link-target/index.js 0000664 0000000 0000000 00000000000 14173543707 0022734 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/dir/ 0000775 0000000 0000000 00000000000 14173543707 0017062 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/dir/lorem.js 0000664 0000000 0000000 00000000041 14173543707 0020531 0 ustar 00root root 0000000 0000000 "use strict";
require("outer");
ncjsm-4.3.0/test/__playground/dir/package.json 0000664 0000000 0000000 00000000024 14173543707 0021344 0 ustar 00root root 0000000 0000000 { "main": "lorem" }
ncjsm-4.3.0/test/__playground/dir/subdir/ 0000775 0000000 0000000 00000000000 14173543707 0020352 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/dir/subdir/bar.js 0000664 0000000 0000000 00000000037 14173543707 0021454 0 ustar 00root root 0000000 0000000 "use strict";
require("../");
ncjsm-4.3.0/test/__playground/file-link-target.js 0000664 0000000 0000000 00000000016 14173543707 0021775 0 ustar 00root root 0000000 0000000 "use strict";
ncjsm-4.3.0/test/__playground/foo.js 0000664 0000000 0000000 00000000075 14173543707 0017427 0 ustar 00root root 0000000 0000000 "use strict";
require("./dir/subdir/bar");
require("url");
ncjsm-4.3.0/test/__playground/invalid-file-link-with-a-fallback.json 0000664 0000000 0000000 00000000003 14173543707 0025412 0 ustar 00root root 0000000 0000000 {}
ncjsm-4.3.0/test/__playground/is-module-not-found-error/ 0000775 0000000 0000000 00000000000 14173543707 0023240 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/is-module-not-found-error/sample-error.js 0000664 0000000 0000000 00000000057 14173543707 0026210 0 ustar 00root root 0000000 0000000 "use strict";
global.should.generate.error();
ncjsm-4.3.0/test/__playground/node_modules/ 0000775 0000000 0000000 00000000000 14173543707 0020761 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/broken-main/ 0000775 0000000 0000000 00000000000 14173543707 0023163 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/broken-main/index.js 0000664 0000000 0000000 00000000015 14173543707 0024624 0 ustar 00root root 0000000 0000000 "use strict"; ncjsm-4.3.0/test/__playground/node_modules/broken-main/package.json 0000664 0000000 0000000 00000000023 14173543707 0025444 0 ustar 00root root 0000000 0000000 {
"main": "foo"
}
ncjsm-4.3.0/test/__playground/node_modules/outer/ 0000775 0000000 0000000 00000000000 14173543707 0022117 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/outer/boo.js 0000664 0000000 0000000 00000000000 14173543707 0023222 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/outer/node_modules/ 0000775 0000000 0000000 00000000000 14173543707 0024574 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/outer/node_modules/nested/ 0000775 0000000 0000000 00000000000 14173543707 0026056 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/outer/node_modules/nested/elo.js 0000664 0000000 0000000 00000000000 14173543707 0027161 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/outer/package.json 0000664 0000000 0000000 00000000022 14173543707 0024377 0 ustar 00root root 0000000 0000000 { "main": "raz" }
ncjsm-4.3.0/test/__playground/node_modules/outer/raz.js 0000664 0000000 0000000 00000000042 14173543707 0023245 0 ustar 00root root 0000000 0000000 "use strict";
require("outer3");
ncjsm-4.3.0/test/__playground/node_modules/outer3/ 0000775 0000000 0000000 00000000000 14173543707 0022202 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/outer3/index.js 0000664 0000000 0000000 00000000000 14173543707 0023635 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/pkg-main-dir/ 0000775 0000000 0000000 00000000000 14173543707 0023240 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/pkg-main-dir/lib/ 0000775 0000000 0000000 00000000000 14173543707 0024006 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/node_modules/pkg-main-dir/lib/index.js 0000664 0000000 0000000 00000000016 14173543707 0025450 0 ustar 00root root 0000000 0000000 "use strict";
ncjsm-4.3.0/test/__playground/node_modules/pkg-main-dir/package.json 0000664 0000000 0000000 00000000026 14173543707 0025524 0 ustar 00root root 0000000 0000000 {
"main": "./lib"
}
ncjsm-4.3.0/test/__playground/other.js 0000664 0000000 0000000 00000000000 14173543707 0017751 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/other/ 0000775 0000000 0000000 00000000000 14173543707 0017425 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/other/index.js 0000664 0000000 0000000 00000000042 14173543707 0021066 0 ustar 00root root 0000000 0000000 "use strict";
require("../foo");
ncjsm-4.3.0/test/__playground/otherdir/ 0000775 0000000 0000000 00000000000 14173543707 0020124 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/otherdir/esli.js 0000664 0000000 0000000 00000000000 14173543707 0021404 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/samename 0000664 0000000 0000000 00000000000 14173543707 0020003 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/samename.js 0000664 0000000 0000000 00000000000 14173543707 0020416 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/__playground/samename.json 0000664 0000000 0000000 00000000000 14173543707 0020753 0 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/_lib/ 0000775 0000000 0000000 00000000000 14173543707 0014527 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/_lib/setup-playground-dir-symlinks.js 0000664 0000000 0000000 00000001531 14173543707 0023032 0 ustar 00root root 0000000 0000000 "use strict";
const { resolve } = require("path")
, symlink = require("fs2/symlink")
, unlink = require("fs2/unlink");
const playgroundDir = resolve(__dirname, "../__playground"), symlinkOptions = { type: "junction" };
const links = [
{
destination: resolve(playgroundDir, "another-deep-dir-link"),
source: "deep-dir-link-target"
},
{ destination: resolve(playgroundDir, "deep-dir-link"), source: "another-deep-dir-link" },
{ destination: resolve(playgroundDir, "invalid-dir-link"), source: "non-existing-dir" },
{ destination: resolve(playgroundDir, "valid-dir-link"), source: "dir-link-target" }
];
module.exports = {
setup: () =>
Promise.all(
links.map(({ source, destination }) => symlink(source, destination, symlinkOptions))
),
teardown: () => Promise.all(links.map(({ destination }) => unlink(destination)))
};
ncjsm-4.3.0/test/_lib/setup-playground-file-symlinks.js 0000664 0000000 0000000 00000001761 14173543707 0023200 0 ustar 00root root 0000000 0000000 "use strict";
const { resolve } = require("path")
, symlink = require("fs2/symlink")
, unlink = require("fs2/unlink");
const playgroundDir = resolve(__dirname, "../__playground"), symlinkOptions = { type: "file" };
const links = [
{
destination: resolve(playgroundDir, "another-deep-file-link.js"),
source: "deep-file-link-target.js"
},
{
destination: resolve(playgroundDir, "deep-file-link.js"),
source: "another-deep-file-link.js"
},
{
destination: resolve(playgroundDir, "invalid-file-link-with-a-fallback.js"),
source: "non-existing-file.js"
},
{ destination: resolve(playgroundDir, "invalid-file-link.js"), source: "non-existing-file.js" },
{ destination: resolve(playgroundDir, "valid-file-link.js"), source: "file-link-target.js" }
];
module.exports = {
setup: () =>
Promise.all(
links.map(({ source, destination }) => symlink(source, destination, symlinkOptions))
),
teardown: () => Promise.all(links.map(({ destination }) => unlink(destination)))
};
ncjsm-4.3.0/test/get-dependencies.js 0000664 0000000 0000000 00000001517 14173543707 0017367 0 ustar 00root root 0000000 0000000 "use strict";
const { resolve } = require("path");
const pgDir = resolve(__dirname, "__playground");
module.exports.regular = function (t, a, d) {
t(resolve(pgDir, "other/index.js")).done(result => {
a.deep(
result.sort(),
[
resolve(pgDir, "other/index.js"), resolve(pgDir, "foo.js"),
resolve(pgDir, "dir/subdir/bar.js"), resolve(pgDir, "dir/lorem.js"),
resolve(pgDir, "node_modules/outer/raz.js"),
resolve(pgDir, "node_modules/outer3/index.js")
].sort()
);
d();
}, d);
};
module.exports.ignoreExternal = function (t, a, d) {
t(resolve(pgDir, "other/index.js"), { ignoreExternal: true }).done(result => {
a.deep(
result.sort(),
[
resolve(pgDir, "other/index.js"), resolve(pgDir, "foo.js"),
resolve(pgDir, "dir/subdir/bar.js"), resolve(pgDir, "dir/lorem.js")
].sort()
);
d();
}, d);
};
ncjsm-4.3.0/test/get-resolver.js 0000664 0000000 0000000 00000007156 14173543707 0016607 0 ustar 00root root 0000000 0000000 /* eslint max-statements: off */
"use strict";
const { resolve } = require("path")
, PassThru = require("../utils/pass-thru");
const existingFiles = [
"/project/foo.js", "/project/other.js", "/project/other/index.js", "/project/samename",
"/project/samename.js", "/project/samename.json", "/project/dir/subdir/bar.js",
"/project/dir/lorem.js", "/project/otherdir/esli.js", "/project/node_modules/outer/boo.js",
"/project/node_modules/outer/raz.js", "/project/node_modules/outer/node_modules/nested/elo.js",
"/project/node_modules/outer3/index.js"
];
existingFiles.includes = require("es5-ext/array/#/contains");
const existingMains = { "/project/dir": "lorem", "/project/node_modules/outer": "raz" };
const isFile = function (path) {
path = resolve(path);
return new PassThru(existingFiles.includes(path) ? path : null);
};
const resolvePackageMain = function (path) {
return new PassThru(existingMains[resolve(path)] || null);
};
module.exports = function (t, a) {
const resolver = t([".js", ".json"], isFile, resolvePackageMain);
a(resolver("/", "elo").value, null);
a(resolver("/", "foo").value, null);
a(resolver("/", "outer/boo").value, null);
a(resolver("/", "./project/foo").value, "/project/foo.js");
a(resolver("/project", "./foo").value, "/project/foo.js");
a(resolver("/project", "./foo.js").value, "/project/foo.js");
a(resolver("/project", "./foo.json").value, null);
a(resolver("/project", "./other").value, "/project/other.js");
a(resolver("/project", "./other/").value, "/project/other/index.js");
a(resolver("/project", "./samename").value, "/project/samename");
a(resolver("/project", "./samename.js").value, "/project/samename.js");
a(resolver("/project", "./samename.json").value, "/project/samename.json");
a(resolver("/project", "./samename").value, "/project/samename");
a(resolver("/project", "./dir").value, "/project/dir/lorem.js");
a(resolver("/project", "./dir/lorem").value, "/project/dir/lorem.js");
a(resolver("/project", "./dir/subdir/bar").value, "/project/dir/subdir/bar.js");
a(resolver("/project/dir", ".").value, "/project/dir/lorem.js");
a(resolver("/project/dir", "./").value, "/project/dir/lorem.js");
a(resolver("/project/dir", "./lorem").value, "/project/dir/lorem.js");
a(resolver("/project/dir", "../other").value, "/project/other.js");
a(resolver("/project/dir", "../other/").value, "/project/other/index.js");
a(resolver("/project/dir/subdir", "../").value, "/project/dir/lorem.js");
a(resolver("/project/dir/subdir", "../../foo").value, "/project/foo.js");
a(resolver("/project", "outer").value, "/project/node_modules/outer/raz.js");
a(resolver("/project", "outer/boo").value, "/project/node_modules/outer/boo.js");
a(resolver("/project", "outer/boo.json").value, null);
a(resolver("/project", "outer3").value, "/project/node_modules/outer3/index.js");
a(resolver("/project", "nested/elo").value, null);
a(
resolver("/project/node_modules/outer", "outer3").value,
"/project/node_modules/outer3/index.js"
);
a(resolver("/project/node_modules/outer", "project/foo").value, null);
a(
resolver("/project/node_modules/outer", "nested/elo").value,
"/project/node_modules/outer/node_modules/nested/elo.js"
);
a(resolver("/project/node_modules/outer/node_modules/nested", "project/foo").value, null);
a(
resolver("/project/node_modules/outer/node_modules/nested", "outer").value,
"/project/node_modules/outer/raz.js"
);
a(
resolver("/project/node_modules/outer/node_modules/nested", "outer/boo").value,
"/project/node_modules/outer/boo.js"
);
a(
resolver("/project/node_modules/outer/node_modules/nested", "outer3").value,
"/project/node_modules/outer3/index.js"
);
};
ncjsm-4.3.0/test/is-module-not-found-error/ 0000775 0000000 0000000 00000000000 14173543707 0020556 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/is-module-not-found-error/index.js 0000664 0000000 0000000 00000000674 14173543707 0022232 0 ustar 00root root 0000000 0000000 "use strict";
const { resolve } = require("path");
const pg = resolve(__dirname, "../__playground/is-module-not-found-error");
module.exports = function (t, a) {
let path;
try {
require((path = "./wrong/path"));
a.never("Wrong path");
} catch (e) {
a(t(e, path), true, "Wrong path");
}
try {
require((path = `${ pg }/sample-error`));
a.never("Evaluation error");
} catch (e2) {
a(t(e2, path), false, "Syntax error");
}
};
ncjsm-4.3.0/test/is-package-root.js 0000664 0000000 0000000 00000001256 14173543707 0017151 0 ustar 00root root 0000000 0000000 "use strict";
const deferred = require("deferred")
, { resolve } = require("path");
const playgroundDir = resolve(__dirname, "__playground");
module.exports = function (t, a, d) {
deferred(
t(playgroundDir)(value => { a(value, true, "node_modules"); }),
t(resolve(playgroundDir, "otherdir"))(value => { a(value, false, "Empty"); }),
t(resolve(playgroundDir, "dir"))(value => { a(value, true, "package.json"); }),
t(resolve(playgroundDir, "node_modules/outer"))(value => {
a(value, true, "package.json and node_modules");
}),
t(resolve(playgroundDir, "node_modules/outer3"))(value => {
a(value, false, "In node_modules");
})
).done(() => { d(); }, d);
};
ncjsm-4.3.0/test/lib/ 0000775 0000000 0000000 00000000000 14173543707 0014370 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/lib/get-node-resolver.js 0000664 0000000 0000000 00000001104 14173543707 0020263 0 ustar 00root root 0000000 0000000 "use strict";
const PassThru = require("../../utils/pass-thru")
, isModuleNotFoundError = require("../../is-module-not-found-error");
const resolver = function () { return new PassThru(null); };
module.exports = function (t, a) {
const resolve = t(resolver, resolver);
a.throws(() => { resolve(); }, TypeError);
a.throws(() => { resolve("asdfa"); }, TypeError);
a.throws(() => { resolve("asdfa", ""); }, TypeError);
try {
resolve("asdfa", "elo");
throw new Error("Unexpected");
} catch (error) {
a(isModuleNotFoundError(error, "elo"), true);
}
};
ncjsm-4.3.0/test/lib/resolve-root.js 0000664 0000000 0000000 00000000417 14173543707 0017370 0 ustar 00root root 0000000 0000000 "use strict";
// TOOD: Configure tests bulletproof against environment side-effects
// In this case test is vulnerable to location of tested package
// (any upmost package.json or node_modules folder will affect its result)
module.exports = function (t, a, d) { d(); };
ncjsm-4.3.0/test/require-uncached.js 0000664 0000000 0000000 00000001606 14173543707 0017407 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
const pathA = "./__playground/other"
, pathB = "./__playground/samename"
, moduleA = require(pathA);
let moduleA2;
const innerModuleB = t([require.resolve(pathA), require.resolve(pathB)], () => {
moduleA2 = require(pathA);
a.not(moduleA2, moduleA);
return require(pathB);
});
const moduleB = require(pathB);
a(require(pathA), moduleA);
a.not(moduleB, innerModuleB);
t([require.resolve(pathA), require.resolve(pathB)], () => {
const moduleA3 = require(pathA);
a.not(moduleA3, moduleA);
a.not(moduleA3, moduleA2);
const moduleB3 = require(pathB);
a.not(moduleB3, moduleB);
});
a(require(pathA), moduleA);
a(require(pathB), moduleB);
t(() => {
const moduleA3 = require(pathA);
a.not(moduleA3, moduleA);
a.not(moduleA3, moduleA2);
const moduleB3 = require(pathB);
a.not(moduleB3, moduleB);
});
};
ncjsm-4.3.0/test/resolve-package-root.js 0000664 0000000 0000000 00000001415 14173543707 0020212 0 ustar 00root root 0000000 0000000 "use strict";
const deferred = require("deferred")
, { resolve } = require("path");
const playgroundDir = resolve(__dirname, "__playground");
module.exports = function (t, a, d) {
deferred(
t(playgroundDir)(value => { a(value, playgroundDir, "node_modules"); }),
t(resolve(playgroundDir, "otherdir"))(value => { a(value, playgroundDir, "Empty"); }),
t(resolve(playgroundDir, "dir"))(value => {
a(value, resolve(playgroundDir, "dir"), "package.json");
}),
t(resolve(playgroundDir, "node_modules/outer"))(value => {
a(value, resolve(playgroundDir, "node_modules/outer"), "package.json and node_modules");
}),
t(resolve(playgroundDir, "node_modules/outer3"))(value => {
a(value, playgroundDir, "In node_modules");
})
).done(() => { d(); }, d);
};
ncjsm-4.3.0/test/resolve-project-root.js 0000664 0000000 0000000 00000000417 14173543707 0020266 0 ustar 00root root 0000000 0000000 "use strict";
// TOOD: Configure tests bulletproof against environment side-effects
// In this case test is vulnerable to location of tested package
// (any upmost package.json or node_modules folder will affect its result)
module.exports = function (t, a, d) { d(); };
ncjsm-4.3.0/test/resolve/ 0000775 0000000 0000000 00000000000 14173543707 0015301 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/resolve/index.js 0000664 0000000 0000000 00000022636 14173543707 0016757 0 ustar 00root root 0000000 0000000 /* eslint max-lines: "off" */
"use strict";
const noop = require("es5-ext/function/noop")
, { resolve } = require("path")
, isModuleNotFoundError = require("../../is-module-not-found-error");
const {
setup: setupFileLinks,
teardown: teardownFileLinks
} = require("../_lib/setup-playground-file-symlinks");
const {
setup: setupDirLinks,
teardown: teardownDirLinks
} = require("../_lib/setup-playground-dir-symlinks");
const playgroundDir = resolve(__dirname, "../__playground");
const unexpected = () => { throw new Error("Unexpected"); };
module.exports = (t, a) =>
Promise.all([
t(playgroundDir, "./foo").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/foo.js`),
realPath: resolve(`${ playgroundDir }/foo.js`)
});
}),
t(playgroundDir, "./foo.js").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/foo.js`),
realPath: resolve(`${ playgroundDir }/foo.js`)
});
}),
t(playgroundDir, "./foo.json").then(unexpected, error => {
a(isModuleNotFoundError(error, "./foo.json"), true);
}),
t(playgroundDir, "./foo.json", { silent: true }).then(value => a(value, null)),
t(playgroundDir, "./other").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/other.js`),
realPath: resolve(`${ playgroundDir }/other.js`)
});
}),
t(playgroundDir, "./other/").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/other/index.js`),
realPath: resolve(`${ playgroundDir }/other/index.js`)
});
}),
t(playgroundDir, "./samename").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/samename`),
realPath: resolve(`${ playgroundDir }/samename`)
});
}),
t(playgroundDir, "./samename.js").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/samename.js`),
realPath: resolve(`${ playgroundDir }/samename.js`)
});
}),
t(playgroundDir, "./samename.json").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/samename.json`),
realPath: resolve(`${ playgroundDir }/samename.json`)
});
}),
t(playgroundDir, "./samename").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/samename`),
realPath: resolve(`${ playgroundDir }/samename`)
});
}),
t(playgroundDir, "./dir").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
}),
t(playgroundDir, "./dir/lorem").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
}),
t(playgroundDir, "./dir/subdir/bar").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/dir/subdir/bar.js`),
realPath: resolve(`${ playgroundDir }/dir/subdir/bar.js`)
});
}),
t(`${ playgroundDir }/dir`, ".").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
}),
t(`${ playgroundDir }/dir`, "./").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
}),
t(`${ playgroundDir }/dir`, "./lorem").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
}),
t(`${ playgroundDir }/dir`, "../other").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/other.js`),
realPath: resolve(`${ playgroundDir }/other.js`)
});
}),
t(`${ playgroundDir }/dir`, "../other/").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/other/index.js`),
realPath: resolve(`${ playgroundDir }/other/index.js`)
});
}),
t(`${ playgroundDir }/dir/subdir`, "../").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
}),
t(`${ playgroundDir }/dir/subdir`, "../../foo").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/foo.js`),
realPath: resolve(`${ playgroundDir }/foo.js`)
});
}),
t(playgroundDir, "outer").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`)
});
}),
t(playgroundDir, "outer/boo").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`)
});
}),
t(playgroundDir, "outer/boo.json").then(unexpected, error => {
a(isModuleNotFoundError(error, "outer/boo.json"), true);
}),
t(playgroundDir, "outer3").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`)
});
}),
t(playgroundDir, "pkg-main-dir").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/node_modules/pkg-main-dir/lib/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/pkg-main-dir/lib/index.js`)
});
}),
t(playgroundDir, "nested/elo").then(unexpected, error => {
a(isModuleNotFoundError(error, "nested/elo"), true);
}),
t(playgroundDir, "broken-main").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/node_modules/broken-main/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/broken-main/index.js`)
});
}),
t(`${ playgroundDir }/node_modules/outer`, "outer3").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`)
});
}),
t(`${ playgroundDir }/node_modules/outer`, "project/foo").then(unexpected, error => {
a(isModuleNotFoundError(error, "project/foo"), true);
}),
t(`${ playgroundDir }/node_modules/outer`, "nested/elo").then(value => {
a.deep(value, {
targetPath: resolve(
`${ playgroundDir }/node_modules/outer/node_modules/nested/elo.js`
),
realPath: resolve(
`${ playgroundDir }/node_modules/outer/node_modules/nested/elo.js`
)
});
}),
t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "project/foo").then(
unexpected,
error => { a(isModuleNotFoundError(error, "project/foo"), true); }
),
t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "outer").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`)
});
}),
t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "outer/boo").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`)
});
}),
t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "outer3").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`)
});
}),
setupFileLinks().then(
() =>
Promise.all([
t(playgroundDir, "./valid-file-link").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/valid-file-link.js`),
realPath: resolve(`${ playgroundDir }/file-link-target.js`)
});
}),
t(playgroundDir, "./deep-file-link").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/deep-file-link.js`),
realPath: resolve(`${ playgroundDir }/deep-file-link-target.js`)
});
}),
t(playgroundDir, "./invalid-file-link").then(unexpected, error => {
a(isModuleNotFoundError(error, "./invalid-file-link"), true);
}),
t(playgroundDir, "./invalid-file-link-with-a-fallback").then(value => {
a.deep(value, {
targetPath: resolve(
`${ playgroundDir }/invalid-file-link-with-a-fallback.json`
),
realPath: resolve(
`${ playgroundDir }/invalid-file-link-with-a-fallback.json`
)
});
})
]).then(teardownFileLinks, error => teardownFileLinks.then(() => { throw error; })),
error => {
if (error.code === "EPERM") {
process.stdout.write(
"Warning: Could not test file symlinks due to not suffient " +
"process permissions to create them\n"
);
return;
}
throw error;
}
),
setupDirLinks().then(() =>
Promise.all([
t(playgroundDir, "./valid-dir-link").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/valid-dir-link/index.js`),
realPath: resolve(`${ playgroundDir }/dir-link-target/index.js`)
});
}),
t(playgroundDir, "./deep-dir-link").then(value => {
a.deep(value, {
targetPath: resolve(`${ playgroundDir }/deep-dir-link/index.js`),
realPath: resolve(`${ playgroundDir }/deep-dir-link-target/index.js`)
});
}),
t(playgroundDir, "./invalid-dir-link").then(unexpected, error => {
a(isModuleNotFoundError(error, "./invalid-dir-link"), true);
})
]).then(teardownDirLinks, error => teardownDirLinks.then(() => { throw error; }))
)
]).then(noop);
ncjsm-4.3.0/test/resolve/sync.js 0000664 0000000 0000000 00000021103 14173543707 0016610 0 ustar 00root root 0000000 0000000 /* eslint max-lines: "off" */
"use strict";
const noop = require("es5-ext/function/noop")
, { resolve } = require("path")
, isModuleNotFoundError = require("../../is-module-not-found-error");
const {
setup: setupFileLinks,
teardown: teardownFileLinks
} = require("../_lib/setup-playground-file-symlinks");
const {
setup: setupDirLinks,
teardown: teardownDirLinks
} = require("../_lib/setup-playground-dir-symlinks");
const playgroundDir = resolve(__dirname, "../__playground");
module.exports = (t, a) => {
a.deep(t(playgroundDir, "./foo"), {
targetPath: resolve(`${ playgroundDir }/foo.js`),
realPath: resolve(`${ playgroundDir }/foo.js`)
});
a.deep(t(playgroundDir, "./foo.js"), {
targetPath: resolve(`${ playgroundDir }/foo.js`),
realPath: resolve(`${ playgroundDir }/foo.js`)
});
try {
t(playgroundDir, "./foo.json");
throw new Error("Unexpected");
} catch (error) {
a(isModuleNotFoundError(error, "./foo.json"), true);
}
a(t(playgroundDir, "./foo.json", { silent: true }), null);
a.deep(t(playgroundDir, "./other"), {
targetPath: resolve(`${ playgroundDir }/other.js`),
realPath: resolve(`${ playgroundDir }/other.js`)
});
a.deep(t(playgroundDir, "./other/"), {
targetPath: resolve(`${ playgroundDir }/other/index.js`),
realPath: resolve(`${ playgroundDir }/other/index.js`)
});
a.deep(t(playgroundDir, "./samename"), {
targetPath: resolve(`${ playgroundDir }/samename`),
realPath: resolve(`${ playgroundDir }/samename`)
});
a.deep(t(playgroundDir, "./samename.js"), {
targetPath: resolve(`${ playgroundDir }/samename.js`),
realPath: resolve(`${ playgroundDir }/samename.js`)
});
a.deep(t(playgroundDir, "./samename.json"), {
targetPath: resolve(`${ playgroundDir }/samename.json`),
realPath: resolve(`${ playgroundDir }/samename.json`)
});
a.deep(t(playgroundDir, "./samename"), {
targetPath: resolve(`${ playgroundDir }/samename`),
realPath: resolve(`${ playgroundDir }/samename`)
});
a.deep(t(playgroundDir, "./dir"), {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
a.deep(t(playgroundDir, "./dir/lorem"), {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
a.deep(t(playgroundDir, "./dir/subdir/bar"), {
targetPath: resolve(`${ playgroundDir }/dir/subdir/bar.js`),
realPath: resolve(`${ playgroundDir }/dir/subdir/bar.js`)
});
a.deep(t(`${ playgroundDir }/dir`, "."), {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
a.deep(t(`${ playgroundDir }/dir`, "./"), {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
a.deep(t(`${ playgroundDir }/dir`, "./lorem"), {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
a.deep(t(`${ playgroundDir }/dir`, "../other"), {
targetPath: resolve(`${ playgroundDir }/other.js`),
realPath: resolve(`${ playgroundDir }/other.js`)
});
a.deep(t(`${ playgroundDir }/dir`, "../other/"), {
targetPath: resolve(`${ playgroundDir }/other/index.js`),
realPath: resolve(`${ playgroundDir }/other/index.js`)
});
a.deep(t(`${ playgroundDir }/dir/subdir`, "../"), {
targetPath: resolve(`${ playgroundDir }/dir/lorem.js`),
realPath: resolve(`${ playgroundDir }/dir/lorem.js`)
});
a.deep(t(`${ playgroundDir }/dir/subdir`, "../../foo"), {
targetPath: resolve(`${ playgroundDir }/foo.js`),
realPath: resolve(`${ playgroundDir }/foo.js`)
});
a.deep(t(playgroundDir, "outer"), {
targetPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`)
});
a.deep(t(playgroundDir, "outer/boo"), {
targetPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`)
});
try {
t(playgroundDir, "outer/boo.json");
throw new Error("Unexpected");
} catch (error) {
a(isModuleNotFoundError(error, "outer/boo.json"), true);
}
a.deep(t(playgroundDir, "outer3"), {
targetPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`)
});
a.deep(t(playgroundDir, "pkg-main-dir"), {
targetPath: resolve(`${ playgroundDir }/node_modules/pkg-main-dir/lib/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/pkg-main-dir/lib/index.js`)
});
a.deep(t(playgroundDir, "broken-main"), {
targetPath: resolve(`${ playgroundDir }/node_modules/broken-main/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/broken-main/index.js`)
});
try {
t(playgroundDir, "nested/elo");
throw new Error("Unexpected");
} catch (error) {
a(isModuleNotFoundError(error, "nested/elo"), true);
}
a.deep(t(`${ playgroundDir }/node_modules/outer`, "outer3"), {
targetPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`)
});
try {
t(`${ playgroundDir }/node_modules/outer`, "project/foo");
throw new Error("Unexpected");
} catch (error) {
a(isModuleNotFoundError(error, "project/foo"), true);
}
a.deep(t(`${ playgroundDir }/node_modules/outer`, "nested/elo"), {
targetPath: resolve(`${ playgroundDir }/node_modules/outer/node_modules/nested/elo.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer/node_modules/nested/elo.js`)
});
try {
t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "project/foo");
throw new Error("Unexpected");
} catch (error) {
a(isModuleNotFoundError(error, "project/foo"), true);
}
a.deep(t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "outer"), {
targetPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer/raz.js`)
});
a.deep(t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "outer/boo"), {
targetPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer/boo.js`)
});
a.deep(t(`${ playgroundDir }/node_modules/outer/node_modules/nested`, "outer3"), {
targetPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`),
realPath: resolve(`${ playgroundDir }/node_modules/outer3/index.js`)
});
// Symlink tests
return Promise.all([
setupFileLinks().then(
() => {
let testError, teardownPromise;
try {
a.deep(t(playgroundDir, "./valid-file-link"), {
targetPath: resolve(`${ playgroundDir }/valid-file-link.js`),
realPath: resolve(`${ playgroundDir }/file-link-target.js`)
});
a.deep(t(playgroundDir, "./deep-file-link"), {
targetPath: resolve(`${ playgroundDir }/deep-file-link.js`),
realPath: resolve(`${ playgroundDir }/deep-file-link-target.js`)
});
try {
t(playgroundDir, "./invalid-file-link");
throw new Error("Unexpected");
} catch (error) {
a(isModuleNotFoundError(error, "./invalid-file-link"), true);
}
a.deep(t(playgroundDir, "./invalid-file-link-with-a-fallback"), {
targetPath: resolve(
`${ playgroundDir }/invalid-file-link-with-a-fallback.json`
),
realPath: resolve(
`${ playgroundDir }/invalid-file-link-with-a-fallback.json`
)
});
} catch (error) {
testError = error;
} finally {
teardownPromise = teardownFileLinks();
}
return teardownPromise.then(() => { if (testError) throw testError; });
},
error => {
if (error.code === "EPERM") {
process.stdout.write(
"Warning: Could not test file symlinks due to not suffient " +
"process permissions to create them\n"
);
return;
}
throw error;
}
),
setupDirLinks().then(() => {
let testError, teardownPromise;
try {
a.deep(t(playgroundDir, "./valid-dir-link"), {
targetPath: resolve(`${ playgroundDir }/valid-dir-link/index.js`),
realPath: resolve(`${ playgroundDir }/dir-link-target/index.js`)
});
a.deep(t(playgroundDir, "./deep-dir-link"), {
targetPath: resolve(`${ playgroundDir }/deep-dir-link/index.js`),
realPath: resolve(`${ playgroundDir }/deep-dir-link-target/index.js`)
});
try {
t(playgroundDir, "./invalid-dir-link");
throw new Error("Unexpected");
} catch (error) {
a(isModuleNotFoundError(error, "./invalid-dir-link"), true);
}
} catch (error) {
testError = error;
} finally {
teardownPromise = teardownDirLinks();
}
return teardownPromise.then(() => { if (testError) throw testError; });
})
]).then(noop);
};
ncjsm-4.3.0/test/utils/ 0000775 0000000 0000000 00000000000 14173543707 0014762 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/test/utils/is-path-external.js 0000664 0000000 0000000 00000000431 14173543707 0020503 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
a(t("foo"), true);
a(t("foo/bar.js"), true);
a(t("/foo/bar.js"), false);
a(t("./foo/bar.js"), false);
a(t("../foo/bar.js"), false);
a(t(".."), false);
a(t("."), false);
a(t("../../"), false);
a(t(".../sdfsdf/"), true);
};
ncjsm-4.3.0/test/utils/pass-thru.js 0000664 0000000 0000000 00000000255 14173543707 0017250 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (T, a) {
const passThru = new T("foo");
a(passThru.value, "foo");
a(passThru.then(value => `${ value }bar`).value, "foobar");
};
ncjsm-4.3.0/utils/ 0000775 0000000 0000000 00000000000 14173543707 0014003 5 ustar 00root root 0000000 0000000 ncjsm-4.3.0/utils/is-path-external.js 0000664 0000000 0000000 00000000700 14173543707 0017523 0 ustar 00root root 0000000 0000000 "use strict";
const ensureString = require("type/string/ensure");
module.exports = function (path) {
let pathChar;
path = ensureString(path);
pathChar = path.charAt(0);
if (pathChar === "/") return false;
if (pathChar === ".") {
pathChar = path.charAt(1);
if (!pathChar || pathChar === "/") return false;
if (pathChar === ".") {
pathChar = path.charAt(2);
if (!pathChar || pathChar === "/") return false;
}
}
return true;
};
ncjsm-4.3.0/utils/pass-thru.js 0000664 0000000 0000000 00000000472 14173543707 0016272 0 ustar 00root root 0000000 0000000 // Promise-like mock, to be used for sync resolution of modules
"use strict";
const PassThru = (module.exports = function (value) { this.value = value; });
PassThru.prototype.then = function (fn) {
const result = fn(this.value);
if (result instanceof PassThru) return result;
return new PassThru(result);
};