Skip to content

Commit 30ed813

Browse files
authored
👷 Move build chain to ESM (#5670)
**Description** <!-- Please provide a short description and potentially linked issues justifying the need for this PR --> The build chain of fast-check has been CommonJS-based since day 1. With ESM moving forward in the ecosystem, it's time to move ourselves to the new standard and adapt our build chains to ESM. Unfortunately it may have some subtle impacts on our users as our package will not be a CJS one offering a ESM fallback anymore. I will rather be the opposite: an ESM package with a fallback to CJS. It implies that we moved ESM related files closer to the root of the package (we could have kept them in esm/) and moved the CJS ones further in the file structure (we had to move them). Another subtle impact is that it would impose our users to run at least Node ≥12.17.0. As such we consider it as a breaking change. On its own it should not be a huge problem for most of the users but given it changes our minimal requirement let's put it into the next major release. Superseed #4592 <!-- * Your PR is fixing a bug or regression? Check for existing issues related to this bug and link them --> <!-- * Your PR is adding a new feature? Make sure there is a related issue or discussion attached to it --> <!-- You can provide any additional context to help into understanding what's this PR is attempting to solve: reproduction of a bug, code snippets... --> **Checklist** — _Don't delete this checklist and make sure you do the following before opening the PR_ - [x] The name of my PR follows [gitmoji](https://gitmoji.dev/) specification - [x] My PR references one of several related issues (if any) - [x] New features or breaking changes must come with an associated Issue or Discussion - [x] My PR does not add any new dependency without an associated Issue or Discussion - [x] My PR includes bumps details, please run `yarn bump` and flag the impacts properly - [x] My PR adds relevant tests and they would have failed without my PR (when applicable) <!-- More about contributing at https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md --> **Advanced** <!-- How to fill the advanced section is detailed below! --> - [x] Category: 👷 Configuration of the package - [x] Impacts: Requires users to rely on more recent versions of Node, at least 12.17 <!-- [Category] Please use one of the categories below, it will help us into better understanding the urgency of the PR --> <!-- * ✨ Introduce new features --> <!-- * 📝 Add or update documentation --> <!-- * ✅ Add or update tests --> <!-- * 🐛 Fix a bug --> <!-- * 🏷️ Add or update types --> <!-- * ⚡️ Improve performance --> <!-- * _Other(s):_ ... --> <!-- [Impacts] Please provide a comma separated list of the potential impacts that might be introduced by this change --> <!-- * Generated values: Can your change impact any of the existing generators in terms of generated values, if so which ones? when? --> <!-- * Shrink values: Can your change impact any of the existing generators in terms of shrink values, if so which ones? when? --> <!-- * Performance: Can it require some typings changes on user side? Please give more details --> <!-- * Typings: Is there a potential performance impact? In which cases? -->
1 parent 4e88009 commit 30ed813

File tree

7 files changed

+25
-20
lines changed

7 files changed

+25
-20
lines changed

.changeset/blue-donkeys-compare.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"fast-check": major
3+
---
4+
5+
👷 Move build chain to ESM

packages/fast-check/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Here are the minimal requirements to use fast-check properly without any polyfil
118118

119119
| fast-check | node | ECMAScript version | _TypeScript (optional)_ |
120120
| ---------- | ------------------- | ------------------ | ----------------------- |
121-
| **4.x** |10.5.0 | ES2020 | ≥5.0 |
121+
| **4.x** |12.17.0 | ES2020 | ≥5.0 |
122122
| **3.x** | ≥8<sup>(1)</sup> | ES2017 | ≥4.1<sup>(2)</sup> |
123123
| **2.x** | ≥8<sup>(1)</sup> | ES2017 | ≥3.2<sup>(3)</sup> |
124124
| **1.x** | ≥0.12<sup>(1)</sup> | ES3 | ≥3.0<sup>(3)</sup> |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

packages/fast-check/package.esm-template.json

-3
This file was deleted.

packages/fast-check/package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
"name": "fast-check",
33
"version": "3.23.2",
44
"description": "Property based testing framework for JavaScript (like QuickCheck)",
5-
"type": "commonjs",
5+
"type": "module",
66
"main": "lib/fast-check.js",
77
"exports": {
88
"./package.json": "./package.json",
99
".": {
1010
"require": {
11-
"types": "./lib/types/fast-check.d.ts",
12-
"default": "./lib/fast-check.js"
11+
"types": "./lib/cjs/types/fast-check.d.ts",
12+
"default": "./lib/cjs/fast-check.js"
1313
},
1414
"import": {
15-
"types": "./lib/esm/types/fast-check.d.ts",
16-
"default": "./lib/esm/fast-check.js"
15+
"types": "./lib/types/fast-check.d.ts",
16+
"default": "./lib/fast-check.js"
1717
}
1818
}
1919
},
20-
"module": "lib/esm/fast-check.js",
20+
"module": "lib/fast-check.js",
2121
"types": "lib/types/fast-check.d.ts",
2222
"files": [
2323
"lib",
@@ -28,15 +28,15 @@
2828
"scripts": {
2929
"build": "yarn build:publish-cjs && yarn build:publish-esm && yarn build:publish-types && node postbuild/main.mjs",
3030
"build-ci": "cross-env EXPECT_GITHUB_SHA=true yarn build",
31-
"build:publish-types": "tsc -p tsconfig.publish.types.json && tsc -p tsconfig.publish.types.json --outDir lib/esm/types",
32-
"build:publish-cjs": "tsc -p tsconfig.publish.json",
33-
"build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node --outDir lib/esm && cp package.esm-template.json lib/esm/package.json",
31+
"build:publish-types": "tsc -p tsconfig.publish.types.json && tsc -p tsconfig.publish.types.json --outDir lib/cjs/types",
32+
"build:publish-cjs": "tsc -p tsconfig.publish.json --outDir lib/cjs && cp package.cjs-template.json lib/cjs/package.json",
33+
"build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node",
3434
"typecheck": "tsc --noEmit",
3535
"test": "vitest --config vitest.unit.config.mjs",
3636
"e2e": "vitest --config vitest.e2e.config.mjs",
3737
"update:documentation": "cross-env UPDATE_CODE_SNIPPETS=true vitest --config vitest.documentation.config.mjs",
3838
"test-bundle": "node test-bundle/run.cjs && node test-bundle/run.mjs && node test-bundle/run-advanced.cjs",
39-
"test-legacy-bundle": "nvs add 10.5 && $(nvs which 10.5) test-bundle/run.cjs && $(nvs which 10.5) test-bundle/run-advanced.cjs",
39+
"test-legacy-bundle": "nvs add 12.17 && $(nvs which 12.17) test-bundle/run.cjs && $(nvs which 12.17) test-bundle/run-advanced.cjs",
4040
"docs": "api-extractor run --local && rm docs/fast-check.api.json && typedoc --out docs src/fast-check-default.ts && node postbuild/main.mjs",
4141
"docs-ci": "cross-env EXPECT_GITHUB_SHA=true yarn docs",
4242
"docs:serve": "yarn dlx serve docs/"

packages/fast-check/postbuild/main.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
3636
const packageVersion = JSON.parse(data.toString()).version;
3737

3838
const commonJsReplacement = replaceInFileSync({
39-
files: 'lib/fast-check-default.js',
39+
files: 'lib/cjs/fast-check-default.js',
4040
from: [/__PACKAGE_TYPE__/g, /__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g],
4141
to: ['commonjs', packageVersion, commitHash],
4242
});
@@ -45,7 +45,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
4545
}
4646

4747
const moduleReplacement = replaceInFileSync({
48-
files: 'lib/esm/fast-check-default.js',
48+
files: 'lib/fast-check-default.js',
4949
from: [/__PACKAGE_TYPE__/g, /__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g],
5050
to: ['module', packageVersion, commitHash],
5151
});
@@ -54,7 +54,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
5454
}
5555

5656
const dTsReplacement = replaceInFileSync({
57-
files: 'lib/types/fast-check-default.d.ts',
57+
files: 'lib/cjs/types/fast-check-default.d.ts',
5858
from: [/__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g],
5959
to: [packageVersion, commitHash],
6060
});
@@ -63,7 +63,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
6363
}
6464

6565
const dTsReplacement2 = replaceInFileSync({
66-
files: 'lib/esm/types/fast-check-default.d.ts',
66+
files: 'lib/types/fast-check-default.d.ts',
6767
from: [/__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g],
6868
to: [packageVersion, commitHash],
6969
});

website/docs/migration/from-3.x-to-4.x.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Simple migration guide to fast-check v4 starting from fast-check v3
1111

1212
| Name | New requirement | Previous requirement |
1313
| ------------------------ | --------------- | -------------------- |
14-
| Node |10.5.0 | ≥8 |
14+
| Node |12.17.0 | ≥8 |
1515
| ECMAScript specification | ES2020 | ES2017 |
1616
| TypeScript _(optional)_ | ≥5.0 | ≥4.1 |
1717

18-
Related pull requests: [#5577](https://github.com/dubzzz/fast-check/pull/5577), [#5605](https://github.com/dubzzz/fast-check/pull/5605), [#5617](https://github.com/dubzzz/fast-check/pull/5617), [#5634](https://github.com/dubzzz/fast-check/pull/5634), [#5635](https://github.com/dubzzz/fast-check/pull/5635)
18+
Related pull requests: [#5577](https://github.com/dubzzz/fast-check/pull/5577), [#5605](https://github.com/dubzzz/fast-check/pull/5605), [#5617](https://github.com/dubzzz/fast-check/pull/5617), [#5634](https://github.com/dubzzz/fast-check/pull/5634), [#5635](https://github.com/dubzzz/fast-check/pull/5635), [#5670](https://github.com/dubzzz/fast-check/pull/5670)
1919

2020
## Update to latest v3.x
2121

0 commit comments

Comments
 (0)