diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b10eecf..81c79ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: - ubuntu-latest - macos-latest - windows-latest - node-version: [20.x, 22.x, 24.x] + node-version: [22.x, 24.x, 26.x] fail-fast: false steps: @@ -44,7 +44,7 @@ jobs: persist-credentials: false - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 with: - node-version: 24.x + node-version: 22.x - run: npm ci - run: npm run build - run: npm run coverage:check @@ -58,7 +58,7 @@ jobs: persist-credentials: false - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 with: - node-version: 24.x + node-version: 22.x - run: npm ci - run: npm run build - run: npm run exports:check @@ -72,6 +72,6 @@ jobs: persist-credentials: false - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 with: - node-version: 24.x + node-version: 22.x - run: npm ci - run: npm run docs diff --git a/.mocharc.json b/.mocharc.json index 40ba7d1..b5b7170 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,5 +1,5 @@ { - "require": "ts-node/register", + "node-option": ["loader=ts-node/esm"], "extension": ["ts"], "recursive": true } diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a67f7e..dd1f583 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- BREAKING CHANGE: Switch to ESM ([#70](https://github.com/cucumber/javascript-core/pull/70)) ## [0.8.3] - 2026-01-27 ### Changed diff --git a/package.json b/package.json index ac75482..39a03ae 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@cucumber/core", "version": "0.8.3", "description": "Core test case composition library for building a Cucumber implementation", - "type": "commonjs", + "type": "module", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ @@ -17,6 +17,7 @@ "exports:update": "api-extractor run --verbose --local", "fix": "biome check --fix --error-on-warnings", "lint": "biome check --error-on-warnings", + "postbuild": "node -e \"require('.')\"", "test": "mocha \"src/**/*.spec.ts\"", "prepublishOnly": "npm run build" }, diff --git a/src/AmbiguousError.spec.ts b/src/AmbiguousError.spec.ts index 1cf5050..919916b 100644 --- a/src/AmbiguousError.spec.ts +++ b/src/AmbiguousError.spec.ts @@ -2,8 +2,8 @@ import type { PickleStep, SourceReference } from '@cucumber/messages' import { expect } from 'chai' import sinon from 'sinon' -import { AmbiguousError } from './AmbiguousError' -import type { AmbiguousStep, DefinedStep } from './types' +import { AmbiguousError } from './AmbiguousError.js' +import type { AmbiguousStep, DefinedStep } from './types.js' describe('AmbiguousError', () => { it('handles source references with and without locations', () => { diff --git a/src/AmbiguousError.ts b/src/AmbiguousError.ts index 716738f..a9c0065 100644 --- a/src/AmbiguousError.ts +++ b/src/AmbiguousError.ts @@ -1,4 +1,4 @@ -import type { AmbiguousStep } from './types' +import type { AmbiguousStep } from './types.js' /** * Represents an error that occurs when multiple step definitions are found matching the text of a step diff --git a/src/DataTable.spec.ts b/src/DataTable.spec.ts index 71d4b71..6c2634a 100644 --- a/src/DataTable.spec.ts +++ b/src/DataTable.spec.ts @@ -2,8 +2,8 @@ import type { PickleTable } from '@cucumber/messages' import { expect } from 'chai' import { describe, it } from 'mocha' -import { parseGherkin } from '../test/parseGherkin' -import { DataTable } from './DataTable' +import { parseGherkin } from '../test/parseGherkin.js' +import { DataTable } from './DataTable.js' describe('DataTable', () => { describe('raw', () => { diff --git a/src/SupportCodeBuilderImpl.ts b/src/SupportCodeBuilderImpl.ts index b543459..65c07a1 100644 --- a/src/SupportCodeBuilderImpl.ts +++ b/src/SupportCodeBuilderImpl.ts @@ -7,7 +7,7 @@ import { import { HookType, StepDefinitionPatternType } from '@cucumber/messages' import parse from '@cucumber/tag-expressions' -import { SupportCodeLibraryImpl } from './SupportCodeLibraryImpl' +import { SupportCodeLibraryImpl } from './SupportCodeLibraryImpl.js' import type { DefinedParameterType, DefinedStep, @@ -19,7 +19,7 @@ import type { NewTestRunHook, SupportCodeBuilder, UndefinedParameterType, -} from './types' +} from './types.js' type Registered = { id: string; order: number } & T diff --git a/src/SupportCodeLibraryImpl.ts b/src/SupportCodeLibraryImpl.ts index bf8b527..8e6c647 100644 --- a/src/SupportCodeLibraryImpl.ts +++ b/src/SupportCodeLibraryImpl.ts @@ -12,7 +12,7 @@ import type { MatchedStep, SupportCodeLibrary, UndefinedParameterType, -} from './types' +} from './types.js' type OrderedEnvelope = { order: number diff --git a/src/UndefinedError.spec.ts b/src/UndefinedError.spec.ts index cb683fe..5417444 100644 --- a/src/UndefinedError.spec.ts +++ b/src/UndefinedError.spec.ts @@ -1,8 +1,8 @@ import type { PickleStep, Snippet } from '@cucumber/messages' import { expect } from 'chai' -import type { UndefinedStep } from './types' -import { UndefinedError } from './UndefinedError' +import type { UndefinedStep } from './types.js' +import { UndefinedError } from './UndefinedError.js' describe('UndefinedError', () => { it('should create an error message with the step text', () => { diff --git a/src/UndefinedError.ts b/src/UndefinedError.ts index 1ceb0c6..11c0b46 100644 --- a/src/UndefinedError.ts +++ b/src/UndefinedError.ts @@ -1,6 +1,6 @@ import type { Snippet } from '@cucumber/messages' -import type { UndefinedStep } from './types' +import type { UndefinedStep } from './types.js' /** * Represents an error that occurs when no step definitions are found matching the text of a step diff --git a/src/buildSupportCode.spec.ts b/src/buildSupportCode.spec.ts index 796ddd9..77156d7 100644 --- a/src/buildSupportCode.spec.ts +++ b/src/buildSupportCode.spec.ts @@ -10,8 +10,8 @@ import { import { expect } from 'chai' import sinon from 'sinon' -import { buildSupportCode } from './buildSupportCode' -import type { SupportCodeLibrary } from './types' +import { buildSupportCode } from './buildSupportCode.js' +import type { SupportCodeLibrary } from './types.js' describe('buildSupportCode', () => { let newId: () => string diff --git a/src/buildSupportCode.ts b/src/buildSupportCode.ts index 40c447b..d23bae5 100644 --- a/src/buildSupportCode.ts +++ b/src/buildSupportCode.ts @@ -1,7 +1,7 @@ import { IdGenerator } from '@cucumber/messages' -import { SupportCodeBuilderImpl } from './SupportCodeBuilderImpl' -import type { SupportCodeBuilder, SupportCodeOptions } from './types' +import { SupportCodeBuilderImpl } from './SupportCodeBuilderImpl.js' +import type { SupportCodeBuilder, SupportCodeOptions } from './types.js' /** * Start building up a library user-defined support code diff --git a/src/index.ts b/src/index.ts index fcf3c14..3d7c390 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -export * from './AmbiguousError' -export * from './buildSupportCode' -export * from './DataTable' -export * from './makeTestPlan' -export * from './types' -export * from './UndefinedError' +export * from './AmbiguousError.js' +export * from './buildSupportCode.js' +export * from './DataTable.js' +export * from './makeTestPlan.js' +export * from './types.js' +export * from './UndefinedError.js' diff --git a/src/makeTestPlan.spec.ts b/src/makeTestPlan.spec.ts index 8e5ba5a..91f8758 100644 --- a/src/makeTestPlan.spec.ts +++ b/src/makeTestPlan.spec.ts @@ -3,9 +3,9 @@ import { expect, use } from 'chai' import sinon from 'sinon' import sinonChai from 'sinon-chai' -import { parseGherkin } from '../test/parseGherkin' -import { buildSupportCode } from './buildSupportCode' -import { makeTestPlan } from './makeTestPlan' +import { parseGherkin } from '../test/parseGherkin.js' +import { buildSupportCode } from './buildSupportCode.js' +import { makeTestPlan } from './makeTestPlan.js' use(sinonChai) diff --git a/src/makeTestPlan.ts b/src/makeTestPlan.ts index a4c9b26..62633e9 100644 --- a/src/makeTestPlan.ts +++ b/src/makeTestPlan.ts @@ -22,7 +22,7 @@ import type { SupportCodeLibrary, TestPlanIngredients, TestPlanOptions, -} from './types' +} from './types.js' /** * Make an executable test plan for a Gherkin document diff --git a/test/parseGherkin.ts b/test/parseGherkin.ts index 14bcbc9..75c2012 100644 --- a/test/parseGherkin.ts +++ b/test/parseGherkin.ts @@ -7,7 +7,9 @@ export function parseGherkin( file: string, newId: () => string = IdGenerator.uuid() ): { gherkinDocument: GherkinDocument; pickles: ReadonlyArray } { - const data = fs.readFileSync(path.join(__dirname, '..', 'testdata', file), { encoding: 'utf-8' }) + const data = fs.readFileSync(path.join(import.meta.dirname, '..', 'testdata', file), { + encoding: 'utf-8', + }) const builder = new AstBuilder(newId) const matcher = new GherkinClassicTokenMatcher() const parser = new Parser(builder, matcher)