From 74819fbd73bea7a8ba976368c3b504d2d21e24dd Mon Sep 17 00:00:00 2001 From: likui <2218301630@qq.com> Date: Mon, 20 Jul 2020 17:28:59 +0800 Subject: [PATCH] fix: fix test --- src/node/resolver.ts | 2 +- src/node/server/serverPluginModuleRewrite.ts | 12 ++++++++++-- src/node/utils/pathUtils.ts | 9 +++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/node/resolver.ts b/src/node/resolver.ts index b4a4990eabf826..a602d85da71ef1 100644 --- a/src/node/resolver.ts +++ b/src/node/resolver.ts @@ -254,7 +254,7 @@ export function createResolver( // example id: "@babel/runtime/helpers/esm/slicedToArray" // see the test case: /playground/TestNormalizePublicPath.vue - const id = publicPath.replace(moduleRE, '') + const id = cleanPublicPath.replace(moduleRE, '') const { scope, name, inPkgPath } = parseNodeModuleId(id) if (!inPkgPath) return publicPath let filePathPostFix = '' diff --git a/src/node/server/serverPluginModuleRewrite.ts b/src/node/server/serverPluginModuleRewrite.ts index 878a7c589ecd2c..68b0c5e3040ff7 100644 --- a/src/node/server/serverPluginModuleRewrite.ts +++ b/src/node/server/serverPluginModuleRewrite.ts @@ -22,7 +22,13 @@ import { hmrDirtyFilesMap, latestVersionsMap } from './serverPluginHmr' -import { readBody, cleanUrl, isExternalUrl, bareImportRE } from '../utils' +import { + readBody, + cleanUrl, + isExternalUrl, + bareImportRE, + removeQueryTimestamp +} from '../utils' import chalk from 'chalk' import { isCSSRequest } from '../utils/cssUtils' import { envPublicPath } from './serverPluginEnv' @@ -76,7 +82,9 @@ export const moduleRewritePlugin: ServerPlugin = ({ // before we perform hmr analysis. // on the other hand, static import is guaranteed to have extension // because they must all have gone through module rewrite. - const importer = resolver.normalizePublicPath(ctx.path) + const importer = removeQueryTimestamp( + resolver.normalizePublicPath(ctx.url) + ) ctx.body = rewriteImports( root, content!, diff --git a/src/node/utils/pathUtils.ts b/src/node/utils/pathUtils.ts index 30c7d44ddcd7a7..68f4211ce9d106 100644 --- a/src/node/utils/pathUtils.ts +++ b/src/node/utils/pathUtils.ts @@ -87,3 +87,12 @@ export function parseNodeModuleId(id: string) { inPkgPath } } + +export function removeQueryTimestamp(url: string) { + if (url.includes('t=')) { + const { path, query } = parseWithQuery(url) + delete query.t + return path + qs.stringify(query) + } + return url +}