one
Version:
One is a new React Framework that makes Vite serve both native and web.
26 lines (25 loc) • 992 B
JavaScript
import { AsyncLocalStorage } from "node:async_hooks";
import { _registerWatchFileImpl } from "./watchFile";
const LOADER_DEPS_KEY = "__oneLoaderDepsContext", LOADER_DEPS_STORE = {
get current() {
if (globalThis[LOADER_DEPS_KEY]) return globalThis[LOADER_DEPS_KEY];
const als = new AsyncLocalStorage();
return globalThis[LOADER_DEPS_KEY] = als, als;
}
}, debugLoaderDeps = process.env.ONE_DEBUG_LOADER_DEPS;
function watchFileImpl(path) {
const store = LOADER_DEPS_STORE.current.getStore();
store && store.deps.add(path);
}
_registerWatchFileImpl(watchFileImpl);
async function trackLoaderDependencies(fn) {
const deps = /* @__PURE__ */ new Set(), result = await LOADER_DEPS_STORE.current.run({ deps }, async () => await fn());
return debugLoaderDeps && deps.size > 0 && console.info("[loader-deps] tracked dependencies:", [...deps]), {
result,
dependencies: deps
};
}
export {
trackLoaderDependencies
};
//# sourceMappingURL=trackLoaderDependencies.js.map