From 921d9a27e243c27e40e429a0a5c7d562d7b9633f Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Wed, 22 Jun 2022 14:13:32 -0700 Subject: [PATCH 01/58] simplify a complex peer semver used by astro add (#3633) * fix peer semver used by astro add * Create pink-shirts-mix.md * update with regex over `' '` split Co-authored-by: Ben Holmes --- .changeset/pink-shirts-mix.md | 5 +++++ packages/astro/src/core/add/index.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/pink-shirts-mix.md diff --git a/.changeset/pink-shirts-mix.md b/.changeset/pink-shirts-mix.md new file mode 100644 index 0000000000000..a1d14454aad90 --- /dev/null +++ b/.changeset/pink-shirts-mix.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fix a bug with `astro add react` adding a too-complex semver to your package.json diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index 09664f8f1bf7c..f0225991203a7 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -407,7 +407,7 @@ async function getInstallIntegrationsCommand({ .map<[string, string | null][]>((i) => [[i.packageName, null], ...i.dependencies]) .flat(1) .filter((dep, i, arr) => arr.findIndex((d) => d[0] === dep[0]) === i) - .map(([name, version]) => (version === null ? name : `${name}@${version}`)) + .map(([name, version]) => (version === null ? name : `${name}@${version.split(/\s*\|\|\s*/).pop()}`)) .sort(); switch (pm.name) { From a3654a7537784a1f379188159705d6aa3576b7b7 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Wed, 22 Jun 2022 21:15:21 +0000 Subject: [PATCH 02/58] [ci] format --- packages/astro/src/core/add/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index f0225991203a7..f66a2006d0e02 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -407,7 +407,9 @@ async function getInstallIntegrationsCommand({ .map<[string, string | null][]>((i) => [[i.packageName, null], ...i.dependencies]) .flat(1) .filter((dep, i, arr) => arr.findIndex((d) => d[0] === dep[0]) === i) - .map(([name, version]) => (version === null ? name : `${name}@${version.split(/\s*\|\|\s*/).pop()}`)) + .map(([name, version]) => + version === null ? name : `${name}@${version.split(/\s*\|\|\s*/).pop()}` + ) .sort(); switch (pm.name) { From 3d554fdbfb49d85d2945b7775825f7d9ace959ce Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Wed, 22 Jun 2022 19:52:32 -0400 Subject: [PATCH 03/58] Fix: pass Astro config postcss to Svelte preprocess (#3685) * fix: pass Astro config postcss to Svelte preprocess * test: preset env for nested styles * chore: changeset --- .changeset/empty-chicken-refuse.md | 6 + .../astro/test/fixtures/postcss/package.json | 3 + .../test/fixtures/postcss/postcss.config.cjs | 15 +- .../postcss/src/components/Astro.astro | 8 +- .../fixtures/postcss/src/components/Solid.css | 4 +- .../fixtures/postcss/src/components/Solid.jsx | 4 +- .../postcss/src/components/Svelte.svelte | 8 +- .../fixtures/postcss/src/components/Vue.vue | 8 +- .../fixtures/postcss/src/pages/index.astro | 6 +- packages/astro/test/postcss.test.js | 11 +- packages/integrations/svelte/src/index.ts | 24 +- pnpm-lock.yaml | 498 +++++++++++++++++- 12 files changed, 565 insertions(+), 30 deletions(-) create mode 100644 .changeset/empty-chicken-refuse.md diff --git a/.changeset/empty-chicken-refuse.md b/.changeset/empty-chicken-refuse.md new file mode 100644 index 0000000000000..b473aa7b4d722 --- /dev/null +++ b/.changeset/empty-chicken-refuse.md @@ -0,0 +1,6 @@ +--- +'astro': patch +'@astrojs/svelte': patch +--- + +Fix PostCSS config not applied to Svelte component by default diff --git a/packages/astro/test/fixtures/postcss/package.json b/packages/astro/test/fixtures/postcss/package.json index ff4f0e14d6ae2..417914c1225c4 100644 --- a/packages/astro/test/fixtures/postcss/package.json +++ b/packages/astro/test/fixtures/postcss/package.json @@ -9,5 +9,8 @@ "astro": "workspace:*", "autoprefixer": "^10.4.7", "postcss": "^8.4.14" + }, + "devDependencies": { + "postcss-preset-env": "^7.7.1" } } diff --git a/packages/astro/test/fixtures/postcss/postcss.config.cjs b/packages/astro/test/fixtures/postcss/postcss.config.cjs index 019f400400286..7ed7dd7e2dd9f 100644 --- a/packages/astro/test/fixtures/postcss/postcss.config.cjs +++ b/packages/astro/test/fixtures/postcss/postcss.config.cjs @@ -1,7 +1,12 @@ +const postcssPresetEnv = require('postcss-preset-env') +const autoPrefixer = require('autoprefixer') + module.exports = { - plugins: { - autoprefixer: { + plugins: [ + // included to ensure public/ CSS resources are NOT transformed + autoPrefixer({ overrideBrowserslist: ['> 0.1%', 'IE 11'] // enforce `appearance: none;` is prefixed with -webkit and -moz - } - } -}; + }), + postcssPresetEnv({ features: { 'nesting-rules': true } }), + ] +} diff --git a/packages/astro/test/fixtures/postcss/src/components/Astro.astro b/packages/astro/test/fixtures/postcss/src/components/Astro.astro index c85cd0415db63..5563e477865df 100644 --- a/packages/astro/test/fixtures/postcss/src/components/Astro.astro +++ b/packages/astro/test/fixtures/postcss/src/components/Astro.astro @@ -1,9 +1,11 @@ -
- Astro +
+ Astro
diff --git a/packages/astro/test/fixtures/postcss/src/components/Solid.css b/packages/astro/test/fixtures/postcss/src/components/Solid.css index 9c4272b56c3bf..6d06e4d891482 100644 --- a/packages/astro/test/fixtures/postcss/src/components/Solid.css +++ b/packages/astro/test/fixtures/postcss/src/components/Solid.css @@ -1,3 +1,5 @@ .solid { - appearance: none; + &.nested { + color: red; + } } diff --git a/packages/astro/test/fixtures/postcss/src/components/Solid.jsx b/packages/astro/test/fixtures/postcss/src/components/Solid.jsx index 9f172eb3b676f..63ee46a522e6c 100644 --- a/packages/astro/test/fixtures/postcss/src/components/Solid.jsx +++ b/packages/astro/test/fixtures/postcss/src/components/Solid.jsx @@ -3,8 +3,8 @@ import './Solid.css'; export default function Counter() { return ( -
- Solid +
+ Solid
); } diff --git a/packages/astro/test/fixtures/postcss/src/components/Svelte.svelte b/packages/astro/test/fixtures/postcss/src/components/Svelte.svelte index 0b55ab627542b..0311464439586 100644 --- a/packages/astro/test/fixtures/postcss/src/components/Svelte.svelte +++ b/packages/astro/test/fixtures/postcss/src/components/Svelte.svelte @@ -1,9 +1,11 @@ -
- Svelte +
+ Svelte
diff --git a/packages/astro/test/fixtures/postcss/src/components/Vue.vue b/packages/astro/test/fixtures/postcss/src/components/Vue.vue index 20b928e0857be..103eda0aaa5f3 100644 --- a/packages/astro/test/fixtures/postcss/src/components/Vue.vue +++ b/packages/astro/test/fixtures/postcss/src/components/Vue.vue @@ -1,12 +1,14 @@ diff --git a/packages/astro/test/fixtures/postcss/src/pages/index.astro b/packages/astro/test/fixtures/postcss/src/pages/index.astro index 2f73d045b058b..c239cff643209 100644 --- a/packages/astro/test/fixtures/postcss/src/pages/index.astro +++ b/packages/astro/test/fixtures/postcss/src/pages/index.astro @@ -12,13 +12,15 @@ import Vue from '../components/Vue.vue'; -
+
diff --git a/packages/astro/test/postcss.test.js b/packages/astro/test/postcss.test.js index d5360ba1db164..1cf06bee1029b 100644 --- a/packages/astro/test/postcss.test.js +++ b/packages/astro/test/postcss.test.js @@ -23,24 +23,25 @@ describe('PostCSS', () => { .replace('/n', ''); }); + /** All test cases check whether nested styles (i.e. &.nested {}) are correctly transformed */ it('works in Astro page styles', () => { - expect(bundledCSS).to.match(new RegExp(`.astro-page.astro-[^{]+${PREFIXED_CSS}`)); + expect(bundledCSS).to.match(new RegExp(`\.astro-page(\.(\w|-)*)*\.nested`)); }); it('works in Astro component styles', () => { - expect(bundledCSS).to.match(new RegExp(`.astro-component.astro-[^{]+${PREFIXED_CSS}`)); + expect(bundledCSS).to.match(new RegExp(`\.astro-component(\.(\w|-)*)*\.nested`)); }); it('works in JSX', () => { - expect(bundledCSS).to.match(new RegExp(`.solid[^{]*${PREFIXED_CSS}`)); + expect(bundledCSS).to.match(new RegExp(`\.solid(\.(\w|-)*)*\.nested`)); }); it('works in Vue', () => { - expect(bundledCSS).to.match(new RegExp(`.vue[^{]*${PREFIXED_CSS}`)); + expect(bundledCSS).to.match(new RegExp(`\.vue(\.(\w|-)*)*\.nested`)); }); it('works in Svelte', () => { - expect(bundledCSS).to.match(new RegExp(`.svelte.s[^{]+${PREFIXED_CSS}`)); + expect(bundledCSS).to.match(new RegExp(`\.svelte(\.(\w|-)*)*\.nested`)); }); it('ignores CSS in public/', async () => { diff --git a/packages/integrations/svelte/src/index.ts b/packages/integrations/svelte/src/index.ts index 340e2def0a7f8..268d5a59027e6 100644 --- a/packages/integrations/svelte/src/index.ts +++ b/packages/integrations/svelte/src/index.ts @@ -1,6 +1,7 @@ import type { Options } from '@sveltejs/vite-plugin-svelte'; +import type { AstroIntegration, AstroRenderer, AstroConfig } from 'astro'; +import type { UserConfig } from 'vite' import { svelte } from '@sveltejs/vite-plugin-svelte'; -import type { AstroIntegration, AstroRenderer } from 'astro'; import preprocess from 'svelte-preprocess'; function getRenderer(): AstroRenderer { @@ -11,13 +12,20 @@ function getRenderer(): AstroRenderer { }; } -function getViteConfiguration(isDev: boolean, options?: Options | OptionsCallback) { - const defaultOptions = { +type ViteConfigurationArgs = { + isDev: boolean; + options?: Options | OptionsCallback; + postcssConfig: AstroConfig['style']['postcss']; +} + +function getViteConfiguration({ options, postcssConfig, isDev }: ViteConfigurationArgs): UserConfig { + const defaultOptions: Partial = { emitCss: true, compilerOptions: { dev: isDev, hydratable: true }, preprocess: [ preprocess({ less: true, + postcss: postcssConfig, sass: { renderSync: true }, scss: { renderSync: true }, stylus: true, @@ -61,9 +69,15 @@ export default function (options?: Options | OptionsCallback): AstroIntegration name: '@astrojs/svelte', hooks: { // Anything that gets returned here is merged into Astro Config - 'astro:config:setup': ({ command, updateConfig, addRenderer }) => { + 'astro:config:setup': ({ command, updateConfig, addRenderer, config }) => { addRenderer(getRenderer()); - updateConfig({ vite: getViteConfiguration(command === 'dev', options) }); + updateConfig({ + vite: getViteConfiguration({ + options, + isDev: command === 'dev', + postcssConfig: config.style.postcss, + }) + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 05c6e0f56d17f..c5690fe4e308f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1474,6 +1474,7 @@ importers: astro: workspace:* autoprefixer: ^10.4.7 postcss: ^8.4.14 + postcss-preset-env: ^7.7.1 dependencies: '@astrojs/solid-js': link:../../../../integrations/solid '@astrojs/svelte': link:../../../../integrations/svelte @@ -1481,6 +1482,8 @@ importers: astro: link:../../.. autoprefixer: 10.4.7_postcss@8.4.14 postcss: 8.4.14 + devDependencies: + postcss-preset-env: 7.7.1_postcss@8.4.14 packages/astro/test/fixtures/preact-component: specifiers: @@ -3996,6 +3999,141 @@ packages: prettier: 1.19.1 dev: true + /@csstools/postcss-cascade-layers/1.0.3_postcss@8.4.14: + resolution: {integrity: sha512-fvXP0+dcllGtRKAjA5n5tBr57xWQalKky09hSiXAZ9qqjHn0sDuQV2Jz0Y5zHRQ6iGrAjJZOf2+xQj3yuXfLwA==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + '@csstools/selector-specificity': 2.0.1_444rcjjorr3kpoqtvoodsr46pu + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /@csstools/postcss-color-function/1.1.0_postcss@8.4.14: + resolution: {integrity: sha512-5D5ND/mZWcQoSfYnSPsXtuiFxhzmhxt6pcjrFLJyldj+p0ZN2vvRpYNX+lahFTtMhAYOa2WmkdGINr0yP0CvGA==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + '@csstools/postcss-progressive-custom-properties': 1.3.0_postcss@8.4.14 + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /@csstools/postcss-font-format-keywords/1.0.0_postcss@8.4.14: + resolution: {integrity: sha512-oO0cZt8do8FdVBX8INftvIA4lUrKUSCcWUf9IwH9IPWOgKT22oAZFXeHLoDK7nhB2SmkNycp5brxfNMRLIhd6Q==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /@csstools/postcss-hwb-function/1.0.1_postcss@8.4.14: + resolution: {integrity: sha512-AMZwWyHbbNLBsDADWmoXT9A5yl5dsGEBeJSJRUJt8Y9n8Ziu7Wstt4MC8jtPW7xjcLecyfJwtnUTNSmOzcnWeg==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /@csstools/postcss-ic-unit/1.0.0_postcss@8.4.14: + resolution: {integrity: sha512-i4yps1mBp2ijrx7E96RXrQXQQHm6F4ym1TOD0D69/sjDjZvQ22tqiEvaNw7pFZTUO5b9vWRHzbHzP9+UKuw+bA==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + '@csstools/postcss-progressive-custom-properties': 1.3.0_postcss@8.4.14 + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /@csstools/postcss-is-pseudo-class/2.0.5_postcss@8.4.14: + resolution: {integrity: sha512-Ek+UFI4UP2hB9u0N1cJd6KgSF1rL0J3PT4is0oSStuus8+WzbGGPyJNMOKQ0w/tyPjxiCnOI4RdSMZt3nks64g==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + '@csstools/selector-specificity': 2.0.1_444rcjjorr3kpoqtvoodsr46pu + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /@csstools/postcss-normalize-display-values/1.0.0_postcss@8.4.14: + resolution: {integrity: sha512-bX+nx5V8XTJEmGtpWTO6kywdS725t71YSLlxWt78XoHUbELWgoCXeOFymRJmL3SU1TLlKSIi7v52EWqe60vJTQ==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /@csstools/postcss-oklab-function/1.1.0_postcss@8.4.14: + resolution: {integrity: sha512-e/Q5HopQzmnQgqimG9v3w2IG4VRABsBq3itOcn4bnm+j4enTgQZ0nWsaH/m9GV2otWGQ0nwccYL5vmLKyvP1ww==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + '@csstools/postcss-progressive-custom-properties': 1.3.0_postcss@8.4.14 + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /@csstools/postcss-progressive-custom-properties/1.3.0_postcss@8.4.14: + resolution: {integrity: sha512-ASA9W1aIy5ygskZYuWams4BzafD12ULvSypmaLJT2jvQ8G0M3I8PRQhC0h7mG0Z3LI05+agZjqSR9+K9yaQQjA==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /@csstools/postcss-stepped-value-functions/1.0.0_postcss@8.4.14: + resolution: {integrity: sha512-q8c4bs1GumAiRenmFjASBcWSLKrbzHzWl6C2HcaAxAXIiL2rUlUWbqQZUjwVG5tied0rld19j/Mm90K3qI26vw==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /@csstools/postcss-trigonometric-functions/1.0.1_postcss@8.4.14: + resolution: {integrity: sha512-G78CY/+GePc6dDCTUbwI6TTFQ5fs3N9POHhI6v0QzteGpf6ylARiJUNz9HrRKi4eVYBNXjae1W2766iUEFxHlw==} + engines: {node: ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /@csstools/postcss-unset-value/1.0.1_postcss@8.4.14: + resolution: {integrity: sha512-f1G1WGDXEU/RN1TWAxBPQgQudtLnLQPyiWdtypkPC+mVYNKFKH/HYXSxH4MVNqwF8M0eDsoiU7HumJHCg/L/jg==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + dev: true + + /@csstools/selector-specificity/2.0.1_444rcjjorr3kpoqtvoodsr46pu: + resolution: {integrity: sha512-aG20vknL4/YjQF9BSV7ts4EWm/yrjagAN7OWBNmlbEOUiu0llj4OGrFoOKK3g2vey4/p2omKCoHrWtPxSwV3HA==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + postcss-selector-parser: ^6.0.10 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + /@docsearch/css/3.1.0: resolution: {integrity: sha512-bh5IskwkkodbvC0FzSg1AxMykfDl95hebEKwxNoq4e5QaGzOXSBgW8+jnMFZ7JU4sTBiB04vZWoUSzNrPboLZA==} dev: false @@ -8186,6 +8324,38 @@ packages: engines: {node: '>=8'} dev: true + /css-blank-pseudo/3.0.3_postcss@8.4.14: + resolution: {integrity: sha512-VS90XWtsHGqoM0t4KpH053c4ehxZ2E6HtGI7x68YFV0pTo/QmkV/YFA+NnlvK8guxZVNWGQhVNJGC39Q8XF4OQ==} + engines: {node: ^12 || ^14 || >=16} + hasBin: true + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /css-has-pseudo/3.0.4_postcss@8.4.14: + resolution: {integrity: sha512-Vse0xpR1K9MNlp2j5w1pgWIJtm1a8qS0JwS9goFYcImjlHEmywP9VUF05aGBXzGpDJF86QXk4L0ypBmwPhGArw==} + engines: {node: ^12 || ^14 || >=16} + hasBin: true + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /css-prefers-color-scheme/6.0.3_postcss@8.4.14: + resolution: {integrity: sha512-4BqMbZksRkJQx2zAjrokiGMd07RqOa2IxIrrN10lyBe9xhn9DEvjUK79J6jkeiv9D9hQFXKb6g1jwU62jziJZA==} + engines: {node: ^12 || ^14 || >=16} + hasBin: true + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + dev: true + /css-select/5.1.0: resolution: {integrity: sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==} dependencies: @@ -8204,6 +8374,10 @@ packages: engines: {node: '>= 6'} dev: true + /cssdb/6.6.3: + resolution: {integrity: sha512-7GDvDSmE+20+WcSMhP17Q1EVWUrLlbxxpMDqG731n8P99JhnQZHR9YvtjPvEHfjFUjvQJvdpKCjlKOX+xe4UVA==} + dev: true + /cssesc/3.0.0: resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==} engines: {node: '>=4'} @@ -11742,6 +11916,172 @@ packages: hasBin: true dev: true + /postcss-attribute-case-insensitive/5.0.1_postcss@8.4.14: + resolution: {integrity: sha512-wrt2VndqSLJpyBRNz9OmJcgnhI9MaongeWgapdBuUMu2a/KNJ8SENesG4SdiTnQwGO9b1VKbTWYAfCPeokLqZQ==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /postcss-clamp/4.1.0_postcss@8.4.14: + resolution: {integrity: sha512-ry4b1Llo/9zz+PKC+030KUnPITTJAHeOwjfAyyB60eT0AorGLdzp52s31OsPRHRf8NchkgFoG2y6fCfn1IV1Ow==} + engines: {node: '>=7.6.0'} + peerDependencies: + postcss: ^8.4.6 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-color-functional-notation/4.2.3_postcss@8.4.14: + resolution: {integrity: sha512-5fbr6FzFzjwHXKsVnkmEYrJYG8VNNzvD1tAXaPPWR97S6rhKI5uh2yOfV5TAzhDkZoq4h+chxEplFDc8GeyFtw==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-color-hex-alpha/8.0.4_postcss@8.4.14: + resolution: {integrity: sha512-nLo2DCRC9eE4w2JmuKgVA3fGL3d01kGq752pVALF68qpGLmx2Qrk91QTKkdUqqp45T1K1XV8IhQpcu1hoAQflQ==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-color-rebeccapurple/7.1.0_postcss@8.4.14: + resolution: {integrity: sha512-1jtE5AKnZcKq4pjOrltFHcbEM2/IvtbD1OdhZ/wqds18//bh0UmQkffcCkzDJU+/vGodfIsVQeKn+45CJvX9Bw==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-custom-media/8.0.2_postcss@8.4.14: + resolution: {integrity: sha512-7yi25vDAoHAkbhAzX9dHx2yc6ntS4jQvejrNcC+csQJAXjj15e7VcWfMgLqBNAbOvqi5uIa9huOVwdHbf+sKqg==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-custom-properties/12.1.8_postcss@8.4.14: + resolution: {integrity: sha512-8rbj8kVu00RQh2fQF81oBqtduiANu4MIxhyf0HbbStgPtnFlWn0yiaYTpLHrPnJbffVY1s9apWsIoVZcc68FxA==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-custom-selectors/6.0.3_postcss@8.4.14: + resolution: {integrity: sha512-fgVkmyiWDwmD3JbpCmB45SvvlCD6z9CG6Ie6Iere22W5aHea6oWa7EM2bpnv2Fj3I94L3VbtvX9KqwSi5aFzSg==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /postcss-dir-pseudo-class/6.0.4_postcss@8.4.14: + resolution: {integrity: sha512-I8epwGy5ftdzNWEYok9VjW9whC4xnelAtbajGv4adql4FIF09rnrxnA9Y8xSHN47y7gqFIv10C5+ImsLeJpKBw==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /postcss-double-position-gradients/3.1.1_postcss@8.4.14: + resolution: {integrity: sha512-jM+CGkTs4FcG53sMPjrrGE0rIvLDdCrqMzgDC5fLI7JHDO7o6QG8C5TQBtExb13hdBdoH9C2QVbG4jo2y9lErQ==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + '@csstools/postcss-progressive-custom-properties': 1.3.0_postcss@8.4.14 + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-env-function/4.0.6_postcss@8.4.14: + resolution: {integrity: sha512-kpA6FsLra+NqcFnL81TnsU+Z7orGtDTxcOhl6pwXeEq1yFPpRMkCDpHhrz8CFQDr/Wfm0jLiNQ1OsGGPjlqPwA==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-focus-visible/6.0.4_postcss@8.4.14: + resolution: {integrity: sha512-QcKuUU/dgNsstIK6HELFRT5Y3lbrMLEOwG+A4s5cA+fx3A3y/JTq3X9LaOj3OC3ALH0XqyrgQIgey/MIZ8Wczw==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /postcss-focus-within/5.0.4_postcss@8.4.14: + resolution: {integrity: sha512-vvjDN++C0mu8jz4af5d52CB184ogg/sSxAFS+oUJQq2SuCe7T5U2iIsVJtsCp2d6R4j0jr5+q3rPkBVZkXD9fQ==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /postcss-font-variant/5.0.0_postcss@8.4.14: + resolution: {integrity: sha512-1fmkBaCALD72CK2a9i468mA/+tr9/1cBxRRMXOUaZqO43oWPR5imcyPjXwuv7PXbCid4ndlP5zWhidQVVa3hmA==} + peerDependencies: + postcss: ^8.1.0 + dependencies: + postcss: 8.4.14 + dev: true + + /postcss-gap-properties/3.0.3_postcss@8.4.14: + resolution: {integrity: sha512-rPPZRLPmEKgLk/KlXMqRaNkYTUpE7YC+bOIQFN5xcu1Vp11Y4faIXv6/Jpft6FMnl6YRxZqDZG0qQOW80stzxQ==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + dev: true + + /postcss-image-set-function/4.0.6_postcss@8.4.14: + resolution: {integrity: sha512-KfdC6vg53GC+vPd2+HYzsZ6obmPqOk6HY09kttU19+Gj1nC3S3XBVEXDHxkhxTohgZqzbUb94bKXvKDnYWBm/A==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-initial/4.0.1_postcss@8.4.14: + resolution: {integrity: sha512-0ueD7rPqX8Pn1xJIjay0AZeIuDoF+V+VvMt/uOnn+4ezUKhZM/NokDeP6DwMNyIoYByuN/94IQnt5FEkaN59xQ==} + peerDependencies: + postcss: ^8.0.0 + dependencies: + postcss: 8.4.14 + dev: true + /postcss-js/4.0.0_postcss@8.4.14: resolution: {integrity: sha512-77QESFBwgX4irogGVPgQ5s07vLvFqWr228qZY+w6lW599cRlK/HmnlivnnVUxkjHnCu4J16PDMHcH+e+2HbvTQ==} engines: {node: ^12 || ^14 || >= 16} @@ -11751,6 +12091,17 @@ packages: camelcase-css: 2.0.1 postcss: 8.4.14 + /postcss-lab-function/4.2.0_postcss@8.4.14: + resolution: {integrity: sha512-Zb1EO9DGYfa3CP8LhINHCcTTCTLI+R3t7AX2mKsDzdgVQ/GkCpHOTgOr6HBHslP7XDdVbqgHW5vvRPMdVANQ8w==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + '@csstools/postcss-progressive-custom-properties': 1.3.0_postcss@8.4.14 + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + /postcss-load-config/3.1.4: resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==} engines: {node: '>= 10'} @@ -11783,6 +12134,24 @@ packages: postcss: 8.4.14 yaml: 1.10.2 + /postcss-logical/5.0.4_postcss@8.4.14: + resolution: {integrity: sha512-RHXxplCeLh9VjinvMrZONq7im4wjWGlRJAqmAVLXyZaXwfDWP73/oq4NdIp+OZwhQUMj0zjqDfM5Fj7qby+B4g==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + dev: true + + /postcss-media-minmax/5.0.0_postcss@8.4.14: + resolution: {integrity: sha512-yDUvFf9QdFZTuCUg0g0uNSHVlJ5X1lSzDZjPSFaiCWvjgsvu8vEVxtahPrLMinIDEEGnx6cBe6iqdx5YWz08wQ==} + engines: {node: '>=10.0.0'} + peerDependencies: + postcss: ^8.1.0 + dependencies: + postcss: 8.4.14 + dev: true + /postcss-nested/5.0.6_postcss@8.4.14: resolution: {integrity: sha512-rKqm2Fk0KbA8Vt3AdGN0FB9OBOMDVajMG6ZCf/GoHgdxUJ4sBFp0A/uMIRm+MJUdo33YXEtjqIz8u7DAp8B7DA==} engines: {node: '>=12.0'} @@ -11792,6 +12161,133 @@ packages: postcss: 8.4.14 postcss-selector-parser: 6.0.10 + /postcss-nesting/10.1.8_postcss@8.4.14: + resolution: {integrity: sha512-txdb3/idHYsBbNDFo1PFY0ExCgH5nfWi8G5lO49e6iuU42TydbODTzJgF5UuL5bhgeSlnAtDgfFTDG0Cl1zaSQ==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + '@csstools/selector-specificity': 2.0.1_444rcjjorr3kpoqtvoodsr46pu + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /postcss-opacity-percentage/1.1.2: + resolution: {integrity: sha512-lyUfF7miG+yewZ8EAk9XUBIlrHyUE6fijnesuz+Mj5zrIHIEw6KcIZSOk/elVMqzLvREmXB83Zi/5QpNRYd47w==} + engines: {node: ^12 || ^14 || >=16} + dev: true + + /postcss-overflow-shorthand/3.0.3_postcss@8.4.14: + resolution: {integrity: sha512-CxZwoWup9KXzQeeIxtgOciQ00tDtnylYIlJBBODqkgS/PU2jISuWOL/mYLHmZb9ZhZiCaNKsCRiLp22dZUtNsg==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + dev: true + + /postcss-page-break/3.0.4_postcss@8.4.14: + resolution: {integrity: sha512-1JGu8oCjVXLa9q9rFTo4MbeeA5FMe00/9C7lN4va606Rdb+HkxXtXsmEDrIraQ11fGz/WvKWa8gMuCKkrXpTsQ==} + peerDependencies: + postcss: ^8 + dependencies: + postcss: 8.4.14 + dev: true + + /postcss-place/7.0.4_postcss@8.4.14: + resolution: {integrity: sha512-MrgKeiiu5OC/TETQO45kV3npRjOFxEHthsqGtkh3I1rPbZSbXGD/lZVi9j13cYh+NA8PIAPyk6sGjT9QbRyvSg==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-preset-env/7.7.1_postcss@8.4.14: + resolution: {integrity: sha512-1sx6+Nl1wMVJzaYLVaz4OAR6JodIN/Z1upmVqLwSPCLT6XyxrEoePgNMHPH08kseLe3z06i9Vfkt/32BYEKDeA==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + '@csstools/postcss-cascade-layers': 1.0.3_postcss@8.4.14 + '@csstools/postcss-color-function': 1.1.0_postcss@8.4.14 + '@csstools/postcss-font-format-keywords': 1.0.0_postcss@8.4.14 + '@csstools/postcss-hwb-function': 1.0.1_postcss@8.4.14 + '@csstools/postcss-ic-unit': 1.0.0_postcss@8.4.14 + '@csstools/postcss-is-pseudo-class': 2.0.5_postcss@8.4.14 + '@csstools/postcss-normalize-display-values': 1.0.0_postcss@8.4.14 + '@csstools/postcss-oklab-function': 1.1.0_postcss@8.4.14 + '@csstools/postcss-progressive-custom-properties': 1.3.0_postcss@8.4.14 + '@csstools/postcss-stepped-value-functions': 1.0.0_postcss@8.4.14 + '@csstools/postcss-trigonometric-functions': 1.0.1_postcss@8.4.14 + '@csstools/postcss-unset-value': 1.0.1_postcss@8.4.14 + autoprefixer: 10.4.7_postcss@8.4.14 + browserslist: 4.20.4 + css-blank-pseudo: 3.0.3_postcss@8.4.14 + css-has-pseudo: 3.0.4_postcss@8.4.14 + css-prefers-color-scheme: 6.0.3_postcss@8.4.14 + cssdb: 6.6.3 + postcss: 8.4.14 + postcss-attribute-case-insensitive: 5.0.1_postcss@8.4.14 + postcss-clamp: 4.1.0_postcss@8.4.14 + postcss-color-functional-notation: 4.2.3_postcss@8.4.14 + postcss-color-hex-alpha: 8.0.4_postcss@8.4.14 + postcss-color-rebeccapurple: 7.1.0_postcss@8.4.14 + postcss-custom-media: 8.0.2_postcss@8.4.14 + postcss-custom-properties: 12.1.8_postcss@8.4.14 + postcss-custom-selectors: 6.0.3_postcss@8.4.14 + postcss-dir-pseudo-class: 6.0.4_postcss@8.4.14 + postcss-double-position-gradients: 3.1.1_postcss@8.4.14 + postcss-env-function: 4.0.6_postcss@8.4.14 + postcss-focus-visible: 6.0.4_postcss@8.4.14 + postcss-focus-within: 5.0.4_postcss@8.4.14 + postcss-font-variant: 5.0.0_postcss@8.4.14 + postcss-gap-properties: 3.0.3_postcss@8.4.14 + postcss-image-set-function: 4.0.6_postcss@8.4.14 + postcss-initial: 4.0.1_postcss@8.4.14 + postcss-lab-function: 4.2.0_postcss@8.4.14 + postcss-logical: 5.0.4_postcss@8.4.14 + postcss-media-minmax: 5.0.0_postcss@8.4.14 + postcss-nesting: 10.1.8_postcss@8.4.14 + postcss-opacity-percentage: 1.1.2 + postcss-overflow-shorthand: 3.0.3_postcss@8.4.14 + postcss-page-break: 3.0.4_postcss@8.4.14 + postcss-place: 7.0.4_postcss@8.4.14 + postcss-pseudo-class-any-link: 7.1.4_postcss@8.4.14 + postcss-replace-overflow-wrap: 4.0.0_postcss@8.4.14 + postcss-selector-not: 6.0.0_postcss@8.4.14 + postcss-value-parser: 4.2.0 + dev: true + + /postcss-pseudo-class-any-link/7.1.4_postcss@8.4.14: + resolution: {integrity: sha512-JxRcLXm96u14N3RzFavPIE9cRPuOqLDuzKeBsqi4oRk4vt8n0A7I0plFs/VXTg7U2n7g/XkQi0OwqTO3VWBfEg==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.4 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + + /postcss-replace-overflow-wrap/4.0.0_postcss@8.4.14: + resolution: {integrity: sha512-KmF7SBPphT4gPPcKZc7aDkweHiKEEO8cla/GjcBK+ckKxiZslIu3C4GCRW3DNfL0o7yW7kMQu9xlZ1kXRXLXtw==} + peerDependencies: + postcss: ^8.0.3 + dependencies: + postcss: 8.4.14 + dev: true + + /postcss-selector-not/6.0.0_postcss@8.4.14: + resolution: {integrity: sha512-i/HI/VNd3V9e1WOLCwJsf9nePBRXqcGtVibcJ9FsVo0agfDEfsLSlFt94aYjY35wUNcdG0KrvdyjEr7It50wLQ==} + engines: {node: ^12 || ^14 || >=16} + peerDependencies: + postcss: ^8.3 + dependencies: + postcss: 8.4.14 + postcss-selector-parser: 6.0.10 + dev: true + /postcss-selector-parser/6.0.10: resolution: {integrity: sha512-IQ7TZdoaqbT+LCpShg46jnZVlhWD2w6iQYAcYXfHARZ7X1t/UGhhceQDs5X0cGqKvYlHNOuv7Oa1xmb0oQuA3w==} engines: {node: '>=4'} @@ -13687,7 +14183,7 @@ packages: dev: true /util-deprecate/1.0.2: - resolution: {integrity: sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=} + resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} /util/0.12.4: resolution: {integrity: sha512-bxZ9qtSlGUWSOy9Qa9Xgk11kSslpuZwaxCg4sNIDj6FLucDab2JxnHwyNTCpHMtK1MjoQiWQ6DiUMZYbSrO+Sw==} From 9133a428312d168f6b08a1f8917eb55b30d16bd9 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Wed, 22 Jun 2022 23:55:00 +0000 Subject: [PATCH 04/58] [ci] format --- packages/integrations/svelte/src/index.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/integrations/svelte/src/index.ts b/packages/integrations/svelte/src/index.ts index 268d5a59027e6..3aa27e47e3bc7 100644 --- a/packages/integrations/svelte/src/index.ts +++ b/packages/integrations/svelte/src/index.ts @@ -1,8 +1,8 @@ import type { Options } from '@sveltejs/vite-plugin-svelte'; -import type { AstroIntegration, AstroRenderer, AstroConfig } from 'astro'; -import type { UserConfig } from 'vite' import { svelte } from '@sveltejs/vite-plugin-svelte'; +import type { AstroConfig, AstroIntegration, AstroRenderer } from 'astro'; import preprocess from 'svelte-preprocess'; +import type { UserConfig } from 'vite'; function getRenderer(): AstroRenderer { return { @@ -16,9 +16,13 @@ type ViteConfigurationArgs = { isDev: boolean; options?: Options | OptionsCallback; postcssConfig: AstroConfig['style']['postcss']; -} +}; -function getViteConfiguration({ options, postcssConfig, isDev }: ViteConfigurationArgs): UserConfig { +function getViteConfiguration({ + options, + postcssConfig, + isDev, +}: ViteConfigurationArgs): UserConfig { const defaultOptions: Partial = { emitCss: true, compilerOptions: { dev: isDev, hydratable: true }, @@ -76,7 +80,7 @@ export default function (options?: Options | OptionsCallback): AstroIntegration options, isDev: command === 'dev', postcssConfig: config.style.postcss, - }) + }), }); }, }, From aa883a50c890490f6d968868643f6cc2139af845 Mon Sep 17 00:00:00 2001 From: FredKSchott Date: Thu, 23 Jun 2022 12:02:10 +0000 Subject: [PATCH 05/58] [ci] collect stats --- scripts/stats/stats.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/stats/stats.csv b/scripts/stats/stats.csv index ba6a1a0726001..22035d18fcc39 100644 --- a/scripts/stats/stats.csv +++ b/scripts/stats/stats.csv @@ -1,4 +1,5 @@ Date,Commits (24hr),Issues (24hr),Issues:BUG (24hr),Issues:RFC (24hr),Issues:DOC (24hr),PRs (24hr),Open PRs,Open Issues,Bugs: Needs Triage,Bugs: Accepted,RFC: In Progress,RFC: Accepted,Date (ISO) +"Thursday, June 23, 2022",24,4,4,0,0,11,21,75,51,16,0,0,"2022-06-23T12:02:04.952Z" "Wednesday, June 22, 2022",13,5,5,0,0,12,23,75,51,16,0,0,"2022-06-22T12:02:19.701Z" "Tuesday, June 21, 2022",12,3,3,0,0,7,20,77,50,17,0,0,"2022-06-21T12:02:07.113Z" "Monday, June 20, 2022",1,3,3,0,0,1,20,81,52,20,0,0,"2022-06-20T12:01:57.157Z" From b36ecb717e2cb623501c6d9a60471ac4daba43a8 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 23 Jun 2022 09:03:43 -0400 Subject: [PATCH 06/58] Include partytown scripts in SSR manifest (#3686) * Include partytown scripts in SSR manifst * Adds a changeset --- .changeset/cuddly-llamas-arrive.md | 5 +++ .../fixtures/ssr-partytown/astro.config.mjs | 7 ++++ .../test/fixtures/ssr-partytown/package.json | 9 +++++ .../ssr-partytown/src/pages/index.astro | 6 ++++ packages/astro/test/ssr-partytown.test.js | 34 +++++++++++++++++++ packages/integrations/partytown/src/index.ts | 11 +++++- pnpm-lock.yaml | 17 +++++----- 7 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 .changeset/cuddly-llamas-arrive.md create mode 100644 packages/astro/test/fixtures/ssr-partytown/astro.config.mjs create mode 100644 packages/astro/test/fixtures/ssr-partytown/package.json create mode 100644 packages/astro/test/fixtures/ssr-partytown/src/pages/index.astro create mode 100644 packages/astro/test/ssr-partytown.test.js diff --git a/.changeset/cuddly-llamas-arrive.md b/.changeset/cuddly-llamas-arrive.md new file mode 100644 index 0000000000000..40942b606c34d --- /dev/null +++ b/.changeset/cuddly-llamas-arrive.md @@ -0,0 +1,5 @@ +--- +'@astrojs/partytown': patch +--- + +Include partytown scripts in SSR manifest diff --git a/packages/astro/test/fixtures/ssr-partytown/astro.config.mjs b/packages/astro/test/fixtures/ssr-partytown/astro.config.mjs new file mode 100644 index 0000000000000..ea1fb12db89cd --- /dev/null +++ b/packages/astro/test/fixtures/ssr-partytown/astro.config.mjs @@ -0,0 +1,7 @@ +import { defineConfig } from 'astro/config'; +import partytown from '@astrojs/partytown'; + +// https://astro.build/config +export default defineConfig({ + integrations: [partytown()], +}); diff --git a/packages/astro/test/fixtures/ssr-partytown/package.json b/packages/astro/test/fixtures/ssr-partytown/package.json new file mode 100644 index 0000000000000..5713e2d1bc46b --- /dev/null +++ b/packages/astro/test/fixtures/ssr-partytown/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/ssr-partytown", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*", + "@astrojs/partytown": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/ssr-partytown/src/pages/index.astro b/packages/astro/test/fixtures/ssr-partytown/src/pages/index.astro new file mode 100644 index 0000000000000..743a9d35afbef --- /dev/null +++ b/packages/astro/test/fixtures/ssr-partytown/src/pages/index.astro @@ -0,0 +1,6 @@ + + testing + +

testing

+ + diff --git a/packages/astro/test/ssr-partytown.test.js b/packages/astro/test/ssr-partytown.test.js new file mode 100644 index 0000000000000..5ea2bcde59e91 --- /dev/null +++ b/packages/astro/test/ssr-partytown.test.js @@ -0,0 +1,34 @@ +import { expect } from 'chai'; +import { load as cheerioLoad } from 'cheerio'; +import { loadFixture } from './test-utils.js'; +import testAdapter from './test-adapter.js'; + +describe('Using the Partytown integration in SSR', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/ssr-partytown/', + adapter: testAdapter(), + experimental: { + ssr: true, + }, + }); + await fixture.build(); + }); + + it('Has the scripts in the page', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/'); + const response = await app.render(request); + const html = await response.text(); + const $ = cheerioLoad(html); + expect($('script')).to.have.a.lengthOf(1); + }); + + it('The partytown scripts are in the manifest', async () => { + const app = await fixture.loadTestAdapterApp(); + expect(app.manifest.assets).to.contain('/~partytown/partytown-sw.js'); + }); +}); diff --git a/packages/integrations/partytown/src/index.ts b/packages/integrations/partytown/src/index.ts index 3d1101f968ddf..51343b1691e33 100644 --- a/packages/integrations/partytown/src/index.ts +++ b/packages/integrations/partytown/src/index.ts @@ -1,8 +1,9 @@ import { partytownSnippet } from '@builder.io/partytown/integration'; -import { copyLibFiles } from '@builder.io/partytown/utils'; +import { copyLibFiles, libDirPath } from '@builder.io/partytown/utils'; import type { AstroConfig, AstroIntegration } from 'astro'; import { createRequire } from 'module'; import path from 'path'; +import * as fs from 'fs'; import { fileURLToPath } from 'url'; import sirv from './sirv.js'; const resolve = createRequire(import.meta.url).resolve; @@ -50,6 +51,14 @@ export default function createPlugin(options: PartytownOptions): AstroIntegratio debugDir: false, }); }, + 'astro:build:ssr': async ({ manifest }) => { + const dirpath = libDirPath({ debugDir: false }); + const files = await fs.promises.readdir(dirpath); + for(const file of files) { + if(file === 'debug') continue; + manifest.assets.push(`/~partytown/${file}`) + } + } }, }; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c5690fe4e308f..60a6af258cdcf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1601,6 +1601,14 @@ importers: dependencies: astro: link:../../.. + packages/astro/test/fixtures/ssr-partytown: + specifiers: + '@astrojs/partytown': workspace:* + astro: workspace:* + dependencies: + '@astrojs/partytown': link:../../../../integrations/partytown + astro: link:../../.. + packages/astro/test/fixtures/ssr-scripts: specifiers: '@astrojs/preact': 'workspace:' @@ -8432,11 +8440,6 @@ packages: /debug/3.2.7: resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true dependencies: ms: 2.1.3 dev: false @@ -11358,8 +11361,6 @@ packages: debug: 3.2.7 iconv-lite: 0.4.24 sax: 1.2.4 - transitivePeerDependencies: - - supports-color dev: false /netmask/2.0.2: @@ -11443,8 +11444,6 @@ packages: rimraf: 2.7.1 semver: 5.7.1 tar: 4.4.19 - transitivePeerDependencies: - - supports-color dev: false /node-releases/2.0.5: From 16cdfeef81c7c0472c7fccc882fd3c39b0e88bcd Mon Sep 17 00:00:00 2001 From: matthewp Date: Thu, 23 Jun 2022 13:05:55 +0000 Subject: [PATCH 07/58] [ci] format --- packages/integrations/partytown/src/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/integrations/partytown/src/index.ts b/packages/integrations/partytown/src/index.ts index 51343b1691e33..44ffbe3106f73 100644 --- a/packages/integrations/partytown/src/index.ts +++ b/packages/integrations/partytown/src/index.ts @@ -1,9 +1,9 @@ import { partytownSnippet } from '@builder.io/partytown/integration'; import { copyLibFiles, libDirPath } from '@builder.io/partytown/utils'; import type { AstroConfig, AstroIntegration } from 'astro'; +import * as fs from 'fs'; import { createRequire } from 'module'; import path from 'path'; -import * as fs from 'fs'; import { fileURLToPath } from 'url'; import sirv from './sirv.js'; const resolve = createRequire(import.meta.url).resolve; @@ -54,11 +54,11 @@ export default function createPlugin(options: PartytownOptions): AstroIntegratio 'astro:build:ssr': async ({ manifest }) => { const dirpath = libDirPath({ debugDir: false }); const files = await fs.promises.readdir(dirpath); - for(const file of files) { - if(file === 'debug') continue; - manifest.assets.push(`/~partytown/${file}`) + for (const file of files) { + if (file === 'debug') continue; + manifest.assets.push(`/~partytown/${file}`); } - } + }, }, }; } From 19cd962d0b3433ee305d1d277ca4fc3b93593558 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 23 Jun 2022 09:14:17 -0400 Subject: [PATCH 08/58] [ci] release (#3684) Co-authored-by: github-actions[bot] --- .changeset/cuddly-llamas-arrive.md | 5 -- .changeset/empty-chicken-refuse.md | 6 -- .changeset/neat-seas-peel.md | 23 ------- .changeset/pink-shirts-mix.md | 5 -- .changeset/spotty-rockets-grow.md | 5 -- examples/basics/package.json | 2 +- examples/blog-multiple-authors/package.json | 2 +- examples/blog/package.json | 2 +- examples/component/demo/package.json | 2 +- examples/component/package.json | 2 +- examples/docs/package.json | 2 +- examples/env-vars/package.json | 2 +- examples/framework-alpine/package.json | 2 +- examples/framework-lit/package.json | 2 +- examples/framework-multiple/package.json | 4 +- examples/framework-preact/package.json | 2 +- examples/framework-react/package.json | 2 +- examples/framework-solid/package.json | 2 +- examples/framework-svelte/package.json | 4 +- examples/framework-vue/package.json | 2 +- examples/integrations-playground/package.json | 4 +- examples/minimal/package.json | 2 +- examples/non-html-pages/package.json | 2 +- examples/portfolio/package.json | 2 +- examples/ssr/package.json | 4 +- examples/starter/package.json | 2 +- examples/subpath/package.json | 2 +- examples/with-markdown-plugins/package.json | 2 +- examples/with-markdown-shiki/package.json | 2 +- examples/with-markdown/package.json | 4 +- examples/with-nanostores/package.json | 4 +- examples/with-tailwindcss/package.json | 2 +- examples/with-vite-plugin-pwa/package.json | 2 +- packages/astro/CHANGELOG.md | 30 ++++++++ packages/astro/package.json | 2 +- packages/integrations/partytown/CHANGELOG.md | 6 ++ packages/integrations/partytown/package.json | 2 +- packages/integrations/svelte/CHANGELOG.md | 6 ++ packages/integrations/svelte/package.json | 2 +- pnpm-lock.yaml | 68 +++++++++---------- 40 files changed, 113 insertions(+), 115 deletions(-) delete mode 100644 .changeset/cuddly-llamas-arrive.md delete mode 100644 .changeset/empty-chicken-refuse.md delete mode 100644 .changeset/neat-seas-peel.md delete mode 100644 .changeset/pink-shirts-mix.md delete mode 100644 .changeset/spotty-rockets-grow.md diff --git a/.changeset/cuddly-llamas-arrive.md b/.changeset/cuddly-llamas-arrive.md deleted file mode 100644 index 40942b606c34d..0000000000000 --- a/.changeset/cuddly-llamas-arrive.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@astrojs/partytown': patch ---- - -Include partytown scripts in SSR manifest diff --git a/.changeset/empty-chicken-refuse.md b/.changeset/empty-chicken-refuse.md deleted file mode 100644 index b473aa7b4d722..0000000000000 --- a/.changeset/empty-chicken-refuse.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'astro': patch -'@astrojs/svelte': patch ---- - -Fix PostCSS config not applied to Svelte component by default diff --git a/.changeset/neat-seas-peel.md b/.changeset/neat-seas-peel.md deleted file mode 100644 index 71ce868ccd15d..0000000000000 --- a/.changeset/neat-seas-peel.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -'astro': patch ---- - -Allow TypeScript inside script tags - -This makes it so that you can use TypeScript inside of script tags like so: - -```html - -``` - -Note that the the VSCode extension does not currently support this, however. diff --git a/.changeset/pink-shirts-mix.md b/.changeset/pink-shirts-mix.md deleted file mode 100644 index a1d14454aad90..0000000000000 --- a/.changeset/pink-shirts-mix.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"astro": patch ---- - -Fix a bug with `astro add react` adding a too-complex semver to your package.json diff --git a/.changeset/spotty-rockets-grow.md b/.changeset/spotty-rockets-grow.md deleted file mode 100644 index 68d4554322b29..0000000000000 --- a/.changeset/spotty-rockets-grow.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Allow specifying entryFileNames for client JS diff --git a/examples/basics/package.json b/examples/basics/package.json index 68ffeb727c381..e54ce11673b56 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/blog-multiple-authors/package.json b/examples/blog-multiple-authors/package.json index 3d84620a40d8b..4514566a1f27e 100644 --- a/examples/blog-multiple-authors/package.json +++ b/examples/blog-multiple-authors/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.1.3", - "astro": "^1.0.0-beta.52", + "astro": "^1.0.0-beta.53", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/blog/package.json b/examples/blog/package.json index 65855a94b283d..33680cad82e89 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.1.3", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/component/demo/package.json b/examples/component/demo/package.json index acd46723b5c9a..c91bf5b6b333b 100644 --- a/examples/component/demo/package.json +++ b/examples/component/demo/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@example/my-component": "workspace:*", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/component/package.json b/examples/component/package.json index 6ac119aed8abc..10cd44ec85e05 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -8,6 +8,6 @@ "serve": "astro --root demo preview" }, "devDependencies": { - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/docs/package.json b/examples/docs/package.json index c88176f086912..37720315e274d 100644 --- a/examples/docs/package.json +++ b/examples/docs/package.json @@ -20,6 +20,6 @@ "devDependencies": { "@astrojs/preact": "^0.1.3", "@astrojs/react": "^0.1.3", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/env-vars/package.json b/examples/env-vars/package.json index 4895561bfc7ee..f30366443dbcb 100644 --- a/examples/env-vars/package.json +++ b/examples/env-vars/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index 98f5af1c2b26c..07ca0542ced58 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" }, "dependencies": { "alpinejs": "^3.10.2" diff --git a/examples/framework-lit/package.json b/examples/framework-lit/package.json index 28213a6407e2c..d77a0ef434bc8 100644 --- a/examples/framework-lit/package.json +++ b/examples/framework-lit/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/lit": "^0.2.0", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index a9aa168a7d534..ec0a7766b6f06 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -13,9 +13,9 @@ "@astrojs/preact": "^0.1.3", "@astrojs/react": "^0.1.3", "@astrojs/solid-js": "^0.1.4", - "@astrojs/svelte": "^0.1.4", + "@astrojs/svelte": "^0.1.5", "@astrojs/vue": "^0.1.5", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index c090fc12b9cbc..1000353dec7bf 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.1.3", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index a73f01a9befdb..4a2ddf71cdc01 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -12,7 +12,7 @@ "@astrojs/react": "^0.1.3", "@types/react": "^18.0.10", "@types/react-dom": "^18.0.5", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" }, "dependencies": { "react": "^18.1.0", diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index 543ccf8c68d1c..0bf6eb47f7747 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/solid-js": "^0.1.4", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" }, "dependencies": { "solid-js": "^1.4.3" diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index 093a5607b7b55..61744cf86f699 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/svelte": "^0.1.4", - "astro": "^1.0.0-beta.52" + "@astrojs/svelte": "^0.1.5", + "astro": "^1.0.0-beta.53" }, "dependencies": { "svelte": "^3.48.0" diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 1ff7355d0c27d..9951b5603ba56 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/vue": "^0.1.5", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" }, "dependencies": { "vue": "^3.2.36" diff --git a/examples/integrations-playground/package.json b/examples/integrations-playground/package.json index 922b3b863293f..75bde1026eb88 100644 --- a/examples/integrations-playground/package.json +++ b/examples/integrations-playground/package.json @@ -10,13 +10,13 @@ }, "devDependencies": { "@astrojs/lit": "^0.2.0", - "@astrojs/partytown": "^0.1.4", + "@astrojs/partytown": "^0.1.5", "@astrojs/react": "^0.1.3", "@astrojs/sitemap": "^0.2.1", "@astrojs/solid-js": "0.1.4", "@astrojs/tailwind": "^0.2.1", "@astrojs/turbolinks": "^0.1.3", - "astro": "^1.0.0-beta.52", + "astro": "^1.0.0-beta.53", "solid-js": "^1.4.3" }, "dependencies": { diff --git a/examples/minimal/package.json b/examples/minimal/package.json index 08c740c4a730a..30445f8bff4f6 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/non-html-pages/package.json b/examples/non-html-pages/package.json index 9d629151524e3..9692f99838efd 100644 --- a/examples/non-html-pages/package.json +++ b/examples/non-html-pages/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index 8495bb2d3f3c7..6a7337ee42f3c 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.1.3", - "astro": "^1.0.0-beta.52", + "astro": "^1.0.0-beta.53", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/ssr/package.json b/examples/ssr/package.json index 5ef91c78a0699..51469fc4931ea 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -10,8 +10,8 @@ }, "devDependencies": { "@astrojs/node": "^0.1.2", - "@astrojs/svelte": "^0.1.4", - "astro": "^1.0.0-beta.52", + "@astrojs/svelte": "^0.1.5", + "astro": "^1.0.0-beta.53", "concurrently": "^7.2.1", "lightcookie": "^1.0.25", "unocss": "^0.15.6", diff --git a/examples/starter/package.json b/examples/starter/package.json index ebd0b9915df4c..4bcda5fdcef6f 100644 --- a/examples/starter/package.json +++ b/examples/starter/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/subpath/package.json b/examples/subpath/package.json index cb5c5f5058934..498daf7a7e9ba 100644 --- a/examples/subpath/package.json +++ b/examples/subpath/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/react": "^0.1.3", - "astro": "^1.0.0-beta.52", + "astro": "^1.0.0-beta.53", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/with-markdown-plugins/package.json b/examples/with-markdown-plugins/package.json index 6c997e4f3d05d..534fa609c3593 100644 --- a/examples/with-markdown-plugins/package.json +++ b/examples/with-markdown-plugins/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.52", + "astro": "^1.0.0-beta.53", "hast-util-select": "5.0.1", "rehype-autolink-headings": "^6.1.1", "rehype-slug": "^5.0.1", diff --git a/examples/with-markdown-shiki/package.json b/examples/with-markdown-shiki/package.json index 683b49c76be45..8c997012b4480 100644 --- a/examples/with-markdown-shiki/package.json +++ b/examples/with-markdown-shiki/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/with-markdown/package.json b/examples/with-markdown/package.json index c59c4f1eae4a2..f37e12498ed3a 100644 --- a/examples/with-markdown/package.json +++ b/examples/with-markdown/package.json @@ -12,9 +12,9 @@ "@astrojs/markdown-remark": "^0.11.3", "@astrojs/preact": "^0.1.3", "@astrojs/react": "^0.1.3", - "@astrojs/svelte": "^0.1.4", + "@astrojs/svelte": "^0.1.5", "@astrojs/vue": "^0.1.5", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" }, "dependencies": { "preact": "^10.7.3", diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index 5a9eba65fabe3..a729410fae60d 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -23,8 +23,8 @@ "@astrojs/preact": "^0.1.3", "@astrojs/react": "^0.1.3", "@astrojs/solid-js": "^0.1.4", - "@astrojs/svelte": "^0.1.4", + "@astrojs/svelte": "^0.1.5", "@astrojs/vue": "^0.1.5", - "astro": "^1.0.0-beta.52" + "astro": "^1.0.0-beta.53" } } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index b579cce2d5da1..794d193d4fe68 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/tailwind": "^0.2.1", - "astro": "^1.0.0-beta.52", + "astro": "^1.0.0-beta.53", "autoprefixer": "^10.4.7", "canvas-confetti": "^1.5.1", "postcss": "^8.4.14", diff --git a/examples/with-vite-plugin-pwa/package.json b/examples/with-vite-plugin-pwa/package.json index dac62f41891e4..965e461e1edaf 100644 --- a/examples/with-vite-plugin-pwa/package.json +++ b/examples/with-vite-plugin-pwa/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.52", + "astro": "^1.0.0-beta.53", "vite-plugin-pwa": "0.11.11", "workbox-window": "^6.5.3" } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index a164694eccc18..559b9b52ef0be 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,35 @@ # astro +## 1.0.0-beta.53 + +### Patch Changes + +- [#3685](https://github.com/withastro/astro/pull/3685) [`3d554fdb`](https://github.com/withastro/astro/commit/3d554fdbfb49d85d2945b7775825f7d9ace959ce) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix PostCSS config not applied to Svelte component by default + +* [#3665](https://github.com/withastro/astro/pull/3665) [`9a813268`](https://github.com/withastro/astro/commit/9a813268db2e3a7ed5644739b7a12e83e5d239b2) Thanks [@matthewp](https://github.com/matthewp)! - Allow TypeScript inside script tags + + This makes it so that you can use TypeScript inside of script tags like so: + + ```html + + ``` + + Note that the the VSCode extension does not currently support this, however. + +- [#3633](https://github.com/withastro/astro/pull/3633) [`921d9a27`](https://github.com/withastro/astro/commit/921d9a27e243c27e40e429a0a5c7d562d7b9633f) Thanks [@FredKSchott](https://github.com/FredKSchott)! - Fix a bug with `astro add react` adding a too-complex semver to your package.json + +* [#3676](https://github.com/withastro/astro/pull/3676) [`85c33751`](https://github.com/withastro/astro/commit/85c33751c20002e29bd646325a6e39f83cbb1f4d) Thanks [@matthewp](https://github.com/matthewp)! - Allow specifying entryFileNames for client JS + ## 1.0.0-beta.52 ### Patch Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index 97eb6a6483035..d145c497944b5 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "1.0.0-beta.52", + "version": "1.0.0-beta.53", "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.", "type": "module", "author": "withastro", diff --git a/packages/integrations/partytown/CHANGELOG.md b/packages/integrations/partytown/CHANGELOG.md index 4bcd931bf2dcd..aa79fa8a838aa 100644 --- a/packages/integrations/partytown/CHANGELOG.md +++ b/packages/integrations/partytown/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/partytown +## 0.1.5 + +### Patch Changes + +- [#3686](https://github.com/withastro/astro/pull/3686) [`b36ecb71`](https://github.com/withastro/astro/commit/b36ecb717e2cb623501c6d9a60471ac4daba43a8) Thanks [@matthewp](https://github.com/matthewp)! - Include partytown scripts in SSR manifest + ## 0.1.4 ### Patch Changes diff --git a/packages/integrations/partytown/package.json b/packages/integrations/partytown/package.json index ec00c34b0898c..8c25c1b423051 100644 --- a/packages/integrations/partytown/package.json +++ b/packages/integrations/partytown/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/partytown", "description": "Astro + Partytown integration", - "version": "0.1.4", + "version": "0.1.5", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/packages/integrations/svelte/CHANGELOG.md b/packages/integrations/svelte/CHANGELOG.md index 196ff9b3e735f..4e84b1fee2f60 100644 --- a/packages/integrations/svelte/CHANGELOG.md +++ b/packages/integrations/svelte/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/svelte +## 0.1.5 + +### Patch Changes + +- [#3685](https://github.com/withastro/astro/pull/3685) [`3d554fdb`](https://github.com/withastro/astro/commit/3d554fdbfb49d85d2945b7775825f7d9ace959ce) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix PostCSS config not applied to Svelte component by default + ## 0.1.4 ### Patch Changes diff --git a/packages/integrations/svelte/package.json b/packages/integrations/svelte/package.json index ea6a6829c580b..c25e0eb0a7102 100644 --- a/packages/integrations/svelte/package.json +++ b/packages/integrations/svelte/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/svelte", - "version": "0.1.4", + "version": "0.1.5", "description": "Use Svelte components within Astro", "type": "module", "types": "./dist/index.d.ts", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 60a6af258cdcf..520b204a42266 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,14 +49,14 @@ importers: examples/basics: specifiers: - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 devDependencies: astro: link:../../packages/astro examples/blog: specifiers: '@astrojs/preact': ^0.1.3 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -67,7 +67,7 @@ importers: examples/blog-multiple-authors: specifiers: '@astrojs/preact': ^0.1.3 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -79,14 +79,14 @@ importers: examples/component: specifiers: - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 devDependencies: astro: link:../../packages/astro examples/component/demo: specifiers: '@example/my-component': workspace:* - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 devDependencies: '@example/my-component': link:../packages/my-component astro: link:../../../packages/astro @@ -102,7 +102,7 @@ importers: '@docsearch/css': ^3.1.0 '@docsearch/react': ^3.1.0 '@types/react': ^17.0.45 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -121,14 +121,14 @@ importers: examples/env-vars: specifiers: - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 devDependencies: astro: link:../../packages/astro examples/framework-alpine: specifiers: alpinejs: ^3.10.2 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 dependencies: alpinejs: 3.10.2 devDependencies: @@ -138,7 +138,7 @@ importers: specifiers: '@astrojs/lit': ^0.2.0 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 lit: ^2.2.5 dependencies: '@webcomponents/template-shadowroot': 0.1.0 @@ -153,10 +153,10 @@ importers: '@astrojs/preact': ^0.1.3 '@astrojs/react': ^0.1.3 '@astrojs/solid-js': ^0.1.4 - '@astrojs/svelte': ^0.1.4 + '@astrojs/svelte': ^0.1.5 '@astrojs/vue': ^0.1.5 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -185,7 +185,7 @@ importers: examples/framework-preact: specifiers: '@astrojs/preact': ^0.1.3 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -198,7 +198,7 @@ importers: '@astrojs/react': ^0.1.3 '@types/react': ^18.0.10 '@types/react-dom': ^18.0.5 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 react: ^18.1.0 react-dom: ^18.1.0 dependencies: @@ -213,7 +213,7 @@ importers: examples/framework-solid: specifiers: '@astrojs/solid-js': ^0.1.4 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 solid-js: ^1.4.3 dependencies: solid-js: 1.4.3 @@ -223,8 +223,8 @@ importers: examples/framework-svelte: specifiers: - '@astrojs/svelte': ^0.1.4 - astro: ^1.0.0-beta.52 + '@astrojs/svelte': ^0.1.5 + astro: ^1.0.0-beta.53 svelte: ^3.48.0 dependencies: svelte: 3.48.0 @@ -235,7 +235,7 @@ importers: examples/framework-vue: specifiers: '@astrojs/vue': ^0.1.5 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 vue: ^3.2.36 dependencies: vue: 3.2.37 @@ -246,14 +246,14 @@ importers: examples/integrations-playground: specifiers: '@astrojs/lit': ^0.2.0 - '@astrojs/partytown': ^0.1.4 + '@astrojs/partytown': ^0.1.5 '@astrojs/react': ^0.1.3 '@astrojs/sitemap': ^0.2.1 '@astrojs/solid-js': 0.1.4 '@astrojs/tailwind': ^0.2.1 '@astrojs/turbolinks': ^0.1.3 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -282,20 +282,20 @@ importers: examples/minimal: specifiers: - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 devDependencies: astro: link:../../packages/astro examples/non-html-pages: specifiers: - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 devDependencies: astro: link:../../packages/astro examples/portfolio: specifiers: '@astrojs/preact': ^0.1.3 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -308,8 +308,8 @@ importers: examples/ssr: specifiers: '@astrojs/node': ^0.1.2 - '@astrojs/svelte': ^0.1.4 - astro: ^1.0.0-beta.52 + '@astrojs/svelte': ^0.1.5 + astro: ^1.0.0-beta.53 concurrently: ^7.2.1 lightcookie: ^1.0.25 svelte: ^3.48.0 @@ -328,14 +328,14 @@ importers: examples/starter: specifiers: - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 devDependencies: astro: link:../../packages/astro examples/subpath: specifiers: '@astrojs/react': ^0.1.3 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 react: ^18.1.0 react-dom: ^18.1.0 sass: ^1.52.2 @@ -352,9 +352,9 @@ importers: '@astrojs/markdown-remark': ^0.11.3 '@astrojs/preact': ^0.1.3 '@astrojs/react': ^0.1.3 - '@astrojs/svelte': ^0.1.4 + '@astrojs/svelte': ^0.1.5 '@astrojs/vue': ^0.1.5 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -377,7 +377,7 @@ importers: examples/with-markdown-plugins: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 hast-util-select: 5.0.1 rehype-autolink-headings: ^6.1.1 rehype-slug: ^5.0.1 @@ -395,7 +395,7 @@ importers: examples/with-markdown-shiki: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 devDependencies: '@astrojs/markdown-remark': link:../../packages/markdown/remark astro: link:../../packages/astro @@ -405,12 +405,12 @@ importers: '@astrojs/preact': ^0.1.3 '@astrojs/react': ^0.1.3 '@astrojs/solid-js': ^0.1.4 - '@astrojs/svelte': ^0.1.4 + '@astrojs/svelte': ^0.1.5 '@astrojs/vue': ^0.1.5 '@nanostores/preact': ^0.1.3 '@nanostores/react': ^0.1.5 '@nanostores/vue': ^0.4.1 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 nanostores: ^0.5.12 preact: ^10.7.3 react: ^18.1.0 @@ -438,7 +438,7 @@ importers: examples/with-tailwindcss: specifiers: '@astrojs/tailwind': ^0.2.1 - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 autoprefixer: ^10.4.7 canvas-confetti: ^1.5.1 postcss: ^8.4.14 @@ -453,7 +453,7 @@ importers: examples/with-vite-plugin-pwa: specifiers: - astro: ^1.0.0-beta.52 + astro: ^1.0.0-beta.53 vite-plugin-pwa: 0.11.11 workbox-window: ^6.5.3 devDependencies: From 7373d61cdcaedd64bf5fd60521b157cfa4343558 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 23 Jun 2022 10:10:54 -0500 Subject: [PATCH 09/58] Enable named slots in renderers (#3652) * feat: pass all slots to renderers * refactor: pass `slots` as top-level props * test: add named slot test for frameworks * fix: nested hydration, slots that are not initially rendered * test: add nested-recursive e2e test * fix: render unmatched custom element children * chore: update lockfile * fix: unrendered slots for client:only * fix(lit): ensure lit integration uses new slots API * chore: add changeset * chore: add changesets * fix: lit slots * feat: convert dash-case or snake_case slots to camelCase for JSX * feat: remove tmpl special logic * test: add slot components-in-markdown test * refactor: prefer Object.entries.map() to for/of loop Co-authored-by: Nate Moore --- .changeset/clever-pumpkins-begin.md | 7 ++ .changeset/lovely-bulldogs-admire.md | 29 ++++++ .changeset/mean-ears-mate.md | 7 ++ .changeset/tough-ants-rest.md | 8 ++ .../nested-recursive/astro.config.mjs | 12 +++ .../fixtures/nested-recursive/package.json | 24 +++++ .../src/components/PreactCounter.tsx | 17 ++++ .../src/components/ReactCounter.jsx | 17 ++++ .../src/components/SolidCounter.tsx | 17 ++++ .../src/components/SvelteCounter.svelte | 29 ++++++ .../src/components/VueCounter.vue | 34 +++++++ .../nested-recursive/src/pages/index.astro | 28 ++++++ packages/astro/e2e/nested-recursive.test.js | 96 +++++++++++++++++++ packages/astro/src/@types/astro.ts | 2 +- .../astro/src/runtime/server/astro-island.ts | 27 +++--- packages/astro/src/runtime/server/index.ts | 51 +++++++--- .../lit-element/src/components/my-element.js | 4 + .../lit-element/src/pages/slots.astro | 15 +++ .../slots-preact/src/components/Counter.jsx | 4 +- .../slots-preact/src/pages/index.astro | 2 + .../slots-preact/src/pages/markdown.md | 9 ++ .../slots-react/src/components/Counter.jsx | 4 +- .../slots-react/src/pages/index.astro | 2 + .../slots-react/src/pages/markdown.md | 9 ++ .../slots-solid/src/components/Counter.jsx | 4 +- .../slots-solid/src/pages/index.astro | 2 + .../slots-solid/src/pages/markdown.md | 9 ++ .../src/components/Counter.svelte | 4 +- .../slots-svelte/src/pages/index.astro | 8 +- .../slots-svelte/src/pages/markdown.md | 9 ++ .../slots-vue/src/components/Counter.vue | 2 + .../fixtures/slots-vue/src/pages/index.astro | 2 + .../fixtures/slots-vue/src/pages/markdown.md | 9 ++ packages/astro/test/lit-element.test.js | 19 ++++ packages/astro/test/slots-preact.test.js | 32 +++++++ packages/astro/test/slots-react.test.js | 32 +++++++ packages/astro/test/slots-solid.test.js | 32 +++++++ packages/astro/test/slots-svelte.test.js | 34 ++++++- packages/astro/test/slots-vue.test.js | 32 +++++++ packages/integrations/lit/server.js | 16 +++- packages/integrations/preact/client.js | 5 +- packages/integrations/preact/server.js | 13 ++- packages/integrations/preact/static-html.js | 4 +- packages/integrations/react/client-v17.js | 5 +- packages/integrations/react/client.js | 5 +- packages/integrations/react/server-v17.js | 15 ++- packages/integrations/react/server.js | 15 ++- packages/integrations/react/static-html.js | 5 +- packages/integrations/solid/client.js | 38 ++++---- packages/integrations/solid/server.js | 29 +++--- packages/integrations/solid/static-html.js | 12 --- packages/integrations/svelte/Wrapper.svelte | 21 ---- .../integrations/svelte/Wrapper.svelte.ssr.js | 19 ---- packages/integrations/svelte/client.js | 36 ++++++- packages/integrations/svelte/server.js | 14 ++- packages/integrations/vue/client.js | 6 +- packages/integrations/vue/server.js | 6 +- packages/integrations/vue/static-html.js | 5 +- packages/webapi/mod.d.ts | 2 +- pnpm-lock.yaml | 29 ++++++ 60 files changed, 827 insertions(+), 157 deletions(-) create mode 100644 .changeset/clever-pumpkins-begin.md create mode 100644 .changeset/lovely-bulldogs-admire.md create mode 100644 .changeset/mean-ears-mate.md create mode 100644 .changeset/tough-ants-rest.md create mode 100644 packages/astro/e2e/fixtures/nested-recursive/astro.config.mjs create mode 100644 packages/astro/e2e/fixtures/nested-recursive/package.json create mode 100644 packages/astro/e2e/fixtures/nested-recursive/src/components/PreactCounter.tsx create mode 100644 packages/astro/e2e/fixtures/nested-recursive/src/components/ReactCounter.jsx create mode 100644 packages/astro/e2e/fixtures/nested-recursive/src/components/SolidCounter.tsx create mode 100644 packages/astro/e2e/fixtures/nested-recursive/src/components/SvelteCounter.svelte create mode 100644 packages/astro/e2e/fixtures/nested-recursive/src/components/VueCounter.vue create mode 100644 packages/astro/e2e/fixtures/nested-recursive/src/pages/index.astro create mode 100644 packages/astro/e2e/nested-recursive.test.js create mode 100644 packages/astro/test/fixtures/lit-element/src/pages/slots.astro create mode 100644 packages/astro/test/fixtures/slots-preact/src/pages/markdown.md create mode 100644 packages/astro/test/fixtures/slots-react/src/pages/markdown.md create mode 100644 packages/astro/test/fixtures/slots-solid/src/pages/markdown.md create mode 100644 packages/astro/test/fixtures/slots-svelte/src/pages/markdown.md create mode 100644 packages/astro/test/fixtures/slots-vue/src/pages/markdown.md delete mode 100644 packages/integrations/solid/static-html.js delete mode 100644 packages/integrations/svelte/Wrapper.svelte delete mode 100644 packages/integrations/svelte/Wrapper.svelte.ssr.js diff --git a/.changeset/clever-pumpkins-begin.md b/.changeset/clever-pumpkins-begin.md new file mode 100644 index 0000000000000..26b9e5f18f948 --- /dev/null +++ b/.changeset/clever-pumpkins-begin.md @@ -0,0 +1,7 @@ +--- +'@astrojs/lit': minor +--- + +Adds support for passing named slots from `.astro` => Lit components. + +All slots are treated as Light DOM content. diff --git a/.changeset/lovely-bulldogs-admire.md b/.changeset/lovely-bulldogs-admire.md new file mode 100644 index 0000000000000..74888cb27df2d --- /dev/null +++ b/.changeset/lovely-bulldogs-admire.md @@ -0,0 +1,29 @@ +--- +'@astrojs/preact': minor +'@astrojs/react': minor +'@astrojs/solid-js': minor +--- + +Add support for passing named slots from `.astro` => framework components. + +Each `slot` is be passed as a top-level prop. For example: + +```jsx +// From .astro + +

Hello world!

+

Dash

+
Default
+
+ +// For .jsx +export default function Component({ title, slotWithDash, children }) { + return ( + <> +
{title}
+
{slotWithDash}
+
{children}
+ + ) +} +``` diff --git a/.changeset/mean-ears-mate.md b/.changeset/mean-ears-mate.md new file mode 100644 index 0000000000000..6bb538e4e9865 --- /dev/null +++ b/.changeset/mean-ears-mate.md @@ -0,0 +1,7 @@ +--- +'astro': patch +--- + +Add renderer support for passing named slots to framework components. + +**BREAKING**: integrations using the `addRenderer()` API are now passed all named slots via `Record` rather than `string`. Previously only the default slot was passed. diff --git a/.changeset/tough-ants-rest.md b/.changeset/tough-ants-rest.md new file mode 100644 index 0000000000000..f95ae30c2134e --- /dev/null +++ b/.changeset/tough-ants-rest.md @@ -0,0 +1,8 @@ +--- +'@astrojs/svelte': minor +'@astrojs/vue': minor +--- + +Adds support for passing named slots from `.astro` => framework components. + +Inside your components, use the built-in `slot` API as you normally would. diff --git a/packages/astro/e2e/fixtures/nested-recursive/astro.config.mjs b/packages/astro/e2e/fixtures/nested-recursive/astro.config.mjs new file mode 100644 index 0000000000000..4b50887cd70c0 --- /dev/null +++ b/packages/astro/e2e/fixtures/nested-recursive/astro.config.mjs @@ -0,0 +1,12 @@ +import { defineConfig } from 'astro/config'; +import preact from '@astrojs/preact'; +import react from '@astrojs/react'; +import svelte from '@astrojs/svelte'; +import vue from '@astrojs/vue'; +import solid from '@astrojs/solid-js'; + +// https://astro.build/config +export default defineConfig({ + // Enable many frameworks to support all different kinds of components. + integrations: [preact(), react(), svelte(), vue(), solid()], +}); diff --git a/packages/astro/e2e/fixtures/nested-recursive/package.json b/packages/astro/e2e/fixtures/nested-recursive/package.json new file mode 100644 index 0000000000000..3376ef59616f7 --- /dev/null +++ b/packages/astro/e2e/fixtures/nested-recursive/package.json @@ -0,0 +1,24 @@ +{ + "name": "@e2e/nested-recursive", + "version": "0.0.0", + "private": true, + "devDependencies": { + "@astrojs/preact": "workspace:*", + "@astrojs/react": "workspace:*", + "@astrojs/solid-js": "workspace:*", + "@astrojs/svelte": "workspace:*", + "@astrojs/vue": "workspace:*", + "astro": "workspace:*" + }, + "dependencies": { + "preact": "^10.7.3", + "react": "^18.1.0", + "react-dom": "^18.1.0", + "solid-js": "^1.4.3", + "svelte": "^3.48.0", + "vue": "^3.2.36" + }, + "scripts": { + "dev": "astro dev" + } +} diff --git a/packages/astro/e2e/fixtures/nested-recursive/src/components/PreactCounter.tsx b/packages/astro/e2e/fixtures/nested-recursive/src/components/PreactCounter.tsx new file mode 100644 index 0000000000000..32200f41f64b0 --- /dev/null +++ b/packages/astro/e2e/fixtures/nested-recursive/src/components/PreactCounter.tsx @@ -0,0 +1,17 @@ +import { useState } from 'preact/hooks'; + +/** a counter written in Preact */ +export default function PreactCounter({ children, id }) { + const [count, setCount] = useState(0); + const add = () => setCount((i) => i + 1); + const subtract = () => setCount((i) => i - 1); + + return ( +
+ +
{count}
+ +
{children}
+
+ ); +} diff --git a/packages/astro/e2e/fixtures/nested-recursive/src/components/ReactCounter.jsx b/packages/astro/e2e/fixtures/nested-recursive/src/components/ReactCounter.jsx new file mode 100644 index 0000000000000..6b3a1de5f1672 --- /dev/null +++ b/packages/astro/e2e/fixtures/nested-recursive/src/components/ReactCounter.jsx @@ -0,0 +1,17 @@ +import { useState } from 'react'; + +/** a counter written in React */ +export default function ReactCounter({ children, id }) { + const [count, setCount] = useState(0); + const add = () => setCount((i) => i + 1); + const subtract = () => setCount((i) => i - 1); + + return ( +
+ +
{count}
+ +
{children}
+
+ ); +} diff --git a/packages/astro/e2e/fixtures/nested-recursive/src/components/SolidCounter.tsx b/packages/astro/e2e/fixtures/nested-recursive/src/components/SolidCounter.tsx new file mode 100644 index 0000000000000..afabe43b9e812 --- /dev/null +++ b/packages/astro/e2e/fixtures/nested-recursive/src/components/SolidCounter.tsx @@ -0,0 +1,17 @@ +import { createSignal } from 'solid-js'; + +/** a counter written with Solid */ +export default function SolidCounter({ children, id }) { + const [count, setCount] = createSignal(0); + const add = () => setCount(count() + 1); + const subtract = () => setCount(count() - 1); + + return ( +
+ +
{count()}
+ +
{children}
+
+ ); +} diff --git a/packages/astro/e2e/fixtures/nested-recursive/src/components/SvelteCounter.svelte b/packages/astro/e2e/fixtures/nested-recursive/src/components/SvelteCounter.svelte new file mode 100644 index 0000000000000..733f58076a24a --- /dev/null +++ b/packages/astro/e2e/fixtures/nested-recursive/src/components/SvelteCounter.svelte @@ -0,0 +1,29 @@ + + + +
+ +
{ count }
+ +
+ +
+
+ + diff --git a/packages/astro/e2e/fixtures/nested-recursive/src/components/VueCounter.vue b/packages/astro/e2e/fixtures/nested-recursive/src/components/VueCounter.vue new file mode 100644 index 0000000000000..d404cc965c528 --- /dev/null +++ b/packages/astro/e2e/fixtures/nested-recursive/src/components/VueCounter.vue @@ -0,0 +1,34 @@ + + + diff --git a/packages/astro/e2e/fixtures/nested-recursive/src/pages/index.astro b/packages/astro/e2e/fixtures/nested-recursive/src/pages/index.astro new file mode 100644 index 0000000000000..685c7fb5ed705 --- /dev/null +++ b/packages/astro/e2e/fixtures/nested-recursive/src/pages/index.astro @@ -0,0 +1,28 @@ +--- +import ReactCounter from '../components/ReactCounter.jsx'; +import PreactCounter from '../components/PreactCounter.tsx'; +import SolidCounter from '../components/SolidCounter.tsx'; +import VueCounter from '../components/VueCounter.vue'; +import SvelteCounter from '../components/SvelteCounter.svelte'; +--- + + + + + + + + +
+ + + + + + + + + +
+ + diff --git a/packages/astro/e2e/nested-recursive.test.js b/packages/astro/e2e/nested-recursive.test.js new file mode 100644 index 0000000000000..ae981189a6194 --- /dev/null +++ b/packages/astro/e2e/nested-recursive.test.js @@ -0,0 +1,96 @@ +import { test as base, expect } from '@playwright/test'; +import { loadFixture } from './test-utils.js'; + +const test = base.extend({ + astro: async ({}, use) => { + const fixture = await loadFixture({ root: './fixtures/nested-recursive/' }); + await use(fixture); + }, +}); + +let devServer; + +test.beforeEach(async ({ astro }) => { + devServer = await astro.startDevServer(); +}); + +test.afterEach(async () => { + await devServer.stop(); +}); + +test.describe('Recursive Nested Frameworks', () => { + test('React counter', async ({ astro, page }) => { + await page.goto('/'); + + const counter = await page.locator('#react-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('#react-counter-count'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const increment = await counter.locator('#react-counter-increment'); + await increment.click(); + + await expect(count, 'count incremented by 1').toHaveText('1'); + }); + + test('Preact counter', async ({ astro, page }) => { + await page.goto('/'); + + const counter = await page.locator('#preact-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('#preact-counter-count'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const increment = await counter.locator('#preact-counter-increment'); + await increment.click(); + + await expect(count, 'count incremented by 1').toHaveText('1'); + }); + + test('Solid counter', async ({ astro, page }) => { + await page.goto('/'); + + const counter = await page.locator('#solid-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('#solid-counter-count'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const increment = await counter.locator('#solid-counter-increment'); + await increment.click(); + + await expect(count, 'count incremented by 1').toHaveText('1'); + }); + + test('Vue counter', async ({ astro, page }) => { + await page.goto('/'); + + const counter = await page.locator('#vue-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('#vue-counter-count'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const increment = await counter.locator('#vue-counter-increment'); + await increment.click(); + + await expect(count, 'count incremented by 1').toHaveText('1'); + }); + + test('Svelte counter', async ({ astro, page }) => { + await page.goto('/'); + + const counter = await page.locator('#svelte-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('#svelte-counter-count'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const increment = await counter.locator('#svelte-counter-increment'); + await increment.click(); + + await expect(count, 'count incremented by 1').toHaveText('1'); + }); +}); diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index dc2af7db33a7a..d2ef923654f64 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -737,7 +737,7 @@ export interface AstroConfig extends z.output { export type AsyncRendererComponentFn = ( Component: any, props: any, - children: string | undefined, + slots: Record, metadata?: AstroComponentMetadata ) => Promise; diff --git a/packages/astro/src/runtime/server/astro-island.ts b/packages/astro/src/runtime/server/astro-island.ts index a067c9a5703ec..10c69aa8e66ba 100644 --- a/packages/astro/src/runtime/server/astro-island.ts +++ b/packages/astro/src/runtime/server/astro-island.ts @@ -64,23 +64,24 @@ declare const Astro: { if (!this.hydrator || this.parentElement?.closest('astro-island[ssr]')) { return; } - let innerHTML: string | null = null; - let fragment = this.querySelector('astro-fragment'); - if (fragment == null && this.hasAttribute('tmpl')) { - // If there is no child fragment, check to see if there is a template. - // This happens if children were passed but the client component did not render any. - let template = this.querySelector('template[data-astro-template]'); - if (template) { - innerHTML = template.innerHTML; - template.remove(); - } - } else if (fragment) { - innerHTML = fragment.innerHTML; + const slotted = this.querySelectorAll('astro-slot'); + const slots: Record = {}; + // Always check to see if there are templates. + // This happens if slots were passed but the client component did not render them. + const templates = this.querySelectorAll('template[data-astro-template]'); + for (const template of templates) { + if (!template.closest(this.tagName)?.isSameNode(this)) continue; + slots[template.getAttribute('data-astro-template') || 'default'] = template.innerHTML; + template.remove(); + } + for (const slot of slotted) { + if (!slot.closest(this.tagName)?.isSameNode(this)) continue; + slots[slot.getAttribute('name') || 'default'] = slot.innerHTML; } const props = this.hasAttribute('props') ? JSON.parse(this.getAttribute('props')!, reviver) : {}; - this.hydrator(this)(this.Component, props, innerHTML, { + this.hydrator(this)(this.Component, props, slots, { client: this.getAttribute('client'), }); this.removeAttribute('ssr'); diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 6c7b126993697..1b78d71713325 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -208,7 +208,16 @@ Did you mean to add ${formatList(probableRendererNames.map((r) => '`' + r + '`') throw new Error(message); } - const children = await renderSlot(result, slots?.default); + const children: Record = {}; + if (slots) { + await Promise.all( + Object.entries(slots).map(([key, value]) => + renderSlot(result, value as string).then((output) => { + children[key] = output; + }) + ) + ); + } // Call the renderers `check` hook to see if any claim this component. let renderer: SSRLoadedRenderer | undefined; if (metadata.hydrate !== 'only') { @@ -307,11 +316,12 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr // This is a custom element without a renderer. Because of that, render it // as a string and the user is responsible for adding a script tag for the component definition. if (!html && typeof Component === 'string') { + const childSlots = Object.values(children).join(''); html = await renderAstroComponent( await render`<${Component}${internalSpreadAttributes(props)}${markHTMLString( - (children == null || children == '') && voidElementNames.test(Component) + childSlots === '' && voidElementNames.test(Component) ? `/>` - : `>${children == null ? '' : children}` + : `>${childSlots}` )}` ); } @@ -320,7 +330,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr if (isPage) { return html; } - return markHTMLString(html.replace(/\<\/?astro-fragment\>/g, '')); + return markHTMLString(html.replace(/\<\/?astro-slot\>/g, '')); } // Include componentExport name, componentUrl, and props in hash to dedupe identical islands @@ -336,13 +346,30 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr ); result._metadata.needsHydrationStyles = true; - // Render a template if no fragment is provided. - const needsAstroTemplate = children && !/<\/?astro-fragment\>/.test(html); - const template = needsAstroTemplate ? `` : ''; - - if (needsAstroTemplate) { - island.props.tmpl = ''; - } + // Render template if not all astro fragments are provided. + let unrenderedSlots: string[] = []; + if (html) { + if (Object.keys(children).length > 0) { + for (const key of Object.keys(children)) { + if (!html.includes(key === 'default' ? `` : ``)) { + unrenderedSlots.push(key); + } + } + } + } else { + unrenderedSlots = Object.keys(children); + } + const template = + unrenderedSlots.length > 0 + ? unrenderedSlots + .map( + (key) => + `` + ) + .join('') + : ''; island.children = `${html ?? ''}${template}`; @@ -652,7 +679,7 @@ export async function renderHead(result: SSRResult): Promise { styles.push( renderElement('style', { props: {}, - children: 'astro-island, astro-fragment { display: contents; }', + children: 'astro-island, astro-slot { display: contents; }', }) ); } diff --git a/packages/astro/test/fixtures/lit-element/src/components/my-element.js b/packages/astro/test/fixtures/lit-element/src/components/my-element.js index b2cf72dea8b31..e946924cf7ff1 100644 --- a/packages/astro/test/fixtures/lit-element/src/components/my-element.js +++ b/packages/astro/test/fixtures/lit-element/src/components/my-element.js @@ -29,6 +29,10 @@ export class MyElement extends LitElement {
${this.str}
data: ${this.obj.data}
${typeofwindow}
+ + +
+
`; } } diff --git a/packages/astro/test/fixtures/lit-element/src/pages/slots.astro b/packages/astro/test/fixtures/lit-element/src/pages/slots.astro new file mode 100644 index 0000000000000..b8fc4963c6f01 --- /dev/null +++ b/packages/astro/test/fixtures/lit-element/src/pages/slots.astro @@ -0,0 +1,15 @@ +--- +import {MyElement} from '../components/my-element.js'; +--- + + + + LitElement | Slot + + + +
default
+
named
+
+ + diff --git a/packages/astro/test/fixtures/slots-preact/src/components/Counter.jsx b/packages/astro/test/fixtures/slots-preact/src/components/Counter.jsx index cc11b9ee3fd40..16d2a95b948b0 100644 --- a/packages/astro/test/fixtures/slots-preact/src/components/Counter.jsx +++ b/packages/astro/test/fixtures/slots-preact/src/components/Counter.jsx @@ -1,7 +1,7 @@ import { h, Fragment } from 'preact'; import { useState } from 'preact/hooks' -export default function Counter({ children, count: initialCount, case: id }) { +export default function Counter({ named, dashCase, children, count: initialCount, case: id }) { const [count, setCount] = useState(initialCount); const add = () => setCount((i) => i + 1); const subtract = () => setCount((i) => i - 1); @@ -15,6 +15,8 @@ export default function Counter({ children, count: initialCount, case: id }) {
{children ||

Fallback

} + {named} + {dashCase}
); diff --git a/packages/astro/test/fixtures/slots-preact/src/pages/index.astro b/packages/astro/test/fixtures/slots-preact/src/pages/index.astro index f8f101e73ecfe..b2b039566b2d4 100644 --- a/packages/astro/test/fixtures/slots-preact/src/pages/index.astro +++ b/packages/astro/test/fixtures/slots-preact/src/pages/index.astro @@ -8,4 +8,6 @@ import Counter from '../components/Counter.jsx' {false} {''}

Hello world!

+

/ Named

+

/ Dash Case

diff --git a/packages/astro/test/fixtures/slots-preact/src/pages/markdown.md b/packages/astro/test/fixtures/slots-preact/src/pages/markdown.md new file mode 100644 index 0000000000000..f86720fea9e08 --- /dev/null +++ b/packages/astro/test/fixtures/slots-preact/src/pages/markdown.md @@ -0,0 +1,9 @@ +--- +setup: import Counter from '../components/Counter.jsx' +--- + +# Slots: Preact + +

Hello world!

+

/ Named

+

/ Dash Case

diff --git a/packages/astro/test/fixtures/slots-react/src/components/Counter.jsx b/packages/astro/test/fixtures/slots-react/src/components/Counter.jsx index 93f267ca4ffb7..733cc47cc0502 100644 --- a/packages/astro/test/fixtures/slots-react/src/components/Counter.jsx +++ b/packages/astro/test/fixtures/slots-react/src/components/Counter.jsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; -export default function Counter({ children, count: initialCount, case: id }) { +export default function Counter({ named, dashCase, children, count: initialCount, case: id }) { const [count, setCount] = useState(initialCount); const add = () => setCount((i) => i + 1); const subtract = () => setCount((i) => i - 1); @@ -14,6 +14,8 @@ export default function Counter({ children, count: initialCount, case: id }) {
{children ||

Fallback

} + {named} + {dashCase}
); diff --git a/packages/astro/test/fixtures/slots-react/src/pages/index.astro b/packages/astro/test/fixtures/slots-react/src/pages/index.astro index f8f101e73ecfe..b2b039566b2d4 100644 --- a/packages/astro/test/fixtures/slots-react/src/pages/index.astro +++ b/packages/astro/test/fixtures/slots-react/src/pages/index.astro @@ -8,4 +8,6 @@ import Counter from '../components/Counter.jsx' {false} {''}

Hello world!

+

/ Named

+

/ Dash Case

diff --git a/packages/astro/test/fixtures/slots-react/src/pages/markdown.md b/packages/astro/test/fixtures/slots-react/src/pages/markdown.md new file mode 100644 index 0000000000000..3084505061641 --- /dev/null +++ b/packages/astro/test/fixtures/slots-react/src/pages/markdown.md @@ -0,0 +1,9 @@ +--- +setup: import Counter from '../components/Counter.jsx' +--- + +# Slots: React + +

Hello world!

+

/ Named

+

/ Dash Case

diff --git a/packages/astro/test/fixtures/slots-solid/src/components/Counter.jsx b/packages/astro/test/fixtures/slots-solid/src/components/Counter.jsx index 6a585b8e3c4ec..4b9c63c667224 100644 --- a/packages/astro/test/fixtures/slots-solid/src/components/Counter.jsx +++ b/packages/astro/test/fixtures/slots-solid/src/components/Counter.jsx @@ -1,6 +1,6 @@ import { createSignal } from 'solid-js'; -export default function Counter({ children, count: initialCount, case: id }) { +export default function Counter({ named, dashCase, children, count: initialCount, case: id }) { const [count] = createSignal(0); return ( <> @@ -9,6 +9,8 @@ export default function Counter({ children, count: initialCount, case: id }) {
{children ||

Fallback

} + {named} + {dashCase}
); diff --git a/packages/astro/test/fixtures/slots-solid/src/pages/index.astro b/packages/astro/test/fixtures/slots-solid/src/pages/index.astro index f8f101e73ecfe..b2b039566b2d4 100644 --- a/packages/astro/test/fixtures/slots-solid/src/pages/index.astro +++ b/packages/astro/test/fixtures/slots-solid/src/pages/index.astro @@ -8,4 +8,6 @@ import Counter from '../components/Counter.jsx' {false} {''}

Hello world!

+

/ Named

+

/ Dash Case

diff --git a/packages/astro/test/fixtures/slots-solid/src/pages/markdown.md b/packages/astro/test/fixtures/slots-solid/src/pages/markdown.md new file mode 100644 index 0000000000000..d9bc2dabd07ad --- /dev/null +++ b/packages/astro/test/fixtures/slots-solid/src/pages/markdown.md @@ -0,0 +1,9 @@ +--- +setup: import Counter from '../components/Counter.jsx' +--- + +# Slots: Solid + +

Hello world!

+

/ Named

+

/ Dash Case

diff --git a/packages/astro/test/fixtures/slots-svelte/src/components/Counter.svelte b/packages/astro/test/fixtures/slots-svelte/src/components/Counter.svelte index 11901049e9246..24f4e734e658f 100644 --- a/packages/astro/test/fixtures/slots-svelte/src/components/Counter.svelte +++ b/packages/astro/test/fixtures/slots-svelte/src/components/Counter.svelte @@ -17,9 +17,7 @@
- -

Fallback

-
+

Fallback

diff --git a/packages/astro/e2e/fixtures/vue-component/src/components/Result.vue b/packages/astro/e2e/fixtures/vue-component/src/components/VueComponent.vue similarity index 53% rename from packages/astro/e2e/fixtures/vue-component/src/components/Result.vue rename to packages/astro/e2e/fixtures/vue-component/src/components/VueComponent.vue index 90bf218b25538..ab0cee328266d 100644 --- a/packages/astro/e2e/fixtures/vue-component/src/components/Result.vue +++ b/packages/astro/e2e/fixtures/vue-component/src/components/VueComponent.vue @@ -1,14 +1,13 @@ `; + return ``; case 'directive': return ``; } diff --git a/packages/astro/test/0-css.test.js b/packages/astro/test/0-css.test.js index e1b317f32d284..4b2862470c9f0 100644 --- a/packages/astro/test/0-css.test.js +++ b/packages/astro/test/0-css.test.js @@ -65,7 +65,7 @@ describe('CSS', function () { it('Using hydrated components adds astro-island styles', async () => { const inline = $('style').html(); - expect(inline).to.include('display: contents'); + expect(inline).to.include('display:contents'); }); it(' + + +

testing

+ + diff --git a/packages/webapi/mod.d.ts b/packages/webapi/mod.d.ts index a3c49dc5c406f..b385e82a5e294 100644 --- a/packages/webapi/mod.d.ts +++ b/packages/webapi/mod.d.ts @@ -1,5 +1,5 @@ export { pathToPosix } from './lib/utils'; -export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter } from './mod.js'; +export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; export declare const polyfill: { (target: any, options?: PolyfillOptions): any; internals(target: any, name: string): any; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 70337edc66ee1..c9274296240e2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -463,7 +463,7 @@ importers: packages/astro: specifiers: - '@astrojs/compiler': ^0.16.1 + '@astrojs/compiler': ^0.17.0 '@astrojs/language-server': ^0.13.4 '@astrojs/markdown-remark': ^0.11.3 '@astrojs/prism': 0.4.1 @@ -547,7 +547,7 @@ importers: yargs-parser: ^21.0.1 zod: ^3.17.3 dependencies: - '@astrojs/compiler': 0.16.1 + '@astrojs/compiler': 0.17.0 '@astrojs/language-server': 0.13.4 '@astrojs/markdown-remark': link:../markdown/remark '@astrojs/prism': link:../astro-prism @@ -2439,8 +2439,8 @@ packages: leven: 3.1.0 dev: true - /@astrojs/compiler/0.16.1: - resolution: {integrity: sha512-6l5j9b/sEdyqRUvwJpp+SmlAkNO5WeISuNEXnyH9aGwzIAdqgLB2boAJef9lWadlOjG8rSPO29WHRa3qS2Okew==} + /@astrojs/compiler/0.17.0: + resolution: {integrity: sha512-3q6Yw6CGDfUwheDS29cHjQxn57ql0X98DskU6ym3bw/FdD8RMbGi0Es1Evlh+WHig948LUcYq19EHAMZO3bP3w==} dev: false /@astrojs/language-server/0.13.4: From 3dc22a244372e0a759c4517a3968ea4a4169c3d0 Mon Sep 17 00:00:00 2001 From: matthewp Date: Thu, 23 Jun 2022 19:39:58 +0000 Subject: [PATCH 17/58] [ci] format --- packages/astro/src/core/render/core.ts | 2 +- packages/astro/src/runtime/server/index.ts | 10 ++++------ packages/astro/src/runtime/server/scripts.ts | 4 +++- packages/webapi/mod.d.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index 32641c0208719..b718b4d28f52c 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -9,7 +9,7 @@ import type { } from '../../@types/astro'; import type { LogOptions } from '../logger/core.js'; -import { renderComponent, renderHead, renderPage } from '../../runtime/server/index.js'; +import { renderComponent, renderPage } from '../../runtime/server/index.js'; import { getParams } from '../routing/params.js'; import { createResult } from './result.js'; import { callGetStaticPaths, findPathItemByKey, RouteCache } from './route-cache.js'; diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 322e212df658f..8c58711c58989 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -662,17 +662,15 @@ export async function renderHead(result: SSRResult): Promise { const links = Array.from(result.links) .filter(uniqueElements) .map((link) => renderElement('link', link, false)); - return markHTMLString( - links.join('\n') + styles.join('\n') + scripts.join('\n') - ); + return markHTMLString(links.join('\n') + styles.join('\n') + scripts.join('\n')); } // This function is called by Astro components that do not contain a component // This accomodates the fact that using a is optional in Astro, so this -// is called before a component's first non-head HTML element. If the head was -// already injected it is a noop. +// is called before a component's first non-head HTML element. If the head was +// already injected it is a noop. export function maybeRenderHead(result: SSRResult): string | Promise { - if(alreadyHeadRenderedResults.has(result)) { + if (alreadyHeadRenderedResults.has(result)) { return ''; } return renderHead(result); diff --git a/packages/astro/src/runtime/server/scripts.ts b/packages/astro/src/runtime/server/scripts.ts index 4fe7b9057e7ad..2dba232f9c6e9 100644 --- a/packages/astro/src/runtime/server/scripts.ts +++ b/packages/astro/src/runtime/server/scripts.ts @@ -59,7 +59,9 @@ export function getPrescripts(type: PrescriptType, directive: string): string { // deps to be loaded immediately. switch (type) { case 'both': - return ``; + return ``; case 'directive': return ``; } diff --git a/packages/webapi/mod.d.ts b/packages/webapi/mod.d.ts index b385e82a5e294..a3c49dc5c406f 100644 --- a/packages/webapi/mod.d.ts +++ b/packages/webapi/mod.d.ts @@ -1,5 +1,5 @@ export { pathToPosix } from './lib/utils'; -export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; +export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter } from './mod.js'; export declare const polyfill: { (target: any, options?: PolyfillOptions): any; internals(target: any, name: string): any; From fd0a24c424dfdfbedc66852b0a3e35d908ab0da4 Mon Sep 17 00:00:00 2001 From: dperolio Date: Thu, 23 Jun 2022 21:24:43 -0400 Subject: [PATCH 18/58] fix run-on sentence (#3699) --- packages/astro/src/core/logger/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/core/logger/core.ts b/packages/astro/src/core/logger/core.ts index 9e4da4b8ed45c..06296208613ae 100644 --- a/packages/astro/src/core/logger/core.ts +++ b/packages/astro/src/core/logger/core.ts @@ -137,7 +137,7 @@ export function warnIfUsingExperimentalSSR(opts: LogOptions, config: AstroConfig opts, 'warning', bold(`Warning:`), - `SSR support is still experimental and subject to API changes. If using in production pin your dependencies to prevent accidental breakage.` + `SSR support is still experimental and subject to API changes. If using in production, pin your dependencies to prevent accidental breakage.` ); } } From 3e6ed5d1bc80b55fed1e1b01a4c8d9398d5cd543 Mon Sep 17 00:00:00 2001 From: FredKSchott Date: Fri, 24 Jun 2022 12:02:05 +0000 Subject: [PATCH 19/58] [ci] collect stats --- scripts/stats/stats.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/stats/stats.csv b/scripts/stats/stats.csv index 22035d18fcc39..00df1110c008c 100644 --- a/scripts/stats/stats.csv +++ b/scripts/stats/stats.csv @@ -1,4 +1,5 @@ Date,Commits (24hr),Issues (24hr),Issues:BUG (24hr),Issues:RFC (24hr),Issues:DOC (24hr),PRs (24hr),Open PRs,Open Issues,Bugs: Needs Triage,Bugs: Accepted,RFC: In Progress,RFC: Accepted,Date (ISO) +"Friday, June 24, 2022",14,3,3,0,0,8,21,75,51,16,0,0,"2022-06-24T12:01:59.940Z" "Thursday, June 23, 2022",24,4,4,0,0,11,21,75,51,16,0,0,"2022-06-23T12:02:04.952Z" "Wednesday, June 22, 2022",13,5,5,0,0,12,23,75,51,16,0,0,"2022-06-22T12:02:19.701Z" "Tuesday, June 21, 2022",12,3,3,0,0,7,20,77,50,17,0,0,"2022-06-21T12:02:07.113Z" From 6a6047483bccbedcf3fea890ad588e53f0800b49 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 24 Jun 2022 12:55:36 -0500 Subject: [PATCH 20/58] [ci] release (#3692) Co-authored-by: github-actions[bot] --- .changeset/clever-pumpkins-begin.md | 7 - .changeset/lovely-bulldogs-admire.md | 29 ----- .changeset/mean-ears-mate.md | 7 - .changeset/modern-dots-smile.md | 5 - .changeset/sixty-mirrors-bake.md | 5 - .changeset/tasty-hornets-return.md | 11 -- .changeset/tough-ants-rest.md | 8 -- examples/basics/package.json | 2 +- examples/blog-multiple-authors/package.json | 4 +- examples/blog/package.json | 4 +- examples/component/demo/package.json | 2 +- examples/component/package.json | 2 +- examples/docs/package.json | 6 +- examples/env-vars/package.json | 2 +- examples/framework-alpine/package.json | 2 +- examples/framework-lit/package.json | 4 +- examples/framework-multiple/package.json | 14 +- examples/framework-preact/package.json | 4 +- examples/framework-react/package.json | 4 +- examples/framework-solid/package.json | 4 +- examples/framework-svelte/package.json | 4 +- examples/framework-vue/package.json | 4 +- examples/integrations-playground/package.json | 10 +- examples/minimal/package.json | 2 +- examples/non-html-pages/package.json | 2 +- examples/portfolio/package.json | 4 +- examples/ssr/package.json | 4 +- examples/starter/package.json | 2 +- examples/subpath/package.json | 4 +- examples/with-markdown-plugins/package.json | 2 +- examples/with-markdown-shiki/package.json | 2 +- examples/with-markdown/package.json | 10 +- examples/with-nanostores/package.json | 12 +- examples/with-tailwindcss/package.json | 2 +- examples/with-vite-plugin-pwa/package.json | 2 +- packages/astro/CHANGELOG.md | 18 +++ packages/astro/package.json | 2 +- packages/integrations/lit/CHANGELOG.md | 8 ++ packages/integrations/lit/package.json | 2 +- packages/integrations/preact/CHANGELOG.md | 28 ++++ packages/integrations/preact/package.json | 2 +- packages/integrations/react/CHANGELOG.md | 28 ++++ packages/integrations/react/package.json | 2 +- packages/integrations/sitemap/CHANGELOG.md | 6 + packages/integrations/sitemap/package.json | 2 +- packages/integrations/solid/CHANGELOG.md | 28 ++++ packages/integrations/solid/package.json | 2 +- packages/integrations/svelte/CHANGELOG.md | 8 ++ packages/integrations/svelte/package.json | 2 +- packages/integrations/vue/CHANGELOG.md | 8 ++ packages/integrations/vue/package.json | 2 +- pnpm-lock.yaml | 120 +++++++++--------- 52 files changed, 260 insertions(+), 200 deletions(-) delete mode 100644 .changeset/clever-pumpkins-begin.md delete mode 100644 .changeset/lovely-bulldogs-admire.md delete mode 100644 .changeset/mean-ears-mate.md delete mode 100644 .changeset/modern-dots-smile.md delete mode 100644 .changeset/sixty-mirrors-bake.md delete mode 100644 .changeset/tasty-hornets-return.md delete mode 100644 .changeset/tough-ants-rest.md diff --git a/.changeset/clever-pumpkins-begin.md b/.changeset/clever-pumpkins-begin.md deleted file mode 100644 index 26b9e5f18f948..0000000000000 --- a/.changeset/clever-pumpkins-begin.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'@astrojs/lit': minor ---- - -Adds support for passing named slots from `.astro` => Lit components. - -All slots are treated as Light DOM content. diff --git a/.changeset/lovely-bulldogs-admire.md b/.changeset/lovely-bulldogs-admire.md deleted file mode 100644 index 74888cb27df2d..0000000000000 --- a/.changeset/lovely-bulldogs-admire.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -'@astrojs/preact': minor -'@astrojs/react': minor -'@astrojs/solid-js': minor ---- - -Add support for passing named slots from `.astro` => framework components. - -Each `slot` is be passed as a top-level prop. For example: - -```jsx -// From .astro - -

Hello world!

-

Dash

-
Default
-
- -// For .jsx -export default function Component({ title, slotWithDash, children }) { - return ( - <> -
{title}
-
{slotWithDash}
-
{children}
- - ) -} -``` diff --git a/.changeset/mean-ears-mate.md b/.changeset/mean-ears-mate.md deleted file mode 100644 index 6bb538e4e9865..0000000000000 --- a/.changeset/mean-ears-mate.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'astro': patch ---- - -Add renderer support for passing named slots to framework components. - -**BREAKING**: integrations using the `addRenderer()` API are now passed all named slots via `Record` rather than `string`. Previously only the default slot was passed. diff --git a/.changeset/modern-dots-smile.md b/.changeset/modern-dots-smile.md deleted file mode 100644 index a66e9c34de300..0000000000000 --- a/.changeset/modern-dots-smile.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Added test for dir parameter in astro:build:done diff --git a/.changeset/sixty-mirrors-bake.md b/.changeset/sixty-mirrors-bake.md deleted file mode 100644 index db6a70bc4192d..0000000000000 --- a/.changeset/sixty-mirrors-bake.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@astrojs/sitemap': patch ---- - -Add warning log for sitemap + SSR adapter, with suggestion to use customPages configuration option diff --git a/.changeset/tasty-hornets-return.md b/.changeset/tasty-hornets-return.md deleted file mode 100644 index 2852303110e1d..0000000000000 --- a/.changeset/tasty-hornets-return.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -'astro': patch ---- - -Moves head injection to happen during rendering - -This change makes it so that head injection; to insert component stylesheets, hoisted scripts, for example, to happen during rendering than as a post-rendering step. - -This is to enable streaming. This change will only be noticeable if you are rendering your `` element inside of a framework component. If that is the case then the head items will be injected before the first non-head element in an Astro file instead. - -In the future we may offer a `` component as a way to control where these scripts/styles are inserted. diff --git a/.changeset/tough-ants-rest.md b/.changeset/tough-ants-rest.md deleted file mode 100644 index f95ae30c2134e..0000000000000 --- a/.changeset/tough-ants-rest.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -'@astrojs/svelte': minor -'@astrojs/vue': minor ---- - -Adds support for passing named slots from `.astro` => framework components. - -Inside your components, use the built-in `slot` API as you normally would. diff --git a/examples/basics/package.json b/examples/basics/package.json index e54ce11673b56..d87a9c6000964 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" } } diff --git a/examples/blog-multiple-authors/package.json b/examples/blog-multiple-authors/package.json index 4514566a1f27e..4e397b0559f7c 100644 --- a/examples/blog-multiple-authors/package.json +++ b/examples/blog-multiple-authors/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/preact": "^0.1.3", - "astro": "^1.0.0-beta.53", + "@astrojs/preact": "^0.2.0", + "astro": "^1.0.0-beta.54", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/blog/package.json b/examples/blog/package.json index 33680cad82e89..8ff8252367d54 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/preact": "^0.1.3", - "astro": "^1.0.0-beta.53" + "@astrojs/preact": "^0.2.0", + "astro": "^1.0.0-beta.54" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/component/demo/package.json b/examples/component/demo/package.json index c91bf5b6b333b..2bf06211727ce 100644 --- a/examples/component/demo/package.json +++ b/examples/component/demo/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@example/my-component": "workspace:*", - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" } } diff --git a/examples/component/package.json b/examples/component/package.json index 10cd44ec85e05..16c1593499752 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -8,6 +8,6 @@ "serve": "astro --root demo preview" }, "devDependencies": { - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" } } diff --git a/examples/docs/package.json b/examples/docs/package.json index 37720315e274d..e27a421c6ac0e 100644 --- a/examples/docs/package.json +++ b/examples/docs/package.json @@ -18,8 +18,8 @@ "react-dom": "^18.1.0" }, "devDependencies": { - "@astrojs/preact": "^0.1.3", - "@astrojs/react": "^0.1.3", - "astro": "^1.0.0-beta.53" + "@astrojs/preact": "^0.2.0", + "@astrojs/react": "^0.2.0", + "astro": "^1.0.0-beta.54" } } diff --git a/examples/env-vars/package.json b/examples/env-vars/package.json index f30366443dbcb..aef9b036522c6 100644 --- a/examples/env-vars/package.json +++ b/examples/env-vars/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" } } diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index 07ca0542ced58..f07762b55721a 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" }, "dependencies": { "alpinejs": "^3.10.2" diff --git a/examples/framework-lit/package.json b/examples/framework-lit/package.json index d77a0ef434bc8..86077aa0e8d19 100644 --- a/examples/framework-lit/package.json +++ b/examples/framework-lit/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/lit": "^0.2.0", - "astro": "^1.0.0-beta.53" + "@astrojs/lit": "^0.3.0", + "astro": "^1.0.0-beta.54" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index ec0a7766b6f06..f7af906e037f8 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -9,13 +9,13 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/lit": "^0.2.0", - "@astrojs/preact": "^0.1.3", - "@astrojs/react": "^0.1.3", - "@astrojs/solid-js": "^0.1.4", - "@astrojs/svelte": "^0.1.5", - "@astrojs/vue": "^0.1.5", - "astro": "^1.0.0-beta.53" + "@astrojs/lit": "^0.3.0", + "@astrojs/preact": "^0.2.0", + "@astrojs/react": "^0.2.0", + "@astrojs/solid-js": "^0.2.0", + "@astrojs/svelte": "^0.2.0", + "@astrojs/vue": "^0.2.0", + "astro": "^1.0.0-beta.54" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 1000353dec7bf..5085607dfafd4 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/preact": "^0.1.3", - "astro": "^1.0.0-beta.53" + "@astrojs/preact": "^0.2.0", + "astro": "^1.0.0-beta.54" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index 4a2ddf71cdc01..a9378a304f49d 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -9,10 +9,10 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/react": "^0.1.3", + "@astrojs/react": "^0.2.0", "@types/react": "^18.0.10", "@types/react-dom": "^18.0.5", - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" }, "dependencies": { "react": "^18.1.0", diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index 0bf6eb47f7747..3f1bc3ec5a0a3 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/solid-js": "^0.1.4", - "astro": "^1.0.0-beta.53" + "@astrojs/solid-js": "^0.2.0", + "astro": "^1.0.0-beta.54" }, "dependencies": { "solid-js": "^1.4.3" diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index 61744cf86f699..60d18f27aa1ec 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/svelte": "^0.1.5", - "astro": "^1.0.0-beta.53" + "@astrojs/svelte": "^0.2.0", + "astro": "^1.0.0-beta.54" }, "dependencies": { "svelte": "^3.48.0" diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 9951b5603ba56..72552314b81af 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/vue": "^0.1.5", - "astro": "^1.0.0-beta.53" + "@astrojs/vue": "^0.2.0", + "astro": "^1.0.0-beta.54" }, "dependencies": { "vue": "^3.2.36" diff --git a/examples/integrations-playground/package.json b/examples/integrations-playground/package.json index 75bde1026eb88..c585717977b72 100644 --- a/examples/integrations-playground/package.json +++ b/examples/integrations-playground/package.json @@ -9,14 +9,14 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/lit": "^0.2.0", + "@astrojs/lit": "^0.3.0", "@astrojs/partytown": "^0.1.5", - "@astrojs/react": "^0.1.3", - "@astrojs/sitemap": "^0.2.1", - "@astrojs/solid-js": "0.1.4", + "@astrojs/react": "^0.2.0", + "@astrojs/sitemap": "^0.2.2", + "@astrojs/solid-js": "0.2.0", "@astrojs/tailwind": "^0.2.1", "@astrojs/turbolinks": "^0.1.3", - "astro": "^1.0.0-beta.53", + "astro": "^1.0.0-beta.54", "solid-js": "^1.4.3" }, "dependencies": { diff --git a/examples/minimal/package.json b/examples/minimal/package.json index 30445f8bff4f6..b887e42a76a32 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" } } diff --git a/examples/non-html-pages/package.json b/examples/non-html-pages/package.json index 9692f99838efd..022ece7dec04d 100644 --- a/examples/non-html-pages/package.json +++ b/examples/non-html-pages/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index 6a7337ee42f3c..2be4e7c52ad4d 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/preact": "^0.1.3", - "astro": "^1.0.0-beta.53", + "@astrojs/preact": "^0.2.0", + "astro": "^1.0.0-beta.54", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/ssr/package.json b/examples/ssr/package.json index 51469fc4931ea..abda3716e1c06 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -10,8 +10,8 @@ }, "devDependencies": { "@astrojs/node": "^0.1.2", - "@astrojs/svelte": "^0.1.5", - "astro": "^1.0.0-beta.53", + "@astrojs/svelte": "^0.2.0", + "astro": "^1.0.0-beta.54", "concurrently": "^7.2.1", "lightcookie": "^1.0.25", "unocss": "^0.15.6", diff --git a/examples/starter/package.json b/examples/starter/package.json index 4bcda5fdcef6f..798e207a5dff1 100644 --- a/examples/starter/package.json +++ b/examples/starter/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" } } diff --git a/examples/subpath/package.json b/examples/subpath/package.json index 498daf7a7e9ba..d19ed5e0ed9d0 100644 --- a/examples/subpath/package.json +++ b/examples/subpath/package.json @@ -9,8 +9,8 @@ "preview": "astro preview" }, "devDependencies": { - "@astrojs/react": "^0.1.3", - "astro": "^1.0.0-beta.53", + "@astrojs/react": "^0.2.0", + "astro": "^1.0.0-beta.54", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/with-markdown-plugins/package.json b/examples/with-markdown-plugins/package.json index 534fa609c3593..8fe0df1c94b33 100644 --- a/examples/with-markdown-plugins/package.json +++ b/examples/with-markdown-plugins/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.53", + "astro": "^1.0.0-beta.54", "hast-util-select": "5.0.1", "rehype-autolink-headings": "^6.1.1", "rehype-slug": "^5.0.1", diff --git a/examples/with-markdown-shiki/package.json b/examples/with-markdown-shiki/package.json index 8c997012b4480..9b8624634d5f3 100644 --- a/examples/with-markdown-shiki/package.json +++ b/examples/with-markdown-shiki/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.53" + "astro": "^1.0.0-beta.54" } } diff --git a/examples/with-markdown/package.json b/examples/with-markdown/package.json index f37e12498ed3a..e3c7c0a4c8cb7 100644 --- a/examples/with-markdown/package.json +++ b/examples/with-markdown/package.json @@ -10,11 +10,11 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "@astrojs/preact": "^0.1.3", - "@astrojs/react": "^0.1.3", - "@astrojs/svelte": "^0.1.5", - "@astrojs/vue": "^0.1.5", - "astro": "^1.0.0-beta.53" + "@astrojs/preact": "^0.2.0", + "@astrojs/react": "^0.2.0", + "@astrojs/svelte": "^0.2.0", + "@astrojs/vue": "^0.2.0", + "astro": "^1.0.0-beta.54" }, "dependencies": { "preact": "^10.7.3", diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index a729410fae60d..1d628de3a967b 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -20,11 +20,11 @@ "vue": "^3.2.36" }, "devDependencies": { - "@astrojs/preact": "^0.1.3", - "@astrojs/react": "^0.1.3", - "@astrojs/solid-js": "^0.1.4", - "@astrojs/svelte": "^0.1.5", - "@astrojs/vue": "^0.1.5", - "astro": "^1.0.0-beta.53" + "@astrojs/preact": "^0.2.0", + "@astrojs/react": "^0.2.0", + "@astrojs/solid-js": "^0.2.0", + "@astrojs/svelte": "^0.2.0", + "@astrojs/vue": "^0.2.0", + "astro": "^1.0.0-beta.54" } } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index 794d193d4fe68..25f2bcf4be5f3 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/tailwind": "^0.2.1", - "astro": "^1.0.0-beta.53", + "astro": "^1.0.0-beta.54", "autoprefixer": "^10.4.7", "canvas-confetti": "^1.5.1", "postcss": "^8.4.14", diff --git a/examples/with-vite-plugin-pwa/package.json b/examples/with-vite-plugin-pwa/package.json index 965e461e1edaf..c8a71f81164d4 100644 --- a/examples/with-vite-plugin-pwa/package.json +++ b/examples/with-vite-plugin-pwa/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.53", + "astro": "^1.0.0-beta.54", "vite-plugin-pwa": "0.11.11", "workbox-window": "^6.5.3" } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index 559b9b52ef0be..61b47f7853c40 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,23 @@ # astro +## 1.0.0-beta.54 + +### Patch Changes + +- [#3652](https://github.com/withastro/astro/pull/3652) [`7373d61c`](https://github.com/withastro/astro/commit/7373d61cdcaedd64bf5fd60521b157cfa4343558) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Add renderer support for passing named slots to framework components. + + **BREAKING**: integrations using the `addRenderer()` API are now passed all named slots via `Record` rather than `string`. Previously only the default slot was passed. + +* [#3649](https://github.com/withastro/astro/pull/3649) [`446f8c4f`](https://github.com/withastro/astro/commit/446f8c4f13de04324697e958af027ac8943a039b) Thanks [@dc7290](https://github.com/dc7290)! - Added test for dir parameter in astro:build:done + +- [#3679](https://github.com/withastro/astro/pull/3679) [`fa7ed3f3`](https://github.com/withastro/astro/commit/fa7ed3f3a9ce89c1c46e637b584271a6e199d211) Thanks [@matthewp](https://github.com/matthewp)! - Moves head injection to happen during rendering + + This change makes it so that head injection; to insert component stylesheets, hoisted scripts, for example, to happen during rendering than as a post-rendering step. + + This is to enable streaming. This change will only be noticeable if you are rendering your `` element inside of a framework component. If that is the case then the head items will be injected before the first non-head element in an Astro file instead. + + In the future we may offer a `` component as a way to control where these scripts/styles are inserted. + ## 1.0.0-beta.53 ### Patch Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index 326e64fa6a2c9..4b9e34174b1fa 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "1.0.0-beta.53", + "version": "1.0.0-beta.54", "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.", "type": "module", "author": "withastro", diff --git a/packages/integrations/lit/CHANGELOG.md b/packages/integrations/lit/CHANGELOG.md index 354729d923560..4c4b40c15fac3 100644 --- a/packages/integrations/lit/CHANGELOG.md +++ b/packages/integrations/lit/CHANGELOG.md @@ -1,5 +1,13 @@ # @astrojs/lit +## 0.3.0 + +### Minor Changes + +- [#3652](https://github.com/withastro/astro/pull/3652) [`7373d61c`](https://github.com/withastro/astro/commit/7373d61cdcaedd64bf5fd60521b157cfa4343558) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Adds support for passing named slots from `.astro` => Lit components. + + All slots are treated as Light DOM content. + ## 0.2.0 ### Minor Changes diff --git a/packages/integrations/lit/package.json b/packages/integrations/lit/package.json index 546f510a0bfc5..12beab2451e79 100644 --- a/packages/integrations/lit/package.json +++ b/packages/integrations/lit/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/lit", - "version": "0.2.0", + "version": "0.3.0", "description": "Use Lit components within Astro", "type": "module", "types": "./dist/index.d.ts", diff --git a/packages/integrations/preact/CHANGELOG.md b/packages/integrations/preact/CHANGELOG.md index 07fbf0ea02a4b..fa02e859089e5 100644 --- a/packages/integrations/preact/CHANGELOG.md +++ b/packages/integrations/preact/CHANGELOG.md @@ -1,5 +1,33 @@ # @astrojs/preact +## 0.2.0 + +### Minor Changes + +- [#3652](https://github.com/withastro/astro/pull/3652) [`7373d61c`](https://github.com/withastro/astro/commit/7373d61cdcaedd64bf5fd60521b157cfa4343558) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Add support for passing named slots from `.astro` => framework components. + + Each `slot` is be passed as a top-level prop. For example: + + ```jsx + // From .astro + +

Hello world!

+

Dash

+
Default
+
; + + // For .jsx + export default function Component({ title, slotWithDash, children }) { + return ( + <> +
{title}
+
{slotWithDash}
+
{children}
+ + ); + } + ``` + ## 0.1.3 ### Patch Changes diff --git a/packages/integrations/preact/package.json b/packages/integrations/preact/package.json index 72a6174cc7a7a..7229e6b2eefa4 100644 --- a/packages/integrations/preact/package.json +++ b/packages/integrations/preact/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/preact", "description": "Use Preact components within Astro", - "version": "0.1.3", + "version": "0.2.0", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/packages/integrations/react/CHANGELOG.md b/packages/integrations/react/CHANGELOG.md index fa71e8b1b46bf..7dda8d3c9c890 100644 --- a/packages/integrations/react/CHANGELOG.md +++ b/packages/integrations/react/CHANGELOG.md @@ -1,5 +1,33 @@ # @astrojs/react +## 0.2.0 + +### Minor Changes + +- [#3652](https://github.com/withastro/astro/pull/3652) [`7373d61c`](https://github.com/withastro/astro/commit/7373d61cdcaedd64bf5fd60521b157cfa4343558) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Add support for passing named slots from `.astro` => framework components. + + Each `slot` is be passed as a top-level prop. For example: + + ```jsx + // From .astro + +

Hello world!

+

Dash

+
Default
+
; + + // For .jsx + export default function Component({ title, slotWithDash, children }) { + return ( + <> +
{title}
+
{slotWithDash}
+
{children}
+ + ); + } + ``` + ## 0.1.3 ### Patch Changes diff --git a/packages/integrations/react/package.json b/packages/integrations/react/package.json index 96aa67368e70b..0bc3937bfb46b 100644 --- a/packages/integrations/react/package.json +++ b/packages/integrations/react/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/react", "description": "Use React components within Astro", - "version": "0.1.3", + "version": "0.2.0", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/packages/integrations/sitemap/CHANGELOG.md b/packages/integrations/sitemap/CHANGELOG.md index 5d6e37dcfb60c..47d1c40efe05b 100644 --- a/packages/integrations/sitemap/CHANGELOG.md +++ b/packages/integrations/sitemap/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/sitemap +## 0.2.2 + +### Patch Changes + +- [#3689](https://github.com/withastro/astro/pull/3689) [`3f8ee70e`](https://github.com/withastro/astro/commit/3f8ee70e2bc5b49c65a0444d9606232dadbc2fca) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Add warning log for sitemap + SSR adapter, with suggestion to use customPages configuration option + ## 0.2.1 ### Patch Changes diff --git a/packages/integrations/sitemap/package.json b/packages/integrations/sitemap/package.json index ffb20d4333e67..47e0e0ef067ce 100644 --- a/packages/integrations/sitemap/package.json +++ b/packages/integrations/sitemap/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/sitemap", "description": "Generate a sitemap for Astro", - "version": "0.2.1", + "version": "0.2.2", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/packages/integrations/solid/CHANGELOG.md b/packages/integrations/solid/CHANGELOG.md index d936a6e04dd93..b223e8a3081a9 100644 --- a/packages/integrations/solid/CHANGELOG.md +++ b/packages/integrations/solid/CHANGELOG.md @@ -1,5 +1,33 @@ # @astrojs/solid-js +## 0.2.0 + +### Minor Changes + +- [#3652](https://github.com/withastro/astro/pull/3652) [`7373d61c`](https://github.com/withastro/astro/commit/7373d61cdcaedd64bf5fd60521b157cfa4343558) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Add support for passing named slots from `.astro` => framework components. + + Each `slot` is be passed as a top-level prop. For example: + + ```jsx + // From .astro + +

Hello world!

+

Dash

+
Default
+
; + + // For .jsx + export default function Component({ title, slotWithDash, children }) { + return ( + <> +
{title}
+
{slotWithDash}
+
{children}
+ + ); + } + ``` + ## 0.1.4 ### Patch Changes diff --git a/packages/integrations/solid/package.json b/packages/integrations/solid/package.json index e60677d3abcee..c6fe8c40abaf1 100644 --- a/packages/integrations/solid/package.json +++ b/packages/integrations/solid/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/solid-js", - "version": "0.1.4", + "version": "0.2.0", "description": "Use Solid components within Astro", "type": "module", "types": "./dist/index.d.ts", diff --git a/packages/integrations/svelte/CHANGELOG.md b/packages/integrations/svelte/CHANGELOG.md index 4e84b1fee2f60..116eb60f538e1 100644 --- a/packages/integrations/svelte/CHANGELOG.md +++ b/packages/integrations/svelte/CHANGELOG.md @@ -1,5 +1,13 @@ # @astrojs/svelte +## 0.2.0 + +### Minor Changes + +- [#3652](https://github.com/withastro/astro/pull/3652) [`7373d61c`](https://github.com/withastro/astro/commit/7373d61cdcaedd64bf5fd60521b157cfa4343558) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Adds support for passing named slots from `.astro` => framework components. + + Inside your components, use the built-in `slot` API as you normally would. + ## 0.1.5 ### Patch Changes diff --git a/packages/integrations/svelte/package.json b/packages/integrations/svelte/package.json index c25e0eb0a7102..a9c653ea7de1d 100644 --- a/packages/integrations/svelte/package.json +++ b/packages/integrations/svelte/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/svelte", - "version": "0.1.5", + "version": "0.2.0", "description": "Use Svelte components within Astro", "type": "module", "types": "./dist/index.d.ts", diff --git a/packages/integrations/vue/CHANGELOG.md b/packages/integrations/vue/CHANGELOG.md index 96000a31c231b..e2a78b3fd394d 100644 --- a/packages/integrations/vue/CHANGELOG.md +++ b/packages/integrations/vue/CHANGELOG.md @@ -1,5 +1,13 @@ # @astrojs/vue +## 0.2.0 + +### Minor Changes + +- [#3652](https://github.com/withastro/astro/pull/3652) [`7373d61c`](https://github.com/withastro/astro/commit/7373d61cdcaedd64bf5fd60521b157cfa4343558) Thanks [@natemoo-re](https://github.com/natemoo-re)! - Adds support for passing named slots from `.astro` => framework components. + + Inside your components, use the built-in `slot` API as you normally would. + ## 0.1.5 ### Patch Changes diff --git a/packages/integrations/vue/package.json b/packages/integrations/vue/package.json index e2008fe0b8300..f91ce1cd37493 100644 --- a/packages/integrations/vue/package.json +++ b/packages/integrations/vue/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/vue", - "version": "0.1.5", + "version": "0.2.0", "description": "Use Vue components within Astro", "type": "module", "types": "./dist/index.d.ts", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c9274296240e2..a7b468ed11267 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,14 +49,14 @@ importers: examples/basics: specifiers: - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 devDependencies: astro: link:../../packages/astro examples/blog: specifiers: - '@astrojs/preact': ^0.1.3 - astro: ^1.0.0-beta.53 + '@astrojs/preact': ^0.2.0 + astro: ^1.0.0-beta.54 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -66,8 +66,8 @@ importers: examples/blog-multiple-authors: specifiers: - '@astrojs/preact': ^0.1.3 - astro: ^1.0.0-beta.53 + '@astrojs/preact': ^0.2.0 + astro: ^1.0.0-beta.54 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -79,14 +79,14 @@ importers: examples/component: specifiers: - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 devDependencies: astro: link:../../packages/astro examples/component/demo: specifiers: '@example/my-component': workspace:* - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 devDependencies: '@example/my-component': link:../packages/my-component astro: link:../../../packages/astro @@ -97,12 +97,12 @@ importers: examples/docs: specifiers: '@algolia/client-search': ^4.13.1 - '@astrojs/preact': ^0.1.3 - '@astrojs/react': ^0.1.3 + '@astrojs/preact': ^0.2.0 + '@astrojs/react': ^0.2.0 '@docsearch/css': ^3.1.0 '@docsearch/react': ^3.1.0 '@types/react': ^17.0.45 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -121,14 +121,14 @@ importers: examples/env-vars: specifiers: - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 devDependencies: astro: link:../../packages/astro examples/framework-alpine: specifiers: alpinejs: ^3.10.2 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 dependencies: alpinejs: 3.10.2 devDependencies: @@ -136,9 +136,9 @@ importers: examples/framework-lit: specifiers: - '@astrojs/lit': ^0.2.0 + '@astrojs/lit': ^0.3.0 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 lit: ^2.2.5 dependencies: '@webcomponents/template-shadowroot': 0.1.0 @@ -149,14 +149,14 @@ importers: examples/framework-multiple: specifiers: - '@astrojs/lit': ^0.2.0 - '@astrojs/preact': ^0.1.3 - '@astrojs/react': ^0.1.3 - '@astrojs/solid-js': ^0.1.4 - '@astrojs/svelte': ^0.1.5 - '@astrojs/vue': ^0.1.5 + '@astrojs/lit': ^0.3.0 + '@astrojs/preact': ^0.2.0 + '@astrojs/react': ^0.2.0 + '@astrojs/solid-js': ^0.2.0 + '@astrojs/svelte': ^0.2.0 + '@astrojs/vue': ^0.2.0 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -184,8 +184,8 @@ importers: examples/framework-preact: specifiers: - '@astrojs/preact': ^0.1.3 - astro: ^1.0.0-beta.53 + '@astrojs/preact': ^0.2.0 + astro: ^1.0.0-beta.54 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -195,10 +195,10 @@ importers: examples/framework-react: specifiers: - '@astrojs/react': ^0.1.3 + '@astrojs/react': ^0.2.0 '@types/react': ^18.0.10 '@types/react-dom': ^18.0.5 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 react: ^18.1.0 react-dom: ^18.1.0 dependencies: @@ -212,8 +212,8 @@ importers: examples/framework-solid: specifiers: - '@astrojs/solid-js': ^0.1.4 - astro: ^1.0.0-beta.53 + '@astrojs/solid-js': ^0.2.0 + astro: ^1.0.0-beta.54 solid-js: ^1.4.3 dependencies: solid-js: 1.4.3 @@ -223,8 +223,8 @@ importers: examples/framework-svelte: specifiers: - '@astrojs/svelte': ^0.1.5 - astro: ^1.0.0-beta.53 + '@astrojs/svelte': ^0.2.0 + astro: ^1.0.0-beta.54 svelte: ^3.48.0 dependencies: svelte: 3.48.0 @@ -234,8 +234,8 @@ importers: examples/framework-vue: specifiers: - '@astrojs/vue': ^0.1.5 - astro: ^1.0.0-beta.53 + '@astrojs/vue': ^0.2.0 + astro: ^1.0.0-beta.54 vue: ^3.2.36 dependencies: vue: 3.2.37 @@ -245,15 +245,15 @@ importers: examples/integrations-playground: specifiers: - '@astrojs/lit': ^0.2.0 + '@astrojs/lit': ^0.3.0 '@astrojs/partytown': ^0.1.5 - '@astrojs/react': ^0.1.3 - '@astrojs/sitemap': ^0.2.1 - '@astrojs/solid-js': 0.1.4 + '@astrojs/react': ^0.2.0 + '@astrojs/sitemap': ^0.2.2 + '@astrojs/solid-js': 0.2.0 '@astrojs/tailwind': ^0.2.1 '@astrojs/turbolinks': ^0.1.3 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -282,20 +282,20 @@ importers: examples/minimal: specifiers: - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 devDependencies: astro: link:../../packages/astro examples/non-html-pages: specifiers: - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 devDependencies: astro: link:../../packages/astro examples/portfolio: specifiers: - '@astrojs/preact': ^0.1.3 - astro: ^1.0.0-beta.53 + '@astrojs/preact': ^0.2.0 + astro: ^1.0.0-beta.54 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -308,8 +308,8 @@ importers: examples/ssr: specifiers: '@astrojs/node': ^0.1.2 - '@astrojs/svelte': ^0.1.5 - astro: ^1.0.0-beta.53 + '@astrojs/svelte': ^0.2.0 + astro: ^1.0.0-beta.54 concurrently: ^7.2.1 lightcookie: ^1.0.25 svelte: ^3.48.0 @@ -328,14 +328,14 @@ importers: examples/starter: specifiers: - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 devDependencies: astro: link:../../packages/astro examples/subpath: specifiers: - '@astrojs/react': ^0.1.3 - astro: ^1.0.0-beta.53 + '@astrojs/react': ^0.2.0 + astro: ^1.0.0-beta.54 react: ^18.1.0 react-dom: ^18.1.0 sass: ^1.52.2 @@ -350,11 +350,11 @@ importers: examples/with-markdown: specifiers: '@astrojs/markdown-remark': ^0.11.3 - '@astrojs/preact': ^0.1.3 - '@astrojs/react': ^0.1.3 - '@astrojs/svelte': ^0.1.5 - '@astrojs/vue': ^0.1.5 - astro: ^1.0.0-beta.53 + '@astrojs/preact': ^0.2.0 + '@astrojs/react': ^0.2.0 + '@astrojs/svelte': ^0.2.0 + '@astrojs/vue': ^0.2.0 + astro: ^1.0.0-beta.54 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -377,7 +377,7 @@ importers: examples/with-markdown-plugins: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 hast-util-select: 5.0.1 rehype-autolink-headings: ^6.1.1 rehype-slug: ^5.0.1 @@ -395,22 +395,22 @@ importers: examples/with-markdown-shiki: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 devDependencies: '@astrojs/markdown-remark': link:../../packages/markdown/remark astro: link:../../packages/astro examples/with-nanostores: specifiers: - '@astrojs/preact': ^0.1.3 - '@astrojs/react': ^0.1.3 - '@astrojs/solid-js': ^0.1.4 - '@astrojs/svelte': ^0.1.5 - '@astrojs/vue': ^0.1.5 + '@astrojs/preact': ^0.2.0 + '@astrojs/react': ^0.2.0 + '@astrojs/solid-js': ^0.2.0 + '@astrojs/svelte': ^0.2.0 + '@astrojs/vue': ^0.2.0 '@nanostores/preact': ^0.1.3 '@nanostores/react': ^0.1.5 '@nanostores/vue': ^0.4.1 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 nanostores: ^0.5.12 preact: ^10.7.3 react: ^18.1.0 @@ -438,7 +438,7 @@ importers: examples/with-tailwindcss: specifiers: '@astrojs/tailwind': ^0.2.1 - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 autoprefixer: ^10.4.7 canvas-confetti: ^1.5.1 postcss: ^8.4.14 @@ -453,7 +453,7 @@ importers: examples/with-vite-plugin-pwa: specifiers: - astro: ^1.0.0-beta.53 + astro: ^1.0.0-beta.54 vite-plugin-pwa: 0.11.11 workbox-window: ^6.5.3 devDependencies: From 0d667d0e572d76d4c819816ddf51ed14b43e2551 Mon Sep 17 00:00:00 2001 From: Richard Cooke Date: Fri, 24 Jun 2022 20:30:47 +0100 Subject: [PATCH 21/58] fix: `@astrojs/clooudflare` 404 handling (#3695) --- .changeset/five-zoos-look.md | 5 +++++ packages/integrations/cloudflare/src/server.ts | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/five-zoos-look.md diff --git a/.changeset/five-zoos-look.md b/.changeset/five-zoos-look.md new file mode 100644 index 0000000000000..f882dee9bcf70 --- /dev/null +++ b/.changeset/five-zoos-look.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +fix custom 404 pages not rendering diff --git a/packages/integrations/cloudflare/src/server.ts b/packages/integrations/cloudflare/src/server.ts index 6a76c06ff48c1..032146691ea3c 100644 --- a/packages/integrations/cloudflare/src/server.ts +++ b/packages/integrations/cloudflare/src/server.ts @@ -24,6 +24,11 @@ export function createExports(manifest: SSRManifest) { } // 404 + const _404Request = new Request(`${origin}/404`, request); + if (app.match(_404Request)) { + return app.render(_404Request); + } + return new Response(null, { status: 404, statusText: 'Not found', From 3daaf510ea767fba47ef52d2253b6221967f3b53 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 24 Jun 2022 15:35:21 -0400 Subject: [PATCH 22/58] Streaming (#3696) * Start of streaming * New lockfile * Base should be Uint8Arrays * Remove the ability to throw from a component * Add a warning when returning a Response from a non-page component * Adds a changeset --- .changeset/funny-pianos-mix.md | 40 ++++++ packages/astro/package.json | 1 - packages/astro/src/core/app/index.ts | 14 +- packages/astro/src/core/build/generate.ts | 7 +- packages/astro/src/core/render/core.ts | 29 +--- packages/astro/src/core/render/dev/html.ts | 109 -------------- packages/astro/src/core/render/dev/index.ts | 34 +---- packages/astro/src/core/render/result.ts | 4 +- packages/astro/src/runtime/server/index.ts | 134 +++++++++++------- packages/astro/src/runtime/server/response.ts | 71 ++++++++++ .../src/vite-plugin-astro-server/index.ts | 37 ++--- packages/astro/test/astro-response.test.js | 5 - .../src/components/not-found.astro | 6 - .../src/pages/not-found-component.astro | 4 - .../test/fixtures/streaming/astro.config.mjs | 0 .../test/fixtures/streaming/package.json | 11 ++ .../streaming/src/components/AsyncEach.astro | 11 ++ .../streaming/src/components/Header.astro | 7 + .../fixtures/streaming/src/pages/index.astro | 32 +++++ .../astro/test/fixtures/streaming/src/wait.ts | 4 + packages/astro/test/streaming.test.js | 74 ++++++++++ pnpm-lock.yaml | 50 +------ 22 files changed, 375 insertions(+), 309 deletions(-) create mode 100644 .changeset/funny-pianos-mix.md delete mode 100644 packages/astro/src/core/render/dev/html.ts create mode 100644 packages/astro/src/runtime/server/response.ts delete mode 100644 packages/astro/test/fixtures/astro-response/src/components/not-found.astro delete mode 100644 packages/astro/test/fixtures/astro-response/src/pages/not-found-component.astro create mode 100644 packages/astro/test/fixtures/streaming/astro.config.mjs create mode 100644 packages/astro/test/fixtures/streaming/package.json create mode 100644 packages/astro/test/fixtures/streaming/src/components/AsyncEach.astro create mode 100644 packages/astro/test/fixtures/streaming/src/components/Header.astro create mode 100644 packages/astro/test/fixtures/streaming/src/pages/index.astro create mode 100644 packages/astro/test/fixtures/streaming/src/wait.ts create mode 100644 packages/astro/test/streaming.test.js diff --git a/.changeset/funny-pianos-mix.md b/.changeset/funny-pianos-mix.md new file mode 100644 index 0000000000000..249ba4deada27 --- /dev/null +++ b/.changeset/funny-pianos-mix.md @@ -0,0 +1,40 @@ +--- +'astro': patch +--- + +Support for streaming responses + +Astro supports streaming in its templates. Any time Astro encounters an async boundary it will stream out HTML that occurs before it. For example: + +```astro +--- +import LoadTodos from '../components/LoadTodos.astro'; +--- + + +App + + + + + +``` + +In this arbtrary example Astro will streaming out the `` section and everything else until it encounters `` and then stop. LoadTodos, which is also an Astro component will stream its contents as well; stopping and waiting at any other asynchronous components. + +As part of this Astro also now supports async iterables within its templates. This means you can do this: + +```astro +
    + {(async function * () { + for(const number of numbers) { + await wait(1000); + + yield
  • Number: {number}
  • + yield '\n' + } + })()} +
+``` + +Which will stream out `
  • `s one at a time, waiting a second between each. diff --git a/packages/astro/package.json b/packages/astro/package.json index 4b9e34174b1fa..b1a02bcc6fa46 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -105,7 +105,6 @@ "gray-matter": "^4.0.3", "html-entities": "^2.3.3", "html-escaper": "^3.0.3", - "htmlparser2": "^7.2.0", "kleur": "^4.1.4", "magic-string": "^0.25.9", "micromorph": "^0.1.2", diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 36fb01ff2029b..40842a7f9ac08 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -94,7 +94,7 @@ export class App { } } - const result = await render({ + const response = await render({ links, logging: this.#logging, markdown: manifest.markdown, @@ -119,17 +119,7 @@ export class App { request, }); - if (result.type === 'response') { - return result.response; - } - - let html = result.html; - let init = result.response; - let headers = init.headers as Headers; - let bytes = this.#encoder.encode(html); - headers.set('Content-Type', 'text/html'); - headers.set('Content-Length', bytes.byteLength.toString()); - return new Response(bytes, init); + return response; } async #callEndpoint( diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 05d1bcc55e430..bfc95cb8ed91e 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -251,13 +251,14 @@ async function generatePath( } body = result.body; } else { - const result = await render(options); + const response = await render(options); // If there's a redirect or something, just do nothing. - if (result.type !== 'html') { + if (response.status !== 200 || !response.body) { return; } - body = result.html; + + body = await response.text(); } const outFolder = getOutFolder(astroConfig, pathname, pageData.route.type); diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index b718b4d28f52c..c9c46fda17359 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -85,9 +85,7 @@ export interface RenderOptions { export async function render( opts: RenderOptions -): Promise< - { type: 'html'; html: string; response: ResponseInit } | { type: 'response'; response: Response } -> { +): Promise { const { links, styles, @@ -144,32 +142,11 @@ export async function render( ssr, }); - let page: Awaited>; if (!Component.isAstroComponentFactory) { const props: Record = { ...(pageProps ?? {}), 'server:root': true }; const html = await renderComponent(result, Component.name, Component, props, null); - page = { - type: 'html', - html: html.toString(), - }; + return new Response(html.toString(), result.response); } else { - page = await renderPage(result, Component, pageProps, null); + return await renderPage(result, Component, pageProps, null); } - - if (page.type === 'response') { - return page; - } - - let html = page.html; - - // inject if missing (TODO: is a more robust check needed for comments, etc.?) - if (!/\n' + html; - } - - return { - type: 'html', - html, - response: result.response, - }; } diff --git a/packages/astro/src/core/render/dev/html.ts b/packages/astro/src/core/render/dev/html.ts deleted file mode 100644 index 065b07cf0245a..0000000000000 --- a/packages/astro/src/core/render/dev/html.ts +++ /dev/null @@ -1,109 +0,0 @@ -import type * as vite from 'vite'; - -import htmlparser2 from 'htmlparser2'; - -/** Inject tags into HTML (note: for best performance, group as many tags as possible into as few calls as you can) */ -export function injectTags(html: string, tags: vite.HtmlTagDescriptor[]): string { - let output = html; - if (!tags.length) return output; - - const pos = { 'head-prepend': -1, head: -1, 'body-prepend': -1, body: -1 }; - - // parse html - const parser = new htmlparser2.Parser({ - onopentag(tagname) { - if (tagname === 'head') pos['head-prepend'] = parser.endIndex + 1; - if (tagname === 'body') pos['body-prepend'] = parser.endIndex + 1; - }, - onclosetag(tagname) { - if (tagname === 'head') pos['head'] = parser.startIndex; - if (tagname === 'body') pos['body'] = parser.startIndex; - }, - }); - parser.write(html); - parser.end(); - - // inject - const lastToFirst = Object.entries(pos).sort((a, b) => b[1] - a[1]); - lastToFirst.forEach(([name, i]) => { - if (i === -1) { - // if page didn’t generate or , guess - if (name === 'head-prepend' || name === 'head') i = 0; - if (name === 'body-prepend' || name === 'body') i = html.length; - } - let selected = tags.filter(({ injectTo }) => { - if (name === 'head-prepend' && !injectTo) { - return true; // "head-prepend" is the default - } else { - return injectTo === name; - } - }); - if (!selected.length) return; - output = output.substring(0, i) + serializeTags(selected) + html.substring(i); - }); - - return output; -} - -type Resource = Record; - -/** Collect resources (scans final, rendered HTML so expressions have been applied) */ -export function collectResources(html: string): Resource[] { - let resources: Resource[] = []; - const parser = new htmlparser2.Parser({ - // tags are self-closing, so only use onopentag (avoid onattribute or onclosetag) - onopentag(tagname, attrs) { - if (tagname === 'link') resources.push(attrs); - }, - }); - parser.write(html); - parser.end(); - return resources; -} - -// ------------------------------------------------------------------------------- -// Everything below © Vite. Rather than invent our own tag creating API, we borrow -// Vite’s `transformIndexHtml()` API for ease-of-use and consistency. But we need -// to borrow a few private methods in Vite to make that available here. -// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/html.ts -// -// See LICENSE for more info. -// ------------------------------------------------------------------------------- - -const unaryTags = new Set(['link', 'meta', 'base']); - -function serializeTag({ tag, attrs, children }: vite.HtmlTagDescriptor, indent = ''): string { - if (unaryTags.has(tag)) { - return `<${tag}${serializeAttrs(attrs)}>`; - } else { - return `<${tag}${serializeAttrs(attrs)}>${serializeTags( - children, - incrementIndent(indent) - )}`; - } -} - -function serializeTags(tags: vite.HtmlTagDescriptor['children'], indent = ''): string { - if (typeof tags === 'string') { - return tags; - } else if (tags && tags.length) { - return tags.map((tag) => `${indent}${serializeTag(tag, indent)}\n`).join(''); - } - return ''; -} - -function serializeAttrs(attrs: vite.HtmlTagDescriptor['attrs']): string { - let res = ''; - for (const key in attrs) { - if (typeof attrs[key] === 'boolean') { - res += attrs[key] ? ` ${key}` : ``; - } else { - res += ` ${key}=${JSON.stringify(attrs[key])}`; - } - } - return res; -} - -function incrementIndent(indent = '') { - return `${indent}${indent[0] === '\t' ? '\t' : ' '}`; -} diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index 86e4840f8888e..be1a7b20b0f56 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -1,5 +1,5 @@ import { fileURLToPath } from 'url'; -import type { HtmlTagDescriptor, ViteDevServer } from 'vite'; +import type { ViteDevServer } from 'vite'; import type { AstroConfig, AstroRenderer, @@ -17,7 +17,6 @@ import { RouteCache } from '../route-cache.js'; import { createModuleScriptElementWithSrcSet } from '../ssr-element.js'; import { collectMdMetadata } from '../util.js'; import { getStylesForURL } from './css.js'; -import { injectTags } from './html.js'; import { resolveClientDevPath } from './resolve.js'; export interface SSROptions { @@ -45,10 +44,6 @@ export interface SSROptions { export type ComponentPreload = [SSRLoadedRenderer[], ComponentInstance]; -export type RenderResponse = - | { type: 'html'; html: string; response: ResponseInit } - | { type: 'response'; response: Response }; - const svelteStylesRE = /svelte\?svelte&type=style/; async function loadRenderer( @@ -99,7 +94,7 @@ export async function render( renderers: SSRLoadedRenderer[], mod: ComponentInstance, ssrOpts: SSROptions -): Promise { +): Promise { const { astroConfig, filePath, @@ -167,7 +162,7 @@ export async function render( }); }); - let content = await coreRender({ + let response = await coreRender({ links, styles, logging, @@ -191,32 +186,13 @@ export async function render( ssr: isBuildingToSSR(astroConfig), }); - if (route?.type === 'endpoint' || content.type === 'response') { - return content; - } - - // inject tags - const tags: HtmlTagDescriptor[] = []; - - // add injected tags - let html = injectTags(content.html, tags); - - // inject if missing (TODO: is a more robust check needed for comments, etc.?) - if (!/\n' + content; - } - - return { - type: 'html', - html, - response: content.response, - }; + return response; } export async function ssr( preloadedComponent: ComponentPreload, ssrOpts: SSROptions -): Promise { +): Promise { const [renderers, mod] = preloadedComponent; return await render(renderers, mod, ssrOpts); // NOTE: without "await", errors won’t get caught below } diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 457efe44a28c4..154fb797befae 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -113,10 +113,12 @@ export function createResult(args: CreateResultArgs): SSRResult { const paginated = isPaginatedRoute(pageProps); const url = new URL(request.url); const canonicalURL = createCanonicalURL('.' + pathname, site ?? url.origin, paginated); + const headers = new Headers(); + headers.set('Transfer-Encoding', 'chunked'); const response: ResponseInit = { status: 200, statusText: 'OK', - headers: new Headers(), + headers, }; // Make headers be read-only diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 8c58711c58989..92cb5b4c867f2 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -11,6 +11,7 @@ import type { import { escapeHTML, HTMLString, markHTMLString } from './escape.js'; import { extractDirectives, generateHydrateScript } from './hydration.js'; +import { createResponse } from './response.js'; import { determineIfNeedsHydrationScript, determinesIfNeedsDirectiveScript, @@ -40,19 +41,21 @@ const svgEnumAttributes = /^(autoReverse|externalResourcesRequired|focusable|pre // INVESTIGATE: Can we have more specific types both for the argument and output? // If these are intentional, add comments that these are intention and why. // Or maybe type UserValue = any; ? -async function _render(child: any): Promise { +async function * _render(child: any): AsyncIterable { child = await child; if (child instanceof HTMLString) { - return child; + yield child; } else if (Array.isArray(child)) { - return markHTMLString((await Promise.all(child.map((value) => _render(value)))).join('')); + for(const value of child) { + yield markHTMLString(await _render(value)); + } } else if (typeof child === 'function') { // Special: If a child is a function, call it automatically. // This lets you do {() => ...} without the extra boilerplate // of wrapping it in a function and calling it. - return _render(child()); + yield * _render(child()); } else if (typeof child === 'string') { - return markHTMLString(escapeHTML(child)); + yield markHTMLString(escapeHTML(child)); } else if (!child && child !== 0) { // do nothing, safe to ignore falsey values. } @@ -62,9 +65,11 @@ async function _render(child: any): Promise { child instanceof AstroComponent || Object.prototype.toString.call(child) === '[object AstroComponent]' ) { - return markHTMLString(await renderAstroComponent(child)); + yield * renderAstroComponent(child); + } else if(typeof child === 'object' && Symbol.asyncIterator in child) { + yield * child; } else { - return child; + yield child; } } @@ -83,7 +88,7 @@ export class AstroComponent { return 'AstroComponent'; } - *[Symbol.iterator]() { + async *[Symbol.asyncIterator]() { const { htmlParts, expressions } = this; for (let i = 0; i < htmlParts.length; i++) { @@ -91,7 +96,7 @@ export class AstroComponent { const expression = expressions[i]; yield markHTMLString(html); - yield _render(expression); + yield * _render(expression); } } } @@ -120,9 +125,14 @@ export function createComponent(cb: AstroComponentFactory) { return cb; } -export async function renderSlot(_result: any, slotted: string, fallback?: any) { +export async function renderSlot(_result: any, slotted: string, fallback?: any): Promise { if (slotted) { - return await _render(slotted); + let iterator = _render(slotted); + let content = ''; + for await(const chunk of iterator) { + content += chunk; + } + return markHTMLString(content); } return fallback; } @@ -157,7 +167,7 @@ export async function renderComponent( Component: unknown, _props: Record, slots: any = {} -) { +): Promise> { Component = await Component; if (Component === Fragment) { const children = await renderSlot(result, slots?.default); @@ -168,8 +178,7 @@ export async function renderComponent( } if (Component && (Component as any).isAstroComponentFactory) { - const output = await renderToString(result, Component as any, _props, slots); - return markHTMLString(output); + return renderToIterable(result, Component as any, _props, slots); } if (!Component && !_props['client:only']) { @@ -317,13 +326,17 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr // as a string and the user is responsible for adding a script tag for the component definition. if (!html && typeof Component === 'string') { const childSlots = Object.values(children).join(''); - html = await renderAstroComponent( + const iterable = renderAstroComponent( await render`<${Component}${internalSpreadAttributes(props)}${markHTMLString( childSlots === '' && voidElementNames.test(Component) ? `/>` : `>${childSlots}` )}` ); + html = ''; + for await(const chunk of iterable) { + html += chunk; + } } if (!hydration) { @@ -597,45 +610,72 @@ export async function renderToString( children: any ): Promise { const Component = await componentFactory(result, props, children); + + if (!isAstroComponent(Component)) { + const response: Response = Component; + throw response; + } + + let html = ''; + for await(const chunk of renderAstroComponent(Component)) { + html += chunk; + } + return html; +} + +export async function renderToIterable( + result: SSRResult, + componentFactory: AstroComponentFactory, + props: any, + children: any +): Promise> { + const Component = await componentFactory(result, props, children); + if (!isAstroComponent(Component)) { + console.warn(`Returning a Response is only supported inside of page components. Consider refactoring this logic into something like a function that can be used in the page.`); const response: Response = Component; throw response; } - let template = await renderAstroComponent(Component); - return template; + return renderAstroComponent(Component); } +const encoder = new TextEncoder(); + export async function renderPage( result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any -): Promise<{ type: 'html'; html: string } | { type: 'response'; response: Response }> { - try { - const response = await componentFactory(result, props, children); - - if (isAstroComponent(response)) { - let html = await renderAstroComponent(response); - return { - type: 'html', - html, - }; - } else { - return { - type: 'response', - response, - }; - } - } catch (err) { - if (err instanceof Response) { - return { - type: 'response', - response: err, - }; - } else { - throw err; - } +): Promise { + const factoryReturnValue = await componentFactory(result, props, children); + + if (isAstroComponent(factoryReturnValue)) { + let iterable = renderAstroComponent(factoryReturnValue); + let stream = new ReadableStream({ + start(controller) { + async function read() { + let i = 0; + for await(const chunk of iterable) { + let html = chunk.toString(); + if(i === 0) { + if (!/\n')); + } + } + controller.enqueue(encoder.encode(html)); + i++; + } + controller.close(); + } + read(); + } + }); + let init = result.response; + let response = createResponse(stream, init); + return response; + } else { + return factoryReturnValue; } } @@ -676,16 +716,14 @@ export function maybeRenderHead(result: SSRResult): string | Promise { return renderHead(result); } -export async function renderAstroComponent(component: InstanceType) { - let template = []; - +export async function * renderAstroComponent(component: InstanceType): AsyncIterable { for await (const value of component) { if (value || value === 0) { - template.push(value); + for await(const chunk of _render(value)) { + yield markHTMLString(chunk); + } } } - - return markHTMLString(await _render(template)); } function componentIsHTMLElement(Component: unknown) { diff --git a/packages/astro/src/runtime/server/response.ts b/packages/astro/src/runtime/server/response.ts new file mode 100644 index 0000000000000..d0bf8fefd28ca --- /dev/null +++ b/packages/astro/src/runtime/server/response.ts @@ -0,0 +1,71 @@ + +const isNodeJS = typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]'; + +let StreamingCompatibleResponse: typeof Response | undefined; + +function createResponseClass() { + StreamingCompatibleResponse = class extends Response { + #isStream: boolean; + #body: any; + constructor(body?: BodyInit | null, init?: ResponseInit) { + let isStream = body instanceof ReadableStream; + super(isStream ? null : body, init); + this.#isStream = isStream; + this.#body = body; + } + + get body() { + return this.#body; + } + + async text(): Promise { + if(this.#isStream && isNodeJS) { + let decoder = new TextDecoder(); + let body = this.#body as ReadableStream; + let reader = body.getReader(); + let buffer: number[] = []; + while(true) { + let r = await reader.read(); + if(r.value) { + buffer.push(...r.value); + } + if(r.done) { + break; + } + } + return decoder.decode(Uint8Array.from(buffer)); + } + return super.text(); + } + + async arrayBuffer(): Promise { + if(this.#isStream && isNodeJS) { + let body = this.#body as ReadableStream; + let reader = body.getReader(); + let chunks: number[] = []; + while(true) { + let r = await reader.read(); + if(r.value) { + chunks.push(...r.value); + } + if(r.done) { + break; + } + } + return Uint8Array.from(chunks); + } + return super.arrayBuffer(); + } + } + + return StreamingCompatibleResponse; +} + +type CreateResponseFn = (body?: BodyInit | null, init?: ResponseInit) => Response; + +export const createResponse: CreateResponseFn = isNodeJS ? (body, init) => { + if(typeof StreamingCompatibleResponse === 'undefined') { + return new (createResponseClass())(body, init); + } + return new StreamingCompatibleResponse(body, init); +} : (body, init) => new Response(body, init); diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index d3ad53eff57d6..a26e66a98bb24 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -1,15 +1,16 @@ import type http from 'http'; -import { Readable } from 'stream'; -import stripAnsi from 'strip-ansi'; import type * as vite from 'vite'; import type { AstroConfig, ManifestData } from '../@types/astro'; +import type { SSROptions } from '../core/render/dev/index'; + +import { Readable } from 'stream'; +import stripAnsi from 'strip-ansi'; import { call as callEndpoint } from '../core/endpoint/dev/index.js'; import { fixViteErrorMessage } from '../core/errors.js'; import { error, info, LogOptions, warn } from '../core/logger/core.js'; import * as msg from '../core/messages.js'; import { appendForwardSlash } from '../core/path.js'; import { getParamsAndProps, GetParamsAndPropsError } from '../core/render/core.js'; -import type { RenderResponse, SSROptions } from '../core/render/dev/index'; import { preload, ssr } from '../core/render/dev/index.js'; import { RouteCache } from '../core/render/route-cache.js'; import { createRequest } from '../core/request.js'; @@ -75,7 +76,12 @@ async function writeWebResponse(res: http.ServerResponse, webResponse: Response) res.writeHead(status, _headers); if (body) { - if (body instanceof Readable) { + if(Symbol.for('astro.responseBody') in webResponse) { + let stream = (webResponse as any)[Symbol.for('astro.responseBody')]; + for await(const chunk of stream) { + res.write(chunk.toString()); + } + } else if (body instanceof Readable) { body.pipe(res); return; } else { @@ -93,23 +99,10 @@ async function writeWebResponse(res: http.ServerResponse, webResponse: Response) } async function writeSSRResult( - result: RenderResponse, - res: http.ServerResponse, - statusCode: 200 | 404 + webResponse: Response, + res: http.ServerResponse ) { - if (result.type === 'response') { - const { response } = result; - await writeWebResponse(res, response); - return; - } - - const { html, response: init } = result; - const headers = init.headers as Headers; - - headers.set('Content-Type', 'text/html; charset=utf-8'); - headers.set('Content-Length', Buffer.byteLength(html, 'utf-8').toString()); - - return writeWebResponse(res, new Response(html, init)); + return writeWebResponse(res, webResponse); } async function handle404Response( @@ -296,7 +289,7 @@ async function handleRequest( routeCache, viteServer, }); - return await writeSSRResult(result, res, statusCode); + return await writeSSRResult(result, res); } else { return handle404Response(origin, config, req, res); } @@ -326,7 +319,7 @@ async function handleRequest( } } else { const result = await ssr(preloadedComponent, options); - return await writeSSRResult(result, res, statusCode); + return await writeSSRResult(result, res); } } catch (_err) { const err = fixViteErrorMessage(createSafeError(_err), viteServer); diff --git a/packages/astro/test/astro-response.test.js b/packages/astro/test/astro-response.test.js index 195247ebae450..050feaabbf4c0 100644 --- a/packages/astro/test/astro-response.test.js +++ b/packages/astro/test/astro-response.test.js @@ -24,9 +24,4 @@ describe('Returning responses', () => { let response = await fixture.fetch('/not-found'); expect(response.status).to.equal(404); }); - - it('Works from a component', async () => { - let response = await fixture.fetch('/not-found-component'); - expect(response.status).to.equal(404); - }); }); diff --git a/packages/astro/test/fixtures/astro-response/src/components/not-found.astro b/packages/astro/test/fixtures/astro-response/src/components/not-found.astro deleted file mode 100644 index dd339e72b7753..0000000000000 --- a/packages/astro/test/fixtures/astro-response/src/components/not-found.astro +++ /dev/null @@ -1,6 +0,0 @@ ---- -return new Response(null, { - status: 404, - statusText: `Not found` -}); ---- diff --git a/packages/astro/test/fixtures/astro-response/src/pages/not-found-component.astro b/packages/astro/test/fixtures/astro-response/src/pages/not-found-component.astro deleted file mode 100644 index e1077e9c9a75b..0000000000000 --- a/packages/astro/test/fixtures/astro-response/src/pages/not-found-component.astro +++ /dev/null @@ -1,4 +0,0 @@ ---- -import NotFound from '../components/not-found.astro'; ---- - diff --git a/packages/astro/test/fixtures/streaming/astro.config.mjs b/packages/astro/test/fixtures/streaming/astro.config.mjs new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/packages/astro/test/fixtures/streaming/package.json b/packages/astro/test/fixtures/streaming/package.json new file mode 100644 index 0000000000000..a27a51b6dcf4a --- /dev/null +++ b/packages/astro/test/fixtures/streaming/package.json @@ -0,0 +1,11 @@ +{ + "name": "@test/streaming", + "version": "0.0.0", + "private": true, + "scripts": { + "dev": "astro dev" + }, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/streaming/src/components/AsyncEach.astro b/packages/astro/test/fixtures/streaming/src/components/AsyncEach.astro new file mode 100644 index 0000000000000..02db971cc17e0 --- /dev/null +++ b/packages/astro/test/fixtures/streaming/src/components/AsyncEach.astro @@ -0,0 +1,11 @@ +--- +const { iterable } = Astro.props; +--- + +{(async function * () { + for await(const value of iterable) { + let html = await Astro.slots.render('default', [value]); + yield ; + yield '\n'; + } +})()} diff --git a/packages/astro/test/fixtures/streaming/src/components/Header.astro b/packages/astro/test/fixtures/streaming/src/components/Header.astro new file mode 100644 index 0000000000000..92d650253ff5a --- /dev/null +++ b/packages/astro/test/fixtures/streaming/src/components/Header.astro @@ -0,0 +1,7 @@ +--- +import { wait } from '../wait'; +await wait(10); +--- +
    +

    My Site

    +
    diff --git a/packages/astro/test/fixtures/streaming/src/pages/index.astro b/packages/astro/test/fixtures/streaming/src/pages/index.astro new file mode 100644 index 0000000000000..ef0e8eb49b9a8 --- /dev/null +++ b/packages/astro/test/fixtures/streaming/src/pages/index.astro @@ -0,0 +1,32 @@ +--- +import Header from '../components/Header.astro'; +import AsyncEach from '../components/AsyncEach.astro'; +import { wait } from '../wait'; + +async function * list() { + const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + for(const num of nums) { + await wait(15); + yield num; + } +} +--- + +Testing + +

    Title

    +
    +
    +
    + +
    {Promise.resolve(12)}
    + +
      + + {(num: number) => ( +
    • Number: {num}
    • + )} +
      +
    + + diff --git a/packages/astro/test/fixtures/streaming/src/wait.ts b/packages/astro/test/fixtures/streaming/src/wait.ts new file mode 100644 index 0000000000000..304559799c762 --- /dev/null +++ b/packages/astro/test/fixtures/streaming/src/wait.ts @@ -0,0 +1,4 @@ + +export function wait(ms: number): Promise { + return new Promise(resolve => setTimeout(resolve, ms)); +} diff --git a/packages/astro/test/streaming.test.js b/packages/astro/test/streaming.test.js new file mode 100644 index 0000000000000..489e2ab19e48e --- /dev/null +++ b/packages/astro/test/streaming.test.js @@ -0,0 +1,74 @@ +import { isWindows, loadFixture } from './test-utils.js'; +import { expect } from 'chai'; +import testAdapter from './test-adapter.js'; +import * as cheerio from 'cheerio'; + + +describe('Streaming', () => { + if (isWindows) return; + + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/streaming/', + adapter: testAdapter(), + experimental: { + ssr: true, + }, + }); + }); + + describe('Development', () => { + /** @type {import('./test-utils').DevServer} */ + let devServer; + + before(async () => { + devServer = await fixture.startDevServer(); + }); + + after(async () => { + await devServer.stop(); + }); + + it('Body is chunked', async () => { + let res = await fixture.fetch('/'); + let chunks = []; + for await(const bytes of res.body) { + let chunk = bytes.toString('utf-8'); + chunks.push(chunk); + } + expect(chunks.length).to.be.greaterThan(1); + }); + }); + + describe('Production', () => { + before(async () => { + await fixture.build(); + }); + + it('Can get the full html body', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/'); + const response = await app.render(request); + const html = await response.text(); + const $ = cheerio.load(html); + expect($('header h1')).to.have.a.lengthOf(1); + expect($('ul li')).to.have.a.lengthOf(10); + }); + + it('Body is chunked', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/'); + const response = await app.render(request); + let chunks = []; + let decoder = new TextDecoder(); + for await(const bytes of response.body) { + let chunk = decoder.decode(bytes); + chunks.push(chunk); + } + expect(chunks.length).to.be.greaterThan(1); + }); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a7b468ed11267..b42e76d32e6b3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -515,7 +515,6 @@ importers: gray-matter: ^4.0.3 html-entities: ^2.3.3 html-escaper: ^3.0.3 - htmlparser2: ^7.2.0 kleur: ^4.1.4 magic-string: ^0.25.9 micromorph: ^0.1.2 @@ -574,7 +573,6 @@ importers: gray-matter: 4.0.3 html-entities: 2.3.3 html-escaper: 3.0.3 - htmlparser2: 7.2.0 kleur: 4.1.4 magic-string: 0.25.9 micromorph: 0.1.2 @@ -1701,6 +1699,12 @@ importers: packages/astro/test/fixtures/static-build/pkg: specifiers: {} + packages/astro/test/fixtures/streaming: + specifiers: + astro: workspace:* + dependencies: + astro: link:../../.. + packages/astro/test/fixtures/svelte-component: specifiers: '@astrojs/svelte': workspace:* @@ -8696,14 +8700,6 @@ packages: csstype: 3.1.0 dev: false - /dom-serializer/1.4.1: - resolution: {integrity: sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==} - dependencies: - domelementtype: 2.3.0 - domhandler: 4.3.1 - entities: 2.2.0 - dev: false - /dom-serializer/2.0.0: resolution: {integrity: sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==} dependencies: @@ -8714,13 +8710,7 @@ packages: /domelementtype/2.3.0: resolution: {integrity: sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==} - - /domhandler/4.3.1: - resolution: {integrity: sha512-GrwoxYN+uWlzO8uhUXRl0P+kHE4GtVPfYzVLcUxPL7KNdHKj66vvlhiweIHqYYXWlw+T8iLMp42Lm67ghw4WMQ==} - engines: {node: '>= 4'} - dependencies: - domelementtype: 2.3.0 - dev: false + dev: true /domhandler/5.0.3: resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==} @@ -8729,14 +8719,6 @@ packages: domelementtype: 2.3.0 dev: true - /domutils/2.8.0: - resolution: {integrity: sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==} - dependencies: - dom-serializer: 1.4.1 - domelementtype: 2.3.0 - domhandler: 4.3.1 - dev: false - /domutils/3.0.1: resolution: {integrity: sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==} dependencies: @@ -8811,15 +8793,6 @@ packages: ansi-colors: 4.1.1 dev: true - /entities/2.2.0: - resolution: {integrity: sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==} - dev: false - - /entities/3.0.1: - resolution: {integrity: sha512-WiyBqoomrwMdFG1e0kqvASYfnlb0lp8M5o5Fw2OFq1hNZxxcNk8Ik0Xm7LxzBhuidnZB/UtBqVCgUz3kBOP51Q==} - engines: {node: '>=0.12'} - dev: false - /entities/4.3.0: resolution: {integrity: sha512-/iP1rZrSEJ0DTlPiX+jbzlA3eVkY/e8L8SozroF395fIqE3TYF/Nz7YOMAawta+vLmyJ/hkGNNPcSbMADCCXbg==} engines: {node: '>=0.12'} @@ -9970,15 +9943,6 @@ packages: resolution: {integrity: sha512-0quDb7s97CfemeJAnW9wC0hw78MtW7NU3hqtCD75g2vFlDLt36llsYD7uB7SUzojLMP24N5IatXf7ylGXiGG9A==} dev: false - /htmlparser2/7.2.0: - resolution: {integrity: sha512-H7MImA4MS6cw7nbyURtLPO1Tms7C5H602LRETv95z1MxO/7CP7rDVROehUYeYBUYEON94NXXDEPmZuq+hX4sog==} - dependencies: - domelementtype: 2.3.0 - domhandler: 4.3.1 - domutils: 2.8.0 - entities: 3.0.1 - dev: false - /htmlparser2/8.0.1: resolution: {integrity: sha512-4lVbmc1diZC7GUJQtRQ5yBAeUCL1exyMwmForWkRLnwyzWBFxN633SALPMGYaWZvKe9j1pRZJpauvmxENSp/EA==} dependencies: From 69c955b2bf32bd5f0723b999a67257de50101321 Mon Sep 17 00:00:00 2001 From: matthewp Date: Fri, 24 Jun 2022 19:37:09 +0000 Subject: [PATCH 23/58] [ci] format --- packages/astro/src/core/render/core.ts | 4 +- packages/astro/src/runtime/server/index.ts | 36 ++++---- packages/astro/src/runtime/server/response.ts | 86 ++++++++++--------- .../src/vite-plugin-astro-server/index.ts | 9 +- packages/astro/test/streaming.test.js | 5 +- 5 files changed, 70 insertions(+), 70 deletions(-) diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index c9c46fda17359..2487a79e41410 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -83,9 +83,7 @@ export interface RenderOptions { request: Request; } -export async function render( - opts: RenderOptions -): Promise { +export async function render(opts: RenderOptions): Promise { const { links, styles, diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 92cb5b4c867f2..c55328c161895 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -41,19 +41,19 @@ const svgEnumAttributes = /^(autoReverse|externalResourcesRequired|focusable|pre // INVESTIGATE: Can we have more specific types both for the argument and output? // If these are intentional, add comments that these are intention and why. // Or maybe type UserValue = any; ? -async function * _render(child: any): AsyncIterable { +async function* _render(child: any): AsyncIterable { child = await child; if (child instanceof HTMLString) { yield child; } else if (Array.isArray(child)) { - for(const value of child) { + for (const value of child) { yield markHTMLString(await _render(value)); } } else if (typeof child === 'function') { // Special: If a child is a function, call it automatically. // This lets you do {() => ...} without the extra boilerplate // of wrapping it in a function and calling it. - yield * _render(child()); + yield* _render(child()); } else if (typeof child === 'string') { yield markHTMLString(escapeHTML(child)); } else if (!child && child !== 0) { @@ -65,9 +65,9 @@ async function * _render(child: any): AsyncIterable { child instanceof AstroComponent || Object.prototype.toString.call(child) === '[object AstroComponent]' ) { - yield * renderAstroComponent(child); - } else if(typeof child === 'object' && Symbol.asyncIterator in child) { - yield * child; + yield* renderAstroComponent(child); + } else if (typeof child === 'object' && Symbol.asyncIterator in child) { + yield* child; } else { yield child; } @@ -96,7 +96,7 @@ export class AstroComponent { const expression = expressions[i]; yield markHTMLString(html); - yield * _render(expression); + yield* _render(expression); } } } @@ -129,7 +129,7 @@ export async function renderSlot(_result: any, slotted: string, fallback?: any): if (slotted) { let iterator = _render(slotted); let content = ''; - for await(const chunk of iterator) { + for await (const chunk of iterator) { content += chunk; } return markHTMLString(content); @@ -334,7 +334,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr )}` ); html = ''; - for await(const chunk of iterable) { + for await (const chunk of iterable) { html += chunk; } } @@ -617,7 +617,7 @@ export async function renderToString( } let html = ''; - for await(const chunk of renderAstroComponent(Component)) { + for await (const chunk of renderAstroComponent(Component)) { html += chunk; } return html; @@ -632,7 +632,9 @@ export async function renderToIterable( const Component = await componentFactory(result, props, children); if (!isAstroComponent(Component)) { - console.warn(`Returning a Response is only supported inside of page components. Consider refactoring this logic into something like a function that can be used in the page.`); + console.warn( + `Returning a Response is only supported inside of page components. Consider refactoring this logic into something like a function that can be used in the page.` + ); const response: Response = Component; throw response; } @@ -656,9 +658,9 @@ export async function renderPage( start(controller) { async function read() { let i = 0; - for await(const chunk of iterable) { + for await (const chunk of iterable) { let html = chunk.toString(); - if(i === 0) { + if (i === 0) { if (!/\n')); } @@ -669,7 +671,7 @@ export async function renderPage( controller.close(); } read(); - } + }, }); let init = result.response; let response = createResponse(stream, init); @@ -716,10 +718,12 @@ export function maybeRenderHead(result: SSRResult): string | Promise { return renderHead(result); } -export async function * renderAstroComponent(component: InstanceType): AsyncIterable { +export async function* renderAstroComponent( + component: InstanceType +): AsyncIterable { for await (const value of component) { if (value || value === 0) { - for await(const chunk of _render(value)) { + for await (const chunk of _render(value)) { yield markHTMLString(chunk); } } diff --git a/packages/astro/src/runtime/server/response.ts b/packages/astro/src/runtime/server/response.ts index d0bf8fefd28ca..084ea7436c999 100644 --- a/packages/astro/src/runtime/server/response.ts +++ b/packages/astro/src/runtime/server/response.ts @@ -1,5 +1,5 @@ - -const isNodeJS = typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]'; +const isNodeJS = + typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]'; let StreamingCompatibleResponse: typeof Response | undefined; @@ -13,59 +13,61 @@ function createResponseClass() { this.#isStream = isStream; this.#body = body; } - + get body() { return this.#body; } - + async text(): Promise { - if(this.#isStream && isNodeJS) { - let decoder = new TextDecoder(); - let body = this.#body as ReadableStream; - let reader = body.getReader(); - let buffer: number[] = []; - while(true) { - let r = await reader.read(); - if(r.value) { - buffer.push(...r.value); - } - if(r.done) { - break; - } + if (this.#isStream && isNodeJS) { + let decoder = new TextDecoder(); + let body = this.#body as ReadableStream; + let reader = body.getReader(); + let buffer: number[] = []; + while (true) { + let r = await reader.read(); + if (r.value) { + buffer.push(...r.value); + } + if (r.done) { + break; } - return decoder.decode(Uint8Array.from(buffer)); } - return super.text(); + return decoder.decode(Uint8Array.from(buffer)); + } + return super.text(); } - + async arrayBuffer(): Promise { - if(this.#isStream && isNodeJS) { - let body = this.#body as ReadableStream; - let reader = body.getReader(); - let chunks: number[] = []; - while(true) { - let r = await reader.read(); - if(r.value) { - chunks.push(...r.value); - } - if(r.done) { - break; - } + if (this.#isStream && isNodeJS) { + let body = this.#body as ReadableStream; + let reader = body.getReader(); + let chunks: number[] = []; + while (true) { + let r = await reader.read(); + if (r.value) { + chunks.push(...r.value); + } + if (r.done) { + break; } - return Uint8Array.from(chunks); } - return super.arrayBuffer(); + return Uint8Array.from(chunks); + } + return super.arrayBuffer(); } - } - + }; + return StreamingCompatibleResponse; } type CreateResponseFn = (body?: BodyInit | null, init?: ResponseInit) => Response; -export const createResponse: CreateResponseFn = isNodeJS ? (body, init) => { - if(typeof StreamingCompatibleResponse === 'undefined') { - return new (createResponseClass())(body, init); - } - return new StreamingCompatibleResponse(body, init); -} : (body, init) => new Response(body, init); +export const createResponse: CreateResponseFn = isNodeJS + ? (body, init) => { + if (typeof StreamingCompatibleResponse === 'undefined') { + return new (createResponseClass())(body, init); + } + return new StreamingCompatibleResponse(body, init); + } + : (body, init) => new Response(body, init); diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index a26e66a98bb24..bf1a57a5114a8 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -76,9 +76,9 @@ async function writeWebResponse(res: http.ServerResponse, webResponse: Response) res.writeHead(status, _headers); if (body) { - if(Symbol.for('astro.responseBody') in webResponse) { + if (Symbol.for('astro.responseBody') in webResponse) { let stream = (webResponse as any)[Symbol.for('astro.responseBody')]; - for await(const chunk of stream) { + for await (const chunk of stream) { res.write(chunk.toString()); } } else if (body instanceof Readable) { @@ -98,10 +98,7 @@ async function writeWebResponse(res: http.ServerResponse, webResponse: Response) res.end(); } -async function writeSSRResult( - webResponse: Response, - res: http.ServerResponse -) { +async function writeSSRResult(webResponse: Response, res: http.ServerResponse) { return writeWebResponse(res, webResponse); } diff --git a/packages/astro/test/streaming.test.js b/packages/astro/test/streaming.test.js index 489e2ab19e48e..7d28387d38ab8 100644 --- a/packages/astro/test/streaming.test.js +++ b/packages/astro/test/streaming.test.js @@ -3,7 +3,6 @@ import { expect } from 'chai'; import testAdapter from './test-adapter.js'; import * as cheerio from 'cheerio'; - describe('Streaming', () => { if (isWindows) return; @@ -35,7 +34,7 @@ describe('Streaming', () => { it('Body is chunked', async () => { let res = await fixture.fetch('/'); let chunks = []; - for await(const bytes of res.body) { + for await (const bytes of res.body) { let chunk = bytes.toString('utf-8'); chunks.push(chunk); } @@ -64,7 +63,7 @@ describe('Streaming', () => { const response = await app.render(request); let chunks = []; let decoder = new TextDecoder(); - for await(const bytes of response.body) { + for await (const bytes of response.body) { let chunk = decoder.decode(bytes); chunks.push(chunk); } From 47c81effa69fb5d7f1e576f88c27d5071f1888e3 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 24 Jun 2022 15:55:06 -0400 Subject: [PATCH 24/58] Make Astro.redirect use a 302 status code (#3700) * Make Astro.redirect use a 302 status code * Adds a changeset * Add a package.json --- .changeset/stupid-steaks-hang.md | 5 ++++ packages/astro/src/core/render/result.ts | 2 +- .../test/fixtures/ssr-redirect/package.json | 8 ++++++ .../ssr-redirect/src/pages/secret.astro | 3 +++ packages/astro/test/ssr-redirect.test.js | 27 +++++++++++++++++++ pnpm-lock.yaml | 6 +++++ 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .changeset/stupid-steaks-hang.md create mode 100644 packages/astro/test/fixtures/ssr-redirect/package.json create mode 100644 packages/astro/test/fixtures/ssr-redirect/src/pages/secret.astro create mode 100644 packages/astro/test/ssr-redirect.test.js diff --git a/.changeset/stupid-steaks-hang.md b/.changeset/stupid-steaks-hang.md new file mode 100644 index 0000000000000..157e89480b816 --- /dev/null +++ b/.changeset/stupid-steaks-hang.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Make Astro.redirect use a 302 status code diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 154fb797befae..cfbc4852138fe 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -152,7 +152,7 @@ export function createResult(args: CreateResultArgs): SSRResult { redirect: args.ssr ? (path: string) => { return new Response(null, { - status: 301, + status: 302, headers: { Location: path, }, diff --git a/packages/astro/test/fixtures/ssr-redirect/package.json b/packages/astro/test/fixtures/ssr-redirect/package.json new file mode 100644 index 0000000000000..9017715ce70af --- /dev/null +++ b/packages/astro/test/fixtures/ssr-redirect/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/ssr-redirect", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/ssr-redirect/src/pages/secret.astro b/packages/astro/test/fixtures/ssr-redirect/src/pages/secret.astro new file mode 100644 index 0000000000000..f8fc808e7ade0 --- /dev/null +++ b/packages/astro/test/fixtures/ssr-redirect/src/pages/secret.astro @@ -0,0 +1,3 @@ +--- +return Astro.redirect('/login'); +--- diff --git a/packages/astro/test/ssr-redirect.test.js b/packages/astro/test/ssr-redirect.test.js new file mode 100644 index 0000000000000..29fe701f7a00f --- /dev/null +++ b/packages/astro/test/ssr-redirect.test.js @@ -0,0 +1,27 @@ +import { expect } from 'chai'; +import { loadFixture } from './test-utils.js'; +import testAdapter from './test-adapter.js'; + +describe('Astro.redirect', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/ssr-redirect/', + experimental: { + ssr: true, + }, + adapter: testAdapter(), + }); + await fixture.build(); + }); + + it('Returns a 302 status', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/secret'); + const response = await app.render(request); + expect(response.status).to.equal(302); + expect(response.headers.get('location')).to.equal('/login'); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b42e76d32e6b3..666af67896d12 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1636,6 +1636,12 @@ importers: '@astrojs/partytown': link:../../../../integrations/partytown astro: link:../../.. + packages/astro/test/fixtures/ssr-redirect: + specifiers: + astro: workspace:* + dependencies: + astro: link:../../.. + packages/astro/test/fixtures/ssr-scripts: specifiers: '@astrojs/preact': 'workspace:' From 67b5aa4ca48b7dc3441cb83cbbf598affe5b640f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 24 Jun 2022 16:05:02 -0400 Subject: [PATCH 25/58] [ci] release (#3701) Co-authored-by: github-actions[bot] --- .changeset/five-zoos-look.md | 5 -- .changeset/funny-pianos-mix.md | 40 ------------- .changeset/stupid-steaks-hang.md | 5 -- examples/basics/package.json | 2 +- examples/blog-multiple-authors/package.json | 2 +- examples/blog/package.json | 2 +- examples/component/demo/package.json | 2 +- examples/component/package.json | 2 +- examples/docs/package.json | 2 +- examples/env-vars/package.json | 2 +- examples/framework-alpine/package.json | 2 +- examples/framework-lit/package.json | 2 +- examples/framework-multiple/package.json | 2 +- examples/framework-preact/package.json | 2 +- examples/framework-react/package.json | 2 +- examples/framework-solid/package.json | 2 +- examples/framework-svelte/package.json | 2 +- examples/framework-vue/package.json | 2 +- examples/integrations-playground/package.json | 2 +- examples/minimal/package.json | 2 +- examples/non-html-pages/package.json | 2 +- examples/portfolio/package.json | 2 +- examples/ssr/package.json | 2 +- examples/starter/package.json | 2 +- examples/subpath/package.json | 2 +- examples/with-markdown-plugins/package.json | 2 +- examples/with-markdown-shiki/package.json | 2 +- examples/with-markdown/package.json | 2 +- examples/with-nanostores/package.json | 2 +- examples/with-tailwindcss/package.json | 2 +- examples/with-vite-plugin-pwa/package.json | 2 +- packages/astro/CHANGELOG.md | 43 ++++++++++++++ packages/astro/package.json | 2 +- packages/integrations/cloudflare/CHANGELOG.md | 6 ++ packages/integrations/cloudflare/package.json | 2 +- pnpm-lock.yaml | 56 +++++++++---------- 36 files changed, 107 insertions(+), 108 deletions(-) delete mode 100644 .changeset/five-zoos-look.md delete mode 100644 .changeset/funny-pianos-mix.md delete mode 100644 .changeset/stupid-steaks-hang.md diff --git a/.changeset/five-zoos-look.md b/.changeset/five-zoos-look.md deleted file mode 100644 index f882dee9bcf70..0000000000000 --- a/.changeset/five-zoos-look.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@astrojs/cloudflare': patch ---- - -fix custom 404 pages not rendering diff --git a/.changeset/funny-pianos-mix.md b/.changeset/funny-pianos-mix.md deleted file mode 100644 index 249ba4deada27..0000000000000 --- a/.changeset/funny-pianos-mix.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -'astro': patch ---- - -Support for streaming responses - -Astro supports streaming in its templates. Any time Astro encounters an async boundary it will stream out HTML that occurs before it. For example: - -```astro ---- -import LoadTodos from '../components/LoadTodos.astro'; ---- - - -App - - - - - -``` - -In this arbtrary example Astro will streaming out the `` section and everything else until it encounters `` and then stop. LoadTodos, which is also an Astro component will stream its contents as well; stopping and waiting at any other asynchronous components. - -As part of this Astro also now supports async iterables within its templates. This means you can do this: - -```astro -
      - {(async function * () { - for(const number of numbers) { - await wait(1000); - - yield
    • Number: {number}
    • - yield '\n' - } - })()} -
    -``` - -Which will stream out `
  • `s one at a time, waiting a second between each. diff --git a/.changeset/stupid-steaks-hang.md b/.changeset/stupid-steaks-hang.md deleted file mode 100644 index 157e89480b816..0000000000000 --- a/.changeset/stupid-steaks-hang.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Make Astro.redirect use a 302 status code diff --git a/examples/basics/package.json b/examples/basics/package.json index d87a9c6000964..db7d28f1eb050 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/blog-multiple-authors/package.json b/examples/blog-multiple-authors/package.json index 4e397b0559f7c..ffc3f1ddb5b7e 100644 --- a/examples/blog-multiple-authors/package.json +++ b/examples/blog-multiple-authors/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.54", + "astro": "^1.0.0-beta.55", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/blog/package.json b/examples/blog/package.json index 8ff8252367d54..0014609908c8d 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/component/demo/package.json b/examples/component/demo/package.json index 2bf06211727ce..1e3408492c1bb 100644 --- a/examples/component/demo/package.json +++ b/examples/component/demo/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@example/my-component": "workspace:*", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/component/package.json b/examples/component/package.json index 16c1593499752..1bd5af19f8739 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -8,6 +8,6 @@ "serve": "astro --root demo preview" }, "devDependencies": { - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/docs/package.json b/examples/docs/package.json index e27a421c6ac0e..a464038e5ce0c 100644 --- a/examples/docs/package.json +++ b/examples/docs/package.json @@ -20,6 +20,6 @@ "devDependencies": { "@astrojs/preact": "^0.2.0", "@astrojs/react": "^0.2.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/env-vars/package.json b/examples/env-vars/package.json index aef9b036522c6..0e0b6ca7c0247 100644 --- a/examples/env-vars/package.json +++ b/examples/env-vars/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index f07762b55721a..96a6bd6bca86f 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "alpinejs": "^3.10.2" diff --git a/examples/framework-lit/package.json b/examples/framework-lit/package.json index 86077aa0e8d19..c00c36c82afe8 100644 --- a/examples/framework-lit/package.json +++ b/examples/framework-lit/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/lit": "^0.3.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index f7af906e037f8..a95e648b4c725 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -15,7 +15,7 @@ "@astrojs/solid-js": "^0.2.0", "@astrojs/svelte": "^0.2.0", "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 5085607dfafd4..36842a4312d61 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index a9378a304f49d..0d8533e4ebcf4 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -12,7 +12,7 @@ "@astrojs/react": "^0.2.0", "@types/react": "^18.0.10", "@types/react-dom": "^18.0.5", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "react": "^18.1.0", diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index 3f1bc3ec5a0a3..82ddc9d8ca505 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/solid-js": "^0.2.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "solid-js": "^1.4.3" diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index 60d18f27aa1ec..c8ec4fb36b88a 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/svelte": "^0.2.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "svelte": "^3.48.0" diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 72552314b81af..6e53ef3d95db2 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "vue": "^3.2.36" diff --git a/examples/integrations-playground/package.json b/examples/integrations-playground/package.json index c585717977b72..d0d8bf2d01d03 100644 --- a/examples/integrations-playground/package.json +++ b/examples/integrations-playground/package.json @@ -16,7 +16,7 @@ "@astrojs/solid-js": "0.2.0", "@astrojs/tailwind": "^0.2.1", "@astrojs/turbolinks": "^0.1.3", - "astro": "^1.0.0-beta.54", + "astro": "^1.0.0-beta.55", "solid-js": "^1.4.3" }, "dependencies": { diff --git a/examples/minimal/package.json b/examples/minimal/package.json index b887e42a76a32..b2aa9ee99cb9e 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/non-html-pages/package.json b/examples/non-html-pages/package.json index 022ece7dec04d..19194e4f82b0f 100644 --- a/examples/non-html-pages/package.json +++ b/examples/non-html-pages/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index 2be4e7c52ad4d..5f5fa50406927 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.54", + "astro": "^1.0.0-beta.55", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/ssr/package.json b/examples/ssr/package.json index abda3716e1c06..9230d4812e23b 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -11,7 +11,7 @@ "devDependencies": { "@astrojs/node": "^0.1.2", "@astrojs/svelte": "^0.2.0", - "astro": "^1.0.0-beta.54", + "astro": "^1.0.0-beta.55", "concurrently": "^7.2.1", "lightcookie": "^1.0.25", "unocss": "^0.15.6", diff --git a/examples/starter/package.json b/examples/starter/package.json index 798e207a5dff1..a38003cabf502 100644 --- a/examples/starter/package.json +++ b/examples/starter/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/subpath/package.json b/examples/subpath/package.json index d19ed5e0ed9d0..2fc51a223ee7d 100644 --- a/examples/subpath/package.json +++ b/examples/subpath/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/react": "^0.2.0", - "astro": "^1.0.0-beta.54", + "astro": "^1.0.0-beta.55", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/with-markdown-plugins/package.json b/examples/with-markdown-plugins/package.json index 8fe0df1c94b33..31506955a7b83 100644 --- a/examples/with-markdown-plugins/package.json +++ b/examples/with-markdown-plugins/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.54", + "astro": "^1.0.0-beta.55", "hast-util-select": "5.0.1", "rehype-autolink-headings": "^6.1.1", "rehype-slug": "^5.0.1", diff --git a/examples/with-markdown-shiki/package.json b/examples/with-markdown-shiki/package.json index 9b8624634d5f3..748d7ba7592d3 100644 --- a/examples/with-markdown-shiki/package.json +++ b/examples/with-markdown-shiki/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/with-markdown/package.json b/examples/with-markdown/package.json index e3c7c0a4c8cb7..e0b5c3b3ee720 100644 --- a/examples/with-markdown/package.json +++ b/examples/with-markdown/package.json @@ -14,7 +14,7 @@ "@astrojs/react": "^0.2.0", "@astrojs/svelte": "^0.2.0", "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" }, "dependencies": { "preact": "^10.7.3", diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index 1d628de3a967b..a00b0ebb6b890 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -25,6 +25,6 @@ "@astrojs/solid-js": "^0.2.0", "@astrojs/svelte": "^0.2.0", "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.54" + "astro": "^1.0.0-beta.55" } } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index 25f2bcf4be5f3..e5f8d54d03545 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/tailwind": "^0.2.1", - "astro": "^1.0.0-beta.54", + "astro": "^1.0.0-beta.55", "autoprefixer": "^10.4.7", "canvas-confetti": "^1.5.1", "postcss": "^8.4.14", diff --git a/examples/with-vite-plugin-pwa/package.json b/examples/with-vite-plugin-pwa/package.json index c8a71f81164d4..1b25a1ed0f2e2 100644 --- a/examples/with-vite-plugin-pwa/package.json +++ b/examples/with-vite-plugin-pwa/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.54", + "astro": "^1.0.0-beta.55", "vite-plugin-pwa": "0.11.11", "workbox-window": "^6.5.3" } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index 61b47f7853c40..a16f62bea0d85 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,48 @@ # astro +## 1.0.0-beta.55 + +### Patch Changes + +- [#3696](https://github.com/withastro/astro/pull/3696) [`3daaf510`](https://github.com/withastro/astro/commit/3daaf510ea767fba47ef52d2253b6221967f3b53) Thanks [@matthewp](https://github.com/matthewp)! - Support for streaming responses + + Astro supports streaming in its templates. Any time Astro encounters an async boundary it will stream out HTML that occurs before it. For example: + + ```astro + --- + import LoadTodos from '../components/LoadTodos.astro'; + --- + + + App + + + + + + ``` + + In this arbtrary example Astro will streaming out the `` section and everything else until it encounters `` and then stop. LoadTodos, which is also an Astro component will stream its contents as well; stopping and waiting at any other asynchronous components. + + As part of this Astro also now supports async iterables within its templates. This means you can do this: + + ```astro +
      + {(async function * () { + for(const number of numbers) { + await wait(1000); + + yield
    • Number: {number}
    • + yield '\n' + } + })()} +
    + ``` + + Which will stream out `
  • `s one at a time, waiting a second between each. + +* [#3700](https://github.com/withastro/astro/pull/3700) [`47c81eff`](https://github.com/withastro/astro/commit/47c81effa69fb5d7f1e576f88c27d5071f1888e3) Thanks [@matthewp](https://github.com/matthewp)! - Make Astro.redirect use a 302 status code + ## 1.0.0-beta.54 ### Patch Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index b1a02bcc6fa46..49ddc48b0a3b6 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "1.0.0-beta.54", + "version": "1.0.0-beta.55", "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.", "type": "module", "author": "withastro", diff --git a/packages/integrations/cloudflare/CHANGELOG.md b/packages/integrations/cloudflare/CHANGELOG.md index 359165e237bbe..88913d64b3de7 100644 --- a/packages/integrations/cloudflare/CHANGELOG.md +++ b/packages/integrations/cloudflare/CHANGELOG.md @@ -1,5 +1,11 @@ # @astrojs/cloudflare +## 0.2.1 + +### Patch Changes + +- [#3695](https://github.com/withastro/astro/pull/3695) [`0d667d0e`](https://github.com/withastro/astro/commit/0d667d0e572d76d4c819816ddf51ed14b43e2551) Thanks [@nrgnrg](https://github.com/nrgnrg)! - fix custom 404 pages not rendering + ## 0.2.0 ### Minor Changes diff --git a/packages/integrations/cloudflare/package.json b/packages/integrations/cloudflare/package.json index d3f663b2a0414..fabb771804c5c 100644 --- a/packages/integrations/cloudflare/package.json +++ b/packages/integrations/cloudflare/package.json @@ -1,7 +1,7 @@ { "name": "@astrojs/cloudflare", "description": "Deploy your site to cloudflare pages functions", - "version": "0.2.0", + "version": "0.2.1", "type": "module", "types": "./dist/index.d.ts", "author": "withastro", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 666af67896d12..9ec530eb66b08 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,14 +49,14 @@ importers: examples/basics: specifiers: - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 devDependencies: astro: link:../../packages/astro examples/blog: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -67,7 +67,7 @@ importers: examples/blog-multiple-authors: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -79,14 +79,14 @@ importers: examples/component: specifiers: - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 devDependencies: astro: link:../../packages/astro examples/component/demo: specifiers: '@example/my-component': workspace:* - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 devDependencies: '@example/my-component': link:../packages/my-component astro: link:../../../packages/astro @@ -102,7 +102,7 @@ importers: '@docsearch/css': ^3.1.0 '@docsearch/react': ^3.1.0 '@types/react': ^17.0.45 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -121,14 +121,14 @@ importers: examples/env-vars: specifiers: - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 devDependencies: astro: link:../../packages/astro examples/framework-alpine: specifiers: alpinejs: ^3.10.2 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 dependencies: alpinejs: 3.10.2 devDependencies: @@ -138,7 +138,7 @@ importers: specifiers: '@astrojs/lit': ^0.3.0 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 lit: ^2.2.5 dependencies: '@webcomponents/template-shadowroot': 0.1.0 @@ -156,7 +156,7 @@ importers: '@astrojs/svelte': ^0.2.0 '@astrojs/vue': ^0.2.0 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -185,7 +185,7 @@ importers: examples/framework-preact: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -198,7 +198,7 @@ importers: '@astrojs/react': ^0.2.0 '@types/react': ^18.0.10 '@types/react-dom': ^18.0.5 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 react: ^18.1.0 react-dom: ^18.1.0 dependencies: @@ -213,7 +213,7 @@ importers: examples/framework-solid: specifiers: '@astrojs/solid-js': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 solid-js: ^1.4.3 dependencies: solid-js: 1.4.3 @@ -224,7 +224,7 @@ importers: examples/framework-svelte: specifiers: '@astrojs/svelte': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 svelte: ^3.48.0 dependencies: svelte: 3.48.0 @@ -235,7 +235,7 @@ importers: examples/framework-vue: specifiers: '@astrojs/vue': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 vue: ^3.2.36 dependencies: vue: 3.2.37 @@ -253,7 +253,7 @@ importers: '@astrojs/tailwind': ^0.2.1 '@astrojs/turbolinks': ^0.1.3 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -282,20 +282,20 @@ importers: examples/minimal: specifiers: - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 devDependencies: astro: link:../../packages/astro examples/non-html-pages: specifiers: - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 devDependencies: astro: link:../../packages/astro examples/portfolio: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -309,7 +309,7 @@ importers: specifiers: '@astrojs/node': ^0.1.2 '@astrojs/svelte': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 concurrently: ^7.2.1 lightcookie: ^1.0.25 svelte: ^3.48.0 @@ -328,14 +328,14 @@ importers: examples/starter: specifiers: - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 devDependencies: astro: link:../../packages/astro examples/subpath: specifiers: '@astrojs/react': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 react: ^18.1.0 react-dom: ^18.1.0 sass: ^1.52.2 @@ -354,7 +354,7 @@ importers: '@astrojs/react': ^0.2.0 '@astrojs/svelte': ^0.2.0 '@astrojs/vue': ^0.2.0 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -377,7 +377,7 @@ importers: examples/with-markdown-plugins: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 hast-util-select: 5.0.1 rehype-autolink-headings: ^6.1.1 rehype-slug: ^5.0.1 @@ -395,7 +395,7 @@ importers: examples/with-markdown-shiki: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 devDependencies: '@astrojs/markdown-remark': link:../../packages/markdown/remark astro: link:../../packages/astro @@ -410,7 +410,7 @@ importers: '@nanostores/preact': ^0.1.3 '@nanostores/react': ^0.1.5 '@nanostores/vue': ^0.4.1 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 nanostores: ^0.5.12 preact: ^10.7.3 react: ^18.1.0 @@ -438,7 +438,7 @@ importers: examples/with-tailwindcss: specifiers: '@astrojs/tailwind': ^0.2.1 - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 autoprefixer: ^10.4.7 canvas-confetti: ^1.5.1 postcss: ^8.4.14 @@ -453,7 +453,7 @@ importers: examples/with-vite-plugin-pwa: specifiers: - astro: ^1.0.0-beta.54 + astro: ^1.0.0-beta.55 vite-plugin-pwa: 0.11.11 workbox-window: ^6.5.3 devDependencies: From 908c2638cbe0ba9a21571275d8d8cf975f528c8c Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 24 Jun 2022 15:11:17 -0500 Subject: [PATCH 26/58] Add *private* built-in JSX renderer (#3697) * feat: add private `addPageExtensions` hook * feat: experimental JSX support * chore: remove experimental.jsx option from config * chore: remove automatic astro JSX runtime detection * fix: throw warning when client:* directive is used but no client entrypoint is found * feat: add slot support to renderer * chore: remove client entrypoint from jsx renderer * test: add barebones JSX test * test: add frameworks-in-jsx test * feat: improve error message when no matching import is found * feat: support slots * fix: do not strip `astro-slot` when using JSX renderer * fix: handle null values in isVNode * fix: do not transform slots for elements Co-authored-by: Nate Moore --- packages/astro/package.json | 3 + packages/astro/src/core/config.ts | 11 +- packages/astro/src/jsx-runtime/index.ts | 76 ++++++++++ packages/astro/src/jsx/babel.ts | 131 ++++++++++++++++++ packages/astro/src/jsx/renderer.ts | 15 ++ packages/astro/src/jsx/server.ts | 37 +++++ packages/astro/src/runtime/server/index.ts | 18 ++- packages/astro/src/runtime/server/jsx.ts | 63 +++++++++ packages/astro/src/vite-plugin-jsx/index.ts | 5 +- .../astro/test/fixtures/jsx/astro.config.mjs | 25 ++++ packages/astro/test/fixtures/jsx/package.json | 21 +++ .../jsx/src/components/Frameworks.jsx | 28 ++++ .../jsx/src/components/PreactCounter.tsx | 20 +++ .../jsx/src/components/ReactCounter.jsx | 19 +++ .../jsx/src/components/SolidCounter.jsx | 19 +++ .../jsx/src/components/SvelteCounter.svelte | 21 +++ .../test/fixtures/jsx/src/components/Test.jsx | 5 + .../jsx/src/components/VueCounter.vue | 27 ++++ .../fixtures/jsx/src/pages/component.astro | 6 + .../fixtures/jsx/src/pages/frameworks.astro | 13 ++ packages/astro/test/jsx.test.js | 62 +++++++++ pnpm-lock.yaml | 70 ++++++++++ 22 files changed, 685 insertions(+), 10 deletions(-) create mode 100644 packages/astro/src/jsx-runtime/index.ts create mode 100644 packages/astro/src/jsx/babel.ts create mode 100644 packages/astro/src/jsx/renderer.ts create mode 100644 packages/astro/src/jsx/server.ts create mode 100644 packages/astro/src/runtime/server/jsx.ts create mode 100644 packages/astro/test/fixtures/jsx/astro.config.mjs create mode 100644 packages/astro/test/fixtures/jsx/package.json create mode 100644 packages/astro/test/fixtures/jsx/src/components/Frameworks.jsx create mode 100644 packages/astro/test/fixtures/jsx/src/components/PreactCounter.tsx create mode 100644 packages/astro/test/fixtures/jsx/src/components/ReactCounter.jsx create mode 100644 packages/astro/test/fixtures/jsx/src/components/SolidCounter.jsx create mode 100644 packages/astro/test/fixtures/jsx/src/components/SvelteCounter.svelte create mode 100644 packages/astro/test/fixtures/jsx/src/components/Test.jsx create mode 100644 packages/astro/test/fixtures/jsx/src/components/VueCounter.vue create mode 100644 packages/astro/test/fixtures/jsx/src/pages/component.astro create mode 100644 packages/astro/test/fixtures/jsx/src/pages/frameworks.astro create mode 100644 packages/astro/test/jsx.test.js diff --git a/packages/astro/package.json b/packages/astro/package.json index 49ddc48b0a3b6..256b299c642f4 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -27,6 +27,8 @@ ".": "./astro.js", "./env": "./env.d.ts", "./astro-jsx": "./astro-jsx.d.ts", + "./jsx/*": "./dist/jsx/*", + "./jsx-runtime": "./dist/jsx-runtime/index.js", "./config": "./config.mjs", "./internal": "./internal.js", "./app": "./dist/core/app/index.js", @@ -87,6 +89,7 @@ "@babel/core": "^7.18.2", "@babel/generator": "^7.18.2", "@babel/parser": "^7.18.4", + "@babel/plugin-transform-react-jsx": "^7.17.12", "@babel/traverse": "^7.18.2", "@proload/core": "^0.3.2", "@proload/plugin-tsm": "^0.2.1", diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 44ec20912d60c..f4e097ff6a7db 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -51,7 +51,7 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = { vite: {}, experimental: { ssr: false, - integrations: false, + integrations: false }, }; @@ -346,6 +346,15 @@ export async function validateConfig( adapter: undefined, }, }; + if ( + // TODO: expose @astrojs/mdx package + result.integrations.find(integration => integration.name === '@astrojs/mdx') + ) { + // Enable default JSX integration + const { default: jsxRenderer } = await import('../jsx/renderer.js'); + (result._ctx.renderers as any[]).push(jsxRenderer); + } + // Final-Pass Validation (perform checks that require the full config object) if ( !result.experimental?.integrations && diff --git a/packages/astro/src/jsx-runtime/index.ts b/packages/astro/src/jsx-runtime/index.ts new file mode 100644 index 0000000000000..ee8660742b35a --- /dev/null +++ b/packages/astro/src/jsx-runtime/index.ts @@ -0,0 +1,76 @@ +import { Fragment, markHTMLString } from '../runtime/server/index.js'; + +const AstroJSX = Symbol('@astrojs/jsx'); +const Empty = Symbol('empty'); + +interface AstroVNode { + [AstroJSX]: boolean; + type: string|((...args: any) => any)|typeof Fragment; + props: Record; +} + +const toSlotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase()); + +export function isVNode(vnode: any): vnode is AstroVNode { + return vnode && typeof vnode === 'object' && vnode[AstroJSX]; +} + +export function transformSlots(vnode: AstroVNode) { + if (typeof vnode.type === 'string') return vnode; + if (!Array.isArray(vnode.props.children)) return; + const slots: Record = {}; + vnode.props.children = vnode.props.children.map(child => { + if (!isVNode(child)) return child; + if (!('slot' in child.props)) return child; + const name = toSlotName(child.props.slot) + if (Array.isArray(slots[name])) { + slots[name].push(child); + } else { + slots[name] = [child]; + } + delete child.props.slot; + return Empty; + }).filter(v => v !== Empty); + Object.assign(vnode.props, slots); +} + +function markRawChildren(child: any): any { + if (typeof child === 'string') return markHTMLString(child); + if (Array.isArray(child)) return child.map(c => markRawChildren(c)); + return child; +} + +function transformSetDirectives(vnode: AstroVNode) { + if (!('set:html' in vnode.props || 'set:text' in vnode.props)) return; + if ('set:html' in vnode.props) { + const children = markRawChildren(vnode.props['set:html']); + delete vnode.props['set:html']; + Object.assign(vnode.props, { children }); + return; + } + if ('set:text' in vnode.props) { + const children = vnode.props['set:text']; + delete vnode.props['set:text']; + Object.assign(vnode.props, { children }); + return; + } +} + +function createVNode(type: any, props: Record) { + const vnode: AstroVNode = { + [AstroJSX]: true, + type, + props: props ?? {}, + }; + transformSetDirectives(vnode); + transformSlots(vnode); + return vnode; +} + +export { + AstroJSX, + createVNode as jsx, + createVNode as jsxs, + createVNode as jsxDEV, + Fragment +} diff --git a/packages/astro/src/jsx/babel.ts b/packages/astro/src/jsx/babel.ts new file mode 100644 index 0000000000000..33bd8652beeee --- /dev/null +++ b/packages/astro/src/jsx/babel.ts @@ -0,0 +1,131 @@ +import * as t from "@babel/types"; +import type { PluginObj } from '@babel/core'; + +function isComponent(tagName: string) { + return ( + (tagName[0] && tagName[0].toLowerCase() !== tagName[0]) || + tagName.includes(".") || + /[^a-zA-Z]/.test(tagName[0]) + ); +} + +function hasClientDirective(node: t.JSXElement) { + for (const attr of node.openingElement.attributes) { + if (attr.type === 'JSXAttribute' && attr.name.type === 'JSXNamespacedName') { + return attr.name.namespace.name === 'client' + } + } + return false; +} + +function getTagName(tag: t.JSXElement) { + const jsxName = tag.openingElement.name; + return jsxElementNameToString(jsxName); +} + +function jsxElementNameToString(node: t.JSXOpeningElement['name']): string { + if (t.isJSXMemberExpression(node)) { + return `${jsxElementNameToString(node.object)}.${node.property.name}`; + } + if (t.isJSXIdentifier(node) || t.isIdentifier(node)) { + return node.name; + } + return `${node.namespace.name}:${node.name.name}`; +} + +function jsxAttributeToString(attr: t.JSXAttribute): string { + if (t.isJSXNamespacedName(attr.name)) { + return `${attr.name.namespace.name}:${attr.name.name.name}` + } + return `${attr.name.name}`; +} + +function addClientMetadata(node: t.JSXElement, meta: { path: string, name: string }) { + const existingAttributes = node.openingElement.attributes.map(attr => t.isJSXAttribute(attr) ? jsxAttributeToString(attr) : null); + if (!existingAttributes.find(attr => attr === 'client:component-path')) { + const componentPath = t.jsxAttribute( + t.jsxNamespacedName(t.jsxIdentifier('client'), t.jsxIdentifier('component-path')), + !meta.path.startsWith('.') ? t.stringLiteral(meta.path) : t.jsxExpressionContainer(t.binaryExpression("+", t.stringLiteral('/@fs'), t.memberExpression(t.newExpression(t.identifier('URL'), [t.stringLiteral(meta.path), t.identifier('import.meta.url')]), t.identifier('pathname')))), + ); + node.openingElement.attributes.push(componentPath); + } + if (!existingAttributes.find(attr => attr === 'client:component-export')) { + if (meta.name === '*') { + meta.name = getTagName(node).split('.').at(1)!; + } + const componentExport = t.jsxAttribute( + t.jsxNamespacedName(t.jsxIdentifier('client'), t.jsxIdentifier('component-export')), + t.stringLiteral(meta.name), + ); + node.openingElement.attributes.push(componentExport); + } + if (!existingAttributes.find(attr => attr === 'client:component-hydration')) { + const staticMarker = t.jsxAttribute( + t.jsxNamespacedName(t.jsxIdentifier('client'), t.jsxIdentifier('component-hydration')), + ) + node.openingElement.attributes.push(staticMarker); + } +} + +export default function astroJSX(): PluginObj { + return { + visitor: { + Program(path) { + path.node.body.splice(0, 0, (t.importDeclaration([t.importSpecifier(t.identifier('Fragment'), t.identifier('Fragment'))], t.stringLiteral('astro/jsx-runtime')))); + }, + ImportDeclaration(path, state) { + const source = path.node.source.value; + if (source.startsWith('astro/jsx-runtime')) return; + const specs = path.node.specifiers.map(spec => { + if (t.isImportDefaultSpecifier(spec)) return { local: spec.local.name, imported: 'default' } + if (t.isImportNamespaceSpecifier(spec)) return { local: spec.local.name, imported: '*' } + if (t.isIdentifier(spec.imported)) return { local: spec.local.name, imported: spec.imported.name }; + return { local: spec.local.name, imported: spec.imported.value }; + }); + const imports = state.get('imports') ?? new Map(); + for (const spec of specs) { + if (imports.has(source)) { + const existing = imports.get(source); + existing.add(spec); + imports.set(source, existing) + } else { + imports.set(source, new Set([spec])) + } + } + state.set('imports', imports); + }, + JSXIdentifier(path, state) { + const isAttr = path.findParent(n => t.isJSXAttribute(n)); + if (isAttr) return; + const parent = path.findParent(n => t.isJSXElement(n))!; + const parentNode = parent.node as t.JSXElement; + const tagName = getTagName(parentNode); + if (!isComponent(tagName)) return; + if (!hasClientDirective(parentNode)) return; + + const imports = state.get('imports') ?? new Map(); + const namespace = getTagName(parentNode).split('.'); + for (const [source, specs] of imports) { + for (const { imported, local } of specs) { + const reference = path.referencesImport(source, imported); + if (reference) { + path.setData('import', { name: imported, path: source }); + break; + } + if (namespace.at(0) === local) { + path.setData('import', { name: imported, path: source }); + break; + } + } + } + // TODO: map unmatched identifiers back to imports if possible + const meta = path.getData('import'); + if (meta) { + addClientMetadata(parentNode, meta) + } else { + throw new Error(`Unable to match <${getTagName(parentNode)}> with client:* directive to an import statement!`); + } + }, + } + }; +}; diff --git a/packages/astro/src/jsx/renderer.ts b/packages/astro/src/jsx/renderer.ts new file mode 100644 index 0000000000000..94a63b5fe4c79 --- /dev/null +++ b/packages/astro/src/jsx/renderer.ts @@ -0,0 +1,15 @@ +const renderer = { + name: 'astro:jsx', + serverEntrypoint: 'astro/jsx/server.js', + jsxImportSource: 'astro', + jsxTransformOptions: async () => { + // @ts-ignore + const { default: { default: jsx } } = await import('@babel/plugin-transform-react-jsx'); + const { default: astroJSX } = await import('./babel.js'); + return { + plugins: [astroJSX(), jsx({}, { throwIfNamespace: false, runtime: 'automatic', importSource: 'astro' })], + }; + }, +} + +export default renderer; diff --git a/packages/astro/src/jsx/server.ts b/packages/astro/src/jsx/server.ts new file mode 100644 index 0000000000000..c75135b90c544 --- /dev/null +++ b/packages/astro/src/jsx/server.ts @@ -0,0 +1,37 @@ +import { renderJSX } from '../runtime/server/jsx.js'; +import { AstroJSX, jsx } from '../jsx-runtime/index.js'; + +const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase()); + +export async function check(Component: any, props: any, { default: children = null, ...slotted } = {}) { + if (typeof Component !== 'function') return false; + const slots: Record = {}; + for (const [key, value] of Object.entries(slotted)) { + const name = slotName(key); + slots[name] = value; + } + try { + const result = await Component({ ...props, ...slots, children }); + return result[AstroJSX]; + } catch (e) {}; + return false; +} + +export async function renderToStaticMarkup(this: any, Component: any, props = {}, { default: children = null, ...slotted } = {}) { + const slots: Record = {}; + for (const [key, value] of Object.entries(slotted)) { + const name = slotName(key); + slots[name] = value; + } + + const { result } = this; + try { + const html = await renderJSX(result, jsx(Component, { ...props, ...slots, children })); + return { html }; + } catch (e) {} +} + +export default { + check, + renderToStaticMarkup, +}; diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index c55328c161895..33d41ef5d08a4 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -22,11 +22,11 @@ import { serializeProps } from './serialize.js'; import { shorthash } from './shorthash.js'; import { serializeListValue } from './util.js'; -export { markHTMLString, markHTMLString as unescapeHTML } from './escape.js'; +export { markHTMLString, markHTMLString as unescapeHTML, HTMLString, escapeHTML } from './escape.js'; export type { Metadata } from './metadata'; export { createMetadata } from './metadata.js'; -const voidElementNames = +export const voidElementNames = /^(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/i; const htmlBooleanAttributes = /^(allowfullscreen|async|autofocus|autoplay|controls|default|defer|disabled|disablepictureinpicture|disableremoteplayback|formnovalidate|hidden|loop|nomodule|novalidate|open|playsinline|readonly|required|reversed|scoped|seamless|itemscope)$/i; @@ -233,7 +233,7 @@ Did you mean to add ${formatList(probableRendererNames.map((r) => '`' + r + '`') let error; for (const r of renderers) { try { - if (await r.ssr.check(Component, props, children)) { + if (await r.ssr.check.call({ result }, Component, props, children)) { renderer = r; break; } @@ -299,7 +299,7 @@ Did you mean to enable ${formatList(probableRendererNames.map((r) => '`' + r + ' // We already know that renderer.ssr.check() has failed // but this will throw a much more descriptive error! renderer = matchingRenderers[0]; - ({ html } = await renderer.ssr.renderToStaticMarkup(Component, props, children, metadata)); + ({ html } = await renderer.ssr.renderToStaticMarkup.call({ result }, Component, props, children, metadata)); } else { throw new Error(`Unable to render ${metadata.displayName}! @@ -318,10 +318,14 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr if (metadata.hydrate === 'only') { html = await renderSlot(result, slots?.fallback); } else { - ({ html } = await renderer.ssr.renderToStaticMarkup(Component, props, children, metadata)); + ({ html } = await renderer.ssr.renderToStaticMarkup.call({ result }, Component, props, children, metadata)); } } + if (renderer && !renderer.clientEntrypoint && metadata.hydrate) { + throw new Error(`${metadata.displayName} component has a \`client:${metadata.hydrate}\` directive, but no client entrypoint was provided by ${renderer.name}!`); + } + // This is a custom element without a renderer. Because of that, render it // as a string and the user is responsible for adding a script tag for the component definition. if (!html && typeof Component === 'string') { @@ -340,7 +344,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr } if (!hydration) { - if (isPage) { + if (isPage || renderer?.name === 'astro:jsx') { return html; } return markHTMLString(html.replace(/\<\/?astro-slot\>/g, '')); @@ -496,7 +500,7 @@ function internalSpreadAttributes(values: Record, shouldEscape = true) // Adds support for ` export function spreadAttributes( values: Record, - name: string, + name?: string, { class: scopedClassName }: { class?: string } = {} ) { let output = ''; diff --git a/packages/astro/src/runtime/server/jsx.ts b/packages/astro/src/runtime/server/jsx.ts new file mode 100644 index 0000000000000..dc4df923a8782 --- /dev/null +++ b/packages/astro/src/runtime/server/jsx.ts @@ -0,0 +1,63 @@ +import { HTMLString, markHTMLString, escapeHTML, Fragment, renderComponent, spreadAttributes, voidElementNames } from './index.js'; +import { AstroJSX, isVNode } from '../../jsx-runtime/index.js'; + +export async function renderJSX(result: any, vnode: any): Promise { + switch (true) { + case (vnode instanceof HTMLString): return vnode; + case (typeof vnode === 'string'): return markHTMLString(escapeHTML(vnode)); + case (!vnode && vnode !== 0): return ''; + case (vnode.type === Fragment): return renderJSX(result, vnode.props.children); + case (Array.isArray(vnode)): return markHTMLString((await Promise.all(vnode.map((v: any) => renderJSX(result, v)))).join('')); + } + if (vnode[AstroJSX]) { + if (!vnode.type && vnode.type !== 0) return ''; + if (typeof vnode.type === 'string') { + return await renderElement(result, vnode.type, vnode.props ?? {}); + } + if (!!vnode.type) { + try { + // TODO: silence Invalid hook call warning from React + const output = await vnode.type(vnode.props ?? {}); + if (output && output[AstroJSX]) { + return await renderJSX(result, output); + } else if (!output) { + return await renderJSX(result, output); + } + } catch (e) {} + + const { children = null, ...props } = vnode.props ?? {}; + const slots: Record = { + default: [] + } + function extractSlots(child: any): any { + if (Array.isArray(child)) { + return child.map(c => extractSlots(c)); + } + if (!isVNode(child)) { + return slots.default.push(child); + } + if ('slot' in child.props) { + slots[child.props.slot] = [...(slots[child.props.slot] ?? []), child] + delete child.props.slot; + return; + } + slots.default.push(child); + } + extractSlots(children); + for (const [key, value] of Object.entries(slots)) { + slots[key] = () => renderJSX(result, value); + } + return markHTMLString(await renderComponent(result, vnode.type.name, vnode.type, props, slots)); + } + } + // numbers, plain objects, etc + return markHTMLString(`${vnode}`); +} + +async function renderElement(result: any, tag: string, { children, ...props }: Record) { + return markHTMLString(`<${tag}${spreadAttributes(props)}${markHTMLString( + (children == null || children == '') && voidElementNames.test(tag) + ? `/>` + : `>${children == null ? '' : await renderJSX(result, children)}` + )}`); +} diff --git a/packages/astro/src/vite-plugin-jsx/index.ts b/packages/astro/src/vite-plugin-jsx/index.ts index 22df96cb480e6..421c3622c12a8 100644 --- a/packages/astro/src/vite-plugin-jsx/index.ts +++ b/packages/astro/src/vite-plugin-jsx/index.ts @@ -17,6 +17,7 @@ const IMPORT_STATEMENTS: Record = { react: "import React from 'react'", preact: "import { h } from 'preact'", 'solid-js': "import 'solid-js/web'", + astro: "import 'astro/jsx-runtime'", }; // A code snippet to inject into JS files to prevent esbuild reference bugs. @@ -167,9 +168,9 @@ export default function jsx({ config, logging }: AstroPluginJSXOptions): Plugin if (!importSource) { const multiline = code.match(/\/\*\*[\S\s]*\*\//gm) || []; for (const comment of multiline) { - const [_, lib] = comment.match(/@jsxImportSource\s*(\S+)/) || []; + const [_, lib] = comment.slice(0, -2).match(/@jsxImportSource\s*(\S+)/) || []; if (lib) { - importSource = lib; + importSource = lib.trim(); break; } } diff --git a/packages/astro/test/fixtures/jsx/astro.config.mjs b/packages/astro/test/fixtures/jsx/astro.config.mjs new file mode 100644 index 0000000000000..5b84d23a8f204 --- /dev/null +++ b/packages/astro/test/fixtures/jsx/astro.config.mjs @@ -0,0 +1,25 @@ +import { defineConfig } from 'astro/config'; +import renderer from 'astro/jsx/renderer.js'; +import preact from '@astrojs/preact'; +import react from '@astrojs/react'; +import svelte from '@astrojs/svelte'; +import vue from '@astrojs/vue'; +import solid from '@astrojs/solid-js'; + +export default defineConfig({ + integrations: [ + { + name: '@astrojs/test-jsx', + hooks: { + 'astro:config:setup': ({ addRenderer }) => { + addRenderer(renderer); + } + } + }, + preact(), + react(), + svelte(), + vue(), + solid(), + ] +}) diff --git a/packages/astro/test/fixtures/jsx/package.json b/packages/astro/test/fixtures/jsx/package.json new file mode 100644 index 0000000000000..eb2c75d6931ac --- /dev/null +++ b/packages/astro/test/fixtures/jsx/package.json @@ -0,0 +1,21 @@ +{ + "name": "@test/jsx", + "version": "0.0.0", + "private": true, + "devDependencies": { + "@astrojs/preact": "workspace:*", + "@astrojs/react": "workspace:*", + "@astrojs/solid-js": "workspace:*", + "@astrojs/svelte": "workspace:*", + "@astrojs/vue": "workspace:*", + "astro": "workspace:*" + }, + "dependencies": { + "preact": "^10.7.3", + "react": "^18.1.0", + "react-dom": "^18.1.0", + "solid-js": "^1.4.3", + "svelte": "^3.48.0", + "vue": "^3.2.36" + } +} diff --git a/packages/astro/test/fixtures/jsx/src/components/Frameworks.jsx b/packages/astro/test/fixtures/jsx/src/components/Frameworks.jsx new file mode 100644 index 0000000000000..2cc17596457cf --- /dev/null +++ b/packages/astro/test/fixtures/jsx/src/components/Frameworks.jsx @@ -0,0 +1,28 @@ +import 'astro/jsx-runtime'; +import { Test } from "./Test"; + +import PreactCounter from "./PreactCounter"; +import ReactCounter from "./ReactCounter"; +import SolidCounter from "./SolidCounter"; +import SvelteCounter from "./SvelteCounter.svelte"; +import VueCounter from "./VueCounter.vue"; + +export function Preact() { + return +} + +export function React() { + return +} + +export function Solid() { + return +} + +export function Svelte() { + return +} + +export function Vue() { + return +} diff --git a/packages/astro/test/fixtures/jsx/src/components/PreactCounter.tsx b/packages/astro/test/fixtures/jsx/src/components/PreactCounter.tsx new file mode 100644 index 0000000000000..cdb368377d194 --- /dev/null +++ b/packages/astro/test/fixtures/jsx/src/components/PreactCounter.tsx @@ -0,0 +1,20 @@ +import { h, Fragment } from 'preact'; +import { useState } from 'preact/hooks'; + +/** a counter written in Preact */ +export default function PreactCounter() { + const [count, setCount] = useState(0); + const add = () => setCount((i) => i + 1); + const subtract = () => setCount((i) => i - 1); + + return ( +
    +
    + +
    {count}
    + +
    +
    Preact
    +
    + ); +} diff --git a/packages/astro/test/fixtures/jsx/src/components/ReactCounter.jsx b/packages/astro/test/fixtures/jsx/src/components/ReactCounter.jsx new file mode 100644 index 0000000000000..5c5a001e8863e --- /dev/null +++ b/packages/astro/test/fixtures/jsx/src/components/ReactCounter.jsx @@ -0,0 +1,19 @@ +import React, { useState } from 'react'; + +/** a counter written in React */ +export default function ReactCounter() { + const [count, setCount] = useState(0); + const add = () => setCount((i) => i + 1); + const subtract = () => setCount((i) => i - 1); + + return ( +
    +
    + +
    {count}
    + +
    +
    React
    +
    + ); +} diff --git a/packages/astro/test/fixtures/jsx/src/components/SolidCounter.jsx b/packages/astro/test/fixtures/jsx/src/components/SolidCounter.jsx new file mode 100644 index 0000000000000..9cfd85d02f3c0 --- /dev/null +++ b/packages/astro/test/fixtures/jsx/src/components/SolidCounter.jsx @@ -0,0 +1,19 @@ +import { createSignal } from 'solid-js'; + +/** a counter written with Solid */ +export default function SolidCounter() { + const [count, setCount] = createSignal(0); + const add = () => setCount(count() + 1); + const subtract = () => setCount(count() - 1); + + return ( +
    +
    + +
    {count()}
    + +
    +
    Solid
    +
    + ); +} diff --git a/packages/astro/test/fixtures/jsx/src/components/SvelteCounter.svelte b/packages/astro/test/fixtures/jsx/src/components/SvelteCounter.svelte new file mode 100644 index 0000000000000..3d6f1b2bd2bec --- /dev/null +++ b/packages/astro/test/fixtures/jsx/src/components/SvelteCounter.svelte @@ -0,0 +1,21 @@ + + + +
    +
    + +
    {count}
    + +
    +
    Svelte
    +
    diff --git a/packages/astro/test/fixtures/jsx/src/components/Test.jsx b/packages/astro/test/fixtures/jsx/src/components/Test.jsx new file mode 100644 index 0000000000000..007c8f6172cd2 --- /dev/null +++ b/packages/astro/test/fixtures/jsx/src/components/Test.jsx @@ -0,0 +1,5 @@ +import 'astro'; + +export function Test({ case: id, ...slots }) { + return
    {Object.values(slots)}
    +} diff --git a/packages/astro/test/fixtures/jsx/src/components/VueCounter.vue b/packages/astro/test/fixtures/jsx/src/components/VueCounter.vue new file mode 100644 index 0000000000000..f7492911ec474 --- /dev/null +++ b/packages/astro/test/fixtures/jsx/src/components/VueCounter.vue @@ -0,0 +1,27 @@ + + + diff --git a/packages/astro/test/fixtures/jsx/src/pages/component.astro b/packages/astro/test/fixtures/jsx/src/pages/component.astro new file mode 100644 index 0000000000000..7ee06da8463fc --- /dev/null +++ b/packages/astro/test/fixtures/jsx/src/pages/component.astro @@ -0,0 +1,6 @@ +--- +import { Test } from '../components/Test' +--- + +Basic +Named diff --git a/packages/astro/test/fixtures/jsx/src/pages/frameworks.astro b/packages/astro/test/fixtures/jsx/src/pages/frameworks.astro new file mode 100644 index 0000000000000..ede0f542c3cd4 --- /dev/null +++ b/packages/astro/test/fixtures/jsx/src/pages/frameworks.astro @@ -0,0 +1,13 @@ +--- +import * as Framework from '../components/Frameworks' +--- + + + + + + + + + + diff --git a/packages/astro/test/jsx.test.js b/packages/astro/test/jsx.test.js new file mode 100644 index 0000000000000..bf05d35c0af47 --- /dev/null +++ b/packages/astro/test/jsx.test.js @@ -0,0 +1,62 @@ +import { expect } from 'chai'; +import * as cheerio from 'cheerio'; +import { loadFixture } from './test-utils.js'; + +describe('jsx-runtime', () => { + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/jsx/' + }); + await fixture.build(); + }); + + it('Can load simple JSX components', async () => { + const html = await fixture.readFile('/component/index.html'); + const $ = cheerio.load(html); + + expect($('#basic').text()).to.equal('Basic'); + expect($('#named').text()).to.equal('Named'); + }); + + it('Can load Preact component inside Astro JSX', async () => { + const html = await fixture.readFile('/frameworks/index.html'); + const $ = cheerio.load(html); + + expect($('#has-preact #preact').length).to.equal(1); + expect($('#preact').text()).to.include('Preact'); + }); + + it('Can load React component inside Astro JSX', async () => { + const html = await fixture.readFile('/frameworks/index.html'); + const $ = cheerio.load(html); + + expect($('#has-react #react').length).to.equal(1); + expect($('#react').text()).to.include('React'); + }); + + it('Can load Solid component inside Astro JSX', async () => { + const html = await fixture.readFile('/frameworks/index.html'); + const $ = cheerio.load(html); + + expect($('#has-solid #solid').length).to.equal(1); + expect($('#solid').text()).to.include('Solid'); + }); + + it('Can load Svelte component inside Astro JSX', async () => { + const html = await fixture.readFile('/frameworks/index.html'); + const $ = cheerio.load(html); + + expect($('#has-svelte #svelte').length).to.equal(1); + expect($('#svelte').text()).to.include('Svelte'); + }); + + it('Can load Vue component inside Astro JSX', async () => { + const html = await fixture.readFile('/frameworks/index.html'); + const $ = cheerio.load(html); + + expect($('#has-vue #vue').length).to.equal(1); + expect($('#vue').text()).to.include('Vue'); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ec530eb66b08..8c22fd6952815 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -472,6 +472,7 @@ importers: '@babel/core': ^7.18.2 '@babel/generator': ^7.18.2 '@babel/parser': ^7.18.4 + '@babel/plugin-transform-react-jsx': ^7.17.12 '@babel/traverse': ^7.18.2 '@babel/types': ^7.18.4 '@playwright/test': ^1.22.2 @@ -555,6 +556,7 @@ importers: '@babel/core': 7.18.2 '@babel/generator': 7.18.2 '@babel/parser': 7.18.4 + '@babel/plugin-transform-react-jsx': 7.17.12_@babel+core@7.18.2 '@babel/traverse': 7.18.2 '@proload/core': 0.3.2 '@proload/plugin-tsm': 0.2.1_@proload+core@0.3.2 @@ -1467,6 +1469,35 @@ importers: dependencies: astro: link:../../.. + packages/astro/test/fixtures/jsx: + specifiers: + '@astrojs/preact': workspace:* + '@astrojs/react': workspace:* + '@astrojs/solid-js': workspace:* + '@astrojs/svelte': workspace:* + '@astrojs/vue': workspace:* + astro: workspace:* + preact: ^10.7.3 + react: ^18.1.0 + react-dom: ^18.1.0 + solid-js: ^1.4.3 + svelte: ^3.48.0 + vue: ^3.2.36 + dependencies: + preact: 10.7.3 + react: 18.1.0 + react-dom: 18.1.0_react@18.1.0 + solid-js: 1.4.3 + svelte: 3.48.0 + vue: 3.2.37 + devDependencies: + '@astrojs/preact': link:../../../../integrations/preact + '@astrojs/react': link:../../../../integrations/react + '@astrojs/solid-js': link:../../../../integrations/solid + '@astrojs/svelte': link:../../../../integrations/svelte + '@astrojs/vue': link:../../../../integrations/vue + astro: link:../../.. + packages/astro/test/fixtures/legacy-build: specifiers: '@astrojs/vue': workspace:* @@ -3131,6 +3162,19 @@ packages: '@babel/helper-plugin-utils': 7.17.12 dev: false + /@babel/plugin-syntax-jsx/7.17.12_@babel+core@7.18.2: + resolution: {integrity: sha512-spyY3E3AURfxh/RHtjx5j6hs8am5NbUBGfcZ2vB3uShSpZdQyXSf5rR5Mk76vbtlAZOelyVQ71Fg0x9SG4fsog==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + peerDependenciesMeta: + '@babel/core': + optional: true + dependencies: + '@babel/core': 7.18.2 + '@babel/helper-plugin-utils': 7.17.12 + dev: false + /@babel/plugin-syntax-logical-assignment-operators/7.10.4_@babel+core@7.18.2: resolution: {integrity: sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig==} peerDependencies: @@ -3583,6 +3627,23 @@ packages: '@babel/types': 7.18.4 dev: false + /@babel/plugin-transform-react-jsx/7.17.12_@babel+core@7.18.2: + resolution: {integrity: sha512-Lcaw8bxd1DKht3thfD4A12dqo1X16he1Lm8rIv8sTwjAYNInRS1qHa9aJoqvzpscItXvftKDCfaEQzwoVyXpEQ==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + peerDependenciesMeta: + '@babel/core': + optional: true + dependencies: + '@babel/core': 7.18.2 + '@babel/helper-annotate-as-pure': 7.16.7 + '@babel/helper-module-imports': 7.16.7 + '@babel/helper-plugin-utils': 7.17.12 + '@babel/plugin-syntax-jsx': 7.17.12_@babel+core@7.18.2 + '@babel/types': 7.18.4 + dev: false + /@babel/plugin-transform-regenerator/7.18.0_@babel+core@7.18.2: resolution: {integrity: sha512-C8YdRw9uzx25HSIzwA7EM7YP0FhCe5wNvJbZzjVNHHPGVcDJ3Aie+qGYYdS1oVQgn+B3eAIJbWFLrJ4Jipv7nw==} engines: {node: '>=6.9.0'} @@ -8485,6 +8546,11 @@ packages: /debug/3.2.7: resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true dependencies: ms: 2.1.3 dev: false @@ -11366,6 +11432,8 @@ packages: debug: 3.2.7 iconv-lite: 0.4.24 sax: 1.2.4 + transitivePeerDependencies: + - supports-color dev: false /netmask/2.0.2: @@ -11449,6 +11517,8 @@ packages: rimraf: 2.7.1 semver: 5.7.1 tar: 4.4.19 + transitivePeerDependencies: + - supports-color dev: false /node-releases/2.0.5: From 5e716e8cd5c848b487055db1868c96e8f4ac85ac Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Fri, 24 Jun 2022 20:13:12 +0000 Subject: [PATCH 27/58] [ci] format --- packages/astro/src/core/config.ts | 4 +- packages/astro/src/jsx-runtime/index.ts | 40 ++++---- packages/astro/src/jsx/babel.ts | 113 +++++++++++++-------- packages/astro/src/jsx/renderer.ts | 11 +- packages/astro/src/jsx/server.ts | 17 +++- packages/astro/src/runtime/server/index.ts | 27 ++++- packages/astro/src/runtime/server/jsx.ts | 51 +++++++--- packages/astro/test/jsx.test.js | 2 +- 8 files changed, 173 insertions(+), 92 deletions(-) diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index f4e097ff6a7db..4ad099e1f7f8a 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -51,7 +51,7 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = { vite: {}, experimental: { ssr: false, - integrations: false + integrations: false, }, }; @@ -348,7 +348,7 @@ export async function validateConfig( }; if ( // TODO: expose @astrojs/mdx package - result.integrations.find(integration => integration.name === '@astrojs/mdx') + result.integrations.find((integration) => integration.name === '@astrojs/mdx') ) { // Enable default JSX integration const { default: jsxRenderer } = await import('../jsx/renderer.js'); diff --git a/packages/astro/src/jsx-runtime/index.ts b/packages/astro/src/jsx-runtime/index.ts index ee8660742b35a..37d79a673f438 100644 --- a/packages/astro/src/jsx-runtime/index.ts +++ b/packages/astro/src/jsx-runtime/index.ts @@ -5,7 +5,7 @@ const Empty = Symbol('empty'); interface AstroVNode { [AstroJSX]: boolean; - type: string|((...args: any) => any)|typeof Fragment; + type: string | ((...args: any) => any) | typeof Fragment; props: Record; } @@ -19,24 +19,26 @@ export function transformSlots(vnode: AstroVNode) { if (typeof vnode.type === 'string') return vnode; if (!Array.isArray(vnode.props.children)) return; const slots: Record = {}; - vnode.props.children = vnode.props.children.map(child => { - if (!isVNode(child)) return child; - if (!('slot' in child.props)) return child; - const name = toSlotName(child.props.slot) - if (Array.isArray(slots[name])) { - slots[name].push(child); - } else { - slots[name] = [child]; - } - delete child.props.slot; - return Empty; - }).filter(v => v !== Empty); + vnode.props.children = vnode.props.children + .map((child) => { + if (!isVNode(child)) return child; + if (!('slot' in child.props)) return child; + const name = toSlotName(child.props.slot); + if (Array.isArray(slots[name])) { + slots[name].push(child); + } else { + slots[name] = [child]; + } + delete child.props.slot; + return Empty; + }) + .filter((v) => v !== Empty); Object.assign(vnode.props, slots); } function markRawChildren(child: any): any { if (typeof child === 'string') return markHTMLString(child); - if (Array.isArray(child)) return child.map(c => markRawChildren(c)); + if (Array.isArray(child)) return child.map((c) => markRawChildren(c)); return child; } @@ -57,7 +59,7 @@ function transformSetDirectives(vnode: AstroVNode) { } function createVNode(type: any, props: Record) { - const vnode: AstroVNode = { + const vnode: AstroVNode = { [AstroJSX]: true, type, props: props ?? {}, @@ -67,10 +69,4 @@ function createVNode(type: any, props: Record) { return vnode; } -export { - AstroJSX, - createVNode as jsx, - createVNode as jsxs, - createVNode as jsxDEV, - Fragment -} +export { AstroJSX, createVNode as jsx, createVNode as jsxs, createVNode as jsxDEV, Fragment }; diff --git a/packages/astro/src/jsx/babel.ts b/packages/astro/src/jsx/babel.ts index 33bd8652beeee..0e529115dda4b 100644 --- a/packages/astro/src/jsx/babel.ts +++ b/packages/astro/src/jsx/babel.ts @@ -1,85 +1,110 @@ -import * as t from "@babel/types"; import type { PluginObj } from '@babel/core'; +import * as t from '@babel/types'; function isComponent(tagName: string) { - return ( - (tagName[0] && tagName[0].toLowerCase() !== tagName[0]) || - tagName.includes(".") || - /[^a-zA-Z]/.test(tagName[0]) - ); + return ( + (tagName[0] && tagName[0].toLowerCase() !== tagName[0]) || + tagName.includes('.') || + /[^a-zA-Z]/.test(tagName[0]) + ); } function hasClientDirective(node: t.JSXElement) { for (const attr of node.openingElement.attributes) { if (attr.type === 'JSXAttribute' && attr.name.type === 'JSXNamespacedName') { - return attr.name.namespace.name === 'client' + return attr.name.namespace.name === 'client'; } } return false; } function getTagName(tag: t.JSXElement) { - const jsxName = tag.openingElement.name; - return jsxElementNameToString(jsxName); + const jsxName = tag.openingElement.name; + return jsxElementNameToString(jsxName); } function jsxElementNameToString(node: t.JSXOpeningElement['name']): string { - if (t.isJSXMemberExpression(node)) { - return `${jsxElementNameToString(node.object)}.${node.property.name}`; - } - if (t.isJSXIdentifier(node) || t.isIdentifier(node)) { - return node.name; - } - return `${node.namespace.name}:${node.name.name}`; + if (t.isJSXMemberExpression(node)) { + return `${jsxElementNameToString(node.object)}.${node.property.name}`; + } + if (t.isJSXIdentifier(node) || t.isIdentifier(node)) { + return node.name; + } + return `${node.namespace.name}:${node.name.name}`; } function jsxAttributeToString(attr: t.JSXAttribute): string { if (t.isJSXNamespacedName(attr.name)) { - return `${attr.name.namespace.name}:${attr.name.name.name}` + return `${attr.name.namespace.name}:${attr.name.name.name}`; } return `${attr.name.name}`; } -function addClientMetadata(node: t.JSXElement, meta: { path: string, name: string }) { - const existingAttributes = node.openingElement.attributes.map(attr => t.isJSXAttribute(attr) ? jsxAttributeToString(attr) : null); - if (!existingAttributes.find(attr => attr === 'client:component-path')) { +function addClientMetadata(node: t.JSXElement, meta: { path: string; name: string }) { + const existingAttributes = node.openingElement.attributes.map((attr) => + t.isJSXAttribute(attr) ? jsxAttributeToString(attr) : null + ); + if (!existingAttributes.find((attr) => attr === 'client:component-path')) { const componentPath = t.jsxAttribute( t.jsxNamespacedName(t.jsxIdentifier('client'), t.jsxIdentifier('component-path')), - !meta.path.startsWith('.') ? t.stringLiteral(meta.path) : t.jsxExpressionContainer(t.binaryExpression("+", t.stringLiteral('/@fs'), t.memberExpression(t.newExpression(t.identifier('URL'), [t.stringLiteral(meta.path), t.identifier('import.meta.url')]), t.identifier('pathname')))), + !meta.path.startsWith('.') + ? t.stringLiteral(meta.path) + : t.jsxExpressionContainer( + t.binaryExpression( + '+', + t.stringLiteral('/@fs'), + t.memberExpression( + t.newExpression(t.identifier('URL'), [ + t.stringLiteral(meta.path), + t.identifier('import.meta.url'), + ]), + t.identifier('pathname') + ) + ) + ) ); node.openingElement.attributes.push(componentPath); } - if (!existingAttributes.find(attr => attr === 'client:component-export')) { + if (!existingAttributes.find((attr) => attr === 'client:component-export')) { if (meta.name === '*') { meta.name = getTagName(node).split('.').at(1)!; } const componentExport = t.jsxAttribute( t.jsxNamespacedName(t.jsxIdentifier('client'), t.jsxIdentifier('component-export')), - t.stringLiteral(meta.name), + t.stringLiteral(meta.name) ); node.openingElement.attributes.push(componentExport); } - if (!existingAttributes.find(attr => attr === 'client:component-hydration')) { + if (!existingAttributes.find((attr) => attr === 'client:component-hydration')) { const staticMarker = t.jsxAttribute( - t.jsxNamespacedName(t.jsxIdentifier('client'), t.jsxIdentifier('component-hydration')), - ) + t.jsxNamespacedName(t.jsxIdentifier('client'), t.jsxIdentifier('component-hydration')) + ); node.openingElement.attributes.push(staticMarker); } } export default function astroJSX(): PluginObj { - return { - visitor: { + return { + visitor: { Program(path) { - path.node.body.splice(0, 0, (t.importDeclaration([t.importSpecifier(t.identifier('Fragment'), t.identifier('Fragment'))], t.stringLiteral('astro/jsx-runtime')))); + path.node.body.splice( + 0, + 0, + t.importDeclaration( + [t.importSpecifier(t.identifier('Fragment'), t.identifier('Fragment'))], + t.stringLiteral('astro/jsx-runtime') + ) + ); }, ImportDeclaration(path, state) { const source = path.node.source.value; if (source.startsWith('astro/jsx-runtime')) return; - const specs = path.node.specifiers.map(spec => { - if (t.isImportDefaultSpecifier(spec)) return { local: spec.local.name, imported: 'default' } - if (t.isImportNamespaceSpecifier(spec)) return { local: spec.local.name, imported: '*' } - if (t.isIdentifier(spec.imported)) return { local: spec.local.name, imported: spec.imported.name }; + const specs = path.node.specifiers.map((spec) => { + if (t.isImportDefaultSpecifier(spec)) + return { local: spec.local.name, imported: 'default' }; + if (t.isImportNamespaceSpecifier(spec)) return { local: spec.local.name, imported: '*' }; + if (t.isIdentifier(spec.imported)) + return { local: spec.local.name, imported: spec.imported.name }; return { local: spec.local.name, imported: spec.imported.value }; }); const imports = state.get('imports') ?? new Map(); @@ -87,17 +112,17 @@ export default function astroJSX(): PluginObj { if (imports.has(source)) { const existing = imports.get(source); existing.add(spec); - imports.set(source, existing) + imports.set(source, existing); } else { - imports.set(source, new Set([spec])) + imports.set(source, new Set([spec])); } } state.set('imports', imports); }, JSXIdentifier(path, state) { - const isAttr = path.findParent(n => t.isJSXAttribute(n)); + const isAttr = path.findParent((n) => t.isJSXAttribute(n)); if (isAttr) return; - const parent = path.findParent(n => t.isJSXElement(n))!; + const parent = path.findParent((n) => t.isJSXElement(n))!; const parentNode = parent.node as t.JSXElement; const tagName = getTagName(parentNode); if (!isComponent(tagName)) return; @@ -121,11 +146,15 @@ export default function astroJSX(): PluginObj { // TODO: map unmatched identifiers back to imports if possible const meta = path.getData('import'); if (meta) { - addClientMetadata(parentNode, meta) + addClientMetadata(parentNode, meta); } else { - throw new Error(`Unable to match <${getTagName(parentNode)}> with client:* directive to an import statement!`); + throw new Error( + `Unable to match <${getTagName( + parentNode + )}> with client:* directive to an import statement!` + ); } }, - } - }; -}; + }, + }; +} diff --git a/packages/astro/src/jsx/renderer.ts b/packages/astro/src/jsx/renderer.ts index 94a63b5fe4c79..54f4d6a3d1cdd 100644 --- a/packages/astro/src/jsx/renderer.ts +++ b/packages/astro/src/jsx/renderer.ts @@ -4,12 +4,17 @@ const renderer = { jsxImportSource: 'astro', jsxTransformOptions: async () => { // @ts-ignore - const { default: { default: jsx } } = await import('@babel/plugin-transform-react-jsx'); + const { + default: { default: jsx }, + } = await import('@babel/plugin-transform-react-jsx'); const { default: astroJSX } = await import('./babel.js'); return { - plugins: [astroJSX(), jsx({}, { throwIfNamespace: false, runtime: 'automatic', importSource: 'astro' })], + plugins: [ + astroJSX(), + jsx({}, { throwIfNamespace: false, runtime: 'automatic', importSource: 'astro' }), + ], }; }, -} +}; export default renderer; diff --git a/packages/astro/src/jsx/server.ts b/packages/astro/src/jsx/server.ts index c75135b90c544..1f7ff850ca0b0 100644 --- a/packages/astro/src/jsx/server.ts +++ b/packages/astro/src/jsx/server.ts @@ -1,9 +1,13 @@ -import { renderJSX } from '../runtime/server/jsx.js'; import { AstroJSX, jsx } from '../jsx-runtime/index.js'; +import { renderJSX } from '../runtime/server/jsx.js'; const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase()); -export async function check(Component: any, props: any, { default: children = null, ...slotted } = {}) { +export async function check( + Component: any, + props: any, + { default: children = null, ...slotted } = {} +) { if (typeof Component !== 'function') return false; const slots: Record = {}; for (const [key, value] of Object.entries(slotted)) { @@ -13,11 +17,16 @@ export async function check(Component: any, props: any, { default: children = nu try { const result = await Component({ ...props, ...slots, children }); return result[AstroJSX]; - } catch (e) {}; + } catch (e) {} return false; } -export async function renderToStaticMarkup(this: any, Component: any, props = {}, { default: children = null, ...slotted } = {}) { +export async function renderToStaticMarkup( + this: any, + Component: any, + props = {}, + { default: children = null, ...slotted } = {} +) { const slots: Record = {}; for (const [key, value] of Object.entries(slotted)) { const name = slotName(key); diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 33d41ef5d08a4..e1ffd69e593b2 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -22,7 +22,12 @@ import { serializeProps } from './serialize.js'; import { shorthash } from './shorthash.js'; import { serializeListValue } from './util.js'; -export { markHTMLString, markHTMLString as unescapeHTML, HTMLString, escapeHTML } from './escape.js'; +export { + escapeHTML, + HTMLString, + markHTMLString, + markHTMLString as unescapeHTML, +} from './escape.js'; export type { Metadata } from './metadata'; export { createMetadata } from './metadata.js'; @@ -299,7 +304,13 @@ Did you mean to enable ${formatList(probableRendererNames.map((r) => '`' + r + ' // We already know that renderer.ssr.check() has failed // but this will throw a much more descriptive error! renderer = matchingRenderers[0]; - ({ html } = await renderer.ssr.renderToStaticMarkup.call({ result }, Component, props, children, metadata)); + ({ html } = await renderer.ssr.renderToStaticMarkup.call( + { result }, + Component, + props, + children, + metadata + )); } else { throw new Error(`Unable to render ${metadata.displayName}! @@ -318,12 +329,20 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr if (metadata.hydrate === 'only') { html = await renderSlot(result, slots?.fallback); } else { - ({ html } = await renderer.ssr.renderToStaticMarkup.call({ result }, Component, props, children, metadata)); + ({ html } = await renderer.ssr.renderToStaticMarkup.call( + { result }, + Component, + props, + children, + metadata + )); } } if (renderer && !renderer.clientEntrypoint && metadata.hydrate) { - throw new Error(`${metadata.displayName} component has a \`client:${metadata.hydrate}\` directive, but no client entrypoint was provided by ${renderer.name}!`); + throw new Error( + `${metadata.displayName} component has a \`client:${metadata.hydrate}\` directive, but no client entrypoint was provided by ${renderer.name}!` + ); } // This is a custom element without a renderer. Because of that, render it diff --git a/packages/astro/src/runtime/server/jsx.ts b/packages/astro/src/runtime/server/jsx.ts index dc4df923a8782..0153787970d1a 100644 --- a/packages/astro/src/runtime/server/jsx.ts +++ b/packages/astro/src/runtime/server/jsx.ts @@ -1,13 +1,28 @@ -import { HTMLString, markHTMLString, escapeHTML, Fragment, renderComponent, spreadAttributes, voidElementNames } from './index.js'; import { AstroJSX, isVNode } from '../../jsx-runtime/index.js'; +import { + escapeHTML, + Fragment, + HTMLString, + markHTMLString, + renderComponent, + spreadAttributes, + voidElementNames, +} from './index.js'; export async function renderJSX(result: any, vnode: any): Promise { switch (true) { - case (vnode instanceof HTMLString): return vnode; - case (typeof vnode === 'string'): return markHTMLString(escapeHTML(vnode)); - case (!vnode && vnode !== 0): return ''; - case (vnode.type === Fragment): return renderJSX(result, vnode.props.children); - case (Array.isArray(vnode)): return markHTMLString((await Promise.all(vnode.map((v: any) => renderJSX(result, v)))).join('')); + case vnode instanceof HTMLString: + return vnode; + case typeof vnode === 'string': + return markHTMLString(escapeHTML(vnode)); + case !vnode && vnode !== 0: + return ''; + case vnode.type === Fragment: + return renderJSX(result, vnode.props.children); + case Array.isArray(vnode): + return markHTMLString( + (await Promise.all(vnode.map((v: any) => renderJSX(result, v)))).join('') + ); } if (vnode[AstroJSX]) { if (!vnode.type && vnode.type !== 0) return ''; @@ -27,17 +42,17 @@ export async function renderJSX(result: any, vnode: any): Promise { const { children = null, ...props } = vnode.props ?? {}; const slots: Record = { - default: [] - } + default: [], + }; function extractSlots(child: any): any { if (Array.isArray(child)) { - return child.map(c => extractSlots(c)); + return child.map((c) => extractSlots(c)); } if (!isVNode(child)) { return slots.default.push(child); } if ('slot' in child.props) { - slots[child.props.slot] = [...(slots[child.props.slot] ?? []), child] + slots[child.props.slot] = [...(slots[child.props.slot] ?? []), child]; delete child.props.slot; return; } @@ -47,17 +62,25 @@ export async function renderJSX(result: any, vnode: any): Promise { for (const [key, value] of Object.entries(slots)) { slots[key] = () => renderJSX(result, value); } - return markHTMLString(await renderComponent(result, vnode.type.name, vnode.type, props, slots)); + return markHTMLString( + await renderComponent(result, vnode.type.name, vnode.type, props, slots) + ); } } // numbers, plain objects, etc return markHTMLString(`${vnode}`); } -async function renderElement(result: any, tag: string, { children, ...props }: Record) { - return markHTMLString(`<${tag}${spreadAttributes(props)}${markHTMLString( +async function renderElement( + result: any, + tag: string, + { children, ...props }: Record +) { + return markHTMLString( + `<${tag}${spreadAttributes(props)}${markHTMLString( (children == null || children == '') && voidElementNames.test(tag) ? `/>` : `>${children == null ? '' : await renderJSX(result, children)}` - )}`); + )}` + ); } diff --git a/packages/astro/test/jsx.test.js b/packages/astro/test/jsx.test.js index bf05d35c0af47..41671699cf191 100644 --- a/packages/astro/test/jsx.test.js +++ b/packages/astro/test/jsx.test.js @@ -7,7 +7,7 @@ describe('jsx-runtime', () => { before(async () => { fixture = await loadFixture({ - root: './fixtures/jsx/' + root: './fixtures/jsx/', }); await fixture.build(); }); From b11e3b38ebb59ceec3479cbf580276d3b3bd657c Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 24 Jun 2022 16:14:00 -0400 Subject: [PATCH 28/58] Ensure import.meta.env.SSR is true in SSR mode (#3702) * Ensure import.meta.env.SSR is true in SSR mode * Define in the env plugin instead --- .changeset/moody-crabs-stare.md | 5 ++++ packages/astro/src/core/build/static-build.ts | 1 + packages/astro/src/vite-plugin-env/index.ts | 2 ++ .../test/fixtures/ssr-env/astro.config.mjs | 5 ++++ .../astro/test/fixtures/ssr-env/package.json | 9 ++++++ .../fixtures/ssr-env/src/components/Env.jsx | 7 +++++ .../test/fixtures/ssr-env/src/pages/ssr.astro | 9 ++++++ packages/astro/test/ssr-env.test.js | 29 +++++++++++++++++++ pnpm-lock.yaml | 8 +++++ 9 files changed, 75 insertions(+) create mode 100644 .changeset/moody-crabs-stare.md create mode 100644 packages/astro/test/fixtures/ssr-env/astro.config.mjs create mode 100644 packages/astro/test/fixtures/ssr-env/package.json create mode 100644 packages/astro/test/fixtures/ssr-env/src/components/Env.jsx create mode 100644 packages/astro/test/fixtures/ssr-env/src/pages/ssr.astro create mode 100644 packages/astro/test/ssr-env.test.js diff --git a/.changeset/moody-crabs-stare.md b/.changeset/moody-crabs-stare.md new file mode 100644 index 0000000000000..19b9a23f22bb3 --- /dev/null +++ b/.changeset/moody-crabs-stare.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Ensure import.meta.env.SSR is true in SSR mode diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 25e0b04e4120f..c912b74c11809 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -122,6 +122,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp entryFileNames: opts.buildConfig.serverEntry, }, }, + ssr: true, // must match an esbuild target target: 'esnext', diff --git a/packages/astro/src/vite-plugin-env/index.ts b/packages/astro/src/vite-plugin-env/index.ts index d3a5f2635d99a..565ea0dae0bba 100644 --- a/packages/astro/src/vite-plugin-env/index.ts +++ b/packages/astro/src/vite-plugin-env/index.ts @@ -78,6 +78,7 @@ export default function envVitePlugin({ privateEnv = getPrivateEnv(config, astroConfig); if (privateEnv) { privateEnv.SITE = astroConfig.site ? `'${astroConfig.site}'` : 'undefined'; + privateEnv.SSR = JSON.stringify(true); const entries = Object.entries(privateEnv).map(([key, value]) => [ `import.meta.env.${key}`, value, @@ -86,6 +87,7 @@ export default function envVitePlugin({ // These additional replacements are needed to match Vite replacements = Object.assign(replacements, { 'import.meta.env.SITE': astroConfig.site ? `'${astroConfig.site}'` : 'undefined', + 'import.meta.env.SSR': JSON.stringify(true), // This catches destructed `import.meta.env` calls, // BUT we only want to inject private keys referenced in the file. // We overwrite this value on a per-file basis. diff --git a/packages/astro/test/fixtures/ssr-env/astro.config.mjs b/packages/astro/test/fixtures/ssr-env/astro.config.mjs new file mode 100644 index 0000000000000..42f10a57298df --- /dev/null +++ b/packages/astro/test/fixtures/ssr-env/astro.config.mjs @@ -0,0 +1,5 @@ +import preact from '@astrojs/preact'; + +export default { + integrations: [preact()] +} diff --git a/packages/astro/test/fixtures/ssr-env/package.json b/packages/astro/test/fixtures/ssr-env/package.json new file mode 100644 index 0000000000000..f2d339704a8f2 --- /dev/null +++ b/packages/astro/test/fixtures/ssr-env/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/ssr-env", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*", + "@astrojs/preact": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/ssr-env/src/components/Env.jsx b/packages/astro/test/fixtures/ssr-env/src/components/Env.jsx new file mode 100644 index 0000000000000..776cf37850942 --- /dev/null +++ b/packages/astro/test/fixtures/ssr-env/src/components/Env.jsx @@ -0,0 +1,7 @@ + +export default function() { + const ssr = import.meta.env.SSR; + return ( +
    {'' + ssr }
    + ) +} diff --git a/packages/astro/test/fixtures/ssr-env/src/pages/ssr.astro b/packages/astro/test/fixtures/ssr-env/src/pages/ssr.astro new file mode 100644 index 0000000000000..e554d28eae115 --- /dev/null +++ b/packages/astro/test/fixtures/ssr-env/src/pages/ssr.astro @@ -0,0 +1,9 @@ +--- +import Env from '../components/Env.jsx'; +--- + +Test + + + + diff --git a/packages/astro/test/ssr-env.test.js b/packages/astro/test/ssr-env.test.js new file mode 100644 index 0000000000000..da823fa201c0f --- /dev/null +++ b/packages/astro/test/ssr-env.test.js @@ -0,0 +1,29 @@ +import { expect } from 'chai'; +import * as cheerio from 'cheerio'; +import { loadFixture } from './test-utils.js'; +import testAdapter from './test-adapter.js'; + +describe('SSR Environment Variables', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/ssr-env/', + experimental: { + ssr: true, + }, + adapter: testAdapter(), + }); + await fixture.build(); + }); + + it('import.meta.env.SSR is true', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/ssr'); + const response = await app.render(request); + const html = await response.text(); + const $ = cheerio.load(html); + expect($('#ssr').text()).to.equal('true'); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8c22fd6952815..7be62432c3fde 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1653,6 +1653,14 @@ importers: '@astrojs/solid-js': link:../../../../integrations/solid astro: link:../../.. + packages/astro/test/fixtures/ssr-env: + specifiers: + '@astrojs/preact': workspace:* + astro: workspace:* + dependencies: + '@astrojs/preact': link:../../../../integrations/preact + astro: link:../../.. + packages/astro/test/fixtures/ssr-markdown: specifiers: astro: workspace:* From b5e3403fa151710be4837f6ad265d836adb08025 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 24 Jun 2022 16:58:14 -0400 Subject: [PATCH 29/58] Simplified Response#text() implementation (#3705) * Simplified Response#text() implementation * Adds a changeset * Fix tsignore --- .changeset/early-teachers-vanish.md | 5 ++++ packages/astro/src/jsx/renderer.ts | 2 +- packages/astro/src/runtime/server/response.ts | 30 +++++-------------- pnpm-lock.yaml | 9 ------ 4 files changed, 14 insertions(+), 32 deletions(-) create mode 100644 .changeset/early-teachers-vanish.md diff --git a/.changeset/early-teachers-vanish.md b/.changeset/early-teachers-vanish.md new file mode 100644 index 0000000000000..851541c21baa9 --- /dev/null +++ b/.changeset/early-teachers-vanish.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes build some times breaking in large sites diff --git a/packages/astro/src/jsx/renderer.ts b/packages/astro/src/jsx/renderer.ts index 54f4d6a3d1cdd..3aee8520fc645 100644 --- a/packages/astro/src/jsx/renderer.ts +++ b/packages/astro/src/jsx/renderer.ts @@ -3,9 +3,9 @@ const renderer = { serverEntrypoint: 'astro/jsx/server.js', jsxImportSource: 'astro', jsxTransformOptions: async () => { - // @ts-ignore const { default: { default: jsx }, + // @ts-ignore } = await import('@babel/plugin-transform-react-jsx'); const { default: astroJSX } = await import('./babel.js'); return { diff --git a/packages/astro/src/runtime/server/response.ts b/packages/astro/src/runtime/server/response.ts index 084ea7436c999..1369f3f05e683 100644 --- a/packages/astro/src/runtime/server/response.ts +++ b/packages/astro/src/runtime/server/response.ts @@ -21,36 +21,22 @@ function createResponseClass() { async text(): Promise { if (this.#isStream && isNodeJS) { let decoder = new TextDecoder(); - let body = this.#body as ReadableStream; - let reader = body.getReader(); - let buffer: number[] = []; - while (true) { - let r = await reader.read(); - if (r.value) { - buffer.push(...r.value); - } - if (r.done) { - break; - } + let body = this.#body as AsyncIterable; + let out = ''; + for await(let chunk of body) { + out += decoder.decode(chunk); } - return decoder.decode(Uint8Array.from(buffer)); + return out; } return super.text(); } async arrayBuffer(): Promise { if (this.#isStream && isNodeJS) { - let body = this.#body as ReadableStream; - let reader = body.getReader(); + let body = this.#body as AsyncIterable; let chunks: number[] = []; - while (true) { - let r = await reader.read(); - if (r.value) { - chunks.push(...r.value); - } - if (r.done) { - break; - } + for await(let chunk of body) { + chunks.push(...chunk); } return Uint8Array.from(chunks); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7be62432c3fde..fcedb9ab3bd57 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8554,11 +8554,6 @@ packages: /debug/3.2.7: resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true dependencies: ms: 2.1.3 dev: false @@ -11440,8 +11435,6 @@ packages: debug: 3.2.7 iconv-lite: 0.4.24 sax: 1.2.4 - transitivePeerDependencies: - - supports-color dev: false /netmask/2.0.2: @@ -11525,8 +11518,6 @@ packages: rimraf: 2.7.1 semver: 5.7.1 tar: 4.4.19 - transitivePeerDependencies: - - supports-color dev: false /node-releases/2.0.5: From f3e01f6c266816f1037d20aa93396d49c96a4b18 Mon Sep 17 00:00:00 2001 From: matthewp Date: Fri, 24 Jun 2022 21:00:16 +0000 Subject: [PATCH 30/58] [ci] format --- packages/astro/src/runtime/server/response.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/runtime/server/response.ts b/packages/astro/src/runtime/server/response.ts index 1369f3f05e683..1e92c47ba4539 100644 --- a/packages/astro/src/runtime/server/response.ts +++ b/packages/astro/src/runtime/server/response.ts @@ -23,7 +23,7 @@ function createResponseClass() { let decoder = new TextDecoder(); let body = this.#body as AsyncIterable; let out = ''; - for await(let chunk of body) { + for await (let chunk of body) { out += decoder.decode(chunk); } return out; @@ -35,7 +35,7 @@ function createResponseClass() { if (this.#isStream && isNodeJS) { let body = this.#body as AsyncIterable; let chunks: number[] = []; - for await(let chunk of body) { + for await (let chunk of body) { chunks.push(...chunk); } return Uint8Array.from(chunks); From 701a3bd6982279edbdfb09badb1f5aa200a76488 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 24 Jun 2022 17:02:11 -0400 Subject: [PATCH 31/58] [ci] release (#3707) Co-authored-by: github-actions[bot] --- .changeset/early-teachers-vanish.md | 5 -- .changeset/moody-crabs-stare.md | 5 -- examples/basics/package.json | 2 +- examples/blog-multiple-authors/package.json | 2 +- examples/blog/package.json | 2 +- examples/component/demo/package.json | 2 +- examples/component/package.json | 2 +- examples/docs/package.json | 2 +- examples/env-vars/package.json | 2 +- examples/framework-alpine/package.json | 2 +- examples/framework-lit/package.json | 2 +- examples/framework-multiple/package.json | 2 +- examples/framework-preact/package.json | 2 +- examples/framework-react/package.json | 2 +- examples/framework-solid/package.json | 2 +- examples/framework-svelte/package.json | 2 +- examples/framework-vue/package.json | 2 +- examples/integrations-playground/package.json | 2 +- examples/minimal/package.json | 2 +- examples/non-html-pages/package.json | 2 +- examples/portfolio/package.json | 2 +- examples/ssr/package.json | 2 +- examples/starter/package.json | 2 +- examples/subpath/package.json | 2 +- examples/with-markdown-plugins/package.json | 2 +- examples/with-markdown-shiki/package.json | 2 +- examples/with-markdown/package.json | 2 +- examples/with-nanostores/package.json | 2 +- examples/with-tailwindcss/package.json | 2 +- examples/with-vite-plugin-pwa/package.json | 2 +- packages/astro/CHANGELOG.md | 8 +++ packages/astro/package.json | 2 +- pnpm-lock.yaml | 56 +++++++++---------- 33 files changed, 65 insertions(+), 67 deletions(-) delete mode 100644 .changeset/early-teachers-vanish.md delete mode 100644 .changeset/moody-crabs-stare.md diff --git a/.changeset/early-teachers-vanish.md b/.changeset/early-teachers-vanish.md deleted file mode 100644 index 851541c21baa9..0000000000000 --- a/.changeset/early-teachers-vanish.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Fixes build some times breaking in large sites diff --git a/.changeset/moody-crabs-stare.md b/.changeset/moody-crabs-stare.md deleted file mode 100644 index 19b9a23f22bb3..0000000000000 --- a/.changeset/moody-crabs-stare.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Ensure import.meta.env.SSR is true in SSR mode diff --git a/examples/basics/package.json b/examples/basics/package.json index db7d28f1eb050..0a2cc3108766e 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/blog-multiple-authors/package.json b/examples/blog-multiple-authors/package.json index ffc3f1ddb5b7e..53c39005176b4 100644 --- a/examples/blog-multiple-authors/package.json +++ b/examples/blog-multiple-authors/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.55", + "astro": "^1.0.0-beta.56", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/blog/package.json b/examples/blog/package.json index 0014609908c8d..1d7766d26e28f 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/component/demo/package.json b/examples/component/demo/package.json index 1e3408492c1bb..ee80098050268 100644 --- a/examples/component/demo/package.json +++ b/examples/component/demo/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@example/my-component": "workspace:*", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/component/package.json b/examples/component/package.json index 1bd5af19f8739..b43bf97570f58 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -8,6 +8,6 @@ "serve": "astro --root demo preview" }, "devDependencies": { - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/docs/package.json b/examples/docs/package.json index a464038e5ce0c..a271c57d32b42 100644 --- a/examples/docs/package.json +++ b/examples/docs/package.json @@ -20,6 +20,6 @@ "devDependencies": { "@astrojs/preact": "^0.2.0", "@astrojs/react": "^0.2.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/env-vars/package.json b/examples/env-vars/package.json index 0e0b6ca7c0247..6de1fc5d22a88 100644 --- a/examples/env-vars/package.json +++ b/examples/env-vars/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index 96a6bd6bca86f..2f2276407f460 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "alpinejs": "^3.10.2" diff --git a/examples/framework-lit/package.json b/examples/framework-lit/package.json index c00c36c82afe8..1887ffa30838b 100644 --- a/examples/framework-lit/package.json +++ b/examples/framework-lit/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/lit": "^0.3.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index a95e648b4c725..d5d9011a8687f 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -15,7 +15,7 @@ "@astrojs/solid-js": "^0.2.0", "@astrojs/svelte": "^0.2.0", "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 36842a4312d61..643bc3c68e6b5 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index 0d8533e4ebcf4..aede2e7f5e260 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -12,7 +12,7 @@ "@astrojs/react": "^0.2.0", "@types/react": "^18.0.10", "@types/react-dom": "^18.0.5", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "react": "^18.1.0", diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index 82ddc9d8ca505..2a94d4395d3d8 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/solid-js": "^0.2.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "solid-js": "^1.4.3" diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index c8ec4fb36b88a..8cc81ea1d1d23 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/svelte": "^0.2.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "svelte": "^3.48.0" diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 6e53ef3d95db2..654e4d7b6d85d 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "vue": "^3.2.36" diff --git a/examples/integrations-playground/package.json b/examples/integrations-playground/package.json index d0d8bf2d01d03..172830d88f3f5 100644 --- a/examples/integrations-playground/package.json +++ b/examples/integrations-playground/package.json @@ -16,7 +16,7 @@ "@astrojs/solid-js": "0.2.0", "@astrojs/tailwind": "^0.2.1", "@astrojs/turbolinks": "^0.1.3", - "astro": "^1.0.0-beta.55", + "astro": "^1.0.0-beta.56", "solid-js": "^1.4.3" }, "dependencies": { diff --git a/examples/minimal/package.json b/examples/minimal/package.json index b2aa9ee99cb9e..8a2fb24edfba4 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/non-html-pages/package.json b/examples/non-html-pages/package.json index 19194e4f82b0f..de71eed416379 100644 --- a/examples/non-html-pages/package.json +++ b/examples/non-html-pages/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index 5f5fa50406927..f056fb3726265 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.55", + "astro": "^1.0.0-beta.56", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/ssr/package.json b/examples/ssr/package.json index 9230d4812e23b..10f42adf0239a 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -11,7 +11,7 @@ "devDependencies": { "@astrojs/node": "^0.1.2", "@astrojs/svelte": "^0.2.0", - "astro": "^1.0.0-beta.55", + "astro": "^1.0.0-beta.56", "concurrently": "^7.2.1", "lightcookie": "^1.0.25", "unocss": "^0.15.6", diff --git a/examples/starter/package.json b/examples/starter/package.json index a38003cabf502..caf5f377b7a19 100644 --- a/examples/starter/package.json +++ b/examples/starter/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/subpath/package.json b/examples/subpath/package.json index 2fc51a223ee7d..62724ef2d9087 100644 --- a/examples/subpath/package.json +++ b/examples/subpath/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/react": "^0.2.0", - "astro": "^1.0.0-beta.55", + "astro": "^1.0.0-beta.56", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/with-markdown-plugins/package.json b/examples/with-markdown-plugins/package.json index 31506955a7b83..aaa4334759a77 100644 --- a/examples/with-markdown-plugins/package.json +++ b/examples/with-markdown-plugins/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.55", + "astro": "^1.0.0-beta.56", "hast-util-select": "5.0.1", "rehype-autolink-headings": "^6.1.1", "rehype-slug": "^5.0.1", diff --git a/examples/with-markdown-shiki/package.json b/examples/with-markdown-shiki/package.json index 748d7ba7592d3..cb214e25233b6 100644 --- a/examples/with-markdown-shiki/package.json +++ b/examples/with-markdown-shiki/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/with-markdown/package.json b/examples/with-markdown/package.json index e0b5c3b3ee720..0f1fddfbff218 100644 --- a/examples/with-markdown/package.json +++ b/examples/with-markdown/package.json @@ -14,7 +14,7 @@ "@astrojs/react": "^0.2.0", "@astrojs/svelte": "^0.2.0", "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" }, "dependencies": { "preact": "^10.7.3", diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index a00b0ebb6b890..5141c4e5abf39 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -25,6 +25,6 @@ "@astrojs/solid-js": "^0.2.0", "@astrojs/svelte": "^0.2.0", "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.55" + "astro": "^1.0.0-beta.56" } } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index e5f8d54d03545..54ed31a2c081c 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/tailwind": "^0.2.1", - "astro": "^1.0.0-beta.55", + "astro": "^1.0.0-beta.56", "autoprefixer": "^10.4.7", "canvas-confetti": "^1.5.1", "postcss": "^8.4.14", diff --git a/examples/with-vite-plugin-pwa/package.json b/examples/with-vite-plugin-pwa/package.json index 1b25a1ed0f2e2..b642b2d1fe5e5 100644 --- a/examples/with-vite-plugin-pwa/package.json +++ b/examples/with-vite-plugin-pwa/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.55", + "astro": "^1.0.0-beta.56", "vite-plugin-pwa": "0.11.11", "workbox-window": "^6.5.3" } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index a16f62bea0d85..8ff78be21be3a 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,13 @@ # astro +## 1.0.0-beta.56 + +### Patch Changes + +- [#3705](https://github.com/withastro/astro/pull/3705) [`b5e3403f`](https://github.com/withastro/astro/commit/b5e3403fa151710be4837f6ad265d836adb08025) Thanks [@matthewp](https://github.com/matthewp)! - Fixes build some times breaking in large sites + +* [#3702](https://github.com/withastro/astro/pull/3702) [`b11e3b38`](https://github.com/withastro/astro/commit/b11e3b38ebb59ceec3479cbf580276d3b3bd657c) Thanks [@matthewp](https://github.com/matthewp)! - Ensure import.meta.env.SSR is true in SSR mode + ## 1.0.0-beta.55 ### Patch Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index 256b299c642f4..1a35c6bb78298 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "1.0.0-beta.55", + "version": "1.0.0-beta.56", "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.", "type": "module", "author": "withastro", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fcedb9ab3bd57..d627831f583e1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,14 +49,14 @@ importers: examples/basics: specifiers: - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 devDependencies: astro: link:../../packages/astro examples/blog: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -67,7 +67,7 @@ importers: examples/blog-multiple-authors: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -79,14 +79,14 @@ importers: examples/component: specifiers: - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 devDependencies: astro: link:../../packages/astro examples/component/demo: specifiers: '@example/my-component': workspace:* - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 devDependencies: '@example/my-component': link:../packages/my-component astro: link:../../../packages/astro @@ -102,7 +102,7 @@ importers: '@docsearch/css': ^3.1.0 '@docsearch/react': ^3.1.0 '@types/react': ^17.0.45 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -121,14 +121,14 @@ importers: examples/env-vars: specifiers: - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 devDependencies: astro: link:../../packages/astro examples/framework-alpine: specifiers: alpinejs: ^3.10.2 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 dependencies: alpinejs: 3.10.2 devDependencies: @@ -138,7 +138,7 @@ importers: specifiers: '@astrojs/lit': ^0.3.0 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 lit: ^2.2.5 dependencies: '@webcomponents/template-shadowroot': 0.1.0 @@ -156,7 +156,7 @@ importers: '@astrojs/svelte': ^0.2.0 '@astrojs/vue': ^0.2.0 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -185,7 +185,7 @@ importers: examples/framework-preact: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -198,7 +198,7 @@ importers: '@astrojs/react': ^0.2.0 '@types/react': ^18.0.10 '@types/react-dom': ^18.0.5 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 react: ^18.1.0 react-dom: ^18.1.0 dependencies: @@ -213,7 +213,7 @@ importers: examples/framework-solid: specifiers: '@astrojs/solid-js': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 solid-js: ^1.4.3 dependencies: solid-js: 1.4.3 @@ -224,7 +224,7 @@ importers: examples/framework-svelte: specifiers: '@astrojs/svelte': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 svelte: ^3.48.0 dependencies: svelte: 3.48.0 @@ -235,7 +235,7 @@ importers: examples/framework-vue: specifiers: '@astrojs/vue': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 vue: ^3.2.36 dependencies: vue: 3.2.37 @@ -253,7 +253,7 @@ importers: '@astrojs/tailwind': ^0.2.1 '@astrojs/turbolinks': ^0.1.3 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -282,20 +282,20 @@ importers: examples/minimal: specifiers: - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 devDependencies: astro: link:../../packages/astro examples/non-html-pages: specifiers: - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 devDependencies: astro: link:../../packages/astro examples/portfolio: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -309,7 +309,7 @@ importers: specifiers: '@astrojs/node': ^0.1.2 '@astrojs/svelte': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 concurrently: ^7.2.1 lightcookie: ^1.0.25 svelte: ^3.48.0 @@ -328,14 +328,14 @@ importers: examples/starter: specifiers: - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 devDependencies: astro: link:../../packages/astro examples/subpath: specifiers: '@astrojs/react': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 react: ^18.1.0 react-dom: ^18.1.0 sass: ^1.52.2 @@ -354,7 +354,7 @@ importers: '@astrojs/react': ^0.2.0 '@astrojs/svelte': ^0.2.0 '@astrojs/vue': ^0.2.0 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -377,7 +377,7 @@ importers: examples/with-markdown-plugins: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 hast-util-select: 5.0.1 rehype-autolink-headings: ^6.1.1 rehype-slug: ^5.0.1 @@ -395,7 +395,7 @@ importers: examples/with-markdown-shiki: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 devDependencies: '@astrojs/markdown-remark': link:../../packages/markdown/remark astro: link:../../packages/astro @@ -410,7 +410,7 @@ importers: '@nanostores/preact': ^0.1.3 '@nanostores/react': ^0.1.5 '@nanostores/vue': ^0.4.1 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 nanostores: ^0.5.12 preact: ^10.7.3 react: ^18.1.0 @@ -438,7 +438,7 @@ importers: examples/with-tailwindcss: specifiers: '@astrojs/tailwind': ^0.2.1 - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 autoprefixer: ^10.4.7 canvas-confetti: ^1.5.1 postcss: ^8.4.14 @@ -453,7 +453,7 @@ importers: examples/with-vite-plugin-pwa: specifiers: - astro: ^1.0.0-beta.55 + astro: ^1.0.0-beta.56 vite-plugin-pwa: 0.11.11 workbox-window: ^6.5.3 devDependencies: From 8002271b817c3df16660c1a5a5d09fa1e634da0d Mon Sep 17 00:00:00 2001 From: FredKSchott Date: Sat, 25 Jun 2022 12:02:10 +0000 Subject: [PATCH 32/58] [ci] collect stats --- scripts/stats/stats.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/stats/stats.csv b/scripts/stats/stats.csv index 00df1110c008c..73b25c5a57724 100644 --- a/scripts/stats/stats.csv +++ b/scripts/stats/stats.csv @@ -1,4 +1,5 @@ Date,Commits (24hr),Issues (24hr),Issues:BUG (24hr),Issues:RFC (24hr),Issues:DOC (24hr),PRs (24hr),Open PRs,Open Issues,Bugs: Needs Triage,Bugs: Accepted,RFC: In Progress,RFC: Accepted,Date (ISO) +"Saturday, June 25, 2022",13,4,4,0,0,8,20,76,52,16,0,0,"2022-06-25T12:02:03.060Z" "Friday, June 24, 2022",14,3,3,0,0,8,21,75,51,16,0,0,"2022-06-24T12:01:59.940Z" "Thursday, June 23, 2022",24,4,4,0,0,11,21,75,51,16,0,0,"2022-06-23T12:02:04.952Z" "Wednesday, June 22, 2022",13,5,5,0,0,12,23,75,51,16,0,0,"2022-06-22T12:02:19.701Z" From c3d41d1f60828914e1224d78c347876cdbdfbd7c Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Sat, 25 Jun 2022 10:24:59 -0700 Subject: [PATCH 33/58] update lockfile on fresh install (#3709) --- pnpm-lock.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d627831f583e1..d17f780d01fab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8554,6 +8554,11 @@ packages: /debug/3.2.7: resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true dependencies: ms: 2.1.3 dev: false @@ -11435,6 +11440,8 @@ packages: debug: 3.2.7 iconv-lite: 0.4.24 sax: 1.2.4 + transitivePeerDependencies: + - supports-color dev: false /netmask/2.0.2: @@ -11518,6 +11525,8 @@ packages: rimraf: 2.7.1 semver: 5.7.1 tar: 4.4.19 + transitivePeerDependencies: + - supports-color dev: false /node-releases/2.0.5: From ec3c4a30d2c148d4483e64c3eab88603c528dec1 Mon Sep 17 00:00:00 2001 From: FredKSchott Date: Sun, 26 Jun 2022 12:02:11 +0000 Subject: [PATCH 34/58] [ci] collect stats --- scripts/stats/stats.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/stats/stats.csv b/scripts/stats/stats.csv index 73b25c5a57724..d7416adadfd24 100644 --- a/scripts/stats/stats.csv +++ b/scripts/stats/stats.csv @@ -1,4 +1,5 @@ Date,Commits (24hr),Issues (24hr),Issues:BUG (24hr),Issues:RFC (24hr),Issues:DOC (24hr),PRs (24hr),Open PRs,Open Issues,Bugs: Needs Triage,Bugs: Accepted,RFC: In Progress,RFC: Accepted,Date (ISO) +"Sunday, June 26, 2022",2,2,2,0,0,3,21,78,54,16,0,0,"2022-06-26T12:02:05.156Z" "Saturday, June 25, 2022",13,4,4,0,0,8,20,76,52,16,0,0,"2022-06-25T12:02:03.060Z" "Friday, June 24, 2022",14,3,3,0,0,8,21,75,51,16,0,0,"2022-06-24T12:01:59.940Z" "Thursday, June 23, 2022",24,4,4,0,0,11,21,75,51,16,0,0,"2022-06-23T12:02:04.952Z" From a930aad5a77209c1986d2a2aeb12072ced97f772 Mon Sep 17 00:00:00 2001 From: FredKSchott Date: Mon, 27 Jun 2022 12:02:16 +0000 Subject: [PATCH 35/58] [ci] collect stats --- scripts/stats/stats.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/stats/stats.csv b/scripts/stats/stats.csv index d7416adadfd24..c56b92bad2582 100644 --- a/scripts/stats/stats.csv +++ b/scripts/stats/stats.csv @@ -1,4 +1,5 @@ Date,Commits (24hr),Issues (24hr),Issues:BUG (24hr),Issues:RFC (24hr),Issues:DOC (24hr),PRs (24hr),Open PRs,Open Issues,Bugs: Needs Triage,Bugs: Accepted,RFC: In Progress,RFC: Accepted,Date (ISO) +"Monday, June 27, 2022",1,4,4,0,0,3,24,82,58,16,0,0,"2022-06-27T12:02:10.213Z" "Sunday, June 26, 2022",2,2,2,0,0,3,21,78,54,16,0,0,"2022-06-26T12:02:05.156Z" "Saturday, June 25, 2022",13,4,4,0,0,8,20,76,52,16,0,0,"2022-06-25T12:02:03.060Z" "Friday, June 24, 2022",14,3,3,0,0,8,21,75,51,16,0,0,"2022-06-24T12:01:59.940Z" From 65e2b71b802ec0c8203cbe03bc86f087cab2a977 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Jun 2022 09:07:48 -0400 Subject: [PATCH 36/58] Inline define:var styles rendered after the head --- packages/astro/src/runtime/server/index.ts | 26 +++++++++++++++++-- packages/astro/test/astro-directives.test.js | 13 ++++++++-- .../src/components/Title.astro | 10 +++++++ .../src/pages/define-vars.astro | 3 +++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 packages/astro/test/fixtures/astro-directives/src/components/Title.astro diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index e1ffd69e593b2..bfe095f5256a7 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -183,7 +183,26 @@ export async function renderComponent( } if (Component && (Component as any).isAstroComponentFactory) { - return renderToIterable(result, Component as any, _props, slots); + async function * renderAstroComponentInline(): AsyncGenerator { + let iterable = await renderToIterable(result, Component as any, _props, slots); + // If this component added any define:vars styles and the head has already been + // sent out, we need to include those inline. + if(result.styles.size && alreadyHeadRenderedResults.has(result)) { + let styles = Array.from(result.styles); + result.styles.clear(); + for(const style of styles) { + if('define:vars' in style.props) { + // We only want to render the property value and not the full stylesheet + // which is bundled in the head. + style.children = ''; + yield markHTMLString(renderElement('style', style)); + } + } + } + yield * iterable; + } + + return renderAstroComponentInline(); } if (!Component && !_props['client:only']) { @@ -408,6 +427,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr island.children = `${html ?? ''}${template}`; + // Scripts to prepend let prescriptType: PrescriptType = needsHydrationScript ? 'both' : needsDirectiveScript @@ -415,7 +435,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr : null; let prescripts = getPrescripts(prescriptType, hydration.directive); - return markHTMLString(prescripts + renderElement('astro-island', island, false)); + return markHTMLString(prestyles + prescripts + renderElement('astro-island', island, false)); } /** Create the Astro.fetchContent() runtime function. */ @@ -719,6 +739,8 @@ export async function renderHead(result: SSRResult): Promise { const styles = Array.from(result.styles) .filter(uniqueElements) .map((style) => renderElement('style', style)); + // Clear result.styles so that any new styles added will be inlined. + result.styles.clear(); const scripts = Array.from(result.scripts) .filter(uniqueElements) .map((script, i) => { diff --git a/packages/astro/test/astro-directives.test.js b/packages/astro/test/astro-directives.test.js index 161063e973168..0a4bab43b92c1 100644 --- a/packages/astro/test/astro-directives.test.js +++ b/packages/astro/test/astro-directives.test.js @@ -22,7 +22,7 @@ describe('Directives', async () => { const html = await fixture.readFile('/define-vars/index.html'); const $ = cheerio.load(html); - expect($('style')).to.have.lengthOf(1); + expect($('style')).to.have.lengthOf(2); expect($('style').toString()).to.include('--bg: white;'); expect($('style').toString()).to.include('--fg: black;'); @@ -31,9 +31,18 @@ describe('Directives', async () => { .split(' ') .find((name) => /^astro-[A-Za-z0-9-]+/.test(name)); - expect($('style').toString().replace(/\s+/g, '')).to.equal( + expect($($('style').get(0)).toString().replace(/\s+/g, '')).to.equal( `` ); + + const scopedTitleClass = $('.title') + .attr('class') + .split(' ') + .find((name) => /^astro-[A-Za-z0-9-]+/.test(name)); + + expect($($('style').get(1)).toString().replace(/\s+/g, '')).to.equal( + `` + ); }); it('set:html', async () => { diff --git a/packages/astro/test/fixtures/astro-directives/src/components/Title.astro b/packages/astro/test/fixtures/astro-directives/src/components/Title.astro new file mode 100644 index 0000000000000..b59303ed60619 --- /dev/null +++ b/packages/astro/test/fixtures/astro-directives/src/components/Title.astro @@ -0,0 +1,10 @@ +--- + const textColor = 'red' +--- +

    hello there

    + + diff --git a/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro b/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro index db03705ad19e7..3df42aea10cbf 100644 --- a/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro +++ b/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro @@ -1,4 +1,5 @@ --- +import Title from "../components/Title.astro" let foo = 'bar' let bg = 'white' let fg = 'black' @@ -17,5 +18,7 @@ let fg = 'black' + + </body> </html> From c8dda941255bbb84da1b37240f6882c95c48e818 Mon Sep 17 00:00:00 2001 From: Matthew Phillips <matthew@skypack.dev> Date: Mon, 27 Jun 2022 09:08:40 -0400 Subject: [PATCH 37/58] Revert "Inline define:var styles rendered after the head" This reverts commit 65e2b71b802ec0c8203cbe03bc86f087cab2a977. --- packages/astro/src/runtime/server/index.ts | 26 ++----------------- packages/astro/test/astro-directives.test.js | 13 ++-------- .../src/components/Title.astro | 10 ------- .../src/pages/define-vars.astro | 3 --- 4 files changed, 4 insertions(+), 48 deletions(-) delete mode 100644 packages/astro/test/fixtures/astro-directives/src/components/Title.astro diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index bfe095f5256a7..e1ffd69e593b2 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -183,26 +183,7 @@ export async function renderComponent( } if (Component && (Component as any).isAstroComponentFactory) { - async function * renderAstroComponentInline(): AsyncGenerator<string, void, undefined> { - let iterable = await renderToIterable(result, Component as any, _props, slots); - // If this component added any define:vars styles and the head has already been - // sent out, we need to include those inline. - if(result.styles.size && alreadyHeadRenderedResults.has(result)) { - let styles = Array.from(result.styles); - result.styles.clear(); - for(const style of styles) { - if('define:vars' in style.props) { - // We only want to render the property value and not the full stylesheet - // which is bundled in the head. - style.children = ''; - yield markHTMLString(renderElement('style', style)); - } - } - } - yield * iterable; - } - - return renderAstroComponentInline(); + return renderToIterable(result, Component as any, _props, slots); } if (!Component && !_props['client:only']) { @@ -427,7 +408,6 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr island.children = `${html ?? ''}${template}`; - // Scripts to prepend let prescriptType: PrescriptType = needsHydrationScript ? 'both' : needsDirectiveScript @@ -435,7 +415,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr : null; let prescripts = getPrescripts(prescriptType, hydration.directive); - return markHTMLString(prestyles + prescripts + renderElement('astro-island', island, false)); + return markHTMLString(prescripts + renderElement('astro-island', island, false)); } /** Create the Astro.fetchContent() runtime function. */ @@ -739,8 +719,6 @@ export async function renderHead(result: SSRResult): Promise<string> { const styles = Array.from(result.styles) .filter(uniqueElements) .map((style) => renderElement('style', style)); - // Clear result.styles so that any new styles added will be inlined. - result.styles.clear(); const scripts = Array.from(result.scripts) .filter(uniqueElements) .map((script, i) => { diff --git a/packages/astro/test/astro-directives.test.js b/packages/astro/test/astro-directives.test.js index 0a4bab43b92c1..161063e973168 100644 --- a/packages/astro/test/astro-directives.test.js +++ b/packages/astro/test/astro-directives.test.js @@ -22,7 +22,7 @@ describe('Directives', async () => { const html = await fixture.readFile('/define-vars/index.html'); const $ = cheerio.load(html); - expect($('style')).to.have.lengthOf(2); + expect($('style')).to.have.lengthOf(1); expect($('style').toString()).to.include('--bg: white;'); expect($('style').toString()).to.include('--fg: black;'); @@ -31,18 +31,9 @@ describe('Directives', async () => { .split(' ') .find((name) => /^astro-[A-Za-z0-9-]+/.test(name)); - expect($($('style').get(0)).toString().replace(/\s+/g, '')).to.equal( + expect($('style').toString().replace(/\s+/g, '')).to.equal( `<style>.${scopedClass}{--bg:white;--fg:black;}body{background:var(--bg);color:var(--fg)}</style>` ); - - const scopedTitleClass = $('.title') - .attr('class') - .split(' ') - .find((name) => /^astro-[A-Za-z0-9-]+/.test(name)); - - expect($($('style').get(1)).toString().replace(/\s+/g, '')).to.equal( - `<style>.${scopedTitleClass}{--textColor:red;}</style>` - ); }); it('set:html', async () => { diff --git a/packages/astro/test/fixtures/astro-directives/src/components/Title.astro b/packages/astro/test/fixtures/astro-directives/src/components/Title.astro deleted file mode 100644 index b59303ed60619..0000000000000 --- a/packages/astro/test/fixtures/astro-directives/src/components/Title.astro +++ /dev/null @@ -1,10 +0,0 @@ ---- - const textColor = 'red' ---- -<h1 class="title">hello there</h1> - -<style define:vars={{textColor: textColor}}> - .title { - color: var(--textColor); - } -</style> diff --git a/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro b/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro index 3df42aea10cbf..db03705ad19e7 100644 --- a/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro +++ b/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro @@ -1,5 +1,4 @@ --- -import Title from "../components/Title.astro" let foo = 'bar' let bg = 'white' let fg = 'black' @@ -18,7 +17,5 @@ let fg = 'black' <script id="inline" define:vars={{ foo }}> console.log(foo); </script> - - <Title /> </body> </html> From 86635e035b209845b4e1cdf370a4c78451271b70 Mon Sep 17 00:00:00 2001 From: Matthew Phillips <matthew@skypack.dev> Date: Mon, 27 Jun 2022 10:36:41 -0400 Subject: [PATCH 38/58] Inline define:var styles rendered after the head (#3724) * Inline define:var styles rendered after the head * Adds a changeset * Remove tests that don't work with streaming --- .changeset/plenty-kids-own.md | 5 ++++ packages/astro/src/runtime/server/index.ts | 25 ++++++++++++++++++- packages/astro/test/astro-directives.test.js | 13 ++++++++-- .../src/components/Title.astro | 10 ++++++++ .../src/pages/define-vars.astro | 3 +++ .../src/components/OverwriteHeader.astro | 9 ------- .../src/components/SetAHeader.astro | 3 --- .../src/components/SetStatus.astro | 3 --- .../src/pages/child-set-status.astro | 12 --------- .../src/pages/child-tries-to-overwrite.astro | 14 ----------- .../ssr-response/src/pages/some-header.astro | 2 -- packages/astro/test/ssr-response.test.js | 19 -------------- 12 files changed, 53 insertions(+), 65 deletions(-) create mode 100644 .changeset/plenty-kids-own.md create mode 100644 packages/astro/test/fixtures/astro-directives/src/components/Title.astro delete mode 100644 packages/astro/test/fixtures/ssr-response/src/components/OverwriteHeader.astro delete mode 100644 packages/astro/test/fixtures/ssr-response/src/components/SetAHeader.astro delete mode 100644 packages/astro/test/fixtures/ssr-response/src/components/SetStatus.astro delete mode 100644 packages/astro/test/fixtures/ssr-response/src/pages/child-set-status.astro delete mode 100644 packages/astro/test/fixtures/ssr-response/src/pages/child-tries-to-overwrite.astro diff --git a/.changeset/plenty-kids-own.md b/.changeset/plenty-kids-own.md new file mode 100644 index 0000000000000..56ce7ca1382c4 --- /dev/null +++ b/.changeset/plenty-kids-own.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes define:vars w/ styles used inside of components diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index e1ffd69e593b2..7f2844ed22084 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -183,7 +183,26 @@ export async function renderComponent( } if (Component && (Component as any).isAstroComponentFactory) { - return renderToIterable(result, Component as any, _props, slots); + async function * renderAstroComponentInline(): AsyncGenerator<string, void, undefined> { + let iterable = await renderToIterable(result, Component as any, _props, slots); + // If this component added any define:vars styles and the head has already been + // sent out, we need to include those inline. + if(result.styles.size && alreadyHeadRenderedResults.has(result)) { + let styles = Array.from(result.styles); + result.styles.clear(); + for(const style of styles) { + if('define:vars' in style.props) { + // We only want to render the property value and not the full stylesheet + // which is bundled in the head. + style.children = ''; + yield markHTMLString(renderElement('style', style)); + } + } + } + yield * iterable; + } + + return renderAstroComponentInline(); } if (!Component && !_props['client:only']) { @@ -408,6 +427,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr island.children = `${html ?? ''}${template}`; + // Scripts to prepend let prescriptType: PrescriptType = needsHydrationScript ? 'both' : needsDirectiveScript @@ -655,6 +675,7 @@ export async function renderToIterable( const Component = await componentFactory(result, props, children); if (!isAstroComponent(Component)) { + // eslint-disable-next-line no-console console.warn( `Returning a Response is only supported inside of page components. Consider refactoring this logic into something like a function that can be used in the page.` ); @@ -719,6 +740,8 @@ export async function renderHead(result: SSRResult): Promise<string> { const styles = Array.from(result.styles) .filter(uniqueElements) .map((style) => renderElement('style', style)); + // Clear result.styles so that any new styles added will be inlined. + result.styles.clear(); const scripts = Array.from(result.scripts) .filter(uniqueElements) .map((script, i) => { diff --git a/packages/astro/test/astro-directives.test.js b/packages/astro/test/astro-directives.test.js index 161063e973168..0a4bab43b92c1 100644 --- a/packages/astro/test/astro-directives.test.js +++ b/packages/astro/test/astro-directives.test.js @@ -22,7 +22,7 @@ describe('Directives', async () => { const html = await fixture.readFile('/define-vars/index.html'); const $ = cheerio.load(html); - expect($('style')).to.have.lengthOf(1); + expect($('style')).to.have.lengthOf(2); expect($('style').toString()).to.include('--bg: white;'); expect($('style').toString()).to.include('--fg: black;'); @@ -31,9 +31,18 @@ describe('Directives', async () => { .split(' ') .find((name) => /^astro-[A-Za-z0-9-]+/.test(name)); - expect($('style').toString().replace(/\s+/g, '')).to.equal( + expect($($('style').get(0)).toString().replace(/\s+/g, '')).to.equal( `<style>.${scopedClass}{--bg:white;--fg:black;}body{background:var(--bg);color:var(--fg)}</style>` ); + + const scopedTitleClass = $('.title') + .attr('class') + .split(' ') + .find((name) => /^astro-[A-Za-z0-9-]+/.test(name)); + + expect($($('style').get(1)).toString().replace(/\s+/g, '')).to.equal( + `<style>.${scopedTitleClass}{--textColor:red;}</style>` + ); }); it('set:html', async () => { diff --git a/packages/astro/test/fixtures/astro-directives/src/components/Title.astro b/packages/astro/test/fixtures/astro-directives/src/components/Title.astro new file mode 100644 index 0000000000000..b59303ed60619 --- /dev/null +++ b/packages/astro/test/fixtures/astro-directives/src/components/Title.astro @@ -0,0 +1,10 @@ +--- + const textColor = 'red' +--- +<h1 class="title">hello there</h1> + +<style define:vars={{textColor: textColor}}> + .title { + color: var(--textColor); + } +</style> diff --git a/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro b/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro index db03705ad19e7..3df42aea10cbf 100644 --- a/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro +++ b/packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro @@ -1,4 +1,5 @@ --- +import Title from "../components/Title.astro" let foo = 'bar' let bg = 'white' let fg = 'black' @@ -17,5 +18,7 @@ let fg = 'black' <script id="inline" define:vars={{ foo }}> console.log(foo); </script> + + <Title /> </body> </html> diff --git a/packages/astro/test/fixtures/ssr-response/src/components/OverwriteHeader.astro b/packages/astro/test/fixtures/ssr-response/src/components/OverwriteHeader.astro deleted file mode 100644 index e3a99c6c35ab6..0000000000000 --- a/packages/astro/test/fixtures/ssr-response/src/components/OverwriteHeader.astro +++ /dev/null @@ -1,9 +0,0 @@ ---- -let gotError = false; -try { - Astro.response.headers = new Headers(); -} catch(err) { - gotError = true; -} ---- -<div id="overwrite-error">{gotError}</div> diff --git a/packages/astro/test/fixtures/ssr-response/src/components/SetAHeader.astro b/packages/astro/test/fixtures/ssr-response/src/components/SetAHeader.astro deleted file mode 100644 index 4186561f41c66..0000000000000 --- a/packages/astro/test/fixtures/ssr-response/src/components/SetAHeader.astro +++ /dev/null @@ -1,3 +0,0 @@ ---- -Astro.response.headers.set('Seven-Eight', 'nine'); ---- diff --git a/packages/astro/test/fixtures/ssr-response/src/components/SetStatus.astro b/packages/astro/test/fixtures/ssr-response/src/components/SetStatus.astro deleted file mode 100644 index d98f3a8e1d0ae..0000000000000 --- a/packages/astro/test/fixtures/ssr-response/src/components/SetStatus.astro +++ /dev/null @@ -1,3 +0,0 @@ ---- -Astro.response.status = 403; ---- diff --git a/packages/astro/test/fixtures/ssr-response/src/pages/child-set-status.astro b/packages/astro/test/fixtures/ssr-response/src/pages/child-set-status.astro deleted file mode 100644 index 8b66882f13f64..0000000000000 --- a/packages/astro/test/fixtures/ssr-response/src/pages/child-set-status.astro +++ /dev/null @@ -1,12 +0,0 @@ ---- -import SetStatus from '../components/SetStatus.astro'; ---- -<html> - <head> - <title>Testing - - -

    Testing

    - - - diff --git a/packages/astro/test/fixtures/ssr-response/src/pages/child-tries-to-overwrite.astro b/packages/astro/test/fixtures/ssr-response/src/pages/child-tries-to-overwrite.astro deleted file mode 100644 index 35a207de77e2a..0000000000000 --- a/packages/astro/test/fixtures/ssr-response/src/pages/child-tries-to-overwrite.astro +++ /dev/null @@ -1,14 +0,0 @@ ---- -import SetAHeader from '../components/SetAHeader.astro'; -import OverwriteHeader from '../components/OverwriteHeader.astro'; ---- - - - Testing - - -

    Testing

    - - - - diff --git a/packages/astro/test/fixtures/ssr-response/src/pages/some-header.astro b/packages/astro/test/fixtures/ssr-response/src/pages/some-header.astro index f2840ff94f119..ea62dfd54876b 100644 --- a/packages/astro/test/fixtures/ssr-response/src/pages/some-header.astro +++ b/packages/astro/test/fixtures/ssr-response/src/pages/some-header.astro @@ -1,5 +1,4 @@ --- -import SetAHeader from '../components/SetAHeader.astro'; Astro.response.headers.set('One-Two', 'three'); Astro.response.headers.set('Four-Five', 'six'); --- @@ -9,6 +8,5 @@ Astro.response.headers.set('Four-Five', 'six');

    Testing

    - diff --git a/packages/astro/test/ssr-response.test.js b/packages/astro/test/ssr-response.test.js index 1b517d9eeea86..ffabcbba4a340 100644 --- a/packages/astro/test/ssr-response.test.js +++ b/packages/astro/test/ssr-response.test.js @@ -32,13 +32,6 @@ describe('Using Astro.response in SSR', () => { expect(response.statusText).to.equal('Oops'); }); - it('Child component can set status', async () => { - const app = await fixture.loadTestAdapterApp(); - const request = new Request('http://example.com/child-set-status'); - const response = await app.render(request); - expect(response.status).to.equal(403); - }); - it('Can add headers', async () => { const app = await fixture.loadTestAdapterApp(); const request = new Request('http://example.com/some-header'); @@ -46,17 +39,5 @@ describe('Using Astro.response in SSR', () => { const headers = response.headers; expect(headers.get('one-two')).to.equal('three'); expect(headers.get('four-five')).to.equal('six'); - expect(headers.get('seven-eight')).to.equal('nine'); - }); - - it('Child component cannot override headers object', async () => { - const app = await fixture.loadTestAdapterApp(); - const request = new Request('http://example.com/child-tries-to-overwrite'); - const response = await app.render(request); - const headers = response.headers; - expect(headers.get('seven-eight')).to.equal('nine'); - const html = await response.text(); - const $ = cheerioLoad(html); - expect($('#overwrite-error').html()).to.equal('true'); }); }); From ab3aa3099b30bd6ee20120e188c252e30bbaaf38 Mon Sep 17 00:00:00 2001 From: matthewp Date: Mon, 27 Jun 2022 14:38:25 +0000 Subject: [PATCH 39/58] [ci] format --- packages/astro/src/runtime/server/index.ts | 10 +++++----- packages/astro/test/astro-directives.test.js | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 7f2844ed22084..8df0440c48bb6 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -183,15 +183,15 @@ export async function renderComponent( } if (Component && (Component as any).isAstroComponentFactory) { - async function * renderAstroComponentInline(): AsyncGenerator { + async function* renderAstroComponentInline(): AsyncGenerator { let iterable = await renderToIterable(result, Component as any, _props, slots); // If this component added any define:vars styles and the head has already been // sent out, we need to include those inline. - if(result.styles.size && alreadyHeadRenderedResults.has(result)) { + if (result.styles.size && alreadyHeadRenderedResults.has(result)) { let styles = Array.from(result.styles); result.styles.clear(); - for(const style of styles) { - if('define:vars' in style.props) { + for (const style of styles) { + if ('define:vars' in style.props) { // We only want to render the property value and not the full stylesheet // which is bundled in the head. style.children = ''; @@ -199,7 +199,7 @@ export async function renderComponent( } } } - yield * iterable; + yield* iterable; } return renderAstroComponentInline(); diff --git a/packages/astro/test/astro-directives.test.js b/packages/astro/test/astro-directives.test.js index 0a4bab43b92c1..8bdccb90b9f54 100644 --- a/packages/astro/test/astro-directives.test.js +++ b/packages/astro/test/astro-directives.test.js @@ -36,9 +36,9 @@ describe('Directives', async () => { ); const scopedTitleClass = $('.title') - .attr('class') - .split(' ') - .find((name) => /^astro-[A-Za-z0-9-]+/.test(name)); + .attr('class') + .split(' ') + .find((name) => /^astro-[A-Za-z0-9-]+/.test(name)); expect($($('style').get(1)).toString().replace(/\s+/g, '')).to.equal( `` From 0ae1365533909b403eddcf77b47895c8e3f5dfb2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 27 Jun 2022 10:40:35 -0400 Subject: [PATCH 40/58] [ci] release (#3726) Co-authored-by: github-actions[bot] --- .changeset/plenty-kids-own.md | 5 -- examples/basics/package.json | 2 +- examples/blog-multiple-authors/package.json | 2 +- examples/blog/package.json | 2 +- examples/component/demo/package.json | 2 +- examples/component/package.json | 2 +- examples/docs/package.json | 2 +- examples/env-vars/package.json | 2 +- examples/framework-alpine/package.json | 2 +- examples/framework-lit/package.json | 2 +- examples/framework-multiple/package.json | 2 +- examples/framework-preact/package.json | 2 +- examples/framework-react/package.json | 2 +- examples/framework-solid/package.json | 2 +- examples/framework-svelte/package.json | 2 +- examples/framework-vue/package.json | 2 +- examples/integrations-playground/package.json | 2 +- examples/minimal/package.json | 2 +- examples/non-html-pages/package.json | 2 +- examples/portfolio/package.json | 2 +- examples/ssr/package.json | 2 +- examples/starter/package.json | 2 +- examples/subpath/package.json | 2 +- examples/with-markdown-plugins/package.json | 2 +- examples/with-markdown-shiki/package.json | 2 +- examples/with-markdown/package.json | 2 +- examples/with-nanostores/package.json | 2 +- examples/with-tailwindcss/package.json | 2 +- examples/with-vite-plugin-pwa/package.json | 2 +- packages/astro/CHANGELOG.md | 6 ++ packages/astro/package.json | 2 +- pnpm-lock.yaml | 65 ++++++++----------- 32 files changed, 63 insertions(+), 71 deletions(-) delete mode 100644 .changeset/plenty-kids-own.md diff --git a/.changeset/plenty-kids-own.md b/.changeset/plenty-kids-own.md deleted file mode 100644 index 56ce7ca1382c4..0000000000000 --- a/.changeset/plenty-kids-own.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Fixes define:vars w/ styles used inside of components diff --git a/examples/basics/package.json b/examples/basics/package.json index 0a2cc3108766e..a0295bc6e7235 100644 --- a/examples/basics/package.json +++ b/examples/basics/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/blog-multiple-authors/package.json b/examples/blog-multiple-authors/package.json index 53c39005176b4..426dc59d2a7e7 100644 --- a/examples/blog-multiple-authors/package.json +++ b/examples/blog-multiple-authors/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.56", + "astro": "^1.0.0-beta.57", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/blog/package.json b/examples/blog/package.json index 1d7766d26e28f..7994b7b2062f1 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/component/demo/package.json b/examples/component/demo/package.json index ee80098050268..1fae61292f4a6 100644 --- a/examples/component/demo/package.json +++ b/examples/component/demo/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@example/my-component": "workspace:*", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/component/package.json b/examples/component/package.json index b43bf97570f58..23460b1333d81 100644 --- a/examples/component/package.json +++ b/examples/component/package.json @@ -8,6 +8,6 @@ "serve": "astro --root demo preview" }, "devDependencies": { - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/docs/package.json b/examples/docs/package.json index a271c57d32b42..281c374baf5a0 100644 --- a/examples/docs/package.json +++ b/examples/docs/package.json @@ -20,6 +20,6 @@ "devDependencies": { "@astrojs/preact": "^0.2.0", "@astrojs/react": "^0.2.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/env-vars/package.json b/examples/env-vars/package.json index 6de1fc5d22a88..34194f025365a 100644 --- a/examples/env-vars/package.json +++ b/examples/env-vars/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/framework-alpine/package.json b/examples/framework-alpine/package.json index 2f2276407f460..9ff43bb8d4c93 100644 --- a/examples/framework-alpine/package.json +++ b/examples/framework-alpine/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "alpinejs": "^3.10.2" diff --git a/examples/framework-lit/package.json b/examples/framework-lit/package.json index 1887ffa30838b..b9f5085eaedc4 100644 --- a/examples/framework-lit/package.json +++ b/examples/framework-lit/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/lit": "^0.3.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index d5d9011a8687f..9e5265dd76b8d 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -15,7 +15,7 @@ "@astrojs/solid-js": "^0.2.0", "@astrojs/svelte": "^0.2.0", "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "@webcomponents/template-shadowroot": "^0.1.0", diff --git a/examples/framework-preact/package.json b/examples/framework-preact/package.json index 643bc3c68e6b5..e4e7f84b6dea8 100644 --- a/examples/framework-preact/package.json +++ b/examples/framework-preact/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "preact": "^10.7.3" diff --git a/examples/framework-react/package.json b/examples/framework-react/package.json index aede2e7f5e260..c951c35239d3c 100644 --- a/examples/framework-react/package.json +++ b/examples/framework-react/package.json @@ -12,7 +12,7 @@ "@astrojs/react": "^0.2.0", "@types/react": "^18.0.10", "@types/react-dom": "^18.0.5", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "react": "^18.1.0", diff --git a/examples/framework-solid/package.json b/examples/framework-solid/package.json index 2a94d4395d3d8..ac9e4919bede4 100644 --- a/examples/framework-solid/package.json +++ b/examples/framework-solid/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/solid-js": "^0.2.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "solid-js": "^1.4.3" diff --git a/examples/framework-svelte/package.json b/examples/framework-svelte/package.json index 8cc81ea1d1d23..0502ee30c10e3 100644 --- a/examples/framework-svelte/package.json +++ b/examples/framework-svelte/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/svelte": "^0.2.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "svelte": "^3.48.0" diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index 654e4d7b6d85d..e4adf3c8c310a 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "vue": "^3.2.36" diff --git a/examples/integrations-playground/package.json b/examples/integrations-playground/package.json index 172830d88f3f5..4a5a8b9fa9a1b 100644 --- a/examples/integrations-playground/package.json +++ b/examples/integrations-playground/package.json @@ -16,7 +16,7 @@ "@astrojs/solid-js": "0.2.0", "@astrojs/tailwind": "^0.2.1", "@astrojs/turbolinks": "^0.1.3", - "astro": "^1.0.0-beta.56", + "astro": "^1.0.0-beta.57", "solid-js": "^1.4.3" }, "dependencies": { diff --git a/examples/minimal/package.json b/examples/minimal/package.json index 8a2fb24edfba4..6bec9c0acb438 100644 --- a/examples/minimal/package.json +++ b/examples/minimal/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/non-html-pages/package.json b/examples/non-html-pages/package.json index de71eed416379..d3a51e119c458 100644 --- a/examples/non-html-pages/package.json +++ b/examples/non-html-pages/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/portfolio/package.json b/examples/portfolio/package.json index f056fb3726265..5376afc7a9381 100644 --- a/examples/portfolio/package.json +++ b/examples/portfolio/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/preact": "^0.2.0", - "astro": "^1.0.0-beta.56", + "astro": "^1.0.0-beta.57", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/ssr/package.json b/examples/ssr/package.json index 10f42adf0239a..3814829dbc68a 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -11,7 +11,7 @@ "devDependencies": { "@astrojs/node": "^0.1.2", "@astrojs/svelte": "^0.2.0", - "astro": "^1.0.0-beta.56", + "astro": "^1.0.0-beta.57", "concurrently": "^7.2.1", "lightcookie": "^1.0.25", "unocss": "^0.15.6", diff --git a/examples/starter/package.json b/examples/starter/package.json index caf5f377b7a19..8ea6703c0cc8a 100644 --- a/examples/starter/package.json +++ b/examples/starter/package.json @@ -9,6 +9,6 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/subpath/package.json b/examples/subpath/package.json index 62724ef2d9087..277662639cbfe 100644 --- a/examples/subpath/package.json +++ b/examples/subpath/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/react": "^0.2.0", - "astro": "^1.0.0-beta.56", + "astro": "^1.0.0-beta.57", "sass": "^1.52.2" }, "dependencies": { diff --git a/examples/with-markdown-plugins/package.json b/examples/with-markdown-plugins/package.json index aaa4334759a77..063a572c71ccb 100644 --- a/examples/with-markdown-plugins/package.json +++ b/examples/with-markdown-plugins/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.56", + "astro": "^1.0.0-beta.57", "hast-util-select": "5.0.1", "rehype-autolink-headings": "^6.1.1", "rehype-slug": "^5.0.1", diff --git a/examples/with-markdown-shiki/package.json b/examples/with-markdown-shiki/package.json index cb214e25233b6..1e9ad49026a97 100644 --- a/examples/with-markdown-shiki/package.json +++ b/examples/with-markdown-shiki/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@astrojs/markdown-remark": "^0.11.3", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/with-markdown/package.json b/examples/with-markdown/package.json index 0f1fddfbff218..6e749e548d49a 100644 --- a/examples/with-markdown/package.json +++ b/examples/with-markdown/package.json @@ -14,7 +14,7 @@ "@astrojs/react": "^0.2.0", "@astrojs/svelte": "^0.2.0", "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" }, "dependencies": { "preact": "^10.7.3", diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index 5141c4e5abf39..773149fc859cd 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -25,6 +25,6 @@ "@astrojs/solid-js": "^0.2.0", "@astrojs/svelte": "^0.2.0", "@astrojs/vue": "^0.2.0", - "astro": "^1.0.0-beta.56" + "astro": "^1.0.0-beta.57" } } diff --git a/examples/with-tailwindcss/package.json b/examples/with-tailwindcss/package.json index 54ed31a2c081c..a3d089a7b6a2b 100644 --- a/examples/with-tailwindcss/package.json +++ b/examples/with-tailwindcss/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "@astrojs/tailwind": "^0.2.1", - "astro": "^1.0.0-beta.56", + "astro": "^1.0.0-beta.57", "autoprefixer": "^10.4.7", "canvas-confetti": "^1.5.1", "postcss": "^8.4.14", diff --git a/examples/with-vite-plugin-pwa/package.json b/examples/with-vite-plugin-pwa/package.json index b642b2d1fe5e5..eba6235e534cf 100644 --- a/examples/with-vite-plugin-pwa/package.json +++ b/examples/with-vite-plugin-pwa/package.json @@ -9,7 +9,7 @@ "preview": "astro preview" }, "devDependencies": { - "astro": "^1.0.0-beta.56", + "astro": "^1.0.0-beta.57", "vite-plugin-pwa": "0.11.11", "workbox-window": "^6.5.3" } diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index 8ff78be21be3a..6ac87893464a4 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -1,5 +1,11 @@ # astro +## 1.0.0-beta.57 + +### Patch Changes + +- [#3724](https://github.com/withastro/astro/pull/3724) [`86635e03`](https://github.com/withastro/astro/commit/86635e035b209845b4e1cdf370a4c78451271b70) Thanks [@matthewp](https://github.com/matthewp)! - Fixes define:vars w/ styles used inside of components + ## 1.0.0-beta.56 ### Patch Changes diff --git a/packages/astro/package.json b/packages/astro/package.json index 1a35c6bb78298..2c61ba25bfabd 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -1,6 +1,6 @@ { "name": "astro", - "version": "1.0.0-beta.56", + "version": "1.0.0-beta.57", "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.", "type": "module", "author": "withastro", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d17f780d01fab..66dc6fd881c3e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,14 +49,14 @@ importers: examples/basics: specifiers: - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 devDependencies: astro: link:../../packages/astro examples/blog: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -67,7 +67,7 @@ importers: examples/blog-multiple-authors: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -79,14 +79,14 @@ importers: examples/component: specifiers: - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 devDependencies: astro: link:../../packages/astro examples/component/demo: specifiers: '@example/my-component': workspace:* - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 devDependencies: '@example/my-component': link:../packages/my-component astro: link:../../../packages/astro @@ -102,7 +102,7 @@ importers: '@docsearch/css': ^3.1.0 '@docsearch/react': ^3.1.0 '@types/react': ^17.0.45 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -121,14 +121,14 @@ importers: examples/env-vars: specifiers: - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 devDependencies: astro: link:../../packages/astro examples/framework-alpine: specifiers: alpinejs: ^3.10.2 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 dependencies: alpinejs: 3.10.2 devDependencies: @@ -138,7 +138,7 @@ importers: specifiers: '@astrojs/lit': ^0.3.0 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 lit: ^2.2.5 dependencies: '@webcomponents/template-shadowroot': 0.1.0 @@ -156,7 +156,7 @@ importers: '@astrojs/svelte': ^0.2.0 '@astrojs/vue': ^0.2.0 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -185,7 +185,7 @@ importers: examples/framework-preact: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 preact: ^10.7.3 dependencies: preact: 10.7.3 @@ -198,7 +198,7 @@ importers: '@astrojs/react': ^0.2.0 '@types/react': ^18.0.10 '@types/react-dom': ^18.0.5 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 react: ^18.1.0 react-dom: ^18.1.0 dependencies: @@ -213,7 +213,7 @@ importers: examples/framework-solid: specifiers: '@astrojs/solid-js': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 solid-js: ^1.4.3 dependencies: solid-js: 1.4.3 @@ -224,7 +224,7 @@ importers: examples/framework-svelte: specifiers: '@astrojs/svelte': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 svelte: ^3.48.0 dependencies: svelte: 3.48.0 @@ -235,7 +235,7 @@ importers: examples/framework-vue: specifiers: '@astrojs/vue': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 vue: ^3.2.36 dependencies: vue: 3.2.37 @@ -253,7 +253,7 @@ importers: '@astrojs/tailwind': ^0.2.1 '@astrojs/turbolinks': ^0.1.3 '@webcomponents/template-shadowroot': ^0.1.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 lit: ^2.2.5 preact: ^10.7.3 react: ^18.1.0 @@ -282,20 +282,20 @@ importers: examples/minimal: specifiers: - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 devDependencies: astro: link:../../packages/astro examples/non-html-pages: specifiers: - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 devDependencies: astro: link:../../packages/astro examples/portfolio: specifiers: '@astrojs/preact': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 preact: ^10.7.3 sass: ^1.52.2 dependencies: @@ -309,7 +309,7 @@ importers: specifiers: '@astrojs/node': ^0.1.2 '@astrojs/svelte': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 concurrently: ^7.2.1 lightcookie: ^1.0.25 svelte: ^3.48.0 @@ -328,14 +328,14 @@ importers: examples/starter: specifiers: - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 devDependencies: astro: link:../../packages/astro examples/subpath: specifiers: '@astrojs/react': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 react: ^18.1.0 react-dom: ^18.1.0 sass: ^1.52.2 @@ -354,7 +354,7 @@ importers: '@astrojs/react': ^0.2.0 '@astrojs/svelte': ^0.2.0 '@astrojs/vue': ^0.2.0 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 preact: ^10.7.3 react: ^18.1.0 react-dom: ^18.1.0 @@ -377,7 +377,7 @@ importers: examples/with-markdown-plugins: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 hast-util-select: 5.0.1 rehype-autolink-headings: ^6.1.1 rehype-slug: ^5.0.1 @@ -395,7 +395,7 @@ importers: examples/with-markdown-shiki: specifiers: '@astrojs/markdown-remark': ^0.11.3 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 devDependencies: '@astrojs/markdown-remark': link:../../packages/markdown/remark astro: link:../../packages/astro @@ -410,7 +410,7 @@ importers: '@nanostores/preact': ^0.1.3 '@nanostores/react': ^0.1.5 '@nanostores/vue': ^0.4.1 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 nanostores: ^0.5.12 preact: ^10.7.3 react: ^18.1.0 @@ -438,7 +438,7 @@ importers: examples/with-tailwindcss: specifiers: '@astrojs/tailwind': ^0.2.1 - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 autoprefixer: ^10.4.7 canvas-confetti: ^1.5.1 postcss: ^8.4.14 @@ -453,7 +453,7 @@ importers: examples/with-vite-plugin-pwa: specifiers: - astro: ^1.0.0-beta.56 + astro: ^1.0.0-beta.57 vite-plugin-pwa: 0.11.11 workbox-window: ^6.5.3 devDependencies: @@ -8554,11 +8554,6 @@ packages: /debug/3.2.7: resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true dependencies: ms: 2.1.3 dev: false @@ -11440,8 +11435,6 @@ packages: debug: 3.2.7 iconv-lite: 0.4.24 sax: 1.2.4 - transitivePeerDependencies: - - supports-color dev: false /netmask/2.0.2: @@ -11525,8 +11518,6 @@ packages: rimraf: 2.7.1 semver: 5.7.1 tar: 4.4.19 - transitivePeerDependencies: - - supports-color dev: false /node-releases/2.0.5: From 52f75369efe5a0a1b320478984c90b6727d52159 Mon Sep 17 00:00:00 2001 From: Oleksii Tymoshenko Date: Mon, 27 Jun 2022 21:02:00 +0300 Subject: [PATCH 41/58] =?UTF-8?q?feat:=20better=20behavior=20for=20'undefi?= =?UTF-8?q?ned'=20return=20values=20from=20'serialize=E2=80=A6=20(#3723)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: better behavior with 'undefined' return values after 'serialize' func * build: changeset added --- .changeset/tidy-dots-own.md | 5 +++++ packages/integrations/sitemap/README.md | 7 ++++++- packages/integrations/sitemap/src/index.ts | 10 ++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 .changeset/tidy-dots-own.md diff --git a/.changeset/tidy-dots-own.md b/.changeset/tidy-dots-own.md new file mode 100644 index 0000000000000..a9367dc2ab484 --- /dev/null +++ b/.changeset/tidy-dots-own.md @@ -0,0 +1,5 @@ +--- +'@astrojs/sitemap': patch +--- + +fix: if `serialize` function returns `undefined` for the passed entry, such entry will be excluded from sitemap diff --git a/packages/integrations/sitemap/README.md b/packages/integrations/sitemap/README.md index a2e7b73d9ad60..e37a1ed86bb37 100644 --- a/packages/integrations/sitemap/README.md +++ b/packages/integrations/sitemap/README.md @@ -222,7 +222,9 @@ The `LinkItem` type has two required fields: `url` (the fully-qualified URL for The `serialize` function should return `SitemapItem`, touched or not. -The example below shows the ability to add the sitemap specific properties individually. +To exclude the passed entry from sitemap it should return `undefined`. + +The example below shows the ability to exclude certain entries and add the sitemap specific properties individually. __astro.config.mjs__ @@ -234,6 +236,9 @@ export default { integrations: [ sitemap({ serialize(item) { + if (/exclude-from-sitemap/.test(item.url)) { + return undefined; + } if (/your-special-page/.test(item.url)) { item.changefreq = 'daily'; item.lastmod = new Date(); diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 2e1fa5a6ef5aa..67990b041ea75 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -38,7 +38,7 @@ export type SitemapOptions = priority?: number; // called for each sitemap item just before to save them on disk, sync or async - serialize?(item: SitemapItem): SitemapItem | Promise; + serialize?(item: SitemapItem): SitemapItem | Promise | undefined; } | undefined; @@ -117,8 +117,14 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { const serializedUrls: SitemapItem[] = []; for (const item of urlData) { const serialized = await Promise.resolve(serialize(item)); - serializedUrls.push(serialized); + if (serialized) { + serializedUrls.push(serialized); + } } + if (serializedUrls.length === 0) { + logger.warn('No pages found!'); + return; + } urlData = serializedUrls; } catch (err) { logger.error(`Error serializing pages\n${(err as any).toString()}`); From 35da5bd93ea28c17748934a5e269f6f45b31fc99 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 27 Jun 2022 11:02:44 -0700 Subject: [PATCH 42/58] add fredkbot for push access (#3730) --- .github/workflows/ci.yml | 6 +++--- .github/workflows/format.yml | 2 ++ .github/workflows/nightly.yml | 9 +++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df472da10447e..5e316ca1ccfbd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -245,8 +245,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Setup PNPM uses: pnpm/action-setup@v2.2.1 @@ -276,7 +274,9 @@ jobs: commit: '[ci] release' title: '[ci] release' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Needs access to push to main + GITHUB_TOKEN: ${{ secrets.FREDKBOT_GITHUB_TOKEN }} + # Needs access to publish to npm NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Generate Notification diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 4431c1675ea75..a58fef95d8d68 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -29,3 +29,5 @@ jobs: with: commit_message: '[ci] format' branch: ${{ github.head_ref }} + # Needs access to push to main + token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }} diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 251f5517e58b8..310adb343d0ab 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -29,12 +29,16 @@ jobs: - name: Collect stats run: node scripts/stats/index.js env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Needs access to collect stats from the GitHub API + GITHUB_TOKEN: ${{ secrets.FREDKBOT_GITHUB_TOKEN }} + - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: '[ci] collect stats' branch: ${{ github.head_ref }} + # Needs access to push to main + token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }} lockfile: if: github.repository_owner == 'withastro' @@ -61,7 +65,8 @@ jobs: uses: peter-evans/create-pull-request@v3 with: branch: ci/lockfile - token: ${{ secrets.NIGHTLY_PERSONAL_GITHUB_TOKEN }} + # Access token is needed to trigger CI on this PR + token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }} commit-message: '[ci] update lockfile' title: '[ci] update lockfile' body: > From dee7d6296231b8487f5cc1076f163d6ec8f6b19d Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 27 Jun 2022 11:11:19 -0700 Subject: [PATCH 43/58] Update format.yml --- .github/workflows/format.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index a58fef95d8d68..852982c218b4f 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -13,6 +13,8 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ github.head_ref }} + # Needs access to push to main + token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }} - name: Setup PNPM uses: pnpm/action-setup@v2.2.1 - name: Setup Node @@ -29,5 +31,3 @@ jobs: with: commit_message: '[ci] format' branch: ${{ github.head_ref }} - # Needs access to push to main - token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }} From 7d0c3f9ecbf54b2ea118b7dff5fa01d57e5e2851 Mon Sep 17 00:00:00 2001 From: FredKSchott Date: Mon, 27 Jun 2022 18:12:43 +0000 Subject: [PATCH 44/58] [ci] format --- packages/integrations/sitemap/src/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 67990b041ea75..6c661905f8fa1 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -117,14 +117,14 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { const serializedUrls: SitemapItem[] = []; for (const item of urlData) { const serialized = await Promise.resolve(serialize(item)); - if (serialized) { - serializedUrls.push(serialized); - } + if (serialized) { + serializedUrls.push(serialized); + } + } + if (serializedUrls.length === 0) { + logger.warn('No pages found!'); + return; } - if (serializedUrls.length === 0) { - logger.warn('No pages found!'); - return; - } urlData = serializedUrls; } catch (err) { logger.error(`Error serializing pages\n${(err as any).toString()}`); From 9d78162fd9cab9eb2a64f58ca5703ba5d658828f Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 27 Jun 2022 11:24:22 -0700 Subject: [PATCH 45/58] Prettier update with caching speedup (#3710) * update lockfile on fresh install * update prettier --- package.json | 4 ++-- pnpm-lock.yaml | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index fa8f13392a080..342b882ebc810 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "dev": "turbo run dev --no-deps --no-cache --parallel --scope=astro --scope=create-astro --scope=\"@astrojs/*\"", "format": "pnpm run format:code", "format:ci": "pnpm run format:imports && pnpm run format:code", - "format:code": "prettier -w .", + "format:code": "prettier -w . --cache", "format:imports": "organize-imports-cli ./packages/*/tsconfig.json ./packages/*/*/tsconfig.json", "test": "turbo run test --concurrency=1", "test:match": "cd packages/astro && pnpm run test:match", @@ -74,7 +74,7 @@ "execa": "^6.1.0", "organize-imports-cli": "^0.10.0", "patch-package": "^6.4.7", - "prettier": "^2.6.2", + "prettier": "^2.7.0", "pretty-bytes": "^6.0.0", "tiny-glob": "^0.2.9", "turbo": "1.2.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 66dc6fd881c3e..6955953306bb7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,7 +19,7 @@ importers: execa: ^6.1.0 organize-imports-cli: ^0.10.0 patch-package: ^6.4.7 - prettier: ^2.6.2 + prettier: ^2.7.0 pretty-bytes: ^6.0.0 tiny-glob: ^0.2.9 turbo: 1.2.5 @@ -37,11 +37,11 @@ importers: eslint: 8.17.0 eslint-config-prettier: 8.5.0_eslint@8.17.0 eslint-plugin-no-only-tests: 2.6.0 - eslint-plugin-prettier: 4.0.0_ucegkljdju7q4zmvwxzqoprf3y + eslint-plugin-prettier: 4.0.0_hsbo72uvra2cjko46y2c4fgzzm execa: 6.1.0 organize-imports-cli: 0.10.0 patch-package: 6.4.7 - prettier: 2.6.2 + prettier: 2.7.1 pretty-bytes: 6.0.0 tiny-glob: 0.2.9 turbo: 1.2.5 @@ -8554,6 +8554,11 @@ packages: /debug/3.2.7: resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true dependencies: ms: 2.1.3 dev: false @@ -9163,7 +9168,7 @@ packages: engines: {node: '>=4.0.0'} dev: true - /eslint-plugin-prettier/4.0.0_ucegkljdju7q4zmvwxzqoprf3y: + /eslint-plugin-prettier/4.0.0_hsbo72uvra2cjko46y2c4fgzzm: resolution: {integrity: sha512-98MqmCJ7vJodoQK359bqQWaxOE0CS8paAz/GgjaZLyex4TTk3g9HugoO89EqWCrFiOqn9EVvcoo7gZzONCWVwQ==} engines: {node: '>=6.0.0'} peerDependencies: @@ -9176,7 +9181,7 @@ packages: dependencies: eslint: 8.17.0 eslint-config-prettier: 8.5.0_eslint@8.17.0 - prettier: 2.6.2 + prettier: 2.7.1 prettier-linter-helpers: 1.0.0 dev: true @@ -11435,6 +11440,8 @@ packages: debug: 3.2.7 iconv-lite: 0.4.24 sax: 1.2.4 + transitivePeerDependencies: + - supports-color dev: false /netmask/2.0.2: @@ -11518,6 +11525,8 @@ packages: rimraf: 2.7.1 semver: 5.7.1 tar: 4.4.19 + transitivePeerDependencies: + - supports-color dev: false /node-releases/2.0.5: @@ -12446,8 +12455,8 @@ packages: hasBin: true dev: true - /prettier/2.6.2: - resolution: {integrity: sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==} + /prettier/2.7.1: + resolution: {integrity: sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==} engines: {node: '>=10.13.0'} hasBin: true dev: true From 79fe09fa3093eb8ac2871c1894b9cddf557aecba Mon Sep 17 00:00:00 2001 From: Tony Sullivan Date: Mon, 27 Jun 2022 18:26:21 +0000 Subject: [PATCH 46/58] Adds a prefetch integration for near-instant page navigations (#3725) * Adds a basic @astrojs/prefetch integration * adding tests for custom selectors * missed in last commit * Adding a few docs, removing the option for `selectors` to be an element array * adding an option for the concurrency limit * fixing test for updated integration options * Update packages/labs/prefetch/src/client.ts Co-authored-by: Nate Moore * nit: removing the NodeJS.Timer type to allow typescript to infer the return * updating docs for default selector with ~= * Skip prefetching on 2G connections, or when data saver is enabled * refactor: moving to packages/integrations, Astro Labs TBD down the road * README typo fix Co-authored-by: Nate Moore --- .../prefetch/@types/network-information.d.ts | 15 +++ packages/integrations/prefetch/README.md | 127 ++++++++++++++++++ packages/integrations/prefetch/package.json | 39 ++++++ .../prefetch/playwright.config.js | 41 ++++++ packages/integrations/prefetch/src/client.ts | 109 +++++++++++++++ packages/integrations/prefetch/src/index.ts | 17 +++ .../prefetch/src/requestIdleCallback.ts | 16 +++ .../prefetch/test/basic-prefetch.test.js | 64 +++++++++ .../prefetch/test/custom-selectors.test.js | 72 ++++++++++ .../fixtures/basic-prefetch/astro.config.mjs | 7 + .../test/fixtures/basic-prefetch/package.json | 9 ++ .../basic-prefetch/src/pages/about.astro | 11 ++ .../basic-prefetch/src/pages/admin.astro | 11 ++ .../basic-prefetch/src/pages/contact.astro | 11 ++ .../basic-prefetch/src/pages/index.astro | 26 ++++ .../integrations/prefetch/test/test-utils.js | 31 +++++ packages/integrations/prefetch/tsconfig.json | 10 ++ pnpm-lock.yaml | 43 +++++- 18 files changed, 658 insertions(+), 1 deletion(-) create mode 100644 packages/integrations/prefetch/@types/network-information.d.ts create mode 100644 packages/integrations/prefetch/README.md create mode 100644 packages/integrations/prefetch/package.json create mode 100644 packages/integrations/prefetch/playwright.config.js create mode 100644 packages/integrations/prefetch/src/client.ts create mode 100644 packages/integrations/prefetch/src/index.ts create mode 100644 packages/integrations/prefetch/src/requestIdleCallback.ts create mode 100644 packages/integrations/prefetch/test/basic-prefetch.test.js create mode 100644 packages/integrations/prefetch/test/custom-selectors.test.js create mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/astro.config.mjs create mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/package.json create mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/about.astro create mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/admin.astro create mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/contact.astro create mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/index.astro create mode 100644 packages/integrations/prefetch/test/test-utils.js create mode 100644 packages/integrations/prefetch/tsconfig.json diff --git a/packages/integrations/prefetch/@types/network-information.d.ts b/packages/integrations/prefetch/@types/network-information.d.ts new file mode 100644 index 0000000000000..8932e1f1ac0c9 --- /dev/null +++ b/packages/integrations/prefetch/@types/network-information.d.ts @@ -0,0 +1,15 @@ +export { }; + +declare global { + interface NetworkInformation { + // http://wicg.github.io/netinfo/#effectiveconnectiontype-enum + readonly effectiveType: '2g' | '3g' | '4g' | 'slow-2g'; + // http://wicg.github.io/netinfo/#savedata-attribute + readonly saveData?: boolean; + } + + var NetworkInformation: { + prototype: NetworkInformation; + new(): NetworkInformation; + }; +} diff --git a/packages/integrations/prefetch/README.md b/packages/integrations/prefetch/README.md new file mode 100644 index 0000000000000..c7a50b9566f9d --- /dev/null +++ b/packages/integrations/prefetch/README.md @@ -0,0 +1,127 @@ +# @astrojs/prefetch 🔗 + +- [Why Prefetch?](#why-prefetch) +- [Installation](#installation) +- [Usage](#usage) +- [Configuration](#configuration) +- [Examples](#examples) +- [Troubleshooting](#troubleshooting) +- [Contributing](#contributing) +- [Changelog](#changelog) + +## Why Prefetch? + +Page load times play a big role in usability and overall enjoyment of a site. This integration brings the benefits of near-instant page navigations to your multi-page application (MPA) by prefetching page links when they are visible on screen. + +To further improve the experience, especially on similar pages, stylesheets are also prefetched along with the HTML. This is particularly useful when navigating between tabs on a static site, where most of the page's content and styles don't change. + +## Installation + +
    + Quick Install +
    + +The experimental `astro add` command-line tool automates the installation for you. Run one of the following commands in a new terminal window. (If you aren't sure which package manager you're using, run the first command.) Then, follow the prompts, and type "y" in the terminal (meaning "yes") for each one. + + ```sh + # Using NPM + npx astro add prefetch + # Using Yarn + yarn astro add prefetch + # Using PNPM + pnpx astro add prefetch + ``` + +Then, restart the dev server by typing `CTRL-C` and then `npm run astro dev` in the terminal window that was running Astro. + +Because this command is new, it might not properly set things up. If that happens, [feel free to log an issue on our GitHub](https://github.com/withastro/astro/issues) and try the manual installation steps below. +
    + +
    + Manual Install + +
    + +First, install the `@astrojs/prefetch` package using your package manager. If you're using npm or aren't sure, run this in the terminal: +```sh +npm install @astrojs/prefetch +``` +Then, apply this integration to your `astro.config.*` file using the `integrations` property: + +__astro.config.mjs__ + +```js +import prefetch from '@astrojs/prefetch'; + +export default { + // ... + integrations: [prefetch()], +} +``` + +Then, restart the dev server. +
    + +## Usage + +When you install the integration, the prefetch script is automatically added to every page in the project. Just add `rel="prefetch"` to any `` links on your page and you're ready to go! + +## Configuration + +The Astro Prefetch integration handles which links on the site are prefetched and it has its own options. Change these in the `astro.config.mjs` file which is where your project's integration settings live. + +
    + config.selector + +
    + +By default the prefetch script searches the page for any links that include a `rel="prefetch"` attribute, ex: `
    ` or ``. This behavior can be changed in your `astro.config.*` file to use a custom query selector when finding prefetch links. + +
    + +```js +import prefetch from '@astrojs/prefetch'; + +export default { + // ... + integrations: [prefetch({ + // Only prefetch links with an href that begins with `/products` + selector: "a[href^='/products']" + })], +} +``` +
    + +
    + config.throttle + +
    + +By default the prefetch script will only prefetch one link at a time. This behavior can be changed in your `astro.config.*` file to increase the limit for concurrent downloads. + +
    + +```js +import prefetch from '@astrojs/prefetch'; + +export default { + // ... + integrations: [prefetch({ + // Allow up to three links to be prefetched concurrently + throttle: 3 + })], +} +``` +
    + +## Examples + +> Coming soon! + +## Troubleshooting +- If your installation doesn't seem to be working, make sure to restart the dev server. +- If a link doesn't seem to be prefetching, make sure that the link is pointing to a page on the same domain and matches the integration's `selector` option. + +## Contributing + +This package is maintained by Astro's Core team. You're welcome to submit an issue or PR! diff --git a/packages/integrations/prefetch/package.json b/packages/integrations/prefetch/package.json new file mode 100644 index 0000000000000..2fdf7cf2c7976 --- /dev/null +++ b/packages/integrations/prefetch/package.json @@ -0,0 +1,39 @@ +{ + "name": "@astrojs/prefetch", + "description": "Faster page navigations by prefetching links when the browser is idle.", + "version": "0.0.1", + "type": "module", + "types": "./dist/index.d.ts", + "author": "withastro", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/withastro/astro.git", + "directory": "packages/astro-prefetch" + }, + "bugs": "https://github.com/withastro/astro/issues", + "homepage": "https://astro.build", + "exports": { + ".": "./dist/index.js", + "./client.js": "./dist/client.js", + "./package.json": "./package.json" + }, + "scripts": { + "build": "astro-scripts build \"src/**/*.ts\" && tsc", + "build:ci": "astro-scripts build \"src/**/*.ts\"", + "dev": "astro-scripts dev \"src/**/*.ts\"", + "test": "playwright test", + "test:match": "playwright test -g" + }, + "devDependencies": { + "@types/chai": "^4.3.1", + "@types/chai-as-promised": "^7.1.5", + "@types/mocha": "^9.1.1", + "astro": "workspace:*", + "astro-scripts": "workspace:*", + "playwright": "^1.22.2" + }, + "dependencies": { + "throttles": "^1.0.1" + } +} diff --git a/packages/integrations/prefetch/playwright.config.js b/packages/integrations/prefetch/playwright.config.js new file mode 100644 index 0000000000000..c8353201f9672 --- /dev/null +++ b/packages/integrations/prefetch/playwright.config.js @@ -0,0 +1,41 @@ +import { devices } from '@playwright/test'; + +const config = { + testMatch: 'test/*.test.js', + /* Maximum time one test can run for. */ + timeout: 30 * 1000, + expect: { + /** + * Maximum time expect() should wait for the condition to be met. + * For example in `await expect(locator).toHaveText();` + */ + timeout: 5000, + }, + /* Fail the build on CI if you accidentally left test in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 5 : 0, + /* Opt out of parallel tests on CI. */ + workers: 1, + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ + actionTimeout: 0, + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + }, + projects: [ + { + name: 'Chrome Stable', + use: { + browserName: 'chromium', + channel: 'chrome', + }, + }, + ], +}; + +export default config; diff --git a/packages/integrations/prefetch/src/client.ts b/packages/integrations/prefetch/src/client.ts new file mode 100644 index 0000000000000..46a688f9d78d1 --- /dev/null +++ b/packages/integrations/prefetch/src/client.ts @@ -0,0 +1,109 @@ +/// +import throttles from 'throttles'; +import requestIdleCallback from './requestIdleCallback.js'; + +const events = ['mouseenter', 'touchstart', 'focus']; + +const preloaded = new Set(); + +function shouldPreload({ href }: { href: string }) { + try { + const url = new URL(href); + return ( + window.location.origin === url.origin && + window.location.pathname !== url.hash && + !preloaded.has(href) + ); + } catch {} + + return false; +} + +let parser: DOMParser; +let observer: IntersectionObserver; + +function observe(link: HTMLAnchorElement) { + preloaded.add(link.href); + observer.observe(link); + events.map((event) => link.addEventListener(event, onLinkEvent, { once: true })); +} + +function unobserve(link: HTMLAnchorElement) { + observer.unobserve(link); + events.map((event) => link.removeEventListener(event, onLinkEvent)); +} + +function onLinkEvent({ target }: Event) { + if (!(target instanceof HTMLAnchorElement)) { + return; + } + + preloadHref(target); +} + +async function preloadHref(link: HTMLAnchorElement) { + unobserve(link); + + const { href } = link; + + try { + const contents = await fetch(href).then((res) => res.text()); + parser = parser || new DOMParser(); + + const html = parser.parseFromString(contents, 'text/html'); + const styles = Array.from(html.querySelectorAll('link[rel="stylesheet"]')); + + await Promise.all(styles.map(({ href }) => fetch(href))); + } catch {} +} + +export interface PrefetchOptions { + /** + * Element selector used to find all links on the page that should be prefetched. + * + * @default 'a[href][rel~="prefetch"]' + */ + selector?: string; + /** + * The number of pages that can be prefetched concurrently. + * + * @default 1 + */ + throttle?: number; +} + +export default function prefetch({ selector = 'a[href][rel~="prefetch"]', throttle = 1 }: PrefetchOptions) { + const conn = navigator.connection; + + if (typeof conn !== 'undefined') { + // Don't prefetch if using 2G or if Save-Data is enabled. + if (conn.saveData) { + return Promise.reject(new Error('Cannot prefetch, Save-Data is enabled')); + } + if (/2g/.test(conn.effectiveType)) { + return Promise.reject(new Error('Cannot prefetch, network conditions are poor')); + } + } + + const [toAdd, isDone] = throttles(throttle); + + observer = + observer || + new IntersectionObserver((entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting && entry.target instanceof HTMLAnchorElement) { + toAdd(() => preloadHref(entry.target as HTMLAnchorElement).finally(isDone)); + } + }); + }); + + requestIdleCallback(() => { + const links = Array.from(document.querySelectorAll(selector)).filter( + shouldPreload + ); + + for (const link of links) { + observe(link); + } + }); +} diff --git a/packages/integrations/prefetch/src/index.ts b/packages/integrations/prefetch/src/index.ts new file mode 100644 index 0000000000000..15f52272cb493 --- /dev/null +++ b/packages/integrations/prefetch/src/index.ts @@ -0,0 +1,17 @@ +import type { AstroIntegration } from 'astro'; +import type { PrefetchOptions } from './client.js'; + +export default function (options: PrefetchOptions = {}): AstroIntegration { + return { + name: '@astrojs/lit', + hooks: { + 'astro:config:setup': ({ updateConfig, addRenderer, injectScript }) => { + // Inject the necessary polyfills on every page (inlined for speed). + injectScript( + 'page', + `import prefetch from "@astrojs/prefetch/client.js"; prefetch(${JSON.stringify(options)});` + ); + } + } + }; +} diff --git a/packages/integrations/prefetch/src/requestIdleCallback.ts b/packages/integrations/prefetch/src/requestIdleCallback.ts new file mode 100644 index 0000000000000..9435bd41d780c --- /dev/null +++ b/packages/integrations/prefetch/src/requestIdleCallback.ts @@ -0,0 +1,16 @@ +function shim(callback: IdleRequestCallback, options?: IdleRequestOptions) { + const timeout = options?.timeout ?? 50; + const start = Date.now(); + + return setTimeout(function () { + callback({ + didTimeout: false, + timeRemaining: function () { + return Math.max(0, timeout - (Date.now() - start)); + }, + }); + }, 1); +} + +const requestIdleCallback = window.requestIdleCallback || shim; +export default requestIdleCallback; diff --git a/packages/integrations/prefetch/test/basic-prefetch.test.js b/packages/integrations/prefetch/test/basic-prefetch.test.js new file mode 100644 index 0000000000000..897c00590a69f --- /dev/null +++ b/packages/integrations/prefetch/test/basic-prefetch.test.js @@ -0,0 +1,64 @@ +import { expect } from '@playwright/test'; +import { testFactory } from './test-utils.js'; + +const test = testFactory({ root: './fixtures/basic-prefetch/' }); + +test.describe('Basic prefetch', () => { + test.describe('dev', () => { + let devServer; + + test.beforeEach(async ({ astro }) => { + devServer = await astro.startDevServer(); + }); + + test.afterEach(async () => { + await devServer.stop(); + }); + + test.describe('prefetches rel="prefetch" links', () => { + test('skips /admin', async ({ page, astro }) => { + const requests = new Set(); + + page.on('request', async (request) => requests.add(request.url())); + + await page.goto(astro.resolveUrl('/')); + + await page.waitForLoadState('networkidle'); + + await expect(requests.has(astro.resolveUrl('/about')), '/about was prefetched').toBeTruthy(); + await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy(); + await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); + }); + }); + }); + + test.describe('build', () => { + let previewServer; + + test.beforeAll(async ({ astro }) => { + await astro.build(); + previewServer = await astro.preview(); + }); + + // important: close preview server (free up port and connection) + test.afterAll(async () => { + await previewServer.stop(); + }); + + test.describe('prefetches rel="prefetch" links', () => { + test('skips /admin', async ({ page, astro }) => { + const requests = new Set(); + + page.on('request', async (request) => requests.add(request.url())); + + await page.goto(astro.resolveUrl('/')); + + await page.waitForLoadState('networkidle'); + + await expect(requests.has(astro.resolveUrl('/about')), '/about was prefetched').toBeTruthy(); + await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy(); + await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); + }); + }); + }); +}); diff --git a/packages/integrations/prefetch/test/custom-selectors.test.js b/packages/integrations/prefetch/test/custom-selectors.test.js new file mode 100644 index 0000000000000..2ed5b9753e20e --- /dev/null +++ b/packages/integrations/prefetch/test/custom-selectors.test.js @@ -0,0 +1,72 @@ +import { expect } from '@playwright/test'; +import { testFactory } from './test-utils.js'; +import prefetch from '../dist/index.js'; + +const test = testFactory({ + root: './fixtures/basic-prefetch/', + integrations: [ + prefetch({ + selector: 'a[href="/contact"]' + }), + ] +}); + +test.describe('Custom prefetch selectors', () => { + test.describe('dev', () => { + let devServer; + + test.beforeEach(async ({ astro }) => { + devServer = await astro.startDevServer(); + }); + + test.afterEach(async () => { + await devServer.stop(); + }); + + test.describe('prefetches links by custom selector', () => { + test('only prefetches /contact', async ({ page, astro }) => { + const requests = new Set(); + + page.on('request', async (request) => requests.add(request.url())); + + await page.goto(astro.resolveUrl('/')); + + await page.waitForLoadState('networkidle'); + + await expect(requests.has(astro.resolveUrl('/about')), '/about was skipped').toBeFalsy(); + await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy(); + await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); + }); + }); + }); + + test.describe('build', () => { + let previewServer; + + test.beforeAll(async ({ astro }) => { + await astro.build(); + previewServer = await astro.preview(); + }); + + // important: close preview server (free up port and connection) + test.afterAll(async () => { + await previewServer.stop(); + }); + + test.describe('prefetches links by custom selector', () => { + test('only prefetches /contact', async ({ page, astro }) => { + const requests = new Set(); + + page.on('request', async (request) => requests.add(request.url())); + + await page.goto(astro.resolveUrl('/')); + + await page.waitForLoadState('networkidle'); + + await expect(requests.has(astro.resolveUrl('/about')), '/about was skipped').toBeFalsy(); + await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy(); + await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); + }); + }); + }); +}); diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/astro.config.mjs b/packages/integrations/prefetch/test/fixtures/basic-prefetch/astro.config.mjs new file mode 100644 index 0000000000000..092813b22f734 --- /dev/null +++ b/packages/integrations/prefetch/test/fixtures/basic-prefetch/astro.config.mjs @@ -0,0 +1,7 @@ +import { defineConfig } from 'astro/config'; +import prefetch from '@astrojs/prefetch'; + +// https://astro.build/config +export default defineConfig({ + integrations: [prefetch()], +}); diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/package.json b/packages/integrations/prefetch/test/fixtures/basic-prefetch/package.json new file mode 100644 index 0000000000000..cf10d74712024 --- /dev/null +++ b/packages/integrations/prefetch/test/fixtures/basic-prefetch/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/astro-prefetch", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/prefetch": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/about.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/about.astro new file mode 100644 index 0000000000000..dc2aeb8feefbc --- /dev/null +++ b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/about.astro @@ -0,0 +1,11 @@ +--- +--- + + + +About Us + + +

    About Us

    + + diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/admin.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/admin.astro new file mode 100644 index 0000000000000..7e44fc97d1c52 --- /dev/null +++ b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/admin.astro @@ -0,0 +1,11 @@ +--- +--- + + + +Admin + + +

    Admin

    + + diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/contact.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/contact.astro new file mode 100644 index 0000000000000..b565db9125534 --- /dev/null +++ b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/contact.astro @@ -0,0 +1,11 @@ +--- +--- + + + +Contact Us + + +

    Contact Us

    + + diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/index.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/index.astro new file mode 100644 index 0000000000000..d2c674ebc7810 --- /dev/null +++ b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/index.astro @@ -0,0 +1,26 @@ +--- +--- + + + +Home + + +

    Home

    + +
    + + + + diff --git a/packages/integrations/prefetch/test/test-utils.js b/packages/integrations/prefetch/test/test-utils.js new file mode 100644 index 0000000000000..198ecaafa967d --- /dev/null +++ b/packages/integrations/prefetch/test/test-utils.js @@ -0,0 +1,31 @@ +import { test as testBase } from '@playwright/test'; +import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; + +export function loadFixture(inlineConfig) { + if (!inlineConfig || !inlineConfig.root) + throw new Error("Must provide { root: './fixtures/...' }"); + + // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath + // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` + return baseLoadFixture({ + ...inlineConfig, + root: new URL(inlineConfig.root, import.meta.url).toString(), + }); +} + +export function testFactory(inlineConfig) { + let fixture; + + const test = testBase.extend({ + astro: async ({}, use) => { + fixture = await loadFixture(inlineConfig); + await use(fixture); + }, + }); + + test.afterEach(() => { + fixture.resetAllFiles(); + }); + + return test; +} diff --git a/packages/integrations/prefetch/tsconfig.json b/packages/integrations/prefetch/tsconfig.json new file mode 100644 index 0000000000000..a67ee6859a9b9 --- /dev/null +++ b/packages/integrations/prefetch/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig.base.json", + "include": ["src", "@types"], + "compilerOptions": { + "allowJs": true, + "module": "ES2020", + "outDir": "./dist", + "target": "ES2020", + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6955953306bb7..2b89500c2bb99 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1982,6 +1982,33 @@ importers: astro-scripts: link:../../../scripts preact: 10.7.3 + packages/integrations/prefetch: + specifiers: + '@types/chai': ^4.3.1 + '@types/chai-as-promised': ^7.1.5 + '@types/mocha': ^9.1.1 + astro: workspace:* + astro-scripts: workspace:* + playwright: ^1.22.2 + throttles: ^1.0.1 + dependencies: + throttles: 1.0.1 + devDependencies: + '@types/chai': 4.3.1 + '@types/chai-as-promised': 7.1.5 + '@types/mocha': 9.1.1 + astro: link:../../astro + astro-scripts: link:../../../scripts + playwright: 1.22.2 + + packages/integrations/prefetch/test/fixtures/basic-prefetch: + specifiers: + '@astrojs/prefetch': workspace:* + astro: workspace:* + dependencies: + '@astrojs/prefetch': link:../../.. + astro: link:../../../../../astro + packages/integrations/react: specifiers: '@babel/plugin-transform-react-jsx': ^7.17.12 @@ -11998,6 +12025,15 @@ packages: hasBin: true dev: true + /playwright/1.22.2: + resolution: {integrity: sha512-hUTpg7LytIl3/O4t0AQJS1V6hWsaSY5uZ7w1oCC8r3a1AQN5d6otIdCkiB3cbzgQkcMaRxisinjMFMVqZkybdQ==} + engines: {node: '>=14'} + hasBin: true + requiresBuild: true + dependencies: + playwright-core: 1.22.2 + dev: true + /postcss-attribute-case-insensitive/5.0.1_postcss@8.4.14: resolution: {integrity: sha512-wrt2VndqSLJpyBRNz9OmJcgnhI9MaongeWgapdBuUMu2a/KNJ8SENesG4SdiTnQwGO9b1VKbTWYAfCPeokLqZQ==} engines: {node: ^12 || ^14 || >=16} @@ -13742,6 +13778,11 @@ packages: resolution: {integrity: sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=} dev: true + /throttles/1.0.1: + resolution: {integrity: sha512-fab7Xg+zELr9KOv4fkaBoe/b3L0GMGLd0IBSCn16GoE/Qx6/OfCr1eGNyEcDU2pUA79qQfZ8kPQWlRuok4YwTw==} + engines: {node: '>=6'} + dev: false + /tiny-glob/0.2.9: resolution: {integrity: sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==} dependencies: @@ -14772,7 +14813,7 @@ packages: dev: false /wrappy/1.0.2: - resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=} + resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} /xregexp/2.0.0: resolution: {integrity: sha1-UqY+VsoLhKfzpfPWGHLxJq16WUM=} From cb3fcdde6a1e37e82b672f962d75df2392628519 Mon Sep 17 00:00:00 2001 From: tony-sull Date: Mon, 27 Jun 2022 18:28:16 +0000 Subject: [PATCH 47/58] [ci] format --- .../prefetch/@types/network-information.d.ts | 6 ++--- packages/integrations/prefetch/src/client.ts | 23 +++++++++++-------- packages/integrations/prefetch/src/index.ts | 8 ++++--- .../prefetch/test/basic-prefetch.test.js | 20 ++++++++++++---- .../prefetch/test/custom-selectors.test.js | 14 +++++++---- packages/integrations/prefetch/tsconfig.json | 2 +- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/packages/integrations/prefetch/@types/network-information.d.ts b/packages/integrations/prefetch/@types/network-information.d.ts index 8932e1f1ac0c9..bf1d787f3f6a6 100644 --- a/packages/integrations/prefetch/@types/network-information.d.ts +++ b/packages/integrations/prefetch/@types/network-information.d.ts @@ -1,4 +1,4 @@ -export { }; +export {}; declare global { interface NetworkInformation { @@ -9,7 +9,7 @@ declare global { } var NetworkInformation: { - prototype: NetworkInformation; - new(): NetworkInformation; + prototype: NetworkInformation; + new (): NetworkInformation; }; } diff --git a/packages/integrations/prefetch/src/client.ts b/packages/integrations/prefetch/src/client.ts index 46a688f9d78d1..9f951c8ddb2df 100644 --- a/packages/integrations/prefetch/src/client.ts +++ b/packages/integrations/prefetch/src/client.ts @@ -66,24 +66,27 @@ export interface PrefetchOptions { selector?: string; /** * The number of pages that can be prefetched concurrently. - * + * * @default 1 */ throttle?: number; } -export default function prefetch({ selector = 'a[href][rel~="prefetch"]', throttle = 1 }: PrefetchOptions) { +export default function prefetch({ + selector = 'a[href][rel~="prefetch"]', + throttle = 1, +}: PrefetchOptions) { const conn = navigator.connection; if (typeof conn !== 'undefined') { - // Don't prefetch if using 2G or if Save-Data is enabled. - if (conn.saveData) { - return Promise.reject(new Error('Cannot prefetch, Save-Data is enabled')); - } - if (/2g/.test(conn.effectiveType)) { - return Promise.reject(new Error('Cannot prefetch, network conditions are poor')); - } - } + // Don't prefetch if using 2G or if Save-Data is enabled. + if (conn.saveData) { + return Promise.reject(new Error('Cannot prefetch, Save-Data is enabled')); + } + if (/2g/.test(conn.effectiveType)) { + return Promise.reject(new Error('Cannot prefetch, network conditions are poor')); + } + } const [toAdd, isDone] = throttles(throttle); diff --git a/packages/integrations/prefetch/src/index.ts b/packages/integrations/prefetch/src/index.ts index 15f52272cb493..a15f887476b46 100644 --- a/packages/integrations/prefetch/src/index.ts +++ b/packages/integrations/prefetch/src/index.ts @@ -9,9 +9,11 @@ export default function (options: PrefetchOptions = {}): AstroIntegration { // Inject the necessary polyfills on every page (inlined for speed). injectScript( 'page', - `import prefetch from "@astrojs/prefetch/client.js"; prefetch(${JSON.stringify(options)});` + `import prefetch from "@astrojs/prefetch/client.js"; prefetch(${JSON.stringify( + options + )});` ); - } - } + }, + }, }; } diff --git a/packages/integrations/prefetch/test/basic-prefetch.test.js b/packages/integrations/prefetch/test/basic-prefetch.test.js index 897c00590a69f..0dbb571beebb6 100644 --- a/packages/integrations/prefetch/test/basic-prefetch.test.js +++ b/packages/integrations/prefetch/test/basic-prefetch.test.js @@ -25,8 +25,14 @@ test.describe('Basic prefetch', () => { await page.waitForLoadState('networkidle'); - await expect(requests.has(astro.resolveUrl('/about')), '/about was prefetched').toBeTruthy(); - await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy(); + await expect( + requests.has(astro.resolveUrl('/about')), + '/about was prefetched' + ).toBeTruthy(); + await expect( + requests.has(astro.resolveUrl('/contact')), + '/contact was prefetched' + ).toBeTruthy(); await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); }); }); @@ -55,8 +61,14 @@ test.describe('Basic prefetch', () => { await page.waitForLoadState('networkidle'); - await expect(requests.has(astro.resolveUrl('/about')), '/about was prefetched').toBeTruthy(); - await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy(); + await expect( + requests.has(astro.resolveUrl('/about')), + '/about was prefetched' + ).toBeTruthy(); + await expect( + requests.has(astro.resolveUrl('/contact')), + '/contact was prefetched' + ).toBeTruthy(); await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); }); }); diff --git a/packages/integrations/prefetch/test/custom-selectors.test.js b/packages/integrations/prefetch/test/custom-selectors.test.js index 2ed5b9753e20e..64ac5fc63623c 100644 --- a/packages/integrations/prefetch/test/custom-selectors.test.js +++ b/packages/integrations/prefetch/test/custom-selectors.test.js @@ -6,9 +6,9 @@ const test = testFactory({ root: './fixtures/basic-prefetch/', integrations: [ prefetch({ - selector: 'a[href="/contact"]' + selector: 'a[href="/contact"]', }), - ] + ], }); test.describe('Custom prefetch selectors', () => { @@ -34,7 +34,10 @@ test.describe('Custom prefetch selectors', () => { await page.waitForLoadState('networkidle'); await expect(requests.has(astro.resolveUrl('/about')), '/about was skipped').toBeFalsy(); - await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy(); + await expect( + requests.has(astro.resolveUrl('/contact')), + '/contact was prefetched' + ).toBeTruthy(); await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); }); }); @@ -64,7 +67,10 @@ test.describe('Custom prefetch selectors', () => { await page.waitForLoadState('networkidle'); await expect(requests.has(astro.resolveUrl('/about')), '/about was skipped').toBeFalsy(); - await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy(); + await expect( + requests.has(astro.resolveUrl('/contact')), + '/contact was prefetched' + ).toBeTruthy(); await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); }); }); diff --git a/packages/integrations/prefetch/tsconfig.json b/packages/integrations/prefetch/tsconfig.json index a67ee6859a9b9..ae0c4a8762d13 100644 --- a/packages/integrations/prefetch/tsconfig.json +++ b/packages/integrations/prefetch/tsconfig.json @@ -5,6 +5,6 @@ "allowJs": true, "module": "ES2020", "outDir": "./dist", - "target": "ES2020", + "target": "ES2020" } } From 7ef4efac673f6dbba5f5e8831cb4261d94cea43a Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 27 Jun 2022 11:32:24 -0700 Subject: [PATCH 48/58] add fredkbot to author of format commit --- .github/workflows/format.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 852982c218b4f..7478ea6b9632d 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -31,3 +31,5 @@ jobs: with: commit_message: '[ci] format' branch: ${{ github.head_ref }} + commit_user_name: fredkbot + commit_user_email: fred+astrobot@astro.build From 0bcc969cd4afff37d11560fc6e6f1c7001fcefd8 Mon Sep 17 00:00:00 2001 From: Sarah Rainsberger Date: Mon, 27 Jun 2022 15:44:32 -0300 Subject: [PATCH 49/58] removed experimental warning from astro add command (#3727) --- packages/integrations/lit/README.md | 2 +- packages/integrations/preact/README.md | 2 +- packages/integrations/react/README.md | 2 +- packages/integrations/solid/README.md | 2 +- packages/integrations/svelte/README.md | 2 +- packages/integrations/vue/README.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/integrations/lit/README.md b/packages/integrations/lit/README.md index f8dd0349a41c7..6f4571ee32cf1 100644 --- a/packages/integrations/lit/README.md +++ b/packages/integrations/lit/README.md @@ -6,7 +6,7 @@ This **[Astro integration][astro-integration]** enables server-side rendering an There are two ways to add integrations to your project. Let's try the most convenient option first! -### (experimental) `astro add` command +### `astro add` command Astro includes a CLI tool for adding first party integrations: `astro add`. This command will: 1. (Optionally) Install all necessary dependencies and peer dependencies diff --git a/packages/integrations/preact/README.md b/packages/integrations/preact/README.md index ccae01b83889d..c31b9e35cf875 100644 --- a/packages/integrations/preact/README.md +++ b/packages/integrations/preact/README.md @@ -6,7 +6,7 @@ This **[Astro integration][astro-integration]** enables server-side rendering an There are two ways to add integrations to your project. Let's try the most convenient option first! -### (experimental) `astro add` command +### `astro add` command Astro includes a CLI tool for adding first party integrations: `astro add`. This command will: 1. (Optionally) Install all necessary dependencies and peer dependencies diff --git a/packages/integrations/react/README.md b/packages/integrations/react/README.md index ee2244d4430ff..e610faecdd5c6 100644 --- a/packages/integrations/react/README.md +++ b/packages/integrations/react/README.md @@ -6,7 +6,7 @@ This **[Astro integration][astro-integration]** enables server-side rendering an There are two ways to add integrations to your project. Let's try the most convenient option first! -### (experimental) `astro add` command +### `astro add` command Astro includes a CLI tool for adding first party integrations: `astro add`. This command will: 1. (Optionally) Install all necessary dependencies and peer dependencies diff --git a/packages/integrations/solid/README.md b/packages/integrations/solid/README.md index ed6d7dc03f702..366a81512e34e 100644 --- a/packages/integrations/solid/README.md +++ b/packages/integrations/solid/README.md @@ -6,7 +6,7 @@ This **[Astro integration][astro-integration]** enables server-side rendering an There are two ways to add integrations to your project. Let's try the most convenient option first! -### (experimental) `astro add` command +### `astro add` command Astro includes a CLI tool for adding first party integrations: `astro add`. This command will: 1. (Optionally) Install all necessary dependencies and peer dependencies diff --git a/packages/integrations/svelte/README.md b/packages/integrations/svelte/README.md index b0cddafe2297f..7a9ca7bf4c524 100644 --- a/packages/integrations/svelte/README.md +++ b/packages/integrations/svelte/README.md @@ -6,7 +6,7 @@ This **[Astro integration][astro-integration]** enables server-side rendering an There are two ways to add integrations to your project. Let's try the most convenient option first! -### (experimental) `astro add` command +### `astro add` command Astro includes a CLI tool for adding first party integrations: `astro add`. This command will: 1. (Optionally) Install all necessary dependencies and peer dependencies diff --git a/packages/integrations/vue/README.md b/packages/integrations/vue/README.md index 3d5baa70d15eb..bbbbb555ed50d 100644 --- a/packages/integrations/vue/README.md +++ b/packages/integrations/vue/README.md @@ -6,7 +6,7 @@ This **[Astro integration][astro-integration]** enables server-side rendering an There are two ways to add integrations to your project. Let's try the most convenient option first! -### (experimental) `astro add` command +### `astro add` command Astro includes a CLI tool for adding first party integrations: `astro add`. This command will: 1. (Optionally) Install all necessary dependencies and peer dependencies From bd4dac0e1a8598045f10c42faf08abff96ed6766 Mon Sep 17 00:00:00 2001 From: Tony Sullivan Date: Mon, 27 Jun 2022 21:13:18 +0000 Subject: [PATCH 50/58] Add missing changeset for @astrojs/prefetch (#3736) --- .changeset/lovely-radios-grin.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .changeset/lovely-radios-grin.md diff --git a/.changeset/lovely-radios-grin.md b/.changeset/lovely-radios-grin.md new file mode 100644 index 0000000000000..6bf7ad719ff1e --- /dev/null +++ b/.changeset/lovely-radios-grin.md @@ -0,0 +1,19 @@ +--- +'@astrojs/prefetch': patch +--- + +Adds a new `@astrojs/prefetch` integration with the goal of adding near-instant page navigation for Astro projects. HTML and CSS for visible links marked with `rel="prefetch"` will be preloaded in the browser when the browser is idle. + +__astro.config.mjs__ +```js +import prefetch from '@astrojs/prefetch'; +export default { + // ... + integrations: [prefetch()], +} +``` + +```html + +All Products +``` From 4d6d8644e623522ca6c19dbb2078865b17044c38 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 27 Jun 2022 14:15:51 -0700 Subject: [PATCH 51/58] SImplify "astro add" by removing confusing multi-select (#3715) * wip * update create-astro for new astro add * update copy * update git prompt * Update packages/astro/src/core/logger/node.ts Co-authored-by: Chris Swithinbank * Update packages/create-astro/test/install-step.test.js Co-authored-by: Chris Swithinbank * update git prompt * update test Co-authored-by: Chris Swithinbank --- .changeset/lucky-apes-yell.md | 5 + .changeset/perfect-drinks-fold.md | 5 + packages/astro/src/cli/index.ts | 39 ++++---- packages/astro/src/cli/telemetry.ts | 14 +-- packages/astro/src/core/add/consts.ts | 27 ----- packages/astro/src/core/add/index.ts | 99 +++++++++---------- packages/astro/src/core/messages.ts | 46 ++++----- packages/create-astro/create-astro.mjs | 2 +- packages/create-astro/src/index.ts | 94 ++++++++---------- .../create-astro/test/astro-add-step.test.js | 69 ------------- .../create-astro/test/install-step.test.js | 5 - packages/create-astro/test/utils.js | 8 +- packages/webapi/mod.d.ts | 2 +- 13 files changed, 157 insertions(+), 258 deletions(-) create mode 100644 .changeset/lucky-apes-yell.md create mode 100644 .changeset/perfect-drinks-fold.md delete mode 100644 packages/astro/src/core/add/consts.ts delete mode 100644 packages/create-astro/test/astro-add-step.test.js diff --git a/.changeset/lucky-apes-yell.md b/.changeset/lucky-apes-yell.md new file mode 100644 index 0000000000000..ea244403e5747 --- /dev/null +++ b/.changeset/lucky-apes-yell.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Update "astro add" output to remove confusing multi-select prompt. diff --git a/.changeset/perfect-drinks-fold.md b/.changeset/perfect-drinks-fold.md new file mode 100644 index 0000000000000..2af9edabaf61e --- /dev/null +++ b/.changeset/perfect-drinks-fold.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Update the help output to improve formatting diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 7fd3b25728c2f..ab38daa0945ee 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -37,26 +37,27 @@ type CLICommand = function printAstroHelp() { printHelp({ commandName: 'astro', + usage: '[command] [...flags]', headline: 'Futuristic web development tool.', - commands: [ - ['add', 'Add an integration to your configuration.'], - ['docs', "Launch Astro's Doc site directly from the terminal. "], - ['dev', 'Run Astro in development mode.'], - ['build', 'Build a pre-compiled production-ready site.'], - ['preview', 'Preview your build locally before deploying.'], - ['check', 'Check your project for errors.'], - ['telemetry', 'Enable/disable anonymous data collection.'], - ['--version', 'Show the version number and exit.'], - ['--help', 'Show this help message.'], - ], - flags: [ - ['--host [optional IP]', 'Expose server on network'], - ['--config ', 'Specify the path to the Astro config file.'], - ['--root ', 'Specify the path to the project root folder.'], - ['--drafts', 'Include markdown draft pages in the build.'], - ['--verbose', 'Enable verbose logging'], - ['--silent', 'Disable logging'], - ], + tables: { + Commands: [ + ['add', 'Add an integration.'], + ['build', 'Build your project and write it to disk.'], + ['check', 'Check your project for errors.'], + ['dev', 'Start the development server.'], + ['docs', "Open documentation in your web browser."], + ['preview', 'Preview your build locally.'], + ['telemetry', 'Configure telemetry settings.'], + ], + 'Global Flags': [ + ['--config ', 'Specify your config file.'], + ['--root ', 'Specify your project root folder.'], + ['--verbose', 'Enable verbose logging.'], + ['--silent', 'Disable all logging.'], + ['--version', 'Show the version number and exit.'], + ['--help', 'Show this help message.'], + ], + }, }); } diff --git a/packages/astro/src/cli/telemetry.ts b/packages/astro/src/cli/telemetry.ts index 8247b459dac0d..ded7bc7a15d68 100644 --- a/packages/astro/src/cli/telemetry.ts +++ b/packages/astro/src/cli/telemetry.ts @@ -15,12 +15,14 @@ export async function update(subcommand: string, { flags, telemetry }: Telemetry if (flags.help || !isValid) { msg.printHelp({ commandName: 'astro telemetry', - usage: '', - commands: [ - ['enable', 'Enable anonymous data collection.'], - ['disable', 'Disable anonymous data collection.'], - ['reset', 'Reset anonymous data collection settings.'], - ], + usage: '[command]', + tables: { + Commands: [ + ['enable', 'Enable anonymous data collection.'], + ['disable', 'Disable anonymous data collection.'], + ['reset', 'Reset anonymous data collection settings.'], + ], + }, }); return; } diff --git a/packages/astro/src/core/add/consts.ts b/packages/astro/src/core/add/consts.ts deleted file mode 100644 index e17d704d5947a..0000000000000 --- a/packages/astro/src/core/add/consts.ts +++ /dev/null @@ -1,27 +0,0 @@ -export const FIRST_PARTY_FRAMEWORKS = [ - { value: 'react', title: 'React' }, - { value: 'preact', title: 'Preact' }, - { value: 'vue', title: 'Vue' }, - { value: 'svelte', title: 'Svelte' }, - { value: 'solid-js', title: 'Solid' }, - { value: 'lit', title: 'Lit' }, -]; -export const FIRST_PARTY_ADDONS = [ - { value: 'tailwind', title: 'Tailwind' }, - { value: 'turbolinks', title: 'Turbolinks' }, - { value: 'partytown', title: 'Partytown' }, - { value: 'sitemap', title: 'Sitemap' }, -]; -export const ALIASES = new Map([ - ['solid', 'solid-js'], - ['tailwindcss', 'tailwind'], -]); -export const CONFIG_STUB = `import { defineConfig } from 'astro/config';\n\nexport default defineConfig({});`; -export const TAILWIND_CONFIG_STUB = `/** @type {import('tailwindcss').Config} */ -module.exports = { - content: ['./src/**/*.{astro,html,js,jsx,md,svelte,ts,tsx,vue}'], - theme: { - extend: {}, - }, - plugins: [], -}\n`; diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index f66a2006d0e02..2e5e5315a2bd8 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -11,14 +11,13 @@ import prompts from 'prompts'; import { fileURLToPath, pathToFileURL } from 'url'; import type yargs from 'yargs-parser'; import { resolveConfigURL } from '../config.js'; -import { debug, error, info, LogOptions } from '../logger/core.js'; +import { debug, info, LogOptions } from '../logger/core.js'; import * as msg from '../messages.js'; import { printHelp } from '../messages.js'; import { appendForwardSlash } from '../path.js'; import { apply as applyPolyfill } from '../polyfill.js'; import { parseNpmName } from '../util.js'; import { generate, parse, t, visit } from './babel.js'; -import * as CONSTS from './consts.js'; import { ensureImport } from './imports.js'; import { wrapDefaultExport } from './wrapper.js'; @@ -34,71 +33,71 @@ export interface IntegrationInfo { packageName: string; dependencies: [name: string, version: string][]; } +const ALIASES = new Map([ + ['solid', 'solid-js'], + ['tailwindcss', 'tailwind'], +]); +const ASTRO_CONFIG_STUB = `import { defineConfig } from 'astro/config';\n\ndefault defineConfig({});`; +const TAILWIND_CONFIG_STUB = `/** @type {import('tailwindcss').Config} */ +module.exports = { + content: ['./src/**/*.{astro,html,js,jsx,md,svelte,ts,tsx,vue}'], + theme: { + extend: {}, + }, + plugins: [], +}\n`; export default async function add(names: string[], { cwd, flags, logging, telemetry }: AddOptions) { - if (flags.help) { + if (flags.help || names.length === 0) { printHelp({ commandName: 'astro add', - usage: '[FLAGS] [INTEGRATIONS...]', - flags: [ - ['--yes', 'Add the integration without user interaction.'], - ['--help', 'Show this help message.'], - ], + usage: '[...integrations]', + tables: { + Flags: [ + ['--yes', 'Accept all prompts.'], + ['--help', 'Show this help message.'], + ], + 'Example: Add a UI Framework': [ + ['react', 'astro add react'], + ['preact', 'astro add preact'], + ['vue', 'astro add vue'], + ['svelte', 'astro add svelte'], + ['solid-js', 'astro add solid-js'], + ['lit', 'astro add lit'], + ], + 'Example: Add an Integration': [ + ['tailwind', 'astro add tailwind'], + ['partytown', 'astro add partytown'], + ['sitemap', 'astro add sitemap'], + ], + }, + description: `Check out the full integration catalog: ${cyan('https://astro.build/integrations')}`, }); return; } let configURL: URL | undefined; const root = pathToFileURL(cwd ? path.resolve(cwd) : process.cwd()); - // TODO: improve error handling for invalid configs configURL = await resolveConfigURL({ cwd, flags }); - - if (configURL?.pathname.endsWith('package.json')) { - throw new Error( - `Unable to use astro add with package.json#astro configuration! Try migrating to \`astro.config.mjs\` and try again.` - ); - } applyPolyfill(); - - // If no integrations were given, prompt the user for some popular ones. - if (names.length === 0) { - const response = await prompts([ - { - type: 'multiselect', - name: 'frameworks', - message: 'What frameworks would you like to enable?', - instructions: '\n Space to select. Return to submit', - choices: CONSTS.FIRST_PARTY_FRAMEWORKS, - }, - { - type: 'multiselect', - name: 'addons', - message: 'What additional integrations would you like to enable?', - instructions: '\n Space to select. Return to submit', - choices: CONSTS.FIRST_PARTY_ADDONS, - }, - ]); - - names = [...(response.frameworks ?? []), ...(response.addons ?? [])]; - } - - // If still empty after prompting, exit gracefully. - if (names.length === 0) { - error(logging, null, `No integrations specified.`); - return; - } - - // Some packages might have a common alias! We normalize those here. - names = names.map((name) => (CONSTS.ALIASES.has(name) ? CONSTS.ALIASES.get(name)! : name)); - + if (configURL) { debug('add', `Found config at ${configURL}`); } else { info(logging, 'add', `Unable to locate a config file, generating one for you.`); configURL = new URL('./astro.config.mjs', appendForwardSlash(root.href)); - await fs.writeFile(fileURLToPath(configURL), CONSTS.CONFIG_STUB, { encoding: 'utf-8' }); + await fs.writeFile(fileURLToPath(configURL), ASTRO_CONFIG_STUB, { encoding: 'utf-8' }); + } + + // TODO: improve error handling for invalid configs + if (configURL?.pathname.endsWith('package.json')) { + throw new Error( + `Unable to use "astro add" with package.json configuration. Try migrating to \`astro.config.mjs\` and try again.` + ); } - const integrations = await validateIntegrations(names); + // Some packages might have a common alias! We normalize those here. + const integrationNames = names.map((name) => (ALIASES.has(name) ? ALIASES.get(name)! : name)); + const integrations = await validateIntegrations(integrationNames); let ast: t.File | null = null; try { @@ -194,7 +193,7 @@ export default async function add(names: string[], { cwd, flags, logging, teleme if (await askToContinue({ flags })) { await fs.writeFile( fileURLToPath(new URL('./tailwind.config.cjs', configURL)), - CONSTS.TAILWIND_CONFIG_STUB, + TAILWIND_CONFIG_STUB, { encoding: 'utf-8' } ); debug('add', `Generated default ./tailwind.config.cjs file`); diff --git a/packages/astro/src/core/messages.ts b/packages/astro/src/core/messages.ts index 7da96d6961760..561457368c3ee 100644 --- a/packages/astro/src/core/messages.ts +++ b/packages/astro/src/core/messages.ts @@ -248,29 +248,28 @@ export function printHelp({ commandName, headline, usage, - commands, - flags, + tables, + description, }: { commandName: string; headline?: string; usage?: string; - commands?: [command: string, help: string][]; - flags?: [flag: string, help: string][]; + tables?: Record; + description?: string, }) { const linebreak = () => ''; const title = (label: string) => ` ${bgWhite(black(` ${label} `))}`; - const table = (rows: [string, string][], opts: { padding: number; prefix: string }) => { - const split = rows.some((row) => { - const message = `${opts.prefix}${' '.repeat(opts.padding)}${row[1]}`; - return message.length > process.stdout.columns; - }); - + const table = (rows: [string, string][], { padding }: { padding: number }) => { + const split = process.stdout.columns < 60; let raw = ''; for (const row of rows) { - raw += `${opts.prefix}${bold(`${row[0]}`.padStart(opts.padding - opts.prefix.length))}`; - if (split) raw += '\n '; - raw += ' ' + dim(row[1]) + '\n'; + if (split) { + raw += ` ${row[0]}\n `; + } else { + raw += `${(`${row[0]}`.padStart(padding))}`; + } + raw += ' ' + dim(row[1]) + '\n'; } return raw.slice(0, -1); // remove latest \n @@ -291,18 +290,21 @@ export function printHelp({ message.push(linebreak(), ` ${green(commandName)} ${bold(usage)}`); } - if (commands) { - message.push( - linebreak(), - title('Commands'), - table(commands, { padding: 28, prefix: ` ${commandName || 'astro'} ` }) - ); + if (tables) { + function calculateTablePadding(rows: [string, string][]) { + return rows.reduce((val, [first]) => Math.max(val, first.length), 0) + 2; + }; + const tableEntries = Object.entries(tables); + const padding = Math.max(...tableEntries.map(([, rows]) => calculateTablePadding(rows))); + for (const [tableTitle, tableRows] of tableEntries) { + message.push(linebreak(), title(tableTitle), table(tableRows, { padding })); + } } - if (flags) { - message.push(linebreak(), title('Flags'), table(flags, { padding: 28, prefix: ' ' })); + if (description) { + message.push(linebreak(), `${description}`); } // eslint-disable-next-line no-console - console.log(message.join('\n')); + console.log(message.join('\n') + '\n'); } diff --git a/packages/create-astro/create-astro.mjs b/packages/create-astro/create-astro.mjs index be032f3c2c09d..7f09ba70086cd 100755 --- a/packages/create-astro/create-astro.mjs +++ b/packages/create-astro/create-astro.mjs @@ -3,7 +3,7 @@ const currentVersion = process.versions.node; const requiredMajorVersion = parseInt(currentVersion.split('.')[0], 10); -const minimumMajorVersion = 12; +const minimumMajorVersion = 14; if (requiredMajorVersion < minimumMajorVersion) { console.error(`Node.js v${currentVersion} is out of date and unsupported!`); diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index 08396a4e82464..4960062cb84de 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -2,7 +2,7 @@ import degit from 'degit'; import { execa, execaCommand } from 'execa'; import fs from 'fs'; -import { bgCyan, black, bold, cyan, gray, green, red, yellow } from 'kleur/colors'; +import { bgCyan, black, bold, cyan, dim, gray, green, red, yellow } from 'kleur/colors'; import ora from 'ora'; import path from 'path'; import prompts from 'prompts'; @@ -11,6 +11,13 @@ import { loadWithRocketGradient, rocketAscii } from './gradient.js'; import { defaultLogLevel, logger } from './logger.js'; import { TEMPLATES } from './templates.js'; +function wait(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} +function logAndWait(message: string, ms: number = 100) { + console.log(message); + return wait(ms); +} // NOTE: In the v7.x version of npm, the default behavior of `npm init` was changed // to no longer require `--` to pass args and instead pass `--` directly to us. This // broke our arg parser, since `--` is a special kind of flag. Filtering for `--` here @@ -43,6 +50,7 @@ export async function main() { logger.debug('Verbose logging turned on'); console.log(`\n${bold('Welcome to Astro!')} ${gray(`(create-astro v${version})`)}`); + console.log(`Lets walk through setting up your new Astro project.\n`); let cwd = args['_'][2] as string; @@ -64,7 +72,7 @@ export async function main() { const dirResponse = await prompts({ type: 'text', name: 'directory', - message: 'Where would you like to create your app?', + message: 'Where would you like to create your new project?', initial: './my-astro-site', validate(value) { if (!isEmpty(value)) { @@ -84,7 +92,7 @@ export async function main() { { type: 'select', name: 'template', - message: 'Which app template would you like to use?', + message: 'Which template would you like to use?', choices: TEMPLATES, }, ]); @@ -112,7 +120,7 @@ export async function main() { }); // Copy - if (!args.dryrun) { + if (!args.dryRun) { try { emitter.on('info', (info) => { logger.debug(info.message); @@ -175,11 +183,9 @@ export async function main() { initial: true, }); - if (!installResponse) { - process.exit(0); - } - - if (installResponse.install && !args.dryrun) { + if (args.dryRun) { + ora().info(dim(`--dry-run enabled, skipping.`)); + } else if (installResponse.install) { const installExec = execa(pkgManager, ['install'], { cwd }); const installingPackagesMsg = `Installing packages${emojiWithFallback(' 📦', '...')}`; const installSpinner = await loadWithRocketGradient(installingPackagesMsg); @@ -194,69 +200,51 @@ export async function main() { }); installSpinner.text = green('Packages installed!'); installSpinner.succeed(); - } - - const astroAddCommand = installResponse.install - ? 'astro add --yes' - : `${pkgManagerExecCommand(pkgManager)} astro@latest add --yes`; - - const astroAddResponse = await prompts({ - type: 'confirm', - name: 'astroAdd', - message: `Run "${astroAddCommand}?" This lets you optionally add component frameworks (ex. React), CSS frameworks (ex. Tailwind), and more.`, - initial: true, - }); - - if (!astroAddResponse) { - process.exit(0); - } - - if (!astroAddResponse.astroAdd) { - ora().info( - `No problem. You can always run "${pkgManagerExecCommand(pkgManager)} astro add" later!` - ); - } - - if (astroAddResponse.astroAdd && !args.dryrun) { - await execaCommand( - astroAddCommand, - astroAddCommand === 'astro add --yes' - ? { cwd, stdio: 'inherit', localDir: cwd, preferLocal: true } - : { cwd, stdio: 'inherit' } - ); + } else { + ora().info(dim(`No problem! You can install dependencies yourself after setup.`)); } const gitResponse = await prompts({ type: 'confirm', name: 'git', - message: 'Initialize a git repository?', + message: `Initialize a new git repository? ${dim('This can be useful to track changes.')}`, initial: true, }); - if (!gitResponse) { - process.exit(0); - } - - if (gitResponse.git && !args.dryrun) { + if (args.dryRun) { + ora().info(dim(`--dry-run enabled, skipping.`)); + } else if (gitResponse.git) { await execaCommand('git init', { cwd }); + } else { + ora().info( + dim(`Sounds good! You can come back and run ${cyan(`git init`)} later.`) + ); } - ora({ text: green('Done. Ready for liftoff!') }).succeed(); + ora().succeed('Setup complete.'); + ora({ text: green('Ready for liftoff!') }).succeed(); + await wait(300); + console.log(`\n${bgCyan(black(' Next steps '))}\n`); - const projectDir = path.relative(process.cwd(), cwd); + let projectDir = path.relative(process.cwd(), cwd); const devCmd = pkgManager === 'npm' ? 'npm run dev' : `${pkgManager} dev`; - console.log( + await logAndWait( `You can now ${bold(cyan('cd'))} into the ${bold(cyan(projectDir))} project directory.` ); - console.log( + await logAndWait( `Run ${bold(cyan(devCmd))} to start the Astro dev server. ${bold(cyan('CTRL-C'))} to close.` ); - if (!installResponse.install) { - console.log(yellow(`Remember to install dependencies first!`)); - } - console.log(`\nStuck? Come join us at ${bold(cyan('https://astro.build/chat'))}`); + await logAndWait( + `Add frameworks like ${bold(cyan('react'))} and ${bold( + cyan('tailwind') + )} to your project using ${bold(cyan('astro add'))}` + ); + await logAndWait(''); + await logAndWait(`Stuck? Come join us at ${bold(cyan('https://astro.build/chat'))}`, 1000); + await logAndWait(dim('Good luck out there, astronaut.')); + await logAndWait('', 300); } function emojiWithFallback(char: string, fallback: string) { diff --git a/packages/create-astro/test/astro-add-step.test.js b/packages/create-astro/test/astro-add-step.test.js deleted file mode 100644 index 73d963ed03fcd..0000000000000 --- a/packages/create-astro/test/astro-add-step.test.js +++ /dev/null @@ -1,69 +0,0 @@ -import { setup, promiseWithTimeout, timeout, PROMPT_MESSAGES } from './utils.js'; -import { sep } from 'path'; -import fs from 'fs'; -import os from 'os'; - -// reset package manager in process.env -// prevents test issues when running with pnpm -const FAKE_PACKAGE_MANAGER = 'npm'; -let initialEnvValue = null; - -describe('[create-astro] astro add', function () { - this.timeout(timeout); - let tempDir = ''; - beforeEach(async () => { - tempDir = await fs.promises.mkdtemp(`${os.tmpdir()}${sep}`); - }); - this.beforeAll(() => { - initialEnvValue = process.env.npm_config_user_agent; - process.env.npm_config_user_agent = FAKE_PACKAGE_MANAGER; - }); - this.afterAll(() => { - process.env.npm_config_user_agent = initialEnvValue; - }); - - it('should use "astro add" when user has installed dependencies', function () { - const { stdout, stdin } = setup([tempDir]); - return promiseWithTimeout((resolve) => { - const seen = new Set(); - const installPrompt = PROMPT_MESSAGES.install('npm'); - stdout.on('data', (chunk) => { - if (!seen.has(PROMPT_MESSAGES.template) && chunk.includes(PROMPT_MESSAGES.template)) { - seen.add(PROMPT_MESSAGES.template); - // respond with "enter key" - stdin.write('\x0D'); - } - if (!seen.has(installPrompt) && chunk.includes(installPrompt)) { - seen.add(installPrompt); - stdin.write('\x0D'); - } - if (chunk.includes(PROMPT_MESSAGES.astroAdd('astro add --yes'))) { - resolve(); - } - }); - }); - }); - - it('should use "npx astro@latest add" when use has NOT installed dependencies', function () { - const { stdout, stdin } = setup([tempDir]); - return promiseWithTimeout((resolve) => { - const seen = new Set(); - const installPrompt = PROMPT_MESSAGES.install('npm'); - stdout.on('data', (chunk) => { - if (!seen.has(PROMPT_MESSAGES.template) && chunk.includes(PROMPT_MESSAGES.template)) { - seen.add(PROMPT_MESSAGES.template); - // respond with "enter key" - stdin.write('\x0D'); - } - if (!seen.has(installPrompt) && chunk.includes(installPrompt)) { - seen.add(installPrompt); - // respond with "no, then enter key" - stdin.write('n\x0D'); - } - if (chunk.includes(PROMPT_MESSAGES.astroAdd('npx astro@latest add --yes'))) { - resolve(); - } - }); - }); - }); -}); diff --git a/packages/create-astro/test/install-step.test.js b/packages/create-astro/test/install-step.test.js index d8219b5201a5e..3f1dea4a9f9ba 100644 --- a/packages/create-astro/test/install-step.test.js +++ b/packages/create-astro/test/install-step.test.js @@ -44,7 +44,6 @@ describe('[create-astro] install', function () { return promiseWithTimeout((resolve) => { const seen = new Set(); const installPrompt = PROMPT_MESSAGES.install(FAKE_PACKAGE_MANAGER); - const astroAddPrompt = PROMPT_MESSAGES.astroAdd(); stdout.on('data', (chunk) => { if (!seen.has(PROMPT_MESSAGES.template) && chunk.includes(PROMPT_MESSAGES.template)) { seen.add(PROMPT_MESSAGES.template); @@ -56,10 +55,6 @@ describe('[create-astro] install', function () { // respond with "no, then enter key" stdin.write('n\x0D'); } - if (!seen.has(astroAddPrompt) && chunk.includes(astroAddPrompt)) { - seen.add(astroAddPrompt); - stdin.write('n\x0D'); - } if (!seen.has(PROMPT_MESSAGES.git) && chunk.includes(PROMPT_MESSAGES.git)) { seen.add(PROMPT_MESSAGES.git); stdin.write('\x0D'); diff --git a/packages/create-astro/test/utils.js b/packages/create-astro/test/utils.js index 964ae6a2022f2..9d227f6b5bc27 100644 --- a/packages/create-astro/test/utils.js +++ b/packages/create-astro/test/utils.js @@ -24,12 +24,10 @@ export function promiseWithTimeout(testFn) { } export const PROMPT_MESSAGES = { - directory: 'Where would you like to create your app?', - template: 'Which app template would you like to use?', + directory: 'Where would you like to create your new project?', + template: 'Which template would you like to use?', install: (pkgManager) => `Would you like us to run "${pkgManager} install?"`, - astroAdd: (astroAddCommand = 'npx astro@latest add --yes') => - `Run "${astroAddCommand}?" This lets you optionally add component frameworks (ex. React), CSS frameworks (ex. Tailwind), and more.`, - git: 'Initialize a git repository?', + git: 'Initialize a new git repository?', }; export function setup(args = []) { diff --git a/packages/webapi/mod.d.ts b/packages/webapi/mod.d.ts index a3c49dc5c406f..b385e82a5e294 100644 --- a/packages/webapi/mod.d.ts +++ b/packages/webapi/mod.d.ts @@ -1,5 +1,5 @@ export { pathToPosix } from './lib/utils'; -export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter } from './mod.js'; +export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; export declare const polyfill: { (target: any, options?: PolyfillOptions): any; internals(target: any, name: string): any; From ebd7e7ad81e5245deffa331f11e5196ff1b21d84 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 27 Jun 2022 14:16:07 -0700 Subject: [PATCH 52/58] update telemetry to support more anonymized project id (#3713) * update telemetry to support more anonymized project id * Create strange-laws-kick.md * respond to nate feedback --- .changeset/strange-laws-kick.md | 6 + packages/astro/src/cli/index.ts | 113 ++++++-------- packages/astro/src/cli/telemetry.ts | 2 - .../{telemetry => astro}/src/events/index.ts | 1 - .../src/events/session.ts | 26 ++-- .../test/events.test.js} | 78 ++-------- packages/telemetry/events.d.ts | 1 - packages/telemetry/package.json | 1 - packages/telemetry/src/anonymous-meta.ts | 48 ------ packages/telemetry/src/config-keys.ts | 8 + packages/telemetry/src/config.ts | 6 +- packages/telemetry/src/events/build.ts | 2 - packages/telemetry/src/index.ts | 142 +++++++----------- packages/telemetry/src/keys.ts | 16 -- packages/telemetry/src/post.ts | 8 +- packages/telemetry/src/project-id.ts | 27 ---- packages/telemetry/src/project-info.ts | 87 +++++++++++ packages/telemetry/src/system-info.ts | 72 +++++++++ packages/telemetry/test/config.test.js | 9 ++ packages/telemetry/test/index.test.js | 9 ++ 20 files changed, 311 insertions(+), 351 deletions(-) create mode 100644 .changeset/strange-laws-kick.md rename packages/{telemetry => astro}/src/events/index.ts (51%) rename packages/{telemetry => astro}/src/events/session.ts (81%) rename packages/{telemetry/test/session-event.test.js => astro/test/events.test.js} (82%) delete mode 100644 packages/telemetry/events.d.ts delete mode 100644 packages/telemetry/src/anonymous-meta.ts create mode 100644 packages/telemetry/src/config-keys.ts delete mode 100644 packages/telemetry/src/events/build.ts delete mode 100644 packages/telemetry/src/keys.ts delete mode 100644 packages/telemetry/src/project-id.ts create mode 100644 packages/telemetry/src/project-info.ts create mode 100644 packages/telemetry/src/system-info.ts create mode 100644 packages/telemetry/test/config.test.js create mode 100644 packages/telemetry/test/index.test.js diff --git a/.changeset/strange-laws-kick.md b/.changeset/strange-laws-kick.md new file mode 100644 index 0000000000000..5a7ec191dd959 --- /dev/null +++ b/.changeset/strange-laws-kick.md @@ -0,0 +1,6 @@ +--- +"astro": patch +"@astrojs/telemetry": minor +--- + +Update telemetry to support a more anonymized project id. `anonymousProjectId` is now hashed based on anonymous git data instead of your git remote URL. diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index ab38daa0945ee..422d057cf3734 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -3,7 +3,7 @@ import { LogOptions } from '../core/logger/core.js'; import { AstroTelemetry } from '@astrojs/telemetry'; -import * as event from '@astrojs/telemetry/events'; +import * as event from '../events/index.js'; import * as colors from 'kleur/colors'; import yargs from 'yargs-parser'; import { z } from 'zod'; @@ -19,6 +19,7 @@ import { createSafeError } from '../core/util.js'; import { check } from './check.js'; import { openInBrowser } from './open.js'; import * as telemetryHandler from './telemetry.js'; +import { AstroUserConfig } from '../@types/astro.js'; type Arguments = yargs.Arguments; type CLICommand = @@ -61,12 +62,13 @@ function printAstroHelp() { }); } +// PACKAGE_VERSION is injected when we build and publish the astro package. +const ASTRO_VERSION = process.env.PACKAGE_VERSION ?? 'development'; + /** Display --version flag */ async function printVersion() { - // PACKAGE_VERSION is injected at build time - const version = process.env.PACKAGE_VERSION ?? ''; console.log(); - console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`); + console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${ASTRO_VERSION}`)}`); } /** Determine which command the user requested */ @@ -110,43 +112,51 @@ export async function cli(args: string[]) { } else if (flags.silent) { logging.level = 'silent'; } - const telemetry = new AstroTelemetry({ version: process.env.PACKAGE_VERSION ?? '' }); - - if (cmd === 'telemetry') { - try { - const subcommand = flags._[3]?.toString(); - return await telemetryHandler.update(subcommand, { flags, telemetry }); - } catch (err) { - return throwAndExit(err); - } - } + const telemetry = new AstroTelemetry({ version: ASTRO_VERSION }); + // Special CLI Commands: "add", "docs", "telemetry" + // These commands run before the user's config is parsed, and may have other special + // conditions that should be handled here, before the others. + // switch (cmd) { case 'add': { try { + telemetry.record(event.eventCliSession({ cliCommand: cmd })); const packages = flags._.slice(3) as string[]; - telemetry.record( - event.eventCliSession({ - astroVersion: process.env.PACKAGE_VERSION ?? '', - cliCommand: 'add', - }) - ); return await add(packages, { cwd: root, flags, logging, telemetry }); } catch (err) { return throwAndExit(err); } } + case 'docs': { + try { + telemetry.record(event.eventCliSession({ cliCommand: cmd })); + return await openInBrowser('https://docs.astro.build/'); + } catch (err) { + return throwAndExit(err); + } + } + case 'telemetry': { + try { + // Do not track session start, since the user may be trying to enable, + // disable, or modify telemetry settings. + const subcommand = flags._[3]?.toString(); + return await telemetryHandler.update(subcommand, { flags, telemetry }); + } catch (err) { + return throwAndExit(err); + } + } + } + + const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd }); + telemetry.record(event.eventCliSession({ cliCommand: cmd }, userConfig, flags)); + + // Common CLI Commands: + // These commands run normally. All commands are assumed to have been handled + // by the end of this switch statement. + switch (cmd) { case 'dev': { try { - const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd }); - - telemetry.record( - event.eventCliSession( - { astroVersion: process.env.PACKAGE_VERSION ?? '', cliCommand: 'dev' }, - userConfig, - flags - ) - ); await devServer(astroConfig, { logging, telemetry }); return await new Promise(() => {}); // lives forever } catch (err) { @@ -156,14 +166,6 @@ export async function cli(args: string[]) { case 'build': { try { - const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd }); - telemetry.record( - event.eventCliSession( - { astroVersion: process.env.PACKAGE_VERSION ?? '', cliCommand: 'build' }, - userConfig, - flags - ) - ); return await build(astroConfig, { logging, telemetry }); } catch (err) { return throwAndExit(err); @@ -171,53 +173,22 @@ export async function cli(args: string[]) { } case 'check': { - const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd }); - telemetry.record( - event.eventCliSession( - { astroVersion: process.env.PACKAGE_VERSION ?? '', cliCommand: 'check' }, - userConfig, - flags - ) - ); const ret = await check(astroConfig); return process.exit(ret); } case 'preview': { try { - const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd }); - telemetry.record( - event.eventCliSession( - { astroVersion: process.env.PACKAGE_VERSION ?? '', cliCommand: 'preview' }, - userConfig, - flags - ) - ); const server = await preview(astroConfig, { logging, telemetry }); return await server.closed(); // keep alive until the server is closed } catch (err) { return throwAndExit(err); } } - - case 'docs': { - try { - await telemetry.record( - event.eventCliSession({ - astroVersion: process.env.PACKAGE_VERSION ?? '', - cliCommand: 'docs', - }) - ); - return await openInBrowser('https://docs.astro.build/'); - } catch (err) { - return throwAndExit(err); - } - } - - default: { - throw new Error(`Error running ${cmd}`); - } } + + // No command handler matched! This is unexpected. + throwAndExit(new Error(`Error running ${cmd} -- no command found.`)); } /** Display error and exit */ diff --git a/packages/astro/src/cli/telemetry.ts b/packages/astro/src/cli/telemetry.ts index ded7bc7a15d68..ee3ab47ff46c0 100644 --- a/packages/astro/src/cli/telemetry.ts +++ b/packages/astro/src/cli/telemetry.ts @@ -1,9 +1,7 @@ /* eslint-disable no-console */ import type { AstroTelemetry } from '@astrojs/telemetry'; import type yargs from 'yargs-parser'; - import * as msg from '../core/messages.js'; - export interface TelemetryOptions { flags: yargs.Arguments; telemetry: AstroTelemetry; diff --git a/packages/telemetry/src/events/index.ts b/packages/astro/src/events/index.ts similarity index 51% rename from packages/telemetry/src/events/index.ts rename to packages/astro/src/events/index.ts index 6c671ff6cd85d..dc768aa2d629f 100644 --- a/packages/telemetry/src/events/index.ts +++ b/packages/astro/src/events/index.ts @@ -1,2 +1 @@ -export * from './build.js'; export * from './session.js'; diff --git a/packages/telemetry/src/events/session.ts b/packages/astro/src/events/session.ts similarity index 81% rename from packages/telemetry/src/events/session.ts rename to packages/astro/src/events/session.ts index e8c222bf1c81d..6a246f5816e59 100644 --- a/packages/telemetry/src/events/session.ts +++ b/packages/astro/src/events/session.ts @@ -1,14 +1,10 @@ import { createRequire } from 'node:module'; - +import type { AstroUserConfig } from '../@types/astro'; const require = createRequire(import.meta.url); const EVENT_SESSION = 'ASTRO_CLI_SESSION_STARTED'; -// :( We can't import the type because of TurboRepo circular dep limitation -type AstroUserConfig = Record; - interface EventCliSession { - astroVersion: string; cliCommand: string; } @@ -25,7 +21,7 @@ interface ConfigInfo { markdown: | undefined | { - mode: undefined | 'md' | 'mdx'; + drafts: undefined | boolean; syntaxHighlight: undefined | 'shiki' | 'prism' | false; }; } @@ -91,15 +87,18 @@ export function eventCliSession( flags?: Record ): { eventName: string; payload: EventCliSessionInternal }[] { // Filter out falsy integrations - const integrations = userConfig?.integrations?.filter?.(Boolean) ?? []; const configValues = userConfig ? { markdownPlugins: [ - userConfig?.markdown?.remarkPlugins ?? [], - userConfig?.markdown?.rehypePlugins ?? [], - ].flat(1), + ...(userConfig?.markdown?.remarkPlugins?.map((p) => + typeof p === 'string' ? p : typeof p + ) ?? []), + ...(userConfig?.markdown?.rehypePlugins?.map((p) => + typeof p === 'string' ? p : typeof p + ) ?? []), + ] as string[], adapter: userConfig?.adapter?.name ?? null, - integrations: integrations?.map?.((i: any) => i?.name) ?? [], + integrations: (userConfig?.integrations ?? []).filter(Boolean).map((i: any) => i?.name), trailingSlash: userConfig?.trailingSlash, build: userConfig?.build ? { @@ -108,7 +107,7 @@ export function eventCliSession( : undefined, markdown: userConfig?.markdown ? { - mode: userConfig?.markdown?.mode, + drafts: userConfig.markdown?.drafts, syntaxHighlight: userConfig.markdown?.syntaxHighlight, } : undefined, @@ -121,15 +120,12 @@ export function eventCliSession( const payload: EventCliSessionInternal = { cliCommand: event.cliCommand, // Versions - astroVersion: event.astroVersion, viteVersion: getViteVersion(), nodeVersion: process.version.replace(/^v?/, ''), configKeys: userConfig ? configKeys(userConfig, '') : undefined, // Config Values config: configValues, flags: cliFlags, - // Optional integrations - optionalIntegrations: userConfig?.integrations?.length - integrations?.length, }; return [{ eventName: EVENT_SESSION, payload }]; } diff --git a/packages/telemetry/test/session-event.test.js b/packages/astro/test/events.test.js similarity index 82% rename from packages/telemetry/test/session-event.test.js rename to packages/astro/test/events.test.js index 5702f5fa54135..3eeef269c9869 100644 --- a/packages/telemetry/test/session-event.test.js +++ b/packages/astro/test/events.test.js @@ -18,7 +18,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -37,7 +36,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -54,7 +52,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -74,7 +71,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -88,7 +84,6 @@ describe('Session event', () => { publicDir: 1, markdown: { drafts: true, - mode: 'mdx', shikiConfig: { lang: 1, theme: 2, @@ -102,7 +97,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -110,7 +104,6 @@ describe('Session event', () => { 'publicDir', 'markdown', 'markdown.drafts', - 'markdown.mode', 'markdown.shikiConfig', 'markdown.shikiConfig.lang', 'markdown.shikiConfig.theme', @@ -121,22 +114,6 @@ describe('Session event', () => { ]); }); - it('mode', () => { - const config = { - markdown: { - mode: 'mdx', - }, - }; - const [{ payload }] = events.eventCliSession( - { - cliCommand: 'dev', - astroVersion: '0.0.0', - }, - config - ); - expect(payload.config.markdown.mode).to.equal('mdx'); - }); - it('syntaxHighlight', () => { const config = { markdown: { @@ -146,7 +123,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -172,7 +148,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -203,7 +178,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -231,7 +205,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -262,7 +235,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -293,7 +265,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -322,7 +293,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -348,7 +318,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -373,7 +342,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -398,7 +366,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config ); @@ -411,38 +378,18 @@ describe('Session event', () => { }); }); - describe('config.integrations + optionalIntegrations', () => { - it('optional/conditional integrations', () => { - const config = { - srcDir: 1, - integrations: [null, undefined, { name: 'example-integration' }], - }; - const [{ payload }] = events.eventCliSession( - { - cliCommand: 'dev', - astroVersion: '0.0.0', - }, - config - ); - expect(payload.config.integrations).deep.equal(['example-integration']); - expect(payload.optionalIntegrations).to.equal(2); - }); - - it('falsy integrations', () => { - const config = { - srcDir: 1, - integrations: [null, undefined, false], - }; - const [{ payload }] = events.eventCliSession( - { - cliCommand: 'dev', - astroVersion: '0.0.0', - }, - config - ); - expect(payload.config.integrations.length).to.equal(0); - expect(payload.optionalIntegrations).to.equal(3); - }); + it('falsy integrations', () => { + const config = { + srcDir: 1, + integrations: [null, undefined, false], + }; + const [{ payload }] = events.eventCliSession( + { + cliCommand: 'dev', + }, + config + ); + expect(payload.config.integrations.length).to.equal(0); }); describe('flags', () => { @@ -461,7 +408,6 @@ describe('Session event', () => { const [{ payload }] = events.eventCliSession( { cliCommand: 'dev', - astroVersion: '0.0.0', }, config, flags diff --git a/packages/telemetry/events.d.ts b/packages/telemetry/events.d.ts deleted file mode 100644 index e1bf0951835e2..0000000000000 --- a/packages/telemetry/events.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/types/events'; diff --git a/packages/telemetry/package.json b/packages/telemetry/package.json index ac80025a98e32..31faf49fc8999 100644 --- a/packages/telemetry/package.json +++ b/packages/telemetry/package.json @@ -14,7 +14,6 @@ "homepage": "https://astro.build", "exports": { ".": "./dist/index.js", - "./events": "./dist/events/index.js", "./package.json": "./package.json" }, "scripts": { diff --git a/packages/telemetry/src/anonymous-meta.ts b/packages/telemetry/src/anonymous-meta.ts deleted file mode 100644 index 8f42d91bfac24..0000000000000 --- a/packages/telemetry/src/anonymous-meta.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { isCI, name as ciName } from 'ci-info'; -import isDocker from 'is-docker'; -import isWSL from 'is-wsl'; -import os from 'node:os'; - -type AnonymousMeta = { - systemPlatform: NodeJS.Platform; - systemRelease: string; - systemArchitecture: string; - cpuCount: number; - cpuModel: string | null; - cpuSpeed: number | null; - memoryInMb: number; - isDocker: boolean; - isWSL: boolean; - isCI: boolean; - ciName: string | null; - astroVersion: string; -}; - -let meta: AnonymousMeta | undefined; - -export function getAnonymousMeta(astroVersion: string): AnonymousMeta { - if (meta) { - return meta; - } - - const cpus = os.cpus() || []; - meta = { - // Software information - systemPlatform: os.platform(), - systemRelease: os.release(), - systemArchitecture: os.arch(), - // Machine information - cpuCount: cpus.length, - cpuModel: cpus.length ? cpus[0].model : null, - cpuSpeed: cpus.length ? cpus[0].speed : null, - memoryInMb: Math.trunc(os.totalmem() / Math.pow(1024, 2)), - // Environment information - isDocker: isDocker(), - isWSL, - isCI, - ciName, - astroVersion, - }; - - return meta!; -} diff --git a/packages/telemetry/src/config-keys.ts b/packages/telemetry/src/config-keys.ts new file mode 100644 index 0000000000000..932e602e2d374 --- /dev/null +++ b/packages/telemetry/src/config-keys.ts @@ -0,0 +1,8 @@ +// Global Config Keys + +/** Specifies whether or not telemetry is enabled or disabled. */ +export const TELEMETRY_ENABLED = 'telemetry.enabled'; +/** Specifies when the user was informed of anonymous telemetry. */ +export const TELEMETRY_NOTIFY_DATE = 'telemetry.notifiedAt'; +/** Specifies an anonymous identifier used to dedupe events for a user. */ +export const TELEMETRY_ID = `telemetry.anonymousId`; diff --git a/packages/telemetry/src/config.ts b/packages/telemetry/src/config.ts index 9317ab80d6bb2..d03f9102b182e 100644 --- a/packages/telemetry/src/config.ts +++ b/packages/telemetry/src/config.ts @@ -7,7 +7,6 @@ import process from 'node:process'; export interface ConfigOptions { name: string; - defaults: Map; } // Adapted from https://github.com/sindresorhus/env-paths @@ -32,7 +31,7 @@ function getConfigDir(name: string) { } } -export class Config { +export class GlobalConfig { private dir: string; private file: string; @@ -49,9 +48,6 @@ export class Config { this._store = JSON.parse(fs.readFileSync(this.file).toString()); } else { const store = {}; - for (const [key, value] of this.project.defaults) { - dset(store, key, value); - } this._store = store; this.write(); } diff --git a/packages/telemetry/src/events/build.ts b/packages/telemetry/src/events/build.ts deleted file mode 100644 index 1d6b8b7fda9e4..0000000000000 --- a/packages/telemetry/src/events/build.ts +++ /dev/null @@ -1,2 +0,0 @@ -// See https://github.com/vercel/next.js/blob/canary/packages/next/telemetry/events/build.ts -export {}; diff --git a/packages/telemetry/src/index.ts b/packages/telemetry/src/index.ts index 26c0dd04050d3..f0315e16cf464 100644 --- a/packages/telemetry/src/index.ts +++ b/packages/telemetry/src/index.ts @@ -1,44 +1,27 @@ -import type { BinaryLike } from 'node:crypto'; -import { createHash, randomBytes } from 'node:crypto'; - import { isCI } from 'ci-info'; import debug from 'debug'; -// @ts-ignore -import gitUp from 'git-up'; - -import { getAnonymousMeta } from './anonymous-meta.js'; -import { Config } from './config.js'; -import * as KEY from './keys.js'; +import { randomBytes } from 'node:crypto'; +import * as KEY from './config-keys.js'; +import { GlobalConfig } from './config.js'; import { post } from './post.js'; -import { getRawProjectId } from './project-id.js'; - -export interface AstroTelemetryOptions { - version: string; -} +import { getProjectInfo, ProjectInfo } from './project-info.js'; +import { getSystemInfo, SystemInfo } from './system-info.js'; +export type AstroTelemetryOptions = { version: string }; export type TelemetryEvent = { eventName: string; payload: Record }; - interface EventContext { anonymousId: string; - projectId: string; - projectMetadata: any; - sessionId: string; + anonymousProjectId: string; + anonymousSessionId: string; } +interface EventMeta extends SystemInfo { + isGit: boolean; +} export class AstroTelemetry { - private rawProjectId = getRawProjectId(); - private sessionId = randomBytes(32).toString('hex'); - private config = new Config({ - name: 'astro', - // Use getter to defer generation of defaults unless needed - get defaults() { - return new Map([ - [KEY.TELEMETRY_ENABLED, true], - [KEY.TELEMETRY_SALT, randomBytes(16).toString('hex')], - [KEY.TELEMETRY_ID, randomBytes(32).toString('hex')], - ]); - }, - }); + private _anonymousSessionId: string | undefined; + private _anonymousProjectInfo: ProjectInfo | undefined; + private config = new GlobalConfig({ name: 'astro' }); private debug = debug('astro:telemetry'); private get astroVersion() { @@ -53,65 +36,47 @@ export class AstroTelemetry { constructor(private opts: AstroTelemetryOptions) { // TODO: When the process exits, flush any queued promises - // This line caused a "cannot exist astro" error, needs to be revisited. + // This caused a "cannot exist astro" error when it ran, so it was removed. // process.on('SIGINT', () => this.flush()); } - // Util to get value from config or set it if missing - private getWithFallback(key: string, value: T): T { - const val = this.config.get(key); - if (val) { - return val; + /** + * Get value from either the global config or the provided fallback. + * If value is not set, the fallback is saved to the global config, + * persisted for later sessions. + */ + private getConfigWithFallback(key: string, getValue: () => T): T { + const currentValue = this.config.get(key); + if (currentValue) { + return currentValue; } - this.config.set(key, value); - return value; + const newValue = getValue(); + this.config.set(key, newValue); + return newValue; } - private get salt(): string { - return this.getWithFallback(KEY.TELEMETRY_SALT, randomBytes(16).toString('hex')); - } private get enabled(): boolean { - return this.getWithFallback(KEY.TELEMETRY_ENABLED, true); - } - private get anonymousId(): string { - return this.getWithFallback(KEY.TELEMETRY_ID, randomBytes(32).toString('hex')); - } - private get notifyDate(): string { - return this.getWithFallback(KEY.TELEMETRY_NOTIFY_DATE, ''); + return this.getConfigWithFallback(KEY.TELEMETRY_ENABLED, () => true); } - private hash(payload: BinaryLike): string { - const hash = createHash('sha256'); - hash.update(payload); - return hash.digest('hex'); + private get notifyDate(): string { + return this.getConfigWithFallback(KEY.TELEMETRY_NOTIFY_DATE, () => ''); } - // Create a ONE-WAY hash so there is no way for Astro to decode the value later. - private oneWayHash(payload: BinaryLike): string { - const hash = createHash('sha256'); - // Always prepend the payload value with salt! This ensures the hash is one-way. - hash.update(this.salt); - hash.update(payload); - return hash.digest('hex'); + private get anonymousId(): string { + return this.getConfigWithFallback(KEY.TELEMETRY_ID, () => randomBytes(32).toString('hex')); } - // Instead of sending `rawProjectId`, we only ever reference a hashed value *derived* - // from `rawProjectId`. This ensures that `projectId` is ALWAYS anonymous and can't - // be reversed from the hashed value. - private get projectId(): string { - return this.oneWayHash(this.rawProjectId); + private get anonymousSessionId(): string { + // NOTE(fks): this value isn't global, so it can't use getConfigWithFallback(). + this._anonymousSessionId = this._anonymousSessionId || randomBytes(32).toString('hex'); + return this._anonymousSessionId; } - private get projectMetadata(): undefined | { owner: string; name: string } { - const projectId = this.rawProjectId; - if (projectId === process.cwd()) { - return; - } - const { pathname, resource } = gitUp(projectId); - const parts = pathname.split('/').slice(1); - const owner = `${resource}${parts[0]}`; - const name = parts[1].replace('.git', ''); - return { owner: this.hash(owner), name: this.hash(name) }; + private get anonymousProjectInfo(): ProjectInfo { + // NOTE(fks): this value isn't global, so it can't use getConfigWithFallback(). + this._anonymousProjectInfo = this._anonymousProjectInfo || getProjectInfo(isCI); + return this._anonymousProjectInfo; } private get isDisabled(): boolean { @@ -129,13 +94,6 @@ export class AstroTelemetry { return this.config.clear(); } - private queue: Promise[] = []; - - // Wait for any in-flight promises to resolve - private async flush() { - await Promise.all(this.queue); - } - async notify(callback: () => Promise) { if (this.isDisabled || isCI) { return; @@ -172,22 +130,24 @@ export class AstroTelemetry { return Promise.resolve(); } + const meta: EventMeta = { + ...getSystemInfo(this.astroVersion), + isGit: this.anonymousProjectInfo.isGit, + }; + const context: EventContext = { anonymousId: this.anonymousId, - projectId: this.projectId, - projectMetadata: this.projectMetadata, - sessionId: this.sessionId, + anonymousProjectId: this.anonymousProjectInfo.anonymousProjectId, + anonymousSessionId: this.anonymousSessionId, }; - const meta = getAnonymousMeta(this.astroVersion); - const req = post({ + return post({ context, meta, events, - }).then(() => { - this.queue = this.queue.filter((r) => r !== req); + }).catch((err) => { + // Log the error to the debugger, but otherwise do nothing. + this.debug(`Error sending event: ${err.message}`); }); - this.queue.push(req); - return req; } } diff --git a/packages/telemetry/src/keys.ts b/packages/telemetry/src/keys.ts deleted file mode 100644 index f1c9e2ad2abe7..0000000000000 --- a/packages/telemetry/src/keys.ts +++ /dev/null @@ -1,16 +0,0 @@ -// This is the key that stores whether or not telemetry is enabled or disabled. -export const TELEMETRY_ENABLED = 'telemetry.enabled'; - -// This is the key that specifies when the user was informed about anonymous -// telemetry collection. -export const TELEMETRY_NOTIFY_DATE = 'telemetry.notifiedAt'; - -// This is a quasi-persistent identifier used to dedupe recurring events. It's -// generated from random data and completely anonymous. -export const TELEMETRY_ID = `telemetry.anonymousId`; - -// This is the cryptographic salt that is included within every hashed value. -// This salt value is never sent to us, ensuring privacy and the one-way nature -// of the hash (prevents dictionary lookups of pre-computed hashes). -// See the `oneWayHash` function. -export const TELEMETRY_SALT = `telemetry.salt`; diff --git a/packages/telemetry/src/post.ts b/packages/telemetry/src/post.ts index ae1626a406264..a0647075f9889 100644 --- a/packages/telemetry/src/post.ts +++ b/packages/telemetry/src/post.ts @@ -1,13 +1,11 @@ import fetch from 'node-fetch'; + const ASTRO_TELEMETRY_ENDPOINT = `https://telemetry.astro.build/api/v1/record`; -const noop = () => {}; -export function post(body: Record) { +export function post(body: Record): Promise { return fetch(ASTRO_TELEMETRY_ENDPOINT, { method: 'POST', body: JSON.stringify(body), headers: { 'content-type': 'application/json' }, - }) - .catch(noop) - .then(noop, noop); + }); } diff --git a/packages/telemetry/src/project-id.ts b/packages/telemetry/src/project-id.ts deleted file mode 100644 index 655a72fc610f9..0000000000000 --- a/packages/telemetry/src/project-id.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { execSync } from 'child_process'; - -// Why does Astro need a project ID? Why is it looking at my git remote? -// --- -// Astro's telemetry is and always will be completely anonymous. -// Differentiating unique projects helps us track feature usage accurately. -// -// We **never** read your actual git remote! The value is hashed one-way -// with random salt data, making it impossible for us to reverse or try to -// guess the remote by re-computing hashes. - -function getProjectIdFromGit() { - try { - const originBuffer = execSync(`git config --local --get remote.origin.url`, { - timeout: 1000, - stdio: `pipe`, - }); - - return String(originBuffer).trim(); - } catch (_) { - return null; - } -} - -export function getRawProjectId(): string { - return getProjectIdFromGit() ?? process.env.REPOSITORY_URL ?? process.cwd(); -} diff --git a/packages/telemetry/src/project-info.ts b/packages/telemetry/src/project-info.ts new file mode 100644 index 0000000000000..afb6c83bb4665 --- /dev/null +++ b/packages/telemetry/src/project-info.ts @@ -0,0 +1,87 @@ +import { execSync } from 'child_process'; +import type { BinaryLike } from 'node:crypto'; +import { createHash } from 'node:crypto'; + +/** + * Astro Telemetry -- Project Info + * + * To better understand our telemetry insights, Astro attempts to create an anonymous identifier + * for each Astro project. This value is meant to be unique to each project but common across + * multiple different users on the same project. + * + * To do this, we generate a unique, anonymous hash from your working git repository data. This is + * ideal because git data is shared across all users on the same repository, but the data itself + * that we generate our hash from does not contain any personal or otherwise identifying information. + * + * We do not use your repository's remote URL, GitHub URL, or any other personally identifying + * information to generate the project identifier hash. In this way it is almost completely anonymous. + * + * If you are running Astro outside of a git repository, then we will generate a unique, anonymous project + * identifier by hashing your project's file path on your machine. + * + * ~~~ + * + * Q: Can this project identifier be traced back to me? + * + * A: If your repository is private, there is no way for anyone to trace your unique + * project identifier back to you, your organization, or your project. This is because it is itself + * a hash of a commit hash, and a commit hash does not include any identifying information. + * + * If your repository is publicly available, then it is possible for someone to generate this unique + * project identifier themselves by cloning your repo. Specifically, someone would need access to run + * the `git rev-list` command below to generate this hash. Without this access, it is impossible to + * trace the project identifier back to you or your project. + * + * If you are running Astro outside of a git repository, then the project identifier could be matched + * back to the exact file path on your machine. It is unlikely (but still possible) for this to happen + * without access to your machine or knowledge of your machine's file system. + * + * ~~~ + * + * Q: I don't want Astro to collect a project identifier. How can I disable it? + * + * A: You can disable telemetry completely at any time by running `astro telemetry disable`. There is + * currently no way to disable just this identifier while keeping the rest of telemetry enabled. + */ + +export interface ProjectInfo { + /* Your unique project identifier. This will be hashed again before sending. */ + anonymousProjectId: string; + /* true if your project is connected to a git repository. false otherwise. */ + isGit: boolean; +} + +function createAnonymousValue(payload: BinaryLike): string { + // We use empty string to represent an empty value. Avoid hashing this + // since that would create a real hash and remove its "empty" meaning. + if (payload === '') { + return payload; + } + // Otherwise, create a new hash from the payload and return it. + const hash = createHash('sha256'); + hash.update(payload); + return hash.digest('hex'); +} + +function getProjectIdFromGit(): string | null { + try { + const originBuffer = execSync(`git rev-list --max-parents=0 HEAD`, {timeout: 500, stdio: [0, 'pipe', 0]}); + return String(originBuffer).trim(); + } catch (_) { + return null; + } +} + +export function getProjectInfo(isCI: boolean): ProjectInfo { + const projectIdFromGit = getProjectIdFromGit(); + if (projectIdFromGit) { + return { + isGit: true, + anonymousProjectId: createAnonymousValue(projectIdFromGit), + }; + } + return { + isGit: false, + anonymousProjectId: isCI ? '' : process.cwd(), + }; +} diff --git a/packages/telemetry/src/system-info.ts b/packages/telemetry/src/system-info.ts new file mode 100644 index 0000000000000..0f0de7025dad2 --- /dev/null +++ b/packages/telemetry/src/system-info.ts @@ -0,0 +1,72 @@ +import { isCI, name as ciName } from 'ci-info'; +import isDocker from 'is-docker'; +import isWSL from 'is-wsl'; +import os from 'node:os'; + +/** + * Astro Telemetry -- System Info + * + * To better understand our telemetry insights, Astro collects the following anonymous information + * about the system that it runs on. This helps us prioritize fixes and new features based on a + * better understanding of our real-world system requirements. + * + * ~~~ + * + * Q: Can this system info be traced back to me? + * + * A: No personally identifiable information is contained in the system info that we collect. It could + * be possible for someone with direct access to your machine to collect this information themselves + * and then attempt to match it all together with our collected telemetry data, however most users' + * systems are probably not uniquely identifiable via their system info alone. + * + * ~~~ + * + * Q: I don't want Astro to collect system info. How can I disable it? + * + * A: You can disable telemetry completely at any time by running `astro telemetry disable`. There is + * currently no way to disable this otherwise while keeping the rest of telemetry enabled. + */ + +export type SystemInfo = { + systemPlatform: NodeJS.Platform; + systemRelease: string; + systemArchitecture: string; + cpuCount: number; + cpuModel: string | null; + cpuSpeed: number | null; + memoryInMb: number; + isDocker: boolean; + isWSL: boolean; + isCI: boolean; + ciName: string | null; + astroVersion: string; +}; + +let meta: SystemInfo | undefined; + +export function getSystemInfo(astroVersion: string): SystemInfo { + if (meta) { + return meta; + } + + const cpus = os.cpus() || []; + meta = { + // Software information + systemPlatform: os.platform(), + systemRelease: os.release(), + systemArchitecture: os.arch(), + // Machine information + cpuCount: cpus.length, + cpuModel: cpus.length ? cpus[0].model : null, + cpuSpeed: cpus.length ? cpus[0].speed : null, + memoryInMb: Math.trunc(os.totalmem() / Math.pow(1024, 2)), + // Environment information + isDocker: isDocker(), + isWSL, + isCI, + ciName, + astroVersion, + }; + + return meta!; +} diff --git a/packages/telemetry/test/config.test.js b/packages/telemetry/test/config.test.js new file mode 100644 index 0000000000000..97408ec0dff90 --- /dev/null +++ b/packages/telemetry/test/config.test.js @@ -0,0 +1,9 @@ +import { expect } from 'chai'; +import {GlobalConfig} from '../dist/config.js'; + +describe('GlobalConfig', () => { + it('initializes when expected arguments are given', () => { + const config = new GlobalConfig({ name: 'TEST_NAME' }); + expect(config).to.be.instanceOf(GlobalConfig); + }); +}); diff --git a/packages/telemetry/test/index.test.js b/packages/telemetry/test/index.test.js new file mode 100644 index 0000000000000..2085221364b58 --- /dev/null +++ b/packages/telemetry/test/index.test.js @@ -0,0 +1,9 @@ +import { expect } from 'chai'; +import {AstroTelemetry} from '../dist/index.js'; + +describe('AstroTelemetry', () => { + it('initializes when expected arguments are given', () => { + const telemetry = new AstroTelemetry({ version: '0.0.0-test.1' }); + expect(telemetry).to.be.instanceOf(AstroTelemetry); + }); +}); From 701799c6d68bc48b75a13e64ffff6f51dc4f4858 Mon Sep 17 00:00:00 2001 From: FredKSchott Date: Mon, 27 Jun 2022 21:17:40 +0000 Subject: [PATCH 53/58] [ci] format --- packages/astro/src/cli/index.ts | 5 ++--- packages/astro/src/core/add/index.ts | 6 ++++-- packages/astro/src/core/messages.ts | 6 +++--- packages/create-astro/src/index.ts | 4 +--- packages/telemetry/src/project-info.ts | 5 ++++- packages/telemetry/src/system-info.ts | 8 ++++---- packages/telemetry/test/config.test.js | 6 +++--- packages/telemetry/test/index.test.js | 6 +++--- packages/webapi/mod.d.ts | 2 +- 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 422d057cf3734..a04b1524727b6 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -3,10 +3,10 @@ import { LogOptions } from '../core/logger/core.js'; import { AstroTelemetry } from '@astrojs/telemetry'; -import * as event from '../events/index.js'; import * as colors from 'kleur/colors'; import yargs from 'yargs-parser'; import { z } from 'zod'; +import * as event from '../events/index.js'; import add from '../core/add/index.js'; import build from '../core/build/index.js'; @@ -19,7 +19,6 @@ import { createSafeError } from '../core/util.js'; import { check } from './check.js'; import { openInBrowser } from './open.js'; import * as telemetryHandler from './telemetry.js'; -import { AstroUserConfig } from '../@types/astro.js'; type Arguments = yargs.Arguments; type CLICommand = @@ -46,7 +45,7 @@ function printAstroHelp() { ['build', 'Build your project and write it to disk.'], ['check', 'Check your project for errors.'], ['dev', 'Start the development server.'], - ['docs', "Open documentation in your web browser."], + ['docs', 'Open documentation in your web browser.'], ['preview', 'Preview your build locally.'], ['telemetry', 'Configure telemetry settings.'], ], diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index 2e5e5315a2bd8..5a1fb9cf6c2ae 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -71,7 +71,9 @@ export default async function add(names: string[], { cwd, flags, logging, teleme ['sitemap', 'astro add sitemap'], ], }, - description: `Check out the full integration catalog: ${cyan('https://astro.build/integrations')}`, + description: `Check out the full integration catalog: ${cyan( + 'https://astro.build/integrations' + )}`, }); return; } @@ -79,7 +81,7 @@ export default async function add(names: string[], { cwd, flags, logging, teleme const root = pathToFileURL(cwd ? path.resolve(cwd) : process.cwd()); configURL = await resolveConfigURL({ cwd, flags }); applyPolyfill(); - + if (configURL) { debug('add', `Found config at ${configURL}`); } else { diff --git a/packages/astro/src/core/messages.ts b/packages/astro/src/core/messages.ts index 561457368c3ee..7f592c46b941e 100644 --- a/packages/astro/src/core/messages.ts +++ b/packages/astro/src/core/messages.ts @@ -255,7 +255,7 @@ export function printHelp({ headline?: string; usage?: string; tables?: Record; - description?: string, + description?: string; }) { const linebreak = () => ''; const title = (label: string) => ` ${bgWhite(black(` ${label} `))}`; @@ -267,7 +267,7 @@ export function printHelp({ if (split) { raw += ` ${row[0]}\n `; } else { - raw += `${(`${row[0]}`.padStart(padding))}`; + raw += `${`${row[0]}`.padStart(padding)}`; } raw += ' ' + dim(row[1]) + '\n'; } @@ -293,7 +293,7 @@ export function printHelp({ if (tables) { function calculateTablePadding(rows: [string, string][]) { return rows.reduce((val, [first]) => Math.max(val, first.length), 0) + 2; - }; + } const tableEntries = Object.entries(tables); const padding = Math.max(...tableEntries.map(([, rows]) => calculateTablePadding(rows))); for (const [tableTitle, tableRows] of tableEntries) { diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index 4960062cb84de..df676fbfbd0f3 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -216,9 +216,7 @@ export async function main() { } else if (gitResponse.git) { await execaCommand('git init', { cwd }); } else { - ora().info( - dim(`Sounds good! You can come back and run ${cyan(`git init`)} later.`) - ); + ora().info(dim(`Sounds good! You can come back and run ${cyan(`git init`)} later.`)); } ora().succeed('Setup complete.'); diff --git a/packages/telemetry/src/project-info.ts b/packages/telemetry/src/project-info.ts index afb6c83bb4665..66b83c5ac8579 100644 --- a/packages/telemetry/src/project-info.ts +++ b/packages/telemetry/src/project-info.ts @@ -65,7 +65,10 @@ function createAnonymousValue(payload: BinaryLike): string { function getProjectIdFromGit(): string | null { try { - const originBuffer = execSync(`git rev-list --max-parents=0 HEAD`, {timeout: 500, stdio: [0, 'pipe', 0]}); + const originBuffer = execSync(`git rev-list --max-parents=0 HEAD`, { + timeout: 500, + stdio: [0, 'pipe', 0], + }); return String(originBuffer).trim(); } catch (_) { return null; diff --git a/packages/telemetry/src/system-info.ts b/packages/telemetry/src/system-info.ts index 0f0de7025dad2..9fe628ff0fd0f 100644 --- a/packages/telemetry/src/system-info.ts +++ b/packages/telemetry/src/system-info.ts @@ -7,16 +7,16 @@ import os from 'node:os'; * Astro Telemetry -- System Info * * To better understand our telemetry insights, Astro collects the following anonymous information - * about the system that it runs on. This helps us prioritize fixes and new features based on a + * about the system that it runs on. This helps us prioritize fixes and new features based on a * better understanding of our real-world system requirements. - * + * * ~~~ * * Q: Can this system info be traced back to me? * * A: No personally identifiable information is contained in the system info that we collect. It could - * be possible for someone with direct access to your machine to collect this information themselves - * and then attempt to match it all together with our collected telemetry data, however most users' + * be possible for someone with direct access to your machine to collect this information themselves + * and then attempt to match it all together with our collected telemetry data, however most users' * systems are probably not uniquely identifiable via their system info alone. * * ~~~ diff --git a/packages/telemetry/test/config.test.js b/packages/telemetry/test/config.test.js index 97408ec0dff90..a74e8d6f01302 100644 --- a/packages/telemetry/test/config.test.js +++ b/packages/telemetry/test/config.test.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; -import {GlobalConfig} from '../dist/config.js'; +import { GlobalConfig } from '../dist/config.js'; describe('GlobalConfig', () => { it('initializes when expected arguments are given', () => { - const config = new GlobalConfig({ name: 'TEST_NAME' }); - expect(config).to.be.instanceOf(GlobalConfig); + const config = new GlobalConfig({ name: 'TEST_NAME' }); + expect(config).to.be.instanceOf(GlobalConfig); }); }); diff --git a/packages/telemetry/test/index.test.js b/packages/telemetry/test/index.test.js index 2085221364b58..29ade53f90e80 100644 --- a/packages/telemetry/test/index.test.js +++ b/packages/telemetry/test/index.test.js @@ -1,9 +1,9 @@ import { expect } from 'chai'; -import {AstroTelemetry} from '../dist/index.js'; +import { AstroTelemetry } from '../dist/index.js'; describe('AstroTelemetry', () => { it('initializes when expected arguments are given', () => { - const telemetry = new AstroTelemetry({ version: '0.0.0-test.1' }); - expect(telemetry).to.be.instanceOf(AstroTelemetry); + const telemetry = new AstroTelemetry({ version: '0.0.0-test.1' }); + expect(telemetry).to.be.instanceOf(AstroTelemetry); }); }); diff --git a/packages/webapi/mod.d.ts b/packages/webapi/mod.d.ts index b385e82a5e294..a3c49dc5c406f 100644 --- a/packages/webapi/mod.d.ts +++ b/packages/webapi/mod.d.ts @@ -1,5 +1,5 @@ export { pathToPosix } from './lib/utils'; -export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; +export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter } from './mod.js'; export declare const polyfill: { (target: any, options?: PolyfillOptions): any; internals(target: any, name: string): any; From 4acd245d8f59871eb9c0083ae1a0fe7aa70c84f5 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Mon, 27 Jun 2022 17:20:28 -0400 Subject: [PATCH 54/58] Refactor: remove Deno shim to esbuild "banner" (#3734) * refactor: remove Deno shim to esbuild "banner" * refactor: move shim to const * refactor: add shim to netlify edge * chore: changeset --- .changeset/spotty-islands-raise.md | 6 ++++++ packages/integrations/deno/src/index.ts | 8 ++++++++ packages/integrations/deno/src/server.ts | 5 ----- packages/integrations/deno/src/shim.ts | 5 ----- packages/integrations/netlify/src/edge-shim.ts | 4 ---- .../netlify/src/integration-edge-functions.ts | 8 ++++++++ .../integrations/netlify/src/netlify-edge-functions.ts | 1 - 7 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 .changeset/spotty-islands-raise.md delete mode 100644 packages/integrations/deno/src/shim.ts delete mode 100644 packages/integrations/netlify/src/edge-shim.ts diff --git a/.changeset/spotty-islands-raise.md b/.changeset/spotty-islands-raise.md new file mode 100644 index 0000000000000..f8246006de127 --- /dev/null +++ b/.changeset/spotty-islands-raise.md @@ -0,0 +1,6 @@ +--- +'@astrojs/deno': patch +'@astrojs/netlify': patch +--- + +Fix: append shim to top of built file to avoid "can't read process of undefined" issues diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index 0dad8e8ef9ab5..a104ba863c85c 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -9,6 +9,11 @@ interface Options { hostname?: string; } +const SHIM = `globalThis.process = { + argv: [], + env: Deno.env.toObject(), +};` + export function getAdapter(args?: Options): AstroAdapter { return { name: '@astrojs/deno', @@ -63,6 +68,9 @@ export default function createIntegration(args?: Options): AstroIntegration { format: 'esm', bundle: true, external: ['@astrojs/markdown-remark'], + banner: { + js: SHIM, + } }); // Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash. diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts index 9d2fc98a9c89c..f6dbcb62c4b7f 100644 --- a/packages/integrations/deno/src/server.ts +++ b/packages/integrations/deno/src/server.ts @@ -1,8 +1,3 @@ -// NOTE(fks): Side-effect -- shim.js must run first. This isn't guaranteed by -// the language, but it is a Node.js behavior that we rely on here. Keep this -// separate from the other imports so that it doesn't get organized & reordered. -import './shim.js'; - // Normal Imports import type { SSRManifest } from 'astro'; import { App } from 'astro/app'; diff --git a/packages/integrations/deno/src/shim.ts b/packages/integrations/deno/src/shim.ts deleted file mode 100644 index 62e82ba30300c..0000000000000 --- a/packages/integrations/deno/src/shim.ts +++ /dev/null @@ -1,5 +0,0 @@ -(globalThis as any).process = { - argv: [], - // @ts-ignore - env: Deno.env.toObject(), -}; diff --git a/packages/integrations/netlify/src/edge-shim.ts b/packages/integrations/netlify/src/edge-shim.ts deleted file mode 100644 index 1a4a6ee9be4c5..0000000000000 --- a/packages/integrations/netlify/src/edge-shim.ts +++ /dev/null @@ -1,4 +0,0 @@ -(globalThis as any).process = { - argv: [], - env: {}, -}; diff --git a/packages/integrations/netlify/src/integration-edge-functions.ts b/packages/integrations/netlify/src/integration-edge-functions.ts index 72788abaf348c..17eaf8350f825 100644 --- a/packages/integrations/netlify/src/integration-edge-functions.ts +++ b/packages/integrations/netlify/src/integration-edge-functions.ts @@ -6,6 +6,11 @@ import { fileURLToPath } from 'url'; import type { Plugin as VitePlugin } from 'vite'; import { createRedirects } from './shared.js'; +const SHIM = `globalThis.process = { + argv: [], + env: {}, +};`; + export function getAdapter(): AstroAdapter { return { name: '@astrojs/netlify/edge-functions', @@ -78,6 +83,9 @@ async function bundleServerEntry(buildConfig: BuildConfig, vite: any) { format: 'esm', bundle: true, external: ['@astrojs/markdown-remark'], + banner: { + js: SHIM, + } }); // Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash. diff --git a/packages/integrations/netlify/src/netlify-edge-functions.ts b/packages/integrations/netlify/src/netlify-edge-functions.ts index 8d3ecf1079f27..0d2974c61d5cd 100644 --- a/packages/integrations/netlify/src/netlify-edge-functions.ts +++ b/packages/integrations/netlify/src/netlify-edge-functions.ts @@ -1,6 +1,5 @@ import type { SSRManifest } from 'astro'; import { App } from 'astro/app'; -import './edge-shim.js'; export function createExports(manifest: SSRManifest) { const app = new App(manifest); From efd6548d498aa6dc23cbb010c708139d4eac077d Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 27 Jun 2022 21:22:26 +0000 Subject: [PATCH 55/58] [ci] format --- packages/integrations/deno/src/index.ts | 4 ++-- .../integrations/netlify/src/integration-edge-functions.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index a104ba863c85c..9a6df4f769deb 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -12,7 +12,7 @@ interface Options { const SHIM = `globalThis.process = { argv: [], env: Deno.env.toObject(), -};` +};`; export function getAdapter(args?: Options): AstroAdapter { return { @@ -70,7 +70,7 @@ export default function createIntegration(args?: Options): AstroIntegration { external: ['@astrojs/markdown-remark'], banner: { js: SHIM, - } + }, }); // Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash. diff --git a/packages/integrations/netlify/src/integration-edge-functions.ts b/packages/integrations/netlify/src/integration-edge-functions.ts index 17eaf8350f825..b3f27997d5aa7 100644 --- a/packages/integrations/netlify/src/integration-edge-functions.ts +++ b/packages/integrations/netlify/src/integration-edge-functions.ts @@ -85,7 +85,7 @@ async function bundleServerEntry(buildConfig: BuildConfig, vite: any) { external: ['@astrojs/markdown-remark'], banner: { js: SHIM, - } + }, }); // Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash. From 6360f474fb8cecaf4fe27e9184058b57da1df72a Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 28 Jun 2022 14:49:08 +0200 Subject: [PATCH 56/58] Fix Tailwind integration Typescript warning (#3732) * Make options optional * chore: add changeset Co-authored-by: Tony Sullivan --- .changeset/khaki-ligers-glow.md | 5 +++++ packages/integrations/tailwind/src/index.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/khaki-ligers-glow.md diff --git a/.changeset/khaki-ligers-glow.md b/.changeset/khaki-ligers-glow.md new file mode 100644 index 0000000000000..1022514daa163 --- /dev/null +++ b/.changeset/khaki-ligers-glow.md @@ -0,0 +1,5 @@ +--- +'@astrojs/tailwind': patch +--- + +Marks the Tailwind integration config as optional to fix TypeScript validation warnings diff --git a/packages/integrations/tailwind/src/index.ts b/packages/integrations/tailwind/src/index.ts index 4051b93eecb14..9aaccce7d2346 100644 --- a/packages/integrations/tailwind/src/index.ts +++ b/packages/integrations/tailwind/src/index.ts @@ -50,7 +50,7 @@ type TailwindOptions = } | undefined; -export default function tailwindIntegration(options: TailwindOptions): AstroIntegration { +export default function tailwindIntegration(options?: TailwindOptions): AstroIntegration { const applyBaseStyles = options?.config?.applyBaseStyles ?? true; const customConfigPath = options?.config?.path; return { From 768c8ed21db9114fa99d6d8d87e8f7ad4350f855 Mon Sep 17 00:00:00 2001 From: "Fred K. Bot" <108291165+fredkbot@users.noreply.github.com> Date: Tue, 28 Jun 2022 06:33:13 -0700 Subject: [PATCH 57/58] [ci] update lockfile (#3740) Co-authored-by: FredKSchott --- examples/framework-multiple/package.json | 2 +- examples/framework-vue/package.json | 2 +- examples/integrations-playground/package.json | 2 +- examples/with-markdown/package.json | 2 +- examples/with-nanostores/package.json | 2 +- package.json | 10 +-- .../e2e/fixtures/client-only/package.json | 2 +- .../fixtures/multiple-frameworks/package.json | 2 +- .../fixtures/nested-in-preact/package.json | 2 +- .../e2e/fixtures/nested-in-react/package.json | 2 +- .../e2e/fixtures/nested-in-solid/package.json | 2 +- .../fixtures/nested-in-svelte/package.json | 2 +- .../e2e/fixtures/nested-in-vue/package.json | 2 +- packages/astro/package.json | 4 +- .../fixtures/react-component/package.json | 2 +- packages/integrations/deno/package.json | 2 +- packages/integrations/netlify/package.json | 2 +- packages/integrations/svelte/package.json | 6 +- packages/integrations/vue/package.json | 4 +- packages/markdown/remark/package.json | 2 +- packages/telemetry/package.json | 2 +- packages/webapi/package.json | 6 +- pnpm-lock.yaml | 74 +++++++++---------- scripts/package.json | 4 +- 24 files changed, 71 insertions(+), 71 deletions(-) diff --git a/examples/framework-multiple/package.json b/examples/framework-multiple/package.json index 9e5265dd76b8d..102fb2b9e68be 100644 --- a/examples/framework-multiple/package.json +++ b/examples/framework-multiple/package.json @@ -25,6 +25,6 @@ "react-dom": "^18.1.0", "solid-js": "^1.4.3", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/examples/framework-vue/package.json b/examples/framework-vue/package.json index e4adf3c8c310a..b4ff277b819ec 100644 --- a/examples/framework-vue/package.json +++ b/examples/framework-vue/package.json @@ -13,6 +13,6 @@ "astro": "^1.0.0-beta.57" }, "dependencies": { - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/examples/integrations-playground/package.json b/examples/integrations-playground/package.json index 4a5a8b9fa9a1b..8d4c3f04b0475 100644 --- a/examples/integrations-playground/package.json +++ b/examples/integrations-playground/package.json @@ -26,6 +26,6 @@ "react": "^18.1.0", "react-dom": "^18.1.0", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/examples/with-markdown/package.json b/examples/with-markdown/package.json index 6e749e548d49a..16b0583cd5ef1 100644 --- a/examples/with-markdown/package.json +++ b/examples/with-markdown/package.json @@ -21,6 +21,6 @@ "react": "^18.1.0", "react-dom": "^18.1.0", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/examples/with-nanostores/package.json b/examples/with-nanostores/package.json index 773149fc859cd..b6201319e516b 100644 --- a/examples/with-nanostores/package.json +++ b/examples/with-nanostores/package.json @@ -17,7 +17,7 @@ "react": "^18.1.0", "react-dom": "^18.1.0", "solid-nanostores": "0.0.6", - "vue": "^3.2.36" + "vue": "^3.2.37" }, "devDependencies": { "@astrojs/preact": "^0.2.0", diff --git a/package.json b/package.json index 342b882ebc810..769afbcd5a005 100644 --- a/package.json +++ b/package.json @@ -63,11 +63,11 @@ "@changesets/changelog-github": "0.4.4", "@changesets/cli": "2.22.0", "@octokit/action": "^3.18.1", - "@typescript-eslint/eslint-plugin": "^5.27.0", - "@typescript-eslint/parser": "^5.27.0", + "@typescript-eslint/eslint-plugin": "^5.27.1", + "@typescript-eslint/parser": "^5.27.1", "del": "^6.1.1", - "esbuild": "^0.14.42", - "eslint": "^8.16.0", + "esbuild": "^0.14.43", + "eslint": "^8.17.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-no-only-tests": "^2.6.0", "eslint-plugin-prettier": "^4.0.0", @@ -78,6 +78,6 @@ "pretty-bytes": "^6.0.0", "tiny-glob": "^0.2.9", "turbo": "1.2.5", - "typescript": "~4.7.2" + "typescript": "~4.7.3" } } diff --git a/packages/astro/e2e/fixtures/client-only/package.json b/packages/astro/e2e/fixtures/client-only/package.json index abb7cdfb35662..2a1e89ab36303 100644 --- a/packages/astro/e2e/fixtures/client-only/package.json +++ b/packages/astro/e2e/fixtures/client-only/package.json @@ -16,6 +16,6 @@ "react-dom": "^18.1.0", "solid-js": "^1.4.3", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/packages/astro/e2e/fixtures/multiple-frameworks/package.json b/packages/astro/e2e/fixtures/multiple-frameworks/package.json index 2bcbde31ed0fc..36723d2fc2816 100644 --- a/packages/astro/e2e/fixtures/multiple-frameworks/package.json +++ b/packages/astro/e2e/fixtures/multiple-frameworks/package.json @@ -19,6 +19,6 @@ "react-dom": "^18.1.0", "solid-js": "^1.4.3", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/packages/astro/e2e/fixtures/nested-in-preact/package.json b/packages/astro/e2e/fixtures/nested-in-preact/package.json index fb6877f0cda5d..624316f913c80 100644 --- a/packages/astro/e2e/fixtures/nested-in-preact/package.json +++ b/packages/astro/e2e/fixtures/nested-in-preact/package.json @@ -16,6 +16,6 @@ "react-dom": "^18.1.0", "solid-js": "^1.4.3", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/packages/astro/e2e/fixtures/nested-in-react/package.json b/packages/astro/e2e/fixtures/nested-in-react/package.json index 4aba5a5d4cd74..29ee37d2aae5a 100644 --- a/packages/astro/e2e/fixtures/nested-in-react/package.json +++ b/packages/astro/e2e/fixtures/nested-in-react/package.json @@ -16,6 +16,6 @@ "react-dom": "^18.1.0", "solid-js": "^1.4.3", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/packages/astro/e2e/fixtures/nested-in-solid/package.json b/packages/astro/e2e/fixtures/nested-in-solid/package.json index b0c61713a1899..9a51cb0093bb1 100644 --- a/packages/astro/e2e/fixtures/nested-in-solid/package.json +++ b/packages/astro/e2e/fixtures/nested-in-solid/package.json @@ -16,6 +16,6 @@ "react-dom": "^18.1.0", "solid-js": "^1.4.3", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/packages/astro/e2e/fixtures/nested-in-svelte/package.json b/packages/astro/e2e/fixtures/nested-in-svelte/package.json index 23e6d5aa6ebd6..ea847e24b5216 100644 --- a/packages/astro/e2e/fixtures/nested-in-svelte/package.json +++ b/packages/astro/e2e/fixtures/nested-in-svelte/package.json @@ -16,6 +16,6 @@ "react-dom": "^18.1.0", "solid-js": "^1.4.3", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/packages/astro/e2e/fixtures/nested-in-vue/package.json b/packages/astro/e2e/fixtures/nested-in-vue/package.json index fc24f8ea3637b..30a3895747798 100644 --- a/packages/astro/e2e/fixtures/nested-in-vue/package.json +++ b/packages/astro/e2e/fixtures/nested-in-vue/package.json @@ -16,6 +16,6 @@ "react-dom": "^18.1.0", "solid-js": "^1.4.3", "svelte": "^3.48.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/packages/astro/package.json b/packages/astro/package.json index 2c61ba25bfabd..0b07f671135e6 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -101,7 +101,7 @@ "diff": "^5.1.0", "eol": "^0.9.1", "es-module-lexer": "^0.10.5", - "esbuild": "^0.14.42", + "esbuild": "^0.14.43", "estree-walker": "^3.0.1", "execa": "^6.1.0", "fast-glob": "^3.2.11", @@ -122,7 +122,7 @@ "prompts": "^2.4.2", "recast": "^0.20.5", "resolve": "^1.22.0", - "rollup": "^2.75.5", + "rollup": "^2.75.6", "semver": "^7.3.7", "shiki": "^0.10.1", "sirv": "^2.0.2", diff --git a/packages/astro/test/fixtures/react-component/package.json b/packages/astro/test/fixtures/react-component/package.json index 73a159f6149ef..dc9b2fd6f01de 100644 --- a/packages/astro/test/fixtures/react-component/package.json +++ b/packages/astro/test/fixtures/react-component/package.json @@ -8,6 +8,6 @@ "astro": "workspace:*", "react": "^18.1.0", "react-dom": "^18.1.0", - "vue": "^3.2.36" + "vue": "^3.2.37" } } diff --git a/packages/integrations/deno/package.json b/packages/integrations/deno/package.json index d84d23c4d4470..df164f2dd6307 100644 --- a/packages/integrations/deno/package.json +++ b/packages/integrations/deno/package.json @@ -25,7 +25,7 @@ "test": "deno test --allow-run --allow-env --allow-read --allow-net ./test/" }, "dependencies": { - "esbuild": "^0.14.42" + "esbuild": "^0.14.43" }, "devDependencies": { "astro": "workspace:*", diff --git a/packages/integrations/netlify/package.json b/packages/integrations/netlify/package.json index 9cf33befd6ab5..53f1767828a59 100644 --- a/packages/integrations/netlify/package.json +++ b/packages/integrations/netlify/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@astrojs/webapi": "^0.12.0", - "esbuild": "^0.14.42" + "esbuild": "^0.14.43" }, "devDependencies": { "@netlify/edge-handler-types": "^0.34.1", diff --git a/packages/integrations/svelte/package.json b/packages/integrations/svelte/package.json index a9c653ea7de1d..53ce95147aa40 100644 --- a/packages/integrations/svelte/package.json +++ b/packages/integrations/svelte/package.json @@ -31,10 +31,10 @@ "dev": "astro-scripts dev \"src/**/*.ts\"" }, "dependencies": { - "@sveltejs/vite-plugin-svelte": "^1.0.0-next.47", + "@sveltejs/vite-plugin-svelte": "^1.0.0-next.48", "postcss-load-config": "^3.1.4", - "svelte-preprocess": "^4.10.6", - "vite": "^2.9.9" + "svelte-preprocess": "^4.10.7", + "vite": "^2.9.10" }, "devDependencies": { "astro": "workspace:*", diff --git a/packages/integrations/vue/package.json b/packages/integrations/vue/package.json index f91ce1cd37493..a6b2989fe9b49 100644 --- a/packages/integrations/vue/package.json +++ b/packages/integrations/vue/package.json @@ -32,12 +32,12 @@ }, "dependencies": { "@vitejs/plugin-vue": "^2.3.3", - "vite": "^2.9.9" + "vite": "^2.9.10" }, "devDependencies": { "astro": "workspace:*", "astro-scripts": "workspace:*", - "vue": "^3.2.36" + "vue": "^3.2.37" }, "peerDependencies": { "vue": "^3.2.30" diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json index 08cca86bd62e0..bceac48978dd9 100644 --- a/packages/markdown/remark/package.json +++ b/packages/markdown/remark/package.json @@ -31,7 +31,7 @@ "acorn-jsx": "^5.3.2", "assert": "^2.0.0", "github-slugger": "^1.4.0", - "mdast-util-mdx-expression": "^1.2.0", + "mdast-util-mdx-expression": "^1.2.1", "mdast-util-mdx-jsx": "^1.2.0", "mdast-util-to-string": "^3.1.0", "micromark-extension-mdx-expression": "^1.0.3", diff --git a/packages/telemetry/package.json b/packages/telemetry/package.json index 31faf49fc8999..56d6e8ffd8263 100644 --- a/packages/telemetry/package.json +++ b/packages/telemetry/package.json @@ -38,7 +38,7 @@ }, "devDependencies": { "@types/dlv": "^1.1.2", - "@types/node": "^14.18.20", + "@types/node": "^14.18.21", "astro-scripts": "workspace:*" }, "engines": { diff --git a/packages/webapi/package.json b/packages/webapi/package.json index f2ab64fb5a359..4148783178f7e 100644 --- a/packages/webapi/package.json +++ b/packages/webapi/package.json @@ -59,7 +59,7 @@ "@rollup/plugin-typescript": "^8.3.2", "@types/chai": "^4.3.1", "@types/mocha": "^9.1.1", - "@types/node": "^14.18.20", + "@types/node": "^14.18.21", "@ungap/structured-clone": "^0.3.4", "abort-controller": "^3.0.0", "chai": "^4.3.6", @@ -68,10 +68,10 @@ "formdata-polyfill": "^4.0.10", "magic-string": "^0.25.9", "mocha": "^9.2.2", - "rollup": "^2.75.5", + "rollup": "^2.75.6", "rollup-plugin-terser": "^7.0.2", "tslib": "^2.4.0", - "typescript": "~4.7.2", + "typescript": "~4.7.3", "urlpattern-polyfill": "^1.0.0-rc5", "web-streams-polyfill": "^3.2.1" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2b89500c2bb99..79afdc3075410 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,11 +8,11 @@ importers: '@changesets/changelog-github': 0.4.4 '@changesets/cli': 2.22.0 '@octokit/action': ^3.18.1 - '@typescript-eslint/eslint-plugin': ^5.27.0 - '@typescript-eslint/parser': ^5.27.0 + '@typescript-eslint/eslint-plugin': ^5.27.1 + '@typescript-eslint/parser': ^5.27.1 del: ^6.1.1 - esbuild: ^0.14.42 - eslint: ^8.16.0 + esbuild: ^0.14.43 + eslint: ^8.17.0 eslint-config-prettier: ^8.5.0 eslint-plugin-no-only-tests: ^2.6.0 eslint-plugin-prettier: ^4.0.0 @@ -23,7 +23,7 @@ importers: pretty-bytes: ^6.0.0 tiny-glob: ^0.2.9 turbo: 1.2.5 - typescript: ~4.7.2 + typescript: ~4.7.3 dependencies: '@astrojs/webapi': link:packages/webapi devDependencies: @@ -163,7 +163,7 @@ importers: react-dom: ^18.1.0 solid-js: ^1.4.3 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: '@webcomponents/template-shadowroot': 0.1.0 lit: 2.2.5 @@ -236,7 +236,7 @@ importers: specifiers: '@astrojs/vue': ^0.2.0 astro: ^1.0.0-beta.57 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: vue: 3.2.37 devDependencies: @@ -260,7 +260,7 @@ importers: react-dom: ^18.1.0 solid-js: ^1.4.3 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: '@webcomponents/template-shadowroot': 0.1.0 lit: 2.2.5 @@ -359,7 +359,7 @@ importers: react: ^18.1.0 react-dom: ^18.1.0 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: preact: 10.7.3 react: 18.1.0 @@ -416,7 +416,7 @@ importers: react: ^18.1.0 react-dom: ^18.1.0 solid-nanostores: 0.0.6 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: '@nanostores/preact': 0.1.3_xtkr2uyxt54wubcnyxiwramgs4 '@nanostores/react': 0.1.5_ib7jseorxmnfrhevtrqzsp5cr4 @@ -509,7 +509,7 @@ importers: diff: ^5.1.0 eol: ^0.9.1 es-module-lexer: ^0.10.5 - esbuild: ^0.14.42 + esbuild: ^0.14.43 estree-walker: ^3.0.1 execa: ^6.1.0 fast-glob: ^3.2.11 @@ -531,7 +531,7 @@ importers: prompts: ^2.4.2 recast: ^0.20.5 resolve: ^1.22.0 - rollup: ^2.75.5 + rollup: ^2.75.6 sass: ^1.52.2 semver: ^7.3.7 shiki: ^0.10.1 @@ -680,7 +680,7 @@ importers: react-dom: ^18.1.0 solid-js: ^1.4.3 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: preact: 10.7.3 react: 18.1.0 @@ -724,7 +724,7 @@ importers: react-dom: ^18.1.0 solid-js: ^1.4.3 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: '@webcomponents/template-shadowroot': 0.1.0 lit: 2.2.5 @@ -756,7 +756,7 @@ importers: react-dom: ^18.1.0 solid-js: ^1.4.3 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: preact: 10.7.3 react: 18.1.0 @@ -785,7 +785,7 @@ importers: react-dom: ^18.1.0 solid-js: ^1.4.3 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: preact: 10.7.3 react: 18.1.0 @@ -814,7 +814,7 @@ importers: react-dom: ^18.1.0 solid-js: ^1.4.3 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: preact: 10.7.3 react: 18.1.0 @@ -843,7 +843,7 @@ importers: react-dom: ^18.1.0 solid-js: ^1.4.3 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: preact: 10.7.3 react: 18.1.0 @@ -872,7 +872,7 @@ importers: react-dom: ^18.1.0 solid-js: ^1.4.3 svelte: ^3.48.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: preact: 10.7.3 react: 18.1.0 @@ -1558,7 +1558,7 @@ importers: astro: workspace:* react: ^18.1.0 react-dom: ^18.1.0 - vue: ^3.2.36 + vue: ^3.2.37 dependencies: '@astrojs/react': link:../../../../integrations/react '@astrojs/vue': link:../../../../integrations/vue @@ -1850,7 +1850,7 @@ importers: specifiers: astro: workspace:* astro-scripts: workspace:* - esbuild: ^0.14.42 + esbuild: ^0.14.43 dependencies: esbuild: 0.14.43 devDependencies: @@ -1902,7 +1902,7 @@ importers: '@types/node': ^14.18.20 astro: workspace:* astro-scripts: workspace:* - esbuild: ^0.14.42 + esbuild: ^0.14.43 dependencies: '@astrojs/webapi': link:../../webapi esbuild: 0.14.43 @@ -2056,13 +2056,13 @@ importers: packages/integrations/svelte: specifiers: - '@sveltejs/vite-plugin-svelte': ^1.0.0-next.47 + '@sveltejs/vite-plugin-svelte': ^1.0.0-next.48 astro: workspace:* astro-scripts: workspace:* postcss-load-config: ^3.1.4 svelte: ^3.48.0 - svelte-preprocess: ^4.10.6 - vite: ^2.9.9 + svelte-preprocess: ^4.10.7 + vite: ^2.9.10 dependencies: '@sveltejs/vite-plugin-svelte': 1.0.0-next.48_svelte@3.48.0+vite@2.9.10 postcss-load-config: 3.1.4 @@ -2121,8 +2121,8 @@ importers: '@vitejs/plugin-vue': ^2.3.3 astro: workspace:* astro-scripts: workspace:* - vite: ^2.9.9 - vue: ^3.2.36 + vite: ^2.9.10 + vue: ^3.2.37 dependencies: '@vitejs/plugin-vue': 2.3.3_vite@2.9.10+vue@3.2.37 vite: 2.9.10 @@ -2148,7 +2148,7 @@ importers: astro-scripts: workspace:* chai: ^4.3.6 github-slugger: ^1.4.0 - mdast-util-mdx-expression: ^1.2.0 + mdast-util-mdx-expression: ^1.2.1 mdast-util-mdx-jsx: ^1.2.0 mdast-util-to-string: ^3.1.0 micromark-extension-mdx-expression: ^1.0.3 @@ -2175,7 +2175,7 @@ importers: acorn-jsx: 5.3.2_acorn@8.7.1 assert: 2.0.0 github-slugger: 1.4.0 - mdast-util-mdx-expression: 1.2.0 + mdast-util-mdx-expression: 1.2.1 mdast-util-mdx-jsx: 1.2.0 mdast-util-to-string: 3.1.0 micromark-extension-mdx-expression: 1.0.3 @@ -2209,7 +2209,7 @@ importers: packages/telemetry: specifiers: '@types/dlv': ^1.1.2 - '@types/node': ^14.18.20 + '@types/node': ^14.18.21 astro-scripts: workspace:* ci-info: ^3.3.1 debug: ^4.3.4 @@ -2243,7 +2243,7 @@ importers: '@rollup/plugin-typescript': ^8.3.2 '@types/chai': ^4.3.1 '@types/mocha': ^9.1.1 - '@types/node': ^14.18.20 + '@types/node': ^14.18.21 '@ungap/structured-clone': ^0.3.4 abort-controller: ^3.0.0 chai: ^4.3.6 @@ -2253,10 +2253,10 @@ importers: magic-string: ^0.25.9 mocha: ^9.2.2 node-fetch: ^3.2.5 - rollup: ^2.75.5 + rollup: ^2.75.6 rollup-plugin-terser: ^7.0.2 tslib: ^2.4.0 - typescript: ~4.7.2 + typescript: ~4.7.3 urlpattern-polyfill: ^1.0.0-rc5 web-streams-polyfill: ^3.2.1 dependencies: @@ -2288,8 +2288,8 @@ importers: specifiers: '@astrojs/webapi': workspace:* adm-zip: ^0.5.9 - arg: ^5.0.1 - esbuild: ^0.14.42 + arg: ^5.0.2 + esbuild: ^0.14.43 globby: ^12.2.0 kleur: ^4.1.4 svelte: ^3.48.0 @@ -10901,8 +10901,8 @@ packages: - supports-color dev: false - /mdast-util-mdx-expression/1.2.0: - resolution: {integrity: sha512-wb36oi09XxqO9RVqgfD+xo8a7xaNgS+01+k3v0GKW0X0bYbeBmUZz22Z/IJ8SuphVlG+DNgNo9VoEaUJ3PKfJQ==} + /mdast-util-mdx-expression/1.2.1: + resolution: {integrity: sha512-BtQwyalaq6jRjx0pagtuAwGrmzL1yInrfA4EJv7GOoiPOUbR4gr6h65I+G3WTh1/Cag2Eda4ip400Ch6CFmWiA==} dependencies: '@types/estree-jsx': 0.0.1 '@types/hast': 2.3.4 diff --git a/scripts/package.json b/scripts/package.json index 51ae419199730..6c125fbd19320 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -10,8 +10,8 @@ "dependencies": { "@astrojs/webapi": "workspace:*", "adm-zip": "^0.5.9", - "arg": "^5.0.1", - "esbuild": "^0.14.42", + "arg": "^5.0.2", + "esbuild": "^0.14.43", "globby": "^12.2.0", "kleur": "^4.1.4", "svelte": "^3.48.0", From 53bf0be280b9387c804098f75574b8402ebf8c0c Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Tue, 28 Jun 2022 08:39:10 -0500 Subject: [PATCH 58/58] chore(lint): fix lint issues (#3743) Co-authored-by: Nate Moore --- packages/create-astro/src/index.ts | 2 +- packages/integrations/prefetch/src/client.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index df676fbfbd0f3..fba9b710cfe72 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -14,7 +14,7 @@ import { TEMPLATES } from './templates.js'; function wait(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } -function logAndWait(message: string, ms: number = 100) { +function logAndWait(message: string, ms = 100) { console.log(message); return wait(ms); } diff --git a/packages/integrations/prefetch/src/client.ts b/packages/integrations/prefetch/src/client.ts index 9f951c8ddb2df..fae2db54a65fe 100644 --- a/packages/integrations/prefetch/src/client.ts +++ b/packages/integrations/prefetch/src/client.ts @@ -1,4 +1,4 @@ -/// +import "../@types/network-information.d.ts"; import throttles from 'throttles'; import requestIdleCallback from './requestIdleCallback.js'; @@ -53,7 +53,7 @@ async function preloadHref(link: HTMLAnchorElement) { const html = parser.parseFromString(contents, 'text/html'); const styles = Array.from(html.querySelectorAll('link[rel="stylesheet"]')); - await Promise.all(styles.map(({ href }) => fetch(href))); + await Promise.all(styles.map((el) => fetch(el.href))); } catch {} }