Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove mkdirp, bump fs-extra to 9.0.0 #11251

Merged
merged 4 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -301,7 +300,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
})),
}

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')
Expand Down Expand Up @@ -755,7 +754,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
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)
}

Expand Down
3 changes: 1 addition & 2 deletions packages/next/build/profiler/profiler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path'
import mkdirp from 'mkdirp'
import fs from 'fs'

let inspector
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
})
Expand Down
11 changes: 5 additions & 6 deletions packages/next/export/worker.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
}
}
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions packages/next/next-server/server/spr-cache.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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'),
Expand Down
2 changes: 0 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions test/integration/create-next-app/index.test.js
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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" }')

Expand Down
38 changes: 30 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2707,13 +2707,6 @@
dependencies:
"@types/node" "*"

"@types/[email protected]":
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/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/nanoid/-/nanoid-2.0.0.tgz#b59002c475e6dfcc26e67ba563ff61b512e5ebf8"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -7386,6 +7384,16 @@ [email protected], fs-extra@^7.0.0:
jsonfile "^4.0.0"
universalify "^0.1.0"

[email protected]:
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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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=

[email protected], "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=
Expand Down Expand Up @@ -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==

[email protected], unpipe@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
Expand Down