Removes snowpack warning suppression (#504)

* Start of warnings

* Provide knownEntrypoints by renderers

This allows renderers to provide knownEntrypoints that will be forwarded to snowpack. This gets rid of renderer-specific warnings and allows us to remove the snowpack logging hacks we were doing.

* Adds a changeset
This commit is contained in:
Matthew Phillips 2021-06-21 15:34:22 -04:00 committed by GitHub
parent b2a72ccac4
commit 0abd251cda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 21 deletions

View file

@ -0,0 +1,8 @@
---
'astro': patch
'@astrojs/renderer-preact': patch
'@astrojs/renderer-react': patch
'@astrojs/renderer-vue': patch
---
Allows renderers to provide knownEntrypoint config values

View file

@ -100,6 +100,7 @@ export default {
server: './server.js', // relative path to the server entrypoint
snowpackPlugin: '@snowpack/plugin-xxx', // optional, the name of a snowpack plugin to inject
snowpackPluginOptions: { example: true }, // optional, any options to be forwarded to the snowpack plugin
knownEntrypoint: ['framework'] // optional, entrypoint modules that will be used by compiled source
};
```

View file

@ -23,7 +23,13 @@ module.exports = (snowpackConfig, options = {}) => {
let hmrPort = DEFAULT_HMR_PORT;
return {
name: 'snowpack-astro',
knownEntrypoints: ['astro/dist/internal/h.js', 'astro/components/Prism.astro'],
knownEntrypoints: [
'astro/dist/internal/h.js',
'astro/components/Prism.astro',
'shorthash',
'estree-util-value-to-estree',
'astring'
],
resolve: {
input: ['.astro', '.md'],
output: ['.js', '.css'],

View file

@ -12,6 +12,7 @@ interface RendererInstance {
snowpackPlugin: RendererSnowpackPlugin;
client: string;
server: string;
knownEntrypoints: string[] | undefined;
}
const CONFIG_MODULE_BASE_NAME = '__astro_config.js';
@ -96,6 +97,7 @@ export class ConfigManager {
snowpackPlugin,
client: path.join(name, raw.client),
server: path.join(name, raw.server),
knownEntrypoints: raw.knownEntrypoints
};
});

View file

@ -345,7 +345,13 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO
// Make sure that Snowpack builds our renderer plugins
const rendererInstances = await configManager.buildRendererInstances();
const knownEntrypoints = [].concat(...(rendererInstances.map((renderer) => [renderer.server, renderer.client]) as any));
const knownEntrypoints: string[] = [];
for(const renderer of rendererInstances) {
knownEntrypoints.push(renderer.server, renderer.client);
if(renderer.knownEntrypoints) {
knownEntrypoints.push(...renderer.knownEntrypoints);
}
}
const rendererSnowpackPlugins = rendererInstances.filter((renderer) => renderer.snowpackPlugin).map((renderer) => renderer.snowpackPlugin) as string | [string, any];
const snowpackConfig = await loadConfiguration({

View file

@ -1,27 +1,8 @@
import { logger as snowpackLogger } from 'snowpack';
import { defaultLogLevel } from './logger.js';
const neverWarn = new RegExp(
'(' +
/(run "snowpack init" to create a project config file.)|/.source +
/(Unscannable package import found.)|/.source +
/(Cannot call a namespace \('loadLanguages'\))|/.source +
/('default' is imported from external module 'node-fetch' but never used)/.source +
')'
);
export function configureSnowpackLogger(logger: typeof snowpackLogger) {
const messageCache = new Set<string>();
if (defaultLogLevel === 'debug') {
logger.level = 'debug';
}
logger.on('warn', (message) => {
// Silence this output message, since it doesn't make sense for Astro.
if (neverWarn.test(message)) {
return;
}
console.error(message);
});
}

View file

@ -2,4 +2,5 @@ export default {
name: '@astrojs/renderer-preact',
client: './client',
server: './server',
knownEntrypoints: ['preact', 'preact-render-to-string']
};

View file

@ -2,4 +2,5 @@ export default {
name: '@astrojs/renderer-react',
client: './client',
server: './server',
knownEntrypoints: ['react', 'react-dom/server']
};

View file

@ -3,4 +3,5 @@ export default {
snowpackPlugin: '@snowpack/plugin-vue',
client: './client',
server: './server',
knownEntrypoints: ['vue']
};