Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,24 @@ Server-side rendering (SSR) can be complicated. The Astro package (`packages/ast
- `server/`: Code that executes **inside Vite’s SSR.** Though this is a Node environment inside, this will be executed independently of `core/` and may have to be structured differently.
- `vite-plugin-*/`: Any Vite plugins that Astro needs to run. For the most part, these also execute within Vite similar to `src/runtime/server/`, but it’s also helpful to think about them as independent modules. _Note: at the moment these are internal while they’re in development_

### Public vs. internal API

`packages/astro/package.json` declares two export maps:

- `"exports"` — the monorepo view. Includes public entries plus `./_internal/*` subpaths for use by other workspace packages.
- `"publishConfig.exports"` — the npm view. [pnpm replaces `"exports"` with this at publish time](https://pnpm.io/package_json#publishconfig), so `_internal/*` entries never ship.

Other workspace packages should import internals via the subpath, not a deep relative path:

```ts
// Do this
import { loadFixture } from 'astro/_internal/test/test-utils';
// Not tihs
import { loadFixture } from '../../../astro/test/test-utils.js';
```

To add a new internal entry, add the `./_internal/*` key to `"exports"` only — not to `"publishConfig.exports"`.

### Thinking about SSR

There are 3 contexts in which code executes:
Expand Down
63 changes: 62 additions & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@
"./zod": "./dist/zod.js",
"./errors": "./dist/core/errors/userError.js",
"./middleware": "./dist/core/middleware/index.js",
"./virtual-modules/*": "./dist/virtual-modules/*"
"./virtual-modules/*": "./dist/virtual-modules/*",
"./_internal/assets": "./dist/assets/internal.js",
"./_internal/logger": "./dist/core/logger/core.js",
"./_internal/test/test-adapter": "./test/test-adapter.js",
"./_internal/test/test-utils": "./test/test-utils.js"
},
"bin": {
"astro": "./bin/astro.mjs"
Expand Down Expand Up @@ -217,6 +221,63 @@
"pnpm": ">=7.1.0"
},
"publishConfig": {
"exports": {
".": "./dist/index.js",
"./env": "./env.d.ts",
"./env/runtime": "./dist/env/runtime.js",
"./env/setup": "./dist/env/setup.js",
"./types": "./types.d.ts",
"./client": "./client.d.ts",
"./astro-jsx": "./astro-jsx.d.ts",
"./tsconfigs/*.json": "./tsconfigs/*",
"./tsconfigs/*": "./tsconfigs/*.json",
"./jsx/rehype.js": "./dist/jsx/rehype.js",
"./jsx-runtime": {
"types": "./jsx-runtime.d.ts",
"default": "./dist/jsx-runtime/index.js"
},
"./jsx-dev-runtime": {
"types": "./jsx-runtime.d.ts",
"default": "./dist/jsx-runtime/index.js"
},
"./compiler-runtime": "./dist/runtime/compiler/index.js",
"./runtime/*": "./dist/runtime/*",
"./config": "./dist/config/entrypoint.js",
"./container": "./dist/container/index.js",
"./app": "./dist/core/app/entrypoints/index.js",
"./app/node": "./dist/core/app/entrypoints/node.js",
"./app/entrypoint": "./dist/core/app/entrypoints/virtual/index.js",
"./app/entrypoint/dev": "./dist/core/app/entrypoints/virtual/dev.js",
"./app/entrypoint/prod": "./dist/core/app/entrypoints/virtual/prod.js",
"./app/manifest": "./dist/core/app/entrypoints/manifest.js",
"./entrypoints/prerender": "./dist/entrypoints/prerender.js",
"./entrypoints/legacy": "./dist/entrypoints/legacy.js",
"./client/*": "./dist/runtime/client/*",
"./components": "./components/index.ts",
"./components/*": "./components/*",
"./toolbar": "./dist/toolbar/index.js",
"./actions/runtime/entrypoints/*": "./dist/actions/runtime/entrypoints/*",
"./assets": "./dist/assets/index.js",
"./assets/runtime": "./dist/assets/runtime.js",
"./assets/utils": "./dist/assets/utils/index.js",
"./assets/utils/node": "./dist/assets/utils/node.js",
"./assets/utils/inferRemoteSize.js": "./dist/assets/utils/remoteProbe.js",
"./assets/endpoint/*": "./dist/assets/endpoint/*.js",
"./assets/services/sharp": "./dist/assets/services/sharp.js",
"./assets/services/noop": "./dist/assets/services/noop.js",
"./cache/memory": "./dist/core/cache/memory-provider.js",
"./assets/fonts/runtime.js": "./dist/assets/fonts/runtime.js",
"./loaders": "./dist/content/loaders/index.js",
"./content/config": "./dist/content/config.js",
"./content/runtime": "./dist/content/runtime.js",
"./content/runtime-assets": "./dist/content/runtime-assets.js",
"./debug": "./components/Debug.astro",
"./package.json": "./package.json",
"./zod": "./dist/zod.js",
"./errors": "./dist/core/errors/userError.js",
"./middleware": "./dist/core/middleware/index.js",
"./virtual-modules/*": "./dist/virtual-modules/*"
},
"provenance": true
},
"funding": {
Expand Down
13 changes: 13 additions & 0 deletions packages/astro/test/exports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import assert from 'node:assert/strict';
import { it } from 'node:test';

it('"exports" and "publishConfig.exports" should be the same except for internal API', async () => {
const { default: pkgJson } = await import('../package.json', { with: { type: 'json' } });
const exports: Record<string, unknown> = pkgJson.exports;
const publishConfigExports: Record<string, unknown> = pkgJson.publishConfig.exports;
const internal = Object.keys(exports).filter((key) => key.startsWith('./_internal/'));
for (const key of internal) {
delete exports[key];
}
assert.deepEqual(exports, publishConfigExports);
});
2 changes: 1 addition & 1 deletion packages/db/test/basics.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { load as cheerioLoad } from 'cheerio';
import testAdapter from '../../astro/test/test-adapter.js';
import testAdapter from 'astro/_internal/test/test-adapter';
import {
clearEnvironment,
type DevServer,
Expand Down
2 changes: 1 addition & 1 deletion packages/db/test/db-in-src.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { load as cheerioLoad } from 'cheerio';
import testAdapter from '../../astro/test/test-adapter.js';
import testAdapter from 'astro/_internal/test/test-adapter';
import { type DevServer, type Fixture, loadFixture } from './test-utils.ts';

describe('astro:db', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/db/test/libsql-remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { rm } from 'node:fs/promises';
import { relative } from 'node:path';
import { after, before, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import testAdapter from '../../astro/test/test-adapter.js';
import testAdapter from 'astro/_internal/test/test-adapter';
import { clearEnvironment, type Fixture, initializeRemoteDb, loadFixture } from './test-utils.ts';

describe('astro:db local database', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/db/test/local-prod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
import { relative } from 'node:path';
import { after, before, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import testAdapter from '../../astro/test/test-adapter.js';
import testAdapter from 'astro/_internal/test/test-adapter';
import { type Fixture, loadFixture } from './test-utils.ts';

describe('astro:db local database', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/db/test/ssr-no-apptoken.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import testAdapter from '../../astro/test/test-adapter.js';
import testAdapter from 'astro/_internal/test/test-adapter';
import { type Fixture, loadFixture, type RemoteDbServer, setupRemoteDb } from './test-utils.ts';

describe('missing app token', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/db/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export {
loadFixture,
type DevServer,
type Fixture,
} from '../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';

const isWindows = process.platform === 'win32';

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/alpinejs/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type Fixture,
type AstroInlineConfig,
type DevServer,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';

// Get all test files in directory, assign unique port for each of them so they don't conflict
const testFiles = await fs.readdir(new URL('.', import.meta.url));
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/cloudflare/test/ssr-deps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { rmSync } from 'node:fs';
import { Writable } from 'node:stream';
import { after, before, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import { AstroLogger } from '../../../astro/dist/core/logger/core.js';
import { AstroLogger } from 'astro/_internal/logger';
import { type DevServer, type Fixture, loadFixture } from './test-utils.ts';

describe('SSR dependencies', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/integrations/cloudflare/test/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { DevServer } from '../../../astro/src/core/dev/dev.js';
import type { PreviewServer } from '../../../astro/src/types/public/preview.js';
import type { PreviewServer } from 'astro';
import {
loadFixture as baseLoadFixture,
type AstroInlineConfig,
type DevServer,
type Fixture,
loadFixture as baseLoadFixture,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';

export type { AstroInlineConfig, DevServer, Fixture, PreviewServer };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Writable } from 'node:stream';
import { type Fixture, loadFixture } from './test-utils.ts';
import assert from 'node:assert/strict';
import { fileURLToPath } from 'node:url';
import { AstroLogger } from '../../../astro/dist/core/logger/core.js';
import { AstroLogger } from 'astro/_internal/logger';

describe('Top-level Return', () => {
let fixture: Fixture;
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/cloudflare/test/with-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { rmSync } from 'node:fs';
import { Writable } from 'node:stream';
import { after, before, describe, it } from 'node:test';
import { type Fixture, loadFixture } from './test-utils.ts';
import { AstroLogger } from '../../../astro/dist/core/logger/core.js';
import { AstroLogger } from 'astro/_internal/logger';
import { fileURLToPath } from 'node:url';

describe('base', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/cloudflare/test/with-react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Writable } from 'node:stream';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { type Fixture, loadFixture, type PreviewServer } from './test-utils.ts';
import { AstroLogger } from '../../../astro/dist/core/logger/core.js';
import { AstroLogger } from 'astro/_internal/logger';
import { fileURLToPath } from 'node:url';

describe('React', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/markdoc/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export {
loadFixture,
type DevServer,
type Fixture,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';
7 changes: 2 additions & 5 deletions packages/integrations/mdx/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import type * as estree from 'estree';
import type * as hast from 'hast';
import type * as mdast from 'mdast';
import type * as unified from 'unified';
import {
AstroIntegrationLogger,
type AstroLogMessage,
} from '../../../astro/dist/core/logger/core.js';
import { AstroIntegrationLogger, type AstroLogMessage } from 'astro/_internal/logger';

export {
loadFixture,
type AstroInlineConfig,
type DevServer,
type Fixture,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';

export type RemarkPlugin<PluginParameters extends any[] = any[]> = unified.Plugin<
PluginParameters,
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/netlify/src/image-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ExternalImageService } from 'astro';
import { baseService } from 'astro/assets';
import { verifyOptions } from '../../../astro/dist/assets/internal.js';
import { verifyOptions } from 'astro/_internal/assets';
import { isESMImportedImage } from 'astro/assets/utils';
import { AstroError } from 'astro/errors';

Expand Down
7 changes: 2 additions & 5 deletions packages/integrations/netlify/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import {
type AstroInlineConfig,
type Fixture,
loadFixture as baseLoadFixture,
} from '../../../astro/test/test-utils.js';
import {
AstroIntegrationLogger,
type AstroLogMessage,
} from '../../../astro/dist/core/logger/core.js';
} from 'astro/_internal/test/test-utils';
import { AstroIntegrationLogger, type AstroLogMessage } from 'astro/_internal/logger';

export type { AstroInlineConfig, DevServer, Fixture };

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/test/api-route.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'node:assert/strict';
import crypto from 'node:crypto';
import { after, before, describe, it } from 'node:test';
import type { PreviewServer } from '../../../astro/src/types/public/preview.js';
import type { PreviewServer } from 'astro';
import nodejs from '../dist/index.js';
import { createRequestAndResponse, type Fixture, loadFixture } from './test-utils.ts';

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/test/assets.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import type { PreviewServer } from '../../../astro/src/types/public/preview.js';
import type { PreviewServer } from 'astro';
import * as cheerio from 'cheerio';
import nodejs from '../dist/index.js';
import { type Fixture, loadFixture } from './test-utils.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/test/bad-urls.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import type { PreviewServer } from '../../../astro/src/types/public/preview.js';
import type { PreviewServer } from 'astro';
import nodejs from '../dist/index.js';
import { type Fixture, loadFixture } from './test-utils.ts';

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/test/image.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as assert from 'node:assert/strict';
import { cp, rm } from 'node:fs/promises';
import { after, before, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import type { PreviewServer } from '../../../astro/src/types/public/preview.js';
import type { PreviewServer } from 'astro';
import { inferRemoteSize } from 'astro/assets/utils/inferRemoteSize.js';
import * as cheerio from 'cheerio';
import nodejs from '../dist/index.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import type { PreviewServer } from '../../../astro/src/types/public/preview.js';
import type { PreviewServer } from 'astro';
import node from '../dist/index.js';
import { type Fixture, loadFixture } from './test-utils.ts';

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/test/preview-headers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import type { PreviewServer } from '../../../astro/src/types/public/preview.js';
import type { PreviewServer } from 'astro';
import nodejs from '../dist/index.js';
import { type Fixture, loadFixture } from './test-utils.ts';

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/test/sessions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import type { PreviewServer } from '../../../astro/src/types/public/preview.js';
import type { PreviewServer } from 'astro';
import * as devalue from 'devalue';
import nodejs from '../dist/index.js';
import { type Fixture, loadFixture, type DevServer } from './test-utils.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type AdapterServer,
type DevServer,
loadFixture as baseLoadFixture,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';
import type * as express from 'express';

process.env.ASTRO_NODE_AUTOSTART = 'disabled';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import type { PreviewServer } from '../../../astro/src/types/public/preview.js';
import type { PreviewServer } from 'astro';
import nodejs from '../dist/index.js';
import { createRequestAndResponse, type Fixture, loadFixture } from './test-utils.ts';

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/react/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export {
loadFixture,
type DevServer,
type Fixture,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';
2 changes: 1 addition & 1 deletion packages/integrations/sitemap/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
type AstroInlineConfig,
type Fixture,
loadFixture as baseLoadFixture,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';

export type { AstroInlineConfig, Fixture };

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/svelte/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export {
loadFixture,
type DevServer,
type Fixture,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';
2 changes: 1 addition & 1 deletion packages/integrations/vercel/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
type Fixture,
type DevServer,
type AstroInlineConfig,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';

export type { Fixture, DevServer, AstroInlineConfig };

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vue/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type Fixture,
type DevServer,
type AstroInlineConfig,
} from '../../../astro/test/test-utils.js';
} from 'astro/_internal/test/test-utils';

export { cli };
export type { Fixture, DevServer };
Expand Down
2 changes: 1 addition & 1 deletion packages/language-tools/language-server/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { cli } from '../../../astro/test/test-utils.js';
import { cli } from 'astro/_internal/test/test-utils';

// Copied from utils.ts so we don't have to import TS code for Node 20
const __filename = fileURLToPath(import.meta.url);
Expand Down
Loading