Skip to content

Commit 1d24d7e

Browse files
committed
fix(optimizer): windows paths
1 parent 9a21ed5 commit 1d24d7e

File tree

5 files changed

+125
-78
lines changed

5 files changed

+125
-78
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ jobs:
232232
run: pnpm lint.rust
233233

234234
- name: Unit tests
235-
if: matrix.settings.wasm
235+
if: matrix.settings.wasm || matrix.settings.host == 'windows-latest'
236236
run: pnpm test.rust
237237

238238
- name: Build Platform Binding

packages/qwik/src/optimizer/core/src/parse.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ impl Emitter for ErrorBuffer {
206206

207207
pub fn transform_code(config: TransformCodeOptions) -> Result<TransformOutput, anyhow::Error> {
208208
let source_map = Lrc::new(SourceMap::default());
209-
let path_data = parse_path(config.relative_path, config.src_dir)?;
209+
let path_data = parse_path(
210+
config.relative_path.replace('\\', "/").as_str(),
211+
config.src_dir,
212+
)?;
210213
let module = parse(
211214
config.code,
212215
&path_data,
@@ -470,7 +473,7 @@ pub fn transform_code(config: TransformCodeOptions) -> Result<TransformOutput, a
470473
} else {
471474
path_data.file_name
472475
};
473-
let path = path_data.rel_dir.join(a).to_string_lossy().to_string();
476+
let path = path_data.rel_dir.join(a).to_slash_lossy().to_string();
474477

475478
let mut hasher = DefaultHasher::new();
476479
hasher.write(path.as_bytes());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
source: packages/qwik/src/optimizer/core/src/test.rs
3+
assertion_line: 1948
4+
expression: output
5+
---
6+
==INPUT==
7+
8+
9+
import { component$ } from '@builder.io/qwik';
10+
export const Greeter = component$(() => <div/>)
11+
12+
============================= components/apps/greeter_component_0jjovx068y0.ts (ENTRY POINT)==
13+
14+
import { _jsxQ } from "@builder.io/qwik";
15+
export const Greeter_component_0jjOvx068y0 = ()=>/*#__PURE__*/ _jsxQ("div", null, null, null, 3, "KD_0");
16+
17+
18+
Some("{\"version\":3,\"sources\":[\"C:\\\\users\\\\apps/components/apps/apps.tsx\"],\"names\":[],\"mappings\":\";6CAEkC,kBAAM,MAAC\"}")
19+
/*
20+
{
21+
"origin": "components/apps/apps.tsx",
22+
"name": "Greeter_component_0jjOvx068y0",
23+
"entry": null,
24+
"displayName": "Greeter_component",
25+
"hash": "0jjOvx068y0",
26+
"canonicalFilename": "greeter_component_0jjovx068y0",
27+
"path": "components/apps",
28+
"extension": "ts",
29+
"parent": null,
30+
"ctxKind": "function",
31+
"ctxName": "component$",
32+
"captures": false,
33+
"loc": [
34+
83,
35+
95
36+
]
37+
}
38+
*/
39+
============================= components/apps/apps.ts ==
40+
41+
import { componentQrl } from "@builder.io/qwik";
42+
import { qrl } from "@builder.io/qwik";
43+
export const Greeter = /*#__PURE__*/ componentQrl(/*#__PURE__*/ qrl(()=>import("./greeter_component_0jjovx068y0"), "Greeter_component_0jjOvx068y0"));
44+
45+
46+
Some("{\"version\":3,\"sources\":[\"C:\\\\users\\\\apps/components/apps/apps.tsx\"],\"names\":[],\"mappings\":\";;AAEA,OAAO,MAAM,wBAAU,gHAAwB\"}")
47+
== DIAGNOSTICS ==
48+
49+
[]

packages/qwik/src/optimizer/core/src/test.rs

+69-69
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,6 @@
33
use super::*;
44
use serde_json::to_string_pretty;
55

6-
macro_rules! test_input {
7-
($input: expr) => {
8-
let input = $input;
9-
let strip_exports: Option<Vec<JsWord>> = input
10-
.strip_exports
11-
.map(|v| v.into_iter().map(|s| JsWord::from(s)).collect());
12-
13-
let reg_ctx_name: Option<Vec<JsWord>> = input
14-
.reg_ctx_name
15-
.map(|v| v.into_iter().map(|s| JsWord::from(s)).collect());
16-
17-
let strip_ctx_name: Option<Vec<JsWord>> = input
18-
.strip_ctx_name
19-
.map(|v| v.into_iter().map(|s| JsWord::from(s)).collect());
20-
21-
let res = transform_modules(TransformModulesOptions {
22-
src_dir: input.src_dir,
23-
root_dir: input.root_dir,
24-
input: vec![TransformModuleInput {
25-
code: input.code.clone(),
26-
path: input.filename,
27-
}],
28-
source_maps: true,
29-
minify: input.minify,
30-
transpile_ts: input.transpile_ts,
31-
transpile_jsx: input.transpile_jsx,
32-
preserve_filenames: input.preserve_filenames,
33-
explicit_extensions: input.explicit_extensions,
34-
manual_chunks: input.manual_chunks,
35-
entry_strategy: input.entry_strategy,
36-
mode: input.mode,
37-
scope: input.scope,
38-
core_module: input.core_module,
39-
strip_exports,
40-
strip_ctx_name,
41-
reg_ctx_name,
42-
strip_event_handlers: input.strip_event_handlers,
43-
is_server: input.is_server,
44-
});
45-
if input.snapshot {
46-
let input = input.code.to_string();
47-
let output = format!("==INPUT==\n\n{}", input);
48-
snapshot_res!(&res, output);
49-
}
50-
drop(res)
51-
};
52-
}
53-
546
macro_rules! snapshot_res {
557
($res: expr, $prefix: expr) => {
568
match $res {
@@ -68,8 +20,6 @@ macro_rules! snapshot_res {
6820
let hook = to_string_pretty(&hook).unwrap();
6921
output += &format!("\n/*\n{}\n*/", hook);
7022
}
71-
// let map = if let Some(map) = s.map { map } else { "".to_string() };
72-
// output += format!("\n== MAP ==\n{}", map).as_str();
7323
}
7424
output += format!(
7525
"\n== DIAGNOSTICS ==\n\n{}",
@@ -85,6 +35,56 @@ macro_rules! snapshot_res {
8535
};
8636
}
8737

38+
macro_rules! test_input {
39+
($input: expr) => {{
40+
let input = $input;
41+
let code = input.code.to_string();
42+
let snapshot = input.snapshot;
43+
let res = test_input_fn(input);
44+
if snapshot {
45+
snapshot_res!(&res, format!("==INPUT==\n\n{}", code.to_string()));
46+
}
47+
res
48+
}};
49+
}
50+
51+
fn test_input_fn(input: TestInput) -> Result<TransformOutput, anyhow::Error> {
52+
let strip_exports: Option<Vec<JsWord>> = input
53+
.strip_exports
54+
.map(|v| v.into_iter().map(|s| JsWord::from(s)).collect());
55+
let reg_ctx_name: Option<Vec<JsWord>> = input
56+
.reg_ctx_name
57+
.map(|v| v.into_iter().map(|s| JsWord::from(s)).collect());
58+
let strip_ctx_name: Option<Vec<JsWord>> = input
59+
.strip_ctx_name
60+
.map(|v| v.into_iter().map(|s| JsWord::from(s)).collect());
61+
62+
transform_modules(TransformModulesOptions {
63+
src_dir: input.src_dir,
64+
root_dir: input.root_dir,
65+
input: vec![TransformModuleInput {
66+
code: input.code.clone(),
67+
path: input.filename,
68+
}],
69+
source_maps: true,
70+
minify: input.minify,
71+
transpile_ts: input.transpile_ts,
72+
transpile_jsx: input.transpile_jsx,
73+
preserve_filenames: input.preserve_filenames,
74+
explicit_extensions: input.explicit_extensions,
75+
manual_chunks: input.manual_chunks,
76+
entry_strategy: input.entry_strategy,
77+
mode: input.mode,
78+
scope: input.scope,
79+
core_module: input.core_module,
80+
strip_exports,
81+
strip_ctx_name,
82+
reg_ctx_name,
83+
strip_event_handlers: input.strip_event_handlers,
84+
is_server: input.is_server,
85+
})
86+
}
87+
8888
#[test]
8989
fn example_1() {
9090
test_input!(TestInput {
@@ -1857,7 +1857,7 @@ export const Parent = component$(() => {
18571857
transpile_ts: true,
18581858
transpile_jsx: true,
18591859
entry_strategy: EntryStrategy::Inline,
1860-
strip_ctx_name: Some(vec!["useClientMount$".into(),]),
1860+
strip_ctx_name: Some(vec!["useClientMount$".into()]),
18611861
strip_event_handlers: true,
18621862
..TestInput::default()
18631863
});
@@ -1943,34 +1943,34 @@ export const Greeter = component$(() => {
19431943
});
19441944
}
19451945

1946-
#[cfg(target_os = "windows")]
19471946
#[test]
1948-
fn issue_188() {
1949-
let res = test_input!({
1947+
fn support_windows_paths() {
1948+
let res = test_input!(TestInput {
19501949
filename: r"components\apps\apps.tsx".to_string(),
19511950
src_dir: r"C:\users\apps".to_string(),
19521951
code: r#"
1953-
import { component$, $ } from '@builder.io/qwik';
1954-
1955-
export const Greeter = component$(() => {
1956-
return $(() => {
1957-
return (
1958-
<div/>
1959-
)
1960-
});
1961-
});
1962-
1963-
const d = $(()=>console.log('thing'));
1952+
import { component$ } from '@builder.io/qwik';
1953+
export const Greeter = component$(() => <div/>)
19641954
"#
19651955
.to_string(),
1966-
transpile_ts: true,
19671956
transpile_jsx: true,
1968-
snapshot: false,
1957+
is_server: Some(false),
1958+
entry_strategy: EntryStrategy::Hook,
1959+
..TestInput::default()
19691960
})
19701961
.unwrap();
1971-
let last_module = res.modules.last().unwrap();
1972-
assert_eq!(last_module.path, r"C:/users/apps/components/apps/apps.tsx")
1962+
// verify that none of the modules have a path that contains backslashes
1963+
for module in res.modules {
1964+
assert!(!module.path.contains('\\'));
1965+
}
19731966
}
1967+
// filler to retain assertion line numbers
1968+
//
1969+
//
1970+
//
1971+
//
1972+
//
1973+
19741974
#[test]
19751975
fn issue_476() {
19761976
test_input!(TestInput {

packages/qwik/src/optimizer/core/src/transform.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,7 @@ impl<'a> QwikTransform<'a> {
265265

266266
fn get_dev_location(&self, span: Span) -> ast::ExprOrSpread {
267267
let loc = self.options.cm.lookup_char_pos(span.lo);
268-
let file_name = self
269-
.options
270-
.path_data
271-
.rel_path
272-
.to_string_lossy()
273-
.to_string();
268+
let file_name = self.options.path_data.rel_path.to_slash_lossy().to_string();
274269
ast::ExprOrSpread {
275270
spread: None,
276271
expr: Box::new(ast::Expr::Object(ast::ObjectLit {

0 commit comments

Comments
 (0)