@fastify/autoload
Advanced tools
Comparing version 5.3.0 to 5.3.1
25
index.js
@@ -8,2 +8,3 @@ 'use strict' | ||
const isTsNode = (Symbol.for('ts-node.register.instance') in process) || !!process.env.TS_NODE_DEV | ||
const isJestEnvironment = process.env.JEST_WORKER_ID !== undefined | ||
@@ -15,2 +16,3 @@ const isSWCRegister = process._preload_modules && process._preload_modules.includes('@swc/register') | ||
const isTsx = process._preload_modules && process._preload_modules.toString().includes('tsx') | ||
const typescriptSupport = isTsNode || isJestEnvironment || isSWCRegister || isSWCNodeRegister || isSWCNode || isTsm || isTsx | ||
const routeParamPattern = /\/_/ig | ||
@@ -165,8 +167,4 @@ const routeMixedParamPattern = /__/g | ||
const type = getScriptType(file, options.packageType) | ||
if (tsFileNoTsSupport()) { | ||
try { | ||
require('ts-node').register() | ||
} catch { | ||
throw new Error(`@fastify/autoload cannot import hooks plugin at '${file}'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.`) | ||
} | ||
if (type === 'typescript' && !typescriptSupport) { | ||
throw new Error(`@fastify/autoload cannot import hooks plugin at '${file}'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.`) | ||
} | ||
@@ -223,8 +221,4 @@ | ||
const type = getScriptType(file, options.packageType) | ||
if (tsFileNoTsSupport()) { | ||
try { | ||
require('ts-node').register() | ||
} catch { | ||
throw new Error(`@fastify/autoload cannot import plugin at '${file}'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.`) | ||
} | ||
if (type === 'typescript' && !typescriptSupport) { | ||
throw new Error(`@fastify/autoload cannot import plugin at '${file}'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.`) | ||
} | ||
@@ -356,9 +350,2 @@ | ||
function tsFileNoTsSupport () { | ||
const isTsNode = (Symbol.for('ts-node.register.instance') in process) || !!process.env.TS_NODE_DEV | ||
const typescriptSupport = isTsNode || isJestEnvironment || isSWCRegister || isSWCNodeRegister || isSWCNode || isTsm || isTsx | ||
// return isTsNode && !typescriptSupport | ||
return isTsNode === false && typescriptSupport === false | ||
} | ||
// do not create a new context, do not encapsulate | ||
@@ -365,0 +352,0 @@ // same as fastify-plugin |
{ | ||
"name": "@fastify/autoload", | ||
"version": "5.3.0", | ||
"version": "5.3.1", | ||
"description": "Require all plugins in a directory", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"lint:fix": "standard --fix | snazzy", | ||
"test": "npm run lint && 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 vitest", | ||
"test": "npm run lint && 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", | ||
"typescript": "tsd", | ||
@@ -21,4 +21,3 @@ "typescript:jest": "jest", | ||
"unit:with-modules": "tap test/commonjs/*.js test/module/*.js test/typescript/*.ts", | ||
"unit:without-modules": "tap test/commonjs/*.js test/typescript/*.ts", | ||
"vitest": "vitest run" | ||
"unit:without-modules": "tap test/commonjs/*.js test/typescript/*.ts" | ||
}, | ||
@@ -68,5 +67,3 @@ "repository": { | ||
"tsx": "^3.7.1", | ||
"typescript": "^4.5.4", | ||
"vite": "^3.0.9", | ||
"vitest": "^0.22.1" | ||
"typescript": "^4.5.4" | ||
}, | ||
@@ -73,0 +70,0 @@ "dependencies": { |
@@ -6,3 +6,2 @@ 'use strict' | ||
const semver = require('semver') | ||
const { join } = require('path') | ||
@@ -33,17 +32,7 @@ const moduleSupport = semver.satisfies(process.version, '>= 14 || >= 12.17.0 < 13.0.0') | ||
const mockedAutoLoad = t.mock('../../', { | ||
'ts-node': { | ||
register: function () { | ||
throw new Error('ts-node doesn\'t exist because it is mocked') | ||
} | ||
} | ||
}) | ||
app3.register(require('./ts-error/app')) | ||
app3.register(mockedAutoLoad, { | ||
dir: join(__dirname, 'ts-node/routes') | ||
}) | ||
app3.ready(function (err) { | ||
t.type(err, Error) | ||
t.match(err.message, /cannot import plugin.*typescript/i, 't.match error.message for app 3') | ||
t.match(err.message, /cannot import plugin.*typescript/i) | ||
}) | ||
@@ -50,0 +39,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22
110859
223
3219