Skip to content

Commit

Permalink
fix: Improve publish postfix
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts committed Dec 19, 2023
1 parent 7aadd3e commit 62fa0c6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/heavy-ads-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"secco": patch
---

When secco publishes a package to the local Verdaccio registry it's in the format `<pkg-name>@1.0.0-secco-1702997119379` where `1702997119379` is the `Date.now()` timestamp. The postfix got extended by using [`nanoid`](https://github.com/ai/nanoid) to add 4 characters at the end, e.g. `<pkg-name>@1.0.0-secco-1702998721042-9hax`.

The goal of this is to mitigate collisions during publishing when at the same timestamp publishing happens to the instance.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"find-workspaces": "^0.3.0",
"fs-extra": "^11.2.0",
"lodash-es": "^4.17.21",
"nanoid": "^5.0.4",
"node-fetch": "^3.3.2",
"nypm": "^0.3.3",
"pathe": "^1.1.1",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/verdaccio/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Server } from 'node:http'
import { runServer } from 'verdaccio'
import { customAlphabet } from 'nanoid/non-secure'
import fs from 'fs-extra'
import { intersection } from 'lodash-es'
import { logger } from '../utils/logger'
Expand All @@ -8,6 +9,8 @@ import { VERDACCIO_CONFIG } from './verdaccio-config'
import { publishPackage } from './publish-package'
import { installPackages } from './install-packages'

const nanoid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 4)

async function startVerdaccio() {
let resolved = false

Expand Down Expand Up @@ -49,7 +52,7 @@ export interface PublishPackagesAndInstallArgs {
export async function publishPackagesAndInstall({ packageNamesToFilePath, destinationPackages, ignorePackageJsonChanges, packagesToPublish, source }: PublishPackagesAndInstallArgs) {
await startVerdaccio()

const versionPostfix = Date.now() + Math.floor(Math.random() * 1000)
const versionPostfix = `${Date.now()}-${nanoid()}`
const newlyPublishedPackageVersions: Record<string, string> = {}

for (const packageName of packagesToPublish) {
Expand Down
2 changes: 1 addition & 1 deletion src/verdaccio/publish-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function createTempNpmRc({ pathToPkg, sourcePath }: CreateTempNpmRcArgs) {

type PublishPackageArgs = Omit<PublishPackagesAndInstallArgs, 'destinationPackages'> & {
packageName: string
versionPostfix: number
versionPostfix: string
}

export async function publishPackage({ packageName, packagesToPublish, packageNamesToFilePath, versionPostfix, source, ignorePackageJsonChanges }: PublishPackageArgs) {
Expand Down

0 comments on commit 62fa0c6

Please sign in to comment.