From dec8f62d0e2877869073db7b8431233bc5d18618 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Tue, 22 Aug 2023 12:54:59 -0700 Subject: [PATCH 1/2] Fix URL path for childProcess.fork when using Pleasantest from ESM --- .changeset/calm-windows-retire.md | 5 +++++ rollup.config.js | 5 ----- src/connect-to-browser.ts | 11 +++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 .changeset/calm-windows-retire.md diff --git a/.changeset/calm-windows-retire.md b/.changeset/calm-windows-retire.md new file mode 100644 index 00000000..90cfd37d --- /dev/null +++ b/.changeset/calm-windows-retire.md @@ -0,0 +1,5 @@ +--- +'pleasantest': minor +--- + +Fix fork URL for ESM use diff --git a/rollup.config.js b/rollup.config.js index 3173c88b..0222db11 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -91,11 +91,6 @@ function bundlePlugin() { return resolved; }, - resolveFileUrl({ relativePath, format }) { - return format === 'es' - ? `new URL('${relativePath}', import.meta.url).href` - : `require('path').join(__dirname,'${relativePath}')`; - }, resolveImportMeta(property, { format }) { if (property === 'url' && format === 'cjs') { // eslint-disable-next-line no-template-curly-in-string diff --git a/src/connect-to-browser.ts b/src/connect-to-browser.ts index acff571c..3be12be5 100644 --- a/src/connect-to-browser.ts +++ b/src/connect-to-browser.ts @@ -111,10 +111,13 @@ export const connectToBrowser = async ( return connectedBrowser; } - const subprocess = childProcess.fork(startDisownedBrowserPath, { - detached: true, - stdio: 'ignore', - }); + const subprocess = childProcess.fork( + fileURLToPath(startDisownedBrowserPath), + { + detached: true, + stdio: 'ignore', + }, + ); const wsEndpoint = await new Promise((resolve, reject) => { subprocess.send({ browser, headless }); subprocess.on('message', (msg: any) => { From 76a2ec49880a3ec4f766e18af0ed3014e3194a49 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Tue, 22 Aug 2023 13:01:17 -0700 Subject: [PATCH 2/2] Remove more unneeded code --- rollup.config.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 0222db11..83d46424 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -91,14 +91,6 @@ function bundlePlugin() { return resolved; }, - resolveImportMeta(property, { format }) { - if (property === 'url' && format === 'cjs') { - // eslint-disable-next-line no-template-curly-in-string - return '`file://${__filename}`'; - } - - return null; - }, async load(id) { if (!id.startsWith('\0bundle:')) return; id = id.slice(8);