diff --git a/package.json b/package.json index f6512307ff35c..2df76f6eb5a72 100644 --- a/package.json +++ b/package.json @@ -72,13 +72,12 @@ "express": "4.17.0", "faunadb": "2.6.1", "firebase": "6.3.4", - "fs-extra": "7.0.1", + "fs-extra": "9.0.0", "get-port": "5.0.0", "isomorphic-unfetch": "3.0.0", "jest-cli": "24.9.0", "lerna": "3.14.1", "lint-staged": "9.4.2", - "mkdirp": "0.5.1", "moment": "^2.24.0", "node-fetch": "2.6.0", "node-notifier": "5.4.0", diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index a63780edc9044..5f9f3f1ccc217 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -6,7 +6,6 @@ import escapeStringRegexp from 'escape-string-regexp' import findUp from 'find-up' import fs from 'fs' import Worker from 'jest-worker' -import mkdirpOrig from 'mkdirp' import nanoid from 'next/dist/compiled/nanoid/index.js' import path from 'path' import { pathToRegexp } from 'path-to-regexp' @@ -80,7 +79,7 @@ const fsStat = promisify(fs.stat) const fsMove = promisify(fs.rename) const fsReadFile = promisify(fs.readFile) const fsWriteFile = promisify(fs.writeFile) -const mkdirp = promisify(mkdirpOrig) +const mkdir = promisify(fs.mkdir) const staticCheckWorker = require.resolve('./utils') @@ -301,7 +300,7 @@ export default async function build(dir: string, conf = null): Promise { })), } - await mkdirp(distDir) + await mkdir(distDir, { recursive: true }) // We need to write the manifest with rewrites before build // so serverless can import the manifest await fsWriteFile(routesManifestPath, JSON.stringify(routesManifest), 'utf8') @@ -755,7 +754,7 @@ export default async function build(dir: string, conf = null): Promise { if (page === '/') pagesManifest['/index'] = relativeDest if (page === '/.amp') pagesManifest['/index.amp'] = relativeDest } - await mkdirp(path.dirname(dest)) + await mkdir(path.dirname(dest), { recursive: true }) await fsMove(orig, dest) } diff --git a/packages/next/build/profiler/profiler.js b/packages/next/build/profiler/profiler.js index 89afb1332515e..ffaa00f2d8bd1 100644 --- a/packages/next/build/profiler/profiler.js +++ b/packages/next/build/profiler/profiler.js @@ -1,5 +1,4 @@ import path from 'path' -import mkdirp from 'mkdirp' import fs from 'fs' let inspector @@ -92,7 +91,7 @@ export const createTrace = outputPath => { const profiler = new Profiler(inspector) if (/\/|\\/.test(outputPath)) { const dirPath = path.dirname(outputPath) - mkdirp.sync(dirPath) + fs.mkdirSync(dirPath, { recursive: true }) } const fsStream = fs.createWriteStream(outputPath) diff --git a/packages/next/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js b/packages/next/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js index d8c0b48df39fd..17e2244a2e869 100644 --- a/packages/next/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js +++ b/packages/next/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js @@ -2,8 +2,7 @@ import { join } from 'path' import minify from './minify' import { promisify } from 'util' import Worker from 'jest-worker' -import { writeFile, readFile } from 'fs' -import mkdirp from 'mkdirp' +import { mkdirSync, writeFile, readFile } from 'fs' const worker = require.resolve('./minify') const writeFileP = promisify(writeFile) @@ -12,7 +11,9 @@ const readFileP = promisify(readFile) export default class TaskRunner { constructor({ distDir, cpus, cache, workerThreads }) { if (cache) { - mkdirp.sync((this.cacheDir = join(distDir, 'cache', 'next-minifier'))) + mkdirSync((this.cacheDir = join(distDir, 'cache', 'next-minifier')), { + recursive: true, + }) } // In some cases cpus() returns undefined // https://github.com/nodejs/node/issues/19022 diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index e43f65e243417..808ce043b060c 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -3,11 +3,11 @@ import findUp from 'find-up' import { copyFile as copyFileOrig, existsSync, + mkdir as mkdirOrig, readFileSync, writeFileSync, } from 'fs' import Worker from 'jest-worker' -import mkdirpModule from 'mkdirp' import { cpus } from 'os' import { dirname, join, resolve, sep } from 'path' import { promisify } from 'util' @@ -35,8 +35,8 @@ import { eventCliSession } from '../telemetry/events' import { Telemetry } from '../telemetry/storage' import { normalizePagePath } from '../next-server/server/normalize-page-path' -const mkdirp = promisify(mkdirpModule) const copyFile = promisify(copyFileOrig) +const mkdir = promisify(mkdirOrig) const createProgress = (total: number, label = 'Exporting') => { let curProgress = 0 @@ -184,7 +184,7 @@ export default async function( } await recursiveDelete(join(outDir)) - await mkdirp(join(outDir, '_next', buildId)) + await mkdir(join(outDir, '_next', buildId), { recursive: true }) writeFileSync( join(distDir, EXPORT_DETAIL), @@ -363,8 +363,8 @@ export default async function( ) const jsonDest = join(pagesDataDir, `${route}.json`) - await mkdirp(dirname(htmlDest)) - await mkdirp(dirname(jsonDest)) + await mkdir(dirname(htmlDest), { recursive: true }) + await mkdir(dirname(jsonDest), { recursive: true }) await copyFile(`${orig}.html`, htmlDest) await copyFile(`${orig}.json`, jsonDest) }) diff --git a/packages/next/export/worker.js b/packages/next/export/worker.js index d54536af22090..7f4ec2220cb03 100644 --- a/packages/next/export/worker.js +++ b/packages/next/export/worker.js @@ -1,9 +1,8 @@ -import mkdirpModule from 'mkdirp' import { promisify } from 'util' import url from 'url' import { extname, join, dirname, sep } from 'path' import { renderToHTML } from '../next-server/server/render' -import { writeFile, access } from 'fs' +import { access, mkdir as mkdirOrig, writeFile } from 'fs' import AmpHtmlValidator from 'amphtml-validator' import { loadComponents } from '../next-server/server/load-components' import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' @@ -14,8 +13,8 @@ import { SERVER_PROPS_EXPORT_ERROR } from '../lib/constants' const envConfig = require('../next-server/lib/runtime-config') const writeFileP = promisify(writeFile) -const mkdirp = promisify(mkdirpModule) const accessP = promisify(access) +const mkdir = promisify(mkdirOrig) global.__NEXT_DATA__ = { nextExport: true, @@ -114,7 +113,7 @@ export default async function({ const baseDir = join(outDir, dirname(htmlFilename)) let htmlFilepath = join(outDir, htmlFilename) - await mkdirp(baseDir) + await mkdir(baseDir, { recursive: true }) let html let curRenderOpts = {} let renderMethod = renderToHTML @@ -254,7 +253,7 @@ export default async function({ } await validateAmp(ampHtml, page + '?amp=1') - await mkdirp(ampBaseDir) + await mkdir(ampBaseDir, { recursive: true }) await writeFileP(ampHtmlFilepath, ampHtml, 'utf8') } } @@ -265,7 +264,7 @@ export default async function({ htmlFilename.replace(/\.html$/, '.json') ) - await mkdirp(dirname(dataFile)) + await mkdir(dirname(dataFile), { recursive: true }) await writeFileP(dataFile, JSON.stringify(curRenderOpts.pageData), 'utf8') } results.fromBuildExportRevalidate = curRenderOpts.revalidate diff --git a/packages/next/next-server/server/spr-cache.ts b/packages/next/next-server/server/spr-cache.ts index 65b0de02e47e0..87deb0707539b 100644 --- a/packages/next/next-server/server/spr-cache.ts +++ b/packages/next/next-server/server/spr-cache.ts @@ -1,13 +1,12 @@ import fs from 'fs' import LRUCache from 'lru-cache' -import mkdirpOrig from 'mkdirp' import path from 'path' import { promisify } from 'util' import { PrerenderManifest } from '../../build' import { PRERENDER_MANIFEST } from '../lib/constants' import { normalizePagePath } from './normalize-page-path' -const mkdirp = promisify(mkdirpOrig) +const mkdir = promisify(fs.mkdir) const readFile = promisify(fs.readFile) const writeFile = promisify(fs.writeFile) @@ -183,7 +182,7 @@ export async function setSprCache( if (sprOptions.flushToDisk) { try { const seedPath = getSeedPath(pathname, 'html') - await mkdirp(path.dirname(seedPath)) + await mkdir(path.dirname(seedPath), { recursive: true }) await writeFile(seedPath, data.html, 'utf8') await writeFile( getSeedPath(pathname, 'json'), diff --git a/packages/next/package.json b/packages/next/package.json index cd1053d8c8e87..d42b384d40f91 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -114,7 +114,6 @@ "lodash.curry": "4.1.1", "lru-cache": "5.1.1", "mini-css-extract-plugin": "0.8.0", - "mkdirp": "0.5.1", "native-url": "0.2.6", "node-fetch": "2.6.0", "ora": "3.4.0", @@ -175,7 +174,6 @@ "@types/lodash.curry": "4.1.6", "@types/lru-cache": "5.1.0", "@types/mini-css-extract-plugin": "0.8.0", - "@types/mkdirp": "0.5.2", "@types/nanoid": "2.0.0", "@types/node-fetch": "2.3.4", "@types/react": "16.9.17", diff --git a/test/integration/create-next-app/index.test.js b/test/integration/create-next-app/index.test.js index c60777c3e85df..c7bb146dd1b6d 100644 --- a/test/integration/create-next-app/index.test.js +++ b/test/integration/create-next-app/index.test.js @@ -1,12 +1,8 @@ /* eslint-env jest */ -import mkdirpModule from 'mkdirp' import path from 'path' -import fs from 'fs' +import fs from 'fs-extra' import execa from 'execa' import os from 'os' -import { promisify } from 'util' - -const mkdirp = promisify(mkdirpModule) const cli = require.resolve('create-next-app/dist/index.js') const cwd = path.join( @@ -21,13 +17,13 @@ const run = (...args) => execa('node', [cli, ...args], { cwd }) describe('create next app', () => { beforeAll(async () => { jest.setTimeout(1000 * 60) - await mkdirp(cwd) + await fs.mkdirp(cwd) }) it('non-empty directory', async () => { const projectName = 'non-empty-directory' - await mkdirp(path.join(cwd, projectName)) + await fs.mkdirp(path.join(cwd, projectName)) const pkg = path.join(cwd, projectName, 'package.json') fs.writeFileSync(pkg, '{ "foo": "bar" }') diff --git a/yarn.lock b/yarn.lock index 2a449b0016e38..668c42fee2964 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2707,13 +2707,6 @@ dependencies: "@types/node" "*" -"@types/mkdirp@0.5.2": - version "0.5.2" - resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.5.2.tgz#503aacfe5cc2703d5484326b1b27efa67a339c1f" - integrity sha512-U5icWpv7YnZYGsN4/cmh3WD2onMY0aJIiTE6+51TwJCttdHvtCYmkBNOobHlXwrJRL0nkH9jH4kD+1FAdMN4Tg== - dependencies: - "@types/node" "*" - "@types/nanoid@2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@types/nanoid/-/nanoid-2.0.0.tgz#b59002c475e6dfcc26e67ba563ff61b512e5ebf8" @@ -3681,6 +3674,11 @@ asyncro@^3.0.0: resolved "https://registry.yarnpkg.com/asyncro/-/asyncro-3.0.0.tgz#3c7a732e263bc4a42499042f48d7d858e9c0134e" integrity sha512-nEnWYfrBmA3taTiuiOoZYmgJ/CNrSoQLeLs29SeLcPu60yaw/mHDBHV0iOZ051fTvsTHxpCY+gXibqT9wbQYfg== +at-least-node@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" + integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== + atob-lite@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/atob-lite/-/atob-lite-2.0.0.tgz#0fef5ad46f1bd7a8502c65727f0367d5ee43d696" @@ -7386,6 +7384,16 @@ fs-extra@7.0.1, fs-extra@^7.0.0: jsonfile "^4.0.0" universalify "^0.1.0" +fs-extra@9.0.0: + version "9.0.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.0.tgz#b6afc31036e247b2466dc99c29ae797d5d4580a3" + integrity sha512-pmEYSk3vYsG/bF651KPUXZ+hvjpgWYw/Gc7W9NFUe3ZVLczKKWIij3IKpOrQcdw4TILtibFslZ0UmR8Vvzig4g== + dependencies: + at-least-node "^1.0.0" + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^1.0.0" + fs-extra@^8.0.0: version "8.1.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0" @@ -9617,6 +9625,15 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" +jsonfile@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.0.1.tgz#98966cba214378c8c84b82e085907b40bf614179" + integrity sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg== + dependencies: + universalify "^1.0.0" + optionalDependencies: + graceful-fs "^4.1.6" + jsonparse@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280" @@ -10829,7 +10846,7 @@ mk-dirs@^1.0.0: resolved "https://registry.yarnpkg.com/mk-dirs/-/mk-dirs-1.0.0.tgz#44ee67f82341c6762718e88e85e577882e1f67fd" integrity sha1-RO5n+CNBxnYnGOiOheV3iC4fZ/0= -mkdirp@0.5.1, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: +"mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM= @@ -16459,6 +16476,11 @@ universalify@^0.1.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== +universalify@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d" + integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug== + unpipe@1.0.0, unpipe@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"