Skip to content

Commit

Permalink
ESM Support (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 authored Dec 30, 2023
1 parent 831cc17 commit 8597db7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
File renamed without changes.
33 changes: 27 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@
"name": "@fastify/type-provider-typebox",
"version": "3.6.0",
"description": "A Type Provider for Typebox over Fastify",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"module": "dist/esm/index.mjs",
"main": "dist/cjs/index.js",
"types": "dist/cjs/index.d.ts",
"exports": {
".": {
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
}
}
},
"peerDependencies": {
"@sinclair/typebox": ">=0.26 <=0.32"
},
"scripts": {
"build": "rimraf ./dist && mkdir dist && tsc --outDir dist",
"test": "npm run build && npm run typescript && tap tests/index.js --no-check-coverage",
"lint": "eslint . --ext .ts --ext .js",
"build:clean": "rimraf ./dist",
"build:cjs": "tsc --outDir dist/cjs --module CommonJS --moduleResolution Node10 --sourcemap false",
"build:esm": "tsc --outDir dist/esm --module NodeNext --moduleResolution NodeNext --sourcemap false",
"build:post": "node post-build.js",
"build:test": "attw --pack .",
"build": "npm-run-all build:clean build:cjs build:esm build:post build:test",
"test:tap": "tap tests/index.js --no-check-coverage",
"test:types": "tsd",
"test": "npm-run-all build test:tap test:types",
"lint:fix": "npm run lint -- --fix",
"typescript": "tsd",
"lint": "eslint . --ext .ts --ext .js --ext .mts --ext .mjs",
"prepublishOnly": "npm run build"
},
"repository": {
Expand All @@ -30,6 +49,7 @@
},
"homepage": "https://github.com/fastify/fastify-type-provider-typebox#readme",
"devDependencies": {
"@arethetypeswrong/cli": "^0.13.5",
"@types/node": "^20.1.0",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.32.0",
Expand All @@ -41,6 +61,7 @@
"fastify": "^4.17.0",
"fastify-plugin": "^4.5.0",
"fastify-tsconfig": "^2.0.0",
"npm-run-all": "^4.1.5",
"rimraf": "^5.0.0",
"tap": "^16.3.0",
"tsd": "^0.29.0",
Expand Down
17 changes: 17 additions & 0 deletions post-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ------------------------------------------------------------------
// Post Build
//
// TypeScript emits .mjs files when compiling from .mts. This
// is true even if the module target is set to CommonJS. This
// code renames the compiler emitted files to use the correct
// file extension.
//
// Run via:
//
// $ npm run build:post
//
// ------------------------------------------------------------------

const fs = require('fs')
fs.renameSync('dist/cjs/index.d.mts', 'dist/cjs/index.d.ts')
fs.renameSync('dist/cjs/index.mjs', 'dist/cjs/index.js')
2 changes: 1 addition & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const tap = require('tap')
const Fastify = require('fastify')
const { Type, TypeBoxValidatorCompiler } = require('../dist/index')
const { Type, TypeBoxValidatorCompiler } = require('../dist/cjs/index')

// This test ensures AJV ignores the TypeBox [Kind] symbol property in strict
tap.test('should compile typebox schema without configuration', async t => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"sourceMap": true,
"declaration": true
},
"exclude": ["./node_modules", "types/**/*.test-d.ts"]
"exclude": ["./node_modules", "types/**/*.test-d.mts"]
}
2 changes: 1 addition & 1 deletion types/index.test-d.ts → types/index.test-d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type, TypeBoxTypeProvider } from '../index'
import { Type, TypeBoxTypeProvider } from '../index.mjs'
import { expectAssignable, expectType } from 'tsd'
import Fastify, { FastifyInstance, FastifyBaseLogger, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerDefault } from 'fastify'

Expand Down
2 changes: 1 addition & 1 deletion types/plugin.test-d.ts → types/plugin.test-d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Type, FastifyPluginAsyncTypebox, FastifyPluginCallbackTypebox } from '../index'
import { Type, FastifyPluginAsyncTypebox, FastifyPluginCallbackTypebox } from '../index.mjs'
import { expectType } from 'tsd'
import Fastify, { FastifyPluginAsync, FastifyPluginCallback } from 'fastify'
import fp from 'fastify-plugin'
Expand Down

0 comments on commit 8597db7

Please sign in to comment.