Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and github-actions[bot] committed May 3, 2022
1 parent f76038a commit f7335c7
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 111 deletions.
1 change: 0 additions & 1 deletion packages/astro/src/cli/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ export async function update(subcommand: string, { flags, telemetry }: Telemetry
}
}
}

2 changes: 1 addition & 1 deletion packages/astro/src/core/render/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ ${extra}`
_metadata: {
renderers,
pathname,
needsHydrationStyles: false
needsHydrationStyles: false,
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/astro-island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ customElements.define('astro-island', class extends HTMLElement {
* This is a minified version of the above. If you modify the above you need to
* copy/paste it into a .js file and then run:
* > node_modules/.bin/terser --mangle --compress -- file.js
*
*
* And copy/paste the result below
*/
export const islandScript = `customElements.define("astro-island",class extends HTMLElement{async connectedCallback(){const[{default:t}]=await Promise.all([import(this.getAttribute("directive-url")),import(this.getAttribute("before-hydration-url"))]);const e=JSON.parse(this.getAttribute("opts"));t(this,e,(async()=>{const t=this.getAttribute("props");const e=t?JSON.parse(t):{};const r=this.getAttribute("renderer-url");const[{default:s},{default:i}]=await Promise.all([import(this.getAttribute("component-url")),r?import(r):()=>()=>{}]);return(t,r)=>i(t)(s,e,r)}))}});`;
17 changes: 9 additions & 8 deletions packages/astro/src/runtime/server/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { hydrationSpecifier, serializeListValue } from './util.js';
import { escapeHTML } from './escape.js';
import serializeJavaScript from 'serialize-javascript';


// Serializes props passed into a component so that they can be reused during hydration.
// The value is any
export function serializeProps(value: any) {
Expand Down Expand Up @@ -116,25 +115,27 @@ export async function generateHydrateScript(
children: '',
props: {
// This is for HMR, probably can avoid it in prod
uid: astroId
}
uid: astroId,
},
};

// Add component url
island.props['component-url'] = await result.resolve(componentUrl);

// Add renderer url
if(renderer.clientEntrypoint) {
if (renderer.clientEntrypoint) {
island.props['renderer-url'] = await result.resolve(renderer.clientEntrypoint);
island.props['props'] = escapeHTML(serializeProps(props));
}

island.props['directive-url'] = await result.resolve(hydrationSpecifier(hydrate));
island.props['before-hydration-url'] = await result.resolve('astro:scripts/before-hydration.js');
island.props['opts'] = escapeHTML(JSON.stringify({
name: metadata.displayName,
value: metadata.hydrateArgs || ''
}))
island.props['opts'] = escapeHTML(
JSON.stringify({
name: metadata.displayName,
value: metadata.hydrateArgs || '',
})
);

return island;
}
13 changes: 4 additions & 9 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,27 +321,22 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
const needsAstroTemplate = children && !/<\/?astro-fragment\>/.test(html);
const template = needsAstroTemplate ? `<template data-astro-template>${children}</template>` : '';

if(needsAstroTemplate) {
if (needsAstroTemplate) {
island.props.tmpl = '';
}

island.children = `${
html ?? ''
}${template}`;
island.children = `${html ?? ''}${template}`;

// Add the astro-island definition only once. Since the SSRResult object
// is scoped to a page renderer we can use it as a key to know if the script
// has been rendered or not.
let script = '';
if(!resultsWithHydrationScript.has(result)) {
if (!resultsWithHydrationScript.has(result)) {
resultsWithHydrationScript.add(result);
script = `<script>${islandScript}</script>`;
}

return markHTMLString(
script +
renderElement('astro-island', island, false)
);
return markHTMLString(script + renderElement('astro-island', island, false));
}

/** Create the Astro.fetchContent() runtime function. */
Expand Down
46 changes: 29 additions & 17 deletions packages/telemetry/src/events/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,37 @@ function getExperimentalFeatures(astroConfig?: Record<string, any>): string[] |
}, [] as string[]);
}

const secondLevelViteKeys = new Set(["resolve", "css", "json", "server", "server.fs", "build", "preview", "optimizeDeps", "ssr", "worker"]);
const secondLevelViteKeys = new Set([
'resolve',
'css',
'json',
'server',
'server.fs',
'build',
'preview',
'optimizeDeps',
'ssr',
'worker',
]);
function viteConfigKeys(obj: Record<string, any> | undefined, parentKey: string): string[] {
if(!obj) {
if (!obj) {
return [];
}

return Object.entries(obj).map(([key, value]) => {
if(typeof value === 'object' && !Array.isArray(value)) {
const localKey = parentKey ? parentKey + '.' + key : key;
if(secondLevelViteKeys.has(localKey)) {
let keys = viteConfigKeys(value, localKey).map(subkey => key + '.' + subkey);
keys.unshift(key);
return keys;
return Object.entries(obj)
.map(([key, value]) => {
if (typeof value === 'object' && !Array.isArray(value)) {
const localKey = parentKey ? parentKey + '.' + key : key;
if (secondLevelViteKeys.has(localKey)) {
let keys = viteConfigKeys(value, localKey).map((subkey) => key + '.' + subkey);
keys.unshift(key);
return keys;
}
}
}

return key;
}).flat(1);
return key;
})
.flat(1);
}

export function eventCliSession(
Expand All @@ -79,11 +92,10 @@ export function eventCliSession(
config: astroConfig
? {
hasViteConfig: Object.keys(astroConfig?.vite).length > 0,
markdownPlugins:
[
astroConfig?.markdown?.remarkPlugins ?? [],
astroConfig?.markdown?.rehypePlugins ?? [],
].flat(1),
markdownPlugins: [
astroConfig?.markdown?.remarkPlugins ?? [],
astroConfig?.markdown?.rehypePlugins ?? [],
].flat(1),
hasBase: astroConfig?.base !== '/',
viteKeys: viteConfigKeys(astroConfig?.vite, ''),
adapter: astroConfig?.adapter?.name ?? null,
Expand Down
Loading

0 comments on commit f7335c7

Please sign in to comment.