Skip to content

Commit f6ba613

Browse files
committed
add missing changes
Signed-off-by: Matthias Wippich <mfwippich@gmail.com>
1 parent 94c52a0 commit f6ba613

6 files changed

Lines changed: 191 additions & 0 deletions

File tree

.github/workflows/publish-npm.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish npm packages
2+
3+
on:
4+
push:
5+
tags:
6+
- "codeblocks/v*"
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: pnpm/action-setup@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: "22"
21+
cache: pnpm
22+
registry-url: https://registry.npmjs.org
23+
- run: pnpm install --frozen-lockfile
24+
- name: Install WASM from the latest artifact release
25+
env:
26+
GH_TOKEN: ${{ github.token }}
27+
RELEASE_REPOSITORY: ${{ github.repository }}
28+
run: scripts/install-latest-clangd-release
29+
- name: Verify package version
30+
run: test "codeblocks/v$(node -p "require('./package.json').version")" = "$GITHUB_REF_NAME"
31+
- name: Build self-contained package
32+
run: pnpm build && pnpm package:npm
33+
- name: Build hosted-WASM package
34+
env:
35+
CLANGD_WASM_BASE: https://clangd.cpp.social/wasm/
36+
run: |
37+
pnpm exec vite build --outDir dist-remote --emptyOutDir
38+
pnpm exec tsc -p tsconfig.types.json --outDir dist-remote/types
39+
node scripts/copy-runtime-assets.mjs --outdir=dist-remote --without-wasm
40+
node scripts/prepare-npm-package.mjs dist-remote packages/codeblocks-remote codeblocks-remote
41+
- run: npm install --global npm@latest
42+
- name: Publish codeblocks
43+
run: npm publish packages/codeblocks --access public --provenance
44+
- name: Publish codeblocks-remote
45+
run: npm publish packages/codeblocks-remote --access public --provenance

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ pnpm package:npm
189189
npm pack ./packages/codeblocks
190190
```
191191

192+
<<<<<<< HEAD
193+
=======
194+
Publishing is restricted to the `Publish npm packages` workflow and tags matching
195+
`codeblocks/v<package-version>`. Its separate artifact-install step downloads and
196+
verifies the newest `clangd-wasm/*` release before either distribution is built.
197+
The packages are then published using npm trusted publishing and provenance.
198+
>>>>>>> b363f44 (add missing changes)
192199
193200
Create a deployable archive with:
194201

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
release_repository=${RELEASE_REPOSITORY:?RELEASE_REPOSITORY is required}
5+
release_prefix="clangd-wasm/"
6+
release_tag=$(
7+
gh api --paginate "repos/${release_repository}/releases?per_page=100" |
8+
jq -sr --arg prefix "$release_prefix" '
9+
add
10+
| map(select(
11+
(.draft | not)
12+
and (.tag_name | startswith($prefix))
13+
))
14+
| sort_by(.published_at)
15+
| last
16+
| .tag_name // empty
17+
'
18+
)
19+
if [[ -z "$release_tag" ]]; then
20+
echo "No published clangd wasm release found with prefix ${release_prefix}" >&2
21+
exit 1
22+
fi
23+
24+
artifact_dir=$(mktemp -d)
25+
trap 'rm -rf "$artifact_dir"' EXIT
26+
echo "Installing ${release_tag}"
27+
gh release download "$release_tag" \
28+
--repo "$release_repository" \
29+
--pattern clangd.js \
30+
--pattern clangd.wasm \
31+
--pattern SHA256SUMS \
32+
--dir "$artifact_dir"
33+
(
34+
cd "$artifact_dir"
35+
sha256sum -c SHA256SUMS
36+
)
37+
scripts/install-clangd-artifacts "$artifact_dir"

scripts/prepare-npm-package.mjs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
2+
import path from "node:path";
3+
4+
const [source, destination, name] = process.argv.slice(2);
5+
if (!source || !destination || !name) {
6+
throw new Error(
7+
"Usage: prepare-npm-package.mjs SOURCE DESTINATION PACKAGE_NAME",
8+
);
9+
}
10+
11+
const root = path.resolve(import.meta.dirname, "..");
12+
const sourceDirectory = path.resolve(root, source);
13+
const destinationDirectory = path.resolve(root, destination);
14+
const project = JSON.parse(
15+
await readFile(path.join(root, "package.json"), "utf8"),
16+
);
17+
18+
await rm(destinationDirectory, { recursive: true, force: true });
19+
await mkdir(destinationDirectory, { recursive: true });
20+
await cp(sourceDirectory, destinationDirectory, {
21+
recursive: true,
22+
filter: (file) => !/[\\/]index\.html$|[\\/]_headers$/.test(file),
23+
});
24+
const declaration = path.join(destinationDirectory, "types", "codeblocks.d.ts");
25+
await writeFile(
26+
declaration,
27+
(await readFile(declaration, "utf8")).replace(
28+
'import "./codeblocks.css";\n',
29+
"",
30+
),
31+
);
32+
await writeFile(
33+
path.join(destinationDirectory, "package.json"),
34+
`${JSON.stringify(
35+
{
36+
name,
37+
version: project.version,
38+
description: project.description,
39+
license: project.license,
40+
type: "module",
41+
files: ["**/*"],
42+
exports: {
43+
".": {
44+
types: "./types/codeblocks.d.ts",
45+
import: "./codeblocks-module.js",
46+
},
47+
"./loader": {
48+
types: "./loader.d.ts",
49+
default: "./codeblocks.js",
50+
},
51+
"./styles.css": "./codeblocks.css",
52+
},
53+
},
54+
null,
55+
2,
56+
)}\n`,
57+
);

src/loader-api.d.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export type CodeBlocksStatus =
2+
| { type: "monaco-loading" }
3+
| { type: "monaco-ready" }
4+
| { type: "clangd-downloading"; loaded: number; total?: number }
5+
| { type: "clangd-starting" }
6+
| { type: "clangd-loaded" }
7+
| { type: "clangd-ready" }
8+
| { type: "clangd-error"; error: Error };
9+
10+
export interface CodeBlockInstance {
11+
setTheme(theme: "light" | "dark"): Promise<void>;
12+
}
13+
14+
export interface CodeBlocksApi {
15+
configure(options: {
16+
theme?: "auto" | "light" | "dark";
17+
editorOptions?: Record<string, unknown>;
18+
onStatus?: (status: CodeBlocksStatus) => void;
19+
}): void;
20+
get(element: Element): CodeBlockInstance | undefined;
21+
ready: Promise<CodeBlocksApi>;
22+
}
23+
24+
declare global {
25+
var CodeBlocks: CodeBlocksApi;
26+
27+
interface Window {
28+
CodeBlocks?: CodeBlocksApi;
29+
}
30+
}

tsconfig.types.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"emitDeclarationOnly": true,
6+
"noEmit": false,
7+
"outDir": "dist/types"
8+
},
9+
"include": [
10+
"src/codeblocks.ts",
11+
"src/runtime.ts",
12+
"src/ansi.ts",
13+
"src/vite-env.d.ts"
14+
]
15+
}

0 commit comments

Comments
 (0)