merge-tsconfigs 0.1.3 → 0.2.0
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 +21 -2
- package/dist/index.cjs +31 -6
- package/dist/index.d.ts +6 -4
- package/dist/index.js +30 -6
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://github.com/yowainwright/merge-tsconfigs)
|
|
9
9
|

|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
_Merge-tsconfigs_ is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want. 💪
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
@@ -82,10 +82,11 @@ Options:
|
|
|
82
82
|
-o, --out [out] output file
|
|
83
83
|
-i, --include [include...] files to include, matches a glob or array pattern
|
|
84
84
|
-e, --exclude [exclude...] files to exclude, matches a glob or array pattern
|
|
85
|
+
-p, --path <path> a json parseable string wrapped object, e.g. {"item/*": ["foo": "bar"]}
|
|
85
86
|
-h, --help display help for command
|
|
86
87
|
```
|
|
87
88
|
|
|
88
|
-
\*`compilerOptions` are not added above for readability (but they can be leveraged). To view all cli options, run `merge-tsconfigs --help`! `compilerOptions.paths`
|
|
89
|
+
\*`compilerOptions` are not added above for readability (but they can be leveraged). To view all cli options, run `merge-tsconfigs --help`! `compilerOptions.paths` is a string wrapped object.
|
|
89
90
|
|
|
90
91
|
#### Recipes
|
|
91
92
|
|
|
@@ -173,6 +174,24 @@ merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --allowJS --noEmit 'delete
|
|
|
173
174
|
}
|
|
174
175
|
```
|
|
175
176
|
|
|
177
|
+
Add a path to `compilerOptions.paths`
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --path '{"item/*": ["foo": "bar"]}'
|
|
181
|
+
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
// tsconfig.merged.json
|
|
186
|
+
{
|
|
187
|
+
"compilerOptions": {
|
|
188
|
+
"paths": {
|
|
189
|
+
"item/*": ["foo": "bar"]
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
176
195
|
---
|
|
177
196
|
|
|
178
197
|
### Node API
|
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ __export(src_exports, {
|
|
|
31
31
|
mergeConfigContent: () => mergeConfigContent,
|
|
32
32
|
mergeConfigObjects: () => mergeConfigObjects,
|
|
33
33
|
mergeTsConfigs: () => mergeTsConfigs,
|
|
34
|
+
parsePath: () => parsePath,
|
|
34
35
|
resolveJSON: () => resolveJSON,
|
|
35
36
|
script: () => script,
|
|
36
37
|
updateCompilerOptions: () => updateCompilerOptions,
|
|
@@ -72,7 +73,6 @@ function resolveJSON(path, debug = false) {
|
|
|
72
73
|
const json = import_json5.default.parse((0, import_fs.readFileSync)(path, "utf8"));
|
|
73
74
|
return json;
|
|
74
75
|
} catch (err) {
|
|
75
|
-
console.log({ err });
|
|
76
76
|
if (debug)
|
|
77
77
|
logger({ isDebugging: debug })("error")("resolveJSON")("There was an error:")(err);
|
|
78
78
|
return {};
|
|
@@ -126,7 +126,7 @@ var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
|
126
126
|
(0, import_fs.writeFileSync)(path, JSON.stringify(tsconfig, null, 2));
|
|
127
127
|
return tsconfig;
|
|
128
128
|
};
|
|
129
|
-
var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions) => {
|
|
129
|
+
var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions, updatedPath) => {
|
|
130
130
|
const compilerOptionKeys = compilerOptions2 ? Object.keys(compilerOptions2) : [];
|
|
131
131
|
const hasCompilerOptions = compilerOptionKeys.length > 0;
|
|
132
132
|
if (!hasCompilerOptions)
|
|
@@ -138,9 +138,26 @@ var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions) => {
|
|
|
138
138
|
delete updatedOptions[key];
|
|
139
139
|
return updatedOptions || {};
|
|
140
140
|
}
|
|
141
|
-
|
|
141
|
+
const paths = {
|
|
142
|
+
...updatedOptions.paths || {},
|
|
143
|
+
...key === "paths" ? { value } : {},
|
|
144
|
+
...updatedPath ? { ...updatedPath } : {}
|
|
145
|
+
};
|
|
146
|
+
return { ...updatedOptions, [key]: value, ...Object.keys(paths).length > 0 ? { paths } : {} };
|
|
142
147
|
}, {});
|
|
143
148
|
};
|
|
149
|
+
var parsePath = (path = "", debug = false) => {
|
|
150
|
+
if (!path)
|
|
151
|
+
return {};
|
|
152
|
+
try {
|
|
153
|
+
const json = import_json5.default.parse(path);
|
|
154
|
+
return json;
|
|
155
|
+
} catch (err) {
|
|
156
|
+
if (debug)
|
|
157
|
+
logger({ isDebugging: debug })("error")("parsePath")("There was an error:")(err);
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
144
161
|
var mergeTsConfigs = ({
|
|
145
162
|
tsconfigs = [],
|
|
146
163
|
exclude,
|
|
@@ -148,6 +165,7 @@ var mergeTsConfigs = ({
|
|
|
148
165
|
compilerOptions: compilerOptions2,
|
|
149
166
|
debug = false,
|
|
150
167
|
out = "tsconfig.merged.json",
|
|
168
|
+
path,
|
|
151
169
|
isTesting = false
|
|
152
170
|
}) => {
|
|
153
171
|
if (tsconfigs.length === 0) {
|
|
@@ -159,7 +177,12 @@ var mergeTsConfigs = ({
|
|
|
159
177
|
const updatedTsconfig = mergeConfigContent(tsconfigs, cwd, debug);
|
|
160
178
|
if (debug)
|
|
161
179
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
162
|
-
const
|
|
180
|
+
const updatedPath = parsePath(path, debug);
|
|
181
|
+
const updatedCompilerOptions = updateCompilerOptions(
|
|
182
|
+
compilerOptions2,
|
|
183
|
+
updatedTsconfig?.compilerOptions || {},
|
|
184
|
+
updatedPath
|
|
185
|
+
);
|
|
163
186
|
const updatedExclude = exclude ? { exclude: [...updatedTsconfig?.exclude || [], ...exclude] } : {};
|
|
164
187
|
const updatedInclude = include ? { include: [...updatedTsconfig.include || [], ...include] } : {};
|
|
165
188
|
const tsconfig = {
|
|
@@ -228,20 +251,21 @@ function action(files, options = {}) {
|
|
|
228
251
|
isTesting = false,
|
|
229
252
|
isTestingCLI = false,
|
|
230
253
|
out,
|
|
254
|
+
path,
|
|
231
255
|
...compilerOptions2
|
|
232
256
|
} = options;
|
|
233
257
|
if (isTestingCLI) {
|
|
234
258
|
console.info({ files, options });
|
|
235
259
|
return;
|
|
236
260
|
}
|
|
237
|
-
script({ debug, exclude, include, isTesting, out, tsconfigs: files, compilerOptions: compilerOptions2 });
|
|
261
|
+
script({ debug, exclude, include, isTesting, path, out, tsconfigs: files, compilerOptions: compilerOptions2 });
|
|
238
262
|
} catch (err) {
|
|
239
263
|
logger({ isDebugging: options.debug })("error")("action")("There was an error:")(err);
|
|
240
264
|
}
|
|
241
265
|
}
|
|
242
266
|
import_commander.program.name("merge-tsconfigs").description(
|
|
243
267
|
"Merge-tsconfigs is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want \u{1F6E3}\uFE0F"
|
|
244
|
-
).argument("[files...]", "files to check, matches an array pattern").option("-d, --debug", "enable debugging").option("-e, --exclude [exclude...]", "files to exclude, matches a glob or array pattern").option("-i, --include [include...]", "files to include, matches a glob or array pattern").option("--isTesting", "enable testing").option("-o, --out <file>", "output file, otherwise, the file will be written to tsconfig.merged.json").option("--isTesting", "enable testing").option("-t, --isTestingCLI", "enable CLI only testing");
|
|
268
|
+
).argument("[files...]", "files to check, matches an array pattern").option("-d, --debug", "enable debugging").option("-e, --exclude [exclude...]", "files to exclude, matches a glob or array pattern").option("-i, --include [include...]", "files to include, matches a glob or array pattern").option("--isTesting", "enable testing").option("-o, --out <file>", "output file, otherwise, the file will be written to tsconfig.merged.json").option("--isTesting", "enable testing").option("-t, --isTestingCLI", "enable CLI only testing").option("-p, --path <path>", 'a json parseable string wrapped object, e.g. {"item/*": ["foo": "bar"]}');
|
|
245
269
|
Object.keys(compilerOptions).map((name) => ({ name, value: compilerOptions[name] })).forEach(({ name, value }) => {
|
|
246
270
|
if (value === "boolean") {
|
|
247
271
|
import_commander.program.option(`--${name}`, `tsconfig.compilerOptions.${name}`);
|
|
@@ -263,6 +287,7 @@ var src_default = scripts_default;
|
|
|
263
287
|
mergeConfigContent,
|
|
264
288
|
mergeConfigObjects,
|
|
265
289
|
mergeTsConfigs,
|
|
290
|
+
parsePath,
|
|
266
291
|
resolveJSON,
|
|
267
292
|
script,
|
|
268
293
|
updateCompilerOptions,
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface ConfigOptions {
|
|
|
14
14
|
tsconfigs?: string[];
|
|
15
15
|
exclude?: string[];
|
|
16
16
|
include?: string[];
|
|
17
|
+
path?: string;
|
|
17
18
|
isTesting?: boolean;
|
|
18
19
|
}
|
|
19
20
|
type LoggerParams = {
|
|
@@ -136,8 +137,9 @@ declare const mergeConfigObjects: (tsconfig1: TsConfig, tsconfig2: TsConfig) =>
|
|
|
136
137
|
};
|
|
137
138
|
declare const mergeConfigContent: (tsconfigs: string[], cwd: string, debug?: boolean) => TsConfig;
|
|
138
139
|
declare const writeTsconfig: (tsconfig: TsConfig, cwd: string, out: string, isTesting: boolean) => TsConfig;
|
|
139
|
-
declare const updateCompilerOptions: (compilerOptions: PartialCompilerOptions | undefined, currentCompilerOptions: PartialCompilerOptions) => PartialCompilerOptions;
|
|
140
|
-
declare const
|
|
141
|
-
declare const
|
|
140
|
+
declare const updateCompilerOptions: (compilerOptions: PartialCompilerOptions | undefined, currentCompilerOptions: PartialCompilerOptions, updatedPath: CompilerOptions['paths']) => PartialCompilerOptions;
|
|
141
|
+
declare const parsePath: (path?: string, debug?: boolean) => CompilerOptions['paths'];
|
|
142
|
+
declare const mergeTsConfigs: ({ tsconfigs, exclude, include, compilerOptions, debug, out, path, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
143
|
+
declare const script: ({ tsconfigs, exclude, include, compilerOptions, debug, out, path, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
142
144
|
|
|
143
|
-
export { mergeTsConfigs as default, logger, mergeConfigContent, mergeConfigObjects, mergeTsConfigs, resolveJSON, script, updateCompilerOptions, writeTsconfig };
|
|
145
|
+
export { mergeTsConfigs as default, logger, mergeConfigContent, mergeConfigObjects, mergeTsConfigs, parsePath, resolveJSON, script, updateCompilerOptions, writeTsconfig };
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,6 @@ function resolveJSON(path, debug = false) {
|
|
|
32
32
|
const json = JSON5.parse(readFileSync(path, "utf8"));
|
|
33
33
|
return json;
|
|
34
34
|
} catch (err) {
|
|
35
|
-
console.log({ err });
|
|
36
35
|
if (debug)
|
|
37
36
|
logger({ isDebugging: debug })("error")("resolveJSON")("There was an error:")(err);
|
|
38
37
|
return {};
|
|
@@ -86,7 +85,7 @@ var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
|
86
85
|
writeFileSync(path, JSON.stringify(tsconfig, null, 2));
|
|
87
86
|
return tsconfig;
|
|
88
87
|
};
|
|
89
|
-
var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions) => {
|
|
88
|
+
var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions, updatedPath) => {
|
|
90
89
|
const compilerOptionKeys = compilerOptions2 ? Object.keys(compilerOptions2) : [];
|
|
91
90
|
const hasCompilerOptions = compilerOptionKeys.length > 0;
|
|
92
91
|
if (!hasCompilerOptions)
|
|
@@ -98,9 +97,26 @@ var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions) => {
|
|
|
98
97
|
delete updatedOptions[key];
|
|
99
98
|
return updatedOptions || {};
|
|
100
99
|
}
|
|
101
|
-
|
|
100
|
+
const paths = {
|
|
101
|
+
...updatedOptions.paths || {},
|
|
102
|
+
...key === "paths" ? { value } : {},
|
|
103
|
+
...updatedPath ? { ...updatedPath } : {}
|
|
104
|
+
};
|
|
105
|
+
return { ...updatedOptions, [key]: value, ...Object.keys(paths).length > 0 ? { paths } : {} };
|
|
102
106
|
}, {});
|
|
103
107
|
};
|
|
108
|
+
var parsePath = (path = "", debug = false) => {
|
|
109
|
+
if (!path)
|
|
110
|
+
return {};
|
|
111
|
+
try {
|
|
112
|
+
const json = JSON5.parse(path);
|
|
113
|
+
return json;
|
|
114
|
+
} catch (err) {
|
|
115
|
+
if (debug)
|
|
116
|
+
logger({ isDebugging: debug })("error")("parsePath")("There was an error:")(err);
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
};
|
|
104
120
|
var mergeTsConfigs = ({
|
|
105
121
|
tsconfigs = [],
|
|
106
122
|
exclude,
|
|
@@ -108,6 +124,7 @@ var mergeTsConfigs = ({
|
|
|
108
124
|
compilerOptions: compilerOptions2,
|
|
109
125
|
debug = false,
|
|
110
126
|
out = "tsconfig.merged.json",
|
|
127
|
+
path,
|
|
111
128
|
isTesting = false
|
|
112
129
|
}) => {
|
|
113
130
|
if (tsconfigs.length === 0) {
|
|
@@ -119,7 +136,12 @@ var mergeTsConfigs = ({
|
|
|
119
136
|
const updatedTsconfig = mergeConfigContent(tsconfigs, cwd, debug);
|
|
120
137
|
if (debug)
|
|
121
138
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
122
|
-
const
|
|
139
|
+
const updatedPath = parsePath(path, debug);
|
|
140
|
+
const updatedCompilerOptions = updateCompilerOptions(
|
|
141
|
+
compilerOptions2,
|
|
142
|
+
updatedTsconfig?.compilerOptions || {},
|
|
143
|
+
updatedPath
|
|
144
|
+
);
|
|
123
145
|
const updatedExclude = exclude ? { exclude: [...updatedTsconfig?.exclude || [], ...exclude] } : {};
|
|
124
146
|
const updatedInclude = include ? { include: [...updatedTsconfig.include || [], ...include] } : {};
|
|
125
147
|
const tsconfig = {
|
|
@@ -188,20 +210,21 @@ function action(files, options = {}) {
|
|
|
188
210
|
isTesting = false,
|
|
189
211
|
isTestingCLI = false,
|
|
190
212
|
out,
|
|
213
|
+
path,
|
|
191
214
|
...compilerOptions2
|
|
192
215
|
} = options;
|
|
193
216
|
if (isTestingCLI) {
|
|
194
217
|
console.info({ files, options });
|
|
195
218
|
return;
|
|
196
219
|
}
|
|
197
|
-
script({ debug, exclude, include, isTesting, out, tsconfigs: files, compilerOptions: compilerOptions2 });
|
|
220
|
+
script({ debug, exclude, include, isTesting, path, out, tsconfigs: files, compilerOptions: compilerOptions2 });
|
|
198
221
|
} catch (err) {
|
|
199
222
|
logger({ isDebugging: options.debug })("error")("action")("There was an error:")(err);
|
|
200
223
|
}
|
|
201
224
|
}
|
|
202
225
|
program.name("merge-tsconfigs").description(
|
|
203
226
|
"Merge-tsconfigs is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want \u{1F6E3}\uFE0F"
|
|
204
|
-
).argument("[files...]", "files to check, matches an array pattern").option("-d, --debug", "enable debugging").option("-e, --exclude [exclude...]", "files to exclude, matches a glob or array pattern").option("-i, --include [include...]", "files to include, matches a glob or array pattern").option("--isTesting", "enable testing").option("-o, --out <file>", "output file, otherwise, the file will be written to tsconfig.merged.json").option("--isTesting", "enable testing").option("-t, --isTestingCLI", "enable CLI only testing");
|
|
227
|
+
).argument("[files...]", "files to check, matches an array pattern").option("-d, --debug", "enable debugging").option("-e, --exclude [exclude...]", "files to exclude, matches a glob or array pattern").option("-i, --include [include...]", "files to include, matches a glob or array pattern").option("--isTesting", "enable testing").option("-o, --out <file>", "output file, otherwise, the file will be written to tsconfig.merged.json").option("--isTesting", "enable testing").option("-t, --isTestingCLI", "enable CLI only testing").option("-p, --path <path>", 'a json parseable string wrapped object, e.g. {"item/*": ["foo": "bar"]}');
|
|
205
228
|
Object.keys(compilerOptions).map((name) => ({ name, value: compilerOptions[name] })).forEach(({ name, value }) => {
|
|
206
229
|
if (value === "boolean") {
|
|
207
230
|
program.option(`--${name}`, `tsconfig.compilerOptions.${name}`);
|
|
@@ -223,6 +246,7 @@ export {
|
|
|
223
246
|
mergeConfigContent,
|
|
224
247
|
mergeConfigObjects,
|
|
225
248
|
mergeTsConfigs,
|
|
249
|
+
parsePath,
|
|
226
250
|
resolveJSON,
|
|
227
251
|
script,
|
|
228
252
|
updateCompilerOptions,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "merge-tsconfigs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lint": "eslint src --ext .ts",
|
|
29
29
|
"lint-fix": "pnpm run lint --fix",
|
|
30
30
|
"pre-commit": "lint-staged",
|
|
31
|
-
"prepare": "husky install",
|
|
31
|
+
"prepare": "husky install && pnpm env use --global 18",
|
|
32
32
|
"prepublishOnly": "pnpm run test && pnpm run build",
|
|
33
33
|
"release": "release-it",
|
|
34
34
|
"setup:config": "mkdir config && cd config npx tsc --init",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"eslint-config-prettier": "^8.6.0",
|
|
52
52
|
"husky": "^8.0.3",
|
|
53
53
|
"lint-staged": "^13.1.0",
|
|
54
|
+
"pnpm": "^7.28.0",
|
|
54
55
|
"prettier": "^2.8.3",
|
|
55
56
|
"release-it": "^15.6.0",
|
|
56
57
|
"rimraf": "^3.0.2",
|
|
@@ -109,10 +110,6 @@
|
|
|
109
110
|
"commitMessage": "chore: release v$npm_package_version"
|
|
110
111
|
}
|
|
111
112
|
},
|
|
112
|
-
"engines": {
|
|
113
|
-
"node": ">=18.0.0",
|
|
114
|
-
"pnpm": ">=7.0.0"
|
|
115
|
-
},
|
|
116
113
|
"keywords": [
|
|
117
114
|
"tsconfig",
|
|
118
115
|
"typescript",
|