feat: add package_json_file option

Signed-off-by: Kengo TODA <skypencil@gmail.com>
This commit is contained in:
Kengo TODA committed 2023-07-08 07:02:46 +08:00
1 parent 11dd14d0c0
commit b27f801bf9
5 files changed
+16 -5

No files matched your search

+4
View File
@@ -38,6 +38,10 @@ If `run_install` is a YAML string representation of either an object or an array
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
### `package_json_file`
**Optional** File path to the `package.json` to read "packageManager" configutation. If not specified, `package.json` in the project root directory is used.
## Outputs
### `dest`
+5
View File
@@ -6,6 +6,7 @@ branding:
inputs:
version:
description: Version of pnpm to install
required: false
dest:
description: Where to store pnpm files
required: false
@@ -14,6 +15,10 @@ inputs:
description: If specified, run `pnpm install`
required: false
default: 'null'
package_json_file:
description: File path to the package.json to read "packageManager" configutation
required: false
default: 'package.json'
runs:
using: node16
main: dist/index.js
+1 -1
View File
@@ -1,4 +1,4 @@
(()=>{var e={9450:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});const i=t(8829);const n=a(t(8436));const s=a(t(2191));const o=a(t(3326));const l=a(t(9150));const u=a(t(9268));async function main(){const e=(0,n.default)();const r=(0,i.getState)("is_post");if(r==="true")return(0,u.default)(e);(0,i.saveState)("is_post","true");await(0,s.default)(e);console.log("Installation Completed!");(0,o.default)(e);(0,l.default)(e)}main().catch((e=>{console.error(e);(0,i.setFailed)(e)}))},8436:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});r.getInputs=void 0;const i=t(8829);const n=a(t(6906));const s=t(4264);const o={required:true};const parseInputPath=e=>(0,n.default)((0,i.getInput)(e,o));const getInputs=()=>({version:(0,i.getInput)("version"),dest:parseInputPath("dest"),runInstall:(0,s.parseRunInstall)("run_install")});r.getInputs=getInputs;r["default"]=r.getInputs},4264:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});r.parseRunInstall=void 0;const i=t(8829);const n=a(t(4376));const s=t(1236);const o=a(t(7282));const l=a(t(5379));const u={required:true};function parseRunInstall(e){const r=(0,s.load)((0,i.getInput)(e,u));const t=new n.default({allErrors:true});const a=t.compile(l.default);if(!a(r)){for(const e of a.errors){(0,i.error)(`with.run_install${e.dataPath}: ${e.message}`)}return o.default.exit(1)}if(!r)return[];if(r===true)return[{recursive:true}];if(Array.isArray(r))return r;return[r]}r.parseRunInstall=parseRunInstall},2191:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});r.install=r.runSelfInstaller=void 0;const i=t(8829);const n=a(t(5907));r.runSelfInstaller=n.default;async function install(e){(0,i.startGroup)("Running self-installer...");const r=await(0,n.default)(e);(0,i.endGroup)();if(r){return(0,i.setFailed)(`Something went wrong, self-installer exits with code ${r}`)}}r.install=install;r["default"]=install},5907:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});r.runSelfInstaller=void 0;const i=t(8829);const n=t(2081);const s=t(1690);const o=a(t(1017));const l=t(7282);async function runSelfInstaller(e){const{version:r,dest:t}=e;await(0,s.remove)(t);const a=o.default.join(t,"package.json");await(0,s.ensureFile)(a);await(0,s.writeFile)(a,JSON.stringify({private:true}));const u=await readTarget(r);const c=(0,n.spawn)(l.execPath,[o.default.join(__dirname,"pnpm.js"),"install",u,"--no-lockfile"],{cwd:t,stdio:["pipe","inherit","inherit"]});const f=await new Promise(((e,r)=>{c.on("error",r);c.on("close",e)}));if(f===0){const e=o.default.join(t,"node_modules/.bin");(0,i.addPath)(e);(0,i.exportVariable)("PNPM_HOME",e)}return f}r.runSelfInstaller=runSelfInstaller;async function readTarget(e){if(e)return`pnpm@${e}`;const{GITHUB_WORKSPACE:r}=process.env;if(!r){throw new Error(`No workspace is found.\nIf you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,\nplease run the actions/checkout before pnpm/action-setup.\nOtherwise, please specify the pnpm version in the action configuration.`)}const{packageManager:t}=JSON.parse(await(0,s.readFile)(o.default.join(r,"package.json"),"utf8"));if(typeof t!=="string"){throw new Error(`No pnpm version is specified.\nPlease specify it by one of the following ways:\n - in the GitHub Action config with the key "version"\n - in the package.json with the key "packageManager" (See https://nodejs.org/api/corepack.html)`)}if(!t.startsWith("pnpm@")){throw new Error("Invalid packageManager field in package.json")}return t}r["default"]=runSelfInstaller},3326:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r.setOutputs=void 0;const a=t(8829);const i=t(3763);function setOutputs(e){const r=(0,i.getBinDest)(e);(0,a.addPath)(r);(0,a.setOutput)("dest",e.dest);(0,a.setOutput)("bin_dest",r)}r.setOutputs=setOutputs;r["default"]=setOutputs},9150:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r.runPnpmInstall=void 0;const a=t(8829);const i=t(2081);const n=t(3763);function runPnpmInstall(e){const r=(0,n.patchPnpmEnv)(e);for(const t of e.runInstall){const e=["install"];if(t.recursive)e.unshift("recursive");if(t.args)e.push(...t.args);const n=["pnpm",...e].join(" ");(0,a.startGroup)(`Running ${n}...`);const{error:s,status:o}=(0,i.spawnSync)("pnpm",e,{stdio:"inherit",cwd:t.cwd,shell:true,env:r});(0,a.endGroup)();if(s){(0,a.setFailed)(s);continue}if(o){(0,a.setFailed)(`Command ${n} (cwd: ${t.cwd}) exits with st Line truncated
(()=>{var e={9450:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});const i=t(8829);const n=a(t(8436));const s=a(t(2191));const o=a(t(3326));const l=a(t(9150));const u=a(t(9268));async function main(){const e=(0,n.default)();const r=(0,i.getState)("is_post");if(r==="true")return(0,u.default)(e);(0,i.saveState)("is_post","true");await(0,s.default)(e);console.log("Installation Completed!");(0,o.default)(e);(0,l.default)(e)}main().catch((e=>{console.error(e);(0,i.setFailed)(e)}))},8436:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});r.getInputs=void 0;const i=t(8829);const n=a(t(6906));const s=t(4264);const o={required:true};const parseInputPath=e=>(0,n.default)((0,i.getInput)(e,o));const getInputs=()=>({version:(0,i.getInput)("version"),dest:parseInputPath("dest"),runInstall:(0,s.parseRunInstall)("run_install"),packageJsonFile:parseInputPath("package_json_file")});r.getInputs=getInputs;r["default"]=r.getInputs},4264:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});r.parseRunInstall=void 0;const i=t(8829);const n=a(t(4376));const s=t(1236);const o=a(t(7282));const l=a(t(5379));const u={required:true};function parseRunInstall(e){const r=(0,s.load)((0,i.getInput)(e,u));const t=new n.default({allErrors:true});const a=t.compile(l.default);if(!a(r)){for(const e of a.errors){(0,i.error)(`with.run_install${e.dataPath}: ${e.message}`)}return o.default.exit(1)}if(!r)return[];if(r===true)return[{recursive:true}];if(Array.isArray(r))return r;return[r]}r.parseRunInstall=parseRunInstall},2191:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});r.install=r.runSelfInstaller=void 0;const i=t(8829);const n=a(t(5907));r.runSelfInstaller=n.default;async function install(e){(0,i.startGroup)("Running self-installer...");const r=await(0,n.default)(e);(0,i.endGroup)();if(r){return(0,i.setFailed)(`Something went wrong, self-installer exits with code ${r}`)}}r.install=install;r["default"]=install},5907:function(e,r,t){"use strict";var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});r.runSelfInstaller=void 0;const i=t(8829);const n=t(2081);const s=t(1690);const o=a(t(1017));const l=t(7282);async function runSelfInstaller(e){const{version:r,dest:t,packageJsonFile:a}=e;await(0,s.remove)(t);const u=o.default.join(t,"package.json");await(0,s.ensureFile)(u);await(0,s.writeFile)(u,JSON.stringify({private:true}));const c=await readTarget(a,r);const f=(0,n.spawn)(l.execPath,[o.default.join(__dirname,"pnpm.js"),"install",c,"--no-lockfile"],{cwd:t,stdio:["pipe","inherit","inherit"]});const p=await new Promise(((e,r)=>{f.on("error",r);f.on("close",e)}));if(p===0){const e=o.default.join(t,"node_modules/.bin");(0,i.addPath)(e);(0,i.exportVariable)("PNPM_HOME",e)}return p}r.runSelfInstaller=runSelfInstaller;async function readTarget(e,r){if(r)return`pnpm@${r}`;const{GITHUB_WORKSPACE:t}=process.env;if(!t){throw new Error(`No workspace is found.\nIf you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,\nplease run the actions/checkout before pnpm/action-setup.\nOtherwise, please specify the pnpm version in the action configuration.`)}const{packageManager:a}=JSON.parse(await(0,s.readFile)(o.default.join(t,e),"utf8"));if(typeof a!=="string"){throw new Error(`No pnpm version is specified.\nPlease specify it by one of the following ways:\n - in the GitHub Action config with the key "version"\n - in the package.json with the key "packageManager" (See https://nodejs.org/api/corepack.html)`)}if(!a.startsWith("pnpm@")){throw new Error("Invalid packageManager field in package.json")}return a}r["default"]=runSelfInstaller},3326:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r.setOutputs=void 0;const a=t(8829);const i=t(3763);function setOutputs(e){const r=(0,i.getBinDest)(e);(0,a.addPath)(r);(0,a.setOutput)("dest",e.dest);(0,a.setOutput)("bin_dest",r)}r.setOutputs=setOutputs;r["default"]=setOutputs},9150:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r.runPnpmInstall=void 0;const a=t(8829);const i=t(2081);const n=t(3763);function runPnpmInstall(e){const r=(0,n.patchPnpmEnv)(e);for(const t of e.runInstall){const e=["install"];if(t.recursive)e.unshift("recursive");if(t.args)e.push(...t.args);const n=["pnpm",...e].join(" ");(0,a.startGroup)(`Running ${n}...`);const{error:s,status:o}=(0,i.spawnSync)("pnpm",e,{stdio:"inherit",cwd:t.cwd,shell:true,env:r});(0,a.endGroup)();if(s){(0,a.setFailed)(s);continue}if(oLine truncated
/*!
* expand-tilde <https://github.com/jonschlinkert/expand-tilde>
*
+2
View File
@@ -6,6 +6,7 @@ export interface Inputs {
readonly version?: string
readonly dest: string
readonly runInstall: RunInstall[]
readonly packageJsonFile: string
}
const options: InputOptions = {
@@ -18,6 +19,7 @@ export const getInputs = (): Inputs => ({
version: getInput('version'),
dest: parseInputPath('dest'),
runInstall: parseRunInstall('run_install'),
packageJsonFile: parseInputPath('package_json_file'),
})
export default getInputs
+4 -4
View File
@@ -6,7 +6,7 @@ import { execPath } from 'process'
import { Inputs } from '../inputs'
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest } = inputs
const { version, dest, packageJsonFile } = inputs
// prepare self install
await remove(dest)
@@ -15,7 +15,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
await writeFile(pkgJson, JSON.stringify({ private: true }))
// prepare target pnpm
const target = await readTarget(version)
const target = await readTarget(packageJsonFile, version)
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], {
cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'],
@@ -33,7 +33,7 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
return exitCode
}
async function readTarget(version?: string | undefined) {
async function readTarget(packageJsonFile: string, version?: string | undefined) {
if (version) return `pnpm@${version}`
const { GITHUB_WORKSPACE } = process.env
@@ -44,7 +44,7 @@ please run the actions/checkout before pnpm/action-setup.
Otherwise, please specify the pnpm version in the action configuration.`)
}
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, 'package.json'), 'utf8'))
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8'))
if (typeof packageManager !== 'string') {
throw new Error(`No pnpm version is specified.
Please specify it by one of the following ways: