add check for packageManager field
parent
9ca6fa06b4
commit
48ed97757d
|
@ -89,19 +89,19 @@ describe('setup-node', () => {
|
||||||
warningSpy = jest.spyOn(core, 'warning');
|
warningSpy = jest.spyOn(core, 'warning');
|
||||||
cnSpy.mockImplementation(line => {
|
cnSpy.mockImplementation(line => {
|
||||||
// uncomment to debug
|
// uncomment to debug
|
||||||
process.stderr.write('write:' + line + '\n');
|
// process.stderr.write('write:' + line + '\n');
|
||||||
});
|
});
|
||||||
logSpy.mockImplementation(line => {
|
logSpy.mockImplementation(line => {
|
||||||
// uncomment to debug
|
// uncomment to debug
|
||||||
process.stderr.write('log:' + line + '\n');
|
// process.stderr.write('log:' + line + '\n');
|
||||||
});
|
});
|
||||||
dbgSpy.mockImplementation(msg => {
|
dbgSpy.mockImplementation(msg => {
|
||||||
// uncomment to see debug output
|
// uncomment to see debug output
|
||||||
process.stderr.write(msg + '\n');
|
// process.stderr.write(msg + '\n');
|
||||||
});
|
});
|
||||||
warningSpy.mockImplementation(msg => {
|
warningSpy.mockImplementation(msg => {
|
||||||
// uncomment to debug
|
// uncomment to debug
|
||||||
process.stderr.write('log:' + msg + '\n');
|
// process.stderr.write('log:' + msg + '\n');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
23
src/main.ts
23
src/main.ts
|
@ -47,11 +47,24 @@ export async function run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache && isCacheFeatureAvailable()) {
|
if (cache && isCacheFeatureAvailable()) {
|
||||||
if (semver.gte(version, '14.19.0')) {
|
const pkgJsonPath = path.join(__dirname, '..', 'package.json');
|
||||||
try {
|
try {
|
||||||
core.info(await getCommandOutput('corepack enable'));
|
const stat = await fs.promises.stat(pkgJsonPath);
|
||||||
} catch (err) {
|
if (stat.isFile()) {
|
||||||
core.warning(`Failed to enable corepack. Error: ${err.message}`)
|
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');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
|
|
Loading…
Reference in New Issue