@vercel/fs-detectors 5.0.1 → 5.0.2

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 (31) hide show
  1. package/dist/detect-builders.js +701 -748
  2. package/dist/detect-builders.js.map +7 -1
  3. package/dist/detect-file-system-api.js +177 -154
  4. package/dist/detect-file-system-api.js.map +7 -1
  5. package/dist/detect-framework.js +196 -143
  6. package/dist/detect-framework.js.map +7 -1
  7. package/dist/detectors/filesystem.js +106 -109
  8. package/dist/detectors/filesystem.js.map +7 -1
  9. package/dist/detectors/local-file-system-detector.js +90 -63
  10. package/dist/detectors/local-file-system-detector.js.map +7 -1
  11. package/dist/get-project-paths.js +74 -35
  12. package/dist/get-project-paths.js.map +7 -1
  13. package/dist/index.js +85 -48
  14. package/dist/index.js.map +7 -1
  15. package/dist/is-official-runtime.js +34 -19
  16. package/dist/is-official-runtime.js.map +7 -1
  17. package/dist/monorepos/get-monorepo-default-settings.js +154 -150
  18. package/dist/monorepos/get-monorepo-default-settings.js.map +7 -1
  19. package/dist/monorepos/monorepo-managers.js +112 -100
  20. package/dist/monorepos/monorepo-managers.js.map +7 -1
  21. package/dist/package-managers/package-managers.js +79 -55
  22. package/dist/package-managers/package-managers.js.map +7 -1
  23. package/dist/workspaces/get-glob-fs.js +90 -66
  24. package/dist/workspaces/get-glob-fs.js.map +7 -1
  25. package/dist/workspaces/get-workspace-package-paths.js +130 -79
  26. package/dist/workspaces/get-workspace-package-paths.js.map +7 -1
  27. package/dist/workspaces/get-workspaces.js +71 -31
  28. package/dist/workspaces/get-workspaces.js.map +7 -1
  29. package/dist/workspaces/workspace-managers.js +104 -92
  30. package/dist/workspaces/workspace-managers.js.map +7 -1
  31. package/package.json +4 -4
@@ -1,166 +1,219 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectFrameworkVersion = exports.detectFrameworkRecord = exports.detectFrameworks = exports.detectFramework = exports.removeSupersededFrameworks = void 0;
4
- const child_process_1 = require("child_process");
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var detect_framework_exports = {};
20
+ __export(detect_framework_exports, {
21
+ detectFramework: () => detectFramework,
22
+ detectFrameworkRecord: () => detectFrameworkRecord,
23
+ detectFrameworkVersion: () => detectFrameworkVersion,
24
+ detectFrameworks: () => detectFrameworks,
25
+ removeSupersededFrameworks: () => removeSupersededFrameworks
26
+ });
27
+ module.exports = __toCommonJS(detect_framework_exports);
28
+ var import_child_process = require("child_process");
5
29
  async function matches(fs, framework) {
6
- const { detectors } = framework;
7
- if (!detectors) {
8
- return;
30
+ const { detectors } = framework;
31
+ if (!detectors) {
32
+ return;
33
+ }
34
+ const { every, some } = detectors;
35
+ if (every !== void 0 && !Array.isArray(every)) {
36
+ return;
37
+ }
38
+ if (some !== void 0 && !Array.isArray(some)) {
39
+ return;
40
+ }
41
+ const check = async ({
42
+ path,
43
+ matchContent,
44
+ matchPackage
45
+ }) => {
46
+ if (matchPackage && matchContent) {
47
+ throw new Error(
48
+ `Cannot specify "matchPackage" and "matchContent" in the same detector for "${framework.slug}"`
49
+ );
9
50
  }
10
- const { every, some } = detectors;
11
- if (every !== undefined && !Array.isArray(every)) {
12
- return;
51
+ if (matchPackage && path) {
52
+ throw new Error(
53
+ `Cannot specify "matchPackage" and "path" in the same detector for "${framework.slug}" because "path" is assumed to be "package.json".`
54
+ );
13
55
  }
14
- if (some !== undefined && !Array.isArray(some)) {
15
- return;
56
+ if (!path && !matchPackage) {
57
+ throw new Error(
58
+ `Must specify either "path" or "matchPackage" in detector for "${framework.slug}".`
59
+ );
16
60
  }
17
- const check = async ({ path, matchContent, matchPackage, }) => {
18
- if (matchPackage && matchContent) {
19
- throw new Error(`Cannot specify "matchPackage" and "matchContent" in the same detector for "${framework.slug}"`);
20
- }
21
- if (matchPackage && path) {
22
- throw new Error(`Cannot specify "matchPackage" and "path" in the same detector for "${framework.slug}" because "path" is assumed to be "package.json".`);
23
- }
24
- if (!path && !matchPackage) {
25
- throw new Error(`Must specify either "path" or "matchPackage" in detector for "${framework.slug}".`);
26
- }
27
- if (!path) {
28
- path = 'package.json';
29
- }
30
- if (matchPackage) {
31
- matchContent = `"(dev)?(d|D)ependencies":\\s*{[^}]*"${matchPackage}":\\s*"(.+?)"[^}]*}`;
32
- }
33
- if ((await fs.hasPath(path)) === false) {
34
- return;
35
- }
36
- if (matchContent) {
37
- if ((await fs.isFile(path)) === false) {
38
- return;
39
- }
40
- const regex = new RegExp(matchContent, 'm');
41
- const content = await fs.readFile(path);
42
- const match = content.toString().match(regex);
43
- if (!match) {
44
- return;
45
- }
46
- if (matchPackage && match[3]) {
47
- return {
48
- framework,
49
- detectedVersion: match[3],
50
- };
51
- }
52
- }
53
- return {
54
- framework,
55
- };
56
- };
57
- const result = [];
58
- if (every) {
59
- const everyResult = await Promise.all(every.map(item => check(item)));
60
- result.push(...everyResult);
61
+ if (!path) {
62
+ path = "package.json";
61
63
  }
62
- if (some) {
63
- let someResult;
64
- for (const item of some) {
65
- const itemResult = await check(item);
66
- if (itemResult) {
67
- someResult = itemResult;
68
- break;
69
- }
70
- }
71
- result.push(someResult);
64
+ if (matchPackage) {
65
+ matchContent = `"(dev)?(d|D)ependencies":\\s*{[^}]*"${matchPackage}":\\s*"(.+?)"[^}]*}`;
72
66
  }
73
- if (!result.every(res => !!res)) {
67
+ if (await fs.hasPath(path) === false) {
68
+ return;
69
+ }
70
+ if (matchContent) {
71
+ if (await fs.isFile(path) === false) {
72
+ return;
73
+ }
74
+ const regex = new RegExp(matchContent, "m");
75
+ const content = await fs.readFile(path);
76
+ const match = content.toString().match(regex);
77
+ if (!match) {
74
78
  return;
79
+ }
80
+ if (matchPackage && match[3]) {
81
+ return {
82
+ framework,
83
+ detectedVersion: match[3]
84
+ };
85
+ }
75
86
  }
76
- const detectedVersion = result.find(r => typeof r === 'object' && r.detectedVersion)?.detectedVersion;
77
87
  return {
78
- framework,
79
- detectedVersion,
88
+ framework
80
89
  };
90
+ };
91
+ const result = [];
92
+ if (every) {
93
+ const everyResult = await Promise.all(every.map((item) => check(item)));
94
+ result.push(...everyResult);
95
+ }
96
+ if (some) {
97
+ let someResult;
98
+ for (const item of some) {
99
+ const itemResult = await check(item);
100
+ if (itemResult) {
101
+ someResult = itemResult;
102
+ break;
103
+ }
104
+ }
105
+ result.push(someResult);
106
+ }
107
+ if (!result.every((res) => !!res)) {
108
+ return;
109
+ }
110
+ const detectedVersion = result.find(
111
+ (r) => typeof r === "object" && r.detectedVersion
112
+ )?.detectedVersion;
113
+ return {
114
+ framework,
115
+ detectedVersion
116
+ };
81
117
  }
82
- function removeSupersededFramework(matches, slug) {
83
- const index = matches.findIndex(f => f?.slug === slug);
84
- const framework = matches[index];
85
- if (framework) {
86
- if (framework.supersedes) {
87
- removeSupersededFramework(matches, framework.supersedes);
88
- }
89
- matches.splice(index, 1);
118
+ function removeSupersededFramework(matches2, slug) {
119
+ const index = matches2.findIndex((f) => f?.slug === slug);
120
+ const framework = matches2[index];
121
+ if (framework) {
122
+ if (framework.supersedes) {
123
+ removeSupersededFramework(matches2, framework.supersedes);
90
124
  }
125
+ matches2.splice(index, 1);
126
+ }
91
127
  }
92
- function removeSupersededFrameworks(matches) {
93
- for (const match of matches.slice()) {
94
- if (match?.supersedes) {
95
- removeSupersededFramework(matches, match.supersedes);
96
- }
128
+ function removeSupersededFrameworks(matches2) {
129
+ for (const match of matches2.slice()) {
130
+ if (match?.supersedes) {
131
+ removeSupersededFramework(matches2, match.supersedes);
97
132
  }
133
+ }
98
134
  }
99
- exports.removeSupersededFrameworks = removeSupersededFrameworks;
100
- // TODO: Deprecate and replace with `detectFrameworkRecord`
101
- async function detectFramework({ fs, frameworkList, }) {
102
- const result = await Promise.all(frameworkList.map(async (frameworkMatch) => {
103
- if (await matches(fs, frameworkMatch)) {
104
- return frameworkMatch;
105
- }
106
- return null;
107
- }));
108
- removeSupersededFrameworks(result);
109
- return result.find(res => res !== null)?.slug ?? null;
135
+ async function detectFramework({
136
+ fs,
137
+ frameworkList
138
+ }) {
139
+ const result = await Promise.all(
140
+ frameworkList.map(async (frameworkMatch) => {
141
+ if (await matches(fs, frameworkMatch)) {
142
+ return frameworkMatch;
143
+ }
144
+ return null;
145
+ })
146
+ );
147
+ removeSupersededFrameworks(result);
148
+ return result.find((res) => res !== null)?.slug ?? null;
110
149
  }
111
- exports.detectFramework = detectFramework;
112
- /**
113
- * Detects all matching Frameworks based on the given virtual filesystem.
114
- */
115
- async function detectFrameworks({ fs, frameworkList, }) {
116
- const result = await Promise.all(frameworkList.map(async (frameworkMatch) => {
117
- if (await matches(fs, frameworkMatch)) {
118
- return frameworkMatch;
119
- }
120
- return null;
121
- }));
122
- removeSupersededFrameworks(result);
123
- return result.filter(res => res !== null);
150
+ async function detectFrameworks({
151
+ fs,
152
+ frameworkList
153
+ }) {
154
+ const result = await Promise.all(
155
+ frameworkList.map(async (frameworkMatch) => {
156
+ if (await matches(fs, frameworkMatch)) {
157
+ return frameworkMatch;
158
+ }
159
+ return null;
160
+ })
161
+ );
162
+ removeSupersededFrameworks(result);
163
+ return result.filter((res) => res !== null);
124
164
  }
125
- exports.detectFrameworks = detectFrameworks;
126
- // Note: Does not currently support a `frameworkList` of monorepo managers
127
- async function detectFrameworkRecord({ fs, frameworkList, }) {
128
- const result = await Promise.all(frameworkList.map(async (frameworkMatch) => {
129
- const matchResult = await matches(fs, frameworkMatch);
130
- if (matchResult) {
131
- return {
132
- ...frameworkMatch,
133
- detectedVersion: matchResult?.detectedVersion,
134
- };
135
- }
136
- return null;
137
- }));
138
- removeSupersededFrameworks(result);
139
- return result.find(res => res !== null) ?? null;
165
+ async function detectFrameworkRecord({
166
+ fs,
167
+ frameworkList
168
+ }) {
169
+ const result = await Promise.all(
170
+ frameworkList.map(async (frameworkMatch) => {
171
+ const matchResult = await matches(fs, frameworkMatch);
172
+ if (matchResult) {
173
+ return {
174
+ ...frameworkMatch,
175
+ detectedVersion: matchResult?.detectedVersion
176
+ };
177
+ }
178
+ return null;
179
+ })
180
+ );
181
+ removeSupersededFrameworks(result);
182
+ return result.find((res) => res !== null) ?? null;
140
183
  }
141
- exports.detectFrameworkRecord = detectFrameworkRecord;
142
184
  function detectFrameworkVersion(frameworkRecord) {
143
- const allDetectors = [
144
- ...(frameworkRecord.detectors?.every || []),
145
- ...(frameworkRecord.detectors?.some || []),
146
- ];
147
- const firstMatchPackage = allDetectors.find(d => d.matchPackage);
148
- if (!firstMatchPackage?.matchPackage) {
149
- return;
150
- }
151
- return lookupInstalledVersion(process.execPath, firstMatchPackage.matchPackage);
185
+ const allDetectors = [
186
+ ...frameworkRecord.detectors?.every || [],
187
+ ...frameworkRecord.detectors?.some || []
188
+ ];
189
+ const firstMatchPackage = allDetectors.find((d) => d.matchPackage);
190
+ if (!firstMatchPackage?.matchPackage) {
191
+ return;
192
+ }
193
+ return lookupInstalledVersion(
194
+ process.execPath,
195
+ firstMatchPackage.matchPackage
196
+ );
152
197
  }
153
- exports.detectFrameworkVersion = detectFrameworkVersion;
154
198
  function lookupInstalledVersion(cwd, packageName) {
155
- try {
156
- const script = `require('${packageName}/package.json').version`;
157
- return (0, child_process_1.spawnSync)(cwd, ['-p', script], {
158
- encoding: 'utf-8',
159
- }).stdout.trim();
160
- }
161
- catch (error) {
162
- console.debug(`Error looking up version of installed package "${packageName}": ${error}`);
163
- }
164
- return;
199
+ try {
200
+ const script = `require('${packageName}/package.json').version`;
201
+ return (0, import_child_process.spawnSync)(cwd, ["-p", script], {
202
+ encoding: "utf-8"
203
+ }).stdout.trim();
204
+ } catch (error) {
205
+ console.debug(
206
+ `Error looking up version of installed package "${packageName}": ${error}`
207
+ );
208
+ }
209
+ return;
165
210
  }
166
- //# sourceMappingURL=detect-framework.js.map
211
+ // Annotate the CommonJS export names for ESM import in node:
212
+ 0 && (module.exports = {
213
+ detectFramework,
214
+ detectFrameworkRecord,
215
+ detectFrameworkVersion,
216
+ detectFrameworks,
217
+ removeSupersededFrameworks
218
+ });
219
+ //# sourceMappingURL=detect-framework.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"detect-framework.js","sourceRoot":"","sources":["../src/detect-framework.ts"],"names":[],"mappings":";;;AACA,iDAA0C;AAuB1C,KAAK,UAAU,OAAO,CACpB,EAAsB,EACtB,SAAwB;IAExB,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;IAEhC,IAAI,CAAC,SAAS,EAAE;QACd,OAAO;KACR;IAED,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;IAElC,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAChD,OAAO;KACR;IAED,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC9C,OAAO;KACR;IAED,MAAM,KAAK,GAAG,KAAK,EAAE,EACnB,IAAI,EACJ,YAAY,EACZ,YAAY,GACW,EAAoC,EAAE;QAC7D,IAAI,YAAY,IAAI,YAAY,EAAE;YAChC,MAAM,IAAI,KAAK,CACb,8EAA8E,SAAS,CAAC,IAAI,GAAG,CAChG,CAAC;SACH;QACD,IAAI,YAAY,IAAI,IAAI,EAAE;YACxB,MAAM,IAA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AAK,EAAE,CAC3E,CAAC;KACH;IAED,OAAO;AACT,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/detect-framework.ts"],
4
+ "sourcesContent": ["import type { Framework, FrameworkDetectionItem } from '@vercel/frameworks';\nimport { spawnSync } from 'child_process';\nimport { DetectorFilesystem } from './detectors/filesystem';\n\ninterface BaseFramework {\n slug: Framework['slug'];\n detectors?: Framework['detectors'];\n}\n\nexport interface DetectFrameworkOptions {\n fs: DetectorFilesystem;\n frameworkList: readonly BaseFramework[];\n}\n\nexport interface DetectFrameworkRecordOptions {\n fs: DetectorFilesystem;\n frameworkList: readonly Framework[];\n}\n\ntype MatchResult = {\n framework: BaseFramework;\n detectedVersion?: string;\n};\n\nasync function matches(\n fs: DetectorFilesystem,\n framework: BaseFramework\n): Promise<MatchResult | undefined> {\n const { detectors } = framework;\n\n if (!detectors) {\n return;\n }\n\n const { every, some } = detectors;\n\n if (every !== undefined && !Array.isArray(every)) {\n return;\n }\n\n if (some !== undefined && !Array.isArray(some)) {\n return;\n }\n\n const check = async ({\n path,\n matchContent,\n matchPackage,\n }: FrameworkDetectionItem): Promise<MatchResult | undefined> => {\n if (matchPackage && matchContent) {\n throw new Error(\n `Cannot specify \"matchPackage\" and \"matchContent\" in the same detector for \"${framework.slug}\"`\n );\n }\n if (matchPackage && path) {\n throw new Error(\n `Cannot specify \"matchPackage\" and \"path\" in the same detector for \"${framework.slug}\" because \"path\" is assumed to be \"package.json\".`\n );\n }\n\n if (!path && !matchPackage) {\n throw new Error(\n `Must specify either \"path\" or \"matchPackage\" in detector for \"${framework.slug}\".`\n );\n }\n\n if (!path) {\n path = 'package.json';\n }\n\n if (matchPackage) {\n matchContent = `\"(dev)?(d|D)ependencies\":\\\\s*{[^}]*\"${matchPackage}\":\\\\s*\"(.+?)\"[^}]*}`;\n }\n\n if ((await fs.hasPath(path)) === false) {\n return;\n }\n\n if (matchContent) {\n if ((await fs.isFile(path)) === false) {\n return;\n }\n\n const regex = new RegExp(matchContent, 'm');\n const content = await fs.readFile(path);\n\n const match = content.toString().match(regex);\n if (!match) {\n return;\n }\n if (matchPackage && match[3]) {\n return {\n framework,\n detectedVersion: match[3],\n };\n }\n }\n\n return {\n framework,\n };\n };\n\n const result: (MatchResult | undefined)[] = [];\n\n if (every) {\n const everyResult = await Promise.all(every.map(item => check(item)));\n result.push(...everyResult);\n }\n\n if (some) {\n let someResult: MatchResult | undefined;\n\n for (const item of some) {\n const itemResult = await check(item);\n if (itemResult) {\n someResult = itemResult;\n break;\n }\n }\n\n result.push(someResult);\n }\n\n if (!result.every(res => !!res)) {\n return;\n }\n\n const detectedVersion = result.find(\n r => typeof r === 'object' && r.detectedVersion\n )?.detectedVersion;\n return {\n framework,\n detectedVersion,\n };\n}\n\nfunction removeSupersededFramework(\n matches: (Pick<Framework, 'supersedes' | 'slug'> | null)[],\n slug: string\n) {\n const index = matches.findIndex(f => f?.slug === slug);\n const framework = matches[index];\n if (framework) {\n if (framework.supersedes) {\n removeSupersededFramework(matches, framework.supersedes);\n }\n matches.splice(index, 1);\n }\n}\n\nexport function removeSupersededFrameworks(\n matches: (Pick<Framework, 'supersedes' | 'slug'> | null)[]\n) {\n for (const match of matches.slice()) {\n if (match?.supersedes) {\n removeSupersededFramework(matches, match.supersedes);\n }\n }\n}\n\n// TODO: Deprecate and replace with `detectFrameworkRecord`\nexport async function detectFramework({\n fs,\n frameworkList,\n}: DetectFrameworkOptions): Promise<string | null> {\n const result = await Promise.all(\n frameworkList.map(async frameworkMatch => {\n if (await matches(fs, frameworkMatch)) {\n return frameworkMatch;\n }\n return null;\n })\n );\n removeSupersededFrameworks(result);\n return result.find(res => res !== null)?.slug ?? null;\n}\n\n/**\n * Detects all matching Frameworks based on the given virtual filesystem.\n */\nexport async function detectFrameworks({\n fs,\n frameworkList,\n}: DetectFrameworkRecordOptions): Promise<Framework[]> {\n const result = await Promise.all(\n frameworkList.map(async frameworkMatch => {\n if (await matches(fs, frameworkMatch)) {\n return frameworkMatch;\n }\n return null;\n })\n );\n removeSupersededFrameworks(result);\n return result.filter(res => res !== null) as Framework[];\n}\n\n/**\n * Framework with a `detectedVersion` specifying the version\n * or version range of the relevant package\n */\ntype VersionedFramework = Framework & {\n detectedVersion?: string;\n};\n\n// Note: Does not currently support a `frameworkList` of monorepo managers\nexport async function detectFrameworkRecord({\n fs,\n frameworkList,\n}: DetectFrameworkRecordOptions): Promise<VersionedFramework | null> {\n const result = await Promise.all(\n frameworkList.map(async frameworkMatch => {\n const matchResult = await matches(fs, frameworkMatch);\n if (matchResult) {\n return {\n ...frameworkMatch,\n detectedVersion: matchResult?.detectedVersion,\n };\n }\n return null;\n })\n );\n removeSupersededFrameworks(result);\n return result.find(res => res !== null) ?? null;\n}\n\nexport function detectFrameworkVersion(\n frameworkRecord: Framework\n): string | undefined {\n const allDetectors = [\n ...(frameworkRecord.detectors?.every || []),\n ...(frameworkRecord.detectors?.some || []),\n ];\n const firstMatchPackage = allDetectors.find(d => d.matchPackage);\n\n if (!firstMatchPackage?.matchPackage) {\n return;\n }\n\n return lookupInstalledVersion(\n process.execPath,\n firstMatchPackage.matchPackage\n );\n}\n\nfunction lookupInstalledVersion(\n cwd: string,\n packageName: string\n): string | undefined {\n try {\n const script = `require('${packageName}/package.json').version`;\n return spawnSync(cwd, ['-p', script], {\n encoding: 'utf-8',\n }).stdout.trim();\n } catch (error) {\n console.debug(\n `Error looking up version of installed package \"${packageName}\": ${error}`\n );\n }\n\n return;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAA0B;AAuB1B,eAAe,QACb,IACA,WACkC;AAClC,QAAM,EAAE,UAAU,IAAI;AAEtB,MAAI,CAAC,WAAW;AACd;AAAA,EACF;AAEA,QAAM,EAAE,OAAO,KAAK,IAAI;AAExB,MAAI,UAAU,UAAa,CAAC,MAAM,QAAQ,KAAK,GAAG;AAChD;AAAA,EACF;AAEA,MA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Module", { value: true });
3
- exports.DetectorFilesystem = void 0;
4
- const path_1 = require("path");
5
- /**
6
- * `DetectorFilesystem` is an abstract class that represents a virtual filesystem
7
- * to perform read-only operations on in order to detect which framework is being
8
- * used.
9
- *
10
- * Its abstract methods must be implemented by a subclass that perform the actual
11
- * FS operations. Example subclasses could be implemented as:
12
- *
13
- * - Local filesystem, which proxies the FS operations to the equivalent `fs`
14
- * module functions.
15
- * - HTTP filesystem, which implements the FS operations over an HTTP server
16
- * and does not require a local copy of the files.
17
- * - `Files` filesystem, which operates on a virtual `Files` object (i.e. from
18
- * the `glob()` function) which could include `FileFsRef`, `FileBlob`, etc.
19
- *
20
- * This base class implements various helper functions for common tasks (i.e.
21
- * read and parse a JSON file). It also includes caching for all FS operations
22
- * so that multiple detector functions de-dup read operations on the same file
23
- * to reduce network/filesystem overhead.
24
- *
25
- * **NOTE:** It's important that all instance methods in this base class are
26
- * bound to `this` so that the `fs` object may be destructured in the detector
27
- * functions. The easiest way to do this is to use the `=` syntax when defining
28
- * methods in this class definition.
29
- */
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var filesystem_exports = {};
20
+ __export(filesystem_exports, {
21
+ DetectorFilesystem: () => DetectorFilesystem
22
+ });
23
+ module.exports = __toCommonJS(filesystem_exports);
24
+ var import_path = require("path");
30
25
  class DetectorFilesystem {
31
- constructor() {
32
- this.hasPath = async (path) => {
33
- let p = this.pathCache.get(path);
34
- if (!p) {
35
- p = this._hasPath(path);
36
- this.pathCache.set(path, p);
37
- }
38
- return p;
39
- };
40
- this.isFile = async (name) => {
41
- let p = this.fileCache.get(name);
42
- if (!p) {
43
- p = this._isFile(name);
44
- this.fileCache.set(name, p);
45
- }
46
- return p;
47
- };
48
- this.readFile = async (name) => {
49
- let p = this.readFileCache.get(name);
50
- if (!p) {
51
- p = this._readFile(name);
52
- this.readFileCache.set(name, p);
53
- }
54
- return p;
55
- };
56
- /**
57
- * Returns a list of Stat objects from the current working directory.
58
- * @param dirPath The path of the directory to read.
59
- * @param options.potentialFiles optional. Array of potential file names (relative to the path). If provided, these will be used to mark the filesystem caches as existing or not existing.
60
- */
61
- this.readdir = async (dirPath, options) => {
62
- let p = this.readdirCache.get(dirPath);
63
- if (!p) {
64
- p = this._readdir(dirPath);
65
- this.readdirCache.set(dirPath, p);
66
- }
67
- const directoryContent = await p;
68
- const directoryFiles = new Set();
69
- for (const file of directoryContent) {
70
- if (file.type === 'file') {
71
- // we know this file exists, mark it as so on the filesystem
72
- this.fileCache.set(file.path, Promise.resolve(true));
73
- this.pathCache.set(file.path, Promise.resolve(true));
74
- directoryFiles.add(file.name);
75
- }
76
- }
77
- if (options?.potentialFiles) {
78
- // calculate the set of paths that truly do not exist
79
- const filesThatDoNotExist = options.potentialFiles.filter(path => !directoryFiles.has(path));
80
- for (const filePath of filesThatDoNotExist) {
81
- const fullFilePath = dirPath === '/' ? filePath : path_1.posix.join(dirPath, filePath);
82
- // we know this file does not exist, mark it as so on the filesystem
83
- this.fileCache.set(fullFilePath, Promise.resolve(false));
84
- this.pathCache.set(fullFilePath, Promise.resolve(false));
85
- }
86
- }
87
- return p;
88
- };
89
- /**
90
- * Changes the current directory to the specified path and returns a new instance of DetectorFilesystem.
91
- */
92
- this.chdir = (name) => {
93
- return this._chdir(name);
94
- };
95
- /**
96
- * Writes a file to the filesystem cache.
97
- * @param name the name of the file to write
98
- * @param content The content of the file
99
- */
100
- this.writeFile = async (name, content) => {
101
- this.readFileCache.set(name, Promise.resolve(Buffer.from(content)));
102
- this.fileCache.set(name, Promise.resolve(true));
103
- this.pathCache.set(name, Promise.resolve(true));
104
- };
105
- this.pathCache = new Map();
106
- this.fileCache = new Map();
107
- this.readFileCache = new Map();
108
- this.readdirCache = new Map();
109
- }
26
+ constructor() {
27
+ this.hasPath = async (path) => {
28
+ let p = this.pathCache.get(path);
29
+ if (!p) {
30
+ p = this._hasPath(path);
31
+ this.pathCache.set(path, p);
32
+ }
33
+ return p;
34
+ };
35
+ this.isFile = async (name) => {
36
+ let p = this.fileCache.get(name);
37
+ if (!p) {
38
+ p = this._isFile(name);
39
+ this.fileCache.set(name, p);
40
+ }
41
+ return p;
42
+ };
43
+ this.readFile = async (name) => {
44
+ let p = this.readFileCache.get(name);
45
+ if (!p) {
46
+ p = this._readFile(name);
47
+ this.readFileCache.set(name, p);
48
+ }
49
+ return p;
50
+ };
51
+ /**
52
+ * Returns a list of Stat objects from the current working directory.
53
+ * @param dirPath The path of the directory to read.
54
+ * @param options.potentialFiles optional. Array of potential file names (relative to the path). If provided, these will be used to mark the filesystem caches as existing or not existing.
55
+ */
56
+ this.readdir = async (dirPath, options) => {
57
+ let p = this.readdirCache.get(dirPath);
58
+ if (!p) {
59
+ p = this._readdir(dirPath);
60
+ this.readdirCache.set(dirPath, p);
61
+ }
62
+ const directoryContent = await p;
63
+ const directoryFiles = /* @__PURE__ */ new Set();
64
+ for (const file of directoryContent) {
65
+ if (file.type === "file") {
66
+ this.fileCache.set(file.path, Promise.resolve(true));
67
+ this.pathCache.set(file.path, Promise.resolve(true));
68
+ directoryFiles.add(file.name);
69
+ }
70
+ }
71
+ if (options?.potentialFiles) {
72
+ const filesThatDoNotExist = options.potentialFiles.filter(
73
+ (path) => !directoryFiles.has(path)
74
+ );
75
+ for (const filePath of filesThatDoNotExist) {
76
+ const fullFilePath = dirPath === "/" ? filePath : import_path.posix.join(dirPath, filePath);
77
+ this.fileCache.set(fullFilePath, Promise.resolve(false));
78
+ this.pathCache.set(fullFilePath, Promise.resolve(false));
79
+ }
80
+ }
81
+ return p;
82
+ };
83
+ /**
84
+ * Changes the current directory to the specified path and returns a new instance of DetectorFilesystem.
85
+ */
86
+ this.chdir = (name) => {
87
+ return this._chdir(name);
88
+ };
89
+ /**
90
+ * Writes a file to the filesystem cache.
91
+ * @param name the name of the file to write
92
+ * @param content The content of the file
93
+ */
94
+ this.writeFile = async (name, content) => {
95
+ this.readFileCache.set(name, Promise.resolve(Buffer.from(content)));
96
+ this.fileCache.set(name, Promise.resolve(true));
97
+ this.pathCache.set(name, Promise.resolve(true));
98
+ };
99
+ this.pathCache = /* @__PURE__ */ new Map();
100
+ this.fileCache = /* @__PURE__ */ new Map();
101
+ this.readFileCache = /* @__PURE__ */ new Map();
102
+ this.readdirCache = /* @__PURE__ */ new Map();
103
+ }
110
104
  }
111
- exports.DetectorFilesystem = DetectorFilesystem;
112
- //# sourceMappingURL=filesystem.js.map
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ DetectorFilesystem
108
+ });
109
+ //# sourceMappingURL=filesystem.js.map