Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to new config #2962

Merged
merged 46 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
137af27
wip: config migration
Mar 30, 2022
0998a31
fix: formatting
bholmesdev Apr 1, 2022
1f53957
refactor: projectRoot -> root
bholmesdev Apr 1, 2022
bf072d8
refactor: pageUrlFormat -> format
bholmesdev Apr 1, 2022
df642c6
refactor: buildOptions.site -> site
bholmesdev Apr 1, 2022
2dc6b3e
refactor: public -> publicDir
bholmesdev Apr 1, 2022
08d9c02
refactor: dist -> outDir
bholmesdev Apr 1, 2022
a42559e
refactor: styleOptions -> style
bholmesdev Apr 1, 2022
b82564d
fix: some dist tests -> outDir
bholmesdev Apr 1, 2022
835126b
refactor: remove legacyBuild (with TODOs)
bholmesdev Apr 1, 2022
1afeecd
refactor: more legacyBuild cleanup
bholmesdev Apr 1, 2022
0603c07
refactor: server host and port
bholmesdev Apr 1, 2022
d332380
fix: remove experimentalStaticBuild CLI flag
bholmesdev Apr 1, 2022
a29af9c
refactor: src -> srcDir
bholmesdev Apr 1, 2022
959036c
refactor: devOptions.trailing -> trailing
bholmesdev Apr 1, 2022
5318b47
refactor: remove sitemap + related flags
bholmesdev Apr 1, 2022
10d2528
refactor: experimentalSSR -> experimental.ssr
bholmesdev Apr 1, 2022
7837f61
fix: last devOptions
bholmesdev Apr 1, 2022
2cc7682
refactor: drafts -> markdown.drafts
bholmesdev Apr 1, 2022
4ba2bf3
fix: TS error on port as const
bholmesdev Apr 1, 2022
658094e
refactor: remove pages
bholmesdev Apr 1, 2022
9d15648
refactor: more --project-root updates
bholmesdev Apr 1, 2022
8d18719
refactor: markdownOptions -> markdown
bholmesdev Apr 1, 2022
090e301
fix: remaining type errors
bholmesdev Apr 1, 2022
7c38c18
feat: update AstroUserConfig
bholmesdev Apr 1, 2022
e3ddd5f
refactor: update CLI flag mapper + server mapper
bholmesdev Apr 1, 2022
be7b62b
fix: loadFixture projectRoot
bholmesdev Apr 1, 2022
1d3fa13
fix: merge CLI flags before validating / transforming
bholmesdev Apr 1, 2022
4dab14c
wip: attempt to fix bad createRouteManifest config
bholmesdev Apr 1, 2022
1d60488
refactor: combine config.base and config.site
Apr 2, 2022
c8c6f86
fix: skip route manifest test for now
Apr 2, 2022
82ef288
fix: site and base handling
Apr 2, 2022
759c46c
refactor: update failing config testes
Apr 2, 2022
1dda1d0
fix: build failure
Apr 2, 2022
22b045c
feat: update config types with migration help
Apr 2, 2022
9038ff3
chore: update types
Apr 2, 2022
534394b
fix(deno): update deno fixture
Apr 2, 2022
d7cae89
chore: remove config migration logic
Apr 2, 2022
5c0bf81
chore: remove logLevel
Apr 2, 2022
7b4dd45
chore: clean-up config types
Apr 2, 2022
2f5035f
chore: update config warning
Apr 2, 2022
4ee4246
chore: add changeset
Apr 2, 2022
52ca910
Sitemap Integration (#2965)
natemoo-re Apr 2, 2022
ffcb645
fred pass
FredKSchott Apr 2, 2022
35dc594
fix: Astro.resolve typo
Apr 2, 2022
c382bdd
fix: public => publicDir
Apr 2, 2022
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
Prev Previous commit
Next Next commit
refactor: buildOptions.site -> site
  • Loading branch information
bholmesdev authored and FredKSchott committed Apr 2, 2022
commit df642c6f514aaeec43cbf9b125b343d2387f96da
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function getStaticPaths({ paginate, rss }) {
const sortedPosts = allPosts.sort((a, b) => new Date(b.frontmatter.date).valueOf() - new Date(a.frontmatter.date).valueOf());

// Generate an RSS feed from this collection of posts.
// NOTE: This is disabled by default, since it requires `buildOptions.site` to be set in your "astro.config.mjs" file.
// NOTE: This is disabled by default, since it requires `site` to be set in your "astro.config.mjs" file.
// rss({
// title: 'Don’s Blog',
// description: 'An example blog on Astro',
Expand Down
4 changes: 1 addition & 3 deletions examples/blog/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import preact from '@astrojs/preact';
// https://astro.build/config
export default defineConfig({
integrations: [preact()],
buildOptions: {
site: 'https://example.com/',
},
site: 'https://example.com/',
});
4 changes: 1 addition & 3 deletions examples/subpath/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import react from '@astrojs/react';
// https://astro.build/config
export default defineConfig({
integrations: [react()],
buildOptions: {
site: 'http:https://example.com/blog',
},
site: 'http:https://example.com/blog',
});
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function generatePath(pathname: string, opts: StaticBuildOptions, gopts: G

debug('build', `Generating: ${pathname}`);

const site = astroConfig.buildOptions.site;
const site = astroConfig.site;
const links = createLinkStylesheetElementSet(linkIds.reverse(), site);
const scripts = createModuleScriptElementWithSrcSet(hoistedId ? [hoistedId] : [], site);

Expand Down Expand Up @@ -196,7 +196,7 @@ async function generatePath(pathname: string, opts: StaticBuildOptions, gopts: G
request: createRequest({ url, headers: new Headers(), logging }),
route: pageData.route,
routeCache,
site: astroConfig.buildOptions.site,
site: astroConfig.site,
ssr: isBuildingToSSR(opts.astroConfig),
};

Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AstroBuilder {
private timer: Record<string, number>;

constructor(config: AstroConfig, options: BuildOptions) {
if (!config.buildOptions.site && config.buildOptions.sitemap !== false) {
if (!config.site && config.buildOptions.sitemap !== false) {
warn(options.logging, 'config', `Set "buildOptions.site" to generate correct canonical URLs and sitemap`);
}
if (options.mode) {
Expand All @@ -52,7 +52,7 @@ class AstroBuilder {
const port = config.devOptions.port; // no need to save this (don’t rely on port in builder)
this.logging = options.logging;
this.routeCache = new RouteCache(this.logging);
this.origin = config.buildOptions.site ? new URL(config.buildOptions.site).origin : `http:https://localhost:${port}`;
this.origin = config.site ? new URL(config.site).origin : `http:https://localhost:${port}`;
this.manifest = createRouteManifest({ config }, this.logging);
this.timer = {};
}
Expand Down Expand Up @@ -164,11 +164,11 @@ class AstroBuilder {
debug('build', timerMessage('Additional assets copied', this.timer.assetsStart));

// Build your final sitemap.
if (this.config.buildOptions.sitemap && this.config.buildOptions.site) {
if (this.config.buildOptions.sitemap && this.config.site) {
this.timer.sitemapStart = performance.now();
const sitemapFilter = this.config.buildOptions.sitemapFilter ? (this.config.buildOptions.sitemapFilter as (page: string) => boolean) : undefined;
const sitemap = generateSitemap(
pageNames.map((pageName) => new URL(pageName, this.config.buildOptions.site).href),
pageNames.map((pageName) => new URL(pageName, this.config.site).href),
sitemapFilter
);
const sitemapPath = new URL('./sitemap.xml', this.config.dist);
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export async function collectPagesData(opts: CollectPagesDataOptions): Promise<C
debug('build', `├── ${colors.bold(colors.red('✗'))} ${route.component}`);
throw err;
});
const rssFn = generateRssFunction(astroConfig.buildOptions.site, route);
const rssFn = generateRssFunction(astroConfig.site, route);
for (const rssCallArg of result.rss) {
const rssResult = rssFn(rssCallArg);
if (rssResult.xml) {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/scan-based-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ export async function build(opts: ScanBasedBuildOptions): Promise<RollupOutput |
root: viteConfig.root,
envPrefix: 'PUBLIC_',
server: viteConfig.server,
base: astroConfig.buildOptions.site ? new URL(astroConfig.buildOptions.site).pathname : '/',
base: astroConfig.site ? new URL(astroConfig.site).pathname : '/',
});
}
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
root: viteConfig.root,
envPrefix: 'PUBLIC_',
server: viteConfig.server,
base: astroConfig.buildOptions.site ? new URL(astroConfig.buildOptions.site).pathname : '/',
base: astroConfig.site ? new URL(astroConfig.site).pathname : '/',
ssr: viteConfig.ssr,
resolve: viteConfig.resolve,
} as ViteConfigWithSSR;
Expand Down Expand Up @@ -218,7 +218,7 @@ async function clientBuild(opts: StaticBuildOptions, internals: BuildInternals,
root: viteConfig.root,
envPrefix: 'PUBLIC_',
server: viteConfig.server,
base: appendForwardSlash(astroConfig.buildOptions.site ? new URL(astroConfig.buildOptions.site).pathname : '/'),
base: astroConfig.base,
} as ViteConfigWithSSR;

await runHookBuildSetup({ config: astroConfig, vite: viteBuildConfig, target: 'client' });
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/vite-plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function buildManifest(opts: StaticBuildOptions, internals: BuildInternals): Ser

const ssrManifest: SerializedSSRManifest = {
routes,
site: astroConfig.buildOptions.site,
site: astroConfig.site,
markdown: {
render: astroConfig.markdownOptions.render,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default async function dev(config: AstroConfig, options: DevOptions = { l
await viteServer.listen(config.devOptions.port);

const devServerAddressInfo = viteServer.httpServer!.address() as AddressInfo;
const site = config.buildOptions.site ? new URL(config.buildOptions.site) : undefined;
const site = config.site ? new URL(config.site) : undefined;
info(options.logging, null, msg.devStart({ startupTime: performance.now() - devStart, config, devServerAddressInfo, site, https: !!viteConfig.server?.https }));

const currentVersion = process.env.PACKAGE_VERSION ?? '0.0.0';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
const defaultOrigin = 'http:https://localhost';
const trailingSlash = config.devOptions.trailingSlash;
/** Base request URL. */
let baseURL = new URL(config.buildOptions.site || '/', defaultOrigin);
let baseURL = new URL(config.site || '/', defaultOrigin);
const staticFileServer = sirv(fileURLToPath(config.dist), {
dev: true,
etag: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/render/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInsta
request,
route,
routeCache,
site: astroConfig.buildOptions.site,
site: astroConfig.site,
ssr: isBuildingToSSR(astroConfig),
});

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/render/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function generateRSSStylesheet() {
export function generateRssFunction(site: string | undefined, route: RouteData): RSSFunction {
return function rssUtility(args: RSS): RSSResult {
if (!site) {
throw new Error(`[${route.component}] rss() tried to generate RSS but "buildOptions.site" missing in astro.config.mjs`);
throw new Error(`[${route.component}] rss() tried to generate RSS but "site" missing in astro.config.mjs`);
}
let result: RSSResult = {} as any;
const { dest, ...rssData } = args;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function isBuildingToSSR(config: AstroConfig): boolean {
if (!adapter) return false;

if (typeof adapter.serverEntrypoint === 'string') {
if (!adapter.name.startsWith('@astrojs/') && !config.buildOptions.experimentalSsr) {
if (!adapter.name.startsWith('@astrojs/') && !config.experimental.ssr) {
throw new Error(
[
`Server-side rendering (SSR) is still experimental.`,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/template/4xx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function subpathNotUsedTemplate(base: string, pathname: string) {
statusCode: 404,
title: 'Not found',
tabTitle: '404: Not Found',
body: `<p>In your <code>buildOptions.site</code> you have your base path set to <a href="${base}">${base}</a>. Do you want to go there instead?</p>
body: `<p>In your <code>site</code> you have your base path set to <a href="${base}">${base}</a>. Do you want to go there instead?</p>
<p>Come to our <a href="https://astro.build/chat">Discord</a> if you need help.</p>`,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/vite-plugin-astro-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async function writeSSRResult(result: RenderResponse, res: http.ServerResponse,
}

async function handle404Response(origin: string, config: AstroConfig, req: http.IncomingMessage, res: http.ServerResponse) {
const site = config.buildOptions.site ? new URL(config.buildOptions.site) : undefined;
const site = config.site ? new URL(config.site) : undefined;
const devRoot = site ? site.pathname : '/';
const pathname = decodeURI(new URL(origin + req.url).pathname);
let html = '';
Expand Down Expand Up @@ -120,7 +120,7 @@ async function handleRequest(
res: http.ServerResponse
) {
const reqStart = performance.now();
const site = config.buildOptions.site ? new URL(config.buildOptions.site) : undefined;
const site = config.site ? new URL(config.site) : undefined;
const devRoot = site ? site.pathname : '/';
const origin = `${viteServer.config.server.https ? 'https' : 'http'}:https://${req.headers.host}`;
const buildingToSSR = isBuildingToSSR(config);
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function compile(config: AstroConfig, filename: string, source: string, vi
const transformResult = await transform(source, {
pathname,
projectRoot: config.root.toString(),
site: config.buildOptions.site,
site: config.site,
sourcefile: filename,
sourcemap: 'both',
internalURL: `/@fs${prependForwardSlash(viteID(new URL('../runtime/server/index.js', import.meta.url)))}`,
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function markdown({ config }: AstroPluginOptions): Plugin {
// Return the file's JS representation, including all Markdown
// frontmatter and a deferred `import() of the compiled markdown content.
if (id.startsWith(VIRTUAL_MODULE_ID)) {
const sitePathname = config.buildOptions.site ? new URL(config.buildOptions.site).pathname : '/';
const sitePathname = config.site ? new URL(config.site).pathname : '/';
const fileId = id.substring(VIRTUAL_MODULE_ID.length);
const fileUrl = fileId.includes('/pages/') ? fileId.replace(/^.*\/pages\//, sitePathname).replace(/(\/index)?\.md$/, '') : undefined;
const source = await fs.promises.readFile(fileId, 'utf8');
Expand Down Expand Up @@ -153,7 +153,7 @@ ${setup}`.trim();
let { code: tsResult } = await transform(astroResult, {
pathname: fileUrl.pathname.substr(config.root.pathname.length - 1),
projectRoot: config.root.toString(),
site: config.buildOptions.site,
site: config.site,
sourcefile: id,
sourcemap: 'inline',
internalURL: `/@fs${new URL('../runtime/server/index.js', import.meta.url).pathname}`,
Expand Down
18 changes: 6 additions & 12 deletions packages/astro/test/dev-routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ describe('Development Routing', () => {

before(async () => {
fixture = await loadFixture({
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
root: './fixtures/with-subpath-no-trailing-slash/',
dist: './dist-4007',
buildOptions: {
site: 'http:https://example.com/',
},
site: 'http:https://example.com/',
});
devServer = await fixture.startDevServer();
});
Expand Down Expand Up @@ -94,11 +92,9 @@ describe('Development Routing', () => {

before(async () => {
fixture = await loadFixture({
projectRoot: './fixtures/with-subpath-no-trailing-slash/',
root: './fixtures/with-subpath-no-trailing-slash/',
dist: './dist-4008',
buildOptions: {
site: 'http:https://example.com/blog/',
},
site: 'http:https://example.com/blog/',
});
devServer = await fixture.startDevServer();
});
Expand Down Expand Up @@ -195,10 +191,8 @@ describe('Development Routing', () => {

before(async () => {
fixture = await loadFixture({
projectRoot: './fixtures/with-endpoint-routes/',
buildOptions: {
site: 'http:https://example.com/',
},
root: './fixtures/with-endpoint-routes/',
site: 'http:https://example.com/',
});
devServer = await fixture.startDevServer();
});
Expand Down
6 changes: 2 additions & 4 deletions packages/astro/test/fixtures/static build/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import preact from '@astrojs/preact';
// https://astro.build/config
export default defineConfig({
integrations: [preact()],
buildOptions: {
site: 'http:https://example.com/subpath/',
},
site: 'http:https://example.com/subpath/',
ssr: {
noExternal: ['@test/static-build-pkg'],
},
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
buildOptions: {
site: 'http:https://example.com/subpath/',
pageUrlFormat: 'file',
site: 'http:https://example.com/subpath/',
build: {
format: 'file',
},
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

export default {
buildOptions: {
site: 'http:https://example.com/blog'
}
site: 'http:https://example.com/blog',
}
2 changes: 1 addition & 1 deletion packages/integrations/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function netlifyFunctions({ dist }: NetlifyFunctionsOptions = {}): AstroIntegrat
}
},
'astro:config:done': ({ config, setAdapter }) => {
setAdapter(getAdapter(config.buildOptions.site));
setAdapter(getAdapter(config.site));
_config = config;
},
'astro:build:start': async ({ buildConfig }) => {
Expand Down
6 changes: 2 additions & 4 deletions packages/integrations/sitemap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {

## Getting started

`@astrojs/sitemap` requires a deployment / site URL for generation. Add your site's URL under your `astro.config.*` using the `buildOptions.site` property:
`@astrojs/sitemap` requires a deployment / site URL for generation. Add your site's URL under your `astro.config.*` using the `site` property:

__astro.config.mjs__

Expand All @@ -59,9 +59,7 @@ import sitemap from '@astrojs/sitemap';

export default {
// ...
buildOptions: {
site: 'https://stargazers.club',
},
site: 'https://stargazers.club',
integrations: [sitemap()],
}
```
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function createPlugin(): AstroIntegration {
config = _config;
},
'astro:build:done': async ({ pages, dir }) => {
const finalSiteUrl = config.buildOptions.site;
const finalSiteUrl = config.site;
if (!finalSiteUrl) {
return;
}
Expand Down