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

Commit2016dff

Browse files
committed
refactor: Extract package manager utility
1 parent2a937a1 commit2016dff

File tree

3 files changed

+46
-44
lines changed

3 files changed

+46
-44
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 & 44 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,27 +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-
letbunLockb=awaitfileExists(path.resolve(cwd,'bun.lockb'));
56-
letbunLock=awaitfileExists(path.resolve(cwd,'bun.lock'));
57-
letpackageLock=awaitfileExists(path.resolve(cwd,'package-lock.json'));
58-
59-
letpackageManager='npm';
60-
letinstallScript='npm install';
61-
if(yarnLock){
62-
installScript='yarn --frozen-lockfile';
63-
packageManager='yarn';
64-
}elseif(pnpmLock){
65-
installScript='pnpm install --frozen-lockfile';
66-
packageManager='pnpm';
67-
}elseif(bunLockb||bunLock){
68-
installScript='bun install --frozen-lockfile';
69-
packageManager='bun';
70-
}elseif(packageLock){
71-
installScript='npm ci';
72-
}
73-
52+
let{ packageManager, installScript}=awaitgetPackageManagerAndInstallScript(cwd);
7453
if(getInput('install-script')){
7554
installScript=getInput('install-script');
7655
}
@@ -128,27 +107,7 @@ async function run(octokit, context, token) {
128107

129108
startGroup(`[base] Install Dependencies`);
130109

131-
yarnLock=awaitfileExists(path.resolve(cwd,'yarn.lock'));
132-
pnpmLock=awaitfileExists(path.resolve(cwd,'pnpm-lock.yaml'));
133-
bunLockb=awaitfileExists(path.resolve(cwd,'bun.lockb'));
134-
bunLock=awaitfileExists(path.resolve(cwd,'bun.lock'));
135-
packageLock=awaitfileExists(path.resolve(cwd,'package-lock.json'));
136-
137-
packageManager='npm';
138-
installScript='npm install';
139-
if(yarnLock){
140-
installScript=`yarn --frozen-lockfile`;
141-
packageManager=`yarn`;
142-
}elseif(pnpmLock){
143-
installScript=`pnpm install --frozen-lockfile`;
144-
packageManager=`pnpm`;
145-
}elseif(bunLockb||bunLock){
146-
installScript=`bun install --frozen-lockfile`;
147-
packageManager=`bun`;
148-
}elseif(packageLock){
149-
installScript=`npm ci`;
150-
}
151-
110+
({ packageManager, installScript}=awaitgetPackageManagerAndInstallScript(cwd));
152111
if(getInput('install-script')){
153112
installScript=getInput('install-script');
154113
}

‎src/utils.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
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,bunLockBinaryExists,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,'bun.lock')),
15+
fileExists(path.resolve(cwd,'package-lock.json')),
16+
]);
17+
18+
letpackageManager='npm';
19+
letinstallScript='npm install';
20+
if(yarnLockExists){
21+
installScript='yarn --frozen-lockfile';
22+
packageManager='yarn';
23+
}elseif(pnpmLockExists){
24+
installScript='pnpm install --frozen-lockfile';
25+
packageManager='pnpm';
26+
}elseif(bunLockBinaryExists||bunLockExists){
27+
installScript='bun install --frozen-lockfile';
28+
packageManager='bun';
29+
}elseif(packageLockExists){
30+
installScript='npm ci';
31+
}
32+
33+
return{ packageManager, installScript};
34+
}
35+
436
/**
537
* Check if a given file exists and can be accessed.
638
*@param {string} filename

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp