Skip to content

Commit

Permalink
fix: join path
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Dec 31, 2024
1 parent 695530e commit e34c6af
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
19 changes: 17 additions & 2 deletions crates/rspack_core/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rspack_error::Result;
use rspack_fs::{IntermediateFileSystem, NativeFileSystem, ReadableFileSystem, WritableFileSystem};
use rspack_futures::FuturesResults;
use rspack_hook::define_hook;
use rspack_paths::{Utf8Path, Utf8PathBuf};
use rspack_paths::{Utf8Component, Utf8Path, Utf8PathBuf};
use rspack_sources::BoxSource;
use rustc_hash::FxHashMap as HashMap;
use tracing::instrument;
Expand Down Expand Up @@ -354,7 +354,22 @@ impl Compiler {
) -> Result<()> {
if let Some(source) = asset.get_source() {
let (target_file, query) = filename.split_once('?').unwrap_or((filename, ""));
let file_path = output_path.join(target_file);
let file_path = {
let target_path = Utf8Path::new(target_file);
if target_path.is_absolute() {
let mut relative_path = Utf8PathBuf::new();
for component in target_path.components() {
match component {
Utf8Component::Prefix(_) => continue,
Utf8Component::RootDir => continue,
_ => relative_path.push(component),
}
}
output_path.join(relative_path)
} else {
output_path.join(target_path)
}
};
self
.output_filesystem
.create_dir_all(
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_devtool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ rspack_plugin_javascript = { workspace = true }
rspack_util = { workspace = true }
rustc-hash = { workspace = true }
simd-json = { workspace = true }
sugar_path = { workspace = true }
tracing = { workspace = true }
sugar_path = { workspace = true }

[package.metadata.cargo-shear]
ignored = ["tracing"]
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ impl SourceMapDevToolPlugin {
source_map_path.push(Component::RootDir);
source_map_path.extend(Path::new(&source_map_filename).components());

#[allow(clippy::unwrap_used)]
file_path
.parent()
.unwrap()
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require("path");
const fs = require("fs");

const PLUGIN_NAME = "plugin";

class Plugin {
/**
* @param {import("@rspack/core").Compiler} compiler
*/
apply(compiler) {
const { RawSource } = compiler.rspack.sources;

compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
compilation.hooks.processAssets.tap(PLUGIN_NAME, () => {
compilation.emitAsset("/foo.txt", new RawSource(""));
});
});

compiler.hooks.afterCompile.tap(PLUGIN_NAME, () => {
const outputPath = path.join(compiler.options.output.path, "/foo.txt");
console.log("outputPath: ", outputPath);
expect(fs.existsSync(outputPath)).toBe(true);
});
}
}

/**@type {import("@rspack/core").Configuration}*/
module.exports = {
entry: "./index.js",
plugins: [new Plugin()]
};

0 comments on commit e34c6af

Please sign in to comment.