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

Add automatic corepack support for node v14 + #482

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
add check for packageManager field
  • Loading branch information
Ethan Arrowood committed May 5, 2022
commit 48ed97757dab49189b7fbe7f97ffdcc2b7e78962
8 changes: 4 additions & 4 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -89,19 +89,19 @@ describe('setup-node', () => {
warningSpy = jest.spyOn(core, 'warning');
cnSpy.mockImplementation(line => {
// uncomment to debug
process.stderr.write('write:' + line + '\n');
// process.stderr.write('write:' + line + '\n');
});
logSpy.mockImplementation(line => {
// uncomment to debug
process.stderr.write('log:' + line + '\n');
// process.stderr.write('log:' + line + '\n');
});
dbgSpy.mockImplementation(msg => {
// uncomment to see debug output
process.stderr.write(msg + '\n');
// process.stderr.write(msg + '\n');
});
warningSpy.mockImplementation(msg => {
// uncomment to debug
process.stderr.write('log:' + msg + '\n');
// process.stderr.write('log:' + msg + '\n');
});
});

23 changes: 18 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -47,11 +47,24 @@ export async function run() {
}

if (cache && isCacheFeatureAvailable()) {
if (semver.gte(version, '14.19.0')) {
try {
core.info(await getCommandOutput('corepack enable'));
} catch (err) {
core.warning(`Failed to enable corepack. Error: ${err.message}`)
const pkgJsonPath = path.join(__dirname, '..', 'package.json');
try {
const stat = await fs.promises.stat(pkgJsonPath);
if (stat.isFile()) {
const packageJson = JSON.parse(await fs.promises.readFile(pkgJsonPath, 'utf8'))
const packageManager = packageJson.packageManager;

if (packageManager !== undefined && semver.gte(version, '14.19.0')) {
try {
core.info(await getCommandOutput('corepack enable'));
} catch (err) {
core.warning(`Failed to enable corepack. Error: ${err.message}`)
}
}
}
} catch (err) {
if (err instanceof Error && (err as NodeJS.ErrnoException).code === 'ENOENT') {
core.warning(`Cannot find package.json at path ${pkgJsonPath}`)
}
}
const cacheDependencyPath = core.getInput('cache-dependency-path');