mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
fix(es/module): Fix interop of jsc.paths
with symlinks (#8757)
**Related issue:** - Closes #8667
This commit is contained in:
parent
4c83dcc370
commit
e2c6db5226
@ -1 +1 @@
|
||||
import { module } from "@src/config";
|
||||
import { module } from "@src/conf";
|
||||
|
@ -2,4 +2,4 @@
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
const _config = require("../config");
|
||||
const _conf = require("../conf");
|
||||
|
@ -1 +1 @@
|
||||
import { module } from "@src/config";
|
||||
import { module } from "@src/conf";
|
||||
|
@ -1 +1 @@
|
||||
import { module } from "../config";
|
||||
import { module } from "../conf";
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
fs::{self, create_dir_all},
|
||||
fs::{self, create_dir_all, hard_link},
|
||||
path::Path,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
@ -81,6 +81,69 @@ fn issue_8495_1() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_8667_1() -> Result<()> {
|
||||
let output_base = TempDir::new()?;
|
||||
let bin_dir = output_base.path().join("bazel-out/arch/bin");
|
||||
let sandbox = output_base.path().join("sandbox/123");
|
||||
|
||||
let pwd = Path::new("tests/fixture-manual/8265").canonicalize()?;
|
||||
|
||||
create_dir_all(bin_dir.join("src/modules/moduleA"))?;
|
||||
create_dir_all(bin_dir.join("src/modules/moduleB"))?;
|
||||
create_dir_all(sandbox.join("src/modules/moduleA"))?;
|
||||
create_dir_all(sandbox.join("src/modules/moduleB"))?;
|
||||
|
||||
// hard links from BINDIR into src
|
||||
hard_link(pwd.join(".swcrc"), bin_dir.join(".swcrc"))?;
|
||||
hard_link(pwd.join("src/index.ts"), bin_dir.join("src/index.ts"))?;
|
||||
hard_link(
|
||||
pwd.join("src/modules/moduleA/index.ts"),
|
||||
bin_dir.join("src/modules/moduleA/index.ts"),
|
||||
)?;
|
||||
hard_link(
|
||||
pwd.join("src/modules/moduleB/index.ts"),
|
||||
bin_dir.join("src/modules/moduleB/index.ts"),
|
||||
)?;
|
||||
|
||||
// soft links from sandbox into bazel-bin
|
||||
symlink(&bin_dir.join(".swcrc"), &sandbox.join(".swcrc"));
|
||||
symlink(&bin_dir.join("src/index.ts"), &sandbox.join("src/index.ts"));
|
||||
symlink(
|
||||
&bin_dir.join("src/modules/moduleA/index.ts"),
|
||||
&sandbox.join("src/modules/moduleA/index.ts"),
|
||||
);
|
||||
symlink(
|
||||
&bin_dir.join("src/modules/moduleB/index.ts"),
|
||||
&sandbox.join("src/modules/moduleB/index.ts"),
|
||||
);
|
||||
|
||||
//
|
||||
print_ls_alr(&sandbox);
|
||||
|
||||
let mut cmd = cli()?;
|
||||
cmd.current_dir(&sandbox)
|
||||
.arg("compile")
|
||||
.arg("--source-maps")
|
||||
.arg("false")
|
||||
.arg("--config-file")
|
||||
.arg(".swcrc")
|
||||
.arg("--out-file")
|
||||
.arg(bin_dir.join("src/index.js"))
|
||||
.arg("src/index.ts");
|
||||
|
||||
cmd.assert().success();
|
||||
|
||||
let content = fs::read_to_string(bin_dir.join("src/index.js"))?;
|
||||
assert!(
|
||||
content.contains("require(\"./modules/moduleA\")"),
|
||||
"{}",
|
||||
content
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ln -s $a $b
|
||||
fn symlink(a: &Path, b: &Path) {
|
||||
#[cfg(unix)]
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
env::current_dir,
|
||||
fs::read_link,
|
||||
io::{self},
|
||||
fs::canonicalize,
|
||||
io,
|
||||
path::{Component, Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
@ -245,7 +245,7 @@ where
|
||||
//
|
||||
// https://github.com/swc-project/swc/issues/8265
|
||||
if let FileName::Real(resolved) = &target.filename {
|
||||
if let Ok(orig) = read_link(resolved) {
|
||||
if let Ok(orig) = canonicalize(resolved) {
|
||||
target.filename = FileName::Real(orig);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user