Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default = ["napi"]
#
# The embedder writes its own thin `#[napi]` forwarders — for `create_resolve`,
# `load`, `transform`, `OxcTransformer`, `set_tsconfig_path`,
# `get_tsconfig_path`, `initialize_loader`, `freeze_tsconfig`,
# `get_tsconfig_path`, `initialize_loader_js`, `freeze_tsconfig_js`,
# `set_transform_deps`, `get_transform_deps`,
# `transforms_dep`, `freeze_transform_deps`, `transform_module_runner`, and for
# watch mode `enable_watch_report` and `take_watch_dependencies` — compiling this crate against
Expand Down
6 changes: 2 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,7 @@ pub fn initialize_loader(path: Option<String>) -> Result<()> {
set_tsconfig_override(path, false, "setTsconfigPath()")
}

#[cfg(feature = "napi")]
#[napi(js_name = "initializeLoader")]
#[cfg_attr(feature = "napi", napi(js_name = "initializeLoader"))]
/// Initialize this loader from a frozen tsconfig selection. A missing or empty path
/// selects discovery without reading environment variables. The optional source
/// preserves the original diagnostic label: `setTsconfigPath()`, `TS_NODE_PROJECT`,
Expand Down Expand Up @@ -946,8 +945,7 @@ pub fn freeze_tsconfig(cwd: String) -> FrozenTsconfig {
}
}

#[cfg(feature = "napi")]
#[napi(js_name = "freezeTsconfig")]
#[cfg_attr(feature = "napi", napi(js_name = "freezeTsconfig"))]
/// Freeze this thread's effective tsconfig path and diagnostic source for an
/// asynchronous loader. An absent path means discovery. This does not parse the
/// config or emit diagnostics; it prevents later changes to the selected config.
Expand Down
25 changes: 24 additions & 1 deletion tests/loader_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use std::{

use napi::Either;
use oxc_node::{
CapturedLoaderContext, OxcTransformer, get_tsconfig_path, set_transform_deps, set_tsconfig_path,
CapturedLoaderContext, OxcTransformer, get_tsconfig_path, initialize_loader_js,
set_transform_deps, set_tsconfig_path,
};

const SOURCE: &str = r#"
Expand Down Expand Up @@ -175,3 +176,25 @@ fn nested_contexts_restore_after_errors_and_panics() {
});
assert_eq!(get_tsconfig_path(), None);
}

#[test]
fn embedders_initialize_loaders_from_a_frozen_selection() {
let fixture = Fixture::new();
thread::scope(|scope| {
scope
.spawn(|| {
assert!(
error_reason(initialize_loader_js(None, Some("unknown".into())))
.contains("Invalid tsconfig source")
);
unwrap_oxc(initialize_loader_js(
Some(fixture.config("assign")),
Some("TS_NODE_PROJECT".into()),
));
assert_eq!(get_tsconfig_path(), Some(fixture.config("assign")));
assert_eq!(setter_calls(&transform(&fixture.transformer())), 1);
})
.join()
.unwrap();
});
}
Loading