Skip to content

Commit

Permalink
fix reading options from config
Browse files Browse the repository at this point in the history
fixes #12
  • Loading branch information
orlov-vo committed Oct 29, 2020
1 parent d46e5a5 commit c0c3785
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const { compile, preprocess } = require('svelte/compiler.js');

Object.defineProperty(exports, '__esModule', { value: true });

const CONFIG_FILES = ['.svelterc', 'svelte.config.js'];
const CONFIG_PACKAGE_KEY = 'svelte';

function generateName(input) {
let name = path
.basename(input)
Expand Down Expand Up @@ -37,12 +40,16 @@ async function handleError(sourceFileName, func) {
}
}

async function getConfig(config) {
const packageKey = CONFIG_PACKAGE_KEY;
const data = await config.getConfig(CONFIG_FILES, { packageKey });

return data && data.contents ? data.contents : {};
}

exports.default = new Transformer({
async loadConfig({ config, options }) {
const customOptions =
(await config.getConfig(['.svelterc', 'svelte.config.js'], {
packageKey: 'svelte',
})) || {};
const customOptions = await getConfig(config);

if (customOptions.compiler) {
console.error(
Expand Down

0 comments on commit c0c3785

Please sign in to comment.