Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
api.afterBuild(async ({ queue, config }) => {
const { outputDir: base, pathPrefix, publicPath } = config
const patterns = options.paths.map(p => normalize(p))
const pages = queue.filter(page => {
return micromatch(page.path, patterns).length
})
const worker = new Worker(require.resolve('./lib/worker'))
console.log(`Extract critical CSS (${pages.length} pages)`)
await Promise.all(pages.map(async ({ htmlOutput }) => {
try {
await worker.generate(htmlOutput, {
ignore: options.ignore,
width: options.width,
height: options.height,
// TODO: remove pathPrefix fallback
pathPrefix: publicPath || pathPrefix || '/',
polyfill: options.polyfill,
base
})
} catch (err) {
worker.end()
numLayers = layersPkgsToPackage.length;
tasks = tasks.concat(layersPkgsToPackage.map((obj) => () =>
this.packageLayer({ ...obj, worker, report })
));
}
// Run all packaging work.
this._log(
`Packaging ${numFns} functions, ${shouldPackageService ? 1 : 0} services, and `
+ `${numLayers} layers with concurrency ${concurrency}`
);
let results;
if (concurrency > 1) {
// Run concurrently.
worker = new Worker(require.resolve("./util/bundle"), {
numWorkers: concurrency
});
results = await Promise.all(tasks.map((fn) => fn()));
worker.end();
} else {
// Run serially in-band.
const limit = pLimit(1);
results = await Promise.all(tasks.map(limit));
}
// Report.
if (report) {
this._report({ results });
}
return results;
_makeFarm(
workerPath: string,
exposedMethods: $ReadOnlyArray,
numWorkers: number,
) {
const env = {
...process.env,
// Force color to print syntax highlighted code frames.
FORCE_COLOR: 1,
};
return new JestWorker(workerPath, {
computeWorkerKey: this._config.stickyWorkers
? this._computeWorkerKey
: undefined,
exposedMethods,
forkOptions: {env},
numWorkers,
});
}
function createWorker(path) {
if (process.env.CI == null) {
return new Worker(path);
}
return require(path);
}
module.exports = async function build(argv /*: BuildOpts */) {
const worker = new Worker(path.join(__dirname, 'worker.js'));
worker.getStdout().pipe(process.stdout);
worker.getStderr().pipe(process.stderr);
if (!argv.skipPreflight) {
const preflight = require('./preflight.js');
try {
await preflight(path.join(argv.dir, 'package.json'));
} catch (err) {
worker.end();
throw err;
}
}
const files = await glob('src/**/*.js', {
cwd: argv.dir,
filesOnly: true,
function build(opts, variants = {}, preflight) {
const worker = new Worker(require.resolve('./worker.js'), {
exposedMethods: ['build', 'preflight', 'buildBrowser', 'genFlowLibdef'],
});
const baseInputOptions = {
input: path.join(opts.dir, 'src/index.js'),
pureExternalModules: true,
};
const browserInputOptions = {
...baseInputOptions,
};
const nodeInputOptions = {
...baseInputOptions,
};
const generateFlowLibdef =
!opts.separateEntries &&
module.exports = (config, numWorkers) => {
const workerPath = require.resolve('./worker')
return new Worker(workerPath, {
numWorkers,
forkOptions: {
stdio: ['pipe', 'pipe', process.stderr, 'ipc']
}
})
}
module.exports = async ({testPath}) => {
const worker = new Worker(require.resolve('./require-module'))
worker.getStdout().pipe(process.stdout)
worker.getStderr().pipe(process.stderr)
process.stdout.write('\n')
const start = +new Date()
try {
await worker.require(testPath)
return pass({
start,
end: +new Date(),
test: {path: testPath}
})
} catch (error) {
return fail({
start,
end: +new Date(),
test: {
function createWorker() {
if (require('os').cpus().length < 2) return void 0;
return new Worker(require.resolve('./loaders/babel-worker.js'), {
exposedMethods: ['runTransformation'],
forkOptions: {stdio: 'inherit'},
});
}