Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored and actions-user committed Mar 9, 2022
1 parent 72c2c86 commit 43a5c06
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 80 deletions.
46 changes: 23 additions & 23 deletions packages/astro/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

```json
{
"scripts": {
"build": "astro build --legacy-build"
}
"scripts": {
"build": "astro build --legacy-build"
}
}
```

Expand Down Expand Up @@ -126,12 +126,12 @@
```typescript
// src/pages/company.json.ts
export async function get() {
return {
body: JSON.stringify({
name: 'Astro Technology Company',
url: 'https://astro.build/',
}),
};
return {
body: JSON.stringify({
name: 'Astro Technology Company',
url: 'https://astro.build/',
}),
};
}
```

Expand Down Expand Up @@ -293,12 +293,12 @@
```typescript
// src/pages/company.json.ts
export async function get() {
return {
body: JSON.stringify({
name: 'Astro Technology Company',
url: 'https://astro.build/',
}),
};
return {
body: JSON.stringify({
name: 'Astro Technology Company',
url: 'https://astro.build/',
}),
};
}
```
Expand Down Expand Up @@ -1653,10 +1653,10 @@ For convenience, you may now also move your `astro.config.js` file to a top-leve

```js
export default {
markdownOptions: {
remarkPlugins: ['remark-slug', ['remark-autolink-headings', { behavior: 'prepend' }]],
rehypePlugins: ['rehype-slug', ['rehype-autolink-headings', { behavior: 'prepend' }]],
},
markdownOptions: {
remarkPlugins: ['remark-slug', ['remark-autolink-headings', { behavior: 'prepend' }]],
rehypePlugins: ['rehype-slug', ['rehype-autolink-headings', { behavior: 'prepend' }]],
},
};
```

Expand All @@ -1676,10 +1676,10 @@ For convenience, you may now also move your `astro.config.js` file to a top-leve

```js
export default {
name: '@matthewp/my-renderer',
server: './server.js',
client: './client.js',
hydrationPolyfills: ['./my-polyfill.js'],
name: '@matthewp/my-renderer',
server: './server.js',
client: './client.js',
hydrationPolyfills: ['./my-polyfill.js'],
};
```

Expand Down
5 changes: 2 additions & 3 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,14 @@ function getOutFolder(astroConfig: AstroConfig, pathname: string, routeType: Rou
case 'page':
switch (astroConfig.buildOptions.pageUrlFormat) {
case 'directory': {
if(STATUS_CODE_PAGES.has(pathname)) {
if (STATUS_CODE_PAGES.has(pathname)) {
return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot);
}
return new URL('.' + appendForwardSlash(pathname), outRoot);
}
case 'file': {
return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot);
}

}
}
}
Expand All @@ -503,7 +502,7 @@ function getOutFile(astroConfig: AstroConfig, outFolder: URL, pathname: string,
case 'page':
switch (astroConfig.buildOptions.pageUrlFormat) {
case 'directory': {
if(STATUS_CODE_PAGES.has(pathname)) {
if (STATUS_CODE_PAGES.has(pathname)) {
const baseName = npath.basename(pathname);
return new URL('./' + (baseName || 'index') + '.html', outFolder);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ function addTrailingSlash(str: string): string {

/** Convert the generic "yargs" flag object into our own, custom TypeScript object. */
function resolveFlags(flags: Partial<Flags>): CLIFlags {
if(flags.experimentalStaticBuild) {
if (flags.experimentalStaticBuild) {
// eslint-disable-next-line no-console
console.warn(`Passing --experimental-static-build is no longer necessary and is now the default. The flag will be removed in a future version of Astro.`)
console.warn(`Passing --experimental-static-build is no longer necessary and is now the default. The flag will be removed in a future version of Astro.`);
}

return {
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/src/core/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
export default async function preview(config: AstroConfig, { logging }: PreviewOptions): Promise<PreviewServer> {
const startServerTime = performance.now();
const defaultOrigin = 'http:https://localhost';
const trailingSlash = config.devOptions.trailingSlash
const trailingSlash = config.devOptions.trailingSlash;
/** Base request URL. */
let baseURL = new URL(config.buildOptions.site || '/', defaultOrigin);
const staticFileServer = sirv(fileURLToPath(config.dist), {
etag: true,
maxAge: 0,
})
});
// Create the preview server, send static files out of the `dist/` directory.
const server = http.createServer((req, res) => {
const requestURL = new URL(req.url as string, defaultOrigin);
Expand All @@ -56,7 +56,7 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
function sendError(message: string) {
res.statusCode = 404;
res.end(notFoundTemplate(pathname, message));
};
}

switch (true) {
case hasTrailingSlash && trailingSlash == 'never' && !isRoot:
Expand All @@ -67,7 +67,7 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
return;
default: {
// HACK: rewrite req.url so that sirv finds the file
req.url = '/' + req.url?.replace(baseURL.pathname, '')
req.url = '/' + req.url?.replace(baseURL.pathname, '');
staticFileServer(req, res, () => sendError('Not Found'));
return;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ export default async function preview(config: AstroConfig, { logging }: PreviewO
server: httpServer!,
stop: async () => {
await new Promise((resolve, reject) => {
httpServer.close((err) => err ? reject(err) : resolve(undefined));
httpServer.close((err) => (err ? reject(err) : resolve(undefined)));
});
},
};
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/core/render/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ export async function render(opts: RenderOptions): Promise<string> {
let html = await renderToString(result, Component, pageProps, null);

// handle final head injection if it hasn't happened already
if (html.indexOf("<!--astro:head:injected-->") == -1) {
html = await renderHead(result) + html;
if (html.indexOf('<!--astro:head:injected-->') == -1) {
html = (await renderHead(result)) + html;
}
// cleanup internal state flags
html = html.replace("<!--astro:head:injected-->", '');
html = html.replace('<!--astro:head:injected-->', '');

// inject <!doctype html> if missing (TODO: is a more robust check needed for comments, etc.?)
if (!legacyBuild && !/<!doctype html/i.test(html)) {
Expand Down
9 changes: 3 additions & 6 deletions packages/astro/src/core/render/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
const legacy = astroConfig.buildOptions.legacyBuild;

// Add hoisted script tags
const scripts = createModuleScriptElementWithSrcSet(
!legacy && mod.hasOwnProperty('$$metadata') ? Array.from(mod.$$metadata.hoistedScriptPaths()) : []
);
const scripts = createModuleScriptElementWithSrcSet(!legacy && mod.hasOwnProperty('$$metadata') ? Array.from(mod.$$metadata.hoistedScriptPaths()) : []);

// Inject HMR scripts
if (mod.hasOwnProperty('$$metadata') && mode === 'development' && !legacy) {
Expand All @@ -69,7 +67,7 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO

// Pass framework CSS in as link tags to be appended to the page.
let links = new Set<SSRElement>();
if(!legacy) {
if (!legacy) {
[...getStylesForURL(filePath, viteServer)].forEach((href) => {
if (mode === 'development' && svelteStylesRE.test(href)) {
scripts.add({
Expand Down Expand Up @@ -136,7 +134,7 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
}

// inject CSS
if(legacy) {
if (legacy) {
[...getStylesForURL(filePath, viteServer)].forEach((href) => {
if (mode === 'development' && svelteStylesRE.test(href)) {
tags.push({
Expand All @@ -158,7 +156,6 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
});
}


// add injected tags
content = injectTags(content, tags);

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/render/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ ${extra}`
_metadata: {
renderers,
pathname,
legacyBuild
legacyBuild,
},
};

Expand Down
5 changes: 1 addition & 4 deletions packages/astro/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@ export function createAstro(filePathname: string, _site: string, projectRootStr:
};
}

const toAttributeString = (value: any, shouldEscape = true) => shouldEscape ?
String(value).replace(/&/g, '&#38;').replace(/"/g, '&#34;') :
value;
const toAttributeString = (value: any, shouldEscape = true) => (shouldEscape ? String(value).replace(/&/g, '&#38;').replace(/"/g, '&#34;') : value);

const STATIC_DIRECTIVES = new Set(['set:html', 'set:text']);

Expand Down Expand Up @@ -439,7 +437,6 @@ const uniqueElements = (item: any, index: number, all: any[]) => {
return index === all.findIndex((i) => JSON.stringify(i.props) === props && i.children == children);
};


// Renders a page to completion by first calling the factory callback, waiting for its result, and then appending
// styles and scripts into the head.
export async function renderHead(result: SSRResult) {
Expand Down
32 changes: 17 additions & 15 deletions packages/astro/src/vite-plugin-env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,31 @@ export default function envVitePlugin({ config: astroConfig }: EnvPluginOptions)
async transform(source, id, options) {
const ssr = options?.ssr === true;

if(!ssr) {
if (!ssr) {
return source;
}

if(!source.includes('import.meta') || !/\benv\b/.test(source)) {
if (!source.includes('import.meta') || !/\benv\b/.test(source)) {
return source;
}

if (typeof privateEnv === 'undefined') {
privateEnv = getPrivateEnv(config, astroConfig);
if(privateEnv) {
const entries = Object.entries(privateEnv).map(([key, value]) => ([`import.meta.env.${key}`, value]));
if (privateEnv) {
const entries = Object.entries(privateEnv).map(([key, value]) => [`import.meta.env.${key}`, value]);
replacements = Object.fromEntries(entries);
pattern = new RegExp(
// Do not allow preceding '.', but do allow preceding '...' for spread operations
'(?<!(?<!\\.\\.)\\.)\\b(' +
Object.keys(replacements)
.map((str) => {
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
Object.keys(replacements)
.map((str) => {
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
})
.join('|') +
// prevent trailing assignments
')\\b(?!\\s*?=[^=])', 'g');
.join('|') +
// prevent trailing assignments
')\\b(?!\\s*?=[^=])',
'g'
);
}
}

Expand All @@ -86,13 +88,13 @@ export default function envVitePlugin({ config: astroConfig }: EnvPluginOptions)

// Find matches for *private* env and do our own replacement.
const s = new MagicString(source);
let match: RegExpExecArray | null
let match: RegExpExecArray | null;

while ((match = pattern.exec(source))) {
const start = match.index
const end = start + match[0].length
const replacement = '' + replacements[match[1]]
s.overwrite(start, end, replacement)
const start = match.index;
const end = start + match[0].length;
const replacement = '' + replacements[match[1]];
s.overwrite(start, end, replacement);
}

return s.toString();
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/test/0-css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ describe('CSS', function () {
renderers: ['@astrojs/renderer-react', '@astrojs/renderer-svelte', '@astrojs/renderer-vue'],
vite: {
build: {
assetsInlineLimit: 0
}
}
assetsInlineLimit: 0,
},
},
});
});

Expand Down
8 changes: 4 additions & 4 deletions packages/astro/test/astro-assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe('Assets', () => {
projectRoot: './fixtures/astro-assets/',
vite: {
build: {
assetsInlineLimit: 0
}
}
assetsInlineLimit: 0,
},
},
});
await fixture.build();
});
Expand All @@ -26,7 +26,7 @@ describe('Assets', () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const imgPath = $('img').attr('src');
const data = await fixture.readFile( imgPath);
const data = await fixture.readFile(imgPath);
expect(!!data).to.equal(true);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/astro-global.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Astro.*', () => {
projectRoot: './fixtures/astro-global/',
buildOptions: {
site: 'https://mysite.dev/blog/',
sitemap: false
sitemap: false,
},
});
await fixture.build();
Expand Down
12 changes: 7 additions & 5 deletions packages/astro/test/astro-partial-html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ describe('Partial HTML ', async () => {

// test 2: correct CSS present
const link = $('link').attr('href');
const css = await fixture.fetch(link, {
headers: {
accept: 'text/css'
}
}).then(res => res.text());
const css = await fixture
.fetch(link, {
headers: {
accept: 'text/css',
},
})
.then((res) => res.text());
expect(css).to.match(/\.astro-[^{]+{color:red;}/);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/astro/test/astro-scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('Scripts (hoisted and not)', () => {
projectRoot: './fixtures/astro-scripts/',
vite: {
build: {
assetsInlineLimit: 0
}
}
assetsInlineLimit: 0,
},
},
});
await fixture.build();
});
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('Scripts (hoisted and not)', () => {
// test 2: attr removed
expect($('script').attr('data-astro')).to.equal(undefined);

const entryURL = $('script').attr('src');
const entryURL = $('script').attr('src');
const inlineEntryJS = await fixture.readFile(entryURL);

// test 3: the JS exists
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/static-build-frameworks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Static build - frameworks', () => {
});

// SKIP: Lit polyfills the server in a way that breaks `sass` require/import
// Leads to CI bugs like: "Cannot read properties of undefined (reading 'length')"
// Leads to CI bugs like: "Cannot read properties of undefined (reading 'length')"
it.skip('can build lit', async () => {
const html = await fixture.readFile('/lit/index.html');
expect(html).to.be.a('string');
Expand Down

0 comments on commit 43a5c06

Please sign in to comment.