diff options
Diffstat (limited to 'packages/astro/src')
-rw-r--r-- | packages/astro/src/ast.ts | 1 | ||||
-rw-r--r-- | packages/astro/src/build.ts | 29 | ||||
-rw-r--r-- | packages/astro/src/cli.ts | 1 | ||||
-rw-r--r-- | packages/astro/src/compiler/index.ts | 3 | ||||
-rw-r--r-- | packages/astro/src/config.ts | 1 | ||||
-rw-r--r-- | packages/astro/src/dev.ts | 1 | ||||
-rw-r--r-- | packages/astro/src/frontend/SvelteWrapper.svelte.client.ts | 166 | ||||
-rw-r--r-- | packages/astro/src/frontend/SvelteWrapper.svelte.server.ts | 12 | ||||
-rw-r--r-- | packages/astro/src/frontend/render/svelte.ts | 3 | ||||
-rw-r--r-- | packages/astro/src/frontend/runtime/svelte.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/logger.ts | 1 | ||||
-rw-r--r-- | packages/astro/src/runtime.ts | 1 | ||||
-rw-r--r-- | packages/astro/src/search.ts | 1 |
13 files changed, 32 insertions, 190 deletions
diff --git a/packages/astro/src/ast.ts b/packages/astro/src/ast.ts index 4f6848c89..6e6bd191f 100644 --- a/packages/astro/src/ast.ts +++ b/packages/astro/src/ast.ts @@ -1,3 +1,4 @@ +import 'source-map-support/register.js'; import type { Attribute } from 'astro-parser'; // AST utility functions diff --git a/packages/astro/src/build.ts b/packages/astro/src/build.ts index 392b0a920..fb603641d 100644 --- a/packages/astro/src/build.ts +++ b/packages/astro/src/build.ts @@ -1,3 +1,4 @@ +import 'source-map-support/register.js'; import type { AstroConfig, RuntimeMode } from './@types/astro'; import type { LogOptions } from './logger'; import type { AstroRuntime, LoadResult } from './runtime'; @@ -15,7 +16,7 @@ import { generateRSS } from './build/rss.js'; import { generateSitemap } from './build/sitemap.js'; import { collectStatics } from './build/static.js'; import { canonicalURL } from './build/util.js'; - +import { pathToFileURL } from 'node:url'; const { mkdir, readFile, writeFile } = fsPromises; @@ -65,12 +66,19 @@ async function writeFilep(outPath: URL, bytes: string | Buffer, encoding: 'utf8' await writeFile(outPath, bytes, encoding || 'binary'); } +interface WriteResultOptions { + srcPath: string; + result: LoadResult; + outPath: URL, + encoding: null|'utf8' +} + /** Utility for writing a build result to disk */ -async function writeResult(result: LoadResult, outPath: URL, encoding: null | 'utf8') { +async function writeResult({ srcPath, result, outPath, encoding }: WriteResultOptions) { if (result.statusCode === 500 || result.statusCode === 404) { - error(logging, 'build', result.error || result.statusCode); + error(logging, 'build', ` Failed to build ${srcPath}\n${' '.repeat(9)}`, result.error?.message ?? `Unexpected load result (${result.statusCode})`); } else if (result.statusCode !== 200) { - error(logging, 'build', `Unexpected load result (${result.statusCode}) for ${fileURLToPath(outPath)}`); + error(logging, 'build', ` Failed to build ${srcPath}\n${' '.repeat(9)}`, `Unexpected load result (${result.statusCode}) for ${fileURLToPath(outPath)}`); } else { const bytes = result.contents; await writeFilep(outPath, bytes, encoding); @@ -87,6 +95,7 @@ function getPageType(filepath: URL): 'collection' | 'static' { async function buildCollectionPage({ astroRoot, dist, filepath, runtime, site, statics }: PageBuildOptions): Promise<PageResult> { const rel = path.relative(fileURLToPath(astroRoot) + '/pages', fileURLToPath(filepath)); // pages/index.astro const pagePath = `/${rel.replace(/\$([^.]+)\.astro$/, '$1')}`; + const srcPath = fileURLToPath(new URL('pages/' + rel, astroRoot)); const builtURLs = new Set<string>(); // !important: internal cache that prevents building the same URLs /** Recursively build collection URLs */ @@ -96,7 +105,7 @@ async function buildCollectionPage({ astroRoot, dist, filepath, runtime, site, s builtURLs.add(url); if (result.statusCode === 200) { const outPath = new URL('./' + url + '/index.html', dist); - await writeResult(result, outPath, 'utf8'); + await writeResult({ srcPath, result, outPath, encoding: 'utf8' }); mergeSet(statics, collectStatics(result.contents.toString('utf8'))); } return result; @@ -152,10 +161,11 @@ async function buildStaticPage({ astroRoot, dist, filepath, runtime, sitemap, st relPath = relPath.replace(/\.html$/, '/index.html'); } + const srcPath = fileURLToPath(new URL('pages/' + rel, astroRoot)); const outPath = new URL(relPath, dist); const result = await runtime.load(pagePath); - await writeResult(result, outPath, 'utf8'); + await writeResult({ srcPath, result, outPath, encoding: 'utf8' }); if (result.statusCode === 200) { mergeSet(statics, collectStatics(result.contents.toString('utf8'))); @@ -199,9 +209,8 @@ export async function build(astroConfig: AstroConfig): Promise<0 | 1> { const pages = await allPages(pageRoot); let builtURLs: string[] = []; - try { - info(logging , 'build', yellow('! building pages...')); + info(logging, 'build', yellow('! building pages...')); // Vue also console.warns, this silences it. const release = trapWarn(); await Promise.all( @@ -258,7 +267,7 @@ export async function build(astroConfig: AstroConfig): Promise<0 | 1> { const outPath = new URL('.' + url, dist); const result = await runtime.load(url); - await writeResult(result, outPath, null); + await writeResult({ srcPath: url, result, outPath, encoding: null }); } if (existsSync(astroConfig.public)) { @@ -275,7 +284,7 @@ export async function build(astroConfig: AstroConfig): Promise<0 | 1> { } info(logging, 'build', green('✔'), 'public folder copied.'); } else { - if(path.basename(astroConfig.public.toString()) !=='public'){ + if (path.basename(astroConfig.public.toString()) !== 'public') { info(logging, 'tip', yellow(`! no public folder ${astroConfig.public} found...`)); } } diff --git a/packages/astro/src/cli.ts b/packages/astro/src/cli.ts index be0dfe27a..b028d754c 100644 --- a/packages/astro/src/cli.ts +++ b/packages/astro/src/cli.ts @@ -1,3 +1,4 @@ +import 'source-map-support/register.js'; /* eslint-disable no-console */ import type { AstroConfig } from './@types/astro'; diff --git a/packages/astro/src/compiler/index.ts b/packages/astro/src/compiler/index.ts index bb8ac61d4..6a9e8dbe6 100644 --- a/packages/astro/src/compiler/index.ts +++ b/packages/astro/src/compiler/index.ts @@ -1,3 +1,4 @@ +import 'source-map-support/register.js'; import type { CompileResult, TransformResult } from '../@types/astro'; import type { CompileOptions } from '../@types/compiler.js'; @@ -14,6 +15,8 @@ import { encodeAstroMdx } from './markdown/micromark-mdx-astro.js'; import { transform } from './transform/index.js'; import { codegen } from './codegen/index.js'; +export { scopeRule } from './transform/postcss-scoped-styles/index.js' + /** Return Astro internal import URL */ function internalImport(internalPath: string) { return `/_astro_internal/${internalPath}`; diff --git a/packages/astro/src/config.ts b/packages/astro/src/config.ts index 8f3ebaf5a..cf4b5b229 100644 --- a/packages/astro/src/config.ts +++ b/packages/astro/src/config.ts @@ -1,3 +1,4 @@ +import 'source-map-support/register.js'; import type { AstroConfig } from './@types/astro'; import { join as pathJoin, resolve as pathResolve } from 'path'; import { existsSync } from 'fs'; diff --git a/packages/astro/src/dev.ts b/packages/astro/src/dev.ts index 4ca8e28e9..2522ab645 100644 --- a/packages/astro/src/dev.ts +++ b/packages/astro/src/dev.ts @@ -1,3 +1,4 @@ +import 'source-map-support/register.js'; import type { AstroConfig } from './@types/astro'; import type { LogOptions } from './logger.js'; diff --git a/packages/astro/src/frontend/SvelteWrapper.svelte.client.ts b/packages/astro/src/frontend/SvelteWrapper.svelte.client.ts deleted file mode 100644 index 9df168895..000000000 --- a/packages/astro/src/frontend/SvelteWrapper.svelte.client.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* eslint-disable */ -// @ts-nocheck -// TODO: don't precompile this, but it works for now -import { - HtmlTag, - SvelteComponentDev, - assign, - claim_component, - create_component, - destroy_component, - detach_dev, - dispatch_dev, - empty, - exclude_internal_props, - get_spread_object, - get_spread_update, - init, - insert_dev, - mount_component, - noop, - not_equal, - transition_in, - transition_out, - validate_slots, -} from 'svelte/internal'; - -const file = 'App.svelte'; - -// (5:0) <Component {...props}> -function create_default_slot(ctx) { - let html_tag; - let html_anchor; - - const block = { - c: function create() { - html_anchor = empty(); - this.h(); - }, - l: function claim(nodes) { - html_anchor = empty(); - this.h(); - }, - h: function hydrate() { - html_tag = new HtmlTag(html_anchor); - }, - m: function mount(target, anchor) { - html_tag.m(/*__astro_children*/ ctx[1], target, anchor); - insert_dev(target, html_anchor, anchor); - }, - p: noop, - d: function destroy(detaching) { - if (detaching) detach_dev(html_anchor); - if (detaching) html_tag.d(); - }, - }; - - dispatch_dev('SvelteRegisterBlock', { - block, - id: create_default_slot.name, - type: 'slot', - source: '(5:0) <Component {...props}>', - ctx, - }); - - return block; -} - -function create_fragment(ctx) { - let component; - let current; - const component_spread_levels = [/*props*/ ctx[2]]; - - let component_props = { - $$slots: { default: [create_default_slot] }, - $$scope: { ctx }, - }; - - for (let i = 0; i < component_spread_levels.length; i += 1) { - component_props = assign(component_props, component_spread_levels[i]); - } - - component = new /*Component*/ ctx[0]({ props: component_props, $$inline: true }); - - const block = { - c: function create() { - create_component(component.$$.fragment); - }, - l: function claim(nodes) { - claim_component(component.$$.fragment, nodes); - }, - m: function mount(target, anchor) { - mount_component(component, target, anchor); - current = true; - }, - p: function update(ctx, [dirty]) { - const component_changes = dirty & /*props*/ 4 ? get_spread_update(component_spread_levels, [get_spread_object(/*props*/ ctx[2])]) : {}; - - if (dirty & /*$$scope*/ 16) { - component_changes.$$scope = { dirty, ctx }; - } - - component.$set(component_changes); - }, - i: function intro(local) { - if (current) return; - transition_in(component.$$.fragment, local); - current = true; - }, - o: function outro(local) { - transition_out(component.$$.fragment, local); - current = false; - }, - d: function destroy(detaching) { - destroy_component(component, detaching); - }, - }; - - dispatch_dev('SvelteRegisterBlock', { - block, - id: create_fragment.name, - type: 'component', - source: '', - ctx, - }); - - return block; -} - -function instance($$self, $$props, $$invalidate) { - let { $$slots: slots = {}, $$scope } = $$props; - validate_slots('App', slots, []); - const { __astro_component: Component, __astro_children, ...props } = $$props; - - $$self.$$set = ($$new_props) => { - $$invalidate(3, ($$props = assign(assign({}, $$props), exclude_internal_props($$new_props)))); - }; - - $$self.$capture_state = () => ({ Component, __astro_children, props }); - - $$self.$inject_state = ($$new_props) => { - $$invalidate(3, ($$props = assign(assign({}, $$props), $$new_props))); - }; - - if ($$props && '$$inject' in $$props) { - $$self.$inject_state($$props.$$inject); - } - - $$props = exclude_internal_props($$props); - return [Component, __astro_children, props]; -} - -class App extends SvelteComponentDev { - constructor(options) { - super(options); - init(this, options, instance, create_fragment, not_equal, {}); - - dispatch_dev('SvelteRegisterComponent', { - component: this, - tagName: 'App', - options, - id: create_fragment.name, - }); - } -} - -export default App; diff --git a/packages/astro/src/frontend/SvelteWrapper.svelte.server.ts b/packages/astro/src/frontend/SvelteWrapper.svelte.server.ts deleted file mode 100644 index c5a25ff03..000000000 --- a/packages/astro/src/frontend/SvelteWrapper.svelte.server.ts +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-disable */ -// @ts-nocheck -// TODO: don't precompile this, but it works for now -/* App.svelte generated by Svelte v3.37.0 */ -import { create_ssr_component, validate_component } from 'svelte/internal'; - -const App = create_ssr_component(($$result, $$props, $$bindings, slots) => { - const { __astro_component: Component, __astro_children, ...props } = $$props; - return `${validate_component(Component, 'Component').$$render($$result, Object.assign(props), {}, { default: () => `${__astro_children}` })}`; -}); - -export default App; diff --git a/packages/astro/src/frontend/render/svelte.ts b/packages/astro/src/frontend/render/svelte.ts index 13e2b8f58..69c7ac8b4 100644 --- a/packages/astro/src/frontend/render/svelte.ts +++ b/packages/astro/src/frontend/render/svelte.ts @@ -1,11 +1,12 @@ import type { ComponentRenderer } from '../../@types/renderer'; import type { SvelteComponent } from 'svelte'; import { createRenderer } from './renderer'; -import SvelteWrapper from '../SvelteWrapper.svelte.server'; +import SvelteWrapper from '../SvelteWrapper.server.svelte'; const SvelteRenderer: ComponentRenderer<SvelteComponent> = { renderStatic(Component) { return async (props, ...children) => { + /// @ts-expect-error const { html } = SvelteWrapper.render({ __astro_component: Component, __astro_children: children.join('\n'), ...props }); return html; }; diff --git a/packages/astro/src/frontend/runtime/svelte.ts b/packages/astro/src/frontend/runtime/svelte.ts index 78b6af6b6..7a41586b4 100644 --- a/packages/astro/src/frontend/runtime/svelte.ts +++ b/packages/astro/src/frontend/runtime/svelte.ts @@ -1,4 +1,4 @@ -import SvelteWrapper from '../SvelteWrapper.svelte.client'; +import SvelteWrapper from '../SvelteWrapper.client.svelte'; import type { SvelteComponent } from 'svelte'; export default (target: Element, component: SvelteComponent, props: any, children: string) => { diff --git a/packages/astro/src/logger.ts b/packages/astro/src/logger.ts index c42c889f1..f700e91e1 100644 --- a/packages/astro/src/logger.ts +++ b/packages/astro/src/logger.ts @@ -1,3 +1,4 @@ +import 'source-map-support/register.js'; import type { CompileError } from 'astro-parser'; import { bold, blue, red, grey, underline } from 'kleur/colors'; import { Writable } from 'stream'; diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index 5369996f4..d08c0f387 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -1,3 +1,4 @@ +import 'source-map-support/register.js'; import { fileURLToPath } from 'url'; import type { SnowpackDevServer, ServerRuntime as SnowpackServerRuntime, SnowpackConfig } from 'snowpack'; import type { AstroConfig, CollectionResult, CollectionRSS, CreateCollection, Params, RuntimeMode } from './@types/astro'; diff --git a/packages/astro/src/search.ts b/packages/astro/src/search.ts index c141e4a77..f097751b1 100644 --- a/packages/astro/src/search.ts +++ b/packages/astro/src/search.ts @@ -1,3 +1,4 @@ +import 'source-map-support/register.js'; import { existsSync } from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; |