diff --git a/src/compiler/index.ts b/src/compiler/index.ts index 1afa97c87..0ba5657cd 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -1,12 +1,12 @@ import type { LogOptions } from '../logger.js'; -import type { AstroConfig } from '../@types/astro'; +import type { AstroConfig, CompileResult, TransformResult } from '../@types/astro'; import path from 'path'; import micromark from 'micromark'; import gfmSyntax from 'micromark-extension-gfm'; import matter from 'gray-matter'; import gfmHtml from 'micromark-extension-gfm/html.js'; -import { CompileResult, TransformResult } from '../@types/astro'; + import { parse } from '../parser/index.js'; import { createMarkdownHeadersCollector } from '../micromark-collect-headers.js'; import { encodeMarkdown } from '../micromark-encode.js'; @@ -130,13 +130,12 @@ export default __render; // triggered by loading a component directly by URL. export async function __renderPage({request, children, props}) { const currentChild = { - setup: typeof setup === 'undefined' ? (passthrough) => passthrough : setup, layout: typeof __layout === 'undefined' ? undefined : __layout, content: typeof __content === 'undefined' ? undefined : __content, __render, }; - await currentChild.setup({request}); + import.meta.request = request; const childBodyResult = await currentChild.__render(props, children); // find layout, if one was given. diff --git a/test/astro-request.test.js b/test/astro-request.test.js new file mode 100644 index 000000000..05fcf035b --- /dev/null +++ b/test/astro-request.test.js @@ -0,0 +1,19 @@ +import { suite } from 'uvu'; +import * as assert from 'uvu/assert'; +import { doc } from './test-utils.js'; +import { setup } from './helpers.js'; + +const Request = suite('import.meta.request'); + +setup(Request, './fixtures/astro-request'); + +Request('import.meta.request available', async (context) => { + const result = await context.runtime.load('/'); + + assert.equal(result.statusCode, 200); + + const $ = doc(result.contents); + assert.equal($('h1').text(), '/'); +}); + +Request.run(); diff --git a/test/fixtures/astro-request/astro.config.mjs b/test/fixtures/astro-request/astro.config.mjs new file mode 100644 index 000000000..48c4c3aad --- /dev/null +++ b/test/fixtures/astro-request/astro.config.mjs @@ -0,0 +1,5 @@ +export default { + projectRoot: '.', + astroRoot: './astro', + dist: './_site' +}; diff --git a/test/fixtures/astro-request/astro/pages/index.astro b/test/fixtures/astro-request/astro/pages/index.astro new file mode 100644 index 000000000..590a5e154 --- /dev/null +++ b/test/fixtures/astro-request/astro/pages/index.astro @@ -0,0 +1,10 @@ +--- +let path = import.meta.request.path; +--- + + +Test + +

{path}

+ + \ No newline at end of file