Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename source map prefix #8034

Merged
merged 2 commits into from Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/lib.rs
Expand Up @@ -46,7 +46,7 @@ pub mod virtual_fs {
}

pub const PROJECT_FILESYSTEM_NAME: &str = "project";
pub const SOURCE_MAP_ROOT_NAME: &str = "turbopack";
pub const SOURCE_MAP_PREFIX: &str = "turbopack://";

#[doc(hidden)]
pub mod __private {
Expand Down
6 changes: 3 additions & 3 deletions crates/turbopack-core/src/source_map/mod.rs
Expand Up @@ -14,7 +14,7 @@ use turbo_tasks_fs::{
FileContent, FileSystemPath,
};

use crate::{source_pos::SourcePos, SOURCE_MAP_ROOT_NAME};
use crate::{source_pos::SourcePos, SOURCE_MAP_PREFIX};

pub(crate) mod source_map_asset;

Expand Down Expand Up @@ -398,7 +398,7 @@ impl SourceMap {
Ok(
if let Some(path) = *origin.parent().try_join(source_request.to_string()).await? {
let path_str = path.to_string().await?;
let source = format!("/{SOURCE_MAP_ROOT_NAME}/{}", path_str);
let source = format!("{SOURCE_MAP_PREFIX}{}", path_str);
let source_content = if let Some(source_content) = source_content {
source_content
} else if let FileContent::Content(file) = &*path.read().await? {
Expand All @@ -416,7 +416,7 @@ impl SourceMap {
.replace_all(&source_request, |s: &regex::Captures<'_>| {
s[0].replace('.', "_")
});
let source = format!("/{SOURCE_MAP_ROOT_NAME}/{}/{}", origin_str, source);
let source = format!("{SOURCE_MAP_PREFIX}{}/{}", origin_str, source);
let source_content = source_content.unwrap_or_else(|| {
format!(
"unable to access {source_request} in {origin_str} (it's leaving the \
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-css/src/parse.rs
@@ -1,5 +1,5 @@
use swc_core::common::{source_map::SourceMapGenConfig, FileName};
use turbopack_core::SOURCE_MAP_ROOT_NAME;
use turbopack_core::SOURCE_MAP_PREFIX;

/// A config to generate a source map which includes the source content of every
/// source file. SWC doesn't inline sources content by default when generating a
Expand All @@ -9,7 +9,7 @@ pub struct InlineSourcesContentConfig {}
impl SourceMapGenConfig for InlineSourcesContentConfig {
fn file_name_to_source(&self, f: &FileName) -> String {
match f {
FileName::Custom(s) => format!("/{SOURCE_MAP_ROOT_NAME}/{s}"),
FileName::Custom(s) => format!("{SOURCE_MAP_PREFIX}{s}"),
_ => f.to_string(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-css/src/process.rs
Expand Up @@ -48,7 +48,7 @@ use turbopack_core::{
source::Source,
source_map::{GenerateSourceMap, OptionSourceMap},
source_pos::SourcePos,
SOURCE_MAP_ROOT_NAME,
SOURCE_MAP_PREFIX,
};
use turbopack_swc_utils::emitter::IssueEmitter;

Expand Down Expand Up @@ -977,7 +977,7 @@ impl GenerateSourceMap for ParseCssResultSourceMap {
let mut builder = SourceMapBuilder::new(None);

for src in source_map.get_sources() {
builder.add_source(&format!("/{SOURCE_MAP_ROOT_NAME}/{src}"));
builder.add_source(&format!("{SOURCE_MAP_PREFIX}{src}"));
}

for (idx, content) in source_map.get_sources_content().iter().enumerate() {
Expand Down
4 changes: 2 additions & 2 deletions crates/turbopack-ecmascript/src/parse.rs
Expand Up @@ -30,7 +30,7 @@ use turbopack_core::{
issue::{Issue, IssueExt, IssueSeverity, IssueStage, OptionStyledString, StyledString},
source::Source,
source_map::{GenerateSourceMap, OptionSourceMap, SourceMap},
SOURCE_MAP_ROOT_NAME,
SOURCE_MAP_PREFIX,
};
use turbopack_swc_utils::emitter::IssueEmitter;

Expand Down Expand Up @@ -140,7 +140,7 @@ impl SourceMapGenConfig for InlineSourcesContentConfig {
fn file_name_to_source(&self, f: &FileName) -> String {
match f {
FileName::Custom(s) => {
format!("/{SOURCE_MAP_ROOT_NAME}/{s}")
format!("{SOURCE_MAP_PREFIX}{s}")
}
_ => f.to_string(),
}
Expand Down
8 changes: 3 additions & 5 deletions crates/turbopack-node/src/source_map/mod.rs
Expand Up @@ -16,8 +16,7 @@ use turbo_tasks_fs::{
};
use turbopack_cli_utils::source_context::format_source_context_lines;
use turbopack_core::{
output::OutputAsset, source_map::GenerateSourceMap, PROJECT_FILESYSTEM_NAME,
SOURCE_MAP_ROOT_NAME,
output::OutputAsset, source_map::GenerateSourceMap, PROJECT_FILESYSTEM_NAME, SOURCE_MAP_PREFIX,
};
use turbopack_ecmascript::magic_identifier::unmangle_identifiers;

Expand Down Expand Up @@ -233,9 +232,8 @@ async fn resolve_source_mapping(
TraceResult::Found(frame) => {
let lib_code = frame.file.contains("/node_modules/");
if let Some(project_path) = frame.file.strip_prefix(concatcp!(
"/",
SOURCE_MAP_ROOT_NAME,
"/[",
SOURCE_MAP_PREFIX,
"[",
PROJECT_FILESYSTEM_NAME,
"]/"
)) {
Expand Down