mirror of
https://github.com/hanzoai/unrs-resolver.git
synced 2026-09-24 17:03:52 +00:00
chore(js): replace dprint with oxfmt (#925)
This commit is contained in:
@@ -21,26 +21,13 @@ jobs:
|
||||
- uses: oxc-project/setup-rust@ecabb7322a2ba5aeedb3612d2a40b86a85cee235 # v1.0.11
|
||||
with:
|
||||
restore-cache: false
|
||||
tools: just,cargo-shear@1,dprint
|
||||
tools: just,cargo-shear@1
|
||||
components: rustfmt
|
||||
|
||||
- name: Restore dprint plugin cache
|
||||
id: cache-restore
|
||||
uses: actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
|
||||
with:
|
||||
key: dprint-autofix-ci-${{ runner.os }}-${{ hashFiles('dprint.json') }}
|
||||
path: ~/.cache/dprint
|
||||
- uses: ./.github/actions/pnpm
|
||||
|
||||
- run: just fmt
|
||||
|
||||
- uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27 # v1.3.2
|
||||
with:
|
||||
fail-fast: false
|
||||
|
||||
- name: Save dprint plugin cache
|
||||
if: ${{ github.ref_name == 'main' }}
|
||||
id: cache-save
|
||||
uses: actions/cache/save@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
|
||||
with:
|
||||
key: ${{ steps.cache-restore.outputs.cache-primary-key }}
|
||||
path: ~/.cache/dprint
|
||||
|
||||
@@ -32,16 +32,9 @@ jobs:
|
||||
with:
|
||||
cache-key: warm
|
||||
save-cache: false
|
||||
tools: just,watchexec-cli,cargo-insta,typos-cli,cargo-shear,dprint
|
||||
tools: just,watchexec-cli,cargo-insta,typos-cli,cargo-shear
|
||||
components: clippy rust-docs rustfmt
|
||||
|
||||
- uses: oxc-project/setup-node@141eb77546de6702f92d320926403fe3f9f6a6f2 # v1.0.5
|
||||
|
||||
- uses: ./.github/actions/pnpm
|
||||
|
||||
- name: Restore dprint plugin cache
|
||||
id: cache-restore
|
||||
uses: actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
|
||||
with:
|
||||
key: dprint-${{ hashFiles('dprint.json') }}
|
||||
path: ~/.cache/dprint
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
||||
"ignorePatterns": [
|
||||
"CHANGELOG.md",
|
||||
"fixtures",
|
||||
"napi/browser.js",
|
||||
"napi/browser.js",
|
||||
"napi/index.d.ts",
|
||||
"napi/index.js",
|
||||
"napi/resolver.wasi-browser.js",
|
||||
"napi/resolver.wasi.cjs",
|
||||
"napi/wasi-worker-browser.mjs",
|
||||
"napi/wasi-worker.mjs",
|
||||
"napi/webcontainer-fallback.js"
|
||||
]
|
||||
}
|
||||
@@ -27,7 +27,7 @@ oxc-resolver/
|
||||
|
||||
## Development Workflow
|
||||
|
||||
`just init` has already been run, all tools (`typos-cli`, `cargo-shear`, `dprint`) are already installed, do not run `just init`.
|
||||
`just init` has already been run, all tools (`typos-cli`, `cargo-shear`) are already installed, do not run `just init`.
|
||||
|
||||
Rust and `cargo` components `clippy`, `rust-docs` and `rustfmt` have already been installed, do not install them.
|
||||
|
||||
@@ -40,7 +40,7 @@ just ready # Run all checks (format, lint, test, build)
|
||||
just test # Run all tests (Rust + Node.js)
|
||||
just check # Cargo check with all features
|
||||
just lint # Run clippy with strict settings
|
||||
just fmt # Format code (cargo fmt + dprint)
|
||||
just fmt # Format code (cargo fmt + oxfmt)
|
||||
```
|
||||
|
||||
## Code Conventions
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"$schema": "https://dprint.dev/schemas/v0.json",
|
||||
"lineWidth": 120,
|
||||
"typescript": {
|
||||
"quoteStyle": "preferSingle",
|
||||
"binaryExpression.operatorPosition": "sameLine"
|
||||
},
|
||||
"json": {
|
||||
"indentWidth": 2
|
||||
},
|
||||
"toml": {
|
||||
},
|
||||
"excludes": [
|
||||
"fixtures/**",
|
||||
"CHANGELOG.md",
|
||||
"pnpm-workspace.yaml",
|
||||
"pnpm-lock.yaml",
|
||||
"napi/*.{cjs,js,mjs,d.ts}",
|
||||
"!napi/test.mjs"
|
||||
],
|
||||
"plugins": [
|
||||
"https://plugins.dprint.dev/typescript-0.95.13.wasm",
|
||||
"https://plugins.dprint.dev/json-0.21.0.wasm",
|
||||
"https://plugins.dprint.dev/markdown-0.20.0.wasm",
|
||||
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm",
|
||||
"https://plugins.dprint.dev/toml-0.7.0.wasm"
|
||||
]
|
||||
}
|
||||
@@ -13,7 +13,7 @@ alias r := ready
|
||||
# or install via `cargo install cargo-binstall`
|
||||
# Initialize the project by installing all the necessary tools.
|
||||
init:
|
||||
cargo binstall cargo-shear dprint typos-cli watchexec-cli -y
|
||||
cargo binstall cargo-shear typos-cli watchexec-cli -y
|
||||
rustup target add s390x-unknown-linux-gnu
|
||||
|
||||
install:
|
||||
@@ -51,7 +51,7 @@ example target *args='':
|
||||
fmt:
|
||||
cargo shear --fix # remove all unused dependencies
|
||||
cargo fmt --all
|
||||
dprint fmt
|
||||
node --run fmt
|
||||
|
||||
# Run cargo check
|
||||
check:
|
||||
|
||||
+8
-6
@@ -1,9 +1,9 @@
|
||||
import fs from 'node:fs';
|
||||
import fs from "node:fs";
|
||||
|
||||
const filename = './napi/index.js';
|
||||
let data = fs.readFileSync(filename, 'utf-8');
|
||||
const filename = "./napi/index.js";
|
||||
let data = fs.readFileSync(filename, "utf-8");
|
||||
data = data.replace(
|
||||
'\nif (!nativeBinding) {',
|
||||
"\nif (!nativeBinding) {",
|
||||
(s) =>
|
||||
`
|
||||
if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
|
||||
@@ -15,9 +15,11 @@ if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
|
||||
}
|
||||
` + s,
|
||||
);
|
||||
data = data + `
|
||||
data =
|
||||
data +
|
||||
`
|
||||
if (process.versions.pnp) {
|
||||
process.env.OXC_RESOLVER_YARN_PNP = '1'
|
||||
}
|
||||
`
|
||||
`;
|
||||
fs.writeFileSync(filename, data);
|
||||
|
||||
+9
-20
@@ -1,40 +1,29 @@
|
||||
import assert from 'assert';
|
||||
import path from 'path';
|
||||
import resolve, { ResolverFactory } from './index.js';
|
||||
import assert from "assert";
|
||||
import path from "path";
|
||||
import resolve, { ResolverFactory } from "./index.js";
|
||||
|
||||
console.log(`Testing on ${process.platform}-${process.arch}`);
|
||||
|
||||
const dir = import.meta.dirname;
|
||||
|
||||
// `resolve`
|
||||
assert.deepStrictEqual(
|
||||
resolve.sync(dir, './index.js').path,
|
||||
path.join(dir, 'index.js'),
|
||||
);
|
||||
assert.deepStrictEqual(resolve.sync(dir, "./index.js").path, path.join(dir, "index.js"));
|
||||
|
||||
// `ResolverFactory`
|
||||
const resolver = new ResolverFactory();
|
||||
assert.deepStrictEqual(
|
||||
resolver.sync(dir, './index.js').path,
|
||||
path.join(dir, 'index.js'),
|
||||
);
|
||||
assert.deepStrictEqual(resolver.sync(dir, "./index.js").path, path.join(dir, "index.js"));
|
||||
|
||||
assert.strict(resolver.sync(dir, './ts').error.length > 0);
|
||||
assert.strict(resolver.sync(dir, "./ts").error.length > 0);
|
||||
|
||||
resolver
|
||||
.async(dir, './ts')
|
||||
.then((result) => assert.strict(result.error.length > 0));
|
||||
resolver.async(dir, "./ts").then((result) => assert.strict(result.error.length > 0));
|
||||
|
||||
const newResolver = resolver.cloneWithOptions({});
|
||||
newResolver.clearCache();
|
||||
|
||||
// custom constructor
|
||||
const resolver2 = new ResolverFactory({
|
||||
extensions: ['.mjs'],
|
||||
extensions: [".mjs"],
|
||||
});
|
||||
|
||||
// After add `.ts` extension, resolver can resolve `ts` as `ts.ts` now
|
||||
assert.deepStrictEqual(
|
||||
resolver2.sync(dir, './test.mjs').path,
|
||||
path.join(dir, 'test.mjs'),
|
||||
);
|
||||
assert.deepStrictEqual(resolver2.sync(dir, "./test.mjs").path, path.join(dir, "test.mjs"));
|
||||
|
||||
@@ -1,37 +1,32 @@
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { assert, describe, test } from 'vitest';
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { assert, describe, test } from "vitest";
|
||||
|
||||
let ResolverFactory;
|
||||
|
||||
if (process.env.WASI_TEST) {
|
||||
const wasi = await import('../resolver.wasi.cjs');
|
||||
const wasi = await import("../resolver.wasi.cjs");
|
||||
ResolverFactory = wasi.ResolverFactory;
|
||||
} else {
|
||||
const napi = await import('../index.js');
|
||||
const napi = await import("../index.js");
|
||||
ResolverFactory = napi.ResolverFactory;
|
||||
}
|
||||
|
||||
const currentDir = join(fileURLToPath(import.meta.url), '..');
|
||||
const rootDir = join(currentDir, '..', '..');
|
||||
const fixturesDir = join(rootDir, 'fixtures');
|
||||
const enhancedResolveRoot = join(
|
||||
fixturesDir,
|
||||
'enhanced-resolve',
|
||||
'test',
|
||||
'fixtures',
|
||||
);
|
||||
const currentDir = join(fileURLToPath(import.meta.url), "..");
|
||||
const rootDir = join(currentDir, "..", "..");
|
||||
const fixturesDir = join(rootDir, "fixtures");
|
||||
const enhancedResolveRoot = join(fixturesDir, "enhanced-resolve", "test", "fixtures");
|
||||
|
||||
// ESM allows file:// protocol URLs for module specifiers
|
||||
// See: https://nodejs.org/api/esm.html#urls
|
||||
|
||||
describe.skipIf(process.env.WASI_TEST)('file:// protocol', () => {
|
||||
test('with absolute path', () => {
|
||||
describe.skipIf(process.env.WASI_TEST)("file:// protocol", () => {
|
||||
test("with absolute path", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
const main1Path = join(enhancedResolveRoot, 'main1.js');
|
||||
const main1Path = join(enhancedResolveRoot, "main1.js");
|
||||
const fileUrl = pathToFileURL(main1Path).href;
|
||||
|
||||
const result = resolver.sync(enhancedResolveRoot, fileUrl);
|
||||
@@ -39,54 +34,54 @@ describe.skipIf(process.env.WASI_TEST)('file:// protocol', () => {
|
||||
assert.equal(result.path, main1Path);
|
||||
});
|
||||
|
||||
test('with query string', () => {
|
||||
test("with query string", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
const main1Path = join(enhancedResolveRoot, 'main1.js');
|
||||
const fileUrl = pathToFileURL(main1Path).href + '?query=value';
|
||||
const main1Path = join(enhancedResolveRoot, "main1.js");
|
||||
const fileUrl = pathToFileURL(main1Path).href + "?query=value";
|
||||
|
||||
const result = resolver.sync(enhancedResolveRoot, fileUrl);
|
||||
|
||||
assert.ok(result.path.includes('main1.js'));
|
||||
assert.ok(result.path.includes('?query=value'));
|
||||
assert.ok(result.path.includes("main1.js"));
|
||||
assert.ok(result.path.includes("?query=value"));
|
||||
});
|
||||
|
||||
test('with fragment', () => {
|
||||
test("with fragment", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
const main1Path = join(enhancedResolveRoot, 'main1.js');
|
||||
const fileUrl = pathToFileURL(main1Path).href + '#fragment';
|
||||
const main1Path = join(enhancedResolveRoot, "main1.js");
|
||||
const fileUrl = pathToFileURL(main1Path).href + "#fragment";
|
||||
|
||||
const result = resolver.sync(enhancedResolveRoot, fileUrl);
|
||||
|
||||
assert.ok(result.path.includes('main1.js'));
|
||||
assert.ok(result.path.includes('#fragment'));
|
||||
assert.ok(result.path.includes("main1.js"));
|
||||
assert.ok(result.path.includes("#fragment"));
|
||||
});
|
||||
|
||||
test('with query and fragment', () => {
|
||||
test("with query and fragment", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
const main1Path = join(enhancedResolveRoot, 'main1.js');
|
||||
const fileUrl = pathToFileURL(main1Path).href + '?query=value#fragment';
|
||||
const main1Path = join(enhancedResolveRoot, "main1.js");
|
||||
const fileUrl = pathToFileURL(main1Path).href + "?query=value#fragment";
|
||||
|
||||
const result = resolver.sync(enhancedResolveRoot, fileUrl);
|
||||
|
||||
assert.ok(result.path.includes('main1.js'));
|
||||
assert.ok(result.path.includes('?query=value#fragment'));
|
||||
assert.ok(result.path.includes("main1.js"));
|
||||
assert.ok(result.path.includes("?query=value#fragment"));
|
||||
});
|
||||
|
||||
test('with unicode path', () => {
|
||||
test("with unicode path", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
const unicodePath = join(enhancedResolveRoot, '测试.js');
|
||||
const unicodePath = join(enhancedResolveRoot, "测试.js");
|
||||
const fileUrl = pathToFileURL(unicodePath).href;
|
||||
|
||||
const result = resolver.sync(enhancedResolveRoot, fileUrl);
|
||||
@@ -94,18 +89,18 @@ describe.skipIf(process.env.WASI_TEST)('file:// protocol', () => {
|
||||
assert.equal(result.path, unicodePath);
|
||||
});
|
||||
|
||||
test('with percent-encoded special characters', () => {
|
||||
test("with percent-encoded special characters", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
// Test that percent-encoded characters in file URLs are handled
|
||||
// Node.js requires # to be encoded as %23 in file URLs
|
||||
const main1Path = join(enhancedResolveRoot, 'main1.js');
|
||||
const main1Path = join(enhancedResolveRoot, "main1.js");
|
||||
const fileUrl = pathToFileURL(main1Path).href;
|
||||
|
||||
// Manually create a URL with encoded characters
|
||||
const encodedUrl = fileUrl.replace('main1.js', 'main%231.js');
|
||||
const encodedUrl = fileUrl.replace("main1.js", "main%231.js");
|
||||
|
||||
const result = resolver.sync(enhancedResolveRoot, encodedUrl);
|
||||
|
||||
@@ -113,40 +108,40 @@ describe.skipIf(process.env.WASI_TEST)('file:// protocol', () => {
|
||||
assert.ok(result.error);
|
||||
});
|
||||
|
||||
test('with directory path', () => {
|
||||
test("with directory path", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
const dirPath = join(enhancedResolveRoot, 'dirOrFile/');
|
||||
const dirPath = join(enhancedResolveRoot, "dirOrFile/");
|
||||
const fileUrl = pathToFileURL(dirPath).href;
|
||||
|
||||
const result = resolver.sync(enhancedResolveRoot, fileUrl);
|
||||
|
||||
// Should resolve to index.js in the directory
|
||||
assert.ok(result.path.includes('dirOrFile'));
|
||||
assert.ok(result.path.includes('index.js'));
|
||||
assert.ok(result.path.includes("dirOrFile"));
|
||||
assert.ok(result.path.includes("index.js"));
|
||||
});
|
||||
|
||||
test('with relative path segments (should error)', () => {
|
||||
test("with relative path segments (should error)", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
// file:// URLs with relative path segments like './main.js' are invalid
|
||||
// This should error
|
||||
const result = resolver.sync(enhancedResolveRoot, 'file://./main.js');
|
||||
const result = resolver.sync(enhancedResolveRoot, "file://./main.js");
|
||||
|
||||
// Should return an error for malformed file URLs
|
||||
assert.ok(result.error);
|
||||
});
|
||||
|
||||
test('async resolution', async () => {
|
||||
test("async resolution", async () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
const main1Path = join(enhancedResolveRoot, 'main1.js');
|
||||
const main1Path = join(enhancedResolveRoot, "main1.js");
|
||||
const fileUrl = pathToFileURL(main1Path).href;
|
||||
|
||||
const result = await resolver.async(enhancedResolveRoot, fileUrl);
|
||||
|
||||
@@ -1,112 +1,112 @@
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { assert, test } from 'vitest';
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { assert, test } from "vitest";
|
||||
|
||||
import { ModuleType, ResolverFactory } from '../index.js';
|
||||
import { ModuleType, ResolverFactory } from "../index.js";
|
||||
|
||||
const currentDir = join(fileURLToPath(import.meta.url), '..');
|
||||
const cwd = join(currentDir, '..');
|
||||
const rootDir = join(cwd, '..');
|
||||
const fixturesDir = join(rootDir, 'fixtures');
|
||||
const currentDir = join(fileURLToPath(import.meta.url), "..");
|
||||
const cwd = join(currentDir, "..");
|
||||
const rootDir = join(cwd, "..");
|
||||
const fixturesDir = join(rootDir, "fixtures");
|
||||
|
||||
test('resolveFileSync basic resolution', () => {
|
||||
test("resolveFileSync basic resolution", () => {
|
||||
const resolver = new ResolverFactory();
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
|
||||
const result = resolver.resolveFileSync(testFile, './resolver.test.mjs');
|
||||
assert.equal(result.path, join(currentDir, 'resolver.test.mjs'));
|
||||
const result = resolver.resolveFileSync(testFile, "./resolver.test.mjs");
|
||||
assert.equal(result.path, join(currentDir, "resolver.test.mjs"));
|
||||
});
|
||||
|
||||
test('resolveFileSync with relative import', () => {
|
||||
test("resolveFileSync with relative import", () => {
|
||||
const resolver = new ResolverFactory();
|
||||
const testFile = join(cwd, 'index.js');
|
||||
const testFile = join(cwd, "index.js");
|
||||
|
||||
const result = resolver.resolveFileSync(testFile, './src/lib.rs');
|
||||
assert.equal(result.path, join(cwd, 'src', 'lib.rs'));
|
||||
const result = resolver.resolveFileSync(testFile, "./src/lib.rs");
|
||||
assert.equal(result.path, join(cwd, "src", "lib.rs"));
|
||||
});
|
||||
|
||||
test('resolveFileSync error handling', () => {
|
||||
test("resolveFileSync error handling", () => {
|
||||
const resolver = new ResolverFactory();
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
|
||||
const result = resolver.resolveFileSync(testFile, './nonexistent-file');
|
||||
const result = resolver.resolveFileSync(testFile, "./nonexistent-file");
|
||||
assert.isNotNull(result.error);
|
||||
assert.isAbove(result.error.length, 0);
|
||||
assert.isUndefined(result.path);
|
||||
});
|
||||
|
||||
test('resolveFileAsync basic resolution', async () => {
|
||||
test("resolveFileAsync basic resolution", async () => {
|
||||
const resolver = new ResolverFactory();
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
|
||||
const result = await resolver.resolveFileAsync(testFile, './resolver.test.mjs');
|
||||
assert.equal(result.path, join(currentDir, 'resolver.test.mjs'));
|
||||
const result = await resolver.resolveFileAsync(testFile, "./resolver.test.mjs");
|
||||
assert.equal(result.path, join(currentDir, "resolver.test.mjs"));
|
||||
});
|
||||
|
||||
test('resolveFileAsync error handling', async () => {
|
||||
test("resolveFileAsync error handling", async () => {
|
||||
const resolver = new ResolverFactory();
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
|
||||
const result = await resolver.resolveFileAsync(testFile, './nonexistent');
|
||||
const result = await resolver.resolveFileAsync(testFile, "./nonexistent");
|
||||
assert.isNotNull(result.error);
|
||||
assert.isAbove(result.error.length, 0);
|
||||
assert.isUndefined(result.path);
|
||||
});
|
||||
|
||||
test('resolveFileSync with module type', () => {
|
||||
test("resolveFileSync with module type", () => {
|
||||
const resolver = new ResolverFactory({ moduleType: true });
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
|
||||
const result = resolver.resolveFileSync(testFile, '../index.js');
|
||||
assert.equal(result.path, join(cwd, 'index.js'));
|
||||
const result = resolver.resolveFileSync(testFile, "../index.js");
|
||||
assert.equal(result.path, join(cwd, "index.js"));
|
||||
assert.isNotNull(result.moduleType);
|
||||
});
|
||||
|
||||
test('resolveFileSync builtin module', () => {
|
||||
test("resolveFileSync builtin module", () => {
|
||||
const resolver = new ResolverFactory({ builtinModules: true });
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
|
||||
const result = resolver.resolveFileSync(testFile, 'node:fs');
|
||||
const result = resolver.resolveFileSync(testFile, "node:fs");
|
||||
assert.deepEqual(result.builtin, {
|
||||
resolved: 'node:fs',
|
||||
resolved: "node:fs",
|
||||
isRuntimeModule: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('resolveFileSync builtin module without prefix', () => {
|
||||
test("resolveFileSync builtin module without prefix", () => {
|
||||
const resolver = new ResolverFactory({ builtinModules: true });
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
|
||||
const result = resolver.resolveFileSync(testFile, 'fs');
|
||||
const result = resolver.resolveFileSync(testFile, "fs");
|
||||
assert.deepEqual(result.builtin, {
|
||||
resolved: 'node:fs',
|
||||
resolved: "node:fs",
|
||||
isRuntimeModule: false,
|
||||
});
|
||||
});
|
||||
|
||||
test('resolveFileSync with extensions option', () => {
|
||||
test("resolveFileSync with extensions option", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
extensions: ['.js', '.mjs', '.json'],
|
||||
extensions: [".js", ".mjs", ".json"],
|
||||
});
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
|
||||
const result = resolver.resolveFileSync(testFile, './simple.test');
|
||||
assert.equal(result.path, join(currentDir, 'simple.test.mjs'));
|
||||
const result = resolver.resolveFileSync(testFile, "./simple.test");
|
||||
assert.equal(result.path, join(currentDir, "simple.test.mjs"));
|
||||
});
|
||||
|
||||
test('resolveFileAsync with module type', async () => {
|
||||
test("resolveFileAsync with module type", async () => {
|
||||
const resolver = new ResolverFactory({ moduleType: true });
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
|
||||
const result = await resolver.resolveFileAsync(testFile, '../index.js');
|
||||
assert.equal(result.path, join(cwd, 'index.js'));
|
||||
const result = await resolver.resolveFileAsync(testFile, "../index.js");
|
||||
assert.equal(result.path, join(cwd, "index.js"));
|
||||
assert.isNotNull(result.moduleType);
|
||||
});
|
||||
|
||||
test('sync and async return same results', async () => {
|
||||
test("sync and async return same results", async () => {
|
||||
const resolver = new ResolverFactory();
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const request = './resolver.test.mjs';
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
const request = "./resolver.test.mjs";
|
||||
|
||||
const syncResult = resolver.resolveFileSync(testFile, request);
|
||||
const asyncResult = await resolver.resolveFileAsync(testFile, request);
|
||||
@@ -114,10 +114,10 @@ test('sync and async return same results', async () => {
|
||||
assert.deepEqual(syncResult, asyncResult);
|
||||
});
|
||||
|
||||
test('sync and async return same errors', async () => {
|
||||
test("sync and async return same errors", async () => {
|
||||
const resolver = new ResolverFactory();
|
||||
const testFile = join(currentDir, 'simple.test.mjs');
|
||||
const request = './nonexistent-module';
|
||||
const testFile = join(currentDir, "simple.test.mjs");
|
||||
const request = "./nonexistent-module";
|
||||
|
||||
const syncResult = resolver.resolveFileSync(testFile, request);
|
||||
const asyncResult = await resolver.resolveFileAsync(testFile, request);
|
||||
|
||||
+21
-27
@@ -1,62 +1,56 @@
|
||||
import * as path from 'node:path';
|
||||
import { assert, describe, it } from 'vitest';
|
||||
import * as path from "node:path";
|
||||
import { assert, describe, it } from "vitest";
|
||||
|
||||
import { ResolverFactory } from '../index.js';
|
||||
import { normalizePath } from './utils.mjs';
|
||||
import { ResolverFactory } from "../index.js";
|
||||
import { normalizePath } from "./utils.mjs";
|
||||
|
||||
const fixtureDir = path.resolve(
|
||||
import.meta.dirname,
|
||||
'../../fixtures/enhanced-resolve/test/fixtures',
|
||||
"../../fixtures/enhanced-resolve/test/fixtures",
|
||||
);
|
||||
|
||||
describe('option', () => {
|
||||
describe('aliasFields', () => {
|
||||
it('should allow field string ', () => {
|
||||
const resolver = new ResolverFactory({ aliasFields: ['browser'] });
|
||||
describe("option", () => {
|
||||
describe("aliasFields", () => {
|
||||
it("should allow field string ", () => {
|
||||
const resolver = new ResolverFactory({ aliasFields: ["browser"] });
|
||||
assert.match(
|
||||
normalizePath(resolver.sync(fixtureDir, './browser-module/lib/replaced.js').path),
|
||||
normalizePath(resolver.sync(fixtureDir, "./browser-module/lib/replaced.js").path),
|
||||
/browser-module\/lib\/browser\.js$/,
|
||||
);
|
||||
});
|
||||
it('should allow json path array', () => {
|
||||
it("should allow json path array", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
aliasFields: [['innerBrowser1', 'field', 'browser']],
|
||||
aliasFields: [["innerBrowser1", "field", "browser"]],
|
||||
});
|
||||
|
||||
assert.match(
|
||||
normalizePath(resolver.sync(fixtureDir, './browser-module/lib/main1.js').path),
|
||||
normalizePath(resolver.sync(fixtureDir, "./browser-module/lib/main1.js").path),
|
||||
/browser-module\/lib\/main\.js$/,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('exportsFields', () => {
|
||||
describe("exportsFields", () => {
|
||||
const createTest = (exportsFields) => {
|
||||
const resolver = new ResolverFactory({ exportsFields });
|
||||
assert.match(
|
||||
normalizePath(
|
||||
resolver.sync(
|
||||
path.resolve(fixtureDir, './exports-field3'),
|
||||
'exports-field',
|
||||
).path,
|
||||
resolver.sync(path.resolve(fixtureDir, "./exports-field3"), "exports-field").path,
|
||||
),
|
||||
/\/exports-field\/src\/index\.js$/,
|
||||
);
|
||||
};
|
||||
it('should allow string as field item', createTest(['broken']));
|
||||
it('should allow json path array as field item', createTest([['broken']]));
|
||||
it("should allow string as field item", createTest(["broken"]));
|
||||
it("should allow json path array as field item", createTest([["broken"]]));
|
||||
});
|
||||
|
||||
describe('mainFields', () => {
|
||||
describe("mainFields", () => {
|
||||
const createTest = (mainFields) => {
|
||||
const resolver = new ResolverFactory({ mainFields });
|
||||
assert.match(
|
||||
normalizePath(resolver.sync(fixtureDir, '../..').path),
|
||||
/\/lib\/index\.js$/,
|
||||
);
|
||||
assert.match(normalizePath(resolver.sync(fixtureDir, "../..").path), /\/lib\/index\.js$/);
|
||||
};
|
||||
it("should use `'main'` as default", createTest(undefined));
|
||||
it('should allow field string', createTest('main'));
|
||||
it('should allow field array', createTest(['main']));
|
||||
it("should allow field string", createTest("main"));
|
||||
it("should allow field array", createTest(["main"]));
|
||||
});
|
||||
});
|
||||
|
||||
+196
-229
@@ -1,279 +1,246 @@
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { assert, test } from 'vitest';
|
||||
import { assert, test } from "vitest";
|
||||
|
||||
let ResolverFactory;
|
||||
|
||||
if (process.env.WASI_TEST) {
|
||||
const wasi = await import('../resolver.wasi.cjs');
|
||||
const wasi = await import("../resolver.wasi.cjs");
|
||||
ResolverFactory = wasi.ResolverFactory;
|
||||
} else {
|
||||
const napi = await import('../index.js');
|
||||
const napi = await import("../index.js");
|
||||
ResolverFactory = napi.ResolverFactory;
|
||||
}
|
||||
|
||||
const currentDir = join(fileURLToPath(import.meta.url), '..');
|
||||
const currentDir = join(fileURLToPath(import.meta.url), "..");
|
||||
|
||||
const rootDir = join(currentDir, '..', '..');
|
||||
const rootDir = join(currentDir, "..", "..");
|
||||
|
||||
const fixturesDir = join(rootDir, 'fixtures');
|
||||
const fixturesDir = join(rootDir, "fixtures");
|
||||
|
||||
const enhancedResolveRoot = join(
|
||||
fixturesDir,
|
||||
'enhanced-resolve',
|
||||
'test',
|
||||
'fixtures',
|
||||
);
|
||||
const enhancedResolveRoot = join(fixturesDir, "enhanced-resolve", "test", "fixtures");
|
||||
|
||||
// https://github.com/webpack/enhanced-resolve/blob/main/test/resolve.test.js
|
||||
|
||||
for (
|
||||
const [title, context, request, expected] of [
|
||||
[
|
||||
'absolute path',
|
||||
enhancedResolveRoot,
|
||||
join(enhancedResolveRoot, 'main1.js'),
|
||||
join(enhancedResolveRoot, 'main1.js'),
|
||||
],
|
||||
[
|
||||
'file with .js',
|
||||
enhancedResolveRoot,
|
||||
'./main1.js',
|
||||
join(enhancedResolveRoot, 'main1.js'),
|
||||
],
|
||||
[
|
||||
'file without extension',
|
||||
enhancedResolveRoot,
|
||||
'./main1',
|
||||
join(enhancedResolveRoot, 'main1.js'),
|
||||
],
|
||||
[
|
||||
'another file with .js',
|
||||
enhancedResolveRoot,
|
||||
'./a.js',
|
||||
join(enhancedResolveRoot, 'a.js'),
|
||||
],
|
||||
[
|
||||
'another file without extension',
|
||||
enhancedResolveRoot,
|
||||
'./a',
|
||||
join(enhancedResolveRoot, 'a.js'),
|
||||
],
|
||||
[
|
||||
'file in module with .js',
|
||||
enhancedResolveRoot,
|
||||
'm1/a.js',
|
||||
join(enhancedResolveRoot, 'node_modules/m1/a.js'),
|
||||
],
|
||||
[
|
||||
'file in module without extension',
|
||||
enhancedResolveRoot,
|
||||
'm1/a',
|
||||
join(enhancedResolveRoot, 'node_modules/m1/a.js'),
|
||||
],
|
||||
[
|
||||
'another file in module without extension',
|
||||
enhancedResolveRoot,
|
||||
'complexm/step1',
|
||||
join(enhancedResolveRoot, 'node_modules/complexm/step1.js'),
|
||||
],
|
||||
[
|
||||
'from submodule to file in sibling module',
|
||||
join(enhancedResolveRoot, 'node_modules/complexm'),
|
||||
'm2/b.js',
|
||||
join(enhancedResolveRoot, 'node_modules/m2/b.js'),
|
||||
],
|
||||
[
|
||||
'from nested directory to overwritten file in module',
|
||||
join(enhancedResolveRoot, 'multiple-modules'),
|
||||
'm1/a.js',
|
||||
join(enhancedResolveRoot, 'multiple-modules/node_modules/m1/a.js'),
|
||||
],
|
||||
[
|
||||
'from nested directory to not overwritten file in module',
|
||||
join(enhancedResolveRoot, 'multiple-modules'),
|
||||
'm1/b.js',
|
||||
join(enhancedResolveRoot, 'node_modules/m1/b.js'),
|
||||
],
|
||||
[
|
||||
'file with query',
|
||||
enhancedResolveRoot,
|
||||
'./main1.js?query',
|
||||
join(enhancedResolveRoot, 'main1.js?query'),
|
||||
],
|
||||
[
|
||||
'file with fragment',
|
||||
enhancedResolveRoot,
|
||||
'./main1.js#fragment',
|
||||
join(enhancedResolveRoot, 'main1.js#fragment'),
|
||||
],
|
||||
[
|
||||
'file with fragment and query',
|
||||
enhancedResolveRoot,
|
||||
'./main1.js#fragment?query',
|
||||
join(enhancedResolveRoot, 'main1.js#fragment?query'),
|
||||
],
|
||||
[
|
||||
'file with query and fragment',
|
||||
enhancedResolveRoot,
|
||||
'./main1.js?#fragment',
|
||||
join(enhancedResolveRoot, 'main1.js?#fragment'),
|
||||
],
|
||||
for (const [title, context, request, expected] of [
|
||||
[
|
||||
"absolute path",
|
||||
enhancedResolveRoot,
|
||||
join(enhancedResolveRoot, "main1.js"),
|
||||
join(enhancedResolveRoot, "main1.js"),
|
||||
],
|
||||
["file with .js", enhancedResolveRoot, "./main1.js", join(enhancedResolveRoot, "main1.js")],
|
||||
["file without extension", enhancedResolveRoot, "./main1", join(enhancedResolveRoot, "main1.js")],
|
||||
["another file with .js", enhancedResolveRoot, "./a.js", join(enhancedResolveRoot, "a.js")],
|
||||
["another file without extension", enhancedResolveRoot, "./a", join(enhancedResolveRoot, "a.js")],
|
||||
[
|
||||
"file in module with .js",
|
||||
enhancedResolveRoot,
|
||||
"m1/a.js",
|
||||
join(enhancedResolveRoot, "node_modules/m1/a.js"),
|
||||
],
|
||||
[
|
||||
"file in module without extension",
|
||||
enhancedResolveRoot,
|
||||
"m1/a",
|
||||
join(enhancedResolveRoot, "node_modules/m1/a.js"),
|
||||
],
|
||||
[
|
||||
"another file in module without extension",
|
||||
enhancedResolveRoot,
|
||||
"complexm/step1",
|
||||
join(enhancedResolveRoot, "node_modules/complexm/step1.js"),
|
||||
],
|
||||
[
|
||||
"from submodule to file in sibling module",
|
||||
join(enhancedResolveRoot, "node_modules/complexm"),
|
||||
"m2/b.js",
|
||||
join(enhancedResolveRoot, "node_modules/m2/b.js"),
|
||||
],
|
||||
[
|
||||
"from nested directory to overwritten file in module",
|
||||
join(enhancedResolveRoot, "multiple-modules"),
|
||||
"m1/a.js",
|
||||
join(enhancedResolveRoot, "multiple-modules/node_modules/m1/a.js"),
|
||||
],
|
||||
[
|
||||
"from nested directory to not overwritten file in module",
|
||||
join(enhancedResolveRoot, "multiple-modules"),
|
||||
"m1/b.js",
|
||||
join(enhancedResolveRoot, "node_modules/m1/b.js"),
|
||||
],
|
||||
[
|
||||
"file with query",
|
||||
enhancedResolveRoot,
|
||||
"./main1.js?query",
|
||||
join(enhancedResolveRoot, "main1.js?query"),
|
||||
],
|
||||
[
|
||||
"file with fragment",
|
||||
enhancedResolveRoot,
|
||||
"./main1.js#fragment",
|
||||
join(enhancedResolveRoot, "main1.js#fragment"),
|
||||
],
|
||||
[
|
||||
"file with fragment and query",
|
||||
enhancedResolveRoot,
|
||||
"./main1.js#fragment?query",
|
||||
join(enhancedResolveRoot, "main1.js#fragment?query"),
|
||||
],
|
||||
[
|
||||
"file with query and fragment",
|
||||
enhancedResolveRoot,
|
||||
"./main1.js?#fragment",
|
||||
join(enhancedResolveRoot, "main1.js?#fragment"),
|
||||
],
|
||||
|
||||
[
|
||||
'file with query (unicode)',
|
||||
enhancedResolveRoot,
|
||||
'./测试.js?query',
|
||||
join(enhancedResolveRoot, '测试.js?query'),
|
||||
],
|
||||
[
|
||||
'file with fragment (unicode)',
|
||||
enhancedResolveRoot,
|
||||
'./测试.js#fragment',
|
||||
join(enhancedResolveRoot, '测试.js#fragment'),
|
||||
],
|
||||
[
|
||||
'file with fragment and query (unicode)',
|
||||
enhancedResolveRoot,
|
||||
'./测试.js#fragment?query',
|
||||
join(enhancedResolveRoot, '测试.js#fragment?query'),
|
||||
],
|
||||
[
|
||||
'file with query and fragment (unicode)',
|
||||
enhancedResolveRoot,
|
||||
'./测试.js?#fragment',
|
||||
join(enhancedResolveRoot, '测试.js?#fragment'),
|
||||
],
|
||||
[
|
||||
"file with query (unicode)",
|
||||
enhancedResolveRoot,
|
||||
"./测试.js?query",
|
||||
join(enhancedResolveRoot, "测试.js?query"),
|
||||
],
|
||||
[
|
||||
"file with fragment (unicode)",
|
||||
enhancedResolveRoot,
|
||||
"./测试.js#fragment",
|
||||
join(enhancedResolveRoot, "测试.js#fragment"),
|
||||
],
|
||||
[
|
||||
"file with fragment and query (unicode)",
|
||||
enhancedResolveRoot,
|
||||
"./测试.js#fragment?query",
|
||||
join(enhancedResolveRoot, "测试.js#fragment?query"),
|
||||
],
|
||||
[
|
||||
"file with query and fragment (unicode)",
|
||||
enhancedResolveRoot,
|
||||
"./测试.js?#fragment",
|
||||
join(enhancedResolveRoot, "测试.js?#fragment"),
|
||||
],
|
||||
|
||||
[
|
||||
'file in module with query',
|
||||
enhancedResolveRoot,
|
||||
'm1/a?query',
|
||||
join(enhancedResolveRoot, 'node_modules/m1/a.js?query'),
|
||||
],
|
||||
[
|
||||
'file in module with fragment',
|
||||
enhancedResolveRoot,
|
||||
'm1/a#fragment',
|
||||
join(enhancedResolveRoot, 'node_modules/m1/a.js#fragment'),
|
||||
],
|
||||
[
|
||||
'file in module with fragment and query',
|
||||
enhancedResolveRoot,
|
||||
'm1/a#fragment?query',
|
||||
join(enhancedResolveRoot, 'node_modules/m1/a.js#fragment?query'),
|
||||
],
|
||||
[
|
||||
'file in module with query and fragment',
|
||||
enhancedResolveRoot,
|
||||
'm1/a?#fragment',
|
||||
join(enhancedResolveRoot, 'node_modules/m1/a.js?#fragment'),
|
||||
],
|
||||
[
|
||||
'differ between directory and file, resolve file',
|
||||
enhancedResolveRoot,
|
||||
'./dirOrFile',
|
||||
join(enhancedResolveRoot, 'dirOrFile.js'),
|
||||
],
|
||||
[
|
||||
'differ between directory and file, resolve directory',
|
||||
enhancedResolveRoot,
|
||||
'./dirOrFile/',
|
||||
join(enhancedResolveRoot, 'dirOrFile/index.js'),
|
||||
],
|
||||
[
|
||||
'find node_modules outside of node_modules',
|
||||
join(enhancedResolveRoot, 'browser-module/node_modules'),
|
||||
'm1/a',
|
||||
join(enhancedResolveRoot, 'node_modules/m1/a.js'),
|
||||
],
|
||||
[
|
||||
"don't crash on main field pointing to self",
|
||||
enhancedResolveRoot,
|
||||
'./main-field-self',
|
||||
join(enhancedResolveRoot, './main-field-self/index.js'),
|
||||
],
|
||||
[
|
||||
"don't crash on main field pointing to self (2)",
|
||||
enhancedResolveRoot,
|
||||
'./main-field-self2',
|
||||
join(enhancedResolveRoot, './main-field-self2/index.js'),
|
||||
],
|
||||
// enhanced-resolve has `#` prepended with a `\0`, they are removed from the
|
||||
// following 3 expected test results.
|
||||
// See https://github.com/webpack/enhanced-resolve#escaping
|
||||
[
|
||||
'handle fragment edge case (no fragment)',
|
||||
enhancedResolveRoot,
|
||||
'./no#fragment/#/#',
|
||||
join(enhancedResolveRoot, 'no#fragment', '#', '#.js'),
|
||||
],
|
||||
[
|
||||
'handle fragment edge case (fragment)',
|
||||
enhancedResolveRoot,
|
||||
'./no#fragment/#/',
|
||||
join(enhancedResolveRoot, 'no.js#fragment') + '/#/',
|
||||
],
|
||||
[
|
||||
'handle fragment escaping',
|
||||
enhancedResolveRoot,
|
||||
'./no\0#fragment/\0#/\0##fragment',
|
||||
join(enhancedResolveRoot, 'no#fragment', '#', '#.js#fragment'),
|
||||
],
|
||||
]
|
||||
) {
|
||||
[
|
||||
"file in module with query",
|
||||
enhancedResolveRoot,
|
||||
"m1/a?query",
|
||||
join(enhancedResolveRoot, "node_modules/m1/a.js?query"),
|
||||
],
|
||||
[
|
||||
"file in module with fragment",
|
||||
enhancedResolveRoot,
|
||||
"m1/a#fragment",
|
||||
join(enhancedResolveRoot, "node_modules/m1/a.js#fragment"),
|
||||
],
|
||||
[
|
||||
"file in module with fragment and query",
|
||||
enhancedResolveRoot,
|
||||
"m1/a#fragment?query",
|
||||
join(enhancedResolveRoot, "node_modules/m1/a.js#fragment?query"),
|
||||
],
|
||||
[
|
||||
"file in module with query and fragment",
|
||||
enhancedResolveRoot,
|
||||
"m1/a?#fragment",
|
||||
join(enhancedResolveRoot, "node_modules/m1/a.js?#fragment"),
|
||||
],
|
||||
[
|
||||
"differ between directory and file, resolve file",
|
||||
enhancedResolveRoot,
|
||||
"./dirOrFile",
|
||||
join(enhancedResolveRoot, "dirOrFile.js"),
|
||||
],
|
||||
[
|
||||
"differ between directory and file, resolve directory",
|
||||
enhancedResolveRoot,
|
||||
"./dirOrFile/",
|
||||
join(enhancedResolveRoot, "dirOrFile/index.js"),
|
||||
],
|
||||
[
|
||||
"find node_modules outside of node_modules",
|
||||
join(enhancedResolveRoot, "browser-module/node_modules"),
|
||||
"m1/a",
|
||||
join(enhancedResolveRoot, "node_modules/m1/a.js"),
|
||||
],
|
||||
[
|
||||
"don't crash on main field pointing to self",
|
||||
enhancedResolveRoot,
|
||||
"./main-field-self",
|
||||
join(enhancedResolveRoot, "./main-field-self/index.js"),
|
||||
],
|
||||
[
|
||||
"don't crash on main field pointing to self (2)",
|
||||
enhancedResolveRoot,
|
||||
"./main-field-self2",
|
||||
join(enhancedResolveRoot, "./main-field-self2/index.js"),
|
||||
],
|
||||
// enhanced-resolve has `#` prepended with a `\0`, they are removed from the
|
||||
// following 3 expected test results.
|
||||
// See https://github.com/webpack/enhanced-resolve#escaping
|
||||
[
|
||||
"handle fragment edge case (no fragment)",
|
||||
enhancedResolveRoot,
|
||||
"./no#fragment/#/#",
|
||||
join(enhancedResolveRoot, "no#fragment", "#", "#.js"),
|
||||
],
|
||||
[
|
||||
"handle fragment edge case (fragment)",
|
||||
enhancedResolveRoot,
|
||||
"./no#fragment/#/",
|
||||
join(enhancedResolveRoot, "no.js#fragment") + "/#/",
|
||||
],
|
||||
[
|
||||
"handle fragment escaping",
|
||||
enhancedResolveRoot,
|
||||
"./no\0#fragment/\0#/\0##fragment",
|
||||
join(enhancedResolveRoot, "no#fragment", "#", "#.js#fragment"),
|
||||
],
|
||||
]) {
|
||||
test(title, () => {
|
||||
const resolver = new ResolverFactory({
|
||||
modules: ['src/a', 'src/b', 'src/common', 'node_modules'],
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
modules: ["src/a", "src/b", "src/common", "node_modules"],
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
});
|
||||
|
||||
assert.equal(resolver.sync(context, request).path, expected);
|
||||
});
|
||||
}
|
||||
|
||||
const pnpmDir = join(rootDir, 'node_modules', '.pnpm');
|
||||
const pnpmDir = join(rootDir, "node_modules", ".pnpm");
|
||||
|
||||
test('resolve pnpm package', () => {
|
||||
const pnpmProjectPath = join(fixturesDir, 'pnpm');
|
||||
test("resolve pnpm package", () => {
|
||||
const pnpmProjectPath = join(fixturesDir, "pnpm");
|
||||
const resolver = new ResolverFactory({
|
||||
aliasFields: ['browser'],
|
||||
aliasFields: ["browser"],
|
||||
});
|
||||
|
||||
const styledComponents = resolver.sync(pnpmProjectPath, 'styled-components');
|
||||
const styledComponents = resolver.sync(pnpmProjectPath, "styled-components");
|
||||
assert.deepEqual(
|
||||
styledComponents.path,
|
||||
join(
|
||||
pnpmDir,
|
||||
'[email protected][email protected][email protected][email protected]/node_modules/styled-components/dist/styled-components.browser.cjs.js',
|
||||
"[email protected][email protected][email protected][email protected]/node_modules/styled-components/dist/styled-components.browser.cjs.js",
|
||||
),
|
||||
);
|
||||
|
||||
const react = resolver.sync(
|
||||
join(
|
||||
pnpmDir,
|
||||
'[email protected][email protected][email protected][email protected]/node_modules/styled-components',
|
||||
"[email protected][email protected][email protected][email protected]/node_modules/styled-components",
|
||||
),
|
||||
'react',
|
||||
);
|
||||
assert.deepEqual(
|
||||
react.path,
|
||||
join(pnpmDir, '[email protected]/node_modules/react/index.js'),
|
||||
"react",
|
||||
);
|
||||
assert.deepEqual(react.path, join(pnpmDir, "[email protected]/node_modules/react/index.js"));
|
||||
});
|
||||
|
||||
test('resolve recursive symbol link', () => {
|
||||
const workspaceProjectPath = join(fixturesDir, 'pnpm-workspace');
|
||||
test("resolve recursive symbol link", () => {
|
||||
const workspaceProjectPath = join(fixturesDir, "pnpm-workspace");
|
||||
const resolver = new ResolverFactory({});
|
||||
|
||||
const react = resolver.sync(
|
||||
join(workspaceProjectPath, './packages/app'),
|
||||
'./node_modules/@monorepo/lib/node_modules/react/package.json',
|
||||
join(workspaceProjectPath, "./packages/app"),
|
||||
"./node_modules/@monorepo/lib/node_modules/react/package.json",
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
react.path,
|
||||
join(pnpmDir, '[email protected]/node_modules/react/package.json'),
|
||||
);
|
||||
assert.deepEqual(react.path, join(pnpmDir, "[email protected]/node_modules/react/package.json"));
|
||||
});
|
||||
|
||||
+21
-29
@@ -1,64 +1,56 @@
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { assert, test } from 'vitest';
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { assert, test } from "vitest";
|
||||
|
||||
import resolve, { ModuleType, ResolverFactory } from '../index.js';
|
||||
import resolve, { ModuleType, ResolverFactory } from "../index.js";
|
||||
|
||||
const cwd = join(fileURLToPath(import.meta.url), '..', '..');
|
||||
const cwd = join(fileURLToPath(import.meta.url), "..", "..");
|
||||
|
||||
test('simple', () => {
|
||||
test("simple", () => {
|
||||
// `resolve`
|
||||
assert.equal(resolve.sync(cwd, './index.js').path, join(cwd, 'index.js'));
|
||||
assert.equal(resolve.sync(cwd, "./index.js").path, join(cwd, "index.js"));
|
||||
|
||||
// `ResolverFactory`
|
||||
const resolver = new ResolverFactory();
|
||||
assert.equal(resolver.sync(cwd, './index.js').path, join(cwd, 'index.js'));
|
||||
assert.equal(resolver.sync(cwd, "./index.js").path, join(cwd, "index.js"));
|
||||
|
||||
assert.isAbove(resolver.sync(cwd, './ts').error.length, 0);
|
||||
assert.isAbove(resolver.sync(cwd, "./ts").error.length, 0);
|
||||
|
||||
resolver
|
||||
.async(cwd, './ts')
|
||||
.then((result) => assert.isAbove(result.error.length, 0));
|
||||
resolver.async(cwd, "./ts").then((result) => assert.isAbove(result.error.length, 0));
|
||||
|
||||
// Test API
|
||||
const newResolver = resolver.cloneWithOptions({});
|
||||
newResolver.clearCache();
|
||||
});
|
||||
|
||||
test('module_type', () => {
|
||||
const dir = join(cwd, '..', 'fixtures', 'pnpm');
|
||||
test("module_type", () => {
|
||||
const dir = join(cwd, "..", "fixtures", "pnpm");
|
||||
|
||||
const esmResolver = new ResolverFactory({
|
||||
conditionNames: ['node', 'import'],
|
||||
conditionNames: ["node", "import"],
|
||||
moduleType: true,
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
esmResolver.sync(dir, 'minimatch').moduleType,
|
||||
ModuleType.Module,
|
||||
);
|
||||
assert.equal(esmResolver.sync(dir, "minimatch").moduleType, ModuleType.Module);
|
||||
|
||||
const cjsResolver = esmResolver.cloneWithOptions({
|
||||
conditionNames: ['node', 'require'],
|
||||
conditionNames: ["node", "require"],
|
||||
moduleType: true,
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
cjsResolver.sync(dir, 'minimatch').moduleType,
|
||||
ModuleType.CommonJs,
|
||||
);
|
||||
assert.equal(cjsResolver.sync(dir, "minimatch").moduleType, ModuleType.CommonJs);
|
||||
});
|
||||
|
||||
test('builtin', () => {
|
||||
test("builtin", () => {
|
||||
const resolver = new ResolverFactory({
|
||||
builtinModules: true,
|
||||
});
|
||||
assert.deepEqual(resolver.sync('/', 'fs').builtin, {
|
||||
resolved: 'node:fs',
|
||||
assert.deepEqual(resolver.sync("/", "fs").builtin, {
|
||||
resolved: "node:fs",
|
||||
isRuntimeModule: false,
|
||||
});
|
||||
assert.deepEqual(resolver.sync('/', 'node:fs').builtin, {
|
||||
resolved: 'node:fs',
|
||||
assert.deepEqual(resolver.sync("/", "node:fs").builtin, {
|
||||
resolved: "node:fs",
|
||||
isRuntimeModule: true,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const normalizePath = (p) => p.replaceAll('\\', '/');
|
||||
export const normalizePath = (p) => p.replaceAll("\\", "/");
|
||||
|
||||
+16
-14
@@ -1,9 +1,7 @@
|
||||
{
|
||||
"name": "oxc-resolver",
|
||||
"version": "11.15.0",
|
||||
"license": "MIT",
|
||||
"description": "Oxc Resolver Node API",
|
||||
"packageManager": "[email protected]",
|
||||
"homepage": "https://oxc.rs",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -12,40 +10,34 @@
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/Boshen"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"browser": "browser.js",
|
||||
"files": [
|
||||
"browser.js",
|
||||
"index.d.ts",
|
||||
"index.js",
|
||||
"browser.js",
|
||||
"webcontainer-fallback.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "vitest run -r ./napi",
|
||||
"build:debug": "napi build --platform --manifest-path napi/Cargo.toml",
|
||||
"build": "pnpm run build:debug --features allocator --release",
|
||||
"postbuild:debug": "node napi/patch.mjs"
|
||||
"postbuild:debug": "node napi/patch.mjs",
|
||||
"fmt": "oxfmt"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@napi-rs/cli": "^3.3.1",
|
||||
"@napi-rs/wasm-runtime": "^1.0.7",
|
||||
"@types/node": "^25.0.0",
|
||||
"emnapi": "^1.6.0",
|
||||
"oxfmt": "^0.18.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^4.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"napi": {
|
||||
"binaryName": "resolver",
|
||||
"packageName": "@oxc-resolver/binding",
|
||||
"wasm": {
|
||||
"browser": {
|
||||
"fs": true
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
"aarch64-apple-darwin",
|
||||
"aarch64-linux-android",
|
||||
@@ -67,6 +59,16 @@
|
||||
"x86_64-unknown-freebsd",
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"x86_64-unknown-linux-musl"
|
||||
]
|
||||
],
|
||||
"wasm": {
|
||||
"browser": {
|
||||
"fs": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"packageManager": "[email protected]",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+91
@@ -20,6 +20,9 @@ importers:
|
||||
emnapi:
|
||||
specifier: ^1.6.0
|
||||
version: 1.7.1
|
||||
oxfmt:
|
||||
specifier: ^0.18.0
|
||||
version: 0.18.0
|
||||
typescript:
|
||||
specifier: ^5.9.3
|
||||
version: 5.9.3
|
||||
@@ -789,6 +792,46 @@ packages:
|
||||
'@oxc-resolver/test-longfilename-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@file:fixtures/pnpm/longfilename':
|
||||
resolution: {directory: fixtures/pnpm/longfilename, type: directory}
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
resolution: {integrity: sha512-Dp3mOFUtLtG/0eDclI3rx2be5FEnUxh2T6zlq7Zx5Q1c+DS9LJF8H97nQx+O/OU+o0e0J90kN8Msf9v3j7Hhsg==}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
resolution: {integrity: sha512-Oe3KS4tdfLq+f1Ebje7D9BF7/0xmBYSMN6dWatSko1xfvu8oCZzKcNCcbwz0a8rBnoH/BnIiGFUEbgJDnA/JLQ==}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
resolution: {integrity: sha512-zW9z8LrAgL9bswgsaFOnQmoImCbq9YQST8B15FAoTeZYr9sb/VfdD6/PQEBLCptYlFmoTvmDNHjppi9g61NwHQ==}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
resolution: {integrity: sha512-mFnpcasZZv1s/+6YDPradhIgR2G7GWr+mnzgJMIKQOJAtX3b0vzG+FE4f7hDIZPEUhC0hvZSd8f31FjAtrX0aQ==}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
resolution: {integrity: sha512-G1AXQNHVkPgVgRrAvDYdNi0x3gkvVyEmpL6WLMwoSjMnwYWQLt5/jrndHbS2Db8/CcmMo6VPP8lUQGvM4TRVaQ==}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
resolution: {integrity: sha512-M/KEIMHDr5lcK9gDxgIGr9xVwX7Pfl3PZs+6e8SySuckMgoJMkee6uWxhMdxws3dfU94saAkVmNQzM2+l3hvtA==}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
resolution: {integrity: sha512-LunuNBTLOgfkYFjiHOeNHD/Ii5paO/GVyNPSEYBwEPULbdeMGnjHqxzQHLGU8QIQjwu55mp4uuBP0DAXTli2TQ==}
|
||||
cpu: [arm64]
|
||||
os: [win32]
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
resolution: {integrity: sha512-0kJJwn4FPeGJ4uV6ofOCiY+oBKWg+RWpRjYc9bywTjDbxWR6JAqtuXkiARCJej8UD/rJeXnHYTF78sFALkwZyA==}
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
|
||||
'@rollup/[email protected]':
|
||||
resolution: {integrity: sha512-mRSi+4cBjrRLoaal2PnqH82Wqyb+d3HsPUN/W+WslCXsZsyHa9ZeQQX/pQsZaVIWDkPcpV6jJ+3KLbTbgnwv8w==}
|
||||
cpu: [arm]
|
||||
@@ -1227,6 +1270,11 @@ packages:
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-uTqF9MuPraAQ+IsnPf366RG4cP9RtUi7MLO1N3KEc+wb0a6yKpeL0lmk2IB1jY5KHPAlTc6T/JRdC/YqxHNwkQ==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-XqVS+LQi7ARsFlIftB69+jGN2qQaJNBjQU2b9ZQYt+iaUV9digh+dBIsU0isQIZhaQ1ihxGFfsTYQXE/Oak8Qw==}
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
hasBin: true
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==}
|
||||
|
||||
@@ -1339,6 +1387,10 @@ packages:
|
||||
resolution: {integrity: sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-/RX9RzeH2xU5ADE7n2Ykvmi9ED3FBGPAjw9u3zucrNNaEBIO0HPSYgL0NT7+3p147ojeSdaVu08F6hjpv31HJg==}
|
||||
engines: {node: ^20.0.0 || >=22.0.0}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-PSkbLUoxOFRzJYjjxHJt9xro7D+iilgMX/C9lawzVuYiIdcihh9DXmVibBe8lmcFrRi/VzlPjBxbN7rH24q8/Q==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
@@ -1982,6 +2034,30 @@ snapshots:
|
||||
|
||||
'@oxc-resolver/test-longfilename-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@file:fixtures/pnpm/longfilename': {}
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
optional: true
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
optional: true
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
optional: true
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
optional: true
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
optional: true
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
optional: true
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
optional: true
|
||||
|
||||
'@oxfmt/[email protected]':
|
||||
optional: true
|
||||
|
||||
'@rollup/[email protected]':
|
||||
optional: true
|
||||
|
||||
@@ -2364,6 +2440,19 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
tinypool: 2.0.0
|
||||
optionalDependencies:
|
||||
'@oxfmt/darwin-arm64': 0.18.0
|
||||
'@oxfmt/darwin-x64': 0.18.0
|
||||
'@oxfmt/linux-arm64-gnu': 0.18.0
|
||||
'@oxfmt/linux-arm64-musl': 0.18.0
|
||||
'@oxfmt/linux-x64-gnu': 0.18.0
|
||||
'@oxfmt/linux-x64-musl': 0.18.0
|
||||
'@oxfmt/win32-arm64': 0.18.0
|
||||
'@oxfmt/win32-x64': 0.18.0
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
@@ -2486,6 +2575,8 @@ snapshots:
|
||||
fdir: 6.5.0([email protected])
|
||||
picomatch: 4.0.3
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "name",
|
||||
"type": "module",
|
||||
"sideEffects": {}
|
||||
"sideEffects": {},
|
||||
"type": "module"
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,2 +1 @@
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
Reference in New Issue
Block a user