mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
fix(npm): add performance.markResourceTiming sham (#19123)
This commit shams "performance.markResourceTiming" API by using a noop function. It is done to provide compatibility with "npm:undici" package. We should look into actually implementing this API properly, but I wanted to unblock support for "undici" and "astro" for now. Ref https://github.com/denoland/deno/issues/19065
This commit is contained in:
parent
ab9a17eeee
commit
78fbc3f3f6
4 changed files with 7 additions and 2 deletions
|
@ -32,6 +32,7 @@ static NODE_GLOBALS: &[&str] = &[
|
||||||
"setImmediate",
|
"setImmediate",
|
||||||
"setInterval",
|
"setInterval",
|
||||||
"setTimeout",
|
"setTimeout",
|
||||||
|
"performance",
|
||||||
];
|
];
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -528,7 +529,7 @@ mod tests {
|
||||||
"var clearTimeout = globalThis.clearTimeout;var console = globalThis.console;",
|
"var clearTimeout = globalThis.clearTimeout;var console = globalThis.console;",
|
||||||
"var global = globalThis.global;var process = globalThis.process;",
|
"var global = globalThis.global;var process = globalThis.process;",
|
||||||
"var setImmediate = globalThis.setImmediate;var setInterval = globalThis.setInterval;",
|
"var setImmediate = globalThis.setImmediate;var setInterval = globalThis.setInterval;",
|
||||||
"var setTimeout = globalThis.setTimeout;\n",
|
"var setTimeout = globalThis.setTimeout;var performance = globalThis.performance;\n",
|
||||||
"export const x = 1;"
|
"export const x = 1;"
|
||||||
),
|
),
|
||||||
NODE_GLOBAL_THIS_NAME,
|
NODE_GLOBAL_THIS_NAME,
|
||||||
|
|
|
@ -907,7 +907,7 @@ Module.prototype.require = function (id) {
|
||||||
Module.wrapper = [
|
Module.wrapper = [
|
||||||
// We provide the non-standard APIs in the CommonJS wrapper
|
// We provide the non-standard APIs in the CommonJS wrapper
|
||||||
// to avoid exposing them in global namespace.
|
// to avoid exposing them in global namespace.
|
||||||
"(function (exports, require, module, __filename, __dirname, globalThis) { const { Buffer, clearImmediate, clearInterval, clearTimeout, console, global, process, setImmediate, setInterval, setTimeout} = globalThis; var window = undefined; (function () {",
|
"(function (exports, require, module, __filename, __dirname, globalThis) { const { Buffer, clearImmediate, clearInterval, clearTimeout, console, global, process, setImmediate, setInterval, setTimeout, performance} = globalThis; var window = undefined; (function () {",
|
||||||
"\n}).call(this); })",
|
"\n}).call(this); })",
|
||||||
];
|
];
|
||||||
Module.wrap = function (script) {
|
Module.wrap = function (script) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ function initialize(
|
||||||
nodeGlobals.setImmediate = nativeModuleExports["timers"].setImmediate;
|
nodeGlobals.setImmediate = nativeModuleExports["timers"].setImmediate;
|
||||||
nodeGlobals.setInterval = nativeModuleExports["timers"].setInterval;
|
nodeGlobals.setInterval = nativeModuleExports["timers"].setInterval;
|
||||||
nodeGlobals.setTimeout = nativeModuleExports["timers"].setTimeout;
|
nodeGlobals.setTimeout = nativeModuleExports["timers"].setTimeout;
|
||||||
|
nodeGlobals.performance = nativeModuleExports["perf_hooks"].performance;
|
||||||
|
|
||||||
// add a hidden global for the esm code to use in order to reliably
|
// add a hidden global for the esm code to use in order to reliably
|
||||||
// get node's globalThis
|
// get node's globalThis
|
||||||
|
|
|
@ -22,6 +22,8 @@ const performance:
|
||||||
timerify: any;
|
timerify: any;
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
timeOrigin: any;
|
timeOrigin: any;
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
markResourceTiming: any;
|
||||||
} = {
|
} = {
|
||||||
clearMarks: (markName: string) => shimPerformance.clearMarks(markName),
|
clearMarks: (markName: string) => shimPerformance.clearMarks(markName),
|
||||||
eventLoopUtilization: () =>
|
eventLoopUtilization: () =>
|
||||||
|
@ -50,6 +52,7 @@ const performance:
|
||||||
timerify: () => notImplemented("timerify from performance"),
|
timerify: () => notImplemented("timerify from performance"),
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
timeOrigin: (shimPerformance as any).timeOrigin,
|
timeOrigin: (shimPerformance as any).timeOrigin,
|
||||||
|
markResourceTiming: () => {},
|
||||||
// @ts-ignore waiting on update in `deno`, but currently this is
|
// @ts-ignore waiting on update in `deno`, but currently this is
|
||||||
// a circular dependency
|
// a circular dependency
|
||||||
toJSON: () => shimPerformance.toJSON(),
|
toJSON: () => shimPerformance.toJSON(),
|
||||||
|
|
Loading…
Reference in a new issue