mirror of
https://github.com/microsoft/playwright.git
synced 2024-11-28 09:23:42 +03:00
chore: do not use module.exports in the injected esm files (#21412)
Follow up to #17145
This commit is contained in:
parent
5735752c65
commit
47427e87ec
@ -103,7 +103,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
|
||||
(() => {
|
||||
const module = {};
|
||||
${injectedScriptSource.source}
|
||||
return new module.exports(
|
||||
return new (module.exports.InjectedScript())(
|
||||
globalThis,
|
||||
${isUnderTest()},
|
||||
"${sdkLanguage}",
|
||||
|
@ -128,4 +128,4 @@ class ConsoleAPI {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConsoleAPI;
|
||||
export default ConsoleAPI;
|
||||
|
@ -380,7 +380,7 @@ export class InjectedScript {
|
||||
(() => {
|
||||
const module = {};
|
||||
${source}
|
||||
return module.exports;
|
||||
return module.exports.default();
|
||||
})()`);
|
||||
return new constrFunction(this, params);
|
||||
}
|
||||
@ -1504,5 +1504,3 @@ function deepEquals(a: any, b: any): boolean {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = InjectedScript;
|
||||
|
@ -487,7 +487,7 @@ interface Embedder {
|
||||
__pw_refreshOverlay(): void;
|
||||
}
|
||||
|
||||
class PollingRecorder implements RecorderDelegate {
|
||||
export class PollingRecorder implements RecorderDelegate {
|
||||
private _recorder: Recorder;
|
||||
private _embedder: Embedder;
|
||||
private _pollRecorderModeTimer: NodeJS.Timeout | undefined;
|
||||
@ -535,4 +535,4 @@ class PollingRecorder implements RecorderDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PollingRecorder;
|
||||
export default PollingRecorder;
|
||||
|
@ -70,5 +70,3 @@ export class UtilityScript {
|
||||
return safeJson(value);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UtilityScript;
|
||||
|
@ -122,7 +122,7 @@ export class ExecutionContext extends SdkObject {
|
||||
(() => {
|
||||
const module = {};
|
||||
${utilityScriptSource.source}
|
||||
return new module.exports();
|
||||
return new (module.exports.UtilityScript())();
|
||||
})();`;
|
||||
this._utilityScriptPromise = this._raceAgainstContextDestroyed(this._delegate.rawEvaluateHandle(source).then(objectId => new JSHandle(this, 'object', undefined, objectId)));
|
||||
}
|
||||
|
@ -22,6 +22,10 @@
|
||||
"@recorder/*": ["../recorder/src/*"],
|
||||
"@trace/*": ["../trace/src/*"],
|
||||
"@web/*": ["../web/src/*"],
|
||||
// Resolving type dependencies will start processing types in @playwright/test
|
||||
// which in turn will start parsing the files and hence stumble upon the core
|
||||
// imports.
|
||||
"playwright-core/lib/*": ["../playwright-core/src/*"],
|
||||
},
|
||||
"useUnknownInCatchVariables": false,
|
||||
},
|
||||
|
@ -29,23 +29,9 @@ const injectedScripts = [
|
||||
path.join(ROOT, 'packages', 'playwright-core', 'src', 'server', 'injected', 'recorder.ts'),
|
||||
];
|
||||
|
||||
const modulePrefix = `"use strict";
|
||||
let __export = (target, all) => {
|
||||
for (var name in all)
|
||||
target[name] = all[name];
|
||||
};
|
||||
let __commonJS = cb => function __require() {
|
||||
let fn;
|
||||
for (const name in cb) {
|
||||
fn = cb[name];
|
||||
break;
|
||||
}
|
||||
const exports = {};
|
||||
fn(exports);
|
||||
return exports;
|
||||
};
|
||||
let __toESM = mod => ({ ...mod, 'default': mod });
|
||||
let __toCommonJS = mod => ({ ...mod, __esModule: true });
|
||||
const modulePrefix = `
|
||||
var __export = (target, all) => {for (var name in all) target[name] = all[name];};
|
||||
var __toCommonJS = mod => ({ ...mod, __esModule: true });
|
||||
`;
|
||||
|
||||
async function replaceEsbuildHeader(content, outFileJs) {
|
||||
@ -53,10 +39,10 @@ async function replaceEsbuildHeader(content, outFileJs) {
|
||||
if (sourcesStart === -1)
|
||||
throw new Error(`Did not find start of bundled code in ${outFileJs}`);
|
||||
|
||||
const preambule = content.substring(0, sourcesStart);
|
||||
const preamble = content.substring(0, sourcesStart);
|
||||
// Replace standard esbuild definition with our own which do not depend on builtins.
|
||||
// See https://github.com/microsoft/playwright/issues/17029
|
||||
if (preambule.indexOf('__toESM') !== -1 || preambule.indexOf('__toCommonJS') !== -1) {
|
||||
if (preamble.indexOf('__toCommonJS') !== -1) {
|
||||
content = modulePrefix + content.substring(sourcesStart);
|
||||
await fs.promises.writeFile(outFileJs, content);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user