Skip to content

Commit

Permalink
fix: resolver priority issue (#1441)
Browse files Browse the repository at this point in the history
* fix: #1433

* fix: #1433

* chore: bump version

* chore: update skip example

* chore: update skip example
  • Loading branch information
ErKeLost authored Jun 26, 2024
1 parent 14b9fdb commit 223af33
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-kings-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farmfe/core": patch
---

resolver priority exports field when string type
21 changes: 8 additions & 13 deletions crates/plugin_resolve/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ impl Resolver {
let maybe_node_modules_path = current.join(NODE_MODULES);
if maybe_node_modules_path.exists() && maybe_node_modules_path.is_dir() {
let parse_package_source_result = utils::parse_package_source(source);

if parse_package_source_result.is_none() {
return (None, tried_paths);
}
Expand Down Expand Up @@ -647,18 +646,14 @@ impl Resolver {
let entry_point = raw_package_json_info
.get(HIGHEST_PRIORITY_FIELD)
.and_then(|field_value| {
if let Value::Object(_) = field_value {
resolve_exports_or_imports(
&package_json_info,
".",
HIGHEST_PRIORITY_FIELD,
kind,
context,
)
.map(|exports_entries| exports_entries.get(0).unwrap().to_string())
} else {
None
}
resolve_exports_or_imports(
&package_json_info,
".",
HIGHEST_PRIORITY_FIELD,
kind,
context,
)
.map(|exports_entries| exports_entries.get(0).unwrap().to_string())
})
.or_else(|| {
context
Expand Down
33 changes: 33 additions & 0 deletions crates/plugin_resolve/tests/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,36 @@ fn resolve_exports_browser() {
}
);
}


#[test]
// resolve exports value is string
fn resolve_exports_issue_1433() {
fixture!(
"tests/fixtures/resolve-node-modules/exports/index.ts",
|file, _| {
let cwd = file.parent().unwrap().to_path_buf();
let resolver = Resolver::new();
// Parsing packages in node_modules
let resolved = resolver.resolve(
"@issues/1433",
cwd.clone(),
&ResolveKind::Import,
&Arc::new(CompilationContext::default()),
);
assert!(resolved.is_some());
let resolved = resolved.unwrap();
assert_eq!(
resolved.resolved_path,
cwd
.join("node_modules")
.join("@issues")
.join("1433")
.join("lib")
.join("default.js")
.to_string_lossy()
.to_string()
);
}
);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/default.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { logger } from './utils.js';
import { describe } from 'node:test';
// import { ssrExamples } from './test-utils.js';

const excludeExamples: string[] = [];
const excludeExamples: string[] = ['issues1433'];

describe('Default E2E Tests', async () => {
const examples = readdirSync('./examples');
const examples = readdirSync('./examples')
// const examples = ['react-ssr', 'solid-ssr', 'vue-ssr'];
logger(`Running E2E tests for ${examples.length} examples`);

Expand Down
9 changes: 9 additions & 0 deletions examples/issues1433/farm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from '@farmfe/core'

export default defineConfig({
compilation: {
output: {
targetEnv: 'node'
}
}
})
19 changes: 19 additions & 0 deletions examples/issues1433/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// import {stringifyPosition} from 'unist-util-stringify-position';

// const node = {
// type: 'text',
// value: 'Hello, world!',
// position: {
// start: { line: 1, column: 1, offset: 0 },
// end: { line: 1, column: 13, offset: 12 }
// }
// };

// const positionString = stringifyPosition(node);
// console.log(positionString);
import {codes, constants, types, values} from 'micromark-util-symbol'

console.log(codes.atSign) // 64
console.log(constants.characterReferenceNamedSizeMax) // 31
console.log(types.definitionDestinationRaw) // 'definitionDestinationRaw'
console.log(values.atSign) // '@'
22 changes: 22 additions & 0 deletions examples/issues1433/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@farmfe-examples/issues1433",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"build": "farm build"
},
"devDependencies": {
"@farmfe/cli": "workspace:*",
"@farmfe/core": "workspace:*"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"micromark-util-symbol": "^2.0.0",
"unist-util-stringify-position": "^4.0.0"
}
}
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 223af33

Please sign in to comment.