Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert messages into a hybrid cjs/esm package #1756

Merged
merged 36 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1f9cb92
Convert cucumber-expressions into a module
aurelien-reeves Sep 8, 2021
5f85f23
Use a root-level tsconfig.esm.json file
aurelien-reeves Sep 10, 2021
30f0e22
Update TypeScript builds to consider legacy and new esm-compatible ones
aurelien-reeves Sep 10, 2021
5b62fd1
Add a dedicated template for javascript esm-compatible packages
aurelien-reeves Sep 10, 2021
8cd1da7
Add the specific cjs package.json to javascript-esm template
aurelien-reeves Sep 10, 2021
4818310
Fix 'npm run clean' scripts to avoid deleting the 'javascript/dist/cj…
aurelien-reeves Sep 10, 2021
d98f0ef
Merge branch 'main' into make-cucumber-expressions-esm-compatible
aurelien-reeves Sep 10, 2021
2a3b005
Add an entry in the CHANGELOG after merge of main
aurelien-reeves Sep 10, 2021
f51dc7e
Update javascript-esm/default.mk with the last version of javascript/…
aurelien-reeves Sep 10, 2021
447ea7a
Merge branch 'main' into make-cucumber-expressions-esm-compatible
aslakhellesoy Sep 13, 2021
8a80ff1
Merge branch 'main' into make-cucumber-expressions-esm-compatible
aurelien-reeves Sep 14, 2021
694a4ec
Add tests to make sure the CJS build works well
aurelien-reeves Sep 14, 2021
d6ecb77
Merge branch 'main' into make-cucumber-expressions-esm-compatible
aurelien-reeves Sep 14, 2021
3359759
Merge remote-tracking branch 'origin/main' into make-cucumber-express…
aurelien-reeves Sep 15, 2021
71937a0
Merge branch 'main' into make-cucumber-expressions-esm-compatible
aurelien-reeves Sep 16, 2021
f25166b
Fix make clean targets for hybrid esm/cjs packages
aurelien-reeves Sep 16, 2021
98741bf
Convert messages into a hybrid cjs/esm package
aurelien-reeves Sep 16, 2021
6ed60e5
Fix tsconfig build files
aurelien-reeves Sep 16, 2021
a795db5
Fix make clean for messages javascript
aurelien-reeves Sep 16, 2021
6c59065
Fix Makefile clean target
aurelien-reeves Sep 16, 2021
50b0992
Merge branch 'main' into make-cucumber-expressions-esm-compatible
aurelien-reeves Sep 16, 2021
abc544e
Merge branch 'main' into make-cucumber-expressions-esm-compatible
aurelien-reeves Sep 17, 2021
769f7b3
Convert message-streams to hybrid cjs/esm: rsync
aurelien-reeves Sep 17, 2021
ff86b0f
Convert message-streams to hybrid cjs/esm: convert the package
aurelien-reeves Sep 17, 2021
994aaf5
Use lib: es2019 in tsconfig
aurelien-reeves Sep 17, 2021
5f7afbb
Merge branch 'main' into make-cucumber-expressions-esm-compatible
aurelien-reeves Sep 17, 2021
df2d343
Merge branch 'make-cucumber-expressions-esm-compatible' into make-mes…
aurelien-reeves Sep 17, 2021
b991aba
Merge remote-tracking branch 'origin/main' into make-messages-esm-com…
aurelien-reeves Sep 20, 2021
34d50d8
[skip ci]Update changelogs
aurelien-reeves Sep 20, 2021
06efb3a
Merge remote-tracking branch 'origin/main' into make-messages-esm-com…
aurelien-reeves Sep 21, 2021
fc9d3b8
Merge branch 'main' into make-messages-esm-compatible
aurelien-reeves Sep 22, 2021
ca30b69
Fix json-formatter package.json
aurelien-reeves Sep 22, 2021
0f4c16b
Manage dist/cjs/package.json another way
aurelien-reeves Sep 22, 2021
b6ba515
Fix templates for esm package
aurelien-reeves Sep 22, 2021
6b92619
Remove jsnext:main from package.json
aurelien-reeves Sep 22, 2021
288c1b4
Merge remote-tracking branch 'origin/main' into make-messages-esm-com…
aurelien-reeves Sep 24, 2021
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
3 changes: 3 additions & 0 deletions message-streams/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

* Support for EcmaScript modules (aka ESM)
([#1756](https://github.com/cucumber/common/pull/1756))

### Changed

### Deprecated
Expand Down
5 changes: 4 additions & 1 deletion message-streams/javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
dist/
dist/*
aurelien-reeves marked this conversation as resolved.
Show resolved Hide resolved
!dist/cjs
dist/cjs/*
!dist/cjs/package.json
.idea/
.nyc_output/
coverage/
Expand Down
2 changes: 1 addition & 1 deletion message-streams/javascript/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": ["tsconfig-paths/register", "ts-node/register", "source-map-support/register"],
"loader": "ts-node/esm",
"extension": ["ts", "tsx"],
"recursive": true,
"timeout": 10000
Expand Down
2 changes: 1 addition & 1 deletion message-streams/javascript/.rsync
Original file line number Diff line number Diff line change
@@ -1 +1 @@
../../.templates/javascript/ .
../../.templates/javascript-esm/ .
1 change: 1 addition & 0 deletions message-streams/javascript/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ clean: clean-javascript

clean-javascript:
rm -rf .deps .codegen .tested* coverage dist acceptance
git checkout dist
aurelien-reeves marked this conversation as resolved.
Show resolved Hide resolved
.PHONY: clean-javascript

clobber: clean
Expand Down
3 changes: 3 additions & 0 deletions message-streams/javascript/dist/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
25 changes: 21 additions & 4 deletions message-streams/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,34 @@
"name": "@cucumber/message-streams",
"version": "3.0.0",
"description": "Streams for reading/writing messages",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"type": "module",
"main": "dist/cjs/src/index.js",
"types": "dist/cjs/src/index.d.ts",
"files": [
"dist/cjs",
"dist/esm"
],
"module": "dist/esm/src/index.js",
"jsnext:main": "dist/esm/src/index.js",
aurelien-reeves marked this conversation as resolved.
Show resolved Hide resolved
"exports": {
".": {
"import": "./dist/esm/src/index.js",
"require": "./dist/cjs/src/index.js"
}
},
"repository": {
"type": "git",
"url": "git://github.com/cucumber/cucumber.git"
},
"author": "Cucumber Limited <[email protected]>",
"license": "MIT",
"scripts": {
"test": "mocha",
"prepublishOnly": "tsc --build tsconfig.build.json"
"build:cjs": "tsc --build tsconfig.build-cjs.json",
"build:esm": "tsc --build tsconfig.build-esm.json",
"build": "npm run build:cjs && npm run build:esm",
"test": "mocha && npm run test:cjs",
"test:cjs": "npm run build:cjs && mocha --no-config dist/cjs/test",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@cucumber/messages": "^17.1.1"
Expand Down
4 changes: 2 additions & 2 deletions message-streams/javascript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MessageToNdjsonStream from './MessageToNdjsonStream'
import NdjsonToMessageStream from './NdjsonToMessageStream'
import MessageToNdjsonStream from './MessageToNdjsonStream.js'
import NdjsonToMessageStream from './NdjsonToMessageStream.js'

export { MessageToNdjsonStream, NdjsonToMessageStream }
8 changes: 4 additions & 4 deletions message-streams/javascript/test/NdjsonStreamTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as messages from '@cucumber/messages'
import { MessageToNdjsonStream } from '../src'
import { MessageToNdjsonStream } from '../src/index.js'
import assert from 'assert'
import NdjsonToMessageStream from '../src/NdjsonToMessageStream'
import verifyStreamContract from './verifyStreamContract'
import toArray from './toArray'
import NdjsonToMessageStream from '../src/NdjsonToMessageStream.js'
import verifyStreamContract from './verifyStreamContract.js'
import toArray from './toArray.js'
import { Envelope } from '@cucumber/messages'

describe('NdjsonStream', () => {
Expand Down
4 changes: 2 additions & 2 deletions message-streams/javascript/test/verifyStreamContract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as messages from '@cucumber/messages'
import { Transform } from 'stream'
import toArray from './toArray'
import assert = require('assert')
import toArray from './toArray.js'
import assert from 'assert'

export default function verifyStreamContract(
makeFromMessageStream: () => Transform,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "../../tsconfig.build.json",
"extends": "../../tsconfig.build-cjs.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "dist"
"outDir": "dist/cjs"
},
"include": [
"src",
"test"
]
],
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"extends": "../../tsconfig.build.json",
"extends": "../../tsconfig.build-esm.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "dist"
"outDir": "dist/esm"
},
"include": [
"package.json",
"src",
"test"
]
],
}
2 changes: 1 addition & 1 deletion message-streams/javascript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "../../tsconfig.json"
"extends": "../../tsconfig.esm.json"
}
3 changes: 3 additions & 0 deletions messages/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

* Support for EcmaScript modules (aka ESM)
([#1756](https://github.com/cucumber/common/pull/1756))

### Changed

### Deprecated
Expand Down
5 changes: 4 additions & 1 deletion messages/javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
dist/
dist/*
!dist/cjs
dist/cjs/*
!dist/cjs/package.json
.idea/
.nyc_output/
coverage/
Expand Down
2 changes: 1 addition & 1 deletion messages/javascript/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": ["tsconfig-paths/register", "ts-node/register", "source-map-support/register"],
"loader": "ts-node/esm",
"extension": ["ts", "tsx"],
"recursive": true,
"timeout": 10000
Expand Down
2 changes: 1 addition & 1 deletion messages/javascript/.rsync
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
../../LICENSE LICENSE
../../.templates/github/ .github/
../../.templates/javascript/ .
../../.templates/javascript-esm/ .
7 changes: 5 additions & 2 deletions messages/javascript/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ include default.mk

JSONSCHEMAS = $(shell find ../jsonschema -name "*.json")

.codegen: src/messages.ts
.codegen: src/messages.ts src/version.ts

src/messages.ts: $(JSONSCHEMAS) ../jsonschema/scripts/codegen.rb
ruby ../jsonschema/scripts/codegen.rb TypeScript ../jsonschema > $@

src/version.ts: package.json
npm version --json | jq $$'"// This file is generated using `make src/version.ts` or `make .codegen`\nexport const version = \'" + (."@cucumber/messages") + "\'"' --raw-output > $@

clean:
rm -rf dist src/types/*.ts
rm -rf src/types/*.ts
1 change: 1 addition & 0 deletions messages/javascript/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ clean: clean-javascript

clean-javascript:
rm -rf .deps .codegen .tested* coverage dist acceptance
git checkout dist
.PHONY: clean-javascript

clobber: clean
Expand Down
3 changes: 3 additions & 0 deletions messages/javascript/dist/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
29 changes: 23 additions & 6 deletions messages/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,41 @@
"name": "@cucumber/messages",
"version": "17.1.1",
"description": "JSON schema-based messages for Cucumber's inter-process communication",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"type": "module",
"main": "dist/cjs/src/index.js",
"types": "dist/cjs/src/index.d.ts",
"files": [
"dist/cjs",
"dist/esm"
],
"module": "dist/esm/src/index.js",
"jsnext:main": "dist/esm/src/index.js",
"exports": {
".": {
"import": "./dist/esm/src/index.js",
"require": "./dist/cjs/src/index.js"
}
},
"repository": {
"type": "git",
"url": "git://github.com/cucumber/messages-javascript.git"
},
"author": "Cucumber Limited <[email protected]>",
"license": "MIT",
"scripts": {
"build:cjs": "tsc --build tsconfig.build-cjs.json",
"build:esm": "tsc --build tsconfig.build-esm.json",
"build": "npm run build:cjs && npm run build:esm",
"prepare": "make src/messages.ts",
"test": "mocha",
"prepublishOnly": "tsc --build tsconfig.build.json"
"test": "mocha && npm run test:cjs",
"test:cjs": "npm run build:cjs && mocha --no-config dist/cjs/test",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@types/uuid": "8.3.1",
"uuid": "8.3.2",
"class-transformer": "0.4.0",
"reflect-metadata": "0.1.13"
"reflect-metadata": "0.1.13",
"uuid": "8.3.2"
},
"devDependencies": {
"@types/mocha": "9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion messages/javascript/src/TimeConversion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as messages from './messages'
import * as messages from './messages.js'

const MILLISECONDS_PER_SECOND = 1e3
const NANOSECONDS_PER_MILLISECOND = 1e6
Expand Down
4 changes: 2 additions & 2 deletions messages/javascript/src/getWorstTestStepResult.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestStepResult, TestStepResultStatus } from './messages'
import { millisecondsToDuration } from './TimeConversion'
import { TestStepResult, TestStepResultStatus } from './messages.js'
import { millisecondsToDuration } from './TimeConversion.js'

/**
* Gets the worst result
Expand Down
12 changes: 6 additions & 6 deletions messages/javascript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as TimeConversion from './TimeConversion'
import * as IdGenerator from './IdGenerator'
import { version } from '../package.json'
import { parseEnvelope } from './parseEnvelope'
import { getWorstTestStepResult } from './getWorstTestStepResult'
import * as TimeConversion from './TimeConversion.js'
import * as IdGenerator from './IdGenerator.js'
import { parseEnvelope } from './parseEnvelope.js'
import { getWorstTestStepResult } from './getWorstTestStepResult.js'
import { version } from './version.js'

export * from './messages'
export * from './messages.js'

export { TimeConversion, IdGenerator, version, parseEnvelope, getWorstTestStepResult }
2 changes: 1 addition & 1 deletion messages/javascript/src/parseEnvelope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Envelope } from './messages'
import { Envelope } from './messages.js'
import { plainToClass } from 'class-transformer'

/**
Expand Down
2 changes: 2 additions & 0 deletions messages/javascript/src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file is generated using `make src/version.ts` or `make .codegen`
export const version = '17.1.0'
4 changes: 2 additions & 2 deletions messages/javascript/test/TimeConversionTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'assert'
import { Duration, TimeConversion } from '../src'
import { addDurations } from '../src/TimeConversion'
import { Duration, TimeConversion } from '../src/index.js'
import { addDurations } from '../src/TimeConversion.js'

const {
durationToMilliseconds,
Expand Down
4 changes: 2 additions & 2 deletions messages/javascript/test/getWorstTestStepResultsTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getWorstTestStepResult } from '../src/getWorstTestStepResult'
import { TestStepResultStatus } from '../src/messages'
import { getWorstTestStepResult } from '../src/getWorstTestStepResult.js'
import { TestStepResultStatus } from '../src/messages.js'
import assert from 'assert'

describe('getWorstTestStepResult', () => {
Expand Down
2 changes: 1 addition & 1 deletion messages/javascript/test/messagesTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert'
import { Envelope, parseEnvelope } from '../src/index'
import { Envelope, parseEnvelope } from '../src/index.js'

describe('messages', () => {
it('defaults missing fields when deserialising from JSON', () => {
Expand Down
11 changes: 11 additions & 0 deletions messages/javascript/tsconfig.build-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.build-cjs.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "dist/cjs"
},
"include": [
"src",
"test"
],
}
11 changes: 11 additions & 0 deletions messages/javascript/tsconfig.build-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.build-esm.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "dist/esm"
},
"include": [
"src",
"test"
],
}
2 changes: 1 addition & 1 deletion messages/javascript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "../../tsconfig.json"
"extends": "../../tsconfig.esm.json"
}
Loading