merge-tsconfigs 0.1.2 → 0.1.3
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 +9 -2
- package/dist/index.cjs +51 -28
- package/dist/index.d.ts +106 -1
- package/dist/index.js +44 -28
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://github.com/yowainwright/merge-tsconfigs)
|
|
9
9
|

|
|
10
10
|
|
|
11
|
-
_Merge-tsconfigs_ is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want. 💪
|
|
11
|
+
**WIP:** _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
|
|
|
@@ -228,7 +228,14 @@ Install merge-tsconfigs with your preferred package manager.
|
|
|
228
228
|
npm install merge-tsconfigs --save-dev
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
\*
|
|
231
|
+
\*_Untested_: In, Deno, Snowpack, or other options, you can import merge-tsconfigs directly into your project.
|
|
232
|
+
```ts
|
|
233
|
+
import mergeTsconfigs from 'npm:merge-tsconfigs';
|
|
234
|
+
// or
|
|
235
|
+
import mergeTsconfigs from "https://cdn.skypack.dev/merge-tsconfigs@latest";
|
|
236
|
+
// or
|
|
237
|
+
import mergeTsconfigs from "https://unpkg.com/merge-tsconfigs@latest/dist/index.js";
|
|
238
|
+
```
|
|
232
239
|
|
|
233
240
|
---
|
|
234
241
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
18
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
25
|
|
|
20
26
|
// src/index.ts
|
|
@@ -23,6 +29,7 @@ __export(src_exports, {
|
|
|
23
29
|
default: () => src_default,
|
|
24
30
|
logger: () => logger,
|
|
25
31
|
mergeConfigContent: () => mergeConfigContent,
|
|
32
|
+
mergeConfigObjects: () => mergeConfigObjects,
|
|
26
33
|
mergeTsConfigs: () => mergeTsConfigs,
|
|
27
34
|
resolveJSON: () => resolveJSON,
|
|
28
35
|
script: () => script,
|
|
@@ -34,6 +41,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
34
41
|
// src/scripts.ts
|
|
35
42
|
var import_fs = require("fs");
|
|
36
43
|
var import_path = require("path");
|
|
44
|
+
var import_json5 = __toESM(require("json5"), 1);
|
|
37
45
|
var logger = ({ isDebugging = false, emoji = `\u{1F6E3}\uFE0F`, gap = ` => `, name = "merge-tsconfigs" }) => (type) => (section) => (message) => (err) => {
|
|
38
46
|
const debugMsg = isDebugging ? "debugging:" : "";
|
|
39
47
|
const sectionMsg = section.length ? `${section}:` : "";
|
|
@@ -61,7 +69,7 @@ var logger = ({ isDebugging = false, emoji = `\u{1F6E3}\uFE0F`, gap = ` => `, na
|
|
|
61
69
|
};
|
|
62
70
|
function resolveJSON(path, debug = false) {
|
|
63
71
|
try {
|
|
64
|
-
const json =
|
|
72
|
+
const json = import_json5.default.parse((0, import_fs.readFileSync)(path, "utf8"));
|
|
65
73
|
return json;
|
|
66
74
|
} catch (err) {
|
|
67
75
|
console.log({ err });
|
|
@@ -70,6 +78,26 @@ function resolveJSON(path, debug = false) {
|
|
|
70
78
|
return {};
|
|
71
79
|
}
|
|
72
80
|
}
|
|
81
|
+
var mergeConfigObjects = (tsconfig1, tsconfig2) => ({
|
|
82
|
+
...tsconfig1,
|
|
83
|
+
...tsconfig2,
|
|
84
|
+
compilerOptions: {
|
|
85
|
+
...tsconfig1?.compilerOptions,
|
|
86
|
+
...tsconfig2?.compilerOptions
|
|
87
|
+
},
|
|
88
|
+
...tsconfig1?.exclude || tsconfig2?.exclude ? {
|
|
89
|
+
exclude: [
|
|
90
|
+
...tsconfig1?.exclude || [],
|
|
91
|
+
...tsconfig2?.exclude || []
|
|
92
|
+
]
|
|
93
|
+
} : {},
|
|
94
|
+
...tsconfig1?.include || tsconfig2?.include ? {
|
|
95
|
+
include: [
|
|
96
|
+
...tsconfig1?.include || [],
|
|
97
|
+
...tsconfig2?.include || []
|
|
98
|
+
]
|
|
99
|
+
} : {}
|
|
100
|
+
});
|
|
73
101
|
var mergeConfigContent = (tsconfigs, cwd, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
74
102
|
const path = `${cwd}/${tsconfig}`;
|
|
75
103
|
let tsconfigJSON = resolveJSON(path, debug);
|
|
@@ -81,33 +109,19 @@ var mergeConfigContent = (tsconfigs, cwd, debug = false) => tsconfigs.reduce((ac
|
|
|
81
109
|
logger({ isDebugging: debug })("error")("mergeConfigContent")("Parent tsconfig:merge-tsconfigs only handles extending from a parent, consider extending tsconfigs less.")(parentTsconfig);
|
|
82
110
|
}
|
|
83
111
|
const { extends: _, ...tsconfigWithoutExtends } = tsconfigJSON;
|
|
84
|
-
tsconfigJSON =
|
|
85
|
-
...parentTsconfig,
|
|
86
|
-
...tsconfigWithoutExtends,
|
|
87
|
-
compilerOptions: {
|
|
88
|
-
...parentTsconfig?.compilerOptions,
|
|
89
|
-
...tsconfigWithoutExtends?.compilerOptions
|
|
90
|
-
}
|
|
91
|
-
};
|
|
112
|
+
tsconfigJSON = mergeConfigObjects(parentTsconfig, tsconfigWithoutExtends);
|
|
92
113
|
}
|
|
93
114
|
if (!tsconfigJSON) {
|
|
94
115
|
if (debug)
|
|
95
116
|
logger({ isDebugging: debug })("error")("mergeConfigContent")("There was an error:")(tsconfigJSON);
|
|
96
117
|
return acc;
|
|
97
118
|
}
|
|
98
|
-
return
|
|
99
|
-
...acc,
|
|
100
|
-
...tsconfigJSON,
|
|
101
|
-
compilerOptions: {
|
|
102
|
-
...acc?.compilerOptions,
|
|
103
|
-
...tsconfigJSON?.compilerOptions
|
|
104
|
-
}
|
|
105
|
-
};
|
|
119
|
+
return mergeConfigObjects(acc, tsconfigJSON);
|
|
106
120
|
}, {});
|
|
107
121
|
var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
108
122
|
if (isTesting)
|
|
109
123
|
return tsconfig;
|
|
110
|
-
const path =
|
|
124
|
+
const path = `${cwd}/${out}`;
|
|
111
125
|
(0, import_fs.mkdirSync)((0, import_path.dirname)(path), { recursive: true });
|
|
112
126
|
(0, import_fs.writeFileSync)(path, JSON.stringify(tsconfig, null, 2));
|
|
113
127
|
return tsconfig;
|
|
@@ -133,7 +147,7 @@ var mergeTsConfigs = ({
|
|
|
133
147
|
include,
|
|
134
148
|
compilerOptions: compilerOptions2,
|
|
135
149
|
debug = false,
|
|
136
|
-
out = "",
|
|
150
|
+
out = "tsconfig.merged.json",
|
|
137
151
|
isTesting = false
|
|
138
152
|
}) => {
|
|
139
153
|
if (tsconfigs.length === 0) {
|
|
@@ -146,8 +160,8 @@ var mergeTsConfigs = ({
|
|
|
146
160
|
if (debug)
|
|
147
161
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
148
162
|
const updatedCompilerOptions = updateCompilerOptions(compilerOptions2, updatedTsconfig?.compilerOptions || {});
|
|
149
|
-
const updatedExclude = exclude ? [...updatedTsconfig?.exclude || [], ...exclude] :
|
|
150
|
-
const updatedInclude = include ? [...updatedTsconfig.include || [], ...include] :
|
|
163
|
+
const updatedExclude = exclude ? { exclude: [...updatedTsconfig?.exclude || [], ...exclude] } : {};
|
|
164
|
+
const updatedInclude = include ? { include: [...updatedTsconfig.include || [], ...include] } : {};
|
|
151
165
|
const tsconfig = {
|
|
152
166
|
...updatedTsconfig,
|
|
153
167
|
...updatedExclude,
|
|
@@ -205,14 +219,22 @@ var compilerOptions = {
|
|
|
205
219
|
};
|
|
206
220
|
|
|
207
221
|
// src/program.ts
|
|
208
|
-
|
|
209
|
-
const { debug = false, isTesting = false, isTestingCLI = false, ...compilerOptions2 } = options;
|
|
210
|
-
if (isTestingCLI) {
|
|
211
|
-
console.info({ files, options });
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
222
|
+
function action(files, options = {}) {
|
|
214
223
|
try {
|
|
215
|
-
|
|
224
|
+
const {
|
|
225
|
+
debug = false,
|
|
226
|
+
exclude,
|
|
227
|
+
include,
|
|
228
|
+
isTesting = false,
|
|
229
|
+
isTestingCLI = false,
|
|
230
|
+
out,
|
|
231
|
+
...compilerOptions2
|
|
232
|
+
} = options;
|
|
233
|
+
if (isTestingCLI) {
|
|
234
|
+
console.info({ files, options });
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
script({ debug, exclude, include, isTesting, out, tsconfigs: files, compilerOptions: compilerOptions2 });
|
|
216
238
|
} catch (err) {
|
|
217
239
|
logger({ isDebugging: options.debug })("error")("action")("There was an error:")(err);
|
|
218
240
|
}
|
|
@@ -239,6 +261,7 @@ var src_default = scripts_default;
|
|
|
239
261
|
0 && (module.exports = {
|
|
240
262
|
logger,
|
|
241
263
|
mergeConfigContent,
|
|
264
|
+
mergeConfigObjects,
|
|
242
265
|
mergeTsConfigs,
|
|
243
266
|
resolveJSON,
|
|
244
267
|
script,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as type_fest_source_partial_deep from 'type-fest/source/partial-deep';
|
|
2
|
+
import * as typescript from 'typescript';
|
|
1
3
|
import { CompilerOptions } from 'typescript';
|
|
2
4
|
import { PartialDeep } from 'type-fest';
|
|
3
5
|
|
|
@@ -29,10 +31,113 @@ interface TsConfig {
|
|
|
29
31
|
|
|
30
32
|
declare const logger: ({ isDebugging, emoji, gap, name }: LoggerParams) => (type: string) => (section: string) => (message: string) => (err: unknown) => void;
|
|
31
33
|
declare function resolveJSON(path: string, debug?: boolean): TsConfig;
|
|
34
|
+
declare const mergeConfigObjects: (tsconfig1: TsConfig, tsconfig2: TsConfig) => {
|
|
35
|
+
include?: string[] | undefined;
|
|
36
|
+
exclude?: string[] | undefined;
|
|
37
|
+
compilerOptions: {
|
|
38
|
+
[x: string]: string | number | boolean | string[] | (string | number)[] | typescript.PluginImport[] | typescript.ProjectReference[] | type_fest_source_partial_deep.PartialObjectDeep<typescript.MapLike<string[]>, {}> | type_fest_source_partial_deep.PartialObjectDeep<typescript.TsConfigSourceFile, {}> | null | undefined;
|
|
39
|
+
allowJs?: boolean | undefined;
|
|
40
|
+
allowSyntheticDefaultImports?: boolean | undefined;
|
|
41
|
+
allowUmdGlobalAccess?: boolean | undefined;
|
|
42
|
+
allowUnreachableCode?: boolean | undefined;
|
|
43
|
+
allowUnusedLabels?: boolean | undefined;
|
|
44
|
+
alwaysStrict?: boolean | undefined;
|
|
45
|
+
baseUrl?: string | undefined;
|
|
46
|
+
charset?: string | undefined;
|
|
47
|
+
checkJs?: boolean | undefined;
|
|
48
|
+
declaration?: boolean | undefined;
|
|
49
|
+
declarationMap?: boolean | undefined;
|
|
50
|
+
emitDeclarationOnly?: boolean | undefined;
|
|
51
|
+
declarationDir?: string | undefined;
|
|
52
|
+
disableSizeLimit?: boolean | undefined;
|
|
53
|
+
disableSourceOfProjectReferenceRedirect?: boolean | undefined;
|
|
54
|
+
disableSolutionSearching?: boolean | undefined;
|
|
55
|
+
disableReferencedProjectLoad?: boolean | undefined;
|
|
56
|
+
downlevelIteration?: boolean | undefined;
|
|
57
|
+
emitBOM?: boolean | undefined;
|
|
58
|
+
emitDecoratorMetadata?: boolean | undefined;
|
|
59
|
+
exactOptionalPropertyTypes?: boolean | undefined;
|
|
60
|
+
experimentalDecorators?: boolean | undefined;
|
|
61
|
+
forceConsistentCasingInFileNames?: boolean | undefined;
|
|
62
|
+
importHelpers?: boolean | undefined;
|
|
63
|
+
importsNotUsedAsValues?: typescript.ImportsNotUsedAsValues | undefined;
|
|
64
|
+
inlineSourceMap?: boolean | undefined;
|
|
65
|
+
inlineSources?: boolean | undefined;
|
|
66
|
+
isolatedModules?: boolean | undefined;
|
|
67
|
+
jsx?: typescript.JsxEmit | undefined;
|
|
68
|
+
keyofStringsOnly?: boolean | undefined;
|
|
69
|
+
lib?: string[] | undefined;
|
|
70
|
+
locale?: string | undefined;
|
|
71
|
+
mapRoot?: string | undefined;
|
|
72
|
+
maxNodeModuleJsDepth?: number | undefined;
|
|
73
|
+
module?: typescript.ModuleKind | undefined;
|
|
74
|
+
moduleResolution?: typescript.ModuleResolutionKind | undefined;
|
|
75
|
+
moduleSuffixes?: string[] | undefined;
|
|
76
|
+
moduleDetection?: typescript.ModuleDetectionKind | undefined;
|
|
77
|
+
newLine?: typescript.NewLineKind | undefined;
|
|
78
|
+
noEmit?: boolean | undefined;
|
|
79
|
+
noEmitHelpers?: boolean | undefined;
|
|
80
|
+
noEmitOnError?: boolean | undefined;
|
|
81
|
+
noErrorTruncation?: boolean | undefined;
|
|
82
|
+
noFallthroughCasesInSwitch?: boolean | undefined;
|
|
83
|
+
noImplicitAny?: boolean | undefined;
|
|
84
|
+
noImplicitReturns?: boolean | undefined;
|
|
85
|
+
noImplicitThis?: boolean | undefined;
|
|
86
|
+
noStrictGenericChecks?: boolean | undefined;
|
|
87
|
+
noUnusedLocals?: boolean | undefined;
|
|
88
|
+
noUnusedParameters?: boolean | undefined;
|
|
89
|
+
noImplicitUseStrict?: boolean | undefined;
|
|
90
|
+
noPropertyAccessFromIndexSignature?: boolean | undefined;
|
|
91
|
+
assumeChangesOnlyAffectDirectDependencies?: boolean | undefined;
|
|
92
|
+
noLib?: boolean | undefined;
|
|
93
|
+
noResolve?: boolean | undefined;
|
|
94
|
+
noUncheckedIndexedAccess?: boolean | undefined;
|
|
95
|
+
out?: string | undefined;
|
|
96
|
+
outDir?: string | undefined;
|
|
97
|
+
outFile?: string | undefined;
|
|
98
|
+
paths?: type_fest_source_partial_deep.PartialObjectDeep<typescript.MapLike<string[]>, {}> | undefined;
|
|
99
|
+
preserveConstEnums?: boolean | undefined;
|
|
100
|
+
noImplicitOverride?: boolean | undefined;
|
|
101
|
+
preserveSymlinks?: boolean | undefined;
|
|
102
|
+
preserveValueImports?: boolean | undefined;
|
|
103
|
+
project?: string | undefined;
|
|
104
|
+
reactNamespace?: string | undefined;
|
|
105
|
+
jsxFactory?: string | undefined;
|
|
106
|
+
jsxFragmentFactory?: string | undefined;
|
|
107
|
+
jsxImportSource?: string | undefined;
|
|
108
|
+
composite?: boolean | undefined;
|
|
109
|
+
incremental?: boolean | undefined;
|
|
110
|
+
tsBuildInfoFile?: string | undefined;
|
|
111
|
+
removeComments?: boolean | undefined;
|
|
112
|
+
rootDir?: string | undefined;
|
|
113
|
+
rootDirs?: string[] | undefined;
|
|
114
|
+
skipLibCheck?: boolean | undefined;
|
|
115
|
+
skipDefaultLibCheck?: boolean | undefined;
|
|
116
|
+
sourceMap?: boolean | undefined;
|
|
117
|
+
sourceRoot?: string | undefined;
|
|
118
|
+
strict?: boolean | undefined;
|
|
119
|
+
strictFunctionTypes?: boolean | undefined;
|
|
120
|
+
strictBindCallApply?: boolean | undefined;
|
|
121
|
+
strictNullChecks?: boolean | undefined;
|
|
122
|
+
strictPropertyInitialization?: boolean | undefined;
|
|
123
|
+
stripInternal?: boolean | undefined;
|
|
124
|
+
suppressExcessPropertyErrors?: boolean | undefined;
|
|
125
|
+
suppressImplicitAnyIndexErrors?: boolean | undefined;
|
|
126
|
+
target?: typescript.ScriptTarget | undefined;
|
|
127
|
+
traceResolution?: boolean | undefined;
|
|
128
|
+
useUnknownInCatchVariables?: boolean | undefined;
|
|
129
|
+
resolveJsonModule?: boolean | undefined;
|
|
130
|
+
types?: string[] | undefined;
|
|
131
|
+
typeRoots?: string[] | undefined;
|
|
132
|
+
esModuleInterop?: boolean | undefined;
|
|
133
|
+
useDefineForClassFields?: boolean | undefined;
|
|
134
|
+
};
|
|
135
|
+
extends?: string | undefined;
|
|
136
|
+
};
|
|
32
137
|
declare const mergeConfigContent: (tsconfigs: string[], cwd: string, debug?: boolean) => TsConfig;
|
|
33
138
|
declare const writeTsconfig: (tsconfig: TsConfig, cwd: string, out: string, isTesting: boolean) => TsConfig;
|
|
34
139
|
declare const updateCompilerOptions: (compilerOptions: PartialCompilerOptions | undefined, currentCompilerOptions: PartialCompilerOptions) => PartialCompilerOptions;
|
|
35
140
|
declare const mergeTsConfigs: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
36
141
|
declare const script: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
37
142
|
|
|
38
|
-
export { mergeTsConfigs as default, logger, mergeConfigContent, mergeTsConfigs, resolveJSON, script, updateCompilerOptions, writeTsconfig };
|
|
143
|
+
export { mergeTsConfigs as default, logger, mergeConfigContent, mergeConfigObjects, mergeTsConfigs, resolveJSON, script, updateCompilerOptions, writeTsconfig };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/scripts.ts
|
|
2
2
|
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
3
|
import { dirname, join } from "path";
|
|
4
|
+
import JSON5 from "json5";
|
|
4
5
|
var logger = ({ isDebugging = false, emoji = `\u{1F6E3}\uFE0F`, gap = ` => `, name = "merge-tsconfigs" }) => (type) => (section) => (message) => (err) => {
|
|
5
6
|
const debugMsg = isDebugging ? "debugging:" : "";
|
|
6
7
|
const sectionMsg = section.length ? `${section}:` : "";
|
|
@@ -28,7 +29,7 @@ var logger = ({ isDebugging = false, emoji = `\u{1F6E3}\uFE0F`, gap = ` => `, na
|
|
|
28
29
|
};
|
|
29
30
|
function resolveJSON(path, debug = false) {
|
|
30
31
|
try {
|
|
31
|
-
const json =
|
|
32
|
+
const json = JSON5.parse(readFileSync(path, "utf8"));
|
|
32
33
|
return json;
|
|
33
34
|
} catch (err) {
|
|
34
35
|
console.log({ err });
|
|
@@ -37,6 +38,26 @@ function resolveJSON(path, debug = false) {
|
|
|
37
38
|
return {};
|
|
38
39
|
}
|
|
39
40
|
}
|
|
41
|
+
var mergeConfigObjects = (tsconfig1, tsconfig2) => ({
|
|
42
|
+
...tsconfig1,
|
|
43
|
+
...tsconfig2,
|
|
44
|
+
compilerOptions: {
|
|
45
|
+
...tsconfig1?.compilerOptions,
|
|
46
|
+
...tsconfig2?.compilerOptions
|
|
47
|
+
},
|
|
48
|
+
...tsconfig1?.exclude || tsconfig2?.exclude ? {
|
|
49
|
+
exclude: [
|
|
50
|
+
...tsconfig1?.exclude || [],
|
|
51
|
+
...tsconfig2?.exclude || []
|
|
52
|
+
]
|
|
53
|
+
} : {},
|
|
54
|
+
...tsconfig1?.include || tsconfig2?.include ? {
|
|
55
|
+
include: [
|
|
56
|
+
...tsconfig1?.include || [],
|
|
57
|
+
...tsconfig2?.include || []
|
|
58
|
+
]
|
|
59
|
+
} : {}
|
|
60
|
+
});
|
|
40
61
|
var mergeConfigContent = (tsconfigs, cwd, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
41
62
|
const path = `${cwd}/${tsconfig}`;
|
|
42
63
|
let tsconfigJSON = resolveJSON(path, debug);
|
|
@@ -48,33 +69,19 @@ var mergeConfigContent = (tsconfigs, cwd, debug = false) => tsconfigs.reduce((ac
|
|
|
48
69
|
logger({ isDebugging: debug })("error")("mergeConfigContent")("Parent tsconfig:merge-tsconfigs only handles extending from a parent, consider extending tsconfigs less.")(parentTsconfig);
|
|
49
70
|
}
|
|
50
71
|
const { extends: _, ...tsconfigWithoutExtends } = tsconfigJSON;
|
|
51
|
-
tsconfigJSON =
|
|
52
|
-
...parentTsconfig,
|
|
53
|
-
...tsconfigWithoutExtends,
|
|
54
|
-
compilerOptions: {
|
|
55
|
-
...parentTsconfig?.compilerOptions,
|
|
56
|
-
...tsconfigWithoutExtends?.compilerOptions
|
|
57
|
-
}
|
|
58
|
-
};
|
|
72
|
+
tsconfigJSON = mergeConfigObjects(parentTsconfig, tsconfigWithoutExtends);
|
|
59
73
|
}
|
|
60
74
|
if (!tsconfigJSON) {
|
|
61
75
|
if (debug)
|
|
62
76
|
logger({ isDebugging: debug })("error")("mergeConfigContent")("There was an error:")(tsconfigJSON);
|
|
63
77
|
return acc;
|
|
64
78
|
}
|
|
65
|
-
return
|
|
66
|
-
...acc,
|
|
67
|
-
...tsconfigJSON,
|
|
68
|
-
compilerOptions: {
|
|
69
|
-
...acc?.compilerOptions,
|
|
70
|
-
...tsconfigJSON?.compilerOptions
|
|
71
|
-
}
|
|
72
|
-
};
|
|
79
|
+
return mergeConfigObjects(acc, tsconfigJSON);
|
|
73
80
|
}, {});
|
|
74
81
|
var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
75
82
|
if (isTesting)
|
|
76
83
|
return tsconfig;
|
|
77
|
-
const path =
|
|
84
|
+
const path = `${cwd}/${out}`;
|
|
78
85
|
mkdirSync(dirname(path), { recursive: true });
|
|
79
86
|
writeFileSync(path, JSON.stringify(tsconfig, null, 2));
|
|
80
87
|
return tsconfig;
|
|
@@ -100,7 +107,7 @@ var mergeTsConfigs = ({
|
|
|
100
107
|
include,
|
|
101
108
|
compilerOptions: compilerOptions2,
|
|
102
109
|
debug = false,
|
|
103
|
-
out = "",
|
|
110
|
+
out = "tsconfig.merged.json",
|
|
104
111
|
isTesting = false
|
|
105
112
|
}) => {
|
|
106
113
|
if (tsconfigs.length === 0) {
|
|
@@ -113,8 +120,8 @@ var mergeTsConfigs = ({
|
|
|
113
120
|
if (debug)
|
|
114
121
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
115
122
|
const updatedCompilerOptions = updateCompilerOptions(compilerOptions2, updatedTsconfig?.compilerOptions || {});
|
|
116
|
-
const updatedExclude = exclude ? [...updatedTsconfig?.exclude || [], ...exclude] :
|
|
117
|
-
const updatedInclude = include ? [...updatedTsconfig.include || [], ...include] :
|
|
123
|
+
const updatedExclude = exclude ? { exclude: [...updatedTsconfig?.exclude || [], ...exclude] } : {};
|
|
124
|
+
const updatedInclude = include ? { include: [...updatedTsconfig.include || [], ...include] } : {};
|
|
118
125
|
const tsconfig = {
|
|
119
126
|
...updatedTsconfig,
|
|
120
127
|
...updatedExclude,
|
|
@@ -172,14 +179,22 @@ var compilerOptions = {
|
|
|
172
179
|
};
|
|
173
180
|
|
|
174
181
|
// src/program.ts
|
|
175
|
-
|
|
176
|
-
const { debug = false, isTesting = false, isTestingCLI = false, ...compilerOptions2 } = options;
|
|
177
|
-
if (isTestingCLI) {
|
|
178
|
-
console.info({ files, options });
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
182
|
+
function action(files, options = {}) {
|
|
181
183
|
try {
|
|
182
|
-
|
|
184
|
+
const {
|
|
185
|
+
debug = false,
|
|
186
|
+
exclude,
|
|
187
|
+
include,
|
|
188
|
+
isTesting = false,
|
|
189
|
+
isTestingCLI = false,
|
|
190
|
+
out,
|
|
191
|
+
...compilerOptions2
|
|
192
|
+
} = options;
|
|
193
|
+
if (isTestingCLI) {
|
|
194
|
+
console.info({ files, options });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
script({ debug, exclude, include, isTesting, out, tsconfigs: files, compilerOptions: compilerOptions2 });
|
|
183
198
|
} catch (err) {
|
|
184
199
|
logger({ isDebugging: options.debug })("error")("action")("There was an error:")(err);
|
|
185
200
|
}
|
|
@@ -206,6 +221,7 @@ export {
|
|
|
206
221
|
src_default as default,
|
|
207
222
|
logger,
|
|
208
223
|
mergeConfigContent,
|
|
224
|
+
mergeConfigObjects,
|
|
209
225
|
mergeTsConfigs,
|
|
210
226
|
resolveJSON,
|
|
211
227
|
script,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "merge-tsconfigs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
23
23
|
"clean": "rimraf dist config",
|
|
24
24
|
"cmd:test": "ts-node src/program.ts --isTestingCLI",
|
|
25
|
+
"cmd:test:cli": "ts-node src/program.ts 'tsconfig.json' --out 'tsconfig.test.json' --outDir 'fooboo' --debug",
|
|
25
26
|
"commit": "git-cz",
|
|
26
27
|
"commit-msg": "commitlint --edit $1",
|
|
27
28
|
"lint": "eslint src --ext .ts",
|
|
@@ -36,7 +37,8 @@
|
|
|
36
37
|
"update": "codependence --update"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"commander": "^9.5.0"
|
|
40
|
+
"commander": "^9.5.0",
|
|
41
|
+
"json5": "^2.2.3"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@commitlint/cli": "^17.4.2",
|