Skip to content

Commit

Permalink
rename source map prefix (#8034)
Browse files Browse the repository at this point in the history
### Description

Change source map prefix from `/turbopack/` to `turbopack://` to be more
inline with other tools.

This gives turbopack as separate root namespace for sources

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->


Closes PACK-2998
  • Loading branch information
sokra authored Apr 30, 2024
1 parent 903ce78 commit ca175f1
Show file tree
Hide file tree
Showing 93 changed files with 167 additions and 169 deletions.
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/lib.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

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.

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.

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.

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

Loading

0 comments on commit ca175f1

Please sign in to comment.