-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* kitOptions namespace * kitOptions -> kit * add validation, rename kit.paths -> kit.files * add changeset * fix adapt option * lint
- Loading branch information
1 parent
b04833b
commit 0e45255
Showing
15 changed files
with
251 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'create-svelte': patch | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
Move options behind kit namespace, change paths -> kit.files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports = { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-netlify' | ||
}; | ||
kit: { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-netlify' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports = { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-node' | ||
kit: { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-node' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports = { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-node' | ||
kit: { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-node' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports = { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-node' | ||
kit: { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-node' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
module.exports = { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-node' | ||
kit: { | ||
// By default, `npm run build` will create a standard Node app. | ||
// You can create optimized builds for different platforms by | ||
// specifying a different adapter | ||
adapter: '@sveltejs/adapter-node' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
import relative from 'require-relative'; | ||
import { bold, yellow } from 'kleur/colors'; | ||
import options from './options'; | ||
|
||
const default_config = { | ||
target: null, | ||
startGlobal: null, // used for testing | ||
paths: { | ||
static: 'static', | ||
routes: 'src/routes', | ||
setup: 'src/setup', | ||
template: 'src/app.html' | ||
function warn(msg) { | ||
console.log(bold(yellow(msg))); | ||
} | ||
|
||
function validate(definition, option, keypath) { | ||
for (const key in option) { | ||
if (!(key in definition)) { | ||
throw new Error(`Unexpected option ${keypath}.${key}`); | ||
} | ||
} | ||
}; | ||
|
||
const merged = {}; | ||
|
||
for (const key in definition) { | ||
const expected = definition[key]; | ||
const actual = option[key]; | ||
|
||
const child_keypath = `${keypath}.${key}`; | ||
const has_children = expected.default && typeof expected.default === 'object' && !Array.isArray(expected.default); | ||
|
||
if (key in option) { | ||
if (has_children) { | ||
if (actual && (typeof actual !== 'object' || Array.isArray(actual))) { | ||
throw new Error(`${keypath}.${key} should be an object`); | ||
} | ||
|
||
merged[key] = validate(expected.default, actual, child_keypath); | ||
} else { | ||
merged[key] = expected.validate(actual, child_keypath); | ||
} | ||
} else { | ||
merged[key] = has_children | ||
? validate(expected.default, {}, child_keypath) | ||
: expected.default; | ||
} | ||
} | ||
|
||
return merged; | ||
} | ||
|
||
const expected = new Set(['compilerOptions', 'kit', 'preprocess']); | ||
|
||
export function load_config({ cwd = process.cwd() } = {}) { | ||
const config = relative('./svelte.config.js', cwd); | ||
return validate_config(config); | ||
} | ||
|
||
return { | ||
...default_config, | ||
...config, | ||
paths: { | ||
...default_config.paths, | ||
...config.paths | ||
export function validate_config(config) { | ||
for (const key in config) { | ||
if (!expected.has(key)) { | ||
warn(`Unexpected option ${key}${key in options ? ` (did you mean kit.${key}?)` : ''}`); | ||
} | ||
}; | ||
} | ||
|
||
const { kit = {} } = config; | ||
|
||
return validate(options, kit, 'kit'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import { validate_config } from './index'; | ||
|
||
test('fills in defaults', () => { | ||
const validated = validate_config({}); | ||
|
||
assert.equal(validated, { | ||
adapter: [null], | ||
target: null, | ||
startGlobal: null, | ||
files: { | ||
assets: 'static', | ||
routes: 'src/routes', | ||
setup: 'src/setup', | ||
template: 'src/app.html' | ||
} | ||
}); | ||
}); | ||
|
||
test('errors on invalid values', () => { | ||
assert.throws(() => { | ||
validate_config({ | ||
kit: { | ||
target: 42 | ||
} | ||
}); | ||
}, /^kit\.target should be a string, if specified$/); | ||
}); | ||
|
||
test('errors on invalid nested values', () => { | ||
assert.throws(() => { | ||
validate_config({ | ||
kit: { | ||
files: { | ||
potato: 'blah' | ||
} | ||
} | ||
}); | ||
}, /^Unexpected option kit\.files\.potato$/); | ||
}); | ||
|
||
test('fills in partial blanks', () => { | ||
const validated = validate_config({ | ||
kit: { | ||
files: { | ||
assets: 'public' | ||
} | ||
} | ||
}); | ||
|
||
assert.equal(validated, { | ||
adapter: [null], | ||
target: null, | ||
startGlobal: null, | ||
files: { | ||
assets: 'public', | ||
routes: 'src/routes', | ||
setup: 'src/setup', | ||
template: 'src/app.html' | ||
} | ||
}); | ||
}); | ||
|
||
test.run(); |
Oops, something went wrong.