Skip to content

Commit

Permalink
fix: alias and aliasPrefixes in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
skovy committed Apr 26, 2022
1 parent 7a2a5d5 commit 8ce9540
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
64 changes: 64 additions & 0 deletions __tests__/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,68 @@ describe("#mergeOptions", () => {
importer,
});
});

it("should give ignore undefined CLI options", () => {
const importer = jest.fn();

expect(
mergeOptions(
{
aliases: undefined,
aliasPrefixes: undefined,
nameFormat: "kebab",
implementation: "sass",
exportType: "default",
exportTypeName: "Classes",
exportTypeInterface: "AllStyles",
watch: true,
ignoreInitial: true,
listDifferent: true,
ignore: ["path"],
quoteType: "double",
updateStaleOnly: true,
logLevel: "silent",
banner: undefined,
outputFolder: "__cli-generated__",
},
{
aliases: {},
aliasPrefixes: {},
nameFormat: "param",
implementation: "node-sass",
exportType: "named",
exportTypeName: "Classnames",
exportTypeInterface: "TheStyles",
watch: false,
ignoreInitial: false,
listDifferent: false,
ignore: ["another/path"],
quoteType: "single",
updateStaleOnly: false,
logLevel: "info",
banner: "// banner",
outputFolder: "__generated__",
importer,
}
)
).toEqual({
aliases: {},
aliasPrefixes: {},
nameFormat: "kebab",
implementation: "sass",
exportType: "default",
exportTypeName: "Classes",
exportTypeInterface: "AllStyles",
watch: true,
ignoreInitial: true,
listDifferent: true,
ignore: ["path"],
quoteType: "double",
updateStaleOnly: true,
logLevel: "silent",
banner: "// banner",
outputFolder: "__cli-generated__",
importer,
});
});
});
2 changes: 2 additions & 0 deletions examples/config-file/typed-scss-modules.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const jsonImporter = require("node-sass-json-importer");

export const config = {
aliases: { "not-real": "test-value" },
aliasPrefixes: { "also-not-real": "test-value" },
banner: "// config file banner",
nameFormat: "kebab",
exportType: "default",
Expand Down
12 changes: 11 additions & 1 deletion lib/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ export const DEFAULT_OPTIONS: CLIOptions = {
outputFolder: null,
};

const removedUndefinedValues = <Obj extends {}>(obj: Obj): Obj => {
for (let key in obj) {
if (obj[key] === undefined) {
delete obj[key];
}
}

return obj;
};

/**
* Given both the CLI and config file options merge into a single options object.
*
Expand All @@ -92,6 +102,6 @@ export const mergeOptions = (
return {
...DEFAULT_OPTIONS,
...configOptions,
...cliOptions,
...removedUndefinedValues(cliOptions),
};
};

0 comments on commit 8ce9540

Please sign in to comment.