Skip to content

Commit f6fc2df

Browse files
committed
chore: export nodejs builtins
1 parent 3be0636 commit f6fc2df

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/builtins.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// <https://nodejs.org/api/modules.html#core-modules>
2-
// node -p "[...require('module').builtinModules].map(b => JSON.stringify(b)).join(',\n')"
3-
pub const BUILTINS: &[&str] = &[
1+
/// Node.js built-in modules
2+
///
3+
/// `node -p "[...require('module').builtinModules].map(b => JSON.stringify(b)).join(',\n')"`
4+
/// <https://nodejs.org/api/modules.html#core-modules>
5+
pub const NODEJS_BUILTINS: &[&str] = &[
46
"_http_agent",
57
"_http_client",
68
"_http_common",

src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,8 @@ use std::{
4646
sync::Arc,
4747
};
4848

49-
use crate::{
50-
builtins::BUILTINS,
51-
cache::{Cache, CachedPath},
52-
context::ResolveContext as Ctx,
53-
file_system::FileSystemOs,
54-
package_json::{ExportsField, ExportsKey, MatchObject},
55-
path::{PathUtil, SLASH_START},
56-
specifier::Specifier,
57-
tsconfig::{ProjectReference, TsConfig},
58-
};
5949
pub use crate::{
50+
builtins::NODEJS_BUILTINS,
6051
error::{JSONError, ResolveError, SpecifierError},
6152
file_system::{FileMetadata, FileSystem},
6253
options::{
@@ -66,6 +57,15 @@ pub use crate::{
6657
package_json::PackageJson,
6758
resolution::Resolution,
6859
};
60+
use crate::{
61+
cache::{Cache, CachedPath},
62+
context::ResolveContext as Ctx,
63+
file_system::FileSystemOs,
64+
package_json::{ExportsField, ExportsKey, MatchObject},
65+
path::{PathUtil, SLASH_START},
66+
specifier::Specifier,
67+
tsconfig::{ProjectReference, TsConfig},
68+
};
6969

7070
type ResolveResult = Result<Option<CachedPath>, ResolveError>;
7171

@@ -275,7 +275,7 @@ impl<Fs: FileSystem + Default> ResolverGeneric<Fs> {
275275

276276
fn require_core(&self, specifier: &str) -> Result<(), ResolveError> {
277277
if self.options.builtin_modules
278-
&& (specifier.starts_with("node:") || BUILTINS.binary_search(&specifier).is_ok())
278+
&& (specifier.starts_with("node:") || NODEJS_BUILTINS.binary_search(&specifier).is_ok())
279279
{
280280
return Err(ResolveError::Builtin(specifier.to_string()));
281281
}

0 commit comments

Comments
 (0)