[ci] format

This commit is contained in:
matthewp 2022-11-11 19:36:40 +00:00 committed by fredkbot
parent bee8c14afd
commit 591153f457
7 changed files with 33 additions and 27 deletions

View file

@ -14,7 +14,6 @@ import type {
} from '../../@types/astro'; } from '../../@types/astro';
import type { BuildInternals } from '../../core/build/internal.js'; import type { BuildInternals } from '../../core/build/internal.js';
import { import {
joinPaths,
prependForwardSlash, prependForwardSlash,
removeLeadingForwardSlash, removeLeadingForwardSlash,
removeTrailingForwardSlash, removeTrailingForwardSlash,
@ -292,7 +291,10 @@ async function generatePath(
debug('build', `Generating: ${pathname}`); debug('build', `Generating: ${pathname}`);
const links = createLinkStylesheetElementSet(linkIds, settings.config.base); const links = createLinkStylesheetElementSet(linkIds, settings.config.base);
const scripts = createModuleScriptsSet(hoistedScripts ? [hoistedScripts] : [], settings.config.base); const scripts = createModuleScriptsSet(
hoistedScripts ? [hoistedScripts] : [],
settings.config.base
);
if (settings.scripts.some((script) => script.stage === 'page')) { if (settings.scripts.some((script) => script.stage === 'page')) {
const hashedFilePath = internals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID); const hashedFilePath = internals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID);

View file

@ -41,7 +41,10 @@ export function vitePluginHoistedScripts(
async generateBundle(_options, bundle) { async generateBundle(_options, bundle) {
let assetInlineLimit = 4096; let assetInlineLimit = 4096;
if(settings.config.vite?.build && settings.config.vite.build.assetsInlineLimit !== undefined) { if (
settings.config.vite?.build &&
settings.config.vite.build.assetsInlineLimit !== undefined
) {
assetInlineLimit = settings.config.vite?.build.assetsInlineLimit; assetInlineLimit = settings.config.vite?.build.assetsInlineLimit;
} }

View file

@ -139,15 +139,16 @@ function buildManifest(
for (const pageData of eachPageData(internals)) { for (const pageData of eachPageData(internals)) {
const scripts: SerializedRouteInfo['scripts'] = []; const scripts: SerializedRouteInfo['scripts'] = [];
if (pageData.hoistedScript) { if (pageData.hoistedScript) {
scripts.unshift(Object.assign({}, pageData.hoistedScript, { scripts.unshift(
value: joinBase(pageData.hoistedScript.value) Object.assign({}, pageData.hoistedScript, {
})); value: joinBase(pageData.hoistedScript.value),
})
);
} }
if (settings.scripts.some((script) => script.stage === 'page')) { if (settings.scripts.some((script) => script.stage === 'page')) {
scripts.push({ type: 'external', value: entryModules[PAGE_SCRIPT_ID] }); scripts.push({ type: 'external', value: entryModules[PAGE_SCRIPT_ID] });
} }
const links = sortedCSS(pageData).map((pth) => joinBase(pth)); const links = sortedCSS(pageData).map((pth) => joinBase(pth));
routes.push({ routes.push({

View file

@ -326,19 +326,19 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: URL) {
// If there is no base but there is a base for site config, warn. // If there is no base but there is a base for site config, warn.
const sitePathname = config.site && new URL(config.site).pathname; const sitePathname = config.site && new URL(config.site).pathname;
if(!trimmedBase.length && sitePathname && sitePathname !== '/') { if (!trimmedBase.length && sitePathname && sitePathname !== '/') {
config.base = sitePathname; config.base = sitePathname;
/* eslint-disable no-console */ /* eslint-disable no-console */
console.warn(`The site configuration value includes a pathname of ${sitePathname} but there is no base configuration. console.warn(`The site configuration value includes a pathname of ${sitePathname} but there is no base configuration.
A future version of Astro will stop using the site pathname when producing <link> and <script> tags. Set your site's base with the base configuration.`) A future version of Astro will stop using the site pathname when producing <link> and <script> tags. Set your site's base with the base configuration.`);
} }
if(trimmedBase.length && config.trailingSlash === 'never') { if (trimmedBase.length && config.trailingSlash === 'never') {
config.base = prependForwardSlash(trimmedBase); config.base = prependForwardSlash(trimmedBase);
} else { } else {
config.base = prependForwardSlash(appendForwardSlash(trimmedBase)); config.base = prependForwardSlash(appendForwardSlash(trimmedBase));
} }
return config; return config;
}); });

View file

@ -11,12 +11,12 @@ describe('Asset URL resolution in build', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/asset-url-base/', root: './fixtures/asset-url-base/',
site: 'http://example.com/sub/path/' site: 'http://example.com/sub/path/',
}); });
await fixture.build(); await fixture.build();
}); });
it('does not include the site\'s subpath', async () => { it("does not include the site's subpath", async () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
const href = $('link[rel=stylesheet]').attr('href'); const href = $('link[rel=stylesheet]').attr('href');
@ -29,12 +29,12 @@ describe('Asset URL resolution in build', () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/asset-url-base/', root: './fixtures/asset-url-base/',
site: 'http://example.com/sub/path/', site: 'http://example.com/sub/path/',
base: '/another/base/' base: '/another/base/',
}); });
await fixture.build(); await fixture.build();
}); });
it('does not include the site\'s subpath', async () => { it("does not include the site's subpath", async () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
const href = $('link[rel=stylesheet]').attr('href'); const href = $('link[rel=stylesheet]').attr('href');

View file

@ -116,18 +116,18 @@ describe('Scripts (hoisted and not)', () => {
it('External page builds the hoisted scripts to a single bundle', async () => { it('External page builds the hoisted scripts to a single bundle', async () => {
let external = await fixture.readFile('/external/index.html'); let external = await fixture.readFile('/external/index.html');
let $ = cheerio.load(external); let $ = cheerio.load(external);
// test 1: there are two scripts // test 1: there are two scripts
expect($('script')).to.have.lengthOf(2); expect($('script')).to.have.lengthOf(2);
let el = $('script').get(1); let el = $('script').get(1);
expect($(el).attr('src')).to.equal(undefined, 'This should have been inlined'); expect($(el).attr('src')).to.equal(undefined, 'This should have been inlined');
let externalEntryJS = $(el).text(); let externalEntryJS = $(el).text();
// test 2: the JS exists // test 2: the JS exists
expect(externalEntryJS).to.be.ok; expect(externalEntryJS).to.be.ok;
}); });
}) });
}); });
describe('Dev', () => { describe('Dev', () => {

View file

@ -15,9 +15,9 @@ describe('Using Astro.request in SSR', () => {
base: '/subpath/', base: '/subpath/',
vite: { vite: {
build: { build: {
assetsInlineLimit: 0 assetsInlineLimit: 0,
} },
} },
}); });
await fixture.build(); await fixture.build();
}); });