mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: replace rimraf with a helper in BrowserFetcher/Connector (#9890)
This commit is contained in:
parent
510b36c500
commit
1f76cdda12
4
package-lock.json
generated
4
package-lock.json
generated
@ -7750,6 +7750,7 @@
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.4.0.tgz",
|
||||
"integrity": "sha512-X36S+qpCUR0HjXlkDe4NAOhS//aHH0Z+h8Ckf2auGJk3PTnx5rLmrHkwNdbVQuCSUhOyFrlRvFEllZOYE+yZGQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"glob": "^9.2.0"
|
||||
},
|
||||
@ -9303,7 +9304,6 @@
|
||||
"extract-zip": "2.0.1",
|
||||
"https-proxy-agent": "5.0.1",
|
||||
"proxy-from-env": "1.1.0",
|
||||
"rimraf": "4.4.0",
|
||||
"tar-fs": "2.1.1",
|
||||
"unbzip2-stream": "1.4.3",
|
||||
"ws": "8.13.0"
|
||||
@ -14108,7 +14108,6 @@
|
||||
"mitt": "3.0.0",
|
||||
"parsel-js": "1.1.0",
|
||||
"proxy-from-env": "1.1.0",
|
||||
"rimraf": "4.4.0",
|
||||
"tar-fs": "2.1.1",
|
||||
"unbzip2-stream": "1.4.3",
|
||||
"ws": "8.13.0"
|
||||
@ -14410,6 +14409,7 @@
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.4.0.tgz",
|
||||
"integrity": "sha512-X36S+qpCUR0HjXlkDe4NAOhS//aHH0Z+h8Ckf2auGJk3PTnx5rLmrHkwNdbVQuCSUhOyFrlRvFEllZOYE+yZGQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"glob": "^9.2.0"
|
||||
}
|
||||
|
@ -138,7 +138,6 @@
|
||||
"extract-zip": "2.0.1",
|
||||
"https-proxy-agent": "5.0.1",
|
||||
"proxy-from-env": "1.1.0",
|
||||
"rimraf": "4.4.0",
|
||||
"tar-fs": "2.1.1",
|
||||
"unbzip2-stream": "1.4.3",
|
||||
"ws": "8.13.0"
|
||||
|
@ -30,13 +30,13 @@ import createHttpsProxyAgent, {
|
||||
HttpsProxyAgentOptions,
|
||||
} from 'https-proxy-agent';
|
||||
import {getProxyForUrl} from 'proxy-from-env';
|
||||
import rimraf from 'rimraf';
|
||||
import tar from 'tar-fs';
|
||||
import bzip from 'unbzip2-stream';
|
||||
|
||||
import {debug} from '../common/Debug.js';
|
||||
import {Product} from '../common/Product.js';
|
||||
import {assert} from '../util/assert.js';
|
||||
import {rm} from '../util/fs.js';
|
||||
|
||||
const debugFetcher = debug('puppeteer:fetcher');
|
||||
|
||||
@ -412,7 +412,7 @@ export class BrowserFetcher {
|
||||
existsSync(folderPath),
|
||||
`Failed to remove: revision ${revision} is not downloaded`
|
||||
);
|
||||
await rimraf(folderPath);
|
||||
await rm(folderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,8 +20,6 @@ import {rename, unlink} from 'fs/promises';
|
||||
import path from 'path';
|
||||
import readline from 'readline';
|
||||
|
||||
import rimraf from 'rimraf';
|
||||
|
||||
import type {Connection as BiDiConnection} from '../common/bidi/bidi.js';
|
||||
import {Connection} from '../common/Connection.js';
|
||||
import {debug} from '../common/Debug.js';
|
||||
@ -36,6 +34,7 @@ import {
|
||||
} from '../common/util.js';
|
||||
import {assert} from '../util/assert.js';
|
||||
import {isErrnoException, isErrorLike} from '../util/ErrorLike.js';
|
||||
import {rm, rmSync} from '../util/fs.js';
|
||||
|
||||
import {LaunchOptions} from './LaunchOptions.js';
|
||||
import {PipeTransport} from './PipeTransport.js';
|
||||
@ -122,7 +121,7 @@ export class BrowserRunner {
|
||||
// Cleanup as processes exit.
|
||||
if (this.#isTempUserDataDir) {
|
||||
try {
|
||||
await rimraf(this.#userDataDir);
|
||||
await rm(this.#userDataDir);
|
||||
fulfill();
|
||||
} catch (error) {
|
||||
debugError(error);
|
||||
@ -236,7 +235,7 @@ export class BrowserRunner {
|
||||
// Attempt to remove temporary profile directory to avoid littering.
|
||||
try {
|
||||
if (this.#isTempUserDataDir) {
|
||||
rimraf.sync(this.#userDataDir);
|
||||
rmSync(this.#userDataDir);
|
||||
}
|
||||
} catch (error) {}
|
||||
|
||||
|
37
packages/puppeteer-core/src/util/fs.ts
Normal file
37
packages/puppeteer-core/src/util/fs.ts
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
const rmOptions = {
|
||||
force: true,
|
||||
recursive: true,
|
||||
maxRetries: 5,
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export async function rm(path: string): Promise<void> {
|
||||
await fs.promises.rm(path, rmOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function rmSync(path: string): void {
|
||||
fs.rmSync(path, rmOptions);
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
export * from './assert.js';
|
||||
export * from './fs.js';
|
||||
export * from './DebuggableDeferredPromise.js';
|
||||
export * from './DeferredPromise.js';
|
||||
export * from './ErrorLike.js';
|
||||
|
@ -23,8 +23,9 @@ import {
|
||||
PuppeteerLaunchOptions,
|
||||
PuppeteerNode,
|
||||
} from 'puppeteer-core/internal/node/PuppeteerNode.js';
|
||||
import {rmSync} from 'puppeteer-core/internal/util/fs.js';
|
||||
|
||||
import {getTestState, rmSync} from './mocha-utils.js';
|
||||
import {getTestState} from './mocha-utils.js';
|
||||
|
||||
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||
|
||||
|
@ -23,9 +23,10 @@ import {Protocol} from 'devtools-protocol';
|
||||
import expect from 'expect';
|
||||
import {BrowserFetcher, TimeoutError} from 'puppeteer';
|
||||
import {Page} from 'puppeteer-core/internal/api/Page.js';
|
||||
import {rmSync} from 'puppeteer-core/internal/util/fs.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import {getTestState, itOnlyRegularInstall, rmSync} from './mocha-utils.js';
|
||||
import {getTestState, itOnlyRegularInstall} from './mocha-utils.js';
|
||||
import utils from './utils.js';
|
||||
|
||||
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||
|
@ -34,6 +34,7 @@ import {
|
||||
PuppeteerNode,
|
||||
} from 'puppeteer-core/internal/node/PuppeteerNode.js';
|
||||
import {isErrorLike} from 'puppeteer-core/internal/util/ErrorLike.js';
|
||||
import {rmSync} from 'puppeteer-core/internal/util/fs.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import {extendExpectWithToBeGolden} from './utils.js';
|
||||
@ -331,11 +332,3 @@ export const createTimeout = <T>(
|
||||
}, n);
|
||||
});
|
||||
};
|
||||
|
||||
export function rmSync(target: string): void {
|
||||
fs.rmSync(target, {
|
||||
force: true,
|
||||
recursive: true,
|
||||
maxRetries: 5,
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user