Skip to content

Commit

Permalink
feat!: support only ECMAScript Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
L2jLiga committed Oct 16, 2021
1 parent 9ee1644 commit 2e2ec29
Show file tree
Hide file tree
Showing 105 changed files with 604 additions and 2,274 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ dist
coverage
# don't lint scripts/configs
*.js
*.cjs
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
* text=auto

# Source code
*.cjs text eol=lf linguist-language=JavaScript
*.js text eol=lf linguist-language=JavaScript
*.json text eol=lf linguist-language=JSON-With-Comments
*.ts text eol=lf linguist-language=TypeScript
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ jobs:
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lock-file
- name: Build projects (with ESM)
- name: Build projects
run: yarn build
- name: Run library tests (with ESM)
- name: Run tests
run: yarn test
env:
CI: true
- name: Upload unit-tests coverage to Codecov
uses: codecov/codecov-action@v2.1.0
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
node_modules
*.log
*.sarif
*.tsbuildinfo
4 changes: 2 additions & 2 deletions .idea/runConfigurations/Library_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- BREAKING: minimal supported Node.js version is v12.13.1
- BREAKING: moved dependency injection functionality into separate package
- BREAKING: removed CommonJS build
- BREAKING: minimal TypeScript version supported is 4.0

## 3.10.0

Expand Down
9 changes: 1 addition & 8 deletions docs/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,7 @@ module.exports = {
// Note resolver required only when using imports with extensions
resolver: 'jest-ts-webcompat-resolver',
// In test environment we setup reflect-metadata
testEnvironment: './jest.environment.cjs',
// Jest does not support ESM modules well, so you will need to define mappings to CJS modules
moduleNameMapper: {
'^fastify-decorators/testing$': 'fastify-decorators/testing/index.cjs',
'^fastify-decorators/plugins$': 'fastify-decorators/plugins/index.cjs',
'^fastify-decorators$': 'fastify-decorators/index.cjs',
},
testEnvironment: './jest.environment.js',
};
```

Expand Down Expand Up @@ -330,4 +324,3 @@ describe('Application: authorization', () => {
```

[`reflect-metadata`]: https://npmjs.com/package/reflect-metadata
[`jest.environment.cjs`]: ../jest.environment.cjs
4 changes: 2 additions & 2 deletions examples/aws-lambda/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const baseConfig = require('../../jest.examples.config');
import baseConfig from '../../jest.examples.config.js';

module.exports = {
export default {
...baseConfig,
coverageDirectory: './coverage/integration/aws-lambda',
testRegex: 'examples/aws-lambda/test/.*.test.ts$',
Expand Down
9 changes: 5 additions & 4 deletions examples/aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "Example how to use fastify-decorators to write controllers",
"version": "1.0.0",
"main": "dist/index.js",
"type": "module",
"license": "MIT",
"scripts": {
"build": "ncc build src/index.ts -o dist",
"test": "jest"
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
},
"dependencies": {
"aws-lambda-fastify": "^1.7.1",
Expand All @@ -17,12 +18,12 @@
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/node": "~12.20.28",
"@types/node": "~12.20.33",
"@vercel/ncc": "^0.31.1",
"jest": "^27.2.5",
"jest-ts-webcompat-resolver": "^1.0.0",
"ts-jest": "^27.0.5",
"ts-jest": "^27.0.6",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
"typescript": "^4.4.4"
}
}
3 changes: 1 addition & 2 deletions examples/aws-lambda/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

/* Basic Options */
"target": "ES2019",
"module": "CommonJS",
"module": "ESNext",
"outDir": "./dist",
"importHelpers": true,

/* Strict Type-Checking Options */
"strict": true,
Expand Down
4 changes: 2 additions & 2 deletions examples/controllers/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const baseConfig = require('../../jest.examples.config');
import baseConfig from '../../jest.examples.config.js';

module.exports = {
export default {
...baseConfig,
coverageDirectory: './coverage/integration/controllers',
testRegex: 'examples/controllers/test/.*.test.ts$',
Expand Down
11 changes: 6 additions & 5 deletions examples/controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"description": "Example how to use fastify-decorators to write controllers",
"version": "1.0.0",
"main": "dist/index.js",
"type": "module",
"license": "MIT",
"scripts": {
"start": "node dist/index.js",
"start": "node dist/start.js",
"build": "tsc -p tsconfig.app.json",
"test": "jest"
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
},
"dependencies": {
"fastify": "^3.22.0",
Expand All @@ -17,10 +18,10 @@
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/node": "~12.20.28",
"@types/node": "~12.20.33",
"jest": "^27.2.5",
"jest-ts-webcompat-resolver": "^1.0.0",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3"
"ts-jest": "^27.0.6",
"typescript": "^4.4.4"
}
}
18 changes: 3 additions & 15 deletions examples/controllers/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
import { fastify } from 'fastify';
import { bootstrap } from 'fastify-decorators';
import { dirname } from 'path';
import { fileURLToPath } from 'url';

export const app = fastify();

const address = '127.0.0.1';
const port = 3001;

app.register(bootstrap, {
directory: __dirname,
directory: dirname(fileURLToPath(import.meta.url)),
});

if (module.parent == null) {
app.listen(port, address, (error, address) => {
if (error != null) {
console.error(error);
process.exit(-1);
}
console.log(`Application start and listening at ${address}`);
console.log(`Available routes: \n${app.printRoutes()}`);
});
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { app } from './app.js';
import { app } from './index.js';

const address = '127.0.0.1';
const port = 3001;
const hostname = '127.0.0.1';
const port = 3003;

app.listen(port, address, (error, address) => {
app.listen(port, hostname, (error, address) => {
if (error != null) {
console.error(error);
process.exit(-1);
Expand Down
5 changes: 3 additions & 2 deletions examples/controllers/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"extends": "./tsconfig.base.json",
"files": ["src/index.ts"],
"files": ["src/index.ts", "src/start.ts"],
"include": ["src/**/*.ts"],
"compilerOptions": {
"composite": true
"composite": true,
"rootDir": "src"
},
"references": [
{
Expand Down
3 changes: 1 addition & 2 deletions examples/controllers/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

/* Basic Options */
"target": "ES2019",
"module": "CommonJS",
"module": "ESNext",
"outDir": "./dist",
"importHelpers": true,

/* Strict Type-Checking Options */
"strict": true,
Expand Down
2 changes: 2 additions & 0 deletions examples/controllers/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": "./tsconfig.base.json",
"include": ["test/**/*.ts"],
"compilerOptions": {
"allowJs": true,

"composite": true
},
"references": [
Expand Down
3 changes: 0 additions & 3 deletions examples/esm/.gitignore

This file was deleted.

19 changes: 0 additions & 19 deletions examples/esm/.mocharc.yml

This file was deleted.

1 change: 0 additions & 1 deletion examples/esm/.npmrc

This file was deleted.

1 change: 0 additions & 1 deletion examples/esm/.yarnrc

This file was deleted.

9 changes: 0 additions & 9 deletions examples/esm/README.md

This file was deleted.

Loading

0 comments on commit 2e2ec29

Please sign in to comment.