[ci] format
This commit is contained in:
parent
f76038ac7d
commit
f7335c76a7
7 changed files with 178 additions and 111 deletions
|
@ -44,4 +44,3 @@ export async function update(subcommand: string, { flags, telemetry }: Telemetry
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ ${extra}`
|
|||
_metadata: {
|
||||
renderers,
|
||||
pathname,
|
||||
needsHydrationStyles: false
|
||||
needsHydrationStyles: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -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)}))}});`;
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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(
|
||||
|
@ -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,
|
||||
|
|
|
@ -17,32 +17,45 @@ describe('Session event', () => {
|
|||
a: 'b',
|
||||
},
|
||||
publicDir: 'some/dir',
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const [{ payload }] = events.eventCliSession({
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0'
|
||||
}, config);
|
||||
expect(payload.config.viteKeys).is.deep.equal(['css', 'css.modules', 'base', 'mode', 'define', 'publicDir']);
|
||||
})
|
||||
const [{ payload }] = events.eventCliSession(
|
||||
{
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0',
|
||||
},
|
||||
config
|
||||
);
|
||||
expect(payload.config.viteKeys).is.deep.equal([
|
||||
'css',
|
||||
'css.modules',
|
||||
'base',
|
||||
'mode',
|
||||
'define',
|
||||
'publicDir',
|
||||
]);
|
||||
});
|
||||
|
||||
it('vite.resolve keys are captured', async () => {
|
||||
const config = await mockConfig({
|
||||
vite: {
|
||||
resolve: {
|
||||
alias: {
|
||||
a: 'b'
|
||||
a: 'b',
|
||||
},
|
||||
dedupe: ['one', 'two']
|
||||
}
|
||||
}
|
||||
dedupe: ['one', 'two'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [{ payload }] = events.eventCliSession({
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0'
|
||||
}, config);
|
||||
const [{ payload }] = events.eventCliSession(
|
||||
{
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0',
|
||||
},
|
||||
config
|
||||
);
|
||||
expect(payload.config.viteKeys).is.deep.equal(['resolve', 'resolve.alias', 'resolve.dedupe']);
|
||||
});
|
||||
|
||||
|
@ -50,20 +63,29 @@ describe('Session event', () => {
|
|||
const config = await mockConfig({
|
||||
vite: {
|
||||
resolve: {
|
||||
dedupe: ['one', 'two']
|
||||
dedupe: ['one', 'two'],
|
||||
},
|
||||
css: {
|
||||
modules: [],
|
||||
postcss: {}
|
||||
}
|
||||
}
|
||||
postcss: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [{ payload }] = events.eventCliSession({
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0'
|
||||
}, config);
|
||||
expect(payload.config.viteKeys).is.deep.equal(['resolve', 'resolve.dedupe', 'css', 'css.modules', 'css.postcss']);
|
||||
const [{ payload }] = events.eventCliSession(
|
||||
{
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0',
|
||||
},
|
||||
config
|
||||
);
|
||||
expect(payload.config.viteKeys).is.deep.equal([
|
||||
'resolve',
|
||||
'resolve.dedupe',
|
||||
'css',
|
||||
'css.modules',
|
||||
'css.postcss',
|
||||
]);
|
||||
});
|
||||
|
||||
it('vite.server keys are captured', async () => {
|
||||
|
@ -74,17 +96,27 @@ describe('Session event', () => {
|
|||
open: true,
|
||||
fs: {
|
||||
strict: true,
|
||||
allow: ['a', 'b']
|
||||
}
|
||||
}
|
||||
}
|
||||
allow: ['a', 'b'],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [{ payload }] = events.eventCliSession({
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0'
|
||||
}, config);
|
||||
expect(payload.config.viteKeys).is.deep.equal(['server', 'server.host', 'server.open', 'server.fs', 'server.fs.strict', 'server.fs.allow']);
|
||||
const [{ payload }] = events.eventCliSession(
|
||||
{
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0',
|
||||
},
|
||||
config
|
||||
);
|
||||
expect(payload.config.viteKeys).is.deep.equal([
|
||||
'server',
|
||||
'server.host',
|
||||
'server.open',
|
||||
'server.fs',
|
||||
'server.fs.strict',
|
||||
'server.fs.allow',
|
||||
]);
|
||||
});
|
||||
|
||||
it('vite.build keys are captured', async () => {
|
||||
|
@ -94,20 +126,27 @@ describe('Session event', () => {
|
|||
target: 'one',
|
||||
outDir: 'some/dir',
|
||||
cssTarget: {
|
||||
one: 'two'
|
||||
}
|
||||
}
|
||||
}
|
||||
one: 'two',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [{ payload }] = events.eventCliSession({
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0'
|
||||
}, config);
|
||||
expect(payload.config.viteKeys).is.deep.equal(['build', 'build.target', 'build.outDir', 'build.cssTarget']);
|
||||
const [{ payload }] = events.eventCliSession(
|
||||
{
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0',
|
||||
},
|
||||
config
|
||||
);
|
||||
expect(payload.config.viteKeys).is.deep.equal([
|
||||
'build',
|
||||
'build.target',
|
||||
'build.outDir',
|
||||
'build.cssTarget',
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
it('vite.preview keys are captured', async () => {
|
||||
const config = await mockConfig({
|
||||
vite: {
|
||||
|
@ -115,17 +154,25 @@ describe('Session event', () => {
|
|||
host: 'example.com',
|
||||
port: 8080,
|
||||
another: {
|
||||
a: 'b'
|
||||
}
|
||||
}
|
||||
}
|
||||
a: 'b',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [{ payload }] = events.eventCliSession({
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0'
|
||||
}, config);
|
||||
expect(payload.config.viteKeys).is.deep.equal(['preview', 'preview.host', 'preview.port', 'preview.another']);
|
||||
const [{ payload }] = events.eventCliSession(
|
||||
{
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0',
|
||||
},
|
||||
config
|
||||
);
|
||||
expect(payload.config.viteKeys).is.deep.equal([
|
||||
'preview',
|
||||
'preview.host',
|
||||
'preview.port',
|
||||
'preview.another',
|
||||
]);
|
||||
});
|
||||
|
||||
it('vite.optimizeDeps keys are captured', async () => {
|
||||
|
@ -133,16 +180,23 @@ describe('Session event', () => {
|
|||
vite: {
|
||||
optimizeDeps: {
|
||||
entries: ['one', 'two'],
|
||||
exclude: ['secret', 'name']
|
||||
}
|
||||
}
|
||||
exclude: ['secret', 'name'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [{ payload }] = events.eventCliSession({
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0'
|
||||
}, config);
|
||||
expect(payload.config.viteKeys).is.deep.equal(['optimizeDeps', 'optimizeDeps.entries', 'optimizeDeps.exclude']);
|
||||
const [{ payload }] = events.eventCliSession(
|
||||
{
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0',
|
||||
},
|
||||
config
|
||||
);
|
||||
expect(payload.config.viteKeys).is.deep.equal([
|
||||
'optimizeDeps',
|
||||
'optimizeDeps.entries',
|
||||
'optimizeDeps.exclude',
|
||||
]);
|
||||
});
|
||||
|
||||
it('vite.ssr keys are captured', async () => {
|
||||
|
@ -150,15 +204,18 @@ describe('Session event', () => {
|
|||
vite: {
|
||||
ssr: {
|
||||
external: ['a'],
|
||||
target: { one: 'two' }
|
||||
}
|
||||
}
|
||||
target: { one: 'two' },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [{ payload }] = events.eventCliSession({
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0'
|
||||
}, config);
|
||||
const [{ payload }] = events.eventCliSession(
|
||||
{
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0',
|
||||
},
|
||||
config
|
||||
);
|
||||
expect(payload.config.viteKeys).is.deep.equal(['ssr', 'ssr.external', 'ssr.target']);
|
||||
});
|
||||
|
||||
|
@ -167,15 +224,18 @@ describe('Session event', () => {
|
|||
vite: {
|
||||
worker: {
|
||||
format: { a: 'b' },
|
||||
plugins: ['a', 'b']
|
||||
}
|
||||
}
|
||||
plugins: ['a', 'b'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [{ payload }] = events.eventCliSession({
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0'
|
||||
}, config);
|
||||
const [{ payload }] = events.eventCliSession(
|
||||
{
|
||||
cliCommand: 'dev',
|
||||
astroVersion: '0.0.0',
|
||||
},
|
||||
config
|
||||
);
|
||||
expect(payload.config.viteKeys).is.deep.equal(['worker', 'worker.format', 'worker.plugins']);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue