diff --git a/lib/helpers/construct-polyfill-url.js b/lib/helpers/construct-polyfill-url.js index bb46b316..058e1d9f 100644 --- a/lib/helpers/construct-polyfill-url.js +++ b/lib/helpers/construct-polyfill-url.js @@ -2,8 +2,7 @@ const path = require('path'); const globby = require('globby'); -const denodeify = require('util').promisify; -const readFile = denodeify(require('fs-extra').readFile); +const { readFile } = require('fs/promises'); async function constructBrowserDeps() { const dependencies = await globby(['node_modules/*/*/origami.json', 'node_modules/*/origami.json', 'origami.json']); diff --git a/lib/helpers/files.js b/lib/helpers/files.js index 6a378e69..8f9e1ab2 100644 --- a/lib/helpers/files.js +++ b/lib/helpers/files.js @@ -1,12 +1,11 @@ 'use strict'; -const fs = require('fs-extra'); +const { readFile, open } = require('fs/promises'); const path = require('path'); const denodeify = require('util').promisify; const deglob = denodeify(require('deglob')); -const fileExists = (file) => denodeify(fs.open)(file, 'r').then(() => true).catch(() => false); -const readFile = denodeify(fs.readFile); +const fileExists = (file) => open(file, 'r').then(() => true).catch(() => false); function getBuildFolderPath(cwd) { cwd = cwd || process.cwd(); diff --git a/lib/tasks/demo.js b/lib/tasks/demo.js index 147cd99e..4e64c2df 100644 --- a/lib/tasks/demo.js +++ b/lib/tasks/demo.js @@ -3,9 +3,7 @@ const Listr = require('listr'); const ListrRenderer = require('../helpers/listr-renderer'); const path = require('path'); -const fs = require('fs'); -const denodeify = require('util').promisify; -const readFile = denodeify(fs.readFile); +const {readFile} = require('fs/promises'); const buildDemo = require('./demo-build'); module.exports = function (cfg) { diff --git a/lib/tasks/test-sass-compilation.js b/lib/tasks/test-sass-compilation.js index e76ff47d..0ab52f43 100644 --- a/lib/tasks/test-sass-compilation.js +++ b/lib/tasks/test-sass-compilation.js @@ -6,12 +6,10 @@ const ListrRenderer = require('../helpers/listr-renderer'); const isCI = require('is-ci'); const { camelCase } = require('lodash'); const ftSass = require('@financial-times/sass'); -const denodeify = require('util').promisify; -const fsOpen = denodeify(require('fs').open); -const { readFile } = require('fs/promises'); +const { readFile, open } = require('fs/promises'); const execa = require('execa'); -const fileExists = file => fsOpen(file, 'r').then(() => true).catch(() => false); +const fileExists = file => open(file, 'r').then(() => true).catch(() => false); async function compilationTest(cwd, { silent, brand } = { silent: false, brand: false diff --git a/lib/tasks/test-sass.js b/lib/tasks/test-sass.js index 1eba699f..68e69915 100644 --- a/lib/tasks/test-sass.js +++ b/lib/tasks/test-sass.js @@ -1,12 +1,9 @@ "use strict"; const commandLine = require("../helpers/command-line"); -const denodeify = require("util").promisify; const files = require("../helpers/files"); -const fs = require("fs"); +const { writeFile, unlink } = require("fs/promises"); const path = require("path"); -const writeFile = denodeify(fs.writeFile); -const unlink = denodeify(fs.unlink); const trueTest = function(config, task) { const testRunner = path.join(config.cwd, "test/scss/test-runner.js"); diff --git a/lib/tasks/verify-javascript.js b/lib/tasks/verify-javascript.js index daa941f5..16addadd 100644 --- a/lib/tasks/verify-javascript.js +++ b/lib/tasks/verify-javascript.js @@ -5,11 +5,11 @@ const path = require('path'); const ESLint = require('eslint').ESLint; const denodeify = require('util').promisify; const deglob = denodeify(require('deglob')); -const fs = require('fs-extra'); +const { open } = require('fs/promises'); const log = require('../helpers/log'); const isCI = require('is-ci'); -const fileExists = file => denodeify(fs.open)(file, 'r').then(() => true).catch(() => false); +const fileExists = file => open(file, 'r').then(() => true).catch(() => false); async function lint (config) { const hasJS = await projectHasJavaScriptFiles(config); diff --git a/lib/tasks/verify-origami-json.js b/lib/tasks/verify-origami-json.js index fec79a76..be59f39b 100644 --- a/lib/tasks/verify-origami-json.js +++ b/lib/tasks/verify-origami-json.js @@ -1,13 +1,11 @@ 'use strict'; const process = require('process'); -const fs = require('fs'); +const { readFile, open} = require('fs/promises'); const path = require('path'); -const denodeify = require('util').promisify; const isCI = require('is-ci'); -const fileExists = file => denodeify(fs.open)(file, 'r').then(() => true).catch(() => false); -const readFile = denodeify(fs.readFile); +const fileExists = file => open(file, 'r').then(() => true).catch(() => false); // https://origami.ft.com/docs/manifests/origami-json/#origamitype // "component": A front-end component that follows the component specification diff --git a/lib/tasks/verify-package-json.js b/lib/tasks/verify-package-json.js index f1021531..a48675d0 100644 --- a/lib/tasks/verify-package-json.js +++ b/lib/tasks/verify-package-json.js @@ -1,14 +1,12 @@ 'use strict'; const process = require('process'); -const fs = require('fs'); +const { readFile, open } = require('fs/promises'); const path = require('path'); -const denodeify = require('util').promisify; const isCI = require('is-ci'); const semver = require('semver'); -const fileExists = file => denodeify(fs.open)(file, 'r').then(() => true).catch(() => false); -const readFile = denodeify(fs.readFile); +const fileExists = file => open(file, 'r').then(() => true).catch(() => false); /** * Checks whether description conforms to the origami package.json description specification. @@ -64,11 +62,11 @@ function validEngines(engines) { * Checks whether browser conforms to the origami package.json browser specification. * @param {any} manifest The manifest to check * @param {string} workingDirectory The directory which contains the component to check - * @returns {string|void} If valid, returns undefined, otherwise returns a string which explains why it is not valid + * @returns {Promise} If valid, returns undefined, otherwise returns a string which explains why it is not valid */ -function validJavaScriptEntryPoint(manifest, workingDirectory) { +async function validJavaScriptEntryPoint(manifest, workingDirectory) { const mainJavaScriptExpectedPath = path.resolve(path.join(workingDirectory, '/main.js')); - const mainJavaScriptFileExists = fs.existsSync(mainJavaScriptExpectedPath); + const mainJavaScriptFileExists = await fileExists(mainJavaScriptExpectedPath); if (mainJavaScriptFileExists) { if (typeof manifest.browser === 'string') { const browserPathIsCorrect = path.resolve(manifest.browser) === mainJavaScriptExpectedPath; @@ -129,7 +127,7 @@ async function packageJson(config) { result.push('The engines property is required. It must have the npm property set to a SemVer range which disallows versions lower than 7.0.0.'); } - const invalidExplanation = validJavaScriptEntryPoint(packageJson, config.cwd); + const invalidExplanation = await validJavaScriptEntryPoint(packageJson, config.cwd); if (invalidExplanation) { result.push(invalidExplanation); } diff --git a/lib/tasks/verify-readme.js b/lib/tasks/verify-readme.js index 97179b28..122e562e 100644 --- a/lib/tasks/verify-readme.js +++ b/lib/tasks/verify-readme.js @@ -1,27 +1,23 @@ 'use strict'; const process = require('process'); -const { - promises: {readFile}, -} = require('fs'); +const { readFile, open } = require('fs/promises'); const path = require('path'); const isCI = require('is-ci'); const vfile = require('vfile'); -const fs = require('fs-extra'); const remark = require('remark'); const remarkLint = require('remark-lint'); const report = require('vfile-reporter'); const log = require('../helpers/log'); -const denodeify = require('util').promisify; -const fileExists = file => denodeify(fs.open)(file, 'r').then(() => true).catch(() => false); +const fileExists = file => open(file, 'r').then(() => true).catch(() => false); async function origamiJson(config) { // Error if there is no readme to verify. const uppercaseReadmePath = path.join(config.cwd, '/README.md'); - const hasUppercaseReadme = await fs.exists(uppercaseReadmePath); + const hasUppercaseReadme = await fileExists(uppercaseReadmePath); const lowercaseReadmePath = path.join(config.cwd, '/readme.md'); - const hasLowercaseReadme = await fs.exists(lowercaseReadmePath); + const hasLowercaseReadme = await fileExists(lowercaseReadmePath); if (!hasUppercaseReadme && !hasLowercaseReadme) { throw new Error('Components require a README.md with documentation.'); } diff --git a/lib/tasks/verify-sass.js b/lib/tasks/verify-sass.js index f99e4b78..9ea1eaa6 100644 --- a/lib/tasks/verify-sass.js +++ b/lib/tasks/verify-sass.js @@ -4,11 +4,11 @@ const process = require('process'); const path = require('path'); const denodeify = require('util').promisify; const deglob = denodeify(require('deglob')); -const fs = require('fs-extra'); +const { open } = require('fs/promises'); const isCI = require('is-ci'); const execa = require('execa'); -const fileExists = file => denodeify(fs.open)(file, 'r').then(() => true).catch(() => false); +const fileExists = file => open(file, 'r').then(() => true).catch(() => false); async function sassLint(config) { const hasScss = await projectHasScssFiles(config); diff --git a/test/integration/helpers/fileExists.js b/test/integration/helpers/fileExists.js index dc5db84f..19729ef9 100644 --- a/test/integration/helpers/fileExists.js +++ b/test/integration/helpers/fileExists.js @@ -1,7 +1,6 @@ 'use strict'; -const denodeify = require('util').promisify; -const open = denodeify(require('fs-extra').open); +const open = require('fs/promises').open; /** * Node.JS no longer has an fs.exists method. diff --git a/test/integration/helpers/obtpath.js b/test/integration/helpers/obtpath.js index 98a326de..04ffdc20 100644 --- a/test/integration/helpers/obtpath.js +++ b/test/integration/helpers/obtpath.js @@ -1,10 +1,8 @@ 'use strict'; -const denodeify = require('util').promisify; -const fs = require('fs-extra'); +const { readFile } = require('fs/promises'); const path = require('path'); -const readFile = denodeify(fs.readFile); module.exports = function obtBin() { return readFile(path.join(__dirname, '../../../package.json')) diff --git a/test/integration/verify/verify.test.js b/test/integration/verify/verify.test.js index 17d76d08..5b268702 100644 --- a/test/integration/verify/verify.test.js +++ b/test/integration/verify/verify.test.js @@ -7,11 +7,11 @@ const process = require('process'); const proclaim = require('proclaim'); const obtBinPath = require('../helpers/obtpath'); const rimraf = require('../helpers/delete'); -const fs = require('fs'); -const { promisify } = require('util'); -const writeFile = promisify(fs.writeFile); +const { writeFile, open } = require('fs/promises'); const tmpdir = require('../helpers/tmpdir'); +const fileExists = file => open(file, 'r').then(() => true).catch(() => false); + describe('obt verify', function () { let obt; @@ -94,7 +94,7 @@ describe('obt verify', function () { const folder = await tmpdir('obt-verify-task-'); const filePath = path.join(folder, 'testFilesystemCaseSensitivity.txt'); await writeFile(path.join(folder, 'testFilesystemCaseSensitivity.txt'), "hello", "utf8"); - const caseSensitiveFileSystem = fs.existsSync(filePath.toUpperCase()); + const caseSensitiveFileSystem = await fileExists(filePath.toUpperCase()); // Do not run this test on case-insensitive filesystems because it will fail. if (!caseSensitiveFileSystem) { return execa(obt, ['verify']) diff --git a/test/unit/helpers/construct-polyfill-url.test.js b/test/unit/helpers/construct-polyfill-url.test.js index 920ce7aa..3f1e2ed8 100644 --- a/test/unit/helpers/construct-polyfill-url.test.js +++ b/test/unit/helpers/construct-polyfill-url.test.js @@ -12,22 +12,18 @@ describe('construct-polyfill-url', function() { let globby; let constructPolyfillUrl; let fs; - let denodeify; beforeEach(function() { fs = { readFile: sinon.stub() }; globby = sinon.stub(); - denodeify = sinon.stub().returnsArg(0); mockery.enable({ useCleanCache: true, warnOnReplace: false, warnOnUnregistered: false }); - mockery.registerMock('fs-extra', fs); - - mockery.registerMock('util', {promisify:denodeify}); + mockery.registerMock('fs/promises', fs); mockery.registerMock('globby', globby);