From 8ef3584620e5476b9a4ce874e546d79f08247e6f Mon Sep 17 00:00:00 2001 From: alexrecuenco Date: Sun, 22 Sep 2024 23:12:34 +0200 Subject: [PATCH 1/3] Enable ESM --- .github/workflows/main.yml | 7 +- .npmignore | 7 + .pre-commit-config.yaml | 16 +- .vscode/settings.json | 4 +- __tests__/replace.test.ts | 2 +- __tests__/server.test.ts | 21 ++ __tests__/tsconfig.json | 19 ++ eslint.config.mjs | 2 +- jest.config.ts | 36 +- package-lock.json | 667 ++++++++++++++++++++++++++++++++++++- package.cjs-template.json | 5 + package.json | 37 +- prettier.config.cjs | 1 + src/index.ts | 28 +- src/replacer.ts | 16 + src/server.ts | 19 ++ src/tsconfig.json | 12 + tsconfig.aliases.json | 8 + tsconfig.cjs.json | 8 + tsconfig.eslint.json | 3 + tsconfig.esm.json | 8 + tsconfig.json | 18 +- tsconfig.node.json | 27 ++ tsconfig.prod.json | 13 - 24 files changed, 930 insertions(+), 54 deletions(-) create mode 100644 .npmignore create mode 100644 __tests__/server.test.ts create mode 100644 __tests__/tsconfig.json create mode 100644 package.cjs-template.json create mode 100644 src/replacer.ts create mode 100644 src/server.ts create mode 100644 src/tsconfig.json create mode 100644 tsconfig.aliases.json create mode 100644 tsconfig.cjs.json create mode 100644 tsconfig.esm.json create mode 100644 tsconfig.node.json delete mode 100644 tsconfig.prod.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f4bf8bf..7fe070c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,8 +13,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: + # python-version: '3.12' cache: 'pip' - uses: pre-commit/action@v3.0.1 @@ -23,7 +24,7 @@ jobs: strategy: matrix: - node-version: [18.x, 20.x] + node-version: [20.x, 22.x] steps: - uses: actions/checkout@v4 @@ -38,3 +39,5 @@ jobs: - run: npm run format - run: npm run build:debug - run: npm run build:prod + - run: npm run check:esmloads + - run: npm run check:cjsloads diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..d80c083 --- /dev/null +++ b/.npmignore @@ -0,0 +1,7 @@ +* +!dist/** +!src/** +!package*json +!README* +!tsconfig* +tsconfig.eslint.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 19bfa74..7b29094 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: #The order matters, we want prospector to run after all the sorting was d - id: check-json # JSON that are not json # (?x) means verbose (we can add spaces for better readibility, but they are ignored) - exclude: (?x) ^(tsconfig(\.\w+)? | \.vscode/.*) \.json$ + exclude: (?x) /?(tsconfig(\.\w+)? | \.vscode/.*) \.json$ - id: check-merge-conflict - id: check-symlinks - id: check-toml @@ -19,10 +19,10 @@ repos: #The order matters, we want prospector to run after all the sorting was d # File normalization - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pre-commit/mirrors-prettier - rev: 'v3.1.0' - hooks: - - id: prettier - additional_dependencies: - - prettier@3.2.5 - - prettier-plugin-jsdoc@1.3.0 + # - repo: https://github.com/pre-commit/mirrors-prettier + # rev: 'v3.1.0' + # hooks: + # - id: prettier + # additional_dependencies: + # - prettier@3.2.5 + # - prettier-plugin-jsdoc@1.3.0 diff --git a/.vscode/settings.json b/.vscode/settings.json index 87e721d..519f205 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,10 +7,12 @@ }, "editor.formatOnSaveMode": "modificationsIfAvailable", "[javascript,typescript,jsonc,json]": { + "editor.indentSize": "tabSize", + "editor.tabSize": 2, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSaveMode": "modificationsIfAvailable", }, - "eslint.experimental.useFlatConfig": true, + "eslint.useFlatConfig": true, "jest.jestCommandLine": "npm test -- ", "jest.runMode": { "type": "on-demand", diff --git a/__tests__/replace.test.ts b/__tests__/replace.test.ts index 0d68c75..357d51d 100644 --- a/__tests__/replace.test.ts +++ b/__tests__/replace.test.ts @@ -1,5 +1,5 @@ import fc, { Arbitrary } from 'fast-check'; -import { replace } from '../src'; +import { replace } from '../src/replacer.js'; const EachSimpleType = [ ['string', fc.string()], diff --git a/__tests__/server.test.ts b/__tests__/server.test.ts new file mode 100644 index 0000000..1d71e23 --- /dev/null +++ b/__tests__/server.test.ts @@ -0,0 +1,21 @@ +import { serverFactory } from '@/server.js'; +import type { Server } from 'http'; +import request from 'supertest'; +if (process.env.liveUrl) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + //@ts-ignore this enables connection to a live server and verify the app + request = request.bind(request, process.env.liveUrl); +} + +let app: Server; + +beforeAll(() => { + app = serverFactory(); +}); + +describe('Server responds', () => { + // eslint-disable-next-line jest/expect-expect + test('Responds 200', async () => { + await request(app).get('/health').expect(200); + }); +}); diff --git a/__tests__/tsconfig.json b/__tests__/tsconfig.json new file mode 100644 index 0000000..2016363 --- /dev/null +++ b/__tests__/tsconfig.json @@ -0,0 +1,19 @@ +// Typescript config for tests +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "rootDir": "../", + "types": ["jest", "node"], + "composite": true, + "allowJs": true, + "sourceMap": true, + }, + "references": [{ "path": "../src/" }], + "include": [ + "./**/*", + "./*", + "../jest*.ts", + "../tsconfig.aliases.json", + "../package.json", + ], +} diff --git a/eslint.config.mjs b/eslint.config.mjs index 8da37b3..854e274 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -74,7 +74,7 @@ export default [ project: [ './tsconfig.eslint.json', './tsconfig.json', - './tsconfig.prod.json', + './tsconfig.node.json', ], }, }, diff --git a/jest.config.ts b/jest.config.ts index 7b3136f..5187b7d 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,15 +1,43 @@ -import type { JestConfigWithTsJest } from 'ts-jest'; +import { + createDefaultEsmPreset, + pathsToModuleNameMapper, + type JestConfigWithTsJest, +} from 'ts-jest'; + +import { compilerOptions } from './tsconfig.aliases.json'; +import packageJson from './package.json'; + +const pathAliases = { + ...compilerOptions.paths, + // Jest wants to know the folder to do the transformation, not the `src/index.js`. 🤷 + [packageJson.name]: ['src'], +}; + +// See here for more info https://kulshekhar.github.io/ts-jest/docs/getting-started/presets/#advanced +const preset = createDefaultEsmPreset({ + tsconfig: './__tests__/tsconfig.json', +}); const config: JestConfigWithTsJest = { - preset: 'ts-jest', + ...preset, + roots: [''], + modulePaths: [compilerOptions.baseUrl], + moduleNameMapper: pathsToModuleNameMapper(pathAliases, { + useESM: true, + }), + modulePathIgnorePatterns: ['/dist/', '/build/'], testRegex: [ '/tests/.*tests?.[jt]sx?', '/__tests__/.*tests?.[jt]sx?', '.*.(spec|test).[jt]sx?', ], // I dono't think we need to run the spec multiple times.. the functional test on tests/ maybe. - // We can change this if we consider it useful to run the spec tests when the code is transpiled to javascript - testPathIgnorePatterns: ['node_modules', 'build/'], + // We can change this back if we consider it useful to run the spec tests when the code is transpiled to javascript + testPathIgnorePatterns: [ + 'node_modules', + '/build/', + '/dist/', + ], testEnvironment: 'node', collectCoverageFrom: ['src/**/*.{js,ts,jsx,tsx}'], verbose: true, diff --git a/package-lock.json b/package-lock.json index 6fc41e0..16dde21 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@eslint/js": "^9.11.0", "@types/jest": "^29.5.3", "@types/node": "^22.5.5", + "@types/supertest": "^6.0.2", "@typescript-eslint/eslint-plugin": "^8.6.0", "@typescript-eslint/parser": "^8.6.0", "eslint": "^9.11.0", @@ -22,14 +23,17 @@ "jest": "^29.6.2", "prettier": "^3.3.3", "prettier-plugin-jsdoc": "^1.3.0", + "supertest": "^7.0.0", "ts-jest": "^29.2.5", "ts-node": "^10.9.2", + "tsc-alias": "^1.8.10", "tsc-watch": "^6.2.0", + "tsconfig-paths": "^4.2.0", "typescript": "5.5.3", "typescript-eslint": "^8.6.0" }, "engines": { - "node": ">=18.0.0 <21.0.0", + "node": ">=20.0.0 <23.0.0", "npm": ">=9.0.0" } }, @@ -1482,6 +1486,13 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/cookiejar": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.5.tgz", + "integrity": "sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/debug": { "version": "4.1.12", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", @@ -1550,6 +1561,13 @@ "@types/unist": "*" } }, + "node_modules/@types/methods": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@types/methods/-/methods-1.1.4.tgz", + "integrity": "sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/ms": { "version": "0.7.34", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz", @@ -1574,6 +1592,30 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/superagent": { + "version": "8.1.9", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-8.1.9.tgz", + "integrity": "sha512-pTVjI73witn+9ILmoJdajHGW2jkSaOzhiFYF1Rd3EQ94kymLqB9PjD9ISg7WaALC7+dCHT0FGe9T2LktLq/3GQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/cookiejar": "^2.1.5", + "@types/methods": "^1.1.4", + "@types/node": "*", + "form-data": "^4.0.0" + } + }, + "node_modules/@types/supertest": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-6.0.2.tgz", + "integrity": "sha512-137ypx2lk/wTQbW6An6safu9hXmajAifU/s7szAHLN/FeIm5w7yR0Wkl9fdJMRSHwOn4HLAI0DaB2TOORuhPDg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/methods": "^1.1.4", + "@types/superagent": "^8.1.0" + } + }, "node_modules/@types/unist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", @@ -1911,6 +1953,23 @@ "dev": true, "license": "Python-2.0" }, + "node_modules/array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", + "dev": true, + "license": "MIT" + }, "node_modules/async": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", @@ -1918,6 +1977,13 @@ "dev": true, "license": "MIT" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true, + "license": "MIT" + }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -2051,6 +2117,19 @@ "dev": true, "license": "MIT" }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/binary-searching": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/binary-searching/-/binary-searching-2.0.5.tgz", @@ -2144,6 +2223,26 @@ "dev": true, "license": "MIT" }, + "node_modules/call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2223,6 +2322,44 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "license": "MIT", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chokidar/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/ci-info": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", @@ -2299,6 +2436,29 @@ "dev": true, "license": "MIT" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || >=14" + } + }, "node_modules/comment-parser": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-1.4.1.tgz", @@ -2309,6 +2469,16 @@ "node": ">= 12.0.0" } }, + "node_modules/component-emitter": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", + "integrity": "sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2323,6 +2493,13 @@ "dev": true, "license": "MIT" }, + "node_modules/cookiejar": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", + "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", + "dev": true, + "license": "MIT" + }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", @@ -2431,6 +2608,34 @@ "node": ">=0.10.0" } }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/dequal": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", @@ -2465,6 +2670,17 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/dezalgo": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", + "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", + "dev": true, + "license": "ISC", + "dependencies": { + "asap": "^2.0.0", + "wrappy": "1" + } + }, "node_modules/diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -2485,6 +2701,19 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/duplexer": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", @@ -2545,6 +2774,29 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -2965,6 +3217,13 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "dev": true, + "license": "MIT" + }, "node_modules/fastq": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", @@ -3072,6 +3331,36 @@ "dev": true, "license": "ISC" }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/formidable": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-3.5.1.tgz", + "integrity": "sha512-WJWKelbRHN41m5dumb0/k8TeAx7Id/y3a+Z7QfhxP/htI9Js5zYaEDtG8uMgG0vM0lOlqnmjE99/kfpOYi/0Og==", + "dev": true, + "license": "MIT", + "dependencies": { + "dezalgo": "^1.0.4", + "hexoid": "^1.0.0", + "once": "^1.4.0" + }, + "funding": { + "url": "https://ko-fi.com/tunnckoCore/commissions" + } + }, "node_modules/from": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz", @@ -3131,6 +3420,26 @@ "node": "6.* || 8.* || >= 10.*" } }, + "node_modules/get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/get-package-type": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", @@ -3226,6 +3535,40 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "license": "MIT", + "dependencies": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, + "license": "MIT", + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -3250,6 +3593,45 @@ "node": ">=8" } }, + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", @@ -3263,6 +3645,16 @@ "node": ">= 0.4" } }, + "node_modules/hexoid": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", + "integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -3363,6 +3755,19 @@ "dev": true, "license": "MIT" }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "license": "MIT", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/is-core-module": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.1.tgz", @@ -4419,6 +4824,16 @@ "node": ">= 8" } }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/micromark": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/micromark/-/micromark-4.0.0.tgz", @@ -4896,6 +5311,42 @@ "node": ">=8.6" } }, + "node_modules/mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "dev": true, + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -4922,6 +5373,16 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -4929,6 +5390,20 @@ "dev": true, "license": "MIT" }, + "node_modules/mylas": { + "version": "2.1.13", + "resolved": "https://registry.npmjs.org/mylas/-/mylas-2.1.13.tgz", + "integrity": "sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/raouldeheer" + } + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -4980,6 +5455,19 @@ "node": ">=8" } }, + "node_modules/object-inspect": { + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", + "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -5135,6 +5623,16 @@ "dev": true, "license": "MIT" }, + "node_modules/path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/pause-stream": { "version": "0.0.11", "resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz", @@ -5247,6 +5745,19 @@ "node": ">=8" } }, + "node_modules/plimit-lit": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/plimit-lit/-/plimit-lit-1.6.1.tgz", + "integrity": "sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==", + "dev": true, + "license": "MIT", + "dependencies": { + "queue-lit": "^1.5.1" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -5376,6 +5887,32 @@ ], "license": "MIT" }, + "node_modules/qs": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.0.6" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/queue-lit": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/queue-lit/-/queue-lit-1.5.2.tgz", + "integrity": "sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -5404,6 +5941,19 @@ "dev": true, "license": "MIT" }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -5523,6 +6073,24 @@ "node": ">=10" } }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dev": true, + "license": "MIT", + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -5546,6 +6114,25 @@ "node": ">=8" } }, + "node_modules/side-channel": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", + "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "dev": true, + "license": "MIT", + "dependencies": { + "call-bind": "^1.0.7", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", @@ -5729,6 +6316,41 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/superagent": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-9.0.2.tgz", + "integrity": "sha512-xuW7dzkUpcJq7QnhOsnNUgtYp3xRwpt2F7abdRYIpCsAt0hhUqia0EdxyXZQQpNmGtsCzYHryaKSV3q3GJnq7w==", + "dev": true, + "license": "MIT", + "dependencies": { + "component-emitter": "^1.3.0", + "cookiejar": "^2.1.4", + "debug": "^4.3.4", + "fast-safe-stringify": "^2.1.1", + "form-data": "^4.0.0", + "formidable": "^3.5.1", + "methods": "^1.1.2", + "mime": "2.6.0", + "qs": "^6.11.0" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/supertest": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/supertest/-/supertest-7.0.0.tgz", + "integrity": "sha512-qlsr7fIC0lSddmA3tzojvzubYxvlGtzumcdHgPwbFWMISQwL22MhM2Y3LNt+6w9Yyx7559VW5ab70dgphm8qQA==", + "dev": true, + "license": "MIT", + "dependencies": { + "methods": "^1.1.2", + "superagent": "^9.0.1" + }, + "engines": { + "node": ">=14.18.0" + } + }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -5944,6 +6566,24 @@ } } }, + "node_modules/tsc-alias": { + "version": "1.8.10", + "resolved": "https://registry.npmjs.org/tsc-alias/-/tsc-alias-1.8.10.tgz", + "integrity": "sha512-Ibv4KAWfFkFdKJxnWfVtdOmB0Zi1RJVxcbPGiCDsFpCQSsmpWyuzHG3rQyI5YkobWwxFPEyQfu1hdo4qLG2zPw==", + "dev": true, + "license": "MIT", + "dependencies": { + "chokidar": "^3.5.3", + "commander": "^9.0.0", + "globby": "^11.0.4", + "mylas": "^2.1.9", + "normalize-path": "^3.0.0", + "plimit-lit": "^1.2.6" + }, + "bin": { + "tsc-alias": "dist/bin/index.js" + } + }, "node_modules/tsc-watch": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/tsc-watch/-/tsc-watch-6.2.0.tgz", @@ -5966,6 +6606,31 @@ "typescript": "*" } }, + "node_modules/tsconfig-paths": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", + "integrity": "sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==", + "dev": true, + "license": "MIT", + "dependencies": { + "json5": "^2.2.2", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/tsconfig-paths/node_modules/strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.cjs-template.json b/package.cjs-template.json new file mode 100644 index 0000000..589bff7 --- /dev/null +++ b/package.cjs-template.json @@ -0,0 +1,5 @@ +{ + "//": "See fast-check for example of exporting both CJS and ESM. https://github.com/dubzzz/fast-check/blob/main/packages/vitest/package.json", + "type": "commonjs", + "sideEffects": false +} diff --git a/package.json b/package.json index 6c03c55..e83307f 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,51 @@ { "name": "typescript-eslint-prettier-jest-example", "version": "0.2.0", + "type": "module", "description": "Example of Combining eslint prettier jest.", "repository": { "type": "git", "url": "https://github.com/alexrecuenco/typescript-eslint-prettier-jest-example.git" }, + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "default": "./dist/src/index.js", + "types": "./dist/src/index.d.ts" + }, + "require": { + "default": "./dist/cjs/src/index.js", + "types": "./dist/cjs/src/index.d.ts" + } + } + }, + "types": "dist/src/index.d.ts", + "main": "dist/src/index.js", + "module": "dist/src/index.js", "engines": { "npm": ">=9.0.0", - "node": ">=18.0.0 <21.0.0" + "node": ">=20.0.0 <23.0.0" }, "scripts": { - "start": "npm run build && node .", + "start": "npm run build && node . serve", + "build:prod:esm": "tsc --build tsconfig.esm.json && tsc-alias -p tsconfig.esm.json", + "build:prod:cjs": "tsc --build tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json && cp package.cjs-template.json dist/cjs/package.json", "build": "npm run build:debug", - "build:debug": "tsc", - "build:prod": "tsc --build tsconfig.prod.json", + "build:debug": "tsc && tsc --build ./__tests__/tsconfig.json", + "build:prod": "npm run build:prod:esm && npm run build:prod:cjs", "watch": "tsc-watch --onSuccess 'node .'", "lint": "eslint .", "lint:fix": "eslint . --fix", "format": "prettier . --check", "format:fix": "prettier . -w", "test": "jest", + "check:esmloads": "node -e '(async () => { var o = await import(\"typescript-eslint-prettier-jest-example\"); })();'", + "check:cjsloads": "node -e 'require(\"typescript-eslint-prettier-jest-example\");'", + "check:loads": "npm run check:esmloads && npm run check:cjsloads", + "check:builds": "npm run build:prod && npm run build:debug", + "check:lint": "npm run lint && npm run format", + "check:all": "npm run check:lint && npm run check:builds && npm run check:loads", "deps:upgrade": "npm-check -u" }, "license": "SEE LICENSE IN LICENSE", @@ -34,6 +59,7 @@ "@eslint/js": "^9.11.0", "@types/jest": "^29.5.3", "@types/node": "^22.5.5", + "@types/supertest": "^6.0.2", "@typescript-eslint/eslint-plugin": "^8.6.0", "@typescript-eslint/parser": "^8.6.0", "eslint": "^9.11.0", @@ -44,9 +70,12 @@ "jest": "^29.6.2", "prettier": "^3.3.3", "prettier-plugin-jsdoc": "^1.3.0", + "supertest": "^7.0.0", "ts-jest": "^29.2.5", "ts-node": "^10.9.2", + "tsc-alias": "^1.8.10", "tsc-watch": "^6.2.0", + "tsconfig-paths": "^4.2.0", "typescript": "5.5.3", "typescript-eslint": "^8.6.0" }, diff --git a/prettier.config.cjs b/prettier.config.cjs index 364da87..5510c1b 100644 --- a/prettier.config.cjs +++ b/prettier.config.cjs @@ -17,6 +17,7 @@ const options = { }, { files: ['tsconfig.*json', 'jsconfig.*json', '.vscode/*.json'], + excludeFiles: ['tsconfig.aliases.json'], options: { parser: 'jsonc', }, diff --git a/src/index.ts b/src/index.ts index 606abd5..9907517 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,14 @@ -export function replace( - f: (t: T) => T, - isTType: (t: any) => t is T, -): (obj: U) => U { - const recurseApply = (obj: unknown): any => { - if (isTType(obj)) return f(obj); - if (obj == null) return obj; - if (Array.isArray(obj)) return obj.map(recurseApply); - if (typeof obj === 'object') - return Object.fromEntries( - Object.entries(obj).map(([k, v]) => [k, recurseApply(v)]), - ); - return obj; - }; - return recurseApply; +import { serverFactory } from './server.js'; + +const PORT = process.env.PORT || process.env.port || 3000; +const server = serverFactory(); + +export { serverFactory }; + +if (process.argv[2] === 'serve') { + // eslint-disable-next-line no-console + server.listen(PORT, () => { + // eslint-disable-next-line no-console + console.log(`Server running at http://localhost:${PORT}/`); + }); } diff --git a/src/replacer.ts b/src/replacer.ts new file mode 100644 index 0000000..606abd5 --- /dev/null +++ b/src/replacer.ts @@ -0,0 +1,16 @@ +export function replace( + f: (t: T) => T, + isTType: (t: any) => t is T, +): (obj: U) => U { + const recurseApply = (obj: unknown): any => { + if (isTType(obj)) return f(obj); + if (obj == null) return obj; + if (Array.isArray(obj)) return obj.map(recurseApply); + if (typeof obj === 'object') + return Object.fromEntries( + Object.entries(obj).map(([k, v]) => [k, recurseApply(v)]), + ); + return obj; + }; + return recurseApply; +} diff --git a/src/server.ts b/src/server.ts new file mode 100644 index 0000000..b75265e --- /dev/null +++ b/src/server.ts @@ -0,0 +1,19 @@ +import http from 'http'; +import { replace } from './replacer.js'; + +// See simple example here + +const addOneToNumbers = replace( + (p) => p + 1, + (t: number): t is number => typeof t === 'number', +); + +let start = { a: 1, b: 2, c: { d: 3, e: 'hi' } }; +export function serverFactory() { + return http.createServer((req, res) => { + res.statusCode = 200; + start = addOneToNumbers(start); + res.setHeader('Content-Type', 'text/plain'); + res.end(`Hello World\r\n${JSON.stringify(start, null, 2)}\r\n`); + }); +} diff --git a/src/tsconfig.json b/src/tsconfig.json new file mode 100644 index 0000000..c93b1bf --- /dev/null +++ b/src/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "rootDir": "../", + "types": ["node"], + "composite": true, + "allowJs": true, + "sourceMap": true, + }, + "include": ["./**/*", "./*"], + "exclude": ["node_modules"], +} diff --git a/tsconfig.aliases.json b/tsconfig.aliases.json new file mode 100644 index 0000000..96c46e6 --- /dev/null +++ b/tsconfig.aliases.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "baseUrl": "./", + "paths": { + "@/*": ["src/*"] + } + } +} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..c842d1b --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.esm.json", + "compilerOptions": { + "outDir": "./dist/cjs", + "module": "CommonJS", + "moduleResolution": null, + }, +} diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index efd6d1e..a3eb205 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -3,9 +3,11 @@ "extends": "./tsconfig.json", // WARN: If 'include' is changed on the main config, this file would overwrite it, so you should consider modifying this. "include": [ + "package.json", "**/*.json", "src/**/*", "bin/**/*", + "jest*", "__tests__/**/*", "*.js", "*.mjs", @@ -15,4 +17,5 @@ "*.mts", "*.cts", ], + "exclude": [], } diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..e5ab27b --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,8 @@ +// This file currently just significes ESM support. +// So that if tsconfig.node changes to not be directly ESM, this one can still be used and build scripts dont change +{ + "extends": "./tsconfig.node.json", + "compilerOptions": { + // "outDir": "./dist", + }, +} diff --git a/tsconfig.json b/tsconfig.json index a29598f..0e6b008 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,12 @@ { + "extends": "./tsconfig.aliases.json", "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "ES2022", + "target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ - "module": "commonjs", + "module": "nodenext", + "moduleResolution": "nodenext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": [ /* Specify library files to be included in the compilation. */ @@ -61,7 +63,7 @@ // }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ "rootDirs": [] /* List of root folders whose combined content represents the structure of the project at runtime. */, // "typeRoots": ["./types", "./node_modules/@types"], /* List of folders to include type definitions from. */ - "types": ["node", "jest"], + "types": ["node"], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ "esModuleInterop": true, @@ -82,7 +84,15 @@ /* Advanced Options */ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ + "composite": true, }, - "include": ["src/**/*", "bin/**/*", "tests/**/*", "__tests__/**/*"], + "include": ["bin/**/*"], "exclude": ["node_modules"], + + "references": [{ "path": "./__tests__/" }, { "path": "./src/" }], + "ts-node": { + // Runtime help for ts-node + "require": ["tsconfig-paths/register"], + "esm": true, + }, } diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 0000000..1691bb0 --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,27 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + // For library (you send everything and let the consumer decide what to use, + // usually their compiler will prune the extra information) + "declaration": true, + "declarationMap": true, + "sourceMap": true, + // For application, + // WARN: if you enable the section below, make sure to modify the package.json to REMOVE the types from there + // "declaration": false, + // "declarationMap": false, + // "sourceMap": false, + /* Generates corresponding '.d.ts' file. */ + "rootDir": ".", + "types": ["node"], + }, + "include": ["src/**/*", "bin/**/*"], + "exclude": [ + "node_modules", + "./dist/", + "./build/", + "./build-*/", + "**/*.test.*", + ], +} diff --git a/tsconfig.prod.json b/tsconfig.prod.json deleted file mode 100644 index 76115a9..0000000 --- a/tsconfig.prod.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "./dist", - "declaration": false, - /* Generates corresponding '.d.ts' file. */ - "declarationMap": false, - "sourceMap": false, - "rootDir": ".", - "types": ["node"], - }, - "include": ["src/**/*", "bin/**/*"], -} From 11766e35f023aa79a52b1668d28f61579b6f3f5c Mon Sep 17 00:00:00 2001 From: alexrecuenco Date: Sun, 22 Sep 2024 23:03:43 +0200 Subject: [PATCH 2/3] Working intellisense in ESM --- .gitignore | 2 + __tests__/replace.test.ts | 2 +- __tests__/tsconfig.json | 20 +--- __tests__/tsconfig.test.json | 21 +++++ jest.config.ts | 15 +-- package.json | 3 +- {__tests__ => src}/server.test.ts | 2 +- src/{tsconfig.json => tsconfig.base.json} | 5 +- src/tsconfig.test.json | 5 + tsconfig.base.json | 107 ++++++++++++++++++++++ tsconfig.json | 99 +------------------- tsconfig.node.json | 9 +- 12 files changed, 157 insertions(+), 133 deletions(-) create mode 100644 __tests__/tsconfig.test.json rename {__tests__ => src}/server.test.ts (92%) rename src/{tsconfig.json => tsconfig.base.json} (55%) create mode 100644 src/tsconfig.test.json create mode 100644 tsconfig.base.json diff --git a/.gitignore b/.gitignore index 3511f0e..577d535 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ # Created by git when using merge tools for conflicts *.BACKUP.* *.BASE.* +!tsconfig.base* *.LOCAL.* *.REMOTE.* *_BACKUP_*.txt @@ -395,3 +396,4 @@ $RECYCLE.BIN/ *.lnk # End of https://www.gitignore.io/api/git,node,linux,macos,python,pycharm,windows,visualstudiocode +build*/ diff --git a/__tests__/replace.test.ts b/__tests__/replace.test.ts index 357d51d..2414337 100644 --- a/__tests__/replace.test.ts +++ b/__tests__/replace.test.ts @@ -1,5 +1,5 @@ +import { replace } from '@/replacer.js'; import fc, { Arbitrary } from 'fast-check'; -import { replace } from '../src/replacer.js'; const EachSimpleType = [ ['string', fc.string()], diff --git a/__tests__/tsconfig.json b/__tests__/tsconfig.json index 2016363..b2c3f0d 100644 --- a/__tests__/tsconfig.json +++ b/__tests__/tsconfig.json @@ -1,19 +1,9 @@ -// Typescript config for tests +// Fake config to satisfy the vscode intellisense { - "extends": "../tsconfig.json", + "extends": "./tsconfig.test.json", "compilerOptions": { - "rootDir": "../", - "types": ["jest", "node"], - "composite": true, - "allowJs": true, - "sourceMap": true, + "composite": false, }, - "references": [{ "path": "../src/" }], - "include": [ - "./**/*", - "./*", - "../jest*.ts", - "../tsconfig.aliases.json", - "../package.json", - ], + "include": ["./**/*", "../src/**/*"], + "exclude": ["node_modules"], } diff --git a/__tests__/tsconfig.test.json b/__tests__/tsconfig.test.json new file mode 100644 index 0000000..aeb5bd4 --- /dev/null +++ b/__tests__/tsconfig.test.json @@ -0,0 +1,21 @@ +// Typescript config for tests +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "rootDir": "../", + "types": ["jest", "node"], + "composite": true, + "allowJs": true, + "sourceMap": true, + }, + "references": [{ "path": "../src/tsconfig.base.json" }], + "include": [ + "./**/*", + "./*", + "../jest*.ts", + "../tsconfig.aliases.json", + "../package.json", + "../src/server.test.ts", + ], + "exclude": ["node_modules"], +} diff --git a/jest.config.ts b/jest.config.ts index 5187b7d..7fb8979 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -15,7 +15,7 @@ const pathAliases = { // See here for more info https://kulshekhar.github.io/ts-jest/docs/getting-started/presets/#advanced const preset = createDefaultEsmPreset({ - tsconfig: './__tests__/tsconfig.json', + tsconfig: './__tests__/tsconfig.test.json', }); const config: JestConfigWithTsJest = { @@ -27,19 +27,22 @@ const config: JestConfigWithTsJest = { }), modulePathIgnorePatterns: ['/dist/', '/build/'], testRegex: [ - '/tests/.*tests?.[jt]sx?', - '/__tests__/.*tests?.[jt]sx?', - '.*.(spec|test).[jt]sx?', + '/tests/.*tests?.[mc]?[jt]sx?$', + '/__tests__/.*tests?.[mc]?[jt]sx?$', + '.*.(spec|test).[mc]?[jt]sx?$', ], // I dono't think we need to run the spec multiple times.. the functional test on tests/ maybe. // We can change this back if we consider it useful to run the spec tests when the code is transpiled to javascript testPathIgnorePatterns: [ 'node_modules', - '/build/', + '/build[^/]*/', '/dist/', ], testEnvironment: 'node', - collectCoverageFrom: ['src/**/*.{js,ts,jsx,tsx}'], + collectCoverageFrom: [ + 'src/**/*.{js,ts,jsx,tsx}', + '!src/**/*.{spec,test}.{js,ts,jsx,tsx}', + ], verbose: true, // Important to use the AfterEnv to have the jest timeout and all the other settings inside that file to be correctly understood // See the difference between setupFiles and setupFilesAfterEnv to see the difference. diff --git a/package.json b/package.json index e83307f..6ffe678 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,7 @@ "start": "npm run build && node . serve", "build:prod:esm": "tsc --build tsconfig.esm.json && tsc-alias -p tsconfig.esm.json", "build:prod:cjs": "tsc --build tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json && cp package.cjs-template.json dist/cjs/package.json", - "build": "npm run build:debug", - "build:debug": "tsc && tsc --build ./__tests__/tsconfig.json", + "build:debug": "tsc --build ./__tests__/tsconfig.test.json && tsc --build ./src/tsconfig.test.json", "build:prod": "npm run build:prod:esm && npm run build:prod:cjs", "watch": "tsc-watch --onSuccess 'node .'", "lint": "eslint .", diff --git a/__tests__/server.test.ts b/src/server.test.ts similarity index 92% rename from __tests__/server.test.ts rename to src/server.test.ts index 1d71e23..4016b74 100644 --- a/__tests__/server.test.ts +++ b/src/server.test.ts @@ -1,6 +1,6 @@ -import { serverFactory } from '@/server.js'; import type { Server } from 'http'; import request from 'supertest'; +import { serverFactory } from './server.js'; if (process.env.liveUrl) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore this enables connection to a live server and verify the app diff --git a/src/tsconfig.json b/src/tsconfig.base.json similarity index 55% rename from src/tsconfig.json rename to src/tsconfig.base.json index c93b1bf..90eb98b 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.base.json @@ -1,12 +1,9 @@ { - "extends": "../tsconfig.json", + "extends": "../tsconfig.base.json", "compilerOptions": { "rootDir": "../", "types": ["node"], "composite": true, - "allowJs": true, - "sourceMap": true, }, "include": ["./**/*", "./*"], - "exclude": ["node_modules"], } diff --git a/src/tsconfig.test.json b/src/tsconfig.test.json new file mode 100644 index 0000000..7b515a5 --- /dev/null +++ b/src/tsconfig.test.json @@ -0,0 +1,5 @@ +{ + "extends": "../__tests__/tsconfig.json", + "include": ["../src/**/*.spec.ts", "../src/**/*.test.ts"], + "exclude": ["node_modules"], +} diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..214de8c --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,107 @@ +{ + "extends": "./tsconfig.aliases.json", + "compilerOptions": { + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "ESNext", + /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "module": "nodenext", + "moduleResolution": "nodenext", + /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "lib": [ + /* Specify library files to be included in the compilation. */ + "ES2015", + "ES2016", + "ES2017", + "ES2018", + "ES2019", + "ES2020", + "ES2021", + "ES2022", + ], + "noImplicitOverride": true, + "checkJs": true /* Report errors in .js files. */, + "declaration": true, + /* Generates corresponding '.d.ts' file. */ + "declarationMap": true, + /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": true /* Generates corresponding '.map' file. */, + "outDir": "./build", + /* Redirect output structure to the directory. */ + "rootDir": ".", + + /* Strict Type-Checking Options */ + "strict": true, + /* Enable all strict type-checking options. */ + "noImplicitAny": true, + /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, + /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + "noImplicitThis": true, + /* Raise error on 'this' expressions with an implied 'any' type. */ + "alwaysStrict": true, + /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + "noImplicitReturns": true, + /* Report error when not all code paths in function return a value. */ + "noFallthroughCasesInSwitch": true, + /* Report errors for fallthrough cases in switch statement. */ + "resolveJsonModule": true, + //"keyofStringsOnly": true, // We don't have symbol keys for objects, so this will simplify our code... + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": { + // "/package.json":["./package.json"] + // }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + "rootDirs": [] /* List of root folders whose combined content represents the structure of the project at runtime. */, + // "typeRoots": ["./types", "./node_modules/@types"], /* List of folders to include type definitions from. */ + "types": ["node"], + /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, + /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "forceConsistentCasingInFileNames": true, + /* Disallow inconsistently-cased references to the same file. */ + }, + "include": ["./**/*"], + "exclude": [ + "node_modules", + "./dist/", + "./build/", + "./build-*/", + "./**/*.spec.ts", + "./**/*.test.ts", + ], + "references": [ + { "path": "./__tests__/tsconfig.test.json" }, + { "path": "./src/tsconfig.base.json" }, + { "path": "./src/tsconfig.test.json" }, + ], + "ts-node": { + // Runtime help for ts-node + "require": ["tsconfig-paths/register"], + "esm": true, + }, +} diff --git a/tsconfig.json b/tsconfig.json index 0e6b008..1a59b60 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,98 +1,5 @@ { - "extends": "./tsconfig.aliases.json", - "compilerOptions": { - /* Basic Options */ - // "incremental": true, /* Enable incremental compilation */ - "target": "ESNext", - /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ - "module": "nodenext", - "moduleResolution": "nodenext", - /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "lib": [ - /* Specify library files to be included in the compilation. */ - "ES2015", - "ES2016", - "ES2017", - "ES2018", - "ES2019", - "ES2020", - "ES2021", - "ES2022", - ], - "noImplicitOverride": true, - "checkJs": true /* Report errors in .js files. */, - "declaration": true, - /* Generates corresponding '.d.ts' file. */ - "declarationMap": true, - /* Generates a sourcemap for each corresponding '.d.ts' file. */ - "sourceMap": true /* Generates corresponding '.map' file. */, - "outDir": "./build", - /* Redirect output structure to the directory. */ - "rootDir": ".", - - /* Strict Type-Checking Options */ - "strict": true, - /* Enable all strict type-checking options. */ - "noImplicitAny": true, - /* Raise error on expressions and declarations with an implied 'any' type. */ - "strictNullChecks": true, - /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - "noImplicitThis": true, - /* Raise error on 'this' expressions with an implied 'any' type. */ - "alwaysStrict": true, - /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - "noImplicitReturns": true, - /* Report error when not all code paths in function return a value. */ - "noFallthroughCasesInSwitch": true, - /* Report errors for fallthrough cases in switch statement. */ - "resolveJsonModule": true, - //"keyofStringsOnly": true, // We don't have symbol keys for objects, so this will simplify our code... - - /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": { - // "/package.json":["./package.json"] - // }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - "rootDirs": [] /* List of root folders whose combined content represents the structure of the project at runtime. */, - // "typeRoots": ["./types", "./node_modules/@types"], /* List of folders to include type definitions from. */ - "types": ["node"], - /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true, - /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - - /* Advanced Options */ - "forceConsistentCasingInFileNames": true, - /* Disallow inconsistently-cased references to the same file. */ - "composite": true, - }, - "include": ["bin/**/*"], - "exclude": ["node_modules"], - - "references": [{ "path": "./__tests__/" }, { "path": "./src/" }], - "ts-node": { - // Runtime help for ts-node - "require": ["tsconfig-paths/register"], - "esm": true, - }, + "extends": "./tsconfig.base.json", + "compilerOptions": {}, + "include": ["**/*"], } diff --git a/tsconfig.node.json b/tsconfig.node.json index 1691bb0..216984c 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.json", + "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "./dist", // For library (you send everything and let the consumer decide what to use, @@ -17,11 +17,4 @@ "types": ["node"], }, "include": ["src/**/*", "bin/**/*"], - "exclude": [ - "node_modules", - "./dist/", - "./build/", - "./build-*/", - "**/*.test.*", - ], } From 44088b19b7ef3c8e470e7f6b567cf7faa1173be7 Mon Sep 17 00:00:00 2001 From: alexrecuenco Date: Sun, 22 Sep 2024 23:39:55 +0200 Subject: [PATCH 3/3] Re-enable ESM By removing the concept of composites and using simple tsconfig.json --- __tests__/tsconfig.json | 9 --- __tests__/tsconfig.test.json | 21 ------ jest.config.ts | 8 +- package.json | 5 +- src/index.ts | 1 - src/tsconfig.base.json | 9 --- src/tsconfig.test.json | 5 -- {__tests__ => tests}/replace.test.ts | 0 tests/tsconfig.json | 11 +++ tsconfig.base.json | 107 --------------------------- tsconfig.eslint.json | 4 +- tsconfig.json | 107 ++++++++++++++++++++++++++- tsconfig.node.json | 3 +- 13 files changed, 124 insertions(+), 166 deletions(-) delete mode 100644 __tests__/tsconfig.json delete mode 100644 __tests__/tsconfig.test.json delete mode 100644 src/tsconfig.base.json delete mode 100644 src/tsconfig.test.json rename {__tests__ => tests}/replace.test.ts (100%) create mode 100644 tests/tsconfig.json delete mode 100644 tsconfig.base.json diff --git a/__tests__/tsconfig.json b/__tests__/tsconfig.json deleted file mode 100644 index b2c3f0d..0000000 --- a/__tests__/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -// Fake config to satisfy the vscode intellisense -{ - "extends": "./tsconfig.test.json", - "compilerOptions": { - "composite": false, - }, - "include": ["./**/*", "../src/**/*"], - "exclude": ["node_modules"], -} diff --git a/__tests__/tsconfig.test.json b/__tests__/tsconfig.test.json deleted file mode 100644 index aeb5bd4..0000000 --- a/__tests__/tsconfig.test.json +++ /dev/null @@ -1,21 +0,0 @@ -// Typescript config for tests -{ - "extends": "../tsconfig.base.json", - "compilerOptions": { - "rootDir": "../", - "types": ["jest", "node"], - "composite": true, - "allowJs": true, - "sourceMap": true, - }, - "references": [{ "path": "../src/tsconfig.base.json" }], - "include": [ - "./**/*", - "./*", - "../jest*.ts", - "../tsconfig.aliases.json", - "../package.json", - "../src/server.test.ts", - ], - "exclude": ["node_modules"], -} diff --git a/jest.config.ts b/jest.config.ts index 7fb8979..212e96e 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -15,7 +15,7 @@ const pathAliases = { // See here for more info https://kulshekhar.github.io/ts-jest/docs/getting-started/presets/#advanced const preset = createDefaultEsmPreset({ - tsconfig: './__tests__/tsconfig.test.json', + tsconfig: './tests/tsconfig.json', }); const config: JestConfigWithTsJest = { @@ -26,11 +26,7 @@ const config: JestConfigWithTsJest = { useESM: true, }), modulePathIgnorePatterns: ['/dist/', '/build/'], - testRegex: [ - '/tests/.*tests?.[mc]?[jt]sx?$', - '/__tests__/.*tests?.[mc]?[jt]sx?$', - '.*.(spec|test).[mc]?[jt]sx?$', - ], + testRegex: ['/tests/.*tests?.[mc]?[jt]sx?$', '.*.(spec|test).[mc]?[jt]sx?$'], // I dono't think we need to run the spec multiple times.. the functional test on tests/ maybe. // We can change this back if we consider it useful to run the spec tests when the code is transpiled to javascript testPathIgnorePatterns: [ diff --git a/package.json b/package.json index 6ffe678..1bb930a 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "start": "npm run build && node . serve", "build:prod:esm": "tsc --build tsconfig.esm.json && tsc-alias -p tsconfig.esm.json", "build:prod:cjs": "tsc --build tsconfig.cjs.json && tsc-alias -p tsconfig.cjs.json && cp package.cjs-template.json dist/cjs/package.json", - "build:debug": "tsc --build ./__tests__/tsconfig.test.json && tsc --build ./src/tsconfig.test.json", + "build:debug": "tsc", + "build:debug:test": "tsc --build ./tests/tsconfig.json", "build:prod": "npm run build:prod:esm && npm run build:prod:cjs", "watch": "tsc-watch --onSuccess 'node .'", "lint": "eslint .", @@ -42,7 +43,7 @@ "check:esmloads": "node -e '(async () => { var o = await import(\"typescript-eslint-prettier-jest-example\"); })();'", "check:cjsloads": "node -e 'require(\"typescript-eslint-prettier-jest-example\");'", "check:loads": "npm run check:esmloads && npm run check:cjsloads", - "check:builds": "npm run build:prod && npm run build:debug", + "check:builds": "npm run build:prod && npm run build:debug && npm run build:debug:test", "check:lint": "npm run lint && npm run format", "check:all": "npm run check:lint && npm run check:builds && npm run check:loads", "deps:upgrade": "npm-check -u" diff --git a/src/index.ts b/src/index.ts index 9907517..827eae0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,6 @@ const server = serverFactory(); export { serverFactory }; if (process.argv[2] === 'serve') { - // eslint-disable-next-line no-console server.listen(PORT, () => { // eslint-disable-next-line no-console console.log(`Server running at http://localhost:${PORT}/`); diff --git a/src/tsconfig.base.json b/src/tsconfig.base.json deleted file mode 100644 index 90eb98b..0000000 --- a/src/tsconfig.base.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../tsconfig.base.json", - "compilerOptions": { - "rootDir": "../", - "types": ["node"], - "composite": true, - }, - "include": ["./**/*", "./*"], -} diff --git a/src/tsconfig.test.json b/src/tsconfig.test.json deleted file mode 100644 index 7b515a5..0000000 --- a/src/tsconfig.test.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../__tests__/tsconfig.json", - "include": ["../src/**/*.spec.ts", "../src/**/*.test.ts"], - "exclude": ["node_modules"], -} diff --git a/__tests__/replace.test.ts b/tests/replace.test.ts similarity index 100% rename from __tests__/replace.test.ts rename to tests/replace.test.ts diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 0000000..99ed29d --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,11 @@ +// Fake config to satisfy the vscode intellisense +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "types": ["node", "jest"], + "allowJs": true, + "sourceMap": true, + }, + "include": ["./**/*", "../src/**/*"], + "exclude": ["node_modules", "../*.config.*"], +} diff --git a/tsconfig.base.json b/tsconfig.base.json deleted file mode 100644 index 214de8c..0000000 --- a/tsconfig.base.json +++ /dev/null @@ -1,107 +0,0 @@ -{ - "extends": "./tsconfig.aliases.json", - "compilerOptions": { - /* Basic Options */ - // "incremental": true, /* Enable incremental compilation */ - "target": "ESNext", - /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ - "module": "nodenext", - "moduleResolution": "nodenext", - /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "lib": [ - /* Specify library files to be included in the compilation. */ - "ES2015", - "ES2016", - "ES2017", - "ES2018", - "ES2019", - "ES2020", - "ES2021", - "ES2022", - ], - "noImplicitOverride": true, - "checkJs": true /* Report errors in .js files. */, - "declaration": true, - /* Generates corresponding '.d.ts' file. */ - "declarationMap": true, - /* Generates a sourcemap for each corresponding '.d.ts' file. */ - "sourceMap": true /* Generates corresponding '.map' file. */, - "outDir": "./build", - /* Redirect output structure to the directory. */ - "rootDir": ".", - - /* Strict Type-Checking Options */ - "strict": true, - /* Enable all strict type-checking options. */ - "noImplicitAny": true, - /* Raise error on expressions and declarations with an implied 'any' type. */ - "strictNullChecks": true, - /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - "noImplicitThis": true, - /* Raise error on 'this' expressions with an implied 'any' type. */ - "alwaysStrict": true, - /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - "noImplicitReturns": true, - /* Report error when not all code paths in function return a value. */ - "noFallthroughCasesInSwitch": true, - /* Report errors for fallthrough cases in switch statement. */ - "resolveJsonModule": true, - //"keyofStringsOnly": true, // We don't have symbol keys for objects, so this will simplify our code... - - /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": { - // "/package.json":["./package.json"] - // }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - "rootDirs": [] /* List of root folders whose combined content represents the structure of the project at runtime. */, - // "typeRoots": ["./types", "./node_modules/@types"], /* List of folders to include type definitions from. */ - "types": ["node"], - /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true, - /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - - /* Advanced Options */ - "forceConsistentCasingInFileNames": true, - /* Disallow inconsistently-cased references to the same file. */ - }, - "include": ["./**/*"], - "exclude": [ - "node_modules", - "./dist/", - "./build/", - "./build-*/", - "./**/*.spec.ts", - "./**/*.test.ts", - ], - "references": [ - { "path": "./__tests__/tsconfig.test.json" }, - { "path": "./src/tsconfig.base.json" }, - { "path": "./src/tsconfig.test.json" }, - ], - "ts-node": { - // Runtime help for ts-node - "require": ["tsconfig-paths/register"], - "esm": true, - }, -} diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index a3eb205..fea7f69 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -8,7 +8,7 @@ "src/**/*", "bin/**/*", "jest*", - "__tests__/**/*", + "tests/**/*", "*.js", "*.mjs", "*.cjs", @@ -17,5 +17,5 @@ "*.mts", "*.cts", ], - "exclude": [], + "exclude": ["node_modules"], } diff --git a/tsconfig.json b/tsconfig.json index 1a59b60..60dcfef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,106 @@ { - "extends": "./tsconfig.base.json", - "compilerOptions": {}, - "include": ["**/*"], + "extends": "./tsconfig.aliases.json", + "compilerOptions": { + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "ESNext", + /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "module": "nodenext", + "moduleResolution": "nodenext", + /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "lib": [ + /* Specify library files to be included in the compilation. */ + "ES2015", + "ES2016", + "ES2017", + "ES2018", + "ES2019", + "ES2020", + "ES2021", + "ES2022", + ], + "noImplicitOverride": true, + "checkJs": true /* Report errors in .js files. */, + "declaration": true, + /* Generates corresponding '.d.ts' file. */ + "declarationMap": true, + /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": true /* Generates corresponding '.map' file. */, + "outDir": "./build", + /* Redirect output structure to the directory. */ + "rootDir": ".", + + /* Strict Type-Checking Options */ + "strict": true, + /* Enable all strict type-checking options. */ + "noImplicitAny": true, + /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, + /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + "noImplicitThis": true, + /* Raise error on 'this' expressions with an implied 'any' type. */ + "alwaysStrict": true, + /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + "noImplicitReturns": true, + /* Report error when not all code paths in function return a value. */ + "noFallthroughCasesInSwitch": true, + /* Report errors for fallthrough cases in switch statement. */ + "resolveJsonModule": true, + //"keyofStringsOnly": true, // We don't have symbol keys for objects, so this will simplify our code... + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": { + // "/package.json":["./package.json"] + // }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + "rootDirs": [] /* List of root folders whose combined content represents the structure of the project at runtime. */, + // "typeRoots": ["./types", "./node_modules/@types"], /* List of folders to include type definitions from. */ + "types": ["node"], + /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, + /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "forceConsistentCasingInFileNames": true, + /* Disallow inconsistently-cased references to the same file. */ + }, + "include": ["./**/*"], + "exclude": [ + "node_modules", + "./dist/", + "./build/", + "./build-*/", + // Ignore tests so that tests/tsconfig.json grabs those files instead + "*.config.*", + "tests/**/*", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "jest.setup*.ts", + ], + "ts-node": { + // Runtime help for ts-node + "require": ["tsconfig-paths/register"], + "esm": true, + }, } diff --git a/tsconfig.node.json b/tsconfig.node.json index 216984c..397fcb3 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.base.json", + "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./dist", // For library (you send everything and let the consumer decide what to use, @@ -17,4 +17,5 @@ "types": ["node"], }, "include": ["src/**/*", "bin/**/*"], + "exclude": ["tests/**", "node_modules", "**/*.spec.ts", "**/*.test.ts"], }