Unverified Commit 81e67ce9 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Update terser-webpack-plugin to support webpack 4 (#20089)

Solves some of the cache warnings when using webpack 5
parent 5b89b1b6
...@@ -4,7 +4,8 @@ import crypto from 'crypto' ...@@ -4,7 +4,8 @@ import crypto from 'crypto'
import { readFileSync, realpathSync } from 'fs' import { readFileSync, realpathSync } from 'fs'
import chalk from 'chalk' import chalk from 'chalk'
import semver from 'next/dist/compiled/semver' import semver from 'next/dist/compiled/semver'
import TerserPlugin from 'next/dist/compiled/terser-webpack-plugin' // @ts-ignore No typings yet
import TerserPlugin from './webpack/plugins/terser-webpack-plugin/src/index.js'
import path from 'path' import path from 'path'
import webpack from 'webpack' import webpack from 'webpack'
import type { Configuration } from 'webpack' import type { Configuration } from 'webpack'
...@@ -743,9 +744,8 @@ export default async function getBaseWebpackConfig( ...@@ -743,9 +744,8 @@ export default async function getBaseWebpackConfig(
minimizer: [ minimizer: [
// Minify JavaScript // Minify JavaScript
new TerserPlugin({ new TerserPlugin({
extractComments: false, cacheDir: path.join(distDir, 'cache', 'next-minifier'),
cache: path.join(distDir, 'cache', 'next-minifier'), parallel: config.experimental.cpus,
parallel: config.experimental.cpus || true,
terserOptions, terserOptions,
}), }),
// Minify CSS // Minify CSS
......
// @ts-nocheck
import * as path from 'path'
import webpack, { ModuleFilenameHelpers } from 'webpack'
import sources from 'webpack-sources'
import pLimit from 'p-limit'
import jestWorker from 'jest-worker'
import crypto from 'crypto'
import cacache from 'next/dist/compiled/cacache'
const isWebpack5 = parseInt(webpack.version) === 5
function getEcmaVersion(environment) {
// ES 6th
if (
environment.arrowFunction ||
environment.const ||
environment.destructuring ||
environment.forOf ||
environment.module
) {
return 2015
}
// ES 11th
if (environment.bigIntLiteral || environment.dynamicImport) {
return 2020
}
return 5
}
function buildError(error, file) {
if (error.line) {
return new Error(
`${file} from Terser\n${error.message} [${file}:${error.line},${
error.col
}]${
error.stack ? `\n${error.stack.split('\n').slice(1).join('\n')}` : ''
}`
)
}
if (error.stack) {
return new Error(`${file} from Terser\n${error.message}\n${error.stack}`)
}
return new Error(`${file} from Terser\n${error.message}`)
}
class Webpack4Cache {
constructor(cacheDir, { SourceMapSource, RawSource }) {
this.cacheDir = cacheDir
this.sources = { SourceMapSource, RawSource }
}
getLazyHashedEtag(obj) {
let str
if (obj.source) {
str = obj.source()
}
const hash = crypto.createHash('md4')
hash.update(str ? str : obj)
return hash.digest('base64')
}
async getPromise(identifier, etag) {
let cachedResult
try {
cachedResult = await cacache.get(this.cacheDir, etag)
} catch (ignoreError) {
// eslint-disable-next-line no-undefined
return undefined
}
cachedResult = JSON.parse(cachedResult.data)
const { code, name, map, input, inputSourceMap } = cachedResult
let source
if (map) {
source = new this.sources.SourceMapSource(
code,
name,
map,
input,
inputSourceMap,
true
)
} else {
source = new this.sources.RawSource(code)
}
return { source }
}
async storePromise(identifier, etag, data) {
await cacache.put(this.cacheDir, etag, JSON.stringify(data))
}
}
class TerserPlugin {
constructor(options = {}) {
const { cacheDir, terserOptions = {}, parallel } = options
this.options = {
cacheDir,
parallel,
terserOptions,
}
}
async optimize(
compilation,
assets,
optimizeOptions,
cache,
{ SourceMapSource, RawSource }
) {
let numberOfAssetsForMinify = 0
const assetsList = isWebpack5
? Object.keys(assets)
: [
...Array.from(compilation.additionalChunkAssets || []),
...Array.from(assets).reduce((acc, chunk) => {
return acc.concat(Array.from(chunk.files || []))
}, []),
]
const assetsForMinify = await Promise.all(
assetsList
.filter((name) => {
if (
!ModuleFilenameHelpers.matchObject.bind(
// eslint-disable-next-line no-undefined
undefined,
{ test: /\.[cm]?js(\?.*)?$/i }
)(name)
) {
return false
}
const res = compilation.getAsset(name)
if (!res) {
console.log(name)
return false
}
const { info } = res
// Skip double minimize assets from child compilation
if (info.minimized) {
return false
}
return true
})
.map(async (name) => {
const { info, source } = compilation.getAsset(name)
const eTag = cache.getLazyHashedEtag(source)
const output = await cache.getPromise(name, eTag)
if (!output) {
numberOfAssetsForMinify += 1
}
return { name, info, inputSource: source, output, eTag }
})
)
const numberOfWorkers = Math.min(
numberOfAssetsForMinify,
optimizeOptions.availableNumberOfCores
)
let initializedWorker
// eslint-disable-next-line consistent-return
const getWorker = () => {
if (initializedWorker) {
return initializedWorker
}
initializedWorker = new jestWorker(path.join(__dirname, './minify.js'), {
numWorkers: numberOfWorkers,
enableWorkerThreads: true,
})
initializedWorker.getStdout().pipe(process.stdout)
initializedWorker.getStderr().pipe(process.stderr)
return initializedWorker
}
const limit = pLimit(
numberOfAssetsForMinify > 0 ? numberOfWorkers : Infinity
)
const scheduledTasks = []
for (const asset of assetsForMinify) {
scheduledTasks.push(
limit(async () => {
const { name, inputSource, info, eTag } = asset
let { output } = asset
if (!output) {
let input
let inputSourceMap
const {
source: sourceFromInputSource,
map,
} = inputSource.sourceAndMap()
input = sourceFromInputSource
if (Buffer.isBuffer(input)) {
input = input.toString()
}
const options = {
name,
input,
inputSourceMap: map,
terserOptions: { ...this.options.terserOptions },
}
if (typeof options.terserOptions.module === 'undefined') {
if (typeof info.javascriptModule !== 'undefined') {
options.terserOptions.module = info.javascriptModule
} else if (/\.mjs(\?.*)?$/i.test(name)) {
options.terserOptions.module = true
} else if (/\.cjs(\?.*)?$/i.test(name)) {
options.terserOptions.module = false
}
}
try {
output = await getWorker().minify(options)
} catch (error) {
compilation.errors.push(buildError(error, name))
return
}
if (output.map) {
output.source = new SourceMapSource(
output.code,
name,
output.map,
input,
/** @type {SourceMapRawSourceMap} */ (inputSourceMap),
true
)
} else {
output.source = new RawSource(output.code)
}
if (isWebpack5) {
await cache.storePromise(name, eTag, { source: output.source })
} else {
await cache.storePromise(name, eTag, {
code: output.code,
map: output.map,
name,
input,
inputSourceMap,
})
}
}
/** @type {AssetInfo} */
const newInfo = { minimized: true }
const { source } = output
compilation.updateAsset(name, source, newInfo)
})
)
}
await Promise.all(scheduledTasks)
if (initializedWorker) {
await initializedWorker.end()
}
}
/**
* @param {Compiler} compiler
* @returns {void}
*/
apply(compiler) {
const { SourceMapSource, RawSource } = compiler?.webpack?.sources || sources
const { output } = compiler.options
if (typeof this.options.terserOptions.ecma === 'undefined') {
this.options.terserOptions.ecma = getEcmaVersion(output.environment || {})
}
const pluginName = this.constructor.name
const availableNumberOfCores = this.options.parallel
compiler.hooks.compilation.tap(pluginName, (compilation) => {
const cache = isWebpack5
? compilation.getCache('TerserWebpackPlugin')
: new Webpack4Cache(this.options.cacheDir, {
SourceMapSource,
RawSource,
})
const handleHashForChunk = (hash, chunk) => {
hash.update('a')
}
if (isWebpack5) {
const JSModulesHooks = webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(
compilation
)
JSModulesHooks.chunkHash.tap(pluginName, (chunk, hash) => {
if (!chunk.hasRuntime()) return
return handleHashForChunk(hash, chunk)
})
compilation.hooks.processAssets.tapPromise(
{
name: pluginName,
stage:
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
},
(assets) =>
this.optimize(
compilation,
assets,
{
availableNumberOfCores,
},
cache,
{ SourceMapSource, RawSource }
)
)
compilation.hooks.statsPrinter.tap(pluginName, (stats) => {
stats.hooks.print
.for('asset.info.minimized')
.tap('terser-webpack-plugin', (minimized, { green, formatFlag }) =>
// eslint-disable-next-line no-undefined
minimized ? green(formatFlag('minimized')) : undefined
)
})
} else {
compilation.mainTemplate.hooks.hashForChunk.tap(
pluginName,
handleHashForChunk
)
compilation.chunkTemplate.hooks.hashForChunk.tap(
pluginName,
handleHashForChunk
)
compilation.hooks.optimizeChunkAssets.tapPromise(pluginName, (assets) =>
this.optimize(
compilation,
assets,
{
availableNumberOfCores,
},
cache,
{ SourceMapSource, RawSource }
)
)
}
})
}
}
export default TerserPlugin
// @ts-nocheck
import terser from 'next/dist/compiled/terser'
function buildTerserOptions(terserOptions = {}) {
return {
...terserOptions,
mangle:
terserOptions.mangle == null
? true
: typeof terserOptions.mangle === 'boolean'
? terserOptions.mangle
: { ...terserOptions.mangle },
// Ignoring sourceMap from options
// eslint-disable-next-line no-undefined
sourceMap: undefined,
// the `output` option is deprecated
...(terserOptions.format
? { format: { beautify: false, ...terserOptions.format } }
: { output: { beautify: false, ...terserOptions.output } }),
}
}
export async function minify(options) {
const { name, input, inputSourceMap, terserOptions } = options
// Copy terser options
const opts = buildTerserOptions(terserOptions)
// Let terser generate a SourceMap
if (inputSourceMap) {
// @ts-ignore
opts.sourceMap = { asObject: true }
}
const result = await terser.minify({ [name]: input }, opts)
return result
}
module.exports=(()=>{"use strict";var e={235:(e,t,r)=>{const n=r(404);const s=e=>{if(!((Number.isInteger(e)||e===Infinity)&&e>0)){return Promise.reject(new TypeError("Expected `concurrency` to be a number from 1 and up"))}const t=[];let r=0;const s=()=>{r--;if(t.length>0){t.shift()()}};const c=(e,t,...c)=>{r++;const o=n(e,...c);t(o);o.then(s,s)};const o=(n,s,...o)=>{if(r<e){c(n,s,...o)}else{t.push(c.bind(null,n,s,...o))}};const i=(e,...t)=>new Promise(r=>o(e,r,...t));Object.defineProperties(i,{activeCount:{get:()=>r},pendingCount:{get:()=>t.length},clearQueue:{value:()=>{t.length=0}}});return i};e.exports=s;e.exports.default=s},404:e=>{const t=(e,...t)=>new Promise(r=>{r(e(...t))});e.exports=t;e.exports.default=t},21:(e,t,r)=>{const n=r(622);const s=r(387);const c=r(164);const o=Symbol("findUp.stop");e.exports=(async(e,t={})=>{let r=n.resolve(t.cwd||"");const{root:c}=n.parse(r);const i=[].concat(e);const a=async t=>{if(typeof e!=="function"){return s(i,t)}const r=await e(t.cwd);if(typeof r==="string"){return s([r],t)}return r};while(true){const e=await a({...t,cwd:r});if(e===o){return}if(e){return n.resolve(r,e)}if(r===c){return}r=n.dirname(r)}});e.exports.sync=((e,t={})=>{let r=n.resolve(t.cwd||"");const{root:c}=n.parse(r);const i=[].concat(e);const a=t=>{if(typeof e!=="function"){return s.sync(i,t)}const r=e(t.cwd);if(typeof r==="string"){return s.sync([r],t)}return r};while(true){const e=a({...t,cwd:r});if(e===o){return}if(e){return n.resolve(r,e)}if(r===c){return}r=n.dirname(r)}});e.exports.exists=c;e.exports.sync.exists=c.sync;e.exports.stop=o},387:(e,t,r)=>{const n=r(622);const s=r(747);const{promisify:c}=r(669);const o=r(940);const i=c(s.stat);const a=c(s.lstat);const u={directory:"isDirectory",file:"isFile"};function checkType({type:e}){if(e in u){return}throw new Error(`Invalid type specified: ${e}`)}const p=(e,t)=>e===undefined||t[u[e]]();e.exports=(async(e,t)=>{t={cwd:process.cwd(),type:"file",allowSymlinks:true,...t};checkType(t);const r=t.allowSymlinks?i:a;return o(e,async e=>{try{const s=await r(n.resolve(t.cwd,e));return p(t.type,s)}catch(e){return false}},t)});e.exports.sync=((e,t)=>{t={cwd:process.cwd(),allowSymlinks:true,type:"file",...t};checkType(t);const r=t.allowSymlinks?s.statSync:s.lstatSync;for(const s of e){try{const e=r(n.resolve(t.cwd,s));if(p(t.type,e)){return s}}catch(e){}}})},940:(e,t,r)=>{const n=r(235);class EndError extends Error{constructor(e){super();this.value=e}}const s=async(e,t)=>t(await e);const c=async e=>{const t=await Promise.all(e);if(t[1]===true){throw new EndError(t[0])}return false};const o=async(e,t,r)=>{r={concurrency:Infinity,preserveOrder:true,...r};const o=n(r.concurrency);const i=[...e].map(e=>[e,o(s,e,t)]);const a=n(r.preserveOrder?1:Infinity);try{await Promise.all(i.map(e=>a(c,e)))}catch(e){if(e instanceof EndError){return e.value}throw e}};e.exports=o;e.exports.default=o},164:(e,t,r)=>{const n=r(747);const{promisify:s}=r(669);const c=s(n.access);e.exports=(async e=>{try{await c(e);return true}catch(e){return false}});e.exports.sync=(e=>{try{n.accessSync(e);return true}catch(e){return false}})},747:e=>{e.exports=require("fs")},622:e=>{e.exports=require("path")},669:e=>{e.exports=require("util")}};var t={};function __webpack_require__(r){if(t[r]){return t[r].exports}var n=t[r]={exports:{}};var s=true;try{e[r](n,n.exports,__webpack_require__);s=false}finally{if(s)delete t[r]}return n.exports}__webpack_require__.ab=__dirname+"/";return __webpack_require__(21)})(); module.exports=(()=>{"use strict";var e={404:e=>{const t=(e,...t)=>new Promise(r=>{r(e(...t))});e.exports=t;e.exports.default=t},21:(e,t,r)=>{const n=r(622);const s=r(387);const c=r(164);const o=Symbol("findUp.stop");e.exports=(async(e,t={})=>{let r=n.resolve(t.cwd||"");const{root:c}=n.parse(r);const i=[].concat(e);const a=async t=>{if(typeof e!=="function"){return s(i,t)}const r=await e(t.cwd);if(typeof r==="string"){return s([r],t)}return r};while(true){const e=await a({...t,cwd:r});if(e===o){return}if(e){return n.resolve(r,e)}if(r===c){return}r=n.dirname(r)}});e.exports.sync=((e,t={})=>{let r=n.resolve(t.cwd||"");const{root:c}=n.parse(r);const i=[].concat(e);const a=t=>{if(typeof e!=="function"){return s.sync(i,t)}const r=e(t.cwd);if(typeof r==="string"){return s.sync([r],t)}return r};while(true){const e=a({...t,cwd:r});if(e===o){return}if(e){return n.resolve(r,e)}if(r===c){return}r=n.dirname(r)}});e.exports.exists=c;e.exports.sync.exists=c.sync;e.exports.stop=o},387:(e,t,r)=>{const n=r(622);const s=r(747);const{promisify:c}=r(669);const o=r(940);const i=c(s.stat);const a=c(s.lstat);const u={directory:"isDirectory",file:"isFile"};function checkType({type:e}){if(e in u){return}throw new Error(`Invalid type specified: ${e}`)}const p=(e,t)=>e===undefined||t[u[e]]();e.exports=(async(e,t)=>{t={cwd:process.cwd(),type:"file",allowSymlinks:true,...t};checkType(t);const r=t.allowSymlinks?i:a;return o(e,async e=>{try{const s=await r(n.resolve(t.cwd,e));return p(t.type,s)}catch(e){return false}},t)});e.exports.sync=((e,t)=>{t={cwd:process.cwd(),allowSymlinks:true,type:"file",...t};checkType(t);const r=t.allowSymlinks?s.statSync:s.lstatSync;for(const s of e){try{const e=r(n.resolve(t.cwd,s));if(p(t.type,e)){return s}}catch(e){}}})},940:(e,t,r)=>{const n=r(991);class EndError extends Error{constructor(e){super();this.value=e}}const s=async(e,t)=>t(await e);const c=async e=>{const t=await Promise.all(e);if(t[1]===true){throw new EndError(t[0])}return false};const o=async(e,t,r)=>{r={concurrency:Infinity,preserveOrder:true,...r};const o=n(r.concurrency);const i=[...e].map(e=>[e,o(s,e,t)]);const a=n(r.preserveOrder?1:Infinity);try{await Promise.all(i.map(e=>a(c,e)))}catch(e){if(e instanceof EndError){return e.value}throw e}};e.exports=o;e.exports.default=o},991:(e,t,r)=>{const n=r(404);const s=e=>{if(!((Number.isInteger(e)||e===Infinity)&&e>0)){return Promise.reject(new TypeError("Expected `concurrency` to be a number from 1 and up"))}const t=[];let r=0;const s=()=>{r--;if(t.length>0){t.shift()()}};const c=(e,t,...c)=>{r++;const o=n(e,...c);t(o);o.then(s,s)};const o=(n,s,...o)=>{if(r<e){c(n,s,...o)}else{t.push(c.bind(null,n,s,...o))}};const i=(e,...t)=>new Promise(r=>o(e,r,...t));Object.defineProperties(i,{activeCount:{get:()=>r},pendingCount:{get:()=>t.length},clearQueue:{value:()=>{t.length=0}}});return i};e.exports=s;e.exports.default=s},164:(e,t,r)=>{const n=r(747);const{promisify:s}=r(669);const c=s(n.access);e.exports=(async e=>{try{await c(e);return true}catch(e){return false}});e.exports.sync=(e=>{try{n.accessSync(e);return true}catch(e){return false}})},747:e=>{e.exports=require("fs")},622:e=>{e.exports=require("path")},669:e=>{e.exports=require("util")}};var t={};function __webpack_require__(r){if(t[r]){return t[r].exports}var n=t[r]={exports:{}};var s=true;try{e[r](n,n.exports,__webpack_require__);s=false}finally{if(s)delete t[r]}return n.exports}__webpack_require__.ab=__dirname+"/";return __webpack_require__(21)})();
\ No newline at end of file \ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
"use strict";
const {
minify: terserMinify
} = require("next/dist/compiled/terser");
const buildTerserOptions = ({
ecma,
parse = {},
compress = {},
mangle,
module,
output,
toplevel,
nameCache,
ie8,
/* eslint-disable camelcase */
keep_classnames,
keep_fnames,
/* eslint-enable camelcase */
safari10
} = {}) => ({
parse: { ...parse
},
compress: typeof compress === 'boolean' ? compress : { ...compress
},
// eslint-disable-next-line no-nested-ternary
mangle: mangle == null ? true : typeof mangle === 'boolean' ? mangle : { ...mangle
},
output: {
beautify: false,
...output
},
// Ignoring sourceMap from options
sourceMap: null,
ecma,
keep_classnames,
keep_fnames,
ie8,
module,
nameCache,
safari10,
toplevel
});
function isObject(value) {
const type = typeof value;
return value != null && (type === 'object' || type === 'function');
}
const buildComments = (options, terserOptions, extractedComments) => {
const condition = {};
const commentsOpts = terserOptions.output.comments;
const {
extractComments
} = options;
condition.preserve = typeof commentsOpts !== 'undefined' ? commentsOpts : false;
if (typeof extractComments === 'boolean' && extractComments) {
condition.extract = 'some';
} else if (typeof extractComments === 'string' || extractComments instanceof RegExp) {
condition.extract = extractComments;
} else if (typeof extractComments === 'function') {
condition.extract = extractComments;
} else if (isObject(extractComments)) {
condition.extract = typeof extractComments.condition === 'boolean' && extractComments.condition ? 'some' : typeof extractComments.condition !== 'undefined' ? extractComments.condition : 'some';
} else {
// No extract
// Preserve using "commentsOpts" or "some"
condition.preserve = typeof commentsOpts !== 'undefined' ? commentsOpts : 'some';
condition.extract = false;
} // Ensure that both conditions are functions
['preserve', 'extract'].forEach(key => {
let regexStr;
let regex;
switch (typeof condition[key]) {
case 'boolean':
condition[key] = condition[key] ? () => true : () => false;
break;
case 'function':
break;
case 'string':
if (condition[key] === 'all') {
condition[key] = () => true;
break;
}
if (condition[key] === 'some') {
condition[key] = (astNode, comment) => {
return (comment.type === 'comment2' || comment.type === 'comment1') && /@preserve|@lic|@cc_on|^\**!/i.test(comment.value);
};
break;
}
regexStr = condition[key];
condition[key] = (astNode, comment) => {
return new RegExp(regexStr).test(comment.value);
};
break;
default:
regex = condition[key];
condition[key] = (astNode, comment) => regex.test(comment.value);
}
}); // Redefine the comments function to extract and preserve
// comments according to the two conditions
return (astNode, comment) => {
if (condition.extract(astNode, comment)) {
const commentText = comment.type === 'comment2' ? `/*${comment.value}*/` : `//${comment.value}`; // Don't include duplicate comments
if (!extractedComments.includes(commentText)) {
extractedComments.push(commentText);
}
}
return condition.preserve(astNode, comment);
};
};
async function minify(options) {
const {
name,
input,
inputSourceMap,
minify: minifyFn
} = options;
if (minifyFn) {
return minifyFn({
[name]: input
}, inputSourceMap);
} // Copy terser options
const terserOptions = buildTerserOptions(options.terserOptions); // Let terser generate a SourceMap
if (inputSourceMap) {
terserOptions.sourceMap = {
asObject: true
};
}
const extractedComments = [];
terserOptions.output.comments = buildComments(options, terserOptions, extractedComments);
const result = await terserMinify({
[name]: input
}, terserOptions);
return { ...result,
extractedComments
};
}
function transform(options) {
// 'use strict' => this === undefined (Clean Scope)
// Safer for possible security issues, albeit not critical at all here
// eslint-disable-next-line no-new-func, no-param-reassign
options = new Function('exports', 'require', 'module', '__filename', '__dirname', `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
return minify(options);
}
module.exports.minify = minify;
module.exports.transform = transform;
\ No newline at end of file
{"name":"terser-webpack-plugin","main":"cjs.js","author":"webpack Contrib Team","license":"MIT"}
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
"native-url": "0.3.4", "native-url": "0.3.4",
"node-fetch": "2.6.1", "node-fetch": "2.6.1",
"node-html-parser": "1.4.9", "node-html-parser": "1.4.9",
"p-limit": "3.1.0",
"path-browserify": "1.0.1", "path-browserify": "1.0.1",
"pnp-webpack-plugin": "1.6.4", "pnp-webpack-plugin": "1.6.4",
"postcss": "8.1.7", "postcss": "8.1.7",
...@@ -214,7 +215,6 @@ ...@@ -214,7 +215,6 @@
"strip-ansi": "6.0.0", "strip-ansi": "6.0.0",
"taskr": "1.1.0", "taskr": "1.1.0",
"terser": "5.5.1", "terser": "5.5.1",
"terser-webpack-plugin": "4.1.0",
"text-table": "0.2.0", "text-table": "0.2.0",
"thread-loader": "2.1.3", "thread-loader": "2.1.3",
"typescript": "3.8.3", "typescript": "3.8.3",
......
...@@ -18,19 +18,6 @@ module.exports = function (task) { ...@@ -18,19 +18,6 @@ module.exports = function (task) {
Object.keys(assets).forEach((key) => { Object.keys(assets).forEach((key) => {
let data = assets[key].source let data = assets[key].source
if (
join(file.dir, key).endsWith('terser-webpack-plugin/dist/minify.js')
) {
data = Buffer.from(
data
.toString()
.replace(
`require('terser')`,
`require("${options.externals['terser']}")`
)
)
}
this._.files.push({ this._.files.push({
data, data,
base: basename(key), base: basename(key),
......
...@@ -513,16 +513,6 @@ export async function ncc_web_vitals(task, opts) { ...@@ -513,16 +513,6 @@ export async function ncc_web_vitals(task, opts) {
.target('compiled/web-vitals') .target('compiled/web-vitals')
} }
externals['terser-webpack-plugin'] = 'next/dist/compiled/terser-webpack-plugin'
export async function ncc_terser_webpack_plugin(task, opts) {
await task
.source(
opts.src || relative(__dirname, require.resolve('terser-webpack-plugin'))
)
.ncc({ packageName: 'terser-webpack-plugin', externals })
.target('compiled/terser-webpack-plugin')
}
externals['comment-json'] = 'next/dist/compiled/comment-json' externals['comment-json'] = 'next/dist/compiled/comment-json'
export async function ncc_comment_json(task, opts) { export async function ncc_comment_json(task, opts) {
await task await task
...@@ -612,7 +602,6 @@ export async function ncc(task) { ...@@ -612,7 +602,6 @@ export async function ncc(task) {
'ncc_thread_loader', 'ncc_thread_loader',
'ncc_unistore', 'ncc_unistore',
'ncc_web_vitals', 'ncc_web_vitals',
'ncc_terser_webpack_plugin',
'ncc_comment_json', 'ncc_comment_json',
'ncc_semver', 'ncc_semver',
]) ])
......
...@@ -199,7 +199,6 @@ declare module 'next/dist/compiled/web-vitals' { ...@@ -199,7 +199,6 @@ declare module 'next/dist/compiled/web-vitals' {
export = m export = m
} }
declare module 'next/dist/compiled/terser-webpack-plugin'
declare module 'next/dist/compiled/comment-json' { declare module 'next/dist/compiled/comment-json' {
import m from 'comment-json' import m from 'comment-json'
export = m export = m
......
...@@ -4233,7 +4233,7 @@ bytes@3.1.0, bytes@^3.0.0: ...@@ -4233,7 +4233,7 @@ bytes@3.1.0, bytes@^3.0.0:
version "3.1.0" version "3.1.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
cacache@15.0.5, cacache@^15.0.5: cacache@15.0.5:
version "15.0.5" version "15.0.5"
resolved "https://registry.yarnpkg.com/cacache/-/cacache-15.0.5.tgz#69162833da29170d6732334643c60e005f5f17d0" resolved "https://registry.yarnpkg.com/cacache/-/cacache-15.0.5.tgz#69162833da29170d6732334643c60e005f5f17d0"
integrity sha512-lloiL22n7sOjEEXdL8NAjTgv9a1u43xICE9/203qonkZUCj5X1UEWIdf2/Y0d6QcCtMzbKQyhrcDbdvlZTs/+A== integrity sha512-lloiL22n7sOjEEXdL8NAjTgv9a1u43xICE9/203qonkZUCj5X1UEWIdf2/Y0d6QcCtMzbKQyhrcDbdvlZTs/+A==
...@@ -7126,7 +7126,7 @@ finalhandler@~1.1.2: ...@@ -7126,7 +7126,7 @@ finalhandler@~1.1.2:
statuses "~1.5.0" statuses "~1.5.0"
unpipe "~1.0.0" unpipe "~1.0.0"
find-cache-dir@3.3.1, find-cache-dir@^3.0.0, find-cache-dir@^3.3.1: find-cache-dir@3.3.1, find-cache-dir@^3.0.0:
version "3.3.1" version "3.3.1"
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.3.1.tgz#89b33fad4a4670daa94f855f7fbe31d6d84fe880" resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.3.1.tgz#89b33fad4a4670daa94f855f7fbe31d6d84fe880"
dependencies: dependencies:
...@@ -9512,15 +9512,6 @@ jest-worker@^26.0.0: ...@@ -9512,15 +9512,6 @@ jest-worker@^26.0.0:
merge-stream "^2.0.0" merge-stream "^2.0.0"
supports-color "^7.0.0" supports-color "^7.0.0"
jest-worker@^26.3.0:
version "26.3.0"
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.3.0.tgz#7c8a97e4f4364b4f05ed8bca8ca0c24de091871f"
integrity sha512-Vmpn2F6IASefL+DVBhPzI2J9/GJUsqzomdeN+P+dK8/jKxbh8R3BtFnx3FIta7wYlPU62cpJMJQo4kuOowcMnw==
dependencies:
"@types/node" "*"
merge-stream "^2.0.0"
supports-color "^7.0.0"
js-base64@^2.1.8, js-base64@^2.1.9: js-base64@^2.1.8, js-base64@^2.1.9:
version "2.5.1" version "2.5.1"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.5.1.tgz#1efa39ef2c5f7980bb1784ade4a8af2de3291121" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.5.1.tgz#1efa39ef2c5f7980bb1784ade4a8af2de3291121"
...@@ -11664,6 +11655,13 @@ p-is-promise@^2.0.0: ...@@ -11664,6 +11655,13 @@ p-is-promise@^2.0.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-2.1.0.tgz#918cebaea248a62cf7ffab8e3bca8c5f882fc42e" resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-2.1.0.tgz#918cebaea248a62cf7ffab8e3bca8c5f882fc42e"
p-limit@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==
dependencies:
yocto-queue "^0.1.0"
p-limit@^1.1.0: p-limit@^1.1.0:
version "1.3.0" version "1.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8"
...@@ -11676,13 +11674,6 @@ p-limit@^2.0.0, p-limit@^2.2.0: ...@@ -11676,13 +11674,6 @@ p-limit@^2.0.0, p-limit@^2.2.0:
dependencies: dependencies:
p-try "^2.0.0" p-try "^2.0.0"
p-limit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.0.2.tgz#1664e010af3cadc681baafd3e2a437be7b0fb5fe"
integrity sha512-iwqZSOoWIW+Ew4kAGUlN16J4M7OB3ysMLSZtnhmqx7njIHFPlxWBX8xo3lVTyFVq6mI/lL9qt2IsN1sHwaxJkg==
dependencies:
p-try "^2.0.0"
p-locate@^2.0.0: p-locate@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43"
...@@ -14689,13 +14680,6 @@ serialize-javascript@^3.1.0: ...@@ -14689,13 +14680,6 @@ serialize-javascript@^3.1.0:
dependencies: dependencies:
randombytes "^2.1.0" randombytes "^2.1.0"
serialize-javascript@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa"
integrity sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==
dependencies:
randombytes "^2.1.0"
serve-static@1.14.1: serve-static@1.14.1:
version "1.14.1" version "1.14.1"
resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.14.1.tgz#666e636dc4f010f7ef29970a88a674320898b2f9" resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.14.1.tgz#666e636dc4f010f7ef29970a88a674320898b2f9"
...@@ -15664,21 +15648,6 @@ temp@^0.8.1: ...@@ -15664,21 +15648,6 @@ temp@^0.8.1:
dependencies: dependencies:
rimraf "~2.6.2" rimraf "~2.6.2"
terser-webpack-plugin@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-4.1.0.tgz#6e9d6ae4e1a900d88ddce8da6a47507ea61f44bc"
integrity sha512-0ZWDPIP8BtEDZdChbufcXUigOYk6dOX/P/X0hWxqDDcVAQLb8Yy/0FAaemSfax3PAA67+DJR778oz8qVbmy4hA==
dependencies:
cacache "^15.0.5"
find-cache-dir "^3.3.1"
jest-worker "^26.3.0"
p-limit "^3.0.2"
schema-utils "^2.6.6"
serialize-javascript "^4.0.0"
source-map "^0.6.1"
terser "^5.0.0"
webpack-sources "^1.4.3"
terser-webpack-plugin@^1.4.3: terser-webpack-plugin@^1.4.3:
version "1.4.4" version "1.4.4"
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.4.4.tgz#2c63544347324baafa9a56baaddf1634c8abfc2f" resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.4.4.tgz#2c63544347324baafa9a56baaddf1634c8abfc2f"
...@@ -15720,15 +15689,6 @@ terser@^4.1.2: ...@@ -15720,15 +15689,6 @@ terser@^4.1.2:
source-map "~0.6.1" source-map "~0.6.1"
source-map-support "~0.5.12" source-map-support "~0.5.12"
terser@^5.0.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.1.0.tgz#1f4ab81c8619654fdded51f3157b001e1747281d"
integrity sha512-pwC1Jbzahz1ZPU87NQ8B3g5pKbhyJSiHih4gLH6WZiPU8mmS1IlGbB0A2Nuvkj/LCNsgIKctg6GkYwWCeTvXZQ==
dependencies:
commander "^2.20.0"
source-map "~0.6.1"
source-map-support "~0.5.12"
test-exclude@^5.2.3: test-exclude@^5.2.3:
version "5.2.3" version "5.2.3"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-5.2.3.tgz#c3d3e1e311eb7ee405e092dac10aefd09091eac0" resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-5.2.3.tgz#c3d3e1e311eb7ee405e092dac10aefd09091eac0"
...@@ -16538,7 +16498,7 @@ webpack-bundle-analyzer@3.6.1: ...@@ -16538,7 +16498,7 @@ webpack-bundle-analyzer@3.6.1:
opener "^1.5.1" opener "^1.5.1"
ws "^6.0.0" ws "^6.0.0"
webpack-sources@1.4.3, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-sources@^1.4.1, webpack-sources@^1.4.3: webpack-sources@1.4.3, webpack-sources@^1.1.0, webpack-sources@^1.4.0, webpack-sources@^1.4.1:
version "1.4.3" version "1.4.3"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.4.3.tgz#eedd8ec0b928fbf1cbfe994e22d2d890f330a933" resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.4.3.tgz#eedd8ec0b928fbf1cbfe994e22d2d890f330a933"
dependencies: dependencies:
...@@ -16977,3 +16937,8 @@ yauzl@^2.10.0: ...@@ -16977,3 +16937,8 @@ yauzl@^2.10.0:
dependencies: dependencies:
buffer-crc32 "~0.2.3" buffer-crc32 "~0.2.3"
fd-slicer "~1.1.0" fd-slicer "~1.1.0"
yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment