chore(nextjs): clean up constants import path and remove support for Next.js 10 (#11287)
This commit is contained in:
parent
f9a6df5d63
commit
c76eb7fb74
@ -1,26 +1,22 @@
|
|||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { ExecutorContext } from '@nrwl/devkit';
|
import { ExecutorContext } from '@nrwl/devkit';
|
||||||
|
|
||||||
import build from 'next/dist/build';
|
import build from 'next/dist/build';
|
||||||
|
|
||||||
import { join, resolve } from 'path';
|
import { join, resolve } from 'path';
|
||||||
import { copySync, mkdir } from 'fs-extra';
|
import { copySync, mkdir } from 'fs-extra';
|
||||||
|
|
||||||
import { prepareConfig } from '../../utils/config';
|
|
||||||
import { NextBuildBuilderOptions } from '../../utils/types';
|
|
||||||
import { createPackageJson } from './lib/create-package-json';
|
|
||||||
import { createNextConfigFile } from './lib/create-next-config-file';
|
|
||||||
import { directoryExists } from '@nrwl/workspace/src/utilities/fileutils';
|
import { directoryExists } from '@nrwl/workspace/src/utilities/fileutils';
|
||||||
import { readCachedProjectGraph } from '@nrwl/devkit';
|
import { readCachedProjectGraph } from '@nrwl/devkit';
|
||||||
import {
|
import {
|
||||||
calculateProjectDependencies,
|
calculateProjectDependencies,
|
||||||
DependentBuildableProjectNode,
|
DependentBuildableProjectNode,
|
||||||
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
|
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
|
||||||
import { checkPublicDirectory } from './lib/check-project';
|
|
||||||
import { importConstants } from '../../utils/require-shim';
|
|
||||||
import { workspaceLayout } from '@nrwl/devkit';
|
import { workspaceLayout } from '@nrwl/devkit';
|
||||||
|
|
||||||
const { PHASE_PRODUCTION_BUILD } = importConstants();
|
import { prepareConfig } from '../../utils/config';
|
||||||
|
import { createPackageJson } from './lib/create-package-json';
|
||||||
|
import { createNextConfigFile } from './lib/create-next-config-file';
|
||||||
|
import { checkPublicDirectory } from './lib/check-project';
|
||||||
|
import { NextBuildBuilderOptions } from '../../utils/types';
|
||||||
|
import { PHASE_PRODUCTION_BUILD } from '../../utils/constants';
|
||||||
|
|
||||||
export default async function buildExecutor(
|
export default async function buildExecutor(
|
||||||
options: NextBuildBuilderOptions,
|
options: NextBuildBuilderOptions,
|
||||||
|
|||||||
@ -7,23 +7,21 @@ import {
|
|||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import exportApp from 'next/dist/export';
|
import exportApp from 'next/dist/export';
|
||||||
import { join, resolve } from 'path';
|
import { join, resolve } from 'path';
|
||||||
|
import { readCachedProjectGraph } from '@nrwl/devkit';
|
||||||
|
import {
|
||||||
|
calculateProjectDependencies,
|
||||||
|
DependentBuildableProjectNode,
|
||||||
|
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
|
||||||
|
import { workspaceLayout } from '@nrwl/devkit';
|
||||||
|
|
||||||
import { prepareConfig } from '../../utils/config';
|
import { prepareConfig } from '../../utils/config';
|
||||||
import {
|
import {
|
||||||
NextBuildBuilderOptions,
|
NextBuildBuilderOptions,
|
||||||
NextExportBuilderOptions,
|
NextExportBuilderOptions,
|
||||||
} from '../../utils/types';
|
} from '../../utils/types';
|
||||||
import { readCachedProjectGraph } from '@nrwl/devkit';
|
import { PHASE_EXPORT } from '../../utils/constants';
|
||||||
import {
|
|
||||||
calculateProjectDependencies,
|
|
||||||
DependentBuildableProjectNode,
|
|
||||||
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
|
|
||||||
import { importConstants } from '../../utils/require-shim';
|
|
||||||
import { workspaceLayout } from '@nrwl/devkit';
|
|
||||||
import nextTrace = require('next/dist/trace');
|
import nextTrace = require('next/dist/trace');
|
||||||
|
|
||||||
const { PHASE_EXPORT } = importConstants();
|
|
||||||
|
|
||||||
export default async function exportExecutor(
|
export default async function exportExecutor(
|
||||||
options: NextExportBuilderOptions,
|
options: NextExportBuilderOptions,
|
||||||
context: ExecutorContext
|
context: ExecutorContext
|
||||||
|
|||||||
@ -5,10 +5,15 @@ import {
|
|||||||
parseTargetString,
|
parseTargetString,
|
||||||
readTargetOptions,
|
readTargetOptions,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
|
|
||||||
import * as chalk from 'chalk';
|
import * as chalk from 'chalk';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { join, resolve } from 'path';
|
import { join, resolve } from 'path';
|
||||||
|
import { readCachedProjectGraph } from '@nrwl/devkit';
|
||||||
|
import {
|
||||||
|
calculateProjectDependencies,
|
||||||
|
DependentBuildableProjectNode,
|
||||||
|
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
|
||||||
|
import { workspaceLayout } from '@nrwl/devkit';
|
||||||
|
|
||||||
import { prepareConfig } from '../../utils/config';
|
import { prepareConfig } from '../../utils/config';
|
||||||
import {
|
import {
|
||||||
@ -20,16 +25,11 @@ import {
|
|||||||
} from '../../utils/types';
|
} from '../../utils/types';
|
||||||
import { customServer } from './lib/custom-server';
|
import { customServer } from './lib/custom-server';
|
||||||
import { defaultServer } from './lib/default-server';
|
import { defaultServer } from './lib/default-server';
|
||||||
import { readCachedProjectGraph } from '@nrwl/devkit';
|
|
||||||
import {
|
|
||||||
calculateProjectDependencies,
|
|
||||||
DependentBuildableProjectNode,
|
|
||||||
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
|
|
||||||
import { assertDependentProjectsHaveBeenBuilt } from '../../utils/buildable-libs';
|
import { assertDependentProjectsHaveBeenBuilt } from '../../utils/buildable-libs';
|
||||||
import { importConstants } from '../../utils/require-shim';
|
import {
|
||||||
import { workspaceLayout } from '@nrwl/devkit';
|
PHASE_DEVELOPMENT_SERVER,
|
||||||
|
PHASE_PRODUCTION_SERVER,
|
||||||
const { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_SERVER } = importConstants();
|
} from '../../utils/constants';
|
||||||
|
|
||||||
const infoPrefix = `[ ${chalk.dim(chalk.cyan('info'))} ] `;
|
const infoPrefix = `[ ${chalk.dim(chalk.cyan('info'))} ] `;
|
||||||
const readyPrefix = `[ ${chalk.green('ready')} ]`;
|
const readyPrefix = `[ ${chalk.green('ready')} ]`;
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
import { chain, Rule, Tree } from '@angular-devkit/schematics';
|
import { chain, Rule, Tree } from '@angular-devkit/schematics';
|
||||||
import { formatFiles, readWorkspace } from '@nrwl/workspace';
|
import { formatFiles, readWorkspace } from '@nrwl/workspace';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { importConstants } from '../../utils/require-shim';
|
|
||||||
|
|
||||||
const { CONFIG_FILE, CONFIG_FILES } = importConstants();
|
import { CONFIG_FILES } from '../../utils/constants';
|
||||||
|
|
||||||
const defaultConfig = `const withSass = require('@zeit/next-sass');
|
const defaultConfig = `const withSass = require('@zeit/next-sass');
|
||||||
const withLess = require('@zeit/next-less');
|
const withLess = require('@zeit/next-less');
|
||||||
@ -41,7 +40,7 @@ export default function update(): Rule {
|
|||||||
// Next.js 12 specifies two config files.
|
// Next.js 12 specifies two config files.
|
||||||
const configFile = Array.isArray(CONFIG_FILES)
|
const configFile = Array.isArray(CONFIG_FILES)
|
||||||
? CONFIG_FILES[0]
|
? CONFIG_FILES[0]
|
||||||
: CONFIG_FILE;
|
: 'next.config.js';
|
||||||
const configPath = join(p.root, configFile);
|
const configPath = join(p.root, configFile);
|
||||||
if (!host.exists(configPath)) {
|
if (!host.exists(configPath)) {
|
||||||
host.create(configPath, defaultConfig);
|
host.create(configPath, defaultConfig);
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
import { createWebpackConfig, prepareConfig } from './config';
|
import { createWebpackConfig, prepareConfig } from './config';
|
||||||
import { NextBuildBuilderOptions } from '@nrwl/next';
|
import { NextBuildBuilderOptions } from '@nrwl/next';
|
||||||
import { dirname } from 'path';
|
import { dirname } from 'path';
|
||||||
import { importConstants } from './require-shim';
|
|
||||||
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
|
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
|
||||||
|
|
||||||
const { PHASE_PRODUCTION_BUILD } = importConstants();
|
import { PHASE_PRODUCTION_BUILD } from './constants';
|
||||||
|
|
||||||
jest.mock('@nrwl/web/src/utils/config', () => ({
|
jest.mock('@nrwl/web/src/utils/config', () => ({
|
||||||
createCopyPlugin: () => {},
|
createCopyPlugin: () => {},
|
||||||
|
|||||||
@ -28,8 +28,7 @@ import {
|
|||||||
createTmpTsConfig,
|
createTmpTsConfig,
|
||||||
DependentBuildableProjectNode,
|
DependentBuildableProjectNode,
|
||||||
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
|
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
|
||||||
import { importConfig } from './require-shim';
|
const loadConfig = require('next/dist/server/config').default;
|
||||||
const loadConfig = importConfig();
|
|
||||||
|
|
||||||
export function createWebpackConfig(
|
export function createWebpackConfig(
|
||||||
workspaceRoot: string,
|
workspaceRoot: string,
|
||||||
|
|||||||
1
packages/next/src/utils/constants.ts
Normal file
1
packages/next/src/utils/constants.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from 'next/dist/shared/lib/constants';
|
||||||
@ -1,15 +0,0 @@
|
|||||||
export function importConstants() {
|
|
||||||
try {
|
|
||||||
return require('next/dist/next-server/lib/constants');
|
|
||||||
} catch {
|
|
||||||
return require('next/dist/shared/lib/constants');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function importConfig() {
|
|
||||||
try {
|
|
||||||
return require('next/dist/next-server/lib/config').default;
|
|
||||||
} catch {
|
|
||||||
return require('next/dist/server/config').default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user