-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
create-package-json.ts
35 lines (30 loc) · 1.08 KB
/
create-package-json.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
import type { ExecutorContext } from '@nrwl/devkit';
import { writeJsonFile } from '@nrwl/devkit';
import { createPackageJson as generatePackageJson } from 'nx/src/utils/create-package-json';
import type { NextBuildBuilderOptions } from '../../../utils/types';
export async function createPackageJson(
options: NextBuildBuilderOptions,
context: ExecutorContext
) {
const packageJson = generatePackageJson(
context.projectName,
context.projectGraph,
{
root: context.root,
}
);
// By default we remove devDependencies since this is a production build.
if (!options.includeDevDependenciesInPackageJson) {
delete packageJson.devDependencies;
}
if (!packageJson.scripts) {
packageJson.scripts = {};
}
packageJson.scripts.start = 'next start';
const typescriptNode = context.projectGraph.externalNodes['npm:typescript'];
if (typescriptNode) {
packageJson.dependencies = packageJson.dependencies || {};
packageJson.dependencies['typescript'] = typescriptNode.data.version;
}
writeJsonFile(`${options.outputPath}/package.json`, packageJson);
}