@ms-cloudpack/esm-stub-utilities 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browserEnvironment.cjs +53 -0
- package/lib/browserEnvironment.cjs.map +1 -0
- package/lib/browserEnvironment.d.cts +1 -0
- package/lib/createESMStub.js +4 -6
- package/lib/createESMStub.js.map +1 -1
- package/lib/runInSandbox.d.ts +1 -0
- package/lib/runInSandbox.js +141 -0
- package/lib/runInSandbox.js.map +1 -0
- package/package.json +4 -3
- package/lib/initializeBrowserEnvironment.d.ts +0 -4
- package/lib/initializeBrowserEnvironment.js +0 -67
- package/lib/initializeBrowserEnvironment.js.map +0 -1
- package/lib/tryRequire.cjs +0 -13
- package/lib/tryRequire.cjs.map +0 -1
- package/lib/tryRequire.d.cts +0 -2
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This file uses JS because it's loaded directly into the CJS sandbox environment
|
|
3
|
+
// (see runInSandbox.ts)
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
7
|
+
/* eslint-disable etc/no-deprecated */
|
|
8
|
+
const { JSDOM } = require('jsdom');
|
|
9
|
+
const btoa = require('btoa');
|
|
10
|
+
const atob = require('atob');
|
|
11
|
+
require('jsdom-global');
|
|
12
|
+
require('regenerator-runtime');
|
|
13
|
+
const dom = new JSDOM();
|
|
14
|
+
global.window = dom.window;
|
|
15
|
+
global.window.requestAnimationFrame = dom.window.setTimeout;
|
|
16
|
+
global.window.cancelAnimationFrame = dom.window.clearTimeout;
|
|
17
|
+
global.btoa = btoa;
|
|
18
|
+
global.atob = atob;
|
|
19
|
+
global.self = dom.window;
|
|
20
|
+
global.document = dom.window.document;
|
|
21
|
+
global.navigator = dom.window.navigator;
|
|
22
|
+
// Simulate WebSocket existence. (Needed for isomorphic-ws)
|
|
23
|
+
global.WebSocket = global.window.WebSocket = /** @type {*} */ (class WebSocket {
|
|
24
|
+
});
|
|
25
|
+
// Fake MessageChannel so scheduler won't hang the process by opening a channel.
|
|
26
|
+
global.MessageChannel = global.window.MessageChannel = class MessageChannel {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.port1 = ({});
|
|
29
|
+
this.port2 = ({});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const createElement = dom.window.document.createElement.bind(dom.window.document);
|
|
33
|
+
// Mock out canvas.
|
|
34
|
+
global.document.createElement =
|
|
35
|
+
/** @type {*} */ (global.window).createElement =
|
|
36
|
+
/** @type {*} */ (global).createElement =
|
|
37
|
+
(/** @type {string} */ tagName, /** @type {ElementCreationOptions} */ options) => {
|
|
38
|
+
if (tagName === 'canvas') {
|
|
39
|
+
return /** @type {*} */ ({
|
|
40
|
+
getContext: () => ({
|
|
41
|
+
fillRect: () => {
|
|
42
|
+
/* no-op */
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
measureText: () => ({}),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return createElement.apply(dom.window.document, [tagName, options]);
|
|
49
|
+
};
|
|
50
|
+
global.window.fetch = /** @type {*} */ (async () => {
|
|
51
|
+
/* no-op */
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=browserEnvironment.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserEnvironment.cjs","sourceRoot":"","sources":["../src/browserEnvironment.cjs"],"names":[],"mappings":";AAAA,kFAAkF;AAClF,wBAAwB;;AAExB,4DAA4D;AAC5D,uDAAuD;AACvD,sCAAsC;AACtC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AACnC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,C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CAAC,CAAC,MAAM,CAAC,CAAC,aAAa;YACrC,CAAC,qBAAqB,CAAC,OAAO,EAAE,qCAAqC,CAAC,OAAO,EAAE,EAAE;gBAC/E,IAAI,OAAO,KAAK,QAAQ,EAAE;oBACxB,OAAO,gBAAgB,CAAC,CAAC;wBACvB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;4BACjB,QAAQ,EAAE,GAAG,EAAE;gCACb,WAAW;4BACb,CAAC;yBACF,CAAC;wBACF,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;qBACxB,CAAC,CAAC;iBACJ;gBAED,OAAO,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YACtE,CAAC,CAAC;AAEN,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,gBAAgB,CAAC,CACrC,KAAK,IAAI,EAAE;IACT,WAAW;AACb,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/createESMStub.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
2
1
|
import path from 'path';
|
|
3
|
-
import {
|
|
2
|
+
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
4
3
|
import { forbiddenExportNames } from './forbiddenExportNames.js';
|
|
5
|
-
import {
|
|
4
|
+
import { runInSandbox } from './runInSandbox.js';
|
|
6
5
|
/**
|
|
7
6
|
* Generates an ESM stub for CommonJS modules.
|
|
8
7
|
* @param entryPath - The full path to the CommonJS entry file.
|
|
@@ -13,9 +12,8 @@ import { tryRequire } from './tryRequire.cjs';
|
|
|
13
12
|
export async function createESMStub(entryPath, stubPath) {
|
|
14
13
|
const result = [];
|
|
15
14
|
const relativePath = './' + slash(path.relative(path.dirname(stubPath), entryPath));
|
|
16
|
-
//
|
|
17
|
-
await
|
|
18
|
-
const packageExport = tryRequire(entryPath);
|
|
15
|
+
// Run the entry point file in a sandbox to determine the exports
|
|
16
|
+
const packageExport = (await runInSandbox(entryPath));
|
|
19
17
|
if (packageExport !== undefined) {
|
|
20
18
|
const isExportObject = typeof packageExport === 'object';
|
|
21
19
|
const isExportFunction = typeof packageExport === 'function';
|
package/lib/createESMStub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createESMStub.js","sourceRoot":"","sources":["../src/createESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"createESMStub.js","sourceRoot":"","sources":["../src/createESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,SAAiB,EAAE,QAAgB;IACrE,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,MAAM,YAAY,GAAG,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAEpF,iEAAiE;IACjE,MAAM,aAAa,GAAG,CAAC,MAAM,YAAY,CAAC,SAAS,CAAC,CAA4B,CAAC;IAEjF,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,MAAM,cAAc,GAAG,OAAO,aAAa,KAAK,QAAQ,CAAC;QACzD,MAAM,gBAAgB,GAAG,OAAO,aAAa,KAAK,UAAU,CAAC;QAE7D,IAAI,gBAAgB,IAAI,CAAC,cAAc,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE;YACzE,gCAAgC;YAChC,MAAM,YAAY,G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AC;SACjD;aAAM,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;YAC5C,qBAAqB;YACrB,MAAM,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;SACjE;aAAM;YACL,iDAAiD;YACjD,MAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;SAC9C;KACF;SAAM;QACL,uCAAuC;QACvC,MAAM,CAAC,IAAI,CAAC,WAAW,YAAY,IAAI,CAAC,CAAC;KAC1C;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runInSandbox(entryPath: string): Promise<unknown>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { builtinModules } from 'module';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { NodeVM, VMError } from 'vm2';
|
|
6
|
+
import { findPackageRoot } from '@ms-cloudpack/path-utilities';
|
|
7
|
+
const filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const dirname = path.dirname(filename);
|
|
9
|
+
const browserEnvSetup = path.join(dirname, 'browserEnvironment.cjs');
|
|
10
|
+
/** Allow the sandbox to load these built-in modules */
|
|
11
|
+
// ('events' and 'stream' export classes which other things extend and can't be proxied)
|
|
12
|
+
const allowedBuiltins = ['events', 'path', 'stream', 'url', 'util'];
|
|
13
|
+
/** Built-in modules provided by vm2 */
|
|
14
|
+
const includedBuiltins = ['buffer'];
|
|
15
|
+
/** Empty mocks of all built-in modules that aren't allowed (to ensure that requires succeed) */
|
|
16
|
+
const mockBuiltins = Object.fromEntries(builtinModules.filter((m) => !allowedBuiltins.includes(m) && !includedBuiltins.includes(m)).map((m) => [m, {}]));
|
|
17
|
+
/** Mapping from sandbox root to VM */
|
|
18
|
+
const vms = {};
|
|
19
|
+
/** Mapping from directory to sandbox root */
|
|
20
|
+
const sandboxRoots = {};
|
|
21
|
+
/** Sandbox root for this file and other cloudpack-related files */
|
|
22
|
+
let cloudpackSandboxRoot = '';
|
|
23
|
+
/**
|
|
24
|
+
* Try to figure out a root directory where the sandbox should be allowed to require files from.
|
|
25
|
+
* This prefers the git root if found, falling back to package root or parent directory.
|
|
26
|
+
*
|
|
27
|
+
* (This is very likely overly permissive and might be good to restrict in the future.)
|
|
28
|
+
*/
|
|
29
|
+
function findSandboxRoot(filePath) {
|
|
30
|
+
const root = path.parse(filePath).root;
|
|
31
|
+
let dir = path.dirname(filePath);
|
|
32
|
+
if (!sandboxRoots[dir]) {
|
|
33
|
+
// try to find a git root first
|
|
34
|
+
while (dir !== root && !fs.existsSync(path.join(dir, '.git'))) {
|
|
35
|
+
dir = path.dirname(dir);
|
|
36
|
+
}
|
|
37
|
+
if (dir === root) {
|
|
38
|
+
// fallback: package root
|
|
39
|
+
dir = findPackageRoot(filePath);
|
|
40
|
+
if (!dir) {
|
|
41
|
+
// final fallback: parent directory
|
|
42
|
+
dir = path.dirname(filePath);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
sandboxRoots[dir] = dir;
|
|
46
|
+
}
|
|
47
|
+
return sandboxRoots[dir];
|
|
48
|
+
}
|
|
49
|
+
function handleError(action, err, sandboxRoot) {
|
|
50
|
+
const message = [`Error ${action}: ${err.message || err}`];
|
|
51
|
+
const stack = err.stack?.split(/\r?\n/g);
|
|
52
|
+
if (stack && err instanceof VMError && err.message.includes('Cannot find module')) {
|
|
53
|
+
message.push('', 'If this module or file exists on disk, this may be a bug with the choice of `root` ' +
|
|
54
|
+
'(allowed parent directories) settings in @ms-cloudpack/esm-stub-utilities runInSandbox.', `- Root for file being stubbed: ${sandboxRoot}`, `- Root for cloudpack files: ${cloudpackSandboxRoot}`);
|
|
55
|
+
// Find the actual line which caused the error
|
|
56
|
+
const errorLines = stack.filter((line) => line.trim().startsWith('at') && !line.includes('vm2'));
|
|
57
|
+
if (errorLines.length) {
|
|
58
|
+
message.push('', 'Code that may have required this module:', ...errorLines);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (stack && stack.length) {
|
|
62
|
+
message.push('', 'Original stack:', ...stack);
|
|
63
|
+
}
|
|
64
|
+
throw new Error(message.join('\n'));
|
|
65
|
+
}
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/require-await -- using async to catch async errors
|
|
67
|
+
export async function runInSandbox(entryPath) {
|
|
68
|
+
// Allow code in the sandbox to require files under the requested file's package root,
|
|
69
|
+
// or under its directory if it's not in a package.
|
|
70
|
+
const sandboxRoot = findSandboxRoot(entryPath);
|
|
71
|
+
if (!vms[sandboxRoot]) {
|
|
72
|
+
if (!cloudpackSandboxRoot) {
|
|
73
|
+
cloudpackSandboxRoot = findSandboxRoot(filename);
|
|
74
|
+
}
|
|
75
|
+
console.log('esm-stub-utilities: Creating sandbox for ' + sandboxRoot);
|
|
76
|
+
try {
|
|
77
|
+
vms[sandboxRoot] = new NodeVM({
|
|
78
|
+
// disable console logging instead of passing through to the host console
|
|
79
|
+
console: 'off',
|
|
80
|
+
// look for these import extensions
|
|
81
|
+
sourceExtensions: ['js', 'cjs', 'mjs'],
|
|
82
|
+
// use a commonjs module wrapper
|
|
83
|
+
wrapper: 'commonjs',
|
|
84
|
+
require: {
|
|
85
|
+
// allow local and dependency modules to be required under here
|
|
86
|
+
root: [cloudpackSandboxRoot, sandboxRoot],
|
|
87
|
+
// load, compile, and require modules in the sandbox (instead of requiring in the host)
|
|
88
|
+
context: 'sandbox',
|
|
89
|
+
// allowed built-in modules
|
|
90
|
+
builtin: allowedBuiltins,
|
|
91
|
+
// allow loading "external" modules under the given roots
|
|
92
|
+
external: true,
|
|
93
|
+
// simulate the browser at startup (can throw errors)
|
|
94
|
+
import: [browserEnvSetup],
|
|
95
|
+
// mock these modules so they can be successfully required
|
|
96
|
+
mock: {
|
|
97
|
+
...mockBuiltins,
|
|
98
|
+
// some modules reference these built-ins during their setup
|
|
99
|
+
perf_hooks: {
|
|
100
|
+
performance: { now: () => Date.now() },
|
|
101
|
+
},
|
|
102
|
+
tty: {
|
|
103
|
+
isatty: () => false,
|
|
104
|
+
},
|
|
105
|
+
vm: {
|
|
106
|
+
isContext: () => false,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
sandbox: {
|
|
111
|
+
// these are normally available in the global context (and are referenced by some modules)
|
|
112
|
+
// but for some reason are not passed through by vm2
|
|
113
|
+
TextEncoder,
|
|
114
|
+
TextDecoder,
|
|
115
|
+
},
|
|
116
|
+
env: {
|
|
117
|
+
// prevent debug from accessing process.stderr
|
|
118
|
+
DEBUG_COLORS: 0,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
handleError(`initializing sandbox for ${sandboxRoot}`, err, sandboxRoot);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const onError = (err) => {
|
|
127
|
+
handleError(`running ${entryPath} in sandbox`, err, sandboxRoot);
|
|
128
|
+
};
|
|
129
|
+
process.on('uncaughtException', onError);
|
|
130
|
+
try {
|
|
131
|
+
const cjsFile = fs.readFileSync(entryPath, 'utf8');
|
|
132
|
+
return vms[sandboxRoot].run(cjsFile, { filename: entryPath });
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
onError(err);
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
process.off('uncaughtException', onError);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=runInSandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runInSandbox.js","sourceRoot":"","sources":["../src/runInSandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,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|
"name": "@ms-cloudpack/esm-stub-utilities",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Generates ESM stubs for CommonJS entry files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ms-cloudpack/path-utilities": "^2.1.
|
|
16
|
+
"@ms-cloudpack/path-utilities": "^2.1.1",
|
|
17
17
|
"@ms-cloudpack/path-string-parsing": "^1.0.1",
|
|
18
18
|
"atob": "^2.1.2",
|
|
19
19
|
"btoa": "^1.2.1",
|
|
20
20
|
"jsdom-global": "^3.0.2",
|
|
21
21
|
"jsdom": "^21.1.0",
|
|
22
|
-
"regenerator-runtime": "^0.13.9"
|
|
22
|
+
"regenerator-runtime": "^0.13.9",
|
|
23
|
+
"vm2": "^3.9.13"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@ms-cloudpack/eslint-config-base": "*",
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
6
|
-
let hasInitialized = false;
|
|
7
|
-
/**
|
|
8
|
-
* Initializes a browser environment (e.g. by setting up the global `window` in a node environment).
|
|
9
|
-
*/
|
|
10
|
-
export async function initializeBrowserEnvironment() {
|
|
11
|
-
if (!hasInitialized) {
|
|
12
|
-
hasInitialized = true;
|
|
13
|
-
if (typeof window === 'undefined' && typeof global !== 'undefined') {
|
|
14
|
-
const { JSDOM } = await import('jsdom');
|
|
15
|
-
const btoa = await import('btoa');
|
|
16
|
-
const atob = await import('atob');
|
|
17
|
-
await import('jsdom-global');
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
await import('regenerator-runtime');
|
|
21
|
-
const dom = new JSDOM();
|
|
22
|
-
const globalThis = global;
|
|
23
|
-
globalThis.window = dom.window;
|
|
24
|
-
globalThis.window.requestAnimationFrame = dom.window.setTimeout;
|
|
25
|
-
globalThis.window.cancelAnimationFrame = dom.window.clearTimeout;
|
|
26
|
-
globalThis.btoa = btoa;
|
|
27
|
-
globalThis.atob = atob;
|
|
28
|
-
globalThis.self = dom.window;
|
|
29
|
-
globalThis.document = dom.window.document;
|
|
30
|
-
globalThis.navigator = dom.window.navigator;
|
|
31
|
-
// Simulate WebSocket existence. (Needed for isomorphic-ws)
|
|
32
|
-
globalThis.WebSocket = globalThis.window.WebSocket = function () {
|
|
33
|
-
/* noop */
|
|
34
|
-
};
|
|
35
|
-
// Fake MessageChannel so scheduler won't hang the process by opening a channel.
|
|
36
|
-
globalThis.MessageChannel = globalThis.window.MessageChannel = class MessageChannel {
|
|
37
|
-
constructor() {
|
|
38
|
-
this.port1 = {};
|
|
39
|
-
this.port2 = {};
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
// eslint-disable-next-line etc/no-deprecated
|
|
43
|
-
const createElement = dom.window.document.createElement.bind(dom.window.document);
|
|
44
|
-
// Mock out canvas.
|
|
45
|
-
globalThis.document.createElement =
|
|
46
|
-
globalThis.window.createElement =
|
|
47
|
-
globalThis.createElement =
|
|
48
|
-
(tagName, ...args) => {
|
|
49
|
-
if (tagName === 'canvas') {
|
|
50
|
-
return {
|
|
51
|
-
getContext: () => ({
|
|
52
|
-
fillRect: () => {
|
|
53
|
-
/* no-op */
|
|
54
|
-
},
|
|
55
|
-
}),
|
|
56
|
-
measureText: () => ({}),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return createElement.apply(dom.window.document, [tagName, ...args]);
|
|
60
|
-
};
|
|
61
|
-
globalThis.window.fetch = async () => {
|
|
62
|
-
/* no-op */
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=initializeBrowserEnvironment.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initializeBrowserEnvironment.js","sourceRoot":"","sources":["../src/initializeBrowserEnvironment.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,4DAA4D;AAC5D,sDAAsD;AACtD,+DAA+D;AAC/D,wDAAwD;AACxD,IAAI,cAAc,GAAG,KAAK,CAAC;AAE3B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B;IAChD,IAAI,CAAC,cAAc,EAAE;QACnB,cAAc,GAAG,IAAI,CAAC;QACtB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YAClE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;YAClC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;YAElC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;YAE7B,6DAA6D;YAC7D,aAAa;YACb,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;YAEpC,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,MAAM,UAAU,GAAG,MAAa,CAAC;YAEjC,UAAU,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;YAC/B,UAAU,CAAC,MAAM,CAAC,qBAAqB,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC;YAChE,UAAU,CAAC,MAAM,CAAC,oBAAoB,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC;YACjE,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC;YACvB,UA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C,MAAM,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE;gBACnC,WAAW;YACb,CAAC,CAAC;SACH;KACF;AACH,CAAC"}
|
package/lib/tryRequire.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Requires a CommonJS entry file. We need to call require to ensure the cjs module is
|
|
5
|
-
* parsed and we aren't redirected to an esm via exports maps.
|
|
6
|
-
*/
|
|
7
|
-
module.exports = {
|
|
8
|
-
/** @param {string} modulePath */
|
|
9
|
-
tryRequire(modulePath) {
|
|
10
|
-
return /** @type {unknown} */ (require(modulePath));
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=tryRequire.cjs.map
|
package/lib/tryRequire.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tryRequire.cjs","sourceRoot":"","sources":["../src/tryRequire.cjs"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,GAAG;IACf,iCAAiC;IACjC,UAAU,CAAC,UAAU;QACnB,OAAO,sBAAsB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACtD,CAAC;CACF,CAAC"}
|
package/lib/tryRequire.d.cts
DELETED