Skip to content

Commit

Permalink
Update config parser to support export default with identifier and ad…
Browse files Browse the repository at this point in the history
…d SvelteKit code

Co-authored-by: NatoBoram <natoboram@users.noreply.github.com>
  • Loading branch information
AndrewLester and NatoBoram committed Aug 10, 2022
1 parent c61e34f commit c872edc
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 6 deletions.
18 changes: 16 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14578,8 +14578,8 @@ class ConfigParser {
}

// Find the configuration object in an AST.
// Look for a default export, a direct module export or an indirect module
// export (in that order).
// Look for a default export, an export default with idenfitier, a direct module export
// or an indirect module export (in that order).
//
// Return the configuration object or null.
findConfigurationObject(ast) {
Expand Down Expand Up @@ -14908,6 +14908,20 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
pathPrefix: path
}
}
case 'sveltekit':
// SvelteKit does not want a trailing slash
if (path.endsWith('/')) {
path = path.slice(0, -1)
}

return {
configurationFile: './svelte.config.js',
blankConfigurationFile: __nccwpck_require__.ab + "sveltekit.js",
properties: {
// Configure a base path
'kit.paths.base': path
}
}
default:
throw `Unsupported static site generator: ${staticSiteGenerator}`
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/sveltekit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Default Pages configuration for SvelteKit
import adapter from '@sveltejs/adapter-auto'

export default {
kit: {
adapter: adapter()
}
}
8 changes: 8 additions & 0 deletions src/blank-configurations/sveltekit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Default Pages configuration for SvelteKit
import adapter from '@sveltejs/adapter-auto'

export default {
kit: {
adapter: adapter()
}
}
4 changes: 2 additions & 2 deletions src/config-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class ConfigParser {
}

// Find the configuration object in an AST.
// Look for a default export, a direct module export or an indirect module
// export (in that order).
// Look for a default export, an export default with idenfitier, a direct module export
// or an indirect module export (in that order).
//
// Return the configuration object or null.
findConfigurationObject(ast) {
Expand Down
9 changes: 9 additions & 0 deletions src/fixtures/sveltekit/blank.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Default Pages configuration for SvelteKit
import adapter from '@sveltejs/adapter-auto'

export default {
kit: {
paths: { base: '/docs' },
adapter: adapter()
}
}
1 change: 1 addition & 0 deletions src/fixtures/sveltekit/blank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file is not read by the test suite
11 changes: 11 additions & 0 deletions src/fixtures/sveltekit/default.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import adapter from '@sveltejs/adapter-auto'

/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
paths: { base: '/docs' },
adapter: adapter()
}
}

export default config
10 changes: 10 additions & 0 deletions src/fixtures/sveltekit/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import adapter from '@sveltejs/adapter-auto'

/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter()
}
}

export default config
14 changes: 14 additions & 0 deletions src/set-pages-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, pat
pathPrefix: path
}
}
case 'sveltekit':
// SvelteKit does not want a trailing slash
if (path.endsWith('/')) {
path = path.slice(0, -1)
}

return {
configurationFile: './svelte.config.js',
blankConfigurationFile: `${__dirname}/blank-configurations/sveltekit.js`,
properties: {
// Configure a base path
'kit.paths.base': path
}
}
default:
throw `Unsupported static site generator: ${staticSiteGenerator}`
}
Expand Down
2 changes: 1 addition & 1 deletion src/set-pages-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { getTempFolder, compareFiles } = require('./test-helpers')
// Get the temp folder
const tempFolder = getTempFolder()

const SUPPORTED_GENERATORS = ['next', 'nuxt', 'gatsby']
const SUPPORTED_GENERATORS = ['next', 'nuxt', 'gatsby', 'sveltekit']
const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs']

// Test suite
Expand Down

0 comments on commit c872edc

Please sign in to comment.