diff --git a/.changeset/violet-spies-play.md b/.changeset/violet-spies-play.md new file mode 100644 index 000000000000..1b9463894975 --- /dev/null +++ b/.changeset/violet-spies-play.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Add esm config support diff --git a/packages/kit/package.json b/packages/kit/package.json index bdd7e30d620e..78631667ff6d 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -35,7 +35,7 @@ "vite": "^2.2.3" }, "peerDependencies": { - "svelte": "^3.32.1", + "svelte": "^3.34.0", "vite": "^2.2.3" }, "bin": { diff --git a/packages/kit/src/cli.js b/packages/kit/src/cli.js index a122f3288140..705534385e91 100644 --- a/packages/kit/src/cli.js +++ b/packages/kit/src/cli.js @@ -26,16 +26,11 @@ async function get_config() { if ( error.code === 'MODULE_NOT_FOUND' && - /Cannot find module svelte\.config\.cjs/.test(error.message) + /Cannot find module svelte\.config\./.test(error.message) ) { - if (existsSync('svelte.config.js')) { - // TODO this is temporary, for the benefit of early adopters - message = 'You must rename svelte.config.js to svelte.config.cjs'; - } else { - message = 'Missing svelte.config.cjs'; - } + message = 'Missing svelte.config.js'; } else if (error.name === 'SyntaxError') { - message = 'Malformed svelte.config.cjs'; + message = 'Malformed svelte.config.js'; } console.error(colors.bold().red(message)); diff --git a/packages/kit/src/core/load_config/index.js b/packages/kit/src/core/load_config/index.js index 5cce4d283a55..88e9d97b74cf 100644 --- a/packages/kit/src/core/load_config/index.js +++ b/packages/kit/src/core/load_config/index.js @@ -1,6 +1,7 @@ import options from './options.js'; import * as url from 'url'; import path from 'path'; +import fs from 'fs'; import { resolve_entry } from '../utils.js'; /** @typedef {import('./types').ConfigDefinition} ConfigDefinition */ @@ -81,7 +82,10 @@ function remove_trailing_slash(str) { } export async function load_config({ cwd = process.cwd() } = {}) { - const config_file = path.join(cwd, 'svelte.config.cjs'); + const config_file_esm = path.join(cwd, 'svelte.config.js'); + const config_file = fs.existsSync(config_file_esm) + ? config_file_esm + : path.join(cwd, 'svelte.config.cjs'); const config = await import(url.pathToFileURL(config_file).href); const validated = validate_config(config.default); diff --git a/packages/kit/src/core/load_config/test/fixtures/svelte.config.cjs b/packages/kit/src/core/load_config/test/fixtures/default-cjs/svelte.config.cjs similarity index 100% rename from packages/kit/src/core/load_config/test/fixtures/svelte.config.cjs rename to packages/kit/src/core/load_config/test/fixtures/default-cjs/svelte.config.cjs diff --git a/packages/kit/src/core/load_config/test/fixtures/default-esm/svelte.config.js b/packages/kit/src/core/load_config/test/fixtures/default-esm/svelte.config.js new file mode 100644 index 000000000000..ff8b4c56321a --- /dev/null +++ b/packages/kit/src/core/load_config/test/fixtures/default-esm/svelte.config.js @@ -0,0 +1 @@ +export default {}; diff --git a/packages/kit/src/core/load_config/test/index.js b/packages/kit/src/core/load_config/test/index.js index 3a5fbf57b6d4..f67ea5561c2d 100644 --- a/packages/kit/src/core/load_config/test/index.js +++ b/packages/kit/src/core/load_config/test/index.js @@ -7,8 +7,11 @@ import { load_config } from '../index.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = join(__filename, '..'); -test('load default config', async () => { - const cwd = join(__dirname, 'fixtures'); +/** + * @param {string} path + */ +async function testLoadDefaultConfig(path) { + const cwd = join(__dirname, 'fixtures', path); const config = await load_config({ cwd }); @@ -42,6 +45,14 @@ test('load default config', async () => { }, preprocess: null }); +} + +test('load default config (cjs)', async () => { + await testLoadDefaultConfig('default-cjs'); +}); + +test('load default config (esm)', async () => { + await testLoadDefaultConfig('default-esm'); }); test.run();