merge-tsconfigs 0.0.7 → 0.1.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/dist/index.cjs +25 -10
- package/dist/index.d.ts +4 -3
- package/dist/index.js +26 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -63,21 +63,29 @@ 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
72
|
var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
72
|
-
let tsconfigJSON = resolveJSON(tsconfig,
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
let tsconfigJSON = resolveJSON(tsconfig, debug);
|
|
74
|
+
const parentPath = tsconfigJSON?.extends;
|
|
75
|
+
if (parentPath) {
|
|
76
|
+
const relativeParentPath = (0, import_path.join)((0, import_path.dirname)(tsconfig), parentPath);
|
|
77
|
+
const parentTsconfig = resolveJSON(relativeParentPath, debug);
|
|
75
78
|
if (parentTsconfig?.extends) {
|
|
76
|
-
logger({ isDebugging:
|
|
79
|
+
logger({ isDebugging: debug })("error")("mergeConfigContent")("Parent tsconfig:merge-tsconfigs only handles extending from a parent, consider extending tsconfigs less.")(parentTsconfig);
|
|
77
80
|
}
|
|
81
|
+
const { extends: _, ...tsconfigWithoutExtends } = tsconfigJSON;
|
|
78
82
|
tsconfigJSON = {
|
|
79
83
|
...parentTsconfig,
|
|
80
|
-
...
|
|
84
|
+
...tsconfigWithoutExtends,
|
|
85
|
+
compilerOptions: {
|
|
86
|
+
...parentTsconfig?.compilerOptions,
|
|
87
|
+
...tsconfigWithoutExtends?.compilerOptions
|
|
88
|
+
}
|
|
81
89
|
};
|
|
82
90
|
}
|
|
83
91
|
if (!tsconfigJSON) {
|
|
@@ -87,10 +95,16 @@ var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {
|
|
|
87
95
|
}
|
|
88
96
|
return {
|
|
89
97
|
...acc,
|
|
90
|
-
...tsconfigJSON
|
|
98
|
+
...tsconfigJSON,
|
|
99
|
+
compilerOptions: {
|
|
100
|
+
...acc?.compilerOptions,
|
|
101
|
+
...tsconfigJSON?.compilerOptions
|
|
102
|
+
}
|
|
91
103
|
};
|
|
92
104
|
}, {});
|
|
93
|
-
var writeTsconfig = (tsconfig, out) => {
|
|
105
|
+
var writeTsconfig = (tsconfig, out, isTesting) => {
|
|
106
|
+
if (isTesting)
|
|
107
|
+
return tsconfig;
|
|
94
108
|
const path = out.length ? out : "./tsconfig.merged.json";
|
|
95
109
|
(0, import_fs.mkdirSync)((0, import_path.dirname)(path), { recursive: true });
|
|
96
110
|
(0, import_fs.writeFileSync)(path, JSON.stringify(tsconfig, null, 2));
|
|
@@ -102,7 +116,8 @@ var mergeTsConfigs = ({
|
|
|
102
116
|
include = [],
|
|
103
117
|
compilerOptions: compilerOptions2 = {},
|
|
104
118
|
debug = false,
|
|
105
|
-
out = ""
|
|
119
|
+
out = "",
|
|
120
|
+
isTesting = false
|
|
106
121
|
}) => {
|
|
107
122
|
if (tsconfigs.length === 0) {
|
|
108
123
|
if (debug)
|
|
@@ -118,7 +133,7 @@ var mergeTsConfigs = ({
|
|
|
118
133
|
include: [...updatedTsconfig.include || [], ...include],
|
|
119
134
|
...compilerOptions2
|
|
120
135
|
};
|
|
121
|
-
return writeTsconfig(tsconfig, out);
|
|
136
|
+
return writeTsconfig(tsconfig, out, isTesting);
|
|
122
137
|
};
|
|
123
138
|
var script = mergeTsConfigs;
|
|
124
139
|
var scripts_default = mergeTsConfigs;
|
|
@@ -183,7 +198,7 @@ async function action(files, options = {}) {
|
|
|
183
198
|
}
|
|
184
199
|
import_commander.program.name("merge-tsconfigs").description(
|
|
185
200
|
"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");
|
|
201
|
+
).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
202
|
Object.keys(compilerOptions).map((name) => ({ name, value: compilerOptions[name] })).forEach(({ name, value }) => {
|
|
188
203
|
if (value === "boolean") {
|
|
189
204
|
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;
|
|
@@ -25,8 +26,8 @@ interface TsConfig {
|
|
|
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
28
|
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;
|
|
29
|
+
declare const writeTsconfig: (tsconfig: TsConfig, 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,29 @@ 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
40
|
var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {}, tsconfig) => {
|
|
40
|
-
let tsconfigJSON = resolveJSON(tsconfig,
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
let tsconfigJSON = resolveJSON(tsconfig, debug);
|
|
42
|
+
const parentPath = tsconfigJSON?.extends;
|
|
43
|
+
if (parentPath) {
|
|
44
|
+
const relativeParentPath = join(dirname(tsconfig), parentPath);
|
|
45
|
+
const parentTsconfig = resolveJSON(relativeParentPath, debug);
|
|
43
46
|
if (parentTsconfig?.extends) {
|
|
44
|
-
logger({ isDebugging:
|
|
47
|
+
logger({ isDebugging: debug })("error")("mergeConfigContent")("Parent tsconfig:merge-tsconfigs only handles extending from a parent, consider extending tsconfigs less.")(parentTsconfig);
|
|
45
48
|
}
|
|
49
|
+
const { extends: _, ...tsconfigWithoutExtends } = tsconfigJSON;
|
|
46
50
|
tsconfigJSON = {
|
|
47
51
|
...parentTsconfig,
|
|
48
|
-
...
|
|
52
|
+
...tsconfigWithoutExtends,
|
|
53
|
+
compilerOptions: {
|
|
54
|
+
...parentTsconfig?.compilerOptions,
|
|
55
|
+
...tsconfigWithoutExtends?.compilerOptions
|
|
56
|
+
}
|
|
49
57
|
};
|
|
50
58
|
}
|
|
51
59
|
if (!tsconfigJSON) {
|
|
@@ -55,10 +63,16 @@ var mergeConfigContent = (tsconfigs, debug = false) => tsconfigs.reduce((acc = {
|
|
|
55
63
|
}
|
|
56
64
|
return {
|
|
57
65
|
...acc,
|
|
58
|
-
...tsconfigJSON
|
|
66
|
+
...tsconfigJSON,
|
|
67
|
+
compilerOptions: {
|
|
68
|
+
...acc?.compilerOptions,
|
|
69
|
+
...tsconfigJSON?.compilerOptions
|
|
70
|
+
}
|
|
59
71
|
};
|
|
60
72
|
}, {});
|
|
61
|
-
var writeTsconfig = (tsconfig, out) => {
|
|
73
|
+
var writeTsconfig = (tsconfig, out, isTesting) => {
|
|
74
|
+
if (isTesting)
|
|
75
|
+
return tsconfig;
|
|
62
76
|
const path = out.length ? out : "./tsconfig.merged.json";
|
|
63
77
|
mkdirSync(dirname(path), { recursive: true });
|
|
64
78
|
writeFileSync(path, JSON.stringify(tsconfig, null, 2));
|
|
@@ -70,7 +84,8 @@ var mergeTsConfigs = ({
|
|
|
70
84
|
include = [],
|
|
71
85
|
compilerOptions: compilerOptions2 = {},
|
|
72
86
|
debug = false,
|
|
73
|
-
out = ""
|
|
87
|
+
out = "",
|
|
88
|
+
isTesting = false
|
|
74
89
|
}) => {
|
|
75
90
|
if (tsconfigs.length === 0) {
|
|
76
91
|
if (debug)
|
|
@@ -86,7 +101,7 @@ var mergeTsConfigs = ({
|
|
|
86
101
|
include: [...updatedTsconfig.include || [], ...include],
|
|
87
102
|
...compilerOptions2
|
|
88
103
|
};
|
|
89
|
-
return writeTsconfig(tsconfig, out);
|
|
104
|
+
return writeTsconfig(tsconfig, out, isTesting);
|
|
90
105
|
};
|
|
91
106
|
var script = mergeTsConfigs;
|
|
92
107
|
var scripts_default = mergeTsConfigs;
|
|
@@ -151,7 +166,7 @@ async function action(files, options = {}) {
|
|
|
151
166
|
}
|
|
152
167
|
program.name("merge-tsconfigs").description(
|
|
153
168
|
"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");
|
|
169
|
+
).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
170
|
Object.keys(compilerOptions).map((name) => ({ name, value: compilerOptions[name] })).forEach(({ name, value }) => {
|
|
156
171
|
if (value === "boolean") {
|
|
157
172
|
program.option(`--${name}`, `tsconfig.compilerOptions.${name}`);
|
package/package.json
CHANGED