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

try to fix windows tests #1419

Merged
merged 12 commits into from
Feb 22, 2021
11 changes: 6 additions & 5 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* text=auto


*.ts text merge=union eol=lf
*.tsx text merge=union eol=lf
*.rs text merge=union eol=lf
*.js text merge=union eol=lf
*.json text merge=union eol=lf
*.ts text eol=lf merge=union
*.tsx text eol=lf merge=union
*.rs text eol=lf merge=union
*.js text eol=lf merge=union
*.json text eol=lf merge=union
*.debug text eol=lf merge=union
3 changes: 1 addition & 2 deletions ecmascript/jsdoc/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ fn add_test<F: FnOnce() + Send + 'static>(
}

#[test]

fn fixture() {
let args: Vec<_> = env::args().collect();
let mut tests = Vec::new();
Expand Down Expand Up @@ -63,7 +62,7 @@ fn add_fixture(tests: &mut Vec<TestDescAndFn>) -> Result<(), Error> {

let fm = cm
.load_file(entry.path())
.expect("failed to load fixtue file");
.expect("failed to load fixture file");

let lexer = Lexer::new(
Syntax::Es(EsConfig {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@types/node": "^14.0.5",
"axios": "^0.21.1",
"babel-plugin-transform-node-env-inline": "^0.4.3",
"browserslist": "^4.12.0",
"browserslist": "^4.16.3",
"jest": "^23.6.0",
"lodash": "^4.17.11",
"progress": "^2.0.3",
Expand Down
3 changes: 3 additions & 0 deletions spack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ walkdir = "2.3.1"
[target.'cfg(all(unix, not(target_env = "musl")))'.dev-dependencies]
jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]}

[target.'cfg(windows)'.dependencies]
normpath="0.2"

[target.'cfg(windows)'.dev-dependencies]
mimalloc = {version = "0.1"}
1 change: 1 addition & 0 deletions spack/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(test, feature(test))]
#![feature(or_patterns)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really required?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swc uses nightly for a while because of some rustfmt options, but it does not rely on nightly features from non-test codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required, I just noticed that nightly was used anyway so I wanted to use some terser syntax, i'm not familiar with the consequences of using nightly features. looking at rust-lang/rust/issues/54883 looks to be out in next stable

should I remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay if it's going to be stabilized. Thanks!


#[cfg(test)]
extern crate test;
Expand Down
31 changes: 22 additions & 9 deletions spack/src/resolvers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

use anyhow::{bail, Context, Error};
use lru::LruCache;
#[cfg(windows)]
use normpath::BasePath;
// use path_slash::{PathBufExt, PathExt};
use serde::Deserialize;
use std::{
fs::File,
io::BufReader,
path::{Path, PathBuf},
path::{Component, Path, PathBuf},
sync::Mutex,
};

use swc_bundler::Resolve;
use swc_common::FileName;

Expand Down Expand Up @@ -49,7 +53,7 @@ impl NodeResolver {
}

fn wrap(&self, base: &PathBuf, target: &str, path: PathBuf) -> Result<FileName, Error> {
let path = path.canonicalize().context("failaed to canonicalize")?;
let path = path.canonicalize().context("failed to canonicalize")?;
self.store(base, target, path.clone());
Ok(FileName::Real(path))
}
Expand Down Expand Up @@ -176,12 +180,10 @@ impl Resolve for NodeResolver {
Err(_) => {}
}
}
let target_path = Path::new(target);

// Absolute path
if target.starts_with("/") {
let base_dir = &Path::new("/");

let path = base_dir.join(target);
if target_path.is_absolute() {
let path = PathBuf::from(target_path);
return self
.resolve_as_file(&path)
.or_else(|_| self.resolve_as_directory(&path))
Expand All @@ -190,8 +192,19 @@ impl Resolve for NodeResolver {

let cwd = &Path::new(".");
let base_dir = base.parent().unwrap_or(&cwd);

if target.starts_with("./") || target.starts_with("../") {
let mut components = target_path.components();

if let Some(Component::CurDir | Component::ParentDir) = components.next() {
#[cfg(windows)]
let path = {
let base_dir = BasePath::new(base_dir).unwrap();
base_dir
.join(target.replace('/', "\\"))
.normalize_virtually()
.unwrap()
.into_path_buf()
};
#[cfg(not(windows))]
let path = base_dir.join(target);
return self
.resolve_as_file(&path)
Expand Down
1 change: 1 addition & 0 deletions testing/macros/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub fn expand(test_file: &SourceFile, callee: &Ident, attr: Config) -> Result<Ve
callee,
path_for_name
.to_string_lossy()
.replace("\\", "__")
.replace("/", "__")
.replace(".", "_")
.replace("-", "_")
Expand Down