merge-tsconfigs 0.1.1 → 0.1.2
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 +62 -9
- package/dist/index.cjs +25 -6
- package/dist/index.d.ts +7 -2
- package/dist/index.js +24 -6
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
[](https://badge.fury.io/js/merge-tsconfigs)
|
|
5
|
+
[](https://unpkg.com/merge-tsconfigs@0.1.1/dist/index.js)
|
|
6
|
+
[](https://cdn.skypack.dev/merge-tsconfigs?min)
|
|
5
7
|

|
|
6
8
|
[](https://github.com/yowainwright/merge-tsconfigs)
|
|
7
9
|

|
|
@@ -10,7 +12,7 @@ _Merge-tsconfigs_ is a CLI and node tool for merging tsconfig files into the exa
|
|
|
10
12
|
|
|
11
13
|
---
|
|
12
14
|
|
|
13
|
-
**[Why do I want this?](#why-do-i-want-this)** | **[Example](#for-example)** | **[How do I use this?](#how-do-i-use-this)** | **[CLI API](#cli-api)** | **[Node API](#node-api)** | **[
|
|
15
|
+
**[Why do I want this?](#why-do-i-want-this)** | **[Example](#for-example)** | **[How do I use this?](#how-do-i-use-this)** | **[CLI API](#cli-api)** | **[Node API](#node-api)** | **[How do I start using this?](#how-do-i-start-using-this)**
|
|
14
16
|
|
|
15
17
|
---
|
|
16
18
|
|
|
@@ -82,7 +84,8 @@ Options:
|
|
|
82
84
|
-e, --exclude [exclude...] files to exclude, matches a glob or array pattern
|
|
83
85
|
-h, --help display help for command
|
|
84
86
|
```
|
|
85
|
-
|
|
87
|
+
|
|
88
|
+
\*`compilerOptions` are not added above for readability (but they can be leveraged). To view all cli options, run `merge-tsconfigs --help`! `compilerOptions.paths` aren't implemented.
|
|
86
89
|
|
|
87
90
|
#### Recipes
|
|
88
91
|
|
|
@@ -90,34 +93,84 @@ Merge tsconfig files into a single tsconfig
|
|
|
90
93
|
|
|
91
94
|
```sh
|
|
92
95
|
merge-tsconfigs ./tsconfig.json ./tsconfig.build.json
|
|
93
|
-
# => ./tsconfig.merged.json
|
|
96
|
+
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
|
|
94
97
|
```
|
|
95
98
|
|
|
96
99
|
Merge tsconfig files a specific tsconfig file
|
|
97
100
|
|
|
98
101
|
```sh
|
|
99
102
|
merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --out ./tsconfig.out.json
|
|
100
|
-
# => ./tsconfig.out.json
|
|
103
|
+
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.out.json
|
|
101
104
|
```
|
|
102
105
|
|
|
103
106
|
Merge tsconfig files with unique `include` and `exclude` strings
|
|
104
107
|
|
|
105
108
|
```sh
|
|
106
109
|
merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --include 'src/**.ts' --exclude 'test/**.ts'
|
|
107
|
-
# => ./tsconfig.merged.json
|
|
110
|
+
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
// tsconfig.merged.json
|
|
115
|
+
{
|
|
116
|
+
"compilerOptions": {
|
|
117
|
+
// ...options
|
|
118
|
+
},
|
|
119
|
+
"include": ["src/**.ts"],
|
|
120
|
+
"exclude": ["test/**.ts", "config/*.ts"]
|
|
121
|
+
}
|
|
108
122
|
```
|
|
109
123
|
|
|
110
124
|
Merge tsconfig files with unique `include` and `exclude` or by using arrays
|
|
111
125
|
|
|
112
126
|
```sh
|
|
113
127
|
merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --include 'src/**.ts' --exclude 'test/**.ts' 'config/*.ts'
|
|
114
|
-
# => ./tsconfig.merged.json
|
|
128
|
+
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
// tsconfig.merged.json
|
|
133
|
+
{
|
|
134
|
+
"compilerOptions": {
|
|
135
|
+
// ...options
|
|
136
|
+
},
|
|
137
|
+
"include": ["src/**.ts"],
|
|
138
|
+
"exclude": ["test/**.ts", "config/*.ts"]
|
|
139
|
+
}
|
|
115
140
|
```
|
|
116
141
|
|
|
117
142
|
Sprinkle in some `compilerOptions` to the mix
|
|
118
143
|
|
|
119
144
|
```sh
|
|
120
145
|
merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --out ./tsconfig.out.json --allowJs true --noEmit true
|
|
146
|
+
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.out.json
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
// tsconfig.out.json
|
|
151
|
+
{
|
|
152
|
+
"compilerOptions": {
|
|
153
|
+
"allowJS": true,
|
|
154
|
+
"noEmit": true,
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Delete a compiler option
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --allowJS --noEmit 'delete'
|
|
163
|
+
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
// tsconfig.merged.json
|
|
168
|
+
{
|
|
169
|
+
"compilerOptions": {
|
|
170
|
+
"allowJS": true,
|
|
171
|
+
// "noEmit": true, // deleted
|
|
172
|
+
}
|
|
173
|
+
}
|
|
121
174
|
```
|
|
122
175
|
|
|
123
176
|
---
|
|
@@ -152,7 +205,7 @@ Merge tsconfig files into a single tsconfig
|
|
|
152
205
|
const config = mergeTsconfigs({
|
|
153
206
|
files: ['./tsconfig.json', './tsconfig.build.json'],
|
|
154
207
|
});
|
|
155
|
-
//
|
|
208
|
+
// ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
|
|
156
209
|
```
|
|
157
210
|
|
|
158
211
|
Merge tsconfig files into a custom output file
|
|
@@ -162,7 +215,7 @@ const config = mergeTsconfigs({
|
|
|
162
215
|
files: ['./tsconfig.json', './tsconfig.build.json'],
|
|
163
216
|
out: './new-dir/tsconfig.out.json',
|
|
164
217
|
});
|
|
165
|
-
//
|
|
218
|
+
// ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.out.json
|
|
166
219
|
```
|
|
167
220
|
|
|
168
221
|
---
|
|
@@ -175,7 +228,7 @@ Install merge-tsconfigs with your preferred package manager.
|
|
|
175
228
|
npm install merge-tsconfigs --save-dev
|
|
176
229
|
```
|
|
177
230
|
|
|
178
|
-
\*unpkg and skypack support coming very soon! 🚀
|
|
231
|
+
\*[unpkg](https://unpkg.com/merge-tsconfigs@0.1.1/dist/index.js) and [skypack](https://cdn.skypack.dev/merge-tsconfigs?min) support coming very soon! 🚀
|
|
179
232
|
|
|
180
233
|
---
|
|
181
234
|
|
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
mergeTsConfigs: () => mergeTsConfigs,
|
|
27
27
|
resolveJSON: () => resolveJSON,
|
|
28
28
|
script: () => script,
|
|
29
|
+
updateCompilerOptions: () => updateCompilerOptions,
|
|
29
30
|
writeTsconfig: () => writeTsconfig
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -111,6 +112,21 @@ var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
|
111
112
|
(0, import_fs.writeFileSync)(path, JSON.stringify(tsconfig, null, 2));
|
|
112
113
|
return tsconfig;
|
|
113
114
|
};
|
|
115
|
+
var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions) => {
|
|
116
|
+
const compilerOptionKeys = compilerOptions2 ? Object.keys(compilerOptions2) : [];
|
|
117
|
+
const hasCompilerOptions = compilerOptionKeys.length > 0;
|
|
118
|
+
if (!hasCompilerOptions)
|
|
119
|
+
return {};
|
|
120
|
+
return compilerOptionKeys.reduce((acc = {}, key) => {
|
|
121
|
+
const updatedOptions = { ...acc, ...currentCompilerOptions };
|
|
122
|
+
const value = compilerOptions2?.[key];
|
|
123
|
+
if (updatedOptions?.[key] === "delete") {
|
|
124
|
+
delete updatedOptions[key];
|
|
125
|
+
return updatedOptions || {};
|
|
126
|
+
}
|
|
127
|
+
return { ...updatedOptions, [key]: value };
|
|
128
|
+
}, {});
|
|
129
|
+
};
|
|
114
130
|
var mergeTsConfigs = ({
|
|
115
131
|
tsconfigs = [],
|
|
116
132
|
exclude,
|
|
@@ -129,14 +145,14 @@ var mergeTsConfigs = ({
|
|
|
129
145
|
const updatedTsconfig = mergeConfigContent(tsconfigs, cwd, debug);
|
|
130
146
|
if (debug)
|
|
131
147
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
148
|
+
const updatedCompilerOptions = updateCompilerOptions(compilerOptions2, updatedTsconfig?.compilerOptions || {});
|
|
149
|
+
const updatedExclude = exclude ? [...updatedTsconfig?.exclude || [], ...exclude] : updatedTsconfig?.exclude;
|
|
150
|
+
const updatedInclude = include ? [...updatedTsconfig.include || [], ...include] : updatedTsconfig?.include;
|
|
132
151
|
const tsconfig = {
|
|
133
152
|
...updatedTsconfig,
|
|
134
|
-
...
|
|
135
|
-
...
|
|
136
|
-
compilerOptions: {
|
|
137
|
-
...updatedTsconfig?.compilerOptions,
|
|
138
|
-
...compilerOptions2
|
|
139
|
-
}
|
|
153
|
+
...updatedExclude,
|
|
154
|
+
...updatedInclude,
|
|
155
|
+
...Object.keys(updatedCompilerOptions).length > 0 ? { compilerOptions: updatedCompilerOptions } : {}
|
|
140
156
|
};
|
|
141
157
|
return writeTsconfig(tsconfig, cwd, out, isTesting);
|
|
142
158
|
};
|
|
@@ -211,6 +227,8 @@ Object.keys(compilerOptions).map((name) => ({ name, value: compilerOptions[name]
|
|
|
211
227
|
import_commander.program.option(`--${name} <${value}>`, `tsconfig.compilerOptions.${name}`);
|
|
212
228
|
} else if (value === "array") {
|
|
213
229
|
import_commander.program.option(`--${name} [${value}...]`, `tsconfig.compilerOptions.${name}`);
|
|
230
|
+
} else if (value === "object") {
|
|
231
|
+
import_commander.program.option(`--${name} <${value}>`, `tsconfig.compilerOptions.${name}`);
|
|
214
232
|
}
|
|
215
233
|
});
|
|
216
234
|
import_commander.program.action(action).parse(process.argv);
|
|
@@ -224,5 +242,6 @@ var src_default = scripts_default;
|
|
|
224
242
|
mergeTsConfigs,
|
|
225
243
|
resolveJSON,
|
|
226
244
|
script,
|
|
245
|
+
updateCompilerOptions,
|
|
227
246
|
writeTsconfig
|
|
228
247
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { CompilerOptions } from 'typescript';
|
|
2
2
|
import { PartialDeep } from 'type-fest';
|
|
3
3
|
|
|
4
|
+
interface CompilerOptionOverrides {
|
|
5
|
+
[key: string]: string | boolean | string[] | undefined;
|
|
6
|
+
}
|
|
7
|
+
type PartialCompilerOptions = PartialDeep<CompilerOptions | CompilerOptionOverrides>;
|
|
4
8
|
interface ConfigOptions {
|
|
5
|
-
compilerOptions?:
|
|
9
|
+
compilerOptions?: PartialCompilerOptions;
|
|
6
10
|
debug?: boolean;
|
|
7
11
|
out?: string;
|
|
8
12
|
tsconfigs?: string[];
|
|
@@ -27,7 +31,8 @@ declare const logger: ({ isDebugging, emoji, gap, name }: LoggerParams) => (type
|
|
|
27
31
|
declare function resolveJSON(path: string, debug?: boolean): TsConfig;
|
|
28
32
|
declare const mergeConfigContent: (tsconfigs: string[], cwd: string, debug?: boolean) => TsConfig;
|
|
29
33
|
declare const writeTsconfig: (tsconfig: TsConfig, cwd: string, out: string, isTesting: boolean) => TsConfig;
|
|
34
|
+
declare const updateCompilerOptions: (compilerOptions: PartialCompilerOptions | undefined, currentCompilerOptions: PartialCompilerOptions) => PartialCompilerOptions;
|
|
30
35
|
declare const mergeTsConfigs: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
31
36
|
declare const script: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
32
37
|
|
|
33
|
-
export { mergeTsConfigs as default, logger, mergeConfigContent, mergeTsConfigs, resolveJSON, script, writeTsconfig };
|
|
38
|
+
export { mergeTsConfigs as default, logger, mergeConfigContent, mergeTsConfigs, resolveJSON, script, updateCompilerOptions, writeTsconfig };
|
package/dist/index.js
CHANGED
|
@@ -79,6 +79,21 @@ var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
|
79
79
|
writeFileSync(path, JSON.stringify(tsconfig, null, 2));
|
|
80
80
|
return tsconfig;
|
|
81
81
|
};
|
|
82
|
+
var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions) => {
|
|
83
|
+
const compilerOptionKeys = compilerOptions2 ? Object.keys(compilerOptions2) : [];
|
|
84
|
+
const hasCompilerOptions = compilerOptionKeys.length > 0;
|
|
85
|
+
if (!hasCompilerOptions)
|
|
86
|
+
return {};
|
|
87
|
+
return compilerOptionKeys.reduce((acc = {}, key) => {
|
|
88
|
+
const updatedOptions = { ...acc, ...currentCompilerOptions };
|
|
89
|
+
const value = compilerOptions2?.[key];
|
|
90
|
+
if (updatedOptions?.[key] === "delete") {
|
|
91
|
+
delete updatedOptions[key];
|
|
92
|
+
return updatedOptions || {};
|
|
93
|
+
}
|
|
94
|
+
return { ...updatedOptions, [key]: value };
|
|
95
|
+
}, {});
|
|
96
|
+
};
|
|
82
97
|
var mergeTsConfigs = ({
|
|
83
98
|
tsconfigs = [],
|
|
84
99
|
exclude,
|
|
@@ -97,14 +112,14 @@ var mergeTsConfigs = ({
|
|
|
97
112
|
const updatedTsconfig = mergeConfigContent(tsconfigs, cwd, debug);
|
|
98
113
|
if (debug)
|
|
99
114
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
115
|
+
const updatedCompilerOptions = updateCompilerOptions(compilerOptions2, updatedTsconfig?.compilerOptions || {});
|
|
116
|
+
const updatedExclude = exclude ? [...updatedTsconfig?.exclude || [], ...exclude] : updatedTsconfig?.exclude;
|
|
117
|
+
const updatedInclude = include ? [...updatedTsconfig.include || [], ...include] : updatedTsconfig?.include;
|
|
100
118
|
const tsconfig = {
|
|
101
119
|
...updatedTsconfig,
|
|
102
|
-
...
|
|
103
|
-
...
|
|
104
|
-
compilerOptions: {
|
|
105
|
-
...updatedTsconfig?.compilerOptions,
|
|
106
|
-
...compilerOptions2
|
|
107
|
-
}
|
|
120
|
+
...updatedExclude,
|
|
121
|
+
...updatedInclude,
|
|
122
|
+
...Object.keys(updatedCompilerOptions).length > 0 ? { compilerOptions: updatedCompilerOptions } : {}
|
|
108
123
|
};
|
|
109
124
|
return writeTsconfig(tsconfig, cwd, out, isTesting);
|
|
110
125
|
};
|
|
@@ -179,6 +194,8 @@ Object.keys(compilerOptions).map((name) => ({ name, value: compilerOptions[name]
|
|
|
179
194
|
program.option(`--${name} <${value}>`, `tsconfig.compilerOptions.${name}`);
|
|
180
195
|
} else if (value === "array") {
|
|
181
196
|
program.option(`--${name} [${value}...]`, `tsconfig.compilerOptions.${name}`);
|
|
197
|
+
} else if (value === "object") {
|
|
198
|
+
program.option(`--${name} <${value}>`, `tsconfig.compilerOptions.${name}`);
|
|
182
199
|
}
|
|
183
200
|
});
|
|
184
201
|
program.action(action).parse(process.argv);
|
|
@@ -192,5 +209,6 @@ export {
|
|
|
192
209
|
mergeTsConfigs,
|
|
193
210
|
resolveJSON,
|
|
194
211
|
script,
|
|
212
|
+
updateCompilerOptions,
|
|
195
213
|
writeTsconfig
|
|
196
214
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "merge-tsconfigs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Merge-tsconfigs is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want 🛣️",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"unpkg": "dist/index.js",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"import": "./dist/index.js",
|