|
1 |
| -import { camelize } from '@vue/shared'; |
| 1 | +import { camelize, NOOP as noop } from '@vue/shared'; |
2 | 2 | import { posix as path } from 'path-browserify';
|
3 | 3 | import type * as ts from 'typescript';
|
4 | 4 | import { generateGlobalTypes, getGlobalTypesFileName } from '../codegen/globalTypes';
|
@@ -232,30 +232,32 @@ export class CompilerOptionsResolver {
|
232 | 232 | ),
|
233 | 233 | };
|
234 | 234 |
|
235 |
| - if (this.fileExists && this.globalTypesPath === undefined) { |
236 |
| - const fileDirToGlobalTypesPath = new Map<string, string | undefined>(); |
237 |
| - resolvedOptions.globalTypesPath = fileName => { |
238 |
| - const fileDir = path.dirname(fileName); |
239 |
| - if (fileDirToGlobalTypesPath.has(fileDir)) { |
240 |
| - return fileDirToGlobalTypesPath.get(fileDir); |
241 |
| - } |
| 235 | + if (resolvedOptions.globalTypesPath === noop) { |
| 236 | + if (this.fileExists && this.globalTypesPath === undefined) { |
| 237 | + const fileDirToGlobalTypesPath = new Map<string, string | undefined>(); |
| 238 | + resolvedOptions.globalTypesPath = fileName => { |
| 239 | + const fileDir = path.dirname(fileName); |
| 240 | + if (fileDirToGlobalTypesPath.has(fileDir)) { |
| 241 | + return fileDirToGlobalTypesPath.get(fileDir); |
| 242 | + } |
242 | 243 |
|
243 |
| - const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib); |
244 |
| - const result = root |
245 |
| - ? path.join( |
246 |
| - root, |
247 |
| - 'node_modules', |
248 |
| - '.vue-global-types', |
249 |
| - getGlobalTypesFileName(resolvedOptions), |
250 |
| - ) |
251 |
| - : undefined; |
| 244 | + const root = this.findNodeModulesRoot(fileDir, resolvedOptions.lib); |
| 245 | + const result = root |
| 246 | + ? path.join( |
| 247 | + root, |
| 248 | + 'node_modules', |
| 249 | + '.vue-global-types', |
| 250 | + getGlobalTypesFileName(resolvedOptions), |
| 251 | + ) |
| 252 | + : undefined; |
252 | 253 |
|
253 |
| - fileDirToGlobalTypesPath.set(fileDir, result); |
254 |
| - return result; |
255 |
| - }; |
256 |
| - } |
257 |
| - else { |
258 |
| - resolvedOptions.globalTypesPath = () => this.globalTypesPath; |
| 254 | + fileDirToGlobalTypesPath.set(fileDir, result); |
| 255 | + return result; |
| 256 | + }; |
| 257 | + } |
| 258 | + else { |
| 259 | + resolvedOptions.globalTypesPath = () => this.globalTypesPath; |
| 260 | + } |
259 | 261 | }
|
260 | 262 |
|
261 | 263 | return resolvedOptions;
|
@@ -303,7 +305,7 @@ export function getDefaultCompilerOptions(target = 99, lib = 'vue', strictTempla
|
303 | 305 | return {
|
304 | 306 | target,
|
305 | 307 | lib,
|
306 |
| - globalTypesPath: () => undefined, |
| 308 | + globalTypesPath: noop, |
307 | 309 | extensions: ['.vue'],
|
308 | 310 | vitePressExtensions: [],
|
309 | 311 | petiteVueExtensions: [],
|
|
0 commit comments