Skip to content
Merged
Show file tree
Hide file tree
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
66 changes: 54 additions & 12 deletions .github/workflows/build-codemirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,96 @@ name: Build CodeMirror bundle

on:
workflow_dispatch:
inputs:
codemirror_version:
description: "Version of codemirror"
required: true
type: string
default: "6.0.2"
autocompletion_version:
description: "Version of @codemirror/autocomplete"
required: true
type: string
default: "6.0.0"
lang_yaml_version:
description: "Version of @codemirror/lang-yaml"
required: true
type: string
default: "6.1.3"
esbuild_version:
description: "Version of esbuild (build tool)"
required: true
type: string
default: "0.25.11"

permissions:
contents: read

jobs:
build:
name: Bundle CodeMirror and YAML language support
name: Bundle CodeMirror and utilities (such as YAML language support)
runs-on: ubuntu-latest
timeout-minutes: 10

defaults:
run:
working-directory: build/codemirror

env:
CODEMIRROR_VERSION: ${{ inputs.codemirror_version }}
LANG_YAML_VERSION: ${{ inputs.lang_yaml_version }}
ESBUILD_VERSION: ${{ inputs.esbuild_version }}
AUTOCOMPLETION_VERSION: ${{ inputs.autocompletion_version}}

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Set up Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v7
with:
node-version: 22

- name: Install pinned dependencies
run: npm install --no-audit --no-fund
- name: Install selected dependencies
run: |
npm install --no-save --no-package-lock --no-audit --no-fund \
"codemirror@${CODEMIRROR_VERSION}" \
"@codemirror/autocomplete@${AUTOCOMPLETION_VERSION}" \
"@codemirror/lang-yaml@${LANG_YAML_VERSION}" \
"esbuild@${ESBUILD_VERSION}"

- id: js
name: Set js name
run: |
t0="cm-${CODEMIRROR_VERSION}"
t1="-yaml-${LANG_YAML_VERSION}"
t2="-autocmp-${AUTOCOMPLETION_VERSION}"
echo "name=$t0$t1$t2" >> "$GITHUB_OUTPUT"

- name: Build ES module bundle
run: |
OUTPUT="dist/${{ steps.js.outputs.name }}.js"
mkdir -p dist
npx esbuild src/index.js \
./node_modules/.bin/esbuild src/index.js \
--bundle \
--format=esm \
--target=es2022 \
--outfile=dist/codemirror.js
--outfile="${OUTPUT}"
echo "BUNDLE_FILE=${OUTPUT}" >> "$GITHUB_ENV"

- name: Check bundle
run: |
test -s dist/codemirror.js
if grep -Eq 'from ["'\''/](@codemirror|codemirror)|import\(["'\''/](@codemirror|codemirror)' dist/codemirror.js; then
test -s "${BUNDLE_FILE}"
if grep -Eq 'from ["'\''/](@codemirror|codemirror)|import\(["'\''/](@codemirror|codemirror)' "${BUNDLE_FILE}"; then
echo "::error::The bundle still contains an external CodeMirror import."
exit 1
fi
echo "Bundle size: $(wc -c < dist/codemirror.js) bytes"
echo "Bundle size: $(wc -c < "${BUNDLE_FILE}") bytes"

- name: Upload CodeMirror bundle
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: codemirror-6.0.2-yaml-6.1.3
path: build/codemirror/dist/codemirror.js
name: codemirror-${{ steps.js.outputs.name }}-${{ inputs.esbuild_version }}
path: build/codemirror/dist/${{ steps.js.outputs.name }}.js
if-no-files-found: error
retention-days: 30
37 changes: 15 additions & 22 deletions build/codemirror/README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
# CodeMirror browser bundle

This directory contains the build-time configuration for the OBM CodeMirror
This directory contains the build-time entry point for the OBM CodeMirror
bundle. It is deliberately separate from the static site runtime.

## Build

Run the **Build CodeMirror bundle** workflow manually from GitHub Actions.
It installs the pinned direct dependencies, bundles their dependencies into
one browser ES module, and publishes the result as the
`codemirror-6.0.2-yaml-6.1.3` workflow artifact.
The workflow exposes some version inputs of components to bundle

The artifact contains:
The selected packages are installed for that workflow run only. The output
filename and artifact name include the selected versions. The artifact also
records the esbuild version in its name, although esbuild is only a build tool
and is not included in the browser bundle.

```text
codemirror.js
```

Download and extract that artifact into the site's `vendor/codemirror/`
directory. No npm, Node.js, or CDN access is required by the deployed site.
Download and extract the JavaScript file into the site's
`vendor/codemirror/` directory. No npm, Node.js, or CDN access is required
by the deployed site.

## Browser usage

The bundle exposes the same three named exports as the current esm.sh imports:

```js
import { EditorView, basicSetup, yaml } from
"/vendor/codemirror/codemirror.js";
import { EditorView, basicSetup, autocompletion, yaml } from
"/vendor/codemirror/xxxxxxxxx.js";
```

Replace the versioned filename with the one produced by the workflow run.

CodeMirror injects its editor styles through its JavaScript modules, so this
bundle does not require a separate stylesheet.

## Versions

- `codemirror`: 6.0.2
- `@codemirror/lang-yaml`: 6.1.3
- `esbuild`: 0.25.11 (build tool only)
## Entry point

The CodeMirror packages are bundled into the output; esbuild is not included
in the browser bundle.
`src/index.js` defines the public exports included in the browser bundle.
7 changes: 1 addition & 6 deletions build/codemirror/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
"name": "obm-codemirror-bundle",
"private": true,
"type": "module",
"description": "Build-time dependencies for the OBM CodeMirror browser bundle.",
"description": "Build-time configuration for the OBM CodeMirror browser bundle.",
"scripts": {
"build": "esbuild src/index.js --bundle --format=esm --target=es2022 --outfile=dist/codemirror.js"
},
"dependencies": {
"@codemirror/lang-yaml": "6.1.3",
"codemirror": "6.0.2",
"esbuild": "0.25.11"
}
}
1 change: 1 addition & 0 deletions build/codemirror/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Public API exposed by the local OBM CodeMirror bundle.
export { EditorView, basicSetup } from "codemirror";
export { yaml } from "@codemirror/lang-yaml";
export { autocompletion } from '@codemirror/autocomplete';
Loading