@rollup/plugin-terser 0.4.0 → 0.4.2
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/cjs/index.js +8 -5
- package/dist/es/index.js +9 -6
- package/package.json +1 -1
- package/src/constants.ts +1 -0
- package/src/worker-pool.ts +4 -2
- package/src/worker.ts +4 -2
- package/types/index.d.ts +6 -1
package/dist/cjs/index.js
CHANGED
|
@@ -11,6 +11,10 @@ var os = require('os');
|
|
|
11
11
|
var events = require('events');
|
|
12
12
|
var serializeJavascript = require('serialize-javascript');
|
|
13
13
|
|
|
14
|
+
const taskInfo = Symbol('taskInfo');
|
|
15
|
+
const freeWorker = Symbol('freeWorker');
|
|
16
|
+
const workerPoolWorkerFlag = 'WorkerPoolWorker';
|
|
17
|
+
|
|
14
18
|
/**
|
|
15
19
|
* Duck typing worker context.
|
|
16
20
|
*
|
|
@@ -24,7 +28,7 @@ function isWorkerContextSerialized(input) {
|
|
|
24
28
|
typeof input.options === 'string');
|
|
25
29
|
}
|
|
26
30
|
function runWorker() {
|
|
27
|
-
if (worker_threads.isMainThread || !worker_threads.parentPort) {
|
|
31
|
+
if (worker_threads.isMainThread || !worker_threads.parentPort || worker_threads.workerData !== workerPoolWorkerFlag) {
|
|
28
32
|
return;
|
|
29
33
|
}
|
|
30
34
|
// eslint-disable-next-line no-eval
|
|
@@ -49,9 +53,6 @@ function runWorker() {
|
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
const taskInfo = Symbol('taskInfo');
|
|
53
|
-
const freeWorker = Symbol('freeWorker');
|
|
54
|
-
|
|
55
56
|
class WorkerPoolTaskInfo extends async_hooks.AsyncResource {
|
|
56
57
|
constructor(callback) {
|
|
57
58
|
super('WorkerPoolTaskInfo');
|
|
@@ -102,7 +103,9 @@ class WorkerPool extends events.EventEmitter {
|
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
addNewWorker() {
|
|
105
|
-
const worker = new worker_threads.Worker(this.filePath
|
|
106
|
+
const worker = new worker_threads.Worker(this.filePath, {
|
|
107
|
+
workerData: workerPoolWorkerFlag
|
|
108
|
+
});
|
|
106
109
|
worker.on('message', (result) => {
|
|
107
110
|
var _a;
|
|
108
111
|
(_a = worker[taskInfo]) === null || _a === void 0 ? void 0 : _a.done(null, result);
|
package/dist/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isMainThread, parentPort, Worker } from 'worker_threads';
|
|
1
|
+
import { isMainThread, parentPort, workerData, Worker } from 'worker_threads';
|
|
2
2
|
import { isObject, hasOwnProperty, merge } from 'smob';
|
|
3
3
|
import { minify } from 'terser';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
@@ -7,6 +7,10 @@ import { cpus } from 'os';
|
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
8
|
import serializeJavascript from 'serialize-javascript';
|
|
9
9
|
|
|
10
|
+
const taskInfo = Symbol('taskInfo');
|
|
11
|
+
const freeWorker = Symbol('freeWorker');
|
|
12
|
+
const workerPoolWorkerFlag = 'WorkerPoolWorker';
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Duck typing worker context.
|
|
12
16
|
*
|
|
@@ -20,7 +24,7 @@ function isWorkerContextSerialized(input) {
|
|
|
20
24
|
typeof input.options === 'string');
|
|
21
25
|
}
|
|
22
26
|
function runWorker() {
|
|
23
|
-
if (isMainThread || !parentPort) {
|
|
27
|
+
if (isMainThread || !parentPort || workerData !== workerPoolWorkerFlag) {
|
|
24
28
|
return;
|
|
25
29
|
}
|
|
26
30
|
// eslint-disable-next-line no-eval
|
|
@@ -45,9 +49,6 @@ function runWorker() {
|
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
const taskInfo = Symbol('taskInfo');
|
|
49
|
-
const freeWorker = Symbol('freeWorker');
|
|
50
|
-
|
|
51
52
|
class WorkerPoolTaskInfo extends AsyncResource {
|
|
52
53
|
constructor(callback) {
|
|
53
54
|
super('WorkerPoolTaskInfo');
|
|
@@ -98,7 +99,9 @@ class WorkerPool extends EventEmitter {
|
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
addNewWorker() {
|
|
101
|
-
const worker = new Worker(this.filePath
|
|
102
|
+
const worker = new Worker(this.filePath, {
|
|
103
|
+
workerData: workerPoolWorkerFlag
|
|
104
|
+
});
|
|
102
105
|
worker.on('message', (result) => {
|
|
103
106
|
var _a;
|
|
104
107
|
(_a = worker[taskInfo]) === null || _a === void 0 ? void 0 : _a.done(null, result);
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
package/src/worker-pool.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { EventEmitter } from 'events';
|
|
|
5
5
|
|
|
6
6
|
import serializeJavascript from 'serialize-javascript';
|
|
7
7
|
|
|
8
|
-
import { freeWorker, taskInfo } from './constants';
|
|
8
|
+
import { freeWorker, taskInfo, workerPoolWorkerFlag } from './constants';
|
|
9
9
|
|
|
10
10
|
import type {
|
|
11
11
|
WorkerCallback,
|
|
@@ -81,7 +81,9 @@ export class WorkerPool extends EventEmitter {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
private addNewWorker() {
|
|
84
|
-
const worker: WorkerWithTaskInfo = new Worker(this.filePath
|
|
84
|
+
const worker: WorkerWithTaskInfo = new Worker(this.filePath, {
|
|
85
|
+
workerData: workerPoolWorkerFlag
|
|
86
|
+
});
|
|
85
87
|
|
|
86
88
|
worker.on('message', (result) => {
|
|
87
89
|
worker[taskInfo]?.done(null, result);
|
package/src/worker.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { isMainThread, parentPort } from 'worker_threads';
|
|
1
|
+
import { isMainThread, parentPort, workerData } from 'worker_threads';
|
|
2
2
|
|
|
3
3
|
import { hasOwnProperty, isObject } from 'smob';
|
|
4
4
|
|
|
5
5
|
import { minify } from 'terser';
|
|
6
6
|
|
|
7
|
+
import { workerPoolWorkerFlag } from './constants';
|
|
8
|
+
|
|
7
9
|
import type { WorkerContextSerialized, WorkerOutput } from './type';
|
|
8
10
|
|
|
9
11
|
/**
|
|
@@ -22,7 +24,7 @@ function isWorkerContextSerialized(input: unknown): input is WorkerContextSerial
|
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export function runWorker() {
|
|
25
|
-
if (isMainThread || !parentPort) {
|
|
27
|
+
if (isMainThread || !parentPort || workerData !== workerPoolWorkerFlag) {
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
28
30
|
|
package/types/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Plugin } from 'rollup';
|
|
2
2
|
import type { MinifyOptions } from 'terser';
|
|
3
3
|
|
|
4
|
+
export interface Options extends MinifyOptions {
|
|
5
|
+
nameCache?: Record<string, any>;
|
|
6
|
+
maxWorkers?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* A Rollup plugin to generate a minified output bundle.
|
|
6
11
|
*
|
|
7
12
|
* @param options - Plugin options.
|
|
8
13
|
* @returns Plugin instance.
|
|
9
14
|
*/
|
|
10
|
-
export default function terser(options?:
|
|
15
|
+
export default function terser(options?: Options): Plugin;
|