From cfda7b3fcb12df9e3356f7281486b6b36d9c7f0c Mon Sep 17 00:00:00 2001 From: patak Date: Wed, 16 Nov 2022 23:52:26 +0100 Subject: [PATCH] chore: setIsSelfAccepting param to isSelfAccepting --- .../vite/src/node/plugins/importAnalysis.ts | 9 +++++++-- packages/vite/src/node/server/moduleGraph.ts | 17 ++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 8162f621988630..b1dd6d2341d3c2 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -361,11 +361,16 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { // its last updated timestamp to force the browser to fetch the most // up-to-date version of this module. try { - // delay setting `isSelfAccepting` until the file is actually used (#7870) const depModule = await moduleGraph.ensureEntryFromUrl( unwrapId(url), ssr, - canSkipImportAnalysis(url) || forceSkipImportAnalysis + // delay setting `isSelfAccepting` until the file is actually used (#7870) + { + isSelfAccepting: + canSkipImportAnalysis(url) || forceSkipImportAnalysis + ? false + : undefined + } ) if (depModule.lastHMRTimestamp > 0) { url = injectQuery(url, `t=${depModule.lastHMRTimestamp}`) diff --git a/packages/vite/src/node/server/moduleGraph.ts b/packages/vite/src/node/server/moduleGraph.ts index b9d928b589e00b..a5492a2ae01c65 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -10,6 +10,8 @@ import { import { FS_PREFIX } from '../constants' import type { TransformResult } from './transformRequest' +type ModuleNodeOptions = { isSelfAccepting: boolean | undefined } + export class ModuleNode { /** * Public served url path, starts with / @@ -37,14 +39,15 @@ export class ModuleNode { lastInvalidationTimestamp = 0 /** - * @param setIsSelfAccepting - set `false` to set `isSelfAccepting` later. e.g. #7870 + * @param isSelfAccepting - undefined means its value isn't know when creating the module #7870 */ - constructor(url: string, setIsSelfAccepting = true) { + constructor( + url: string, + options: ModuleNodeOptions = { isSelfAccepting: false } + ) { this.url = url this.type = isDirectCSSRequest(url) ? 'css' : 'js' - if (setIsSelfAccepting) { - this.isSelfAccepting = false - } + this.isSelfAccepting = options.isSelfAccepting } } @@ -182,12 +185,12 @@ export class ModuleGraph { async ensureEntryFromUrl( rawUrl: string, ssr?: boolean, - setIsSelfAccepting = true + options?: ModuleNodeOptions ): Promise { const [url, resolvedId, meta] = await this.resolveUrl(rawUrl, ssr) let mod = this.idToModuleMap.get(resolvedId) if (!mod) { - mod = new ModuleNode(url, setIsSelfAccepting) + mod = new ModuleNode(url, options) if (meta) mod.meta = meta this.urlToModuleMap.set(url, mod) mod.id = resolvedId