Skip to content

Commit 0df2eb3

Browse files
committed
feat: Only export as ESM.
1 parent 7268f1b commit 0df2eb3

File tree

8 files changed

+40
-52
lines changed

8 files changed

+40
-52
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Use Node.js LTS
1111
uses: actions/setup-node@v2
1212
with:
13-
node-version: 12.x
13+
node-version: lts/*
1414
- name: Restore cached dependencies
1515
uses: actions/cache@v2
1616
with:

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ If the UI is enabled, it will be reachable at `/${prefix}`.
4040
## Example
4141

4242
```js
43-
const server = require('fastify')()
43+
import fastify from 'fastify'
44+
import fastifyOpenapiDocs from 'fastify-openapi-docs'
4445

45-
server.register(require('fastify-openapi-docs'), {
46+
const server = fastify()
47+
48+
server.register(fastifyOpenapiDocs, {
4649
openapi: {
4750
// All these fields are optional, but they should be provided to satisfy OpenAPI specification.
4851
openapi: '3.0.3',

package.json

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,43 @@
2323
"LICENSE.md",
2424
"README.md"
2525
],
26-
"main": "dist/cjs/index.js",
27-
"exports": {
28-
"require": "./dist/cjs/index.js",
29-
"import": "./dist/mjs/index.mjs"
30-
},
26+
"type": "module",
27+
"main": "./dist/index.js",
28+
"exports": "./dist/index.js",
3129
"typings": "types/index.d.ts",
3230
"types": "types/index.d.ts",
3331
"scripts": {
34-
"lint": "eslint src/*.ts test/*.ts",
35-
"test": "tap --reporter=spec --coverage-report=html --coverage-report=text --no-browser test/*.test.ts",
36-
"test:ci": "tap --no-color --reporter=spec --coverage-report=json --coverage-report=text --branches 90 --functions 90 --lines 90 --statements 90 test/*.test.ts",
37-
"ci": "npm run lint && npm run test:ci",
3832
"prebuild": "rm -rf dist types && npm run lint",
39-
"build": "tsc -p . && tsc -p tsconfig.modules.json && renamer --find js --replace mjs dist/mjs/* >> /dev/null && jscodeshift -s --extensions=mjs -t node_modules/@cowtech/esm-package-utils dist/mjs/**",
33+
"build": "tsc -p . && esm-pkg-add-imports-extensions dist",
34+
"format": "prettier -w src test",
35+
"lint": "eslint src test",
36+
"test": "c8 --reporter=text --reporter=html esm-ts-tap --reporter=spec --no-coverage test/*.test.ts",
37+
"test:ci": "c8 --reporter=text --reporter=json --check-coverage --branches 90 --functions 90 --lines 90 --statements 90 esm-ts-tap --no-color --no-coverage test/*.test.ts",
38+
"ci": "npm run lint && npm run test:ci",
4039
"prepublishOnly": "npm run ci",
4140
"postpublish": "git push origin && git push origin -f --tags"
4241
},
4342
"dependencies": {
4443
"fastify-plugin": "^3.0.0",
45-
"fastify-static": "^3.3.0",
46-
"js-yaml": "^3.14.1",
47-
"swagger-ui-dist": "^3.38.0"
44+
"fastify-static": "^4.2.3",
45+
"js-yaml": "^4.1.0",
46+
"swagger-ui-dist": "^4.0.0-beta.4"
4847
},
4948
"devDependencies": {
50-
"@cowtech/eslint-config": "^7.14.0",
51-
"@cowtech/esm-package-utils": "^0.2.0",
52-
"@types/js-yaml": "^3.12.5",
53-
"@types/node": "^14.14.19",
54-
"@types/swagger-ui-dist": "^3.30.0",
55-
"@types/tap": "^14.10.1",
56-
"fastify": "^3.9.2",
57-
"prettier": "^2.2.1",
58-
"tap": "^14.11.0",
59-
"typescript": "^4.1.3"
49+
"@cowtech/eslint-config": "^7.14.5",
50+
"@cowtech/esm-package-utils": "^0.9.0",
51+
"@types/js-yaml": "^4.0.2",
52+
"@types/node": "^16.6.1",
53+
"@types/swagger-ui-dist": "^3.30.1",
54+
"@types/tap": "^15.0.5",
55+
"c8": "^7.8.0",
56+
"fastify": "^3.20.2",
57+
"prettier": "^2.3.2",
58+
"tap": "^15.0.9",
59+
"ts-node": "^10.2.0",
60+
"typescript": "^4.2.4"
6061
},
6162
"engines": {
62-
"node": ">=12.15.0"
63+
"node": ">=14.15.0"
6364
}
6465
}
File renamed without changes.

src/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,3 @@ export const plugin = fastifyPlugin(
6363
)
6464

6565
export default plugin
66-
67-
// Fix CommonJS exporting
68-
/* istanbul ignore else */
69-
if (typeof module !== 'undefined') {
70-
module.exports = plugin
71-
Object.assign(module.exports, exports)
72-
}

test/spec.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ info:
109109
description: Description
110110
contact:
111111
name: Shogun
112-
url: 'https://cowtech.it'
112+
url: https://cowtech.it
113113
email: shogun@cowtech.it
114114
license:
115115
name: ISC
116-
url: 'https://choosealicense.com/licenses/isc/'
116+
url: https://choosealicense.com/licenses/isc/
117117
version: 1.0.0
118118
servers:
119-
- url: 'https://example.com'
119+
- url: https://example.com
120120
description: Production Server
121-
- url: 'https://dev.example.com'
121+
- url: https://dev.example.com
122122
description: Development Server
123123
tags:
124124
- name: service

tsconfig.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"compilerOptions": {
3-
"target": "es2019",
4-
"module": "commonjs",
3+
"target": "ES2020",
4+
"module": "ESNext",
55
"moduleResolution": "node",
66
"jsx": "preserve",
7-
"outDir": "dist/cjs",
7+
"declaration": true,
8+
"outDir": "dist",
89
"declarationDir": "types",
910
"allowJs": false,
1011
"allowSyntheticDefaultImports": true,
@@ -13,8 +14,7 @@
1314
"noImplicitAny": true,
1415
"noUnusedLocals": true,
1516
"noUnusedParameters": true,
16-
"strictNullChecks": true,
17-
"declaration": true
17+
"strictNullChecks": true
1818
},
1919
"include": ["src/*.ts"],
2020
"exclude": []

tsconfig.modules.json

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

0 commit comments

Comments
 (0)