pax_global_header00006660000000000000000000000064151663104200014510gustar00rootroot0000000000000052 comment=d2d30de86300fa862e7792057b82b59cd44f2b5d browserify-resolve-7877a0d/000077500000000000000000000000001516631042000157235ustar00rootroot00000000000000browserify-resolve-7877a0d/.editorconfig000066400000000000000000000012161516631042000204000ustar00rootroot00000000000000root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true max_line_length = 200 [*.{,m}js] block_comment_start = /* block_comment = * block_comment_end = */ [*.yml] indent_style = space indent_size = 1 [{package.json,*.mjs}] indent_style = tab [lib/core.json] indent_style = tab [CHANGELOG.md] indent_style = space indent_size = 2 [{*.json,Makefile,CONTRIBUTING.md}] max_line_length = off [test/{dotdot,resolver,module_dir,multirepo,node_path,pathfilter,precedence}/**/*] indent_style = off indent_size = off max_line_length = off insert_final_newline = off browserify-resolve-7877a0d/.eslintrc000066400000000000000000000032271516631042000175530ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "indent": [2, 4], "strict": 0, "complexity": 0, "consistent-return": 0, "curly": 0, "dot-notation": [2, { "allowKeywords": true }], "func-name-matching": 0, "func-style": 0, "global-require": 1, "id-length": [2, { "min": 1, "max": 40 }], "max-lines": [2, 360], "max-lines-per-function": 0, "max-nested-callbacks": 0, "max-params": 0, "max-statements-per-line": [2, { "max": 2 }], "max-statements": 0, "no-magic-numbers": 0, "no-shadow": 0, "no-use-before-define": 0, "sort-keys": 0, }, "overrides": [ { "files": "bin/**", "rules": { "no-process-exit": "off", }, }, { "files": "example/**", "rules": { "no-console": 0, }, }, { "files": "test/resolver/nested_symlinks/mylib/*.js", "rules": { "no-throw-literal": 0, }, }, { "files": "test/**", "parserOptions": { "ecmaVersion": 5, "allowReserved": false, }, "rules": { "dot-notation": [2, { "allowPattern": "throws" }], "max-lines": 0, "max-lines-per-function": 0, "no-unused-vars": [2, { "vars": "all", "args": "none" }], }, }, ], "ignorePatterns": [ "./test/resolver/malformed_package_json/package.json", ], } browserify-resolve-7877a0d/.github/000077500000000000000000000000001516631042000172635ustar00rootroot00000000000000browserify-resolve-7877a0d/.github/FUNDING.yml000066400000000000000000000011021516631042000210720ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/resolve community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] browserify-resolve-7877a0d/.github/INCIDENT_RESPONSE_PROCESS.md000066400000000000000000000072701516631042000235240ustar00rootroot00000000000000# Incident Response Process for **resolve** ## Reporting a Vulnerability We take the security of **resolve** very seriously. If you believe you’ve found a security vulnerability, please inform us responsibly through coordinated disclosure. ### How to Report > **Do not** report security vulnerabilities through public GitHub issues, discussions, or social media. Instead, please use one of these secure channels: 1. **GitHub Security Advisories** Use the **Report a vulnerability** button in the Security tab of the [browserify/resolve repository](https://github.com/browserify/resolve). 2. **Email** Follow the posted [Security Policy](https://github.com/browserify/resolve/security/policy). ### What to Include **Required Information:** - Brief description of the vulnerability type - Affected version(s) and components - Steps to reproduce the issue - Impact assessment (what an attacker could achieve) - Confirm the issue is not present in test files (in other words, only via the official entry points in `exports`) **Helpful Additional Details:** - Full paths of affected source files - Specific commit or branch where the issue exists - Required configuration to reproduce - Proof-of-concept code (if available) - Suggested mitigation or fix ## Our Response Process **Timeline Commitments:** - **Initial acknowledgment**: Within 24 hours - **Detailed response**: Within 3 business days - **Status updates**: Every 7 days until resolved - **Resolution target**: 90 days for most issues **What We’ll Do:** 1. Acknowledge your report and assign a tracking ID 2. Assess the vulnerability and determine severity 3. Develop and test a fix 4. Coordinate disclosure timeline with you 5. Release a security update and publish an advisory and CVE 6. Credit you in our security advisory (if desired) ## Disclosure Policy - **Coordinated disclosure**: We’ll work with you on timing - **Typical timeline**: 90 days from report to public disclosure - **Early disclosure**: If actively exploited - **Delayed disclosure**: For complex issues ## Scope **In Scope:** - **resolve** package (all supported versions) - Official examples and documentation - Core resolution APIs - Dependencies with direct security implications **Out of Scope:** - Third-party wrappers or extensions - Bundler-specific integrations - Social engineering or physical attacks - Theoretical vulnerabilities without practical exploitation - Issues in non-production files ## Security Measures **Our Commitments:** - Regular vulnerability scanning via `npm audit` - Automated security checks in CI/CD (GitHub Actions) - Secure coding practices and mandatory code review - Prompt patch releases for critical issues **User Responsibilities:** - Keep **resolve** updated - Monitor dependency vulnerabilities - Follow secure configuration guidelines for module resolution ## Legal Safe Harbor **We will NOT:** - Initiate legal action - Contact law enforcement - Suspend or terminate your access **You must:** - Only test against your own installations - Not access, modify, or delete user data - Not degrade service availability - Not publicly disclose before coordinated disclosure - Act in good faith ## Recognition - **Advisory Credits**: Credit in GitHub Security Advisories (unless anonymous) ## Security Updates **Stay Informed:** - Subscribe to npm updates for **resolve** - Enable GitHub Security Advisory notifications **Update Process:** - Patch releases (e.g., 1.22.10 → 1.22.11) - Out-of-band releases for critical issues - Advisories via GitHub Security Advisories ## Contact Information - **Security reports**: Security tab of [browserify/resolve](https://github.com/browserify/resolve/security) - **General inquiries**: GitHub Discussions or Issues browserify-resolve-7877a0d/.github/THREAT_MODEL.md000066400000000000000000000102241516631042000215130ustar00rootroot00000000000000## Threat Model for resolve (module path resolution library) ### 1. Library Overview - **Library Name:** resolve - **Brief Description:** Implements Node.js `require.resolve()` algorithm for synchronous and asynchronous file path resolution. Used to locate modules and files in Node.js projects. - **Key Public APIs/Functions:** `resolve.sync()` / `resolve/sync`, `resolve()` / `resolve/async` ### 2. Define Scope This threat model focuses on the core path resolution algorithm, including filesystem interaction, option handling, and cache management. ### 3. Conceptual System Diagram ``` Caller Application → resolve(id, options) → Resolution Algorithm → File System │ └→ Options Handling └→ Cache System ``` **Trust Boundaries:** - **Input module IDs:** May come from untrusted sources (user input, configuration) - **Filesystem access:** The library interacts with the filesystem to resolve paths - **Options:** Provided by the caller - **Cache:** Used to improve performance, but could be a vector for tampering or information disclosure if not handled securely ### 4. Identify Assets - **Integrity of resolution output:** Ensure correct and safe file path matching. - **Confidentiality of configuration:** Prevent sensitive path information from being leaked. - **Availability/performance for host application:** Prevent crashes or resource exhaustion. - **Security of host application:** Prevent path traversal or unintended filesystem access. - **Reputation of library:** Maintain trust by avoiding supply chain attacks and vulnerabilities[1][3][4]. ### 5. Identify Threats | Component / API / Interaction | S | T | R | I | D | E | |-----------------------------------------------------|----|----|----|----|----|----| | Public API Call (`resolve/async`, `resolve/sync`) | ✓ | ✓ | – | ✓ | – | – | | Filesystem Access | – | ✓ | – | ✓ | ✓ | – | | Options Handling | ✓ | ✓ | – | ✓ | – | – | | Cache System | – | ✓ | – | ✓ | – | – | **Key Threats:** - **Spoofing:** Malicious module IDs mimicking legitimate packages, or spoofing configuration options[1]. - **Tampering:** Caller-provided paths altering resolution order, or cache tampering leading to incorrect results[1][4]. - **Information Disclosure:** Error messages revealing filesystem structure or sensitive paths[1]. - **Denial of Service:** Recursive or excessive resolution exhausting filesystem handles or causing application crashes[1]. - **Path Traversal:** Malicious input allowing access to files outside the intended directory[4]. ### 6. Mitigation/Countermeasures | Threat Identified | Proposed Mitigation | |--------------------------------------------|---------------------| | Spoofing (malicious module IDs/config) | Sanitize input IDs; validate against known patterns; restrict `basedir` to app-controlled paths[1][4]. | | Tampering (path traversal, cache) | Validate input IDs for directory escapes; secure cache reads/writes; restrict cache to trusted sources[1][4]. | | Information Disclosure (error messages) | Generic "not found" errors without internal paths; avoid exposing sensitive configuration in errors[1]. | | Denial of Service (resource exhaustion) | Limit recursive resolution depth; implement timeout; monitor for excessive filesystem operations[1]. | ### 7. Risk Ranking - **High:** Path traversal via malicious IDs (if not properly mitigated) - **Medium:** Cache tampering or spoofing (if cache is not secured) - **Low:** Information disclosure in errors (if error handling is generic) ### 8. Next Steps & Review 1. **Implement input sanitization for module IDs and configuration.** 2. **Add resolution depth limiting and timeout.** 3. **Audit cache handling for race conditions and tampering.** 4. **Regularly review dependencies for vulnerabilities.** 5. **Keep documentation and threat model up to date.** 6. **Monitor for new threats as the ecosystem and library evolve[1][3].** browserify-resolve-7877a0d/.github/workflows/000077500000000000000000000000001516631042000213205ustar00rootroot00000000000000browserify-resolve-7877a0d/.github/workflows/executable.yml000066400000000000000000000010121516631042000241560ustar00rootroot00000000000000name: resolve executable on: [push, pull_request] permissions: read-all jobs: _: name: cli runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ljharb/actions/node/install@main - run: "[ $(./bin/resolve fs) = 'fs' ]" name: run inside the package with a direct path - run: "npm link && [ $(resolve fs) = 'fs' ] && npm uninstall -g resolve" name: run linked as a global in the PATH - run: "[ $(npx resolve fs) = 'fs' ]" name: run via npx browserify-resolve-7877a0d/.github/workflows/node-aught.yml000066400000000000000000000005451516631042000241020ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] permissions: read-all jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '< 10' type: minors command: npm run tests-only node: name: 'node < 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' browserify-resolve-7877a0d/.github/workflows/node-pretest.yml000066400000000000000000000002351516631042000244540ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] permissions: read-all jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main browserify-resolve-7877a0d/.github/workflows/node-tens.yml000066400000000000000000000005371516631042000237440ustar00rootroot00000000000000name: 'Tests: node.js 10 - 20' on: [pull_request, push] permissions: read-all jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10 < 20' type: minors command: npm run tests-only node: name: 'node 10 - 20' needs: [tests] runs-on: ubuntu-latest steps: - run: true browserify-resolve-7877a0d/.github/workflows/node-twenties.yml000066400000000000000000000005261516631042000246330ustar00rootroot00000000000000name: 'Tests: node.js >= 20' on: [pull_request, push] permissions: read-all jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 20' type: minors command: npm run tests-only node: name: 'node >= 20' needs: [tests] runs-on: ubuntu-latest steps: - run: true browserify-resolve-7877a0d/.github/workflows/rebase.yml000066400000000000000000000004401516631042000233020ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] permissions: read-all jobs: _: name: "Automatic Rebase" runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ljharb/rebase@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} browserify-resolve-7877a0d/.github/workflows/require-allow-edits.yml000066400000000000000000000003321516631042000257370ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] permissions: read-all jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main browserify-resolve-7877a0d/.gitignore000066400000000000000000000003571516631042000177200ustar00rootroot00000000000000# gitignore node_modules **/node_modules coverage/ .nyc_output/ # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock # symlinked file used in tests test/resolver/symlinked/_/node_modules/package .npmignore browserify-resolve-7877a0d/.npmrc000066400000000000000000000000231516631042000170360ustar00rootroot00000000000000package-lock=false browserify-resolve-7877a0d/CONTRIBUTING.md000066400000000000000000000135021516631042000201550ustar00rootroot00000000000000# Contributing :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: The following is a set of guidelines for contributing to all the repositories managed by [@LJHarb](https://github.com/ljharb), which are hosted on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request. # How Can I Contribute? There are lots of ways to get involved. Here are some suggestions of things we'd love some help with. ## Resolving existing issues You can consider helping out with issues already requiring attention - look for a "help wanted" label. ## Reporting issues If you run into problems in the project, you can report them by opening a new issue within the repository. Before filing an issue, please perform a cursory search to see if the problem has already been reported. If it has **and the issue is still open**, add a comment to the existing issue instead of opening a new one. If there is an issue template available, please always fill it out in its entirety - the template is there for a reason. ### How Do I Submit a (Good) Bug Report? Explain the problem and include additional details to help maintainers reproduce the problem: * **Use a clear and descriptive title** for the issue to identify the problem. * **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining which command exactly you used in the terminal. When listing steps, **don't just say what you did, but explain how you did it**. For example, if you moved the cursor to the end of a line, explain if you used the mouse, or a keyboard shortcut or a command, and if so which one? * **Provide specific examples to demonstrate the steps**. Include links to files or Github projects, or copy/pasteable snippets, which you use in those examples. If you're providing snippets in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). * **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior. * **Explain which behavior you expected to see instead and why.** * **Provide as much context as possible** in order to help others verify and ultimately fix the issue. ## Documentation We are happy to welcome contributions from anyone willing to improve documentation by adding missing information or making it more consistent and coherent. # Dev Environment * Install [Node.js](https://nodejs.org/en/), preferably with [nvm](https://github.com/nvm-sh/nvm) * [Fork the repo and clone your fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) * Get all dependencies ``` npm install ``` * Add the upstream source for being able to sync main project changes back into your fork. For example, to configure an upstream remote repository for a fork of https://github.com/ljharb/repo-report run: ``` git remote add upstream git@github.com:ljharb/repo-report.git ``` * Run the tests and the build ``` npm test ``` * Make and submit changes to the project source files following our [pull request submission workflow](#pull-requests) # Style Guide / Coding conventions ### Pull requests Create a new branch ``` git checkout -b issue1234 ``` Commit the changes to your branch, including a coherent commit message that follows our [standards](#commit-messages) ``` git commit -a ``` Before sending the pull request, make sure your code is running on the latest available code by rebasing onto the upstream source ``` git fetch upstream git rebase upstream/main ``` Verify your changes. Tests that fail without your changes *must* be added. ``` npm test # or npm run tests-only ``` Push your changes ``` git push origin issue1234 ``` Send the [pull request](https://docs.github.com/en/pull-requests), make requested changes, and get merged. ### Commit Messages * Limit the first line of the commit message (message summary) to 72 characters or less. * Use the present tense ("Add feature" not "Added feature") and imperative mood ("Move cursor to..." not "Moves cursor to...") when providing a description of what you did. * If your PR addresses an issue, reference it in the body of the commit message. * See the rest of the conventions [here](https://gist.github.com/ljharb/772b0334387a4bee89af24183114b3c7) #### Commit message example ``` [Tag]: Short description of what you did Longer description here if necessary Fixes #1234 ``` > **Note:** Add co-authors to your commit message for commits with multiple authors ``` Co-authored-by: Name Here ``` # Code of Conduct [Code of Conduct](https://github.com/ljharb/.github/blob/HEAD/CODE_OF_CONDUCT.md) # Where can I ask for help? If you have any questions, please contact [@LJHarb](mailto:ljharb@gmail.com). # Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: - The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or - The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or - The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. - I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. browserify-resolve-7877a0d/LICENSE000066400000000000000000000020571516631042000167340ustar00rootroot00000000000000MIT License Copyright (c) 2012 James Halliday Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. browserify-resolve-7877a0d/SECURITY.md000066400000000000000000000006001516631042000175100ustar00rootroot00000000000000# Security Please [file a private vulnerability report](https://github.com/browserify/resolve/security/advisories/new), or email [@ljharb](https://github.com/ljharb), if you have a potential security vulnerability to report. ## Incident Response See our [Incident Response Process](.github/INCIDENT_RESPONSE_PROCESS.md). ## Threat Model See [THREAT_MODEL.md](./THREAT_MODEL.md). browserify-resolve-7877a0d/appveyor.yml000066400000000000000000000055141516631042000203200ustar00rootroot00000000000000version: 1.0.{build} skip_branch_with_pr: true build: off environment: matrix: #- nodejs_version: "17" - nodejs_version: "16" - nodejs_version: "15" - nodejs_version: "14" - nodejs_version: "13" - nodejs_version: "12" - nodejs_version: "11" - nodejs_version: "10" - nodejs_version: "9" - nodejs_version: "8" - nodejs_version: "7" - nodejs_version: "6" - nodejs_version: "5" - nodejs_version: "4" - nodejs_version: "3" - nodejs_version: "2" - nodejs_version: "1" - nodejs_version: "0.12" - nodejs_version: "0.10" - nodejs_version: "0.8" - nodejs_version: "0.6" matrix: # fast_finish: true allow_failures: - nodejs_version: "0.8" # platform: x86 # x64 has started failing on the registry side, around early November 2020 - nodejs_version: "0.6" platform: - x86 - x64 # Install scripts. (runs after repo cloning) install: # Fix symlinks in working copy (see https://github.com/appveyor/ci/issues/650#issuecomment-186592582) / https://github.com/charleskorn/batect/commit/d08986802ec43086902958c4ee7e57ff3e71dbef - git config core.symlinks true - git reset --hard # Get the latest stable version of Node.js or io.js - ps: if ($env:nodejs_version -ne '0.6') { Install-Product node $env:nodejs_version $env:platform } - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:platform - IF %nodejs_version% EQU 0.6 npm config set strict-ssl false && npm -g install npm@1.3 - IF %nodejs_version% EQU 0.8 npm config set strict-ssl false && npm -g install npm@1.4.28 && npm install -g npm@4.5 - IF %nodejs_version% EQU 1 npm -g install npm@2.9 - IF %nodejs_version% EQU 2 npm -g install npm@4 - IF %nodejs_version% EQU 3 npm -g install npm@4 - IF %nodejs_version% EQU 4 npm -g install npm@5.3 - IF %nodejs_version% EQU 5 npm -g install npm@5.3 - IF %nodejs_version% EQU 6 npm -g install npm@6.9 - IF %nodejs_version% EQU 7 npm -g install npm@5 - IF %nodejs_version% EQU 7 npm -g install npm@6 - IF %nodejs_version% EQU 8 npm -g install npm@6 - IF %nodejs_version% EQU 9 npm -g install npm@6.9 - IF %nodejs_version% EQU 10 npm -g install npm@7 - IF %nodejs_version% EQU 11 npm -g install npm@7 - IF %nodejs_version% EQU 12 npm -g install npm@7 - IF %nodejs_version% EQU 13 npm -g install npm@7 - IF %nodejs_version% EQU 14 npm -g install npm@7 - IF %nodejs_version% EQU 15 npm -g install npm@7 - IF %nodejs_version% EQU 16 npm -g install npm@7 - set PATH=%APPDATA%\npm;%PATH% #- IF %nodejs_version% NEQ 0.6 AND %nodejs_version% NEQ 0.8 npm -g install npm # install modules - npm install # Post-install test scripts. test_script: # Output useful info for debugging. - node --version - npm --version # run tests - cd - npm run tests-only - 'subst X: ..' - 'cd /d X:\resolve' - cd - npm run tests-only browserify-resolve-7877a0d/async.js000066400000000000000000000000701516631042000173730ustar00rootroot00000000000000'use strict'; module.exports = require('./lib/async'); browserify-resolve-7877a0d/bin/000077500000000000000000000000001516631042000164735ustar00rootroot00000000000000browserify-resolve-7877a0d/bin/resolve000077500000000000000000000027771516631042000201150ustar00rootroot00000000000000#!/usr/bin/env node 'use strict'; var path = require('path'); var fs = require('fs'); if ( String(process.env.npm_lifecycle_script).slice(0, 8) !== 'resolve ' && ( !process.argv || process.argv.length < 2 || (process.argv[1] !== __filename && fs.statSync(process.argv[1]).ino !== fs.statSync(__filename).ino) || (process.env.npm_lifecycle_event !== 'npx' && process.env._ && fs.realpathSync(path.resolve(process.env._)) !== __filename) ) ) { console.error('Error: `resolve` must be run directly as an executable'); process.exit(1); } var supportsPreserveSymlinkFlag = require('supports-preserve-symlinks-flag'); var preserveSymlinks = false; for (var i = 2; i < process.argv.length; i += 1) { if (process.argv[i].slice(0, 2) === '--') { if (supportsPreserveSymlinkFlag && process.argv[i] === '--preserve-symlinks') { preserveSymlinks = true; } else if (process.argv[i].length > 2) { console.error('Unknown argument ' + process.argv[i].replace(/[=].*$/, '')); process.exit(2); } process.argv.splice(i, 1); i -= 1; if (process.argv[i] === '--') { break; } // eslint-disable-line no-restricted-syntax } } if (process.argv.length < 3) { console.error('Error: `resolve` expects a specifier'); process.exit(2); } var resolve = require('../'); var result = resolve.sync(process.argv[2], { basedir: process.cwd(), preserveSymlinks: preserveSymlinks }); console.log(result); browserify-resolve-7877a0d/eslint.config.mjs000066400000000000000000000030471516631042000212040ustar00rootroot00000000000000import ljharb from '@ljharb/eslint-config/flat'; export default [ ...ljharb, { ignores: [ 'test/resolver/malformed_package_json/package.json', 'test/list-exports/**', ], }, { rules: { 'array-bracket-newline': 'off', complexity: 'off', 'consistent-return': 'off', curly: 'off', 'dot-notation': ['error', { allowKeywords: true }], 'func-name-matching': 'off', 'func-style': 'off', 'global-require': 'warn', 'id-length': ['error', { min: 1, max: 40 }], 'max-depth': 'off', 'max-lines-per-function': 'off', 'max-lines': 'off', 'max-nested-callbacks': 'off', 'max-params': 'off', 'max-statements-per-line': ['error', { max: 2 }], 'max-statements': 'off', 'multiline-comment-style': 'off', 'no-magic-numbers': 'off', 'no-shadow': 'off', 'no-use-before-define': 'off', 'sort-keys': 'off', strict: 'off', }, }, { files: ['**/*.js'], rules: { indent: ['error', 4], }, }, { files: ['bin/**'], rules: { 'no-process-exit': 'off', }, }, { files: ['example/**'], rules: { 'no-console': 'off', }, }, { files: ['test/resolver/nested_symlinks/mylib/*.js'], rules: { 'no-throw-literal': 'off', }, }, { files: ['test/**'], languageOptions: { ecmaVersion: 5, parserOptions: { allowReserved: false, }, }, rules: { 'dot-notation': ['error', { allowPattern: 'throws' }], 'max-lines': 'off', 'max-lines-per-function': 'off', 'no-unused-vars': ['error', { vars: 'all', args: 'none', caughtErrors: 'none', }], }, }, ]; browserify-resolve-7877a0d/example/000077500000000000000000000000001516631042000173565ustar00rootroot00000000000000browserify-resolve-7877a0d/example/async.js000066400000000000000000000002331516631042000210270ustar00rootroot00000000000000var resolve = require('../'); resolve('tap', { basedir: __dirname }, function (err, res) { if (err) console.error(err); else console.log(res); }); browserify-resolve-7877a0d/example/sync.js000066400000000000000000000001471516631042000206720ustar00rootroot00000000000000var resolve = require('../'); var res = resolve.sync('tap', { basedir: __dirname }); console.log(res); browserify-resolve-7877a0d/index.js000066400000000000000000000002561516631042000173730ustar00rootroot00000000000000var async = require('./lib/async'); async.core = require('./lib/core'); async.isCore = require('./lib/is-core'); async.sync = require('./lib/sync'); module.exports = async; browserify-resolve-7877a0d/lib/000077500000000000000000000000001516631042000164715ustar00rootroot00000000000000browserify-resolve-7877a0d/lib/async.js000066400000000000000000000264361516631042000201570ustar00rootroot00000000000000var fs = require('fs'); var getHomedir = require('./homedir'); var path = require('path'); var caller = require('./caller'); var nodeModulesPaths = require('./node-modules-paths'); var normalizeOptions = require('./normalize-options'); var isCore = require('is-core-module'); var $Error = require('es-errors'); var $TypeError = require('es-errors/type'); var realpathFS = process.platform !== 'win32' && fs.realpath && typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath; var relativePathRegex = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/; var windowsDriveRegex = /^\w:[/\\]*$/; var nodeModulesRegex = /[/\\]node_modules[/\\]*$/; var homedir = getHomedir(); function defaultPaths() { if (!homedir) return []; return [ path.join(homedir, '.node_modules'), path.join(homedir, '.node_libraries') ]; } var defaultIsFile = function isFile(file, cb) { fs.stat(file, function (err, stat) { if (!err) { return cb(null, stat.isFile() || stat.isFIFO()); } if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); return cb(err); }); }; var defaultIsDir = function isDirectory(dir, cb) { fs.stat(dir, function (err, stat) { if (!err) { return cb(null, stat.isDirectory()); } if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); return cb(err); }); }; var defaultRealpath = function realpath(x, cb) { realpathFS(x, function (realpathErr, realPath) { if (realpathErr && realpathErr.code !== 'ENOENT') cb(realpathErr); else cb(null, realpathErr ? x : realPath); }); }; function maybeRealpath(realpath, x, opts, cb) { if (opts && opts.preserveSymlinks === false) { realpath(x, cb); } else { cb(null, x); } } function defaultReadPackage(readFile, pkgfile, cb) { readFile(pkgfile, function (readFileErr, body) { if (readFileErr) cb(readFileErr); else { try { var pkg = JSON.parse(body); cb(null, pkg); } catch (jsonErr) { cb(null); } } }); } function getPackageCandidates(x, start, opts) { var dirs = nodeModulesPaths(start, opts, x); for (var i = 0; i < dirs.length; i++) { dirs[i] = path.join(dirs[i], x); } return dirs; } module.exports = function resolve(x, options, callback) { var cb = callback; var opts = options; if (typeof options === 'function') { cb = opts; opts = {}; } if (typeof x !== 'string') { var err = new $TypeError('Path must be a string.'); return process.nextTick(function () { cb(err); }); } opts = normalizeOptions(x, opts); var isFile = opts.isFile || defaultIsFile; var isDirectory = opts.isDirectory || defaultIsDir; var readFile = opts.readFile || fs.readFile; var realpath = opts.realpath || defaultRealpath; var readPackage = opts.readPackage || defaultReadPackage; if (opts.readFile && opts.readPackage) { var conflictErr = new $TypeError('`readFile` and `readPackage` are mutually exclusive.'); return process.nextTick(function () { cb(conflictErr); }); } var packageIterator = opts.packageIterator; var extensions = opts.extensions || ['.js']; var includeCoreModules = opts.includeCoreModules !== false; var basedir = opts.basedir || path.dirname(caller()); var parent = opts.filename || basedir; opts.paths = opts.paths || defaultPaths(); // ensure that `basedir` is an absolute path at this point, resolving against the process' current working directory var absoluteStart = path.resolve(basedir); maybeRealpath( realpath, absoluteStart, opts, function (err, realStart) { if (err) cb(err); else init(realStart); } ); var res; function init(basedir) { if (relativePathRegex.test(x)) { res = path.resolve(basedir, x); if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/'; if (x.slice(-1) === '/' && res === basedir) { loadAsDirectory(res, opts.package, onfile); } else loadAsFile(res, opts.package, onfile); } else if (includeCoreModules && isCore(x)) { return cb(null, x); } else loadNodeModules(x, basedir, function (err, n, pkg) { if (err) cb(err); else if (n) { return maybeRealpath(realpath, n, opts, function (err, realN) { if (err) { cb(err); } else { cb(null, realN, pkg); } }); } else { var moduleError = new $Error("Cannot find module '" + x + "' from '" + parent + "'"); moduleError.code = 'MODULE_NOT_FOUND'; cb(moduleError); } }); } function onfile(err, m, pkg) { if (err) cb(err); else if (m) cb(null, m, pkg); else loadAsDirectory(res, function (err, d, pkg) { if (err) cb(err); else if (d) { maybeRealpath(realpath, d, opts, function (err, realD) { if (err) { cb(err); } else { cb(null, realD, pkg); } }); } else { var moduleError = new $Error("Cannot find module '" + x + "' from '" + parent + "'"); moduleError.code = 'MODULE_NOT_FOUND'; cb(moduleError); } }); } function loadAsFile(x, thePackage, callback) { var loadAsFilePackage = thePackage; var cb = callback; if (typeof loadAsFilePackage === 'function') { cb = loadAsFilePackage; loadAsFilePackage = undefined; } var exts = [''].concat(extensions); load(exts, x, loadAsFilePackage); function load(exts, x, loadPackage) { if (exts.length === 0) return cb(null, undefined, loadPackage); var file = x + exts[0]; var pkg = loadPackage; if (pkg) onpkg(null, pkg); else loadpkg(path.dirname(file), onpkg); function onpkg(err, pkg_, dir) { pkg = pkg_; if (err) return cb(err); if (dir && pkg && opts.pathFilter) { var rfile = path.relative(dir, file); var rel = rfile.slice(0, rfile.length - exts[0].length); var r = opts.pathFilter(pkg, x, rel); if (r) return load( [''].concat(extensions), path.resolve(dir, r), pkg ); } isFile(file, onex); } function onex(err, ex) { if (err) return cb(err); if (ex) return cb(null, file, pkg); load(exts.slice(1), x, pkg); } } } function loadpkg(dir, cb) { if (dir === '' || dir === '/') return cb(null); if (process.platform === 'win32' && windowsDriveRegex.test(dir)) { return cb(null); } if (nodeModulesRegex.test(dir)) return cb(null); maybeRealpath(realpath, dir, opts, function (unwrapErr, pkgdir) { if (unwrapErr) return loadpkg(path.dirname(dir), cb); var pkgfile = path.join(pkgdir, 'package.json'); isFile(pkgfile, function (err, ex) { // on err, ex is false if (!ex) return loadpkg(path.dirname(dir), cb); readPackage(readFile, pkgfile, function (err, pkgParam) { if (err) { return cb(err); } var pkg = pkgParam; if (pkg && opts.packageFilter) { pkg = opts.packageFilter(pkg, pkgfile); } cb(null, pkg, dir); }); }); }); } function loadAsDirectory(x, loadAsDirectoryPackage, callback) { var cb = callback; var fpkg = loadAsDirectoryPackage; if (typeof fpkg === 'function') { cb = fpkg; fpkg = opts.package; } maybeRealpath(realpath, x, opts, function (unwrapErr, pkgdir) { if (unwrapErr) return cb(unwrapErr); var pkgfile = path.join(pkgdir, 'package.json'); isFile(pkgfile, function (err, ex) { if (err) return cb(err); if (!ex) return loadAsFile(path.join(x, 'index'), fpkg, cb); readPackage(readFile, pkgfile, function (err, pkgParam) { if (err) return cb(err); var pkg = pkgParam; if (pkg && opts.packageFilter) { pkg = opts.packageFilter(pkg, pkgfile); } if (pkg && pkg.main) { if (typeof pkg.main !== 'string') { var mainError = new $TypeError('package “' + pkg.name + '” `main` must be a string'); mainError.code = 'INVALID_PACKAGE_MAIN'; return cb(mainError); } if (pkg.main === '.' || pkg.main === './') { pkg.main = 'index'; } loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) { if (err) return cb(err); if (m) return cb(null, m, pkg); if (!pkg) return loadAsFile(path.join(x, 'index'), pkg, cb); var dir = path.resolve(x, pkg.main); loadAsDirectory(dir, pkg, function (err, n, pkg) { if (err) return cb(err); if (n) return cb(null, n, pkg); loadAsFile(path.join(x, 'index'), pkg, cb); }); }); return; } loadAsFile(path.join(x, '/index'), pkg, cb); }); }); }); } function processDirs(cb, dirs) { if (dirs.length === 0) return cb(null, undefined); var dir = dirs[0]; isDirectory(path.dirname(dir), isdir); function isdir(err, isdir) { if (err) return cb(err); if (!isdir) return processDirs(cb, dirs.slice(1)); loadAsFile(dir, opts.package, onfile); } function onfile(err, m, pkg) { if (err) return cb(err); if (m) return cb(null, m, pkg); loadAsDirectory(dir, opts.package, ondir); } function ondir(err, n, pkg) { if (err) return cb(err); if (n) return cb(null, n, pkg); processDirs(cb, dirs.slice(1)); } } function loadNodeModules(x, start, cb) { var thunk = function () { return getPackageCandidates(x, start, opts); }; processDirs( cb, packageIterator ? packageIterator(x, start, thunk, opts) : thunk() ); } }; browserify-resolve-7877a0d/lib/caller.js000066400000000000000000000006311516631042000202710ustar00rootroot00000000000000'use strict'; var $Error = require('es-errors'); module.exports = function () { // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi var origPrepareStackTrace = $Error.prepareStackTrace; $Error.prepareStackTrace = function (_, stack) { return stack; }; var stack = (new $Error()).stack; $Error.prepareStackTrace = origPrepareStackTrace; return stack[2].getFileName(); }; browserify-resolve-7877a0d/lib/core.js000066400000000000000000000004651516631042000177640ustar00rootroot00000000000000'use strict'; var isCoreModule = require('is-core-module'); var data = require('./core.json'); var core = {}; for (var mod in data) { // eslint-disable-line no-restricted-syntax if (Object.prototype.hasOwnProperty.call(data, mod)) { core[mod] = isCoreModule(mod); } } module.exports = core; browserify-resolve-7877a0d/lib/core.json000066400000000000000000000135011516631042000203140ustar00rootroot00000000000000{ "assert": true, "node:assert": [">= 14.18 && < 15", ">= 16"], "assert/strict": ">= 15", "node:assert/strict": ">= 16", "async_hooks": ">= 8", "node:async_hooks": [">= 14.18 && < 15", ">= 16"], "buffer_ieee754": ">= 0.5 && < 0.9.7", "buffer": true, "node:buffer": [">= 14.18 && < 15", ">= 16"], "child_process": true, "node:child_process": [">= 14.18 && < 15", ">= 16"], "cluster": ">= 0.5", "node:cluster": [">= 14.18 && < 15", ">= 16"], "console": true, "node:console": [">= 14.18 && < 15", ">= 16"], "constants": true, "node:constants": [">= 14.18 && < 15", ">= 16"], "crypto": true, "node:crypto": [">= 14.18 && < 15", ">= 16"], "_debug_agent": ">= 1 && < 8", "_debugger": "< 8", "dgram": true, "node:dgram": [">= 14.18 && < 15", ">= 16"], "diagnostics_channel": [">= 14.17 && < 15", ">= 15.1"], "node:diagnostics_channel": [">= 14.18 && < 15", ">= 16"], "dns": true, "node:dns": [">= 14.18 && < 15", ">= 16"], "dns/promises": ">= 15", "node:dns/promises": ">= 16", "domain": ">= 0.7.12", "node:domain": [">= 14.18 && < 15", ">= 16"], "events": true, "node:events": [">= 14.18 && < 15", ">= 16"], "freelist": "< 6", "fs": true, "node:fs": [">= 14.18 && < 15", ">= 16"], "fs/promises": [">= 10 && < 10.1", ">= 14"], "node:fs/promises": [">= 14.18 && < 15", ">= 16"], "_http_agent": ">= 0.11.1", "node:_http_agent": [">= 14.18 && < 15", ">= 16"], "_http_client": ">= 0.11.1", "node:_http_client": [">= 14.18 && < 15", ">= 16"], "_http_common": ">= 0.11.1", "node:_http_common": [">= 14.18 && < 15", ">= 16"], "_http_incoming": ">= 0.11.1", "node:_http_incoming": [">= 14.18 && < 15", ">= 16"], "_http_outgoing": ">= 0.11.1", "node:_http_outgoing": [">= 14.18 && < 15", ">= 16"], "_http_server": ">= 0.11.1", "node:_http_server": [">= 14.18 && < 15", ">= 16"], "http": true, "node:http": [">= 14.18 && < 15", ">= 16"], "http2": ">= 8.8", "node:http2": [">= 14.18 && < 15", ">= 16"], "https": true, "node:https": [">= 14.18 && < 15", ">= 16"], "inspector": ">= 8", "node:inspector": [">= 14.18 && < 15", ">= 16"], "inspector/promises": [">= 19"], "node:inspector/promises": [">= 19"], "_linklist": "< 8", "module": true, "node:module": [">= 14.18 && < 15", ">= 16"], "net": true, "node:net": [">= 14.18 && < 15", ">= 16"], "node-inspect/lib/_inspect": ">= 7.6 && < 12", "node-inspect/lib/internal/inspect_client": ">= 7.6 && < 12", "node-inspect/lib/internal/inspect_repl": ">= 7.6 && < 12", "os": true, "node:os": [">= 14.18 && < 15", ">= 16"], "path": true, "node:path": [">= 14.18 && < 15", ">= 16"], "path/posix": ">= 15.3", "node:path/posix": ">= 16", "path/win32": ">= 15.3", "node:path/win32": ">= 16", "perf_hooks": ">= 8.5", "node:perf_hooks": [">= 14.18 && < 15", ">= 16"], "process": ">= 1", "node:process": [">= 14.18 && < 15", ">= 16"], "punycode": ">= 0.5", "node:punycode": [">= 14.18 && < 15", ">= 16"], "querystring": true, "node:querystring": [">= 14.18 && < 15", ">= 16"], "readline": true, "node:readline": [">= 14.18 && < 15", ">= 16"], "readline/promises": ">= 17", "node:readline/promises": ">= 17", "repl": true, "node:repl": [">= 14.18 && < 15", ">= 16"], "node:sea": [">= 20.12 && < 21", ">= 21.7"], "smalloc": ">= 0.11.5 && < 3", "node:sqlite": [">= 22.13 && < 23", ">= 23.4"], "_stream_duplex": ">= 0.9.4", "node:_stream_duplex": [">= 14.18 && < 15", ">= 16"], "_stream_transform": ">= 0.9.4", "node:_stream_transform": [">= 14.18 && < 15", ">= 16"], "_stream_wrap": ">= 1.4.1", "node:_stream_wrap": [">= 14.18 && < 15", ">= 16"], "_stream_passthrough": ">= 0.9.4", "node:_stream_passthrough": [">= 14.18 && < 15", ">= 16"], "_stream_readable": ">= 0.9.4", "node:_stream_readable": [">= 14.18 && < 15", ">= 16"], "_stream_writable": ">= 0.9.4", "node:_stream_writable": [">= 14.18 && < 15", ">= 16"], "stream": true, "node:stream": [">= 14.18 && < 15", ">= 16"], "stream/consumers": ">= 16.7", "node:stream/consumers": ">= 16.7", "stream/promises": ">= 15", "node:stream/promises": ">= 16", "stream/web": ">= 16.5", "node:stream/web": ">= 16.5", "string_decoder": true, "node:string_decoder": [">= 14.18 && < 15", ">= 16"], "sys": [">= 0.4 && < 0.7", ">= 0.8"], "node:sys": [">= 14.18 && < 15", ">= 16"], "test/reporters": ">= 19.9 && < 20.2", "node:test/reporters": [">= 18.17 && < 19", ">= 19.9", ">= 20"], "test/mock_loader": ">= 22.3 && < 22.7", "node:test/mock_loader": ">= 22.3 && < 22.7", "node:test": [">= 16.17 && < 17", ">= 18"], "timers": true, "node:timers": [">= 14.18 && < 15", ">= 16"], "timers/promises": ">= 15", "node:timers/promises": ">= 16", "_tls_common": ">= 0.11.13", "node:_tls_common": [">= 14.18 && < 15", ">= 16"], "_tls_legacy": ">= 0.11.3 && < 10", "_tls_wrap": ">= 0.11.3", "node:_tls_wrap": [">= 14.18 && < 15", ">= 16"], "tls": true, "node:tls": [">= 14.18 && < 15", ">= 16"], "trace_events": ">= 10", "node:trace_events": [">= 14.18 && < 15", ">= 16"], "tty": true, "node:tty": [">= 14.18 && < 15", ">= 16"], "url": true, "node:url": [">= 14.18 && < 15", ">= 16"], "util": true, "node:util": [">= 14.18 && < 15", ">= 16"], "util/types": ">= 15.3", "node:util/types": ">= 16", "v8/tools/arguments": ">= 10 && < 12", "v8/tools/codemap": [">= 4.4 && < 5", ">= 5.2 && < 12"], "v8/tools/consarray": [">= 4.4 && < 5", ">= 5.2 && < 12"], "v8/tools/csvparser": [">= 4.4 && < 5", ">= 5.2 && < 12"], "v8/tools/logreader": [">= 4.4 && < 5", ">= 5.2 && < 12"], "v8/tools/profile_view": [">= 4.4 && < 5", ">= 5.2 && < 12"], "v8/tools/splaytree": [">= 4.4 && < 5", ">= 5.2 && < 12"], "v8": ">= 1", "node:v8": [">= 14.18 && < 15", ">= 16"], "vm": true, "node:vm": [">= 14.18 && < 15", ">= 16"], "wasi": [">= 13.4 && < 13.5", ">= 18.17 && < 19", ">= 20"], "node:wasi": [">= 18.17 && < 19", ">= 20"], "worker_threads": ">= 11.7", "node:worker_threads": [">= 14.18 && < 15", ">= 16"], "zlib": ">= 0.5", "node:zlib": [">= 14.18 && < 15", ">= 16"] } browserify-resolve-7877a0d/lib/homedir.js000066400000000000000000000016741516631042000204660ustar00rootroot00000000000000'use strict'; var os = require('os'); // adapted from https://github.com/sindresorhus/os-homedir/blob/11e089f4754db38bb535e5a8416320c4446e8cfd/index.js module.exports = os.homedir || function homedir() { var home = process.env.HOME; var user = process.env.LOGNAME || process.env.USER || process.env.LNAME || process.env.USERNAME; if (process.platform === 'win32') { return process.env.USERPROFILE || ( process.env.HOMEDRIVE && process.env.HOMEPATH && (process.env.HOMEDRIVE + process.env.HOMEPATH) ) || home || null; } if (process.platform === 'darwin') { return home || (user ? '/Users/' + user : null); } if (process.platform === 'linux') { return home || (process.getuid() === 0 ? '/root' : (user ? '/home/' + user : null)); // eslint-disable-line no-extra-parens } return home || null; }; browserify-resolve-7877a0d/lib/is-core.js000066400000000000000000000001641516631042000203710ustar00rootroot00000000000000var isCoreModule = require('is-core-module'); module.exports = function isCore(x) { return isCoreModule(x); }; browserify-resolve-7877a0d/lib/node-modules-paths.js000066400000000000000000000024731516631042000225450ustar00rootroot00000000000000var path = require('path'); var parse = path.parse || require('path-parse'); // eslint-disable-line global-require var driveLetterRegex = /^([A-Za-z]:)/; var uncPathRegex = /^\\\\/; function getNodeModulesDirs(absoluteStart, modules) { var prefix = '/'; if (driveLetterRegex.test(absoluteStart)) { prefix = ''; } else if (uncPathRegex.test(absoluteStart)) { prefix = '\\\\'; } var paths = [absoluteStart]; var parsed = parse(absoluteStart); while (parsed.dir !== paths[paths.length - 1]) { paths.push(parsed.dir); parsed = parse(parsed.dir); } return paths.reduce(function (dirs, aPath) { return dirs.concat(modules.map(function (moduleDir) { return path.resolve(prefix, aPath, moduleDir); })); }, []); } module.exports = function nodeModulesPaths(start, opts, request) { var modules = opts && opts.moduleDirectory ? [].concat(opts.moduleDirectory) : ['node_modules']; if (opts && typeof opts.paths === 'function') { return opts.paths( request, start, function () { return getNodeModulesDirs(start, modules); }, opts ); } var dirs = getNodeModulesDirs(start, modules); return opts && opts.paths ? dirs.concat(opts.paths) : dirs; }; browserify-resolve-7877a0d/lib/normalize-options.js000066400000000000000000000005341516631042000225220ustar00rootroot00000000000000module.exports = function (x, opts) { /** * This file is purposefully a passthrough. It's expected that third-party * environments will override it at runtime in order to inject special logic * into `resolve` (by manipulating the options). One such example is the PnP * code path in Yarn. */ return opts || {}; }; browserify-resolve-7877a0d/lib/sync.js000066400000000000000000000160011516631042000200010ustar00rootroot00000000000000var isCore = require('is-core-module'); var fs = require('fs'); var path = require('path'); var $Error = require('es-errors'); var $TypeError = require('es-errors/type'); var getHomedir = require('./homedir'); var caller = require('./caller'); var nodeModulesPaths = require('./node-modules-paths'); var normalizeOptions = require('./normalize-options'); var realpathFS = process.platform !== 'win32' && fs.realpathSync && typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync; var relativePathRegex = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/; var windowsDriveRegex = /^\w:[/\\]*$/; var nodeModulesRegex = /[/\\]node_modules[/\\]*$/; var homedir = getHomedir(); function defaultPaths() { if (!homedir) return []; return [ path.join(homedir, '.node_modules'), path.join(homedir, '.node_libraries') ]; } var defaultIsFile = function isFile(file) { try { var stat = fs.statSync(file, { throwIfNoEntry: false }); } catch (e) { if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; throw e; } return !!stat && (stat.isFile() || stat.isFIFO()); }; var defaultIsDir = function isDirectory(dir) { try { var stat = fs.statSync(dir, { throwIfNoEntry: false }); } catch (e) { if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; throw e; } return !!stat && stat.isDirectory(); }; var defaultRealpathSync = function realpathSync(x) { try { return realpathFS(x); } catch (realpathErr) { if (realpathErr.code !== 'ENOENT') { throw realpathErr; } } return x; }; function maybeRealpathSync(realpathSync, x, opts) { if (opts && opts.preserveSymlinks === false) { return realpathSync(x); } return x; } function defaultReadPackageSync(readFileSync, pkgfile) { var body = readFileSync(pkgfile); try { var pkg = JSON.parse(body); return pkg; } catch (jsonErr) {} } function getPackageCandidates(x, start, opts) { var dirs = nodeModulesPaths(start, opts, x); for (var i = 0; i < dirs.length; i++) { dirs[i] = path.join(dirs[i], x); } return dirs; } module.exports = function resolveSync(x, options) { if (typeof x !== 'string') { throw new $TypeError('Path must be a string.'); } var opts = normalizeOptions(x, options); var isFile = opts.isFile || defaultIsFile; var readFileSync = opts.readFileSync || fs.readFileSync; var isDirectory = opts.isDirectory || defaultIsDir; var realpathSync = opts.realpathSync || defaultRealpathSync; var readPackageSync = opts.readPackageSync || defaultReadPackageSync; if (opts.readFileSync && opts.readPackageSync) { throw new $TypeError('`readFileSync` and `readPackageSync` are mutually exclusive.'); } var packageIterator = opts.packageIterator; var extensions = opts.extensions || ['.js']; var includeCoreModules = opts.includeCoreModules !== false; var basedir = opts.basedir || path.dirname(caller()); var parent = opts.filename || basedir; opts.paths = opts.paths || defaultPaths(); // ensure that `basedir` is an absolute path at this point, resolving against the process' current working directory var absoluteStart = maybeRealpathSync(realpathSync, path.resolve(basedir), opts); if (relativePathRegex.test(x)) { var res = path.resolve(absoluteStart, x); if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/'; var m = loadAsFileSync(res) || loadAsDirectorySync(res); if (m) return maybeRealpathSync(realpathSync, m, opts); } else if (includeCoreModules && isCore(x)) { return x; } else { var n = loadNodeModulesSync(x, absoluteStart); if (n) return maybeRealpathSync(realpathSync, n, opts); } var err = new $Error("Cannot find module '" + x + "' from '" + parent + "'"); err.code = 'MODULE_NOT_FOUND'; throw err; function loadAsFileSync(x) { var pkg = loadpkg(path.dirname(x)); if (pkg && pkg.dir && pkg.pkg && opts.pathFilter) { var rfile = path.relative(pkg.dir, x); var r = opts.pathFilter(pkg.pkg, x, rfile); if (r) { x = path.resolve(pkg.dir, r); // eslint-disable-line no-param-reassign } } if (isFile(x)) { return x; } for (var i = 0; i < extensions.length; i++) { var file = x + extensions[i]; if (isFile(file)) { return file; } } } function loadpkg(dir) { if (dir === '' || dir === '/') return; if (process.platform === 'win32' && windowsDriveRegex.test(dir)) { return; } if (nodeModulesRegex.test(dir)) return; var pkgfile = path.join(maybeRealpathSync(realpathSync, dir, opts), 'package.json'); if (!isFile(pkgfile)) { return loadpkg(path.dirname(dir)); } var pkg = readPackageSync(readFileSync, pkgfile); if (pkg && opts.packageFilter) { // v2 will pass pkgfile pkg = opts.packageFilter(pkg, /*pkgfile,*/ dir); // eslint-disable-line spaced-comment } return { pkg: pkg, dir: dir }; } function loadAsDirectorySync(x) { var pkgfile = path.join(maybeRealpathSync(realpathSync, x, opts), '/package.json'); if (isFile(pkgfile)) { try { var pkg = readPackageSync(readFileSync, pkgfile); } catch (e) {} if (pkg && opts.packageFilter) { // v2 will pass pkgfile pkg = opts.packageFilter(pkg, /*pkgfile,*/ x); // eslint-disable-line spaced-comment } if (pkg && pkg.main) { if (typeof pkg.main !== 'string') { var mainError = new $TypeError('package “' + pkg.name + '” `main` must be a string'); mainError.code = 'INVALID_PACKAGE_MAIN'; throw mainError; } if (pkg.main === '.' || pkg.main === './') { pkg.main = 'index'; } try { var m = loadAsFileSync(path.resolve(x, pkg.main)); if (m) return m; var n = loadAsDirectorySync(path.resolve(x, pkg.main)); if (n) return n; } catch (e) {} } } return loadAsFileSync(path.join(x, '/index')); } function loadNodeModulesSync(x, start) { var thunk = function () { return getPackageCandidates(x, start, opts); }; var dirs = packageIterator ? packageIterator(x, start, thunk, opts) : thunk(); for (var i = 0; i < dirs.length; i++) { var dir = dirs[i]; if (isDirectory(path.dirname(dir))) { var m = loadAsFileSync(dir); if (m) return m; var n = loadAsDirectorySync(dir); if (n) return n; } } } }; browserify-resolve-7877a0d/package.json000066400000000000000000000041051516631042000202110ustar00rootroot00000000000000{ "name": "resolve", "description": "resolve like require.resolve() on behalf of files asynchronously and synchronously", "version": "1.22.12", "repository": { "type": "git", "url": "ssh://github.com/browserify/resolve.git" }, "bin": { "resolve": "./bin/resolve" }, "main": "index.js", "keywords": [ "resolve", "require", "node", "module" ], "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated && cp node_modules/is-core-module/core.json ./lib/ ||:", "prepublishOnly": "safe-publish-latest", "prepublish": "not-in-publish || npm run prepublishOnly", "prelint": "eclint check $(git ls-files | grep -Ev test\\/list-exports$ | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')", "lint": "eslint .", "pretests-only": "cd ./test/resolver/nested_symlinks && node mylib/sync && node mylib/async", "tests-only": "tape test/*.js", "pretest": "npm run lint", "test": "npm run --silent tests-only", "posttest": "npm run test:multirepo && npx npm@'>= 10.2' audit --production", "test:multirepo": "cd ./test/resolver/multirepo && npm install && npm test" }, "devDependencies": { "@ljharb/eslint-config": "^22.2.2", "array.prototype.map": "^1.0.8", "copy-dir": "^1.3.0", "eclint": "^2.8.1", "eslint": "^9.39.1", "in-publish": "^2.0.1", "jiti": "^0.0.0", "mkdirp": "^0.5.6", "mv": "^2.1.1", "npmignore": "^0.3.5", "object-keys": "^1.1.1", "rimraf": "^2.7.1", "safe-publish-latest": "^2.0.0", "semver": "^6.3.1", "tap": "^0.4.13", "tape": "^5.9.0", "tmp": "^0.0.31" }, "license": "MIT", "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "funding": { "url": "https://github.com/sponsors/ljharb" }, "dependencies": { "es-errors": "^1.3.0", "is-core-module": "^2.16.1", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, "publishConfig": { "ignore": [ ".github/workflows", "appveyor.yml", "CONTRIBUTING.md", "test/resolver/malformed_package_json", "test/list-exports" ] }, "engines": { "node": ">= 0.4" } } browserify-resolve-7877a0d/readme.markdown000066400000000000000000000264401516631042000207320ustar00rootroot00000000000000# resolve [![Version Badge][2]][1] implements the [node `require.resolve()` algorithm](https://nodejs.org/api/modules.html#modules_all_together) such that you can `require.resolve()` on behalf of a file asynchronously and synchronously [![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/10759/badge)](https://bestpractices.coreinfrastructure.org/projects/10759) [![npm badge][11]][1] # example asynchronously resolve: ```js var resolve = require('resolve/async'); // or, require('resolve') resolve('tap', { basedir: __dirname }, function (err, res) { if (err) console.error(err); else console.log(res); }); ``` ``` $ node example/async.js /home/substack/projects/node-resolve/node_modules/tap/lib/main.js ``` synchronously resolve: ```js var resolve = require('resolve/sync'); // or, `require('resolve').sync var res = resolve('tap', { basedir: __dirname }); console.log(res); ``` ``` $ node example/sync.js /home/substack/projects/node-resolve/node_modules/tap/lib/main.js ``` # methods ```js var resolve = require('resolve'); var async = require('resolve/async'); var sync = require('resolve/sync'); ``` For both the synchronous and asynchronous methods, errors may have any of the following `err.code` values: - `MODULE_NOT_FOUND`: the given path string (`id`) could not be resolved to a module - `INVALID_BASEDIR`: the specified `opts.basedir` doesn't exist, or is not a directory - `INVALID_PACKAGE_MAIN`: a `package.json` was encountered with an invalid `main` property (eg. not a string) ## resolve(id, opts={}, cb) Asynchronously resolve the module path string `id` into `cb(err, res [, pkg])`, where `pkg` (if defined) is the data from `package.json`. options are: * opts.basedir - directory to begin resolving from * opts.package - `package.json` data applicable to the module being loaded * opts.extensions - array of file extensions to search in order * opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search * opts.readFile - how to read files asynchronously * opts.isFile - function to asynchronously test whether a file exists * opts.isDirectory - function to asynchronously test whether a file exists and is a directory * opts.realpath - function to asynchronously resolve a potential symlink to its real path * `opts.readPackage(readFile, pkgfile, cb)` - function to asynchronously read and parse a package.json file * readFile - the passed `opts.readFile` or `fs.readFile` if not specified * pkgfile - path to package.json * cb - callback * `opts.packageFilter(pkg, pkgfile, dir)` - transform the parsed package.json contents before looking at the "main" field * pkg - package data * pkgfile - path to package.json * dir - directory that contains package.json * `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package * pkg - package data * path - the path being resolved * relativePath - the path relative from the package.json location * returns - a relative path that will be joined from the package.json location * opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this) For advanced users, `paths` can also be a `opts.paths(request, start, opts)` function * request - the import specifier being resolved * start - lookup path * getNodeModulesDirs - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution * opts - the resolution options * `opts.packageIterator(request, start, opts)` - return the list of candidate paths where the packages sources may be found (probably don't use this) * request - the import specifier being resolved * start - lookup path * getPackageCandidates - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution * opts - the resolution options * opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"` * opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving. This is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag. **Note:** this property is currently `true` by default but it will be changed to `false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*. default `opts` values: ```js { paths: [], basedir: __dirname, extensions: ['.js'], includeCoreModules: true, readFile: fs.readFile, isFile: function isFile(file, cb) { fs.stat(file, function (err, stat) { if (!err) { return cb(null, stat.isFile() || stat.isFIFO()); } if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); return cb(err); }); }, isDirectory: function isDirectory(dir, cb) { fs.stat(dir, function (err, stat) { if (!err) { return cb(null, stat.isDirectory()); } if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); return cb(err); }); }, realpath: function realpath(file, cb) { var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath; realpath(file, function (realPathErr, realPath) { if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr); else cb(null, realPathErr ? file : realPath); }); }, readPackage: function defaultReadPackage(readFile, pkgfile, cb) { readFile(pkgfile, function (readFileErr, body) { if (readFileErr) cb(readFileErr); else { try { var pkg = JSON.parse(body); cb(null, pkg); } catch (jsonErr) { cb(null); } } }); }, moduleDirectory: 'node_modules', preserveSymlinks: true } ``` ## resolve.sync(id, opts) Synchronously resolve the module path string `id`, returning the result and throwing an error when `id` can't be resolved. options are: * opts.basedir - directory to begin resolving from * opts.extensions - array of file extensions to search in order * opts.includeCoreModules - set to `false` to exclude node core modules (e.g. `fs`) from the search * opts.readFileSync - how to read files synchronously * opts.isFile - function to synchronously test whether a file exists * opts.isDirectory - function to synchronously test whether a file exists and is a directory * opts.realpathSync - function to synchronously resolve a potential symlink to its real path * `opts.readPackageSync(readFileSync, pkgfile)` - function to synchronously read and parse a package.json file * readFileSync - the passed `opts.readFileSync` or `fs.readFileSync` if not specified * pkgfile - path to package.json * `opts.packageFilter(pkg, dir)` - transform the parsed package.json contents before looking at the "main" field * pkg - package data * dir - directory that contains package.json (Note: the second argument will change to "pkgfile" in v2) * `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package * pkg - package data * path - the path being resolved * relativePath - the path relative from the package.json location * returns - a relative path that will be joined from the package.json location * opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this) For advanced users, `paths` can also be a `opts.paths(request, start, opts)` function * request - the import specifier being resolved * start - lookup path * getNodeModulesDirs - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution * opts - the resolution options * `opts.packageIterator(request, start, opts)` - return the list of candidate paths where the packages sources may be found (probably don't use this) * request - the import specifier being resolved * start - lookup path * getPackageCandidates - a thunk (no-argument function) that returns the paths using standard `node_modules` resolution * opts - the resolution options * opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"` * opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving. This is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag. **Note:** this property is currently `true` by default but it will be changed to `false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*. default `opts` values: ```js { paths: [], basedir: __dirname, extensions: ['.js'], includeCoreModules: true, readFileSync: fs.readFileSync, isFile: function isFile(file) { try { var stat = fs.statSync(file); } catch (e) { if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; throw e; } return stat.isFile() || stat.isFIFO(); }, isDirectory: function isDirectory(dir) { try { var stat = fs.statSync(dir); } catch (e) { if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; throw e; } return stat.isDirectory(); }, realpathSync: function realpathSync(file) { try { var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync; return realpath(file); } catch (realPathErr) { if (realPathErr.code !== 'ENOENT') { throw realPathErr; } } return file; }, readPackageSync: function defaultReadPackageSync(readFileSync, pkgfile) { var body = readFileSync(pkgfile); try { var pkg = JSON.parse(body); return pkg; } catch (jsonErr) {} }, moduleDirectory: 'node_modules', preserveSymlinks: true } ``` # install With [npm](https://npmjs.org) do: ```sh npm install resolve ``` # license MIT [1]: https://npmjs.org/package/resolve [2]: https://versionbadg.es/browserify/resolve.svg [5]: https://david-dm.org/browserify/resolve.svg [6]: https://david-dm.org/browserify/resolve [7]: https://david-dm.org/browserify/resolve/dev-status.svg [8]: https://david-dm.org/browserify/resolve#info=devDependencies [11]: https://nodei.co/npm/resolve.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/resolve.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/resolve.svg [downloads-url]: https://npm-stat.com/charts.html?package=resolve [codecov-image]: https://codecov.io/gh/browserify/resolve/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/browserify/resolve/ [actions-image]: https://img.shields.io/github/check-runs/browserify/resolve/main [actions-url]: https://github.com/browserify/resolve/actions browserify-resolve-7877a0d/sync.js000066400000000000000000000000671516631042000172400ustar00rootroot00000000000000'use strict'; module.exports = require('./lib/sync'); browserify-resolve-7877a0d/test/000077500000000000000000000000001516631042000167025ustar00rootroot00000000000000browserify-resolve-7877a0d/test/core.js000066400000000000000000000057621516631042000202020ustar00rootroot00000000000000var test = require('tape'); var keys = require('object-keys'); var semver = require('semver'); var resolve = require('../'); var brokenNode = semver.satisfies(process.version, '11.11 - 11.13'); test('core modules', function (t) { t.test('isCore()', function (st) { st.ok(resolve.isCore('fs')); st.ok(resolve.isCore('net')); st.ok(resolve.isCore('http')); st.ok(!resolve.isCore('seq')); st.ok(!resolve.isCore('../')); st.ok(!resolve.isCore('toString')); st.end(); }); t.test('core list', function (st) { var cores = keys(resolve.core); st.plan(cores.length); for (var i = 0; i < cores.length; ++i) { var mod = cores[i]; // note: this must be require, not require.resolve, due to https://github.com/nodejs/node/issues/43274 var requireFunc = function () { require(mod); }; // eslint-disable-line no-loop-func t.comment(mod + ': ' + resolve.core[mod]); if (resolve.core[mod]) { st.doesNotThrow(requireFunc, mod + ' supported; requiring does not throw'); } else if (brokenNode) { st.ok(true, 'this version of node is broken: attempting to require things that fail to resolve breaks "home_paths" tests'); } else { st.throws(requireFunc, mod + ' not supported; requiring throws'); } } st.end(); }); t.test('core via repl module', { skip: !resolve.core.repl }, function (st) { var libs = require('repl')._builtinLibs; // eslint-disable-line no-underscore-dangle if (!libs) { st.skip('module.builtinModules does not exist'); return st.end(); } for (var i = 0; i < libs.length; ++i) { var mod = libs[i]; st.ok(resolve.core[mod], mod + ' is a core module'); st.doesNotThrow( function () { require(mod); }, // eslint-disable-line no-loop-func 'requiring ' + mod + ' does not throw' ); } st.end(); }); t.test('core via builtinModules list', { skip: !resolve.core.module }, function (st) { var libs = require('module').builtinModules; if (!libs) { st.skip('module.builtinModules does not exist'); return st.end(); } var blacklist = [ '_debug_agent', 'v8/tools/tickprocessor-driver', 'v8/tools/SourceMap', 'v8/tools/tickprocessor', 'v8/tools/profile' ]; for (var i = 0; i < libs.length; ++i) { var mod = libs[i]; if (blacklist.indexOf(mod) === -1) { st.ok(resolve.core[mod], mod + ' is a core module'); st.doesNotThrow( function () { require(mod); }, // eslint-disable-line no-loop-func 'requiring ' + mod + ' does not throw' ); } } st.end(); }); t.end(); }); browserify-resolve-7877a0d/test/default_paths.js000066400000000000000000000031221516631042000220610ustar00rootroot00000000000000'use strict'; var path = require('path'); var test = require('tape'); var mockProperty = require('mock-property'); var homedirPath = require.resolve('../lib/homedir'); var asyncPath = require.resolve('../async'); var libAsyncPath = require.resolve('../lib/async'); var syncPath = require.resolve('../sync'); var libSyncPath = require.resolve('../lib/sync'); function mockNullHomedir(t) { t.teardown(mockProperty(require.cache, homedirPath, { value: { id: homedirPath, filename: homedirPath, loaded: true, exports: function () { return null; } } })); } test('async: null homedir does not throw', function (t) { t.plan(2); mockNullHomedir(t); t.teardown(mockProperty(require.cache, asyncPath, { 'delete': true })); t.teardown(mockProperty(require.cache, libAsyncPath, { 'delete': true })); var resolve = require('../lib/async'); var dir = path.join(__dirname, 'resolver'); resolve('./baz', { basedir: dir }, function (err, res) { t.error(err, 'no error'); t.equal(res, path.join(dir, 'baz', 'quux.js'), 'resolves correctly with null homedir'); }); }); test('sync: null homedir does not throw', function (t) { mockNullHomedir(t); t.teardown(mockProperty(require.cache, syncPath, { 'delete': true })); t.teardown(mockProperty(require.cache, libSyncPath, { 'delete': true })); var resolveSync = require('../lib/sync'); var dir = path.join(__dirname, 'resolver'); var res = resolveSync('./baz', { basedir: dir }); t.equal(res, path.join(dir, 'baz', 'quux.js'), 'resolves correctly with null homedir'); t.end(); }); browserify-resolve-7877a0d/test/dotdot.js000066400000000000000000000014371516631042000205420ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('dotdot', function (t) { t.plan(4); var dir = path.join(__dirname, '/dotdot/abc'); resolve('..', { basedir: dir }, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(__dirname, 'dotdot/index.js')); }); resolve('.', { basedir: dir }, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, 'index.js')); }); }); test('dotdot sync', function (t) { t.plan(2); var dir = path.join(__dirname, '/dotdot/abc'); var a = resolve.sync('..', { basedir: dir }); t.equal(a, path.join(__dirname, 'dotdot/index.js')); var b = resolve.sync('.', { basedir: dir }); t.equal(b, path.join(dir, 'index.js')); }); browserify-resolve-7877a0d/test/dotdot/000077500000000000000000000000001516631042000201775ustar00rootroot00000000000000browserify-resolve-7877a0d/test/dotdot/abc/000077500000000000000000000000001516631042000207245ustar00rootroot00000000000000browserify-resolve-7877a0d/test/dotdot/abc/index.js000066400000000000000000000000471516631042000223720ustar00rootroot00000000000000var x = require('..'); console.log(x); browserify-resolve-7877a0d/test/dotdot/index.js000066400000000000000000000000351516631042000216420ustar00rootroot00000000000000module.exports = 'whatever'; browserify-resolve-7877a0d/test/faulty_basedir.js000066400000000000000000000014471516631042000222430ustar00rootroot00000000000000var test = require('tape'); var path = require('path'); var resolve = require('../'); test('faulty basedir must produce error in windows', { skip: process.platform !== 'win32' }, function (t) { t.plan(1); var resolverDir = 'C:\\a\\b\\c\\d'; resolve('tape/lib/test.js', { basedir: resolverDir }, function (err, res, pkg) { t.equal(!!err, true); }); }); test('non-existent basedir should not throw when preserveSymlinks is false', function (t) { t.plan(2); var opts = { basedir: path.join(path.sep, 'unreal', 'path', 'that', 'does', 'not', 'exist'), preserveSymlinks: false }; var module = './dotdot/abc'; resolve(module, opts, function (err, res) { t.equal(err.code, 'MODULE_NOT_FOUND'); t.equal(res, undefined); }); }); browserify-resolve-7877a0d/test/filter.js000066400000000000000000000020251516631042000205240ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('filter', function (t) { t.plan(4); var dir = path.join(__dirname, 'resolver'); var packageFilterArgs; resolve('./baz', { basedir: dir, packageFilter: function (pkg, pkgfile) { pkg.main = 'doom'; // eslint-disable-line no-param-reassign packageFilterArgs = [pkg, pkgfile]; return pkg; } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works'); var packageData = packageFilterArgs[0]; t.equal(pkg, packageData, 'first packageFilter argument is "pkg"'); t.equal(packageData.main, 'doom', 'package "main" was altered'); var packageFile = packageFilterArgs[1]; t.equal( packageFile, path.join(dir, 'baz/package.json'), 'second packageFilter argument is "pkgfile"' ); t.end(); }); }); browserify-resolve-7877a0d/test/filter_sync.js000066400000000000000000000026231516631042000215640ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('filter', function (t) { var dir = path.join(__dirname, 'resolver'); var packageFilterArgs; var res = resolve.sync('./baz', { basedir: dir, // NOTE: in v2.x, this will be `pkg, pkgfile, dir`, but must remain "broken" here in v1.x for compatibility packageFilter: function (pkg, /*pkgfile,*/ dir) { // eslint-disable-line spaced-comment pkg.main = 'doom'; // eslint-disable-line no-param-reassign packageFilterArgs = 'is 1.x' ? [pkg, dir] : [pkg, pkgfile, dir]; // eslint-disable-line no-constant-condition, no-undef return pkg; } }); t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works'); var packageData = packageFilterArgs[0]; t.equal(packageData.main, 'doom', 'package "main" was altered'); if (!'is 1.x') { // eslint-disable-line no-constant-condition var packageFile = packageFilterArgs[1]; t.equal(packageFile, path.join(dir, 'baz', 'package.json'), 'package.json path is correct'); } var packageDir = packageFilterArgs['is 1.x' ? 1 : 2]; // eslint-disable-line no-constant-condition // eslint-disable-next-line no-constant-condition t.equal(packageDir, path.join(dir, 'baz'), ('is 1.x' ? 'second' : 'third') + ' packageFilter argument is "dir"'); t.end(); }); browserify-resolve-7877a0d/test/home_paths.js000066400000000000000000000105701516631042000213720ustar00rootroot00000000000000'use strict'; var fs = require('fs'); var homedir = require('../lib/homedir'); var path = require('path'); var test = require('tape'); var mkdirp = require('mkdirp'); var rimraf = require('rimraf'); var mv = require('mv'); var copyDir = require('copy-dir'); var tmp = require('tmp'); var HOME = homedir(); var hnm = path.join(HOME, '.node_modules'); var hnl = path.join(HOME, '.node_libraries'); var resolve = require('../async'); function makeDir(t, dir, cb) { mkdirp(dir, function (err) { if (err) { cb(err); } else { t.teardown(function cleanup() { rimraf.sync(dir); }); cb(); } }); } function makeTempDir(t, dir, cb) { if (fs.existsSync(dir)) { var tmpResult = tmp.dirSync(); t.teardown(tmpResult.removeCallback); var backup = path.join(tmpResult.name, path.basename(dir)); mv(dir, backup, function (err) { if (err) { cb(err); } else { t.teardown(function () { mv(backup, dir, cb); }); makeDir(t, dir, cb); } }); } else { makeDir(t, dir, cb); } } test('homedir module paths', function (t) { t.plan(7); makeTempDir(t, hnm, function (err) { t.error(err, 'no error with HNM temp dir'); if (err) { return t.end(); } var bazHNMDir = path.join(hnm, 'baz'); var dotMainDir = path.join(hnm, 'dot_main'); copyDir.sync(path.join(__dirname, 'resolver/baz'), bazHNMDir); copyDir.sync(path.join(__dirname, 'resolver/dot_main'), dotMainDir); var bazPkg = { name: 'baz', main: 'quux.js' }; var dotMainPkg = { main: 'index' }; var bazHNMmain = path.join(bazHNMDir, 'quux.js'); t.equal(require.resolve('baz'), bazHNMmain, 'sanity check: require.resolve finds HNM `baz`'); var dotMainMain = path.join(dotMainDir, 'index.js'); t.equal(require.resolve('dot_main'), dotMainMain, 'sanity check: require.resolve finds `dot_main`'); makeTempDir(t, hnl, function (err) { t.error(err, 'no error with HNL temp dir'); if (err) { return t.end(); } var bazHNLDir = path.join(hnl, 'baz'); copyDir.sync(path.join(__dirname, 'resolver/baz'), bazHNLDir); var dotSlashMainDir = path.join(hnl, 'dot_slash_main'); var dotSlashMainMain = path.join(dotSlashMainDir, 'index.js'); var dotSlashMainPkg = { main: 'index' }; copyDir.sync(path.join(__dirname, 'resolver/dot_slash_main'), dotSlashMainDir); t.equal(require.resolve('baz'), bazHNMmain, 'sanity check: require.resolve finds HNM `baz`'); t.equal(require.resolve('dot_slash_main'), dotSlashMainMain, 'sanity check: require.resolve finds HNL `dot_slash_main`'); t.test('with temp dirs', function (st) { st.plan(3); st.test('just in `$HOME/.node_modules`', function (s2t) { s2t.plan(3); resolve('dot_main', function (err, res, pkg) { s2t.error(err, 'no error resolving `dot_main`'); s2t.equal(res, dotMainMain, '`dot_main` resolves in `$HOME/.node_modules`'); s2t.deepEqual(pkg, dotMainPkg); }); }); st.test('just in `$HOME/.node_libraries`', function (s2t) { s2t.plan(3); resolve('dot_slash_main', function (err, res, pkg) { s2t.error(err, 'no error resolving `dot_slash_main`'); s2t.equal(res, dotSlashMainMain, '`dot_slash_main` resolves in `$HOME/.node_libraries`'); s2t.deepEqual(pkg, dotSlashMainPkg); }); }); st.test('in `$HOME/.node_libraries` and `$HOME/.node_modules`', function (s2t) { s2t.plan(3); resolve('baz', function (err, res, pkg) { s2t.error(err, 'no error resolving `baz`'); s2t.equal(res, bazHNMmain, '`baz` resolves in `$HOME/.node_modules` when in both'); s2t.deepEqual(pkg, bazPkg); }); }); }); }); }); }); browserify-resolve-7877a0d/test/home_paths_sync.js000066400000000000000000000073251516631042000224320ustar00rootroot00000000000000'use strict'; var fs = require('fs'); var homedir = require('../lib/homedir'); var path = require('path'); var test = require('tape'); var mkdirp = require('mkdirp'); var rimraf = require('rimraf'); var mv = require('mv'); var copyDir = require('copy-dir'); var tmp = require('tmp'); var HOME = homedir(); var hnm = path.join(HOME, '.node_modules'); var hnl = path.join(HOME, '.node_libraries'); var resolve = require('../sync'); function makeDir(t, dir, cb) { mkdirp(dir, function (err) { if (err) { cb(err); } else { t.teardown(function cleanup() { rimraf.sync(dir); }); cb(); } }); } function makeTempDir(t, dir, cb) { if (fs.existsSync(dir)) { var tmpResult = tmp.dirSync(); t.teardown(tmpResult.removeCallback); var backup = path.join(tmpResult.name, path.basename(dir)); mv(dir, backup, function (err) { if (err) { cb(err); } else { t.teardown(function () { mv(backup, dir, cb); }); makeDir(t, dir, cb); } }); } else { makeDir(t, dir, cb); } } test('homedir module paths', function (t) { t.plan(7); makeTempDir(t, hnm, function (err) { t.error(err, 'no error with HNM temp dir'); if (err) { return t.end(); } var bazHNMDir = path.join(hnm, 'baz'); var dotMainDir = path.join(hnm, 'dot_main'); copyDir.sync(path.join(__dirname, 'resolver/baz'), bazHNMDir); copyDir.sync(path.join(__dirname, 'resolver/dot_main'), dotMainDir); var bazHNMmain = path.join(bazHNMDir, 'quux.js'); t.equal(require.resolve('baz'), bazHNMmain, 'sanity check: require.resolve finds HNM `baz`'); var dotMainMain = path.join(dotMainDir, 'index.js'); t.equal(require.resolve('dot_main'), dotMainMain, 'sanity check: require.resolve finds `dot_main`'); makeTempDir(t, hnl, function (err) { t.error(err, 'no error with HNL temp dir'); if (err) { return t.end(); } var bazHNLDir = path.join(hnl, 'baz'); copyDir.sync(path.join(__dirname, 'resolver/baz'), bazHNLDir); var dotSlashMainDir = path.join(hnl, 'dot_slash_main'); var dotSlashMainMain = path.join(dotSlashMainDir, 'index.js'); copyDir.sync(path.join(__dirname, 'resolver/dot_slash_main'), dotSlashMainDir); t.equal(require.resolve('baz'), bazHNMmain, 'sanity check: require.resolve finds HNM `baz`'); t.equal(require.resolve('dot_slash_main'), dotSlashMainMain, 'sanity check: require.resolve finds HNL `dot_slash_main`'); t.test('with temp dirs', function (st) { st.plan(3); st.test('just in `$HOME/.node_modules`', function (s2t) { s2t.plan(1); var res = resolve('dot_main'); s2t.equal(res, dotMainMain, '`dot_main` resolves in `$HOME/.node_modules`'); }); st.test('just in `$HOME/.node_libraries`', function (s2t) { s2t.plan(1); var res = resolve('dot_slash_main'); s2t.equal(res, dotSlashMainMain, '`dot_slash_main` resolves in `$HOME/.node_libraries`'); }); st.test('in `$HOME/.node_libraries` and `$HOME/.node_modules`', function (s2t) { s2t.plan(1); var res = resolve('baz'); s2t.equal(res, bazHNMmain, '`baz` resolves in `$HOME/.node_modules` when in both'); }); }); }); }); }); browserify-resolve-7877a0d/test/homedir.js000066400000000000000000000061051516631042000206710ustar00rootroot00000000000000'use strict'; var os = require('os'); var test = require('tape'); var mockProperty = require('mock-property'); var envKeys = ['HOME', 'USERPROFILE', 'HOMEDRIVE', 'HOMEPATH', 'LOGNAME', 'USER', 'LNAME', 'USERNAME']; function mockEnv(t, key, value) { var has = key in process.env; var orig = process.env[key]; if (arguments.length > 2) { process.env[key] = value; } else { delete process.env[key]; } t.teardown(function () { if (has) { process.env[key] = orig; } else { delete process.env[key]; } }); } function clearEnv(t) { for (var i = 0; i < envKeys.length; i++) { mockEnv(t, envKeys[i]); } } function getFallback(t) { t.teardown(mockProperty(os, 'homedir', { value: undefined })); var homedirPath = require.resolve('../lib/homedir'); t.teardown(mockProperty(require.cache, homedirPath, { 'delete': true })); return require('../lib/homedir'); } test('homedir fallback', function (t) { t.test('win32: HOMEDRIVE without HOMEPATH does not produce a false concatenation', function (st) { clearEnv(st); st.teardown(mockProperty(process, 'platform', { value: 'win32' })); var homedir = getFallback(st); mockEnv(st, 'HOMEDRIVE', 'C:'); st.equal(homedir(), null, 'returns null when only HOMEDRIVE is set'); st.end(); }); t.test('win32: HOMEPATH without HOMEDRIVE does not produce a false concatenation', function (st) { clearEnv(st); st.teardown(mockProperty(process, 'platform', { value: 'win32' })); var homedir = getFallback(st); mockEnv(st, 'HOMEPATH', '\\Users\\foo'); st.equal(homedir(), null, 'returns null when only HOMEPATH is set'); st.end(); }); t.test('win32: HOMEDRIVE + HOMEPATH both set returns concatenation', function (st) { clearEnv(st); st.teardown(mockProperty(process, 'platform', { value: 'win32' })); var homedir = getFallback(st); mockEnv(st, 'HOMEDRIVE', 'C:'); mockEnv(st, 'HOMEPATH', '\\Users\\foo'); st.equal(homedir(), 'C:\\Users\\foo', 'returns concatenated drive and path'); st.end(); }); t.test('win32: USERPROFILE takes precedence over HOMEDRIVE+HOMEPATH', function (st) { clearEnv(st); st.teardown(mockProperty(process, 'platform', { value: 'win32' })); var homedir = getFallback(st); mockEnv(st, 'USERPROFILE', 'C:\\Users\\bar'); mockEnv(st, 'HOMEDRIVE', 'C:'); mockEnv(st, 'HOMEPATH', '\\Users\\foo'); st.equal(homedir(), 'C:\\Users\\bar', 'returns USERPROFILE'); st.end(); }); t.test('win32: falls back to HOME when HOMEDRIVE/HOMEPATH are partial', function (st) { clearEnv(st); st.teardown(mockProperty(process, 'platform', { value: 'win32' })); var homedir = getFallback(st); mockEnv(st, 'HOME', 'C:\\Users\\baz'); mockEnv(st, 'HOMEDRIVE', 'C:'); st.equal(homedir(), 'C:\\Users\\baz', 'falls back to HOME'); st.end(); }); t.end(); }); browserify-resolve-7877a0d/test/mock.js000066400000000000000000000257001516631042000201750ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('mock', function (t) { t.plan(8); var files = {}; files[path.resolve('/foo/bar/baz.js')] = 'beep'; var dirs = {}; dirs[path.resolve('/foo/bar')] = true; function opts(basedir) { return { basedir: path.resolve(basedir), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, isDirectory: function (dir, cb) { cb(null, !!dirs[path.resolve(dir)]); }, readFile: function (file, cb) { cb(null, files[path.resolve(file)]); }, realpath: function (file, cb) { cb(null, file); } }; } resolve('./baz', opts('/foo/bar'), function (err, res, pkg) { if (err) return t.fail(err); t.equal(res, path.resolve('/foo/bar/baz.js')); t.equal(pkg, undefined); }); resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) { if (err) return t.fail(err); t.equal(res, path.resolve('/foo/bar/baz.js')); t.equal(pkg, undefined); }); resolve('baz', opts('/foo/bar'), function (err, res) { t.equal(err.message, "Cannot find module 'baz' from '" + path.resolve('/foo/bar') + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); resolve('../baz', opts('/foo/bar'), function (err, res) { t.equal(err.message, "Cannot find module '../baz' from '" + path.resolve('/foo/bar') + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); }); test('mock from package', function (t) { t.plan(8); var files = {}; files[path.resolve('/foo/bar/baz.js')] = 'beep'; var dirs = {}; dirs[path.resolve('/foo/bar')] = true; function opts(basedir) { return { basedir: path.resolve(basedir), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(files, file)); }, isDirectory: function (dir, cb) { cb(null, !!dirs[path.resolve(dir)]); }, 'package': { main: 'bar' }, readFile: function (file, cb) { cb(null, files[file]); }, realpath: function (file, cb) { cb(null, file); } }; } resolve('./baz', opts('/foo/bar'), function (err, res, pkg) { if (err) return t.fail(err); t.equal(res, path.resolve('/foo/bar/baz.js')); t.equal(pkg && pkg.main, 'bar'); }); resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) { if (err) return t.fail(err); t.equal(res, path.resolve('/foo/bar/baz.js')); t.equal(pkg && pkg.main, 'bar'); }); resolve('baz', opts('/foo/bar'), function (err, res) { t.equal(err.message, "Cannot find module 'baz' from '" + path.resolve('/foo/bar') + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); resolve('../baz', opts('/foo/bar'), function (err, res) { t.equal(err.message, "Cannot find module '../baz' from '" + path.resolve('/foo/bar') + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); }); test('mock package', function (t) { t.plan(2); var files = {}; files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep'; files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({ main: './baz.js' }); var dirs = {}; dirs[path.resolve('/foo')] = true; dirs[path.resolve('/foo/node_modules')] = true; function opts(basedir) { return { basedir: path.resolve(basedir), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, isDirectory: function (dir, cb) { cb(null, !!dirs[path.resolve(dir)]); }, readFile: function (file, cb) { cb(null, files[path.resolve(file)]); }, realpath: function (file, cb) { cb(null, file); } }; } resolve('bar', opts('/foo'), function (err, res, pkg) { if (err) return t.fail(err); t.equal(res, path.resolve('/foo/node_modules/bar/baz.js')); t.equal(pkg && pkg.main, './baz.js'); }); }); test('mock package from package', function (t) { t.plan(2); var files = {}; files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep'; files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({ main: './baz.js' }); var dirs = {}; dirs[path.resolve('/foo')] = true; dirs[path.resolve('/foo/node_modules')] = true; function opts(basedir) { return { basedir: path.resolve(basedir), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, isDirectory: function (dir, cb) { cb(null, !!dirs[path.resolve(dir)]); }, 'package': { main: 'bar' }, readFile: function (file, cb) { cb(null, files[path.resolve(file)]); }, realpath: function (file, cb) { cb(null, file); } }; } resolve('bar', opts('/foo'), function (err, res, pkg) { if (err) return t.fail(err); t.equal(res, path.resolve('/foo/node_modules/bar/baz.js')); t.equal(pkg && pkg.main, './baz.js'); }); }); test('symlinked', function (t) { t.plan(4); var files = {}; files[path.resolve('/foo/bar/baz.js')] = 'beep'; files[path.resolve('/foo/bar/symlinked/baz.js')] = 'beep'; var dirs = {}; dirs[path.resolve('/foo/bar')] = true; dirs[path.resolve('/foo/bar/symlinked')] = true; function opts(basedir) { return { preserveSymlinks: false, basedir: path.resolve(basedir), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, isDirectory: function (dir, cb) { cb(null, !!dirs[path.resolve(dir)]); }, readFile: function (file, cb) { cb(null, files[path.resolve(file)]); }, realpath: function (file, cb) { var resolved = path.resolve(file); if (resolved.indexOf('symlinked') >= 0) { cb(null, resolved); return; } var ext = path.extname(resolved); if (ext) { var dir = path.dirname(resolved); var base = path.basename(resolved); cb(null, path.join(dir, 'symlinked', base)); } else { cb(null, path.join(resolved, 'symlinked')); } } }; } resolve('./baz', opts('/foo/bar'), function (err, res, pkg) { if (err) return t.fail(err); t.equal(res, path.resolve('/foo/bar/symlinked/baz.js')); t.equal(pkg, undefined); }); resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) { if (err) return t.fail(err); t.equal(res, path.resolve('/foo/bar/symlinked/baz.js')); t.equal(pkg, undefined); }); }); test('readPackage', function (t) { t.plan(4); var files = {}; files[path.resolve('/foo/node_modules/bar/something-else.js')] = 'beep'; files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({ main: './baz.js' }); files[path.resolve('/foo/node_modules/bar/baz.js')] = 'boop'; var dirs = {}; dirs[path.resolve('/foo')] = true; dirs[path.resolve('/foo/node_modules')] = true; function opts(basedir) { return { basedir: path.resolve(basedir), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, isDirectory: function (dir, cb) { cb(null, !!dirs[path.resolve(dir)]); }, 'package': { main: 'bar' }, readFile: function (file, cb) { cb(null, files[path.resolve(file)]); }, realpath: function (file, cb) { cb(null, file); } }; } t.test('with readFile', function (st) { st.plan(3); resolve('bar', opts('/foo'), function (err, res, pkg) { st.error(err); st.equal(res, path.resolve('/foo/node_modules/bar/baz.js')); st.equal(pkg && pkg.main, './baz.js'); }); }); function readPackage(readFile, file, cb) { var barPackage = path.join('bar', 'package.json'); if (file.slice(-barPackage.length) === barPackage) { cb(null, { main: './something-else.js' }); } else { cb(null, JSON.parse(files[path.resolve(file)])); } } t.test('with readPackage', function (st) { st.plan(3); var options = opts('/foo'); delete options.readFile; options.readPackage = readPackage; resolve('bar', options, function (err, res, pkg) { st.error(err); st.equal(res, path.resolve('/foo/node_modules/bar/something-else.js')); st.equal(pkg && pkg.main, './something-else.js'); }); }); t.test('with readFile and readPackage', function (st) { st.plan(1); var options = opts('/foo'); options.readPackage = readPackage; resolve('bar', options, function (err) { st.throws(function () { throw err; }, TypeError, 'errors when both readFile and readPackage are provided'); }); }); t.test('readPackage error in loadpkg does not invoke callback twice', function (st) { st.plan(1); var callCount = 0; var readPackageError = new Error('read package error'); function failReadPackage(rf, file, cb) { cb(readPackageError); } var relFiles = {}; relFiles[path.resolve('/foo/bar/baz.js')] = 'beep'; relFiles[path.resolve('/foo/bar/package.json')] = '{}'; var relDirs = {}; relDirs[path.resolve('/foo/bar')] = true; resolve('./baz', { basedir: path.resolve('/foo/bar'), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(relFiles, path.resolve(file))); }, isDirectory: function (dir, cb) { cb(null, !!relDirs[path.resolve(dir)]); }, readPackage: failReadPackage, realpath: function (file, cb) { cb(null, file); } }, function () { callCount += 1; }); setTimeout(function () { st.equal(callCount, 1, 'callback is invoked exactly once'); }, 50); }); }); browserify-resolve-7877a0d/test/mock_sync.js000066400000000000000000000146751516631042000212420ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('mock', function (t) { t.plan(4); var files = {}; files[path.resolve('/foo/bar/baz.js')] = 'beep'; var dirs = {}; dirs[path.resolve('/foo/bar')] = true; function opts(basedir) { return { basedir: path.resolve(basedir), isFile: function (file) { return Object.prototype.hasOwnProperty.call(files, path.resolve(file)); }, isDirectory: function (dir) { return !!dirs[path.resolve(dir)]; }, readFileSync: function (file) { return files[path.resolve(file)]; }, realpathSync: function (file) { return file; } }; } t.equal( resolve.sync('./baz', opts('/foo/bar')), path.resolve('/foo/bar/baz.js') ); t.equal( resolve.sync('./baz.js', opts('/foo/bar')), path.resolve('/foo/bar/baz.js') ); t.throws(function () { resolve.sync('baz', opts('/foo/bar')); }); t.throws(function () { resolve.sync('../baz', opts('/foo/bar')); }); }); test('mock package', function (t) { t.plan(1); var files = {}; files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep'; files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({ main: './baz.js' }); var dirs = {}; dirs[path.resolve('/foo')] = true; dirs[path.resolve('/foo/node_modules')] = true; function opts(basedir) { return { basedir: path.resolve(basedir), isFile: function (file) { return Object.prototype.hasOwnProperty.call(files, path.resolve(file)); }, isDirectory: function (dir) { return !!dirs[path.resolve(dir)]; }, readFileSync: function (file) { return files[path.resolve(file)]; }, realpathSync: function (file) { return file; } }; } t.equal( resolve.sync('bar', opts('/foo')), path.resolve('/foo/node_modules/bar/baz.js') ); }); test('symlinked', function (t) { t.plan(2); var files = {}; files[path.resolve('/foo/bar/baz.js')] = 'beep'; files[path.resolve('/foo/bar/symlinked/baz.js')] = 'beep'; var dirs = {}; dirs[path.resolve('/foo/bar')] = true; dirs[path.resolve('/foo/bar/symlinked')] = true; function opts(basedir) { return { preserveSymlinks: false, basedir: path.resolve(basedir), isFile: function (file) { return Object.prototype.hasOwnProperty.call(files, path.resolve(file)); }, isDirectory: function (dir) { return !!dirs[path.resolve(dir)]; }, readFileSync: function (file) { return files[path.resolve(file)]; }, realpathSync: function (file) { var resolved = path.resolve(file); if (resolved.indexOf('symlinked') >= 0) { return resolved; } var ext = path.extname(resolved); if (ext) { var dir = path.dirname(resolved); var base = path.basename(resolved); return path.join(dir, 'symlinked', base); } return path.join(resolved, 'symlinked'); } }; } t.equal( resolve.sync('./baz', opts('/foo/bar')), path.resolve('/foo/bar/symlinked/baz.js') ); t.equal( resolve.sync('./baz.js', opts('/foo/bar')), path.resolve('/foo/bar/symlinked/baz.js') ); }); test('readPackageSync', function (t) { t.plan(4); var files = {}; files[path.resolve('/foo/node_modules/bar/something-else.js')] = 'beep'; files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({ main: './baz.js' }); files[path.resolve('/foo/node_modules/bar/baz.js')] = 'boop'; var dirs = {}; dirs[path.resolve('/foo')] = true; dirs[path.resolve('/foo/node_modules')] = true; function opts(basedir, useReadPackage) { return { basedir: path.resolve(basedir), isFile: function (file) { return Object.prototype.hasOwnProperty.call(files, path.resolve(file)); }, isDirectory: function (dir) { return !!dirs[path.resolve(dir)]; }, readFileSync: useReadPackage ? null : function (file) { return files[path.resolve(file)]; }, realpathSync: function (file) { return file; } }; } t.test('with readFile', function (st) { st.plan(1); st.equal( resolve.sync('bar', opts('/foo')), path.resolve('/foo/node_modules/bar/baz.js') ); }); function readPackageSync(readFileSync, file) { if (file.indexOf(path.join('bar', 'package.json')) >= 0) { return { main: './something-else.js' }; } return JSON.parse(files[path.resolve(file)]); } t.test('with readPackage', function (st) { st.plan(1); var options = opts('/foo'); delete options.readFileSync; options.readPackageSync = readPackageSync; st.equal( resolve.sync('bar', options), path.resolve('/foo/node_modules/bar/something-else.js') ); }); t.test('with readFile and readPackage', function (st) { st.plan(1); var options = opts('/foo'); options.readPackageSync = readPackageSync; st.throws( function () { resolve.sync('bar', options); }, TypeError, 'errors when both readFile and readPackage are provided' ); }); t.test('readPackageSync error propagates correctly', function (st) { st.plan(1); var readPackageError = new Error('read package error'); function failReadPackageSync() { throw readPackageError; } var options = opts('/foo'); delete options.readFileSync; options.readPackageSync = failReadPackageSync; st.throws( function () { resolve.sync('bar', options); }, readPackageError, 'readPackageSync error is thrown' ); }); }); browserify-resolve-7877a0d/test/module_dir.js000066400000000000000000000030261516631042000213640ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('moduleDirectory strings', function (t) { t.plan(4); var dir = path.join(__dirname, 'module_dir'); var xopts = { basedir: dir, moduleDirectory: 'xmodules' }; resolve('aaa', xopts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/xmodules/aaa/index.js')); }); var yopts = { basedir: dir, moduleDirectory: 'ymodules' }; resolve('aaa', yopts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/ymodules/aaa/index.js')); }); }); test('moduleDirectory array', function (t) { t.plan(6); var dir = path.join(__dirname, 'module_dir'); var aopts = { basedir: dir, moduleDirectory: ['xmodules', 'ymodules', 'zmodules'] }; resolve('aaa', aopts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/xmodules/aaa/index.js')); }); var bopts = { basedir: dir, moduleDirectory: ['zmodules', 'ymodules', 'xmodules'] }; resolve('aaa', bopts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/ymodules/aaa/index.js')); }); var copts = { basedir: dir, moduleDirectory: ['xmodules', 'ymodules', 'zmodules'] }; resolve('bbb', copts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/zmodules/bbb/main.js')); }); }); browserify-resolve-7877a0d/test/module_dir/000077500000000000000000000000001516631042000210255ustar00rootroot00000000000000browserify-resolve-7877a0d/test/module_dir/xmodules/000077500000000000000000000000001516631042000226655ustar00rootroot00000000000000browserify-resolve-7877a0d/test/module_dir/xmodules/aaa/000077500000000000000000000000001516631042000234075ustar00rootroot00000000000000browserify-resolve-7877a0d/test/module_dir/xmodules/aaa/index.js000066400000000000000000000000631516631042000250530ustar00rootroot00000000000000module.exports = function (x) { return x * 100; }; browserify-resolve-7877a0d/test/module_dir/ymodules/000077500000000000000000000000001516631042000226665ustar00rootroot00000000000000browserify-resolve-7877a0d/test/module_dir/ymodules/aaa/000077500000000000000000000000001516631042000234105ustar00rootroot00000000000000browserify-resolve-7877a0d/test/module_dir/ymodules/aaa/index.js000066400000000000000000000000631516631042000250540ustar00rootroot00000000000000module.exports = function (x) { return x + 100; }; browserify-resolve-7877a0d/test/module_dir/zmodules/000077500000000000000000000000001516631042000226675ustar00rootroot00000000000000browserify-resolve-7877a0d/test/module_dir/zmodules/bbb/000077500000000000000000000000001516631042000234145ustar00rootroot00000000000000browserify-resolve-7877a0d/test/module_dir/zmodules/bbb/main.js000066400000000000000000000000631516631042000246750ustar00rootroot00000000000000module.exports = function (n) { return n * 111; }; browserify-resolve-7877a0d/test/module_dir/zmodules/bbb/package.json000066400000000000000000000000301516631042000256730ustar00rootroot00000000000000{ "main": "main.js" } browserify-resolve-7877a0d/test/node-modules-paths.js000066400000000000000000000117011516631042000227500ustar00rootroot00000000000000var test = require('tape'); var path = require('path'); var parse = path.parse || require('path-parse'); var keys = require('object-keys'); var nodeModulesPaths = require('../lib/node-modules-paths'); function verifyDirs(t, start, dirs, moduleDirectories, paths) { var moduleDirs = [].concat(moduleDirectories || 'node_modules'); if (paths) { for (var k = 0; k < paths.length; ++k) { moduleDirs.push(path.basename(paths[k])); } } var foundModuleDirs = {}; var uniqueDirs = {}; var parsedDirs = {}; for (var i = 0; i < dirs.length; ++i) { var parsed = parse(dirs[i]); if (!foundModuleDirs[parsed.base]) { foundModuleDirs[parsed.base] = 0; } foundModuleDirs[parsed.base] += 1; parsedDirs[parsed.dir] = true; uniqueDirs[dirs[i]] = true; } t.equal(keys(parsedDirs).length >= start.split(path.sep).length, true, 'there are >= dirs than "start" has'); var foundModuleDirNames = keys(foundModuleDirs); t.deepEqual(foundModuleDirNames, moduleDirs, 'all desired module dirs were found'); t.equal(keys(uniqueDirs).length, dirs.length, 'all dirs provided were unique'); var counts = {}; for (var j = 0; j < foundModuleDirNames.length; ++j) { counts[foundModuleDirs[j]] = true; } t.equal(keys(counts).length, 1, 'all found module directories had the same count'); } test('node-modules-paths', function (t) { t.test('no options', function (t) { var start = path.join(__dirname, 'resolver'); var dirs = nodeModulesPaths(start); verifyDirs(t, start, dirs); t.end(); }); t.test('empty options', function (t) { var start = path.join(__dirname, 'resolver'); var dirs = nodeModulesPaths(start, {}); verifyDirs(t, start, dirs); t.end(); }); t.test('with paths=array option', function (t) { var start = path.join(__dirname, 'resolver'); var paths = ['a', 'b']; var dirs = nodeModulesPaths(start, { paths: paths }); verifyDirs(t, start, dirs, null, paths); t.end(); }); t.test('with paths=function option', function (t) { function paths(request, absoluteStart, getNodeModulesDirs, opts) { return getNodeModulesDirs().concat(path.join(absoluteStart, 'not node modules', request)); } var start = path.join(__dirname, 'resolver'); var dirs = nodeModulesPaths(start, { paths: paths }, 'pkg'); verifyDirs(t, start, dirs, null, [path.join(start, 'not node modules', 'pkg')]); t.end(); }); t.test('with paths=function skipping node modules resolution', function (t) { function paths(request, absoluteStart, getNodeModulesDirs, opts) { return []; } var start = path.join(__dirname, 'resolver'); var dirs = nodeModulesPaths(start, { paths: paths }); t.deepEqual(dirs, [], 'no node_modules was computed'); t.end(); }); t.test('with moduleDirectory option', function (t) { var start = path.join(__dirname, 'resolver'); var moduleDirectory = 'not node modules'; var dirs = nodeModulesPaths(start, { moduleDirectory: moduleDirectory }); verifyDirs(t, start, dirs, moduleDirectory); t.end(); }); t.test('with 1 moduleDirectory and paths options', function (t) { var start = path.join(__dirname, 'resolver'); var paths = ['a', 'b']; var moduleDirectory = 'not node modules'; var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectory }); verifyDirs(t, start, dirs, moduleDirectory, paths); t.end(); }); t.test('with 1+ moduleDirectory and paths options', function (t) { var start = path.join(__dirname, 'resolver'); var paths = ['a', 'b']; var moduleDirectories = ['not node modules', 'other modules']; var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories }); verifyDirs(t, start, dirs, moduleDirectories, paths); t.end(); }); t.test('combine paths correctly on Windows', function (t) { var start = 'C:\\Users\\username\\myProject\\src'; var paths = []; var moduleDirectories = ['node_modules', start]; var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories }); t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir'); t.end(); }); t.test('combine paths correctly on non-Windows', { skip: process.platform === 'win32' }, function (t) { var start = '/Users/username/git/myProject/src'; var paths = []; var moduleDirectories = ['node_modules', '/Users/username/git/myProject/src']; var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories }); t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir'); t.end(); }); }); browserify-resolve-7877a0d/test/node_path.js000066400000000000000000000041101516631042000211750ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var test = require('tape'); var resolve = require('../'); test('$NODE_PATH', function (t) { t.plan(8); function isDir(dir, cb) { if (dir === '/node_path' || dir === 'node_path/x') { return cb(null, true); } fs.stat(dir, function (err, stat) { if (!err) { return cb(null, stat.isDirectory()); } if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); return cb(err); }); } resolve('aaa', { paths: [ path.join(__dirname, '/node_path/x'), path.join(__dirname, '/node_path/y') ], basedir: __dirname, isDirectory: isDir }, function (err, res) { t.error(err); t.equal(res, path.join(__dirname, '/node_path/x/aaa/index.js'), 'aaa resolves'); }); resolve('bbb', { paths: [ path.join(__dirname, '/node_path/x'), path.join(__dirname, '/node_path/y') ], basedir: __dirname, isDirectory: isDir }, function (err, res) { t.error(err); t.equal(res, path.join(__dirname, '/node_path/y/bbb/index.js'), 'bbb resolves'); }); resolve('ccc', { paths: [ path.join(__dirname, '/node_path/x'), path.join(__dirname, '/node_path/y') ], basedir: __dirname, isDirectory: isDir }, function (err, res) { t.error(err); t.equal(res, path.join(__dirname, '/node_path/x/ccc/index.js'), 'ccc resolves'); }); // ensure that relative paths still resolve against the regular `node_modules` correctly resolve('tap', { paths: [ 'node_path' ], basedir: path.join(__dirname, 'node_path/x'), isDirectory: isDir }, function (err, res) { var root = require('tap/package.json').main; // eslint-disable-line global-require t.error(err); t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root), 'tap resolves'); }); }); browserify-resolve-7877a0d/test/node_path/000077500000000000000000000000001516631042000206435ustar00rootroot00000000000000browserify-resolve-7877a0d/test/node_path/x/000077500000000000000000000000001516631042000211125ustar00rootroot00000000000000browserify-resolve-7877a0d/test/node_path/x/aaa/000077500000000000000000000000001516631042000216345ustar00rootroot00000000000000browserify-resolve-7877a0d/test/node_path/x/aaa/index.js000066400000000000000000000000261516631042000232770ustar00rootroot00000000000000module.exports = 'A'; browserify-resolve-7877a0d/test/node_path/x/ccc/000077500000000000000000000000001516631042000216425ustar00rootroot00000000000000browserify-resolve-7877a0d/test/node_path/x/ccc/index.js000066400000000000000000000000261516631042000233050ustar00rootroot00000000000000module.exports = 'C'; browserify-resolve-7877a0d/test/node_path/y/000077500000000000000000000000001516631042000211135ustar00rootroot00000000000000browserify-resolve-7877a0d/test/node_path/y/bbb/000077500000000000000000000000001516631042000216405ustar00rootroot00000000000000browserify-resolve-7877a0d/test/node_path/y/bbb/index.js000066400000000000000000000000261516631042000233030ustar00rootroot00000000000000module.exports = 'B'; browserify-resolve-7877a0d/test/node_path/y/ccc/000077500000000000000000000000001516631042000216435ustar00rootroot00000000000000browserify-resolve-7877a0d/test/node_path/y/ccc/index.js000066400000000000000000000000271516631042000233070ustar00rootroot00000000000000module.exports = 'CY'; browserify-resolve-7877a0d/test/nonstring.js000066400000000000000000000002661516631042000212650ustar00rootroot00000000000000var test = require('tape'); var resolve = require('../'); test('nonstring', function (t) { t.plan(1); resolve(555, function (err, res, pkg) { t.ok(err); }); }); browserify-resolve-7877a0d/test/pathfilter.js000066400000000000000000000043001516631042000213770ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); var resolverDir = path.join(__dirname, '/pathfilter/deep_ref'); function pathFilterFactory(t) { return function (pkg, x, remainder) { t.equal(pkg.version, '1.2.3'); t.equal(x, path.join(resolverDir, 'node_modules/deep/ref')); t.equal(remainder, 'ref'); return 'alt'; }; } test('#62: deep module references and the pathFilter', function (t) { t.test('deep/ref.js', function (st) { st.plan(3); resolve('deep/ref', { basedir: resolverDir }, function (err, res, pkg) { if (err) st.fail(err); st.equal(pkg.version, '1.2.3'); st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js')); }); var res = resolve.sync('deep/ref', { basedir: resolverDir }); st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js')); }); t.test('deep/deeper/ref', function (st) { st.plan(4); resolve( 'deep/deeper/ref', { basedir: resolverDir }, function (err, res, pkg) { if (err) t.fail(err); st.notEqual(pkg, undefined); st.equal(pkg.version, '1.2.3'); st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js')); } ); var res = resolve.sync( 'deep/deeper/ref', { basedir: resolverDir } ); st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js')); }); t.test('deep/ref alt', function (st) { st.plan(8); var pathFilter = pathFilterFactory(st); var res = resolve.sync( 'deep/ref', { basedir: resolverDir, pathFilter: pathFilter } ); st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js')); resolve( 'deep/ref', { basedir: resolverDir, pathFilter: pathFilter }, function (err, res, pkg) { if (err) st.fail(err); st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js')); st.end(); } ); }); t.end(); }); browserify-resolve-7877a0d/test/pathfilter/000077500000000000000000000000001516631042000210445ustar00rootroot00000000000000browserify-resolve-7877a0d/test/pathfilter/deep_ref/000077500000000000000000000000001516631042000226155ustar00rootroot00000000000000browserify-resolve-7877a0d/test/pathfilter/deep_ref/main.js000066400000000000000000000000001516631042000240650ustar00rootroot00000000000000browserify-resolve-7877a0d/test/pathfilter/deep_ref/node_modules/000077500000000000000000000000001516631042000252725ustar00rootroot00000000000000browserify-resolve-7877a0d/test/pathfilter/deep_ref/node_modules/deep/000077500000000000000000000000001516631042000262075ustar00rootroot00000000000000browserify-resolve-7877a0d/test/pathfilter/deep_ref/node_modules/deep/alt.js000066400000000000000000000000001516631042000273130ustar00rootroot00000000000000browserify-resolve-7877a0d/test/pathfilter/deep_ref/node_modules/deep/deeper/000077500000000000000000000000001516631042000274535ustar00rootroot00000000000000browserify-resolve-7877a0d/test/pathfilter/deep_ref/node_modules/deep/deeper/ref.js000066400000000000000000000000001516631042000305530ustar00rootroot00000000000000browserify-resolve-7877a0d/test/pathfilter/deep_ref/node_modules/deep/package.json000066400000000000000000000000531516631042000304730ustar00rootroot00000000000000{ "name": "deep", "version": "1.2.3" } browserify-resolve-7877a0d/test/pathfilter/deep_ref/node_modules/deep/ref.js000066400000000000000000000000001516631042000273070ustar00rootroot00000000000000browserify-resolve-7877a0d/test/pathfilter_sync.js000066400000000000000000000016051516631042000224400ustar00rootroot00000000000000var test = require('tape'); var path = require('path'); var resolve = require('../'); test('synchronous pathfilter', function (t) { var res; var resolverDir = __dirname + '/pathfilter/deep_ref'; function pathFilter(pkg, x, remainder) { t.equal(pkg.version, '1.2.3'); t.equal(x, path.join(resolverDir, 'node_modules', 'deep', 'ref')); t.equal(remainder, 'ref'); return 'alt'; } res = resolve.sync('deep/ref', { basedir: resolverDir }); t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'ref.js')); res = resolve.sync('deep/deeper/ref', { basedir: resolverDir }); t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'deeper', 'ref.js')); res = resolve.sync('deep/ref', { basedir: resolverDir, pathFilter: pathFilter }); t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'alt.js')); t.end(); }); browserify-resolve-7877a0d/test/precedence.js000066400000000000000000000012061516631042000213340ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('precedence', function (t) { t.plan(3); var dir = path.join(__dirname, 'precedence/aaa'); resolve('./', { basedir: dir }, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, 'index.js')); t.equal(pkg.name, 'resolve'); }); }); test('./ should not load ${dir}.js', function (t) { // eslint-disable-line no-template-curly-in-string t.plan(1); var dir = path.join(__dirname, 'precedence/bbb'); resolve('./', { basedir: dir }, function (err, res, pkg) { t.ok(err); }); }); browserify-resolve-7877a0d/test/precedence/000077500000000000000000000000001516631042000207775ustar00rootroot00000000000000browserify-resolve-7877a0d/test/precedence/aaa.js000066400000000000000000000000301516631042000220500ustar00rootroot00000000000000module.exports = 'wtf'; browserify-resolve-7877a0d/test/precedence/aaa/000077500000000000000000000000001516631042000215215ustar00rootroot00000000000000browserify-resolve-7877a0d/test/precedence/aaa/index.js000066400000000000000000000000311516631042000231600ustar00rootroot00000000000000module.exports = 'okok'; browserify-resolve-7877a0d/test/precedence/aaa/main.js000066400000000000000000000000341516631042000230000ustar00rootroot00000000000000console.log(require('./')); browserify-resolve-7877a0d/test/precedence/bbb.js000066400000000000000000000000301516631042000220530ustar00rootroot00000000000000module.exports = '>_<'; browserify-resolve-7877a0d/test/precedence/bbb/000077500000000000000000000000001516631042000215245ustar00rootroot00000000000000browserify-resolve-7877a0d/test/precedence/bbb/main.js000066400000000000000000000000541516631042000230050ustar00rootroot00000000000000console.log(require('./')); // should throw browserify-resolve-7877a0d/test/resolver.js000066400000000000000000000471261516631042000211130ustar00rootroot00000000000000var path = require('path'); var fs = require('fs'); var test = require('tape'); var resolve = require('../'); var async = require('../async'); test('`./async` entry point', function (t) { t.equal(resolve, async, '`./async` entry point is the same as `main`'); t.end(); }); test('async foo', function (t) { t.plan(12); var dir = path.join(__dirname, 'resolver'); resolve('./foo', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'foo.js')); t.equal(pkg && pkg.name, 'resolve'); }); resolve('./foo.js', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'foo.js')); t.equal(pkg && pkg.name, 'resolve'); }); resolve('./foo', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'foo.js')); t.equal(pkg && pkg.main, 'resolver'); }); resolve('./foo.js', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'foo.js')); t.equal(pkg.main, 'resolver'); }); resolve('./foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(dir, 'foo.js')); }); resolve('foo', { basedir: dir }, function (err) { t.equal(err.message, "Cannot find module 'foo' from '" + path.resolve(dir) + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); // Test that filename is reported as the "from" value when passed. resolve('foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err) { t.equal(err.message, "Cannot find module 'foo' from '" + path.join(dir, 'baz.js') + "'"); }); }); test('bar', function (t) { t.plan(6); var dir = path.join(__dirname, 'resolver'); resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js')); t.equal(pkg, undefined); }); resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js')); t.equal(pkg, undefined); }); resolve('foo', { basedir: dir + '/bar', 'package': { main: 'bar' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js')); t.equal(pkg.main, 'bar'); }); }); test('baz', function (t) { t.plan(4); var dir = path.join(__dirname, 'resolver'); resolve('./baz', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'baz/quux.js')); t.equal(pkg.main, 'quux.js'); }); resolve('./baz', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'baz/quux.js')); t.equal(pkg.main, 'quux.js'); }); }); test('biz', function (t) { t.plan(24); var dir = path.join(__dirname, 'resolver/biz/node_modules'); resolve('./grux', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg, undefined); }); resolve('./grux', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg.main, 'biz'); }); resolve('./garply', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); resolve('./garply', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); resolve('tiv', { basedir: dir + '/grux' }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg, undefined); }); resolve('tiv', { basedir: dir + '/grux', 'package': { main: 'grux' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg.main, 'grux'); }); resolve('tiv', { basedir: dir + '/garply' }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg, undefined); }); resolve('tiv', { basedir: dir + '/garply', 'package': { main: './lib' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg.main, './lib'); }); resolve('grux', { basedir: dir + '/tiv' }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg, undefined); }); resolve('grux', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg.main, 'tiv'); }); resolve('garply', { basedir: dir + '/tiv' }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); resolve('garply', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); }); test('quux', function (t) { t.plan(2); var dir = path.join(__dirname, 'resolver/quux'); resolve('./foo', { basedir: dir, 'package': { main: 'quux' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'foo/index.js')); t.equal(pkg.main, 'quux'); }); }); test('normalize', function (t) { t.plan(2); var dir = path.join(__dirname, 'resolver/biz/node_modules/grux'); resolve('../grux', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'index.js')); t.equal(pkg, undefined); }); }); test('cup', function (t) { t.plan(5); var dir = path.join(__dirname, 'resolver'); resolve('./cup', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(dir, 'cup.coffee')); }); resolve('./cup.coffee', { basedir: dir }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(dir, 'cup.coffee')); }); resolve('./cup', { basedir: dir, extensions: ['.js'] }, function (err, res) { t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); // Test that filename is reported as the "from" value when passed. resolve('./cup', { basedir: dir, extensions: ['.js'], filename: path.join(dir, 'cupboard.js') }, function (err, res) { t.equal(err.message, "Cannot find module './cup' from '" + path.join(dir, 'cupboard.js') + "'"); }); }); test('mug', function (t) { t.plan(3); var dir = path.join(__dirname, 'resolver'); resolve('./mug', { basedir: dir }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(dir, 'mug.js')); }); resolve('./mug', { basedir: dir, extensions: ['.coffee', '.js'] }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(dir, '/mug.coffee')); }); resolve('./mug', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) { t.equal(res, path.join(dir, '/mug.js')); }); }); test('other path', function (t) { t.plan(6); var resolverDir = path.join(__dirname, 'resolver'); var dir = path.join(resolverDir, 'bar'); var otherDir = path.join(resolverDir, 'other_path'); resolve('root', { basedir: dir, paths: [otherDir] }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(resolverDir, 'other_path/root.js')); }); resolve('lib/other-lib', { basedir: dir, paths: [otherDir] }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(resolverDir, 'other_path/lib/other-lib.js')); }); resolve('root', { basedir: dir }, function (err, res) { t.equal(err.message, "Cannot find module 'root' from '" + path.resolve(dir) + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); resolve('zzz', { basedir: dir, paths: [otherDir] }, function (err, res) { t.equal(err.message, "Cannot find module 'zzz' from '" + path.resolve(dir) + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); }); test('path iterator', function (t) { t.plan(2); var resolverDir = path.join(__dirname, 'resolver'); function exactIterator(x, start, getPackageCandidates, opts) { return [path.join(resolverDir, x)]; } resolve('baz', { packageIterator: exactIterator }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(resolverDir, 'baz/quux.js')); t.equal(pkg && pkg.name, 'baz'); }); }); test('incorrect main', function (t) { t.plan(1); var resolverDir = path.join(__dirname, 'resolver'); var dir = path.join(resolverDir, 'incorrect_main'); resolve('./incorrect_main', { basedir: resolverDir }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'index.js')); }); }); test('missing index', function (t) { t.plan(2); var resolverDir = path.join(__dirname, 'resolver'); resolve('./missing_index', { basedir: resolverDir }, function (err, res, pkg) { t.ok(err instanceof Error); t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code'); }); }); test('missing main', function (t) { t.plan(1); var resolverDir = path.join(__dirname, 'resolver'); resolve('./missing_main', { basedir: resolverDir }, function (err, res, pkg) { t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code'); }); }); test('null main', function (t) { t.plan(1); var resolverDir = path.join(__dirname, 'resolver'); resolve('./null_main', { basedir: resolverDir }, function (err, res, pkg) { t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code'); }); }); test('main: false', function (t) { t.plan(2); var basedir = path.join(__dirname, 'resolver'); var dir = path.join(basedir, 'false_main'); resolve('./false_main', { basedir: basedir }, function (err, res, pkg) { if (err) t.fail(err); t.equal( res, path.join(dir, 'index.js'), '`"main": false`: resolves to `index.js`' ); t.deepEqual(pkg, { name: 'false_main', main: false }); }); }); test('without basedir', function (t) { t.plan(1); var dir = path.join(__dirname, 'resolver/without_basedir'); var tester = require(path.join(dir, 'main.js')); // eslint-disable-line global-require tester(t, function (err, res, pkg) { if (err) { t.fail(err); } else { t.equal(res, path.join(dir, 'node_modules/mymodule.js')); } }); }); test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) { t.plan(2); var dir = path.join(__dirname, 'resolver'); resolve('./foo', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'same_names/foo.js')); }); resolve('./foo/', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'same_names/foo/index.js')); }); }); test('#211 - incorrectly resolves module-paths like "." when from inside a folder with a sibling file of the same name', function (t) { t.plan(2); var dir = path.join(__dirname, 'resolver'); resolve('./', { basedir: path.join(dir, 'same_names/foo') }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'same_names/foo/index.js')); }); resolve('.', { basedir: path.join(dir, 'same_names/foo') }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'same_names/foo/index.js')); }); }); test('async: #121 - treating an existing file as a dir when no basedir', function (t) { var testFile = path.basename(__filename); t.test('sanity check', function (st) { st.plan(1); resolve('./' + testFile, function (err, res, pkg) { if (err) t.fail(err); st.equal(res, __filename, 'sanity check'); }); }); t.test('with a fake directory', function (st) { st.plan(4); resolve('./' + testFile + '/blah', function (err, res, pkg) { st.ok(err, 'there is an error'); st.notOk(res, 'no result'); st.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve'); st.equal( err && err.message, 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'', 'can not find nonexistent module' ); st.end(); }); }); t.end(); }); test('async dot main', function (t) { var start = new Date(); t.plan(3); resolve('./resolver/dot_main', function (err, ret) { t.notOk(err); t.equal(ret, path.join(__dirname, 'resolver/dot_main/index.js')); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); }); test('async dot slash main', function (t) { var start = new Date(); t.plan(3); resolve('./resolver/dot_slash_main', function (err, ret) { t.notOk(err); t.equal(ret, path.join(__dirname, 'resolver/dot_slash_main/index.js')); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); }); test('not a directory', function (t) { t.plan(6); var path = './foo'; resolve(path, { basedir: __filename }, function (err, res, pkg) { t.ok(err, 'a non-directory errors'); t.equal(arguments.length, 1); t.equal(res, undefined); t.equal(pkg, undefined); t.equal(err && err.message, 'Cannot find module \'' + path + '\' from \'' + __filename + '\''); t.equal(err && err.code, 'MODULE_NOT_FOUND'); }); }); test('non-string "main" field in package.json', function (t) { t.plan(5); var dir = path.join(__dirname, 'resolver'); resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) { t.ok(err, 'errors on non-string main'); t.equal(err.message, 'package “invalid_main” `main` must be a string'); t.equal(err.code, 'INVALID_PACKAGE_MAIN'); t.equal(res, undefined, 'res is undefined'); t.equal(pkg, undefined, 'pkg is undefined'); }); }); test('non-string "main" field in package.json', function (t) { t.plan(5); var dir = path.join(__dirname, 'resolver'); resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) { t.ok(err, 'errors on non-string main'); t.equal(err.message, 'package “invalid_main” `main` must be a string'); t.equal(err.code, 'INVALID_PACKAGE_MAIN'); t.equal(res, undefined, 'res is undefined'); t.equal(pkg, undefined, 'pkg is undefined'); }); }); test('browser field in package.json', function (t) { t.plan(3); var dir = path.join(__dirname, 'resolver'); resolve( './browser_field', { basedir: dir, packageFilter: function packageFilter(pkg) { if (pkg.browser) { pkg.main = pkg.browser; // eslint-disable-line no-param-reassign delete pkg.browser; // eslint-disable-line no-param-reassign } return pkg; } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'browser_field', 'b.js')); t.equal(pkg && pkg.main, 'b'); t.equal(pkg && pkg.browser, undefined); } ); }); test('absolute paths', function (t) { t.plan(4); var extensionless = __filename.slice(0, -path.extname(__filename).length); resolve(__filename, function (err, res) { t.equal( res, __filename, 'absolute path to this file resolves' ); }); resolve(extensionless, function (err, res) { t.equal( res, __filename, 'extensionless absolute path to this file resolves' ); }); resolve(__filename, { basedir: process.cwd() }, function (err, res) { t.equal( res, __filename, 'absolute path to this file with a basedir resolves' ); }); resolve(extensionless, { basedir: process.cwd() }, function (err, res) { t.equal( res, __filename, 'extensionless absolute path to this file with a basedir resolves' ); }); }); var malformedDir = path.join(__dirname, 'resolver/malformed_package_json'); test('malformed package.json', { skip: !fs.existsSync(malformedDir) }, function (t) { /* eslint operator-linebreak: ["error", "before"], function-paren-newline: "off" */ t.plan( (3 * 3) // 3 sets of 3 assertions in the final callback + 2 // 1 readPackage call with malformed package.json ); var basedir = malformedDir; var expected = path.join(basedir, 'index.js'); resolve('./index.js', { basedir: basedir }, function (err, res, pkg) { t.error(err, 'no error'); t.equal(res, expected, 'malformed package.json is silently ignored'); t.equal(pkg, undefined, 'malformed package.json gives an undefined `pkg` argument'); }); resolve( './index.js', { basedir: basedir, packageFilter: function (pkg, pkgfile, dir) { t.fail('should not reach here'); } }, function (err, res, pkg) { t.error(err, 'with packageFilter: no error'); t.equal(res, expected, 'with packageFilter: malformed package.json is silently ignored'); t.equal(pkg, undefined, 'with packageFilter: malformed package.json gives an undefined `pkg` argument'); } ); resolve( './index.js', { basedir: basedir, readPackage: function (readFile, pkgfile, cb) { t.equal(pkgfile, path.join(basedir, 'package.json'), 'readPackageSync: `pkgfile` is package.json path'); readFile(pkgfile, function (err, result) { try { cb(null, JSON.parse(result)); } catch (e) { t.ok(e instanceof SyntaxError, 'readPackage: malformed package.json parses as a syntax error'); cb(null); } }); } }, function (err, res, pkg) { t.error(err, 'with readPackage: no error'); t.equal(res, expected, 'with readPackage: malformed package.json is silently ignored'); t.equal(pkg, undefined, 'with readPackage: malformed package.json gives an undefined `pkg` argument'); } ); }); browserify-resolve-7877a0d/test/resolver/000077500000000000000000000000001516631042000205435ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/bar/000077500000000000000000000000001516631042000213075ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/bar/node_modules/000077500000000000000000000000001516631042000237645ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/bar/node_modules/foo/000077500000000000000000000000001516631042000245475ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/bar/node_modules/foo/index.js000066400000000000000000000000241516631042000262100ustar00rootroot00000000000000module.exports = 1; browserify-resolve-7877a0d/test/resolver/baz/000077500000000000000000000000001516631042000213175ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/baz/doom.js000066400000000000000000000000001516631042000226010ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/baz/package.json000066400000000000000000000000551516631042000236050ustar00rootroot00000000000000{ "name": "baz", "main": "quux.js" } browserify-resolve-7877a0d/test/resolver/baz/quux.js000066400000000000000000000000241516631042000226530ustar00rootroot00000000000000module.exports = 1; browserify-resolve-7877a0d/test/resolver/biz/000077500000000000000000000000001516631042000213275ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/biz/node_modules/000077500000000000000000000000001516631042000240045ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/biz/node_modules/garply/000077500000000000000000000000001516631042000253025ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/biz/node_modules/garply/lib/000077500000000000000000000000001516631042000260505ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/biz/node_modules/garply/lib/index.js000066400000000000000000000000411516631042000275100ustar00rootroot00000000000000module.exports = 'hello garply'; browserify-resolve-7877a0d/test/resolver/biz/node_modules/garply/package.json000066400000000000000000000000311516631042000275620ustar00rootroot00000000000000{ "main" : "./lib" } browserify-resolve-7877a0d/test/resolver/biz/node_modules/grux/000077500000000000000000000000001516631042000247715ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/biz/node_modules/grux/index.js000066400000000000000000000000471516631042000264370ustar00rootroot00000000000000module.exports = require('tiv') * 100; browserify-resolve-7877a0d/test/resolver/biz/node_modules/tiv/000077500000000000000000000000001516631042000246065ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/biz/node_modules/tiv/index.js000066400000000000000000000000241516631042000262470ustar00rootroot00000000000000module.exports = 3; browserify-resolve-7877a0d/test/resolver/browser_field/000077500000000000000000000000001516631042000233715ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/browser_field/a.js000066400000000000000000000000001516631042000241350ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/browser_field/b.js000066400000000000000000000000001516631042000241360ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/browser_field/package.json000066400000000000000000000000771516631042000256630ustar00rootroot00000000000000{ "name": "browser_field", "main": "a", "browser": "b" } browserify-resolve-7877a0d/test/resolver/cup.coffee000066400000000000000000000000011516631042000224720ustar00rootroot00000000000000 browserify-resolve-7877a0d/test/resolver/dot_main/000077500000000000000000000000001516631042000223355ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/dot_main/index.js000066400000000000000000000000241516631042000237760ustar00rootroot00000000000000module.exports = 1; browserify-resolve-7877a0d/test/resolver/dot_main/package.json000066400000000000000000000000241516631042000246170ustar00rootroot00000000000000{ "main": "." } browserify-resolve-7877a0d/test/resolver/dot_slash_main/000077500000000000000000000000001516631042000235275ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/dot_slash_main/index.js000066400000000000000000000000241516631042000251700ustar00rootroot00000000000000module.exports = 1; browserify-resolve-7877a0d/test/resolver/dot_slash_main/package.json000066400000000000000000000000251516631042000260120ustar00rootroot00000000000000{ "main": "./" } browserify-resolve-7877a0d/test/resolver/false_main/000077500000000000000000000000001516631042000226415ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/false_main/index.js000066400000000000000000000000001516631042000242740ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/false_main/package.json000066400000000000000000000000521516631042000251240ustar00rootroot00000000000000{ "name": "false_main", "main": false } browserify-resolve-7877a0d/test/resolver/foo.js000066400000000000000000000000241516631042000216600ustar00rootroot00000000000000module.exports = 1; browserify-resolve-7877a0d/test/resolver/incorrect_main/000077500000000000000000000000001516631042000235375ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/incorrect_main/index.js000066400000000000000000000001641516631042000252050ustar00rootroot00000000000000// this is the actual main file 'index.js', not 'wrong.js' like the package.json would indicate module.exports = 1; browserify-resolve-7877a0d/test/resolver/incorrect_main/package.json000066400000000000000000000000331516631042000260210ustar00rootroot00000000000000{ "main": "wrong.js" } browserify-resolve-7877a0d/test/resolver/invalid_main/000077500000000000000000000000001516631042000231755ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/invalid_main/package.json000066400000000000000000000001351516631042000254620ustar00rootroot00000000000000{ "name": "invalid_main", "main": [ "why is this a thing", "srsly omg wtf" ] } browserify-resolve-7877a0d/test/resolver/malformed_package_json/000077500000000000000000000000001516631042000252155ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/malformed_package_json/index.js000066400000000000000000000000001516631042000266500ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/malformed_package_json/package.json000066400000000000000000000000021516631042000274730ustar00rootroot00000000000000{ browserify-resolve-7877a0d/test/resolver/mug.coffee000066400000000000000000000000001516631042000224720ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/mug.js000066400000000000000000000000001516631042000216570ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/multirepo/000077500000000000000000000000001516631042000225635ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/multirepo/.npmrc000066400000000000000000000000231516631042000236760ustar00rootroot00000000000000package-lock=false browserify-resolve-7877a0d/test/resolver/multirepo/lerna.json000066400000000000000000000000771516631042000245630ustar00rootroot00000000000000{ "packages": [ "packages/*" ], "version": "0.0.0" } browserify-resolve-7877a0d/test/resolver/multirepo/package.json000066400000000000000000000006031516631042000250500ustar00rootroot00000000000000{ "name": "ljharb-monorepo-symlink-test", "private": true, "version": "0.0.0", "description": "", "main": "index.js", "scripts": { "postinstall": "lerna bootstrap", "test": "node packages/package-a" }, "author": "", "license": "MIT", "dependencies": { "jquery": "^3.3.1", "resolve": "../../../" }, "devDependencies": { "lerna": "^3.4.3" } } browserify-resolve-7877a0d/test/resolver/multirepo/packages/000077500000000000000000000000001516631042000243415ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/multirepo/packages/package-a/000077500000000000000000000000001516631042000261525ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/multirepo/packages/package-a/index.js000066400000000000000000000024471516631042000276260ustar00rootroot00000000000000'use strict'; var assert = require('assert'); var path = require('path'); var resolve = require('resolve'); var basedir = __dirname + '/node_modules/@my-scope/package-b'; var expected = path.join(__dirname, '../../node_modules/jquery/dist/jquery.js'); /* * preserveSymlinks === false * will search NPM package from * - packages/package-b/node_modules * - packages/node_modules * - node_modules */ assert.equal(resolve.sync('jquery', { basedir: basedir, preserveSymlinks: false }), expected); assert.equal(resolve.sync('../../node_modules/jquery', { basedir: basedir, preserveSymlinks: false }), expected); /* * preserveSymlinks === true * will search NPM package from * - packages/package-a/node_modules/@my-scope/packages/package-b/node_modules * - packages/package-a/node_modules/@my-scope/packages/node_modules * - packages/package-a/node_modules/@my-scope/node_modules * - packages/package-a/node_modules/node_modules * - packages/package-a/node_modules * - packages/node_modules * - node_modules */ assert.equal(resolve.sync('jquery', { basedir: basedir, preserveSymlinks: true }), expected); assert.equal(resolve.sync('../../../../../node_modules/jquery', { basedir: basedir, preserveSymlinks: true }), expected); console.log(' * all monorepo paths successfully resolved through symlinks'); browserify-resolve-7877a0d/test/resolver/multirepo/packages/package-a/package.json000066400000000000000000000004311516631042000304360ustar00rootroot00000000000000{ "name": "@my-scope/package-a", "version": "0.0.0", "private": true, "description": "", "license": "MIT", "main": "index.js", "scripts": { "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { "@my-scope/package-b": "^0.0.0" } } browserify-resolve-7877a0d/test/resolver/multirepo/packages/package-b/000077500000000000000000000000001516631042000261535ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/multirepo/packages/package-b/index.js000066400000000000000000000000001516631042000276060ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/multirepo/packages/package-b/package.json000066400000000000000000000004311516631042000304370ustar00rootroot00000000000000{ "name": "@my-scope/package-b", "private": true, "version": "0.0.0", "description": "", "license": "MIT", "main": "index.js", "scripts": { "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { "@my-scope/package-a": "^0.0.0" } } browserify-resolve-7877a0d/test/resolver/nested_symlinks/000077500000000000000000000000001516631042000237565ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/nested_symlinks/common/000077500000000000000000000000001516631042000252465ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/nested_symlinks/common/node_modules/000077500000000000000000000000001516631042000277235ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/nested_symlinks/common/node_modules/buffer/000077500000000000000000000000001516631042000311745ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/nested_symlinks/common/node_modules/buffer/index.js000066400000000000000000000000311516631042000326330ustar00rootroot00000000000000module.exports = Buffer; browserify-resolve-7877a0d/test/resolver/nested_symlinks/common/node_modules/buffer/package.json000066400000000000000000000001731516631042000334630ustar00rootroot00000000000000{ "description": "fake buffer shim", "main": "index.js", "name": "buffer", "version": "0.0.0", "private": true } browserify-resolve-7877a0d/test/resolver/nested_symlinks/mylib/000077500000000000000000000000001516631042000250725ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/nested_symlinks/mylib/async.js000066400000000000000000000015161516631042000265500ustar00rootroot00000000000000var a = require.resolve('buffer/').replace(process.cwd(), '$CWD'); var b; var c; function test() { console.log(a, ': require.resolve, preserveSymlinks ' + (process.execArgv.indexOf('preserve-symlinks') > -1 ? 'true' : 'false')); console.log(b, ': preserveSymlinks true'); console.log(c, ': preserveSymlinks false'); if (a !== b && a !== c) { throw 'async: no match'; } console.log('async: success! a matched either b or c\n'); } require('resolve')('buffer/', { preserveSymlinks: true }, function (err, result) { if (err) { throw err; } b = result.replace(process.cwd(), '$CWD'); if (b && c) { test(); } }); require('resolve')('buffer/', { preserveSymlinks: false }, function (err, result) { if (err) { throw err; } c = result.replace(process.cwd(), '$CWD'); if (b && c) { test(); } }); browserify-resolve-7877a0d/test/resolver/nested_symlinks/mylib/node_modules/000077500000000000000000000000001516631042000275475ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/nested_symlinks/mylib/node_modules/buffer000077700000000000000000000000001516631042000365252../../common/node_modules/bufferustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/nested_symlinks/mylib/node_modules/resolve000077700000000000000000000000001516631042000323562../../../../..ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/nested_symlinks/mylib/package.json000066400000000000000000000004031516631042000273550ustar00rootroot00000000000000{ "name": "mylib", "version": "0.0.0", "description": "", "private": true, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "buffer": "*" } } browserify-resolve-7877a0d/test/resolver/nested_symlinks/mylib/sync.js000066400000000000000000000011361516631042000264050ustar00rootroot00000000000000var a = require.resolve('buffer/').replace(process.cwd(), '$CWD'); var b = require('resolve').sync('buffer/', { preserveSymlinks: true }).replace(process.cwd(), '$CWD'); var c = require('resolve').sync('buffer/', { preserveSymlinks: false }).replace(process.cwd(), '$CWD'); console.log(a, ': require.resolve, preserveSymlinks ' + (process.execArgv.indexOf('preserve-symlinks') > -1 ? 'true' : 'false')); console.log(b, ': preserveSymlinks true'); console.log(c, ': preserveSymlinks false'); if (a !== b && a !== c) { throw 'sync: no match'; } console.log('sync: success! a matched either b or c\n'); browserify-resolve-7877a0d/test/resolver/other_path/000077500000000000000000000000001516631042000227005ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/other_path/lib/000077500000000000000000000000001516631042000234465ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/other_path/lib/other-lib.js000066400000000000000000000000001516631042000256570ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/other_path/root.js000066400000000000000000000000001516631042000242070ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/punycode/000077500000000000000000000000001516631042000223715ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/punycode/node_modules/000077500000000000000000000000001516631042000250465ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/punycode/node_modules/punycode/000077500000000000000000000000001516631042000266745ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/punycode/node_modules/punycode/index.js000066400000000000000000000000001516631042000303270ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/quux/000077500000000000000000000000001516631042000215455ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/quux/foo/000077500000000000000000000000001516631042000223305ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/quux/foo/index.js000066400000000000000000000000241516631042000237710ustar00rootroot00000000000000module.exports = 1; browserify-resolve-7877a0d/test/resolver/same_names/000077500000000000000000000000001516631042000226535ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/same_names/foo.js000066400000000000000000000000251516631042000237710ustar00rootroot00000000000000module.exports = 42; browserify-resolve-7877a0d/test/resolver/same_names/foo/000077500000000000000000000000001516631042000234365ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/same_names/foo/index.js000066400000000000000000000000241516631042000250770ustar00rootroot00000000000000module.exports = 1; browserify-resolve-7877a0d/test/resolver/symlinked/000077500000000000000000000000001516631042000225425ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/symlinked/.gitignore000066400000000000000000000000101516631042000245210ustar00rootroot00000000000000symlink browserify-resolve-7877a0d/test/resolver/symlinked/_/000077500000000000000000000000001516631042000227605ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/symlinked/_/.gitignore000066400000000000000000000000161516631042000247450ustar00rootroot00000000000000!node_modules browserify-resolve-7877a0d/test/resolver/symlinked/_/node_modules/000077500000000000000000000000001516631042000254355ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/symlinked/_/node_modules/foo.js000066400000000000000000000000001516631042000265440ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/symlinked/_/symlink_target/000077500000000000000000000000001516631042000260145ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/symlinked/_/symlink_target/.gitkeep000066400000000000000000000000001516631042000274330ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/symlinked/package/000077500000000000000000000000001516631042000241355ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/symlinked/package/bar.js000066400000000000000000000000301516631042000252300ustar00rootroot00000000000000module.exports = 'bar'; browserify-resolve-7877a0d/test/resolver/symlinked/package/package.json000066400000000000000000000000301516631042000264140ustar00rootroot00000000000000{ "main": "bar.js" }browserify-resolve-7877a0d/test/resolver/without_basedir/000077500000000000000000000000001516631042000237375ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/without_basedir/main.js000066400000000000000000000001571516631042000252240ustar00rootroot00000000000000var resolve = require('../../../'); module.exports = function (t, cb) { resolve('mymodule', null, cb); }; browserify-resolve-7877a0d/test/resolver/without_basedir/node_modules/000077500000000000000000000000001516631042000264145ustar00rootroot00000000000000browserify-resolve-7877a0d/test/resolver/without_basedir/node_modules/mymodule.js000066400000000000000000000002351516631042000306050ustar00rootroot00000000000000module.exports = "The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities.- E. Dijkstra" browserify-resolve-7877a0d/test/resolver_sync.js000066400000000000000000000506711516631042000221460ustar00rootroot00000000000000var path = require('path'); var fs = require('fs'); var test = require('tape'); var resolve = require('../'); var sync = require('../sync'); var requireResolveSupportsPaths = require.resolve.length > 1 && !(/^v12\.[012]\./).test(process.version); // broken in v12.0-12.2, see https://github.com/nodejs/node/issues/27794 var requireResolveDefaultPathsBroken = (/^v8\.9\.|^v9\.[01]\.0|^v9\.2\./).test(process.version); // broken in node v8.9.x, v9.0, v9.1, v9.2.x. see https://github.com/nodejs/node/pull/17113 test('`./sync` entry point', function (t) { t.equal(resolve.sync, sync, '`./sync` entry point is the same as `.sync` on `main`'); t.end(); }); test('foo', function (t) { var dir = path.join(__dirname, 'resolver'); t.equal( resolve.sync('./foo', { basedir: dir }), path.join(dir, 'foo.js'), './foo' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./foo', { basedir: dir }), require.resolve('./foo', { paths: [dir] }), './foo: resolve.sync === require.resolve' ); } t.equal( resolve.sync('./foo.js', { basedir: dir }), path.join(dir, 'foo.js'), './foo.js' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./foo.js', { basedir: dir }), require.resolve('./foo.js', { paths: [dir] }), './foo.js: resolve.sync === require.resolve' ); } t.equal( resolve.sync('./foo.js', { basedir: dir, filename: path.join(dir, 'bar.js') }), path.join(dir, 'foo.js') ); t.throws(function () { resolve.sync('foo', { basedir: dir }); }); // Test that filename is reported as the "from" value when passed. t.throws( function () { resolve.sync('foo', { basedir: dir, filename: path.join(dir, 'bar.js') }); }, { name: 'Error', message: "Cannot find module 'foo' from '" + path.join(dir, 'bar.js') + "'" } ); t.end(); }); test('bar', function (t) { var dir = path.join(__dirname, 'resolver'); var basedir = path.join(dir, 'bar'); t.equal( resolve.sync('foo', { basedir: basedir }), path.join(dir, 'bar/node_modules/foo/index.js'), 'foo in bar' ); if (!requireResolveDefaultPathsBroken && requireResolveSupportsPaths) { t.equal( resolve.sync('foo', { basedir: basedir }), require.resolve('foo', { paths: [basedir] }), 'foo in bar: resolve.sync === require.resolve' ); } t.end(); }); test('baz', function (t) { var dir = path.join(__dirname, 'resolver'); t.equal( resolve.sync('./baz', { basedir: dir }), path.join(dir, 'baz/quux.js'), './baz' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./baz', { basedir: dir }), require.resolve('./baz', { paths: [dir] }), './baz: resolve.sync === require.resolve' ); } t.end(); }); test('biz', function (t) { var dir = path.join(__dirname, 'resolver/biz/node_modules'); t.equal( resolve.sync('./grux', { basedir: dir }), path.join(dir, 'grux/index.js') ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./grux', { basedir: dir }), require.resolve('./grux', { paths: [dir] }), './grux: resolve.sync === require.resolve' ); } var tivDir = path.join(dir, 'grux'); t.equal( resolve.sync('tiv', { basedir: tivDir }), path.join(dir, 'tiv/index.js') ); if (!requireResolveDefaultPathsBroken && requireResolveSupportsPaths) { t.equal( resolve.sync('tiv', { basedir: tivDir }), require.resolve('tiv', { paths: [tivDir] }), 'tiv: resolve.sync === require.resolve' ); } var gruxDir = path.join(dir, 'tiv'); t.equal( resolve.sync('grux', { basedir: gruxDir }), path.join(dir, 'grux/index.js') ); if (!requireResolveDefaultPathsBroken && requireResolveSupportsPaths) { t.equal( resolve.sync('grux', { basedir: gruxDir }), require.resolve('grux', { paths: [gruxDir] }), 'grux: resolve.sync === require.resolve' ); } t.end(); }); test('normalize', function (t) { var dir = path.join(__dirname, 'resolver/biz/node_modules/grux'); t.equal( resolve.sync('../grux', { basedir: dir }), path.join(dir, 'index.js') ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('../grux', { basedir: dir }), require.resolve('../grux', { paths: [dir] }), '../grux: resolve.sync === require.resolve' ); } t.end(); }); test('cup', function (t) { var dir = path.join(__dirname, 'resolver'); t.equal( resolve.sync('./cup', { basedir: dir, extensions: ['.js', '.coffee'] }), path.join(dir, 'cup.coffee'), './cup -> ./cup.coffee' ); t.equal( resolve.sync('./cup.coffee', { basedir: dir }), path.join(dir, 'cup.coffee'), './cup.coffee' ); t.throws(function () { resolve.sync('./cup', { basedir: dir, extensions: ['.js'] }); }); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./cup.coffee', { basedir: dir, extensions: ['.js', '.coffee'] }), require.resolve('./cup.coffee', { paths: [dir] }), './cup.coffee: resolve.sync === require.resolve' ); } t.end(); }); test('mug', function (t) { var dir = path.join(__dirname, 'resolver'); t.equal( resolve.sync('./mug', { basedir: dir }), path.join(dir, 'mug.js'), './mug -> ./mug.js' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./mug', { basedir: dir }), require.resolve('./mug', { paths: [dir] }), './mug: resolve.sync === require.resolve' ); } t.equal( resolve.sync('./mug', { basedir: dir, extensions: ['.coffee', '.js'] }), path.join(dir, 'mug.coffee'), './mug -> ./mug.coffee' ); t.equal( resolve.sync('./mug', { basedir: dir, extensions: ['.js', '.coffee'] }), path.join(dir, 'mug.js'), './mug -> ./mug.js' ); t.end(); }); test('other path', function (t) { var resolverDir = path.join(__dirname, 'resolver'); var dir = path.join(resolverDir, 'bar'); var otherDir = path.join(resolverDir, 'other_path'); t.equal( resolve.sync('root', { basedir: dir, paths: [otherDir] }), path.join(resolverDir, 'other_path/root.js') ); t.equal( resolve.sync('lib/other-lib', { basedir: dir, paths: [otherDir] }), path.join(resolverDir, 'other_path/lib/other-lib.js') ); t.throws(function () { resolve.sync('root', { basedir: dir }); }); t.throws(function () { resolve.sync('zzz', { basedir: dir, paths: [otherDir] }); }); t.end(); }); test('path iterator', function (t) { var resolverDir = path.join(__dirname, 'resolver'); function exactIterator(x, start, getPackageCandidates, opts) { return [path.join(resolverDir, x)]; } t.equal( resolve.sync('baz', { packageIterator: exactIterator }), path.join(resolverDir, 'baz/quux.js') ); t.end(); }); test('incorrect main', function (t) { var resolverDir = path.join(__dirname, 'resolver'); var dir = path.join(resolverDir, 'incorrect_main'); t.equal( resolve.sync('./incorrect_main', { basedir: resolverDir }), path.join(dir, 'index.js') ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./incorrect_main', { basedir: resolverDir }), require.resolve('./incorrect_main', { paths: [resolverDir] }), './incorrect_main: resolve.sync === require.resolve' ); } t.end(); }); test('missing index', function (t) { t.plan(requireResolveSupportsPaths ? 2 : 1); var resolverDir = path.join(__dirname, 'resolver'); try { resolve.sync('./missing_index', { basedir: resolverDir }); t.fail('did not fail'); } catch (err) { t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code'); } if (requireResolveSupportsPaths) { try { require.resolve('./missing_index', { basedir: resolverDir }); t.fail('require.resolve did not fail'); } catch (err) { t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code'); } } }); test('missing main', function (t) { var resolverDir = path.join(__dirname, 'resolver'); try { resolve.sync('./missing_main', { basedir: resolverDir }); t.fail('require.resolve did not fail'); } catch (err) { t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code'); } if (requireResolveSupportsPaths) { try { resolve.sync('./missing_main', { basedir: resolverDir }); t.fail('require.resolve did not fail'); } catch (err) { t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code'); } } t.end(); }); test('null main', function (t) { var resolverDir = path.join(__dirname, 'resolver'); try { resolve.sync('./null_main', { basedir: resolverDir }); t.fail('require.resolve did not fail'); } catch (err) { t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code'); } if (requireResolveSupportsPaths) { try { resolve.sync('./null_main', { basedir: resolverDir }); t.fail('require.resolve did not fail'); } catch (err) { t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code'); } } t.end(); }); test('main: false', function (t) { var basedir = path.join(__dirname, 'resolver'); var dir = path.join(basedir, 'false_main'); t.equal( resolve.sync('./false_main', { basedir: basedir }), path.join(dir, 'index.js'), '`"main": false`: resolves to `index.js`' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./false_main', { basedir: basedir }), require.resolve('./false_main', { paths: [basedir] }), '`"main": false`: resolve.sync === require.resolve' ); } t.end(); }); function stubStatSync(fn) { var statSync = fs.statSync; try { fs.statSync = function () { throw new EvalError('Unknown Error'); }; return fn(); } finally { fs.statSync = statSync; } } test('#79 - re-throw non ENOENT errors from stat', function (t) { var dir = path.join(__dirname, 'resolver'); stubStatSync(function () { t.throws(function () { resolve.sync('foo', { basedir: dir }); }, /Unknown Error/); }); t.end(); }); test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) { var dir = path.join(__dirname, 'resolver'); var basedir = path.join(dir, 'same_names'); t.equal( resolve.sync('./foo', { basedir: basedir }), path.join(dir, 'same_names/foo.js') ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./foo', { basedir: basedir }), require.resolve('./foo', { paths: [basedir] }), './foo: resolve.sync === require.resolve' ); } t.equal( resolve.sync('./foo/', { basedir: basedir }), path.join(dir, 'same_names/foo/index.js') ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./foo/', { basedir: basedir }), require.resolve('./foo/', { paths: [basedir] }), './foo/: resolve.sync === require.resolve' ); } t.end(); }); test('#211 - incorrectly resolves module-paths like "." when from inside a folder with a sibling file of the same name', function (t) { var dir = path.join(__dirname, 'resolver'); var basedir = path.join(dir, 'same_names/foo'); t.equal( resolve.sync('./', { basedir: basedir }), path.join(dir, 'same_names/foo/index.js'), './' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./', { basedir: basedir }), require.resolve('./', { paths: [basedir] }), './: resolve.sync === require.resolve' ); } t.equal( resolve.sync('.', { basedir: basedir }), path.join(dir, 'same_names/foo/index.js'), '.' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('.', { basedir: basedir }), require.resolve('.', { paths: [basedir] }), '.: resolve.sync === require.resolve', { todo: true } ); } t.end(); }); test('sync: #121 - treating an existing file as a dir when no basedir', function (t) { var testFile = path.basename(__filename); t.test('sanity check', function (st) { st.equal( resolve.sync('./' + testFile), __filename, 'sanity check' ); st.equal( resolve.sync('./' + testFile), require.resolve('./' + testFile), 'sanity check: resolve.sync === require.resolve' ); st.end(); }); t.test('with a fake directory', function (st) { function run() { return resolve.sync('./' + testFile + '/blah'); } st.throws(run, 'throws an error'); try { run(); } catch (e) { st.equal(e.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve'); st.equal( e.message, 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'', 'can not find nonexistent module' ); } st.end(); }); t.end(); }); test('sync dot main', function (t) { var start = new Date(); t.equal( resolve.sync('./resolver/dot_main'), path.join(__dirname, 'resolver/dot_main/index.js'), './resolver/dot_main' ); t.equal( resolve.sync('./resolver/dot_main'), require.resolve('./resolver/dot_main'), './resolver/dot_main: resolve.sync === require.resolve' ); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); test('sync dot slash main', function (t) { var start = new Date(); t.equal( resolve.sync('./resolver/dot_slash_main'), path.join(__dirname, 'resolver/dot_slash_main/index.js') ); t.equal( resolve.sync('./resolver/dot_slash_main'), require.resolve('./resolver/dot_slash_main'), './resolver/dot_slash_main: resolve.sync === require.resolve' ); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); test('not a directory', function (t) { var path = './foo'; try { resolve.sync(path, { basedir: __filename }); t.fail(); } catch (err) { t.ok(err, 'a non-directory errors'); t.equal(err && err.message, 'Cannot find module \'' + path + "' from '" + __filename + "'"); t.equal(err && err.code, 'MODULE_NOT_FOUND'); } t.end(); }); test('non-string "main" field in package.json', function (t) { var dir = path.join(__dirname, 'resolver'); try { var result = resolve.sync('./invalid_main', { basedir: dir }); t.equal(result, undefined, 'result should not exist'); t.fail('should not get here'); } catch (err) { t.ok(err, 'errors on non-string main'); t.equal(err.message, 'package “invalid_main” `main` must be a string'); t.equal(err.code, 'INVALID_PACKAGE_MAIN'); } t.end(); }); test('non-string "main" field in package.json', function (t) { var dir = path.join(__dirname, 'resolver'); try { var result = resolve.sync('./invalid_main', { basedir: dir }); t.equal(result, undefined, 'result should not exist'); t.fail('should not get here'); } catch (err) { t.ok(err, 'errors on non-string main'); t.equal(err.message, 'package “invalid_main” `main` must be a string'); t.equal(err.code, 'INVALID_PACKAGE_MAIN'); } t.end(); }); test('browser field in package.json', function (t) { var dir = path.join(__dirname, 'resolver'); var res = resolve.sync('./browser_field', { basedir: dir, packageFilter: function packageFilter(pkg) { if (pkg.browser) { pkg.main = pkg.browser; // eslint-disable-line no-param-reassign delete pkg.browser; // eslint-disable-line no-param-reassign } return pkg; } }); t.equal(res, path.join(dir, 'browser_field', 'b.js')); t.end(); }); test('absolute paths', function (t) { var extensionless = __filename.slice(0, -path.extname(__filename).length); t.equal( resolve.sync(__filename), __filename, 'absolute path to this file resolves' ); t.equal( resolve.sync(__filename), require.resolve(__filename), 'absolute path to this file: resolve.sync === require.resolve' ); t.equal( resolve.sync(extensionless), __filename, 'extensionless absolute path to this file resolves' ); t.equal( resolve.sync(__filename), require.resolve(__filename), 'absolute path to this file: resolve.sync === require.resolve' ); t.equal( resolve.sync(__filename, { basedir: process.cwd() }), __filename, 'absolute path to this file with a basedir resolves' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync(__filename, { basedir: process.cwd() }), require.resolve(__filename, { paths: [process.cwd()] }), 'absolute path to this file + basedir: resolve.sync === require.resolve' ); } t.equal( resolve.sync(extensionless, { basedir: process.cwd() }), __filename, 'extensionless absolute path to this file with a basedir resolves' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync(extensionless, { basedir: process.cwd() }), require.resolve(extensionless, { paths: [process.cwd()] }), 'extensionless absolute path to this file + basedir: resolve.sync === require.resolve' ); } t.end(); }); var malformedDir = path.join(__dirname, 'resolver/malformed_package_json'); test('malformed package.json', { skip: !fs.existsSync(malformedDir) }, function (t) { t.plan(5 + (requireResolveSupportsPaths ? 1 : 0)); var basedir = malformedDir; var expected = path.join(basedir, 'index.js'); t.equal( resolve.sync('./index.js', { basedir: basedir }), expected, 'malformed package.json is silently ignored' ); if (requireResolveSupportsPaths) { t.equal( resolve.sync('./index.js', { basedir: basedir }), require.resolve('./index.js', { paths: [basedir] }), 'malformed package.json: resolve.sync === require.resolve' ); } var res1 = resolve.sync( './index.js', { basedir: basedir, packageFilter: function (pkg, pkgfile, dir) { t.fail('should not reach here'); } } ); t.equal( res1, expected, 'with packageFilter: malformed package.json is silently ignored' ); var res2 = resolve.sync( './index.js', { basedir: basedir, readPackageSync: function (readFileSync, pkgfile) { t.equal(pkgfile, path.join(basedir, 'package.json'), 'readPackageSync: `pkgfile` is package.json path'); var result = String(readFileSync(pkgfile)); try { return JSON.parse(result); } catch (e) { t.ok(e instanceof SyntaxError, 'readPackageSync: malformed package.json parses as a syntax error'); } } } ); t.equal( res2, expected, 'with readPackageSync: malformed package.json is silently ignored' ); }); browserify-resolve-7877a0d/test/shadowed_core.js000066400000000000000000000034261516631042000220530ustar00rootroot00000000000000var test = require('tape'); var resolve = require('../'); var path = require('path'); test('shadowed core modules still return core module', function (t) { t.plan(2); resolve('util', { basedir: path.join(__dirname, 'shadowed_core') }, function (err, res) { t.ifError(err); t.equal(res, 'util'); }); }); test('shadowed core modules still return core module [sync]', function (t) { t.plan(1); var res = resolve.sync('util', { basedir: path.join(__dirname, 'shadowed_core') }); t.equal(res, 'util'); }); test('shadowed core modules return shadow when appending `/`', function (t) { t.plan(2); resolve('util/', { basedir: path.join(__dirname, 'shadowed_core') }, function (err, res) { t.ifError(err); t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js')); }); }); test('shadowed core modules return shadow when appending `/` [sync]', function (t) { t.plan(1); var res = resolve.sync('util/', { basedir: path.join(__dirname, 'shadowed_core') }); t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js')); }); test('shadowed core modules return shadow with `includeCoreModules: false`', function (t) { t.plan(2); resolve('util', { basedir: path.join(__dirname, 'shadowed_core'), includeCoreModules: false }, function (err, res) { t.ifError(err); t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js')); }); }); test('shadowed core modules return shadow with `includeCoreModules: false` [sync]', function (t) { t.plan(1); var res = resolve.sync('util', { basedir: path.join(__dirname, 'shadowed_core'), includeCoreModules: false }); t.equal(res, path.join(__dirname, 'shadowed_core/node_modules/util/index.js')); }); browserify-resolve-7877a0d/test/shadowed_core/000077500000000000000000000000001516631042000215105ustar00rootroot00000000000000browserify-resolve-7877a0d/test/shadowed_core/.gitignore000066400000000000000000000000171516631042000234760ustar00rootroot00000000000000!/node_modules browserify-resolve-7877a0d/test/shadowed_core/node_modules/000077500000000000000000000000001516631042000241655ustar00rootroot00000000000000browserify-resolve-7877a0d/test/shadowed_core/node_modules/util/000077500000000000000000000000001516631042000251425ustar00rootroot00000000000000browserify-resolve-7877a0d/test/shadowed_core/node_modules/util/index.js000066400000000000000000000000001516631042000265750ustar00rootroot00000000000000browserify-resolve-7877a0d/test/subdirs.js000066400000000000000000000005411516631042000207130ustar00rootroot00000000000000var test = require('tape'); var resolve = require('../'); var path = require('path'); test('subdirs', function (t) { t.plan(2); var dir = path.join(__dirname, '/subdirs'); resolve('a/b/c/x.json', { basedir: dir }, function (err, res) { t.ifError(err); t.equal(res, path.join(dir, 'node_modules/a/b/c/x.json')); }); }); browserify-resolve-7877a0d/test/subdirs/000077500000000000000000000000001516631042000203555ustar00rootroot00000000000000browserify-resolve-7877a0d/test/subdirs/node_modules/000077500000000000000000000000001516631042000230325ustar00rootroot00000000000000browserify-resolve-7877a0d/test/subdirs/node_modules/a/000077500000000000000000000000001516631042000232525ustar00rootroot00000000000000browserify-resolve-7877a0d/test/subdirs/node_modules/a/b/000077500000000000000000000000001516631042000234735ustar00rootroot00000000000000browserify-resolve-7877a0d/test/subdirs/node_modules/a/b/c/000077500000000000000000000000001516631042000237155ustar00rootroot00000000000000browserify-resolve-7877a0d/test/subdirs/node_modules/a/b/c/x.json000066400000000000000000000000101516631042000250460ustar00rootroot00000000000000[1,2,3] browserify-resolve-7877a0d/test/subdirs/node_modules/a/package.json000066400000000000000000000000031516631042000255310ustar00rootroot00000000000000{} browserify-resolve-7877a0d/test/symlinks.js000066400000000000000000000146071516631042000211210ustar00rootroot00000000000000var path = require('path'); var fs = require('fs'); var test = require('tape'); var map = require('array.prototype.map'); var resolve = require('../'); var symlinkDir = path.join(__dirname, 'resolver', 'symlinked', 'symlink'); var packageDir = path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'package'); var modADir = path.join(__dirname, 'symlinks', 'source', 'node_modules', 'mod-a'); var symlinkModADir = path.join(__dirname, 'symlinks', 'dest', 'node_modules', 'mod-a'); try { fs.unlinkSync(symlinkDir); } catch (err) {} try { fs.unlinkSync(packageDir); } catch (err) {} try { fs.unlinkSync(modADir); } catch (err) {} try { fs.unlinkSync(symlinkModADir); } catch (err) {} try { fs.symlinkSync('./_/symlink_target', symlinkDir, 'dir'); } catch (err) { // if fails then it is probably on Windows and lets try to create a junction fs.symlinkSync(path.join(__dirname, 'resolver', 'symlinked', '_', 'symlink_target') + '\\', symlinkDir, 'junction'); } try { fs.symlinkSync('../../package', packageDir, 'dir'); } catch (err) { // if fails then it is probably on Windows and lets try to create a junction fs.symlinkSync(path.join(__dirname, '..', '..', 'package') + '\\', packageDir, 'junction'); } try { fs.symlinkSync('../../source/node_modules/mod-a', symlinkModADir, 'dir'); } catch (err) { // if fails then it is probably on Windows and lets try to create a junction fs.symlinkSync(path.join(__dirname, '..', '..', 'source', 'node_modules', 'mod-a') + '\\', symlinkModADir, 'junction'); } test('symlink', function (t) { t.plan(2); resolve('foo', { basedir: symlinkDir, preserveSymlinks: false }, function (err, res, pkg) { t.error(err); t.equal(res, path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js')); }); }); test('sync symlink when preserveSymlinks = true', function (t) { t.plan(4); resolve('foo', { basedir: symlinkDir }, function (err, res, pkg) { t.ok(err, 'there is an error'); t.notOk(res, 'no result'); t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve'); t.equal( err && err.message, 'Cannot find module \'foo\' from \'' + symlinkDir + '\'', 'can not find nonexistent module' ); }); }); test('sync symlink', function (t) { var start = new Date(); t.doesNotThrow(function () { t.equal( resolve.sync('foo', { basedir: symlinkDir, preserveSymlinks: false }), path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js') ); }); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); test('sync symlink when preserveSymlinks = true', function (t) { t.throws(function () { resolve.sync('foo', { basedir: symlinkDir }); }, /Cannot find module 'foo'/); t.end(); }); test('sync symlink from node_modules to other dir when preserveSymlinks = false', function (t) { var basedir = path.join(__dirname, 'resolver', 'symlinked', '_'); var fn = resolve.sync('package', { basedir: basedir, preserveSymlinks: false }); t.equal(fn, path.resolve(__dirname, 'resolver/symlinked/package/bar.js')); t.end(); }); test('async symlink from node_modules to other dir when preserveSymlinks = false', function (t) { t.plan(2); var basedir = path.join(__dirname, 'resolver', 'symlinked', '_'); resolve('package', { basedir: basedir, preserveSymlinks: false }, function (err, result) { t.notOk(err, 'no error'); t.equal(result, path.resolve(__dirname, 'resolver/symlinked/package/bar.js')); }); }); test('packageFilter', function (t) { function relative(x) { return path.relative(__dirname, x); } function testPackageFilter(preserveSymlinks) { return function (st) { st.plan('is 1.x' ? 3 : 5); // eslint-disable-line no-constant-condition var destMain = 'symlinks/dest/node_modules/mod-a/index.js'; var destPkg = 'symlinks/dest/node_modules/mod-a/package.json'; var sourceMain = 'symlinks/source/node_modules/mod-a/index.js'; var sourcePkg = 'symlinks/source/node_modules/mod-a/package.json'; var destDir = path.join(__dirname, 'symlinks', 'dest'); /* eslint multiline-comment-style: 0 */ /* v2.x will restore these tests var packageFilterPath = []; var actualPath = resolve.sync('mod-a', { basedir: destDir, preserveSymlinks: preserveSymlinks, packageFilter: function (pkg, pkgfile, dir) { packageFilterPath.push(pkgfile); } }); st.equal( relative(actualPath), path.normalize(preserveSymlinks ? destMain : sourceMain), 'sync: actual path is correct' ); st.deepEqual( map(packageFilterPath, relative), map(preserveSymlinks ? [destPkg, destPkg] : [sourcePkg, sourcePkg], path.normalize), 'sync: packageFilter pkgfile arg is correct' ); */ var asyncPackageFilterPath = []; resolve( 'mod-a', { basedir: destDir, preserveSymlinks: preserveSymlinks, packageFilter: function (pkg, pkgfile) { asyncPackageFilterPath.push(pkgfile); } }, function (err, actualPath) { st.error(err, 'no error'); st.equal( relative(actualPath), path.normalize(preserveSymlinks ? destMain : sourceMain), 'async: actual path is correct' ); st.deepEqual( map(asyncPackageFilterPath, relative), map( preserveSymlinks ? [destPkg, destPkg, destPkg] : [sourcePkg, sourcePkg, sourcePkg], path.normalize ), 'async: packageFilter pkgfile arg is correct' ); } ); }; } t.test('preserveSymlinks: false', testPackageFilter(false)); t.test('preserveSymlinks: true', testPackageFilter(true)); t.end(); }); browserify-resolve-7877a0d/test/symlinks/000077500000000000000000000000001516631042000205535ustar00rootroot00000000000000browserify-resolve-7877a0d/test/symlinks/dest/000077500000000000000000000000001516631042000215125ustar00rootroot00000000000000browserify-resolve-7877a0d/test/symlinks/dest/node_modules/000077500000000000000000000000001516631042000241675ustar00rootroot00000000000000browserify-resolve-7877a0d/test/symlinks/dest/node_modules/mod-a000077700000000000000000000000001516631042000324252../../source/node_modules/mod-austar00rootroot00000000000000browserify-resolve-7877a0d/test/symlinks/source/000077500000000000000000000000001516631042000220535ustar00rootroot00000000000000browserify-resolve-7877a0d/test/symlinks/source/node_modules/000077500000000000000000000000001516631042000245305ustar00rootroot00000000000000browserify-resolve-7877a0d/test/symlinks/source/node_modules/mod-a/000077500000000000000000000000001516631042000255255ustar00rootroot00000000000000browserify-resolve-7877a0d/test/symlinks/source/node_modules/mod-a/index.js000066400000000000000000000000441516631042000271700ustar00rootroot00000000000000'use strict'; module.exports = 42; browserify-resolve-7877a0d/test/symlinks/source/node_modules/mod-a/package.json000066400000000000000000000000041516631042000300050ustar00rootroot00000000000000{ }