@visulima/package 1.7.5 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/chunk-5VO6NTKJ.js +361 -0
  3. package/dist/chunk-5VO6NTKJ.js.map +1 -0
  4. package/dist/chunk-7IOK6YPW.cjs +52 -0
  5. package/dist/chunk-7IOK6YPW.cjs.map +1 -0
  6. package/dist/chunk-CVVFWSMT.cjs +65 -0
  7. package/dist/chunk-CVVFWSMT.cjs.map +1 -0
  8. package/dist/chunk-E2PKJX3Q.js +54 -0
  9. package/dist/chunk-E2PKJX3Q.js.map +1 -0
  10. package/dist/chunk-EYMR7Z2I.js +62 -0
  11. package/dist/chunk-EYMR7Z2I.js.map +1 -0
  12. package/dist/chunk-G3SI24AJ.cjs +88 -0
  13. package/dist/{chunk-6KT7465D.cjs.map → chunk-G3SI24AJ.cjs.map} +1 -1
  14. package/dist/chunk-IIYQBLPC.js +119 -0
  15. package/dist/chunk-IIYQBLPC.js.map +1 -0
  16. package/dist/chunk-IK5YSYLX.cjs +126 -0
  17. package/dist/chunk-IK5YSYLX.cjs.map +1 -0
  18. package/dist/chunk-UZ2FN6C5.js +78 -0
  19. package/dist/{chunk-U4YVB3GU.js.map → chunk-UZ2FN6C5.js.map} +1 -1
  20. package/dist/chunk-WXFZK4G3.cjs +374 -0
  21. package/dist/chunk-WXFZK4G3.cjs.map +1 -0
  22. package/dist/chunk-YLCN7EVV.js +50 -0
  23. package/dist/chunk-YLCN7EVV.js.map +1 -0
  24. package/dist/chunk-YOQXHFU3.cjs +56 -0
  25. package/dist/chunk-YOQXHFU3.cjs.map +1 -0
  26. package/dist/error.cjs +5 -5
  27. package/dist/error.js +3 -3
  28. package/dist/index.cjs +102 -53
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.js +58 -9
  31. package/dist/index.js.map +1 -1
  32. package/dist/monorepo.cjs +5 -5
  33. package/dist/monorepo.js +3 -3
  34. package/dist/package-json.cjs +11 -11
  35. package/dist/package-json.js +1 -1
  36. package/dist/package-manager.cjs +14 -14
  37. package/dist/package-manager.js +2 -2
  38. package/dist/package.cjs +7 -7
  39. package/dist/package.js +3 -3
  40. package/dist/tsconfig.cjs +15 -15
  41. package/dist/tsconfig.js +1 -1
  42. package/package.json +8 -8
  43. package/dist/chunk-3I7BDTA7.cjs +0 -28
  44. package/dist/chunk-3I7BDTA7.cjs.map +0 -1
  45. package/dist/chunk-44SW4DFI.js +0 -12
  46. package/dist/chunk-44SW4DFI.js.map +0 -1
  47. package/dist/chunk-5YG33J5B.cjs +0 -13
  48. package/dist/chunk-5YG33J5B.cjs.map +0 -1
  49. package/dist/chunk-6KT7465D.cjs +0 -22
  50. package/dist/chunk-DNYCFU7L.cjs +0 -9
  51. package/dist/chunk-DNYCFU7L.cjs.map +0 -1
  52. package/dist/chunk-GMIFPTPB.js +0 -11
  53. package/dist/chunk-GMIFPTPB.js.map +0 -1
  54. package/dist/chunk-I3QTPGJY.js +0 -10
  55. package/dist/chunk-I3QTPGJY.js.map +0 -1
  56. package/dist/chunk-KSXRMTAQ.cjs +0 -19
  57. package/dist/chunk-KSXRMTAQ.cjs.map +0 -1
  58. package/dist/chunk-U4YVB3GU.js +0 -12
  59. package/dist/chunk-WOLHGXXJ.cjs +0 -13
  60. package/dist/chunk-WOLHGXXJ.cjs.map +0 -1
  61. package/dist/chunk-YUFKVE42.js +0 -15
  62. package/dist/chunk-YUFKVE42.js.map +0 -1
  63. package/dist/chunk-ZDLZRGSC.js +0 -7
  64. package/dist/chunk-ZDLZRGSC.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## @visulima/package [1.8.1](https://github.com/visulima/visulima/compare/@visulima/package@1.8.0...@visulima/package@1.8.1) (2024-05-15)
2
+
3
+
4
+ ### Reverts
5
+
6
+ * **package:** revert wrong bump of version ([e41910f](https://github.com/visulima/visulima/commit/e41910fe96c22851649a6a8c1f30c0cfc70ba35c))
7
+
8
+
9
+
10
+ ### Dependencies
11
+
12
+ * **@visulima/fs:** upgraded to 2.1.1
13
+
14
+ ## @visulima/package [1.7.6](https://github.com/visulima/visulima/compare/@visulima/package@1.7.5...@visulima/package@1.7.6) (2024-05-07)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **package:** symlinks shouldn't be resolved to a real path ([#394](https://github.com/visulima/visulima/issues/394)) ([c504321](https://github.com/visulima/visulima/commit/c504321a05de761eda2c310eaf2e9b272fa0832e))
20
+
1
21
  ## @visulima/package [1.7.5](https://github.com/visulima/visulima/compare/@visulima/package@1.7.4...@visulima/package@1.7.5) (2024-05-06)
2
22
 
3
23
 
@@ -0,0 +1,361 @@
1
+ import { findUp, findUpSync, writeJson, readFileSync } from '@visulima/fs';
2
+ import { NotFoundError } from '@visulima/fs/error';
3
+ import { toPath } from '@visulima/fs/utils';
4
+ import { join, dirname, resolve, relative, normalize, toNamespacedPath } from 'pathe';
5
+ import { parse } from 'jsonc-parser';
6
+ import { existsSync, statSync } from 'node:fs';
7
+ import Module from 'node:module';
8
+ import { join as join$1, resolve as resolve$1, isAbsolute } from 'node:path';
9
+ import { resolveExports } from 'resolve-pkg-maps';
10
+
11
+ // src/tsconfig.ts
12
+ var readJsonc = (jsonPath) => parse(readFileSync(jsonPath));
13
+ var getPnpApi = () => {
14
+ const { findPnpApi } = Module;
15
+ return findPnpApi?.(process.cwd());
16
+ };
17
+ var resolveFromPackageJsonPath = (packageJsonPath, subpath, ignoreExports, cache) => {
18
+ const cacheKey = `resolveFromPackageJsonPath:${packageJsonPath}:${subpath}:${ignoreExports}`;
19
+ if (cache?.has(cacheKey)) {
20
+ return cache.get(cacheKey);
21
+ }
22
+ const packageJson = readJsonc(packageJsonPath);
23
+ if (!packageJson) {
24
+ return void 0;
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$1(packageJsonPath, "..", resolvedPath);
38
+ cache?.set(cacheKey, resolvedPath);
39
+ return resolvedPath;
40
+ };
41
+ var PACKAGE_JSON = "package.json";
42
+ var TS_CONFIG_JSON = "tsconfig.json";
43
+ var resolveExtendsPath = (requestedPath, directoryPath, cache) => {
44
+ let filePath = requestedPath;
45
+ if (requestedPath === "..") {
46
+ filePath = join$1(filePath, TS_CONFIG_JSON);
47
+ }
48
+ if (requestedPath.startsWith(".")) {
49
+ filePath = resolve$1(directoryPath, filePath);
50
+ }
51
+ if (isAbsolute(filePath)) {
52
+ if (existsSync(filePath)) {
53
+ if (statSync(filePath).isFile()) {
54
+ return filePath;
55
+ }
56
+ } else if (!filePath.endsWith(".json")) {
57
+ const jsonPath = `${filePath}.json`;
58
+ if (existsSync(jsonPath)) {
59
+ return jsonPath;
60
+ }
61
+ }
62
+ return void 0;
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$1(packageName, PACKAGE_JSON), directoryPath);
73
+ if (packageJsonPath2) {
74
+ const resolvedPath = resolveFromPackageJsonPath(packageJsonPath2, subpath, false, cache);
75
+ if (resolvedPath && existsSync(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$1(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$1(directory, "node_modules", packageName);
96
+ if (existsSync(path)) {
97
+ return join$1("node_modules", packageName);
98
+ }
99
+ return void 0;
100
+ },
101
+ {
102
+ cwd: directoryPath,
103
+ type: "directory"
104
+ }
105
+ );
106
+ if (!packagePath || !statSync(packagePath).isDirectory()) {
107
+ return void 0;
108
+ }
109
+ const packageJsonPath = join$1(packagePath, PACKAGE_JSON);
110
+ if (existsSync(packageJsonPath)) {
111
+ const resolvedPath = resolveFromPackageJsonPath(packageJsonPath, subpath, false, cache);
112
+ if (resolvedPath === false) {
113
+ return void 0;
114
+ }
115
+ if (resolvedPath && existsSync(resolvedPath) && statSync(resolvedPath).isFile()) {
116
+ return resolvedPath;
117
+ }
118
+ }
119
+ const fullPackagePath = join$1(packagePath, subpath);
120
+ const jsonExtension = fullPackagePath.endsWith(".json");
121
+ if (!jsonExtension) {
122
+ const fullPackagePathWithJson = `${fullPackagePath}.json`;
123
+ if (existsSync(fullPackagePathWithJson)) {
124
+ return fullPackagePathWithJson;
125
+ }
126
+ }
127
+ if (!existsSync(fullPackagePath)) {
128
+ return void 0;
129
+ }
130
+ if (statSync(fullPackagePath).isDirectory()) {
131
+ const fullPackageJsonPath = join$1(fullPackagePath, PACKAGE_JSON);
132
+ if (existsSync(fullPackageJsonPath)) {
133
+ const resolvedPath = resolveFromPackageJsonPath(fullPackageJsonPath, "", true, cache);
134
+ if (resolvedPath && existsSync(resolvedPath)) {
135
+ return resolvedPath;
136
+ }
137
+ }
138
+ const tsconfigPath = join$1(fullPackagePath, TS_CONFIG_JSON);
139
+ if (existsSync(tsconfigPath)) {
140
+ return tsconfigPath;
141
+ }
142
+ } else if (jsonExtension) {
143
+ return fullPackagePath;
144
+ }
145
+ return void 0;
146
+ };
147
+ var resolve_extends_path_default = resolveExtendsPath;
148
+
149
+ // src/read-tsconfig.ts
150
+ var readJsonc2 = (jsonPath) => parse(readFileSync(jsonPath));
151
+ var normalizePath = (path) => toNamespacedPath(/^\.{1,2}(?:\/.*)?$/.test(path) ? path : `./${path}`);
152
+ var resolveExtends = (extendsPath, fromDirectoryPath, circularExtendsTracker, options) => {
153
+ const resolvedExtendsPath = resolve_extends_path_default(extendsPath, fromDirectoryPath);
154
+ if (!resolvedExtendsPath) {
155
+ throw new NotFoundError(`No such file or directory, for '${extendsPath}' found.`);
156
+ }
157
+ if (circularExtendsTracker.has(resolvedExtendsPath)) {
158
+ throw new Error(`Circularity detected while resolving configuration: ${resolvedExtendsPath}`);
159
+ }
160
+ circularExtendsTracker.add(resolvedExtendsPath);
161
+ const extendsDirectoryPath = dirname(resolvedExtendsPath);
162
+ const extendsConfig = internalParseTsConfig(resolvedExtendsPath, options, circularExtendsTracker);
163
+ delete extendsConfig.references;
164
+ const { compilerOptions } = extendsConfig;
165
+ if (compilerOptions) {
166
+ const resolvePaths = ["baseUrl", "outDir"];
167
+ for (const property of resolvePaths) {
168
+ const unresolvedPath = compilerOptions[property];
169
+ if (unresolvedPath) {
170
+ compilerOptions[property] = relative(fromDirectoryPath, join(extendsDirectoryPath, unresolvedPath)).replaceAll("\\", "/") || "./";
171
+ }
172
+ }
173
+ }
174
+ if (extendsConfig.files) {
175
+ extendsConfig.files = extendsConfig.files.map((file) => relative(fromDirectoryPath, join(extendsDirectoryPath, file)));
176
+ }
177
+ if (extendsConfig.include) {
178
+ extendsConfig.include = extendsConfig.include.map((file) => relative(fromDirectoryPath, join(extendsDirectoryPath, file)));
179
+ }
180
+ if (extendsConfig.exclude) {
181
+ extendsConfig.exclude = extendsConfig.exclude.map((file) => relative(fromDirectoryPath, join(extendsDirectoryPath, file)));
182
+ }
183
+ return extendsConfig;
184
+ };
185
+ var internalParseTsConfig = (tsconfigPath, options, circularExtendsTracker = /* @__PURE__ */ new Set()) => {
186
+ let config;
187
+ try {
188
+ config = readJsonc2(tsconfigPath) || {};
189
+ } catch {
190
+ throw new Error(`Cannot resolve tsconfig at path: ${tsconfigPath}`);
191
+ }
192
+ if (typeof config !== "object") {
193
+ throw new SyntaxError(`Failed to parse tsconfig at: ${tsconfigPath}`);
194
+ }
195
+ const directoryPath = dirname(tsconfigPath);
196
+ if (config.compilerOptions) {
197
+ const { compilerOptions } = config;
198
+ if (compilerOptions.paths && !compilerOptions.baseUrl) {
199
+ compilerOptions[implicitBaseUrlSymbol] = directoryPath;
200
+ }
201
+ }
202
+ if (config.extends) {
203
+ const extendsPathList = Array.isArray(config.extends) ? config.extends : [config.extends];
204
+ delete config.extends;
205
+ for (const extendsPath of extendsPathList.reverse()) {
206
+ const extendsConfig = resolveExtends(extendsPath, directoryPath, new Set(circularExtendsTracker), options);
207
+ const merged = {
208
+ ...extendsConfig,
209
+ ...config,
210
+ compilerOptions: {
211
+ ...extendsConfig.compilerOptions,
212
+ ...config.compilerOptions
213
+ }
214
+ };
215
+ if (extendsConfig.watchOptions) {
216
+ merged.watchOptions = {
217
+ ...extendsConfig.watchOptions,
218
+ ...config.watchOptions
219
+ };
220
+ }
221
+ config = merged;
222
+ }
223
+ }
224
+ if (config.compilerOptions) {
225
+ const { compilerOptions } = config;
226
+ const normalizedPaths = ["baseUrl", "rootDir"];
227
+ for (const property of normalizedPaths) {
228
+ const unresolvedPath = compilerOptions[property];
229
+ if (unresolvedPath) {
230
+ const resolvedBaseUrl = resolve(directoryPath, unresolvedPath);
231
+ const relativeBaseUrl = relative(directoryPath, resolvedBaseUrl);
232
+ compilerOptions[property] = normalizePath(relativeBaseUrl);
233
+ }
234
+ }
235
+ const { outDir } = compilerOptions;
236
+ if (outDir) {
237
+ if (!Array.isArray(config.exclude)) {
238
+ config.exclude = [];
239
+ }
240
+ if (!config.exclude.includes(outDir)) {
241
+ config.exclude.push(outDir);
242
+ }
243
+ compilerOptions.outDir = normalizePath(outDir);
244
+ }
245
+ if (options?.tscCompatible && compilerOptions.module === "node16") {
246
+ compilerOptions.allowSyntheticDefaultImports = compilerOptions.allowSyntheticDefaultImports ?? true;
247
+ compilerOptions.esModuleInterop = compilerOptions.esModuleInterop ?? true;
248
+ compilerOptions.moduleDetection = compilerOptions.moduleDetection ?? "force";
249
+ compilerOptions.moduleResolution = compilerOptions.moduleResolution ?? "node16";
250
+ compilerOptions.target = compilerOptions.target ?? "es2022";
251
+ compilerOptions.useDefineForClassFields = compilerOptions.useDefineForClassFields ?? true;
252
+ }
253
+ if (options?.tscCompatible && compilerOptions.strict) {
254
+ compilerOptions.noImplicitAny = compilerOptions.noImplicitAny ?? true;
255
+ compilerOptions.noImplicitThis = compilerOptions.noImplicitThis ?? true;
256
+ compilerOptions.strictNullChecks = compilerOptions.strictNullChecks ?? true;
257
+ compilerOptions.strictFunctionTypes = compilerOptions.strictFunctionTypes ?? true;
258
+ compilerOptions.strictBindCallApply = compilerOptions.strictBindCallApply ?? true;
259
+ compilerOptions.strictPropertyInitialization = compilerOptions.strictPropertyInitialization ?? true;
260
+ compilerOptions.alwaysStrict = compilerOptions.alwaysStrict ?? true;
261
+ compilerOptions.useUnknownInCatchVariables = compilerOptions.useUnknownInCatchVariables ?? true;
262
+ }
263
+ if (options?.tscCompatible && compilerOptions.isolatedModules) {
264
+ compilerOptions.preserveConstEnums = compilerOptions.preserveConstEnums ?? true;
265
+ }
266
+ if (options?.tscCompatible && compilerOptions.esModuleInterop) {
267
+ compilerOptions.allowSyntheticDefaultImports = compilerOptions.allowSyntheticDefaultImports ?? true;
268
+ }
269
+ if (options?.tscCompatible && compilerOptions.target === "esnext") {
270
+ compilerOptions.useDefineForClassFields = compilerOptions.useDefineForClassFields ?? true;
271
+ }
272
+ } else {
273
+ config.compilerOptions = {};
274
+ }
275
+ if (config.files) {
276
+ config.files = config.files.map((element) => normalizePath(element));
277
+ }
278
+ if (config.include) {
279
+ config.include = config.include.map((element) => normalize(element));
280
+ }
281
+ if (config.watchOptions) {
282
+ const { watchOptions } = config;
283
+ if (watchOptions.excludeDirectories) {
284
+ watchOptions.excludeDirectories = watchOptions.excludeDirectories.map((excludePath) => resolve(directoryPath, excludePath));
285
+ }
286
+ }
287
+ return config;
288
+ };
289
+ var implicitBaseUrlSymbol = Symbol("implicitBaseUrl");
290
+ var readTsConfig = (tsconfigPath, options) => internalParseTsConfig(tsconfigPath, options);
291
+
292
+ // src/tsconfig.ts
293
+ var TsConfigFileCache = /* @__PURE__ */ new Map();
294
+ var findTsConfig = async (cwd, options = {}) => {
295
+ const configFileName = options.configFileName ?? "tsconfig.json";
296
+ let filePath = await findUp(configFileName, {
297
+ ...cwd && { cwd },
298
+ type: "file"
299
+ });
300
+ if (!filePath) {
301
+ filePath = await findUp("jsconfig.json", {
302
+ ...cwd && { cwd },
303
+ type: "file"
304
+ });
305
+ }
306
+ if (!filePath) {
307
+ throw new NotFoundError(`No such file or directory, for ${configFileName} or jsconfig.json found.`);
308
+ }
309
+ const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : TsConfigFileCache;
310
+ if (options.cache && cache.has(filePath)) {
311
+ return cache.get(filePath);
312
+ }
313
+ const output = {
314
+ config: readTsConfig(filePath),
315
+ path: filePath
316
+ };
317
+ if (options.cache) {
318
+ cache.set(filePath, output);
319
+ }
320
+ return output;
321
+ };
322
+ var findTSConfig = findTsConfig;
323
+ var findTsConfigSync = (cwd, options = {}) => {
324
+ const configFileName = options.configFileName ?? "tsconfig.json";
325
+ let filePath = findUpSync(configFileName, {
326
+ ...cwd && { cwd },
327
+ type: "file"
328
+ });
329
+ if (!filePath) {
330
+ filePath = findUpSync("jsconfig.json", {
331
+ ...cwd && { cwd },
332
+ type: "file"
333
+ });
334
+ }
335
+ if (!filePath) {
336
+ throw new NotFoundError(`No such file or directory, for ${configFileName} or jsconfig.json found.`);
337
+ }
338
+ const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : TsConfigFileCache;
339
+ if (options.cache && cache.has(filePath)) {
340
+ return cache.get(filePath);
341
+ }
342
+ const output = {
343
+ config: readTsConfig(filePath),
344
+ path: filePath
345
+ };
346
+ if (options.cache) {
347
+ cache.set(filePath, output);
348
+ }
349
+ return output;
350
+ };
351
+ var findTSConfigSync = findTsConfigSync;
352
+ var writeTsConfig = async (data, options = {}) => {
353
+ const { cwd, ...writeOptions } = options;
354
+ const directory = toPath(options.cwd ?? process.cwd());
355
+ await writeJson(join(directory, "tsconfig.json"), data, writeOptions);
356
+ };
357
+ var writeTSConfig = writeTsConfig;
358
+
359
+ export { findTSConfig, findTSConfigSync, findTsConfig, findTsConfigSync, implicitBaseUrlSymbol, readTsConfig, writeTSConfig, writeTsConfig };
360
+ //# sourceMappingURL=out.js.map
361
+ //# sourceMappingURL=chunk-5VO6NTKJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tsconfig.ts","../src/read-tsconfig.ts","../src/utils/resolve-extends-path.ts"],"names":["findUpSync","NotFoundError","join","readFileSync","parse","resolve","packageJsonPath","readJsonc"],"mappings":";AACA,SAAS,QAAQ,cAAAA,aAAY,iBAAiB;AAC9C,SAAS,iBAAAC,sBAAqB;AAC9B,SAAS,cAAc;AACvB,SAAS,QAAAC,aAAY;;;ACErB,SAAS,gBAAAC,qBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,SAAAC,cAAa;AACtB,SAAS,SAAS,QAAAF,OAAM,WAAW,UAAU,WAAAG,UAAS,wBAAwB;;;ACH9E,SAAS,YAAY,gBAAgB;AACrC,OAAO,YAAY;AACnB,SAAS,YAAY,MAAM,eAAe;AAE1C,SAAS,YAAY,oBAAoB;AACzC,SAAS,aAAa;AAEtB,SAAS,sBAAsB;AAK/B,IAAM,YAAY,CAAC,aAAqB,MAAM,aAAa,QAAQ,CAAW;AAE9E,IAAM,YAAY,MAAM;AACpB,QAAM,EAAE,WAAW,IAAI;AAGvB,SAAO,aAAa,QAAQ,IAAI,CAAC;AACrC;AAEA,IAAM,6BAA6B,CAAC,iBAAyB,SAAiB,eAAyB,UA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AiB,QAAQ,kBAAkB;AAEjD,MAAI,WAAWD,YAAW,gBAAgB;AAAA,IACtC,GAAI,OAAO,EAAE,IAAI;AAAA,IACjB,MAAM;AAAA,EACV,CAAC;AAED,MAAI,CAAC,UAAU;AACX,eAAWA,YAAW,iBAAiB;AAAA,MACnC,GAAI,OAAO,EAAE,IAAI;AAAA,MACjB,MAAM;AAAA,IACV,CAAC;AAAA,EACL;AAEA,MAAI,CAAC,UAAU;AACX,UAAM,IAAIC,eAAc,kCAAkC,cAAc,0BAA0B;AAAA,EACtG;AAEA,QAAM,QAAQ,QAAQ,SAAS,OAAO,QAAQ,UAAU,YAAY,QAAQ,QAAQ;AAEpF,MAAI,QAAQ,SAAS,MAAM,IAAI,QAAQ,GAAG;AACtC,WAAO,MAAM,IAAI,QAAQ;AAAA,EAC7B;AAEA,QAAM,SAAS;AAAA,IACX,QAAQ,aAAa,QAAQ;AAAA,IAC7B,MAAM;AAAA,EACV;AAEA,MAAI,QAAQ,OAAO;AACf,UAAM,IAAI,UAAU,MAAM;AAAA,EAC9B;AAEA,SAAO;AACX;AAGO,IAAM,mBAAmB;AAWzB,IAAM,gBAAgB,OAAO,MAAoB,UAAqD,CAAC,MAAqB;AAC/H,QAAM,EAAE,KAAK,GAAG,aAAa,IAAI;AAEjC,QAAM,YAAY,OAAO,QAAQ,OAAO,QAAQ,IAAI,CAAC;AAErD,QAAM,UAAUC,MAAK,WAAW,eAAe,GAAG,MAAM,YAAY;AACxE;AAGO,IAAM,gBAAgB","sourcesContent":["import type { WriteJsonOptions } from \"@visulima/fs\";\nimport { findUp, findUpSync, writeJson } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { toPath } from \"@visulima/fs/utils\";\nimport { join } from \"pathe\";\nimport type { TsConfigJson } from \"type-fest\";\n\nimport { readTsConfig } from \"./read-tsconfig\";\nimport type { TsConfigJsonResolved } from \"./types\";\n\ntype Options = {\n cache?: Map<string, TsConfigJsonResolved> | boolean;\n configFileName?: string;\n};\n\nconst TsConfigFileCache = new Map<string, TsConfigResult>();\n\nexport type TsConfigResult = {\n config: TsConfigJsonResolved;\n path: string;\n};\n\n/**\n * An asynchronous function that retrieves the TSConfig by searching for the \"tsconfig.json\" first,\n * second attempt is to look for the \"jsconfig.json\" file from a given current working directory.\n *\n * @param cwd - Optional. The current working directory from which to search for the \"tsconfig.json\" file.\n * The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the TSConfig result object.\n * The return type of the function is `Promise<TsConfigResult>`.\n * @throws An `Error` when the \"tsconfig.json\" file is not found.\n */\nexport const findTsConfig = async (cwd?: URL | string, options: Options = {}): Promise<TsConfigResult> => {\n const configFileName = options.configFileName ?? \"tsconfig.json\";\n\n let filePath = await findUp(configFileName, {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n filePath = await findUp(\"jsconfig.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n }\n\n if (!filePath) {\n throw new NotFoundError(`No such file or directory, for ${configFileName} or jsconfig.json found.`);\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : TsConfigFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as TsConfigResult;\n }\n\n const output = {\n config: readTsConfig(filePath),\n path: filePath,\n };\n\n if (options.cache) {\n cache.set(filePath, output);\n }\n\n return output;\n};\n\n// @deprecate Please use `findTsConfig` instead.\nexport const findTSConfig = findTsConfig;\n\nexport const findTsConfigSync = (cwd?: URL | string, options: Options = {}): TsConfigResult => {\n const configFileName = options.configFileName ?? \"tsconfig.json\";\n\n let filePath = findUpSync(configFileName, {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n filePath = findUpSync(\"jsconfig.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n }\n\n if (!filePath) {\n throw new NotFoundError(`No such file or directory, for ${configFileName} or jsconfig.json found.`);\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : TsConfigFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as TsConfigResult;\n }\n\n const output = {\n config: readTsConfig(filePath),\n path: filePath,\n };\n\n if (options.cache) {\n cache.set(filePath, output);\n }\n\n return output;\n};\n\n// @deprecate Please use `findTsConfigSync` instead.\nexport const findTSConfigSync = findTsConfigSync;\n\n/**\n * An asynchronous function that writes the provided TypeScript configuration object to a tsconfig.json file.\n *\n * @param tsConfig - The TypeScript configuration object to write. The type of `tsConfig` is `TsConfigJson`.\n * @param options - Optional. The write options and the current working directory. The type of `options` is an\n * intersection type of `WriteOptions` and a Record type with an optional `cwd` key of type `string`.\n * @returns A `Promise` that resolves when the tsconfig.json file has been written.\n * The return type of function is `Promise<void>`.\n */\nexport const writeTsConfig = async (data: TsConfigJson, options: WriteJsonOptions & { cwd?: URL | string } = {}): Promise<void> => {\n const { cwd, ...writeOptions } = options;\n\n const directory = toPath(options.cwd ?? process.cwd());\n\n await writeJson(join(directory, \"tsconfig.json\"), data, writeOptions);\n};\n\n// @deprecate Please use `writeTsconfig` instead.\nexport const writeTSConfig = writeTsConfig;\n// eslint-disable-next-line import/no-unused-modules\nexport { implicitBaseUrlSymbol } from \"./read-tsconfig\";\n","/**\n * A modified version of `readTsconfig` from `https://github.com/privatenumber/get-tsconfig/blob/develop/src/parse-tsconfig/index.ts`\n *\n * MIT License\n * Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>\n */\nimport { readFileSync } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { parse } from \"jsonc-parser\";\nimport { dirname, join, normalize, relative, resolve, toNamespacedPath } from \"pathe\";\nimport type { TsConfigJson } from \"type-fest\";\n\nimport type { TsConfigJsonResolved } from \"./types\";\nimport resolveExtendsPath from \"./utils/resolve-extends-path\";\n\ntype Options = {\n tscCompatible?: boolean;\n};\n\nconst readJsonc = (jsonPath: string) => parse(readFileSync(jsonPath) as string) as unknown;\n// eslint-disable-next-line security/detect-unsafe-regex\nconst normalizePath = (path: string): string => toNamespacedPath(/^\\.{1,2}(?:\\/.*)?$/.test(path) ? path : `./${path}`);\n\nconst resolveExtends = (extendsPath: string, fromDirectoryPath: string, circularExtendsTracker: Set<string>, options?: Options) => {\n const resolvedExtendsPath = resolveExtendsPath(extendsPath, fromDirectoryPath);\n\n if (!resolvedExtendsPath) {\n throw new NotFoundError(`No such file or directory, for '${extendsPath}' found.`);\n }\n\n if (circularExtendsTracker.has(resolvedExtendsPath)) {\n throw new Error(`Circularity detected while resolving configuration: ${resolvedExtendsPath}`);\n }\n\n circularExtendsTracker.add(resolvedExtendsPath);\n\n const extendsDirectoryPath = dirname(resolvedExtendsPath);\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n const extendsConfig = internalParseTsConfig(resolvedExtendsPath, options, circularExtendsTracker);\n\n delete extendsConfig.references;\n\n const { compilerOptions } = extendsConfig;\n\n if (compilerOptions) {\n const resolvePaths = [\"baseUrl\", \"outDir\"] as const;\n\n // eslint-disable-next-line no-loops/no-loops,no-restricted-syntax\n for (const property of resolvePaths) {\n // eslint-disable-next-line security/detect-object-injection\n const unresolvedPath = compilerOptions[property];\n\n if (unresolvedPath) {\n // eslint-disable-next-line security/detect-object-injection\n compilerOptions[property] = relative(fromDirectoryPath, join(extendsDirectoryPath, unresolvedPath)).replaceAll(\"\\\\\", \"/\") || \"./\";\n }\n }\n }\n\n if (extendsConfig.files) {\n extendsConfig.files = extendsConfig.files.map((file) => relative(fromDirectoryPath, join(extendsDirectoryPath, file)));\n }\n\n if (extendsConfig.include) {\n extendsConfig.include = extendsConfig.include.map((file) => relative(fromDirectoryPath, join(extendsDirectoryPath, file)));\n }\n\n if (extendsConfig.exclude) {\n extendsConfig.exclude = extendsConfig.exclude.map((file) => relative(fromDirectoryPath, join(extendsDirectoryPath, file)));\n }\n\n return extendsConfig;\n};\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst internalParseTsConfig = (tsconfigPath: string, options?: Options, circularExtendsTracker = new Set<string>()): TsConfigJsonResolved => {\n /**\n * Decided not to cache the TsConfigJsonResolved object because it's\n * mutable.\n *\n * Note how `resolveExtends` can call `readTsconfig` rescursively\n * and actually mutates the object. It can also be mutated in\n * user-land.\n *\n * By only caching fs results, we can avoid serving mutated objects\n */\n let config: TsConfigJson;\n\n try {\n config = readJsonc(tsconfigPath) || {};\n } catch {\n throw new Error(`Cannot resolve tsconfig at path: ${tsconfigPath}`);\n }\n\n if (typeof config !== \"object\") {\n throw new SyntaxError(`Failed to parse tsconfig at: ${tsconfigPath}`);\n }\n\n const directoryPath = dirname(tsconfigPath);\n\n if (config.compilerOptions) {\n const { compilerOptions } = config;\n if (compilerOptions.paths && !compilerOptions.baseUrl) {\n type WithImplicitBaseUrl = TsConfigJson.CompilerOptions & {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n [implicitBaseUrlSymbol]: string;\n };\n // eslint-disable-next-line security/detect-object-injection,@typescript-eslint/no-use-before-define\n (compilerOptions as WithImplicitBaseUrl)[implicitBaseUrlSymbol] = directoryPath;\n }\n }\n\n if (config.extends) {\n const extendsPathList = Array.isArray(config.extends) ? config.extends : [config.extends];\n\n delete config.extends;\n\n // eslint-disable-next-line no-loops/no-loops,no-restricted-syntax,etc/no-assign-mutated-array\n for (const extendsPath of extendsPathList.reverse()) {\n const extendsConfig = resolveExtends(extendsPath, directoryPath, new Set(circularExtendsTracker), options);\n const merged = {\n ...extendsConfig,\n ...config,\n\n compilerOptions: {\n ...extendsConfig.compilerOptions,\n ...config.compilerOptions,\n },\n };\n\n if (extendsConfig.watchOptions) {\n merged.watchOptions = {\n ...extendsConfig.watchOptions,\n ...config.watchOptions,\n };\n }\n\n config = merged;\n }\n }\n\n if (config.compilerOptions) {\n const { compilerOptions } = config;\n const normalizedPaths = [\"baseUrl\", \"rootDir\"] as const;\n\n // eslint-disable-next-line no-loops/no-loops,no-restricted-syntax\n for (const property of normalizedPaths) {\n // eslint-disable-next-line security/detect-object-injection\n const unresolvedPath = compilerOptions[property];\n\n if (unresolvedPath) {\n const resolvedBaseUrl = resolve(directoryPath, unresolvedPath);\n const relativeBaseUrl = relative(directoryPath, resolvedBaseUrl);\n\n // eslint-disable-next-line security/detect-object-injection\n compilerOptions[property] = normalizePath(relativeBaseUrl);\n }\n }\n\n const { outDir } = compilerOptions;\n\n if (outDir) {\n if (!Array.isArray(config.exclude)) {\n config.exclude = [];\n }\n\n if (!config.exclude.includes(outDir)) {\n config.exclude.push(outDir);\n }\n\n compilerOptions.outDir = normalizePath(outDir);\n }\n\n if (options?.tscCompatible && compilerOptions.module === \"node16\") {\n compilerOptions.allowSyntheticDefaultImports = compilerOptions.allowSyntheticDefaultImports ?? true;\n compilerOptions.esModuleInterop = compilerOptions.esModuleInterop ?? true;\n compilerOptions.moduleDetection = compilerOptions.moduleDetection ?? \"force\";\n compilerOptions.moduleResolution = compilerOptions.moduleResolution ?? \"node16\";\n compilerOptions.target = compilerOptions.target ?? \"es2022\";\n compilerOptions.useDefineForClassFields = compilerOptions.useDefineForClassFields ?? true;\n }\n\n if (options?.tscCompatible && compilerOptions.strict) {\n compilerOptions.noImplicitAny = compilerOptions.noImplicitAny ?? true;\n compilerOptions.noImplicitThis = compilerOptions.noImplicitThis ?? true;\n compilerOptions.strictNullChecks = compilerOptions.strictNullChecks ?? true;\n compilerOptions.strictFunctionTypes = compilerOptions.strictFunctionTypes ?? true;\n compilerOptions.strictBindCallApply = compilerOptions.strictBindCallApply ?? true;\n compilerOptions.strictPropertyInitialization = compilerOptions.strictPropertyInitialization ?? true;\n compilerOptions.alwaysStrict = compilerOptions.alwaysStrict ?? true;\n compilerOptions.useUnknownInCatchVariables = compilerOptions.useUnknownInCatchVariables ?? true;\n }\n\n if (options?.tscCompatible && compilerOptions.isolatedModules) {\n compilerOptions.preserveConstEnums = compilerOptions.preserveConstEnums ?? true;\n }\n\n if (options?.tscCompatible && compilerOptions.esModuleInterop) {\n compilerOptions.allowSyntheticDefaultImports = compilerOptions.allowSyntheticDefaultImports ?? true;\n }\n\n if (options?.tscCompatible && compilerOptions.target === \"esnext\") {\n compilerOptions.useDefineForClassFields = compilerOptions.useDefineForClassFields ?? true;\n }\n } else {\n config.compilerOptions = {};\n }\n\n if (config.files) {\n config.files = config.files.map((element) => normalizePath(element));\n }\n\n if (config.include) {\n config.include = config.include.map((element) => normalize(element));\n }\n\n if (config.watchOptions) {\n const { watchOptions } = config;\n\n if (watchOptions.excludeDirectories) {\n watchOptions.excludeDirectories = watchOptions.excludeDirectories.map((excludePath) => resolve(directoryPath, excludePath));\n }\n }\n\n return config;\n};\n\nexport const implicitBaseUrlSymbol = Symbol(\"implicitBaseUrl\");\nexport const readTsConfig = (tsconfigPath: string, options?: Options): TsConfigJsonResolved => internalParseTsConfig(tsconfigPath, options);\n","/**\n * A modified version of `resolveExtendsPath` from `https://github.com/privatenumber/get-tsconfig/blob/develop/src/parse-tsconfig/resolve-extends-path.ts`\n *\n * MIT License\n * Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>\n */\nimport { existsSync, statSync } from \"node:fs\";\nimport Module from \"node:module\";\nimport { isAbsolute, join, resolve } from \"node:path\";\n\nimport { findUpSync, readFileSync } from \"@visulima/fs\";\nimport { parse } from \"jsonc-parser\";\nimport type { PathConditions } from \"resolve-pkg-maps\";\nimport { resolveExports } from \"resolve-pkg-maps\";\nimport type { PackageJson } from \"type-fest\";\n\nimport type { Cache } from \"../types\";\n\nconst readJsonc = (jsonPath: string) => parse(readFileSync(jsonPath) as string) as unknown;\n\nconst getPnpApi = () => {\n const { findPnpApi } = Module;\n\n // https://yarnpkg.com/advanced/pnpapi/#requirepnpapi\n return findPnpApi?.(process.cwd());\n};\n\nconst resolveFromPackageJsonPath = (packageJsonPath: string, subpath: string, ignoreExports?: boolean, cache?: Cache<string>) => {\n const cacheKey = `resolveFromPackageJsonPath:${packageJsonPath}:${subpath}:${ignoreExports}`;\n\n if (cache?.has(cacheKey)) {\n return cache.get(cacheKey);\n }\n\n const packageJson = readJsonc(packageJsonPath);\n\n if (!packageJson) {\n return undefined;\n }\n\n let resolvedPath = subpath || \"tsconfig.json\";\n\n if (!ignoreExports && (packageJson as PackageJson).exports) {\n try {\n const [resolvedExport] = resolveExports((packageJson as PackageJson).exports as PathConditions, subpath, [\"require\", \"types\"]);\n\n resolvedPath = resolvedExport as string;\n } catch {\n // Block\n return false;\n }\n } else if (!subpath && (packageJson as PackageJson).tsconfig) {\n resolvedPath = (packageJson as PackageJson).tsconfig as string;\n }\n\n resolvedPath = join(packageJsonPath, \"..\", resolvedPath);\n\n cache?.set(cacheKey, resolvedPath);\n\n return resolvedPath;\n};\n\nconst PACKAGE_JSON = \"package.json\";\nconst TS_CONFIG_JSON = \"tsconfig.json\";\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst resolveExtendsPath = (requestedPath: string, directoryPath: string, cache?: Cache<string>): string | undefined => {\n let filePath = requestedPath;\n\n if (requestedPath === \"..\") {\n filePath = join(filePath, TS_CONFIG_JSON);\n }\n\n if (requestedPath.startsWith(\".\")) {\n filePath = resolve(directoryPath, filePath);\n }\n\n if (isAbsolute(filePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(filePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (statSync(filePath).isFile()) {\n return filePath;\n }\n } else if (!filePath.endsWith(\".json\")) {\n const jsonPath = `${filePath}.json`;\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(jsonPath)) {\n return jsonPath;\n }\n }\n\n return undefined;\n }\n\n const [orgOrName, ...remaining] = requestedPath.split(\"/\");\n const packageName = ((orgOrName as string).startsWith(\"@\") ? `${orgOrName}/${remaining.shift()}` : orgOrName) as string;\n const subpath = remaining.join(\"/\");\n\n const pnpApi = getPnpApi();\n\n if (pnpApi) {\n const { resolveRequest: resolveWithPnp } = pnpApi;\n\n try {\n if (packageName === requestedPath) {\n const packageJsonPath = resolveWithPnp(join(packageName, PACKAGE_JSON), directoryPath);\n\n if (packageJsonPath) {\n const resolvedPath = resolveFromPackageJsonPath(packageJsonPath, subpath, false, cache);\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (resolvedPath && existsSync(resolvedPath)) {\n return resolvedPath;\n }\n }\n } else {\n let resolved: string | null;\n\n try {\n resolved = resolveWithPnp(requestedPath, directoryPath, { extensions: [\".json\"] });\n } catch {\n resolved = resolveWithPnp(join(requestedPath, TS_CONFIG_JSON), directoryPath);\n }\n\n if (resolved) {\n return resolved;\n }\n }\n } catch {\n /* empty */\n }\n }\n\n const packagePath = findUpSync(\n (directory) => {\n const path = join(directory, \"node_modules\", packageName);\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(path)) {\n return join(\"node_modules\", packageName);\n }\n\n return undefined;\n },\n {\n cwd: directoryPath,\n type: \"directory\",\n },\n );\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!packagePath || !statSync(packagePath).isDirectory()) {\n return undefined;\n }\n\n const packageJsonPath = join(packagePath, PACKAGE_JSON);\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonPath)) {\n const resolvedPath = resolveFromPackageJsonPath(packageJsonPath, subpath, false, cache);\n\n // Blocked\n if (resolvedPath === false) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (resolvedPath && existsSync(resolvedPath) && statSync(resolvedPath).isFile()) {\n return resolvedPath;\n }\n }\n\n const fullPackagePath = join(packagePath, subpath);\n const jsonExtension = fullPackagePath.endsWith(\".json\");\n\n if (!jsonExtension) {\n const fullPackagePathWithJson = `${fullPackagePath}.json`;\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(fullPackagePathWithJson)) {\n return fullPackagePathWithJson;\n }\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!existsSync(fullPackagePath)) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (statSync(fullPackagePath).isDirectory()) {\n const fullPackageJsonPath = join(fullPackagePath, PACKAGE_JSON);\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(fullPackageJsonPath)) {\n const resolvedPath = resolveFromPackageJsonPath(fullPackageJsonPath, \"\", true, cache);\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (resolvedPath && existsSync(resolvedPath)) {\n return resolvedPath;\n }\n }\n\n const tsconfigPath = join(fullPackagePath, TS_CONFIG_JSON);\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(tsconfigPath)) {\n return tsconfigPath;\n }\n } else if (jsonExtension) {\n return fullPackagePath;\n }\n\n return undefined;\n};\n\nexport default resolveExtendsPath;\n"]}
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var chunkIK5YSYLX_cjs = require('./chunk-IK5YSYLX.cjs');
4
+
5
+ // src/error/package-not-found-error.ts
6
+ var PackageNotFoundError = class extends Error {
7
+ /**
8
+ * @param {string} packageName - The name of the package that was not found.
9
+ * @param {string} packageManager - The package manager used to install the package.
10
+ */
11
+ constructor(packageName, packageManager) {
12
+ if (typeof packageName === "string") {
13
+ packageName = [packageName];
14
+ }
15
+ if (packageName.length === 0) {
16
+ super("Package was not found.");
17
+ return;
18
+ }
19
+ if (packageManager === void 0) {
20
+ try {
21
+ const foundManager = chunkIK5YSYLX_cjs.findPackageManagerSync();
22
+ packageManager = foundManager.packageManager;
23
+ } catch {
24
+ }
25
+ }
26
+ if (packageManager === void 0) {
27
+ packageManager = "npm";
28
+ }
29
+ super(`Package '${packageName.join(" ")}' was not found. Please install it using '${packageManager} install ${packageName.join(" ")}'`);
30
+ }
31
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/class-literal-property-style
32
+ get code() {
33
+ return "PACKAGE_NOT_FOUND";
34
+ }
35
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
36
+ set code(_name) {
37
+ throw new Error("Cannot overwrite code PACKAGE_NOT_FOUND");
38
+ }
39
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/class-literal-property-style
40
+ get name() {
41
+ return "PackageNotFoundError";
42
+ }
43
+ // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
44
+ set name(_name) {
45
+ throw new Error("Cannot overwrite name of PackageNotFoundError");
46
+ }
47
+ };
48
+ var package_not_found_error_default = PackageNotFoundError;
49
+
50
+ exports.package_not_found_error_default = package_not_found_error_default;
51
+ //# sourceMappingURL=out.js.map
52
+ //# sourceMappingURL=chunk-7IOK6YPW.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/error/package-not-found-error.ts"],"names":[],"mappings":";;;;;AAKA,IAAM,uBAAN,cAAmC,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAK9B,YAAY,aAAgC,gBAAyB;AACxE,QAAI,OAAO,gBAAgB,UAAU;AAEjC,oBAAc,CAAC,WAAW;AAAA,IAC9B;AAEA,QAAI,YAAY,WAAW,GAAG;AAC1B,YAAM,wBAAwB;AAC9B;AAAA,IACJ;AAEA,QAAI,mBAAmB,QAAW;AAC9B,UAAI;AACA,cAAM,eAAe,uBAAuB;AAG5C,yBAAiB,aAAa;AAAA,MAClC,QAAQ;AAAA,MAER;AAAA,IACJ;AAEA,QAAI,mBAAmB,QAAW;AAE9B,uBAAiB;AAAA,IACrB;AAEA,UAAM,YAAY,YAAY,KAAK,GAAG,CAAC,6CAA6C,cAAc,YAAY,YAAY,KAAK,GAAG,CAAC,GAAG;AAAA,EAC1I;AAAA;AAAA,EAGA,IAAW,OAAe;AACtB,WAAO;AAAA,EACX;AAAA;AAAA,EAGA,IAAW,KAAK,OAAO;AACnB,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC7D;AAAA;AAAA,EAGA,IAAoB,OAAe;AAC/B,WAAO;AAAA,EACX;AAAA;AAAA,EAGA,IAAoB,KAAK,OAAO;AAC5B,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACnE;AACJ;AAEA,IAAO,kCAAQ","sourcesContent":["import { findPackageManagerSync } from \"../package-manager\";\n\n/**\n * Error thrown when a package was not found.\n */\nclass PackageNotFoundError extends Error {\n /**\n * @param {string} packageName - The name of the package that was not found.\n * @param {string} packageManager - The package manager used to install the package.\n */\n public constructor(packageName: string[] | string, packageManager?: string) {\n if (typeof packageName === \"string\") {\n // eslint-disable-next-line no-param-reassign\n packageName = [packageName];\n }\n\n if (packageName.length === 0) {\n super(\"Package was not found.\");\n return;\n }\n\n if (packageManager === undefined) {\n try {\n const foundManager = findPackageManagerSync();\n\n // eslint-disable-next-line no-param-reassign\n packageManager = foundManager.packageManager;\n } catch {\n // Empty\n }\n }\n\n if (packageManager === undefined) {\n // eslint-disable-next-line no-param-reassign\n packageManager = \"npm\";\n }\n\n super(`Package '${packageName.join(\" \")}' was not found. Please install it using '${packageManager} install ${packageName.join(\" \")}'`);\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/class-literal-property-style\n public get code(): string {\n return \"PACKAGE_NOT_FOUND\";\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types\n public set code(_name) {\n throw new Error(\"Cannot overwrite code PACKAGE_NOT_FOUND\");\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/class-literal-property-style\n public override get name(): string {\n return \"PackageNotFoundError\";\n }\n\n // eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types\n public override set name(_name) {\n throw new Error(\"Cannot overwrite name of PackageNotFoundError\");\n }\n}\n\nexport default PackageNotFoundError;\n"]}
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ var chunkIK5YSYLX_cjs = require('./chunk-IK5YSYLX.cjs');
4
+ var fs$1 = require('fs');
5
+ var fs = require('@visulima/fs');
6
+ var pathe = require('pathe');
7
+
8
+ var packageJsonMatcher = (directory) => {
9
+ if (fs$1.existsSync(pathe.join(directory, "package.json"))) {
10
+ const packageJson = fs.readJsonSync(pathe.join(directory, "package.json"));
11
+ if (packageJson.name && packageJson.private !== true) {
12
+ return "package.json";
13
+ }
14
+ }
15
+ return void 0;
16
+ };
17
+ var findPackageRoot = async (cwd) => {
18
+ try {
19
+ const lockFile = await chunkIK5YSYLX_cjs.findLockFile(cwd);
20
+ return pathe.dirname(lockFile);
21
+ } catch {
22
+ }
23
+ const gitConfig = await fs.findUp(".git/config", {
24
+ ...cwd && { cwd },
25
+ type: "file"
26
+ });
27
+ if (gitConfig) {
28
+ return pathe.dirname(pathe.dirname(gitConfig));
29
+ }
30
+ const filePath = await fs.findUp(packageJsonMatcher, {
31
+ ...cwd && { cwd },
32
+ type: "file"
33
+ });
34
+ if (filePath) {
35
+ return pathe.dirname(filePath);
36
+ }
37
+ throw new Error("Could not find root directory");
38
+ };
39
+ var findPackageRootSync = (cwd) => {
40
+ try {
41
+ const lockFile = chunkIK5YSYLX_cjs.findLockFileSync(cwd);
42
+ return pathe.dirname(lockFile);
43
+ } catch {
44
+ }
45
+ const gitConfig = fs.findUpSync(".git/config", {
46
+ ...cwd && { cwd },
47
+ type: "file"
48
+ });
49
+ if (gitConfig) {
50
+ return pathe.dirname(pathe.dirname(gitConfig));
51
+ }
52
+ const filePath = fs.findUpSync(packageJsonMatcher, {
53
+ ...cwd && { cwd },
54
+ type: "file"
55
+ });
56
+ if (filePath) {
57
+ return pathe.dirname(filePath);
58
+ }
59
+ throw new Error("Could not find root directory");
60
+ };
61
+
62
+ exports.findPackageRoot = findPackageRoot;
63
+ exports.findPackageRootSync = findPackageRootSync;
64
+ //# sourceMappingURL=out.js.map
65
+ //# sourceMappingURL=chunk-CVVFWSMT.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/package.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,kBAAkB;AAE3B,SAAS,QAAQ,YAAY,oBAAoB;AACjD,SAAS,SAAS,YAAY;AAK9B,IAAM,qBAAqB,CAAC,cAAsB;AAE9C,MAAI,WAAW,KAAK,WAAW,cAAc,CAAC,GAAG;AAC7C,UAAM,c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dirname, join } from \"pathe\";\n\nimport { findLockFile, findLockFileSync } from \"./package-manager\";\nimport type { PackageJson } from \"./types\";\n\nconst packageJsonMatcher = (directory: string) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(join(directory, \"package.json\"))) {\n const packageJson = readJsonSync<PackageJson>(join(directory, \"package.json\"));\n\n if (packageJson.name && packageJson.private !== true) {\n return \"package.json\";\n }\n }\n\n return undefined;\n};\n\n/**\n * An asynchronous function that finds the root directory of a project based on certain lookup criteria.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if the root directory could not be found.\n *\n * @example\n * const rootDirectory = await findPackageRoot();\n * console.log(rootDirectory); // '/path/to/project'\n */\nexport const findPackageRoot = async (cwd?: URL | string): Promise<string> => {\n try {\n const lockFile = await findLockFile(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\n const gitConfig = await findUp(\".git/config\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (gitConfig) {\n return dirname(dirname(gitConfig));\n }\n\n const filePath = await findUp(packageJsonMatcher, {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (filePath) {\n return dirname(filePath);\n }\n\n throw new Error(\"Could not find root directory\");\n};\n\nexport const findPackageRootSync = (cwd?: URL | string): string => {\n try {\n const lockFile = findLockFileSync(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\n const gitConfig = findUpSync(\".git/config\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (gitConfig) {\n return dirname(dirname(gitConfig));\n }\n\n const filePath = findUpSync(packageJsonMatcher, {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (filePath) {\n return dirname(filePath);\n }\n\n throw new Error(\"Could not find root directory\");\n};\n"]}
@@ -0,0 +1,54 @@
1
+ import { findPackageManager } from './chunk-IIYQBLPC.js';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { findUp, readJson } from '@visulima/fs';
4
+ import { NotFoundError } from '@visulima/fs/error';
5
+ import { dirname, join } from 'pathe';
6
+
7
+ var findMonorepoRoot = async (cwd) => {
8
+ const workspaceFilePath = await findUp(["lerna.json", "turbo.json"], {
9
+ type: "file",
10
+ ...cwd && { cwd }
11
+ });
12
+ if (workspaceFilePath?.endsWith("lerna.json")) {
13
+ const lerna = await readJson(workspaceFilePath);
14
+ if (lerna.useWorkspaces || lerna.packages) {
15
+ return {
16
+ path: dirname(workspaceFilePath),
17
+ strategy: "lerna"
18
+ };
19
+ }
20
+ }
21
+ const isTurbo = workspaceFilePath?.endsWith("turbo.json");
22
+ try {
23
+ const { packageManager, path } = await findPackageManager(cwd);
24
+ if (["npm", "yarn"].includes(packageManager)) {
25
+ const packageJsonFilePath = join(path, "package.json");
26
+ if (existsSync(packageJsonFilePath)) {
27
+ const packageJson = readFileSync(join(path, "package.json"), "utf8");
28
+ if (packageJson.includes("workspaces")) {
29
+ return {
30
+ path,
31
+ strategy: isTurbo ? "turbo" : packageManager
32
+ };
33
+ }
34
+ }
35
+ } else if (packageManager === "pnpm") {
36
+ const pnpmWorkspacesFilePath = join(path, "pnpm-workspace.yaml");
37
+ if (existsSync(pnpmWorkspacesFilePath)) {
38
+ return {
39
+ path,
40
+ strategy: isTurbo ? "turbo" : "pnpm"
41
+ };
42
+ }
43
+ }
44
+ } catch (error) {
45
+ if (!(error instanceof NotFoundError)) {
46
+ throw error;
47
+ }
48
+ }
49
+ throw new Error(`No monorepo root could be found upwards from the directory ${cwd} using lerna, yarn, pnpm, or npm as indicators.`);
50
+ };
51
+
52
+ export { findMonorepoRoot };
53
+ //# sourceMappingURL=out.js.map
54
+ //# sourceMappingURL=chunk-E2PKJX3Q.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/monorepo.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAAY,oBAAoB;AAEzC,SAAS,QAAQ,gBAA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\n\nimport { findUp, readJson } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { dirname, join } from \"pathe\";\n\nimport { findPackageManager } from \"./package-manager\";\n\nexport type Strategy = \"lerna\" | \"npm\" | \"pnpm\" | \"turbo\" | \"yarn\";\n\nexport interface RootMonorepo<T extends Strategy = Strategy> {\n path: string;\n strategy: T;\n}\n\n/**\n * An asynchronous function to find the root directory path and strategy for a monorepo based on\n * the given current working directory (cwd).\n *\n * @param cwd - The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options[\"cwd\"]`.\n * Default is undefined.\n * @returns A `Promise` that resolves to the root directory path and strategy for the monorepo.\n * The type of the returned promise is `Promise<RootMonorepo>`.\n * @throws An `Error` if no monorepo root can be found using lerna, yarn, pnpm, or npm as indicators.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findMonorepoRoot = async (cwd?: URL | string): Promise<RootMonorepo> => {\n const workspaceFilePath = await findUp([\"lerna.json\", \"turbo.json\"], {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (workspaceFilePath?.endsWith(\"lerna.json\")) {\n const lerna = await readJson<{ packages?: string[]; useWorkspaces?: boolean }>(workspaceFilePath);\n\n if (lerna.useWorkspaces || lerna.packages) {\n return {\n path: dirname(workspaceFilePath),\n strategy: \"lerna\",\n };\n }\n }\n\n const isTurbo = workspaceFilePath?.endsWith(\"turbo.json\");\n\n try {\n const { packageManager, path } = await findPackageManager(cwd);\n\n if ([\"npm\", \"yarn\"].includes(packageManager)) {\n const packageJsonFilePath = join(path, \"package.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = readFileSync(join(path, \"package.json\"), \"utf8\");\n\n if (packageJson.includes(\"workspaces\")) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : (packageManager as \"npm\" | \"yarn\"),\n };\n }\n }\n } else if (packageManager === \"pnpm\") {\n const pnpmWorkspacesFilePath = join(path, \"pnpm-workspace.yaml\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(pnpmWorkspacesFilePath)) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : \"pnpm\",\n };\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n // Skip this error to show the error message from the next block\n if (!(error instanceof NotFoundError)) {\n throw error;\n }\n }\n\n throw new Error(`No monorepo root could be found upwards from the directory ${cwd as string} using lerna, yarn, pnpm, or npm as indicators.`);\n};\n"]}