mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
Modified compileAstro to reflect the settings in viteConfig.esbuild
This commit is contained in:
parent
e21c7e67fd
commit
3d58791c95
3 changed files with 34 additions and 4 deletions
5
.changeset/seven-feet-juggle.md
Normal file
5
.changeset/seven-feet-juggle.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Modified compileAstro to reflect the settings in viteConfig.esbuild
|
|
@ -37,8 +37,8 @@ export async function compileAstro({
|
||||||
// Compile all TypeScript to JavaScript.
|
// Compile all TypeScript to JavaScript.
|
||||||
// Also, catches invalid JS/TS in the compiled output before returning.
|
// Also, catches invalid JS/TS in the compiled output before returning.
|
||||||
esbuildResult = await transformWithEsbuild(transformResult.code, compileProps.filename, {
|
esbuildResult = await transformWithEsbuild(transformResult.code, compileProps.filename, {
|
||||||
|
...compileProps.viteConfig.esbuild,
|
||||||
loader: 'ts',
|
loader: 'ts',
|
||||||
target: 'esnext',
|
|
||||||
sourcemap: 'external',
|
sourcemap: 'external',
|
||||||
tsconfigRaw: {
|
tsconfigRaw: {
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import * as assert from 'node:assert/strict';
|
import * as assert from 'node:assert/strict';
|
||||||
import { describe, it } from 'node:test';
|
import { describe, it, before } from 'node:test';
|
||||||
import { pathToFileURL } from 'node:url';
|
import { pathToFileURL } from 'node:url';
|
||||||
import { init, parse } from 'es-module-lexer';
|
import { init, parse } from 'es-module-lexer';
|
||||||
import { resolveConfig } from 'vite';
|
import { resolveConfig } from 'vite';
|
||||||
import { compileAstro } from '../../../dist/vite-plugin-astro/compile.js';
|
import { compileAstro } from '../../../dist/vite-plugin-astro/compile.js';
|
||||||
|
|
||||||
const viteConfig = await resolveConfig({ configFile: false }, 'serve');
|
let inlineConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} source
|
* @param {string} source
|
||||||
* @param {string} id
|
* @param {string} id
|
||||||
*/
|
*/
|
||||||
async function compile(source, id) {
|
async function compile(source, id) {
|
||||||
|
const viteConfig = await resolveConfig({ configFile: false, ...inlineConfig }, 'serve');
|
||||||
return await compileAstro({
|
return await compileAstro({
|
||||||
compileProps: {
|
compileProps: {
|
||||||
astroConfig: { root: pathToFileURL('/'), base: '/', experimental: {} },
|
astroConfig: { root: pathToFileURL('/'), base: '/', experimental: {} },
|
||||||
|
@ -24,6 +24,10 @@ async function compile(source, id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('astro full compile', () => {
|
describe('astro full compile', () => {
|
||||||
|
before(() => {
|
||||||
|
inlineConfig = {};
|
||||||
|
})
|
||||||
|
|
||||||
it('should compile a single file', async () => {
|
it('should compile a single file', async () => {
|
||||||
const result = await compile(`<h1>Hello World</h1>`, '/src/components/index.astro');
|
const result = await compile(`<h1>Hello World</h1>`, '/src/components/index.astro');
|
||||||
assert.ok(result.code);
|
assert.ok(result.code);
|
||||||
|
@ -69,4 +73,25 @@ const name = 'world
|
||||||
assert.equal(names.includes('file'), true);
|
assert.equal(names.includes('file'), true);
|
||||||
assert.equal(names.includes('url'), true);
|
assert.equal(names.includes('url'), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when the code contains syntax that is transformed by esbuild', () => {
|
||||||
|
let code = `\
|
||||||
|
---
|
||||||
|
using x = {}
|
||||||
|
---`;
|
||||||
|
|
||||||
|
it('should not transform the syntax by default', async () => {
|
||||||
|
const result = await compile(code, '/src/components/index.astro');
|
||||||
|
assert.equal(result.code.includes('using x = {}'), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should transform the syntax by esbuild.target', async () => {
|
||||||
|
inlineConfig = {
|
||||||
|
esbuild: { target: 'es2018' },
|
||||||
|
}
|
||||||
|
const result = await compile(code, '/src/components/index.astro');
|
||||||
|
assert.equal(result.code.includes('using x = {}'), false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue