[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: {
|
_metadata: {
|
||||||
renderers,
|
renderers,
|
||||||
pathname,
|
pathname,
|
||||||
needsHydrationStyles: false
|
needsHydrationStyles: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { hydrationSpecifier, serializeListValue } from './util.js';
|
||||||
import { escapeHTML } from './escape.js';
|
import { escapeHTML } from './escape.js';
|
||||||
import serializeJavaScript from 'serialize-javascript';
|
import serializeJavaScript from 'serialize-javascript';
|
||||||
|
|
||||||
|
|
||||||
// Serializes props passed into a component so that they can be reused during hydration.
|
// Serializes props passed into a component so that they can be reused during hydration.
|
||||||
// The value is any
|
// The value is any
|
||||||
export function serializeProps(value: any) {
|
export function serializeProps(value: any) {
|
||||||
|
@ -116,25 +115,27 @@ export async function generateHydrateScript(
|
||||||
children: '',
|
children: '',
|
||||||
props: {
|
props: {
|
||||||
// This is for HMR, probably can avoid it in prod
|
// This is for HMR, probably can avoid it in prod
|
||||||
uid: astroId
|
uid: astroId,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add component url
|
// Add component url
|
||||||
island.props['component-url'] = await result.resolve(componentUrl);
|
island.props['component-url'] = await result.resolve(componentUrl);
|
||||||
|
|
||||||
// Add renderer url
|
// Add renderer url
|
||||||
if(renderer.clientEntrypoint) {
|
if (renderer.clientEntrypoint) {
|
||||||
island.props['renderer-url'] = await result.resolve(renderer.clientEntrypoint);
|
island.props['renderer-url'] = await result.resolve(renderer.clientEntrypoint);
|
||||||
island.props['props'] = escapeHTML(serializeProps(props));
|
island.props['props'] = escapeHTML(serializeProps(props));
|
||||||
}
|
}
|
||||||
|
|
||||||
island.props['directive-url'] = await result.resolve(hydrationSpecifier(hydrate));
|
island.props['directive-url'] = await result.resolve(hydrationSpecifier(hydrate));
|
||||||
island.props['before-hydration-url'] = await result.resolve('astro:scripts/before-hydration.js');
|
island.props['before-hydration-url'] = await result.resolve('astro:scripts/before-hydration.js');
|
||||||
island.props['opts'] = escapeHTML(JSON.stringify({
|
island.props['opts'] = escapeHTML(
|
||||||
name: metadata.displayName,
|
JSON.stringify({
|
||||||
value: metadata.hydrateArgs || ''
|
name: metadata.displayName,
|
||||||
}))
|
value: metadata.hydrateArgs || '',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return island;
|
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 needsAstroTemplate = children && !/<\/?astro-fragment\>/.test(html);
|
||||||
const template = needsAstroTemplate ? `<template data-astro-template>${children}</template>` : '';
|
const template = needsAstroTemplate ? `<template data-astro-template>${children}</template>` : '';
|
||||||
|
|
||||||
if(needsAstroTemplate) {
|
if (needsAstroTemplate) {
|
||||||
island.props.tmpl = '';
|
island.props.tmpl = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
island.children = `${
|
island.children = `${html ?? ''}${template}`;
|
||||||
html ?? ''
|
|
||||||
}${template}`;
|
|
||||||
|
|
||||||
// Add the astro-island definition only once. Since the SSRResult object
|
// 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
|
// is scoped to a page renderer we can use it as a key to know if the script
|
||||||
// has been rendered or not.
|
// has been rendered or not.
|
||||||
let script = '';
|
let script = '';
|
||||||
if(!resultsWithHydrationScript.has(result)) {
|
if (!resultsWithHydrationScript.has(result)) {
|
||||||
resultsWithHydrationScript.add(result);
|
resultsWithHydrationScript.add(result);
|
||||||
script = `<script>${islandScript}</script>`;
|
script = `<script>${islandScript}</script>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return markHTMLString(
|
return markHTMLString(script + renderElement('astro-island', island, false));
|
||||||
script +
|
|
||||||
renderElement('astro-island', island, false)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create the Astro.fetchContent() runtime function. */
|
/** Create the Astro.fetchContent() runtime function. */
|
||||||
|
|
|
@ -45,24 +45,37 @@ function getExperimentalFeatures(astroConfig?: Record<string, any>): string[] |
|
||||||
}, [] as 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[] {
|
function viteConfigKeys(obj: Record<string, any> | undefined, parentKey: string): string[] {
|
||||||
if(!obj) {
|
if (!obj) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.entries(obj).map(([key, value]) => {
|
return Object.entries(obj)
|
||||||
if(typeof value === 'object' && !Array.isArray(value)) {
|
.map(([key, value]) => {
|
||||||
const localKey = parentKey ? parentKey + '.' + key : key;
|
if (typeof value === 'object' && !Array.isArray(value)) {
|
||||||
if(secondLevelViteKeys.has(localKey)) {
|
const localKey = parentKey ? parentKey + '.' + key : key;
|
||||||
let keys = viteConfigKeys(value, localKey).map(subkey => key + '.' + subkey);
|
if (secondLevelViteKeys.has(localKey)) {
|
||||||
keys.unshift(key);
|
let keys = viteConfigKeys(value, localKey).map((subkey) => key + '.' + subkey);
|
||||||
return keys;
|
keys.unshift(key);
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}).flat(1);
|
})
|
||||||
|
.flat(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function eventCliSession(
|
export function eventCliSession(
|
||||||
|
@ -79,11 +92,10 @@ export function eventCliSession(
|
||||||
config: astroConfig
|
config: astroConfig
|
||||||
? {
|
? {
|
||||||
hasViteConfig: Object.keys(astroConfig?.vite).length > 0,
|
hasViteConfig: Object.keys(astroConfig?.vite).length > 0,
|
||||||
markdownPlugins:
|
markdownPlugins: [
|
||||||
[
|
astroConfig?.markdown?.remarkPlugins ?? [],
|
||||||
astroConfig?.markdown?.remarkPlugins ?? [],
|
astroConfig?.markdown?.rehypePlugins ?? [],
|
||||||
astroConfig?.markdown?.rehypePlugins ?? [],
|
].flat(1),
|
||||||
].flat(1),
|
|
||||||
hasBase: astroConfig?.base !== '/',
|
hasBase: astroConfig?.base !== '/',
|
||||||
viteKeys: viteConfigKeys(astroConfig?.vite, ''),
|
viteKeys: viteConfigKeys(astroConfig?.vite, ''),
|
||||||
adapter: astroConfig?.adapter?.name ?? null,
|
adapter: astroConfig?.adapter?.name ?? null,
|
||||||
|
|
|
@ -17,32 +17,45 @@ describe('Session event', () => {
|
||||||
a: 'b',
|
a: 'b',
|
||||||
},
|
},
|
||||||
publicDir: 'some/dir',
|
publicDir: 'some/dir',
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [{ payload }] = events.eventCliSession({
|
const [{ payload }] = events.eventCliSession(
|
||||||
cliCommand: 'dev',
|
{
|
||||||
astroVersion: '0.0.0'
|
cliCommand: 'dev',
|
||||||
}, config);
|
astroVersion: '0.0.0',
|
||||||
expect(payload.config.viteKeys).is.deep.equal(['css', 'css.modules', 'base', 'mode', 'define', 'publicDir']);
|
},
|
||||||
})
|
config
|
||||||
|
);
|
||||||
|
expect(payload.config.viteKeys).is.deep.equal([
|
||||||
|
'css',
|
||||||
|
'css.modules',
|
||||||
|
'base',
|
||||||
|
'mode',
|
||||||
|
'define',
|
||||||
|
'publicDir',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('vite.resolve keys are captured', async () => {
|
it('vite.resolve keys are captured', async () => {
|
||||||
const config = await mockConfig({
|
const config = await mockConfig({
|
||||||
vite: {
|
vite: {
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
a: 'b'
|
a: 'b',
|
||||||
},
|
},
|
||||||
dedupe: ['one', 'two']
|
dedupe: ['one', 'two'],
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [{ payload }] = events.eventCliSession({
|
const [{ payload }] = events.eventCliSession(
|
||||||
cliCommand: 'dev',
|
{
|
||||||
astroVersion: '0.0.0'
|
cliCommand: 'dev',
|
||||||
}, config);
|
astroVersion: '0.0.0',
|
||||||
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
expect(payload.config.viteKeys).is.deep.equal(['resolve', 'resolve.alias', 'resolve.dedupe']);
|
expect(payload.config.viteKeys).is.deep.equal(['resolve', 'resolve.alias', 'resolve.dedupe']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -50,20 +63,29 @@ describe('Session event', () => {
|
||||||
const config = await mockConfig({
|
const config = await mockConfig({
|
||||||
vite: {
|
vite: {
|
||||||
resolve: {
|
resolve: {
|
||||||
dedupe: ['one', 'two']
|
dedupe: ['one', 'two'],
|
||||||
},
|
},
|
||||||
css: {
|
css: {
|
||||||
modules: [],
|
modules: [],
|
||||||
postcss: {}
|
postcss: {},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [{ payload }] = events.eventCliSession({
|
const [{ payload }] = events.eventCliSession(
|
||||||
cliCommand: 'dev',
|
{
|
||||||
astroVersion: '0.0.0'
|
cliCommand: 'dev',
|
||||||
}, config);
|
astroVersion: '0.0.0',
|
||||||
expect(payload.config.viteKeys).is.deep.equal(['resolve', 'resolve.dedupe', 'css', 'css.modules', 'css.postcss']);
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
|
expect(payload.config.viteKeys).is.deep.equal([
|
||||||
|
'resolve',
|
||||||
|
'resolve.dedupe',
|
||||||
|
'css',
|
||||||
|
'css.modules',
|
||||||
|
'css.postcss',
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('vite.server keys are captured', async () => {
|
it('vite.server keys are captured', async () => {
|
||||||
|
@ -74,17 +96,27 @@ describe('Session event', () => {
|
||||||
open: true,
|
open: true,
|
||||||
fs: {
|
fs: {
|
||||||
strict: true,
|
strict: true,
|
||||||
allow: ['a', 'b']
|
allow: ['a', 'b'],
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [{ payload }] = events.eventCliSession({
|
const [{ payload }] = events.eventCliSession(
|
||||||
cliCommand: 'dev',
|
{
|
||||||
astroVersion: '0.0.0'
|
cliCommand: 'dev',
|
||||||
}, config);
|
astroVersion: '0.0.0',
|
||||||
expect(payload.config.viteKeys).is.deep.equal(['server', 'server.host', 'server.open', 'server.fs', 'server.fs.strict', 'server.fs.allow']);
|
},
|
||||||
|
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 () => {
|
it('vite.build keys are captured', async () => {
|
||||||
|
@ -94,20 +126,27 @@ describe('Session event', () => {
|
||||||
target: 'one',
|
target: 'one',
|
||||||
outDir: 'some/dir',
|
outDir: 'some/dir',
|
||||||
cssTarget: {
|
cssTarget: {
|
||||||
one: 'two'
|
one: 'two',
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [{ payload }] = events.eventCliSession({
|
const [{ payload }] = events.eventCliSession(
|
||||||
cliCommand: 'dev',
|
{
|
||||||
astroVersion: '0.0.0'
|
cliCommand: 'dev',
|
||||||
}, config);
|
astroVersion: '0.0.0',
|
||||||
expect(payload.config.viteKeys).is.deep.equal(['build', 'build.target', 'build.outDir', 'build.cssTarget']);
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
|
expect(payload.config.viteKeys).is.deep.equal([
|
||||||
|
'build',
|
||||||
|
'build.target',
|
||||||
|
'build.outDir',
|
||||||
|
'build.cssTarget',
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('vite.preview keys are captured', async () => {
|
it('vite.preview keys are captured', async () => {
|
||||||
const config = await mockConfig({
|
const config = await mockConfig({
|
||||||
vite: {
|
vite: {
|
||||||
|
@ -115,17 +154,25 @@ describe('Session event', () => {
|
||||||
host: 'example.com',
|
host: 'example.com',
|
||||||
port: 8080,
|
port: 8080,
|
||||||
another: {
|
another: {
|
||||||
a: 'b'
|
a: 'b',
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [{ payload }] = events.eventCliSession({
|
const [{ payload }] = events.eventCliSession(
|
||||||
cliCommand: 'dev',
|
{
|
||||||
astroVersion: '0.0.0'
|
cliCommand: 'dev',
|
||||||
}, config);
|
astroVersion: '0.0.0',
|
||||||
expect(payload.config.viteKeys).is.deep.equal(['preview', 'preview.host', 'preview.port', 'preview.another']);
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
|
expect(payload.config.viteKeys).is.deep.equal([
|
||||||
|
'preview',
|
||||||
|
'preview.host',
|
||||||
|
'preview.port',
|
||||||
|
'preview.another',
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('vite.optimizeDeps keys are captured', async () => {
|
it('vite.optimizeDeps keys are captured', async () => {
|
||||||
|
@ -133,16 +180,23 @@ describe('Session event', () => {
|
||||||
vite: {
|
vite: {
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
entries: ['one', 'two'],
|
entries: ['one', 'two'],
|
||||||
exclude: ['secret', 'name']
|
exclude: ['secret', 'name'],
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [{ payload }] = events.eventCliSession({
|
const [{ payload }] = events.eventCliSession(
|
||||||
cliCommand: 'dev',
|
{
|
||||||
astroVersion: '0.0.0'
|
cliCommand: 'dev',
|
||||||
}, config);
|
astroVersion: '0.0.0',
|
||||||
expect(payload.config.viteKeys).is.deep.equal(['optimizeDeps', 'optimizeDeps.entries', 'optimizeDeps.exclude']);
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
|
expect(payload.config.viteKeys).is.deep.equal([
|
||||||
|
'optimizeDeps',
|
||||||
|
'optimizeDeps.entries',
|
||||||
|
'optimizeDeps.exclude',
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('vite.ssr keys are captured', async () => {
|
it('vite.ssr keys are captured', async () => {
|
||||||
|
@ -150,15 +204,18 @@ describe('Session event', () => {
|
||||||
vite: {
|
vite: {
|
||||||
ssr: {
|
ssr: {
|
||||||
external: ['a'],
|
external: ['a'],
|
||||||
target: { one: 'two' }
|
target: { one: 'two' },
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [{ payload }] = events.eventCliSession({
|
const [{ payload }] = events.eventCliSession(
|
||||||
cliCommand: 'dev',
|
{
|
||||||
astroVersion: '0.0.0'
|
cliCommand: 'dev',
|
||||||
}, config);
|
astroVersion: '0.0.0',
|
||||||
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
expect(payload.config.viteKeys).is.deep.equal(['ssr', 'ssr.external', 'ssr.target']);
|
expect(payload.config.viteKeys).is.deep.equal(['ssr', 'ssr.external', 'ssr.target']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -167,15 +224,18 @@ describe('Session event', () => {
|
||||||
vite: {
|
vite: {
|
||||||
worker: {
|
worker: {
|
||||||
format: { a: 'b' },
|
format: { a: 'b' },
|
||||||
plugins: ['a', 'b']
|
plugins: ['a', 'b'],
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [{ payload }] = events.eventCliSession({
|
const [{ payload }] = events.eventCliSession(
|
||||||
cliCommand: 'dev',
|
{
|
||||||
astroVersion: '0.0.0'
|
cliCommand: 'dev',
|
||||||
}, config);
|
astroVersion: '0.0.0',
|
||||||
|
},
|
||||||
|
config
|
||||||
|
);
|
||||||
expect(payload.config.viteKeys).is.deep.equal(['worker', 'worker.format', 'worker.plugins']);
|
expect(payload.config.viteKeys).is.deep.equal(['worker', 'worker.format', 'worker.plugins']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue