Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit27015cf

Browse files
committed
refactor: Extract package manager utility
1 parent946a292 commit27015cf

File tree

3 files changed

+45
-41
lines changed

3 files changed

+45
-41
lines changed

‎jsconfig.json‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"target":"ESNext",
4+
"module":"ESNext",
5+
"moduleResolution":"NodeNext",
6+
"allowJs":true,
7+
"checkJs":true,
8+
"resolveJsonModule":true,
9+
"noEmit":true
10+
}
11+
}

‎src/index.js‎

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
importpathfrom'path';
21
import{getInput,setFailed,startGroup,endGroup,debug}from'@actions/core';
32
import{context,getOctokit}from'@actions/github';
43
import{exec}from'@actions/exec';
54
importSizePluginfrom'size-plugin-core';
6-
import{fileExists,diffTable,toBool,stripHash}from'./utils.js';
5+
import{getPackageManagerAndInstallScript,diffTable,toBool,stripHash}from'./utils.js';
76

87
/**
98
*@typedef {ReturnType<typeof import("@actions/github").getOctokit>} Octokit
@@ -50,26 +49,7 @@ async function run(octokit, context, token) {
5049
constbuildScript=getInput('build-script')||'build';
5150
constcwd=process.cwd();
5251

53-
letyarnLock=awaitfileExists(path.resolve(cwd,'yarn.lock'));
54-
letpnpmLock=awaitfileExists(path.resolve(cwd,'pnpm-lock.yaml'));
55-
letbunLock=awaitfileExists(path.resolve(cwd,'bun.lockb'));
56-
letpackageLock=awaitfileExists(path.resolve(cwd,'package-lock.json'));
57-
58-
letpackageManager='npm';
59-
letinstallScript='npm install';
60-
if(yarnLock){
61-
installScript='yarn --frozen-lockfile';
62-
packageManager='yarn';
63-
}elseif(pnpmLock){
64-
installScript='pnpm install --frozen-lockfile';
65-
packageManager='pnpm';
66-
}elseif(bunLock){
67-
installScript='bun install --frozen-lockfile';
68-
packageManager='bun';
69-
}elseif(packageLock){
70-
installScript='npm ci';
71-
}
72-
52+
let{ packageManager, installScript}=awaitgetPackageManagerAndInstallScript(cwd);
7353
if(getInput('install-script')){
7454
installScript=getInput('install-script');
7555
}
@@ -127,26 +107,8 @@ async function run(octokit, context, token) {
127107

128108
startGroup(`[base] Install Dependencies`);
129109

130-
yarnLock=awaitfileExists(path.resolve(cwd,'yarn.lock'));
131-
pnpmLock=awaitfileExists(path.resolve(cwd,'pnpm-lock.yaml'));
132-
bunLock=awaitfileExists(path.resolve(cwd,'bun.lockb'));
133-
packageLock=awaitfileExists(path.resolve(cwd,'package-lock.json'));
134-
135-
packageManager='npm';
136-
installScript='npm install';
137-
if(yarnLock){
138-
installScript=`yarn --frozen-lockfile`;
139-
packageManager=`yarn`;
140-
}elseif(pnpmLock){
141-
installScript=`pnpm install --frozen-lockfile`;
142-
packageManager=`pnpm`;
143-
}elseif(bunLock){
144-
installScript=`bun install --frozen-lockfile`;
145-
packageManager=`bun`;
146-
}elseif(packageLock){
147-
installScript=`npm ci`;
148-
}
149110

111+
({ packageManager, installScript}=awaitgetPackageManagerAndInstallScript(cwd));
150112
if(getInput('install-script')){
151113
installScript=getInput('install-script');
152114
}

‎src/utils.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
importfsfrom'fs';
2+
importpathfrom'path';
23
importprettyBytesfrom'pretty-bytes';
34

5+
/**
6+
*@param {string} cwd
7+
*@returns {Promise<{ packageManager: string, installScript: string }>}
8+
*/
9+
exportasyncfunctiongetPackageManagerAndInstallScript(cwd){
10+
const[yarnLockExists,pnpmLockExists,bunLockExists,packageLockExists]=awaitPromise.all([
11+
fileExists(path.resolve(cwd,'yarn.lock')),
12+
fileExists(path.resolve(cwd,'pnpm-lock.yaml')),
13+
fileExists(path.resolve(cwd,'bun.lockb')),
14+
fileExists(path.resolve(cwd,'package-lock.json')),
15+
]);
16+
17+
letpackageManager='npm';
18+
letinstallScript='npm install';
19+
if(yarnLockExists){
20+
installScript='yarn --frozen-lockfile';
21+
packageManager='yarn';
22+
}elseif(pnpmLockExists){
23+
installScript='pnpm install --frozen-lockfile';
24+
packageManager='pnpm';
25+
}elseif(bunLockExists){
26+
installScript='bun install --frozen-lockfile';
27+
packageManager='bun';
28+
}elseif(packageLockExists){
29+
installScript='npm ci';
30+
}
31+
32+
return{ packageManager, installScript};
33+
}
34+
435
/**
536
* Check if a given file exists and can be accessed.
637
*@param {string} filename

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp