Skip to content

Commit 0fef352

Browse files
committed
feat: restructure local npm registry setup and update publish scripts
1 parent fcf6898 commit 0fef352

10 files changed

Lines changed: 54 additions & 95 deletions

File tree

.github/workflows/pkg-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ jobs:
3636
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3737
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3838
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
39+
NPM_CONFIG_PROVENANCE: 'true'
3940
VSCE_PAT: ${{ secrets.VSCE_TOKEN }}

local-npm-registry/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
storage/
2-
htpasswd
1+
storage

local-npm-registry/config.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
storage: ./storage
2+
3+
uplinks:
4+
npmjs:
5+
url: https://registry.npmjs.org/
6+
7+
packages:
8+
'@lemoncode/*':
9+
access: $anonymous
10+
publish: $anonymous
11+
'**':
12+
access: $anonymous
13+
publish: $anonymous
14+
proxy: npmjs
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
local-npm-registry:
3+
image: verdaccio/verdaccio
4+
ports:
5+
- '4873:4873'
6+
volumes:
7+
- ./config:/verdaccio/conf
8+
volumes:
9+
config:

local-npm-registry/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"start": "verdaccio --config ./config.yaml --listen 4873"
7-
},
8-
"devDependencies": {
9-
"verdaccio": "6.5.0"
6+
"prestart": "npm stop",
7+
"start": "docker compose up -d",
8+
"stop": "docker compose down --remove-orphans"
109
}
1110
}

local-npm-registry/publish.js

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,26 @@
1-
import { execSync, spawn } from 'node:child_process';
2-
import { resolve } from 'node:path';
1+
import childProcess from 'node:child_process';
2+
import fs from 'node:fs/promises';
3+
import path from 'node:path';
34

4-
const REGISTRY_URL = 'http://localhost:4873';
5-
const ROOT = resolve(import.meta.dirname, '..');
6-
const CONFIG = resolve(import.meta.dirname, 'config.yaml');
5+
const [...publishCommandArgs] = process.argv.slice(2);
6+
const localRegistryConfig = `registry=http://localhost:4873
7+
//localhost:4873/:_authToken="local-token"
8+
@lemoncode:registry=http://localhost:4873
9+
`;
10+
const publishCommand = publishCommandArgs.join(' ');
11+
const NPMRC_FILE_PATH = path.resolve(process.cwd(), '.npmrc');
712

8-
const command = process.argv[2];
9-
10-
const startVerdaccio = () =>
11-
spawn('npx', ['verdaccio', '--config', CONFIG, '--listen', '4873'], {
12-
cwd: import.meta.dirname,
13-
stdio: 'inherit',
14-
shell: true,
15-
});
16-
17-
const waitForRegistry = async (url, retries = 30, delay = 1000) => {
18-
for (let i = 0; i < retries; i++) {
19-
try {
20-
const res = await fetch(url);
21-
if (res.ok) return;
22-
} catch {}
23-
await new Promise(r => setTimeout(r, delay));
24-
}
25-
throw new Error(`Registry at ${url} did not start in time`);
26-
};
27-
28-
const run = (cmd, opts = {}) =>
29-
execSync(cmd, {
30-
stdio: 'inherit',
31-
cwd: ROOT,
32-
env: { ...process.env, npm_config_registry: REGISTRY_URL },
33-
...opts,
34-
});
35-
36-
if (command === 'start') {
37-
// Just start Verdaccio (foreground)
38-
const child = startVerdaccio();
39-
child.on('exit', code => process.exit(code ?? 0));
40-
} else if (command === 'publish') {
41-
// Full flow: start Verdaccio → changeset version → changeset publish → stop
42-
const child = startVerdaccio();
13+
let originalContent = '';
14+
try {
15+
originalContent = await fs.readFile(NPMRC_FILE_PATH, 'utf-8');
16+
} catch {
17+
originalContent = '';
18+
}
4319

44-
try {
45-
console.log('Waiting for Verdaccio to start...');
46-
await waitForRegistry(REGISTRY_URL);
47-
console.log('Verdaccio ready. Running changeset version...');
48-
run('npx changeset version');
49-
console.log('Publishing to local registry...');
50-
run('npx changeset publish');
51-
console.log('Done! Packages published to local Verdaccio.');
52-
} finally {
53-
child.kill();
54-
}
55-
} else {
56-
console.error('Usage: node publish.js <start|publish>');
57-
process.exit(1);
20+
try {
21+
const newContent = originalContent.trimEnd() + '\n' + localRegistryConfig;
22+
await fs.writeFile(NPMRC_FILE_PATH, newContent);
23+
childProcess.execSync(`${publishCommand}`, { stdio: 'inherit', shell: true });
24+
} finally {
25+
await fs.writeFile(NPMRC_FILE_PATH, originalContent);
5826
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"workspaces": [
1111
"apps/*",
1212
"packages/*",
13-
"tooling/*",
14-
"local-npm-registry"
13+
"tooling/*"
1514
],
1615
"scripts": {
1716
"start": "node --run dev",
@@ -30,8 +29,9 @@
3029
"format:check": "prettier --check .",
3130
"changeset": "changeset",
3231
"publish-packages": "changeset publish",
33-
"start:local-npm-registry": "node local-npm-registry/publish.js start",
34-
"local:publish": "node --run build && node local-npm-registry/publish.js publish",
32+
"start:local-npm-registry": "npm run build && cd ./local-npm-registry && npm start",
33+
"stop:local-npm-registry": "cd ./local-npm-registry && npm stop",
34+
"local:publish": "node --run start:local-npm-registry && changeset version && node local-npm-registry/publish.js changeset publish",
3535
"prepare": "husky || \"No need to install husky\""
3636
},
3737
"lint-staged": {

packages/mcp/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
"files": [
1515
"dist"
1616
],
17-
"publishConfig": {
18-
"provenance": true
19-
},
2017
"scripts": {
2118
"build": "tsdown",
2219
"check-types": "tsc --noEmit",

packages/vscode-extension/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
"files": [
1010
"dist"
1111
],
12-
"publishConfig": {
13-
"provenance": true
14-
},
1512
"scripts": {
1613
"dev": "node --run build -- --watch --sourcemap",
1714
"build": "tsdown",

0 commit comments

Comments
 (0)