-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(container): breakdown files to avoid importing
vite
(#11327)
* fix(container): breakdown files to avoid importing `vite` * chore: update imports inside tests * restore code * format
- Loading branch information
Showing
18 changed files
with
126 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fixes an issue with the container APIs where a runtime error was thrown during the build, when using `pnpm` as package manager. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { AstroConfig } from '../../@types/astro.js'; | ||
import { createRelativeSchema } from './schema.js'; | ||
|
||
/** Turn raw config values into normalized values */ | ||
export async function validateConfig( | ||
userConfig: any, | ||
root: string, | ||
cmd: string | ||
): Promise<AstroConfig> { | ||
const AstroConfigRelativeSchema = createRelativeSchema(cmd, root); | ||
|
||
// First-Pass Validation | ||
return await AstroConfigRelativeSchema.parseAsync(userConfig); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { normalizePath } from 'vite'; | ||
import { prependForwardSlash } from '../core/path.js'; | ||
import type { ModuleLoader } from './module-loader/index.js'; | ||
import { VALID_ID_PREFIX, resolveJsToTs, unwrapId, viteID } from './util.js'; | ||
|
||
/** | ||
* Resolve the hydration paths so that it can be imported in the client | ||
*/ | ||
export function resolvePath(specifier: string, importer: string) { | ||
if (specifier.startsWith('.')) { | ||
const absoluteSpecifier = path.resolve(path.dirname(importer), specifier); | ||
return resolveJsToTs(normalizePath(absoluteSpecifier)); | ||
} else { | ||
return specifier; | ||
} | ||
} | ||
|
||
export function rootRelativePath( | ||
root: URL, | ||
idOrUrl: URL | string, | ||
shouldPrependForwardSlash = true | ||
) { | ||
let id: string; | ||
if (typeof idOrUrl !== 'string') { | ||
id = unwrapId(viteID(idOrUrl)); | ||
} else { | ||
id = idOrUrl; | ||
} | ||
const normalizedRoot = normalizePath(fileURLToPath(root)); | ||
if (id.startsWith(normalizedRoot)) { | ||
id = id.slice(normalizedRoot.length); | ||
} | ||
return shouldPrependForwardSlash ? prependForwardSlash(id) : id; | ||
} | ||
|
||
/** | ||
* Simulate Vite's resolve and import analysis so we can import the id as an URL | ||
* through a script tag or a dynamic import as-is. | ||
*/ | ||
// NOTE: `/@id/` should only be used when the id is fully resolved | ||
export async function resolveIdToUrl(loader: ModuleLoader, id: string, root?: URL) { | ||
let resultId = await loader.resolveId(id, undefined); | ||
// Try resolve jsx to tsx | ||
if (!resultId && id.endsWith('.jsx')) { | ||
resultId = await loader.resolveId(id.slice(0, -4), undefined); | ||
} | ||
if (!resultId) { | ||
return VALID_ID_PREFIX + id; | ||
} | ||
if (path.isAbsolute(resultId)) { | ||
const normalizedRoot = root && normalizePath(fileURLToPath(root)); | ||
// Convert to root-relative path if path is inside root | ||
if (normalizedRoot && resultId.startsWith(normalizedRoot)) { | ||
return resultId.slice(normalizedRoot.length - 1); | ||
} else { | ||
return '/@fs' + prependForwardSlash(resultId); | ||
} | ||
} | ||
return VALID_ID_PREFIX + resultId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.