Skip to content

Commit 53726dd

Browse files
DavertMikclaude
andcommitted
feat: ESM-only release for CodeceptJS 4.x
* Drop the createRequire/require('codeceptjs') bridge in favour of a native ESM `import { output } from 'codeceptjs'`. End users on CodeceptJS 4.x share the host's module graph; no more dual-singleton hazard or stale nested codeceptjs leaking in. * Same treatment for chai-match-pattern and chai-json-schema-ajv — default-imported once, no in-method `require`s. * Drop CJS export entry and the `index.cjs` shim. CodeceptJS 4.x is ESM-only; matching here. * `peerDependencies.codeceptjs` is now `>=4.0.0-rc.1`, marked optional so npm doesn't pull a stale 3.x copy alongside a 4.x host. * Bump version label to 4.0.0-beta.1. * Replace semantic-release / NPM_TOKEN workflow with an OIDC trusted- publisher workflow (Node 24, latest npm, gated on `npm test`, publishes with `--provenance --access public`; derives dist-tag from prerelease label). * Test workflow: trigger on 4.x + main + PRs; Node 20/22/24 matrix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0e8488f commit 53726dd

7 files changed

Lines changed: 2028 additions & 803 deletions

File tree

.github/workflows/node.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@ name: NodeJS Tests
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches:
6+
- 4.x
7+
- main
68
pull_request:
7-
branches: [ "main" ]
9+
branches:
10+
- '**'
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
815

916
jobs:
1017
build:
1118
runs-on: ubuntu-latest
12-
1319
strategy:
1420
matrix:
15-
node-version: [20.x, 22.x]
16-
21+
node-version: [20.x, 22.x, 24.x]
1722
steps:
18-
- uses: actions/checkout@v4
19-
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v4
22-
with:
23-
node-version: ${{ matrix.node-version }}
24-
25-
- name: Test
26-
run: |
27-
npm install
28-
npm test
23+
- uses: actions/checkout@v4
24+
- uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
- run: npm install -g npm@latest
28+
- run: npm install
29+
- run: npm test

.github/workflows/npm-publish.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
id-token: write
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
ref: ${{ github.event.release.target_commitish }}
18+
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: 24
22+
23+
- run: npm install -g npm@latest
24+
- run: npm install
25+
- run: npm test
26+
27+
publish:
28+
needs: test
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.event.release.target_commitish }}
34+
35+
- uses: actions/setup-node@v4
36+
with:
37+
node-version: 24
38+
registry-url: 'https://registry.npmjs.org'
39+
40+
- run: npm install -g npm@latest
41+
- run: npm install
42+
43+
- name: Set package version from release tag
44+
run: npm version "${{ github.event.release.tag_name }}" --no-git-tag-version
45+
46+
- name: Publish to npm
47+
run: |
48+
VERSION="${{ github.event.release.tag_name }}"
49+
if [[ "$VERSION" == *-* ]]; then
50+
TAG=$(echo "$VERSION" | sed -E 's/^[^-]+-([a-zA-Z]+).*/\1/')
51+
npm publish --provenance --access public --tag "$TAG"
52+
else
53+
npm publish --provenance --access public
54+
fi

index.cjs

Lines changed: 0 additions & 6 deletions
This file was deleted.

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { use, expect, assert } from 'chai';
22
import chaiExclude from 'chai-exclude';
3-
import { createRequire } from 'module';
4-
5-
const require = createRequire(import.meta.url);
6-
const { output } = require('codeceptjs');
3+
import chaiMatchPattern from 'chai-match-pattern';
4+
import chaiJsonSchemaAjv from 'chai-json-schema-ajv';
5+
import { output } from 'codeceptjs';
76

87
use(chaiExclude);
9-
use(require('chai-match-pattern'));
8+
use(chaiMatchPattern);
109

1110
/**
1211
* This helper allows performing assertions based on Chai.
@@ -173,7 +172,7 @@ class ExpectHelper {
173172
output.step(
174173
`I expect "${JSON.stringify(targetData)}" to match this JSON schema using AJV "${JSON.stringify(jsonSchema)}"`,
175174
)
176-
use(require('chai-json-schema-ajv').create(ajvOptions))
175+
use(chaiJsonSchemaAjv.create(ajvOptions))
177176
return expect(targetData, customErrorMsg).to.be.jsonSchema(jsonSchema)
178177
}
179178

0 commit comments

Comments
 (0)