Skip to content

Commit

Permalink
ESM/CJS work
Browse files Browse the repository at this point in the history
- delete "type: module" from package.json (this broke CJS typescript consumers)
- give up on "fix-cjs" approach, and switch to tsup-produced bundles.
- ensure CJS is "index.CJS", and ESM is "index.MJS" to avoid ambiguity
- switch from "api-extractor" back to tsc for typings
- DRY up jest-specific tsconfigs
- run jest in both cjs and esm modes
- tweak integration tests to use package exports instead of relative paths
- run awash in regret that I didn't just support CJS. ESM is far too painful for no performance or ergonomic benefit, and supporting only ESM is a huge middle finger to people still "stuck" on CJS.
  • Loading branch information
mceachen committed Dec 21, 2024
1 parent de8c257 commit 67091d3
Show file tree
Hide file tree
Showing 22 changed files with 1,182 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jobs:
cache: "npm"
- run: ls -laR ./prebuilds
- run: npm ci
- run: npm run tsc
- run: npm run prepare-release

# readme: https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token
# https://chatgpt.com/share/6761e017-9950-800e-ba1e-94d575010f2d
Expand Down
4 changes: 2 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import ts_eslint from "typescript-eslint";
/** @type {import('eslint').Linter.Config[]} */
export default [
{
files: ["src/**/*.ts", "scripts/*.js", "*.js"],
files: ["src/**/*.ts", "scripts/*.js"],
languageOptions: {
globals: {
...globals.node,
},
},
},
{ ignores: [".tsup", "build", "coverage", "dist*", "docs"] },
{ ignores: ["build", "coverage", "dist", "docs", "*.cts", "*.cjs"] },
pluginJs.configs.recommended,
...ts_eslint.configs.recommended,
...ts_eslint.configs.strict,
Expand Down
33 changes: 33 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @ts-check

/** @type {import('ts-jest').JestConfigWithTsJest} */

const config = {
displayName: "@photostructure/fs-metadata (CJS)",
testEnvironment: "jest-environment-node",
roots: ["<rootDir>/src"],
coverageProvider: "v8",
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.(c)?ts$": [
"ts-jest",
{
useESM: false,
tsconfig: "tsconfig.jest-cjs.json",
},
],
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
collectCoverage: false,
verbose: true,
silent: false,
randomize: true,
setupFilesAfterEnv: [
"jest-extended/all",
"<rootDir>/src/test-utils/jest-matchers.ts",
],
};

module.exports = config;
10 changes: 5 additions & 5 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ const otherPlatforms = ["linux", "darwin", "windows"]
.map((ea) => `/${ea}/`);

/** @type {import('ts-jest').JestConfigWithTsJest} */

const config = {
displayName: "@photostructure/fs-metadata",
displayName: "@photostructure/fs-metadata (ESM)",
testEnvironment: "jest-environment-node",
roots: ["<rootDir>/src"],
coverageProvider: "v8",
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.tsx?$": [
"^.+\\.(m)?ts$": [
"ts-jest",
{
useESM: true,
tsconfig: "tsconfig.json",
tsconfig: "tsconfig.jest-esm.json",
},
],
},
extensionsToTreatAsEsm: [".ts"],
extensionsToTreatAsEsm: [".ts", ".mts"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
collectCoverage:
argv.includes("--coverage") && !argv.includes("--no-coverage"),
Expand All @@ -33,7 +34,6 @@ const config = {
collectCoverageFrom: ["src/**/*.ts"],
coveragePathIgnorePatterns: [
"debuglog",
"\\.test\\.ts$",
"/test-utils/",
"/types/",
...otherPlatforms,
Expand Down
Loading

0 comments on commit 67091d3

Please sign in to comment.