-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathexecutor.ts
More file actions
64 lines (50 loc) · 2.17 KB
/
Copy pathexecutor.ts
File metadata and controls
64 lines (50 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { type ExecutorContext, type PromiseExecutor } from '@nx/devkit';
import { compileSwc } from './lib/swc';
import { compileWithGriffelStylesAOT, compileWithReactCompiler, hasStylesFilesToProcess } from './lib/babel';
import { assetGlobsToFiles, copyAssets } from './lib/assets';
import { cleanOutput } from './lib/clean';
import { postprocessCjsExtension, copyCjsTypes } from './lib/cjs-extension';
import { NormalizedOptions, normalizeOptions, processAsyncQueue, runInParallel, runSerially } from './lib/shared';
import { measureEnd, measureStart } from '../../utils';
import generateApiExecutor from '../generate-api/executor';
import { type GenerateApiExecutorSchema } from '../generate-api/schema';
import { type BuildExecutorSchema } from './schema';
const runExecutor: PromiseExecutor<BuildExecutorSchema> = async (schema, context) => {
measureStart('BuildExecutor');
const options = normalizeOptions(schema, context);
const assetFiles = assetGlobsToFiles(options.assets ?? [], context.root, options.outputPathRoot);
const success = await runSerially(
() => cleanOutput(options, assetFiles),
() =>
runInParallel(
() => runBuild(options, context),
() => {
if (!options.generateApi) {
return Promise.resolve(true);
}
const generateApiSchema: GenerateApiExecutorSchema =
typeof options.generateApi === 'object' ? options.generateApi : {};
return generateApiExecutor(generateApiSchema, context).then(res => res.success);
},
),
() => copyAssets(assetFiles),
() => postprocessCjsExtension(options),
() => copyCjsTypes(options),
);
measureEnd('BuildExecutor');
return { success };
};
export default runExecutor;
// ===========
async function runBuild(options: NormalizedOptions, _context: ExecutorContext): Promise<boolean> {
if (hasStylesFilesToProcess(options)) {
return compileWithGriffelStylesAOT(options);
}
if (options.reactCompiler) {
return compileWithReactCompiler(options);
}
const compilationQueue = options.moduleOutput.map(outputConfig => {
return compileSwc(outputConfig, options);
});
return processAsyncQueue(compilationQueue);
}