├── .cargo └── config.toml ├── .editorconfig ├── .github ├── CODE_OF_CONDUCT.md ├── SECURITY.md ├── actions │ └── pnpm │ │ └── action.yml ├── codecov.yml └── workflows │ ├── autofix.yml │ ├── benchmark.yml │ ├── ci.yml │ ├── codecov.yml │ ├── deny.yml │ ├── release-napi.yml │ ├── release-plz.yml │ └── zizmor.yml ├── .gitignore ├── .node-version ├── .rustfmt.toml ├── .typos.toml ├── CHANGELOG.md ├── CHANGELOG_OLD.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── benches └── resolver.rs ├── cliff.toml ├── deny.toml ├── dprint.json ├── examples └── resolver.rs ├── fixtures ├── dot │ ├── foo.js │ └── foo │ │ ├── foo.js │ │ └── index.js ├── dual-condition-names │ └── package.json ├── enhanced_resolve │ ├── lib │ │ └── index.js │ ├── package.json │ └── test │ │ ├── .gitignore │ │ └── fixtures │ │ ├── # │ │ └── a.js │ │ ├── a.js │ │ ├── abc.txt │ │ ├── alias │ │ └── files │ │ │ └── a.js │ │ ├── b.js │ │ ├── browser-module │ │ ├── browser │ │ │ └── module-a.js │ │ ├── lib │ │ │ ├── browser.js │ │ │ ├── ignore.js │ │ │ ├── main.js │ │ │ ├── replaced.js │ │ │ ├── self.js │ │ │ └── toString.js │ │ ├── node_modules │ │ │ ├── module-a.js │ │ │ ├── module-b.js │ │ │ ├── module-c.js │ │ │ └── recursive-file │ │ │ │ ├── a.js │ │ │ │ ├── b.js │ │ │ │ ├── c.js │ │ │ │ ├── d.js │ │ │ │ └── package.json │ │ └── package.json │ │ ├── builtins │ │ └── package.json │ │ ├── c.js │ │ ├── complex.js │ │ ├── crypto-js │ │ ├── index.js │ │ └── package.json │ │ ├── decorated-fs │ │ └── exists.js │ │ ├── dirOrFile.js │ │ ├── dirOrFile │ │ └── index.js │ │ ├── directory-default │ │ └── directory-default.js │ │ ├── exports-field-and-extension-alias │ │ └── node_modules │ │ │ ├── @org │ │ │ └── pkg │ │ │ │ ├── dist │ │ │ │ ├── string.js │ │ │ │ └── string.test.d.ts │ │ │ │ └── package.json │ │ │ └── pkg │ │ │ ├── dist │ │ │ ├── string.js │ │ │ └── string.test.d.ts │ │ │ └── package.json │ │ ├── exports-field-error │ │ └── node_modules │ │ │ ├── exports-field │ │ │ └── package.json │ │ │ └── pack1 │ │ │ └── index.js │ │ ├── exports-field │ │ ├── a.js │ │ ├── node_modules │ │ │ ├── exports-field │ │ │ │ ├── lib │ │ │ │ │ ├── browser.js │ │ │ │ │ ├── index.js │ │ │ │ │ ├── lib2 │ │ │ │ │ │ └── main.js │ │ │ │ │ └── main.js │ │ │ │ ├── main.js │ │ │ │ ├── package.json │ │ │ │ └── x.js │ │ │ └── invalid-exports-field │ │ │ │ ├── index.js │ │ │ │ ├── package.json │ │ │ │ └── umd.js │ │ └── package.json │ │ ├── exports-field2 │ │ └── node_modules │ │ │ └── exports-field │ │ │ ├── index.js │ │ │ ├── lib │ │ │ ├── browser.js │ │ │ ├── lib2 │ │ │ │ └── main.js │ │ │ └── main.js │ │ │ ├── main.js │ │ │ └── package.json │ │ ├── exports-field3 │ │ └── node_modules │ │ │ └── exports-field │ │ │ ├── index │ │ │ ├── main.js │ │ │ ├── package.json │ │ │ └── src │ │ │ └── index.js │ │ ├── extension-alias │ │ ├── dir │ │ │ ├── index.js │ │ │ └── index.ts │ │ ├── dir2 │ │ │ ├── index.js │ │ │ └── index.mts │ │ ├── index.js │ │ ├── index.mjs │ │ ├── index.mts.js │ │ └── index.ts │ │ ├── extensions │ │ ├── app.module.js │ │ ├── bar.d.ts │ │ ├── dir │ │ │ ├── index.js │ │ │ └── index.ts │ │ ├── foo.js │ │ ├── foo.ts │ │ ├── index.js │ │ ├── index.ts │ │ ├── node_modules │ │ │ ├── module.js │ │ │ └── module │ │ │ │ └── index.ts │ │ └── package.json │ │ ├── file.load1 │ │ ├── file.load2 │ │ ├── foo │ │ ├── index.js │ │ └── package.json │ │ ├── imports-exports-wildcard │ │ └── node_modules │ │ │ └── m │ │ │ ├── package.json │ │ │ └── src │ │ │ ├── features │ │ │ ├── f.js │ │ │ ├── internal │ │ │ │ └── file.js │ │ │ └── y │ │ │ │ └── y.js │ │ │ ├── internal │ │ │ └── i.js │ │ │ ├── middle-1 │ │ │ ├── f.js │ │ │ └── nested │ │ │ │ └── f.js │ │ │ ├── middle-2 │ │ │ └── nested │ │ │ │ └── f.js │ │ │ ├── middle-3 │ │ │ └── nested │ │ │ │ └── f │ │ │ │ └── nested │ │ │ │ └── f.js │ │ │ ├── middle-4 │ │ │ └── f │ │ │ │ └── f.js │ │ │ ├── middle-5 │ │ │ ├── f$ │ │ │ │ └── $.js │ │ │ └── f │ │ │ │ └── $.js │ │ │ └── middle │ │ │ ├── f.js │ │ │ └── nested │ │ │ └── f.js │ │ ├── imports-field │ │ ├── a.js │ │ ├── b.js │ │ ├── dir │ │ │ └── b.js │ │ ├── node_modules │ │ │ ├── a │ │ │ │ ├── lib │ │ │ │ │ ├── browser.js │ │ │ │ │ ├── index.js │ │ │ │ │ ├── lib2 │ │ │ │ │ │ └── main.js │ │ │ │ │ └── main.js │ │ │ │ ├── main.js │ │ │ │ ├── package.json │ │ │ │ └── x.js │ │ │ └── c │ │ │ │ └── index.js │ │ └── package.json │ │ ├── incorrect-package │ │ ├── pack1 │ │ │ ├── a.js │ │ │ └── package.json │ │ └── pack2 │ │ │ ├── a.js │ │ │ └── package.json │ │ ├── issue-238 │ │ ├── package.json │ │ └── src │ │ │ ├── a │ │ │ └── config.js │ │ │ └── common │ │ │ └── config │ │ │ └── myObjectFile.js │ │ ├── lib.js │ │ ├── lib │ │ └── complex1.js │ │ ├── main-field-self │ │ ├── index.js │ │ └── package.json │ │ ├── main-field-self2 │ │ ├── index.js │ │ └── package.json │ │ ├── main1.js │ │ ├── main2.js │ │ ├── main3.js │ │ ├── multiple_modules │ │ └── node_modules │ │ │ └── m1 │ │ │ └── a.js │ │ ├── no#fragment │ │ └── # │ │ │ └── #.js │ │ ├── no.js │ │ ├── node_modules │ │ ├── browser-module-broken │ │ │ ├── browser.js │ │ │ ├── main.js │ │ │ └── package.json │ │ ├── complexm │ │ │ ├── node_modules │ │ │ │ └── m1 │ │ │ │ │ ├── a.js │ │ │ │ │ └── index.js │ │ │ ├── step1.js │ │ │ └── step2.js │ │ ├── dash-name │ │ │ ├── index.js │ │ │ └── package.json │ │ ├── dash │ │ │ ├── index.js │ │ │ └── package.json │ │ ├── invalidPackageJson │ │ │ └── package.json │ │ ├── m1 │ │ │ ├── a.js │ │ │ └── b.js │ │ ├── m2 │ │ │ └── b.js │ │ └── recursive-module │ │ │ ├── file.js │ │ │ └── index.js │ │ ├── pnp-a │ │ └── m2 │ │ │ └── a.js │ │ ├── pnp │ │ ├── pkg │ │ │ ├── dir │ │ │ │ └── index.js │ │ │ ├── index.js │ │ │ ├── main.js │ │ │ ├── package-alias │ │ │ │ ├── browser.js │ │ │ │ └── index.js │ │ │ ├── package.json │ │ │ └── typescript │ │ │ │ └── index.ts │ │ └── pkg3 │ │ │ ├── a.js │ │ │ └── package.json │ │ ├── prefer-pnp │ │ └── alternative-modules │ │ │ └── m1 │ │ │ └── b.js │ │ ├── restrictions │ │ └── node_modules │ │ │ ├── pck1 │ │ │ ├── index.css │ │ │ ├── index.js │ │ │ └── package.json │ │ │ └── pck2 │ │ │ ├── index.css │ │ │ ├── module.js │ │ │ └── package.json │ │ ├── roots_fall_through │ │ └── index.js │ │ ├── scoped │ │ └── node_modules │ │ │ └── @scope │ │ │ ├── pack1 │ │ │ ├── main.js │ │ │ └── package.json │ │ │ └── pack2 │ │ │ ├── lib │ │ │ └── index.js │ │ │ ├── main.js │ │ │ └── package.json │ │ ├── shortcutdir.js │ │ └── a.js │ │ ├── yield │ │ ├── a │ │ │ ├── foo-2 │ │ │ │ ├── b │ │ │ │ └── c │ │ │ └── foo │ │ │ │ ├── a │ │ │ │ └── b │ │ ├── b │ │ │ └── foo │ │ │ │ └── a │ │ └── c │ │ │ └── foo │ │ │ ├── a │ │ │ └── package.json │ │ └── 测试.js ├── invalid │ └── node_modules │ │ ├── a │ │ ├── dist │ │ │ └── index.js │ │ └── package.json │ │ └── main_field_fallback │ │ ├── exist.js │ │ └── package.json ├── misc │ ├── dir-with-index │ │ └── index.js │ ├── package-json-with-bom │ │ ├── index.js │ │ └── package.json │ └── 中文 │ │ └── 中文.js ├── nested-symlink │ ├── apps │ │ ├── tooling │ │ └── web │ │ │ └── nm │ │ │ └── @repo │ │ │ ├── index.js │ │ │ └── typescript-config │ ├── nm │ │ └── index.js │ └── tooling │ │ └── typescript-config │ │ └── index.js ├── pnp │ ├── .gitignore │ ├── .yarnrc.yml │ ├── package.json │ ├── shared │ │ └── lib.js │ └── yarn.lock ├── pnpm-workspace │ ├── .gitignore │ ├── package.json │ └── packages │ │ ├── app │ │ └── package.json │ │ └── lib │ │ └── package.json ├── pnpm │ ├── .gitignore │ ├── longfilename │ │ ├── index.js │ │ └── package.json │ ├── package.json │ └── pnpm-lock.yaml ├── prefer-file-over-dir │ ├── .gitignore │ ├── node_modules │ │ ├── @foo │ │ │ ├── bar.js │ │ │ └── bar │ │ │ │ └── index.js │ │ ├── bar.js │ │ └── bar │ │ │ ├── index.js │ │ │ └── package.json │ └── package.json ├── symlink-with-nested-node_modules │ ├── .gitignore │ ├── bar │ │ └── node_modules │ │ │ └── foo │ └── foo │ │ └── node_modules │ │ ├── dep │ │ └── index.js │ │ └── foo │ │ └── index.js └── tsconfig │ ├── cases │ ├── absolute-alias │ │ ├── public │ │ │ └── images │ │ │ │ └── foo.ts │ │ ├── test.ts │ │ └── tsconfig.json │ ├── builtins │ │ ├── thing.js │ │ └── tsconfig.json │ ├── exports │ │ ├── index.js │ │ └── tsconfig.json │ ├── extends-extension │ │ ├── base-tsconfig.json │ │ ├── foo.js │ │ └── tsconfig.json │ ├── extends-extensionless │ │ ├── foo.js │ │ └── tsconfig.json │ ├── extends-multiple │ │ ├── foo.js │ │ └── tsconfig.json │ ├── extends-not-found │ │ ├── index.js │ │ └── tsconfig.json │ ├── extends-paths │ │ ├── src │ │ │ └── index.js │ │ ├── tsconfig.base.json │ │ └── tsconfig.json │ ├── field │ │ ├── index.js │ │ └── tsconfig.json │ ├── index │ │ ├── index.js │ │ └── tsconfig.json │ ├── merge_compiler_options │ │ ├── base-tsconfig.json │ │ └── tsconfig.json │ ├── no_merge_compiler_options │ │ ├── base-tsconfig.json │ │ └── tsconfig.json │ ├── parent-base-url │ │ ├── src │ │ │ └── index.ts │ │ ├── test │ │ │ └── story.ts │ │ ├── tsconfig.json │ │ └── tsconfigs │ │ │ ├── tsconfig.base.json │ │ │ └── tsconfig.dev.json │ ├── paths-nested-base │ │ ├── other │ │ │ └── bar.ts │ │ ├── root │ │ │ └── foo.ts │ │ └── tsconfig.json │ ├── paths_template_variable │ │ ├── src │ │ │ └── foo.js │ │ ├── tsconfig.json │ │ ├── tsconfig_base_url1.json │ │ ├── tsconfig_base_url2.json │ │ ├── tsconfig_extends1.json │ │ ├── tsconfig_extends2.json │ │ ├── tsconfig_extends3.json │ │ └── tsconfig_extends4.json │ ├── project_references │ │ ├── app │ │ │ ├── aliased │ │ │ │ └── index.ts │ │ │ ├── index.ts │ │ │ ├── tsconfig.json │ │ │ └── tsconfig.nopaths.json │ │ ├── project_a │ │ │ ├── aliased │ │ │ │ └── index.ts │ │ │ ├── conf.json │ │ │ └── index.ts │ │ ├── project_b │ │ │ ├── src │ │ │ │ └── aliased │ │ │ │ │ └── index.ts │ │ │ └── tsconfig.json │ │ ├── project_c │ │ │ ├── index.ts │ │ │ └── tsconfig.json │ │ └── tsconfig.base.json │ ├── suffixes │ │ ├── a.ios.ts │ │ ├── a.ts │ │ ├── b.ts │ │ ├── c-test.ts │ │ ├── index.ts │ │ └── tsconfig.json │ ├── trailing-comma │ │ ├── bar.js │ │ ├── index.js │ │ └── tsconfig.json │ └── with-bom │ │ ├── bar.js │ │ └── tsconfig.json │ ├── nested │ ├── index.js │ ├── test.js │ └── tsconfig.json │ ├── node_modules │ ├── tsconfig-exports │ │ ├── conf.json │ │ ├── foo.js │ │ └── package.json │ ├── tsconfig-field │ │ ├── conf.json │ │ ├── foo.js │ │ └── package.json │ ├── tsconfig-index │ │ ├── foo.js │ │ ├── package.json │ │ └── tsconfig.json │ └── tsconfig-not-used │ │ ├── foo.js │ │ └── tsconfig.json │ ├── package.json │ ├── src │ └── foo.js │ ├── tsconfig.json │ ├── tsconfig_broken.json │ ├── tsconfig_template_variable1.json │ ├── tsconfig_template_variable2.json │ ├── tsconfig_template_variable3.json │ └── tsconfig_template_variable4.json ├── fuzz ├── .gitignore ├── Cargo.toml └── fuzz_targets │ └── resolver.rs ├── justfile ├── napi ├── .gitignore ├── Cargo.toml ├── README.md ├── browser.js ├── build.rs ├── index.d.ts ├── index.js ├── resolver.wasi-browser.js ├── resolver.wasi.cjs ├── src │ ├── lib.rs │ ├── options.rs │ └── tracing.rs ├── test.mjs ├── tests │ ├── options.test.mjs │ ├── resolver.test.mjs │ └── simple.test.mjs ├── wasi-worker-browser.mjs └── wasi-worker.mjs ├── npm ├── .gitignore ├── README.md └── package.json ├── package.json ├── pnpm-lock.yaml ├── pnpm-workspace.yaml ├── release-plz.toml ├── renovate.json ├── rust-toolchain.toml ├── src ├── builtins.rs ├── cache.rs ├── context.rs ├── error.rs ├── file_system.rs ├── fs_cache.rs ├── lib.rs ├── options.rs ├── package_json.rs ├── package_json_serde.rs ├── path.rs ├── resolution.rs ├── specifier.rs ├── tests │ ├── alias.rs │ ├── browser_field.rs │ ├── builtins.rs │ ├── dependencies.rs │ ├── exports_field.rs │ ├── extension_alias.rs │ ├── extensions.rs │ ├── fallback.rs │ ├── full_specified.rs │ ├── imports_field.rs │ ├── incorrect_description_file.rs │ ├── main_field.rs │ ├── memory_fs.rs │ ├── missing.rs │ ├── mod.rs │ ├── pnp.rs │ ├── resolution.rs │ ├── resolve.rs │ ├── restrictions.rs │ ├── roots.rs │ ├── scoped_packages.rs │ ├── simple.rs │ ├── symlink.rs │ ├── tsconfig_paths.rs │ ├── tsconfig_project_references.rs │ └── windows.rs ├── tsconfig.rs ├── tsconfig_serde.rs └── windows.rs └── tests ├── integration_test.rs ├── package.json ├── resolve_test.rs └── tsconfig.json /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | # Addresses a potential segmentation fault issue that occurs when 2 | # running napi-rs within a Node.js worker thread on GNU/Linux systems. 3 | # See https://x.com/Brooooook_lyn/status/1895848334692401270 4 | [target.'cfg(target_env = "gnu")'] 5 | rustflags = ["-C", "link-args=-Wl,-z,nodelete"] 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root=true 2 | 3 | [*] 4 | indent_style=space 5 | indent_size=2 6 | tab_width=2 7 | end_of_line=lf 8 | charset=utf-8 9 | trim_trailing_whitespace=true 10 | insert_final_newline=true 11 | 12 | [*.rs] 13 | indent_size = 4 14 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | ## Reporting a Vulnerability 6 | 7 | If you find any potential vulnerability, join our [discord channel](https://discord.gg/9uXCAwqQZW) and contact Boshen. 8 | -------------------------------------------------------------------------------- /.github/actions/pnpm/action.yml: -------------------------------------------------------------------------------- 1 | name: Pnpm 2 | 3 | description: Install pnpm 4 | 5 | inputs: 6 | architecture: 7 | description: The architecture to use 8 | required: false 9 | 10 | runs: 11 | using: composite 12 | steps: 13 | - uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 14 | 15 | - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 16 | with: 17 | node-version-file: .node-version 18 | architecture: ${{ inputs.architecture }} 19 | cache: pnpm 20 | 21 | - if: ${{ inputs.architecture == 'x86' }} 22 | shell: bash 23 | run: pnpm config set supportedArchitectures.cpu "ia32" 24 | 25 | - name: pnpm 26 | shell: bash 27 | run: | 28 | corepack enable 29 | pnpm install 30 | 31 | - name: yarn pnp 32 | shell: bash 33 | run: | 34 | cd fixtures/pnp 35 | corepack enable 36 | yarn install 37 | -------------------------------------------------------------------------------- /.github/codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | informational: true 6 | patch: 7 | default: 8 | informational: true 9 | changes: 10 | default: 11 | informational: true 12 | 13 | ignore: 14 | - "examples" 15 | -------------------------------------------------------------------------------- /.github/workflows/autofix.yml: -------------------------------------------------------------------------------- 1 | name: autofix.ci # For security reasons, the workflow in which the autofix.ci action is used must be named "autofix.ci". 2 | 3 | permissions: {} 4 | 5 | on: 6 | pull_request: 7 | types: 8 | - opened 9 | - synchronize 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | autofix: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 20 | 21 | - uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0 22 | with: 23 | restore-cache: false 24 | tools: just,cargo-shear@1,dprint 25 | components: rustfmt 26 | 27 | - name: Restore dprint plugin cache 28 | id: cache-restore 29 | uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 30 | with: 31 | key: dprint-autofix-ci-${{ runner.os }}-${{ hashFiles('dprint.json') }} 32 | path: ~/.cache/dprint 33 | 34 | - run: just fmt 35 | 36 | - uses: autofix-ci/action@2891949f3779a1cafafae1523058501de3d4e944 # v1.3.1 37 | with: 38 | fail-fast: false 39 | 40 | - name: Save dprint plugin cache 41 | if: ${{ github.ref_name == 'main' }} 42 | id: cache-save 43 | uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 44 | with: 45 | key: ${{ steps.cache-restore.outputs.cache-primary-key }} 46 | path: ~/.cache/dprint 47 | -------------------------------------------------------------------------------- /.github/workflows/benchmark.yml: -------------------------------------------------------------------------------- 1 | name: Benchmark 2 | 3 | permissions: {} 4 | 5 | on: 6 | workflow_dispatch: 7 | pull_request: 8 | types: 9 | - opened 10 | - synchronize 11 | paths: 12 | - "src/*.rs" 13 | - "Cargo.lock" 14 | push: 15 | branches: 16 | - main 17 | paths: 18 | - "src/*.rs" 19 | - "Cargo.lock" 20 | 21 | concurrency: 22 | group: ${{ github.workflow }}-${{ github.ref }} 23 | cancel-in-progress: true 24 | 25 | jobs: 26 | benchmark: 27 | name: Benchmark 28 | runs-on: ubuntu-latest 29 | steps: 30 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 31 | 32 | - uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0 33 | with: 34 | cache-key: benchmark 35 | save-cache: ${{ github.ref_name == 'main' }} 36 | tools: cargo-codspeed 37 | 38 | - uses: ./.github/actions/pnpm 39 | 40 | - run: cargo codspeed build --features codspeed 41 | env: 42 | RUSTFLAGS: "-C debuginfo=1 -C strip=none" 43 | 44 | - uses: CodSpeedHQ/action@0010eb0ca6e89b80c88e8edaaa07cfe5f3e6664d # v3.5.0 45 | timeout-minutes: 30 46 | with: 47 | run: cargo codspeed run 48 | token: ${{ secrets.CODSPEED_TOKEN }} 49 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | permissions: {} 4 | 5 | on: 6 | workflow_dispatch: 7 | pull_request: 8 | types: 9 | - opened 10 | - synchronize 11 | paths-ignore: 12 | - "**/*.md" 13 | - "!.github/workflows/ci.yml" 14 | push: 15 | branches: 16 | - main 17 | paths-ignore: 18 | - "**/*.md" 19 | - "!.github/workflows/ci.yml" 20 | 21 | concurrency: 22 | group: ${{ github.workflow }}-${{ github.ref }} 23 | cancel-in-progress: true 24 | 25 | defaults: 26 | run: 27 | shell: bash 28 | 29 | jobs: 30 | test: 31 | name: Test 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | include: 36 | - os: windows-latest 37 | - os: ubuntu-latest 38 | - os: macos-14 39 | runs-on: ${{ matrix.os }} 40 | steps: 41 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 42 | - uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0 43 | with: 44 | save-cache: ${{ github.ref_name == 'main' }} 45 | cache-key: warm 46 | - uses: ./.github/actions/pnpm 47 | - run: cargo check --all-features --locked 48 | - run: cargo test --doc 49 | - run: cargo test --all-features 50 | - run: pnpm run build:debug && pnpm run test 51 | if: ${{ matrix.os != 'windows-latest' }} 52 | 53 | lint: 54 | name: Lint 55 | runs-on: ubuntu-latest 56 | steps: 57 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 58 | - uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0 59 | with: 60 | components: clippy rust-docs 61 | - run: cargo clippy --all-features --all-targets -- -D warnings 62 | - run: RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --all-features 63 | - uses: crate-ci/typos@0f0ccba9ed1df83948f0c15026e4f5ccfce46109 # v1.32.0 64 | with: 65 | files: . 66 | 67 | wasm: 68 | name: Check Wasm 69 | runs-on: ubuntu-latest 70 | steps: 71 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 72 | 73 | - uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0 74 | with: 75 | cache-key: wasm 76 | save-cache: ${{ github.ref_name == 'main' }} 77 | 78 | - name: Check 79 | run: | 80 | rustup target add wasm32-unknown-unknown 81 | cargo check --all-features --target wasm32-unknown-unknown 82 | 83 | wasi: 84 | name: Test wasi target 85 | runs-on: ubuntu-latest 86 | steps: 87 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 88 | 89 | - uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0 90 | with: 91 | cache-key: wasi 92 | save-cache: ${{ github.ref_name == 'main' }} 93 | 94 | - uses: ./.github/actions/pnpm 95 | 96 | - name: Build 97 | run: | 98 | rustup target add wasm32-wasip1-threads 99 | pnpm build --target wasm32-wasip1-threads 100 | 101 | - name: Test 102 | run: pnpm run test 103 | env: 104 | WASI_TEST: 1 105 | -------------------------------------------------------------------------------- /.github/workflows/codecov.yml: -------------------------------------------------------------------------------- 1 | name: Code Coverage # Run cargo-llvm-cov and upload to codecov.io 2 | 3 | permissions: {} 4 | 5 | on: 6 | workflow_dispatch: 7 | pull_request: 8 | types: 9 | - opened 10 | - synchronize 11 | paths: 12 | - "src/**/*.rs" 13 | - "Cargo.lock" 14 | push: 15 | branches: 16 | - main 17 | paths: 18 | - "src/**/*.rs" 19 | - "Cargo.lock" 20 | 21 | concurrency: 22 | group: ${{ github.workflow }}-${{ github.ref }} 23 | cancel-in-progress: true 24 | 25 | jobs: 26 | coverage: 27 | name: Code Coverage 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: Checkout 31 | uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 32 | 33 | - uses: ./.github/actions/pnpm 34 | 35 | - uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0 36 | with: 37 | cache-key: codecov 38 | save-cache: ${{ github.ref_name == 'main' }} 39 | tools: cargo-llvm-cov 40 | components: llvm-tools-preview 41 | 42 | - run: cargo llvm-cov --lcov --output-path lcov.info 43 | 44 | - name: Upload Artifact 45 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 46 | with: 47 | name: codecov 48 | path: lcov.info 49 | 50 | # codecov often fails, use another workflow for retry 51 | upload-codecov: 52 | name: Upload coverage file 53 | runs-on: ubuntu-latest 54 | needs: coverage 55 | # Check if the event is not triggered by a fork by checking whether CODECOV_TOKEN is set 56 | env: 57 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 58 | steps: 59 | - name: Checkout 60 | if: env.CODECOV_TOKEN 61 | uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 62 | 63 | - name: Download coverage file 64 | if: env.CODECOV_TOKEN 65 | uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 66 | with: 67 | name: codecov 68 | 69 | - name: Upload to codecov.io 70 | if: env.CODECOV_TOKEN 71 | uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 72 | with: 73 | token: ${{ secrets.CODECOV_TOKEN }} 74 | fail_ci_if_error: true 75 | files: lcov.info 76 | -------------------------------------------------------------------------------- /.github/workflows/deny.yml: -------------------------------------------------------------------------------- 1 | name: Cargo Deny 2 | 3 | permissions: {} 4 | 5 | on: 6 | workflow_dispatch: 7 | pull_request: 8 | types: 9 | - opened 10 | - synchronize 11 | paths: 12 | - "Cargo.lock" 13 | - "deny.toml" 14 | - ".github/workflows/deny.yml" 15 | push: 16 | branches: 17 | - main 18 | paths: 19 | - "Cargo.lock" 20 | - "deny.toml" 21 | - ".github/workflows/deny.yml" 22 | 23 | concurrency: 24 | group: ${{ github.workflow }}-${{ github.ref }} 25 | cancel-in-progress: true 26 | 27 | jobs: 28 | deny: 29 | name: Cargo Deny 30 | runs-on: ubuntu-latest 31 | steps: 32 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 33 | 34 | - uses: oxc-project/setup-rust@cd82e1efec7fef815e2c23d296756f31c7cdc03d # v1.0.0 35 | with: 36 | restore-cache: false 37 | tools: cargo-deny 38 | 39 | - run: cargo deny check 40 | -------------------------------------------------------------------------------- /.github/workflows/release-plz.yml: -------------------------------------------------------------------------------- 1 | name: Release Plz 2 | 3 | permissions: {} 4 | 5 | on: 6 | workflow_dispatch: 7 | push: 8 | branches: 9 | - main 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | release-plz: 17 | name: Release-plz 18 | runs-on: ubuntu-latest 19 | permissions: 20 | pull-requests: write 21 | contents: write 22 | steps: 23 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 24 | with: 25 | fetch-depth: 0 26 | token: ${{ secrets.RELEASE_PLZ_TOKEN }} 27 | persist-credentials: true # required by release-plz 28 | 29 | - name: Run release-plz 30 | id: release-plz 31 | uses: release-plz/action@dde7b63054529c440305a924e5849c68318bcc9a # v0.5.107 32 | env: 33 | GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} 34 | CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} 35 | 36 | - name: Bump package.json 37 | if: ${{ steps.release-plz.outputs.prs_created }} 38 | env: 39 | GH_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} 40 | PR_NUMBER: ${{ fromJSON(steps.release-plz.outputs.pr).number }} 41 | VERSION: ${{ fromJSON(steps.release-plz.outputs.pr).releases[0].version }} 42 | run: | 43 | set -e 44 | 45 | pr_number="${PR_NUMBER}" 46 | 47 | if [[ -n "$pr_number" ]]; then 48 | version="${VERSION}" 49 | 50 | jq --arg version "${version}" '.version = ($version) | .scripts.postinstall = "napi-postinstall unrs-resolver \($version) check"' npm/package.json > tmp 51 | mv tmp npm/package.json 52 | 53 | gh pr checkout $pr_number 54 | git add . 55 | git commit --amend --no-edit 56 | git push --force-with-lease 57 | fi 58 | -------------------------------------------------------------------------------- /.github/workflows/zizmor.yml: -------------------------------------------------------------------------------- 1 | name: Zizmor 2 | 3 | permissions: {} 4 | 5 | on: 6 | workflow_dispatch: 7 | pull_request: 8 | types: 9 | - opened 10 | - synchronize 11 | paths: 12 | - ".github/workflows/**" 13 | push: 14 | branches: 15 | - main 16 | paths: 17 | - .github/workflows/** 18 | 19 | concurrency: 20 | group: ${{ github.workflow }}-${{ github.ref }} 21 | cancel-in-progress: true 22 | 23 | jobs: 24 | zizmor: 25 | name: zizmor 26 | runs-on: ubuntu-latest 27 | permissions: 28 | security-events: write 29 | steps: 30 | - uses: taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1 31 | 32 | - uses: taiki-e/install-action@735e5933943122c5ac182670a935f54a949265c1 # v2.52.4 33 | with: 34 | tool: zizmor 35 | 36 | - name: Run zizmor 37 | run: zizmor --format sarif . > results.sarif 38 | env: 39 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 40 | 41 | - name: Upload SARIF file 42 | uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 43 | with: 44 | sarif_file: results.sarif 45 | category: zizmor 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | /node_modules 3 | fuzz/Cargo.lock 4 | -------------------------------------------------------------------------------- /.node-version: -------------------------------------------------------------------------------- 1 | 22.16.0 2 | -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | style_edition = "2024" 2 | 3 | # Make Rust more readable given most people have wide screens nowadays. 4 | # This is also the setting used by [rustc](https://github.com/rust-lang/rust/blob/master/rustfmt.toml) 5 | use_small_heuristics = "Max" 6 | 7 | # Use field initialize shorthand if possible 8 | use_field_init_shorthand = true 9 | 10 | reorder_modules = true 11 | 12 | # For `cargo +nightly fmt` 13 | # unstable_features = true 14 | # style_edition = '2024' 15 | # reorder_impl_items = true 16 | # group_imports = "StdExternalCrate" 17 | # imports_granularity = "Crate" 18 | -------------------------------------------------------------------------------- /.typos.toml: -------------------------------------------------------------------------------- 1 | # https://github.com/crate-ci/typos 2 | # cargo install typos-cli 3 | # typos 4 | 5 | [files] 6 | extend-exclude = [ 7 | "CHANGELOG.md", 8 | "CHANGELOG_OLD.md", 9 | ] 10 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["napi"] 3 | resolver = "2" 4 | 5 | [package] 6 | name = "unrs_resolver" 7 | version = "1.7.8" 8 | authors = ["JounQin (https://www.1stG.me)"] 9 | categories = ["development-tools"] 10 | edition = "2024" 11 | homepage = "https://github.com/unrs/unrs-resolver" 12 | include = ["/src", "/examples", "/benches"] 13 | keywords = ["node", "resolve", "cjs", "esm", "enhanced-resolve"] 14 | license = "MIT" 15 | readme = "README.md" 16 | repository = "https://github.com/unrs/unrs-resolver" 17 | rust-version = "1.85.0" 18 | description = "ESM / CJS module resolution" 19 | 20 | [lib] 21 | doctest = false 22 | 23 | [[bench]] 24 | name = "resolver" 25 | harness = false 26 | 27 | [lints.clippy] 28 | all = { level = "warn", priority = -1 } 29 | cargo = { level = "warn", priority = -1 } 30 | # restriction 31 | dbg_macro = "warn" 32 | todo = "warn" 33 | unimplemented = "warn" 34 | # I like the explicitness of this rule as it removes confusion around `clone`. 35 | # This increases readability, avoids `clone` mindlessly and heap allocating on accident. 36 | clone_on_ref_ptr = "warn" 37 | # These two are mutually exclusive, I like `mod.rs` files for better fuzzy searches on module entries. 38 | self_named_module_files = "warn" # "-Wclippy::mod_module_files" 39 | empty_drop = "warn" 40 | empty_structs_with_brackets = "warn" 41 | exit = "warn" 42 | filetype_is_file = "warn" 43 | get_unwrap = "warn" 44 | impl_trait_in_params = "warn" 45 | rc_buffer = "warn" 46 | rc_mutex = "warn" 47 | rest_pat_in_fully_bound_structs = "warn" 48 | unnecessary_safety_comment = "warn" 49 | undocumented_unsafe_blocks = "warn" 50 | pedantic = { level = "warn", priority = -1 } 51 | # This rule is too pedantic, I don't want to force this because naming things are hard. 52 | module_name_repetitions = "allow" 53 | doc_markdown = "allow" 54 | # I want to write the best Rust code so both pedantic and nursery is enabled. 55 | # We should only disable rules globally if they are either false positives, chaotic, or does not make sense. 56 | nursery = { level = "warn", priority = -1 } 57 | literal_string_with_formatting_args = "allow" 58 | missing_const_for_fn = "allow" 59 | # cargo 60 | multiple_crate_versions = "allow" 61 | 62 | [[example]] 63 | name = "resolver" 64 | 65 | [dependencies] 66 | cfg-if = "1.0" 67 | dashmap = "7.0.0-rc2" 68 | dunce = "1.0.5" # Normalize Windows paths to the most compatible format, avoiding UNC where possible 69 | indexmap = { version = "2.9.0", features = ["serde"] } 70 | json-strip-comments = "1.0.4" 71 | once_cell = "1.21.3" # Use `std::sync::OnceLock::get_or_try_init` when it is stable. 72 | papaya = "0.2.1" 73 | rustc-hash = { version = "2.1.1", default-features = false, features = ["std"] } 74 | serde = { version = "1.0.219", features = ["derive"], optional = true } # derive for Deserialize from package.json 75 | serde_json = { version = "1.0.140", features = ["preserve_order"], optional = true } # preserve_order: package_json.exports requires order such as `["require", "import", "default"]` 76 | simdutf8 = { version = "0.1.5", features = ["aarch64_neon"] } 77 | thiserror = "2.0.12" 78 | tracing = "0.1.41" 79 | windows-sys = { version = "0.59", features = ["Win32_Foundation", "Win32_Storage_FileSystem"] } 80 | 81 | pnp = { version = "0.9.4", optional = true } 82 | 83 | document-features = { version = "0.2.11", optional = true } 84 | 85 | [dev-dependencies] 86 | criterion2 = { version = "3.0.0", default-features = false } 87 | normalize-path = { version = "0.2.1" } 88 | rayon = { version = "1.10.0" } 89 | vfs = "0.12.1" # for testing with in memory file system 90 | 91 | [features] 92 | default = ["fs_cache", "yarn_pnp"] 93 | ## Provides the `FsCache` implementation. 94 | fs_cache = ["dep:serde", "dep:serde_json"] 95 | ## Enables the [PackageJsonSerde::raw_json] API, 96 | ## which returns the `package.json` with `serde_json::Value`. 97 | package_json_raw_json_api = [] 98 | ## [Yarn Plug'n'Play](https://yarnpkg.com/features/pnp) 99 | yarn_pnp = ["pnp"] 100 | # For codspeed benchmark 101 | codspeed = ["criterion2/codspeed"] 102 | 103 | [package.metadata.docs.rs] 104 | all-features = true 105 | rustdoc-args = ["--cfg", "docsrs"] 106 | 107 | # For napi 108 | [profile.release] 109 | # Configurations explicitly listed here for clarity. 110 | # Using the best options for performance. 111 | opt-level = 3 112 | lto = "fat" 113 | codegen-units = 1 114 | strip = "symbols" # set to `false` for debug information 115 | debug = false # set to `true` for debug information 116 | panic = "abort" # Let it crash and force ourselves to write safe Rust. 117 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025-present UnRS & Contributors 4 | Copyright (c) 2024 VoidZero Inc. & Contributors 5 | Copyright (c) 2023 Boshen 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /cliff.toml: -------------------------------------------------------------------------------- 1 | # git-cliff ~ configuration file 2 | # https://git-cliff.org/docs/configuration 3 | 4 | [git] 5 | commit_parsers = [ 6 | { message = "^doc", group = "Documentation" }, 7 | { message = "^feat", group = "Features" }, 8 | { message = "^fix", group = "Bug Fixes" }, 9 | { message = "^perf", group = "Performance" }, 10 | { message = "^refactor", group = "Refactor" }, 11 | { message = "^style", group = "Styling" }, 12 | { message = "^test", group = "Testing" }, 13 | ] 14 | # protect breaking changes from being skipped due to matching a skipping commit_parser 15 | protect_breaking_commits = false 16 | -------------------------------------------------------------------------------- /dprint.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://dprint.dev/schemas/v0.json", 3 | "lineWidth": 120, 4 | "typescript": { 5 | "quoteStyle": "preferSingle", 6 | "binaryExpression.operatorPosition": "sameLine" 7 | }, 8 | "json": { 9 | "indentWidth": 2 10 | }, 11 | "toml": { 12 | }, 13 | "excludes": [ 14 | "fixtures/**", 15 | "CHANGELOG.md", 16 | "CHANGELOG_OLD.md", 17 | "pnpm-workspace.yaml", 18 | "pnpm-lock.yaml", 19 | "napi/*.{cjs,js,mjs,d.ts}", 20 | "!napi/test.mjs" 21 | ], 22 | "plugins": [ 23 | "https://plugins.dprint.dev/typescript-0.93.3.wasm", 24 | "https://plugins.dprint.dev/json-0.19.4.wasm", 25 | "https://plugins.dprint.dev/markdown-0.17.8.wasm", 26 | "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm", 27 | "https://plugins.dprint.dev/toml-0.6.3.wasm" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /examples/resolver.rs: -------------------------------------------------------------------------------- 1 | // See documentation at 2 | 3 | use std::{env, path::PathBuf}; 4 | 5 | use unrs_resolver::{AliasValue, ResolveOptions, Resolver}; 6 | 7 | fn main() { 8 | let path = PathBuf::from(env::args().nth(1).expect("path")); 9 | 10 | assert!(path.is_dir(), "{path:?} must be a directory that will be resolved against."); 11 | assert!(path.is_absolute(), "{path:?} must be an absolute path."); 12 | 13 | let specifier = env::args().nth(2).expect("specifier"); 14 | 15 | println!("path: {path:?}"); 16 | println!("specifier: {specifier}"); 17 | 18 | let options = ResolveOptions { 19 | alias_fields: vec![vec!["browser".into()]], 20 | alias: vec![("asdf".into(), vec![AliasValue::from("./test.js")])], 21 | extensions: vec![".js".into(), ".ts".into()], 22 | extension_alias: vec![(".js".into(), vec![".ts".into(), ".js".into()])], 23 | // ESM 24 | condition_names: vec!["node".into(), "import".into()], 25 | // CJS 26 | // condition_names: vec!["node".into(), "require".into()], 27 | ..ResolveOptions::default() 28 | }; 29 | 30 | match Resolver::new(options).resolve(path, &specifier) { 31 | Err(error) => println!("Error: {error}"), 32 | Ok(resolution) => println!("Resolved: {:?}", resolution.full_path()), 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /fixtures/dot/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/dot/foo.js -------------------------------------------------------------------------------- /fixtures/dot/foo/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/dot/foo/foo.js -------------------------------------------------------------------------------- /fixtures/dot/foo/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/dot/foo/index.js -------------------------------------------------------------------------------- /fixtures/dual-condition-names/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dual-condition-names", 3 | "dependencies": { 4 | "zod": "~3.24.4" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/lib/index.js: -------------------------------------------------------------------------------- 1 | // mimic enhanced-resolved root directory structure 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "enhanced-resolve", 3 | "main": "lib/index.js" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/.gitignore: -------------------------------------------------------------------------------- 1 | # created by symlink.rs 2 | /temp.* 3 | 4 | # Currently not used. 5 | /temp 6 | /temp_symlinks 7 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/#/a.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/#/a.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/a.js: -------------------------------------------------------------------------------- 1 | module.exports = function a() { 2 | return "This is a"; 3 | }; 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/abc.txt: -------------------------------------------------------------------------------- 1 | abc -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/alias/files/a.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/alias/files/a.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/b.js: -------------------------------------------------------------------------------- 1 | module.exports = function b() { 2 | return "This is b"; 3 | }; 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/browser/module-a.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/browser/module-a.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/lib/browser.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/lib/browser.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/lib/ignore.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/lib/ignore.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/lib/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/lib/main.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/lib/replaced.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/lib/replaced.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/lib/self.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/lib/self.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/lib/toString.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/lib/toString.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/module-a.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/module-a.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/module-b.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/module-b.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/module-c.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/module-c.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/recursive-file/a.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/recursive-file/a.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/recursive-file/b.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/recursive-file/b.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/recursive-file/c.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/recursive-file/c.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/recursive-file/d.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/recursive-file/d.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/node_modules/recursive-file/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "browser": { 3 | "a.js": "./a", 4 | "./b.js": "./b", 5 | "c.js": "./d.js", 6 | "./d.js": "./c.js" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/browser-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "exports": { 3 | "./lib/index.js": "./lib/index.js" 4 | }, 5 | "browser": { 6 | "./lib/ignore.js": false, 7 | "./lib/replaced.js": "./lib/browser", 8 | "module-a": "./browser/module-a.js", 9 | "module-b": "module-c", 10 | "module-c": "module-c", 11 | "./toString": "./lib/toString.js", 12 | "./lib/main.js": "./lib/main.js", 13 | "./main.js": "./lib/main.js", 14 | "./lib/xyz.js": "./xyz.js", 15 | "./xyz.js": "./lib/xyz.js", 16 | "./lib/non-existent.js": "./lib/non-existent.js", 17 | ".": false, 18 | "./number": 1, 19 | "./foo": "./lib/replaced.js?query" 20 | }, 21 | "innerBrowser1": { 22 | "field": { 23 | "browser": { 24 | "./lib/main1.js": "./lib/main.js" 25 | } 26 | } 27 | }, 28 | "innerBrowser2": { 29 | "browser": { 30 | "./lib/main2.js": "./lib/replaced.js" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/builtins/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "builtins", 3 | "private": true, 4 | "imports": { 5 | "#fs": { 6 | "default": "fs" 7 | }, 8 | "#http": { 9 | "node": "node:http" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/c.js: -------------------------------------------------------------------------------- 1 | module.exports = function b() { 2 | require("./a"); 3 | return "This is c"; 4 | }; 5 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/complex.js: -------------------------------------------------------------------------------- 1 | var complex1 = require("./lib/complex1"); 2 | require.ensure(["./lib/complex1", "complexm/step2"], function(require) { 3 | require("./lib/complex1"); 4 | var a = function() {}; 5 | require.ensure(["complexm/step1"], function(require) { 6 | require("./lib/complex1"); 7 | var s1 = require("complexm/step1"); 8 | var s2 = require("complexm/step2"); 9 | console.log(s1); 10 | console.log(s2); 11 | }); 12 | }); 13 | console.log(complex1); 14 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/crypto-js/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/crypto-js/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/crypto-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crypto-js", 3 | "main": "index.js", 4 | "browser": { 5 | "crypto": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/decorated-fs/exists.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/decorated-fs/exists.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/dirOrFile.js: -------------------------------------------------------------------------------- 1 | module.exports = "file"; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/dirOrFile/index.js: -------------------------------------------------------------------------------- 1 | module.exports = "dir"; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/directory-default/directory-default.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/directory-default/directory-default.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field-and-extension-alias/node_modules/@org/pkg/dist/string.js: -------------------------------------------------------------------------------- 1 | export default "string"; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field-and-extension-alias/node_modules/@org/pkg/dist/string.test.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field-and-extension-alias/node_modules/@org/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@org/pkg", 3 | "exports": { 4 | "./*.js": { 5 | "types": "./dist/*.d.ts", 6 | "default": "./dist/*.js" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field-and-extension-alias/node_modules/pkg/dist/string.js: -------------------------------------------------------------------------------- 1 | export default "string"; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field-and-extension-alias/node_modules/pkg/dist/string.test.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field-and-extension-alias/node_modules/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@raviqqe/hidash", 3 | "exports": { 4 | "./*.js": { 5 | "types": "./dist/*.d.ts", 6 | "default": "./dist/*.js" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field-error/node_modules/exports-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exports-field", 3 | "version": "1.0.0", 4 | "exports": { 5 | ".": "./a/../b/../../pack1/index.js" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field-error/node_modules/pack1/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/exports-field-error/node_modules/pack1/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/a.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/exports-field/lib/browser.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/exports-field/lib/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/exports-field/lib/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/exports-field/lib/lib2/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/exports-field/lib/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/exports-field/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/exports-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exports-field", 3 | "version": "1.0.0", 4 | "main": "./main.js", 5 | "browser": { 6 | "./lib/main.js": "./lib/browser.js", 7 | "./dist/main.js": "./lib/browser.js" 8 | }, 9 | "exports": { 10 | ".": "./x.js", 11 | "./dist/": { 12 | "webpack": ["./lib/lib2/", "./lib/"], 13 | "node": "./lib/", 14 | "default": "./lib/" 15 | }, 16 | "./dist/a.js": "./../../a.js", 17 | "./query.js": "./x.js?query", 18 | "./fragment.js": "./x.js#fragment" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/exports-field/x.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/invalid-exports-field/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/invalid-exports-field/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/invalid-exports-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exports-field", 3 | "version": "1.0.0", 4 | "main": "./main.js", 5 | "browser": { 6 | "./lib/main.js": "./lib/browser.js", 7 | "./dist/main.js": "./lib/browser.js" 8 | }, 9 | "exports": { 10 | ".": "./index.js", 11 | "umd": "./umd.js" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/invalid-exports-field/umd.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/exports-field/node_modules/invalid-exports-field/umd.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@exports-field/core", 3 | "version": "1.0.0", 4 | "exports": "./a.js" 5 | } 6 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field2/node_modules/exports-field/index.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field2/node_modules/exports-field/lib/browser.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field2/node_modules/exports-field/lib/lib2/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field2/node_modules/exports-field/lib/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field2/node_modules/exports-field/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field2/node_modules/exports-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exports-field", 3 | "version": "1.0.0", 4 | "main": "./main.js", 5 | "browser": { 6 | "./lib/main.js": "./lib/browser.js", 7 | "./dist/main.js": "./lib/browser.js" 8 | }, 9 | "exports": { 10 | ".": "./index.js", 11 | "./dist/": { 12 | "webpack": ["./lib/lib2/", "./lib/"], 13 | "node": "./lib/", 14 | "default": "./lib/" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field3/node_modules/exports-field/index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/exports-field3/node_modules/exports-field/index -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field3/node_modules/exports-field/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field3/node_modules/exports-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exports-field", 3 | "exportsField": { 4 | "exports": "./main.js" 5 | }, 6 | "ex": "./index", 7 | "broken": { 8 | ".": "./src" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/exports-field3/node_modules/exports-field/src/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/exports-field3/node_modules/exports-field/src/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extension-alias/dir/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extension-alias/dir/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extension-alias/dir/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extension-alias/dir/index.ts -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extension-alias/dir2/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extension-alias/dir2/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extension-alias/dir2/index.mts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extension-alias/dir2/index.mts -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extension-alias/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extension-alias/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extension-alias/index.mjs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extension-alias/index.mjs -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extension-alias/index.mts.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extension-alias/index.mts.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extension-alias/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extension-alias/index.ts -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/app.module.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/app.module.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/bar.d.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/bar.d.ts -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/dir/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/dir/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/dir/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/dir/index.ts -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/foo.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/foo.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/foo.ts -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/index.ts -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/node_modules/module.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/node_modules/module.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/node_modules/module/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/extensions/node_modules/module/index.ts -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/extensions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "./index.js" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/file.load1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/file.load1 -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/file.load2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/file.load2 -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/foo/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/foo/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/foo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foo", 3 | "version": "1.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "m", 3 | "exports": { 4 | "./features-no-ext/*": "./src/features/*", 5 | "./features/*.js": "./src/features/*.js", 6 | "./features/internal/*": null, 7 | "./middle/nested/f.js": "./src/middle/nested/f.js", 8 | "./middle-1/nested/*.js": "./src/middle-1/nested/*.js", 9 | "./middle-2/*/f.js": "./src/middle-2/*/f.js", 10 | "./middle-3/*": "./src/middle-3/*/*.js", 11 | "./middle-4/*/nested": "./src/middle-4/*/*.js", 12 | "./middle-5/*/$": "./src/middle-5/*/$.js" 13 | }, 14 | "imports": { 15 | "#internal/*.js": "./src/internal/*.js" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/features/f.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/features/f.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/features/internal/file.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/features/internal/file.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/features/y/y.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/features/y/y.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/internal/i.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/internal/i.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-1/f.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-1/f.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-1/nested/f.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-1/nested/f.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-2/nested/f.js: -------------------------------------------------------------------------------- 1 | module.exports = { nested: "nested" } 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-3/nested/f/nested/f.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-3/nested/f/nested/f.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-4/f/f.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-4/f/f.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-5/f$/$.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-5/f$/$.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-5/f/$.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle-5/f/$.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle/f.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle/f.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle/nested/f.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-exports-wildcard/node_modules/m/src/middle/nested/f.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/a.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/b.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-field/b.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/dir/b.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-field/dir/b.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/a/lib/browser.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/a/lib/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/a/lib/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/a/lib/lib2/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/a/lib/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/a/main.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "version": "1.0.0", 4 | "main": "./main.js", 5 | "browser": { 6 | "./lib/main.js": "./lib/browser.js", 7 | "./dist/main.js": "./lib/browser.js" 8 | }, 9 | "exports": { 10 | ".": "./x.js", 11 | "./dist/": { 12 | "webpack": ["./lib/lib2/", "./lib/"], 13 | "node": "./lib/", 14 | "default": "./lib/" 15 | }, 16 | "./dist/a.js": "./../../a.js" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/a/x.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/c/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/imports-field/node_modules/c/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/imports-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "imports-field", 3 | "version": "1.0.0", 4 | "exports": "./a.js", 5 | "imports": { 6 | "#imports-field": "./b.js", 7 | "#b": "../b.js", 8 | "#ccc/": "c/", 9 | "#c": "c", 10 | "#a/": "a/", 11 | "#query": "./a.js?query", 12 | "#fragment": "./a.js#fragment" 13 | }, 14 | "other": { 15 | "imports": { 16 | "#b": "./a.js" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/incorrect-package/pack1/a.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/incorrect-package/pack1/a.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/incorrect-package/pack1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "./a.js", 3 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/incorrect-package/pack2/a.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/incorrect-package/pack2/a.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/incorrect-package/pack2/package.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/incorrect-package/pack2/package.json -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/issue-238/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/issue-238/src/a/config.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/issue-238/src/a/config.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/issue-238/src/common/config/myObjectFile.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/issue-238/src/common/config/myObjectFile.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/lib.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/lib.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/lib/complex1.js: -------------------------------------------------------------------------------- 1 | module.exports = "lib complex1"; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/main-field-self/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/main-field-self/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/main-field-self/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "./" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/main-field-self2/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/main-field-self2/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/main-field-self2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "." 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/main1.js: -------------------------------------------------------------------------------- 1 | var a = require("./a"); 2 | if (x) { 3 | for (var i = 0; i < 100; i++) { 4 | while (true) require("./b"); 5 | do { 6 | i++; 7 | } while (require("m1/a")()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/main2.js: -------------------------------------------------------------------------------- 1 | var a = require("./a"); 2 | with (x) { 3 | switch (a) { 4 | case 1: 5 | require("./b"); 6 | default: 7 | require.ensure(["m1/a"], function() { 8 | var a = require("m1/a"), 9 | b = require("m1/b"); 10 | }); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/main3.js: -------------------------------------------------------------------------------- 1 | var a = require("./a"); 2 | require.ensure([], function(require) { 3 | require("./c.js"); 4 | }); 5 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/multiple_modules/node_modules/m1/a.js: -------------------------------------------------------------------------------- 1 | module.exports = function a() { 2 | return "This is nested m1/a"; 3 | }; 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/no#fragment/#/#.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/no#fragment/#/#.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/no.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/no.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/browser-module-broken/browser.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/node_modules/browser-module-broken/browser.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/browser-module-broken/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/node_modules/browser-module-broken/main.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/browser-module-broken/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "./main.js", 3 | "browser": "./browser.js" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/complexm/node_modules/m1/a.js: -------------------------------------------------------------------------------- 1 | module.exports = "the correct a.js"; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/complexm/node_modules/m1/index.js: -------------------------------------------------------------------------------- 1 | module.exports = " :) " + require("m2/b.js"); 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/complexm/step1.js: -------------------------------------------------------------------------------- 1 | module.exports = require("m1/a") + require("m1"); 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/complexm/step2.js: -------------------------------------------------------------------------------- 1 | module.exports = "Step2"; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/dash-name/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/node_modules/dash-name/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/dash-name/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dash-name", 3 | "exports": "./index.js" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/dash/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/node_modules/dash/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/dash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dash", 3 | "exports": "./index.js" 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/invalidPackageJson/package.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/node_modules/invalidPackageJson/package.json -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/m1/a.js: -------------------------------------------------------------------------------- 1 | module.exports = function a() { 2 | return "This is m1/a"; 3 | }; 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/m1/b.js: -------------------------------------------------------------------------------- 1 | module.exports = function a() { 2 | return "This is m1/b"; 3 | }; 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/m2/b.js: -------------------------------------------------------------------------------- 1 | module.exports = "This is m2/b"; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/recursive-module/file.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/node_modules/recursive-module/file.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/node_modules/recursive-module/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/node_modules/recursive-module/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp-a/m2/a.js: -------------------------------------------------------------------------------- 1 | module.exports = function a() { 2 | return "This is nested m1/a"; 3 | }; 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp/pkg/dir/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/pnp/pkg/dir/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp/pkg/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/pnp/pkg/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp/pkg/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/pnp/pkg/main.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp/pkg/package-alias/browser.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/pnp/pkg/package-alias/browser.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp/pkg/package-alias/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/pnp/pkg/package-alias/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "main.js", 3 | "browser": { 4 | "./package-alias/index.js": "./package-alias/browser.js", 5 | "module": "pkg/dir/index" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp/pkg/typescript/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/pnp/pkg/typescript/index.ts -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp/pkg3/a.js: -------------------------------------------------------------------------------- 1 | module.exports = 1; 2 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/pnp/pkg3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@exports-field/core", 3 | "version": "1.0.0", 4 | "exports": { 5 | ".": "./a.js", 6 | "./x": "./a.js" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/prefer-pnp/alternative-modules/m1/b.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/prefer-pnp/alternative-modules/m1/b.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck1/index.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck1/index.css -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck1/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck1/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "index.js" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck2/index.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck2/index.css -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck2/module.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck2/module.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/restrictions/node_modules/pck2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "../../../c.js", 3 | "module": "module.js", 4 | "style": "index.css" 5 | } 6 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/roots_fall_through/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/roots_fall_through/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/scoped/node_modules/@scope/pack1/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/scoped/node_modules/@scope/pack1/main.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/scoped/node_modules/@scope/pack1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "browser": { 3 | "./index.js": "./main.js" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/scoped/node_modules/@scope/pack2/lib/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/scoped/node_modules/@scope/pack2/lib/index.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/scoped/node_modules/@scope/pack2/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/scoped/node_modules/@scope/pack2/main.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/scoped/node_modules/@scope/pack2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "./main.js" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/shortcutdir.js/a.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/shortcutdir.js/a.js -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/yield/a/foo-2/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/yield/a/foo-2/b -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/yield/a/foo-2/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/yield/a/foo-2/c -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/yield/a/foo/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/yield/a/foo/a -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/yield/a/foo/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/yield/a/foo/b -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/yield/b/foo/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/yield/b/foo/a -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/yield/c/foo/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/yield/c/foo/a -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/yield/c/foo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "foo", 3 | "version": "1.0.0", 4 | "browser": { 5 | "./a": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/enhanced_resolve/test/fixtures/测试.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/enhanced_resolve/test/fixtures/测试.js -------------------------------------------------------------------------------- /fixtures/invalid/node_modules/a/dist/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | hello: 42 3 | } -------------------------------------------------------------------------------- /fixtures/invalid/node_modules/a/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "a", 3 | "main": "/dist/index.js", 4 | "version": "1.0.0" 5 | } -------------------------------------------------------------------------------- /fixtures/invalid/node_modules/main_field_fallback/exist.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | foo: 42 3 | } -------------------------------------------------------------------------------- /fixtures/invalid/node_modules/main_field_fallback/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "main_field_fallback", 3 | "main": "./exist.js", 4 | "module": "./non-exist.js" 5 | } -------------------------------------------------------------------------------- /fixtures/misc/dir-with-index/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/misc/dir-with-index/index.js -------------------------------------------------------------------------------- /fixtures/misc/package-json-with-bom/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/misc/package-json-with-bom/index.js -------------------------------------------------------------------------------- /fixtures/misc/package-json-with-bom/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@oxc-resolver/test-package-json-with-bom", 3 | "private": true, 4 | "version": "0.0.0", 5 | "main": "index.js", 6 | "type": "module" 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/misc/中文/中文.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/misc/中文/中文.js -------------------------------------------------------------------------------- /fixtures/nested-symlink/apps/tooling: -------------------------------------------------------------------------------- 1 | ../tooling -------------------------------------------------------------------------------- /fixtures/nested-symlink/apps/web/nm/@repo/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/nested-symlink/apps/web/nm/@repo/index.js -------------------------------------------------------------------------------- /fixtures/nested-symlink/apps/web/nm/@repo/typescript-config: -------------------------------------------------------------------------------- 1 | ../../../../tooling/typescript-config -------------------------------------------------------------------------------- /fixtures/nested-symlink/nm/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/nested-symlink/nm/index.js -------------------------------------------------------------------------------- /fixtures/nested-symlink/tooling/typescript-config/index.js: -------------------------------------------------------------------------------- 1 | ../../nm/index.js -------------------------------------------------------------------------------- /fixtures/pnp/.gitignore: -------------------------------------------------------------------------------- 1 | .pnp.* 2 | .yarn/* 3 | !.yarn/patches 4 | !.yarn/plugins 5 | !.yarn/releases 6 | !.yarn/sdks 7 | !.yarn/versions 8 | -------------------------------------------------------------------------------- /fixtures/pnp/.yarnrc.yml: -------------------------------------------------------------------------------- 1 | enableGlobalCache: false 2 | -------------------------------------------------------------------------------- /fixtures/pnp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pnp", 3 | "packageManager": "yarn@4.9.1", 4 | "dependencies": { 5 | "@atlaskit/pragmatic-drag-and-drop": "^1.5.2", 6 | "beachball": "^2.52.0", 7 | "is-even": "^1.0.0", 8 | "is-odd": "^3.0.1", 9 | "lib": "link:./shared", 10 | "lodash.zip": "^4.2.0", 11 | "preact": "^10.26.5" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /fixtures/pnp/shared/lib.js: -------------------------------------------------------------------------------- 1 | module.exports = function(){ 2 | return 42; 3 | } -------------------------------------------------------------------------------- /fixtures/pnpm-workspace/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store -------------------------------------------------------------------------------- /fixtures/pnpm-workspace/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "monorepo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "keywords": [], 7 | "author": "", 8 | "license": "MIT", 9 | "dependencies": { 10 | "enhanced-resolve": "^5.18.1", 11 | "unrs-resolver": "workspace:*" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /fixtures/pnpm-workspace/packages/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@monorepo/app", 3 | "private": true, 4 | "dependencies": { 5 | "@monorepo/lib": "workspace:*" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/pnpm-workspace/packages/lib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@monorepo/lib", 3 | "version": "0.0.1", 4 | "private": true, 5 | "type": "module", 6 | "dependencies": { 7 | "react": "^19.1.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/pnpm/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /fixtures/pnpm/longfilename/index.js: -------------------------------------------------------------------------------- 1 | const test = 'hello world' 2 | 3 | export default test 4 | -------------------------------------------------------------------------------- /fixtures/pnpm/longfilename/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@oxc-resolver/test-longfilename-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 3 | "private": true, 4 | "version": "0.0.0", 5 | "main": "index.js", 6 | "type": "module" 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/pnpm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pnpm", 3 | "version": "1.0.0", 4 | "private": true, 5 | "devDependencies": { 6 | "@oxc-resolver/test-longfilename-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": "file:longfilename", 7 | "axios": "1.8.4", 8 | "decimal.js": "10.5.0", 9 | "ipaddr.js": "2.2.0", 10 | "mathjs": "14.4.0", 11 | "postcss": "8.5.3", 12 | "styled-components": "6.1.17" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /fixtures/prefer-file-over-dir/.gitignore: -------------------------------------------------------------------------------- 1 | !node_modules 2 | -------------------------------------------------------------------------------- /fixtures/prefer-file-over-dir/node_modules/@foo/bar.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/prefer-file-over-dir/node_modules/@foo/bar.js -------------------------------------------------------------------------------- /fixtures/prefer-file-over-dir/node_modules/@foo/bar/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/prefer-file-over-dir/node_modules/@foo/bar/index.js -------------------------------------------------------------------------------- /fixtures/prefer-file-over-dir/node_modules/bar.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/prefer-file-over-dir/node_modules/bar.js -------------------------------------------------------------------------------- /fixtures/prefer-file-over-dir/node_modules/bar/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/prefer-file-over-dir/node_modules/bar/index.js -------------------------------------------------------------------------------- /fixtures/prefer-file-over-dir/node_modules/bar/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bar" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/prefer-file-over-dir/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prefer-file-over-dir" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/symlink-with-nested-node_modules/.gitignore: -------------------------------------------------------------------------------- 1 | !node_modules 2 | -------------------------------------------------------------------------------- /fixtures/symlink-with-nested-node_modules/bar/node_modules/foo: -------------------------------------------------------------------------------- 1 | ../../foo/node_modules/foo -------------------------------------------------------------------------------- /fixtures/symlink-with-nested-node_modules/foo/node_modules/dep/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/symlink-with-nested-node_modules/foo/node_modules/dep/index.js -------------------------------------------------------------------------------- /fixtures/symlink-with-nested-node_modules/foo/node_modules/foo/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/symlink-with-nested-node_modules/foo/node_modules/foo/index.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/absolute-alias/public/images/foo.ts: -------------------------------------------------------------------------------- 1 | export default 'image.webp' 2 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/absolute-alias/test.ts: -------------------------------------------------------------------------------- 1 | import image from '/images/foo.js' 2 | 3 | console.log(image) 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/absolute-alias/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "/*": ["./public/*"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/builtins/thing.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/builtins/thing.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/builtins/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "." 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/exports/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/exports/index.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/exports/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tsconfig-exports" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-extension/base-tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "foo": ["foo.js"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-extension/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/extends-extension/foo.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-extension/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./base-tsconfig" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-extensionless/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/extends-extensionless/foo.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-extensionless/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tsconfig-field/conf" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-multiple/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/extends-multiple/foo.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-multiple/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../extends-extension", "../extends-paths"], 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-not-found/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/extends-not-found/index.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-not-found/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./not-found" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-paths/src/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/extends-paths/src/index.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-paths/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "@/*": ["./*"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/extends-paths/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "src" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/field/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/field/index.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/field/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tsconfig-field" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/index/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/index/index.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/index/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tsconfig-index" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/merge_compiler_options/base-tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "experimentalDecorators": true, 4 | "jsx": "react-jsx", 5 | "jsxFactory": "h", 6 | "jsxFragmentFactory": "Fragment", 7 | "jsxImportSource": "xxx" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/merge_compiler_options/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./base-tsconfig" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/no_merge_compiler_options/base-tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "experimentalDecorators": false, 4 | "jsx": "aaa", 5 | "jsxFactory": "bbb", 6 | "jsxFragmentFactory": "ccc", 7 | "jsxImportSource": "ddd" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/no_merge_compiler_options/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./base-tsconfig", 3 | "compilerOptions": { 4 | "experimentalDecorators": true, 5 | "jsx": "react-jsx", 6 | "jsxFactory": "h", 7 | "jsxFragmentFactory": "Fragment", 8 | "jsxImportSource": "xxx" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/parent-base-url/src/index.ts: -------------------------------------------------------------------------------- 1 | export const foo = 'bar' 2 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/parent-base-url/test/story.ts: -------------------------------------------------------------------------------- 1 | export * from "index"; 2 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/parent-base-url/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfigs/tsconfig.dev" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/parent-base-url/tsconfigs/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "../src" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/parent-base-url/tsconfigs/tsconfig.dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths-nested-base/other/bar.ts: -------------------------------------------------------------------------------- 1 | // import using tsconfig.json `baseUrl` 2 | import 'foo' 3 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths-nested-base/root/foo.ts: -------------------------------------------------------------------------------- 1 | // import using tsconfig.json path mapping 2 | import 'other/bar' 3 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths-nested-base/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "root/", 4 | "paths": { 5 | "other/*": ["../other/*"] 6 | } 7 | }, 8 | "files": ["root/foo.ts", "other/bar.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths_template_variable/src/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/paths_template_variable/src/foo.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths_template_variable/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "paths": { 5 | "foo": ["${configDir}/src/foo.js"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths_template_variable/tsconfig_base_url1.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "${configDir}", 4 | "paths": { 5 | "@/*": ["./src/*"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths_template_variable/tsconfig_base_url2.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "${configDir}/", 4 | "paths": { 5 | "@/*": ["./src/*"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths_template_variable/tsconfig_extends1.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig_template_variable1.json" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths_template_variable/tsconfig_extends2.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig_template_variable2.json" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths_template_variable/tsconfig_extends3.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig_template_variable3.json" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/paths_template_variable/tsconfig_extends4.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig_template_variable4.json" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/app/aliased/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/project_references/app/aliased/index.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/app/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/project_references/app/index.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "paths": { 6 | "@/*": ["./aliased/*"] 7 | } 8 | }, 9 | "references": [ 10 | { 11 | "path": "../project_a/conf.json" 12 | }, 13 | { 14 | "path": "../project_b" 15 | }, 16 | { 17 | "path": "../project_c/tsconfig.json" 18 | }, 19 | { 20 | "path": "../../paths_template_variable/tsconfig.json" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/app/tsconfig.nopaths.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "baseUrl": "./" 5 | }, 6 | "references": [ 7 | { 8 | "path": "../project_a/conf.json" 9 | }, 10 | { 11 | "path": "../project_b" 12 | }, 13 | { 14 | "path": "../project_c/tsconfig.json" 15 | }, 16 | { 17 | "path": "../../paths_template_variable/tsconfig.json" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/project_a/aliased/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/project_references/project_a/aliased/index.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/project_a/conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "paths": { 5 | "@/*": ["./aliased/*"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/project_a/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/project_references/project_a/index.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/project_b/src/aliased/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/project_references/project_b/src/aliased/index.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/project_b/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "baseUrl": "./src", 5 | "paths": { 6 | "@/*": ["./aliased/*"] 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/project_c/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/project_references/project_c/index.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/project_c/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/project_references/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | } 4 | } 5 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/suffixes/a.ios.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/suffixes/a.ios.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/suffixes/a.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/suffixes/a.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/suffixes/b.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/suffixes/b.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/suffixes/c-test.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/suffixes/c-test.ts -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/suffixes/index.ts: -------------------------------------------------------------------------------- 1 | import './a'; 2 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/suffixes/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleSuffixes": [".ios", "-test", ""] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/trailing-comma/bar.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/trailing-comma/bar.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/trailing-comma/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/trailing-comma/index.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/trailing-comma/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | /* some comment */ 5 | "foo": ["bar.js"], 6 | }, 7 | }, 8 | // another comment 9 | } 10 | -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/with-bom/bar.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/cases/with-bom/bar.js -------------------------------------------------------------------------------- /fixtures/tsconfig/cases/with-bom/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "foo": ["bar.js"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/nested/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/nested/index.js -------------------------------------------------------------------------------- /fixtures/tsconfig/nested/test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/nested/test.js -------------------------------------------------------------------------------- /fixtures/tsconfig/nested/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "..", 3 | "compilerOptions": { 4 | "paths": { 5 | "ts-path": ["test.js"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-exports/conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "foo": ["foo.js"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-exports/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/node_modules/tsconfig-exports/foo.js -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-exports/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsconfig-exports", 3 | "private": true, 4 | "exports": { 5 | ".": "./conf.json" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-field/conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "foo": ["foo.js"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-field/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/node_modules/tsconfig-field/foo.js -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-field/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsconfig-field", 3 | "private": true, 4 | "tsconfig": "conf.json" 5 | } -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-index/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/node_modules/tsconfig-index/foo.js -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-index/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsconfig-index", 3 | "private": true 4 | } -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-index/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "foo": ["foo.js"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-not-used/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/node_modules/tsconfig-not-used/foo.js -------------------------------------------------------------------------------- /fixtures/tsconfig/node_modules/tsconfig-not-used/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "ts-path": ["foo.js"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "resolver", 3 | "private": true, 4 | "alias": { 5 | "aliased": "foo", 6 | "aliased-file": "./bar.js", 7 | "something": "./nested/test.js", 8 | "aliasedfolder": "./nested", 9 | "aliasedabsolute": "/nested", 10 | "foo/bar": "./bar.js", 11 | "glob/*/*": "./nested/$2", 12 | "./baz": "./bar.js", 13 | "url": false 14 | }, 15 | "imports": { 16 | "#test": "./bar.js" 17 | }, 18 | "dependencies": { 19 | "foo": "^0.3.4" 20 | }, 21 | "peerDependencies": { 22 | "bar": "*" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /fixtures/tsconfig/src/foo.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unrs/unrs-resolver/a184e053cec94da8a859e3d5a018a46bf32683b7/fixtures/tsconfig/src/foo.js -------------------------------------------------------------------------------- /fixtures/tsconfig/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "ts-path": ["src/foo.js"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/tsconfig_broken.json: -------------------------------------------------------------------------------- 1 | { 2 | -------------------------------------------------------------------------------- /fixtures/tsconfig/tsconfig_template_variable1.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "foo": ["${configDir}/src/foo.js"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/tsconfig/tsconfig_template_variable2.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "${configDir}", 4 | "paths": { 5 | "foo": ["./src/foo.js"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/tsconfig/tsconfig_template_variable3.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "foo": ["${configDir}/src/foo.js"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fixtures/tsconfig/tsconfig_template_variable4.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "${configDir}", 4 | "paths": { 5 | "foo": ["${configDir}/src/foo.js"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /fuzz/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | corpus 3 | artifacts 4 | coverage 5 | -------------------------------------------------------------------------------- /fuzz/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "resolver_fuzz" 3 | version = "0.0.0" 4 | edition = "2021" 5 | publish = false 6 | 7 | # Use independent workspace for fuzzers 8 | [workspace] 9 | members = ["."] 10 | 11 | [package.metadata] 12 | cargo-fuzz = true 13 | 14 | [[bin]] 15 | name = "resolver" 16 | path = "fuzz_targets/resolver.rs" 17 | test = false 18 | doc = false 19 | bench = false 20 | 21 | [dependencies] 22 | libfuzzer-sys = "0.4.7" 23 | oxc_resolver = { path = ".." } 24 | -------------------------------------------------------------------------------- /fuzz/fuzz_targets/resolver.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | 3 | use libfuzzer_sys::fuzz_target; 4 | use oxc_resolver::Resolver; 5 | 6 | fuzz_target!(|data: &[u8]| { 7 | if let Ok(s) = std::str::from_utf8(data) { 8 | if s.chars().all(|s| !s.is_control()) { 9 | let resolver = Resolver::default(); 10 | let cwd = std::env::current_dir().unwrap(); 11 | let _ = resolver.resolve(cwd, &s); 12 | } 13 | } 14 | }); 15 | -------------------------------------------------------------------------------- /justfile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S just --justfile 2 | 3 | _default: 4 | @just --list -u 5 | 6 | alias r := ready 7 | 8 | # Make sure you have cargo-binstall installed. 9 | # You can download the pre-compiled binary from 10 | # or install via `cargo install cargo-binstall` 11 | # Initialize the project by installing all the necessary tools. 12 | init: 13 | cargo binstall cargo-shear dprint typos-cli watchexec-cli -y 14 | 15 | install: 16 | pnpm install 17 | cd fixtures/pnp && yarn 18 | 19 | # When ready, run the same CI commands 20 | ready: 21 | git diff --exit-code --quiet 22 | typos 23 | cargo fmt 24 | just check 25 | just test 26 | just lint 27 | git status 28 | 29 | watch *args='': 30 | watchexec {{args}} 31 | 32 | watch-check: 33 | just watch "'cargo check; cargo clippy'" 34 | 35 | watch-example *args='': 36 | just watch "cargo run --example resolver -- {{args}}" 37 | 38 | # Run the example in `parser`, `formatter`, `linter` 39 | example *args='': 40 | cargo run --example resolver -- {{args}} 41 | 42 | # Format all files 43 | fmt: 44 | cargo shear --fix # remove all unused dependencies 45 | cargo fmt --all 46 | dprint fmt 47 | 48 | # Run cargo check 49 | check: 50 | cargo check --all-features --all-targets 51 | 52 | # Run all the tests 53 | test: 54 | cargo test --all-features 55 | pnpm test 56 | 57 | # Lint the whole project 58 | lint: 59 | cargo clippy --all-features --all-targets -- --deny warnings 60 | 61 | # Generate doc 62 | doc: 63 | RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --all-features 64 | 65 | # Get code coverage 66 | codecov: 67 | cargo codecov --html 68 | 69 | # Run the benchmarks. 70 | benchmark: 71 | cargo bench 72 | 73 | # Run cargo-fuzz 74 | fuzz: 75 | cd fuzz && cargo +nightly fuzz run --sanitizer none resolver -- -only_ascii=1 -max_total_time=900 76 | 77 | # Manual Release 78 | release: 79 | cargo binstall -y release-plz 80 | release-plz update 81 | just check 82 | # NOTE: make sure to update version in npm/package.json 83 | -------------------------------------------------------------------------------- /napi/.gitignore: -------------------------------------------------------------------------------- 1 | *.node 2 | *.wasm 3 | -------------------------------------------------------------------------------- /napi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "unrs_resolver_napi" 3 | version = "0.0.0" 4 | edition = "2024" 5 | publish = false 6 | rust-version = "1.85.0" 7 | 8 | [lib] 9 | crate-type = ["cdylib"] 10 | test = false 11 | doctest = false 12 | 13 | [dependencies] 14 | napi = { version = "3.0.0-beta.2", default-features = false, features = ["napi3", "serde-json"] } 15 | napi-derive = { version = "3.0.0-beta.2" } 16 | oxc_resolver = { path = "..", package = "unrs_resolver" } 17 | tracing-subscriber = { version = "0.3.19", default-features = false, features = ["std", "fmt"] } # Omit the `regex` feature 18 | 19 | [target.'cfg(not(any(target_os = "linux", target_os = "freebsd", target_arch = "arm", target_family = "wasm")))'.dependencies] 20 | mimalloc-safe = { version = "0.1.52", features = ["skip_collect_on_exit"] } 21 | 22 | [target.'cfg(all(target_os = "linux", not(target_arch = "arm"), not(target_arch = "aarch64")))'.dependencies] 23 | mimalloc-safe = { version = "0.1.52", features = ["skip_collect_on_exit", "local_dynamic_tls"] } 24 | 25 | [target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.dependencies] 26 | mimalloc-safe = { version = "0.1.52", features = ["skip_collect_on_exit", "local_dynamic_tls", "no_opt_arch"] } 27 | 28 | [build-dependencies] 29 | napi-build = "2.2.0" 30 | -------------------------------------------------------------------------------- /napi/README.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | ```bash 4 | corepack enable 5 | ``` 6 | 7 | # Build 8 | 9 | ```bash 10 | pnpm install 11 | pnpm run build 12 | ``` 13 | 14 | # Test 15 | 16 | ```bash 17 | pnpm test 18 | ``` 19 | -------------------------------------------------------------------------------- /napi/browser.js: -------------------------------------------------------------------------------- 1 | export * from '@unrs/resolver-binding-wasm32-wasi' 2 | -------------------------------------------------------------------------------- /napi/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | napi_build::setup(); 3 | } 4 | -------------------------------------------------------------------------------- /napi/resolver.wasi-browser.js: -------------------------------------------------------------------------------- 1 | import { 2 | createOnMessage as __wasmCreateOnMessageForFsProxy, 3 | getDefaultContext as __emnapiGetDefaultContext, 4 | instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync, 5 | WASI as __WASI, 6 | } from '@napi-rs/wasm-runtime' 7 | import { memfs } from '@napi-rs/wasm-runtime/fs' 8 | import __wasmUrl from './resolver.wasm32-wasi.wasm?url' 9 | 10 | export const { fs: __fs, vol: __volume } = memfs() 11 | 12 | const __wasi = new __WASI({ 13 | version: 'preview1', 14 | fs: __fs, 15 | preopens: { 16 | '/': '/', 17 | }, 18 | }) 19 | 20 | const __emnapiContext = __emnapiGetDefaultContext() 21 | 22 | const __sharedMemory = new WebAssembly.Memory({ 23 | initial: 4000, 24 | maximum: 65536, 25 | shared: true, 26 | }) 27 | 28 | const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer()) 29 | 30 | const { 31 | instance: __napiInstance, 32 | module: __wasiModule, 33 | napiModule: __napiModule, 34 | } = __emnapiInstantiateNapiModuleSync(__wasmFile, { 35 | context: __emnapiContext, 36 | asyncWorkPoolSize: 4, 37 | wasi: __wasi, 38 | onCreateWorker() { 39 | const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), { 40 | type: 'module', 41 | }) 42 | worker.addEventListener('message', __wasmCreateOnMessageForFsProxy(__fs)) 43 | 44 | return worker 45 | }, 46 | overwriteImports(importObject) { 47 | importObject.env = { 48 | ...importObject.env, 49 | ...importObject.napi, 50 | ...importObject.emnapi, 51 | memory: __sharedMemory, 52 | } 53 | return importObject 54 | }, 55 | beforeInit({ instance }) { 56 | for (const name of Object.keys(instance.exports)) { 57 | if (name.startsWith('__napi_register__')) { 58 | instance.exports[name]() 59 | } 60 | } 61 | }, 62 | }) 63 | export default __napiModule.exports 64 | export const ResolverFactory = __napiModule.exports.ResolverFactory 65 | export const EnforceExtension = __napiModule.exports.EnforceExtension 66 | export const sync = __napiModule.exports.sync 67 | -------------------------------------------------------------------------------- /napi/resolver.wasi.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /* prettier-ignore */ 3 | 4 | /* auto-generated by NAPI-RS */ 5 | 6 | const __nodeFs = require('node:fs') 7 | const __nodePath = require('node:path') 8 | const { WASI: __nodeWASI } = require('node:wasi') 9 | const { Worker } = require('node:worker_threads') 10 | 11 | const { 12 | createOnMessage: __wasmCreateOnMessageForFsProxy, 13 | getDefaultContext: __emnapiGetDefaultContext, 14 | instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync, 15 | } = require('@napi-rs/wasm-runtime') 16 | 17 | const __rootDir = __nodePath.parse(process.cwd()).root 18 | 19 | const __wasi = new __nodeWASI({ 20 | version: 'preview1', 21 | env: process.env, 22 | preopens: { 23 | [__rootDir]: __rootDir, 24 | } 25 | }) 26 | 27 | const __emnapiContext = __emnapiGetDefaultContext() 28 | 29 | const __sharedMemory = new WebAssembly.Memory({ 30 | initial: 4000, 31 | maximum: 65536, 32 | shared: true, 33 | }) 34 | 35 | let __wasmFilePath = __nodePath.join(__dirname, 'resolver.wasm32-wasi.wasm') 36 | const __wasmDebugFilePath = __nodePath.join(__dirname, 'resolver.wasm32-wasi.debug.wasm') 37 | 38 | if (__nodeFs.existsSync(__wasmDebugFilePath)) { 39 | __wasmFilePath = __wasmDebugFilePath 40 | } else if (!__nodeFs.existsSync(__wasmFilePath)) { 41 | try { 42 | __wasmFilePath = __nodePath.resolve('@unrs/resolver-binding-wasm32-wasi') 43 | } catch { 44 | throw new Error('Cannot find resolver.wasm32-wasi.wasm file, and @unrs/resolver-binding-wasm32-wasi package is not installed.') 45 | } 46 | } 47 | 48 | const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), { 49 | context: __emnapiContext, 50 | asyncWorkPoolSize: (function() { 51 | const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE) 52 | // NaN > 0 is false 53 | if (threadsSizeFromEnv > 0) { 54 | return threadsSizeFromEnv 55 | } else { 56 | return 4 57 | } 58 | })(), 59 | reuseWorker: true, 60 | wasi: __wasi, 61 | onCreateWorker() { 62 | const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), { 63 | env: process.env, 64 | }) 65 | worker.onmessage = ({ data }) => { 66 | __wasmCreateOnMessageForFsProxy(__nodeFs)(data) 67 | } 68 | return worker 69 | }, 70 | overwriteImports(importObject) { 71 | importObject.env = { 72 | ...importObject.env, 73 | ...importObject.napi, 74 | ...importObject.emnapi, 75 | memory: __sharedMemory, 76 | } 77 | return importObject 78 | }, 79 | beforeInit({ instance }) { 80 | for (const name of Object.keys(instance.exports)) { 81 | if (name.startsWith('__napi_register__')) { 82 | instance.exports[name]() 83 | } 84 | } 85 | }, 86 | }) 87 | module.exports = __napiModule.exports 88 | module.exports.ResolverFactory = __napiModule.exports.ResolverFactory 89 | module.exports.EnforceExtension = __napiModule.exports.EnforceExtension 90 | module.exports.sync = __napiModule.exports.sync 91 | -------------------------------------------------------------------------------- /napi/src/tracing.rs: -------------------------------------------------------------------------------- 1 | use std::sync::OnceLock; 2 | 3 | use tracing_subscriber::{ 4 | filter::Targets, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, 5 | }; 6 | 7 | /// To debug `oxc_resolver`: 8 | /// `OXC_LOG=DEBUG your program` 9 | pub fn init_tracing() { 10 | static TRACING: OnceLock<()> = OnceLock::new(); 11 | TRACING.get_or_init(|| { 12 | // Usage without the `regex` feature. 13 | // 14 | tracing_subscriber::registry() 15 | .with(std::env::var("OXC_LOG").map_or_else( 16 | |_| Targets::new(), 17 | |env_var| { 18 | use std::str::FromStr; 19 | Targets::from_str(&env_var).unwrap() 20 | }, 21 | )) 22 | .with(tracing_subscriber::fmt::layer()) 23 | .init(); 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /napi/test.mjs: -------------------------------------------------------------------------------- 1 | import assert from 'assert'; 2 | import path from 'path'; 3 | import resolve, { ResolverFactory } from './index.js'; 4 | 5 | console.log(`Testing on ${process.platform}-${process.arch}`); 6 | 7 | const dir = import.meta.dirname; 8 | 9 | // `resolve` 10 | assert.deepStrictEqual(resolve.sync(dir, './index.js').path, path.join(dir, 'index.js')); 11 | 12 | // `ResolverFactory` 13 | const resolver = new ResolverFactory(); 14 | assert.deepStrictEqual(resolver.sync(dir, './index.js').path, path.join(dir, 'index.js')); 15 | 16 | assert.strict(resolver.sync(dir, './ts').error.length > 0); 17 | 18 | resolver.async(dir, './ts') 19 | .then((result) => assert.strict(result.error.length > 0)); 20 | 21 | const newResolver = resolver.cloneWithOptions({}); 22 | newResolver.clearCache(); 23 | 24 | // custom constructor 25 | const resolver2 = new ResolverFactory( 26 | { 27 | extensions: ['.mjs'], 28 | }, 29 | ); 30 | 31 | // After add `.ts` extension, resolver can resolve `ts` as `ts.ts` now 32 | assert.deepStrictEqual(resolver2.sync(dir, './test.mjs').path, path.join(dir, 'test.mjs')); 33 | -------------------------------------------------------------------------------- /napi/tests/options.test.mjs: -------------------------------------------------------------------------------- 1 | import * as path from 'node:path'; 2 | import { assert, describe, it } from 'vitest'; 3 | 4 | import { ResolverFactory } from '../index.js'; 5 | 6 | const fixtureDir = new URL( 7 | '../../fixtures/enhanced_resolve/test/fixtures', 8 | import.meta.url, 9 | ).pathname; 10 | 11 | describe('option', () => { 12 | describe('aliasFields', () => { 13 | it('should allow field string ', () => { 14 | const resolver = new ResolverFactory({ aliasFields: ['browser'] }); 15 | assert.match( 16 | resolver.sync(fixtureDir, './browser-module/lib/replaced.js').path, 17 | /browser-module\/lib\/browser\.js$/, 18 | ); 19 | }); 20 | it('should allow json path array', () => { 21 | const resolver = new ResolverFactory({ 22 | aliasFields: [['innerBrowser1', 'field', 'browser']], 23 | }); 24 | 25 | assert.match( 26 | resolver.sync(fixtureDir, './browser-module/lib/main1.js').path, 27 | /browser-module\/lib\/main\.js$/, 28 | ); 29 | }); 30 | }); 31 | 32 | describe('exportsFields', () => { 33 | const createTest = (exportsFields) => { 34 | const resolver = new ResolverFactory({ exportsFields }); 35 | assert.match( 36 | resolver.sync( 37 | path.resolve(fixtureDir, './exports-field3'), 38 | 'exports-field', 39 | ).path, 40 | /\/exports-field\/src\/index\.js$/, 41 | ); 42 | }; 43 | it('should allow string as field item', createTest(['broken'])); 44 | it('should allow json path array as field item', createTest([['broken']])); 45 | }); 46 | 47 | describe('mainFields', () => { 48 | const createTest = (mainFields) => { 49 | const resolver = new ResolverFactory({ mainFields }); 50 | assert.match( 51 | resolver.sync(fixtureDir, '../..').path, 52 | /\/lib\/index\.js$/, 53 | ); 54 | }; 55 | it("should use `'main'` as default", createTest(undefined)); 56 | it('should allow field string', createTest('main')); 57 | it('should allow field array', createTest(['main'])); 58 | }); 59 | }); 60 | -------------------------------------------------------------------------------- /napi/tests/simple.test.mjs: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import { assert, test } from 'vitest'; 3 | 4 | import resolve, { ResolverFactory } from '../index.js'; 5 | 6 | const cwd = path.join(__dirname, '..'); 7 | 8 | test('simple', () => { 9 | // `resolve` 10 | assert.equal(resolve.sync(cwd, './index.js').path, path.join(cwd, 'index.js')); 11 | 12 | // `ResolverFactory` 13 | const resolver = new ResolverFactory(); 14 | assert.equal(resolver.sync(cwd, './index.js').path, path.join(cwd, 'index.js')); 15 | 16 | assert.isAbove(resolver.sync(cwd, './ts').error.length, 0); 17 | 18 | resolver.async(cwd, './ts') 19 | .then((result) => assert.isAbove(result.error.length, 0)); 20 | 21 | // Test API 22 | const newResolver = resolver.cloneWithOptions({}); 23 | newResolver.clearCache(); 24 | }); 25 | -------------------------------------------------------------------------------- /napi/wasi-worker-browser.mjs: -------------------------------------------------------------------------------- 1 | import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime' 2 | import { memfsExported as __memfsExported } from '@napi-rs/wasm-runtime/fs' 3 | 4 | const fs = createFsProxy(__memfsExported) 5 | 6 | const handler = new MessageHandler({ 7 | onLoad({ wasmModule, wasmMemory }) { 8 | const wasi = new WASI({ 9 | fs, 10 | preopens: { 11 | '/': '/', 12 | }, 13 | print: function () { 14 | // eslint-disable-next-line no-console 15 | console.log.apply(console, arguments) 16 | }, 17 | printErr: function() { 18 | // eslint-disable-next-line no-console 19 | console.error.apply(console, arguments) 20 | }, 21 | }) 22 | return instantiateNapiModuleSync(wasmModule, { 23 | childThread: true, 24 | wasi, 25 | overwriteImports(importObject) { 26 | importObject.env = { 27 | ...importObject.env, 28 | ...importObject.napi, 29 | ...importObject.emnapi, 30 | memory: wasmMemory, 31 | } 32 | }, 33 | }) 34 | }, 35 | }) 36 | 37 | globalThis.onmessage = function (e) { 38 | handler.handle(e) 39 | } 40 | -------------------------------------------------------------------------------- /napi/wasi-worker.mjs: -------------------------------------------------------------------------------- 1 | import fs from "node:fs"; 2 | import { createRequire } from "node:module"; 3 | import { parse } from "node:path"; 4 | import { WASI } from "node:wasi"; 5 | import { parentPort, Worker } from "node:worker_threads"; 6 | 7 | const require = createRequire(import.meta.url); 8 | 9 | const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime"); 10 | 11 | if (parentPort) { 12 | parentPort.on("message", (data) => { 13 | globalThis.onmessage({ data }); 14 | }); 15 | } 16 | 17 | Object.assign(globalThis, { 18 | self: globalThis, 19 | require, 20 | Worker, 21 | importScripts: function (f) { 22 | ;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f); 23 | }, 24 | postMessage: function (msg) { 25 | if (parentPort) { 26 | parentPort.postMessage(msg); 27 | } 28 | }, 29 | }); 30 | 31 | const emnapiContext = getDefaultContext(); 32 | 33 | const __rootDir = parse(process.cwd()).root; 34 | 35 | const handler = new MessageHandler({ 36 | onLoad({ wasmModule, wasmMemory }) { 37 | const wasi = new WASI({ 38 | version: 'preview1', 39 | env: process.env, 40 | preopens: { 41 | [__rootDir]: __rootDir, 42 | }, 43 | }); 44 | 45 | return instantiateNapiModuleSync(wasmModule, { 46 | childThread: true, 47 | wasi, 48 | context: emnapiContext, 49 | overwriteImports(importObject) { 50 | importObject.env = { 51 | ...importObject.env, 52 | ...importObject.napi, 53 | ...importObject.emnapi, 54 | memory: wasmMemory 55 | }; 56 | }, 57 | }); 58 | }, 59 | }); 60 | 61 | globalThis.onmessage = function (e) { 62 | handler.handle(e); 63 | }; 64 | -------------------------------------------------------------------------------- /npm/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !package.json 3 | !README.md 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /npm/README.md: -------------------------------------------------------------------------------- 1 | # UnRS Resolver Napi Binding 2 | 3 | See 4 | 5 | - `index.d.ts` for `resolveSync` and `ResolverFactory` API. 6 | - [README.md](https://github.com/unrs/unrs-resolver#unrs-resolver) for options. 7 | 8 | ## API 9 | 10 | `resolve(directory, specifier)` - resolve `specifier` at an absolute path to a `directory`. 11 | 12 | ### `directory` 13 | 14 | An **absolute** path to a directory where the specifier is resolved against. 15 | 16 | For CommonJS modules, it is the `__dirname` variable that contains the absolute path to the folder containing current module. 17 | 18 | For ECMAScript modules, it is the value of `import.meta.url`. 19 | 20 | Behavior is undefined when given a path to a file. 21 | 22 | ### `specifier` 23 | 24 | The string passed to `require` or `import`, i.e. `require("specifier")` or `import "specifier"` 25 | 26 | ## ESM Example 27 | 28 | ```javascript 29 | import assert from 'assert'; 30 | import path from 'path'; 31 | import resolve, { ResolverFactory } from './index.js'; 32 | 33 | // `resolve` 34 | assert(resolve.sync(process.cwd(), './index.js').path, path.join(cwd, 'index.js')); 35 | 36 | // `ResolverFactory` 37 | const resolver = new ResolverFactory(); 38 | assert(resolver.sync(process.cwd(), './index.js').path, path.join(cwd, 'index.js')); 39 | ``` 40 | -------------------------------------------------------------------------------- /npm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unrs-resolver", 3 | "version": "1.7.8", 4 | "type": "commonjs", 5 | "description": "UnRS Resolver Node API with PNP support", 6 | "repository": "git+https://github.com/unrs/unrs-resolver.git", 7 | "homepage": "https://github.com/unrs/unrs-resolver#readme", 8 | "author": "JounQin (https://www.1stG.me)", 9 | "funding": "https://opencollective.com/unrs-resolver", 10 | "license": "MIT", 11 | "main": "index.js", 12 | "browser": "browser.js", 13 | "files": [ 14 | "index.d.ts", 15 | "index.js", 16 | "browser.js" 17 | ], 18 | "scripts": { 19 | "postinstall": "napi-postinstall unrs-resolver 1.7.8 check" 20 | }, 21 | "dependencies": { 22 | "napi-postinstall": "^0.2.2" 23 | }, 24 | "napi": { 25 | "binaryName": "resolver", 26 | "packageName": "@unrs/resolver-binding", 27 | "wasm": { 28 | "browser": { 29 | "fs": true 30 | } 31 | }, 32 | "targets": [ 33 | "x86_64-pc-windows-msvc", 34 | "aarch64-pc-windows-msvc", 35 | "i686-pc-windows-msvc", 36 | "x86_64-unknown-linux-gnu", 37 | "x86_64-unknown-linux-musl", 38 | "x86_64-unknown-freebsd", 39 | "aarch64-unknown-linux-gnu", 40 | "aarch64-unknown-linux-musl", 41 | "armv7-unknown-linux-gnueabihf", 42 | "armv7-unknown-linux-musleabihf", 43 | "powerpc64le-unknown-linux-gnu", 44 | "riscv64gc-unknown-linux-gnu", 45 | "riscv64gc-unknown-linux-musl", 46 | "s390x-unknown-linux-gnu", 47 | "x86_64-apple-darwin", 48 | "aarch64-apple-darwin", 49 | "wasm32-wasip1-threads" 50 | ] 51 | }, 52 | "publishConfig": { 53 | "registry": "https://registry.npmjs.org", 54 | "access": "public" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@unrs/resolver-binding", 3 | "private": true, 4 | "version": "0.0.0", 5 | "repository": "git+https://github.com/unrs/unrs-resolver.git", 6 | "funding": "https://opencollective.com/unrs-resolver", 7 | "scripts": { 8 | "build": "napi build --platform --release --package-json-path npm/package.json --manifest-path napi/Cargo.toml", 9 | "build:debug": "napi build --platform --package-json-path npm/package.json --manifest-path napi/Cargo.toml", 10 | "prepublishOnly": "napi pre-publish -t npm", 11 | "test": "vitest run -r ./napi" 12 | }, 13 | "devDependencies": { 14 | "@napi-rs/cli": "3.0.0-alpha.81", 15 | "@napi-rs/wasm-runtime": "^0.2.10", 16 | "@types/node": "^22.15.21", 17 | "emnapi": "^1.4.3", 18 | "typescript": "^5.8.3", 19 | "vitest": "^3.1.4" 20 | }, 21 | "packageManager": "pnpm@10.11.0" 22 | } 23 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - npm 3 | - napi 4 | - fixtures/dual-condition-names 5 | - fixtures/pnpm 6 | - fixtures/pnpm-workspace/** 7 | 8 | ignoredBuiltDependencies: 9 | - esbuild 10 | 11 | # For `windows_symlinked_longfilename` in tests/resolve_test.rs 12 | virtualStoreDirMaxLength: 1024 13 | -------------------------------------------------------------------------------- /release-plz.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | semver_check = true 3 | allow_dirty = true # The "fixtures" is being marked as dirty. 4 | changelog_config = "cliff.toml" 5 | git_tag_name = "v{{ version }}" 6 | git_release_name = "v{{ version }}" 7 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["github>1stG/configs"], 4 | "ignorePaths": ["**/node_modules/**", "**/fixtures/**"] 5 | } 6 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "1.86.0" 3 | profile = "default" 4 | -------------------------------------------------------------------------------- /src/builtins.rs: -------------------------------------------------------------------------------- 1 | /// Node.js built-in modules 2 | /// 3 | /// `node -p "[...require('module').builtinModules].map(b => JSON.stringify(b)).join(',\n')"` 4 | /// 5 | pub const NODEJS_BUILTINS: &[&str] = &[ 6 | "_http_agent", 7 | "_http_client", 8 | "_http_common", 9 | "_http_incoming", 10 | "_http_outgoing", 11 | "_http_server", 12 | "_stream_duplex", 13 | "_stream_passthrough", 14 | "_stream_readable", 15 | "_stream_transform", 16 | "_stream_wrap", 17 | "_stream_writable", 18 | "_tls_common", 19 | "_tls_wrap", 20 | "assert", 21 | "assert/strict", 22 | "async_hooks", 23 | "buffer", 24 | "child_process", 25 | "cluster", 26 | "console", 27 | "constants", 28 | "crypto", 29 | "dgram", 30 | "diagnostics_channel", 31 | "dns", 32 | "dns/promises", 33 | "domain", 34 | "events", 35 | "fs", 36 | "fs/promises", 37 | "http", 38 | "http2", 39 | "https", 40 | "inspector", 41 | "module", 42 | "net", 43 | "os", 44 | "path", 45 | "path/posix", 46 | "path/win32", 47 | "perf_hooks", 48 | "process", 49 | "punycode", 50 | "querystring", 51 | "readline", 52 | "repl", 53 | "stream", 54 | "stream/consumers", 55 | "stream/promises", 56 | "stream/web", 57 | "string_decoder", 58 | "sys", 59 | "timers", 60 | "timers/promises", 61 | "tls", 62 | "trace_events", 63 | "tty", 64 | "url", 65 | "util", 66 | "util/types", 67 | "v8", 68 | "vm", 69 | "worker_threads", 70 | "zlib", 71 | ]; 72 | -------------------------------------------------------------------------------- /src/cache.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fmt::Debug, 3 | path::{Path, PathBuf}, 4 | sync::Arc, 5 | }; 6 | 7 | use crate::{Ctx, PackageJson, ResolveError, ResolveOptions, TsConfig}; 8 | 9 | #[allow(clippy::missing_errors_doc)] // trait impls should be free to return any typesafe error 10 | pub trait Cache: Sized { 11 | type Cp: CachedPath + Clone; 12 | type Pj: PackageJson; 13 | type Tc: TsConfig + Debug; 14 | 15 | /// Clears the cache. 16 | fn clear(&self); 17 | 18 | /// Returns the cached value for a given path. 19 | fn value(&self, path: &Path) -> Self::Cp; 20 | 21 | /// Returns the canonical version of a `path`, resolving all symbolic links. 22 | fn canonicalize(&self, path: &Self::Cp) -> Result; 23 | 24 | /// Returns whether the given `path` points to a file. 25 | fn is_file(&self, path: &Self::Cp, ctx: &mut Ctx) -> bool; 26 | 27 | /// Returns whether the given `path` points to a file. 28 | fn is_dir(&self, path: &Self::Cp, ctx: &mut Ctx) -> bool; 29 | 30 | /// Returns the package.json stored in the given directory, if one exists. 31 | /// 32 | /// `path` is the path to a directory from which the `package.json` will be 33 | /// read. 34 | #[allow(clippy::type_complexity)] 35 | fn get_package_json( 36 | &self, 37 | path: &Self::Cp, 38 | options: &ResolveOptions, 39 | ctx: &mut Ctx, 40 | ) -> Result)>, ResolveError>; 41 | 42 | /// Returns the tsconfig stored in the given path. 43 | /// 44 | /// `path` is either the path to a tsconfig (with or without `.json` 45 | /// extension) or a directory from which the `tsconfig.json` will be read. 46 | /// 47 | /// `callback` can be used for modifying the returned tsconfig with 48 | /// `extends`. 49 | fn get_tsconfig Result<(), ResolveError>>( 50 | &self, 51 | root: bool, 52 | path: &Path, 53 | callback: F, 54 | ) -> Result, ResolveError>; 55 | } 56 | 57 | #[allow(clippy::missing_errors_doc)] // trait impls should be free to return any typesafe error 58 | pub trait CachedPath: Sized { 59 | fn path(&self) -> &Path; 60 | 61 | fn to_path_buf(&self) -> PathBuf; 62 | 63 | fn parent(&self) -> Option<&Self>; 64 | 65 | fn module_directory>( 66 | &self, 67 | module_name: &str, 68 | cache: &C, 69 | ctx: &mut Ctx, 70 | ) -> Option; 71 | 72 | fn cached_node_modules>(&self, cache: &C, ctx: &mut Ctx) -> Option; 73 | 74 | /// Find package.json of a path by traversing parent directories. 75 | #[allow(clippy::type_complexity)] 76 | fn find_package_json>( 77 | &self, 78 | options: &ResolveOptions, 79 | cache: &C, 80 | ctx: &mut Ctx, 81 | ) -> Result)>, ResolveError>; 82 | 83 | #[must_use] 84 | fn add_extension>(&self, ext: &str, cache: &C) -> Self; 85 | 86 | #[must_use] 87 | fn replace_extension>(&self, ext: &str, cache: &C) -> Self; 88 | 89 | /// Returns a new path by resolving the given subpath (including "." and 90 | /// ".." components) with this path. 91 | #[must_use] 92 | fn normalize_with>(&self, subpath: impl AsRef, cache: &C) -> Self; 93 | 94 | #[must_use] 95 | fn normalize_root>(&self, _cache: &C) -> Self; 96 | } 97 | -------------------------------------------------------------------------------- /src/context.rs: -------------------------------------------------------------------------------- 1 | use std::path::{Path, PathBuf}; 2 | 3 | use crate::error::ResolveError; 4 | 5 | #[derive(Debug, Default, Clone)] 6 | pub struct ResolveContext { 7 | pub fully_specified: bool, 8 | 9 | pub query: Option, 10 | 11 | pub fragment: Option, 12 | 13 | /// Files that was found on file system. 14 | pub file_dependencies: Option>, 15 | 16 | /// Dependencies that was not found on file system. 17 | pub missing_dependencies: Option>, 18 | 19 | /// The current resolving alias for bailing recursion alias. 20 | pub resolving_alias: Option, 21 | 22 | /// For avoiding infinite recursion, which will cause stack overflow. 23 | depth: u8, 24 | } 25 | 26 | impl ResolveContext { 27 | pub fn with_fully_specified(&mut self, yes: bool) { 28 | self.fully_specified = yes; 29 | } 30 | 31 | pub fn with_query_fragment(&mut self, query: Option<&str>, fragment: Option<&str>) { 32 | if let Some(query) = query { 33 | self.query.replace(query.to_string()); 34 | } 35 | if let Some(fragment) = fragment { 36 | self.fragment.replace(fragment.to_string()); 37 | } 38 | } 39 | 40 | pub fn init_file_dependencies(&mut self) { 41 | self.file_dependencies.replace(vec![]); 42 | self.missing_dependencies.replace(vec![]); 43 | } 44 | 45 | pub fn add_file_dependency(&mut self, dep: &Path) { 46 | if let Some(deps) = &mut self.file_dependencies { 47 | deps.push(dep.to_path_buf()); 48 | } 49 | } 50 | 51 | pub fn add_missing_dependency(&mut self, dep: &Path) { 52 | if let Some(deps) = &mut self.missing_dependencies { 53 | deps.push(dep.to_path_buf()); 54 | } 55 | } 56 | 57 | pub fn with_resolving_alias(&mut self, alias: String) { 58 | self.resolving_alias = Some(alias); 59 | } 60 | 61 | /// Increases the context's depth in order to detect recursion. 62 | /// 63 | /// ### Errors 64 | /// 65 | /// * [ResolveError::Recursion] 66 | pub fn test_for_infinite_recursion(&mut self) -> Result<(), ResolveError> { 67 | self.depth += 1; 68 | // 64 should be more than enough for detecting infinite recursion. 69 | if self.depth > 64 { 70 | return Err(ResolveError::Recursion); 71 | } 72 | Ok(()) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/path.rs: -------------------------------------------------------------------------------- 1 | //! Path Utilities 2 | //! 3 | //! Code adapted from the following libraries 4 | //! * [path-absolutize](https://docs.rs/path-absolutize) 5 | //! * [normalize_path](https://docs.rs/normalize-path) 6 | use std::path::{Component, Path, PathBuf}; 7 | 8 | pub const SLASH_START: &[char; 2] = &['/', '\\']; 9 | 10 | /// Extension trait to add path normalization to std's [`Path`]. 11 | pub trait PathUtil { 12 | /// Normalize this path without performing I/O. 13 | /// 14 | /// All redundant separator and up-level references are collapsed. 15 | /// 16 | /// However, this does not resolve links. 17 | fn normalize(&self) -> PathBuf; 18 | 19 | /// Normalize with subpath assuming this path is normalized without performing I/O. 20 | /// 21 | /// All redundant separator and up-level references are collapsed. 22 | /// 23 | /// However, this does not resolve links. 24 | fn normalize_with>(&self, subpath: P) -> PathBuf; 25 | 26 | /// Defined in ESM PACKAGE_TARGET_RESOLVE 27 | /// If target split on "/" or "\" contains any "", ".", "..", or "node_modules" segments after the first "." segment, case insensitive and including percent encoded variants 28 | fn is_invalid_exports_target(&self) -> bool; 29 | } 30 | 31 | impl PathUtil for Path { 32 | // https://github.com/parcel-bundler/parcel/blob/e0b99c2a42e9109a9ecbd6f537844a1b33e7faf5/packages/utils/node-resolver-rs/src/path.rs#L7 33 | fn normalize(&self) -> PathBuf { 34 | let mut components = self.components().peekable(); 35 | let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek() { 36 | let buf = PathBuf::from(c.as_os_str()); 37 | components.next(); 38 | buf 39 | } else { 40 | PathBuf::new() 41 | }; 42 | 43 | for component in components { 44 | match component { 45 | Component::Prefix(..) => unreachable!("Path {:?}", self), 46 | Component::RootDir => { 47 | ret.push(component.as_os_str()); 48 | } 49 | Component::CurDir => {} 50 | Component::ParentDir => { 51 | ret.pop(); 52 | } 53 | Component::Normal(c) => { 54 | ret.push(c); 55 | } 56 | } 57 | } 58 | 59 | ret 60 | } 61 | 62 | // https://github.com/parcel-bundler/parcel/blob/e0b99c2a42e9109a9ecbd6f537844a1b33e7faf5/packages/utils/node-resolver-rs/src/path.rs#L37 63 | fn normalize_with>(&self, subpath: B) -> PathBuf { 64 | let subpath = subpath.as_ref(); 65 | 66 | let mut components = subpath.components(); 67 | 68 | let Some(head) = components.next() else { return subpath.to_path_buf() }; 69 | 70 | if matches!(head, Component::Prefix(..) | Component::RootDir) { 71 | return subpath.to_path_buf(); 72 | } 73 | 74 | let mut ret = self.to_path_buf(); 75 | for component in std::iter::once(head).chain(components) { 76 | match component { 77 | Component::CurDir => {} 78 | Component::ParentDir => { 79 | ret.pop(); 80 | } 81 | Component::Normal(c) => { 82 | ret.push(c); 83 | } 84 | Component::Prefix(..) | Component::RootDir => { 85 | unreachable!("Path {:?} Subpath {:?}", self, subpath) 86 | } 87 | } 88 | } 89 | 90 | ret 91 | } 92 | 93 | fn is_invalid_exports_target(&self) -> bool { 94 | self.components().enumerate().any(|(index, c)| match c { 95 | Component::ParentDir => true, 96 | Component::CurDir => index > 0, 97 | Component::Normal(c) => c.eq_ignore_ascii_case("node_modules"), 98 | _ => false, 99 | }) 100 | } 101 | } 102 | 103 | // https://github.com/webpack/enhanced-resolve/blob/main/test/path.test.js 104 | #[test] 105 | fn is_invalid_exports_target() { 106 | let test_cases = [ 107 | "../a.js", 108 | "../", 109 | "./a/b/../../../c.js", 110 | "./a/b/../../../", 111 | "./../../c.js", 112 | "./../../", 113 | "./a/../b/../../c.js", 114 | "./a/../b/../../", 115 | "./././../", 116 | ]; 117 | 118 | for case in test_cases { 119 | assert!(Path::new(case).is_invalid_exports_target(), "{case}"); 120 | } 121 | 122 | assert!(!Path::new("C:").is_invalid_exports_target()); 123 | assert!(!Path::new("/").is_invalid_exports_target()); 124 | } 125 | 126 | #[test] 127 | fn normalize() { 128 | assert_eq!(Path::new("/foo/.././foo/").normalize(), Path::new("/foo")); 129 | assert_eq!(Path::new("C://").normalize(), Path::new("C://")); 130 | assert_eq!(Path::new("C:").normalize(), Path::new("C:")); 131 | assert_eq!(Path::new(r"\\server\share").normalize(), Path::new(r"\\server\share")); 132 | } 133 | -------------------------------------------------------------------------------- /src/resolution.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fmt, 3 | path::{Path, PathBuf}, 4 | sync::Arc, 5 | }; 6 | 7 | use crate::{Cache, PackageJson}; 8 | 9 | /// The final path resolution with optional `?query` and `#fragment` 10 | pub struct Resolution { 11 | pub(crate) path: PathBuf, 12 | 13 | /// path query `?query`, contains `?`. 14 | pub(crate) query: Option, 15 | 16 | /// path fragment `#query`, contains `#`. 17 | pub(crate) fragment: Option, 18 | 19 | pub(crate) package_json: Option>, 20 | } 21 | 22 | impl Clone for Resolution { 23 | fn clone(&self) -> Self { 24 | Self { 25 | path: self.path.clone(), 26 | query: self.query.clone(), 27 | fragment: self.fragment.clone(), 28 | package_json: self.package_json.clone(), 29 | } 30 | } 31 | } 32 | 33 | impl fmt::Debug for Resolution { 34 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 35 | f.debug_struct("Resolution") 36 | .field("path", &self.path) 37 | .field("query", &self.query) 38 | .field("fragment", &self.fragment) 39 | .field("package_json", &self.package_json.as_ref().map(|p| p.path())) 40 | .finish() 41 | } 42 | } 43 | 44 | impl PartialEq for Resolution { 45 | fn eq(&self, other: &Self) -> bool { 46 | self.path == other.path && self.query == other.query && self.fragment == other.fragment 47 | } 48 | } 49 | impl Eq for Resolution {} 50 | 51 | impl Resolution { 52 | /// Returns the path without query and fragment 53 | #[must_use] 54 | pub fn path(&self) -> &Path { 55 | &self.path 56 | } 57 | 58 | /// Returns the path without query and fragment 59 | #[must_use] 60 | pub fn into_path_buf(self) -> PathBuf { 61 | self.path 62 | } 63 | 64 | /// Returns the path query `?query`, contains the leading `?` 65 | #[must_use] 66 | pub fn query(&self) -> Option<&str> { 67 | self.query.as_deref() 68 | } 69 | 70 | /// Returns the path fragment `#fragment`, contains the leading `#` 71 | #[must_use] 72 | pub fn fragment(&self) -> Option<&str> { 73 | self.fragment.as_deref() 74 | } 75 | 76 | /// Returns serialized package_json 77 | #[must_use] 78 | pub const fn package_json(&self) -> Option<&Arc> { 79 | self.package_json.as_ref() 80 | } 81 | 82 | /// Returns the full path with query and fragment 83 | #[must_use] 84 | pub fn full_path(&self) -> PathBuf { 85 | let mut path = self.path.clone().into_os_string(); 86 | if let Some(query) = &self.query { 87 | path.push(query); 88 | } 89 | if let Some(fragment) = &self.fragment { 90 | path.push(fragment); 91 | } 92 | PathBuf::from(path) 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/tests/builtins.rs: -------------------------------------------------------------------------------- 1 | use std::path::Path; 2 | 3 | use crate::{ResolveError, ResolveOptions, Resolver}; 4 | 5 | #[test] 6 | fn builtins_off() { 7 | let f = Path::new("/"); 8 | let resolver = Resolver::default(); 9 | let resolved_path = resolver.resolve(f, "zlib").map(|r| r.full_path()); 10 | assert_eq!(resolved_path, Err(ResolveError::NotFound("zlib".into()))); 11 | } 12 | 13 | #[test] 14 | fn builtins() { 15 | let f = Path::new("/"); 16 | 17 | let resolver = Resolver::new(ResolveOptions::default().with_builtin_modules(true)); 18 | 19 | let pass = [ 20 | "_http_agent", 21 | "_http_client", 22 | "_http_common", 23 | "_http_incoming", 24 | "_http_outgoing", 25 | "_http_server", 26 | "_stream_duplex", 27 | "_stream_passthrough", 28 | "_stream_readable", 29 | "_stream_transform", 30 | "_stream_wrap", 31 | "_stream_writable", 32 | "_tls_common", 33 | "_tls_wrap", 34 | "assert", 35 | "assert/strict", 36 | "async_hooks", 37 | "buffer", 38 | "child_process", 39 | "cluster", 40 | "console", 41 | "constants", 42 | "crypto", 43 | "dgram", 44 | "diagnostics_channel", 45 | "dns", 46 | "dns/promises", 47 | "domain", 48 | "events", 49 | "fs", 50 | "fs/promises", 51 | "http", 52 | "http2", 53 | "https", 54 | "inspector", 55 | "module", 56 | "net", 57 | "os", 58 | "path", 59 | "path/posix", 60 | "path/win32", 61 | "perf_hooks", 62 | "process", 63 | "punycode", 64 | "querystring", 65 | "readline", 66 | "repl", 67 | "stream", 68 | "stream/consumers", 69 | "stream/promises", 70 | "stream/web", 71 | "string_decoder", 72 | "sys", 73 | "timers", 74 | "timers/promises", 75 | "tls", 76 | "trace_events", 77 | "tty", 78 | "url", 79 | "util", 80 | "util/types", 81 | "v8", 82 | "vm", 83 | "worker_threads", 84 | "zlib", 85 | ]; 86 | 87 | for request in pass { 88 | let prefixed_request = format!("node:{request}"); 89 | for request in [prefixed_request.clone(), request.to_string()] { 90 | let starts_with_node = request.starts_with("node:"); 91 | let resolved_path = resolver.resolve(f, &request).map(|r| r.full_path()); 92 | let err = ResolveError::Builtin { 93 | resolved: prefixed_request.clone(), 94 | is_runtime_module: starts_with_node, 95 | }; 96 | assert_eq!(resolved_path, Err(err), "{request}"); 97 | } 98 | } 99 | } 100 | 101 | #[test] 102 | fn fail() { 103 | let f = Path::new("/"); 104 | let resolver = Resolver::new(ResolveOptions::default().with_builtin_modules(true)); 105 | let request = "xxx"; 106 | let resolved_path = resolver.resolve(f, request); 107 | let err = ResolveError::NotFound(request.to_string()); 108 | assert_eq!(resolved_path, Err(err), "{request}"); 109 | } 110 | 111 | #[test] 112 | fn imports() { 113 | let f = super::fixture().join("builtins"); 114 | let resolver = Resolver::new(ResolveOptions { 115 | builtin_modules: true, 116 | condition_names: vec!["node".into()], 117 | ..ResolveOptions::default() 118 | }); 119 | 120 | for (request, is_runtime_module) in [("#fs", false), ("#http", true)] { 121 | let resolved_path = resolver.resolve(f.clone(), request).map(|r| r.full_path()); 122 | let err = ResolveError::Builtin { 123 | resolved: (format!("node:{}", request.trim_start_matches('#'))), 124 | is_runtime_module, 125 | }; 126 | assert_eq!(resolved_path, Err(err)); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/tests/dependencies.rs: -------------------------------------------------------------------------------- 1 | //! https://github.com/webpack/enhanced-resolve/blob/main/test/dependencies.test.js 2 | 3 | #[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows. 4 | mod windows { 5 | use std::{path::PathBuf, sync::Arc}; 6 | 7 | use super::super::memory_fs::MemoryFS; 8 | use crate::{FsCache, ResolveContext, ResolveOptions, ResolverGeneric}; 9 | 10 | fn file_system() -> MemoryFS { 11 | MemoryFS::new(&[ 12 | ("/a/b/node_modules/some-module/index.js", ""), 13 | ("/a/node_modules/module/package.json", r#"{"main":"entry.js"}"#), 14 | ("/a/node_modules/module/file.js", r#"{"main":"entry.js"}"#), 15 | ("/modules/other-module/file.js", ""), 16 | ]) 17 | } 18 | 19 | #[test] 20 | fn test() { 21 | let file_system = file_system(); 22 | 23 | let resolver = ResolverGeneric::new_with_cache( 24 | Arc::new(FsCache::new(file_system)), 25 | ResolveOptions { 26 | extensions: vec![".json".into(), ".js".into()], 27 | modules: vec!["/modules".into(), "node_modules".into()], 28 | ..ResolveOptions::default() 29 | }, 30 | ); 31 | 32 | let data = [ 33 | ( 34 | "middle module request", 35 | "/a/b/c", 36 | "module/file", 37 | "/a/node_modules/module/file.js", 38 | // These dependencies are different from enhanced-resolve due to different code path to 39 | // querying the file system 40 | vec![ 41 | // found package.json 42 | "/a/node_modules/module/package.json", 43 | // symlink checks 44 | "/a/node_modules/module/file.js", 45 | // "/a/node_modules/module", 46 | // "/a/node_modules", 47 | // "/a", 48 | // "/", 49 | ], 50 | vec![ 51 | // missing package.jsons 52 | // "/a/b/c/package.json", 53 | "/a/b/package.json", 54 | "/a/package.json", 55 | "/package.json", 56 | // missing modules directories 57 | "/a/b/c", 58 | // "/a/b/c/node_modules", 59 | // missing single file modules 60 | "/modules/module", 61 | "/a/b/node_modules/module", 62 | // missing files with alternative extensions 63 | "/a/node_modules/module/file", 64 | "/a/node_modules/module/file.json", 65 | ], 66 | ), 67 | ( 68 | "fast found module", 69 | "/a/b/c", 70 | "other-module/file.js", 71 | "/modules/other-module/file.js", 72 | // These dependencies are different from enhanced-resolve due to different code path to 73 | // querying the file system 74 | vec![ 75 | // symlink checks 76 | "/modules/other-module/file.js", 77 | // "/modules/other-module", 78 | // "/modules", 79 | // "/", 80 | ], 81 | vec![ 82 | // missing package.jsons 83 | // "/a/b/c/package.json", 84 | "/a/b/c", 85 | "/a/b/package.json", 86 | "/a/package.json", 87 | "/package.json", 88 | "/modules/other-module/package.json", 89 | "/modules/package.json", 90 | ], 91 | ), 92 | ]; 93 | 94 | for (name, context, request, result, file_dependencies, missing_dependencies) in data { 95 | let mut ctx = ResolveContext::default(); 96 | let path = PathBuf::from(context); 97 | let resolved_path = 98 | resolver.resolve_with_context(path, request, &mut ctx).map(|r| r.full_path()); 99 | assert_eq!(resolved_path, Ok(PathBuf::from(result))); 100 | let file_dependencies = file_dependencies.iter().map(PathBuf::from).collect(); 101 | let missing_dependencies = missing_dependencies.iter().map(PathBuf::from).collect(); 102 | assert_eq!(ctx.file_dependencies, file_dependencies, "{name}"); 103 | assert_eq!(ctx.missing_dependencies, missing_dependencies, "{name}"); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/tests/extension_alias.rs: -------------------------------------------------------------------------------- 1 | //! 2 | 3 | use crate::{ResolveError, ResolveOptions, Resolver}; 4 | 5 | #[test] 6 | fn extension_alias() { 7 | let f = super::fixture().join("extension-alias"); 8 | 9 | let resolver = Resolver::new(ResolveOptions { 10 | extensions: vec![".js".into()], 11 | main_files: vec!["index.js".into()], 12 | extension_alias: vec![ 13 | (".js".into(), vec![".ts".into(), ".js".into()]), 14 | (".mjs".into(), vec![".mts".into()]), 15 | ], 16 | ..ResolveOptions::default() 17 | }); 18 | 19 | #[rustfmt::skip] 20 | let pass = [ 21 | ("should alias fully specified file", f.clone(), "./index.js", f.join("index.ts")), 22 | ("should alias fully specified file when there are two alternatives", f.clone(), "./dir/index.js", f.join("dir/index.ts")), 23 | ("should also allow the second alternative", f.clone(), "./dir2/index.js", f.join("dir2/index.js")), 24 | ("should support alias option without an array", f.clone(), "./dir2/index.mjs", f.join("dir2/index.mts")), 25 | ]; 26 | 27 | for (comment, path, request, expected) in pass { 28 | let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); 29 | assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); 30 | } 31 | 32 | // should not allow to fallback to the original extension or add extensions 33 | let resolution = resolver.resolve(&f, "./index.mjs").unwrap_err(); 34 | let expected = ResolveError::ExtensionAlias("index.mjs".into(), "index.mts".into(), f); 35 | assert_eq!(resolution, expected); 36 | } 37 | 38 | // should not apply extension alias to extensions or mainFiles field 39 | #[test] 40 | fn not_apply_to_extension_nor_main_files() { 41 | let f = super::fixture().join("extension-alias"); 42 | 43 | let resolver = Resolver::new(ResolveOptions { 44 | extensions: vec![".js".into()], 45 | main_files: vec!["index.js".into()], 46 | extension_alias: vec![(".js".into(), vec![])], 47 | ..ResolveOptions::default() 48 | }); 49 | 50 | #[rustfmt::skip] 51 | let pass = [ 52 | ("directory", f.clone(), "./dir2", "dir2/index.js"), 53 | ("file", f.clone(), "./dir2/index", "dir2/index.js"), 54 | ]; 55 | 56 | for (comment, path, request, expected) in pass { 57 | let resolved_path = resolver.resolve(&path, request).map(|r| r.full_path()); 58 | let expected = f.join(expected); 59 | assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/tests/extensions.rs: -------------------------------------------------------------------------------- 1 | //! 2 | 3 | use rustc_hash::FxHashSet; 4 | 5 | use crate::{EnforceExtension, Resolution, ResolveContext, ResolveError, ResolveOptions, Resolver}; 6 | 7 | #[test] 8 | fn extensions() { 9 | let f = super::fixture().join("extensions"); 10 | 11 | let resolver = Resolver::new(ResolveOptions { 12 | extensions: vec![".ts".into(), ".js".into()], 13 | ..ResolveOptions::default() 14 | }); 15 | 16 | #[rustfmt::skip] 17 | let pass = [ 18 | ("should resolve according to order of provided extensions", "./foo", "foo.ts"), 19 | ("should resolve according to order of provided extensions (dir index)", "./dir", "dir/index.ts"), 20 | ("should resolve according to main field in module root", ".", "index.js"), 21 | // This is a core module 22 | // ("should resolve single file module before directory", "module", "node_modules/module.js"), 23 | ("should resolve trailing slash directory before single file", "module/", "node_modules/module/index.ts"), 24 | ]; 25 | 26 | for (comment, request, expected_path) in pass { 27 | let resolved_path = resolver.resolve(&f, request).map(|r| r.full_path()); 28 | let expected = f.join(expected_path); 29 | assert_eq!(resolved_path, Ok(expected), "{comment} {request} {expected_path}"); 30 | } 31 | 32 | #[rustfmt::skip] 33 | let fail = [ 34 | ("not resolve to file when request has a trailing slash (relative)", "./foo.js/", "./foo.js/".into()) 35 | ]; 36 | 37 | for (comment, request, expected_error) in fail { 38 | let resolution = resolver.resolve(&f, request); 39 | let error = ResolveError::NotFound(expected_error); 40 | assert_eq!(resolution, Err(error), "{comment} {request} {resolution:?}"); 41 | } 42 | } 43 | 44 | // should default enforceExtension to true when extensions includes an empty string 45 | #[test] 46 | fn default_enforce_extension() { 47 | let f = super::fixture().join("extensions"); 48 | 49 | let mut ctx = ResolveContext::default(); 50 | let resolved = Resolver::new(ResolveOptions { 51 | extensions: vec![".ts".into(), String::new(), ".js".into()], 52 | ..ResolveOptions::default() 53 | }) 54 | .resolve_with_context(&f, "./foo", &mut ctx); 55 | 56 | assert_eq!(resolved.map(Resolution::into_path_buf), Ok(f.join("foo.ts"))); 57 | assert_eq!( 58 | ctx.file_dependencies, 59 | FxHashSet::from_iter([f.join("foo.ts"), f.join("package.json")]) 60 | ); 61 | assert!(ctx.missing_dependencies.is_empty()); 62 | } 63 | 64 | // should respect enforceExtension when extensions includes an empty string 65 | #[test] 66 | fn respect_enforce_extension() { 67 | let f = super::fixture().join("extensions"); 68 | 69 | let mut ctx = ResolveContext::default(); 70 | let resolved = Resolver::new(ResolveOptions { 71 | enforce_extension: EnforceExtension::Disabled, 72 | extensions: vec![".ts".into(), String::new(), ".js".into()], 73 | ..ResolveOptions::default() 74 | }) 75 | .resolve_with_context(&f, "./foo", &mut ctx); 76 | 77 | assert_eq!(resolved.map(Resolution::into_path_buf), Ok(f.join("foo.ts"))); 78 | assert_eq!( 79 | ctx.file_dependencies, 80 | FxHashSet::from_iter([f.join("foo.ts"), f.join("package.json")]) 81 | ); 82 | assert_eq!(ctx.missing_dependencies, FxHashSet::from_iter([f.join("foo")])); 83 | } 84 | 85 | #[test] 86 | fn multi_dot_extension() { 87 | let f = super::fixture().join("extensions"); 88 | 89 | let resolver = Resolver::new(ResolveOptions { 90 | // Test for `.d.ts`, not part of enhanced-resolve. 91 | extensions: vec![".a.b.c".into(), ".d.ts".into(), ".ts".into(), ".js".into()], 92 | extension_alias: vec![(".ts".into(), vec![".ts".into(), ".d.ts".into()])], 93 | ..ResolveOptions::default() 94 | }); 95 | 96 | #[rustfmt::skip] 97 | let pass = [ 98 | ("should resolve according to order of provided extensions", "./foo", "foo.ts"), 99 | ("should resolve .d.ts for .ts", "./bar.ts", "bar.d.ts"), 100 | ("should resolve file with extension", "./app.module", "app.module.js") 101 | ]; 102 | 103 | for (comment, request, expected_path) in pass { 104 | let resolved_path = resolver.resolve(&f, request).map(|r| r.full_path()); 105 | let expected = f.join(expected_path); 106 | assert_eq!(resolved_path, Ok(expected), "{comment} {request} {expected_path}"); 107 | } 108 | 109 | #[rustfmt::skip] 110 | let fail = [ 111 | ("not resolve to file", "./index.", "./index.".into()) 112 | ]; 113 | 114 | for (comment, request, expected_error) in fail { 115 | let resolution = resolver.resolve(&f, request); 116 | let error = ResolveError::NotFound(expected_error); 117 | assert_eq!(resolution, Err(error), "{comment} {request} {resolution:?}"); 118 | } 119 | } 120 | 121 | #[test] 122 | #[should_panic = "All extensions must start with a leading dot"] 123 | fn without_leading_dot() { 124 | let _ = Resolver::new(ResolveOptions { 125 | extensions: vec!["ts".into(), "js".into()], 126 | ..ResolveOptions::default() 127 | }); 128 | } 129 | -------------------------------------------------------------------------------- /src/tests/incorrect_description_file.rs: -------------------------------------------------------------------------------- 1 | //! 2 | 3 | use rustc_hash::FxHashSet; 4 | 5 | use crate::{JSONError, Resolution, ResolveContext, ResolveError, ResolveOptions, Resolver}; 6 | 7 | // should not resolve main in incorrect description file #1 8 | #[test] 9 | fn incorrect_description_file_1() { 10 | let f = super::fixture().join("incorrect-package"); 11 | let mut ctx = ResolveContext::default(); 12 | let resolution = Resolver::default().resolve_with_context(f.join("pack1"), ".", &mut ctx); 13 | let _error = ResolveError::JSON(JSONError { 14 | path: f.join("pack1/package.json"), 15 | message: String::from("EOF while parsing a value at line 3 column 0"), 16 | line: 3, 17 | column: 0, 18 | content: None, 19 | }); 20 | 21 | assert!(matches!(resolution, Err(ResolveError::JSON(_)))); 22 | assert_eq!( 23 | ctx.file_dependencies, 24 | FxHashSet::from_iter([f.join("pack1"), f.join("pack1/package.json")]) 25 | ); 26 | assert!(!ctx.missing_dependencies.is_empty()); 27 | } 28 | 29 | // should not resolve main in incorrect description file #2 30 | #[test] 31 | fn incorrect_description_file_2() { 32 | let f = super::fixture().join("incorrect-package"); 33 | let resolution = Resolver::default().resolve(f.join("pack2"), "."); 34 | let _error = ResolveError::JSON(JSONError { 35 | path: f.join("pack2/package.json"), 36 | message: String::from("EOF while parsing a value at line 1 column 0"), 37 | line: 1, 38 | column: 0, 39 | content: Some(String::new()), 40 | }); 41 | assert!(matches!(resolution, Err(ResolveError::JSON(_)))); 42 | } 43 | 44 | // should not resolve main in incorrect description file #3 45 | #[test] 46 | fn incorrect_description_file_3() { 47 | let f = super::fixture().join("incorrect-package"); 48 | let resolution = Resolver::default().resolve(f.join("pack2"), "."); 49 | assert!(resolution.is_err()); 50 | } 51 | 52 | // `enhanced_resolve` does not have this test case 53 | #[test] 54 | fn no_description_file() { 55 | let f = super::fixture_root().join("enhanced_resolve"); 56 | 57 | // has description file 58 | let resolver = Resolver::default(); 59 | assert_eq!( 60 | resolver.resolve(&f, ".").map(Resolution::into_path_buf), 61 | Ok(f.join("lib/index.js")) 62 | ); 63 | 64 | // without description file 65 | let resolver = 66 | Resolver::new(ResolveOptions { description_files: vec![], ..ResolveOptions::default() }); 67 | assert_eq!(resolver.resolve(&f, "."), Err(ResolveError::NotFound(".".into()))); 68 | } 69 | -------------------------------------------------------------------------------- /src/tests/main_field.rs: -------------------------------------------------------------------------------- 1 | //! Not part of enhanced_resolve's test suite 2 | 3 | use crate::{ResolveOptions, Resolver}; 4 | 5 | #[test] 6 | fn test() { 7 | let f = super::fixture().join("restrictions"); 8 | 9 | let resolver1 = Resolver::new(ResolveOptions { 10 | main_fields: vec!["style".into()], 11 | ..ResolveOptions::default() 12 | }); 13 | 14 | let resolution = resolver1.resolve(&f, "pck2").map(|r| r.full_path()); 15 | assert_eq!(resolution, Ok(f.join("node_modules/pck2/index.css"))); 16 | 17 | let resolver2 = resolver1.clone_with_options(ResolveOptions { 18 | main_fields: vec!["module".into(), "main".into()], 19 | ..ResolveOptions::default() 20 | }); 21 | 22 | let resolution = resolver2.resolve(&f, "pck2").map(|r| r.full_path()); 23 | assert_eq!(resolution, Ok(f.join("node_modules/pck2/module.js"))); 24 | } 25 | 26 | #[test] 27 | fn test_fallback() { 28 | let f = super::fixture_root().join("invalid"); 29 | 30 | let resolver1 = Resolver::new(ResolveOptions { 31 | main_fields: vec!["module".into(), "main".into()], 32 | extension_alias: vec![(".js".into(), vec![".ts".into(), ".js".into()])], 33 | ..ResolveOptions::default() 34 | }); 35 | 36 | let resolution = resolver1.resolve(&f, "main_field_fallback").map(|r| r.full_path()); 37 | assert_eq!(resolution, Ok(f.join("node_modules/main_field_fallback/exist.js"))); 38 | } 39 | -------------------------------------------------------------------------------- /src/tests/memory_fs.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | io, 3 | path::{Path, PathBuf}, 4 | }; 5 | 6 | use crate::{FileMetadata, FileSystem, ResolveError}; 7 | 8 | #[derive(Default)] 9 | pub struct MemoryFS { 10 | fs: vfs::MemoryFS, 11 | } 12 | 13 | impl MemoryFS { 14 | /// # Panics 15 | /// 16 | /// * Fails to create directory 17 | /// * Fails to write file 18 | #[allow(dead_code)] 19 | pub fn new(data: &[(&'static str, &'static str)]) -> Self { 20 | let mut fs = Self { fs: vfs::MemoryFS::default() }; 21 | for (path, content) in data { 22 | fs.add_file(Path::new(path), content); 23 | } 24 | fs 25 | } 26 | 27 | #[allow(dead_code)] 28 | pub fn add_file(&mut self, path: &Path, content: &str) { 29 | use vfs::FileSystem; 30 | let fs = &mut self.fs; 31 | // Create all parent directories 32 | for path in path.ancestors().collect::>().iter().rev() { 33 | let path = path.to_string_lossy(); 34 | if !fs.exists(path.as_ref()).unwrap() { 35 | fs.create_dir(path.as_ref()).unwrap(); 36 | } 37 | } 38 | // Create file 39 | let mut file = fs.create_file(path.to_string_lossy().as_ref()).unwrap(); 40 | file.write_all(content.as_bytes()).unwrap(); 41 | } 42 | } 43 | 44 | impl FileSystem for MemoryFS { 45 | fn read_to_string(&self, path: &Path) -> io::Result { 46 | use vfs::FileSystem; 47 | let mut file = self 48 | .fs 49 | .open_file(path.to_string_lossy().as_ref()) 50 | .map_err(|err| io::Error::new(io::ErrorKind::NotFound, err))?; 51 | let mut buffer = String::new(); 52 | file.read_to_string(&mut buffer).unwrap(); 53 | Ok(buffer) 54 | } 55 | fn read(&self, path: &Path) -> io::Result> { 56 | let buf = self.read_to_string(path)?; 57 | Ok(buf.into_bytes()) 58 | } 59 | 60 | fn metadata(&self, path: &Path) -> io::Result { 61 | use vfs::FileSystem; 62 | let metadata = self 63 | .fs 64 | .metadata(path.to_string_lossy().as_ref()) 65 | .map_err(|err| io::Error::new(io::ErrorKind::NotFound, err))?; 66 | let is_file = metadata.file_type == vfs::VfsFileType::File; 67 | let is_dir = metadata.file_type == vfs::VfsFileType::Directory; 68 | Ok(FileMetadata::new(is_file, is_dir, false)) 69 | } 70 | 71 | fn symlink_metadata(&self, path: &Path) -> io::Result { 72 | self.metadata(path) 73 | } 74 | 75 | fn read_link(&self, _path: &Path) -> Result { 76 | Err(io::Error::new(io::ErrorKind::NotFound, "not a symlink").into()) 77 | } 78 | 79 | fn canonicalize(&self, _path: &Path) -> io::Result { 80 | Err(io::Error::new(io::ErrorKind::NotFound, "not a symlink")) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/tests/missing.rs: -------------------------------------------------------------------------------- 1 | //! https://github.com/webpack/enhanced-resolve/blob/main/test/missing.test.js 2 | 3 | use normalize_path::NormalizePath; 4 | 5 | use crate::{AliasValue, ResolveContext, ResolveOptions, Resolver}; 6 | 7 | #[test] 8 | fn test() { 9 | let f = super::fixture(); 10 | 11 | let data = [ 12 | ( 13 | "./missing-file", 14 | vec![f.join("missing-file"), f.join("missing-file.js"), f.join("missing-file.node")], 15 | ), 16 | ( 17 | "missing-module", 18 | vec![ 19 | f.join("node_modules/missing-module"), 20 | f.parent().unwrap().join("node_modules"), // enhanced-resolve is "node_modules/missing-module" 21 | ], 22 | ), 23 | ( 24 | "missing-module/missing-file", 25 | vec![ 26 | f.join("node_modules/missing-module"), 27 | // f.parent().unwrap().join("node_modules/missing-module"), // we don't report this 28 | ], 29 | ), 30 | ( 31 | "m1/missing-file", 32 | vec![ 33 | f.join("node_modules/m1/missing-file"), 34 | f.join("node_modules/m1/missing-file.js"), 35 | f.join("node_modules/m1/missing-file.node"), 36 | // f.parent().unwrap().join("node_modules/m1"), // we don't report this 37 | ], 38 | ), 39 | ( 40 | "m1/", 41 | vec![ 42 | f.join("node_modules/m1/index"), 43 | f.join("node_modules/m1/index.js"), 44 | f.join("node_modules/m1/index.json"), 45 | f.join("node_modules/m1/index.node"), 46 | ], 47 | ), 48 | ("m1/a", vec![f.join("node_modules/m1/a")]), 49 | ]; 50 | 51 | let resolver = Resolver::default(); 52 | 53 | for (specifier, missing_dependencies) in data { 54 | let mut ctx = ResolveContext::default(); 55 | let _ = resolver.resolve_with_context(&f, specifier, &mut ctx); 56 | 57 | for path in ctx.file_dependencies { 58 | assert_eq!(path, path.normalize(), "{path:?}"); 59 | } 60 | 61 | for path in missing_dependencies { 62 | assert_eq!(path, path.normalize(), "{path:?}"); 63 | assert!( 64 | ctx.missing_dependencies.contains(&path), 65 | "{specifier}: {path:?} not in {:?}", 66 | &ctx.missing_dependencies 67 | ); 68 | } 69 | } 70 | } 71 | 72 | #[test] 73 | fn alias_and_extensions() { 74 | let f = super::fixture(); 75 | 76 | let resolver = Resolver::new(ResolveOptions { 77 | alias: vec![ 78 | ( 79 | "@scope-js/package-name/dir$".into(), 80 | vec![AliasValue::Path(f.join("foo/index.js").to_string_lossy().to_string())], 81 | ), 82 | ( 83 | "react-dom".into(), 84 | vec![AliasValue::Path(f.join("foo/index.js").to_string_lossy().to_string())], 85 | ), 86 | ], 87 | extensions: vec![".server.ts".into()], 88 | 89 | ..ResolveOptions::default() 90 | }); 91 | 92 | let mut ctx = ResolveContext::default(); 93 | let _ = resolver.resolve_with_context(&f, "@scope-js/package-name/dir/router", &mut ctx); 94 | let _ = resolver.resolve_with_context(&f, "react-dom/client", &mut ctx); 95 | 96 | for path in ctx.file_dependencies { 97 | assert_eq!(path, path.normalize(), "{path:?}"); 98 | } 99 | 100 | for path in ctx.missing_dependencies { 101 | assert_eq!(path, path.normalize(), "{path:?}"); 102 | if let Some(path) = path.parent() { 103 | assert!(!path.is_file(), "{path:?} must not be a file"); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod alias; 2 | mod browser_field; 3 | mod builtins; 4 | mod dependencies; 5 | mod exports_field; 6 | mod extension_alias; 7 | mod extensions; 8 | mod fallback; 9 | mod full_specified; 10 | mod imports_field; 11 | mod incorrect_description_file; 12 | mod main_field; 13 | mod memory_fs; 14 | mod missing; 15 | #[cfg(feature = "yarn_pnp")] 16 | mod pnp; 17 | mod resolution; 18 | mod resolve; 19 | mod restrictions; 20 | mod roots; 21 | mod scoped_packages; 22 | mod simple; 23 | mod symlink; 24 | mod tsconfig_paths; 25 | mod tsconfig_project_references; 26 | mod windows; 27 | 28 | use std::{env, path::PathBuf, sync::Arc, thread}; 29 | 30 | use crate::Resolver; 31 | 32 | pub fn fixture_root() -> PathBuf { 33 | env::current_dir().unwrap().join("fixtures") 34 | } 35 | 36 | pub fn fixture() -> PathBuf { 37 | fixture_root().join("enhanced_resolve").join("test").join("fixtures") 38 | } 39 | 40 | #[test] 41 | fn threaded_environment() { 42 | let cwd = env::current_dir().unwrap(); 43 | let resolver = Arc::new(Resolver::default()); 44 | for _ in 0..2 { 45 | _ = thread::spawn({ 46 | let cwd = cwd.clone(); 47 | let resolver = Arc::clone(&resolver); 48 | move || { 49 | _ = resolver.resolve(cwd, "."); 50 | } 51 | }) 52 | .join(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/tests/pnp.rs: -------------------------------------------------------------------------------- 1 | //! Not part of enhanced_resolve's test suite 2 | //! 3 | //! enhanced_resolve's test 4 | //! cannot be ported over because it uses mocks on `pnpApi` provided by the runtime. 5 | 6 | use crate::ResolveError::NotFound; 7 | use crate::{ResolveOptions, Resolver}; 8 | 9 | #[test] 10 | fn pnp_basic() { 11 | let fixture = super::fixture_root().join("pnp"); 12 | 13 | let resolver = Resolver::new(ResolveOptions { 14 | extensions: vec![".js".into()], 15 | condition_names: vec!["import".into()], 16 | ..ResolveOptions::default() 17 | }); 18 | 19 | assert_eq!( 20 | resolver.resolve(&fixture, "is-even").map(|r| r.full_path()), 21 | Ok(fixture.join( 22 | ".yarn/cache/is-even-npm-1.0.0-9f726520dc-2728cc2f39.zip/node_modules/is-even/index.js" 23 | )) 24 | ); 25 | 26 | assert_eq!( 27 | resolver.resolve(&fixture, "lodash.zip").map(|r| r.full_path()), 28 | Ok(fixture.join( 29 | ".yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-e596da80a6.zip/node_modules/lodash.zip/index.js" 30 | )) 31 | ); 32 | 33 | assert_eq!( 34 | resolver 35 | .resolve( 36 | fixture.join( 37 | ".yarn/cache/is-even-npm-1.0.0-9f726520dc-2728cc2f39.zip/node_modules/is-even" 38 | ), 39 | "is-odd" 40 | ) 41 | .map(|r| r.full_path()), 42 | Ok(fixture.join( 43 | ".yarn/cache/is-odd-npm-0.1.2-9d980a9da8-7dc6c6fd00.zip/node_modules/is-odd/index.js" 44 | )), 45 | ); 46 | 47 | assert_eq!( 48 | resolver.resolve(&fixture, "is-odd").map(|r| r.full_path()), 49 | Ok(fixture.join( 50 | ".yarn/cache/is-odd-npm-3.0.1-93c3c3f41b-89ee2e353c.zip/node_modules/is-odd/index.js" 51 | )), 52 | ); 53 | 54 | assert_eq!( 55 | resolver.resolve(&fixture, "preact").map(|r| r.full_path()), 56 | Ok(fixture.join( 57 | ".yarn/cache/preact-npm-10.26.5-d46ec4e2ac-542a924009.zip/node_modules/preact/dist/preact.mjs" 58 | )), 59 | ); 60 | 61 | assert_eq!( 62 | resolver.resolve(&fixture, "preact/devtools").map(|r| r.full_path()), 63 | Ok(fixture.join( 64 | ".yarn/cache/preact-npm-10.26.5-d46ec4e2ac-542a924009.zip/node_modules/preact/devtools/dist/devtools.mjs" 65 | )), 66 | ); 67 | 68 | assert_eq!( 69 | resolver.resolve(&fixture, "pnpapi").map(|r| r.full_path()), 70 | Ok(fixture.join(".pnp.cjs")), 71 | ); 72 | } 73 | 74 | #[test] 75 | fn resolve_in_pnp_linked_folder() { 76 | let fixture = super::fixture_root().join("pnp"); 77 | 78 | let resolver = Resolver::new(ResolveOptions { 79 | extensions: vec![".js".into()], 80 | condition_names: vec!["import".into()], 81 | ..ResolveOptions::default() 82 | }); 83 | 84 | assert_eq!( 85 | resolver.resolve(&fixture, "lib/lib.js").map(|r| r.full_path()), 86 | Ok(fixture.join("shared/lib.js")) 87 | ); 88 | } 89 | 90 | #[test] 91 | fn resolve_pnp_pkg_should_failed_while_disable_pnp_mode() { 92 | let fixture = super::fixture_root().join("pnp"); 93 | 94 | let resolver = Resolver::new(ResolveOptions { enable_pnp: false, ..ResolveOptions::default() }); 95 | 96 | assert_eq!( 97 | resolver.resolve(&fixture, "is-even").map(|r| r.full_path()), 98 | Err(NotFound("is-even".to_string())) 99 | ); 100 | } 101 | 102 | #[test] 103 | fn resolve_package_deep_link() { 104 | let fixture = super::fixture_root().join("pnp"); 105 | 106 | let resolver = Resolver::new(ResolveOptions::default()); 107 | 108 | assert_eq!( 109 | resolver.resolve(fixture.join("shared"), "beachball/lib/commands/bump.js").map(|r| r.full_path()), 110 | Ok(fixture.join( 111 | ".yarn/cache/beachball-npm-2.52.0-ee48e46454-96b8c49193.zip/node_modules/beachball/lib/commands/bump.js" 112 | )), 113 | ); 114 | } 115 | 116 | #[test] 117 | fn resolve_pnp_nested_package_json() { 118 | let fixture = super::fixture_root().join("pnp"); 119 | 120 | let resolver = Resolver::new({ 121 | ResolveOptions { 122 | main_fields: vec!["module".into(), "main".into()], 123 | ..ResolveOptions::default() 124 | } 125 | }); 126 | 127 | assert_eq!( 128 | resolver.resolve(&fixture, "@atlaskit/pragmatic-drag-and-drop/combine").map(|r| r.full_path()), 129 | Ok(fixture.join( 130 | ".yarn/cache/@atlaskit-pragmatic-drag-and-drop-npm-1.5.2-3241d4f843-1dace49fa3.zip/node_modules/@atlaskit/pragmatic-drag-and-drop/dist/esm/entry-point/combine.js" 131 | )) 132 | ); 133 | } 134 | -------------------------------------------------------------------------------- /src/tests/resolution.rs: -------------------------------------------------------------------------------- 1 | use std::path::{Path, PathBuf}; 2 | 3 | use crate::{FsCache, Resolution, tests::memory_fs::MemoryFS}; 4 | 5 | #[test] 6 | fn test() { 7 | let resolution: Resolution> = Resolution { 8 | path: PathBuf::from("foo"), 9 | query: Some("?query".to_string()), 10 | fragment: Some("#fragment".to_string()), 11 | package_json: None, 12 | }; 13 | assert_eq!(resolution.path(), Path::new("foo")); 14 | assert_eq!(resolution.query(), Some("?query")); 15 | assert_eq!(resolution.fragment(), Some("#fragment")); 16 | assert_eq!(resolution.full_path(), PathBuf::from("foo?query#fragment")); 17 | assert_eq!(resolution.into_path_buf(), PathBuf::from("foo")); 18 | } 19 | -------------------------------------------------------------------------------- /src/tests/restrictions.rs: -------------------------------------------------------------------------------- 1 | //! 2 | 3 | use crate::{ResolveError, ResolveOptions, Resolver, Restriction}; 4 | 5 | // TODO: regex 6 | // * should respect RegExp restriction 7 | // * should try to find alternative #1 8 | // * should try to find alternative #2 9 | // * should try to find alternative #3 10 | 11 | // should respect string restriction 12 | #[test] 13 | fn restriction1() { 14 | let fixture = super::fixture(); 15 | let f = fixture.join("restrictions"); 16 | 17 | let resolver = Resolver::new(ResolveOptions { 18 | extensions: vec![".js".into()], 19 | restrictions: vec![Restriction::Path(f.clone())], 20 | ..ResolveOptions::default() 21 | }); 22 | 23 | let resolution = resolver.resolve(&f, "pck2"); 24 | assert_eq!(resolution, Err(ResolveError::Restriction(fixture.join("c.js"), f))); 25 | } 26 | -------------------------------------------------------------------------------- /src/tests/roots.rs: -------------------------------------------------------------------------------- 1 | //! 2 | 3 | use std::path::PathBuf; 4 | 5 | use crate::{AliasValue, ResolveError, ResolveOptions, Resolver}; 6 | 7 | fn dirname() -> PathBuf { 8 | super::fixture_root().join("enhanced_resolve").join("test") 9 | } 10 | 11 | #[test] 12 | fn roots() { 13 | let f = super::fixture(); 14 | 15 | let resolver = Resolver::new(ResolveOptions { 16 | extensions: vec![".js".into()], 17 | alias: vec![("foo".into(), vec![AliasValue::from("/fixtures")])], 18 | roots: vec![dirname(), f.clone()], 19 | ..ResolveOptions::default() 20 | }); 21 | 22 | #[rustfmt::skip] 23 | let pass = [ 24 | ("should respect roots option", "/fixtures/b.js", f.join("b.js")), 25 | ("should try another root option, if it exists", "/b.js", f.join("b.js")), 26 | ("should respect extension", "/fixtures/b", f.join("b.js")), 27 | ("should resolve in directory", "/fixtures/extensions/dir", f.join("extensions/dir/index.js")), 28 | ("should respect aliases", "foo/b", f.join("b.js")), 29 | ]; 30 | 31 | for (comment, request, expected) in pass { 32 | let resolved_path = resolver.resolve(&f, request).map(|r| r.full_path()); 33 | assert_eq!(resolved_path, Ok(expected), "{comment} {request}"); 34 | } 35 | 36 | #[rustfmt::skip] 37 | let fail = [ 38 | ("should not work with relative path", "fixtures/b.js", ResolveError::NotFound("fixtures/b.js".into())) 39 | ]; 40 | 41 | for (comment, request, expected) in fail { 42 | let resolution = resolver.resolve(&f, request); 43 | assert_eq!(resolution, Err(expected), "{comment} {request}"); 44 | } 45 | } 46 | 47 | #[test] 48 | fn resolve_to_context() { 49 | let f = super::fixture(); 50 | let resolver = Resolver::new(ResolveOptions { 51 | roots: vec![dirname(), f.clone()], 52 | resolve_to_context: true, 53 | ..ResolveOptions::default() 54 | }); 55 | let resolved_path = resolver.resolve(&f, "/fixtures/lib").map(|r| r.full_path()); 56 | let expected = f.join("lib"); 57 | assert_eq!(resolved_path, Ok(expected)); 58 | } 59 | 60 | #[test] 61 | fn prefer_absolute() { 62 | let f = super::fixture(); 63 | let resolver = Resolver::new(ResolveOptions { 64 | extensions: vec![".js".into()], 65 | alias: vec![("foo".into(), vec![AliasValue::from("/fixtures")])], 66 | roots: vec![dirname(), f.clone()], 67 | prefer_absolute: true, 68 | ..ResolveOptions::default() 69 | }); 70 | 71 | #[rustfmt::skip] 72 | let pass = [ 73 | ("should resolve an absolute path (prefer absolute)", f.join("b.js").to_string_lossy().to_string(), f.join("b.js")), 74 | ]; 75 | 76 | for (comment, request, expected) in pass { 77 | let resolved_path = resolver.resolve(&f, &request).map(|r| r.full_path()); 78 | assert_eq!(resolved_path, Ok(expected), "{comment} {request}"); 79 | } 80 | } 81 | 82 | #[test] 83 | fn roots_fall_through() { 84 | let f = super::fixture(); 85 | let absolute_path = f.join("roots_fall_through/index.js"); 86 | let specifier = absolute_path.to_string_lossy(); 87 | let resolution = Resolver::new(ResolveOptions::default().with_root(&f)).resolve(&f, &specifier); 88 | assert_eq!( 89 | resolution.map(super::super::resolution::Resolution::into_path_buf), 90 | Ok(absolute_path) 91 | ); 92 | } 93 | 94 | #[test] 95 | fn should_resolve_slash() { 96 | let f = super::fixture(); 97 | let dir_with_index = super::fixture_root().join("./misc/dir-with-index"); 98 | 99 | #[rustfmt::skip] 100 | let pass = [ 101 | ("should resolve if importer is root", vec![dir_with_index.clone()], &dir_with_index, dir_with_index.join("index.js")), 102 | ]; 103 | 104 | for (comment, roots, directory, expected) in pass { 105 | let resolver = 106 | Resolver::new(ResolveOptions { roots: roots.clone(), ..ResolveOptions::default() }); 107 | let resolved_path = resolver.resolve(directory, "/").map(|r| r.full_path()); 108 | assert_eq!(resolved_path, Ok(expected), "{comment} {roots:?}"); 109 | } 110 | 111 | #[rustfmt::skip] 112 | let fail = [ 113 | ("should not resolve if not found", vec![f.clone()], &f), 114 | ("should not resolve if importer is not root", vec![dir_with_index], &f) 115 | ]; 116 | 117 | for (comment, roots, directory) in fail { 118 | let resolver = 119 | Resolver::new(ResolveOptions { roots: roots.clone(), ..ResolveOptions::default() }); 120 | let resolution = resolver.resolve(directory, "/"); 121 | assert_eq!(resolution, Err(ResolveError::NotFound("/".into())), "{comment} {roots:?}"); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/tests/scoped_packages.rs: -------------------------------------------------------------------------------- 1 | //! 2 | 3 | use crate::{ResolveOptions, Resolver}; 4 | 5 | #[test] 6 | fn scoped_packages() { 7 | let f = super::fixture().join("scoped"); 8 | 9 | let resolver = Resolver::new(ResolveOptions { 10 | alias_fields: vec![vec!["browser".into()]], 11 | ..ResolveOptions::default() 12 | }); 13 | 14 | #[rustfmt::skip] 15 | let pass = [ 16 | ("main field should work", f.clone(), "@scope/pack1", f.join("./node_modules/@scope/pack1/main.js")), 17 | ("browser field should work", f.clone(), "@scope/pack2", f.join("./node_modules/@scope/pack2/main.js")), 18 | ("folder request should work", f.clone(), "@scope/pack2/lib", f.join("./node_modules/@scope/pack2/lib/index.js")) 19 | ]; 20 | 21 | for (comment, path, request, expected) in pass { 22 | let resolved_path = resolver.resolve(&f, request).map(|r| r.full_path()); 23 | assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/tests/simple.rs: -------------------------------------------------------------------------------- 1 | //! 2 | 3 | use std::env; 4 | 5 | use crate::Resolver; 6 | 7 | #[test] 8 | fn resolve_abs_main() { 9 | let resolver = Resolver::default(); 10 | let dirname = env::current_dir().unwrap().join("fixtures"); 11 | let f = dirname.join("invalid/main.js"); 12 | // a's main field id `/dist/index.js` 13 | let resolution = resolver.resolve(&f, "a").unwrap(); 14 | 15 | assert_eq!(resolution.path(), dirname.join("invalid/node_modules/a/dist/index.js")); 16 | } 17 | 18 | #[test] 19 | fn simple() { 20 | // mimic `enhanced-resolve/test/simple.test.js` 21 | let dirname = env::current_dir().unwrap().join("fixtures"); 22 | let f = dirname.join("enhanced_resolve/test"); 23 | 24 | let resolver = Resolver::default(); 25 | 26 | let data = [ 27 | ("direct", f.clone(), "../lib/index"), 28 | ("as directory", f, ".."), 29 | ("as module", dirname.clone(), "./enhanced_resolve"), 30 | ]; 31 | 32 | for (comment, path, request) in data { 33 | let resolved_path = resolver.resolve(&path, request).map(|f| f.full_path()); 34 | let expected = dirname.join("enhanced_resolve/lib/index.js"); 35 | assert_eq!(resolved_path, Ok(expected), "{comment} {path:?} {request}"); 36 | } 37 | } 38 | 39 | #[test] 40 | fn dashed_name() { 41 | let f = super::fixture(); 42 | 43 | let resolver = Resolver::default(); 44 | 45 | let data = [ 46 | (f.clone(), "dash", f.join("node_modules/dash/index.js")), 47 | (f.clone(), "dash-name", f.join("node_modules/dash-name/index.js")), 48 | (f.join("node_modules/dash"), "dash", f.join("node_modules/dash/index.js")), 49 | (f.join("node_modules/dash"), "dash-name", f.join("node_modules/dash-name/index.js")), 50 | (f.join("node_modules/dash-name"), "dash", f.join("node_modules/dash/index.js")), 51 | (f.join("node_modules/dash-name"), "dash-name", f.join("node_modules/dash-name/index.js")), 52 | ]; 53 | 54 | for (path, request, expected) in data { 55 | let resolved_path = resolver.resolve(&path, request).map(|f| f.full_path()); 56 | assert_eq!(resolved_path, Ok(expected), "{path:?} {request}"); 57 | } 58 | } 59 | 60 | #[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows. 61 | mod windows { 62 | use std::sync::Arc; 63 | 64 | use super::super::memory_fs::MemoryFS; 65 | use crate::{FsCache, ResolveOptions}; 66 | 67 | #[test] 68 | fn no_package() { 69 | use std::path::Path; 70 | 71 | use crate::ResolverGeneric; 72 | let f = Path::new("/"); 73 | let file_system = MemoryFS::new(&[]); 74 | let resolver = ResolverGeneric::new_with_cache( 75 | Arc::new(FsCache::new(file_system)), 76 | ResolveOptions::default(), 77 | ); 78 | let resolved_path = resolver.resolve(f, "package"); 79 | assert!(resolved_path.is_err()); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/tests/windows.rs: -------------------------------------------------------------------------------- 1 | #[cfg(target_os = "windows")] 2 | use std::{ 3 | ffi::{OsStr, OsString}, 4 | fs::canonicalize, 5 | os::windows::ffi::{OsStrExt, OsStringExt}, 6 | path::{Path, PathBuf}, 7 | }; 8 | 9 | use thiserror::Error; 10 | 11 | /// Converts a Win32 drive letter or mounted folder into DOS device path, e.g.: 12 | /// `\\?\Volume{GUID}\` 13 | #[cfg(target_os = "windows")] 14 | pub fn volume_name_from_mount_point>( 15 | mount_point: S, 16 | ) -> Result { 17 | use windows_sys::Win32::{ 18 | Foundation::GetLastError, Storage::FileSystem::GetVolumeNameForVolumeMountPointW, 19 | }; 20 | 21 | const BUFFER_SIZE: u32 = 64; 22 | let mount_point: Vec = mount_point.as_ref().encode_wide().chain(Some(0)).collect(); 23 | // A reasonable size for the buffer to accommodate the largest possible volume GUID path is 50 characters. 24 | let mut buffer = vec![0; BUFFER_SIZE as usize]; 25 | // SAFETY: Win32 API call 26 | unsafe { 27 | // https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumenameforvolumemountpointw 28 | if GetVolumeNameForVolumeMountPointW(mount_point.as_ptr(), buffer.as_mut_ptr(), BUFFER_SIZE) 29 | == 0 30 | { 31 | Err(Win32Error { error_code: GetLastError() }) 32 | } else { 33 | let length = buffer.iter().position(|&c| c == 0).unwrap(); 34 | Ok(OsString::from_wide(&buffer[..length])) 35 | } 36 | } 37 | } 38 | 39 | #[cfg(target_os = "windows")] 40 | pub fn get_dos_device_path>(path: P) -> Result { 41 | let path = path.as_ref(); 42 | assert!(path.has_root(), "Expected a path with a root"); 43 | 44 | let root = { 45 | // lpszVolumeMountPoint: The string must end with a trailing backslash ('\'). 46 | let mut root = OsString::from(path.components().next().unwrap().as_os_str()); 47 | root.push(r"\"); 48 | root 49 | }; 50 | let mut volume_name_root: Vec = 51 | volume_name_from_mount_point(root)?.encode_wide().collect(); 52 | if volume_name_root.starts_with(&[92, 92, 63, 92] /* \\?\ */) { 53 | // Replace \\?\ with \\.\ 54 | // While both is a valid DOS device path, "\\?\" won't be accepted by most of the IO operations. 55 | volume_name_root[2] = u16::from(b'.'); 56 | } 57 | 58 | let mut dos_device_path = PathBuf::from(OsString::from_wide(&volume_name_root)); 59 | dos_device_path.extend(path.components().skip(1)); 60 | 61 | Ok(dos_device_path) 62 | } 63 | 64 | #[derive(Debug, Clone, PartialEq, Eq, Error)] 65 | #[error("Win32 Error (GetLastError: {error_code:#X})")] 66 | pub struct Win32Error { 67 | /// https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes 68 | pub error_code: u32, 69 | } 70 | 71 | #[cfg(target_os = "windows")] 72 | #[test] 73 | fn test_get_dos_device_path() { 74 | let root = super::fixture_root(); 75 | println!("Fixture root: {root:?}"); 76 | let dos_device_path = get_dos_device_path(&root).unwrap(); 77 | println!("Dos device path: {dos_device_path:?}"); 78 | 79 | // On Windows, canonicalize will resolve any path (traditional or DOS device path) 80 | // into a DOS device path with drive letter (e.g., r"\\?\D:\foo\bar.js"). 81 | // https://doc.rust-lang.org/std/fs/fn.canonicalize.html 82 | let canonical_dos_device_path = canonicalize(&dos_device_path).unwrap(); 83 | println!("-> Canonicalized: {canonical_dos_device_path:?}"); 84 | 85 | // So eventually, the canonicalized path should be exactly the same. 86 | assert_eq!(canonical_dos_device_path, canonicalize(root).unwrap()); 87 | } 88 | -------------------------------------------------------------------------------- /src/windows.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | 3 | use crate::ResolveError; 4 | 5 | /// When applicable, converts a [DOS device path](https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths) 6 | /// to a normal path (usually, "Traditional DOS paths" or "UNC path") that can be consumed by the `import`/`require` syntax of Node.js. 7 | /// 8 | /// # Errors 9 | /// Returns error of [`ResolveError::PathNotSupported`] kind if the path cannot be represented as a normal path. 10 | pub fn strip_windows_prefix(path: PathBuf) -> Result { 11 | // See https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file 12 | let path_bytes = path.as_os_str().as_encoded_bytes(); 13 | 14 | let path = if let Some(p) = 15 | path_bytes.strip_prefix(br"\\?\UNC\").or_else(|| path_bytes.strip_prefix(br"\\.\UNC\")) 16 | { 17 | // UNC paths 18 | // SAFETY: `as_encoded_bytes` ensures `p` is valid path bytes 19 | unsafe { 20 | PathBuf::from(std::ffi::OsStr::from_encoded_bytes_unchecked(&[br"\\", p].concat())) 21 | } 22 | } else if let Some(p) = 23 | path_bytes.strip_prefix(br"\\?\").or_else(|| path_bytes.strip_prefix(br"\\.\")) 24 | { 25 | // Assuming traditional DOS path "\\?\C:\" 26 | if p[1] != b':' { 27 | // E.g., 28 | // \\?\Volume{b75e2c83-0000-0000-0000-602f00000000} 29 | // \\?\BootPartition\ 30 | // It seems nodejs does not support DOS device paths with Volume GUIDs. 31 | // This can happen if the path points to a Mounted Volume without a drive letter. 32 | return Err(ResolveError::PathNotSupported(path)); 33 | } 34 | // SAFETY: `as_encoded_bytes` ensures `p` is valid path bytes 35 | unsafe { PathBuf::from(std::ffi::OsStr::from_encoded_bytes_unchecked(p)) } 36 | } else { 37 | path 38 | }; 39 | 40 | Ok(path) 41 | } 42 | 43 | #[test] 44 | fn test_try_strip_windows_prefix() { 45 | let pass = [ 46 | (r"C:\Users\user\Documents\", r"C:\Users\user\Documents\"), 47 | (r"C:\Users\user\Documents\file1.txt", r"C:\Users\user\Documents\file1.txt"), 48 | (r"\\?\C:\Users\user\Documents\", r"C:\Users\user\Documents\"), 49 | (r"\\?\C:\Users\user\Documents\file1.txt", r"C:\Users\user\Documents\file1.txt"), 50 | (r"\\.\C:\Users\user\Documents\file2.txt", r"C:\Users\user\Documents\file2.txt"), 51 | (r"\\?\UNC\server\share\file3.txt", r"\\server\share\file3.txt"), 52 | ]; 53 | 54 | for (path, expected) in pass { 55 | assert_eq!(strip_windows_prefix(PathBuf::from(path)), Ok(PathBuf::from(expected))); 56 | } 57 | 58 | let fail = [ 59 | r"\\?\Volume{c8ec34d8-3ba6-45c3-9b9d-3e4148e12d00}\file4.txt", 60 | r"\\?\BootPartition\file4.txt", 61 | ]; 62 | 63 | for path in fail { 64 | assert_eq!( 65 | strip_windows_prefix(PathBuf::from(path)), 66 | Err(crate::ResolveError::PathNotSupported(PathBuf::from(path))) 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/integration_test.rs: -------------------------------------------------------------------------------- 1 | //! Test public APIs 2 | 3 | use std::{env, path::PathBuf}; 4 | 5 | use unrs_resolver::{ 6 | EnforceExtension, FileSystemOs, FsCache, PackageJson, Resolution, ResolveContext, 7 | ResolveOptions, Resolver, 8 | }; 9 | 10 | fn dir() -> PathBuf { 11 | env::current_dir().unwrap() 12 | } 13 | 14 | fn resolve(specifier: &str) -> Resolution> { 15 | let path = dir(); 16 | Resolver::new(ResolveOptions::default()).resolve(path, specifier).unwrap() 17 | } 18 | 19 | #[test] 20 | fn clone() { 21 | let resolution = resolve("./tests/package.json"); 22 | assert_eq!(resolution.clone(), resolution); 23 | } 24 | 25 | #[test] 26 | fn debug() { 27 | let resolution = resolve("./tests/package.json"); 28 | let s = format!("{resolution:?}"); 29 | assert!(!s.is_empty()); 30 | } 31 | 32 | #[test] 33 | fn eq() { 34 | let resolution = resolve("./tests/package.json"); 35 | assert_eq!(resolution, resolution); 36 | } 37 | 38 | #[test] 39 | fn package_json() { 40 | let resolution = resolve("./tests/package.json"); 41 | let package_json = resolution.package_json().unwrap(); 42 | assert_eq!(package_json.name().unwrap(), "name"); 43 | assert_eq!(package_json.r#type().unwrap().to_string(), "module".to_string()); 44 | assert!(package_json.side_effects.as_ref().unwrap().is_object()); 45 | } 46 | 47 | #[test] 48 | fn tsconfig() { 49 | let resolver = Resolver::new(ResolveOptions::default()); 50 | let tsconfig = resolver.resolve_tsconfig("./tests").unwrap(); 51 | assert!(tsconfig.root); 52 | assert_eq!(tsconfig.path, PathBuf::from("./tests/tsconfig.json")); 53 | } 54 | 55 | #[cfg(feature = "package_json_raw_json_api")] 56 | #[test] 57 | fn package_json_raw_json_api() { 58 | let resolution = resolve("./tests/package.json"); 59 | assert!( 60 | resolution 61 | .package_json() 62 | .unwrap() 63 | .raw_json() 64 | .get("name") 65 | .is_some_and(|name| name == "name") 66 | ); 67 | } 68 | 69 | #[test] 70 | fn clear_cache() { 71 | let resolver = Resolver::new(ResolveOptions::default()); 72 | resolver.clear_cache(); // exists 73 | } 74 | 75 | #[test] 76 | fn options() { 77 | let resolver = Resolver::new(ResolveOptions::default()); 78 | let options = resolver.options(); 79 | assert!(!format!("{options:?}").is_empty()); 80 | } 81 | 82 | #[test] 83 | fn debug_resolver() { 84 | let resolver = Resolver::new(ResolveOptions::default()); 85 | assert!(!format!("{resolver:?}").is_empty()); 86 | } 87 | 88 | #[test] 89 | fn dependencies() { 90 | let path = dir(); 91 | let mut ctx = ResolveContext::default(); 92 | let _ = Resolver::new(ResolveOptions::default()).resolve_with_context( 93 | path, 94 | "./tests/package.json", 95 | &mut ctx, 96 | ); 97 | assert!(!ctx.file_dependencies.is_empty()); 98 | assert!(ctx.missing_dependencies.is_empty()); 99 | } 100 | 101 | #[test] 102 | fn options_api() { 103 | _ = ResolveOptions::default() 104 | .with_builtin_modules(true) 105 | .with_condition_names(&[]) 106 | .with_extension(".js") 107 | .with_force_extension(EnforceExtension::Auto) 108 | .with_fully_specified(true) 109 | .with_main_field("asdf") 110 | .with_main_file("main") 111 | .with_module("module") 112 | .with_prefer_absolute(true) 113 | .with_prefer_relative(true) 114 | .with_root(PathBuf::new()) 115 | .with_symbolic_link(true); 116 | } 117 | -------------------------------------------------------------------------------- /tests/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "name", 3 | "type": "module", 4 | "sideEffects": {} 5 | } 6 | -------------------------------------------------------------------------------- /tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | } 3 | --------------------------------------------------------------------------------