astro 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -190,6 +190,13 @@ callEndpoint_fn = async function(request, routeData, mod, status = 200) {
190
190
  status
191
191
  });
192
192
  if (result.type === "response") {
193
+ if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
194
+ const fourOhFourRequest = new Request(new URL("/404", request.url));
195
+ const fourOhFourRouteData = this.match(fourOhFourRequest);
196
+ if (fourOhFourRouteData) {
197
+ return this.render(fourOhFourRequest, fourOhFourRouteData);
198
+ }
199
+ }
193
200
  return result.response;
194
201
  } else {
195
202
  const body = result.body;
@@ -1,3 +1,9 @@
1
1
  import type { AstroConfig, RouteType } from '../../@types/astro';
2
2
  export declare function getOutFolder(astroConfig: AstroConfig, pathname: string, routeType: RouteType): URL;
3
3
  export declare function getOutFile(astroConfig: AstroConfig, outFolder: URL, pathname: string, routeType: RouteType): URL;
4
+ /**
5
+ * Ensures the `outDir` is within `process.cwd()`. If not it will fallback to `<cwd>/.astro`.
6
+ * This is used for static `ssrBuild` so the output can access node_modules when we import
7
+ * the output files. A hardcoded fallback dir is fine as it would be cleaned up after build.
8
+ */
9
+ export declare function getOutDirWithinCwd(outDir: URL): URL;
@@ -1,6 +1,8 @@
1
1
  import npath from "path";
2
+ import { fileURLToPath, pathToFileURL } from "url";
2
3
  import { appendForwardSlash } from "../../core/path.js";
3
4
  const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["/404", "/500"]);
5
+ const FALLBACK_OUT_DIR_NAME = "./.astro/";
4
6
  function getOutRoot(astroConfig) {
5
7
  return new URL("./", astroConfig.outDir);
6
8
  }
@@ -43,7 +45,15 @@ function getOutFile(astroConfig, outFolder, pathname, routeType) {
43
45
  }
44
46
  }
45
47
  }
48
+ function getOutDirWithinCwd(outDir) {
49
+ if (fileURLToPath(outDir).startsWith(process.cwd())) {
50
+ return outDir;
51
+ } else {
52
+ return new URL(FALLBACK_OUT_DIR_NAME, pathToFileURL(process.cwd() + npath.sep));
53
+ }
54
+ }
46
55
  export {
56
+ getOutDirWithinCwd,
47
57
  getOutFile,
48
58
  getOutFolder
49
59
  };
@@ -18,7 +18,7 @@ import { createLinkStylesheetElementSet, createModuleScriptsSet } from "../rende
18
18
  import { createRequest } from "../request.js";
19
19
  import { matchRoute } from "../routing/match.js";
20
20
  import { getOutputFilename } from "../util.js";
21
- import { getOutFile, getOutFolder } from "./common.js";
21
+ import { getOutDirWithinCwd, getOutFile, getOutFolder } from "./common.js";
22
22
  import { eachPageData, getPageDataByComponent, sortedCSS } from "./internal.js";
23
23
  import { getTimeStat } from "./util.js";
24
24
  const MAX_CONCURRENT_RENDERS = 1;
@@ -65,7 +65,7 @@ async function generatePages(opts, internals) {
65
65
  ${bgGreen(black(" generating static routes "))}`);
66
66
  const ssr = opts.astroConfig.output === "server";
67
67
  const serverEntry = opts.buildConfig.serverEntry;
68
- const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.outDir;
68
+ const outFolder = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.astroConfig.outDir);
69
69
  const ssrEntryURL = new URL("./" + serverEntry + `?time=${Date.now()}`, outFolder);
70
70
  const ssrEntry = await import(ssrEntryURL.toString());
71
71
  const builtPaths = /* @__PURE__ */ new Set();
@@ -1,8 +1,8 @@
1
1
  import type { GetModuleInfo, ModuleInfo } from 'rollup';
2
2
  export declare function walkParentInfos(id: string, ctx: {
3
3
  getModuleInfo: GetModuleInfo;
4
- }, depth?: number, seen?: Set<string>): Generator<[ModuleInfo, number], void, unknown>;
4
+ }, depth?: number, seen?: Set<string>, childId?: string): Generator<[ModuleInfo, number, number], void, unknown>;
5
5
  export declare function moduleIsTopLevelPage(info: ModuleInfo): boolean;
6
6
  export declare function getTopLevelPages(id: string, ctx: {
7
7
  getModuleInfo: GetModuleInfo;
8
- }): Generator<[ModuleInfo, number], void, unknown>;
8
+ }): Generator<[ModuleInfo, number, number], void, unknown>;
@@ -1,16 +1,17 @@
1
1
  import { resolvedPagesVirtualModuleId } from "../app/index.js";
2
- function* walkParentInfos(id, ctx, depth = 0, seen = /* @__PURE__ */ new Set()) {
2
+ function* walkParentInfos(id, ctx, depth = 0, seen = /* @__PURE__ */ new Set(), childId = "") {
3
3
  seen.add(id);
4
4
  const info = ctx.getModuleInfo(id);
5
5
  if (info) {
6
- yield [info, depth];
6
+ let order = childId ? info.importedIds.indexOf(childId) : 0;
7
+ yield [info, depth, order];
7
8
  }
8
9
  const importers = ((info == null ? void 0 : info.importers) || []).concat((info == null ? void 0 : info.dynamicImporters) || []);
9
10
  for (const imp of importers) {
10
11
  if (seen.has(imp)) {
11
12
  continue;
12
13
  }
13
- yield* walkParentInfos(imp, ctx, ++depth, seen);
14
+ yield* walkParentInfos(imp, ctx, ++depth, seen, id);
14
15
  }
15
16
  }
16
17
  function moduleIsTopLevelPage(info) {
@@ -78,13 +78,23 @@ function* eachPageData(internals) {
78
78
  }
79
79
  function sortedCSS(pageData) {
80
80
  return Array.from(pageData.css).sort((a, b) => {
81
- let depthA = a[1].depth, depthB = b[1].depth;
82
- if (depthA === -1) {
81
+ let depthA = a[1].depth, depthB = b[1].depth, orderA = a[1].order, orderB = b[1].order;
82
+ if (orderA === -1 && orderB >= 0) {
83
+ return 1;
84
+ } else if (orderB === -1 && orderA >= 0) {
83
85
  return -1;
84
- } else if (depthB === -1) {
86
+ } else if (orderA > orderB) {
85
87
  return 1;
88
+ } else if (orderA < orderB) {
89
+ return -1;
86
90
  } else {
87
- return depthA > depthB ? -1 : 1;
91
+ if (depthA === -1) {
92
+ return -1;
93
+ } else if (depthB === -1) {
94
+ return 1;
95
+ } else {
96
+ return depthA > depthB ? -1 : 1;
97
+ }
88
98
  }
89
99
  }).map(([id]) => id);
90
100
  }
@@ -9,6 +9,7 @@ import { emptyDir, isModeServerWithNoAdapter, removeDir } from "../../core/util.
9
9
  import { runHookBuildSetup } from "../../integrations/index.js";
10
10
  import { PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
11
11
  import { info } from "../logger/core.js";
12
+ import { getOutDirWithinCwd } from "./common.js";
12
13
  import { generatePages } from "./generate.js";
13
14
  import { trackPageData } from "./internal.js";
14
15
  import { getTimeStat } from "./util.js";
@@ -78,7 +79,7 @@ async function ssrBuild(opts, internals, input) {
78
79
  var _a, _b, _c;
79
80
  const { astroConfig, viteConfig } = opts;
80
81
  const ssr = astroConfig.output === "server";
81
- const out = ssr ? opts.buildConfig.server : astroConfig.outDir;
82
+ const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(astroConfig.outDir);
82
83
  const viteBuildConfig = {
83
84
  ...viteConfig,
84
85
  logLevel: opts.viteConfig.logLevel ?? "error",
@@ -195,12 +196,17 @@ ${bgGreen(black(" building client "))}`);
195
196
  return buildResult;
196
197
  }
197
198
  async function cleanSsrOutput(opts) {
199
+ const out = getOutDirWithinCwd(opts.astroConfig.outDir);
200
+ if (out.toString() !== opts.astroConfig.outDir.toString()) {
201
+ await fs.promises.rm(out, { recursive: true });
202
+ return;
203
+ }
198
204
  const files = await glob("**/*.mjs", {
199
- cwd: fileURLToPath(opts.astroConfig.outDir)
205
+ cwd: fileURLToPath(out)
200
206
  });
201
207
  await Promise.all(
202
208
  files.map(async (filename) => {
203
- const url = new URL(filename, opts.astroConfig.outDir);
209
+ const url = new URL(filename, out);
204
210
  await fs.promises.rm(url);
205
211
  })
206
212
  );
@@ -10,6 +10,7 @@ export interface PageBuildData {
10
10
  moduleSpecifier: string;
11
11
  css: Map<string, {
12
12
  depth: number;
13
+ order: number;
13
14
  }>;
14
15
  hoistedScript: {
15
16
  type: 'inline' | 'external';
@@ -65,15 +65,20 @@ function rollupPluginAstroBuildCSS(options) {
65
65
  };
66
66
  },
67
67
  async generateBundle(_outputOptions, bundle) {
68
- const appendCSSToPage = (pageData, meta, depth) => {
68
+ const appendCSSToPage = (pageData, meta, depth, order) => {
69
69
  for (const importedCssImport of meta.importedCss) {
70
70
  if (pageData == null ? void 0 : pageData.css.has(importedCssImport)) {
71
71
  const cssInfo = pageData == null ? void 0 : pageData.css.get(importedCssImport);
72
72
  if (depth < cssInfo.depth) {
73
73
  cssInfo.depth = depth;
74
74
  }
75
+ if (cssInfo.order === -1) {
76
+ cssInfo.order = order;
77
+ } else if (order < cssInfo.order && order > -1) {
78
+ cssInfo.order = order;
79
+ }
75
80
  } else {
76
- pageData == null ? void 0 : pageData.css.set(importedCssImport, { depth });
81
+ pageData == null ? void 0 : pageData.css.set(importedCssImport, { depth, order });
77
82
  }
78
83
  }
79
84
  };
@@ -101,25 +106,25 @@ function rollupPluginAstroBuildCSS(options) {
101
106
  for (const id of Object.keys(c.modules)) {
102
107
  for (const pageData of getParentClientOnlys(id, this)) {
103
108
  for (const importedCssImport of meta.importedCss) {
104
- pageData.css.set(importedCssImport, { depth: -1 });
109
+ pageData.css.set(importedCssImport, { depth: -1, order: -1 });
105
110
  }
106
111
  }
107
112
  }
108
113
  }
109
114
  for (const id of Object.keys(c.modules)) {
110
- for (const [pageInfo, depth] of walkParentInfos(id, this)) {
115
+ for (const [pageInfo, depth, order] of walkParentInfos(id, this)) {
111
116
  if (moduleIsTopLevelPage(pageInfo)) {
112
117
  const pageViteID = pageInfo.id;
113
118
  const pageData = getPageDataByViteID(internals, pageViteID);
114
119
  if (pageData) {
115
- appendCSSToPage(pageData, meta, depth);
120
+ appendCSSToPage(pageData, meta, depth, order);
116
121
  }
117
122
  } else if (options.target === "client" && isHoistedScript(internals, pageInfo.id)) {
118
123
  for (const pageData of getPageDatasByHoistedScriptId(
119
124
  internals,
120
125
  pageInfo.id
121
126
  )) {
122
- appendCSSToPage(pageData, meta, -1);
127
+ appendCSSToPage(pageData, meta, -1, order);
123
128
  }
124
129
  }
125
130
  }
@@ -143,7 +148,7 @@ function rollupPluginAstroBuildCSS(options) {
143
148
  );
144
149
  if (cssChunk) {
145
150
  for (const pageData of eachPageData(internals)) {
146
- pageData.css.set(cssChunk.fileName, { depth: -1 });
151
+ pageData.css.set(cssChunk.fileName, { depth: -1, order: -1 });
147
152
  }
148
153
  }
149
154
  }
@@ -48,7 +48,7 @@ async function dev(config, options) {
48
48
  isRestart
49
49
  })
50
50
  );
51
- const currentVersion = "1.2.2";
51
+ const currentVersion = "1.2.4";
52
52
  if (currentVersion.includes("-")) {
53
53
  warn(options.logging, null, msg.prerelease({ currentVersion }));
54
54
  }
@@ -47,7 +47,7 @@ function devStart({
47
47
  site,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "1.2.2";
50
+ const version = "1.2.4";
51
51
  const rootPath = site ? site.pathname : "/";
52
52
  const localPrefix = `${dim("\u2503")} Local `;
53
53
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -226,7 +226,7 @@ function printHelp({
226
226
  message.push(
227
227
  linebreak(),
228
228
  ` ${bgGreen(black(` ${commandName} `))} ${green(
229
- `v${"1.2.2"}`
229
+ `v${"1.2.4"}`
230
230
  )} ${headline}`
231
231
  );
232
232
  }
package/dist/core/util.js CHANGED
@@ -5,7 +5,7 @@ import resolve from "resolve";
5
5
  import slash from "slash";
6
6
  import { fileURLToPath, pathToFileURL } from "url";
7
7
  import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
8
- const ASTRO_VERSION = "1.2.2";
8
+ const ASTRO_VERSION = "1.2.4";
9
9
  function isObject(value) {
10
10
  return typeof value === "object" && value != null;
11
11
  }
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.2.2";
1
+ const ASTRO_VERSION = "1.2.4";
2
2
  function createDeprecatedFetchContentFn() {
3
3
  return () => {
4
4
  throw new Error("Deprecated: Astro.fetchContent() has been replaced with Astro.glob().");
@@ -1,3 +1,3 @@
1
1
  import type { EndpointHandler, Params } from '../../@types/astro';
2
2
  /** Renders an endpoint request to completion, returning the body. */
3
- export declare function renderEndpoint(mod: EndpointHandler, request: Request, params: Params): Promise<import("../../@types/astro").EndpointOutput | Response>;
3
+ export declare function renderEndpoint(mod: EndpointHandler, request: Request, params: Params): Promise<Response | import("../../@types/astro").EndpointOutput>;
@@ -15,9 +15,13 @@ async function renderEndpoint(mod, request, params) {
15
15
  const chosenMethod = (_a = request.method) == null ? void 0 : _a.toLowerCase();
16
16
  const handler = getHandlerFromModule(mod, chosenMethod);
17
17
  if (!handler || typeof handler !== "function") {
18
- throw new Error(
19
- `Endpoint handler not found! Expected an exported function for "${chosenMethod}"`
20
- );
18
+ let response = new Response(null, {
19
+ status: 404,
20
+ headers: {
21
+ "X-Astro-Response": "Not-Found"
22
+ }
23
+ });
24
+ return response;
21
25
  }
22
26
  if (handler.length > 1) {
23
27
  console.warn(`
@@ -170,6 +170,7 @@ function filteredConsoleError(msg, ...rest) {
170
170
  if (isKnownReactHookError)
171
171
  return;
172
172
  }
173
+ originalConsoleError(msg, ...rest);
173
174
  }
174
175
  export {
175
176
  renderJSX
@@ -283,10 +283,10 @@ ${source}
283
283
  filename: context.file,
284
284
  moduleId: context.file,
285
285
  source: await context.read(),
286
- transformStyle: createTransformStyles(styleTransformer, context.file, true, this)
286
+ transformStyle: createTransformStyles(styleTransformer, context.file, true)
287
287
  };
288
288
  const compile = () => cachedCompilation(compileProps);
289
- return handleHotUpdate.call(this, context, {
289
+ return handleHotUpdate(context, {
290
290
  config,
291
291
  logging,
292
292
  compile
@@ -16,13 +16,6 @@ import { createRequest } from "../core/request.js";
16
16
  import { createRouteManifest, matchAllRoutes } from "../core/routing/index.js";
17
17
  import { resolvePages } from "../core/util.js";
18
18
  import notFoundTemplate, { subpathNotUsedTemplate } from "../template/4xx.js";
19
- function truncateString(str, n) {
20
- if (str.length > n) {
21
- return str.substring(0, n) + "&#8230;";
22
- } else {
23
- return str;
24
- }
25
- }
26
19
  function writeHtmlResponse(res, statusCode, html) {
27
20
  res.writeHead(statusCode, {
28
21
  "Content-Type": "text/html; charset=utf-8",
@@ -130,9 +123,53 @@ function baseMiddleware(config, logging) {
130
123
  next();
131
124
  };
132
125
  }
126
+ async function matchRoute(pathname, routeCache, viteServer, logging, manifest, config) {
127
+ const matches = matchAllRoutes(pathname, manifest);
128
+ for await (const maybeRoute of matches) {
129
+ const filePath = new URL(`./${maybeRoute.component}`, config.root);
130
+ const preloadedComponent = await preload({ astroConfig: config, filePath, viteServer });
131
+ const [, mod] = preloadedComponent;
132
+ const paramsAndPropsRes = await getParamsAndProps({
133
+ mod,
134
+ route: maybeRoute,
135
+ routeCache,
136
+ pathname,
137
+ logging,
138
+ ssr: config.output === "server"
139
+ });
140
+ if (paramsAndPropsRes !== GetParamsAndPropsError.NoMatchingStaticPath) {
141
+ return {
142
+ route: maybeRoute,
143
+ filePath,
144
+ preloadedComponent,
145
+ mod
146
+ };
147
+ }
148
+ }
149
+ if (matches.length) {
150
+ warn(
151
+ logging,
152
+ "getStaticPaths",
153
+ `Route pattern matched, but no matching static path found. (${pathname})`
154
+ );
155
+ }
156
+ log404(logging, pathname);
157
+ const custom404 = getCustom404Route(config, manifest);
158
+ if (custom404) {
159
+ const filePath = new URL(`./${custom404.component}`, config.root);
160
+ const preloadedComponent = await preload({ astroConfig: config, filePath, viteServer });
161
+ const [, mod] = preloadedComponent;
162
+ return {
163
+ route: custom404,
164
+ filePath,
165
+ preloadedComponent,
166
+ mod
167
+ };
168
+ }
169
+ return void 0;
170
+ }
133
171
  async function handleRequest(routeCache, viteServer, logging, manifest, config, req, res) {
134
172
  var _a;
135
- const reqStart = performance.now();
136
173
  const origin = `${viteServer.config.server.https ? "https" : "http"}://${req.headers.host}`;
137
174
  const buildingToSSR = config.output === "server";
138
175
  const url = new URL(origin + ((_a = req.url) == null ? void 0 : _a.replace(/(index)?\.html$/, "")));
@@ -148,112 +185,38 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
148
185
  if (!(req.method === "GET" || req.method === "HEAD")) {
149
186
  let bytes = [];
150
187
  await new Promise((resolve) => {
151
- req.setEncoding("utf-8");
152
- req.on("data", (bts) => bytes.push(bts));
188
+ req.on("data", (part) => {
189
+ bytes.push(part);
190
+ });
153
191
  req.on("end", resolve);
154
192
  });
155
- body = new TextEncoder().encode(bytes.join("")).buffer;
156
- }
157
- const request = createRequest({
158
- url,
159
- headers: buildingToSSR ? req.headers : new Headers(),
160
- method: req.method,
161
- body,
162
- logging,
163
- ssr: buildingToSSR,
164
- clientAddress: buildingToSSR ? req.socket.remoteAddress : void 0
165
- });
166
- async function matchRoute() {
167
- const matches = matchAllRoutes(pathname, manifest);
168
- for await (const maybeRoute of matches) {
169
- const filePath2 = new URL(`./${maybeRoute.component}`, config.root);
170
- const preloadedComponent = await preload({ astroConfig: config, filePath: filePath2, viteServer });
171
- const [, mod] = preloadedComponent;
172
- const paramsAndPropsRes = await getParamsAndProps({
173
- mod,
174
- route: maybeRoute,
175
- routeCache,
176
- pathname,
177
- logging,
178
- ssr: config.output === "server"
179
- });
180
- if (paramsAndPropsRes !== GetParamsAndPropsError.NoMatchingStaticPath) {
181
- return {
182
- route: maybeRoute,
183
- filePath: filePath2,
184
- preloadedComponent,
185
- mod
186
- };
187
- }
188
- }
189
- if (matches.length) {
190
- warn(
191
- logging,
192
- "getStaticPaths",
193
- `Route pattern matched, but no matching static path found. (${pathname})`
194
- );
195
- }
196
- log404(logging, pathname);
197
- const custom404 = getCustom404Route(config, manifest);
198
- if (custom404) {
199
- const filePath2 = new URL(`./${custom404.component}`, config.root);
200
- const preloadedComponent = await preload({ astroConfig: config, filePath: filePath2, viteServer });
201
- const [, mod] = preloadedComponent;
202
- return {
203
- route: custom404,
204
- filePath: filePath2,
205
- preloadedComponent,
206
- mod
207
- };
208
- }
209
- return void 0;
193
+ body = Buffer.concat(bytes);
210
194
  }
211
195
  let filePath;
212
196
  try {
213
- const matchedRoute = await matchRoute();
214
- if (!matchedRoute) {
215
- return handle404Response(origin, config, req, res);
216
- }
217
- const { route, preloadedComponent, mod } = matchedRoute;
218
- filePath = matchedRoute.filePath;
219
- const paramsAndPropsRes = await getParamsAndProps({
220
- mod,
221
- route,
222
- routeCache,
197
+ const matchedRoute = await matchRoute(
223
198
  pathname,
199
+ routeCache,
200
+ viteServer,
224
201
  logging,
225
- ssr: config.output === "server"
226
- });
227
- const options = {
228
- astroConfig: config,
229
- filePath,
230
- logging,
231
- mode: "development",
232
- origin,
202
+ manifest,
203
+ config
204
+ );
205
+ filePath = matchedRoute == null ? void 0 : matchedRoute.filePath;
206
+ return await handleRoute(
207
+ matchedRoute,
208
+ url,
233
209
  pathname,
234
- route,
210
+ body,
211
+ origin,
235
212
  routeCache,
236
213
  viteServer,
237
- request
238
- };
239
- if (route.type === "endpoint") {
240
- const result = await callEndpoint(options);
241
- if (result.type === "response") {
242
- await writeWebResponse(res, result.response);
243
- } else {
244
- let contentType = "text/plain";
245
- const filepath = route.pathname || route.segments.map((segment) => segment.map((p) => p.content).join("")).join("/");
246
- const computedMimeType = mime.getType(filepath);
247
- if (computedMimeType) {
248
- contentType = computedMimeType;
249
- }
250
- res.writeHead(200, { "Content-Type": `${contentType};charset=utf-8` });
251
- res.end(result.body);
252
- }
253
- } else {
254
- const result = await ssr(preloadedComponent, options);
255
- return await writeSSRResult(result, res);
256
- }
214
+ manifest,
215
+ logging,
216
+ config,
217
+ req,
218
+ res
219
+ );
257
220
  } catch (_err) {
258
221
  const err = fixViteErrorMessage(_err, viteServer, filePath);
259
222
  const errorWithMetadata = collectErrorMetadata(err);
@@ -261,6 +224,85 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
261
224
  handle500Response(viteServer, origin, req, res, errorWithMetadata);
262
225
  }
263
226
  }
227
+ async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache, viteServer, manifest, logging, config, req, res) {
228
+ if (!matchedRoute) {
229
+ return handle404Response(origin, config, req, res);
230
+ }
231
+ const filePath = matchedRoute.filePath;
232
+ const { route, preloadedComponent, mod } = matchedRoute;
233
+ const buildingToSSR = config.output === "server";
234
+ const request = createRequest({
235
+ url,
236
+ headers: buildingToSSR ? req.headers : new Headers(),
237
+ method: req.method,
238
+ body,
239
+ logging,
240
+ ssr: buildingToSSR,
241
+ clientAddress: buildingToSSR ? req.socket.remoteAddress : void 0
242
+ });
243
+ const paramsAndPropsRes = await getParamsAndProps({
244
+ mod,
245
+ route,
246
+ routeCache,
247
+ pathname,
248
+ logging,
249
+ ssr: config.output === "server"
250
+ });
251
+ const options = {
252
+ astroConfig: config,
253
+ filePath,
254
+ logging,
255
+ mode: "development",
256
+ origin,
257
+ pathname,
258
+ route,
259
+ routeCache,
260
+ viteServer,
261
+ request
262
+ };
263
+ if (route.type === "endpoint") {
264
+ const result = await callEndpoint(options);
265
+ if (result.type === "response") {
266
+ if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
267
+ const fourOhFourRoute = await matchRoute(
268
+ "/404",
269
+ routeCache,
270
+ viteServer,
271
+ logging,
272
+ manifest,
273
+ config
274
+ );
275
+ return handleRoute(
276
+ fourOhFourRoute,
277
+ new URL("/404", url),
278
+ "/404",
279
+ body,
280
+ origin,
281
+ routeCache,
282
+ viteServer,
283
+ manifest,
284
+ logging,
285
+ config,
286
+ req,
287
+ res
288
+ );
289
+ }
290
+ await writeWebResponse(res, result.response);
291
+ } else {
292
+ let contentType = "text/plain";
293
+ const filepath = route.pathname || route.segments.map((segment) => segment.map((p) => p.content).join("")).join("/");
294
+ const computedMimeType = mime.getType(filepath);
295
+ if (computedMimeType) {
296
+ contentType = computedMimeType;
297
+ }
298
+ res.writeHead(200, { "Content-Type": `${contentType};charset=utf-8` });
299
+ res.end(result.body);
300
+ }
301
+ } else {
302
+ const result = await ssr(preloadedComponent, options);
303
+ return await writeSSRResult(result, res);
304
+ }
305
+ }
264
306
  function createPlugin({ config, logging }) {
265
307
  return {
266
308
  name: "astro:server",
@@ -7,4 +7,4 @@ export declare type ViteStyleTransformer = {
7
7
  transformStyleWithVite: TransformStyleWithVite;
8
8
  };
9
9
  export declare function createViteStyleTransformer(viteConfig: vite.ResolvedConfig): ViteStyleTransformer;
10
- export declare function createTransformStyles(viteStyleTransformer: ViteStyleTransformer, filename: string, ssr: boolean, pluginContext: PluginContext): TransformStyle;
10
+ export declare function createTransformStyles(viteStyleTransformer: ViteStyleTransformer, filename: string, ssr: boolean, pluginContext?: PluginContext): TransformStyle;
@@ -14,10 +14,6 @@ function getNormalizedIDForPostCSS(filename) {
14
14
  }
15
15
  }
16
16
  function createTransformStyles(viteStyleTransformer, filename, ssr, pluginContext) {
17
- if (!pluginContext.addWatchFile) {
18
- pluginContext.addWatchFile = () => {
19
- };
20
- }
21
17
  const normalizedID = getNormalizedIDForPostCSS(filename);
22
18
  return async function(styleSource, lang) {
23
19
  const result = await viteStyleTransformer.transformStyleWithVite.call(pluginContext, {
@@ -12,7 +12,9 @@ function createTransformStyleWithViteFn(viteConfig) {
12
12
  }
13
13
  const styleId = `${id}?astro&type=style&lang${lang}`;
14
14
  viteDevServer == null ? void 0 : viteDevServer.moduleGraph.ensureEntryFromUrl(styleId, ssr, false);
15
- const transformResult = await transformCss.call(this, source, styleId, ssr);
15
+ const ctx = this ?? { addWatchFile: () => {
16
+ } };
17
+ const transformResult = await transformCss.call(ctx, source, styleId, ssr);
16
18
  const { code, map } = transformResult;
17
19
  const deps = /* @__PURE__ */ new Set();
18
20
  const mod = viteDevServer == null ? void 0 : viteDevServer.moduleGraph.getModuleById(styleId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -125,7 +125,7 @@
125
125
  "recast": "^0.20.5",
126
126
  "rehype": "^12.0.1",
127
127
  "resolve": "^1.22.0",
128
- "rollup": "~2.77.0",
128
+ "rollup": "~2.78.0",
129
129
  "semver": "^7.3.7",
130
130
  "shiki": "^0.11.1",
131
131
  "sirv": "^2.0.2",
@@ -136,7 +136,7 @@
136
136
  "tsconfig-resolver": "^3.0.1",
137
137
  "unist-util-visit": "^4.1.0",
138
138
  "vfile": "^5.3.2",
139
- "vite": "3.0.9",
139
+ "vite": "3.1.0",
140
140
  "yargs-parser": "^21.0.1",
141
141
  "zod": "^3.17.3"
142
142
  },