Skip to content

Commit

Permalink
perf: add npmPersist helper with debug notice
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Sep 19, 2023
1 parent 3515d53 commit 3790f4d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/main/js/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export const fetchManifest = async (pkg, {nothrow} = {}) => {
}
}

export const npmPersist = async (pkg) => {
const {name, version, manifest, manifestAbsPath} = pkg
log({pkg})(`updating ${manifestAbsPath} inners: ${name} ${version}`)
await fs.writeJson(manifestAbsPath, manifest, {spaces: 2})
}

export const npmRestore = async (pkg) => {
const {manifestRaw, manifestAbsPath} = pkg
log({pkg})(`rolling back ${manifestAbsPath} inners to manifestRaw`)
await fs.writeFile(manifestAbsPath, manifestRaw, {encoding: 'utf8'})
}

export const npmPublish = async (pkg) => {
const {absPath: cwd, name, version, manifest, config: {npmPublish, npmRegistry, npmToken, npmConfig, npmProvenance}} = pkg

Expand Down
10 changes: 4 additions & 6 deletions src/main/js/processor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'node:os'
import {createRequire} from 'node:module'
import {$, fs, within} from 'zx-extra'
import {$, within} from 'zx-extra'
import {queuefy} from 'queuefy'
import {analyze} from './analyze.js'
import {pushChangelog} from './changelog.js'
Expand All @@ -10,7 +10,7 @@ import {ghPages, ghRelease} from './gh.js'
import {getRoot, getSha, unsetUserConfig} from './git.js'
import {log, createReport} from './log.js'
import {getLatest, pushMeta, pushReleaseTag} from './meta.js'
import {fetchPkg, npmPublish} from './npm.js'
import {fetchPkg, npmPersist, npmPublish, npmRestore} from './npm.js'
import {memoizeBy, tpl} from './util.js'

export const run = async ({cwd = process.cwd(), env, flags = {}} = {}) => within(async () => {
Expand Down Expand Up @@ -153,7 +153,7 @@ const publish = memoizeBy(async (pkg, run = runCmd) => within(async () => {
throw new Error('package.json version not synced')
}

await fs.writeJson(pkg.manifestPath, pkg.manifest, {spaces: 2})
await npmPersist(pkg)

if (pkg.context.flags.snapshot) {
await Promise.all([
Expand All @@ -176,7 +176,5 @@ const publish = memoizeBy(async (pkg, run = runCmd) => within(async () => {

const clean = async (cwd, packages) => {
await unsetUserConfig(cwd)
await Promise.all(Object.values(packages).map(({manifestPath, manifestRaw}) =>
fs.writeFile(manifestPath, manifestRaw, {encoding: 'utf8'})
))
await Promise.all(Object.values(packages).map(npmRestore))
}

0 comments on commit 3790f4d

Please sign in to comment.