mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
* refactor: use patchwright * refactor: migrate setRequestInterception and waitUntil * fix: overwrite ua * refactor: drop puppeteer cookie/requestfinished shims Migrate page.cookies/setCookie and browser.cookies/setCookie call sites to the native context APIs (page.context().cookies/addCookies), rewrite requestfinished handlers to await request.response() instead of consuming the synchronous puppeteer-shaped payload, and remove the now-redundant browser.close context-cleanup wrapper. Playwright already handles all of these natively; the shims existed only for the puppeteer -> playwright migration. * refactor: remove page.authenticate, page.setUserAgent, browser.newPage(), browser.userAgent() shims update cookie utility tests * refactor: replace browser instance with context in Playwright usage across multiple routes - Updated all instances of `browser` to `context` in Playwright-related functions for consistency and improved resource management. - Ensured proper closure of context after operations to prevent memory leaks. - Adjusted request interception methods to utilize the new context variable. * fix: direct type import * refactor: remove Puppeteer compatibility layers and unify page handling with Playwright * fix: test case * chore: bump patchright to v1.60.0 * chore: pin patchright to 1.59.1 nft can't resolve browser.json due to https://github.com/microsoft/playwright/pull/40093 * chore: pin to node 24.15 for playwright browser install on node 24.16 stucks due to https://github.com/microsoft/playwright/issues/40724 * fix: update patchright and patchright-core to version 1.60.2 and adjust minify-docker.js for compatibility * fix: import BrowserContext from patchright
42 lines
2.3 KiB
JavaScript
42 lines
2.3 KiB
JavaScript
/* eslint-disable no-console */
|
|
import path from 'node:path';
|
|
|
|
import { nodeFileTrace } from '@vercel/nft';
|
|
import fs from 'fs-extra';
|
|
|
|
const __dirname = import.meta.dirname;
|
|
// !!! if any new dependencies are added, update the Dockerfile !!!
|
|
|
|
const projectRoot = path.resolve(process.env.PROJECT_ROOT || path.join(__dirname, '../..'));
|
|
const resultFolder = path.join(projectRoot, 'app-minimal'); // no need to resolve, ProjectRoot is always absolute
|
|
const files = ['dist/index.mjs', 'node_modules/cross-env/dist/bin/cross-env.js', 'node_modules/.bin/cross-env'].map((file) => path.join(projectRoot, file));
|
|
|
|
console.log('Start analyzing, project root:', projectRoot);
|
|
const { fileList: fileSet } = await nodeFileTrace(files, {
|
|
base: projectRoot,
|
|
});
|
|
let fileList = [...fileSet];
|
|
console.log('Total touchable files:', fileList.length);
|
|
fileList = fileList.filter((file) => file.startsWith('node_modules/')); // only need node_modules
|
|
|
|
// playwright-core uses path.join to load browsers.json in v1.60+ instead of ../.., which prevents @vercel/nft from tracing it.
|
|
// https://github.com/microsoft/playwright/blob/v1.60.0/packages/playwright-core/src/server/registry/index.ts#L1544 vs
|
|
// https://github.com/microsoft/playwright/blob/v1.59.1/packages/playwright-core/src/server/registry/index.ts#L1520
|
|
// also, nft's special case for `playwright-core` no longer works for `patchright-core` https://github.com/vercel/nft/blob/1.10.2/src/utils/special-cases.ts#L336
|
|
const patchrightCoreFile = fileList.find((file) => file.includes('/patchright-core/'));
|
|
if (patchrightCoreFile) {
|
|
const packageRoot = patchrightCoreFile.slice(0, patchrightCoreFile.indexOf('/patchright-core/') + '/patchright-core'.length);
|
|
const browsersJson = `${packageRoot}/browsers.json`;
|
|
if (!fileList.includes(browsersJson) && (await fs.pathExists(path.join(projectRoot, browsersJson)))) {
|
|
fileList.push(browsersJson);
|
|
console.log('Manually included patchright-core asset:', browsersJson);
|
|
}
|
|
}
|
|
console.log('Total files need to be copied (touchable files in node_modules/):', fileList.length);
|
|
console.log('Start copying files, destination:', resultFolder);
|
|
await Promise.all(fileList.map((e) => fs.copy(path.join(projectRoot, e), path.join(resultFolder, e)))).catch((error) => {
|
|
// fix unhandled promise rejections
|
|
console.error(error, error.stack);
|
|
process.exit(1);
|
|
});
|