diff --git a/cli/bin/build.js b/cli/bin/build.js index d238c84afe1..c02583446eb 100644 --- a/cli/bin/build.js +++ b/cli/bin/build.js @@ -2,6 +2,7 @@ const {resolve, relative, join} = require('path') const {spawnSync} = require('child_process') const build = require('../lib/build.js') const {nwo} = require('../lib/gh') +const {CacheVersionSha} = require('../lib/cache.js') // check only build with the current versions instead of checking the registry // and also fails if any changes are detected. this is used in CI to make sure @@ -24,21 +25,23 @@ const checkContent = () => { } } -build({ - releases: require('../releases.json'), - loglevel: process.argv.includes('--debug') || process.env.CI ? 'verbose' : 'info', - prerelease: false, - useCurrent: checkOnly, - contentPath, - navPath, -}) - .then(() => { +;(async () => { + try { + await build({ + cache: await CacheVersionSha.load(join(ROOT, 'cache.json')), + releases: require('../releases.json'), + loglevel: process.argv.includes('--debug') || process.env.CI ? 'verbose' : 'info', + prerelease: false, + useCurrent: checkOnly, + contentPath, + navPath, + }) if (checkOnly) { checkContent() } return console.log('DONE') - }) - .catch(e => { + } catch (e) { console.error(e) process.exit(1) - }) + } +})() diff --git a/cli/lib/build.js b/cli/lib/build.js index ee378fe1f76..4f7b6be5298 100644 --- a/cli/lib/build.js +++ b/cli/lib/build.js @@ -5,7 +5,6 @@ const semver = require('semver') const pacote = require('pacote') const extractRelease = require('./extract') const log = require('./log') -const {CacheVersionSha} = require('./cache') const DOCS_PATH = 'cli' @@ -56,7 +55,7 @@ const getCurrentVersions = nav => { } } -const main = async ({loglevel, releases: rawReleases, useCurrent, navPath, contentPath, prerelease}) => { +const main = async ({loglevel, releases: rawReleases, useCurrent, navPath, contentPath, prerelease, cache}) => { /* istanbul ignore next */ if (loglevel) { log.on(loglevel) @@ -114,13 +113,11 @@ const main = async ({loglevel, releases: rawReleases, useCurrent, navPath, conte } }) - const cache = await CacheVersionSha.load() - const updates = await Promise.all( releases.map(r => extractRelease(r, {cache, contentPath, baseNav: navData, prerelease})), ).then(r => r.filter(Boolean)) - await cache.save() + await cache?.save() await updateNav(updates, {nav: navDoc, path: navPath}) } diff --git a/cli/lib/cache.js b/cli/lib/cache.js index c9d3dd265e0..3e0dabc8c4b 100644 --- a/cli/lib/cache.js +++ b/cli/lib/cache.js @@ -1,20 +1,18 @@ -const {join} = require('path') const fs = require('fs/promises') /** cache npm cli version shas to NOT pull down changes we already have */ class CacheVersionSha { - constructor(cache) { + constructor(cache, path) { this.cache = cache + this.path = path } - static path = join(__dirname, '../../content/cli/cache.json') - - static async load() { - return new CacheVersionSha(JSON.parse(await fs.readFile(this.path, 'utf-8'))) + static async load(path) { + return new CacheVersionSha(JSON.parse(await fs.readFile(path, 'utf-8')), path) } async save() { - await fs.writeFile(CacheVersionSha.path, JSON.stringify(this.cache, null, 2)) + await fs.writeFile(this.path, JSON.stringify(this.cache, null, 2)) return this } diff --git a/cli/test/index.js b/cli/test/index.js index 8771518c6c8..99a62ca2b13 100644 --- a/cli/test/index.js +++ b/cli/test/index.js @@ -83,29 +83,6 @@ const mockBuild = async (t, {releases = getReleases(), packument = {}, testdir: }, }, '@prettier/sync': {format: s => s}, - '../lib/cache.js': { - CacheVersionSha: class CacheVersionSha { - constructor() { - this.cache = {} - } - - static async load() { - return new CacheVersionSha() - } - - async save() { - return this - } - - set() { - return this - } - - same() { - return false - } - }, - }, '../lib/gh.js': { getCurrentSha: async () => { shaCounter = shaCounter + 1 diff --git a/content/cli/cache.json b/content/cli/cache.json deleted file mode 100644 index e2a223edc9c..00000000000 --- a/content/cli/cache.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "v6": "abc1", - "v7": "abc2", - "v8": "abc3", - "v9": "abc4" -} \ No newline at end of file