Skip to content

Commit a2e2563

Browse files
committed
feat: use esm
BREAKING CHANGE: move code base to esm Signed-off-by: Vitor Hugo Salgado <[email protected]>
1 parent 5750f5a commit a2e2563

File tree

16 files changed

+95
-56
lines changed

16 files changed

+95
-56
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,4 @@ dist
119119
.github/
120120

121121
docs/
122-
dist/
123122
tools/

.eslintrc.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
extends: ['plugin:@typescript-eslint/recommended'],
66
env: {
77
jest: true,
8-
node: true
8+
node: true,
99
},
1010
rules: {
1111
'no-console': 'error',
@@ -14,6 +14,6 @@ module.exports = {
1414
'@typescript-eslint/no-useless-constructor': ['error'],
1515
'@typescript-eslint/no-inferrable-types': ['off'],
1616

17-
'import/extensions': ['error', 'ignorePackages', { js: 'always', jsx: 'never', ts: 'never', tsx: 'never' }]
18-
}
17+
'import/extensions': ['error', 'ignorePackages', { js: 'always', jsx: 'never', ts: 'never', tsx: 'never' }],
18+
},
1919
}

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"trailingComma": "none",
2+
"trailingComma": "all",
33
"printWidth": 120,
44
"singleQuote": true,
55
"arrowParens": "avoid",

.versionrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ module.exports = {
1010
{ type: 'refactor', section: 'Refactor', hidden: false },
1111
{ type: 'perf', section: 'Perf', hidden: false },
1212
{ type: 'test', section: 'Refactor', hidden: false },
13-
{ type: 'build', section: 'Build', hidden: false }
14-
]
13+
{ type: 'build', section: 'Build', hidden: false },
14+
],
1515
}

Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@ SHELL := /bin/bash
55
help:
66
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
77

8-
up: ## Run a development environment with Docker Compose.
9-
@docker-compose -f ./deployments/dev/docker-compose.yml up
8+
up: ## Run a local development environment with Docker Compose.
9+
@docker-compose -f ./deployments/dev/docker-compose.yml up --build --force-recreate
1010

11-
down: ## Stop Docker Compose development environment.
11+
recreate: ## Recreate and run development docker compose
12+
@docker-compose -f ./deployments/dev/docker-compose.yml up --build --force-recreate
13+
14+
down: ## Stop Docker Compose local development environment.
1215
@docker-compose -f ./deployments/dev/docker-compose.yml down
1316

14-
clean: ## Clean Docker Compose development environment.
17+
clean: ## Clean Docker Compose local development environment.
1518
@docker-compose -f ./deployments/dev/docker-compose.yml down --remove-orphans --volumes
1619

1720
.PHONY: test
18-
test:
21+
test: ## Run tests
1922
@npm test
2023

21-
fmt: # Format code
24+
fmt: ## Format code
2225
@npm run format
2326

24-
lint: # Run static analysis
27+
lint: ## Run static analysis
2528
@npm run lint
2629

27-
check: # Run all checks for this project
30+
check: ## Run all checks for this project
2831
@npm run format:check
2932
@npm run lint
3033
@npm run test

build/docker/Dockerfile.dev

Lines changed: 0 additions & 3 deletions
This file was deleted.

cmd/create-nodejs-ts/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env node
22

3-
const Path = require('path')
4-
const FsExt = require('fs-extra')
3+
import FsExt from 'fs-extra'
4+
import Path, { dirname } from 'path'
5+
import { fileURLToPath } from 'url'
6+
7+
const __dirname = dirname(fileURLToPath(import.meta.url))
58

69
const paramOr = (map, arg, def) => map.get(arg) || def
710
const makePath = (...p) => Path.join(...p)
@@ -38,7 +41,7 @@ const Ignores = [
3841
'Makefile',
3942
'package.json',
4043
'package-lock.json',
41-
'yarn.lock'
44+
'yarn.lock',
4245
]
4346

4447
const NoDeps = ['fs-extra', 'standard-release']
@@ -48,7 +51,7 @@ const Templates = [
4851
{ file: 'README.md', copyTo: 'README.md' },
4952
{ file: '.gitignore.husky', copyTo: '.husky/.gitignore' },
5053
{ file: '.gitignore.root', copyTo: '.gitignore' },
51-
{ file: '.dockerignore.root', copyTo: '.dockerignore' }
54+
{ file: '.dockerignore.root', copyTo: '.dockerignore' },
5255
]
5356

5457
const PkgFieldsToKeep = ['scripts', 'dependencies', 'devDependencies']
@@ -86,7 +89,7 @@ function main() {
8689
Summary:
8790
Destination: ${destination}
8891
App: ${app}
89-
`
92+
`,
9093
)
9194

9295
console.log('Copying Project Files ...')
@@ -102,7 +105,7 @@ App: ${app}
102105
const pkg = FsExt.readJsonSync(makePath(source, 'package.json'))
103106
const newPkg = {
104107
name: app,
105-
main: 'dist/index.js'
108+
main: 'dist/index.js',
106109
}
107110

108111
PkgFieldsToKeep.forEach(field => {
@@ -128,4 +131,4 @@ App: ${app}
128131
return Promise.resolve()
129132
}
130133

131-
main().catch(console.error)
134+
await main()

deployments/dev/docker-compose.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ version: '3.8'
22

33
services:
44
dev-app:
5-
build:
6-
context: ./
7-
dockerfile: ../../build/docker/Dockerfile.dev
8-
container_name: nodejs-ts.dev-app
5+
image: node:16.14.2
6+
working_dir: /app
97
volumes:
108
- ../../:/app
9+
- ../../node_modules:/app/node_modules
10+
- ../../dist:/app/dist
11+
command: bash -c "npm i --quiet --ignore-scripts && npm run start:dev"
1112
ports:
12-
- 8080:8080
13+
- "8080:8080"
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import 'dotenv/config'
2-
import type { Config as JestConfig } from '@jest/types'
32

4-
const config: JestConfig.InitialOptions = {
3+
export default {
54
verbose: true,
65
collectCoverage: false,
76
restoreMocks: true,
8-
transform: { '^.+\\.tsx?$': 'ts-jest' },
7+
transform: {},
8+
preset: 'ts-jest/presets/default-esm',
9+
extensionsToTreatAsEsm: ['.ts'],
910
globals: {
1011
'ts-jest': {
11-
tsconfig: './tsconfig.test.json'
12-
}
12+
tsconfig: './tsconfig.test.json',
13+
useESM: true,
14+
},
1315
},
1416
collectCoverageFrom: ['**/src/*/**/*.ts', '!**/__fixtures__/**', '!**/__tests__/**'],
1517
coveragePathIgnorePatterns: ['<rootDir>/dist/', '/node_modules/', '<rootDir>/scripts', '<rootDir>/tools'],
@@ -19,9 +21,7 @@ const config: JestConfig.InitialOptions = {
1921
branches: 10,
2022
functions: 10,
2123
lines: 10,
22-
statements: 10
23-
}
24-
}
24+
statements: 10,
25+
},
26+
},
2527
}
26-
27-
export default config

lint-staged.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
module.exports = {
44
'*.{js,jsx,ts,tsx,md,json}': 'prettier --write --ignore-unknown',
5-
'*.ts': 'eslint --ext .ts .'
5+
'*.ts': 'eslint --ext .ts .',
66
}

0 commit comments

Comments
 (0)