merge-tsconfigs 0.1.4 → 0.2.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 CHANGED
@@ -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` aren't implemented.
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
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -31,6 +35,7 @@ __export(src_exports, {
31
35
  mergeConfigContent: () => mergeConfigContent,
32
36
  mergeConfigObjects: () => mergeConfigObjects,
33
37
  mergeTsConfigs: () => mergeTsConfigs,
38
+ parsePath: () => parsePath,
34
39
  resolveJSON: () => resolveJSON,
35
40
  script: () => script,
36
41
  updateCompilerOptions: () => updateCompilerOptions,
@@ -72,7 +77,6 @@ function resolveJSON(path, debug = false) {
72
77
  const json = import_json5.default.parse((0, import_fs.readFileSync)(path, "utf8"));
73
78
  return json;
74
79
  } catch (err) {
75
- console.log({ err });
76
80
  if (debug)
77
81
  logger({ isDebugging: debug })("error")("resolveJSON")("There was an error:")(err);
78
82
  return {};
@@ -126,7 +130,7 @@ var writeTsconfig = (tsconfig, cwd, out, isTesting) => {
126
130
  (0, import_fs.writeFileSync)(path, JSON.stringify(tsconfig, null, 2));
127
131
  return tsconfig;
128
132
  };
129
- var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions) => {
133
+ var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions, updatedPath) => {
130
134
  const compilerOptionKeys = compilerOptions2 ? Object.keys(compilerOptions2) : [];
131
135
  const hasCompilerOptions = compilerOptionKeys.length > 0;
132
136
  if (!hasCompilerOptions)
@@ -138,9 +142,26 @@ var updateCompilerOptions = (compilerOptions2 = {}, currentCompilerOptions) => {
138
142
  delete updatedOptions[key];
139
143
  return updatedOptions || {};
140
144
  }
141
- return { ...updatedOptions, [key]: value };
145
+ const paths = {
146
+ ...updatedOptions.paths || {},
147
+ ...key === "paths" ? { value } : {},
148
+ ...updatedPath ? { ...updatedPath } : {}
149
+ };
150
+ return { ...updatedOptions, [key]: value, ...Object.keys(paths).length > 0 ? { paths } : {} };
142
151
  }, {});
143
152
  };
153
+ var parsePath = (path = "", debug = false) => {
154
+ if (!path)
155
+ return {};
156
+ try {
157
+ const json = import_json5.default.parse(path);
158
+ return json;
159
+ } catch (err) {
160
+ if (debug)
161
+ logger({ isDebugging: debug })("error")("parsePath")("There was an error:")(err);
162
+ return {};
163
+ }
164
+ };
144
165
  var mergeTsConfigs = ({
145
166
  tsconfigs = [],
146
167
  exclude,
@@ -148,6 +169,7 @@ var mergeTsConfigs = ({
148
169
  compilerOptions: compilerOptions2,
149
170
  debug = false,
150
171
  out = "tsconfig.merged.json",
172
+ path,
151
173
  isTesting = false
152
174
  }) => {
153
175
  if (tsconfigs.length === 0) {
@@ -159,7 +181,12 @@ var mergeTsConfigs = ({
159
181
  const updatedTsconfig = mergeConfigContent(tsconfigs, cwd, debug);
160
182
  if (debug)
161
183
  logger({ isDebugging: debug })("debug")("mergeTsConfig")("Updated tsconfig:")(updatedTsconfig);
162
- const updatedCompilerOptions = updateCompilerOptions(compilerOptions2, updatedTsconfig?.compilerOptions || {});
184
+ const updatedPath = parsePath(path, debug);
185
+ const updatedCompilerOptions = updateCompilerOptions(
186
+ compilerOptions2,
187
+ updatedTsconfig?.compilerOptions || {},
188
+ updatedPath
189
+ );
163
190
  const updatedExclude = exclude ? { exclude: [...updatedTsconfig?.exclude || [], ...exclude] } : {};
164
191
  const updatedInclude = include ? { include: [...updatedTsconfig.include || [], ...include] } : {};
165
192
  const tsconfig = {
@@ -228,20 +255,21 @@ function action(files, options = {}) {
228
255
  isTesting = false,
229
256
  isTestingCLI = false,
230
257
  out,
258
+ path,
231
259
  ...compilerOptions2
232
260
  } = options;
233
261
  if (isTestingCLI) {
234
262
  console.info({ files, options });
235
263
  return;
236
264
  }
237
- script({ debug, exclude, include, isTesting, out, tsconfigs: files, compilerOptions: compilerOptions2 });
265
+ script({ debug, exclude, include, isTesting, path, out, tsconfigs: files, compilerOptions: compilerOptions2 });
238
266
  } catch (err) {
239
267
  logger({ isDebugging: options.debug })("error")("action")("There was an error:")(err);
240
268
  }
241
269
  }
242
270
  import_commander.program.name("merge-tsconfigs").description(
243
271
  "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");
272
+ ).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
273
  Object.keys(compilerOptions).map((name) => ({ name, value: compilerOptions[name] })).forEach(({ name, value }) => {
246
274
  if (value === "boolean") {
247
275
  import_commander.program.option(`--${name}`, `tsconfig.compilerOptions.${name}`);
@@ -263,6 +291,7 @@ var src_default = scripts_default;
263
291
  mergeConfigContent,
264
292
  mergeConfigObjects,
265
293
  mergeTsConfigs,
294
+ parsePath,
266
295
  resolveJSON,
267
296
  script,
268
297
  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 = {
@@ -36,7 +37,9 @@ declare const mergeConfigObjects: (tsconfig1: TsConfig, tsconfig2: TsConfig) =>
36
37
  exclude?: string[] | undefined;
37
38
  compilerOptions: {
38
39
  [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;
40
+ allowImportingTsExtensions?: boolean | undefined;
39
41
  allowJs?: boolean | undefined;
42
+ allowArbitraryExtensions?: boolean | undefined;
40
43
  allowSyntheticDefaultImports?: boolean | undefined;
41
44
  allowUmdGlobalAccess?: boolean | undefined;
42
45
  allowUnreachableCode?: boolean | undefined;
@@ -45,6 +48,7 @@ declare const mergeConfigObjects: (tsconfig1: TsConfig, tsconfig2: TsConfig) =>
45
48
  baseUrl?: string | undefined;
46
49
  charset?: string | undefined;
47
50
  checkJs?: boolean | undefined;
51
+ customConditions?: string[] | undefined;
48
52
  declaration?: boolean | undefined;
49
53
  declarationMap?: boolean | undefined;
50
54
  emitDeclarationOnly?: boolean | undefined;
@@ -59,6 +63,7 @@ declare const mergeConfigObjects: (tsconfig1: TsConfig, tsconfig2: TsConfig) =>
59
63
  exactOptionalPropertyTypes?: boolean | undefined;
60
64
  experimentalDecorators?: boolean | undefined;
61
65
  forceConsistentCasingInFileNames?: boolean | undefined;
66
+ ignoreDeprecations?: string | undefined;
62
67
  importHelpers?: boolean | undefined;
63
68
  importsNotUsedAsValues?: typescript.ImportsNotUsedAsValues | undefined;
64
69
  inlineSourceMap?: boolean | undefined;
@@ -109,6 +114,8 @@ declare const mergeConfigObjects: (tsconfig1: TsConfig, tsconfig2: TsConfig) =>
109
114
  incremental?: boolean | undefined;
110
115
  tsBuildInfoFile?: string | undefined;
111
116
  removeComments?: boolean | undefined;
117
+ resolvePackageJsonExports?: boolean | undefined;
118
+ resolvePackageJsonImports?: boolean | undefined;
112
119
  rootDir?: string | undefined;
113
120
  rootDirs?: string[] | undefined;
114
121
  skipLibCheck?: boolean | undefined;
@@ -129,6 +136,7 @@ declare const mergeConfigObjects: (tsconfig1: TsConfig, tsconfig2: TsConfig) =>
129
136
  resolveJsonModule?: boolean | undefined;
130
137
  types?: string[] | undefined;
131
138
  typeRoots?: string[] | undefined;
139
+ verbatimModuleSyntax?: boolean | undefined;
132
140
  esModuleInterop?: boolean | undefined;
133
141
  useDefineForClassFields?: boolean | undefined;
134
142
  };
@@ -136,8 +144,9 @@ declare const mergeConfigObjects: (tsconfig1: TsConfig, tsconfig2: TsConfig) =>
136
144
  };
137
145
  declare const mergeConfigContent: (tsconfigs: string[], cwd: string, debug?: boolean) => TsConfig;
138
146
  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 mergeTsConfigs: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
141
- declare const script: ({ tsconfigs, exclude, include, compilerOptions, debug, out, isTesting, }: ConfigOptions) => TsConfig | undefined;
147
+ declare const updateCompilerOptions: (compilerOptions: PartialCompilerOptions | undefined, currentCompilerOptions: PartialCompilerOptions, updatedPath: CompilerOptions['paths']) => PartialCompilerOptions;
148
+ declare const parsePath: (path?: string, debug?: boolean) => CompilerOptions['paths'];
149
+ declare const mergeTsConfigs: ({ tsconfigs, exclude, include, compilerOptions, debug, out, path, isTesting, }: ConfigOptions) => TsConfig | undefined;
150
+ declare const script: ({ tsconfigs, exclude, include, compilerOptions, debug, out, path, isTesting, }: ConfigOptions) => TsConfig | undefined;
142
151
 
143
- export { mergeTsConfigs as default, logger, mergeConfigContent, mergeConfigObjects, mergeTsConfigs, resolveJSON, script, updateCompilerOptions, writeTsconfig };
152
+ 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
- return { ...updatedOptions, [key]: value };
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 updatedCompilerOptions = updateCompilerOptions(compilerOptions2, updatedTsconfig?.compilerOptions || {});
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.1.4",
3
+ "version": "0.2.1",
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",
@@ -37,30 +37,30 @@
37
37
  "update": "codependence --update"
38
38
  },
39
39
  "dependencies": {
40
- "commander": "^9.5.0",
40
+ "commander": "10.0.0",
41
41
  "json5": "^2.2.3"
42
42
  },
43
43
  "devDependencies": {
44
- "@commitlint/cli": "^17.4.2",
45
- "@commitlint/config-conventional": "^17.4.2",
46
- "@types/node": "^18.11.18",
47
- "@typescript-eslint/eslint-plugin": "^5.48.1",
48
- "@typescript-eslint/parser": "^5.48.1",
44
+ "@commitlint/cli": "17.4.4",
45
+ "@commitlint/config-conventional": "17.4.4",
46
+ "@types/node": "18.15.5",
47
+ "@typescript-eslint/eslint-plugin": "5.56.0",
48
+ "@typescript-eslint/parser": "5.56.0",
49
49
  "codependence": "^0.2.6",
50
- "eslint": "^8.32.0",
51
- "eslint-config-prettier": "^8.6.0",
50
+ "eslint": "8.36.0",
51
+ "eslint-config-prettier": "8.8.0",
52
52
  "husky": "^8.0.3",
53
- "lint-staged": "^13.1.0",
53
+ "lint-staged": "13.2.0",
54
54
  "pnpm": "^7.28.0",
55
- "prettier": "^2.8.3",
56
- "release-it": "^15.6.0",
57
- "rimraf": "^3.0.2",
58
- "stdouttojson": "^0.7.1",
55
+ "prettier": "2.8.5",
56
+ "release-it": "15.9.0",
57
+ "rimraf": "4.4.0",
58
+ "stdouttojson": "0.7.2",
59
59
  "ts-node": "^10.9.1",
60
- "tslib": "^2.4.1",
61
- "tsup": "^6.5.0",
62
- "type-fest": "^3.6.0",
63
- "typescript": "^4.9.4",
60
+ "tslib": "2.5.0",
61
+ "tsup": "6.7.0",
62
+ "type-fest": "3.6.1",
63
+ "typescript": "5.0.2",
64
64
  "vitest": "^0.28.5"
65
65
  },
66
66
  "commitlint": {