mirror of
https://github.com/denoland/deno.git
synced 2025-09-29 13:44:47 +00:00
refactor(ext/node): untangle dependencies between js files (#18284)
Moving some code around in `ext/node` is it's a bit better well defined and makes it possible for others to embed it. I expect to see no difference in startup perf with this change.
This commit is contained in:
parent
d78db7c091
commit
cd53ab5427
16 changed files with 385 additions and 395 deletions
|
@ -362,8 +362,7 @@ fn create_cli_snapshot(snapshot_path: PathBuf) {
|
|||
deno_io::deno_io::init_ops(Default::default()),
|
||||
deno_fs::deno_fs::init_ops::<PermissionsContainer>(false),
|
||||
deno_flash::deno_flash::init_ops::<PermissionsContainer>(false), // No --unstable
|
||||
deno_node::deno_node_loading::init_ops::<PermissionsContainer>(None), // No --unstable.
|
||||
deno_node::deno_node::init_ops(),
|
||||
deno_node::deno_node::init_ops::<PermissionsContainer>(None),
|
||||
cli::init_ops_and_esm(), // NOTE: This needs to be init_ops_and_esm!
|
||||
];
|
||||
|
||||
|
|
|
@ -680,7 +680,9 @@ pub fn translate_cjs_to_esm(
|
|||
let mut handled_reexports: HashSet<String> = HashSet::default();
|
||||
|
||||
let mut source = vec![
|
||||
r#"const require = Deno[Deno.internal].require.Module.createRequire(import.meta.url);"#.to_string(),
|
||||
r#"import {createRequire as __internalCreateRequire} from "node:module";
|
||||
const require = __internalCreateRequire(import.meta.url);"#
|
||||
.to_string(),
|
||||
];
|
||||
|
||||
let analysis = perform_cjs_analysis(
|
||||
|
|
10
cli/tests/testdata/commonjs/init.js
vendored
10
cli/tests/testdata/commonjs/init.js
vendored
|
@ -1,10 +0,0 @@
|
|||
import { fromFileUrl } from "../../../../test_util/std/path/mod.ts";
|
||||
|
||||
const DENO_NODE_COMPAT_URL = Deno.env.get("DENO_NODE_COMPAT_URL");
|
||||
const moduleAllUrl = `${DENO_NODE_COMPAT_URL}node/module_all.ts`;
|
||||
let moduleName = import.meta.resolve(Deno.args[0]);
|
||||
moduleName = fromFileUrl(moduleName);
|
||||
|
||||
const moduleAll = await import(moduleAllUrl);
|
||||
Deno[Deno.internal].node.initialize(moduleAll.default);
|
||||
Deno[Deno.internal].require.Module._load(moduleName, null, true);
|
|
@ -507,6 +507,7 @@ impl ReplSession {
|
|||
deno_node::initialize_runtime(
|
||||
&mut self.worker.js_runtime,
|
||||
self.proc_state.options.has_node_modules_dir(),
|
||||
None,
|
||||
)?;
|
||||
self.has_initialized_node_runtime = true;
|
||||
}
|
||||
|
|
|
@ -301,10 +301,8 @@ impl CliMainWorker {
|
|||
}
|
||||
|
||||
fn initialize_main_module_for_node(&mut self) -> Result<(), AnyError> {
|
||||
deno_node::initialize_runtime(
|
||||
&mut self.worker.js_runtime,
|
||||
self.ps.options.has_node_modules_dir(),
|
||||
)?;
|
||||
let mut maybe_binary_command_name = None;
|
||||
|
||||
if let DenoSubcommand::Run(flags) = self.ps.options.sub_command() {
|
||||
if let Ok(pkg_ref) = NpmPackageReqReference::from_str(&flags.script) {
|
||||
// if the user ran a binary command, we'll need to set process.argv[0]
|
||||
|
@ -313,12 +311,16 @@ impl CliMainWorker {
|
|||
.sub_path
|
||||
.as_deref()
|
||||
.unwrap_or(pkg_ref.req.name.as_str());
|
||||
deno_node::initialize_binary_command(
|
||||
&mut self.worker.js_runtime,
|
||||
binary_name,
|
||||
)?;
|
||||
maybe_binary_command_name = Some(binary_name.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
deno_node::initialize_runtime(
|
||||
&mut self.worker.js_runtime,
|
||||
self.ps.options.has_node_modules_dir(),
|
||||
maybe_binary_command_name,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -627,6 +629,7 @@ fn create_web_worker_pre_execute_module_callback(
|
|||
deno_node::initialize_runtime(
|
||||
&mut worker.js_runtime,
|
||||
ps.options.has_node_modules_dir(),
|
||||
None,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue