Skip to content
Merged
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
59 changes: 29 additions & 30 deletions scripts/publish.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
const semver = require('semver')
const log = require('proc-log')
const pacote = require('pacote')
const { run, git, npm, pkg, spawn } = require('./util.js')
const { run, git, npm, pkg: cli, spawn } = require('./util.js')

const resetdeps = () => npm('run', 'resetdeps')

const op = () => spawn('op', 'item', 'get', 'npm', '--otp', { out: true, ok: true })

const TAGS = {
// cli is always published to next-MAJOR
root: (v) => ({ tag: `next-${semver.major(v)}` }),
// workspaces are always published to latest, except prereleases
workspace: () => ({ tag: 'latest', preTag: 'prerelease' }),
const getVersion = async (s) => {
const mani = await pacote.manifest(s, { preferOnline: true })
return mani.version
}
const getLatest = async (s) => {
const pack = await pacote.packument(s, { preferOnline: true })
return pack['dist-tags'].latest
}

const TAG = {
cli: ({ version }) => `next-${semver.major(version)}`,
workspace: async ({ name, version }) => {
const { prerelease, major } = semver.parse(version)
if (prerelease.length) {
return 'prerelease'
}
if (major === await getLatest(name).then(v => semver.major(v))) {
return 'latest'
}
return 'backport'
},
}

const needsPublish = async ({ pkg: { private, name, version }, force, tags: getTags }) => {
const needsPublish = async ({ private, name, version }, { force, getTag }) => {
if (private) {
return
}

const tags = getTags(version)
const tag = semver.parse(version).prerelease.length && tags.preTag
? tags.preTag
: tags.tag

if (force) {
return tag
}

const mani = await pacote.manifest(`${name}@${tag}`, { preferOnline: true })
if (version !== mani.version) {
const tag = await getTag({ name, version })
if (force || version !== await getVersion(`${name}@${tag}`)) {
return tag
}
}

const getPublishes = async ({ force }) => {
const getPublishes = async (opts) => {
const publish = []

for (const { name, pkg: ws } of await pkg.mapWorkspaces()) {
for (const { name, pkg } of await cli.mapWorkspaces()) {
publish.push({
workspace: name,
tag: await needsPublish({
force,
pkg: ws,
tags: TAGS.workspace,
}),
tag: await needsPublish(pkg, { ...opts, getTag: TAG.workspace }),
})
}

publish.push({
tag: await needsPublish({
force,
pkg,
tags: TAGS.root,
}),
tag: await needsPublish(cli, { ...opts, getTag: TAG.cli }),
})

return publish.filter(p => p.tag)
Expand Down