mirror of
https://github.com/actions/setup-node.git
synced 2026-03-10 07:01:46 +08:00
Compare commits
5 Commits
c7a24d68f4
...
ac2419d29d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac2419d29d | ||
|
|
89d709d423 | ||
|
|
55b7d827be | ||
|
|
473cb1b506 | ||
|
|
574c6daa52 |
@ -7,6 +7,7 @@ import * as auth from '../src/authutil';
|
|||||||
import * as cacheUtils from '../src/cache-utils';
|
import * as cacheUtils from '../src/cache-utils';
|
||||||
|
|
||||||
let rcFile: string;
|
let rcFile: string;
|
||||||
|
let pkgJson: string;
|
||||||
|
|
||||||
describe('authutil tests', () => {
|
describe('authutil tests', () => {
|
||||||
const _runnerDir = path.join(__dirname, 'runner');
|
const _runnerDir = path.join(__dirname, 'runner');
|
||||||
@ -25,10 +26,12 @@ describe('authutil tests', () => {
|
|||||||
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
|
||||||
process.env['RUNNER_TEMP'] = tempDir;
|
process.env['RUNNER_TEMP'] = tempDir;
|
||||||
rcFile = path.join(tempDir, '.npmrc');
|
rcFile = path.join(tempDir, '.npmrc');
|
||||||
|
pkgJson = path.join(tempDir, 'package.json');
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await io.rmRF(rcFile);
|
await io.rmRF(rcFile);
|
||||||
|
await io.rmRF(pkgJson);
|
||||||
// if (fs.existsSync(rcFile)) {
|
// if (fs.existsSync(rcFile)) {
|
||||||
// fs.unlinkSync(rcFile);
|
// fs.unlinkSync(rcFile);
|
||||||
// }
|
// }
|
||||||
@ -113,6 +116,15 @@ describe('authutil tests', () => {
|
|||||||
expect(rc['always-auth']).toBe('false');
|
expect(rc['always-auth']).toBe('false');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Automatically configures npm scope from package.json', async () => {
|
||||||
|
process.env['INPUT_SCOPE'] = '';
|
||||||
|
fs.writeFileSync(pkgJson, '{"name":"@myscope/mypackage"}');
|
||||||
|
await auth.configAuthentication('https://registry.npmjs.org', '');
|
||||||
|
|
||||||
|
const rc = readRcFile(rcFile);
|
||||||
|
expect(rc['@myscope:registry']).toBe('https://registry.npmjs.org/');
|
||||||
|
});
|
||||||
|
|
||||||
it('Sets up npmrc for always-auth true', async () => {
|
it('Sets up npmrc for always-auth true', async () => {
|
||||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||||
expect(fs.statSync(rcFile)).toBeDefined();
|
expect(fs.statSync(rcFile)).toBeDefined();
|
||||||
|
|||||||
13
package-lock.json
generated
13
package-lock.json
generated
@ -34,7 +34,7 @@
|
|||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-circus": "^29.7.0",
|
"jest-circus": "^29.7.0",
|
||||||
"jest-each": "^29.7.0",
|
"jest-each": "^29.7.0",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^3.6.2",
|
||||||
"ts-jest": "^29.4.1",
|
"ts-jest": "^29.4.1",
|
||||||
"typescript": "^5.4.2"
|
"typescript": "^5.4.2"
|
||||||
},
|
},
|
||||||
@ -4962,15 +4962,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/prettier": {
|
"node_modules/prettier": {
|
||||||
"version": "2.8.8",
|
"version": "3.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz",
|
||||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
"integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"prettier": "bin-prettier.js"
|
"prettier": "bin/prettier.cjs"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.13.0"
|
"node": ">=14"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||||
|
|||||||
@ -53,7 +53,7 @@
|
|||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-circus": "^29.7.0",
|
"jest-circus": "^29.7.0",
|
||||||
"jest-each": "^29.7.0",
|
"jest-each": "^29.7.0",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^3.6.2",
|
||||||
"ts-jest": "^29.4.1",
|
"ts-jest": "^29.4.1",
|
||||||
"typescript": "^5.4.2"
|
"typescript": "^5.4.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,12 @@ function writeRegistryToFile(
|
|||||||
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
|
if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) {
|
||||||
scope = github.context.repo.owner;
|
scope = github.context.repo.owner;
|
||||||
}
|
}
|
||||||
|
if (!scope) {
|
||||||
|
const namePrefix = packageJson('name')?.match(/^(@[^/]+)\//);
|
||||||
|
if (namePrefix) {
|
||||||
|
scope = namePrefix[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (scope && scope[0] != '@') {
|
if (scope && scope[0] != '@') {
|
||||||
scope = '@' + scope;
|
scope = '@' + scope;
|
||||||
}
|
}
|
||||||
@ -57,3 +63,14 @@ function writeRegistryToFile(
|
|||||||
process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'
|
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`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -167,14 +167,12 @@ const getCacheDirectoriesFromCacheDependencyPath = async (
|
|||||||
packageManagerInfo: PackageManagerInfo,
|
packageManagerInfo: PackageManagerInfo,
|
||||||
cacheDependencyPath: string
|
cacheDependencyPath: string
|
||||||
): Promise<string[]> => {
|
): Promise<string[]> => {
|
||||||
const projectDirectories = await getProjectDirectoriesFromCacheDependencyPath(
|
const projectDirectories =
|
||||||
cacheDependencyPath
|
await getProjectDirectoriesFromCacheDependencyPath(cacheDependencyPath);
|
||||||
);
|
|
||||||
const cacheFoldersPaths = await Promise.all(
|
const cacheFoldersPaths = await Promise.all(
|
||||||
projectDirectories.map(async projectDirectory => {
|
projectDirectories.map(async projectDirectory => {
|
||||||
const cacheFolderPath = await packageManagerInfo.getCacheFolderPath(
|
const cacheFolderPath =
|
||||||
projectDirectory
|
await packageManagerInfo.getCacheFolderPath(projectDirectory);
|
||||||
);
|
|
||||||
core.debug(
|
core.debug(
|
||||||
`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`
|
`${packageManagerInfo.name}'s cache folder "${cacheFolderPath}" configured for the directory "${projectDirectory}"`
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user