Skip to content

Commit

Permalink
Switch to ES Modules (#34)
Browse files Browse the repository at this point in the history
* Switch to ESM
* update dependencies, pin to minor version
  • Loading branch information
jsynowiec committed Mar 12, 2022
1 parent 30b5db8 commit d2982e3
Show file tree
Hide file tree
Showing 8 changed files with 1,663 additions and 1,597 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ insert_final_newline = true
insert_final_newline = false
trim_trailing_whitespace = false

[*.{js,jsx,json,ts,tsx,yml}]
[*.{js,json,ts,yml,yaml}]
indent_size = 2
indent_style = space
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
"sourceType": "module",
"ecmaVersion": 2020
},
"plugins": ["@typescript-eslint", "jest"],
"extends": [
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
🏃🏽 Instant Value: All basic tools included and configured:

- [TypeScript][typescript] [4.5][typescript-4-5]
- [ESM][esm]
- [ESLint][eslint] with some initial rules recommendation
- [Jest][jest] for fast unit testing and code coverage
- Type definitions for Node.js and Jest
Expand Down Expand Up @@ -68,6 +69,10 @@ unzip node-typescript-boilerplate.zip && rm node-typescript-boilerplate.zip

I recommend to [install][volta-getting-started] Volta and use it to manage your project's toolchain.

### ES Modules

Warning: This template is native [ESM][esm]. If your project uses CommonJS, you will have to [convert to ESM][sindresorhus-esm] or use the [dynamic import()][dynamic-import] function. Please do not open issues for questions regarding CommonJS or ESM.

### Writing tests in JavaScript

Writing unit tests in TypeScript can sometimes be troublesome and confusing. Especially when mocking dependencies and using spies.
Expand Down Expand Up @@ -102,3 +107,6 @@ Licensed under the APLv2. See the [LICENSE](https://github.com/jsynowiec/node-ty
[volta-tomdale]: https://twitter.com/tomdale/status/1162017336699838467?s=20
[gh-actions]: https://github.com/features/actions
[repo-template-action]: https://github.com/jsynowiec/node-typescript-boilerplate/generate
[esm]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
[sindresorhus-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[dynamic-import]: https://v8.dev/features/dynamic-import
26 changes: 14 additions & 12 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
module.exports = {
export default {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
useESM: true,
},
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
"^.+\\.tsx?$": "ts-jest"
"^.+\\.ts$": "ts-jest"
},
moduleFileExtensions: [
"ts",
"tsx",
"js",
"jsx",
"json",
"node",
],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(ts|js)x?$',
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.ts$',
coverageDirectory: 'coverage',
collectCoverageFrom: [
'src/**/*.{ts,tsx,js,jsx}',
'src/**/*.ts',
'!src/**/*.d.ts',
],
};
Loading

0 comments on commit d2982e3

Please sign in to comment.