merge-tsconfigs 0.1.0 → 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 +18 -13
- package/dist/index.d.ts +3 -3
- package/dist/index.js +18 -13
- 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
|
@@ -69,11 +69,12 @@ function resolveJSON(path, debug = false) {
|
|
|
69
69
|
return {};
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
73
|
-
|
|
72
|
+
var mergeConfigContent = (tsconfigs, cwd, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
73
|
+
const path = `${cwd}/${tsconfig}`;
|
|
74
|
+
let tsconfigJSON = resolveJSON(path, debug);
|
|
74
75
|
const parentPath = tsconfigJSON?.extends;
|
|
75
76
|
if (parentPath) {
|
|
76
|
-
const relativeParentPath = (0, import_path.join)((0, import_path.dirname)(
|
|
77
|
+
const relativeParentPath = (0, import_path.join)((0, import_path.dirname)(path), parentPath);
|
|
77
78
|
const parentTsconfig = resolveJSON(relativeParentPath, debug);
|
|
78
79
|
if (parentTsconfig?.extends) {
|
|
79
80
|
logger({ isDebugging: debug })("error")("mergeConfigContent")("Parent tsconfig:merge-tsconfigs only handles extending from a parent, consider extending tsconfigs less.")(parentTsconfig);
|
|
@@ -102,19 +103,19 @@ var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {
|
|
|
102
103
|
}
|
|
103
104
|
};
|
|
104
105
|
}, {});
|
|
105
|
-
var writeTsconfig = (tsconfig, out, isTesting) => {
|
|
106
|
+
var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
106
107
|
if (isTesting)
|
|
107
108
|
return tsconfig;
|
|
108
|
-
const path = out.length ? out :
|
|
109
|
+
const path = out.length ? out : `${cwd}/tsconfig.merged.json`;
|
|
109
110
|
(0, import_fs.mkdirSync)((0, import_path.dirname)(path), { recursive: true });
|
|
110
111
|
(0, import_fs.writeFileSync)(path, JSON.stringify(tsconfig, null, 2));
|
|
111
112
|
return tsconfig;
|
|
112
113
|
};
|
|
113
114
|
var mergeTsConfigs = ({
|
|
114
115
|
tsconfigs = [],
|
|
115
|
-
exclude
|
|
116
|
-
include
|
|
117
|
-
compilerOptions: compilerOptions2
|
|
116
|
+
exclude,
|
|
117
|
+
include,
|
|
118
|
+
compilerOptions: compilerOptions2,
|
|
118
119
|
debug = false,
|
|
119
120
|
out = "",
|
|
120
121
|
isTesting = false
|
|
@@ -124,16 +125,20 @@ var mergeTsConfigs = ({
|
|
|
124
125
|
logger({ isDebugging: debug })("error")("mergeTsConfig")("No tsconfig files were provided.")(null);
|
|
125
126
|
return;
|
|
126
127
|
}
|
|
127
|
-
const
|
|
128
|
+
const cwd = process.cwd();
|
|
129
|
+
const updatedTsconfig = mergeConfigContent(tsconfigs, cwd, debug);
|
|
128
130
|
if (debug)
|
|
129
131
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
130
132
|
const tsconfig = {
|
|
131
133
|
...updatedTsconfig,
|
|
132
|
-
exclude
|
|
133
|
-
include
|
|
134
|
-
|
|
134
|
+
...exclude ? [...updatedTsconfig?.exclude || [], ...exclude] : updatedTsconfig?.exclude,
|
|
135
|
+
...include ? [...updatedTsconfig.include || [], ...include] : updatedTsconfig?.include,
|
|
136
|
+
compilerOptions: {
|
|
137
|
+
...updatedTsconfig?.compilerOptions,
|
|
138
|
+
...compilerOptions2
|
|
139
|
+
}
|
|
135
140
|
};
|
|
136
|
-
return writeTsconfig(tsconfig, out, isTesting);
|
|
141
|
+
return writeTsconfig(tsconfig, cwd, out, isTesting);
|
|
137
142
|
};
|
|
138
143
|
var script = mergeTsConfigs;
|
|
139
144
|
var scripts_default = mergeTsConfigs;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,15 +18,15 @@ type LoggerParams = {
|
|
|
18
18
|
};
|
|
19
19
|
interface TsConfig {
|
|
20
20
|
extends?: string;
|
|
21
|
-
compilerOptions?: CompilerOptions
|
|
21
|
+
compilerOptions?: PartialDeep<CompilerOptions>;
|
|
22
22
|
include?: string[];
|
|
23
23
|
exclude?: string[];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
declare const logger: ({ isDebugging, emoji, gap, name }: LoggerParams) => (type: string) => (section: string) => (message: string) => (err: unknown) => void;
|
|
27
27
|
declare function resolveJSON(path: string, debug?: boolean): TsConfig;
|
|
28
|
-
declare const mergeConfigContent: (tsconfigs: string[], debug?: boolean) => TsConfig;
|
|
29
|
-
declare const writeTsconfig: (tsconfig: TsConfig, out: string, isTesting: boolean) => TsConfig;
|
|
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
30
|
declare const mergeTsConfigs: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
31
31
|
declare const script: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
|
|
32
32
|
|
package/dist/index.js
CHANGED
|
@@ -37,11 +37,12 @@ function resolveJSON(path, debug = false) {
|
|
|
37
37
|
return {};
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
41
|
-
|
|
40
|
+
var mergeConfigContent = (tsconfigs, cwd, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
41
|
+
const path = `${cwd}/${tsconfig}`;
|
|
42
|
+
let tsconfigJSON = resolveJSON(path, debug);
|
|
42
43
|
const parentPath = tsconfigJSON?.extends;
|
|
43
44
|
if (parentPath) {
|
|
44
|
-
const relativeParentPath = join(dirname(
|
|
45
|
+
const relativeParentPath = join(dirname(path), parentPath);
|
|
45
46
|
const parentTsconfig = resolveJSON(relativeParentPath, debug);
|
|
46
47
|
if (parentTsconfig?.extends) {
|
|
47
48
|
logger({ isDebugging: debug })("error")("mergeConfigContent")("Parent tsconfig:merge-tsconfigs only handles extending from a parent, consider extending tsconfigs less.")(parentTsconfig);
|
|
@@ -70,19 +71,19 @@ var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {
|
|
|
70
71
|
}
|
|
71
72
|
};
|
|
72
73
|
}, {});
|
|
73
|
-
var writeTsconfig = (tsconfig, out, isTesting) => {
|
|
74
|
+
var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
|
|
74
75
|
if (isTesting)
|
|
75
76
|
return tsconfig;
|
|
76
|
-
const path = out.length ? out :
|
|
77
|
+
const path = out.length ? out : `${cwd}/tsconfig.merged.json`;
|
|
77
78
|
mkdirSync(dirname(path), { recursive: true });
|
|
78
79
|
writeFileSync(path, JSON.stringify(tsconfig, null, 2));
|
|
79
80
|
return tsconfig;
|
|
80
81
|
};
|
|
81
82
|
var mergeTsConfigs = ({
|
|
82
83
|
tsconfigs = [],
|
|
83
|
-
exclude
|
|
84
|
-
include
|
|
85
|
-
compilerOptions: compilerOptions2
|
|
84
|
+
exclude,
|
|
85
|
+
include,
|
|
86
|
+
compilerOptions: compilerOptions2,
|
|
86
87
|
debug = false,
|
|
87
88
|
out = "",
|
|
88
89
|
isTesting = false
|
|
@@ -92,16 +93,20 @@ var mergeTsConfigs = ({
|
|
|
92
93
|
logger({ isDebugging: debug })("error")("mergeTsConfig")("No tsconfig files were provided.")(null);
|
|
93
94
|
return;
|
|
94
95
|
}
|
|
95
|
-
const
|
|
96
|
+
const cwd = process.cwd();
|
|
97
|
+
const updatedTsconfig = mergeConfigContent(tsconfigs, cwd, debug);
|
|
96
98
|
if (debug)
|
|
97
99
|
logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
|
|
98
100
|
const tsconfig = {
|
|
99
101
|
...updatedTsconfig,
|
|
100
|
-
exclude
|
|
101
|
-
include
|
|
102
|
-
|
|
102
|
+
...exclude ? [...updatedTsconfig?.exclude || [], ...exclude] : updatedTsconfig?.exclude,
|
|
103
|
+
...include ? [...updatedTsconfig.include || [], ...include] : updatedTsconfig?.include,
|
|
104
|
+
compilerOptions: {
|
|
105
|
+
...updatedTsconfig?.compilerOptions,
|
|
106
|
+
...compilerOptions2
|
|
107
|
+
}
|
|
103
108
|
};
|
|
104
|
-
return writeTsconfig(tsconfig, out, isTesting);
|
|
109
|
+
return writeTsconfig(tsconfig, cwd, out, isTesting);
|
|
105
110
|
};
|
|
106
111
|
var script = mergeTsConfigs;
|
|
107
112
|
var scripts_default = mergeTsConfigs;
|
package/package.json
CHANGED