Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code generation quotes handling #5678

Merged
merged 1 commit into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/purple-hounds-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix code generation quotes handling
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/vite-plugin-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function vitePluginPages(opts: StaticBuildOptions, internals: BuildIntern
let i = 0;
for (const pageData of eachPageData(internals)) {
const variable = `_page${i}`;
imports.push(`import * as ${variable} from '${pageData.moduleSpecifier}';`);
importMap += `['${pageData.component}', ${variable}],`;
imports.push(`import * as ${variable} from ${JSON.stringify(pageData.moduleSpecifier)};`);
importMap += `[${JSON.stringify(pageData.component)}, ${variable}],`;
i++;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export async function createVite(
root: fileURLToPath(settings.config.root),
envPrefix: 'PUBLIC_',
define: {
'import.meta.env.SITE': settings.config.site ? `'${settings.config.site}'` : 'undefined',
'import.meta.env.SITE': settings.config.site
? JSON.stringify(settings.config.site)
: 'undefined',
},
server: {
hmr:
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/dev/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function createContainer(params: CreateContainerParams = {}): Promi
},
define: {
'import.meta.env.BASE_URL': settings.config.base
? `'${settings.config.base}'`
? JSON.stringify(settings.config.base)
: 'undefined',
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/vite-plugin-env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function getPrivateEnv(
}
}
}
privateEnv.SITE = astroConfig.site ? `'${astroConfig.site}'` : 'undefined';
privateEnv.SITE = astroConfig.site ? JSON.stringify(astroConfig.site) : 'undefined';
privateEnv.SSR = JSON.stringify(true);
privateEnv.BASE_URL = astroConfig.base ? `'${astroConfig.base}'` : 'undefined';
privateEnv.BASE_URL = astroConfig.base ? JSON.stringify(astroConfig.base) : 'undefined';
return privateEnv;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/vite-plugin-markdown-legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ export default function markdown({ settings }: AstroPluginOptions): Plugin {

const prelude = `---
import Slugger from 'github-slugger';
${layout ? `import Layout from '${layout}';` : ''}
${components ? `import * from '${components}';` : ''}
${layout ? `import Layout from ${JSON.stringify(layout)};` : ''}
${components ? `import * from ${JSON.stringify(components)};` : ''}
${setup}

const slugger = new Slugger();
Expand All @@ -193,7 +193,7 @@ Object.defineProperty($$content.astro, 'headers', {
});
---`;

const imports = `${layout ? `import Layout from '${layout}';` : ''}
const imports = `${layout ? `import Layout from ${JSON.stringify(layout)};` : ''}
${setup}`.trim();

// If the user imported "Layout", wrap the content in a Layout
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu
}

const code = escapeViteEnvReferences(`
import { Fragment, jsx as h } from '${astroJsxRuntimeModulePath}';
import { Fragment, jsx as h } from ${JSON.stringify(astroJsxRuntimeModulePath)};
${layout ? `import Layout from ${JSON.stringify(layout)};` : ''}

const html = ${JSON.stringify(html)};
Expand Down
7 changes: 7 additions & 0 deletions packages/astro/test/astro-pages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ describe('Pages', () => {

expect($('h1').text()).to.equal('Name with index');
});

it('Can find page with quotes in file name', async () => {
const html = await fixture.readFile("/quotes'-work-too/index.html");
const $ = cheerio.load(html);

expect($('h1').text()).to.equal("Quotes work too");
});
});

if (isWindows) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Quotes work too