From 0d965b74059ad34f6fbc9d35b70449401c02269f Mon Sep 17 00:00:00 2001 From: Espen Hovlandsdal Date: Thu, 28 Sep 2017 15:59:58 +0200 Subject: [PATCH] [chore] Replace fs-promise with fs-extra (#219) --- packages/@sanity/check/package.json | 2 +- packages/@sanity/check/src/bin.js | 4 ++-- packages/@sanity/check/src/sanityCheck.js | 8 ++++---- packages/@sanity/core/package.json | 3 ++- .../core/src/actions/build/buildStaticAssets.js | 8 ++++---- .../core/src/actions/build/compressJavascript.js | 8 ++++---- .../actions/config/reinitializePluginConfigs.js | 4 ++-- .../core/src/actions/deploy/deployAction.js | 6 +++--- .../@sanity/core/src/actions/exec/execScript.js | 4 ++-- .../src/commands/dataset/exportDatasetCommand.js | 8 ++++---- .../src/commands/dataset/importDatasetCommand.js | 4 ++-- .../core/src/commands/install/installCommand.js | 8 ++++---- .../src/commands/uninstall/uninstallCommand.js | 6 +++--- .../core/src/util/generateConfigChecksum.js | 4 ++-- .../core/src/util/pluginChecksumManifest.js | 8 ++++---- packages/@sanity/resolver/package.json | 2 +- packages/@sanity/resolver/src/readManifest.js | 6 +++--- packages/@sanity/util/package.json | 2 +- packages/@sanity/util/src/addPluginToManifest.js | 14 ++++++-------- packages/@sanity/util/src/readLocalManifest.js | 4 ++-- packages/@sanity/util/src/safeJson.js | 9 +++++---- 21 files changed, 61 insertions(+), 61 deletions(-) diff --git a/packages/@sanity/check/package.json b/packages/@sanity/check/package.json index 0fa636a867b..296ebc228cc 100644 --- a/packages/@sanity/check/package.json +++ b/packages/@sanity/check/package.json @@ -20,7 +20,7 @@ "@sanity/generate-help-url": "^0.113.7", "@sanity/resolver": "^0.113.7", "chalk": "^1.1.3", - "fs-promise": "^2.0.0", + "fs-extra": "^4.0.2", "in-publish": "^2.0.0", "promise-props-recursive": "^1.0.0" }, diff --git a/packages/@sanity/check/src/bin.js b/packages/@sanity/check/src/bin.js index a8b8db7ab61..72590924a14 100755 --- a/packages/@sanity/check/src/bin.js +++ b/packages/@sanity/check/src/bin.js @@ -1,7 +1,7 @@ #!/usr/bin/env node /* eslint-disable no-console, no-process-env, no-process-exit */ const path = require('path') -const fsp = require('fs-promise') +const fse = require('fs-extra') const chalk = require('chalk') const publish = require('in-publish') const sanityCheck = require('./sanityCheck') @@ -39,7 +39,7 @@ if (showVersion) { process.exit() } -fsp.readJson(manifestDir) +fse.readJson(manifestDir) .catch(err => { console.error(chalk.red( `${tag} Failed to read "${manifestDir}":\n${err.message}` diff --git a/packages/@sanity/check/src/sanityCheck.js b/packages/@sanity/check/src/sanityCheck.js index 1c8afdb5ada..92e3db5d344 100644 --- a/packages/@sanity/check/src/sanityCheck.js +++ b/packages/@sanity/check/src/sanityCheck.js @@ -1,5 +1,5 @@ const path = require('path') -const fsp = require('fs-promise') +const fse = require('fs-extra') const promiseProps = require('promise-props-recursive') const generateHelpUrl = require('@sanity/generate-help-url') const resolveParts = require('@sanity/resolver').resolveParts @@ -56,7 +56,7 @@ function throwOnErrors(results, options) { function getFolderContents(dirs) { return promiseProps(dirs.reduce((folders, dir) => { if (!folders[dir]) { - folders[dir] = fsp.readdir(dir).catch(() => []) + folders[dir] = fse.readdir(dir).catch(() => []) } return folders }, {})) @@ -106,7 +106,7 @@ function checkImplementationMsg(impl) { } function isFileOrDirectoryWithIndex(impl) { - return fsp.stat(impl.path).then(stats => { + return fse.stat(impl.path).then(stats => { return stats.isDirectory() ? directoryHasIndex(impl) : true @@ -117,7 +117,7 @@ function isFileOrDirectoryWithIndex(impl) { } function directoryHasIndex(impl) { - return fsp.readdir(impl.path).then(dirContent => { + return fse.readdir(impl.path).then(dirContent => { return includes(dirContent, 'index.js') ? true : new Error( diff --git a/packages/@sanity/core/package.json b/packages/@sanity/core/package.json index 02d6d54b8ff..d25f2d00f04 100644 --- a/packages/@sanity/core/package.json +++ b/packages/@sanity/core/package.json @@ -28,7 +28,7 @@ "debug": "^2.6.3", "deep-sort-object": "^1.0.1", "filesize": "^3.5.6", - "fs-promise": "^2.0.0", + "fs-extra": "^4.0.2", "get-uri": "^2.0.1", "got": "^6.7.1", "json-lexer": "^1.1.1", @@ -42,6 +42,7 @@ "simple-concat": "^1.0.0", "split2": "^2.1.1", "tar-fs": "^1.15.2", + "thenify": "^3.3.0", "through2": "^2.0.3", "uglify-js": "^3.0.23" }, diff --git a/packages/@sanity/core/src/actions/build/buildStaticAssets.js b/packages/@sanity/core/src/actions/build/buildStaticAssets.js index e8836a049b8..3909af21a15 100644 --- a/packages/@sanity/core/src/actions/build/buildStaticAssets.js +++ b/packages/@sanity/core/src/actions/build/buildStaticAssets.js @@ -1,4 +1,4 @@ -import fsp from 'fs-promise' +import fse from 'fs-extra' import path from 'path' import rimTheRaf from 'rimraf' import thenify from 'thenify' @@ -81,7 +81,7 @@ export default async (args, context) => { bundle.stats = stats if (flags.profile) { - await fsp.writeFile( + await fse.writeFile( path.join(workDir, 'build-stats.json'), JSON.stringify(statistics.toJson('verbose')) ) @@ -101,7 +101,7 @@ export default async (args, context) => { }) // Write index file to output destination - await fsp.writeFile( + await fse.writeFile( path.join(outputDir, 'index.html'), `${ReactDOM.renderToStaticMarkup(doc)}` ) @@ -133,7 +133,7 @@ export default async (args, context) => { } // Copy static assets (from /static folder) to output dir - await fsp.copy(path.join(workDir, 'static'), path.join(outputDir, 'static'), {overwrite: false}) + await fse.copy(path.join(workDir, 'static'), path.join(outputDir, 'static'), {overwrite: false}) } catch (err) { spin.fail() throw err diff --git a/packages/@sanity/core/src/actions/build/compressJavascript.js b/packages/@sanity/core/src/actions/build/compressJavascript.js index 9660c1b5701..0eabcf41df2 100644 --- a/packages/@sanity/core/src/actions/build/compressJavascript.js +++ b/packages/@sanity/core/src/actions/build/compressJavascript.js @@ -1,4 +1,4 @@ -import fsp from 'fs-promise' +import fse from 'fs-extra' import {spawn} from 'child_process' import concat from 'simple-concat' @@ -7,10 +7,10 @@ export default inputFile => { const sourceFile = `${inputFile}.source` return new Promise(async (resolve, reject) => { - await fsp.rename(inputFile, sourceFile) + await fse.rename(inputFile, sourceFile) const uglify = spawn(uglifyPath, ['-c', '-m', '--', sourceFile]) - uglify.stdout.pipe(fsp.createWriteStream(inputFile)) + uglify.stdout.pipe(fse.createWriteStream(inputFile)) let error = '' concat(uglify.stderr, (err, buf) => { @@ -26,7 +26,7 @@ export default inputFile => { return reject(new Error(error)) } - await fsp.unlink(sourceFile) + await fse.unlink(sourceFile) return resolve() }) }) diff --git a/packages/@sanity/core/src/actions/config/reinitializePluginConfigs.js b/packages/@sanity/core/src/actions/config/reinitializePluginConfigs.js index 3b5c5d321e2..cabd93aae29 100644 --- a/packages/@sanity/core/src/actions/config/reinitializePluginConfigs.js +++ b/packages/@sanity/core/src/actions/config/reinitializePluginConfigs.js @@ -1,6 +1,6 @@ import path from 'path' import pathExists from 'path-exists' -import fsp from 'fs-promise' +import fse from 'fs-extra' import resolveTree from '@sanity/resolver' import normalizePluginName from '../../util/normalizePluginName' import generateConfigChecksum from '../../util/generateConfigChecksum' @@ -39,7 +39,7 @@ export default async function reinitializePluginConfigs(options, flags = {}) { output.print(`Plugin "${plugin.name}" is missing local configuration file, creating ${prtPath}`) } - return fsp.copy(srcPath, dstPath).then(() => plugin) + return fse.copy(srcPath, dstPath).then(() => plugin) } function warnOnDifferingChecksum(plugin) { diff --git a/packages/@sanity/core/src/actions/deploy/deployAction.js b/packages/@sanity/core/src/actions/deploy/deployAction.js index 88652331068..2ee475fe9ca 100644 --- a/packages/@sanity/core/src/actions/deploy/deployAction.js +++ b/packages/@sanity/core/src/actions/deploy/deployAction.js @@ -1,6 +1,6 @@ import path from 'path' import zlib from 'zlib' -import fsp from 'fs-promise' +import fse from 'fs-extra' import tar from 'tar-fs' import lazyRequire from '@sanity/util/lib/lazyRequire' @@ -80,7 +80,7 @@ export default async (args, context) => { async function checkDir(sourceDir) { try { - const stats = await fsp.stat(sourceDir) + const stats = await fse.stat(sourceDir) if (!stats.isDirectory()) { throw new Error(`Directory ${sourceDir} is not a directory`) } @@ -93,7 +93,7 @@ async function checkDir(sourceDir) { } try { - await fsp.stat(path.join(sourceDir, 'index.html')) + await fse.stat(path.join(sourceDir, 'index.html')) } catch (err) { const error = err.code === 'ENOENT' ? new Error([ `"${sourceDir}/index.html" does not exist -`, diff --git a/packages/@sanity/core/src/actions/exec/execScript.js b/packages/@sanity/core/src/actions/exec/execScript.js index 58227570d04..36e119a9185 100644 --- a/packages/@sanity/core/src/actions/exec/execScript.js +++ b/packages/@sanity/core/src/actions/exec/execScript.js @@ -1,5 +1,5 @@ const spawn = require('child_process').spawn -const fsp = require('fs-promise') +const fse = require('fs-extra') const path = require('path') module.exports = async args => { @@ -10,7 +10,7 @@ module.exports = async args => { throw new Error('SCRIPT must be provided. `sanity exec