@rollup/plugin-terser 0.2.0 → 0.3.0
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 +18 -4
- package/dist/es/index.js +18 -4
- package/package.json +1 -1
- package/src/module.ts +18 -4
- package/src/type.ts +1 -0
- package/src/worker.ts +8 -0
package/dist/cjs/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var process = require('process');
|
|
|
6
6
|
var worker_threads = require('worker_threads');
|
|
7
7
|
var smob = require('smob');
|
|
8
8
|
var terser$1 = require('terser');
|
|
9
|
+
var url = require('url');
|
|
9
10
|
var os = require('os');
|
|
10
11
|
var events = require('events');
|
|
11
12
|
var serializeJavascript = require('serialize-javascript');
|
|
@@ -35,6 +36,12 @@ async function runWorker() {
|
|
|
35
36
|
code: result.code || worker_threads.workerData.code,
|
|
36
37
|
nameCache: options.nameCache
|
|
37
38
|
};
|
|
39
|
+
if (typeof result.map === 'string') {
|
|
40
|
+
output.sourceMap = JSON.parse(result.map);
|
|
41
|
+
}
|
|
42
|
+
if (smob.isObject(result.map)) {
|
|
43
|
+
output.sourceMap = result.map;
|
|
44
|
+
}
|
|
38
45
|
worker_threads.parentPort.postMessage(output);
|
|
39
46
|
}
|
|
40
47
|
catch (e) {
|
|
@@ -120,10 +127,11 @@ class WorkerPool extends events.EventEmitter {
|
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
|
|
123
|
-
function terser(
|
|
130
|
+
function terser(input = {}) {
|
|
131
|
+
const { maxWorkers, ...options } = input;
|
|
124
132
|
const workerPool = new WorkerPool({
|
|
125
|
-
filePath: __filename,
|
|
126
|
-
maxWorkers
|
|
133
|
+
filePath: url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.js', document.baseURI).href))),
|
|
134
|
+
maxWorkers
|
|
127
135
|
});
|
|
128
136
|
return {
|
|
129
137
|
name: 'terser',
|
|
@@ -138,7 +146,7 @@ function terser(options = {}) {
|
|
|
138
146
|
defaultOptions.toplevel = true;
|
|
139
147
|
}
|
|
140
148
|
try {
|
|
141
|
-
const { code: result, nameCache } = await workerPool.addAsync({
|
|
149
|
+
const { code: result, nameCache, sourceMap } = await workerPool.addAsync({
|
|
142
150
|
code,
|
|
143
151
|
options: smob.merge({}, options || {}, defaultOptions)
|
|
144
152
|
});
|
|
@@ -165,6 +173,12 @@ function terser(options = {}) {
|
|
|
165
173
|
// eslint-disable-next-line no-param-reassign
|
|
166
174
|
options.nameCache.props = props;
|
|
167
175
|
}
|
|
176
|
+
if ((!!defaultOptions.sourceMap || !!options.sourceMap) && smob.isObject(sourceMap)) {
|
|
177
|
+
return {
|
|
178
|
+
code: result,
|
|
179
|
+
map: sourceMap
|
|
180
|
+
};
|
|
181
|
+
}
|
|
168
182
|
return result;
|
|
169
183
|
}
|
|
170
184
|
catch (e) {
|
package/dist/es/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import process from 'process';
|
|
|
2
2
|
import { isMainThread, parentPort, workerData, Worker } from 'worker_threads';
|
|
3
3
|
import { isObject, hasOwnProperty, merge } from 'smob';
|
|
4
4
|
import { minify } from 'terser';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
5
6
|
import { cpus } from 'os';
|
|
6
7
|
import { EventEmitter } from 'events';
|
|
7
8
|
import serializeJavascript from 'serialize-javascript';
|
|
@@ -31,6 +32,12 @@ async function runWorker() {
|
|
|
31
32
|
code: result.code || workerData.code,
|
|
32
33
|
nameCache: options.nameCache
|
|
33
34
|
};
|
|
35
|
+
if (typeof result.map === 'string') {
|
|
36
|
+
output.sourceMap = JSON.parse(result.map);
|
|
37
|
+
}
|
|
38
|
+
if (isObject(result.map)) {
|
|
39
|
+
output.sourceMap = result.map;
|
|
40
|
+
}
|
|
34
41
|
parentPort.postMessage(output);
|
|
35
42
|
}
|
|
36
43
|
catch (e) {
|
|
@@ -116,10 +123,11 @@ class WorkerPool extends EventEmitter {
|
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
|
|
119
|
-
function terser(
|
|
126
|
+
function terser(input = {}) {
|
|
127
|
+
const { maxWorkers, ...options } = input;
|
|
120
128
|
const workerPool = new WorkerPool({
|
|
121
|
-
filePath:
|
|
122
|
-
maxWorkers
|
|
129
|
+
filePath: fileURLToPath(import.meta.url),
|
|
130
|
+
maxWorkers
|
|
123
131
|
});
|
|
124
132
|
return {
|
|
125
133
|
name: 'terser',
|
|
@@ -134,7 +142,7 @@ function terser(options = {}) {
|
|
|
134
142
|
defaultOptions.toplevel = true;
|
|
135
143
|
}
|
|
136
144
|
try {
|
|
137
|
-
const { code: result, nameCache } = await workerPool.addAsync({
|
|
145
|
+
const { code: result, nameCache, sourceMap } = await workerPool.addAsync({
|
|
138
146
|
code,
|
|
139
147
|
options: merge({}, options || {}, defaultOptions)
|
|
140
148
|
});
|
|
@@ -161,6 +169,12 @@ function terser(options = {}) {
|
|
|
161
169
|
// eslint-disable-next-line no-param-reassign
|
|
162
170
|
options.nameCache.props = props;
|
|
163
171
|
}
|
|
172
|
+
if ((!!defaultOptions.sourceMap || !!options.sourceMap) && isObject(sourceMap)) {
|
|
173
|
+
return {
|
|
174
|
+
code: result,
|
|
175
|
+
map: sourceMap
|
|
176
|
+
};
|
|
177
|
+
}
|
|
164
178
|
return result;
|
|
165
179
|
}
|
|
166
180
|
catch (e) {
|
package/package.json
CHANGED
package/src/module.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
|
|
1
3
|
import type { NormalizedOutputOptions, RenderedChunk } from 'rollup';
|
|
2
4
|
import { hasOwnProperty, isObject, merge } from 'smob';
|
|
3
5
|
|
|
4
6
|
import type { Options } from './type';
|
|
5
7
|
import { WorkerPool } from './worker-pool';
|
|
6
8
|
|
|
7
|
-
export default function terser(
|
|
9
|
+
export default function terser(input: Options = {}) {
|
|
10
|
+
const { maxWorkers, ...options } = input;
|
|
11
|
+
|
|
8
12
|
const workerPool = new WorkerPool({
|
|
9
|
-
filePath:
|
|
10
|
-
maxWorkers
|
|
13
|
+
filePath: fileURLToPath(import.meta.url),
|
|
14
|
+
maxWorkers
|
|
11
15
|
});
|
|
12
16
|
|
|
13
17
|
return {
|
|
@@ -27,7 +31,11 @@ export default function terser(options: Options = {}) {
|
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
try {
|
|
30
|
-
const {
|
|
34
|
+
const {
|
|
35
|
+
code: result,
|
|
36
|
+
nameCache,
|
|
37
|
+
sourceMap
|
|
38
|
+
} = await workerPool.addAsync({
|
|
31
39
|
code,
|
|
32
40
|
options: merge({}, options || {}, defaultOptions)
|
|
33
41
|
});
|
|
@@ -63,6 +71,12 @@ export default function terser(options: Options = {}) {
|
|
|
63
71
|
options.nameCache.props = props;
|
|
64
72
|
}
|
|
65
73
|
|
|
74
|
+
if ((!!defaultOptions.sourceMap || !!options.sourceMap) && isObject(sourceMap)) {
|
|
75
|
+
return {
|
|
76
|
+
code: result,
|
|
77
|
+
map: sourceMap
|
|
78
|
+
};
|
|
79
|
+
}
|
|
66
80
|
return result;
|
|
67
81
|
} catch (e) {
|
|
68
82
|
return Promise.reject(e);
|
package/src/type.ts
CHANGED
package/src/worker.ts
CHANGED
|
@@ -40,6 +40,14 @@ export async function runWorker() {
|
|
|
40
40
|
nameCache: options.nameCache
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
if (typeof result.map === 'string') {
|
|
44
|
+
output.sourceMap = JSON.parse(result.map);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isObject(result.map)) {
|
|
48
|
+
output.sourceMap = result.map;
|
|
49
|
+
}
|
|
50
|
+
|
|
43
51
|
parentPort.postMessage(output);
|
|
44
52
|
} catch (e) {
|
|
45
53
|
process.exit(1);
|