From 086dc36c7e7487706045073bdf1c82938416d06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Mon, 14 Nov 2022 21:23:27 +0900 Subject: [PATCH] perf: regexp perf issues, refactor regexp stylistic issues (#10905) fix https://github.com/vitejs/vite/issues/10900 --- .eslintrc.cjs | 9 ++++++--- package.json | 1 + packages/plugin-vue/src/handleHotUpdate.ts | 4 ++-- .../__tests__/vue-server-origin.spec.ts | 2 +- scripts/rollupLicensePlugin.mjs | 2 +- scripts/verifyCommit.ts | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 6333ec25..59a3579c 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -7,9 +7,10 @@ module.exports = defineConfig({ extends: [ 'eslint:recommended', 'plugin:node/recommended', - 'plugin:@typescript-eslint/recommended' + 'plugin:@typescript-eslint/recommended', + 'plugin:regexp/recommended' ], - plugins: ['import'], + plugins: ['import', 'regexp'], parser: '@typescript-eslint/parser', parserOptions: { sourceType: 'module', @@ -97,7 +98,9 @@ module.exports = defineConfig({ memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], allowSeparatedGroups: false } - ] + ], + + 'regexp/no-contradiction-with-assertion': 'error' }, overrides: [ { diff --git a/package.json b/package.json index 06dff567..e04e96d5 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "eslint-define-config": "^1.11.0", "eslint-plugin-import": "^2.26.0", "eslint-plugin-node": "^11.1.0", + "eslint-plugin-regexp": "^1.10.0", "execa": "^6.1.0", "fast-glob": "^3.2.12", "fs-extra": "^10.1.0", diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 0db6b23f..5b2d9595 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -11,7 +11,7 @@ import type { ResolvedOptions } from '.' const debug = _debug('vite:hmr') -const directRequestRE = /(\?|&)direct\b/ +const directRequestRE = /(?:\?|&)direct\b/ /** * Vite-specific HMR handling @@ -148,7 +148,7 @@ export async function handleHotUpdate( affectedModules.add(mainModule) } else if (mainModule && !affectedModules.has(mainModule)) { const styleImporters = [...mainModule.importers].filter((m) => - /\.css($|\?)/.test(m.url) + /\.css(?:$|\?)/.test(m.url) ) styleImporters.forEach((m) => affectedModules.add(m)) } diff --git a/playground/vue-server-origin/__tests__/vue-server-origin.spec.ts b/playground/vue-server-origin/__tests__/vue-server-origin.spec.ts index 777ee09b..ef118ef7 100644 --- a/playground/vue-server-origin/__tests__/vue-server-origin.spec.ts +++ b/playground/vue-server-origin/__tests__/vue-server-origin.spec.ts @@ -3,7 +3,7 @@ import { isBuild, page } from '~utils' test('should render', async () => { const expected = isBuild - ? /assets\/asset\.[0-9a-f]+\.png/ + ? /assets\/asset\.[\da-f]+\.png/ : 'http://localhost/server-origin/test/assets/asset.png' expect(await page.getAttribute('img', 'src')).toMatch(expected) diff --git a/scripts/rollupLicensePlugin.mjs b/scripts/rollupLicensePlugin.mjs index 1a3e242e..fedbd34b 100644 --- a/scripts/rollupLicensePlugin.mjs +++ b/scripts/rollupLicensePlugin.mjs @@ -90,7 +90,7 @@ function licensePlugin(licenseFilePath, licenseTitle, packageName) { '\n' + licenseText .trim() - .replace(/(\r\n|\r)/gm, '\n') + .replace(/(\r\n|\r)/g, '\n') .split('\n') .map((line) => `> ${line}`) .join('\n') + diff --git a/scripts/verifyCommit.ts b/scripts/verifyCommit.ts index 848295dd..4d149d97 100644 --- a/scripts/verifyCommit.ts +++ b/scripts/verifyCommit.ts @@ -9,7 +9,7 @@ const msg = readFileSync(msgPath, 'utf-8').trim() const releaseRE = /^v\d/ const commitRE = - /^(revert: )?(feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(\(.+\))?: .{1,50}/ + /^(?:revert: )?(?:feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(?:\(.+\))?: .{1,50}/ if (!releaseRE.test(msg) && !commitRE.test(msg)) { console.log()