From 0abd251cda3e74f055674ddbd6d267fb7d02c4c0 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 21 Jun 2021 15:34:22 -0400 Subject: [PATCH] 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 --- .changeset/silly-bees-flash.md | 8 ++++++++ docs/renderers.md | 1 + packages/astro/snowpack-plugin.cjs | 8 +++++++- packages/astro/src/config_manager.ts | 2 ++ packages/astro/src/runtime.ts | 8 +++++++- packages/astro/src/snowpack-logger.ts | 19 ------------------- packages/renderers/renderer-preact/index.js | 1 + packages/renderers/renderer-react/index.js | 1 + packages/renderers/renderer-vue/index.js | 1 + 9 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 .changeset/silly-bees-flash.md diff --git a/.changeset/silly-bees-flash.md b/.changeset/silly-bees-flash.md new file mode 100644 index 000000000..9c9205bb2 --- /dev/null +++ b/.changeset/silly-bees-flash.md @@ -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 diff --git a/docs/renderers.md b/docs/renderers.md index 9abc69262..aaaab0913 100644 --- a/docs/renderers.md +++ b/docs/renderers.md @@ -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 }; ``` diff --git a/packages/astro/snowpack-plugin.cjs b/packages/astro/snowpack-plugin.cjs index a50816089..30f381e56 100644 --- a/packages/astro/snowpack-plugin.cjs +++ b/packages/astro/snowpack-plugin.cjs @@ -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'], diff --git a/packages/astro/src/config_manager.ts b/packages/astro/src/config_manager.ts index 69635fda4..c4d1db90c 100644 --- a/packages/astro/src/config_manager.ts +++ b/packages/astro/src/config_manager.ts @@ -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 }; }); diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index 9a374b757..e4e7f4d16 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -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({ diff --git a/packages/astro/src/snowpack-logger.ts b/packages/astro/src/snowpack-logger.ts index 4898faa6a..9465bb138 100644 --- a/packages/astro/src/snowpack-logger.ts +++ b/packages/astro/src/snowpack-logger.ts @@ -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(); - 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); - }); } diff --git a/packages/renderers/renderer-preact/index.js b/packages/renderers/renderer-preact/index.js index 07ebe50e7..5602442e6 100644 --- a/packages/renderers/renderer-preact/index.js +++ b/packages/renderers/renderer-preact/index.js @@ -2,4 +2,5 @@ export default { name: '@astrojs/renderer-preact', client: './client', server: './server', + knownEntrypoints: ['preact', 'preact-render-to-string'] }; diff --git a/packages/renderers/renderer-react/index.js b/packages/renderers/renderer-react/index.js index af8e516b8..430e01c3a 100644 --- a/packages/renderers/renderer-react/index.js +++ b/packages/renderers/renderer-react/index.js @@ -2,4 +2,5 @@ export default { name: '@astrojs/renderer-react', client: './client', server: './server', + knownEntrypoints: ['react', 'react-dom/server'] }; diff --git a/packages/renderers/renderer-vue/index.js b/packages/renderers/renderer-vue/index.js index 016beec6b..e3f31fc8e 100644 --- a/packages/renderers/renderer-vue/index.js +++ b/packages/renderers/renderer-vue/index.js @@ -3,4 +3,5 @@ export default { snowpackPlugin: '@snowpack/plugin-vue', client: './client', server: './server', + knownEntrypoints: ['vue'] };