merge-tsconfigs 0.0.7 → 0.1.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 +39 -0
- package/dist/index.cjs +39 -19
- package/dist/index.d.ts +6 -5
- package/dist/index.js +40 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,10 @@ _Merge-tsconfigs_ is a CLI and node tool for merging tsconfig files into the exa
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
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)** | **[Install](#how-do-i-start-using-this)**
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
13
17
|
## Why do I want this?
|
|
14
18
|
|
|
15
19
|
Tsconfig files are copied, pasted, or left as out-of-sync widows 😥 throughout projects. _Merge-tsconfigs_ provides a CLI and node functions to merge tsconfigs files and compilerOptions into _the single tsconfig file you want at a given time_.
|
|
@@ -20,6 +24,41 @@ By providing an easy way to create the tsconfig you want, your everyday tsconfig
|
|
|
20
24
|
|
|
21
25
|
---
|
|
22
26
|
|
|
27
|
+
### _For example_
|
|
28
|
+
|
|
29
|
+
By running `merge-tsconfigs ./tsconfig.build.json` you'll merge `tsconfig.json`
|
|
30
|
+
```ts
|
|
31
|
+
{
|
|
32
|
+
"compilerOptions": {
|
|
33
|
+
"allowJS": true
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
and, `tsconfig.build.json`
|
|
39
|
+
```ts
|
|
40
|
+
{
|
|
41
|
+
"compilerOptions": {
|
|
42
|
+
"target": "esnext"
|
|
43
|
+
},
|
|
44
|
+
"extends": "./tsconfig.json"
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
into `tsconfig.merged.json`
|
|
49
|
+
```ts
|
|
50
|
+
{
|
|
51
|
+
"compilerOptions": {
|
|
52
|
+
"allowJS": true,
|
|
53
|
+
"target": "esnext"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Which you can now use for deployment, dockerfiles, or any other use case. And, you don't have to worry about copying, pasting, or keeping track of multiple tsconfigs! 🎉
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
23
62
|
## How do I use this?
|
|
24
63
|
|
|
25
64
|
Merge-tsconfigs is built to be uses as a CLI first and foremost. It also exports node functions which can be used to preform the same merge operation.
|
package/dist/index.cjs
CHANGED
|
@@ -63,21 +63,30 @@ function resolveJSON(path, debug = false) {
|
|
|
63
63
|
const json = JSON.parse((0, import_fs.readFileSync)(path, "utf8"));
|
|
64
64
|
return json;
|
|
65
65
|
} catch (err) {
|
|
66
|
+
console.log({ err });
|
|
66
67
|
if (debug)
|
|
67
68
|
logger({ isDebugging: debug })("error")("resolveJSON")("There was an error:")(err);
|
|
68
69
|
return {};
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
|
-
var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
var mergeConfigContent = (tsconfigs, cwd, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
73
|
+
const path = `${cwd}/${tsconfig}`;
|
|
74
|
+
let tsconfigJSON = resolveJSON(path, debug);
|
|
75
|
+
const parentPath = tsconfigJSON?.extends;
|
|
76
|
+
if (parentPath) {
|
|
77
|
+
const relativeParentPath = (0, import_path.join)((0, import_path.dirname)(path), parentPath);
|
|
78
|
+
const parentTsconfig = resolveJSON(relativeParentPath, debug);
|
|
75
79
|
if (parentTsconfig?.extends) {
|
|
76
|
-
logger({ isDebugging:
|
|
80
|
+
logger({ isDebugging: debug })("error")("mergeConfigContent")("Parent tsconfig:merge-tsconfigs only handles extending from a parent, consider extending tsconfigs less.")(parentTsconfig);
|
|
77
81
|
}
|
|
82
|
+
const { extends: _, ...tsconfigWithoutExtends } = tsconfigJSON;
|
|
78
83
|
tsconfigJSON = {
|
|
79
84
|
...parentTsconfig,
|
|
80
|
-
...
|
|
85
|
+
...tsconfigWithoutExtends,
|
|
86
|
+
compilerOptions: {
|
|
87
|
+
...parentTsconfig?.compilerOptions,
|
|
88
|
+
...tsconfigWithoutExtends?.compilerOptions
|
|
89
|
+
}
|
|
81
90
|
};
|
|
82
91
|
}
|
|
83
92
|
if (!tsconfigJSON) {
|
|
@@ -87,38 +96,49 @@ var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {
|
|
|
87
96
|
}
|
|
88
97
|
return {
|
|
89
98
|
...acc,
|
|
90
|
-
...tsconfigJSON
|
|
99
|
+
...tsconfigJSON,
|
|
100
|
+
compilerOptions: {
|
|
101
|
+
...acc?.compilerOptions,
|
|
102
|
+
...tsconfigJSON?.compilerOptions
|
|
103
|
+
}
|
|
91
104
|
};
|
|
92
105
|
}, {});
|
|
93
|
-
var writeTsconfig = (tsconfig, out) => {
|
|
94
|
-
|
|
106
|
+
var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
107
|
+
if (isTesting)
|
|
108
|
+
return tsconfig;
|
|
109
|
+
const path = out.length ? out : `${cwd}/tsconfig.merged.json`;
|
|
95
110
|
(0, import_fs.mkdirSync)((0, import_path.dirname)(path), { recursive: true });
|
|
96
111
|
(0, import_fs.writeFileSync)(path, JSON.stringify(tsconfig, null, 2));
|
|
97
112
|
return tsconfig;
|
|
98
113
|
};
|
|
99
114
|
var mergeTsConfigs = ({
|
|
100
115
|
tsconfigs = [],
|
|
101
|
-
exclude
|
|
102
|
-
include
|
|
103
|
-
compilerOptions: compilerOptions2
|
|
116
|
+
exclude,
|
|
117
|
+
include,
|
|
118
|
+
compilerOptions: compilerOptions2,
|
|
104
119
|
debug = false,
|
|
105
|
-
out = ""
|
|
120
|
+
out = "",
|
|
121
|
+
isTesting = false
|
|
106
122
|
}) => {
|
|
107
123
|
if (tsconfigs.length === 0) {
|
|
108
124
|
if (debug)
|
|
109
125
|
logger({ isDebugging: debug })("error")("mergeTsConfig")("No tsconfig files were provided.")(null);
|
|
110
126
|
return;
|
|
111
127
|
}
|
|
112
|
-
const
|
|
128
|
+
const cwd = process.cwd();
|
|
129
|
+
const updatedTsconfig = mergeConfigContent(tsconfigs, cwd, debug);
|
|
113
130
|
if (debug)
|
|
114
131
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
115
132
|
const tsconfig = {
|
|
116
133
|
...updatedTsconfig,
|
|
117
|
-
exclude
|
|
118
|
-
include
|
|
119
|
-
|
|
134
|
+
...exclude ? [...updatedTsconfig?.exclude || [], ...exclude] : updatedTsconfig?.exclude,
|
|
135
|
+
...include ? [...updatedTsconfig.include || [], ...include] : updatedTsconfig?.include,
|
|
136
|
+
compilerOptions: {
|
|
137
|
+
...updatedTsconfig?.compilerOptions,
|
|
138
|
+
...compilerOptions2
|
|
139
|
+
}
|
|
120
140
|
};
|
|
121
|
-
return writeTsconfig(tsconfig, out);
|
|
141
|
+
return writeTsconfig(tsconfig, cwd, out, isTesting);
|
|
122
142
|
};
|
|
123
143
|
var script = mergeTsConfigs;
|
|
124
144
|
var scripts_default = mergeTsConfigs;
|
|
@@ -183,7 +203,7 @@ async function action(files, options = {}) {
|
|
|
183
203
|
}
|
|
184
204
|
import_commander.program.name("merge-tsconfigs").description(
|
|
185
205
|
"Merge-tsconfigs is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want \u{1F6E3}\uFE0F"
|
|
186
|
-
).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("-t, --isTestingCLI", "enable CLI only testing");
|
|
206
|
+
).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");
|
|
187
207
|
Object.keys(compilerOptions).map((name) => ({ name, value: compilerOptions[name] })).forEach(({ name, value }) => {
|
|
188
208
|
if (value === "boolean") {
|
|
189
209
|
import_commander.program.option(`--${name}`, `tsconfig.compilerOptions.${name}`);
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface ConfigOptions {
|
|
|
8
8
|
tsconfigs?: string[];
|
|
9
9
|
exclude?: string[];
|
|
10
10
|
include?: string[];
|
|
11
|
+
isTesting?: boolean;
|
|
11
12
|
}
|
|
12
13
|
type LoggerParams = {
|
|
13
14
|
isDebugging?: boolean;
|
|
@@ -17,16 +18,16 @@ type LoggerParams = {
|
|
|
17
18
|
};
|
|
18
19
|
interface TsConfig {
|
|
19
20
|
extends?: string;
|
|
20
|
-
compilerOptions?: CompilerOptions
|
|
21
|
+
compilerOptions?: PartialDeep<CompilerOptions>;
|
|
21
22
|
include?: string[];
|
|
22
23
|
exclude?: string[];
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
declare const logger: ({ isDebugging, emoji, gap, name }: LoggerParams) => (type: string) => (section: string) => (message: string) => (err: unknown) => void;
|
|
26
27
|
declare function resolveJSON(path: string, debug?: boolean): TsConfig;
|
|
27
|
-
declare const mergeConfigContent: (tsconfigs: string[], debug?: boolean) => TsConfig;
|
|
28
|
-
declare const writeTsconfig: (tsconfig: TsConfig, out: string) => TsConfig;
|
|
29
|
-
declare const mergeTsConfigs: ({ tsconfigs, exclude, include, compilerOptions, debug, out, }: ConfigOptions) => TsConfig | undefined;
|
|
30
|
-
declare const script: ({ tsconfigs, exclude, include, compilerOptions, debug, out, }: ConfigOptions) => TsConfig | undefined;
|
|
28
|
+
declare const mergeConfigContent: (tsconfigs: string[], cwd: string, debug?: boolean) => TsConfig;
|
|
29
|
+
declare const writeTsconfig: (tsconfig: TsConfig, cwd: string, out: string, isTesting: boolean) => TsConfig;
|
|
30
|
+
declare const mergeTsConfigs: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
31
|
+
declare const script: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
31
32
|
|
|
32
33
|
export { mergeTsConfigs as default, logger, mergeConfigContent, mergeTsConfigs, resolveJSON, script, writeTsconfig };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/scripts.ts
|
|
2
2
|
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
-
import { dirname } from "path";
|
|
3
|
+
import { dirname, join } from "path";
|
|
4
4
|
var logger = ({ isDebugging = false, emoji = `\u{1F6E3}\uFE0F`, gap = ` => `, name = "merge-tsconfigs" }) => (type) => (section) => (message) => (err) => {
|
|
5
5
|
const debugMsg = isDebugging ? "debugging:" : "";
|
|
6
6
|
const sectionMsg = section.length ? `${section}:` : "";
|
|
@@ -31,21 +31,30 @@ function resolveJSON(path, debug = false) {
|
|
|
31
31
|
const json = JSON.parse(readFileSync(path, "utf8"));
|
|
32
32
|
return json;
|
|
33
33
|
} catch (err) {
|
|
34
|
+
console.log({ err });
|
|
34
35
|
if (debug)
|
|
35
36
|
logger({ isDebugging: debug })("error")("resolveJSON")("There was an error:")(err);
|
|
36
37
|
return {};
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
var mergeConfigContent = (tsconfigs, cwd, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
41
|
+
const path = `${cwd}/${tsconfig}`;
|
|
42
|
+
let tsconfigJSON = resolveJSON(path, debug);
|
|
43
|
+
const parentPath = tsconfigJSON?.extends;
|
|
44
|
+
if (parentPath) {
|
|
45
|
+
const relativeParentPath = join(dirname(path), parentPath);
|
|
46
|
+
const parentTsconfig = resolveJSON(relativeParentPath, debug);
|
|
43
47
|
if (parentTsconfig?.extends) {
|
|
44
|
-
logger({ isDebugging:
|
|
48
|
+
logger({ isDebugging: debug })("error")("mergeConfigContent")("Parent tsconfig:merge-tsconfigs only handles extending from a parent, consider extending tsconfigs less.")(parentTsconfig);
|
|
45
49
|
}
|
|
50
|
+
const { extends: _, ...tsconfigWithoutExtends } = tsconfigJSON;
|
|
46
51
|
tsconfigJSON = {
|
|
47
52
|
...parentTsconfig,
|
|
48
|
-
...
|
|
53
|
+
...tsconfigWithoutExtends,
|
|
54
|
+
compilerOptions: {
|
|
55
|
+
...parentTsconfig?.compilerOptions,
|
|
56
|
+
...tsconfigWithoutExtends?.compilerOptions
|
|
57
|
+
}
|
|
49
58
|
};
|
|
50
59
|
}
|
|
51
60
|
if (!tsconfigJSON) {
|
|
@@ -55,38 +64,49 @@ var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {
|
|
|
55
64
|
}
|
|
56
65
|
return {
|
|
57
66
|
...acc,
|
|
58
|
-
...tsconfigJSON
|
|
67
|
+
...tsconfigJSON,
|
|
68
|
+
compilerOptions: {
|
|
69
|
+
...acc?.compilerOptions,
|
|
70
|
+
...tsconfigJSON?.compilerOptions
|
|
71
|
+
}
|
|
59
72
|
};
|
|
60
73
|
}, {});
|
|
61
|
-
var writeTsconfig = (tsconfig, out) => {
|
|
62
|
-
|
|
74
|
+
var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
75
|
+
if (isTesting)
|
|
76
|
+
return tsconfig;
|
|
77
|
+
const path = out.length ? out : `${cwd}/tsconfig.merged.json`;
|
|
63
78
|
mkdirSync(dirname(path), { recursive: true });
|
|
64
79
|
writeFileSync(path, JSON.stringify(tsconfig, null, 2));
|
|
65
80
|
return tsconfig;
|
|
66
81
|
};
|
|
67
82
|
var mergeTsConfigs = ({
|
|
68
83
|
tsconfigs = [],
|
|
69
|
-
exclude
|
|
70
|
-
include
|
|
71
|
-
compilerOptions: compilerOptions2
|
|
84
|
+
exclude,
|
|
85
|
+
include,
|
|
86
|
+
compilerOptions: compilerOptions2,
|
|
72
87
|
debug = false,
|
|
73
|
-
out = ""
|
|
88
|
+
out = "",
|
|
89
|
+
isTesting = false
|
|
74
90
|
}) => {
|
|
75
91
|
if (tsconfigs.length === 0) {
|
|
76
92
|
if (debug)
|
|
77
93
|
logger({ isDebugging: debug })("error")("mergeTsConfig")("No tsconfig files were provided.")(null);
|
|
78
94
|
return;
|
|
79
95
|
}
|
|
80
|
-
const
|
|
96
|
+
const cwd = process.cwd();
|
|
97
|
+
const updatedTsconfig = mergeConfigContent(tsconfigs, cwd, debug);
|
|
81
98
|
if (debug)
|
|
82
99
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
83
100
|
const tsconfig = {
|
|
84
101
|
...updatedTsconfig,
|
|
85
|
-
exclude
|
|
86
|
-
include
|
|
87
|
-
|
|
102
|
+
...exclude ? [...updatedTsconfig?.exclude || [], ...exclude] : updatedTsconfig?.exclude,
|
|
103
|
+
...include ? [...updatedTsconfig.include || [], ...include] : updatedTsconfig?.include,
|
|
104
|
+
compilerOptions: {
|
|
105
|
+
...updatedTsconfig?.compilerOptions,
|
|
106
|
+
...compilerOptions2
|
|
107
|
+
}
|
|
88
108
|
};
|
|
89
|
-
return writeTsconfig(tsconfig, out);
|
|
109
|
+
return writeTsconfig(tsconfig, cwd, out, isTesting);
|
|
90
110
|
};
|
|
91
111
|
var script = mergeTsConfigs;
|
|
92
112
|
var scripts_default = mergeTsConfigs;
|
|
@@ -151,7 +171,7 @@ async function action(files, options = {}) {
|
|
|
151
171
|
}
|
|
152
172
|
program.name("merge-tsconfigs").description(
|
|
153
173
|
"Merge-tsconfigs is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want \u{1F6E3}\uFE0F"
|
|
154
|
-
).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("-t, --isTestingCLI", "enable CLI only testing");
|
|
174
|
+
).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");
|
|
155
175
|
Object.keys(compilerOptions).map((name) => ({ name, value: compilerOptions[name] })).forEach(({ name, value }) => {
|
|
156
176
|
if (value === "boolean") {
|
|
157
177
|
program.option(`--${name}`, `tsconfig.compilerOptions.${name}`);
|
package/package.json
CHANGED