mirror of
https://github.com/actions/setup-node.git
synced 2026-02-12 16:24:48 +08:00
Refactor and test
This commit is contained in:
@@ -26,9 +26,9 @@ function writeRegistryToFile(
|
||||
scope = github.context.repo.owner;
|
||||
}
|
||||
if (!scope) {
|
||||
let namePrefix = require('./package').name.match('@[^/]+');
|
||||
const namePrefix = packageJson('name')?.match(/^(@[^/]+)\//);
|
||||
if (namePrefix) {
|
||||
scope = namePrefix[0];
|
||||
scope = namePrefix[1];
|
||||
}
|
||||
}
|
||||
if (scope && scope[0] != '@') {
|
||||
@@ -63,3 +63,14 @@ function writeRegistryToFile(
|
||||
process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'
|
||||
);
|
||||
}
|
||||
|
||||
function packageJson(prop: string){
|
||||
const pkgPath: string = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), 'package.json');
|
||||
try {
|
||||
const json = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
||||
|
||||
return prop ? json[prop] : json;
|
||||
} catch(e) {
|
||||
core.debug(`Unable to read from package.json`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user