v1.0 with SW PWA enabled
This commit is contained in:
80
frontend/node_modules/@rollup/plugin-terser/README.md
generated
vendored
Normal file
80
frontend/node_modules/@rollup/plugin-terser/README.md
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
[npm]: https://img.shields.io/npm/v/@rollup/plugin-terser
|
||||
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-terser
|
||||
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-terser
|
||||
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-terser
|
||||
|
||||
[![npm][npm]][npm-url]
|
||||
[![size][size]][size-url]
|
||||
[](https://liberamanifesto.com)
|
||||
|
||||
# @rollup/plugin-terser
|
||||
|
||||
🍣 A Rollup plugin to generate a minified bundle with terser.
|
||||
|
||||
## Requirements
|
||||
|
||||
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v2.0+.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```console
|
||||
npm install @rollup/plugin-terser --save-dev
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
|
||||
|
||||
```typescript
|
||||
import terser from '@rollup/plugin-terser';
|
||||
|
||||
export default {
|
||||
input: 'src/index.js',
|
||||
output: {
|
||||
dir: 'output',
|
||||
format: 'cjs'
|
||||
},
|
||||
plugins: [terser()]
|
||||
};
|
||||
```
|
||||
|
||||
Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).
|
||||
|
||||
## Options
|
||||
|
||||
The plugin accepts a terser [Options](https://github.com/terser/terser#minify-options) object as input parameter,
|
||||
to modify the default behaviour.
|
||||
|
||||
In addition to the `terser` options, it is also possible to provide the following options:
|
||||
|
||||
### `maxWorkers`
|
||||
|
||||
Type: `Number`<br>
|
||||
Default: `undefined`
|
||||
|
||||
Instructs the plugin to use a specific amount of cpu threads.
|
||||
|
||||
```typescript
|
||||
import terser from '@rollup/plugin-terser';
|
||||
|
||||
export default {
|
||||
input: 'src/index.js',
|
||||
output: {
|
||||
dir: 'output',
|
||||
format: 'cjs'
|
||||
},
|
||||
plugins: [
|
||||
terser({
|
||||
maxWorkers: 4
|
||||
})
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
## Meta
|
||||
|
||||
[CONTRIBUTING](/.github/CONTRIBUTING.md)
|
||||
|
||||
[LICENSE (MIT)](/LICENSE)
|
||||
232
frontend/node_modules/@rollup/plugin-terser/dist/cjs/index.js
generated
vendored
Normal file
232
frontend/node_modules/@rollup/plugin-terser/dist/cjs/index.js
generated
vendored
Normal file
@ -0,0 +1,232 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var worker_threads = require('worker_threads');
|
||||
var smob = require('smob');
|
||||
var terser$1 = require('terser');
|
||||
var url = require('url');
|
||||
var async_hooks = require('async_hooks');
|
||||
var os = require('os');
|
||||
var events = require('events');
|
||||
var serializeJavascript = require('serialize-javascript');
|
||||
|
||||
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
||||
const taskInfo = Symbol('taskInfo');
|
||||
const freeWorker = Symbol('freeWorker');
|
||||
const workerPoolWorkerFlag = 'WorkerPoolWorker';
|
||||
|
||||
/**
|
||||
* Duck typing worker context.
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
function isWorkerContextSerialized(input) {
|
||||
return (smob.isObject(input) &&
|
||||
smob.hasOwnProperty(input, 'code') &&
|
||||
typeof input.code === 'string' &&
|
||||
smob.hasOwnProperty(input, 'options') &&
|
||||
typeof input.options === 'string');
|
||||
}
|
||||
function runWorker() {
|
||||
if (worker_threads.isMainThread || !worker_threads.parentPort || worker_threads.workerData !== workerPoolWorkerFlag) {
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-eval
|
||||
const eval2 = eval;
|
||||
worker_threads.parentPort.on('message', async (data) => {
|
||||
if (!isWorkerContextSerialized(data)) {
|
||||
return;
|
||||
}
|
||||
const options = eval2(`(${data.options})`);
|
||||
const result = await terser$1.minify(data.code, options);
|
||||
const output = {
|
||||
code: result.code || data.code,
|
||||
nameCache: options.nameCache
|
||||
};
|
||||
if (typeof result.map === 'string') {
|
||||
output.sourceMap = JSON.parse(result.map);
|
||||
}
|
||||
if (smob.isObject(result.map)) {
|
||||
output.sourceMap = result.map;
|
||||
}
|
||||
worker_threads.parentPort === null || worker_threads.parentPort === void 0 ? void 0 : worker_threads.parentPort.postMessage(output);
|
||||
});
|
||||
}
|
||||
|
||||
class WorkerPoolTaskInfo extends async_hooks.AsyncResource {
|
||||
constructor(callback) {
|
||||
super('WorkerPoolTaskInfo');
|
||||
this.callback = callback;
|
||||
}
|
||||
done(err, result) {
|
||||
this.runInAsyncScope(this.callback, null, err, result);
|
||||
this.emitDestroy();
|
||||
}
|
||||
}
|
||||
class WorkerPool extends events.EventEmitter {
|
||||
constructor(options) {
|
||||
super();
|
||||
this.tasks = [];
|
||||
this.workers = [];
|
||||
this.freeWorkers = [];
|
||||
this.maxInstances = options.maxWorkers || os.cpus().length;
|
||||
this.filePath = options.filePath;
|
||||
this.on(freeWorker, () => {
|
||||
if (this.tasks.length > 0) {
|
||||
const { context, cb } = this.tasks.shift();
|
||||
this.runTask(context, cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
get numWorkers() {
|
||||
return this.workers.length;
|
||||
}
|
||||
addAsync(context) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.runTask(context, (err, output) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
if (!output) {
|
||||
reject(new Error('The output is empty'));
|
||||
return;
|
||||
}
|
||||
resolve(output);
|
||||
});
|
||||
});
|
||||
}
|
||||
close() {
|
||||
for (let i = 0; i < this.workers.length; i++) {
|
||||
const worker = this.workers[i];
|
||||
worker.terminate();
|
||||
}
|
||||
}
|
||||
addNewWorker() {
|
||||
const worker = new worker_threads.Worker(this.filePath, {
|
||||
workerData: workerPoolWorkerFlag
|
||||
});
|
||||
worker.on('message', (result) => {
|
||||
var _a;
|
||||
(_a = worker[taskInfo]) === null || _a === void 0 ? void 0 : _a.done(null, result);
|
||||
worker[taskInfo] = null;
|
||||
this.freeWorkers.push(worker);
|
||||
this.emit(freeWorker);
|
||||
});
|
||||
worker.on('error', (err) => {
|
||||
if (worker[taskInfo]) {
|
||||
worker[taskInfo].done(err, null);
|
||||
}
|
||||
else {
|
||||
this.emit('error', err);
|
||||
}
|
||||
this.workers.splice(this.workers.indexOf(worker), 1);
|
||||
this.addNewWorker();
|
||||
});
|
||||
this.workers.push(worker);
|
||||
this.freeWorkers.push(worker);
|
||||
this.emit(freeWorker);
|
||||
}
|
||||
runTask(context, cb) {
|
||||
if (this.freeWorkers.length === 0) {
|
||||
this.tasks.push({ context, cb });
|
||||
if (this.numWorkers < this.maxInstances) {
|
||||
this.addNewWorker();
|
||||
}
|
||||
return;
|
||||
}
|
||||
const worker = this.freeWorkers.pop();
|
||||
if (worker) {
|
||||
worker[taskInfo] = new WorkerPoolTaskInfo(cb);
|
||||
worker.postMessage({
|
||||
code: context.code,
|
||||
options: serializeJavascript(context.options)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function terser(input = {}) {
|
||||
const { maxWorkers, ...options } = input;
|
||||
let workerPool;
|
||||
let numOfChunks = 0;
|
||||
let numOfWorkersUsed = 0;
|
||||
return {
|
||||
name: 'terser',
|
||||
async renderChunk(code, chunk, outputOptions) {
|
||||
if (!workerPool) {
|
||||
workerPool = new WorkerPool({
|
||||
filePath: url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))),
|
||||
maxWorkers
|
||||
});
|
||||
}
|
||||
numOfChunks += 1;
|
||||
const defaultOptions = {
|
||||
sourceMap: outputOptions.sourcemap === true || typeof outputOptions.sourcemap === 'string'
|
||||
};
|
||||
if (outputOptions.format === 'es') {
|
||||
defaultOptions.module = true;
|
||||
}
|
||||
if (outputOptions.format === 'cjs') {
|
||||
defaultOptions.toplevel = true;
|
||||
}
|
||||
try {
|
||||
const { code: result, nameCache, sourceMap } = await workerPool.addAsync({
|
||||
code,
|
||||
options: smob.merge({}, options || {}, defaultOptions)
|
||||
});
|
||||
if (options.nameCache && nameCache) {
|
||||
let vars = {
|
||||
props: {}
|
||||
};
|
||||
if (smob.hasOwnProperty(options.nameCache, 'vars') && smob.isObject(options.nameCache.vars)) {
|
||||
vars = smob.merge({}, options.nameCache.vars || {}, vars);
|
||||
}
|
||||
if (smob.hasOwnProperty(nameCache, 'vars') && smob.isObject(nameCache.vars)) {
|
||||
vars = smob.merge({}, nameCache.vars, vars);
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options.nameCache.vars = vars;
|
||||
let props = {};
|
||||
if (smob.hasOwnProperty(options.nameCache, 'props') && smob.isObject(options.nameCache.props)) {
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
props = options.nameCache.props;
|
||||
}
|
||||
if (smob.hasOwnProperty(nameCache, 'props') && smob.isObject(nameCache.props)) {
|
||||
props = smob.merge({}, nameCache.props, props);
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options.nameCache.props = props;
|
||||
}
|
||||
if ((!!defaultOptions.sourceMap || !!options.sourceMap) && smob.isObject(sourceMap)) {
|
||||
return {
|
||||
code: result,
|
||||
map: sourceMap
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
finally {
|
||||
numOfChunks -= 1;
|
||||
if (numOfChunks === 0) {
|
||||
numOfWorkersUsed = workerPool.numWorkers;
|
||||
workerPool.close();
|
||||
workerPool = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
get numOfWorkersUsed() {
|
||||
return numOfWorkersUsed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
runWorker();
|
||||
|
||||
exports.default = terser;
|
||||
module.exports = Object.assign(exports.default, exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
226
frontend/node_modules/@rollup/plugin-terser/dist/es/index.js
generated
vendored
Normal file
226
frontend/node_modules/@rollup/plugin-terser/dist/es/index.js
generated
vendored
Normal file
@ -0,0 +1,226 @@
|
||||
import { isMainThread, parentPort, workerData, Worker } from 'worker_threads';
|
||||
import { isObject, hasOwnProperty, merge } from 'smob';
|
||||
import { minify } from 'terser';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { AsyncResource } from 'async_hooks';
|
||||
import { cpus } from 'os';
|
||||
import { EventEmitter } from 'events';
|
||||
import serializeJavascript from 'serialize-javascript';
|
||||
|
||||
const taskInfo = Symbol('taskInfo');
|
||||
const freeWorker = Symbol('freeWorker');
|
||||
const workerPoolWorkerFlag = 'WorkerPoolWorker';
|
||||
|
||||
/**
|
||||
* Duck typing worker context.
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
function isWorkerContextSerialized(input) {
|
||||
return (isObject(input) &&
|
||||
hasOwnProperty(input, 'code') &&
|
||||
typeof input.code === 'string' &&
|
||||
hasOwnProperty(input, 'options') &&
|
||||
typeof input.options === 'string');
|
||||
}
|
||||
function runWorker() {
|
||||
if (isMainThread || !parentPort || workerData !== workerPoolWorkerFlag) {
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-eval
|
||||
const eval2 = eval;
|
||||
parentPort.on('message', async (data) => {
|
||||
if (!isWorkerContextSerialized(data)) {
|
||||
return;
|
||||
}
|
||||
const options = eval2(`(${data.options})`);
|
||||
const result = await minify(data.code, options);
|
||||
const output = {
|
||||
code: result.code || data.code,
|
||||
nameCache: options.nameCache
|
||||
};
|
||||
if (typeof result.map === 'string') {
|
||||
output.sourceMap = JSON.parse(result.map);
|
||||
}
|
||||
if (isObject(result.map)) {
|
||||
output.sourceMap = result.map;
|
||||
}
|
||||
parentPort === null || parentPort === void 0 ? void 0 : parentPort.postMessage(output);
|
||||
});
|
||||
}
|
||||
|
||||
class WorkerPoolTaskInfo extends AsyncResource {
|
||||
constructor(callback) {
|
||||
super('WorkerPoolTaskInfo');
|
||||
this.callback = callback;
|
||||
}
|
||||
done(err, result) {
|
||||
this.runInAsyncScope(this.callback, null, err, result);
|
||||
this.emitDestroy();
|
||||
}
|
||||
}
|
||||
class WorkerPool extends EventEmitter {
|
||||
constructor(options) {
|
||||
super();
|
||||
this.tasks = [];
|
||||
this.workers = [];
|
||||
this.freeWorkers = [];
|
||||
this.maxInstances = options.maxWorkers || cpus().length;
|
||||
this.filePath = options.filePath;
|
||||
this.on(freeWorker, () => {
|
||||
if (this.tasks.length > 0) {
|
||||
const { context, cb } = this.tasks.shift();
|
||||
this.runTask(context, cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
get numWorkers() {
|
||||
return this.workers.length;
|
||||
}
|
||||
addAsync(context) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.runTask(context, (err, output) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
if (!output) {
|
||||
reject(new Error('The output is empty'));
|
||||
return;
|
||||
}
|
||||
resolve(output);
|
||||
});
|
||||
});
|
||||
}
|
||||
close() {
|
||||
for (let i = 0; i < this.workers.length; i++) {
|
||||
const worker = this.workers[i];
|
||||
worker.terminate();
|
||||
}
|
||||
}
|
||||
addNewWorker() {
|
||||
const worker = new Worker(this.filePath, {
|
||||
workerData: workerPoolWorkerFlag
|
||||
});
|
||||
worker.on('message', (result) => {
|
||||
var _a;
|
||||
(_a = worker[taskInfo]) === null || _a === void 0 ? void 0 : _a.done(null, result);
|
||||
worker[taskInfo] = null;
|
||||
this.freeWorkers.push(worker);
|
||||
this.emit(freeWorker);
|
||||
});
|
||||
worker.on('error', (err) => {
|
||||
if (worker[taskInfo]) {
|
||||
worker[taskInfo].done(err, null);
|
||||
}
|
||||
else {
|
||||
this.emit('error', err);
|
||||
}
|
||||
this.workers.splice(this.workers.indexOf(worker), 1);
|
||||
this.addNewWorker();
|
||||
});
|
||||
this.workers.push(worker);
|
||||
this.freeWorkers.push(worker);
|
||||
this.emit(freeWorker);
|
||||
}
|
||||
runTask(context, cb) {
|
||||
if (this.freeWorkers.length === 0) {
|
||||
this.tasks.push({ context, cb });
|
||||
if (this.numWorkers < this.maxInstances) {
|
||||
this.addNewWorker();
|
||||
}
|
||||
return;
|
||||
}
|
||||
const worker = this.freeWorkers.pop();
|
||||
if (worker) {
|
||||
worker[taskInfo] = new WorkerPoolTaskInfo(cb);
|
||||
worker.postMessage({
|
||||
code: context.code,
|
||||
options: serializeJavascript(context.options)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function terser(input = {}) {
|
||||
const { maxWorkers, ...options } = input;
|
||||
let workerPool;
|
||||
let numOfChunks = 0;
|
||||
let numOfWorkersUsed = 0;
|
||||
return {
|
||||
name: 'terser',
|
||||
async renderChunk(code, chunk, outputOptions) {
|
||||
if (!workerPool) {
|
||||
workerPool = new WorkerPool({
|
||||
filePath: fileURLToPath(import.meta.url),
|
||||
maxWorkers
|
||||
});
|
||||
}
|
||||
numOfChunks += 1;
|
||||
const defaultOptions = {
|
||||
sourceMap: outputOptions.sourcemap === true || typeof outputOptions.sourcemap === 'string'
|
||||
};
|
||||
if (outputOptions.format === 'es') {
|
||||
defaultOptions.module = true;
|
||||
}
|
||||
if (outputOptions.format === 'cjs') {
|
||||
defaultOptions.toplevel = true;
|
||||
}
|
||||
try {
|
||||
const { code: result, nameCache, sourceMap } = await workerPool.addAsync({
|
||||
code,
|
||||
options: merge({}, options || {}, defaultOptions)
|
||||
});
|
||||
if (options.nameCache && nameCache) {
|
||||
let vars = {
|
||||
props: {}
|
||||
};
|
||||
if (hasOwnProperty(options.nameCache, 'vars') && isObject(options.nameCache.vars)) {
|
||||
vars = merge({}, options.nameCache.vars || {}, vars);
|
||||
}
|
||||
if (hasOwnProperty(nameCache, 'vars') && isObject(nameCache.vars)) {
|
||||
vars = merge({}, nameCache.vars, vars);
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options.nameCache.vars = vars;
|
||||
let props = {};
|
||||
if (hasOwnProperty(options.nameCache, 'props') && isObject(options.nameCache.props)) {
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
props = options.nameCache.props;
|
||||
}
|
||||
if (hasOwnProperty(nameCache, 'props') && isObject(nameCache.props)) {
|
||||
props = merge({}, nameCache.props, props);
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options.nameCache.props = props;
|
||||
}
|
||||
if ((!!defaultOptions.sourceMap || !!options.sourceMap) && isObject(sourceMap)) {
|
||||
return {
|
||||
code: result,
|
||||
map: sourceMap
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
finally {
|
||||
numOfChunks -= 1;
|
||||
if (numOfChunks === 0) {
|
||||
numOfWorkersUsed = workerPool.numWorkers;
|
||||
workerPool.close();
|
||||
workerPool = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
get numOfWorkersUsed() {
|
||||
return numOfWorkersUsed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
runWorker();
|
||||
|
||||
export { terser as default };
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
frontend/node_modules/@rollup/plugin-terser/dist/es/package.json
generated
vendored
Normal file
1
frontend/node_modules/@rollup/plugin-terser/dist/es/package.json
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"type":"module"}
|
||||
74
frontend/node_modules/@rollup/plugin-terser/package.json
generated
vendored
Normal file
74
frontend/node_modules/@rollup/plugin-terser/package.json
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
{
|
||||
"name": "@rollup/plugin-terser",
|
||||
"version": "0.4.4",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"description": "Generate minified bundle",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"url": "rollup/plugins",
|
||||
"directory": "packages/terser"
|
||||
},
|
||||
"author": "Peter Placzek <peter.placzek1996@gmail.com>",
|
||||
"homepage": "https://github.com/rollup/plugins/tree/master/packages/terser#readme",
|
||||
"bugs": "https://github.com/rollup/plugins/issues",
|
||||
"main": "dist/cjs/index.js",
|
||||
"module": "dist/es/index.js",
|
||||
"exports": {
|
||||
"types": "./types/index.d.ts",
|
||||
"import": "./dist/es/index.js",
|
||||
"default": "./dist/cjs/index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
|
||||
"ci:lint": "pnpm build && pnpm lint",
|
||||
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
|
||||
"ci:test": "pnpm test -- --verbose && pnpm test:ts",
|
||||
"prebuild": "del-cli dist",
|
||||
"prepare": "if [ ! -d 'dist' ]; then pnpm build; fi",
|
||||
"prerelease": "pnpm build",
|
||||
"pretest": "pnpm build",
|
||||
"release": "pnpm --workspace-root plugin:release --pkg $npm_package_name",
|
||||
"test": "ava",
|
||||
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"!dist/**/*.map",
|
||||
"src",
|
||||
"types",
|
||||
"README.md"
|
||||
],
|
||||
"keywords": [
|
||||
"rollup",
|
||||
"plugin",
|
||||
"terser",
|
||||
"minify",
|
||||
"npm",
|
||||
"modules"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"rollup": "^2.0.0||^3.0.0||^4.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"rollup": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"serialize-javascript": "^6.0.1",
|
||||
"smob": "^1.0.0",
|
||||
"terser": "^5.17.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/serialize-javascript": "^5.0.2",
|
||||
"rollup": "^4.0.0-24",
|
||||
"typescript": "^4.8.3"
|
||||
},
|
||||
"types": "./types/index.d.ts"
|
||||
}
|
||||
3
frontend/node_modules/@rollup/plugin-terser/src/constants.ts
generated
vendored
Normal file
3
frontend/node_modules/@rollup/plugin-terser/src/constants.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export const taskInfo = Symbol('taskInfo');
|
||||
export const freeWorker = Symbol('freeWorker');
|
||||
export const workerPoolWorkerFlag = 'WorkerPoolWorker';
|
||||
8
frontend/node_modules/@rollup/plugin-terser/src/index.ts
generated
vendored
Normal file
8
frontend/node_modules/@rollup/plugin-terser/src/index.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import { runWorker } from './worker';
|
||||
import terser from './module';
|
||||
|
||||
runWorker();
|
||||
|
||||
export * from './type';
|
||||
|
||||
export default terser;
|
||||
105
frontend/node_modules/@rollup/plugin-terser/src/module.ts
generated
vendored
Normal file
105
frontend/node_modules/@rollup/plugin-terser/src/module.ts
generated
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
import type { NormalizedOutputOptions, RenderedChunk } from 'rollup';
|
||||
import { hasOwnProperty, isObject, merge } from 'smob';
|
||||
|
||||
import type { Options } from './type';
|
||||
import { WorkerPool } from './worker-pool';
|
||||
|
||||
export default function terser(input: Options = {}) {
|
||||
const { maxWorkers, ...options } = input;
|
||||
|
||||
let workerPool: WorkerPool | null | undefined;
|
||||
let numOfChunks = 0;
|
||||
let numOfWorkersUsed = 0;
|
||||
|
||||
return {
|
||||
name: 'terser',
|
||||
|
||||
async renderChunk(code: string, chunk: RenderedChunk, outputOptions: NormalizedOutputOptions) {
|
||||
if (!workerPool) {
|
||||
workerPool = new WorkerPool({
|
||||
filePath: fileURLToPath(import.meta.url),
|
||||
maxWorkers
|
||||
});
|
||||
}
|
||||
|
||||
numOfChunks += 1;
|
||||
|
||||
const defaultOptions: Options = {
|
||||
sourceMap: outputOptions.sourcemap === true || typeof outputOptions.sourcemap === 'string'
|
||||
};
|
||||
|
||||
if (outputOptions.format === 'es') {
|
||||
defaultOptions.module = true;
|
||||
}
|
||||
|
||||
if (outputOptions.format === 'cjs') {
|
||||
defaultOptions.toplevel = true;
|
||||
}
|
||||
|
||||
try {
|
||||
const {
|
||||
code: result,
|
||||
nameCache,
|
||||
sourceMap
|
||||
} = await workerPool.addAsync({
|
||||
code,
|
||||
options: merge({}, options || {}, defaultOptions)
|
||||
});
|
||||
|
||||
if (options.nameCache && nameCache) {
|
||||
let vars: Record<string, any> = {
|
||||
props: {}
|
||||
};
|
||||
|
||||
if (hasOwnProperty(options.nameCache, 'vars') && isObject(options.nameCache.vars)) {
|
||||
vars = merge({}, options.nameCache.vars || {}, vars);
|
||||
}
|
||||
|
||||
if (hasOwnProperty(nameCache, 'vars') && isObject(nameCache.vars)) {
|
||||
vars = merge({}, nameCache.vars, vars);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options.nameCache.vars = vars;
|
||||
|
||||
let props: Record<string, any> = {};
|
||||
|
||||
if (hasOwnProperty(options.nameCache, 'props') && isObject(options.nameCache.props)) {
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
props = options.nameCache.props;
|
||||
}
|
||||
|
||||
if (hasOwnProperty(nameCache, 'props') && isObject(nameCache.props)) {
|
||||
props = merge({}, nameCache.props, props);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options.nameCache.props = props;
|
||||
}
|
||||
|
||||
if ((!!defaultOptions.sourceMap || !!options.sourceMap) && isObject(sourceMap)) {
|
||||
return {
|
||||
code: result,
|
||||
map: sourceMap
|
||||
};
|
||||
}
|
||||
return result;
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
} finally {
|
||||
numOfChunks -= 1;
|
||||
if (numOfChunks === 0) {
|
||||
numOfWorkersUsed = workerPool.numWorkers;
|
||||
workerPool.close();
|
||||
workerPool = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get numOfWorkersUsed() {
|
||||
return numOfWorkersUsed;
|
||||
}
|
||||
};
|
||||
}
|
||||
45
frontend/node_modules/@rollup/plugin-terser/src/type.ts
generated
vendored
Normal file
45
frontend/node_modules/@rollup/plugin-terser/src/type.ts
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
import type { AsyncResource } from 'async_hooks';
|
||||
import type { Worker } from 'worker_threads';
|
||||
|
||||
import type { MinifyOptions } from 'terser';
|
||||
|
||||
import type { taskInfo } from './constants';
|
||||
|
||||
export interface Options extends MinifyOptions {
|
||||
nameCache?: Record<string, any>;
|
||||
maxWorkers?: number;
|
||||
}
|
||||
|
||||
export interface WorkerContext {
|
||||
code: string;
|
||||
options: Options;
|
||||
}
|
||||
|
||||
export type WorkerCallback = (err: Error | null, output?: WorkerOutput) => void;
|
||||
|
||||
interface WorkerPoolTaskInfo extends AsyncResource {
|
||||
done(err: Error | null, result: any): void;
|
||||
}
|
||||
|
||||
export type WorkerWithTaskInfo = Worker & { [taskInfo]?: WorkerPoolTaskInfo | null };
|
||||
|
||||
export interface WorkerContextSerialized {
|
||||
code: string;
|
||||
options: string;
|
||||
}
|
||||
|
||||
export interface WorkerOutput {
|
||||
code: string;
|
||||
nameCache?: Options['nameCache'];
|
||||
sourceMap?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface WorkerPoolOptions {
|
||||
filePath: string;
|
||||
maxWorkers?: number;
|
||||
}
|
||||
|
||||
export interface WorkerPoolTask {
|
||||
context: WorkerContext;
|
||||
cb: WorkerCallback;
|
||||
}
|
||||
128
frontend/node_modules/@rollup/plugin-terser/src/worker-pool.ts
generated
vendored
Normal file
128
frontend/node_modules/@rollup/plugin-terser/src/worker-pool.ts
generated
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
import { AsyncResource } from 'async_hooks';
|
||||
import { Worker } from 'worker_threads';
|
||||
import { cpus } from 'os';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
import serializeJavascript from 'serialize-javascript';
|
||||
|
||||
import { freeWorker, taskInfo, workerPoolWorkerFlag } from './constants';
|
||||
|
||||
import type {
|
||||
WorkerCallback,
|
||||
WorkerContext,
|
||||
WorkerOutput,
|
||||
WorkerPoolOptions,
|
||||
WorkerPoolTask,
|
||||
WorkerWithTaskInfo
|
||||
} from './type';
|
||||
|
||||
class WorkerPoolTaskInfo extends AsyncResource {
|
||||
constructor(private callback: WorkerCallback) {
|
||||
super('WorkerPoolTaskInfo');
|
||||
}
|
||||
|
||||
done(err: Error | null, result: any) {
|
||||
this.runInAsyncScope(this.callback, null, err, result);
|
||||
this.emitDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
export class WorkerPool extends EventEmitter {
|
||||
protected maxInstances: number;
|
||||
|
||||
protected filePath: string;
|
||||
|
||||
protected tasks: WorkerPoolTask[] = [];
|
||||
|
||||
protected workers: WorkerWithTaskInfo[] = [];
|
||||
protected freeWorkers: WorkerWithTaskInfo[] = [];
|
||||
|
||||
constructor(options: WorkerPoolOptions) {
|
||||
super();
|
||||
|
||||
this.maxInstances = options.maxWorkers || cpus().length;
|
||||
this.filePath = options.filePath;
|
||||
|
||||
this.on(freeWorker, () => {
|
||||
if (this.tasks.length > 0) {
|
||||
const { context, cb } = this.tasks.shift()!;
|
||||
this.runTask(context, cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get numWorkers(): number {
|
||||
return this.workers.length;
|
||||
}
|
||||
|
||||
addAsync(context: WorkerContext): Promise<WorkerOutput> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.runTask(context, (err, output) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!output) {
|
||||
reject(new Error('The output is empty'));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(output);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
close() {
|
||||
for (let i = 0; i < this.workers.length; i++) {
|
||||
const worker = this.workers[i];
|
||||
worker.terminate();
|
||||
}
|
||||
}
|
||||
|
||||
private addNewWorker() {
|
||||
const worker: WorkerWithTaskInfo = new Worker(this.filePath, {
|
||||
workerData: workerPoolWorkerFlag
|
||||
});
|
||||
|
||||
worker.on('message', (result) => {
|
||||
worker[taskInfo]?.done(null, result);
|
||||
worker[taskInfo] = null;
|
||||
this.freeWorkers.push(worker);
|
||||
this.emit(freeWorker);
|
||||
});
|
||||
|
||||
worker.on('error', (err) => {
|
||||
if (worker[taskInfo]) {
|
||||
worker[taskInfo].done(err, null);
|
||||
} else {
|
||||
this.emit('error', err);
|
||||
}
|
||||
this.workers.splice(this.workers.indexOf(worker), 1);
|
||||
this.addNewWorker();
|
||||
});
|
||||
|
||||
this.workers.push(worker);
|
||||
this.freeWorkers.push(worker);
|
||||
this.emit(freeWorker);
|
||||
}
|
||||
|
||||
private runTask(context: WorkerContext, cb: WorkerCallback) {
|
||||
if (this.freeWorkers.length === 0) {
|
||||
this.tasks.push({ context, cb });
|
||||
if (this.numWorkers < this.maxInstances) {
|
||||
this.addNewWorker();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const worker = this.freeWorkers.pop();
|
||||
if (worker) {
|
||||
worker[taskInfo] = new WorkerPoolTaskInfo(cb);
|
||||
worker.postMessage({
|
||||
code: context.code,
|
||||
options: serializeJavascript(context.options)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
58
frontend/node_modules/@rollup/plugin-terser/src/worker.ts
generated
vendored
Normal file
58
frontend/node_modules/@rollup/plugin-terser/src/worker.ts
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
import { isMainThread, parentPort, workerData } from 'worker_threads';
|
||||
|
||||
import { hasOwnProperty, isObject } from 'smob';
|
||||
|
||||
import { minify } from 'terser';
|
||||
|
||||
import { workerPoolWorkerFlag } from './constants';
|
||||
|
||||
import type { WorkerContextSerialized, WorkerOutput } from './type';
|
||||
|
||||
/**
|
||||
* Duck typing worker context.
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
function isWorkerContextSerialized(input: unknown): input is WorkerContextSerialized {
|
||||
return (
|
||||
isObject(input) &&
|
||||
hasOwnProperty(input, 'code') &&
|
||||
typeof input.code === 'string' &&
|
||||
hasOwnProperty(input, 'options') &&
|
||||
typeof input.options === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
export function runWorker() {
|
||||
if (isMainThread || !parentPort || workerData !== workerPoolWorkerFlag) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-eval
|
||||
const eval2 = eval;
|
||||
|
||||
parentPort.on('message', async (data: WorkerContextSerialized) => {
|
||||
if (!isWorkerContextSerialized(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const options = eval2(`(${data.options})`);
|
||||
|
||||
const result = await minify(data.code, options);
|
||||
|
||||
const output: WorkerOutput = {
|
||||
code: result.code || data.code,
|
||||
nameCache: options.nameCache
|
||||
};
|
||||
|
||||
if (typeof result.map === 'string') {
|
||||
output.sourceMap = JSON.parse(result.map);
|
||||
}
|
||||
|
||||
if (isObject(result.map)) {
|
||||
output.sourceMap = result.map;
|
||||
}
|
||||
|
||||
parentPort?.postMessage(output);
|
||||
});
|
||||
}
|
||||
15
frontend/node_modules/@rollup/plugin-terser/types/index.d.ts
generated
vendored
Normal file
15
frontend/node_modules/@rollup/plugin-terser/types/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import type { Plugin } from 'rollup';
|
||||
import type { MinifyOptions } from 'terser';
|
||||
|
||||
export interface Options extends MinifyOptions {
|
||||
nameCache?: Record<string, any>;
|
||||
maxWorkers?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Rollup plugin to generate a minified output bundle.
|
||||
*
|
||||
* @param options - Plugin options.
|
||||
* @returns Plugin instance.
|
||||
*/
|
||||
export default function terser(options?: Options): Plugin;
|
||||
Reference in New Issue
Block a user