-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support browser filed false value (#395)
* fix: support browser filed false value * chore: add ResolvedPath * Fix snapshot * Fix clippy --------- Co-authored-by: Yunfei <[email protected]>
- Loading branch information
Showing
17 changed files
with
266 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
use rolldown_common::FilePath; | ||
use rolldown_common::ResolvedPath; | ||
use sugar_path::AsPath; | ||
|
||
use crate::{bundler::plugin_driver::PluginDriver, error::BatchedErrors, HookLoadArgs}; | ||
|
||
pub async fn load_source( | ||
plugin_driver: &PluginDriver, | ||
path: &FilePath, | ||
resolved_path: &ResolvedPath, | ||
fs: &dyn rolldown_fs::FileSystem, | ||
) -> Result<String, BatchedErrors> { | ||
let source = if let Some(r) = plugin_driver.load(&HookLoadArgs { id: path.as_ref() }).await? { | ||
r.code | ||
} else { | ||
fs.read_to_string(path.as_path())? | ||
}; | ||
let source = | ||
if let Some(r) = plugin_driver.load(&HookLoadArgs { id: &resolved_path.path }).await? { | ||
r.code | ||
} else if resolved_path.ignored { | ||
String::new() | ||
} else { | ||
fs.read_to_string(resolved_path.path.as_path())? | ||
}; | ||
Ok(source) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
crates/rolldown/tests/fixtures/resolve/browser-filed-false/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!node_modules |
18 changes: 18 additions & 0 deletions
18
crates/rolldown/tests/fixtures/resolve/browser-filed-false/artifacts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
source: crates/rolldown/tests/common/case.rs | ||
expression: content | ||
input_file: crates/rolldown/tests/fixtures/resolve/browser-filed-false | ||
--- | ||
# Assets | ||
|
||
## package.mjs | ||
|
||
```js | ||
import { __commonJS, __toESM } from "./_rolldown_runtime.mjs"; | ||
// (ignored) node_modules/package/util.js | ||
// node_modules/package/index.js | ||
import value from './util.js'; | ||
console.log(import_util.default); | ||
``` |
3 changes: 3 additions & 0 deletions
3
crates/rolldown/tests/fixtures/resolve/browser-filed-false/node_modules/package/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
crates/rolldown/tests/fixtures/resolve/browser-filed-false/node_modules/package/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
crates/rolldown/tests/fixtures/resolve/browser-filed-false/test.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"input": { | ||
"input": [ | ||
{ | ||
"name": "package", | ||
"import": "package" | ||
} | ||
], | ||
"resolve": { | ||
"aliasFields": [ | ||
[ | ||
"browser" | ||
] | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::path::Path; | ||
|
||
use crate::FilePath; | ||
use sugar_path::SugarPath; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ResolvedPath { | ||
pub path: FilePath, | ||
pub ignored: bool, | ||
} | ||
|
||
impl From<String> for ResolvedPath { | ||
fn from(value: String) -> Self { | ||
Self { path: value.into(), ignored: false } | ||
} | ||
} | ||
|
||
impl ResolvedPath { | ||
/// Created a pretty string representation of the path. The path | ||
/// 1. doesn't guarantee to be unique | ||
/// 2. relative to the cwd, so it could show stable path across different machines | ||
pub fn prettify(&self, cwd: impl AsRef<Path>) -> String { | ||
let pretty = if Path::new(self.path.as_ref()).is_absolute() { | ||
Path::new(self.path.as_ref()) | ||
.relative(cwd.as_ref()) | ||
.into_os_string() | ||
.into_string() | ||
.expect("should be valid utf8") | ||
} else { | ||
self.path.to_string() | ||
}; | ||
// remove \0 | ||
let pretty = pretty.replace('\0', ""); | ||
|
||
if self.ignored { | ||
format!("(ignored) {pretty}") | ||
} else { | ||
pretty | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.