chore: replace fs-extra
usage in scripts/
(#57215)
The PR is the continuation of #56917 and #57030. The PR replaces `fs-extra#copy` with Node.js built-in `fs.cp` API (which is almost identical to `fs-extra#copy`, and has been available since Node.js 16). The PR also provides a workaround for flaky Windows `fs.rename` operation (#57030). cc @styfle @wbinnssmith
This commit is contained in:
parent
7281cd3fc4
commit
27dcd26c43
4 changed files with 15 additions and 12 deletions
|
@ -2,7 +2,7 @@ import os from 'os'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import execa from 'execa'
|
import execa from 'execa'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { move } from 'fs-extra'
|
import fsp from 'fs/promises'
|
||||||
;(async function () {
|
;(async function () {
|
||||||
if (process.env.NEXT_SKIP_NATIVE_POSTINSTALL) {
|
if (process.env.NEXT_SKIP_NATIVE_POSTINSTALL) {
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -70,8 +70,12 @@ import { move } from 'fs-extra'
|
||||||
pkgs.map(async (pkg) => {
|
pkgs.map(async (pkg) => {
|
||||||
const from = path.join(tmpdir, 'node_modules/@next', pkg)
|
const from = path.join(tmpdir, 'node_modules/@next', pkg)
|
||||||
const to = path.join(cwd, 'node_modules/@next', pkg)
|
const to = path.join(cwd, 'node_modules/@next', pkg)
|
||||||
// overwriting by removing the target first
|
// The directory from pnpm store is a symlink, which can not be overwritten,
|
||||||
return move(from, to, { overwrite: true })
|
// so we remove the existing directory before copying
|
||||||
|
await fsp.rm(to, { recursive: true, force: true })
|
||||||
|
// Renaming is flaky on Windows, and the tmpdir is going to be deleted anyway,
|
||||||
|
// so we use copy the directory instead
|
||||||
|
return fsp.cp(from, to, { force: true, recursive: true })
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
fs.rmSync(tmpdir, { recursive: true, force: true })
|
fs.rmSync(tmpdir, { recursive: true, force: true })
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const execa = require('execa')
|
const execa = require('execa')
|
||||||
const { copy } = require('fs-extra')
|
|
||||||
const { Sema } = require('async-sema')
|
const { Sema } = require('async-sema')
|
||||||
const { readFile, readdir, writeFile } = require('fs/promises')
|
const { readFile, readdir, writeFile, cp } = require('fs/promises')
|
||||||
|
|
||||||
const cwd = process.cwd()
|
const cwd = process.cwd()
|
||||||
|
|
||||||
|
@ -28,7 +27,7 @@ const cwd = process.cwd()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let binaryName = `next-swc.${platform}.node`
|
let binaryName = `next-swc.${platform}.node`
|
||||||
await copy(
|
await cp(
|
||||||
path.join(cwd, 'packages/next-swc/native', binaryName),
|
path.join(cwd, 'packages/next-swc/native', binaryName),
|
||||||
path.join(nativePackagesDir, platform, binaryName)
|
path.join(nativePackagesDir, platform, binaryName)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { copy } from 'fs-extra'
|
|
||||||
;(async function () {
|
;(async function () {
|
||||||
try {
|
try {
|
||||||
let wasmDir = path.join(process.cwd(), 'packages/next-swc/crates/wasm')
|
let wasmDir = path.join(process.cwd(), 'packages/next-swc/crates/wasm')
|
||||||
|
@ -22,10 +21,10 @@ import { copy } from 'fs-extra'
|
||||||
JSON.stringify(wasmPkg, null, 2)
|
JSON.stringify(wasmPkg, null, 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
await copy(
|
fs.cpSync(
|
||||||
path.join(wasmDir, `${folderName}`),
|
path.join(wasmDir, folderName),
|
||||||
path.join(process.cwd(), `node_modules/@next/swc-wasm-${wasmTarget}`),
|
path.join(process.cwd(), `node_modules/@next/swc-wasm-${wasmTarget}`),
|
||||||
{ overwrite: true }
|
{ force: true, recursive: true }
|
||||||
)
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
|
|
@ -2,7 +2,6 @@ const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const execa = require('execa')
|
const execa = require('execa')
|
||||||
const fsp = require('fs/promises')
|
const fsp = require('fs/promises')
|
||||||
const { copy } = require('fs-extra')
|
|
||||||
const prettyBytes = require('pretty-bytes')
|
const prettyBytes = require('pretty-bytes')
|
||||||
const gzipSize = require('next/dist/compiled/gzip-size')
|
const gzipSize = require('next/dist/compiled/gzip-size')
|
||||||
const { nodeFileTrace } = require('next/dist/compiled/@vercel/nft')
|
const { nodeFileTrace } = require('next/dist/compiled/@vercel/nft')
|
||||||
|
@ -25,7 +24,7 @@ async function main() {
|
||||||
const origTestDir = path.join(origRepoDir, 'test')
|
const origTestDir = path.join(origRepoDir, 'test')
|
||||||
const dotDir = path.join(origRepoDir, './') + '.'
|
const dotDir = path.join(origRepoDir, './') + '.'
|
||||||
|
|
||||||
await copy(origRepoDir, repoDir, {
|
await fsp.cp(origRepoDir, repoDir, {
|
||||||
filter: (item) => {
|
filter: (item) => {
|
||||||
return (
|
return (
|
||||||
!item.startsWith(origTestDir) &&
|
!item.startsWith(origTestDir) &&
|
||||||
|
@ -33,6 +32,8 @@ async function main() {
|
||||||
!item.includes('node_modules')
|
!item.includes('node_modules')
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
force: true,
|
||||||
|
recursive: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('using workdir', workDir)
|
console.log('using workdir', workDir)
|
||||||
|
|
Loading…
Reference in a new issue