Initial commit
This commit is contained in:
34
node_modules/astro/dist/cli/info/infra/yarn-package-manager.js
generated
vendored
Normal file
34
node_modules/astro/dist/cli/info/infra/yarn-package-manager.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
function getYarnOutputDepVersion(dependency, outputLine) {
|
||||
const parsed = JSON.parse(outputLine);
|
||||
for (const [key, value] of Object.entries(parsed.children)) {
|
||||
if (key.startsWith(`${dependency}@`)) {
|
||||
return `v${value.locator.split(":").pop()}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
class YarnPackageManager {
|
||||
name = "yarn";
|
||||
#commandExecutor;
|
||||
constructor({ commandExecutor }) {
|
||||
this.#commandExecutor = commandExecutor;
|
||||
}
|
||||
async getPackageVersion(name) {
|
||||
try {
|
||||
const { stdout } = await this.#commandExecutor.execute("yarn", ["why", name, "--json"], {
|
||||
shell: true
|
||||
});
|
||||
const hasUserDefinition = stdout.includes("workspace:.");
|
||||
for (const line of stdout.split("\n")) {
|
||||
if (hasUserDefinition && line.includes("workspace:."))
|
||||
return getYarnOutputDepVersion(name, line);
|
||||
if (!hasUserDefinition && line.includes("astro@"))
|
||||
return getYarnOutputDepVersion(name, line);
|
||||
}
|
||||
} catch {
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
YarnPackageManager
|
||||
};
|
||||
Reference in New Issue
Block a user