Skip to content

Commit

Permalink
Merge next into master (#396)
Browse files Browse the repository at this point in the history
* chore: update deps (#379)

* upgrade for next realease

refactor: push 'unit' script at the end

fix: update ci

explicitkly add and remove typescript lugin

test: dont explicitly add ts plugin

test: dont explicitly add ts plugin

* create specific test for unit test test/typescript/*.ts

* fix: nullish needed for non Node.js runtime

* fix: reverse version

* fix: increase timeout

* refactor: use node instead of tap for typescript scripts

* fix: force deletion of @tapjs/typescript

* chore: update test

* chore: update command

* chore: check plugin of tap

* fixup

* chore: fix commands

---------

Co-authored-by: jean <jean.antoine.michelet@gmail.com>

* chore: update deps (#379)

* upgrade for next realease

refactor: push 'unit' script at the end

fix: update ci

explicitkly add and remove typescript lugin

test: dont explicitly add ts plugin

test: dont explicitly add ts plugin

* create specific test for unit test test/typescript/*.ts

* fix: nullish needed for non Node.js runtime

* fix: reverse version

* fix: increase timeout

* refactor: use node instead of tap for typescript scripts

* fix: force deletion of @tapjs/typescript

* chore: update test

* chore: update command

* chore: check plugin of tap

* fixup

* chore: fix commands

---------

Co-authored-by: jean <jean.antoine.michelet@gmail.com>

* update fastify deps

* test: fix jest (#399)

* test: fix jest

* test: remove mixed async and callback

---------

Co-authored-by: KaKa <23028015+climba03003@users.noreply.github.com>
Co-authored-by: jean <jean.antoine.michelet@gmail.com>
  • Loading branch information
3 people authored Jul 17, 2024
1 parent 51e3cef commit 03512cf
Show file tree
Hide file tree
Showing 40 changed files with 100 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0
with:
license-check: true
lint: true
8 changes: 0 additions & 8 deletions .swcrc

This file was deleted.

7 changes: 4 additions & 3 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ts: true
jsx: false
flow: false
# vim: set filetype=yaml :
timeout: 60
plugin:
- "!@tapjs/typescript"
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ const fastifyAutoload = async function autoload (fastify, options) {
async function getPackageType (cwd) {
const directories = cwd.split(sep)

/* c8 ignore start */
// required for paths that begin with the sep, such as linux root
directories[0] = /* istanbul ignore next - OS specific */ directories[0] !== '' ? directories[0] : sep

// ignore because OS specific evaluation
directories[0] = directories[0] !== '' ? directories[0] : sep
/* c8 ignore stop */
while (directories.length > 0) {
const filePath = join(...directories, 'package.json')

Expand Down
47 changes: 22 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@
"scripts": {
"lint": "standard | snazzy",
"lint:fix": "standard --fix | snazzy",
"test": "npm run unit && npm run typescript && npm run typescript:jest && npm run typescript:esm && npm run typescript:swc && npm run typescript:swc-node-register && npm run typescript:tsm && npm run typescript:tsx && npm run typescript:vitest && npm run typescript:esbuild",
"test": "npm run typescript && npm run typescript:jest && npm run typescript:swc-node-register && npm run typescript:tsm && npm run typescript:tsx && npm run typescript:vitest && npm run typescript:esbuild && npm run unit",
"typescript": "tsd",
"typescript:jest": "jest",
"typescript:esm": "node scripts/unit-typescript-esm.js",
"typescript:swc": "node scripts/unit-typescript-swc.js",
"typescript:swc-node-register": "node scripts/unit-typescript-swc-node-register.js",
"typescript:tsm": "node scripts/unit-typescript-tsm.js",
"typescript:tsx": "node scripts/unit-typescript-tsx.js",
"typescript:esbuild": "node scripts/unit-typescript-esbuild.js",
"typescript:vitest": "vitest run",
"typescript:vitest:dev": "vitest",
"unit": "node scripts/unit.js",
"unit:with-modules": "tap test/issues/*/test.js test/commonjs/*.js test/module/*.js test/typescript/*.ts"
"unit:with-modules": "tap plugin rm @tapjs/typescript && tap plugin list && tap build && tap test/issues/*/test.js test/commonjs/*.js test/module/*.js"
},
"repository": {
"type": "git",
Expand All @@ -43,33 +42,31 @@
"url": "https://github.com/fastify/fastify-autoload/issues"
},
"homepage": "https://github.com/fastify/fastify-autoload#readme",
"dependencies": {},
"devDependencies": {
"@fastify/pre-commit": "^2.0.2",
"@fastify/url-data": "^5.0.0",
"@swc-node/register": "^1.5.1",
"@swc/core": "^1.2.129",
"@swc/register": "^0.1.9",
"@types/jest": "^29.0.0",
"@types/node": "^20.1.0",
"@types/tap": "^15.0.5",
"esbuild": "^0.21.5",
"esbuild-register": "^3.4.1",
"fastify": "^4.0.0-rc.2",
"fastify-plugin": "^4.0.0",
"jest": "^28.1.3",
"@fastify/pre-commit": "^2.1.0",
"@fastify/url-data": "^6.0.0-pre.fv5.1",
"@swc-node/register": "^1.9.1",
"@swc/core": "^1.5.25",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.2",
"@types/tap": "^15.0.11",
"esbuild": "^0.21.4",
"esbuild-register": "^3.5.0",
"fastify": "^5.0.0-alpha.3",
"fastify-plugin": "^5.0.0-pre.fv5.1",
"jest": "^29.7.0",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
"ts-jest": "^28.0.7",
"ts-node": "^10.4.0",
"standard": "^17.1.0",
"tap": "^19.0.2",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"tsd": "^0.31.1",
"tsm": "^2.2.1",
"tsm": "^2.3.0",
"tsx": "^4.15.7",
"typescript": "^5.0.2",
"vite": "^5.0.0",
"vitest": "^0.34.1"
"typescript": "^5.4.5",
"vite": "^5.2.12",
"vitest": "^1.6.0"
},
"standard": {
"ignore": [
Expand Down
45 changes: 24 additions & 21 deletions runtime.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
'use strict'
// TODO: change x ?? (x = y) to x ??= y when next major

// runtime cache
const cache = {}

let processArgv
function checkProcessArgv (moduleName) {
/* istanbul ignore next - nullish needed for non Node.js runtime */
processArgv ?? (processArgv = (process.execArgv ?? []).concat(process.argv ?? []))
/* c8 ignore start */
// nullish needed for non Node.js runtime
processArgv ??= (process.execArgv ?? []).concat(process.argv ?? [])
/* c8 ignore stop */
return processArgv.some((arg) => arg.indexOf(moduleName) >= 0)
}

let preloadModules
function checkPreloadModules (moduleName) {
/* istanbul ignore next - nullish needed for non Node.js runtime */
preloadModules ?? (preloadModules = (process._preload_modules ?? []))
/* c8 ignore start */
// nullish needed for non Node.js runtime
preloadModules ??= (process._preload_modules ?? [])
/* c8 ignore stop */
return preloadModules.includes(moduleName)
}

let preloadModulesString
function checkPreloadModulesString (moduleName) {
preloadModulesString ?? (preloadModulesString = preloadModules.toString())
preloadModulesString ??= preloadModules.toString()
return preloadModulesString.includes(moduleName)
}

Expand All @@ -35,69 +38,69 @@ const runtime = {}
Object.defineProperties(runtime, {
tsNode: {
get () {
cache.tsNode ?? (cache.tsNode = (
cache.tsNode ??= (
// --require tsnode/register
(Symbol.for('ts-node.register.instance') in process) ||
// --loader ts-node/esm
checkProcessArgv('ts-node/esm') ||
// ts-node-dev
!!process.env.TS_NODE_DEV
))
)
return cache.tsNode
}
},
babelNode: {
get () {
cache.babelNode ?? (cache.babelNode = checkProcessArgv('babel-node'))
cache.babelNode ??= checkProcessArgv('babel-node')
return cache.babelNode
}
},
vitest: {
get () {
cache.vitest ?? (cache.vitest = (
cache.vitest ??= (
checkEnvVariable('VITEST', 'true') ||
checkEnvVariable('VITEST_WORKER_ID')
))
)
return cache.vitest
}
},
jest: {
get () {
cache.jest ?? (cache.jest = checkEnvVariable('JEST_WORKER_ID'))
cache.jest ??= checkEnvVariable('JEST_WORKER_ID')
return cache.jest
}
},
swc: {
get () {
cache.swc ?? (cache.swc = (
cache.swc ??= (
checkPreloadModules('@swc/register') ||
checkPreloadModules('@swc-node/register') ||
checkProcessArgv('.bin/swc-node')
))
)
return cache.swc
}
},
tsm: {
get () {
cache.tsm ?? (cache.tsm = checkPreloadModules('tsm'))
cache.tsm ??= checkPreloadModules('tsm')
return cache.tsm
}
},
esbuild: {
get () {
cache.esbuild ?? (cache.esbuild = checkPreloadModules('esbuild-register'))
cache.esbuild ??= checkPreloadModules('esbuild-register')
return cache.esbuild
}
},
tsx: {
get () {
cache.tsx ?? (cache.tsx = checkPreloadModulesString('tsx'))
cache.tsx ??= checkPreloadModulesString('tsx')
return cache.tsx
}
},
supportTypeScript: {
get () {
cache.supportTypeScript ?? (cache.supportTypeScript = (
cache.supportTypeScript ??= (
checkEnvVariable('FASTIFY_AUTOLOAD_TYPESCRIPT') ||
runtime.tsNode ||
runtime.vitest ||
Expand All @@ -107,17 +110,17 @@ Object.defineProperties(runtime, {
runtime.tsm ||
runtime.tsx ||
runtime.esbuild
))
)
return cache.supportTypeScript
}
},
forceESM: {
get () {
cache.forceESM ?? (cache.forceESM = (
cache.forceESM ??= (
checkProcessArgv('ts-node/esm') ||
runtime.vitest ||
false
))
)
return cache.forceESM
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/unit-typescript-esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { exec } = require('node:child_process')

const args = [
'node',
'-r esbuild-register',
'--require=esbuild-register',
'test/typescript/basic.ts'
]
const child = exec(args.join(' '), {
Expand Down
3 changes: 2 additions & 1 deletion scripts/unit-typescript-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const args = [
'tap',
'--node-arg=--loader=ts-node/esm',
'--node-arg=--experimental-specifier-resolution=node',
'--no-coverage',
'--disable-coverage',
'--allow-empty-coverage',
'test/typescript-esm/*.ts'
]

Expand Down
7 changes: 3 additions & 4 deletions scripts/unit-typescript-swc-node-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
const { exec } = require('node:child_process')

const args = [
'tap',
'--node-arg=--require=@swc-node/register',
'--no-coverage',
'test/typescript/*.ts'
'node',
'--require=@swc-node/register',
'test/typescript/basic.ts'
]

const child = exec(args.join(' '), {
Expand Down
18 changes: 0 additions & 18 deletions scripts/unit-typescript-swc.js

This file was deleted.

8 changes: 3 additions & 5 deletions scripts/unit-typescript-tsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
const { exec } = require('node:child_process')

const args = [
'tap',
'--no-ts',
'--node-arg=--require=tsm',
'--no-coverage',
'test/typescript/*.ts'
'node',
'--require=tsm',
'test/typescript/basic.ts'
]

const child = exec(args.join(' '), {
Expand Down
3 changes: 1 addition & 2 deletions test/commonjs/autohooks/routes/.autohooks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = async function (app, opts, next) {
module.exports = async function (app, opts) {
app.addHook('onRequest', async (req, reply) => {
req.hooked = req.hooked || []
req.hooked.push('root')
next()
})
}
3 changes: 1 addition & 2 deletions test/commonjs/autohooks/routes/child/.autohooks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = async function (app, opts, next) {
module.exports = async function (app, opts) {
app.addHook('onRequest', async (req, reply) => {
req.hooked = req.hooked || []
req.hooked.push('child')
next()
})
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = async function (app, opts, next) {
module.exports = async function (app, opts) {
app.addHook('onRequest', async (req, reply) => {
req.hooked = req.hooked || []
req.hooked.push('grandchild')
next()
})
}
2 changes: 1 addition & 1 deletion test/commonjs/autohooks/routes/child/grandchild/routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

module.exports = async function (app, opts, next) {
module.exports = async function (app, opts) {
app.get('/', async function (req, reply) {
reply.status(200).send({ hooked: req.hooked })
})
Expand Down
2 changes: 1 addition & 1 deletion test/commonjs/autohooks/routes/child/routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

module.exports = async function (app, opts, next) {
module.exports = async function (app, opts) {
app.get('/', async function (req, reply) {
reply.status(200).send({ hooked: req.hooked })
})
Expand Down
2 changes: 1 addition & 1 deletion test/commonjs/autohooks/routes/routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

module.exports = async function (app, opts, next) {
module.exports = async function (app, opts) {
app.get('/', async function (req, reply) {
reply.status(200).send({ hooked: req.hooked })
})
Expand Down
2 changes: 1 addition & 1 deletion test/commonjs/autohooks/routes/sibling/routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

module.exports = async function (app, opts, next) {
module.exports = async function (app, opts) {
app.get('/', async function (req, reply) {
reply.status(200).send({ hooked: req.hooked })
})
Expand Down
2 changes: 1 addition & 1 deletion test/commonjs/basic/encapsulate/plugin2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

module.exports = async (fastify, opts, next) => {
module.exports = async (fastify, opts) => {
fastify.get('/encapsulate', {
handler: async (request, reply) => {
reply.status(200).send({ works: fastify.sharedVar })
Expand Down
2 changes: 1 addition & 1 deletion test/commonjs/basic/index/bar/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

module.exports = async (server, opts, next) => {
module.exports = async (server, opts) => {
server.get('/', async (request, reply) => {
reply.status(200).send({ works: true })
})
Expand Down
Loading

0 comments on commit 03512cf

Please sign in to comment.