UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

38 lines (37 loc) 1.09 kB
import { AsyncLocalStorage } from "node:async_hooks"; import { _registerWatchFileImpl } from "./watchFile.mjs"; const LOADER_DEPS_KEY = "__oneLoaderDepsContext"; const LOADER_DEPS_STORE = { get current() { if (globalThis[LOADER_DEPS_KEY]) return globalThis[LOADER_DEPS_KEY]; const als = new AsyncLocalStorage(); globalThis[LOADER_DEPS_KEY] = als; return als; } }; const debugLoaderDeps = process.env.ONE_DEBUG_LOADER_DEPS; function watchFileImpl(path) { const store = LOADER_DEPS_STORE.current.getStore(); if (store) { store.deps.add(path); } } _registerWatchFileImpl(watchFileImpl); async function trackLoaderDependencies(fn) { const deps = /* @__PURE__ */new Set(); const context = LOADER_DEPS_STORE.current; const result = await context.run({ deps }, async () => { return await fn(); }); if (debugLoaderDeps && deps.size > 0) { console.info("[loader-deps] tracked dependencies:", [...deps]); } return { result, dependencies: deps }; } export { trackLoaderDependencies }; //# sourceMappingURL=trackLoaderDependencies.mjs.map