diff options
-rw-r--r-- | .changeset/cold-clocks-tell.md | 5 | ||||
-rw-r--r-- | packages/astro/src/assets/vite-plugin-assets.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/container/index.ts | 3 | ||||
-rw-r--r-- | packages/astro/src/core/build/css-asset-name.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/core/compile/compile.ts | 8 | ||||
-rw-r--r-- | packages/astro/src/core/compile/style.ts | 3 | ||||
-rw-r--r-- | packages/astro/src/core/errors/dev/utils.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/core/middleware/vite-plugin.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/core/routing/manifest/create.ts | 28 | ||||
-rw-r--r-- | packages/astro/src/core/routing/manifest/parts.ts | 28 | ||||
-rw-r--r-- | packages/astro/src/core/routing/manifest/segment.ts | 24 | ||||
-rw-r--r-- | packages/astro/src/core/sync/index.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-markdown/index.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-scanner/index.ts | 3 |
14 files changed, 73 insertions, 41 deletions
diff --git a/.changeset/cold-clocks-tell.md b/.changeset/cold-clocks-tell.md new file mode 100644 index 000000000..6bebc01f8 --- /dev/null +++ b/.changeset/cold-clocks-tell.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a regression where the Astro Container didn't work during the build, using `pnpm` diff --git a/packages/astro/src/assets/vite-plugin-assets.ts b/packages/astro/src/assets/vite-plugin-assets.ts index 47215903f..c3f37b8f9 100644 --- a/packages/astro/src/assets/vite-plugin-assets.ts +++ b/packages/astro/src/assets/vite-plugin-assets.ts @@ -1,7 +1,6 @@ import { extname } from 'node:path'; import MagicString from 'magic-string'; import type * as vite from 'vite'; -import { normalizePath } from 'vite'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; import { appendForwardSlash, @@ -10,6 +9,7 @@ import { removeBase, removeQueryString, } from '../core/path.js'; +import { normalizePath } from '../core/viteUtils.js'; import type { AstroSettings } from '../types/astro.js'; import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from './consts.js'; import type { ImageTransform } from './types.js'; diff --git a/packages/astro/src/container/index.ts b/packages/astro/src/container/index.ts index 7a31af8a7..92ce0e900 100644 --- a/packages/astro/src/container/index.ts +++ b/packages/astro/src/container/index.ts @@ -9,8 +9,9 @@ import { nodeLogDestination } from '../core/logger/node.js'; import { NOOP_MIDDLEWARE_FN } from '../core/middleware/noop-middleware.js'; import { removeLeadingForwardSlash } from '../core/path.js'; import { RenderContext } from '../core/render-context.js'; -import { getParts, validateSegment } from '../core/routing/manifest/create.js'; +import { getParts } from '../core/routing/manifest/parts.js'; import { getPattern } from '../core/routing/manifest/pattern.js'; +import { validateSegment } from '../core/routing/manifest/segment.js'; import type { AstroComponentFactory } from '../runtime/server/index.js'; import type { ComponentInstance } from '../types/astro.js'; import type { AstroMiddlewareInstance, MiddlewareHandler, Props } from '../types/public/common.js'; diff --git a/packages/astro/src/core/build/css-asset-name.ts b/packages/astro/src/core/build/css-asset-name.ts index 57277c989..84fdaf9e9 100644 --- a/packages/astro/src/core/build/css-asset-name.ts +++ b/packages/astro/src/core/build/css-asset-name.ts @@ -3,9 +3,9 @@ import type { GetModuleInfo, ModuleInfo } from 'rollup'; import crypto from 'node:crypto'; import npath from 'node:path'; import { fileURLToPath } from 'node:url'; -import { normalizePath } from 'vite'; import type { AstroSettings } from '../../types/astro.js'; import { viteID } from '../util.js'; +import { normalizePath } from '../viteUtils.js'; import { getTopLevelPageModuleInfos } from './graph.js'; // These pages could be used as base names for the chunk hashed name, but they are confusing diff --git a/packages/astro/src/core/compile/compile.ts b/packages/astro/src/core/compile/compile.ts index 97025e9f1..5cfe92e1b 100644 --- a/packages/astro/src/core/compile/compile.ts +++ b/packages/astro/src/core/compile/compile.ts @@ -1,15 +1,13 @@ -import type { TransformResult } from '@astrojs/compiler'; -import type { ResolvedConfig } from 'vite'; - import { fileURLToPath } from 'node:url'; +import type { TransformResult } from '@astrojs/compiler'; import { transform } from '@astrojs/compiler'; -import { normalizePath } from 'vite'; +import type { ResolvedConfig } from 'vite'; import type { AstroPreferences } from '../../preferences/index.js'; import type { AstroConfig } from '../../types/public/config.js'; import type { AstroError } from '../errors/errors.js'; import { AggregateError, CompilerError } from '../errors/errors.js'; import { AstroErrorData } from '../errors/index.js'; -import { resolvePath } from '../viteUtils.js'; +import { normalizePath, resolvePath } from '../viteUtils.js'; import { type PartialCompileCssResult, createStylePreprocessor } from './style.js'; import type { CompileCssResult } from './types.js'; diff --git a/packages/astro/src/core/compile/style.ts b/packages/astro/src/core/compile/style.ts index 5d517a514..ce1f6638c 100644 --- a/packages/astro/src/core/compile/style.ts +++ b/packages/astro/src/core/compile/style.ts @@ -1,7 +1,8 @@ import fs from 'node:fs'; import type { TransformOptions } from '@astrojs/compiler'; -import { type ResolvedConfig, normalizePath, preprocessCSS } from 'vite'; +import { type ResolvedConfig, preprocessCSS } from 'vite'; import { AstroErrorData, CSSError, positionAt } from '../errors/index.js'; +import { normalizePath } from '../viteUtils.js'; import type { CompileCssResult } from './types.js'; export type PartialCompileCssResult = Pick<CompileCssResult, 'isGlobal' | 'dependencies'>; diff --git a/packages/astro/src/core/errors/dev/utils.ts b/packages/astro/src/core/errors/dev/utils.ts index fc177033a..d757bb33a 100644 --- a/packages/astro/src/core/errors/dev/utils.ts +++ b/packages/astro/src/core/errors/dev/utils.ts @@ -5,9 +5,9 @@ import { stripVTControlCharacters } from 'node:util'; import { escape } from 'html-escaper'; import { bold, underline } from 'kleur/colors'; import type { ESBuildTransformResult } from 'vite'; -import { normalizePath } from 'vite'; import type { SSRError } from '../../../types/public/internal.js'; import { removeLeadingForwardSlashWindows } from '../../path.js'; +import { normalizePath } from '../../viteUtils.js'; import { AggregateError, type ErrorWithMetadata } from '../errors.js'; import { AstroErrorData } from '../index.js'; import { codeFrame } from '../printer.js'; diff --git a/packages/astro/src/core/middleware/vite-plugin.ts b/packages/astro/src/core/middleware/vite-plugin.ts index 10c5683f7..2587c4565 100644 --- a/packages/astro/src/core/middleware/vite-plugin.ts +++ b/packages/astro/src/core/middleware/vite-plugin.ts @@ -1,5 +1,4 @@ import type { Plugin as VitePlugin } from 'vite'; -import { normalizePath } from 'vite'; import { getOutputDirectory } from '../../prerender/utils.js'; import type { AstroSettings } from '../../types/astro.js'; import { addRollupInput } from '../build/add-rollup-input.js'; @@ -8,6 +7,7 @@ import type { StaticBuildOptions } from '../build/types.js'; import { MIDDLEWARE_PATH_SEGMENT_NAME } from '../constants.js'; import { MissingMiddlewareForInternationalization } from '../errors/errors-data.js'; import { AstroError } from '../errors/index.js'; +import { normalizePath } from '../viteUtils.js'; export const MIDDLEWARE_MODULE_ID = '\0astro-internal:middleware'; const NOOP_MIDDLEWARE = '\0noop-middleware'; diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 9f925fe69..03080e7ef 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -24,6 +24,8 @@ import { routeComparator } from '../priority.js'; import { getRouteGenerator } from './generator.js'; import { getPattern } from './pattern.js'; import { getRoutePrerenderOption } from './prerender.js'; +import { validateSegment } from './segment.js'; + const require = createRequire(import.meta.url); interface Item { @@ -37,14 +39,6 @@ interface Item { routeSuffix: string; } -function countOccurrences(needle: string, haystack: string) { - let count = 0; - for (const hay of haystack) { - if (hay === needle) count += 1; - } - return count; -} - // Disable eslint as we're not sure how to improve this regex yet // eslint-disable-next-line regexp/no-super-linear-backtracking const ROUTE_DYNAMIC_SPLIT = /\[(.+?\(.+?\)|.+?)\]/; @@ -71,24 +65,6 @@ export function getParts(part: string, file: string) { return result; } - -export function validateSegment(segment: string, file = '') { - if (!file) file = segment; - - if (segment.includes('][')) { - throw new Error(`Invalid route ${file} \u2014 parameters must be separated`); - } - if (countOccurrences('[', segment) !== countOccurrences(']', segment)) { - throw new Error(`Invalid route ${file} \u2014 brackets are unbalanced`); - } - if ( - (/.+\[\.\.\.[^\]]+\]/.test(segment) || /\[\.\.\.[^\]]+\].+/.test(segment)) && - file.endsWith('.astro') - ) { - throw new Error(`Invalid route ${file} \u2014 rest parameter must be a standalone segment`); - } -} - /** * Checks whether two route segments are semantically equivalent. * diff --git a/packages/astro/src/core/routing/manifest/parts.ts b/packages/astro/src/core/routing/manifest/parts.ts new file mode 100644 index 000000000..77aa70b2b --- /dev/null +++ b/packages/astro/src/core/routing/manifest/parts.ts @@ -0,0 +1,28 @@ +import type { RoutePart } from '../../../types/public/index.js'; + +// Disable eslint as we're not sure how to improve this regex yet +// eslint-disable-next-line regexp/no-super-linear-backtracking +const ROUTE_DYNAMIC_SPLIT = /\[(.+?\(.+?\)|.+?)\]/; +const ROUTE_SPREAD = /^\.{3}.+$/; + +export function getParts(part: string, file: string) { + const result: RoutePart[] = []; + part.split(ROUTE_DYNAMIC_SPLIT).map((str, i) => { + if (!str) return; + const dynamic = i % 2 === 1; + + const [, content] = dynamic ? /([^(]+)$/.exec(str) || [null, null] : [null, str]; + + if (!content || (dynamic && !/^(?:\.\.\.)?[\w$]+$/.test(content))) { + throw new Error(`Invalid route ${file} — parameter name must match /^[a-zA-Z0-9_$]+$/`); + } + + result.push({ + content, + dynamic, + spread: dynamic && ROUTE_SPREAD.test(content), + }); + }); + + return result; +} diff --git a/packages/astro/src/core/routing/manifest/segment.ts b/packages/astro/src/core/routing/manifest/segment.ts new file mode 100644 index 000000000..d09f4d565 --- /dev/null +++ b/packages/astro/src/core/routing/manifest/segment.ts @@ -0,0 +1,24 @@ +export function validateSegment(segment: string, file = '') { + if (!file) file = segment; + + if (segment.includes('][')) { + throw new Error(`Invalid route ${file} \u2014 parameters must be separated`); + } + if (countOccurrences('[', segment) !== countOccurrences(']', segment)) { + throw new Error(`Invalid route ${file} \u2014 brackets are unbalanced`); + } + if ( + (/.+\[\.\.\.[^\]]+\]/.test(segment) || /\[\.\.\.[^\]]+\].+/.test(segment)) && + file.endsWith('.astro') + ) { + throw new Error(`Invalid route ${file} \u2014 rest parameter must be a standalone segment`); + } +} + +function countOccurrences(needle: string, haystack: string) { + let count = 0; + for (const hay of haystack) { + if (hay === needle) count += 1; + } + return count; +} diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index b1e75097d..ff408e323 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -4,7 +4,6 @@ import { performance } from 'node:perf_hooks'; import { fileURLToPath } from 'node:url'; import { dim } from 'kleur/colors'; import { type HMRPayload, createServer } from 'vite'; -import { normalizePath } from 'vite'; import { CONTENT_TYPES_FILE } from '../../content/consts.js'; import { getDataStoreFile, globalContentLayer } from '../../content/content-layer.js'; import { createContentTypesGenerator } from '../../content/index.js'; @@ -32,6 +31,7 @@ import { import type { Logger } from '../logger/core.js'; import { createRouteManifest } from '../routing/index.js'; import { ensureProcessNodeEnv } from '../util.js'; +import { normalizePath } from '../viteUtils.js'; export type SyncOptions = { mode: string; diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 9b7c80330..8876250f9 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -6,11 +6,11 @@ import { isFrontmatterValid, } from '@astrojs/markdown-remark'; import type { Plugin } from 'vite'; -import { normalizePath } from 'vite'; import { safeParseFrontmatter } from '../content/utils.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; import type { Logger } from '../core/logger/core.js'; import { isMarkdownFile, isPage } from '../core/util.js'; +import { normalizePath } from '../core/viteUtils.js'; import { shorthash } from '../runtime/server/shorthash.js'; import type { AstroSettings } from '../types/astro.js'; import { createDefaultAstroMetadata } from '../vite-plugin-astro/metadata.js'; diff --git a/packages/astro/src/vite-plugin-scanner/index.ts b/packages/astro/src/vite-plugin-scanner/index.ts index 44d56270a..f1c7a2217 100644 --- a/packages/astro/src/vite-plugin-scanner/index.ts +++ b/packages/astro/src/vite-plugin-scanner/index.ts @@ -2,12 +2,11 @@ import { extname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { bold } from 'kleur/colors'; import type { Plugin as VitePlugin } from 'vite'; -import { normalizePath } from 'vite'; import { warnMissingAdapter } from '../core/dev/adapter-validation.js'; import type { Logger } from '../core/logger/core.js'; import { getRoutePrerenderOption } from '../core/routing/manifest/prerender.js'; import { isEndpoint, isPage } from '../core/util.js'; -import { rootRelativePath } from '../core/viteUtils.js'; +import { normalizePath, rootRelativePath } from '../core/viteUtils.js'; import type { AstroSettings, ManifestData } from '../types/astro.js'; export interface AstroPluginScannerOptions { |