pax_global_header00006660000000000000000000000064143602460630014516gustar00rootroot0000000000000052 comment=2b347ff00663a6263c498af4f9dfcdccf1b81846 ncjsm-4.3.2/000077500000000000000000000000001436024606300126365ustar00rootroot00000000000000ncjsm-4.3.2/.editorconfig000066400000000000000000000004561436024606300153200ustar00rootroot00000000000000# 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 [*.md] trim_trailing_whitespace = false ncjsm-4.3.2/.github/000077500000000000000000000000001436024606300141765ustar00rootroot00000000000000ncjsm-4.3.2/.github/FUNDING.yml000066400000000000000000000000201436024606300160030ustar00rootroot00000000000000github: medikoo ncjsm-4.3.2/.github/workflows/000077500000000000000000000000001436024606300162335ustar00rootroot00000000000000ncjsm-4.3.2/.github/workflows/integrate.yml000066400000000000000000000003741436024606300207440ustar00rootroot00000000000000# main only name: Integrate on: push: branches: [main] env: FORCE_COLOR: 1 jobs: _: uses: medikoo/github-actions-workflows/.github/workflows/12-integrate.yml@main secrets: USER_GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }} ncjsm-4.3.2/.github/workflows/publish.yml000066400000000000000000000004721436024606300204270ustar00rootroot00000000000000# Version tags only name: Publish on: push: tags: - v[0-9]+.[0-9]+.[0-9]+ env: FORCE_COLOR: 1 jobs: _: uses: medikoo/github-actions-workflows/.github/workflows/publish.yml@main secrets: USER_GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} ncjsm-4.3.2/.github/workflows/validate.yml000066400000000000000000000002731436024606300205510ustar00rootroot00000000000000# PR's only name: Validate on: pull_request: branches: [main] env: FORCE_COLOR: 1 jobs: _: uses: medikoo/github-actions-workflows/.github/workflows/12-validate.yml@main ncjsm-4.3.2/.gitignore000066400000000000000000000001061436024606300146230ustar00rootroot00000000000000/.nyc_output /coverage /node_modules npm-debug.log /package-lock.json ncjsm-4.3.2/CHANGELOG.md000066400000000000000000000167521436024606300144620ustar00rootroot00000000000000# 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.2](https://github.com/medikoo/ncjsm/compare/v4.3.1...v4.3.2) (2023-01-13) ### Bug Fixes - **`requireUncached`:** Fix modules cache recovery on global reset ([c90dae4](https://github.com/medikoo/ncjsm/commit/c90dae4c31fb4f3e3e490ca8af87d279500730ed)) ### [4.3.1](https://github.com/medikoo/ncjsm/compare/v4.3.0...v4.3.1) (2022-07-09) ### Bug Fixes - Fix `ignoreMissing` support in deep dependencies resolution ([#6](https://github.com/serverless/serverless/issues/6)) ([669491c](https://github.com/medikoo/ncjsm/commit/669491c8ba2942ef7f1d5caa98a11082d9767dd4)) ([Diego Henrique Domingues](https://github.com/ddomingues)) ### Maintenance Improvements - Bump dependencies ([48cac7c](https://github.com/medikoo/ncjsm/commit/48cac7ccc312dd58bee7559b9214fc13f78910b5)) - Fix `.editorconfig` ([3300948](https://github.com/medikoo/ncjsm/commit/3300948b2f5d724df9d5efb14ebb0101f1a37691)) - Upgrade `lint-staged` to v13 ([a6e6a8f](https://github.com/medikoo/ncjsm/commit/a6e6a8f2573a741a081dde9e32555aec140be73c)) ## [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.2/CHANGES000066400000000000000000000003131436024606300136260ustar00rootroot00000000000000For 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.2/LICENSE000066400000000000000000000014051436024606300136430ustar00rootroot00000000000000ISC License Copyright (c) 2015-2023, 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.2/README.md000066400000000000000000000156731436024606300141310ustar00rootroot00000000000000[![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 [![Build Status](https://travis-ci.org/medikoo/ncjsm.svg)](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.2/commitlint.config.js000066400000000000000000000012611436024606300166170ustar00rootroot00000000000000"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", ["", "requireUncached"]], "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.2/get-dependencies.js000066400000000000000000000034461436024606300164060ustar00rootroot00000000000000"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, { silent: true })(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.2/get-resolver/000077500000000000000000000000001436024606300152545ustar00rootroot00000000000000ncjsm-4.3.2/get-resolver/.eslintrc.json000066400000000000000000000002551436024606300200520ustar00rootroot00000000000000{ "extends": "medikoo/es3", "root": true, "rules": { "eqeqeq": ["error", "always", { "null": "ignore" }], "max-lines-per-function": "off", "no-eq-null": "off" } } ncjsm-4.3.2/get-resolver/index.js000066400000000000000000000045111436024606300167220ustar00rootroot00000000000000// 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.2/is-module-not-found-error/000077500000000000000000000000001436024606300175725ustar00rootroot00000000000000ncjsm-4.3.2/is-module-not-found-error/.eslintrc.json000066400000000000000000000000531436024606300223640ustar00rootroot00000000000000{ "extends": "medikoo/es3", "root": true } ncjsm-4.3.2/is-module-not-found-error/index.js000066400000000000000000000013261436024606300212410ustar00rootroot00000000000000// 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.2/is-package-root.js000066400000000000000000000010741436024606300161630ustar00rootroot00000000000000"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.2/lib/000077500000000000000000000000001436024606300134045ustar00rootroot00000000000000ncjsm-4.3.2/lib/get-node-resolver.js000066400000000000000000000016351436024606300173100ustar00rootroot00000000000000// 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.2/lib/resolve-root.js000066400000000000000000000015331436024606300164040ustar00rootroot00000000000000// 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.2/package.json000066400000000000000000000040131436024606300151220ustar00rootroot00000000000000{ "name": "ncjsm", "version": "4.3.2", "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.3.0", "deferred": "^0.7.11", "es5-ext": "^0.10.62", "es6-set": "^0.1.6", "ext": "^1.7.0", "find-requires": "^1.0.0", "fs2": "^0.3.9", "type": "^2.7.2" }, "devDependencies": { "eslint": "^8.31.0", "eslint-config-medikoo": "^4.1.2", "git-list-updated": "^1.2.1", "husky": "^4.3.8", "lint-staged": "^13.1.0", "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.2/require-uncached/000077500000000000000000000000001436024606300160625ustar00rootroot00000000000000ncjsm-4.3.2/require-uncached/.eslintrc.json000066400000000000000000000000531436024606300206540ustar00rootroot00000000000000{ "extends": "medikoo/es5", "root": true } ncjsm-4.3.2/require-uncached/index.js000066400000000000000000000032761436024606300175370ustar00rootroot00000000000000"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 () { if (!moduleIds) { Object.keys(require.cache).forEach(function (moduleId) { if (!cache[moduleId]) delete require.cache[moduleId]; }); } 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.2/resolve-package-root.js000066400000000000000000000002421436024606300172230ustar00rootroot00000000000000// Find top most package root "use strict"; const resolveRoot = require("./lib/resolve-root"); module.exports = function (path) { return resolveRoot(path); }; ncjsm-4.3.2/resolve-project-root.js000066400000000000000000000002501436024606300172750ustar00rootroot00000000000000// Find top most package root "use strict"; const resolveRoot = require("./lib/resolve-root"); module.exports = function (path) { return resolveRoot(path, true); }; ncjsm-4.3.2/resolve/000077500000000000000000000000001436024606300143155ustar00rootroot00000000000000ncjsm-4.3.2/resolve/index.js000066400000000000000000000015071436024606300157650ustar00rootroot00000000000000// 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.2/resolve/sync.js000066400000000000000000000020031436024606300156220ustar00rootroot00000000000000// 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.2/test/000077500000000000000000000000001436024606300136155ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/000077500000000000000000000000001436024606300162775ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/deep-dir-link-target/000077500000000000000000000000001436024606300222075ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/deep-dir-link-target/index.js000066400000000000000000000000001436024606300236420ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/deep-file-link-target.js000066400000000000000000000000001436024606300226740ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/dir-link-target/000077500000000000000000000000001436024606300212745ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/dir-link-target/index.js000066400000000000000000000000001436024606300227270ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/dir/000077500000000000000000000000001436024606300170555ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/dir/lorem.js000066400000000000000000000000411436024606300205240ustar00rootroot00000000000000"use strict"; require("outer"); ncjsm-4.3.2/test/__playground/dir/package.json000066400000000000000000000000241436024606300213370ustar00rootroot00000000000000{ "main": "lorem" } ncjsm-4.3.2/test/__playground/dir/subdir/000077500000000000000000000000001436024606300203455ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/dir/subdir/bar.js000066400000000000000000000000371436024606300214470ustar00rootroot00000000000000"use strict"; require("../"); ncjsm-4.3.2/test/__playground/file-link-target.js000066400000000000000000000000161436024606300217700ustar00rootroot00000000000000"use strict"; ncjsm-4.3.2/test/__playground/foo.js000066400000000000000000000000751436024606300174220ustar00rootroot00000000000000"use strict"; require("./dir/subdir/bar"); require("url"); ncjsm-4.3.2/test/__playground/invalid-file-link-with-a-fallback.json000066400000000000000000000000031436024606300254050ustar00rootroot00000000000000{} ncjsm-4.3.2/test/__playground/is-module-not-found-error/000077500000000000000000000000001436024606300232335ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/is-module-not-found-error/sample-error.js000066400000000000000000000000571436024606300262030ustar00rootroot00000000000000"use strict"; global.should.generate.error(); ncjsm-4.3.2/test/__playground/missing-reference.js000066400000000000000000000000661436024606300222440ustar00rootroot00000000000000"use strict"; require("./other"); require("../bar"); ncjsm-4.3.2/test/__playground/node_modules/000077500000000000000000000000001436024606300207545ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/broken-main/000077500000000000000000000000001436024606300231565ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/broken-main/index.js000066400000000000000000000000151436024606300246170ustar00rootroot00000000000000"use strict";ncjsm-4.3.2/test/__playground/node_modules/broken-main/package.json000066400000000000000000000000231436024606300254370ustar00rootroot00000000000000{ "main": "foo" } ncjsm-4.3.2/test/__playground/node_modules/outer/000077500000000000000000000000001436024606300221125ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/outer/boo.js000066400000000000000000000000001436024606300232150ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/outer/node_modules/000077500000000000000000000000001436024606300245675ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/outer/node_modules/nested/000077500000000000000000000000001436024606300260515ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/outer/node_modules/nested/elo.js000066400000000000000000000000001436024606300271540ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/outer/package.json000066400000000000000000000000221436024606300243720ustar00rootroot00000000000000{ "main": "raz" } ncjsm-4.3.2/test/__playground/node_modules/outer/raz.js000066400000000000000000000000421436024606300232400ustar00rootroot00000000000000"use strict"; require("outer3"); ncjsm-4.3.2/test/__playground/node_modules/outer3/000077500000000000000000000000001436024606300221755ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/outer3/index.js000066400000000000000000000000001436024606300236300ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/pkg-main-dir/000077500000000000000000000000001436024606300232335ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/pkg-main-dir/lib/000077500000000000000000000000001436024606300240015ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/node_modules/pkg-main-dir/lib/index.js000066400000000000000000000000161436024606300254430ustar00rootroot00000000000000"use strict"; ncjsm-4.3.2/test/__playground/node_modules/pkg-main-dir/package.json000066400000000000000000000000261436024606300255170ustar00rootroot00000000000000{ "main": "./lib" } ncjsm-4.3.2/test/__playground/other.js000066400000000000000000000000001436024606300177440ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/other/000077500000000000000000000000001436024606300174205ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/other/index.js000066400000000000000000000000421436024606300210610ustar00rootroot00000000000000"use strict"; require("../foo"); ncjsm-4.3.2/test/__playground/otherdir/000077500000000000000000000000001436024606300201175ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/otherdir/esli.js000066400000000000000000000000001436024606300213770ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/samename000066400000000000000000000000001436024606300177760ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/samename.js000066400000000000000000000000001436024606300204110ustar00rootroot00000000000000ncjsm-4.3.2/test/__playground/samename.json000066400000000000000000000000001436024606300207460ustar00rootroot00000000000000ncjsm-4.3.2/test/_lib/000077500000000000000000000000001436024606300145225ustar00rootroot00000000000000ncjsm-4.3.2/test/_lib/setup-playground-dir-symlinks.js000066400000000000000000000015311436024606300230250ustar00rootroot00000000000000"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.2/test/_lib/setup-playground-file-symlinks.js000066400000000000000000000017611436024606300231730ustar00rootroot00000000000000"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.2/test/get-dependencies.js000066400000000000000000000021331436024606300173550ustar00rootroot00000000000000"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); }; module.exports.ignoreMissing = function (t, a, d) { t(resolve(pgDir, "missing-reference.js"), { ignoreMissing: true }).done(result => { a.deep( result.sort(), [resolve(pgDir, "missing-reference.js"), resolve(pgDir, "other.js")].sort() ); d(); }, d); }; ncjsm-4.3.2/test/get-resolver.js000066400000000000000000000071561436024606300166020ustar00rootroot00000000000000/* 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.2/test/is-module-not-found-error/000077500000000000000000000000001436024606300205515ustar00rootroot00000000000000ncjsm-4.3.2/test/is-module-not-found-error/index.js000066400000000000000000000006741436024606300222250ustar00rootroot00000000000000"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.2/test/is-package-root.js000066400000000000000000000012561436024606300171440ustar00rootroot00000000000000"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.2/test/lib/000077500000000000000000000000001436024606300143635ustar00rootroot00000000000000ncjsm-4.3.2/test/lib/get-node-resolver.js000066400000000000000000000011041436024606300202560ustar00rootroot00000000000000"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.2/test/lib/resolve-root.js000066400000000000000000000004171436024606300173630ustar00rootroot00000000000000"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.2/test/require-uncached.js000066400000000000000000000016061436024606300174020ustar00rootroot00000000000000"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.2/test/resolve-package-root.js000066400000000000000000000014151436024606300202050ustar00rootroot00000000000000"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.2/test/resolve-project-root.js000066400000000000000000000004171436024606300202610ustar00rootroot00000000000000"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.2/test/resolve/000077500000000000000000000000001436024606300152745ustar00rootroot00000000000000ncjsm-4.3.2/test/resolve/index.js000066400000000000000000000226361436024606300167520ustar00rootroot00000000000000/* 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.2/test/resolve/sync.js000066400000000000000000000211031436024606300166030ustar00rootroot00000000000000/* 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.2/test/utils/000077500000000000000000000000001436024606300147555ustar00rootroot00000000000000ncjsm-4.3.2/test/utils/is-path-external.js000066400000000000000000000004311436024606300204760ustar00rootroot00000000000000"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.2/test/utils/pass-thru.js000066400000000000000000000002551436024606300172430ustar00rootroot00000000000000"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.2/utils/000077500000000000000000000000001436024606300137765ustar00rootroot00000000000000ncjsm-4.3.2/utils/is-path-external.js000066400000000000000000000007001436024606300175160ustar00rootroot00000000000000"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.2/utils/pass-thru.js000066400000000000000000000004721436024606300162650ustar00rootroot00000000000000// 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); };