Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Mar 18, 2022
1 parent 001499b commit aa961a5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
12 changes: 11 additions & 1 deletion packages/astro/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ export const AstroConfigSchema = z.object({
.optional()
.default('./dist')
.transform((val) => new URL(val)),
integrations: z.array(z.any()).default([]),
integrations: z.preprocess(
// preprocess
(val) => Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val,
// validate
z.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) })).default([])
// validate: first-party integrations only
// TODO: Add `To use 3rd-party integrations or to create your own, use the --experimental-integrations flag.`,
.refine((arr) => arr.every(integration => integration.name.startsWith('@astrojs/')), {
message: `Astro integrations are still experimental, and only official integrations are currently supported`
}
)),
styleOptions: z
.object({
postcss: z
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function jsx({ config, logging }: AstroPluginJSXOptions): Plugin
throw new Error(
`${colors.yellow(
id
)}\nUnable to resolve a renderer that handles JSX transforms! Please include a \`renderer\` plugin which supports JSX in your \`astro.config.mjs\` file.`
)}\nUnable to resolve a JSX renderer! Did you forget to include one? Add a JSX integration like \`@astrojs/react\` to your \`astro.config.mjs\` file.`
);
}
for (const [importSource, renderer] of possibleRenderers) {
Expand Down
24 changes: 24 additions & 0 deletions packages/astro/test/config-validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,31 @@ describe('Config Validation', () => {
expect(formattedError).to.equal(
`[config] Astro found issue(s) with your configuration:
! pages Expected string, received object.
! integrations.0 Expected object, received number.
! buildOptions.pageUrlFormat Invalid input.`
);
});

it('ignores falsey "integration" values', async () => {
const result = await validateConfig({ integrations: [0, false, null, undefined] }, process.cwd());
expect(result.integrations).to.deep.equal([]);
});
it('normalizes "integration" values', async () => {
const result = await validateConfig({ integrations: [{ name: '@astrojs/a' }] }, process.cwd());
expect(result.integrations).to.deep.equal([{ name: '@astrojs/a', hooks: {} }]);
});
it('flattens array "integration" values', async () => {
const result = await validateConfig({ integrations: [{ name: '@astrojs/a' }, [{ name: '@astrojs/b' }, { name: '@astrojs/c' }]] }, process.cwd());
expect(result.integrations).to.deep.equal([{ name: '@astrojs/a', hooks: {} }, { name: '@astrojs/b', hooks: {} }, { name: '@astrojs/c', hooks: {} }]);
});
it('blocks third-party "integration" values', async () => {
const configError = await validateConfig({ integrations: [{ name: '@my-plugin/a' }]}, process.cwd()).catch((err) => err);
expect(configError instanceof z.ZodError).to.equal(true);
const formattedError = stripAnsi(formatConfigError(configError));
expect(formattedError).to.equal(
`[config] Astro found issue(s) with your configuration:
! integrations Astro integrations are still experimental, and only official integrations are currently supported.`
);
});

});
3 changes: 3 additions & 0 deletions packages/astro/test/tailwindcss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('Tailwind', () => {
before(async () => {
devServer = await fixture.startDevServer();
const html = await fixture.fetch('/').then((res) => res.text());
console.log(html);
$ = cheerio.load(html);
});

Expand All @@ -74,10 +75,12 @@ describe('Tailwind', () => {

it('resolves CSS in src/styles', async () => {
const href = $(`link[href$="/src/styles/global.css"]`).attr('href');
console.log({href});
const res = await fixture.fetch(href);
expect(res.status).to.equal(200);

const text = await res.text();
console.log({text});

expect(text, 'includes used component classes').to.match(/\.bg-purple-600/);

Expand Down
5 changes: 4 additions & 1 deletion packages/integrations/tailwind/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { AstroIntegration } from 'astro';
import {fileURLToPath} from 'url';
import path from 'path';
import tailwindPlugin from 'tailwindcss';
import autoprefixerPlugin from 'autoprefixer';

Expand All @@ -8,7 +10,7 @@ function getDefaultTailwindConfig(srcUrl: URL) {
extend: {},
},
plugins: [],
content: [`${srcUrl.pathname}/**/*.{astro,html,js,jsx,svelte,ts,tsx,vue}`],
content: [path.join(fileURLToPath(srcUrl), `**`, `*.{astro,html,js,jsx,svelte,ts,tsx,vue}`)],
};
}

Expand All @@ -17,6 +19,7 @@ export default function (): AstroIntegration {
name: '@astrojs/tailwind',
hooks: {
'astro:config:setup': ({ config, injectScript }) => {
console.log({TWCONTENT: getDefaultTailwindConfig(config.src)});
// Inject the Tailwind postcss plugin
config.styleOptions.postcss.plugins.push(tailwindPlugin(getDefaultTailwindConfig(config.src)));
config.styleOptions.postcss.plugins.push(autoprefixerPlugin);
Expand Down

0 comments on commit aa961a5

Please sign in to comment.