@ttoss/config 1.11.6 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ttoss/config
2
2
 
3
- <strong>@ttoss/config</strong> is a very opinionated configuration library for monorepo repositories, packages, and applications. It contains a set of default configuration methods that you can use to configure your projects.
3
+ <strong>@ttoss/config</strong> is an opinionated configuration library for monorepo repositories, packages, and applications. It contains a set of <a href="/docs/core/config/default-configs">default configurations</a> that you can use on your projects.
4
4
 
5
5
  Each configuration is customizable and you can extend them with your own. For example, you can use the default `.prettierrc.js` file in your monorepo:
6
6
 
@@ -20,6 +20,31 @@ module.exports = prettierConfig({
20
20
  });
21
21
  ```
22
22
 
23
+ You can also pass a second argument to every configuration to handle array's append or overwrite items.
24
+
25
+ ```js title="babel.config.js"
26
+ const { babelConfig } = require('@ttoss/config');
27
+
28
+ // Append plugins (default)
29
+ const appendConfig = babelConfig(
30
+ {
31
+ plugins: ['@babel/plugin-proposal-class-properties'],
32
+ },
33
+ {
34
+ arrayMerge: 'append',
35
+ }
36
+ );
37
+
38
+ const overwriteConfig = babelConfig(
39
+ {
40
+ plugins: ['@babel/plugin-proposal-class-properties'],
41
+ },
42
+ {
43
+ arrayMerge: 'overwrite',
44
+ }
45
+ );
46
+ ```
47
+
23
48
  ## Install
24
49
 
25
50
  ```shell
@@ -28,7 +53,7 @@ $ yarn add -DW @ttoss/config
28
53
 
29
54
  ## Monorepo
30
55
 
31
- ### Eslint and Prettier
56
+ ### ESLint and Prettier
32
57
 
33
58
  Install the following packages on the root of your monorepo:
34
59
 
@@ -58,7 +83,7 @@ You need `require('@rushstack/eslint-patch/modern-module-resolution');` because
58
83
 
59
84
  ### Husky, commitlint, and lint-staged
60
85
 
61
- This group of packages will only work if you have already installed [Eslint and Prettier](#eslint-and-prettier).
86
+ This group of packages will only work if you have already installed [ESLint and Prettier](#eslint-and-prettier).
62
87
 
63
88
  Install the following packages on the root of your monorepo:
64
89
 
@@ -91,6 +116,50 @@ yarn husky add .husky/commit-msg "yarn commitlint --edit"
91
116
  yarn husky add .husky/pre-commit "yarn lint-staged"
92
117
  ```
93
118
 
119
+ ### Lerna and Yarn Workspaces
120
+
121
+ Although this package doesn't export any configuration for [Lerna](https://github.com/lerna/lerna) or [Yarn Workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/), it's still useful to have them installed.
122
+
123
+ Install [Lerna](https://github.com/lerna/lerna) on the root of your monorepo:
124
+
125
+ ```shell
126
+ yarn add -DW lerna
127
+ ```
128
+
129
+ And add `lerna.json` config file:
130
+
131
+ ```json title="lerna.json"
132
+ {
133
+ "version": "0.0.0",
134
+ "npmClient": "yarn",
135
+ "useWorkspaces": true,
136
+ "stream": true,
137
+ "command": {
138
+ "publish": {
139
+ "allowBranch": "main",
140
+ "conventionalCommits": true,
141
+ "message": "chore: publish new version"
142
+ },
143
+ "version": {
144
+ "forcePublish": true
145
+ }
146
+ }
147
+ }
148
+ ```
149
+
150
+ Finally, add the following in a `package.json` file to configure [Yarn Workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/):
151
+
152
+ ```json title="package.json"
153
+ {
154
+ "private": true,
155
+ "workspaces": ["workspace-a", "workspace-b"]
156
+ }
157
+ ```
158
+
159
+ ### Turborepo
160
+
161
+ Coming soon...
162
+
94
163
  ## Packages and Applications
95
164
 
96
165
  ### Babel
@@ -123,7 +192,7 @@ export default config;
123
192
 
124
193
  Configure the `test` script on `package.json`:
125
194
 
126
- ```json title="package.json'
195
+ ```json title="package.json"
127
196
  "scripts: {
128
197
  test: 'jest',
129
198
  }
@@ -149,7 +218,7 @@ export const tsup = tsupConfig();
149
218
 
150
219
  Configure the `build` script on `package.json`:
151
220
 
152
- ```json title="package.json'
221
+ ```json title="package.json"
153
222
  "scripts: {
154
223
  build: 'tsup',
155
224
  }
package/dist/esm/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  // src/configCreator.ts
2
2
  import deepmerge from "deepmerge";
3
3
  var overwriteMerge = (_, sourceArray) => sourceArray;
4
- var configCreator = (defaultConfig7 = {}) => (config = {}) => deepmerge(defaultConfig7, config, { arrayMerge: overwriteMerge });
4
+ var configCreator = (defaultConfig7 = {}) => (config = {}, deepmergeConfig) => deepmerge(defaultConfig7, config, {
5
+ arrayMerge: (deepmergeConfig == null ? void 0 : deepmergeConfig.arrayMerge) === "overwrite" ? overwriteMerge : void 0
6
+ });
5
7
 
6
8
  // src/babel.ts
7
9
  var defaultConfig = {
package/dist/index.d.ts CHANGED
@@ -1,15 +1,256 @@
1
+ import { Config } from '@jest/types';
1
2
  import { Options } from 'tsup';
2
3
 
3
- declare const babelConfig: (config?: any) => any;
4
+ declare const babelConfig: (config?: any, deepmergeConfig?: {
5
+ arrayMerge: "append" | "overwrite";
6
+ } | undefined) => any;
4
7
 
5
- declare const commitlintConfig: (config?: any) => any;
8
+ declare const commitlintConfig: (config?: any, deepmergeConfig?: {
9
+ arrayMerge: "append" | "overwrite";
10
+ } | undefined) => any;
6
11
 
7
- declare const jestConfig: (config?: any) => any;
12
+ declare const jestConfig: (config?: Partial<{
13
+ automock: boolean;
14
+ bail: number | boolean;
15
+ cache: boolean;
16
+ cacheDirectory: string;
17
+ ci: boolean;
18
+ clearMocks: boolean;
19
+ changedFilesWithAncestor: boolean;
20
+ changedSince: string;
21
+ collectCoverage: boolean;
22
+ collectCoverageFrom: string[];
23
+ collectCoverageOnlyFrom: {
24
+ [key: string]: boolean;
25
+ };
26
+ coverageDirectory: string;
27
+ coveragePathIgnorePatterns: string[];
28
+ coverageProvider: "v8" | "babel";
29
+ coverageReporters: Config.CoverageReporters;
30
+ coverageThreshold: {
31
+ [path: string]: Config.CoverageThresholdValue;
32
+ global: Config.CoverageThresholdValue;
33
+ };
34
+ dependencyExtractor: string;
35
+ detectLeaks: boolean;
36
+ detectOpenHandles: boolean;
37
+ displayName: string | Config.DisplayName;
38
+ expand: boolean;
39
+ extensionsToTreatAsEsm: string[];
40
+ extraGlobals: string[];
41
+ filter: string;
42
+ findRelatedTests: boolean;
43
+ forceCoverageMatch: string[];
44
+ forceExit: boolean;
45
+ json: boolean;
46
+ globals: Config.ConfigGlobals;
47
+ globalSetup: string | null | undefined;
48
+ globalTeardown: string | null | undefined;
49
+ haste: Config.HasteConfig;
50
+ injectGlobals: boolean;
51
+ reporters: (string | Config.ReporterConfig)[];
52
+ logHeapUsage: boolean;
53
+ lastCommit: boolean;
54
+ listTests: boolean;
55
+ maxConcurrency: number;
56
+ maxWorkers: string | number;
57
+ moduleDirectories: string[];
58
+ moduleFileExtensions: string[];
59
+ moduleLoader: string;
60
+ moduleNameMapper: {
61
+ [key: string]: string | string[];
62
+ };
63
+ modulePathIgnorePatterns: string[];
64
+ modulePaths: string[];
65
+ name: string;
66
+ noStackTrace: boolean;
67
+ notify: boolean;
68
+ notifyMode: string;
69
+ onlyChanged: boolean;
70
+ onlyFailures: boolean;
71
+ outputFile: string;
72
+ passWithNoTests: boolean;
73
+ preprocessorIgnorePatterns: string[];
74
+ preset: string | null | undefined;
75
+ prettierPath: string | null | undefined;
76
+ projects: (string | Config.InitialProjectOptions)[];
77
+ replname: string | null | undefined;
78
+ resetMocks: boolean;
79
+ resetModules: boolean;
80
+ resolver: string | null | undefined;
81
+ restoreMocks: boolean;
82
+ rootDir: string;
83
+ roots: string[];
84
+ runner: string;
85
+ runTestsByPath: boolean;
86
+ scriptPreprocessor: string;
87
+ setupFiles: string[];
88
+ setupTestFrameworkScriptFile: string;
89
+ setupFilesAfterEnv: string[];
90
+ silent: boolean;
91
+ skipFilter: boolean;
92
+ skipNodeResolution: boolean;
93
+ slowTestThreshold: number;
94
+ snapshotResolver: string;
95
+ snapshotSerializers: string[];
96
+ snapshotFormat: Config.PrettyFormatOptions;
97
+ errorOnDeprecated: boolean;
98
+ testEnvironment: string;
99
+ testEnvironmentOptions: Record<string, unknown>;
100
+ testFailureExitCode: string | number;
101
+ testLocationInResults: boolean;
102
+ testMatch: string[];
103
+ testNamePattern: string;
104
+ testPathDirs: string[];
105
+ testPathIgnorePatterns: string[];
106
+ testRegex: string | string[];
107
+ testResultsProcessor: string;
108
+ testRunner: string;
109
+ testSequencer: string;
110
+ testURL: string;
111
+ testTimeout: number;
112
+ timers: "fake" | "real" | "modern" | "legacy";
113
+ transform: {
114
+ [regex: string]: string | Config.TransformerConfig;
115
+ };
116
+ transformIgnorePatterns: string[];
117
+ watchPathIgnorePatterns: string[];
118
+ unmockedModulePathPatterns: string[];
119
+ updateSnapshot: boolean;
120
+ useStderr: boolean;
121
+ verbose?: boolean | undefined;
122
+ watch: boolean;
123
+ watchAll: boolean;
124
+ watchman: boolean;
125
+ watchPlugins: (string | [string, Record<string, unknown>])[];
126
+ }>, deepmergeConfig?: {
127
+ arrayMerge: "append" | "overwrite";
128
+ } | undefined) => Partial<{
129
+ automock: boolean;
130
+ bail: number | boolean;
131
+ cache: boolean;
132
+ cacheDirectory: string;
133
+ ci: boolean;
134
+ clearMocks: boolean;
135
+ changedFilesWithAncestor: boolean;
136
+ changedSince: string;
137
+ collectCoverage: boolean;
138
+ collectCoverageFrom: string[];
139
+ collectCoverageOnlyFrom: {
140
+ [key: string]: boolean;
141
+ };
142
+ coverageDirectory: string;
143
+ coveragePathIgnorePatterns: string[];
144
+ coverageProvider: "v8" | "babel";
145
+ coverageReporters: Config.CoverageReporters;
146
+ coverageThreshold: {
147
+ [path: string]: Config.CoverageThresholdValue;
148
+ global: Config.CoverageThresholdValue;
149
+ };
150
+ dependencyExtractor: string;
151
+ detectLeaks: boolean;
152
+ detectOpenHandles: boolean;
153
+ displayName: string | Config.DisplayName;
154
+ expand: boolean;
155
+ extensionsToTreatAsEsm: string[];
156
+ extraGlobals: string[];
157
+ filter: string;
158
+ findRelatedTests: boolean;
159
+ forceCoverageMatch: string[];
160
+ forceExit: boolean;
161
+ json: boolean;
162
+ globals: Config.ConfigGlobals;
163
+ globalSetup: string | null | undefined;
164
+ globalTeardown: string | null | undefined;
165
+ haste: Config.HasteConfig;
166
+ injectGlobals: boolean;
167
+ reporters: (string | Config.ReporterConfig)[];
168
+ logHeapUsage: boolean;
169
+ lastCommit: boolean;
170
+ listTests: boolean;
171
+ maxConcurrency: number;
172
+ maxWorkers: string | number;
173
+ moduleDirectories: string[];
174
+ moduleFileExtensions: string[];
175
+ moduleLoader: string;
176
+ moduleNameMapper: {
177
+ [key: string]: string | string[];
178
+ };
179
+ modulePathIgnorePatterns: string[];
180
+ modulePaths: string[];
181
+ name: string;
182
+ noStackTrace: boolean;
183
+ notify: boolean;
184
+ notifyMode: string;
185
+ onlyChanged: boolean;
186
+ onlyFailures: boolean;
187
+ outputFile: string;
188
+ passWithNoTests: boolean;
189
+ preprocessorIgnorePatterns: string[];
190
+ preset: string | null | undefined;
191
+ prettierPath: string | null | undefined;
192
+ projects: (string | Config.InitialProjectOptions)[];
193
+ replname: string | null | undefined;
194
+ resetMocks: boolean;
195
+ resetModules: boolean;
196
+ resolver: string | null | undefined;
197
+ restoreMocks: boolean;
198
+ rootDir: string;
199
+ roots: string[];
200
+ runner: string;
201
+ runTestsByPath: boolean;
202
+ scriptPreprocessor: string;
203
+ setupFiles: string[];
204
+ setupTestFrameworkScriptFile: string;
205
+ setupFilesAfterEnv: string[];
206
+ silent: boolean;
207
+ skipFilter: boolean;
208
+ skipNodeResolution: boolean;
209
+ slowTestThreshold: number;
210
+ snapshotResolver: string;
211
+ snapshotSerializers: string[];
212
+ snapshotFormat: Config.PrettyFormatOptions;
213
+ errorOnDeprecated: boolean;
214
+ testEnvironment: string;
215
+ testEnvironmentOptions: Record<string, unknown>;
216
+ testFailureExitCode: string | number;
217
+ testLocationInResults: boolean;
218
+ testMatch: string[];
219
+ testNamePattern: string;
220
+ testPathDirs: string[];
221
+ testPathIgnorePatterns: string[];
222
+ testRegex: string | string[];
223
+ testResultsProcessor: string;
224
+ testRunner: string;
225
+ testSequencer: string;
226
+ testURL: string;
227
+ testTimeout: number;
228
+ timers: "fake" | "real" | "modern" | "legacy";
229
+ transform: {
230
+ [regex: string]: string | Config.TransformerConfig;
231
+ };
232
+ transformIgnorePatterns: string[];
233
+ watchPathIgnorePatterns: string[];
234
+ unmockedModulePathPatterns: string[];
235
+ updateSnapshot: boolean;
236
+ useStderr: boolean;
237
+ verbose?: boolean | undefined;
238
+ watch: boolean;
239
+ watchAll: boolean;
240
+ watchman: boolean;
241
+ watchPlugins: (string | [string, Record<string, unknown>])[];
242
+ }>;
8
243
 
9
- declare const lintstagedConfig: (config?: any) => any;
244
+ declare const lintstagedConfig: (config?: any, deepmergeConfig?: {
245
+ arrayMerge: "append" | "overwrite";
246
+ } | undefined) => any;
10
247
 
11
- declare const prettierConfig: (config?: any) => any;
248
+ declare const prettierConfig: (config?: any, deepmergeConfig?: {
249
+ arrayMerge: "append" | "overwrite";
250
+ } | undefined) => any;
12
251
 
13
- declare const tsupConfig: (config?: Options) => Options;
252
+ declare const tsupConfig: (config?: Options, deepmergeConfig?: {
253
+ arrayMerge: "append" | "overwrite";
254
+ } | undefined) => Options;
14
255
 
15
256
  export { babelConfig, commitlintConfig, jestConfig, lintstagedConfig, prettierConfig, tsupConfig };
package/dist/index.js CHANGED
@@ -34,7 +34,9 @@ module.exports = __toCommonJS(src_exports);
34
34
  // src/configCreator.ts
35
35
  var import_deepmerge = __toESM(require("deepmerge"));
36
36
  var overwriteMerge = (_, sourceArray) => sourceArray;
37
- var configCreator = (defaultConfig7 = {}) => (config = {}) => (0, import_deepmerge.default)(defaultConfig7, config, { arrayMerge: overwriteMerge });
37
+ var configCreator = (defaultConfig7 = {}) => (config = {}, deepmergeConfig) => (0, import_deepmerge.default)(defaultConfig7, config, {
38
+ arrayMerge: (deepmergeConfig == null ? void 0 : deepmergeConfig.arrayMerge) === "overwrite" ? overwriteMerge : void 0
39
+ });
38
40
 
39
41
  // src/babel.ts
40
42
  var defaultConfig = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/config",
3
- "version": "1.11.6",
3
+ "version": "1.12.1",
4
4
  "description": "Default configuration for packages.",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -40,7 +40,7 @@
40
40
  "identity-obj-proxy": "^3.0.0",
41
41
  "tsup": "^5.11.11"
42
42
  },
43
- "gitHead": "eb5615ee3b87ffa3eea40f072cefb6d74a3f5423",
43
+ "gitHead": "1236f19e0efc3ed37df87f1bbfd21776b6b5d697",
44
44
  "devDependencies": {
45
45
  "@jest/types": "^27.4.2"
46
46
  }
package/src/babel.spec.ts CHANGED
@@ -3,3 +3,24 @@ import { babelConfig, defaultConfig } from './babel';
3
3
  test('should return default config', () => {
4
4
  expect(babelConfig()).toEqual(defaultConfig);
5
5
  });
6
+
7
+ test('should update plugin', () => {
8
+ expect(
9
+ babelConfig(
10
+ { plugins: ['relay'] },
11
+ {
12
+ arrayMerge: 'overwrite',
13
+ }
14
+ )
15
+ ).toEqual({
16
+ ...defaultConfig,
17
+ plugins: ['relay'],
18
+ });
19
+ });
20
+
21
+ test('should append plugin', () => {
22
+ expect(babelConfig({ plugins: ['relay'] })).toEqual({
23
+ ...defaultConfig,
24
+ plugins: [...defaultConfig.plugins, 'relay'],
25
+ });
26
+ });
@@ -4,10 +4,15 @@ test('should return default configuration', () => {
4
4
  expect(commitlintConfig()).toEqual(defaultConfig);
5
5
  });
6
6
 
7
- test('should return default configuration', () => {
7
+ test('should return default configuration with different extends', () => {
8
8
  expect(
9
- commitlintConfig({
10
- extends: ['other-config'],
11
- })
9
+ commitlintConfig(
10
+ {
11
+ extends: ['other-config'],
12
+ },
13
+ {
14
+ arrayMerge: 'overwrite',
15
+ }
16
+ )
12
17
  ).toEqual({ ...defaultConfig, extends: ['other-config'] });
13
18
  });
@@ -0,0 +1,36 @@
1
+ import { configCreator } from './configCreator';
2
+
3
+ const defaultConfig: any = {
4
+ obj: { a: 1, b: 2 },
5
+ arr: [1, 2, 3],
6
+ };
7
+
8
+ const config = configCreator(defaultConfig);
9
+
10
+ test('should append array', () => {
11
+ expect(config({ arr: [4, 5] })).toEqual({
12
+ obj: { a: 1, b: 2 },
13
+ arr: [1, 2, 3, 4, 5],
14
+ });
15
+ });
16
+
17
+ test('should overwrite array', () => {
18
+ expect(
19
+ config(
20
+ { arr: [4, 5] },
21
+ {
22
+ arrayMerge: 'overwrite',
23
+ }
24
+ )
25
+ ).toEqual({
26
+ obj: { a: 1, b: 2 },
27
+ arr: [4, 5],
28
+ });
29
+ });
30
+
31
+ test('should add obj key', () => {
32
+ expect(config({ obj: { c: 3 } })).toEqual({
33
+ arr: [1, 2, 3],
34
+ obj: { a: 1, b: 2, c: 3 },
35
+ });
36
+ });
@@ -4,5 +4,13 @@ const overwriteMerge = (_: any, sourceArray: any) => sourceArray;
4
4
 
5
5
  export const configCreator =
6
6
  <T extends Record<string, any>>(defaultConfig: T = {} as T) =>
7
- (config: T = {} as T) =>
8
- deepmerge<T>(defaultConfig, config, { arrayMerge: overwriteMerge });
7
+ (
8
+ config: T = {} as T,
9
+ deepmergeConfig?: { arrayMerge: 'append' | 'overwrite' }
10
+ ) =>
11
+ deepmerge<T>(defaultConfig, config, {
12
+ arrayMerge:
13
+ deepmergeConfig?.arrayMerge === 'overwrite'
14
+ ? overwriteMerge
15
+ : undefined,
16
+ });
package/src/jest.ts CHANGED
@@ -198,4 +198,4 @@ export const defaultConfig: Config.InitialOptions = {
198
198
  // watchman: true,
199
199
  };
200
200
 
201
- export const jestConfig = configCreator<any>(defaultConfig);
201
+ export const jestConfig = configCreator<Config.InitialOptions>(defaultConfig);
package/src/tsup.spec.ts CHANGED
@@ -1,13 +1,18 @@
1
- import { tsupConfig, defaultConfig } from './tsup';
1
+ import { defaultConfig, tsupConfig } from './tsup';
2
2
 
3
3
  test('should return default configuration', () => {
4
4
  expect(tsupConfig()).toEqual(defaultConfig);
5
5
  });
6
6
 
7
- test('should return default configuration', () => {
7
+ test('should return default configuration with different entrypoint', () => {
8
8
  expect(
9
- tsupConfig({
10
- entryPoints: ['src/index.tsx'],
11
- })
9
+ tsupConfig(
10
+ {
11
+ entryPoints: ['src/index.tsx'],
12
+ },
13
+ {
14
+ arrayMerge: 'overwrite',
15
+ }
16
+ )
12
17
  ).toEqual({ ...defaultConfig, entryPoints: ['src/index.tsx'] });
13
18
  });