@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.
- package/dist/detect-builders.js +701 -748
- package/dist/detect-builders.js.map +7 -1
- package/dist/detect-file-system-api.js +177 -154
- package/dist/detect-file-system-api.js.map +7 -1
- package/dist/detect-framework.js +196 -143
- package/dist/detect-framework.js.map +7 -1
- package/dist/detectors/filesystem.js +106 -109
- package/dist/detectors/filesystem.js.map +7 -1
- package/dist/detectors/local-file-system-detector.js +90 -63
- package/dist/detectors/local-file-system-detector.js.map +7 -1
- package/dist/get-project-paths.js +74 -35
- package/dist/get-project-paths.js.map +7 -1
- package/dist/index.js +85 -48
- package/dist/index.js.map +7 -1
- package/dist/is-official-runtime.js +34 -19
- package/dist/is-official-runtime.js.map +7 -1
- package/dist/monorepos/get-monorepo-default-settings.js +154 -150
- package/dist/monorepos/get-monorepo-default-settings.js.map +7 -1
- package/dist/monorepos/monorepo-managers.js +112 -100
- package/dist/monorepos/monorepo-managers.js.map +7 -1
- package/dist/package-managers/package-managers.js +79 -55
- package/dist/package-managers/package-managers.js.map +7 -1
- package/dist/workspaces/get-glob-fs.js +90 -66
- package/dist/workspaces/get-glob-fs.js.map +7 -1
- package/dist/workspaces/get-workspace-package-paths.js +130 -79
- package/dist/workspaces/get-workspace-package-paths.js.map +7 -1
- package/dist/workspaces/get-workspaces.js +71 -31
- package/dist/workspaces/get-workspaces.js.map +7 -1
- package/dist/workspaces/workspace-managers.js +104 -92
- package/dist/workspaces/workspace-managers.js.map +7 -1
- package/package.json +4 -4
package/dist/detect-framework.js
CHANGED
|
@@ -1,166 +1,219 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 (
|
|
15
|
-
|
|
56
|
+
if (!path && !matchPackage) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Must specify either "path" or "matchPackage" in detector for "${framework.slug}".`
|
|
59
|
+
);
|
|
16
60
|
}
|
|
17
|
-
|
|
18
|
-
|
|
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 (
|
|
63
|
-
|
|
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 (
|
|
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
|
-
|
|
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(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
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
|
-
{
|
|
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,MAAI,SAAS,UAAa,CAAC,MAAM,QAAQ,IAAI,GAAG;AAC9C;AAAA,EACF;AAEA,QAAM,QAAQ,OAAO;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,EACF,MAAgE;AAC9D,QAAI,gBAAgB,cAAc;AAChC,YAAM,IAAI;AAAA,QACR,8EAA8E,UAAU,IAAI;AAAA,MAC9F;AAAA,IACF;AACA,QAAI,gBAAgB,MAAM;AACxB,YAAM,IAAI;AAAA,QACR,sEAAsE,UAAU,IAAI;AAAA,MACtF;AAAA,IACF;AAEA,QAAI,CAAC,QAAQ,CAAC,cAAc;AAC1B,YAAM,IAAI;AAAA,QACR,iEAAiE,UAAU,IAAI;AAAA,MACjF;AAAA,IACF;AAEA,QAAI,CAAC,MAAM;AACT,aAAO;AAAA,IACT;AAEA,QAAI,cAAc;AAChB,qBAAe,uCAAuC,YAAY;AAAA,IACpE;AAEA,QAAK,MAAM,GAAG,QAAQ,IAAI,MAAO,OAAO;AACtC;AAAA,IACF;AAEA,QAAI,cAAc;AAChB,UAAK,MAAM,GAAG,OAAO,IAAI,MAAO,OAAO;AACrC;AAAA,MACF;AAEA,YAAM,QAAQ,IAAI,OAAO,cAAc,GAAG;AAC1C,YAA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D,MAAI,CAAC,mBAAmB,cAAc;AACpC;AAAA,EACF;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,kBAAkB;AAAA,EACpB;AACF;AAEA,SAAS,uBACP,KACA,aACoB;AACpB,MAAI;AACF,UAAM,SAAS,YAAY,WAAW;AACtC,eAAO,gCAAU,KAAK,CAAC,MAAM,MAAM,GAAG;AAAA,MACpC,UAAU;AAAA,IACZ,CAAC,EAAE,OAAO,KAAK;AAAA,EACjB,SAAS,OAAO;AACd,YAAQ;AAAA,MACN,kDAAkD,WAAW,MAAM,KAAK;AAAA,IAC1E;AAAA,EACF;AAEA;AACF;",
|
|
6
|
+
"names": ["matches"]
|
|
7
|
+
}
|
|
@@ -1,112 +1,109 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
112
|
-
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
DetectorFilesystem
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=filesystem.js.map
|