Skip to content

Commit 0583143

Browse files
authored
Merge pull request #829 from Lemoncode/bugfix/fix-vscode-extension-publish
feat: implement publishing for npm and VS Code extensions
2 parents b4d91b3 + 026cb02 commit 0583143

12 files changed

Lines changed: 492 additions & 699 deletions

File tree

.github/workflows/pkg-publish.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ jobs:
2929

3030
- run: node --run build
3131

32-
- name: Publish to npm
32+
- name: Publish npm packages
3333
uses: changesets/action@v1
3434
with:
35-
publish: node --run publish-packages
35+
publish: node --run publish:npm
3636
env:
3737
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3838
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3939
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4040
NPM_CONFIG_PROVENANCE: 'true'
41+
42+
- name: Publish VS Code extensions
43+
run: node --run publish:vscode
44+
env:
4145
VSCE_PAT: ${{ secrets.VSCE_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ lerna-debug.log*
4141

4242
# Vite
4343
.vite
44+
45+
# Temporary LICENSE copies (created by publish scripts)
46+
packages/*/LICENSE

package-lock.json

Lines changed: 386 additions & 689 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"format": "prettier --write .",
2929
"format:check": "prettier --check .",
3030
"changeset": "changeset",
31-
"publish-packages": "changeset publish",
31+
"publish:npm": "tsx tooling/publish/publish-npm.ts",
32+
"publish:vscode": "tsx tooling/publish/publish-vscode.ts",
3233
"start:local-npm-registry": "npm run build && cd ./local-npm-registry && npm start",
3334
"stop:local-npm-registry": "cd ./local-npm-registry && npm stop",
3435
"local:publish": "node --run start:local-npm-registry && changeset version && node local-npm-registry/publish.js changeset publish",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
src/**
2+
node_modules/**
3+
*.ts
4+
tsconfig.json
5+
tsdown.config.ts
6+
vitest.config.ts
7+
.turbo/**
8+
coverage/**

packages/vscode-extension/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
{
2-
"name": "@lemoncode/quickmock-vscode-extension",
2+
"name": "quickmock",
33
"version": "0.0.1",
44
"type": "module",
55
"main": "./dist/index.mjs",
66
"imports": {
77
"#*": "./src/*"
88
},
9-
"files": [
10-
"dist"
11-
],
129
"scripts": {
1310
"dev": "node --run build -- --watch --sourcemap",
1411
"build": "tsdown",
@@ -50,7 +47,7 @@
5047
"directory": "packages/vscode-extension"
5148
},
5249
"engines": {
53-
"vscode": "^1.105.0"
50+
"vscode": "^1.116.0"
5451
},
5552
"icon": "./assets/app-icon.webp",
5653
"galleryBanner": {

tooling/dev-cli/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as p from '@clack/prompts';
22
import { spawn } from 'node:child_process';
3-
import { filterByScript, getWorkspacePackages } from './lib/workspace.ts';
3+
import { filterByScript, getWorkspacePackages } from './lib/workspace';
44

55
const main = async () => {
66
p.intro('Dev CLI');

tooling/dev-cli/test-watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as p from '@clack/prompts';
22
import { spawn } from 'node:child_process';
33
import { resolve } from 'node:path';
4-
import { filterByScript, getWorkspacePackages } from './lib/workspace.ts';
4+
import { filterByScript, getWorkspacePackages } from './lib/workspace';
55

66
const ROOT = resolve(import.meta.dirname, '../..');
77

tooling/publish/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "publish",
3+
"type": "module",
4+
"private": true
5+
}

tooling/publish/publish-npm.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { execSync, type ExecSyncOptions } from 'node:child_process';
2+
import { readFile, writeFile } from 'node:fs/promises';
3+
import { resolve } from 'node:path';
4+
import { ROOT, VSCODE_EXTENSION_PATHS } from './publish.constants';
5+
6+
interface PackageJson {
7+
private?: boolean;
8+
[key: string]: unknown;
9+
}
10+
11+
const markAsPrivate = async (
12+
pkgPath: string
13+
): Promise<{ path: string; original: string }> => {
14+
const fullPath = resolve(ROOT, pkgPath, 'package.json');
15+
const original = await readFile(fullPath, 'utf-8');
16+
const pkg: PackageJson = JSON.parse(original);
17+
pkg.private = true;
18+
await writeFile(fullPath, JSON.stringify(pkg, null, 2));
19+
return { path: fullPath, original };
20+
};
21+
22+
const restoreAll = async (
23+
backups: Array<{ path: string; original: string }>
24+
) => {
25+
for (const { path, original } of backups) {
26+
await writeFile(path, original);
27+
}
28+
};
29+
30+
const main = async () => {
31+
const backups = await Promise.all(VSCODE_EXTENSION_PATHS.map(markAsPrivate));
32+
33+
const opts: ExecSyncOptions = { stdio: 'inherit', cwd: ROOT };
34+
35+
try {
36+
execSync('changeset publish', opts);
37+
} finally {
38+
await restoreAll(backups);
39+
}
40+
};
41+
42+
main();

0 commit comments

Comments
 (0)