Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Yarn Cache Path From Yarn Config #131

Merged
merged 4 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions dist/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ async function main() {
},
);

const cachePaths = [".yarn", ".pnp.cjs", ".pnp.loader.mjs"];
const cachePaths = [
await yarn.getConfig("cacheFolder"),
await yarn.getConfig("deferredVersionFolder"),
await yarn.getConfig("installStatePath"),
await yarn.getConfig("patchFolder"),
await yarn.getConfig("pnpUnpluggedFolder"),
await yarn.getConfig("virtualFolder"),
".yarn",
".pnp.cjs",
".pnp.loader.mjs",
];

const cacheKey =
lockFileHash !== undefined
? `yarn-install-action-${os.type()}-${version}-${lockFileHash}`
Expand Down
14 changes: 13 additions & 1 deletion src/yarn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ async function enable() {
await exec("corepack", ["enable", "yarn"]);
}

async function getConfig(name) {
const prom = await getExecOutput(
"corepack",
["yarn", "config", name, "--json"],
{
silent: true,
},
);
const jsonData = (await prom).stdout;
return JSON.parse(jsonData).effective;
}

async function install() {
const env = process.env;

Expand All @@ -32,4 +44,4 @@ async function version() {
return res.stdout.trim();
}

export default { disableGlobalCache, enable, install, version };
export default { disableGlobalCache, enable, getConfig, install, version };
22 changes: 22 additions & 0 deletions src/yarn.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ it("should enable Yarn", async () => {
expect(exec).toHaveBeenCalledWith("corepack", ["enable", "yarn"]);
});

it("should get Yarn config", async () => {
const { getExecOutput } = await import("@actions/exec");
const yarn = (await import("./yarn.mjs")).default;

getExecOutput.mockResolvedValue({
stdout: `{"key":"globalFolder","effective":"/.yarn/berry","source":"<default>","description":"Folder where all system-global files are stored","type":"ABSOLUTE_PATH","default":"/.yarn/berry"}\n`,
});

const value = await yarn.getConfig("globalFolder");

expect(getExecOutput).toHaveBeenCalledTimes(1);
expect(getExecOutput).toHaveBeenCalledWith(
"corepack",
["yarn", "config", "globalFolder", "--json"],
{
silent: true,
},
);

expect(value).toEqual("/.yarn/berry");
});

it("should install package using Yarn", async () => {
const { exec } = await import("@actions/exec");
const yarn = (await import("./yarn.mjs")).default;
Expand Down
Loading