Skip to content

Commit 8b1eaa0

Browse files
committed
feat(config): replace tsx with node@>=22.6 type stripping
1 parent ef061b9 commit 8b1eaa0

File tree

4 files changed

+65
-24
lines changed

4 files changed

+65
-24
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
"Stuart Knightley (https://github.com/Stuk)",
4040
"Tom Fletcher (https://github.com/tom-fletcher)"
4141
],
42-
"dependencies": {
43-
"tsx": "^4.21.0"
44-
},
4542
"devDependencies": {
4643
"@biomejs/biome": "^2.3.11",
4744
"@release-it/conventional-changelog": "^10.0.4",

pnpm-lock.yaml

Lines changed: 36 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rcfile/error.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@ pub enum NodeJsResult {
1616

1717
#[derive(Debug, Error)]
1818
pub enum RcfileError {
19-
#[error("Failed to read config file: {0}")]
19+
#[error("Failed to read config file:\n\n{0}")]
2020
FileReadFailed(#[from] std::io::Error),
21-
#[error("Failed to run node to retrieve JS/TS config file: {0}")]
21+
#[error("Failed to run node to retrieve JS/TS config file:\n\n{0}")]
2222
NodeJsExecutionFailed(#[source] std::io::Error),
23-
#[error("Executing a JavaScript config file failed with stderr: {stderr}")]
23+
#[error("Node.js v22.6.0 or higher is needed for a TypeScript config file, try a JavaScript or JSON config file:\n\n{stderr}")]
24+
NodeJsCannotStripTypes { stderr: String },
25+
#[error("Executing a JavaScript config file failed with stderr:\n\n{stderr}")]
2426
ProcessFailed { stderr: String },
25-
#[error("Config file contains invalid UTF-8: {0}")]
27+
#[error("Config file contains invalid UTF-8:\n\n{0}")]
2628
InvalidUtf8(#[from] std::string::FromUtf8Error),
27-
#[error("Config file failed validation: {0}")]
29+
#[error("Config file failed validation:\n\n{0}")]
2830
InvalidConfig(#[from] serde_json::Error),
29-
#[error("Failed to import or require config file: {import_error} {require_error}")]
31+
#[error("Node.js threw when trying to import() your config file:\n\n{import_error}\n\n{require_error}")]
3032
JavaScriptImportFailed { import_error: String, require_error: String },
31-
#[error("Failed to parse JSON in config file: {0}")]
33+
#[error("Failed to parse JSON in config file:\n\n{0}")]
3234
JsonParseFailed(#[source] serde_json::Error),
33-
#[error("Failed to parse YAML in config file: {0}")]
35+
#[error("Failed to parse YAML in config file:\n\n{0}")]
3436
YamlParseFailed(#[from] serde_yaml::Error),
35-
#[error("Config defined as a property in package.json failed validation: {0}")]
37+
#[error("Config defined as a property in package.json failed validation:\n\n{0}")]
3638
PackageJsonConfigInvalid(#[source] serde_json::Error),
3739
}

src/rcfile/javascript.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ pub fn from_javascript_path(file_path: &Path) -> Result<Rcfile, RcfileError> {
1414
let escaped_file_path_for_nodejs = file_path.to_string_lossy().replace('\\', "\\\\");
1515
let nodejs_script = format!(
1616
r#"
17-
import('tsx')
18-
.catch(() => null)
19-
.then(() => import('{escaped_file_path_for_nodejs}'))
17+
import('{escaped_file_path_for_nodejs}')
2018
.then(findConfig)
2119
.then((value) => {{
2220
if (isNonEmptyObject(value)) {{
@@ -71,18 +69,31 @@ pub fn from_javascript_path(file_path: &Path) -> Result<Rcfile, RcfileError> {
7169
"#
7270
);
7371

72+
let is_typescript = file_path.to_string_lossy().ends_with("ts");
73+
let mut args = vec![];
74+
75+
if is_typescript {
76+
args.push("--experimental-strip-types");
77+
}
78+
79+
args.push("--eval");
80+
args.push(&nodejs_script);
81+
7482
Command::new("node")
75-
.args(vec!["-e", &nodejs_script])
83+
.args(args)
7684
.current_dir(file_path.parent().unwrap_or_else(|| Path::new(".")))
7785
.output()
7886
.map_err(RcfileError::NodeJsExecutionFailed)
7987
.and_then(|output| {
8088
if output.status.success() {
8189
Ok(output.stdout)
8290
} else {
83-
Err(RcfileError::ProcessFailed {
84-
stderr: String::from_utf8_lossy(&output.stderr).to_string(),
85-
})
91+
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
92+
if stderr.contains("experimental-strip-types") {
93+
Err(RcfileError::NodeJsCannotStripTypes { stderr })
94+
} else {
95+
Err(RcfileError::ProcessFailed { stderr })
96+
}
8697
}
8798
})
8899
.and_then(|stdout| String::from_utf8(stdout).map_err(RcfileError::InvalidUtf8))

0 commit comments

Comments
 (0)