fix(nextjs): hide lockfile generation behind a flag so it can be toggled on and off (#14204)

This commit is contained in:
Jack Hsu 2023-01-06 15:26:10 -05:00 committed by GitHub
parent e8b2731a47
commit d3ba6447d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 14 deletions

View File

@ -53,6 +53,11 @@
"type": "boolean", "type": "boolean",
"description": "Include `devDependencies` in the generated package.json file. By default only production `dependencies` are included.", "description": "Include `devDependencies` in the generated package.json file. By default only production `dependencies` are included.",
"default": false "default": false
},
"generateLockfile": {
"type": "boolean",
"description": "Generate a lockfile (e.g. yarn.lock) that matches the workspace lockfile to ensure package versions match.",
"default": false
} }
}, },
"required": ["root", "outputPath"], "required": ["root", "outputPath"],

View File

@ -12,9 +12,9 @@ import {
updateFile, updateFile,
updateProjectConfig, updateProjectConfig,
} from '@nrwl/e2e/utils'; } from '@nrwl/e2e/utils';
import { checkApp } from './utils';
import { stringUtils } from '@nrwl/workspace'; import { stringUtils } from '@nrwl/workspace';
import * as http from 'http'; import * as http from 'http';
import { checkApp } from './utils';
describe('Next.js Applications', () => { describe('Next.js Applications', () => {
let proj: string; let proj: string;

View File

@ -1,14 +1,11 @@
import { import {
checkFilesExist, checkFilesExist,
detectPackageManager,
killPorts, killPorts,
readJson, readJson,
runCLI, runCLI,
runCLIAsync, runCLIAsync,
runCypressTests, runCypressTests,
tmpProjPath,
} from '../../utils'; } from '../../utils';
import { getLockFileName } from '../../../packages/nx/src/lock-file/lock-file';
export async function checkApp( export async function checkApp(
appName: string, appName: string,
@ -28,12 +25,6 @@ export async function checkApp(
expect(packageJson.dependencies['react-dom']).toBeDefined(); expect(packageJson.dependencies['react-dom']).toBeDefined();
expect(packageJson.dependencies.next).toBeDefined(); expect(packageJson.dependencies.next).toBeDefined();
checkFilesExist(
`dist/apps/${appName}/${getLockFileName(
detectPackageManager(tmpProjPath())
)}`
);
if (opts.checkLint) { if (opts.checkLint) {
const lintResults = runCLI(`lint ${appName}`); const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.'); expect(lintResults).toContain('All files pass linting.');

View File

@ -90,11 +90,14 @@ export default async function buildExecutor(
} }
); );
updatePackageJson(builtPackageJson, context); updatePackageJson(builtPackageJson, context);
const lockFile = createLockFile(builtPackageJson);
writeJsonFile(`${options.outputPath}/package.json`, builtPackageJson); writeJsonFile(`${options.outputPath}/package.json`, builtPackageJson);
if (options.generateLockfile) {
const lockFile = createLockFile(builtPackageJson);
writeFileSync(`${options.outputPath}/${getLockFileName()}`, lockFile, { writeFileSync(`${options.outputPath}/${getLockFileName()}`, lockFile, {
encoding: 'utf-8', encoding: 'utf-8',
}); });
}
createNextConfigFile(options, context); createNextConfigFile(options, context);

View File

@ -53,6 +53,11 @@
"type": "boolean", "type": "boolean",
"description": "Include `devDependencies` in the generated package.json file. By default only production `dependencies` are included.", "description": "Include `devDependencies` in the generated package.json file. By default only production `dependencies` are included.",
"default": false "default": false
},
"generateLockfile": {
"type": "boolean",
"description": "Generate a lockfile (e.g. yarn.lock) that matches the workspace lockfile to ensure package versions match.",
"default": false
} }
}, },
"required": ["root", "outputPath"] "required": ["root", "outputPath"]

View File

@ -37,6 +37,7 @@ export interface NextBuildBuilderOptions {
nextConfig?: string; nextConfig?: string;
buildLibsFromSource?: boolean; buildLibsFromSource?: boolean;
includeDevDependenciesInPackageJson?: boolean; includeDevDependenciesInPackageJson?: boolean;
generateLockfile?: boolean;
watch?: boolean; watch?: boolean;
} }