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

👷 Move build chain to ESM #4592

Open
wants to merge 16 commits into
base: next-3_15_0
Choose a base branch
from
18 changes: 10 additions & 8 deletions packages/fast-check/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,20 @@ It also proved useful in finding bugs among major open source projects such as [

Here are the minimal requirements to use fast-check properly without any polyfills:

| fast-check | node | ECMAScript version | _TypeScript (optional)_ |
| ---------- | ------------------- | ------------------ | ----------------------- |
| **3.x** | ≥8<sup>(1)</sup> | ES2017 | ≥4.1<sup>(2)</sup> |
| **2.x** | ≥8<sup>(1)</sup> | ES2017 | ≥3.2<sup>(3)</sup> |
| **1.x** | ≥0.12<sup>(1)</sup> | ES3 | ≥3.0<sup>(3)</sup> |
| fast-check | node | ECMAScript version | _TypeScript (optional)_ |
| ---------- | -------------------- | ------------------ | ----------------------- |
| **4.x** | ≥12.17<sup>(1)</sup> | ES2017 | ≥4.1<sup>(3)</sup> |
| **3.x** | ≥8<sup>(2)</sup> | ES2017 | ≥4.1<sup>(3)</sup> |
| **2.x** | ≥8<sup>(2)</sup> | ES2017 | ≥3.2<sup>(4)</sup> |
| **1.x** | ≥0.12<sup>(2)</sup> | ES3 | ≥3.0<sup>(4)</sup> |

<details>
<summary>More details...</summary>

1. Except for features that cannot be polyfilled - such as `bigint`-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check.
2. Require either lib or target ≥ ES2020 or `@types/node` to be installed.
3. Require either lib or target ≥ ES2015 or `@types/node` to be installed.
1. Support for `package.json#exports` is required.
2. Except for features that cannot be polyfilled - such as `bigint`-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check.
3. Require either lib or target ≥ ES2020 or `@types/node` to be installed.
4. Require either lib or target ≥ ES2015 or `@types/node` to be installed.

</details>

Expand Down
5 changes: 3 additions & 2 deletions packages/fast-check/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const process = require('process');
const fc = require('fast-check');
import process from 'process';
import fc from 'fast-check';
import { jest } from '@jest/globals';
dubzzz marked this conversation as resolved.
Show resolved Hide resolved

// Default timeout of 120s
jest.setTimeout(120000);
Expand Down
3 changes: 3 additions & 0 deletions packages/fast-check/package.cjs-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
3 changes: 0 additions & 3 deletions packages/fast-check/package.esm-template.json

This file was deleted.

35 changes: 18 additions & 17 deletions packages/fast-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
"name": "fast-check",
"version": "3.15.0",
"description": "Property based testing framework for JavaScript (like QuickCheck)",
"type": "commonjs",
"type": "module",
"main": "lib/fast-check.js",
"exports": {
"./package.json": "./package.json",
".": {
"require": {
"types": "./lib/types/fast-check.d.ts",
"default": "./lib/fast-check.js"
"types": "./lib/cjs/types/fast-check.d.ts",
"default": "./lib/cjs/fast-check.js"
},
"import": {
"types": "./lib/esm/types/fast-check.d.ts",
"default": "./lib/esm/fast-check.js"
"types": "./lib/types/fast-check.d.ts",
"default": "./lib/fast-check.js"
}
}
},
"module": "lib/esm/fast-check.js",
"module": "lib/fast-check.js",
"types": "lib/types/fast-check.d.ts",
"files": [
"lib",
Expand All @@ -28,19 +28,19 @@
"scripts": {
"build": "yarn build:publish-cjs && yarn build:publish-esm && yarn build:publish-types && node postbuild/main.cjs",
"build-ci": "cross-env EXPECT_GITHUB_SHA=true yarn build",
"build:publish-types": "tsc -p tsconfig.publish.types.json && tsc -p tsconfig.publish.types.json --outDir lib/esm/types",
"build:publish-cjs": "tsc -p tsconfig.publish.json",
"build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node --outDir lib/esm && cp package.esm-template.json lib/esm/package.json",
"build:publish-types": "tsc -p tsconfig.publish.types.json && tsc -p tsconfig.publish.types.json --outDir lib/cjs/types",
"build:publish-cjs": "tsc -p tsconfig.publish.json --outDir lib/cjs && cp package.cjs-template.json lib/cjs/package.json",
"build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node",
"typecheck": "tsc --noEmit",
"test": "jest --config jest.unit.config.cjs --coverage --verbose",
"test:watch": "jest --config jest.unit.config.cjs --watch",
"test:debug": "node --inspect ../../node_modules/jest/bin/jest.js --config jest.unit.config.cjs --watch --runInBand",
"e2e": "jest --config jest.e2e.config.cjs --coverage --verbose",
"e2e:watch": "jest --config jest.e2e.config.cjs --watch",
"e2e:debug": "node --inspect ../../node_modules/jest/bin/jest.js --config jest.e2e.config.cjs --watch --runInBand",
"update:examples": "cross-env UPDATE_CODE_SNIPPETS=true jest --config jest.examples.config.cjs",
"test": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.unit.config.cjs --coverage --verbose",
"test:watch": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.unit.config.cjs --watch",
"test:debug": "yarn node --experimental-vm-modules --inspect $(yarn bin jest) --config jest.unit.config.cjs --watch --runInBand",
"e2e": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.e2e.config.cjs --coverage --verbose",
"e2e:watch": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.e2e.config.cjs --watch",
"e2e:debug": "yarn node --experimental-vm-modules --inspect $(yarn bin jest) --config jest.e2e.config.cjs --watch --runInBand",
"update:examples": "cross-env UPDATE_CODE_SNIPPETS=true yarn node --experimental-vm-modules $(yarn bin jest) --config jest.examples.config.cjs",
"test-bundle": "node test-bundle/run.cjs && node test-bundle/run.mjs && node test-bundle/run-advanced.cjs",
"test-legacy-bundle": "nvs add 8 && $(nvs which 8) test-bundle/run.cjs && $(nvs which 8) test-bundle/run-advanced.cjs",
"test-legacy-bundle": "nvs add 12.17 && $(nvs which 12.17) test-bundle/run.cjs && $(nvs which 12.17) test-bundle/run-advanced.cjs",
"docs": "api-extractor run --local && rm docs/fast-check.api.json && typedoc --out docs src/fast-check-default.ts && node postbuild/main.cjs",
"docs-ci": "cross-env EXPECT_GITHUB_SHA=true yarn docs",
"docs:serve": "yarn dlx serve docs/"
Expand Down Expand Up @@ -68,6 +68,7 @@
"@babel/preset-typescript": "^7.23.3",
"@fast-check/expect-type": "workspace:*",
"@fast-check/poisoning": "workspace:*",
"@jest/globals": "^29.7.0",
"@microsoft/api-extractor": "^7.38.5",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/fast-check/postbuild/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
const packageVersion = JSON.parse(data.toString()).version;

const commonJsReplacement = replace.sync({
files: 'lib/fast-check-default.js',
files: 'lib/cjs/fast-check-default.js',
from: [/__PACKAGE_TYPE__/g, /__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g],
to: ['commonjs', packageVersion, commitHash],
});
Expand All @@ -51,7 +51,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
}

const moduleReplacement = replace.sync({
files: 'lib/esm/fast-check-default.js',
files: 'lib/fast-check-default.js',
from: [/__PACKAGE_TYPE__/g, /__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g],
to: ['module', packageVersion, commitHash],
});
Expand All @@ -61,7 +61,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
}

const dTsReplacement = replace.sync({
files: 'lib/types/fast-check-default.d.ts',
files: 'lib/cjs/types/fast-check-default.d.ts',
from: [/__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g],
to: [packageVersion, commitHash],
});
Expand All @@ -71,7 +71,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => {
}

const dTsReplacement2 = replace.sync({
files: 'lib/esm/types/fast-check-default.d.ts',
files: 'lib/types/fast-check-default.d.ts',
from: [/__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g],
to: [packageVersion, commitHash],
});
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8848,6 +8848,7 @@ __metadata:
"@babel/preset-typescript": "npm:^7.23.3"
"@fast-check/expect-type": "workspace:*"
"@fast-check/poisoning": "workspace:*"
"@jest/globals": "npm:^29.7.0"
"@microsoft/api-extractor": "npm:^7.38.5"
"@types/jest": "npm:^29.5.11"
"@types/node": "npm:^20.10.4"
Expand Down
Loading