@visulima/tsconfig 1.1.5 → 1.1.7
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/CHANGELOG.md +20 -0
- package/README.md +49 -47
- package/dist/index.cjs +16 -1
- package/dist/index.mjs +3 -1
- package/dist/packem_shared/findTsConfig-CdifbnQv.mjs +65 -0
- package/dist/packem_shared/findTsConfig-qT51EoCR.cjs +70 -0
- package/dist/packem_shared/implicitBaseUrlSymbol-BBZsxGbd.cjs +431 -0
- package/dist/packem_shared/implicitBaseUrlSymbol-CEKMlQ_X.mjs +421 -0
- package/dist/packem_shared/writeTsConfig-BImVv2Ba.mjs +18 -0
- package/dist/packem_shared/writeTsConfig-DJa7JuZ_.cjs +23 -0
- package/package.json +12 -13
- package/dist/packem_shared/findTsConfig-C77rAonk.cjs +0 -1
- package/dist/packem_shared/findTsConfig-CvOobjQ5.mjs +0 -1
- package/dist/packem_shared/implicitBaseUrlSymbol-BMiB-zfM.mjs +0 -1
- package/dist/packem_shared/implicitBaseUrlSymbol-Bfg9VyQS.cjs +0 -1
- package/dist/packem_shared/writeTsConfig-D_MA7_Uu.cjs +0 -1
- package/dist/packem_shared/writeTsConfig-Dwba2y0l.mjs +0 -1
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { isAccessibleSync, findUpSync, readFileSync } from '@visulima/fs';
|
|
2
|
+
import { NotFoundError } from '@visulima/fs/error';
|
|
3
|
+
import { join, resolve, isAbsolute, dirname, relative, normalize, toNamespacedPath } from '@visulima/path';
|
|
4
|
+
import { isRelative } from '@visulima/path/utils';
|
|
5
|
+
import { parse } from 'jsonc-parser';
|
|
6
|
+
import { statSync } from 'node:fs';
|
|
7
|
+
import Module from 'node:module';
|
|
8
|
+
import { resolveExports } from 'resolve-pkg-maps';
|
|
9
|
+
|
|
10
|
+
var __defProp$1 = Object.defineProperty;
|
|
11
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
12
|
+
const readJsonc$1 = /* @__PURE__ */ __name$1((jsonPath) => parse(readFileSync(jsonPath, { buffer: false })), "readJsonc");
|
|
13
|
+
const getPnpApi = /* @__PURE__ */ __name$1(() => {
|
|
14
|
+
const { findPnpApi } = Module;
|
|
15
|
+
return findPnpApi?.(process.cwd());
|
|
16
|
+
}, "getPnpApi");
|
|
17
|
+
const resolveFromPackageJsonPath = /* @__PURE__ */ __name$1((packageJsonPath, subpath, ignoreExports, cache) => {
|
|
18
|
+
const cacheKey = "resolveFromPackageJsonPath:" + packageJsonPath + ":" + subpath + ":" + (ignoreExports ? "yes" : "no");
|
|
19
|
+
if (cache?.has(cacheKey)) {
|
|
20
|
+
return cache.get(cacheKey);
|
|
21
|
+
}
|
|
22
|
+
const packageJson = readJsonc$1(packageJsonPath);
|
|
23
|
+
if (!packageJson) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
let resolvedPath = subpath || "tsconfig.json";
|
|
27
|
+
if (!ignoreExports && packageJson.exports) {
|
|
28
|
+
try {
|
|
29
|
+
const [resolvedExport] = resolveExports(packageJson.exports, subpath, ["require", "types"]);
|
|
30
|
+
resolvedPath = resolvedExport;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
} else if (!subpath && packageJson.tsconfig) {
|
|
35
|
+
resolvedPath = packageJson.tsconfig;
|
|
36
|
+
}
|
|
37
|
+
resolvedPath = join(packageJsonPath, "..", resolvedPath);
|
|
38
|
+
cache?.set(cacheKey, resolvedPath);
|
|
39
|
+
return resolvedPath;
|
|
40
|
+
}, "resolveFromPackageJsonPath");
|
|
41
|
+
const PACKAGE_JSON = "package.json";
|
|
42
|
+
const TS_CONFIG_JSON = "tsconfig.json";
|
|
43
|
+
const resolveExtendsPath = /* @__PURE__ */ __name$1((requestedPath, directoryPath, cache) => {
|
|
44
|
+
let filePath = requestedPath;
|
|
45
|
+
if (requestedPath === "..") {
|
|
46
|
+
filePath = join(filePath, TS_CONFIG_JSON);
|
|
47
|
+
}
|
|
48
|
+
if (requestedPath.startsWith(".")) {
|
|
49
|
+
filePath = resolve(directoryPath, filePath);
|
|
50
|
+
}
|
|
51
|
+
if (isAbsolute(filePath)) {
|
|
52
|
+
if (isAccessibleSync(filePath)) {
|
|
53
|
+
if (statSync(filePath).isFile()) {
|
|
54
|
+
return filePath;
|
|
55
|
+
}
|
|
56
|
+
} else if (!filePath.endsWith(".json")) {
|
|
57
|
+
const jsonPath = `${filePath}.json`;
|
|
58
|
+
if (isAccessibleSync(jsonPath)) {
|
|
59
|
+
return jsonPath;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const [orgOrName, ...remaining] = requestedPath.split("/");
|
|
65
|
+
const packageName = orgOrName.startsWith("@") ? orgOrName + "/" + remaining.shift() : orgOrName;
|
|
66
|
+
const subpath = remaining.join("/");
|
|
67
|
+
const pnpApi = getPnpApi();
|
|
68
|
+
if (pnpApi) {
|
|
69
|
+
const { resolveRequest: resolveWithPnp } = pnpApi;
|
|
70
|
+
try {
|
|
71
|
+
if (packageName === requestedPath) {
|
|
72
|
+
const packageJsonPath2 = resolveWithPnp(join(packageName, PACKAGE_JSON), directoryPath);
|
|
73
|
+
if (packageJsonPath2) {
|
|
74
|
+
const resolvedPath = resolveFromPackageJsonPath(packageJsonPath2, subpath, false, cache);
|
|
75
|
+
if (resolvedPath && isAccessibleSync(resolvedPath)) {
|
|
76
|
+
return resolvedPath;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
let resolved;
|
|
81
|
+
try {
|
|
82
|
+
resolved = resolveWithPnp(requestedPath, directoryPath, { extensions: [".json"] });
|
|
83
|
+
} catch {
|
|
84
|
+
resolved = resolveWithPnp(join(requestedPath, TS_CONFIG_JSON), directoryPath);
|
|
85
|
+
}
|
|
86
|
+
if (resolved) {
|
|
87
|
+
return resolved;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const packagePath = findUpSync(
|
|
94
|
+
(directory) => {
|
|
95
|
+
const path = join(resolve(directory), "node_modules", packageName);
|
|
96
|
+
if (isAccessibleSync(path)) {
|
|
97
|
+
return join("node_modules", packageName);
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
cwd: directoryPath,
|
|
103
|
+
type: "directory"
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
if (!packagePath || !statSync(packagePath).isDirectory()) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const packageJsonPath = join(packagePath, PACKAGE_JSON);
|
|
110
|
+
if (isAccessibleSync(packageJsonPath)) {
|
|
111
|
+
const resolvedPath = resolveFromPackageJsonPath(packageJsonPath, subpath, false, cache);
|
|
112
|
+
if (resolvedPath === false) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
if (resolvedPath && isAccessibleSync(resolvedPath) && statSync(resolvedPath).isFile()) {
|
|
116
|
+
return resolvedPath;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const fullPackagePath = join(packagePath, subpath);
|
|
120
|
+
const jsonExtension = fullPackagePath.endsWith(".json");
|
|
121
|
+
if (!jsonExtension) {
|
|
122
|
+
const fullPackagePathWithJson = fullPackagePath + ".json";
|
|
123
|
+
if (isAccessibleSync(fullPackagePathWithJson)) {
|
|
124
|
+
return fullPackagePathWithJson;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!isAccessibleSync(fullPackagePath)) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
if (statSync(fullPackagePath).isDirectory()) {
|
|
131
|
+
const fullPackageJsonPath = join(fullPackagePath, PACKAGE_JSON);
|
|
132
|
+
if (isAccessibleSync(fullPackageJsonPath)) {
|
|
133
|
+
const resolvedPath = resolveFromPackageJsonPath(fullPackageJsonPath, "", true, cache);
|
|
134
|
+
if (resolvedPath && isAccessibleSync(resolvedPath)) {
|
|
135
|
+
return resolvedPath;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const tsconfigPath = join(fullPackagePath, TS_CONFIG_JSON);
|
|
139
|
+
if (isAccessibleSync(tsconfigPath)) {
|
|
140
|
+
return tsconfigPath;
|
|
141
|
+
}
|
|
142
|
+
} else if (jsonExtension) {
|
|
143
|
+
return fullPackagePath;
|
|
144
|
+
}
|
|
145
|
+
return undefined;
|
|
146
|
+
}, "resolveExtendsPath");
|
|
147
|
+
|
|
148
|
+
var __defProp = Object.defineProperty;
|
|
149
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
150
|
+
const readJsonc = /* @__PURE__ */ __name((jsonPath) => parse(readFileSync(jsonPath, { buffer: false })), "readJsonc");
|
|
151
|
+
const normalizePath = /* @__PURE__ */ __name((path) => {
|
|
152
|
+
const namespacedPath = toNamespacedPath(path);
|
|
153
|
+
return isRelative(namespacedPath) ? namespacedPath : `./${namespacedPath}`;
|
|
154
|
+
}, "normalizePath");
|
|
155
|
+
const filesProperties = ["files", "include", "exclude"];
|
|
156
|
+
const resolveExtends = /* @__PURE__ */ __name((extendsPath, fromDirectoryPath, circularExtendsTracker, options) => {
|
|
157
|
+
const resolvedExtendsPath = resolveExtendsPath(extendsPath, fromDirectoryPath);
|
|
158
|
+
if (!resolvedExtendsPath) {
|
|
159
|
+
throw new NotFoundError(`No such file or directory, for '${extendsPath}' found.`);
|
|
160
|
+
}
|
|
161
|
+
if (circularExtendsTracker.has(resolvedExtendsPath)) {
|
|
162
|
+
throw new Error(`Circularity detected while resolving configuration: ${resolvedExtendsPath}`);
|
|
163
|
+
}
|
|
164
|
+
circularExtendsTracker.add(resolvedExtendsPath);
|
|
165
|
+
const extendsDirectoryPath = dirname(resolvedExtendsPath);
|
|
166
|
+
const extendsConfig = internalParseTsConfig(resolvedExtendsPath, options, circularExtendsTracker);
|
|
167
|
+
delete extendsConfig.references;
|
|
168
|
+
const { compilerOptions } = extendsConfig;
|
|
169
|
+
if (compilerOptions) {
|
|
170
|
+
const { baseUrl } = compilerOptions;
|
|
171
|
+
if (baseUrl && !baseUrl.startsWith(configDirectoryPlaceholder)) {
|
|
172
|
+
compilerOptions.baseUrl = normalize(relative(fromDirectoryPath, join(extendsDirectoryPath, baseUrl))) || "./";
|
|
173
|
+
}
|
|
174
|
+
let { outDir } = compilerOptions;
|
|
175
|
+
if (outDir) {
|
|
176
|
+
if (!outDir.startsWith(configDirectoryPlaceholder)) {
|
|
177
|
+
outDir = relative(fromDirectoryPath, join(extendsDirectoryPath, outDir));
|
|
178
|
+
}
|
|
179
|
+
compilerOptions.outDir = normalizePath(outDir.replace(configDirectoryPlaceholder + "/", "")) || "./";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const property of filesProperties) {
|
|
183
|
+
const filesList = extendsConfig[property];
|
|
184
|
+
if (filesList) {
|
|
185
|
+
extendsConfig[property] = filesList.map((file) => {
|
|
186
|
+
if (file.startsWith(configDirectoryPlaceholder)) {
|
|
187
|
+
return file;
|
|
188
|
+
}
|
|
189
|
+
if (isAbsolute(file)) {
|
|
190
|
+
return file;
|
|
191
|
+
}
|
|
192
|
+
return relative(fromDirectoryPath, join(extendsDirectoryPath, file));
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return extendsConfig;
|
|
197
|
+
}, "resolveExtends");
|
|
198
|
+
const internalParseTsConfig = /* @__PURE__ */ __name((tsconfigPath, options, circularExtendsTracker = /* @__PURE__ */ new Set()) => {
|
|
199
|
+
let config;
|
|
200
|
+
try {
|
|
201
|
+
config = readJsonc(tsconfigPath) || {};
|
|
202
|
+
} catch {
|
|
203
|
+
throw new Error(`Cannot resolve tsconfig at path: ${tsconfigPath}`);
|
|
204
|
+
}
|
|
205
|
+
if (typeof config !== "object") {
|
|
206
|
+
throw new SyntaxError(`Failed to parse tsconfig at: ${tsconfigPath}`);
|
|
207
|
+
}
|
|
208
|
+
const directoryPath = dirname(tsconfigPath);
|
|
209
|
+
if (config.compilerOptions) {
|
|
210
|
+
const { compilerOptions } = config;
|
|
211
|
+
if (compilerOptions.paths && !compilerOptions.baseUrl) {
|
|
212
|
+
compilerOptions[implicitBaseUrlSymbol] = directoryPath;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (config.extends) {
|
|
216
|
+
const extendsPathList = Array.isArray(config.extends) ? config.extends : [config.extends];
|
|
217
|
+
delete config.extends;
|
|
218
|
+
for (const extendsPath of extendsPathList.reverse()) {
|
|
219
|
+
const extendsConfig = resolveExtends(extendsPath, directoryPath, new Set(circularExtendsTracker), options);
|
|
220
|
+
const merged = {
|
|
221
|
+
...extendsConfig,
|
|
222
|
+
...config,
|
|
223
|
+
compilerOptions: {
|
|
224
|
+
...extendsConfig.compilerOptions,
|
|
225
|
+
...config.compilerOptions
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
if (extendsConfig.watchOptions) {
|
|
229
|
+
merged.watchOptions = {
|
|
230
|
+
...extendsConfig.watchOptions,
|
|
231
|
+
...config.watchOptions
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
config = merged;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (config.compilerOptions) {
|
|
238
|
+
const { compilerOptions } = config;
|
|
239
|
+
for (const property of ["baseUrl", "rootDir"]) {
|
|
240
|
+
const unresolvedPath = compilerOptions[property];
|
|
241
|
+
if (unresolvedPath && !unresolvedPath.startsWith(configDirectoryPlaceholder)) {
|
|
242
|
+
const resolvedBaseUrl = resolve(directoryPath, unresolvedPath);
|
|
243
|
+
compilerOptions[property] = normalizePath(relative(directoryPath, resolvedBaseUrl));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
for (const outputField of ["outDir", "declarationDir"]) {
|
|
247
|
+
let outputPath = compilerOptions[outputField];
|
|
248
|
+
if (outputPath) {
|
|
249
|
+
if (!Array.isArray(config.exclude)) {
|
|
250
|
+
config.exclude = [];
|
|
251
|
+
}
|
|
252
|
+
let excludePath = outputPath;
|
|
253
|
+
if (!isAbsolute(excludePath)) {
|
|
254
|
+
excludePath = join(directoryPath, excludePath);
|
|
255
|
+
}
|
|
256
|
+
excludePath = excludePath.replace(configDirectoryPlaceholder, "");
|
|
257
|
+
if (!config.exclude.includes(excludePath)) {
|
|
258
|
+
config.exclude.push(excludePath);
|
|
259
|
+
}
|
|
260
|
+
if (!outputPath.startsWith(configDirectoryPlaceholder)) {
|
|
261
|
+
outputPath = normalizePath(outputPath);
|
|
262
|
+
}
|
|
263
|
+
compilerOptions[outputField] = outputPath;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (options?.tscCompatible && compilerOptions.isolatedModules) {
|
|
267
|
+
compilerOptions.preserveConstEnums = compilerOptions.preserveConstEnums ?? true;
|
|
268
|
+
}
|
|
269
|
+
if (options?.tscCompatible && compilerOptions.esModuleInterop) {
|
|
270
|
+
compilerOptions.allowSyntheticDefaultImports = compilerOptions.allowSyntheticDefaultImports ?? true;
|
|
271
|
+
}
|
|
272
|
+
if (options?.tscCompatible && compilerOptions.target === "esnext") {
|
|
273
|
+
compilerOptions.useDefineForClassFields = compilerOptions.useDefineForClassFields ?? true;
|
|
274
|
+
}
|
|
275
|
+
} else {
|
|
276
|
+
config.compilerOptions = {};
|
|
277
|
+
}
|
|
278
|
+
if (config.include) {
|
|
279
|
+
config.include = config.include.map((element) => normalize(element));
|
|
280
|
+
if (config.files) {
|
|
281
|
+
delete config.files;
|
|
282
|
+
}
|
|
283
|
+
} else if (config.files) {
|
|
284
|
+
config.files = config.files.map((file) => file.startsWith(configDirectoryPlaceholder) ? file : normalizePath(file));
|
|
285
|
+
}
|
|
286
|
+
if (config.watchOptions) {
|
|
287
|
+
const { watchOptions } = config;
|
|
288
|
+
if (watchOptions.excludeDirectories) {
|
|
289
|
+
watchOptions.excludeDirectories = watchOptions.excludeDirectories.map((excludePath) => resolve(directoryPath, excludePath));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return config;
|
|
293
|
+
}, "internalParseTsConfig");
|
|
294
|
+
const interpolateConfigDirectory = /* @__PURE__ */ __name((filePath, configDirectory) => {
|
|
295
|
+
if (filePath.startsWith(configDirectoryPlaceholder)) {
|
|
296
|
+
return normalize(join(configDirectory, filePath.slice(configDirectoryPlaceholder.length)));
|
|
297
|
+
}
|
|
298
|
+
return undefined;
|
|
299
|
+
}, "interpolateConfigDirectory");
|
|
300
|
+
const compilerFieldsWithConfigDirectory = ["outDir", "declarationDir", "outFile", "rootDir", "baseUrl", "tsBuildInfoFile"];
|
|
301
|
+
const tsCompatibleWrapper = /* @__PURE__ */ __name((config, options) => {
|
|
302
|
+
if (config.compilerOptions === undefined) {
|
|
303
|
+
return config;
|
|
304
|
+
}
|
|
305
|
+
if (config.compilerOptions.module === "node16" && ["5.4", "5.5", "5.6", "5.7", "true"].includes(String(options.tscCompatible))) {
|
|
306
|
+
config.compilerOptions.allowSyntheticDefaultImports = config.compilerOptions.allowSyntheticDefaultImports ?? true;
|
|
307
|
+
config.compilerOptions.esModuleInterop = config.compilerOptions.module === "node16" || config.compilerOptions.module === "nodenext" || config.compilerOptions.module === "perserve" ? config.compilerOptions.esModuleInterop ?? true : config.compilerOptions.esModuleInterop ?? false;
|
|
308
|
+
config.compilerOptions.moduleDetection = config?.compilerOptions.moduleDetection ?? (["node16", "nodenext"].includes(config.compilerOptions.module) ? "force" : "auto");
|
|
309
|
+
let moduleResolution = "classic";
|
|
310
|
+
switch ((config.compilerOptions?.module).toLocaleLowerCase()) {
|
|
311
|
+
case "commonjs": {
|
|
312
|
+
moduleResolution = "node10";
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
case "node16": {
|
|
316
|
+
moduleResolution = "node16";
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
case "nodenext": {
|
|
320
|
+
moduleResolution = "nodenext";
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
case "preserve": {
|
|
324
|
+
moduleResolution = "bundler";
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
config.compilerOptions.moduleResolution = moduleResolution;
|
|
329
|
+
if (["5.7"].includes(String(options.tscCompatible))) {
|
|
330
|
+
let resolvePackageJson = false;
|
|
331
|
+
if (config.compilerOptions.moduleResolution === "node16" || config.compilerOptions.moduleResolution === "nodenext" || config.compilerOptions.moduleResolution === "bundler") {
|
|
332
|
+
resolvePackageJson = true;
|
|
333
|
+
}
|
|
334
|
+
config.compilerOptions.resolvePackageJsonExports = config.compilerOptions.resolvePackageJsonExports ?? resolvePackageJson;
|
|
335
|
+
config.compilerOptions.resolvePackageJsonImports = config.compilerOptions.resolvePackageJsonImports ?? resolvePackageJson;
|
|
336
|
+
}
|
|
337
|
+
let target = "es5";
|
|
338
|
+
if (config.compilerOptions.module === "node16") {
|
|
339
|
+
target = "es2022";
|
|
340
|
+
} else if (config.compilerOptions.module === "nodenext") {
|
|
341
|
+
target = "esnext";
|
|
342
|
+
}
|
|
343
|
+
config.compilerOptions.target = target;
|
|
344
|
+
config.compilerOptions.useDefineForClassFields = config.compilerOptions.useDefineForClassFields ?? (config.compilerOptions.target.includes("es202") || config.compilerOptions.target === "esnext");
|
|
345
|
+
}
|
|
346
|
+
if (config.compilerOptions.strict) {
|
|
347
|
+
if (["5.6", "5.7", "true"].includes(String(options.tscCompatible))) {
|
|
348
|
+
config.compilerOptions.strictBuiltinIteratorReturn = config.compilerOptions.strictBuiltinIteratorReturn ?? true;
|
|
349
|
+
}
|
|
350
|
+
if (["5.4", "5.5", "5.6", "5.7", "true"].includes(String(options.tscCompatible))) {
|
|
351
|
+
config.compilerOptions.noImplicitAny = config.compilerOptions.noImplicitAny ?? true;
|
|
352
|
+
config.compilerOptions.noImplicitThis = config.compilerOptions.noImplicitThis ?? true;
|
|
353
|
+
config.compilerOptions.strictNullChecks = config.compilerOptions.strictNullChecks ?? true;
|
|
354
|
+
config.compilerOptions.strictFunctionTypes = config.compilerOptions.strictFunctionTypes ?? true;
|
|
355
|
+
config.compilerOptions.strictBindCallApply = config.compilerOptions.strictBindCallApply ?? true;
|
|
356
|
+
config.compilerOptions.strictPropertyInitialization = config.compilerOptions.strictPropertyInitialization ?? true;
|
|
357
|
+
config.compilerOptions.alwaysStrict = config.compilerOptions.alwaysStrict ?? true;
|
|
358
|
+
config.compilerOptions.useUnknownInCatchVariables = config.compilerOptions.useUnknownInCatchVariables ?? true;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return config;
|
|
362
|
+
}, "tsCompatibleWrapper");
|
|
363
|
+
const configDirectoryPlaceholder = "${configDir}";
|
|
364
|
+
const implicitBaseUrlSymbol = Symbol("implicitBaseUrl");
|
|
365
|
+
const readTsConfig = /* @__PURE__ */ __name((tsconfigPath, options) => {
|
|
366
|
+
const resolvedTsconfigPath = resolve(tsconfigPath);
|
|
367
|
+
const config = internalParseTsConfig(resolvedTsconfigPath, options);
|
|
368
|
+
const configDirectory = dirname(resolvedTsconfigPath);
|
|
369
|
+
const { compilerOptions } = config;
|
|
370
|
+
if (compilerOptions) {
|
|
371
|
+
for (const property of compilerFieldsWithConfigDirectory) {
|
|
372
|
+
const value = compilerOptions[property];
|
|
373
|
+
if (value) {
|
|
374
|
+
const resolvedPath = interpolateConfigDirectory(value, configDirectory);
|
|
375
|
+
compilerOptions[property] = resolvedPath ? normalizePath(relative(configDirectory, resolvedPath)) : value;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
for (const property of ["rootDirs", "typeRoots"]) {
|
|
379
|
+
const value = compilerOptions[property];
|
|
380
|
+
if (value) {
|
|
381
|
+
compilerOptions[property] = value.map((v) => {
|
|
382
|
+
const resolvedPath = interpolateConfigDirectory(v, configDirectory);
|
|
383
|
+
return resolvedPath ? normalizePath(relative(configDirectory, resolvedPath)) : v;
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const { paths } = compilerOptions;
|
|
388
|
+
if (paths) {
|
|
389
|
+
for (const name of Object.keys(paths)) {
|
|
390
|
+
paths[name] = paths[name].map((filePath) => interpolateConfigDirectory(filePath, configDirectory) ?? filePath);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (compilerOptions.outDir) {
|
|
394
|
+
compilerOptions.outDir = compilerOptions.outDir.replace(configDirectoryPlaceholder, "");
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
for (const property of filesProperties) {
|
|
398
|
+
const value = config[property];
|
|
399
|
+
if (value) {
|
|
400
|
+
config[property] = value.map((filePath) => {
|
|
401
|
+
const interpolate = interpolateConfigDirectory(filePath, configDirectory);
|
|
402
|
+
if (interpolate) {
|
|
403
|
+
return interpolate;
|
|
404
|
+
}
|
|
405
|
+
if (property === "files" && isRelative(filePath)) {
|
|
406
|
+
return filePath;
|
|
407
|
+
}
|
|
408
|
+
if (property === "include" && isRelative(filePath)) {
|
|
409
|
+
return join(configDirectory, filePath);
|
|
410
|
+
}
|
|
411
|
+
return normalize(filePath);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (options?.tscCompatible) {
|
|
416
|
+
tsCompatibleWrapper(config, options);
|
|
417
|
+
}
|
|
418
|
+
return config;
|
|
419
|
+
}, "readTsConfig");
|
|
420
|
+
|
|
421
|
+
export { configDirectoryPlaceholder, implicitBaseUrlSymbol, readTsConfig };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { writeJson, writeJsonSync } from '@visulima/fs';
|
|
2
|
+
import { toPath } from '@visulima/fs/utils';
|
|
3
|
+
import { join } from '@visulima/path';
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const writeTsConfig = /* @__PURE__ */ __name(async (tsConfig, options = {}) => {
|
|
8
|
+
const { cwd, ...writeOptions } = options;
|
|
9
|
+
const directory = toPath(cwd ?? process.cwd());
|
|
10
|
+
await writeJson(join(directory, "tsconfig.json"), tsConfig, writeOptions);
|
|
11
|
+
}, "writeTsConfig");
|
|
12
|
+
const writeTsConfigSync = /* @__PURE__ */ __name((tsConfig, options = {}) => {
|
|
13
|
+
const { cwd, ...writeOptions } = options;
|
|
14
|
+
const directory = toPath(cwd ?? process.cwd());
|
|
15
|
+
writeJsonSync(join(directory, "tsconfig.json"), tsConfig, writeOptions);
|
|
16
|
+
}, "writeTsConfigSync");
|
|
17
|
+
|
|
18
|
+
export { writeTsConfig, writeTsConfigSync };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const fs = require('@visulima/fs');
|
|
6
|
+
const utils = require('@visulima/fs/utils');
|
|
7
|
+
const path = require('@visulima/path');
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
const writeTsConfig = /* @__PURE__ */ __name(async (tsConfig, options = {}) => {
|
|
12
|
+
const { cwd, ...writeOptions } = options;
|
|
13
|
+
const directory = utils.toPath(cwd ?? process.cwd());
|
|
14
|
+
await fs.writeJson(path.join(directory, "tsconfig.json"), tsConfig, writeOptions);
|
|
15
|
+
}, "writeTsConfig");
|
|
16
|
+
const writeTsConfigSync = /* @__PURE__ */ __name((tsConfig, options = {}) => {
|
|
17
|
+
const { cwd, ...writeOptions } = options;
|
|
18
|
+
const directory = utils.toPath(cwd ?? process.cwd());
|
|
19
|
+
fs.writeJsonSync(path.join(directory, "tsconfig.json"), tsConfig, writeOptions);
|
|
20
|
+
}, "writeTsConfigSync");
|
|
21
|
+
|
|
22
|
+
exports.writeTsConfig = writeTsConfig;
|
|
23
|
+
exports.writeTsConfigSync = writeTsConfigSync;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/tsconfig",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Find and/or parse the tsconfig.json file from a directory path.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -67,29 +67,28 @@
|
|
|
67
67
|
"CHANGELOG.md"
|
|
68
68
|
],
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@visulima/fs": "2.3.
|
|
71
|
-
"@visulima/path": "1.3.
|
|
70
|
+
"@visulima/fs": "2.3.6",
|
|
71
|
+
"@visulima/path": "1.3.2",
|
|
72
72
|
"jsonc-parser": "^3.3.1",
|
|
73
73
|
"resolve-pkg-maps": "^1.0.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@anolilab/eslint-config": "^15.0.3",
|
|
77
77
|
"@anolilab/prettier-config": "^5.0.14",
|
|
78
|
-
"@anolilab/semantic-release-pnpm": "1.1.
|
|
78
|
+
"@anolilab/semantic-release-pnpm": "1.1.6",
|
|
79
79
|
"@anolilab/semantic-release-preset": "^9.0.3",
|
|
80
80
|
"@arethetypeswrong/cli": "^0.17.2",
|
|
81
81
|
"@babel/core": "^7.26.0",
|
|
82
|
-
"@ckeditor/typedoc-plugins": "43.0.0",
|
|
83
82
|
"@rushstack/eslint-plugin-security": "^0.8.3",
|
|
84
83
|
"@secretlint/secretlint-rule-preset-recommend": "^9.0.0",
|
|
85
84
|
"@total-typescript/ts-reset": "^0.6.1",
|
|
86
85
|
"@types/node": "18.18.14",
|
|
87
|
-
"@visulima/packem": "1.
|
|
86
|
+
"@visulima/packem": "1.10.7",
|
|
88
87
|
"@vitest/coverage-v8": "^2.1.8",
|
|
89
88
|
"@vitest/ui": "^2.1.8",
|
|
90
89
|
"conventional-changelog-conventionalcommits": "8.0.0",
|
|
91
90
|
"cross-env": "^7.0.3",
|
|
92
|
-
"esbuild": "0.24.
|
|
91
|
+
"esbuild": "0.24.2",
|
|
93
92
|
"eslint": "8.57.0",
|
|
94
93
|
"eslint-plugin-deprecation": "^3.0.0",
|
|
95
94
|
"eslint-plugin-etc": "^2.0.3",
|
|
@@ -101,13 +100,13 @@
|
|
|
101
100
|
"prettier": "^3.4.2",
|
|
102
101
|
"rimraf": "6.0.1",
|
|
103
102
|
"secretlint": "9.0.0",
|
|
104
|
-
"semantic-release": "^24.2.
|
|
103
|
+
"semantic-release": "^24.2.1",
|
|
105
104
|
"tempy": "^3.1.0",
|
|
106
|
-
"type-fest": "^4.
|
|
107
|
-
"typedoc": "0.
|
|
108
|
-
"typedoc-plugin-markdown": "4.
|
|
109
|
-
"typedoc-plugin-rename-defaults": "0.7.
|
|
110
|
-
"typescript": "5.
|
|
105
|
+
"type-fest": "^4.32.0",
|
|
106
|
+
"typedoc": "0.27.6",
|
|
107
|
+
"typedoc-plugin-markdown": "4.4.1",
|
|
108
|
+
"typedoc-plugin-rename-defaults": "0.7.2",
|
|
109
|
+
"typescript": "5.7.3",
|
|
111
110
|
"vitest": "^2.1.8"
|
|
112
111
|
},
|
|
113
112
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var l=Object.defineProperty;var r=(c,e)=>l(c,"name",{value:e,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@visulima/fs"),s=require("@visulima/fs/error"),a=require("./implicitBaseUrlSymbol-Bfg9VyQS.cjs");var h=Object.defineProperty,d=r((c,e)=>h(c,"name",{value:e,configurable:!0}),"s");const g=new Map,u=d(async(c,e={})=>{const i=e.configFileName??"tsconfig.json";let n=await t.findUp(i,{...c&&{cwd:c},type:"file"});if(n||(n=await t.findUp("jsconfig.json",{...c&&{cwd:c},type:"file"})),!n)throw new s.NotFoundError(`No such file or directory, for ${i} or jsconfig.json found.`);const o=e.cache&&typeof e.cache!="boolean"?e.cache:g;if(e.cache&&o.has(n))return o.get(n);const f={config:a.readTsConfig(n),path:n};return e.cache&&o.set(n,f),f},"findTsConfig"),y=d((c,e={})=>{const i=e.configFileName??"tsconfig.json";let n=t.findUpSync(i,{...c&&{cwd:c},type:"file"});if(n||(n=t.findUpSync("jsconfig.json",{...c&&{cwd:c},type:"file"})),!n)throw new s.NotFoundError(`No such file or directory, for ${i} or jsconfig.json found.`);const o=e.cache&&typeof e.cache!="boolean"?e.cache:g;if(e.cache&&o.has(n))return o.get(n);const f={config:a.readTsConfig(n),path:n};return e.cache&&o.set(n,f),f},"findTsConfigSync");exports.findTsConfig=u;exports.findTsConfigSync=y;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var p=Object.defineProperty;var t=(o,e)=>p(o,"name",{value:e,configurable:!0});import{findUp as r,findUpSync as s}from"@visulima/fs";import{NotFoundError as a}from"@visulima/fs/error";import{readTsConfig as h}from"./implicitBaseUrlSymbol-BMiB-zfM.mjs";var l=Object.defineProperty,g=t((o,e)=>l(o,"name",{value:e,configurable:!0}),"s");const d=new Map,m=g(async(o,e={})=>{const f=e.configFileName??"tsconfig.json";let c=await r(f,{...o&&{cwd:o},type:"file"});if(c||(c=await r("jsconfig.json",{...o&&{cwd:o},type:"file"})),!c)throw new a(`No such file or directory, for ${f} or jsconfig.json found.`);const n=e.cache&&typeof e.cache!="boolean"?e.cache:d;if(e.cache&&n.has(c))return n.get(c);const i={config:h(c),path:c};return e.cache&&n.set(c,i),i},"findTsConfig"),C=g((o,e={})=>{const f=e.configFileName??"tsconfig.json";let c=s(f,{...o&&{cwd:o},type:"file"});if(c||(c=s("jsconfig.json",{...o&&{cwd:o},type:"file"})),!c)throw new a(`No such file or directory, for ${f} or jsconfig.json found.`);const n=e.cache&&typeof e.cache!="boolean"?e.cache:d;if(e.cache&&n.has(c))return n.get(c);const i={config:h(c),path:c};return e.cache&&n.set(c,i),i},"findTsConfigSync");export{m as findTsConfig,C as findTsConfigSync};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var R=Object.defineProperty;var I=(i,r)=>R(i,"name",{value:r,configurable:!0});import{readFileSync as k,isAccessibleSync as d,findUpSync as J}from"@visulima/fs";import{NotFoundError as N}from"@visulima/fs/error";import{join as f,resolve as C,isAbsolute as W,toNamespacedPath as z,dirname as E,normalize as O,relative as D}from"@visulima/path";import{isRelative as A}from"@visulima/path/utils";import{parse as $}from"jsonc-parser";import{statSync as x}from"node:fs";import M from"node:module";import{resolveExports as q}from"resolve-pkg-maps";var V=Object.defineProperty,F=I((i,r)=>V(i,"name",{value:r,configurable:!0}),"d");const _=F(i=>$(k(i,{buffer:!1})),"readJsonc"),G=F(()=>{const{findPnpApi:i}=M;return i?.(process.cwd())},"getPnpApi"),S=F((i,r,u,e)=>{const c="resolveFromPackageJsonPath:"+i+":"+r+":"+(u?"yes":"no");if(e?.has(c))return e.get(c);const t=_(i);if(!t)return;let n=r||"tsconfig.json";if(!u&&t.exports)try{const[o]=q(t.exports,r,["require","types"]);n=o}catch{return!1}else!r&&t.tsconfig&&(n=t.tsconfig);return n=f(i,"..",n),e?.set(c,n),n},"resolveFromPackageJsonPath"),j="package.json",P="tsconfig.json",H=F((i,r,u)=>{let e=i;if(i===".."&&(e=f(e,P)),i.startsWith(".")&&(e=C(r,e)),W(e)){if(d(e)){if(x(e).isFile())return e}else if(!e.endsWith(".json")){const a=`${e}.json`;if(d(a))return a}return}const[c,...t]=i.split("/"),n=c.startsWith("@")?c+"/"+t.shift():c,o=t.join("/"),s=G();if(s){const{resolveRequest:a}=s;try{if(n===i){const p=a(f(n,j),r);if(p){const g=S(p,o,!1,u);if(g&&d(g))return g}}else{let p;try{p=a(i,r,{extensions:[".json"]})}catch{p=a(f(i,P),r)}if(p)return p}}catch{}}const l=J(a=>{const p=f(C(a),"node_modules",n);if(d(p))return f("node_modules",n)},{cwd:r,type:"directory"});if(!l||!x(l).isDirectory())return;const h=f(l,j);if(d(h)){const a=S(h,o,!1,u);if(a===!1)return;if(a&&d(a)&&x(a).isFile())return a}const y=f(l,o),U=y.endsWith(".json");if(!U){const a=y+".json";if(d(a))return a}if(d(y)){if(x(y).isDirectory()){const a=f(y,j);if(d(a)){const g=S(a,"",!0,u);if(g&&d(g))return g}const p=f(y,P);if(d(p))return p}else if(U)return y}},"resolveExtendsPath");var K=Object.defineProperty,w=I((i,r)=>K(i,"name",{value:r,configurable:!0}),"u");const L=w(i=>$(k(i,{buffer:!1})),"readJsonc"),b=w(i=>{const r=z(i);return A(r)?r:`./${r}`},"normalizePath"),B=["files","include","exclude"],Q=w((i,r,u,e)=>{const c=H(i,r);if(!c)throw new N(`No such file or directory, for '${i}' found.`);if(u.has(c))throw new Error(`Circularity detected while resolving configuration: ${c}`);u.add(c);const t=E(c),n=T(c,e,u);delete n.references;const{compilerOptions:o}=n;if(o){const{baseUrl:s}=o;s&&!s.startsWith(m)&&(o.baseUrl=O(D(r,f(t,s)))||"./");let{outDir:l}=o;l&&(l.startsWith(m)||(l=D(r,f(t,l))),o.outDir=b(l.replace(m+"/",""))||"./")}for(const s of B){const l=n[s];l&&(n[s]=l.map(h=>h.startsWith(m)||W(h)?h:D(r,f(t,h))))}return n},"resolveExtends"),T=w((i,r,u=new Set)=>{let e;try{e=L(i)||{}}catch{throw new Error(`Cannot resolve tsconfig at path: ${i}`)}if(typeof e!="object")throw new SyntaxError(`Failed to parse tsconfig at: ${i}`);const c=E(i);if(e.compilerOptions){const{compilerOptions:t}=e;t.paths&&!t.baseUrl&&(t[Y]=c)}if(e.extends){const t=Array.isArray(e.extends)?e.extends:[e.extends];delete e.extends;for(const n of t.reverse()){const o=Q(n,c,new Set(u),r),s={...o,...e,compilerOptions:{...o.compilerOptions,...e.compilerOptions}};o.watchOptions&&(s.watchOptions={...o.watchOptions,...e.watchOptions}),e=s}}if(e.compilerOptions){const{compilerOptions:t}=e;for(const n of["baseUrl","rootDir"]){const o=t[n];if(o&&!o.startsWith(m)){const s=C(c,o);t[n]=b(D(c,s))}}for(const n of["outDir","declarationDir"]){let o=t[n];if(o){Array.isArray(e.exclude)||(e.exclude=[]);let s=o;W(s)||(s=f(c,s)),s=s.replace(m,""),e.exclude.includes(s)||e.exclude.push(s),o.startsWith(m)||(o=b(o)),t[n]=o}}r?.tscCompatible&&t.module==="node16"&&["5.4","5.5","5.6","true"].includes(String(r.tscCompatible))&&(t.allowSyntheticDefaultImports=t.allowSyntheticDefaultImports??!0,t.esModuleInterop=t.esModuleInterop??!0,t.moduleDetection=t.moduleDetection??"force",t.moduleResolution=t.moduleResolution??"node16",t.target=t.target??"es2022",t.useDefineForClassFields=t.useDefineForClassFields??!0),r?.tscCompatible&&t.strict&&(["5.6","true"].includes(String(r.tscCompatible))&&(t.strictBuiltinIteratorReturn=t.strictBuiltinIteratorReturn??!0),["5.4","5.5","5.6","true"].includes(String(r.tscCompatible))&&(t.noImplicitAny=t.noImplicitAny??!0,t.noImplicitThis=t.noImplicitThis??!0,t.strictNullChecks=t.strictNullChecks??!0,t.strictFunctionTypes=t.strictFunctionTypes??!0,t.strictBindCallApply=t.strictBindCallApply??!0,t.strictPropertyInitialization=t.strictPropertyInitialization??!0,t.alwaysStrict=t.alwaysStrict??!0,t.useUnknownInCatchVariables=t.useUnknownInCatchVariables??!0)),r?.tscCompatible&&t.isolatedModules&&(t.preserveConstEnums=t.preserveConstEnums??!0),r?.tscCompatible&&t.esModuleInterop&&(t.allowSyntheticDefaultImports=t.allowSyntheticDefaultImports??!0),r?.tscCompatible&&t.target==="esnext"&&(t.useDefineForClassFields=t.useDefineForClassFields??!0)}else e.compilerOptions={};if(e.include?(e.include=e.include.map(t=>O(t)),e.files&&delete e.files):e.files&&(e.files=e.files.map(t=>t.startsWith(m)?t:b(t))),e.watchOptions){const{watchOptions:t}=e;t.excludeDirectories&&(t.excludeDirectories=t.excludeDirectories.map(n=>C(c,n)))}return e},"internalParseTsConfig"),v=w((i,r)=>{if(i.startsWith(m))return O(f(r,i.slice(m.length)))},"interpolateConfigDirectory"),X=["outDir","declarationDir","outFile","rootDir","baseUrl","tsBuildInfoFile"],m="${configDir}",Y=Symbol("implicitBaseUrl"),lt=w((i,r)=>{const u=C(i),e=T(u,r),c=E(u),{compilerOptions:t}=e;if(t){for(const o of X){const s=t[o];if(s){const l=v(s,c);t[o]=l?b(D(c,l)):s}}for(const o of["rootDirs","typeRoots"]){const s=t[o];s&&(t[o]=s.map(l=>{const h=v(l,c);return h?b(D(c,h)):l}))}const{paths:n}=t;if(n)for(const o of Object.keys(n))n[o]=n[o].map(s=>v(s,c)??s);t.outDir&&(t.outDir=t.outDir.replace(m,""))}for(const n of B){const o=e[n];o&&(e[n]=o.map(s=>v(s,c)||(n==="files"&&A(s)?s:n==="include"&&A(s)?f(c,s):O(s))))}return e},"readTsConfig");export{m as configDirectoryPlaceholder,Y as implicitBaseUrlSymbol,lt as readTsConfig};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var k=Object.defineProperty;var v=(s,i)=>k(s,"name",{value:i,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@visulima/fs"),q=require("@visulima/fs/error"),n=require("@visulima/path"),O=require("@visulima/path/utils"),P=require("jsonc-parser"),j=require("node:fs"),E=require("node:module"),T=require("resolve-pkg-maps"),B=v(s=>s&&typeof s=="object"&&"default"in s?s.default:s,"_interopDefaultCompat"),R=B(E);var $=Object.defineProperty,C=v((s,i)=>$(s,"name",{value:i,configurable:!0}),"d");const z=C(s=>P.parse(p.readFileSync(s,{buffer:!1})),"readJsonc"),M=C(()=>{const{findPnpApi:s}=R;return s?.(process.cwd())},"getPnpApi"),w=C((s,i,f,t)=>{const l="resolveFromPackageJsonPath:"+s+":"+i+":"+(f?"yes":"no");if(t?.has(l))return t.get(l);const e=z(s);if(!e)return;let c=i||"tsconfig.json";if(!f&&e.exports)try{const[o]=T.resolveExports(e.exports,i,["require","types"]);c=o}catch{return!1}else!i&&e.tsconfig&&(c=e.tsconfig);return c=n.join(s,"..",c),t?.set(l,c),c},"resolveFromPackageJsonPath"),A="package.json",x="tsconfig.json",_=C((s,i,f)=>{let t=s;if(s===".."&&(t=n.join(t,x)),s.startsWith(".")&&(t=n.resolve(i,t)),n.isAbsolute(t)){if(p.isAccessibleSync(t)){if(j.statSync(t).isFile())return t}else if(!t.endsWith(".json")){const u=`${t}.json`;if(p.isAccessibleSync(u))return u}return}const[l,...e]=s.split("/"),c=l.startsWith("@")?l+"/"+e.shift():l,o=e.join("/"),r=M();if(r){const{resolveRequest:u}=r;try{if(c===s){const d=u(n.join(c,A),i);if(d){const b=w(d,o,!1,f);if(b&&p.isAccessibleSync(b))return b}}else{let d;try{d=u(s,i,{extensions:[".json"]})}catch{d=u(n.join(s,x),i)}if(d)return d}}catch{}}const a=p.findUpSync(u=>{const d=n.join(n.resolve(u),"node_modules",c);if(p.isAccessibleSync(d))return n.join("node_modules",c)},{cwd:i,type:"directory"});if(!a||!j.statSync(a).isDirectory())return;const y=n.join(a,A);if(p.isAccessibleSync(y)){const u=w(y,o,!1,f);if(u===!1)return;if(u&&p.isAccessibleSync(u)&&j.statSync(u).isFile())return u}const h=n.join(a,o),F=h.endsWith(".json");if(!F){const u=h+".json";if(p.isAccessibleSync(u))return u}if(p.isAccessibleSync(h)){if(j.statSync(h).isDirectory()){const u=n.join(h,A);if(p.isAccessibleSync(u)){const b=w(u,"",!0,f);if(b&&p.isAccessibleSync(b))return b}const d=n.join(h,x);if(p.isAccessibleSync(d))return d}else if(F)return h}},"resolveExtendsPath");var J=Object.defineProperty,S=v((s,i)=>J(s,"name",{value:i,configurable:!0}),"u");const N=S(s=>P.parse(p.readFileSync(s,{buffer:!1})),"readJsonc"),g=S(s=>{const i=n.toNamespacedPath(s);return O.isRelative(i)?i:`./${i}`},"normalizePath"),I=["files","include","exclude"],V=S((s,i,f,t)=>{const l=_(s,i);if(!l)throw new q.NotFoundError(`No such file or directory, for '${s}' found.`);if(f.has(l))throw new Error(`Circularity detected while resolving configuration: ${l}`);f.add(l);const e=n.dirname(l),c=W(l,t,f);delete c.references;const{compilerOptions:o}=c;if(o){const{baseUrl:r}=o;r&&!r.startsWith(m)&&(o.baseUrl=n.normalize(n.relative(i,n.join(e,r)))||"./");let{outDir:a}=o;a&&(a.startsWith(m)||(a=n.relative(i,n.join(e,a))),o.outDir=g(a.replace(m+"/",""))||"./")}for(const r of I){const a=c[r];a&&(c[r]=a.map(y=>y.startsWith(m)||n.isAbsolute(y)?y:n.relative(i,n.join(e,y))))}return c},"resolveExtends"),W=S((s,i,f=new Set)=>{let t;try{t=N(s)||{}}catch{throw new Error(`Cannot resolve tsconfig at path: ${s}`)}if(typeof t!="object")throw new SyntaxError(`Failed to parse tsconfig at: ${s}`);const l=n.dirname(s);if(t.compilerOptions){const{compilerOptions:e}=t;e.paths&&!e.baseUrl&&(e[U]=l)}if(t.extends){const e=Array.isArray(t.extends)?t.extends:[t.extends];delete t.extends;for(const c of e.reverse()){const o=V(c,l,new Set(f),i),r={...o,...t,compilerOptions:{...o.compilerOptions,...t.compilerOptions}};o.watchOptions&&(r.watchOptions={...o.watchOptions,...t.watchOptions}),t=r}}if(t.compilerOptions){const{compilerOptions:e}=t;for(const c of["baseUrl","rootDir"]){const o=e[c];if(o&&!o.startsWith(m)){const r=n.resolve(l,o);e[c]=g(n.relative(l,r))}}for(const c of["outDir","declarationDir"]){let o=e[c];if(o){Array.isArray(t.exclude)||(t.exclude=[]);let r=o;n.isAbsolute(r)||(r=n.join(l,r)),r=r.replace(m,""),t.exclude.includes(r)||t.exclude.push(r),o.startsWith(m)||(o=g(o)),e[c]=o}}i?.tscCompatible&&e.module==="node16"&&["5.4","5.5","5.6","true"].includes(String(i.tscCompatible))&&(e.allowSyntheticDefaultImports=e.allowSyntheticDefaultImports??!0,e.esModuleInterop=e.esModuleInterop??!0,e.moduleDetection=e.moduleDetection??"force",e.moduleResolution=e.moduleResolution??"node16",e.target=e.target??"es2022",e.useDefineForClassFields=e.useDefineForClassFields??!0),i?.tscCompatible&&e.strict&&(["5.6","true"].includes(String(i.tscCompatible))&&(e.strictBuiltinIteratorReturn=e.strictBuiltinIteratorReturn??!0),["5.4","5.5","5.6","true"].includes(String(i.tscCompatible))&&(e.noImplicitAny=e.noImplicitAny??!0,e.noImplicitThis=e.noImplicitThis??!0,e.strictNullChecks=e.strictNullChecks??!0,e.strictFunctionTypes=e.strictFunctionTypes??!0,e.strictBindCallApply=e.strictBindCallApply??!0,e.strictPropertyInitialization=e.strictPropertyInitialization??!0,e.alwaysStrict=e.alwaysStrict??!0,e.useUnknownInCatchVariables=e.useUnknownInCatchVariables??!0)),i?.tscCompatible&&e.isolatedModules&&(e.preserveConstEnums=e.preserveConstEnums??!0),i?.tscCompatible&&e.esModuleInterop&&(e.allowSyntheticDefaultImports=e.allowSyntheticDefaultImports??!0),i?.tscCompatible&&e.target==="esnext"&&(e.useDefineForClassFields=e.useDefineForClassFields??!0)}else t.compilerOptions={};if(t.include?(t.include=t.include.map(e=>n.normalize(e)),t.files&&delete t.files):t.files&&(t.files=t.files.map(e=>e.startsWith(m)?e:g(e))),t.watchOptions){const{watchOptions:e}=t;e.excludeDirectories&&(e.excludeDirectories=e.excludeDirectories.map(c=>n.resolve(l,c)))}return t},"internalParseTsConfig"),D=S((s,i)=>{if(s.startsWith(m))return n.normalize(n.join(i,s.slice(m.length)))},"interpolateConfigDirectory"),G=["outDir","declarationDir","outFile","rootDir","baseUrl","tsBuildInfoFile"],m="${configDir}",U=Symbol("implicitBaseUrl"),H=S((s,i)=>{const f=n.resolve(s),t=W(f,i),l=n.dirname(f),{compilerOptions:e}=t;if(e){for(const o of G){const r=e[o];if(r){const a=D(r,l);e[o]=a?g(n.relative(l,a)):r}}for(const o of["rootDirs","typeRoots"]){const r=e[o];r&&(e[o]=r.map(a=>{const y=D(a,l);return y?g(n.relative(l,y)):a}))}const{paths:c}=e;if(c)for(const o of Object.keys(c))c[o]=c[o].map(r=>D(r,l)??r);e.outDir&&(e.outDir=e.outDir.replace(m,""))}for(const c of I){const o=t[c];o&&(t[c]=o.map(r=>D(r,l)||(c==="files"&&O.isRelative(r)?r:c==="include"&&O.isRelative(r)?n.join(l,r):n.normalize(r))))}return t},"readTsConfig");exports.configDirectoryPlaceholder=m;exports.implicitBaseUrlSymbol=U;exports.readTsConfig=H;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var s=(n,t)=>f(n,"name",{value:t,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@visulima/fs"),c=require("@visulima/fs/utils"),a=require("@visulima/path");var g=Object.defineProperty,w=s((n,t)=>g(n,"name",{value:t,configurable:!0}),"r");const u=w(async(n,t={})=>{const{cwd:e,...i}=t,o=c.toPath(e??process.cwd());await r.writeJson(a.join(o,"tsconfig.json"),n,i)},"writeTsConfig"),y=w((n,t={})=>{const{cwd:e,...i}=t,o=c.toPath(e??process.cwd());r.writeJsonSync(a.join(o,"tsconfig.json"),n,i)},"writeTsConfigSync");exports.writeTsConfig=u;exports.writeTsConfigSync=y;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var w=Object.defineProperty;var t=(o,n)=>w(o,"name",{value:n,configurable:!0});import{writeJson as a,writeJsonSync as p}from"@visulima/fs";import{toPath as c}from"@visulima/fs/utils";import{join as e}from"@visulima/path";var g=Object.defineProperty,f=t((o,n)=>g(o,"name",{value:n,configurable:!0}),"r");const C=f(async(o,n={})=>{const{cwd:i,...r}=n,s=c(i??process.cwd());await a(e(s,"tsconfig.json"),o,r)},"writeTsConfig"),T=f((o,n={})=>{const{cwd:i,...r}=n,s=c(i??process.cwd());p(e(s,"tsconfig.json"),o,r)},"writeTsConfigSync");export{C as writeTsConfig,T as writeTsConfigSync};
|