@d-zero/puppeteer-dealer 0.4.0 → 0.5.1
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/dist/create-child-process.d.ts +2 -24
- package/dist/create-child-process.js +7 -3
- package/dist/create-main-process.d.ts +3 -3
- package/dist/create-main-process.js +1 -1
- package/dist/deal.d.ts +5 -3
- package/dist/deal.js +11 -5
- package/dist/types.d.ts +24 -0
- package/package.json +7 -8
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Page } from 'puppeteer';
|
|
3
|
-
export type ChildProcessMethods<R> = {
|
|
4
|
-
eachPage: (params: EachPageParams, logger: Logger) => Promise<R>;
|
|
5
|
-
};
|
|
6
|
-
type EachPageParams = {
|
|
7
|
-
readonly page: Page;
|
|
8
|
-
readonly id: string;
|
|
9
|
-
readonly url: string;
|
|
10
|
-
readonly index: number;
|
|
11
|
-
};
|
|
12
|
-
export type ChildProcessCommonParams = {
|
|
13
|
-
readonly id: string;
|
|
14
|
-
readonly url: string;
|
|
15
|
-
readonly logger: Logger;
|
|
16
|
-
};
|
|
17
|
-
export type ChildProcessHandler<P, R> = (params: P) => Promise<ChildProcessMethods<R>> | ChildProcessMethods<R>;
|
|
18
|
-
export type ChildProcessCommands<P, R> = {
|
|
19
|
-
init: () => Promise<P>;
|
|
20
|
-
each: (id: string, url: string, index: number) => Promise<R>;
|
|
21
|
-
log: Logger;
|
|
22
|
-
};
|
|
1
|
+
import type { ChildProcessHandler, CommonParams } from './types.js';
|
|
23
2
|
/**
|
|
24
3
|
*
|
|
25
4
|
* @param handler
|
|
26
5
|
*/
|
|
27
|
-
export declare function createChildProcess<P, R = void>(handler: ChildProcessHandler<P, R>): void;
|
|
28
|
-
export {};
|
|
6
|
+
export declare function createChildProcess<P, R = void>(handler: ChildProcessHandler<P & CommonParams, R>): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProcTalk } from '@d-zero/proc-talk';
|
|
2
|
-
import
|
|
2
|
+
import { launch } from 'puppeteer';
|
|
3
3
|
import { log } from './debug.js';
|
|
4
4
|
const childLog = log.extend(`child:${process.pid}`);
|
|
5
5
|
/**
|
|
@@ -18,19 +18,23 @@ export function createChildProcess(handler) {
|
|
|
18
18
|
childLog('Process started: %O', config);
|
|
19
19
|
const params = await this.call('init');
|
|
20
20
|
childLog('Params: %O', params);
|
|
21
|
+
childLog('Needs auth: %s', params.needAuth);
|
|
21
22
|
const { eachPage } = await handler(params);
|
|
22
23
|
const launchOptions = {
|
|
23
|
-
headless: true,
|
|
24
|
+
headless: config.headless ?? (params.needAuth ? 'shell' : true),
|
|
24
25
|
args: [
|
|
25
26
|
//
|
|
26
27
|
`--lang=${config.locale}`,
|
|
27
28
|
'--no-zygote',
|
|
28
29
|
'--ignore-certificate-errors',
|
|
30
|
+
'--no-sandbox',
|
|
31
|
+
'--disable-web-security',
|
|
32
|
+
'--disable-features=SafeBrowsing',
|
|
29
33
|
],
|
|
30
34
|
...config,
|
|
31
35
|
};
|
|
32
36
|
childLog('Launch options: %O', launchOptions);
|
|
33
|
-
const browser = await
|
|
37
|
+
const browser = await launch(launchOptions);
|
|
34
38
|
const page = await browser?.newPage();
|
|
35
39
|
if (!page) {
|
|
36
40
|
throw new Error('Failed to create page');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Logger, PuppeteerDealerOptions } from './types.js';
|
|
1
|
+
import type { CommonParams, Logger, PuppeteerDealerOptions } from './types.js';
|
|
2
2
|
import type { LaunchOptions } from 'puppeteer';
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
@@ -6,10 +6,10 @@ import type { LaunchOptions } from 'puppeteer';
|
|
|
6
6
|
* @param params
|
|
7
7
|
* @param options
|
|
8
8
|
*/
|
|
9
|
-
export declare function createProcess<P, R = void>(subModulePath: string, params: P, options?: PuppeteerDealerOptions & LaunchOptions): ChildProcessManager<P, R>;
|
|
9
|
+
export declare function createProcess<P, R = void>(subModulePath: string, params: P, options?: PuppeteerDealerOptions & LaunchOptions): (needAuth: boolean) => ChildProcessManager<P, R>;
|
|
10
10
|
export declare class ChildProcessManager<P, R> {
|
|
11
11
|
#private;
|
|
12
|
-
constructor(subModulePath: string, params: P, options?: PuppeteerDealerOptions & LaunchOptions);
|
|
12
|
+
constructor(subModulePath: string, params: P & CommonParams, options?: PuppeteerDealerOptions & LaunchOptions);
|
|
13
13
|
close(): Promise<void>;
|
|
14
14
|
each(id: string, url: string, index: number): Promise<R>;
|
|
15
15
|
log(logger: Logger): void;
|
|
@@ -6,7 +6,7 @@ import { ProcTalk } from '@d-zero/proc-talk';
|
|
|
6
6
|
* @param options
|
|
7
7
|
*/
|
|
8
8
|
export function createProcess(subModulePath, params, options) {
|
|
9
|
-
return new ChildProcessManager(subModulePath, params, options);
|
|
9
|
+
return (needAuth) => new ChildProcessManager(subModulePath, { ...params, needAuth }, options);
|
|
10
10
|
}
|
|
11
11
|
export class ChildProcessManager {
|
|
12
12
|
#procTalk;
|
package/dist/deal.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { ChildProcessManager } from './create-main-process.js';
|
|
2
2
|
import type { URLInfo } from './types.js';
|
|
3
|
-
import type { DealHeader } from '@d-zero/dealer';
|
|
3
|
+
import type { DealHeader, DealOptions } from '@d-zero/dealer';
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
6
|
* @param list
|
|
7
7
|
* @param header
|
|
8
8
|
* @param createProcess
|
|
9
|
-
* @param
|
|
9
|
+
* @param options
|
|
10
10
|
*/
|
|
11
|
-
export declare function deal<T
|
|
11
|
+
export declare function deal<T, R = void>(list: readonly URLInfo[], header: DealHeader, createProcess: () => (needAuth: boolean) => ChildProcessManager<T, R>, options?: Omit<DealOptions, 'header'> & {
|
|
12
|
+
each?: (result: R) => void | Promise<void>;
|
|
13
|
+
}): Promise<void>;
|
package/dist/deal.js
CHANGED
|
@@ -5,26 +5,32 @@ import c from 'ansi-colors';
|
|
|
5
5
|
* @param list
|
|
6
6
|
* @param header
|
|
7
7
|
* @param createProcess
|
|
8
|
-
* @param
|
|
8
|
+
* @param options
|
|
9
9
|
*/
|
|
10
|
-
export function deal(list, header, createProcess,
|
|
10
|
+
export function deal(list, header, createProcess, options) {
|
|
11
|
+
const needAuth = list.some(({ url }) => {
|
|
12
|
+
const urlObj = new URL(url);
|
|
13
|
+
return !!(urlObj.username && urlObj.password);
|
|
14
|
+
});
|
|
11
15
|
return coreDeal(list, ({ id, url }, update, index) => {
|
|
12
16
|
const fileId = id || index.toString().padStart(3, '0');
|
|
13
17
|
const lineHeader = `%braille% ${c.bgWhite(` ${fileId} `)} ${c.gray(url.toString())}: `;
|
|
14
18
|
return async () => {
|
|
15
|
-
|
|
19
|
+
update(`${lineHeader}Using ${needAuth ? 'auth' : 'no auth'}`);
|
|
20
|
+
const processManager = createProcess()(needAuth);
|
|
16
21
|
update(`${lineHeader}Booting ChildProcess%dots%`);
|
|
17
22
|
await processManager.ready();
|
|
18
23
|
processManager.log((log) => {
|
|
19
24
|
update(`${lineHeader}${log}`);
|
|
20
25
|
});
|
|
21
26
|
const result = await processManager.each(fileId, url.toString(), index);
|
|
22
|
-
if (each) {
|
|
23
|
-
await each(result);
|
|
27
|
+
if (options?.each) {
|
|
28
|
+
await options.each(result);
|
|
24
29
|
}
|
|
25
30
|
await processManager.close();
|
|
26
31
|
};
|
|
27
32
|
}, {
|
|
33
|
+
...options,
|
|
28
34
|
header,
|
|
29
35
|
});
|
|
30
36
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -12,3 +12,27 @@ export type URLInfo = {
|
|
|
12
12
|
readonly url: string | URL;
|
|
13
13
|
};
|
|
14
14
|
export type Logger = (log: string) => void;
|
|
15
|
+
export type CommonParams = {
|
|
16
|
+
readonly needAuth: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type ChildProcessMethods<R> = {
|
|
19
|
+
eachPage: (params: EachPageParams, logger: Logger) => Promise<R>;
|
|
20
|
+
};
|
|
21
|
+
type EachPageParams = {
|
|
22
|
+
readonly page: Page;
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly url: string;
|
|
25
|
+
readonly index: number;
|
|
26
|
+
};
|
|
27
|
+
export type ChildProcessCommonParams = {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly url: string;
|
|
30
|
+
readonly logger: Logger;
|
|
31
|
+
};
|
|
32
|
+
export type ChildProcessHandler<P extends CommonParams, R> = (params: P) => Promise<ChildProcessMethods<R>> | ChildProcessMethods<R>;
|
|
33
|
+
export type ChildProcessCommands<P extends CommonParams, R> = {
|
|
34
|
+
init: () => Promise<P>;
|
|
35
|
+
each: (id: string, url: string, index: number) => Promise<R>;
|
|
36
|
+
log: Logger;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/puppeteer-dealer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Puppeteer handles each page",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"private": false,
|
|
8
7
|
"publishConfig": {
|
|
9
8
|
"access": "public"
|
|
10
9
|
},
|
|
@@ -24,17 +23,17 @@
|
|
|
24
23
|
"clean": "tsc --build --clean"
|
|
25
24
|
},
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"@d-zero/dealer": "1.3.
|
|
28
|
-
"@d-zero/proc-talk": "0.4.
|
|
29
|
-
"@d-zero/shared": "0.
|
|
26
|
+
"@d-zero/dealer": "1.3.2",
|
|
27
|
+
"@d-zero/proc-talk": "0.4.2",
|
|
28
|
+
"@d-zero/shared": "0.9.1",
|
|
30
29
|
"ansi-colors": "4.1.3",
|
|
31
30
|
"debug": "4.4.1"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
|
-
"puppeteer": "24.
|
|
33
|
+
"puppeteer": "24.10.2"
|
|
35
34
|
},
|
|
36
35
|
"peerDependencies": {
|
|
37
|
-
"puppeteer": "24.
|
|
36
|
+
"puppeteer": "24.10.2"
|
|
38
37
|
},
|
|
39
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "1218a023e62c79efeece6350d561f2e1906be7ea"
|
|
40
39
|
}
|