Skip to content

Commit

Permalink
👷(packaged) Move build chain to ESM (#4588)
Browse files Browse the repository at this point in the history
The build chain of `@fast-check/packaged` 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.
  • Loading branch information
dubzzz authored Jan 2, 2024
1 parent 137e52f commit 6b42042
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .yarn/versions/5da63084.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
"@fast-check/packaged": minor
60 changes: 31 additions & 29 deletions packages/packaged/bin/packaged.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
/* global process, console, require */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { removeNonPublishedFiles } = require('../lib/packaged.js');
/* global process, console */
import { removeNonPublishedFiles } from '../lib/packaged.js';

const args = process.argv.slice(2);
const help = args.includes('--help') || args.includes('-h');
if (help) {
console.log('Usages:');
console.log('- packaged');
console.log(' Drop any file in the current directory that will not be part of the package');
console.log(' if published to npm registry');
console.log('- packaged --dry-run');
console.log(' No removal, just printing');
console.log('- packaged --keep-node-modules');
console.log(' Keep root level node_modules if any');
return;
}
const dryRun = args.includes('--dry-run');
const keepNodeModules = args.includes('--keep-node-modules');
removeNonPublishedFiles('.', { dryRun, keepNodeModules }).then((out) => {
if (dryRun) {
console.log('Those files would have been kept:');
for (const k of out.kept) {
console.log(`- ${k}`);
}
console.log('Those files would have been removed:');
for (const r of out.removed) {
console.log(`- ${r}`);
}
function run(args) {
const help = args.includes('--help') || args.includes('-h');
if (help) {
console.log('Usages:');
console.log('- packaged');
console.log(' Drop any file in the current directory that will not be part of the package');
console.log(' if published to npm registry');
console.log('- packaged --dry-run');
console.log(' No removal, just printing');
console.log('- packaged --keep-node-modules');
console.log(' Keep root level node_modules if any');
return;
}
});
const dryRun = args.includes('--dry-run');
const keepNodeModules = args.includes('--keep-node-modules');
removeNonPublishedFiles('.', { dryRun, keepNodeModules }).then((out) => {
if (dryRun) {
console.log('Those files would have been kept:');
for (const k of out.kept) {
console.log(`- ${k}`);
}
console.log('Those files would have been removed:');
for (const r of out.removed) {
console.log(`- ${r}`);
}
}
});
}

run(process.argv.slice(2));
8 changes: 4 additions & 4 deletions packages/packaged/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@fast-check/packaged",
"description": "Utility package removing any files that will not be part of the final bundle",
"version": "0.2.0",
"type": "commonjs",
"type": "module",
"main": "lib/packaged.js",
"types": "lib/packaged.d.ts",
"bin": "./bin/packaged.js",
Expand All @@ -12,11 +12,11 @@
],
"sideEffects": false,
"scripts": {
"build": "yarn build:publish-cjs && yarn build:publish-types",
"build": "yarn build:publish-esm && yarn build:publish-types",
"build-ci": "yarn build",
"build:publish-types": "tsc -p tsconfig.publish.types.json",
"build:publish-cjs": "tsc -p tsconfig.publish.json",
"test": "jest --verbose",
"build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node",
"test": "yarn node --experimental-vm-modules $(yarn bin jest) --verbose",
"typecheck": "tsc --noEmit"
},
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions packages/packaged/test-types/empty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Just to avoid empty mv from complaining in CI.
// Alternatively we could have muted the complaint by passsing some flags to mv but it would have hidden a potentially legit error.
File renamed without changes.

0 comments on commit 6b42042

Please sign in to comment.