Skip to content

Commit 0a94062

Browse files
committed
chore: Fix graph resolver, npm modules, cache settings
1 parent 026d317 commit 0a94062

File tree

9 files changed

+54
-15
lines changed

9 files changed

+54
-15
lines changed

Cargo.lock

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

crates/event_worker/event_worker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { primordials, core } from "ext:core/mod.js";
22
const { SymbolAsyncIterator } = primordials;
33

4+
const { op_event_accept } = core.ensureFastOps()
5+
46
class SupabaseEventListener {
57
async nextEvent() {
68
try {
7-
const reqEvt = await core.opAsync('op_event_accept');
9+
const reqEvt = await op_event_accept();
810
const done = reqEvt === 'Done';
911

1012
let value = undefined;

crates/npm/cache_dir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl NpmCacheDir {
3434

3535
// this may fail on readonly file systems, so just ignore if so
3636
let root_dir = try_get_canonicalized_root_dir(&root_dir).unwrap_or(root_dir);
37+
println!("Cache Dir {}", root_dir.clone().to_str().unwrap());
3738
let root_dir_url = Url::from_directory_path(&root_dir).unwrap();
3839
Self {
3940
root_dir,

crates/npm/managed/registry.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use deno_core::url::Url;
2121
use deno_npm::registry::NpmPackageInfo;
2222
use deno_npm::registry::NpmRegistryApi;
2323
use deno_npm::registry::NpmRegistryPackageInfoLoadError;
24+
use once_cell::sync::Lazy;
2425

2526
use sb_core::cache::CacheSetting;
2627
use sb_core::cache::CACHE_PERM;
@@ -30,10 +31,32 @@ use sb_core::util::sync::AtomicFlag;
3031

3132
use super::cache::NpmCache;
3233

34+
static NPM_REGISTRY_DEFAULT_URL: Lazy<Url> = Lazy::new(|| {
35+
let env_var_name = "NPM_CONFIG_REGISTRY";
36+
if let Ok(registry_url) = std::env::var(env_var_name) {
37+
// ensure there is a trailing slash for the directory
38+
let registry_url = format!("{}/", registry_url.trim_end_matches('/'));
39+
match Url::parse(&registry_url) {
40+
Ok(url) => {
41+
return url;
42+
}
43+
Err(err) => {
44+
println!("Invalid {} environment variable: {:#}", env_var_name, err,);
45+
}
46+
}
47+
}
48+
49+
Url::parse("https://registry.npmjs.org").unwrap()
50+
});
51+
3352
#[derive(Debug)]
3453
pub struct CliNpmRegistryApi(Option<Arc<CliNpmRegistryApiInner>>);
3554

3655
impl CliNpmRegistryApi {
56+
pub fn default_url() -> &'static Url {
57+
&NPM_REGISTRY_DEFAULT_URL
58+
}
59+
3760
pub fn new(base_url: Url, cache: Arc<NpmCache>, http_client: Arc<HttpClient>) -> Self {
3861
Self(Some(Arc::new(CliNpmRegistryApiInner {
3962
base_url,

crates/sb_core/js/bootstrap.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,16 @@ function runtimeStart(runtimeOptions, source) {
216216
// This is because v8 sets a console that can't be easily overriden
217217
// and collides with globalScope.console
218218
delete globalThis.console;
219-
// ObjectDefineProperties(globalThis, globalScope);
219+
ObjectDefineProperties(globalThis, globalScope);
220220

221221
const globalProperties = {
222-
// Window: globalInterfaces.windowConstructorDescriptor,
223-
// window: getterOnly(() => globalThis),
224-
// Navigator: nonEnumerable(Navigator),
225-
// navigator: getterOnly(() => navigator),
226-
// self: getterOnly(() => globalThis),
222+
Window: globalInterfaces.windowConstructorDescriptor,
223+
window: getterOnly(() => globalThis),
224+
Navigator: nonEnumerable(Navigator),
225+
navigator: getterOnly(() => navigator),
226+
self: getterOnly(() => globalThis),
227227
};
228-
// ObjectDefineProperties(globalThis, globalProperties);
228+
ObjectDefineProperties(globalThis, globalProperties);
229229

230230
const deleteDenoApis = (apis) => {
231231
apis.forEach((key) => {

crates/sb_graph/emitter.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,15 @@ impl EmitterFactory {
265265
maybe_lockfile: self.get_lock_file(),
266266
fs: self.real_fs(),
267267
http_client: self.http_client(),
268-
npm_global_cache_dir: Default::default(),
269-
cache_setting: CacheSetting::Only,
268+
npm_global_cache_dir: self.deno_dir.npm_folder_path().clone(),
269+
cache_setting: CacheSetting::Use,
270270
maybe_node_modules_path: None,
271271
npm_system_info: Default::default(),
272272
package_json_installer:
273273
CliNpmResolverManagedPackageJsonInstallerOption::ConditionalInstall(
274274
self.package_json_deps_provider().clone(),
275275
),
276-
npm_registry_url: ModuleSpecifier::parse("https://localhost/").unwrap(),
276+
npm_registry_url: CliNpmRegistryApi::default_url().clone(),
277277
})
278278
.await
279279
})
@@ -318,6 +318,7 @@ impl EmitterFactory {
318318
self.package_json_deps_provider().clone(),
319319
self.package_json_deps_installer().await.clone(),
320320
self.cli_graph_resolver_options(),
321+
Some(self.npm_resolver().await.clone()),
321322
)))
322323
})
323324
.await

crates/sb_graph/graph_resolver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl CliGraphResolver {
146146
package_json_deps_provider: Arc<PackageJsonDepsProvider>,
147147
package_json_deps_installer: Arc<PackageJsonDepsInstaller>,
148148
options: CliGraphResolverOptions,
149+
npm_resolver: Option<Arc<dyn CliNpmResolver>>,
149150
) -> Self {
150151
Self {
151152
mapped_specifier_resolver: MappedSpecifierResolver {
@@ -167,7 +168,7 @@ impl CliGraphResolver {
167168
npm_resolution,
168169
package_json_deps_installer,
169170
found_package_json_dep_flag: Default::default(),
170-
npm_resolver: None,
171+
npm_resolver,
171172
}
172173
}
173174

crates/sb_module_loader/standalone/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub async fn create_module_loader_for_eszip(
128128
fs: fs.clone(),
129129
http_client,
130130
npm_global_cache_dir,
131-
cache_setting: CacheSetting::Only,
131+
cache_setting: CacheSetting::Use,
132132
maybe_node_modules_path: None,
133133
npm_system_info: Default::default(),
134134
package_json_installer: CliNpmResolverManagedPackageJsonInstallerOption::ConditionalInstall(

crates/sb_workers/user_workers.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { readableStreamForRid, writableStreamForRid } from 'ext:deno_web/06_stre
77
import { getWatcherRid } from 'ext:sb_core_main_js/js/http.js';
88
const ops = core.ops;
99

10+
const {
11+
op_user_worker_fetch_send,
12+
op_user_worker_create
13+
} = core.ensureFastOps();
14+
1015
// interface WorkerOptions {
1116
// servicePath: string;
1217
// memoryLimitMb?: number;
@@ -70,7 +75,7 @@ Invoke \`EdgeRuntime.applyConnectionWatcher(origReq, newReq)\` if you have clone
7075
reqBodyPromise = body.pipeTo(writableStream, { signal });
7176
}
7277

73-
const resPromise = core.opAsync('op_user_worker_fetch_send', this.key, requestRid, watcherRid);
78+
const resPromise = op_user_worker_fetch_send(this.key, requestRid, watcherRid);
7479
let [sent, res] = await Promise.allSettled([reqBodyPromise, resPromise]);
7580

7681
if (sent.status === "rejected") {
@@ -142,7 +147,7 @@ Invoke \`EdgeRuntime.applyConnectionWatcher(origReq, newReq)\` if you have clone
142147
throw new TypeError('service path must be defined');
143148
}
144149

145-
const key = await core.opAsync('op_user_worker_create', readyOptions);
150+
const key = await op_user_worker_create(readyOptions);
146151

147152
return new UserWorker(key);
148153
}

0 commit comments

Comments
 (0)