@effected/tsconfig-json 0.17.2 → 0.17.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/PortableTsconfig.js +18 -19
- package/ResolvedTsconfig.js +57 -60
- package/TsEnumCodec.js +39 -40
- package/TsconfigDiscovery.js +8 -7
- package/TsconfigLoader.js +20 -23
- package/TsconfigLoaderSync.js +10 -7
- package/index.d.ts +13 -13
- package/package.json +2 -2
- package/tsdoc-metadata.json +1 -1
package/PortableTsconfig.js
CHANGED
|
@@ -102,24 +102,6 @@ const OPT_IN_TYPES_OPTION = "types";
|
|
|
102
102
|
* is filtered, which is the safe outcome.)
|
|
103
103
|
*/
|
|
104
104
|
const isResolvedTsconfig = (input) => typeof input.configPath === "string" && Array.isArray(input.extendedPaths) && typeof input.compilerOptions === "object" && input.compilerOptions !== null;
|
|
105
|
-
const make = (input, options) => {
|
|
106
|
-
const source = isResolvedTsconfig(input) ? input.compilerOptions : input;
|
|
107
|
-
const compilerOptions = {};
|
|
108
|
-
for (const key of PRESERVED_OPTIONS) {
|
|
109
|
-
const value = source[key];
|
|
110
|
-
if (value !== void 0) compilerOptions[key] = value;
|
|
111
|
-
}
|
|
112
|
-
if (options?.includeTypes === true) {
|
|
113
|
-
const types = source[OPT_IN_TYPES_OPTION];
|
|
114
|
-
if (types !== void 0) compilerOptions[OPT_IN_TYPES_OPTION] = types;
|
|
115
|
-
}
|
|
116
|
-
compilerOptions.composite = false;
|
|
117
|
-
compilerOptions.noEmit = true;
|
|
118
|
-
return {
|
|
119
|
-
$schema: TSCONFIG_SCHEMA_URL,
|
|
120
|
-
compilerOptions
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
105
|
/**
|
|
124
106
|
* The portable-tsconfig filter: {@link (PortableTsconfig:class).make}
|
|
125
107
|
* narrows a resolved or bare compiler-options object to the allow-listed,
|
|
@@ -153,7 +135,24 @@ var PortableTsconfig = class {
|
|
|
153
135
|
* @param options - Opt-ins for options that are portable but
|
|
154
136
|
* resolution-dependent. Omitted means the strict, always-safe subset.
|
|
155
137
|
*/
|
|
156
|
-
static make
|
|
138
|
+
static make(input, options) {
|
|
139
|
+
const source = isResolvedTsconfig(input) ? input.compilerOptions : input;
|
|
140
|
+
const compilerOptions = {};
|
|
141
|
+
for (const key of PRESERVED_OPTIONS) {
|
|
142
|
+
const value = source[key];
|
|
143
|
+
if (value !== void 0) compilerOptions[key] = value;
|
|
144
|
+
}
|
|
145
|
+
if (options?.includeTypes === true) {
|
|
146
|
+
const types = source[OPT_IN_TYPES_OPTION];
|
|
147
|
+
if (types !== void 0) compilerOptions[OPT_IN_TYPES_OPTION] = types;
|
|
148
|
+
}
|
|
149
|
+
compilerOptions.composite = false;
|
|
150
|
+
compilerOptions.noEmit = true;
|
|
151
|
+
return {
|
|
152
|
+
$schema: TSCONFIG_SCHEMA_URL,
|
|
153
|
+
compilerOptions
|
|
154
|
+
};
|
|
155
|
+
}
|
|
157
156
|
};
|
|
158
157
|
|
|
159
158
|
export { PortableTsconfig };
|
package/ResolvedTsconfig.js
CHANGED
|
@@ -72,15 +72,6 @@ const transformCompilerOptionPaths = (co, transform, includePathsValues) => {
|
|
|
72
72
|
}
|
|
73
73
|
return out;
|
|
74
74
|
};
|
|
75
|
-
const absolutize = (doc, configDir, join) => {
|
|
76
|
-
const co = doc.compilerOptions;
|
|
77
|
-
if (co === void 0) return doc;
|
|
78
|
-
const absolutizeValue = (value) => startsWithConfigDir(value) ? value : join(configDir, value);
|
|
79
|
-
return {
|
|
80
|
-
...doc,
|
|
81
|
-
compilerOptions: transformCompilerOptionPaths(co, absolutizeValue, false)
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
75
|
const DERIVED_CONSUMED_KEYS = /* @__PURE__ */ new Set([
|
|
85
76
|
"compilerOptions",
|
|
86
77
|
"extends",
|
|
@@ -143,38 +134,6 @@ const mergeWatchOptions = (base, derived) => {
|
|
|
143
134
|
...derived
|
|
144
135
|
};
|
|
145
136
|
};
|
|
146
|
-
const merge = (base, derived, derivedPath) => {
|
|
147
|
-
const finalDir = dirname(derivedPath);
|
|
148
|
-
const baseDir = dirname(base.configPath);
|
|
149
|
-
const compilerOptions = {
|
|
150
|
-
...base.compilerOptions,
|
|
151
|
-
...derived.compilerOptions
|
|
152
|
-
};
|
|
153
|
-
const pathsBase = derived.compilerOptions?.paths !== void 0 ? finalDir : base.pathsBase;
|
|
154
|
-
const rerootPrefix = relative(finalDir, baseDir);
|
|
155
|
-
const files = mergeFileList(base.files, derived.files, rerootPrefix);
|
|
156
|
-
const include = mergeFileList(base.include, derived.include, rerootPrefix);
|
|
157
|
-
const exclude = mergeFileList(base.exclude, derived.exclude, rerootPrefix);
|
|
158
|
-
const references = derived.references;
|
|
159
|
-
const typeAcquisition = derived.typeAcquisition;
|
|
160
|
-
const compileOnSave = derived.compileOnSave !== void 0 ? derived.compileOnSave : base.compileOnSave === true ? true : void 0;
|
|
161
|
-
const watchOptions = mergeWatchOptions(base.watchOptions, derived.watchOptions);
|
|
162
|
-
return {
|
|
163
|
-
...extractPassthrough(base, RESOLVED_STRUCTURAL_KEYS),
|
|
164
|
-
...extractPassthrough(derived, DERIVED_CONSUMED_KEYS),
|
|
165
|
-
configPath: derivedPath,
|
|
166
|
-
extendedPaths: [...base.extendedPaths, derivedPath],
|
|
167
|
-
compilerOptions,
|
|
168
|
-
...files !== void 0 ? { files } : {},
|
|
169
|
-
...include !== void 0 ? { include } : {},
|
|
170
|
-
...exclude !== void 0 ? { exclude } : {},
|
|
171
|
-
...references !== void 0 ? { references } : {},
|
|
172
|
-
...watchOptions !== void 0 ? { watchOptions } : {},
|
|
173
|
-
...typeAcquisition !== void 0 ? { typeAcquisition } : {},
|
|
174
|
-
...compileOnSave !== void 0 ? { compileOnSave } : {},
|
|
175
|
-
...pathsBase !== void 0 ? { pathsBase } : {}
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
137
|
const substituteWatchExcludes = (wo, substitute) => {
|
|
179
138
|
if (wo === void 0) return void 0;
|
|
180
139
|
const out = { ...wo };
|
|
@@ -184,22 +143,6 @@ const substituteWatchExcludes = (wo, substitute) => {
|
|
|
184
143
|
}
|
|
185
144
|
return out;
|
|
186
145
|
};
|
|
187
|
-
const substituteConfigDir = (resolved, finalDir) => {
|
|
188
|
-
const substitute = (value) => startsWithConfigDir(value) ? finalDir + value.slice(CONFIG_DIR_TEMPLATE.length) : value;
|
|
189
|
-
const compilerOptions = transformCompilerOptionPaths(resolved.compilerOptions, substitute, true);
|
|
190
|
-
const files = resolved.files === void 0 ? void 0 : resolved.files.map(substitute);
|
|
191
|
-
const include = resolved.include === void 0 ? void 0 : resolved.include.map(substitute);
|
|
192
|
-
const exclude = resolved.exclude === void 0 ? void 0 : resolved.exclude.map(substitute);
|
|
193
|
-
const watchOptions = substituteWatchExcludes(resolved.watchOptions, substitute);
|
|
194
|
-
return {
|
|
195
|
-
...resolved,
|
|
196
|
-
compilerOptions,
|
|
197
|
-
...files !== void 0 ? { files } : {},
|
|
198
|
-
...include !== void 0 ? { include } : {},
|
|
199
|
-
...exclude !== void 0 ? { exclude } : {},
|
|
200
|
-
...watchOptions !== void 0 ? { watchOptions } : {}
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
146
|
/**
|
|
204
147
|
* The pure extends-merge engine: parse-time path absolutization
|
|
205
148
|
* ({@link (ResolvedTsconfig:class).absolutize}), the per-field merge fold
|
|
@@ -219,7 +162,15 @@ var ResolvedTsconfig = class {
|
|
|
219
162
|
* VALUES stay verbatim. Only `compilerOptions` path surfaces are touched;
|
|
220
163
|
* `files`/`include`/`exclude` are re-rooted at merge time instead.
|
|
221
164
|
*/
|
|
222
|
-
static absolutize
|
|
165
|
+
static absolutize(doc, configDir, join) {
|
|
166
|
+
const co = doc.compilerOptions;
|
|
167
|
+
if (co === void 0) return doc;
|
|
168
|
+
const absolutizeValue = (value) => startsWithConfigDir(value) ? value : join(configDir, value);
|
|
169
|
+
return {
|
|
170
|
+
...doc,
|
|
171
|
+
compilerOptions: transformCompilerOptionPaths(co, absolutizeValue, false)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
223
174
|
/**
|
|
224
175
|
* Fold one more-derived config onto the accumulated base, derived
|
|
225
176
|
* winning. The loader applies this across the resolution chain,
|
|
@@ -227,7 +178,38 @@ var ResolvedTsconfig = class {
|
|
|
227
178
|
* normalized path, from which the re-rooting frame and `pathsBase` are
|
|
228
179
|
* computed.
|
|
229
180
|
*/
|
|
230
|
-
static merge
|
|
181
|
+
static merge(base, derived, derivedPath) {
|
|
182
|
+
const finalDir = dirname(derivedPath);
|
|
183
|
+
const baseDir = dirname(base.configPath);
|
|
184
|
+
const compilerOptions = {
|
|
185
|
+
...base.compilerOptions,
|
|
186
|
+
...derived.compilerOptions
|
|
187
|
+
};
|
|
188
|
+
const pathsBase = derived.compilerOptions?.paths !== void 0 ? finalDir : base.pathsBase;
|
|
189
|
+
const rerootPrefix = relative(finalDir, baseDir);
|
|
190
|
+
const files = mergeFileList(base.files, derived.files, rerootPrefix);
|
|
191
|
+
const include = mergeFileList(base.include, derived.include, rerootPrefix);
|
|
192
|
+
const exclude = mergeFileList(base.exclude, derived.exclude, rerootPrefix);
|
|
193
|
+
const references = derived.references;
|
|
194
|
+
const typeAcquisition = derived.typeAcquisition;
|
|
195
|
+
const compileOnSave = derived.compileOnSave !== void 0 ? derived.compileOnSave : base.compileOnSave === true ? true : void 0;
|
|
196
|
+
const watchOptions = mergeWatchOptions(base.watchOptions, derived.watchOptions);
|
|
197
|
+
return {
|
|
198
|
+
...extractPassthrough(base, RESOLVED_STRUCTURAL_KEYS),
|
|
199
|
+
...extractPassthrough(derived, DERIVED_CONSUMED_KEYS),
|
|
200
|
+
configPath: derivedPath,
|
|
201
|
+
extendedPaths: [...base.extendedPaths, derivedPath],
|
|
202
|
+
compilerOptions,
|
|
203
|
+
...files !== void 0 ? { files } : {},
|
|
204
|
+
...include !== void 0 ? { include } : {},
|
|
205
|
+
...exclude !== void 0 ? { exclude } : {},
|
|
206
|
+
...references !== void 0 ? { references } : {},
|
|
207
|
+
...watchOptions !== void 0 ? { watchOptions } : {},
|
|
208
|
+
...typeAcquisition !== void 0 ? { typeAcquisition } : {},
|
|
209
|
+
...compileOnSave !== void 0 ? { compileOnSave } : {},
|
|
210
|
+
...pathsBase !== void 0 ? { pathsBase } : {}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
231
213
|
/**
|
|
232
214
|
* The final phase: replace a leading `${configDir}` token
|
|
233
215
|
* (case-insensitive, leading position only) with `finalDir` — the
|
|
@@ -237,7 +219,22 @@ var ResolvedTsconfig = class {
|
|
|
237
219
|
* `excludeDirectories`/`excludeFiles`. Every other field is left
|
|
238
220
|
* untouched.
|
|
239
221
|
*/
|
|
240
|
-
static substituteConfigDir
|
|
222
|
+
static substituteConfigDir(resolved, finalDir) {
|
|
223
|
+
const substitute = (value) => startsWithConfigDir(value) ? finalDir + value.slice(CONFIG_DIR_TEMPLATE.length) : value;
|
|
224
|
+
const compilerOptions = transformCompilerOptionPaths(resolved.compilerOptions, substitute, true);
|
|
225
|
+
const files = resolved.files === void 0 ? void 0 : resolved.files.map(substitute);
|
|
226
|
+
const include = resolved.include === void 0 ? void 0 : resolved.include.map(substitute);
|
|
227
|
+
const exclude = resolved.exclude === void 0 ? void 0 : resolved.exclude.map(substitute);
|
|
228
|
+
const watchOptions = substituteWatchExcludes(resolved.watchOptions, substitute);
|
|
229
|
+
return {
|
|
230
|
+
...resolved,
|
|
231
|
+
compilerOptions,
|
|
232
|
+
...files !== void 0 ? { files } : {},
|
|
233
|
+
...include !== void 0 ? { include } : {},
|
|
234
|
+
...exclude !== void 0 ? { exclude } : {},
|
|
235
|
+
...watchOptions !== void 0 ? { watchOptions } : {}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
241
238
|
};
|
|
242
239
|
|
|
243
240
|
export { ResolvedTsconfig };
|
package/TsEnumCodec.js
CHANGED
|
@@ -94,13 +94,6 @@ const TABLES = {
|
|
|
94
94
|
["fixedchunksize", 3]
|
|
95
95
|
])
|
|
96
96
|
};
|
|
97
|
-
const encode = (family, value) => Option.fromNullishOr(TABLES[family].forward.get(value));
|
|
98
|
-
const decode = (family, value) => Option.fromNullishOr(TABLES[family].reverse.get(value));
|
|
99
|
-
const normalizeLibReference = (lib) => {
|
|
100
|
-
const base = (lib.split("/").pop() ?? lib).toLowerCase();
|
|
101
|
-
const withoutPrefix = base.startsWith("lib.") ? base.slice(4) : base;
|
|
102
|
-
return withoutPrefix.endsWith(".d.ts") ? withoutPrefix.slice(0, -5) : withoutPrefix;
|
|
103
|
-
};
|
|
104
97
|
/** `compilerOptions` keys whose values are one of the enum families. */
|
|
105
98
|
const COMPILER_OPTION_ENUM_KEYS = [
|
|
106
99
|
["target", "target"],
|
|
@@ -110,33 +103,6 @@ const COMPILER_OPTION_ENUM_KEYS = [
|
|
|
110
103
|
["newLine", "newLine"],
|
|
111
104
|
["moduleDetection", "moduleDetection"]
|
|
112
105
|
];
|
|
113
|
-
const encodeCompilerOptions = (options) => {
|
|
114
|
-
const source = options;
|
|
115
|
-
const result = { ...source };
|
|
116
|
-
for (const [key, family] of COMPILER_OPTION_ENUM_KEYS) {
|
|
117
|
-
const value = source[key];
|
|
118
|
-
if (typeof value === "string") {
|
|
119
|
-
const encoded = encode(family, value);
|
|
120
|
-
if (Option.isSome(encoded)) result[key] = encoded.value;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const lib = source.lib;
|
|
124
|
-
if (Array.isArray(lib)) result.lib = lib.map((entry) => typeof entry === "string" ? `lib.${normalizeLibReference(entry)}.d.ts` : entry);
|
|
125
|
-
return result;
|
|
126
|
-
};
|
|
127
|
-
const decodeCompilerOptions = (numeric) => {
|
|
128
|
-
const result = { ...numeric };
|
|
129
|
-
for (const [key, family] of COMPILER_OPTION_ENUM_KEYS) {
|
|
130
|
-
const value = numeric[key];
|
|
131
|
-
if (typeof value === "number") {
|
|
132
|
-
const decoded = decode(family, value);
|
|
133
|
-
if (Option.isSome(decoded)) result[key] = decoded.value;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const lib = numeric.lib;
|
|
137
|
-
if (Array.isArray(lib)) result.lib = lib.map((entry) => typeof entry === "string" ? normalizeLibReference(entry) : entry);
|
|
138
|
-
return result;
|
|
139
|
-
};
|
|
140
106
|
/**
|
|
141
107
|
* The string↔numeric enum codec for `compilerOptions` / `watchOptions`
|
|
142
108
|
* families. Plain data: every lookup is a synchronous map read
|
|
@@ -144,19 +110,23 @@ const decodeCompilerOptions = (numeric) => {
|
|
|
144
110
|
*
|
|
145
111
|
* @public
|
|
146
112
|
*/
|
|
147
|
-
var TsEnumCodec = class {
|
|
113
|
+
var TsEnumCodec = class TsEnumCodec {
|
|
148
114
|
constructor() {}
|
|
149
115
|
/**
|
|
150
116
|
* Encodes a family's canonical (or alias) string spelling to its numeric
|
|
151
117
|
* form. `Option.none()` for a string with no table entry — never guessed.
|
|
152
118
|
*/
|
|
153
|
-
static encode
|
|
119
|
+
static encode(family, value) {
|
|
120
|
+
return Option.fromNullishOr(TABLES[family].forward.get(value));
|
|
121
|
+
}
|
|
154
122
|
/**
|
|
155
123
|
* Decodes a family's numeric value to its canonical string spelling.
|
|
156
124
|
* `Option.none()` for a numeric value with no table entry (a future TS
|
|
157
125
|
* enum member) — never guessed.
|
|
158
126
|
*/
|
|
159
|
-
static decode
|
|
127
|
+
static decode(family, value) {
|
|
128
|
+
return Option.fromNullishOr(TABLES[family].reverse.get(value));
|
|
129
|
+
}
|
|
160
130
|
/**
|
|
161
131
|
* Normalizes any spelling of a `lib` reference — the plain short name
|
|
162
132
|
* (`esnext`), the on-disk file name (`lib.esnext.d.ts`), or an absolute
|
|
@@ -165,7 +135,11 @@ var TsEnumCodec = class {
|
|
|
165
135
|
* leading directory, the `lib.` prefix and the `.d.ts` suffix; idempotent
|
|
166
136
|
* on an already-short name.
|
|
167
137
|
*/
|
|
168
|
-
static normalizeLibReference
|
|
138
|
+
static normalizeLibReference(lib) {
|
|
139
|
+
const base = (lib.split("/").pop() ?? lib).toLowerCase();
|
|
140
|
+
const withoutPrefix = base.startsWith("lib.") ? base.slice(4) : base;
|
|
141
|
+
return withoutPrefix.endsWith(".d.ts") ? withoutPrefix.slice(0, -5) : withoutPrefix;
|
|
142
|
+
}
|
|
169
143
|
/**
|
|
170
144
|
* Encodes a decoded `compilerOptions` object into the
|
|
171
145
|
* numeric-enum-shaped {@link ProgrammaticCompilerOptions} form
|
|
@@ -184,7 +158,20 @@ var TsEnumCodec = class {
|
|
|
184
158
|
* cast. Runtime behavior is unchanged; only the declared return type
|
|
185
159
|
* narrows.
|
|
186
160
|
*/
|
|
187
|
-
static encodeCompilerOptions
|
|
161
|
+
static encodeCompilerOptions(options) {
|
|
162
|
+
const source = options;
|
|
163
|
+
const result = { ...source };
|
|
164
|
+
for (const [key, family] of COMPILER_OPTION_ENUM_KEYS) {
|
|
165
|
+
const value = source[key];
|
|
166
|
+
if (typeof value === "string") {
|
|
167
|
+
const encoded = TsEnumCodec.encode(family, value);
|
|
168
|
+
if (Option.isSome(encoded)) result[key] = encoded.value;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const lib = source.lib;
|
|
172
|
+
if (Array.isArray(lib)) result.lib = lib.map((entry) => typeof entry === "string" ? `lib.${TsEnumCodec.normalizeLibReference(entry)}.d.ts` : entry);
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
188
175
|
/**
|
|
189
176
|
* Decodes a numeric-enum-shaped `compilerOptions` object (as produced by
|
|
190
177
|
* {@link TsEnumCodec.encodeCompilerOptions} or read off a live
|
|
@@ -198,7 +185,19 @@ var TsEnumCodec = class {
|
|
|
198
185
|
* value would violate that narrower type's contract. Every other key is
|
|
199
186
|
* copied through untouched.
|
|
200
187
|
*/
|
|
201
|
-
static decodeCompilerOptions
|
|
188
|
+
static decodeCompilerOptions(numeric) {
|
|
189
|
+
const result = { ...numeric };
|
|
190
|
+
for (const [key, family] of COMPILER_OPTION_ENUM_KEYS) {
|
|
191
|
+
const value = numeric[key];
|
|
192
|
+
if (typeof value === "number") {
|
|
193
|
+
const decoded = TsEnumCodec.decode(family, value);
|
|
194
|
+
if (Option.isSome(decoded)) result[key] = decoded.value;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const lib = numeric.lib;
|
|
198
|
+
if (Array.isArray(lib)) result.lib = lib.map((entry) => typeof entry === "string" ? TsEnumCodec.normalizeLibReference(entry) : entry);
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
202
201
|
};
|
|
203
202
|
|
|
204
203
|
export { TsEnumCodec };
|
package/TsconfigDiscovery.js
CHANGED
|
@@ -2,12 +2,6 @@ import { Effect, Path } from "effect";
|
|
|
2
2
|
import { Walker } from "@effected/walker";
|
|
3
3
|
|
|
4
4
|
// src/TsconfigDiscovery.ts
|
|
5
|
-
const findNearest = (start, options) => Effect.gen(function* () {
|
|
6
|
-
const path = yield* Path.Path;
|
|
7
|
-
const filename = options?.filename ?? "tsconfig.json";
|
|
8
|
-
const dirs = yield* Walker.ascend(start, options?.stopAt === void 0 ? {} : { stopAt: options.stopAt });
|
|
9
|
-
return yield* Walker.findUpward(dirs, (dir) => [path.join(dir, filename)]);
|
|
10
|
-
});
|
|
11
5
|
/**
|
|
12
6
|
* Nearest-config upward discovery for `tsconfig.json`.
|
|
13
7
|
*
|
|
@@ -35,7 +29,14 @@ var TsconfigDiscovery = class {
|
|
|
35
29
|
* posture, and a permission-denied probe on one directory does not hide a
|
|
36
30
|
* config file above it.
|
|
37
31
|
*/
|
|
38
|
-
static findNearest
|
|
32
|
+
static findNearest(start, options) {
|
|
33
|
+
return Effect.gen(function* () {
|
|
34
|
+
const path = yield* Path.Path;
|
|
35
|
+
const filename = options?.filename ?? "tsconfig.json";
|
|
36
|
+
const dirs = yield* Walker.ascend(start, options?.stopAt === void 0 ? {} : { stopAt: options.stopAt });
|
|
37
|
+
return yield* Walker.findUpward(dirs, (dir) => [path.join(dir, filename)]);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
export { TsconfigDiscovery };
|
package/TsconfigLoader.js
CHANGED
|
@@ -58,10 +58,6 @@ const loadAbs = (abs) => Effect.gen(function* () {
|
|
|
58
58
|
cause
|
|
59
59
|
})));
|
|
60
60
|
});
|
|
61
|
-
const load = Effect.fn("TsconfigLoader.load")(function* (configPath) {
|
|
62
|
-
const path = yield* Path.Path;
|
|
63
|
-
return yield* loadAbs(normalizeSlashes(path.resolve(configPath)));
|
|
64
|
-
});
|
|
65
61
|
/**
|
|
66
62
|
* Collect the flattened, base-most-first list of absolutized config documents
|
|
67
63
|
* for `configPath` and its full `extends` chain. `chain` is the stack of
|
|
@@ -111,21 +107,6 @@ const collect = (configPath, chain) => Effect.gen(function* () {
|
|
|
111
107
|
});
|
|
112
108
|
return layers;
|
|
113
109
|
});
|
|
114
|
-
const resolve = Effect.fn("TsconfigLoader.resolve")(function* (configPath) {
|
|
115
|
-
const path = yield* Path.Path;
|
|
116
|
-
const topAbs = normalizeSlashes(path.resolve(configPath));
|
|
117
|
-
const layers = yield* collect(topAbs, []);
|
|
118
|
-
let acc = {
|
|
119
|
-
configPath: topAbs,
|
|
120
|
-
extendedPaths: [],
|
|
121
|
-
compilerOptions: {}
|
|
122
|
-
};
|
|
123
|
-
for (const entry of layers) acc = ResolvedTsconfig.merge(acc, entry.doc, entry.path);
|
|
124
|
-
return ResolvedTsconfig.substituteConfigDir(acc, path.dirname(topAbs));
|
|
125
|
-
});
|
|
126
|
-
const compilerOptions = Effect.fn("TsconfigLoader.compilerOptions")(function* (configPath) {
|
|
127
|
-
return (yield* resolve(configPath)).compilerOptions;
|
|
128
|
-
});
|
|
129
110
|
/**
|
|
130
111
|
* The tsconfig.json loader: {@link TsconfigLoader.load} reads and decodes one
|
|
131
112
|
* config file, {@link TsconfigLoader.resolve} runs the full load -\> extends -\>
|
|
@@ -146,7 +127,7 @@ const compilerOptions = Effect.fn("TsconfigLoader.compilerOptions")(function* (c
|
|
|
146
127
|
*
|
|
147
128
|
* @public
|
|
148
129
|
*/
|
|
149
|
-
var TsconfigLoader = class {
|
|
130
|
+
var TsconfigLoader = class TsconfigLoader {
|
|
150
131
|
constructor() {}
|
|
151
132
|
/**
|
|
152
133
|
* Read one config file and decode it through {@link TsconfigJsonFromString}.
|
|
@@ -155,7 +136,10 @@ var TsconfigLoader = class {
|
|
|
155
136
|
* untranslated. No `extends` resolution — {@link TsconfigLoader.resolve}
|
|
156
137
|
* drives that.
|
|
157
138
|
*/
|
|
158
|
-
static load = load
|
|
139
|
+
static load = Effect.fn("TsconfigLoader.load")(function* (configPath) {
|
|
140
|
+
const path = yield* Path.Path;
|
|
141
|
+
return yield* loadAbs(normalizeSlashes(path.resolve(configPath)));
|
|
142
|
+
});
|
|
159
143
|
/**
|
|
160
144
|
* Resolve a tsconfig.json and its full `extends` chain into a
|
|
161
145
|
* {@link (ResolvedTsconfig:interface)}: load and decode each config,
|
|
@@ -168,14 +152,27 @@ var TsconfigLoader = class {
|
|
|
168
152
|
* carrying that file's path), `TsconfigExtendsError` (a broken chain), or
|
|
169
153
|
* a `PlatformError` from IO — never a defect.
|
|
170
154
|
*/
|
|
171
|
-
static resolve = resolve
|
|
155
|
+
static resolve = Effect.fn("TsconfigLoader.resolve")(function* (configPath) {
|
|
156
|
+
const path = yield* Path.Path;
|
|
157
|
+
const topAbs = normalizeSlashes(path.resolve(configPath));
|
|
158
|
+
const layers = yield* collect(topAbs, []);
|
|
159
|
+
let acc = {
|
|
160
|
+
configPath: topAbs,
|
|
161
|
+
extendedPaths: [],
|
|
162
|
+
compilerOptions: {}
|
|
163
|
+
};
|
|
164
|
+
for (const entry of layers) acc = ResolvedTsconfig.merge(acc, entry.doc, entry.path);
|
|
165
|
+
return ResolvedTsconfig.substituteConfigDir(acc, path.dirname(topAbs));
|
|
166
|
+
});
|
|
172
167
|
/**
|
|
173
168
|
* Resolve a tsconfig.json's full `extends` chain and project out the
|
|
174
169
|
* merged `compilerOptions` — a thin projection of
|
|
175
170
|
* {@link TsconfigLoader.resolve} for the common "just give me the
|
|
176
171
|
* effective options" query. Same pipeline, same typed failures.
|
|
177
172
|
*/
|
|
178
|
-
static compilerOptions = compilerOptions
|
|
173
|
+
static compilerOptions = Effect.fn("TsconfigLoader.compilerOptions")(function* (configPath) {
|
|
174
|
+
return (yield* TsconfigLoader.resolve(configPath)).compilerOptions;
|
|
175
|
+
});
|
|
179
176
|
};
|
|
180
177
|
|
|
181
178
|
export { TsconfigExtendsError, TsconfigLoader };
|
package/TsconfigLoaderSync.js
CHANGED
|
@@ -68,9 +68,6 @@ const runWith = (options, effect) => {
|
|
|
68
68
|
if (Result.isSuccess(defect)) throw defect.success;
|
|
69
69
|
throw Cause.squash(exit.cause);
|
|
70
70
|
};
|
|
71
|
-
const load = (configPath, options) => runWith(options, TsconfigLoader.load(configPath));
|
|
72
|
-
const resolve = (configPath, options) => runWith(options, TsconfigLoader.resolve(configPath));
|
|
73
|
-
const compilerOptions = (configPath, options) => resolve(configPath, options).compilerOptions;
|
|
74
71
|
/**
|
|
75
72
|
* The synchronous tsconfig.json loader facade: the {@link TsconfigLoader}
|
|
76
73
|
* pipeline run under `Effect.runSyncExit` against consumer-supplied
|
|
@@ -100,7 +97,7 @@ const compilerOptions = (configPath, options) => resolve(configPath, options).co
|
|
|
100
97
|
*
|
|
101
98
|
* @public
|
|
102
99
|
*/
|
|
103
|
-
var TsconfigLoaderSync = class {
|
|
100
|
+
var TsconfigLoaderSync = class TsconfigLoaderSync {
|
|
104
101
|
constructor() {}
|
|
105
102
|
/**
|
|
106
103
|
* {@link TsconfigLoader.load}, synchronously: read and decode one config
|
|
@@ -108,7 +105,9 @@ var TsconfigLoaderSync = class {
|
|
|
108
105
|
* `TsconfigParseError` or a `PlatformError` — the async pipeline's exact
|
|
109
106
|
* typed failures.
|
|
110
107
|
*/
|
|
111
|
-
static load
|
|
108
|
+
static load(configPath, options) {
|
|
109
|
+
return runWith(options, TsconfigLoader.load(configPath));
|
|
110
|
+
}
|
|
112
111
|
/**
|
|
113
112
|
* {@link TsconfigLoader.resolve}, synchronously: the full load -\>
|
|
114
113
|
* extends -\> merge -\> `${configDir}` pipeline through the
|
|
@@ -116,13 +115,17 @@ var TsconfigLoaderSync = class {
|
|
|
116
115
|
* `TsconfigExtendsError` or a `PlatformError` — the async pipeline's exact
|
|
117
116
|
* typed failures.
|
|
118
117
|
*/
|
|
119
|
-
static resolve
|
|
118
|
+
static resolve(configPath, options) {
|
|
119
|
+
return runWith(options, TsconfigLoader.resolve(configPath));
|
|
120
|
+
}
|
|
120
121
|
/**
|
|
121
122
|
* {@link TsconfigLoader.compilerOptions}, synchronously: resolve the full
|
|
122
123
|
* `extends` chain and project out the merged `compilerOptions`. Throws
|
|
123
124
|
* the same typed failures as {@link TsconfigLoaderSync.resolve}.
|
|
124
125
|
*/
|
|
125
|
-
static compilerOptions
|
|
126
|
+
static compilerOptions(configPath, options) {
|
|
127
|
+
return TsconfigLoaderSync.resolve(configPath, options).compilerOptions;
|
|
128
|
+
}
|
|
126
129
|
};
|
|
127
130
|
|
|
128
131
|
export { TsconfigLoaderSync };
|
package/index.d.ts
CHANGED
|
@@ -610,7 +610,7 @@ export declare class ResolvedTsconfig {
|
|
|
610
610
|
* VALUES stay verbatim. Only `compilerOptions` path surfaces are touched;
|
|
611
611
|
* `files`/`include`/`exclude` are re-rooted at merge time instead.
|
|
612
612
|
*/
|
|
613
|
-
static
|
|
613
|
+
static absolutize(doc: TsconfigJson.Type, configDir: string, join: (a: string, b: string) => string): TsconfigJson.Type;
|
|
614
614
|
/**
|
|
615
615
|
* Fold one more-derived config onto the accumulated base, derived
|
|
616
616
|
* winning. The loader applies this across the resolution chain,
|
|
@@ -618,7 +618,7 @@ export declare class ResolvedTsconfig {
|
|
|
618
618
|
* normalized path, from which the re-rooting frame and `pathsBase` are
|
|
619
619
|
* computed.
|
|
620
620
|
*/
|
|
621
|
-
static
|
|
621
|
+
static merge(base: ResolvedTsconfig, derived: TsconfigJson.Type, derivedPath: string): ResolvedTsconfig;
|
|
622
622
|
/**
|
|
623
623
|
* The final phase: replace a leading `${configDir}` token
|
|
624
624
|
* (case-insensitive, leading position only) with `finalDir` — the
|
|
@@ -628,7 +628,7 @@ export declare class ResolvedTsconfig {
|
|
|
628
628
|
* `excludeDirectories`/`excludeFiles`. Every other field is left
|
|
629
629
|
* untouched.
|
|
630
630
|
*/
|
|
631
|
-
static
|
|
631
|
+
static substituteConfigDir(resolved: ResolvedTsconfig, finalDir: string): ResolvedTsconfig;
|
|
632
632
|
}
|
|
633
633
|
/**
|
|
634
634
|
* A portable, JSON-serializable tsconfig.json (compilerOptions-only), for
|
|
@@ -699,7 +699,7 @@ export declare class PortableTsconfig {
|
|
|
699
699
|
* @param options - Opt-ins for options that are portable but
|
|
700
700
|
* resolution-dependent. Omitted means the strict, always-safe subset.
|
|
701
701
|
*/
|
|
702
|
-
static
|
|
702
|
+
static make(input: ResolvedTsconfig | CompilerOptions.Type, options?: PortableTsconfigOptions): PortableTsconfig;
|
|
703
703
|
}
|
|
704
704
|
/**
|
|
705
705
|
* Options for {@link TsconfigDiscovery.findNearest}.
|
|
@@ -739,7 +739,7 @@ export declare class TsconfigDiscovery {
|
|
|
739
739
|
* posture, and a permission-denied probe on one directory does not hide a
|
|
740
740
|
* config file above it.
|
|
741
741
|
*/
|
|
742
|
-
static
|
|
742
|
+
static findNearest(start: string, options?: FindNearestOptions): Effect.Effect<Option.Option<string>, never, FileSystem.FileSystem | Path.Path>;
|
|
743
743
|
}
|
|
744
744
|
declare const TsconfigExtendsError_base: Schema.Class<TsconfigExtendsError, Schema.TaggedStruct<"TsconfigExtendsError", {
|
|
745
745
|
/** The config whose `extends` could not be resolved. */
|
|
@@ -1187,7 +1187,7 @@ export declare class TsconfigLoaderSync {
|
|
|
1187
1187
|
* `TsconfigParseError` or a `PlatformError` — the async pipeline's exact
|
|
1188
1188
|
* typed failures.
|
|
1189
1189
|
*/
|
|
1190
|
-
static
|
|
1190
|
+
static load(configPath: string, options: TsconfigLoaderSyncOptions): TsconfigJson.Type;
|
|
1191
1191
|
/**
|
|
1192
1192
|
* {@link TsconfigLoader.resolve}, synchronously: the full load -\>
|
|
1193
1193
|
* extends -\> merge -\> `${configDir}` pipeline through the
|
|
@@ -1195,13 +1195,13 @@ export declare class TsconfigLoaderSync {
|
|
|
1195
1195
|
* `TsconfigExtendsError` or a `PlatformError` — the async pipeline's exact
|
|
1196
1196
|
* typed failures.
|
|
1197
1197
|
*/
|
|
1198
|
-
static
|
|
1198
|
+
static resolve(configPath: string, options: TsconfigLoaderSyncOptions): ResolvedTsconfig;
|
|
1199
1199
|
/**
|
|
1200
1200
|
* {@link TsconfigLoader.compilerOptions}, synchronously: resolve the full
|
|
1201
1201
|
* `extends` chain and project out the merged `compilerOptions`. Throws
|
|
1202
1202
|
* the same typed failures as {@link TsconfigLoaderSync.resolve}.
|
|
1203
1203
|
*/
|
|
1204
|
-
static
|
|
1204
|
+
static compilerOptions(configPath: string, options: TsconfigLoaderSyncOptions): CompilerOptions.Type;
|
|
1205
1205
|
}
|
|
1206
1206
|
/**
|
|
1207
1207
|
* The nine `compilerOptions` / `watchOptions` enum families this codec knows.
|
|
@@ -1304,13 +1304,13 @@ export declare class TsEnumCodec {
|
|
|
1304
1304
|
* Encodes a family's canonical (or alias) string spelling to its numeric
|
|
1305
1305
|
* form. `Option.none()` for a string with no table entry — never guessed.
|
|
1306
1306
|
*/
|
|
1307
|
-
static
|
|
1307
|
+
static encode(family: EnumFamily, value: string): Option.Option<number>;
|
|
1308
1308
|
/**
|
|
1309
1309
|
* Decodes a family's numeric value to its canonical string spelling.
|
|
1310
1310
|
* `Option.none()` for a numeric value with no table entry (a future TS
|
|
1311
1311
|
* enum member) — never guessed.
|
|
1312
1312
|
*/
|
|
1313
|
-
static
|
|
1313
|
+
static decode(family: EnumFamily, value: number): Option.Option<string>;
|
|
1314
1314
|
/**
|
|
1315
1315
|
* Normalizes any spelling of a `lib` reference — the plain short name
|
|
1316
1316
|
* (`esnext`), the on-disk file name (`lib.esnext.d.ts`), or an absolute
|
|
@@ -1319,7 +1319,7 @@ export declare class TsEnumCodec {
|
|
|
1319
1319
|
* leading directory, the `lib.` prefix and the `.d.ts` suffix; idempotent
|
|
1320
1320
|
* on an already-short name.
|
|
1321
1321
|
*/
|
|
1322
|
-
static
|
|
1322
|
+
static normalizeLibReference(lib: string): string;
|
|
1323
1323
|
/**
|
|
1324
1324
|
* Encodes a decoded `compilerOptions` object into the
|
|
1325
1325
|
* numeric-enum-shaped {@link ProgrammaticCompilerOptions} form
|
|
@@ -1338,7 +1338,7 @@ export declare class TsEnumCodec {
|
|
|
1338
1338
|
* cast. Runtime behavior is unchanged; only the declared return type
|
|
1339
1339
|
* narrows.
|
|
1340
1340
|
*/
|
|
1341
|
-
static
|
|
1341
|
+
static encodeCompilerOptions(options: CompilerOptions.Type): ProgrammaticCompilerOptions;
|
|
1342
1342
|
/**
|
|
1343
1343
|
* Decodes a numeric-enum-shaped `compilerOptions` object (as produced by
|
|
1344
1344
|
* {@link TsEnumCodec.encodeCompilerOptions} or read off a live
|
|
@@ -1352,7 +1352,7 @@ export declare class TsEnumCodec {
|
|
|
1352
1352
|
* value would violate that narrower type's contract. Every other key is
|
|
1353
1353
|
* copied through untouched.
|
|
1354
1354
|
*/
|
|
1355
|
-
static
|
|
1355
|
+
static decodeCompilerOptions(numeric: Readonly<Record<string, unknown>>): Record<string, unknown>;
|
|
1356
1356
|
}
|
|
1357
1357
|
export type { EnumFamily, FindNearestOptions, PortableTsconfigOptions, ProgrammaticCompilerOptions, ProgrammaticCompilerOptionsValue, ProgrammaticRecord, SyncFileSystem, SyncPath, TsconfigLoaderSyncOptions };
|
|
1358
1358
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/tsconfig-json",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Composable tsconfig.json handling for Effect: schemas, extends-chain resolution, and config discovery.",
|
|
6
6
|
"keywords": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@effected/glob": "^0.14.0",
|
|
43
43
|
"@effected/jsonc": "^0.20.0",
|
|
44
|
-
"@effected/walker": "^0.20.
|
|
44
|
+
"@effected/walker": "^0.20.1",
|
|
45
45
|
"effect": "^4.0.0"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|