|
1 | | -import fs from 'node:fs'; |
2 | 1 | import { fileURLToPath } from 'node:url'; |
3 | 2 | import type { AstroSettings } from '../types/astro.js'; |
4 | 3 | import type { AstroConfig } from '../types/public/config.js'; |
@@ -132,51 +131,6 @@ export function isEndpoint(file: URL, settings: AstroSettings): boolean { |
132 | 131 | return !endsWithPageExt(file, settings) && !file.toString().includes('?astro'); |
133 | 132 | } |
134 | 133 |
|
135 | | -export function resolveJsToTs(filePath: string) { |
136 | | - if (filePath.endsWith('.jsx') && !fs.existsSync(filePath)) { |
137 | | - const tryPath = filePath.slice(0, -4) + '.tsx'; |
138 | | - if (fs.existsSync(tryPath)) { |
139 | | - return tryPath; |
140 | | - } |
141 | | - } |
142 | | - return filePath; |
143 | | -} |
144 | | - |
145 | | -// Match Vite's default `resolve.extensions` order so that when multiple |
146 | | -// candidate files exist, we pick the same module Vite will load. |
147 | | -// https://vite.dev/config/shared-options.html#resolve-extensions |
148 | | -const VITE_DEFAULT_RESOLVE_EXTENSIONS = ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']; |
149 | | - |
150 | | -/** |
151 | | - * Resolve a path that doesn't name a file on disk (e.g. produced by an |
152 | | - * extensionless import like `import { Counter } from './Counter'`) to the file |
153 | | - * Vite would load, by probing Vite's default extension order and directory |
154 | | - * `index` files. Returns the path unchanged when it already exists as a file |
155 | | - * or when no candidate is found. |
156 | | - */ |
157 | | -export function resolveExtensionlessPath(filePath: string): string { |
158 | | - const stat = fs.statSync(filePath, { throwIfNoEntry: false }); |
159 | | - if (stat?.isFile()) { |
160 | | - return filePath; |
161 | | - } |
162 | | - for (const ext of VITE_DEFAULT_RESOLVE_EXTENSIONS) { |
163 | | - const tryPath = filePath + ext; |
164 | | - if (fs.existsSync(tryPath)) { |
165 | | - return tryPath; |
166 | | - } |
167 | | - } |
168 | | - // Directory import: resolve to its `index` module, like Vite does. |
169 | | - if (stat?.isDirectory()) { |
170 | | - for (const ext of VITE_DEFAULT_RESOLVE_EXTENSIONS) { |
171 | | - const tryPath = `${filePath}/index${ext}`; |
172 | | - if (fs.existsSync(tryPath)) { |
173 | | - return tryPath; |
174 | | - } |
175 | | - } |
176 | | - } |
177 | | - return filePath; |
178 | | -} |
179 | | - |
180 | 134 | /** |
181 | 135 | * Set a default NODE_ENV so Vite doesn't set an incorrect default when loading the Astro config |
182 | 136 | */ |
|
0 commit comments