Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(index): convert unused capture group to non-capture group #330

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const isTsx = process._preload_modules && process._preload_modules.toString().in
const typescriptSupport = isFastifyAutoloadTypescriptOverride || isTsNode || isVitestEnvironment || isBabelNode || isJestEnvironment || isSWCRegister || isSWCNodeRegister || isSWCNode || isTsm || isTsx || isEsbuildRegister

const forceESMEnvironment = isVitestEnvironment || false
const routeParamPattern = /\/_/ig
const routeMixedParamPattern = /__/g
const routeParamPattern = /\/_/gu
const routeMixedParamPattern = /__/gu

const defaults = {
scriptPattern: /(?:(?:^.?|\.[^d]|[^.]d|[^.][^d])\.ts|\.js|\.cjs|\.mjs)$/i,
indexPattern: /^index(?:\.ts|\.js|\.cjs|\.mjs)$/i,
autoHooksPattern: /^[_.]?auto_?hooks(?:\.ts|\.js|\.cjs|\.mjs)$/i,
scriptPattern: /(?:(?:^.?|\.[^d]|[^.]d|[^.][^d])\.ts|\.js|\.cjs|\.mjs)$/iu,
indexPattern: /^index(?:\.ts|\.js|\.cjs|\.mjs)$/iu,
autoHooksPattern: /^[_.]?auto_?hooks(?:\.ts|\.js|\.cjs|\.mjs)$/iu,
dirNameRoutePrefix: true,
encapsulate: true
}
Expand Down Expand Up @@ -122,9 +122,9 @@ async function getPackageType (cwd) {
}
}

const typescriptPattern = /\.ts$/i
const modulePattern = /\.mjs$/i
const commonjsPattern = /\.cjs$/i
const typescriptPattern = /\.ts$/iu
const modulePattern = /\.mjs$/iu
const commonjsPattern = /\.cjs$/iu
function getScriptType (fname, packageType) {
return (modulePattern.test(fname) ? 'module' : commonjsPattern.test(fname) ? 'commonjs' : typescriptPattern.test(fname) ? 'typescript' : packageType) || 'commonjs'
}
Expand Down Expand Up @@ -238,7 +238,7 @@ async function findPlugins (dir, options, hookedAccumulator = {}, prefix, depth

function accumulatePlugin ({ file, type }) {
// Replace backward slash to forward slash for consistent behavior between windows and posix.
const filePath = '/' + path.relative(options.dir, file).replace(/\\/g, '/')
const filePath = '/' + path.relative(options.dir, file).replace(/\\/gu, '/')

if (matchFilter && !filterPath(filePath, matchFilter)) {
return
Expand Down Expand Up @@ -294,7 +294,7 @@ async function loadPlugin ({ file, type, directoryPrefix, options, log }) {
if (prefixOverride !== undefined) {
pluginOptions.prefix = prefixOverride
} else if (prefix) {
pluginOptions.prefix = (pluginOptions.prefix || '') + prefix.replace(/\/+/g, '/')
pluginOptions.prefix = (pluginOptions.prefix || '') + prefix.replace(/\/+/gu, '/')
}

return {
Expand Down Expand Up @@ -376,7 +376,7 @@ function isPluginOrModule (input) {
let result = false

const inputType = Object.prototype.toString.call(input)
if (/\[object (AsyncFunction|Function|Module)\]/.test(inputType) === true) {
if (/\[object (?:AsyncFunction|Function|Module)\]/u.test(inputType) === true) {
result = true
} else if (Object.prototype.hasOwnProperty.call(input, 'default')) {
result = isPluginOrModule(input.default)
Expand Down
Loading