forked from nrwl/nx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
package.impl.ts
87 lines (80 loc) · 2.29 KB
/
package.impl.ts
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { ExecutorContext } from '@nrwl/devkit';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import { copyAssetFiles } from '@nrwl/workspace/src/utilities/assets';
import {
calculateProjectDependencies,
checkDependentProjectsHaveBeenBuilt,
updateBuildableProjectPackageJsonDependencies,
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
import { NodePackageBuilderOptions } from './utils/models';
import compileTypeScriptFiles from './utils/compile-typescript-files';
import updatePackageJson from './utils/update-package-json';
import normalizeOptions from './utils/normalize-options';
import addCliWrapper from './utils/cli';
export async function packageExecutor(
options: NodePackageBuilderOptions,
context: ExecutorContext
) {
const libRoot = context.workspace.projects[context.projectName].root;
const normalizedOptions = normalizeOptions(options, context, libRoot);
const { target, dependencies } = calculateProjectDependencies(
readCachedProjectGraph(),
context.root,
context.projectName,
context.targetName,
context.configurationName
);
const dependentsBuilt = checkDependentProjectsHaveBeenBuilt(
context.root,
context.projectName,
context.targetName,
dependencies
);
if (!dependentsBuilt) {
throw new Error();
}
const result = await compileTypeScriptFiles(
normalizedOptions,
context,
libRoot,
dependencies,
async () =>
await updatePackageAndCopyAssets(
normalizedOptions,
context,
target,
dependencies
)
);
if (options.cli) {
addCliWrapper(normalizedOptions, context);
}
return {
...(result as { success: boolean }),
outputPath: normalizedOptions.outputPath,
};
}
async function updatePackageAndCopyAssets(
options,
context,
target,
dependencies
) {
await copyAssetFiles(options.files);
updatePackageJson(options, context);
if (
dependencies.length > 0 &&
options.updateBuildableProjectDepsInPackageJson
) {
updateBuildableProjectPackageJsonDependencies(
context.root,
context.projectName,
context.targetName,
context.configurationName,
target,
dependencies,
options.buildableProjectDepsInPackageJsonType
);
}
}
export default packageExecutor;