Skip to content

Commit 1d40f17

Browse files
committed
fix: Copy objects passed as configuration.
1 parent 0a17f60 commit 1d40f17

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

packages/css-blocks/src/normalizeOptions.ts

+36-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1+
import { Preprocessors } from "./BlockParser";
12
import {
2-
Options,
3-
ResolvedConfiguration,
4-
} from "./options";
5-
6-
import { OutputMode } from "./OutputMode";
7-
3+
OutputMode,
4+
} from "./OutputMode";
85
import {
96
filesystemImporter,
107
Importer,
118
ImporterData,
129
} from "./importing";
10+
import {
11+
Configuration,
12+
ConfigurationObjectKeys,
13+
ConfigurationSimpleKeys,
14+
Options,
15+
ResolvedConfiguration,
16+
} from "./options";
1317

14-
import { Preprocessors } from "./BlockParser";
15-
18+
const CONFIG_OBJECT_KEYS: Array<ConfigurationObjectKeys> = [
19+
"importerData",
20+
"preprocessors",
21+
];
22+
const CONFIG_SIMPLE_KEYS: Array<ConfigurationSimpleKeys> = [
23+
"outputMode",
24+
"importer",
25+
"rootDir",
26+
"disablePreprocessChaining",
27+
"maxConcurrentCompiles",
28+
];
1629
const DEFAULTS: ResolvedConfiguration = {
1730
outputMode: OutputMode.BEM,
1831
importer: filesystemImporter,
@@ -28,18 +41,25 @@ const DEFAULTS: ResolvedConfiguration = {
2841
* passed.
2942
*/
3043
class OptionsReader implements ResolvedConfiguration {
31-
private _opts: ResolvedConfiguration;
44+
private _opts: Configuration;
3245

33-
constructor(options: Options = {}, defaults: Options = {}) {
46+
constructor(options?: Options, defaults?: Options) {
3447
this._opts = {...DEFAULTS};
35-
for (let k of Object.keys(defaults)) {
36-
if (defaults[k] !== undefined) {
37-
this._opts[k] = defaults[k];
48+
this.setAll(defaults);
49+
this.setAll(options);
50+
}
51+
private setAll(opts: Options | undefined) {
52+
if (opts === undefined) return;
53+
for (let k of CONFIG_SIMPLE_KEYS) {
54+
let v = opts[k];
55+
if (v !== undefined) {
56+
this._opts[k] = v;
3857
}
3958
}
40-
for (let k of Object.keys(options)) {
41-
if (options[k] !== undefined) {
42-
this._opts[k] = options[k];
59+
for (let k of CONFIG_OBJECT_KEYS) {
60+
let v = opts[k];
61+
if (v !== undefined) {
62+
this._opts[k] = {...v};
4363
}
4464
}
4565
}

packages/css-blocks/src/options.ts

+8
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ export type Options = Partial<Readonly<Configuration>>;
3434
* values will have already been provided.
3535
*/
3636
export type ResolvedConfiguration = Readonly<Configuration>;
37+
38+
export type ConfigurationObjectKeys = "importerData"
39+
| "preprocessors";
40+
export type ConfigurationSimpleKeys = "outputMode"
41+
| "importer"
42+
| "rootDir"
43+
| "disablePreprocessChaining"
44+
| "maxConcurrentCompiles";

packages/webpack-plugin/src/Plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
export interface CssBlocksWebpackOptions {
3232
/// The name of the instance of the plugin. Defaults to outputCssFile.
3333
name?: string;
34-
/// The analzyer that decides what templates are analyzed and what blocks will be compiled.
34+
/// The analyzer that decides what templates are analyzed and what blocks will be compiled.
3535
analyzer: MultiTemplateAnalyzer;
3636
/// The output css file for all compiled CSS Blocks. Defaults to "css-blocks.css"
3737
outputCssFile?: string;

0 commit comments

Comments
 (0)