fix issues uncovered by snowpack warnings (#511)

* fix output issues uncovered by snowpack warnings

* Update the snowpack version

* Load Prism dep as the default

* Rename srcRoot to src

* Document the src option

* Add the changeset

Co-authored-by: Matthew Phillips <matthew@skypack.dev>
This commit is contained in:
Fred K. Schott 2021-06-22 11:41:04 -07:00 committed by GitHub
parent 90929fbfca
commit 09b5779884
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 10 deletions

View file

@ -0,0 +1,5 @@
---
'astro': minor
---
Removes mounting the project folder and adds a `src` root option

View file

@ -5,7 +5,8 @@ To configure Astro, add an `astro.config.mjs` file in the root of your project.
```js ```js
export default { export default {
projectRoot: '.', // Where to resolve all URLs relative to. Useful if you have a monorepo project. projectRoot: '.', // Where to resolve all URLs relative to. Useful if you have a monorepo project.
pages: './src/pages', // Path to Astro components, pages, and data src: './src', // Path to Astro components, pages, and data
pages: './src/pages', // Path to Astro/Markdown pages
dist: './dist', // When running `astro build`, path to final static output dist: './dist', // When running `astro build`, path to final static output
public: './public', // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that dont need processing. public: './public', // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that dont need processing.
buildOptions: { buildOptions: {

View file

@ -1,7 +1,7 @@
--- ---
import Prism from 'prismjs'; import Prism from 'prismjs';
import { addAstro } from '@astrojs/prism'; import { addAstro } from '@astrojs/prism';
import * as loadLanguages from 'prismjs/components/index.js'; import loadLanguages from 'prismjs/components/index.js';
export let lang; export let lang;
export let code; export let code;

View file

@ -92,7 +92,7 @@
"sass": "^1.32.13", "sass": "^1.32.13",
"shorthash": "^0.0.2", "shorthash": "^0.0.2",
"slash": "^4.0.0", "slash": "^4.0.0",
"snowpack": "^3.5.9", "snowpack": "^3.6.0",
"source-map-support": "^0.5.19", "source-map-support": "^0.5.19",
"string-width": "^5.0.0", "string-width": "^5.0.0",
"tiny-glob": "^0.2.8", "tiny-glob": "^0.2.8",

View file

@ -3,6 +3,7 @@ import type { ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier
export interface AstroConfigRaw { export interface AstroConfigRaw {
dist: string; dist: string;
projectRoot: string; projectRoot: string;
src: string;
pages: string; pages: string;
public: string; public: string;
jsx?: string; jsx?: string;
@ -19,6 +20,7 @@ export interface AstroConfig {
projectRoot: URL; projectRoot: URL;
pages: URL; pages: URL;
public: URL; public: URL;
src: URL;
renderers?: string[]; renderers?: string[];
/** Options for rendering markdown content */ /** Options for rendering markdown content */
markdownOptions?: Partial<AstroMarkdownOptions>; markdownOptions?: Partial<AstroMarkdownOptions>;

View file

@ -54,6 +54,7 @@ function configDefaults(userConfig?: any): any {
const config: any = { ...(userConfig || {}) }; const config: any = { ...(userConfig || {}) };
if (!config.projectRoot) config.projectRoot = '.'; if (!config.projectRoot) config.projectRoot = '.';
if (!config.src) config.src = './src';
if (!config.pages) config.pages = './src/pages'; if (!config.pages) config.pages = './src/pages';
if (!config.dist) config.dist = './dist'; if (!config.dist) config.dist = './dist';
if (!config.public) config.public = './public'; if (!config.public) config.public = './public';
@ -72,6 +73,7 @@ function normalizeConfig(userConfig: any, root: string): AstroConfig {
const fileProtocolRoot = `file://${root}/`; const fileProtocolRoot = `file://${root}/`;
config.projectRoot = new URL(config.projectRoot + '/', fileProtocolRoot); config.projectRoot = new URL(config.projectRoot + '/', fileProtocolRoot);
config.src = new URL(config.src + '/', fileProtocolRoot);
config.pages = new URL(config.pages + '/', fileProtocolRoot); config.pages = new URL(config.pages + '/', fileProtocolRoot);
config.public = new URL(config.public + '/', fileProtocolRoot); config.public = new URL(config.public + '/', fileProtocolRoot);

View file

@ -308,7 +308,7 @@ interface CreateSnowpackOptions {
/** Create a new Snowpack instance to power Astro */ /** Create a new Snowpack instance to power Astro */
async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackOptions) { async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackOptions) {
const { projectRoot } = astroConfig; const { projectRoot, src } = astroConfig;
const { mode, resolvePackageUrl } = options; const { mode, resolvePackageUrl } = options;
const frontendPath = new URL('./frontend/', import.meta.url); const frontendPath = new URL('./frontend/', import.meta.url);
@ -335,7 +335,7 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO
const mountOptions = { const mountOptions = {
...(existsSync(astroConfig.public) ? { [fileURLToPath(astroConfig.public)]: '/' } : {}), ...(existsSync(astroConfig.public) ? { [fileURLToPath(astroConfig.public)]: '/' } : {}),
[fileURLToPath(frontendPath)]: '/_astro_frontend', [fileURLToPath(frontendPath)]: '/_astro_frontend',
[fileURLToPath(projectRoot)]: '/_astro', // must be last (greediest) [fileURLToPath(src)]: '/_astro/src', // must be last (greediest)
}; };
// Tailwind: IDK what this does but it makes JIT work 🤷‍♂️ // Tailwind: IDK what this does but it makes JIT work 🤷‍♂️
@ -345,7 +345,7 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO
// Make sure that Snowpack builds our renderer plugins // Make sure that Snowpack builds our renderer plugins
const rendererInstances = await configManager.buildRendererInstances(); const rendererInstances = await configManager.buildRendererInstances();
const knownEntrypoints: string[] = []; const knownEntrypoints: string[] = ['astro/dist/internal/__astro_component.js'];
for (const renderer of rendererInstances) { for (const renderer of rendererInstances) {
knownEntrypoints.push(renderer.server, renderer.client); knownEntrypoints.push(renderer.server, renderer.client);
if (renderer.knownEntrypoints) { if (renderer.knownEntrypoints) {

View file

@ -8940,10 +8940,10 @@ smartwrap@^1.2.3:
wcwidth "^1.0.1" wcwidth "^1.0.1"
yargs "^15.1.0" yargs "^15.1.0"
snowpack@^3.5.9: snowpack@^3.6.0:
version "3.5.9" version "3.6.0"
resolved "https://registry.yarnpkg.com/snowpack/-/snowpack-3.5.9.tgz#c374c6b8633ec5baf8311adc964238edeea67b3b" resolved "https://registry.yarnpkg.com/snowpack/-/snowpack-3.6.0.tgz#4c1af4c760be88b1c65594f0fb90f57c99c2338d"
integrity sha512-Rajenx5DRDiMKC+GiU1vMP+tcjge9bAe35fGsPdhkTtIwRkV3u4he1TfiwTh8F1hcOcG5IzLe8jqGM9sBANtpw== integrity sha512-MCRkA3+vJTBxVtb2nwoHETMunzo96l10VsgUuxHXvxsFaZqAkdT50bViuEyFv6fhEujMh55oSHY9pCrxGYA0aQ==
dependencies: dependencies:
cli-spinners "^2.5.0" cli-spinners "^2.5.0"
default-browser-id "^2.0.0" default-browser-id "^2.0.0"