summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar ematipico <ematipico@users.noreply.github.com> 2023-08-22 10:19:52 +0000
committerGravatar astrobot-houston <fred+astrobot@astro.build> 2023-08-22 10:19:52 +0000
commitf224c539c880add0490b442b4429bdf73b58f6ff (patch)
tree48923a52763073776332147447c9628d42b694d1
parent5821323285646aee7ff9194a505f708028e4db57 (diff)
downloadastro-f224c539c880add0490b442b4429bdf73b58f6ff.tar.gz
astro-f224c539c880add0490b442b4429bdf73b58f6ff.tar.zst
astro-f224c539c880add0490b442b4429bdf73b58f6ff.zip
[ci] format
-rw-r--r--packages/astro/src/core/config/schema.ts67
-rw-r--r--packages/astro/test/units/config/config-validate.test.js10
2 files changed, 42 insertions, 35 deletions
diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts
index 174bfab3b..c051903d3 100644
--- a/packages/astro/src/core/config/schema.ts
+++ b/packages/astro/src/core/config/schema.ts
@@ -376,43 +376,46 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: string) {
.optional()
.default({})
),
- }).transform((config) => {
- // If the user changed outDir but not build.server, build.config, adjust so those
- // are relative to the outDir, as is the expected default.
- if (
- !config.build.server.toString().startsWith(config.outDir.toString()) &&
- config.build.server.toString().endsWith('dist/server/')
- ) {
- config.build.server = new URL('./dist/server/', config.outDir);
- }
- if (
- !config.build.client.toString().startsWith(config.outDir.toString()) &&
- config.build.client.toString().endsWith('dist/client/')
- ) {
- config.build.client = new URL('./dist/client/', config.outDir);
- }
- const trimmedBase = trimSlashes(config.base);
+ })
+ .transform((config) => {
+ // If the user changed outDir but not build.server, build.config, adjust so those
+ // are relative to the outDir, as is the expected default.
+ if (
+ !config.build.server.toString().startsWith(config.outDir.toString()) &&
+ config.build.server.toString().endsWith('dist/server/')
+ ) {
+ config.build.server = new URL('./dist/server/', config.outDir);
+ }
+ if (
+ !config.build.client.toString().startsWith(config.outDir.toString()) &&
+ config.build.client.toString().endsWith('dist/client/')
+ ) {
+ config.build.client = new URL('./dist/client/', config.outDir);
+ }
+ const trimmedBase = trimSlashes(config.base);
- // If there is no base but there is a base for site config, warn.
- const sitePathname = config.site && new URL(config.site).pathname;
- if (!trimmedBase.length && sitePathname && sitePathname !== '/') {
- config.base = sitePathname;
- /* eslint-disable no-console */
- console.warn(`The site configuration value includes a pathname of ${sitePathname} but there is no base configuration.
+ // If there is no base but there is a base for site config, warn.
+ const sitePathname = config.site && new URL(config.site).pathname;
+ if (!trimmedBase.length && sitePathname && sitePathname !== '/') {
+ config.base = sitePathname;
+ /* eslint-disable no-console */
+ 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.`);
- }
+ }
- if (trimmedBase.length && config.trailingSlash === 'never') {
- config.base = prependForwardSlash(trimmedBase);
- } else {
- config.base = prependForwardSlash(appendForwardSlash(trimmedBase));
- }
+ if (trimmedBase.length && config.trailingSlash === 'never') {
+ config.base = prependForwardSlash(trimmedBase);
+ } else {
+ config.base = prependForwardSlash(appendForwardSlash(trimmedBase));
+ }
- return config;
- }).refine((obj) => !obj.outDir.toString().startsWith(obj.publicDir.toString()), {
- message: '`outDir` must not be placed inside `publicDir` to prevent an infinite loop. Please adjust the directory configuration and try again'
- });
+ return config;
+ })
+ .refine((obj) => !obj.outDir.toString().startsWith(obj.publicDir.toString()), {
+ message:
+ '`outDir` must not be placed inside `publicDir` to prevent an infinite loop. Please adjust the directory configuration and try again',
+ });
return AstroConfigRelativeSchema;
}
diff --git a/packages/astro/test/units/config/config-validate.test.js b/packages/astro/test/units/config/config-validate.test.js
index b9b5edd77..604836747 100644
--- a/packages/astro/test/units/config/config-validate.test.js
+++ b/packages/astro/test/units/config/config-validate.test.js
@@ -69,9 +69,13 @@ describe('Config Validation', () => {
expect(configError).to.be.not.instanceOf(Error);
});
it('Error when outDir is placed within publicDir', async () => {
- const configError = await validateConfig({ outDir: './public/dist' }, process.cwd()).catch((err) => err);
+ const configError = await validateConfig({ outDir: './public/dist' }, process.cwd()).catch(
+ (err) => err
+ );
expect(configError instanceof z.ZodError).to.equal(true);
- expect(configError.errors[0].message).to.equal('`outDir` must not be placed inside `publicDir` to prevent an infinite loop. \
-Please adjust the directory configuration and try again')
+ expect(configError.errors[0].message).to.equal(
+ '`outDir` must not be placed inside `publicDir` to prevent an infinite loop. \
+Please adjust the directory configuration and try again'
+ );
});
});