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: remove legacyBuild (with TODOs)
  • Loading branch information
bholmesdev authored and FredKSchott committed Apr 2, 2022
commit 835126bdb2c9d4c42240e1aec643ea95623ac434
37 changes: 11 additions & 26 deletions packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { nodeLogOptions } from '../logger/node.js';
import { createRouteManifest } from '../routing/index.js';
import { generateSitemap } from '../render/sitemap.js';
import { collectPagesData } from './page-data.js';
import { build as scanBasedBuild } from './scan-based-build.js';
import { staticBuild } from './static-build.js';
import { RouteCache } from '../render/route-cache.js';
import { runHookBuildDone, runHookBuildStart, runHookConfigDone, runHookConfigSetup } from '../../integrations/index.js';
Expand Down Expand Up @@ -126,31 +125,17 @@ class AstroBuilder {
this.timer.buildStart = performance.now();
info(this.logging, 'build', colors.dim(`Completed in ${getTimeStat(this.timer.init, performance.now())}.`));

// Use the new faster static based build.
if (!this.config.buildOptions.legacyBuild) {
await staticBuild({
allPages,
astroConfig: this.config,
logging: this.logging,
manifest: this.manifest,
origin: this.origin,
pageNames,
routeCache: this.routeCache,
viteConfig,
buildConfig,
});
} else {
await scanBasedBuild({
allPages,
astroConfig: this.config,
logging: this.logging,
origin: this.origin,
pageNames,
routeCache: this.routeCache,
viteConfig,
viteServer,
});
}
await staticBuild({
allPages,
astroConfig: this.config,
logging: this.logging,
manifest: this.manifest,
origin: this.origin,
pageNames,
routeCache: this.routeCache,
viteConfig,
buildConfig,
});

// Write any additionally generated assets to disk.
this.timer.assetsStart = performance.now();
Expand Down
89 changes: 0 additions & 89 deletions packages/astro/src/core/build/scan-based-build.ts

This file was deleted.

8 changes: 3 additions & 5 deletions packages/astro/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,9 @@ function resolveFlags(flags: Partial<Flags>): CLIFlags {
config: typeof flags.config === 'string' ? flags.config : undefined,
hostname: typeof flags.hostname === 'string' ? flags.hostname : undefined,
host: typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined,
legacyBuild: typeof flags.legacyBuild === 'boolean' ? flags.legacyBuild : undefined,
experimentalSsr: typeof flags.experimentalSsr === 'boolean' ? flags.experimentalSsr : undefined,
experimentalIntegrations: typeof flags.experimentalIntegrations === 'boolean' ? flags.experimentalIntegrations : undefined,
drafts: typeof flags.drafts === 'boolean' ? flags.drafts : undefined,
experimentalSsr: typeof flags.experimentalSsr === 'boolean' ? flags.experimentalSsr : false,
experimentalIntegrations: typeof flags.experimentalIntegrations === 'boolean' ? flags.experimentalIntegrations : false,
drafts: typeof flags.drafts === 'boolean' ? flags.drafts : false,
};
}

Expand All @@ -448,7 +447,6 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags) {
if (typeof flags.port === 'number') astroConfig.devOptions.port = flags.port;
if (typeof flags.host === 'string' || typeof flags.host === 'boolean') astroConfig.devOptions.host = flags.host;
if (typeof flags.hostname === 'string') astroConfig.devOptions.hostname = flags.hostname;
if (typeof flags.legacyBuild === 'boolean') astroConfig.buildOptions.legacyBuild = flags.legacyBuild;
if (typeof flags.experimentalSsr === 'boolean') astroConfig.buildOptions.experimentalSsr = flags.experimentalSsr;
if (typeof flags.experimentalIntegrations === 'boolean') astroConfig.experimentalIntegrations = flags.experimentalIntegrations;
if (typeof flags.drafts === 'boolean') astroConfig.buildOptions.drafts = flags.drafts;
Expand Down
35 changes: 12 additions & 23 deletions packages/astro/src/core/render/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export async function preload({ astroConfig, filePath, viteServer }: Pick<SSROpt
/** use Vite to SSR */
export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInstance, ssrOpts: SSROptions): Promise<RenderResponse> {
const { astroConfig, filePath, logging, mode, origin, pathname, request, route, routeCache, viteServer } = ssrOpts;
const legacy = astroConfig.buildOptions.legacyBuild;
// TODO: clean up "legacy" flag passed through helper functions
const legacy = false;

// Add hoisted script tags
const scripts = createModuleScriptElementWithSrcSet(!legacy && mod.hasOwnProperty('$$metadata') ? Array.from(mod.$$metadata.hoistedScriptPaths()) : []);
Expand Down Expand Up @@ -114,7 +115,8 @@ export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInsta
}

let content = await coreRender({
legacyBuild: astroConfig.buildOptions.legacyBuild,
// TODO: remove legacyBuild flag
legacyBuild: false,
links,
logging,
markdownRender: astroConfig.markdownOptions.render,
Expand All @@ -126,22 +128,15 @@ export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInsta
// TODO: Can we pass the hydration code more directly through Vite, so that we
// don't need to copy-paste and maintain Vite's import resolution here?
async resolve(s: string) {
// The legacy build needs these to remain unresolved so that vite HTML
// Can do the resolution. Without this condition the build output will be
// broken in the legacy build. This can be removed once the legacy build is removed.
if (!astroConfig.buildOptions.legacyBuild) {
const [resolvedUrl, resolvedPath] = await viteServer.moduleGraph.resolveUrl(s);
if (resolvedPath.includes('node_modules/.vite')) {
return resolvedPath.replace(/.*?node_modules\/\.vite/, '/node_modules/.vite');
}
// NOTE: This matches the same logic that Vite uses to add the `/@id/` prefix.
if (!resolvedUrl.startsWith('.') && !resolvedUrl.startsWith('/')) {
return '/@id' + prependForwardSlash(resolvedUrl);
}
return '/@fs' + prependForwardSlash(resolvedPath);
} else {
return s;
const [resolvedUrl, resolvedPath] = await viteServer.moduleGraph.resolveUrl(s);
if (resolvedPath.includes('node_modules/.vite')) {
return resolvedPath.replace(/.*?node_modules\/\.vite/, '/node_modules/.vite');
}
// NOTE: This matches the same logic that Vite uses to add the `/@id/` prefix.
if (!resolvedUrl.startsWith('.') && !resolvedUrl.startsWith('/')) {
return '/@id' + prependForwardSlash(resolvedUrl);
}
return '/@fs' + prependForwardSlash(resolvedPath);
},
renderers,
request,
Expand Down Expand Up @@ -196,12 +191,6 @@ export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInsta
// add injected tags
let html = injectTags(content.html, tags);

// run transformIndexHtml() in dev to run Vite dev transformations
if (mode === 'development' && astroConfig.buildOptions.legacyBuild) {
const relativeURL = filePath.href.replace(astroConfig.root.href, '/');
html = await viteServer.transformIndexHtml(relativeURL, html, pathname);
}

// inject <!doctype html> if missing (TODO: is a more robust check needed for comments, etc.?)
if (!/<!doctype html/i.test(html)) {
html = '<!DOCTYPE html>\n' + content;
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ export async function renderHead(result: SSRResult): Promise<string> {
const styles = Array.from(result.styles)
.filter(uniqueElements)
.map((style) => {
// TODO: clean up legacyBuild from metadata
const styleChildren = !result._metadata.legacyBuild ? '' : style.children;
return renderElement('style', {
children: styleChildren,
Expand Down
26 changes: 12 additions & 14 deletions packages/astro/src/vite-plugin-astro/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,23 @@ async function compile(config: AstroConfig, filename: string, source: string, vi
sourcefile: filename,
sourcemap: 'both',
internalURL: `/@fs${prependForwardSlash(viteID(new URL('../runtime/server/index.js', import.meta.url)))}`,
experimentalStaticExtraction: !config.buildOptions.legacyBuild,
// TODO add experimental flag here
// TODO: baseline flag
experimentalStaticExtraction: true,
preprocessStyle: async (value: string, attrs: Record<string, string>) => {
const lang = `.${attrs?.lang || 'css'}`.toLowerCase();

try {
// In the static build, grab any @import as CSS dependencies for HMR.
if (!config.buildOptions.legacyBuild) {
value.replace(/(?:@import)\s(?:url\()?\s?["\'](.*?)["\']\s?\)?(?:[^;]*);?/gi, (match, spec) => {
rawCSSDeps.add(spec);
// If the language is CSS: prevent `@import` inlining to prevent scoping of imports.
// Otherwise: Sass, etc. need to see imports for variables, so leave in for their compiler to handle.
if (lang === '.css') {
return createImportPlaceholder(spec);
} else {
return match;
}
});
}
value.replace(/(?:@import)\s(?:url\()?\s?["\'](.*?)["\']\s?\)?(?:[^;]*);?/gi, (match, spec) => {
rawCSSDeps.add(spec);
// If the language is CSS: prevent `@import` inlining to prevent scoping of imports.
// Otherwise: Sass, etc. need to see imports for variables, so leave in for their compiler to handle.
if (lang === '.css') {
return createImportPlaceholder(spec);
} else {
return match;
}
});

const result = await transformWithVite({
value,
Expand Down
2 changes: 0 additions & 2 deletions scripts/memory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ let config = await loadConfig({
cwd: fileURLToPath(projDir),
});

config.buildOptions.legacyBuild = false;

const server = await dev(config, { logging: { level: 'error' } });

// Prime the server so initial memory is created
Expand Down