Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function createMinifier() {
trace('creating minification worker pool');
const worker = (new Worker(require.resolve('./minifyWorker'), {
forkOptions: {
// surface console.log and friends in worker
stdio: 'inherit',
},
}) as unknown) as typeof minifyWorker & InstanceType;
return {
minifyFromString: worker.minifyFromString,
destroy: worker.end.bind(worker),
};
}
private ensureSmall(): JestWorker {
if (this.smallWorker) {
return this.smallWorker;
}
// small files are processed in a limited number of threads to improve speed
// The limited number also prevents a large increase in memory usage for an otherwise short operation
return (this.smallWorker = new JestWorker(workerFile, {
exposedMethods: ['process'],
setupArgs: [this.workerOptions],
numWorkers: os.cpus().length < 2 ? 1 : 2,
// Will automatically fallback to processes if not supported
enableWorkerThreads: true
}));
}
private ensureSmall(): JestWorker {
if (this.smallWorker) {
return this.smallWorker;
}
// small files are processed in a limited number of threads to improve speed
// The limited number also prevents a large increase in memory usage for an otherwise short operation
return (this.smallWorker = new JestWorker(workerFile, {
exposedMethods: ['process', 'inlineLocales'],
setupArgs: hasThreadSupport ? [this.workerOptions] : [[...serialize(this.workerOptions)]],
numWorkers: os.cpus().length < 2 ? 1 : 2,
enableWorkerThreads: hasThreadSupport,
}));
}
private ensureLarge(): JestWorker {
if (this.largeWorker) {
return this.largeWorker;
}
// larger files are processed in a separate process to limit memory usage in the main process
return (this.largeWorker = new JestWorker(workerFile, {
exposedMethods: ['process', 'inlineLocales'],
setupArgs: [[...serialize(this.workerOptions)]],
}));
}
private ensureLarge(): JestWorker {
if (this.largeWorker) {
return this.largeWorker;
}
// larger files are processed in a separate process to limit memory usage in the main process
return (this.largeWorker = new JestWorker(workerFile, {
exposedMethods: ['process'],
setupArgs: [this.workerOptions]
}));
}
const buildManifestPath = path.join(distDir, BUILD_MANIFEST)
const sprPages = new Set()
const staticPages = new Set()
const invalidPages = new Set()
const hybridAmpPages = new Set()
const additionalSprPaths = new Map>()
const pageInfos = new Map()
const pagesManifest = JSON.parse(await fsReadFile(manifestPath, 'utf8'))
const buildManifest = JSON.parse(await fsReadFile(buildManifestPath, 'utf8'))
let customAppGetInitialProps: boolean | undefined
process.env.NEXT_PHASE = PHASE_PRODUCTION_BUILD
const staticCheckWorkers = new Worker(staticCheckWorker, {
numWorkers: config.experimental.cpus,
enableWorkerThreads: config.experimental.workerThreads,
})
staticCheckWorkers.getStdout().pipe(process.stdout)
staticCheckWorkers.getStderr().pipe(process.stderr)
const analysisBegin = process.hrtime()
await Promise.all(
pageKeys.map(async page => {
const actualPage = page === '/' ? '/index' : page
const size = await getPageSizeInKb(
actualPage,
distDir,
buildId,
buildManifest,
config.experimental.modern
columnDefault: {
width: 50
},
columns: {
0: {
width: 70,
},
1: {
alignment: 'right'
}
},
columnCount: 2
});
tableStream.write(['file', 'polyfills required']);
const worker = new Worker(require.resolve('./workers/detect'));
const polyfillsLeft = x => basePolyfills.indexOf(x) < 0;
if (mainBundle && mainBundle !== '.') {
basePolyfills = polyfills[mainBundle] = processPolyfills(
await worker.extractPolyfills(dist, mainBundle, options.babelScan, definitions)
);
tableStream.write([mainBundle, basePolyfills.length]);
}
if (addPolyfills && !mainBundle) {
throw new Error("devolution: in order to use `addPolyfills` define `rootBundles` condition.")
}
await Promise.all(
jsFiles.map(async file => {
if (file !== mainBundle) {