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

Make cucumber-expressions compatible with both cjs and esm #1743

Merged
merged 20 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 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
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
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
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
22 changes: 22 additions & 0 deletions .templates/javascript-esm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
dist/*
!dist/cjs
dist/cjs/*
!dist/cjs/package.json
.idea/
.nyc_output/
coverage/
node_modules/
yarn.lock
package-lock.json
*.log
.deps
.tested*
.linted
.built*
.compared
.codegen
acceptance/
storybook-static
*-go
*.iml
.vscode-test
6 changes: 6 additions & 0 deletions .templates/javascript-esm/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"loader": "ts-node/esm",
"extension": ["ts", "tsx"],
"recursive": true,
"timeout": 10000
}
88 changes: 88 additions & 0 deletions .templates/javascript-esm/default.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
SHELL := /usr/bin/env bash
# https://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
TYPESCRIPT_SOURCE_FILES = $(sort $(call rwildcard,src test,*.ts *.tsx))
PRIVATE = $(shell node -e "console.log(require('./package.json').private)")
IS_TESTDATA = $(findstring -testdata,${CURDIR})
NPM_MODULE = $(shell cat package.json | jq .name --raw-output)

default: .tested
.PHONY: default

../../node_modules ../../package-lock.json: package.json
cd ../.. && npm install

.codegen:
touch $@

.tested: .tested-npm .built

.built: $(TYPESCRIPT_SOURCE_FILES) ../../node_modules ../../package-lock.json .codegen
pushd ../.. && \
npm run build && \
popd && \
touch $@

.tested-npm: $(TYPESCRIPT_SOURCE_FILES) ../../node_modules ../../package-lock.json .codegen
npm run test
touch $@

pre-release: clean update-version update-dependencies default
.PHONY: pre-release

update-dependencies:
../../node_modules/.bin/npm-check-updates --upgrade --reject hast-util-sanitize,@types/node,react-markdown,rehype-raw,rehype-sanitize,remark-gfm
.PHONY: update-dependencies

update-version:
ifeq ($(IS_TESTDATA),-testdata)
# no-op
else
ifdef NEW_VERSION
npm --no-git-tag-version --allow-same-version version "$(NEW_VERSION)"
# Update all npm packages that depend on us
pushd ../.. && \
./scripts/npm-each update_npm_dependency_if_exists package.json "$(NPM_MODULE)" "$(NEW_VERSION)"
else
@echo -e "\033[0;31mNEW_VERSION is not defined. Can't update version :-(\033[0m"
exit 1
endif
endif
.PHONY: update-version

publish: .codegen
ifeq ($(IS_TESTDATA),-testdata)
# no-op
else
ifneq (true,$(PRIVATE))
npm publish --access public
else
@echo "Not publishing private npm module"
endif
endif
.PHONY: publish

post-release:
.PHONY: post-release

clean: clean-javascript
.PHONY: clean

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

clobber: clean
rm -rf node_modules ../../node_modules
.PHONY: clobber

### COMMON stuff for all platforms

BERP_VERSION = 1.3.0
BERP_GRAMMAR = gherkin.berp

define berp-generate-parser =
-! dotnet tool list --tool-path /usr/bin | grep "berp\s*$(BERP_VERSION)" && dotnet tool update Berp --version $(BERP_VERSION) --tool-path /usr/bin
berp -g $(BERP_GRAMMAR) -t $< -o $@ --noBOM
endef
3 changes: 3 additions & 0 deletions .templates/javascript-esm/dist/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
3 changes: 3 additions & 0 deletions .templates/javascript-esm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.esm.json"
}
3 changes: 3 additions & 0 deletions cucumber-expressions/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).
([#1743](https://github.com/cucumber/common/pull/1743))

### Changed

### Deprecated
Expand Down
5 changes: 4 additions & 1 deletion cucumber-expressions/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 cucumber-expressions/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 cucumber-expressions/javascript/.rsync
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
../../LICENSE LICENSE
../../.templates/github/ .github/
../../.templates/javascript/ .
../../.templates/javascript-esm/ .
../examples.txt examples.txt
../testdata .
1 change: 1 addition & 0 deletions cucumber-expressions/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 cucumber-expressions/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 cucumber-expressions/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@
"name": "@cucumber/cucumber-expressions",
"version": "13.0.1",
"description": "Cucumber Expressions - a simpler alternative to Regular Expressions",
"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"
}
},
"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"
},
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions cucumber-expressions/javascript/src/Argument.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import TreeRegexp from './TreeRegexp'
import ParameterType from './ParameterType'
import Group from './Group'
import CucumberExpressionError from './CucumberExpressionError'
import TreeRegexp from './TreeRegexp.js'
import ParameterType from './ParameterType.js'
import Group from './Group.js'
import CucumberExpressionError from './CucumberExpressionError.js'

export default class Argument<T> {
public static build(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GeneratedExpression from './GeneratedExpression'
import ParameterType from './ParameterType'
import GeneratedExpression from './GeneratedExpression.js'
import ParameterType from './ParameterType.js'

// 256 generated expressions ought to be enough for anybody
const MAX_EXPRESSIONS = 256
Expand Down
18 changes: 9 additions & 9 deletions cucumber-expressions/javascript/src/CucumberExpression.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import ParameterTypeRegistry from './ParameterTypeRegistry'
import ParameterType from './ParameterType'
import TreeRegexp from './TreeRegexp'
import Argument from './Argument'
import ParameterTypeRegistry from './ParameterTypeRegistry.js'
import ParameterType from './ParameterType.js'
import TreeRegexp from './TreeRegexp.js'
import Argument from './Argument.js'
import {
createAlternativeMayNotBeEmpty,
createAlternativeMayNotExclusivelyContainOptionals,
createOptionalIsNotAllowedInOptional,
createOptionalMayNotBeEmpty,
createParameterIsNotAllowedInOptional,
createUndefinedParameterType,
} from './Errors'
import Expression from './Expression'
import CucumberExpressionParser from './CucumberExpressionParser'
import { Node, NodeType } from './Ast'
import CucumberExpressionError from './CucumberExpressionError'
} from './Errors.js'
import Expression from './Expression.js'
import CucumberExpressionParser from './CucumberExpressionParser.js'
import { Node, NodeType } from './Ast.js'
import CucumberExpressionError from './CucumberExpressionError.js'

const ESCAPE_PATTERN = () => /([\\^[({$.|?*+})\]])/g

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import ParameterTypeMatcher from './ParameterTypeMatcher'
import ParameterType from './ParameterType'

import CombinatorialGeneratedExpressionFactory from './CombinatorialGeneratedExpressionFactory'
import GeneratedExpression from './GeneratedExpression'
import ParameterTypeMatcher from './ParameterTypeMatcher.js'
import ParameterType from './ParameterType.js'
import CombinatorialGeneratedExpressionFactory from './CombinatorialGeneratedExpressionFactory.js'
import GeneratedExpression from './GeneratedExpression.js'

export default class CucumberExpressionGenerator {
constructor(private readonly parameterTypes: () => Iterable<ParameterType<any>>) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Node, NodeType, Token, TokenType } from './Ast'
import CucumberExpressionTokenizer from './CucumberExpressionTokenizer'
import { Node, NodeType, Token, TokenType } from './Ast.js'
import CucumberExpressionTokenizer from './CucumberExpressionTokenizer.js'
import {
createAlternationNotAllowedInOptional,
createInvalidParameterTypeNameInNode,
createMissingEndToken,
} from './Errors'
} from './Errors.js'

/*
* text := whitespace | ')' | '}' | .
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Token, TokenType } from './Ast'
import { createCantEscaped, createTheEndOfLIneCanNotBeEscaped } from './Errors'
import { Token, TokenType } from './Ast.js'
import { createCantEscaped, createTheEndOfLIneCanNotBeEscaped } from './Errors.js'

export default class CucumberExpressionTokenizer {
tokenize(expression: string): readonly Token[] {
Expand Down
8 changes: 4 additions & 4 deletions cucumber-expressions/javascript/src/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ParameterType from './ParameterType'
import GeneratedExpression from './GeneratedExpression'
import { Located, Node, purposeOf, symbolOf, Token, TokenType } from './Ast'
import CucumberExpressionError from './CucumberExpressionError'
import ParameterType from './ParameterType.js'
import GeneratedExpression from './GeneratedExpression.js'
import { Located, Node, purposeOf, symbolOf, Token, TokenType } from './Ast.js'
import CucumberExpressionError from './CucumberExpressionError.js'

export function createAlternativeMayNotExclusivelyContainOptionals(
node: Node,
Expand Down
2 changes: 1 addition & 1 deletion cucumber-expressions/javascript/src/Expression.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Argument from './Argument'
import Argument from './Argument.js'

export default interface Expression {
readonly source: string
Expand Down
8 changes: 4 additions & 4 deletions cucumber-expressions/javascript/src/ExpressionFactory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Expression from './Expression'
import CucumberExpression from './CucumberExpression'
import RegularExpression from './RegularExpression'
import ParameterTypeRegistry from './ParameterTypeRegistry'
import Expression from './Expression.js'
import CucumberExpression from './CucumberExpression.js'
import RegularExpression from './RegularExpression.js'
import ParameterTypeRegistry from './ParameterTypeRegistry.js'

export default class ExpressionFactory {
public constructor(private readonly parameterTypeRegistry: ParameterTypeRegistry) {}
Expand Down
2 changes: 1 addition & 1 deletion cucumber-expressions/javascript/src/GeneratedExpression.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ParameterType from './ParameterType'
import ParameterType from './ParameterType.js'

export default class GeneratedExpression {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion cucumber-expressions/javascript/src/GroupBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Group from './Group'
import Group from './Group.js'
import { RegExpExecArray } from 'regexp-match-indices'

export default class GroupBuilder {
Expand Down
2 changes: 1 addition & 1 deletion cucumber-expressions/javascript/src/ParameterType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CucumberExpressionError from './CucumberExpressionError'
import CucumberExpressionError from './CucumberExpressionError.js'

const ILLEGAL_PARAMETER_NAME_PATTERN = /([[\]()$.|?*+])/
const UNESCAPE_PATTERN = () => /(\\([[$.|?*+\]]))/g
Expand Down
4 changes: 1 addition & 3 deletions cucumber-expressions/javascript/src/ParameterTypeMatcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ParameterType from './ParameterType'
import ParameterType from './ParameterType.js'

export default class ParameterTypeMatcher {
private readonly match: RegExpExecArray
Expand Down Expand Up @@ -75,5 +75,3 @@ export default class ParameterTypeMatcher {
return 0
}
}

module.exports = ParameterTypeMatcher
8 changes: 4 additions & 4 deletions cucumber-expressions/javascript/src/ParameterTypeRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ParameterType from './ParameterType'
import ParameterType from './ParameterType.js'

import CucumberExpressionGenerator from './CucumberExpressionGenerator'
import { AmbiguousParameterTypeError } from './Errors'
import CucumberExpressionError from './CucumberExpressionError'
import CucumberExpressionGenerator from './CucumberExpressionGenerator.js'
import { AmbiguousParameterTypeError } from './Errors.js'
import CucumberExpressionError from './CucumberExpressionError.js'

export default class ParameterTypeRegistry {
public static readonly INTEGER_REGEXPS = [/-?\d+/, /\d+/]
Expand Down
10 changes: 5 additions & 5 deletions cucumber-expressions/javascript/src/RegularExpression.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Argument from './Argument'
import TreeRegexp from './TreeRegexp'
import ParameterType from './ParameterType'
import ParameterTypeRegistry from './ParameterTypeRegistry'
import Expression from './Expression'
import Argument from './Argument.js'
import TreeRegexp from './TreeRegexp.js'
import ParameterType from './ParameterType.js'
import ParameterTypeRegistry from './ParameterTypeRegistry.js'
import Expression from './Expression.js'

export default class RegularExpression implements Expression {
private readonly treeRegexp: TreeRegexp
Expand Down
4 changes: 2 additions & 2 deletions cucumber-expressions/javascript/src/TreeRegexp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GroupBuilder from './GroupBuilder'
import Group from './Group'
import GroupBuilder from './GroupBuilder.js'
import Group from './Group.js'
import execWithIndices from 'regexp-match-indices'

export default class TreeRegexp {
Expand Down
Loading