Include partytown scripts in SSR manifest (#3686)
* Include partytown scripts in SSR manifst * Adds a changeset
This commit is contained in:
parent
aa883a50c8
commit
b36ecb717e
7 changed files with 79 additions and 10 deletions
5
.changeset/cuddly-llamas-arrive.md
Normal file
5
.changeset/cuddly-llamas-arrive.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/partytown': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Include partytown scripts in SSR manifest
|
7
packages/astro/test/fixtures/ssr-partytown/astro.config.mjs
vendored
Normal file
7
packages/astro/test/fixtures/ssr-partytown/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import partytown from '@astrojs/partytown';
|
||||||
|
|
||||||
|
// https://astro.build/config
|
||||||
|
export default defineConfig({
|
||||||
|
integrations: [partytown()],
|
||||||
|
});
|
9
packages/astro/test/fixtures/ssr-partytown/package.json
vendored
Normal file
9
packages/astro/test/fixtures/ssr-partytown/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "@test/ssr-partytown",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"astro": "workspace:*",
|
||||||
|
"@astrojs/partytown": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
6
packages/astro/test/fixtures/ssr-partytown/src/pages/index.astro
vendored
Normal file
6
packages/astro/test/fixtures/ssr-partytown/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<html>
|
||||||
|
<head><title>testing</title></head>
|
||||||
|
<body>
|
||||||
|
<h1>testing</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
34
packages/astro/test/ssr-partytown.test.js
Normal file
34
packages/astro/test/ssr-partytown.test.js
Normal file
|
@ -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');
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,8 +1,9 @@
|
||||||
import { partytownSnippet } from '@builder.io/partytown/integration';
|
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 type { AstroConfig, AstroIntegration } from 'astro';
|
||||||
import { createRequire } from 'module';
|
import { createRequire } from 'module';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import sirv from './sirv.js';
|
import sirv from './sirv.js';
|
||||||
const resolve = createRequire(import.meta.url).resolve;
|
const resolve = createRequire(import.meta.url).resolve;
|
||||||
|
@ -50,6 +51,14 @@ export default function createPlugin(options: PartytownOptions): AstroIntegratio
|
||||||
debugDir: false,
|
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}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1601,6 +1601,14 @@ importers:
|
||||||
dependencies:
|
dependencies:
|
||||||
astro: link:../../..
|
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:
|
packages/astro/test/fixtures/ssr-scripts:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@astrojs/preact': 'workspace:'
|
'@astrojs/preact': 'workspace:'
|
||||||
|
@ -8432,11 +8440,6 @@ packages:
|
||||||
|
|
||||||
/debug/3.2.7:
|
/debug/3.2.7:
|
||||||
resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==}
|
resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==}
|
||||||
peerDependencies:
|
|
||||||
supports-color: '*'
|
|
||||||
peerDependenciesMeta:
|
|
||||||
supports-color:
|
|
||||||
optional: true
|
|
||||||
dependencies:
|
dependencies:
|
||||||
ms: 2.1.3
|
ms: 2.1.3
|
||||||
dev: false
|
dev: false
|
||||||
|
@ -11358,8 +11361,6 @@ packages:
|
||||||
debug: 3.2.7
|
debug: 3.2.7
|
||||||
iconv-lite: 0.4.24
|
iconv-lite: 0.4.24
|
||||||
sax: 1.2.4
|
sax: 1.2.4
|
||||||
transitivePeerDependencies:
|
|
||||||
- supports-color
|
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/netmask/2.0.2:
|
/netmask/2.0.2:
|
||||||
|
@ -11443,8 +11444,6 @@ packages:
|
||||||
rimraf: 2.7.1
|
rimraf: 2.7.1
|
||||||
semver: 5.7.1
|
semver: 5.7.1
|
||||||
tar: 4.4.19
|
tar: 4.4.19
|
||||||
transitivePeerDependencies:
|
|
||||||
- supports-color
|
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/node-releases/2.0.5:
|
/node-releases/2.0.5:
|
||||||
|
|
Loading…
Reference in a new issue