Use pnpm.js to install pnpm

This commit is contained in:
khai96_ committed 2021-03-23 12:42:43 +07:00
1 parent b7b9d6344b
commit aefcd1e623
12 files changed
+64 -37

No files matched your search

-8
View File
@@ -11,14 +11,6 @@ inputs:
description: Where to store PNPM files
required: false
default: ~/setup-pnpm
bin_dest:
description: Where to store executables (pnpm and pnpx commands)
required: false
default: ~/setup-pnpm/.bin
registry:
description: Registry to download PNPM from
required: false
default: https://registry.npmjs.com
run_install:
description: If specified, run `pnpm install`
required: false
+1 -1
View File
@@ -1 +1 @@
module.exports=(()=>{var __webpack_modules__={2492:e=>{"use strict";e.exports=JSON.parse('{"anyOf":[{"$ref":"#/definitions/RunInstall"},{"type":"array","items":{"$ref":"#/definitions/RunInstall"}},{"type":["null","boolean"]}],"definitions":{"RunInstall":{"type":"object","properties":{"recursive":{"type":"boolean"},"cwd":{"type":"string"},"args":{"type":"array","items":{"type":"string"}}}}},"$schema":"http://json-schema.org/draft-07/schema#"}')},6011:function(e,n,f){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});const l=f(6832);const s=r(f(8527));const v=r(f(3406));const c=r(f(9282));const p=r(f(6866));const g=r(f(2726));async function main(){const e=s.default();const n=l.getState("is_post");if(n==="true")return g.default(e);l.saveState("is_post","true");await c.default(e);console.log("Installation Completed!");v.default(e);p.default(e)}main().catch(e=>{console.error(e);l.setFailed(e)})},8527:function(e,n,f){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});n.getInputs=void 0;const l=f(6832);const s=r(f(4010));const v=f(986);const c={required:true};const p=e=>s.default(l.getInput(e,c));const g=()=>({version:l.getInput("version",c),dest:p("dest"),binDest:p("bin_dest"),registry:l.getInput("registry",c),runInstall:v.parseRunInstall("run_install")});n.getInputs=g;n.default=n.getInputs},986:function(e,n,f){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});n.parseRunInstall=void 0;const l=r(f(1765));const s=f(9520);const v=r(f(8469));const c=f(6832);const p=r(f(2492));const g={required:true};function parseRunInstall(e){const n=s.load(c.getInput(e,g));const f=new v.default({allErrors:true});const r=f.compile(p.default);if(!r(n)){for(const e of r.errors){c.error(`with.run_install${e.dataPath}: ${e.message}`)}return l.default.exit(1)}if(!n)return[];if(n===true)return[{recursive:true}];if(Array.isArray(n))return n;return[n]}n.parseRunInstall=parseRunInstall},9282:function(e,n,f){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});n.install=n.runSelfInstaller=void 0;const l=f(6832);const s=r(f(7388));n.runSelfInstaller=s.default;async function install(e){l.startGroup("Running self-installer...");const n=await s.default(e);l.endGroup();if(n){return l.setFailed(`Something does wrong, self-installer exits with code ${n}`)}}n.install=install;n.default=install},7388:(e,n,f)=>{"use strict";Object.defineProperty(n,"__esModule",{value:true});n.runSelfInstaller=void 0;const r=f(3129);const l=f(1765);const s=f(3189);async function runSelfInstaller(e){const n=r.spawn(l.execPath,{env:{PNPM_VERSION:e.version,PNPM_DEST:e.dest,PNPM_BIN_DEST:e.binDest,PNPM_REGISTRY:e.registry},stdio:["pipe","inherit","inherit"]});const f=await s.downloadSelfInstaller();f.body.pipe(n.stdin);return new Promise((e,f)=>{n.on("error",f);n.on("close",e)})}n.runSelfInstaller=runSelfInstaller;n.default=runSelfInstaller},3406:(e,n,f)=>{"use strict";Object.defineProperty(n,"__esModule",{value:true});n.setOutputs=void 0;const r=f(6832);function setOutputs(e){r.addPath(e.binDest);r.setOutput("dest",e.dest);r.setOutput("bin_dest",e.binDest)}n.setOutputs=setOutputs;n.default=setOutputs},6866:(e,n,f)=>{"use strict";Object.defineProperty(n,"__esModule",{value:true});n.runPnpmInstall=void 0;const r=f(3129);const l=f(6832);const s=f(1630);function runPnpmInstall(e){const n=s.patchPnpmEnv(e);for(const f of e.runInstall){const e=["install"];if(f.recursive)e.unshift("recursive");if(f.args)e.push(...f.args);const s=["pnpm",...e].join(" ");l.startGroup(`Running ${s}...`);const{error:v,status:c}=r.spawnSync("pnpm",e,{stdio:"inherit",cwd:f.cwd,shell:true,env:n});l.endGroup();if(v){l.setFailed(v);continue}if(c){l.setFailed(`Command ${s} (cwd: ${f.cwd}) exits with status ${c}`);continue}}}n.runPnpmInstall=runPnpmInstall;n.default=runPnpmInstall},2726:(e,n,f)=>{"use strict";Object.defineProperty(n,"__esModule",{value:true});n.pruneStore=void 0;const r=f(3129);const l=f(6832);const s=f(1630);function pruneStore(e){if(e.runInstall.length===0){console.log("Pruning is unnecessary.");return}l.startGroup("Running pnpm store prune...");const{error:n,status:f}=r.spawnSync("pnpm",["store","prune"],{stdio:"inherit",shell:true,env:s.patchPnpmEnv(e)});l.endGroup();if(n){l.warning(n);return}if(f){l.warning(`command pnpm store prune exits with code ${f}`);return}}n.pruneStore=pruneStore;n.default=pruneStore},3893:function(e,n,f){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});n.downloadSelfInstaller=void 0;const l=r(f(2192));const s=r(f(6174));const v=()=>l.default(s.default);n.downloadSelfInstaller=v;n.defaLine truncated
module.exports=(()=>{var __webpack_modules__={2492:e=>{"use strict";e.exports=JSON.parse('{"anyOf":[{"$ref":"#/definitions/RunInstall"},{"type":"array","items":{"$ref":"#/definitions/RunInstall"}},{"type":["null","boolean"]}],"definitions":{"RunInstall":{"type":"object","properties":{"recursive":{"type":"boolean"},"cwd":{"type":"string"},"args":{"type":"array","items":{"type":"string"}}}}},"$schema":"http://json-schema.org/draft-07/schema#"}')},6011:function(e,n,r){"use strict";var f=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});const s=r(6832);const l=f(r(8527));const c=f(r(3406));const i=f(r(9282));const v=f(r(6866));const p=f(r(2726));async function main(){const e=l.default();const n=s.getState("is_post");if(n==="true")return p.default(e);s.saveState("is_post","true");await i.default(e);console.log("Installation Completed!");c.default(e);v.default(e)}main().catch(e=>{console.error(e);s.setFailed(e)})},8527:function(e,n,r){"use strict";var f=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});n.getInputs=void 0;const s=r(6832);const l=f(r(4010));const c=r(986);const i={required:true};const v=e=>l.default(s.getInput(e,i));const p=()=>({version:s.getInput("version",i),dest:v("dest"),runInstall:c.parseRunInstall("run_install")});n.getInputs=p;n.default=n.getInputs},986:function(e,n,r){"use strict";var f=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});n.parseRunInstall=void 0;const s=f(r(1765));const l=r(9520);const c=f(r(8469));const i=r(6832);const v=f(r(2492));const p={required:true};function parseRunInstall(e){const n=l.load(i.getInput(e,p));const r=new c.default({allErrors:true});const f=r.compile(v.default);if(!f(n)){for(const e of f.errors){i.error(`with.run_install${e.dataPath}: ${e.message}`)}return s.default.exit(1)}if(!n)return[];if(n===true)return[{recursive:true}];if(Array.isArray(n))return n;return[n]}n.parseRunInstall=parseRunInstall},9282:function(e,n,r){"use strict";var f=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});n.install=n.runSelfInstaller=void 0;const s=r(6832);const l=f(r(7388));n.runSelfInstaller=l.default;async function install(e){s.startGroup("Running self-installer...");const n=await l.default(e);s.endGroup();if(n){return s.setFailed(`Something does wrong, self-installer exits with code ${n}`)}}n.install=install;n.default=install},7388:function(e,n,r){"use strict";var f=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:true});n.runSelfInstaller=void 0;const s=r(3129);const l=r(1765);const c=r(5622);const i=r(4240);const v=f(r(2192));async function runSelfInstaller(e){const{version:n,dest:r}=e;const f=n?`pnpm@${n}`:"pnpm";const p=c.join(r,"package.json");await i.remove(r);await i.ensureFile(p);await i.writeFile(p,JSON.stringify({private:true}));const d=s.spawn(l.execPath,["-","install",f,"--no-lockfile"],{stdio:["pipe","inherit","inherit"]});const a=await v.default("https://pnpm.js.org/pnpm.js");a.body.pipe(d.stdin);return new Promise((e,n)=>{d.on("error",n);d.on("close",e)})}n.runSelfInstaller=runSelfInstaller;n.default=runSelfInstaller},3406:(e,n,r)=>{"use strict";Object.defineProperty(n,"__esModule",{value:true});n.setOutputs=void 0;const f=r(6832);const s=r(1630);function setOutputs(e){const n=s.getBinDest(e);f.addPath(n);f.setOutput("dest",e.dest);f.setOutput("bin_dest",n)}n.setOutputs=setOutputs;n.default=setOutputs},6866:(e,n,r)=>{"use strict";Object.defineProperty(n,"__esModule",{value:true});n.runPnpmInstall=void 0;const f=r(3129);const s=r(6832);const l=r(1630);function runPnpmInstall(e){const n=l.patchPnpmEnv(e);for(const r of e.runInstall){const e=["install"];if(r.recursive)e.unshift("recursive");if(r.args)e.push(...r.args);const l=["pnpm",...e].join(" ");s.startGroup(`Running ${l}...`);const{error:c,status:i}=f.spawnSync("pnpm",e,{stdio:"inherit",cwd:r.cwd,shell:true,env:n});s.endGroup();if(c){s.setFailed(c);continue}if(i){s.setFailed(`Command ${l} (cwd: ${r.cwd}) exits with status ${i}`);continue}}}n.runPnpmInstall=runPnpmInstall;n.default=runPnpmInstall},2726:(e,n,r)=>{"use strict";Object.defineProperty(n,"__esModule",{value:true});n.pruneStore=void 0;const f=r(3129);const s=r(6832);const l=r(1630);function pruneStore(e){if(e.runInstall.length===0){console.log("Pruning is unnecessary.");return}s.startGroup("Running pnpm store prune...");const{error:n,status:r}=f.spawnSync("pnpm",["store","prune"],{stdio:"inherit",shell:true,env:l.patchPnpmEnv(e)});s.endGroup();if(n){s.warning(n);return}if(r){s.warning(`command pnpm store prune exits with code ${r}`);return}}n.pruneStore=pruneStore;n.default=pruneStore},1630:function(e,n,r){"use strict";var f=this&&this.__importDefault||functionLine truncated
+2
View File
@@ -11,10 +11,12 @@
"expand-tilde": "^2.0.2",
"js-yaml": "^4.0.0",
"ajv": "^6.12.5",
"fs-extra": "^9.1.0",
"@actions/core": "^1.2.6",
"@types/expand-tilde": "^2.0.0",
"@types/node-fetch": "^2.5.8",
"@types/js-yaml": "^4.0.0",
"@types/fs-extra": "^9.0.8",
"@types/node": "^14.14.35"
},
"devDependencies": {
+41 -1
View File
@@ -1,11 +1,13 @@
dependencies:
'@actions/core': 1.2.6
'@types/expand-tilde': 2.0.0
'@types/fs-extra': 9.0.8
'@types/js-yaml': 4.0.0
'@types/node': 14.14.35
'@types/node-fetch': 2.5.8
ajv: 6.12.6
expand-tilde: 2.0.2
fs-extra: 9.1.0
js-yaml: 4.0.0
node-fetch: 2.6.1
devDependencies:
@@ -175,6 +177,12 @@ packages:
dev: true
resolution:
integrity: sha512-UoOfVEzAUpeSPmjm7h1uk5MH6KZma2z2O7a75onTGjnNvAvMVrPzPL/vBbT65iIGHWj6rokwfmYcmxmlSf2uwg==
/@types/fs-extra/9.0.8:
dependencies:
'@types/node': 14.14.35
dev: false
resolution:
integrity: sha512-bnlTVTwq03Na7DpWxFJ1dvnORob+Otb8xHyUqUWhqvz/Ksg8+JXPlR52oeMSZ37YEOa5PyccbgUNutiQdi13TA==
/@types/js-yaml/3.12.3:
dev: true
resolution:
@@ -278,6 +286,12 @@ packages:
dev: false
resolution:
integrity: sha1-x57Zf380y48robyXkLzDZkdLS3k=
/at-least-node/1.0.0:
dev: false
engines:
node: '>= 4.0.0'
resolution:
integrity: sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
/balanced-match/1.0.0:
dev: true
resolution:
@@ -444,6 +458,17 @@ packages:
node: '>=6 <7 || >=8'
resolution:
integrity: sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
/fs-extra/9.1.0:
dependencies:
at-least-node: 1.0.0
graceful-fs: 4.2.3
jsonfile: 6.1.0
universalify: 2.0.0
dev: false
engines:
node: '>=10'
resolution:
integrity: sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==
/fs.realpath/1.0.0:
dev: true
resolution:
@@ -466,7 +491,6 @@ packages:
resolution:
integrity: sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
/graceful-fs/4.2.3:
dev: true
resolution:
integrity: sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==
/homedir-polyfill/1.0.3:
@@ -530,6 +554,14 @@ packages:
graceful-fs: 4.2.3
resolution:
integrity: sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=
/jsonfile/6.1.0:
dependencies:
universalify: 2.0.0
dev: false
optionalDependencies:
graceful-fs: 4.2.3
resolution:
integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
/jsonify/0.0.0:
dev: true
resolution:
@@ -731,6 +763,12 @@ packages:
node: '>= 4.0.0'
resolution:
integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
/universalify/2.0.0:
dev: false
engines:
node: '>= 10.0.0'
resolution:
integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==
/uri-js/4.2.2:
dependencies:
punycode: 2.1.1
@@ -828,12 +866,14 @@ specifiers:
'@actions/core': ^1.2.6
'@ts-schema-autogen/cli': ^0.1.2
'@types/expand-tilde': ^2.0.0
'@types/fs-extra': ^9.0.8
'@types/js-yaml': ^4.0.0
'@types/node': ^14.14.35
'@types/node-fetch': ^2.5.8
'@vercel/ncc': ^0.27.0
ajv: ^6.12.5
expand-tilde: ^2.0.2
fs-extra: ^9.1.0
js-yaml: ^4.0.0
node-fetch: ^2.6.1
typescript: ^4.2.3
-2
View File
@@ -3,7 +3,5 @@
export HOME="$(pwd)"
export INPUT_VERSION=4.11.1
export INPUT_DEST='~/pnpm.temp'
export INPUT_BIN_DEST='~/pnpm.temp/.bin'
export INPUT_REGISTRY=https://registry.npmjs.com
export INPUT_RUN_INSTALL=null
exec node dist/index.js
-4
View File
@@ -5,8 +5,6 @@ import { RunInstall, parseRunInstall } from './run-install'
export interface Inputs {
readonly version: string
readonly dest: string
readonly binDest: string
readonly registry: string
readonly runInstall: RunInstall[]
}
@@ -19,8 +17,6 @@ const parseInputPath = (name: string) => expandTilde(getInput(name, options))
export const getInputs = (): Inputs => ({
version: getInput('version', options),
dest: parseInputPath('dest'),
binDest: parseInputPath('bin_dest'),
registry: getInput('registry', options),
runInstall: parseRunInstall('run_install'),
})
+13 -9
View File
@@ -1,20 +1,24 @@
import { spawn } from 'child_process'
import { execPath } from 'process'
import { downloadSelfInstaller } from '../self-installer'
import { join } from 'path'
import { remove, ensureFile, writeFile } from 'fs-extra'
import fetch from 'node-fetch'
import { Inputs } from '../inputs'
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const cp = spawn(execPath, {
env: {
PNPM_VERSION: inputs.version,
PNPM_DEST: inputs.dest,
PNPM_BIN_DEST: inputs.binDest,
PNPM_REGISTRY: inputs.registry,
},
const { version, dest } = inputs
const target = version ? `pnpm@${version}` : 'pnpm'
const pkgJson = join(dest, 'package.json')
await remove(dest)
await ensureFile(pkgJson)
await writeFile(pkgJson, JSON.stringify({ private: true }))
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
stdio: ['pipe', 'inherit', 'inherit'],
})
const response = await downloadSelfInstaller()
const response = await fetch('https://pnpm.js.org/pnpm.js')
response.body.pipe(cp.stdin)
return new Promise((resolve, reject) => {
+4 -2
View File
@@ -1,10 +1,12 @@
import { setOutput, addPath } from '@actions/core'
import { Inputs } from '../inputs'
import { getBinDest } from '../utils'
export function setOutputs(inputs: Inputs) {
addPath(inputs.binDest)
const binDest = getBinDest(inputs)
addPath(binDest)
setOutput('dest', inputs.dest)
setOutput('bin_dest', inputs.binDest)
setOutput('bin_dest', binDest)
}
export default setOutputs
-4
View File
@@ -1,4 +0,0 @@
import fetch from 'node-fetch'
import url from './url'
export const downloadSelfInstaller = () => fetch(url)
export default downloadSelfInstaller
-2
View File
@@ -1,2 +0,0 @@
export * from './url'
export * from './download'
-3
View File
@@ -1,3 +0,0 @@
export const ref = '301414cec74a2b6b63c95b42f2ad1790ccb980ed'
export const url = `https://raw.githubusercontent.com/pnpm/self-installer/${ref}/install.js`
export default url
+3 -1
View File
@@ -2,7 +2,9 @@ import process from 'process'
import path from 'path'
import { Inputs } from '../inputs'
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
...process.env,
PATH: inputs.binDest + path.delimiter + process.env.PATH
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH
})