cleanup(nextjs): migrate to node FS (#28065)

This commit is contained in:
James Garbutt 2024-10-01 17:35:18 +07:00 committed by GitHub
parent 1378922496
commit 74061cf5ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 12 deletions

View File

@ -10,6 +10,10 @@
{ {
"name": "chalk", "name": "chalk",
"message": "Please use `picocolors` in place of `chalk` for rendering terminal colors" "message": "Please use `picocolors` in place of `chalk` for rendering terminal colors"
},
{
"name": "fs-extra",
"message": "Please use native functionality in place of `fs-extra` for file-system interaction"
} }
] ]
} }

View File

@ -40,7 +40,6 @@
"@svgr/webpack": "^8.0.1", "@svgr/webpack": "^8.0.1",
"copy-webpack-plugin": "^10.2.4", "copy-webpack-plugin": "^10.2.4",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",
"fs-extra": "^11.1.0",
"ignore": "^5.0.4", "ignore": "^5.0.4",
"picocolors": "^1.1.0", "picocolors": "^1.1.0",
"semver": "^7.5.3", "semver": "^7.5.3",
@ -51,7 +50,6 @@
"@nx/react": "file:../react", "@nx/react": "file:../react",
"@nx/web": "file:../web", "@nx/web": "file:../web",
"@nx/webpack": "file:../webpack", "@nx/webpack": "file:../webpack",
"@nx/workspace": "file:../workspace",
"@phenomnomnominal/tsquery": "~5.0.1" "@phenomnomnominal/tsquery": "~5.0.1"
}, },
"publishConfig": { "publishConfig": {

View File

@ -8,9 +8,9 @@ import {
} from '@nx/devkit'; } from '@nx/devkit';
import { createLockFile, createPackageJson, getLockFileName } from '@nx/js'; import { createLockFile, createPackageJson, getLockFileName } from '@nx/js';
import { join, resolve as pathResolve } from 'path'; import { join, resolve as pathResolve } from 'path';
import { copySync, existsSync, mkdir, writeFileSync } from 'fs-extra'; import { cpSync, existsSync, writeFileSync } from 'node:fs';
import { mkdir } from 'node:fs/promises';
import { gte } from 'semver'; import { gte } from 'semver';
import { directoryExists } from '@nx/workspace/src/utilities/fileutils';
import { checkAndCleanWithSemver } from '@nx/devkit/src/utils/semver'; import { checkAndCleanWithSemver } from '@nx/devkit/src/utils/semver';
import { updatePackageJson } from './lib/update-package-json'; import { updatePackageJson } from './lib/update-package-json';
@ -70,9 +70,7 @@ export default async function buildExecutor(
} }
} }
if (!directoryExists(options.outputPath)) { await mkdir(options.outputPath, { recursive: true });
mkdir(options.outputPath);
}
const builtPackageJson = createPackageJson( const builtPackageJson = createPackageJson(
context.projectName, context.projectName,
@ -114,8 +112,9 @@ export default async function buildExecutor(
// This is the default behavior when running `nx build <app>`. // This is the default behavior when running `nx build <app>`.
if (options.outputPath.replace(/\/$/, '') !== projectRoot) { if (options.outputPath.replace(/\/$/, '') !== projectRoot) {
createNextConfigFile(options, context); createNextConfigFile(options, context);
copySync(join(projectRoot, 'public'), join(options.outputPath, 'public'), { cpSync(join(projectRoot, 'public'), join(options.outputPath, 'public'), {
dereference: true, dereference: true,
recursive: true,
}); });
} }
return { success: true }; return { success: true };

View File

@ -1,5 +1,5 @@
import { logger } from '@nx/devkit'; import { logger } from '@nx/devkit';
import { readdirSync } from 'fs-extra'; import { readdirSync } from 'node:fs';
import { join } from 'path'; import { join } from 'path';
export function checkPublicDirectory(root: string) { export function checkPublicDirectory(root: string) {

View File

@ -9,12 +9,11 @@ import {
import * as ts from 'typescript'; import * as ts from 'typescript';
import { import {
copyFileSync, copyFileSync,
ensureDirSync,
existsSync, existsSync,
mkdirSync, mkdirSync,
readFileSync, readFileSync,
writeFileSync, writeFileSync,
} from 'fs-extra'; } from 'node:fs';
import { dirname, extname, join, relative } from 'path'; import { dirname, extname, join, relative } from 'path';
import { findNodes } from '@nx/js'; import { findNodes } from '@nx/js';
@ -76,7 +75,12 @@ export function createNextConfigFile(
projectRoot projectRoot
); );
for (const moduleFile of moduleFilesToCopy) { for (const moduleFile of moduleFilesToCopy) {
ensureDirSync(dirname(join(context.root, options.outputPath, moduleFile))); const moduleFileDir = dirname(
join(context.root, options.outputPath, moduleFile)
);
mkdirSync(moduleFileDir, { recursive: true });
// We already generate a build version of package.json in the dist folder. // We already generate a build version of package.json in the dist folder.
if (moduleFile !== 'package.json') { if (moduleFile !== 'package.json') {
copyFileSync( copyFileSync(