mirror of
https://github.com/pnpm/action-setup
synced 2026-11-08 21:27:57 +01:00
feat: support installation from custom NPM registry (#179)
copy .npmrc from GitHub workspace if it exists so that PNPM respects custom registry configurations when self-installing
This commit is contained in:
1 parent
f2b2b233b5
commit
41ff726559
2 files changed
+13
-2
No files matched your search
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
(()=>{var e={1046:function(e,t,s){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});const r=s(9999);const i=n(s(6414));const o=n(s(3144));const a=n(s(7215));const c=n(s(4728));const l=n(s(6879));async function main(){const e=(0,i.default)();const t=(0,r.getState)("is_post");if(t==="true")return(0,l.default)(e);(0,r.saveState)("is_post","true");await(0,o.default)(e);console.log("Installation Completed!");(0,a.default)(e);(0,c.default)(e)}main().catch((e=>{console.error(e);(0,r.setFailed)(e)}))},6414:function(e,t,s){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.getInputs=void 0;const r=s(9999);const i=n(s(6746));const o=s(9065);const a={required:true};const parseInputPath=e=>(0,i.default)((0,r.getInput)(e,a));const getInputs=()=>({version:(0,r.getInput)("version"),dest:parseInputPath("dest"),runInstall:(0,o.parseRunInstall)("run_install"),packageJsonFile:parseInputPath("package_json_file"),standalone:(0,r.getBooleanInput)("standalone")});t.getInputs=getInputs;t["default"]=t.getInputs},9065:function(e,t,s){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,s,n){if(n===undefined)n=s;var r=Object.getOwnPropertyDescriptor(t,s);if(!r||("get"in r?!t.__esModule:r.writable||r.configurable)){r={enumerable:true,get:function(){return t[s]}}}Object.defineProperty(e,n,r)}:function(e,t,s,n){if(n===undefined)n=s;e[n]=t[s]});var r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var i=this&&this.__importStar||function(){var ownKeys=function(e){ownKeys=Object.getOwnPropertyNames||function(e){var t=[];for(var s in e)if(Object.prototype.hasOwnProperty.call(e,s))t[t.length]=s;return t};return ownKeys(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var s=ownKeys(e),i=0;i<s.length;i++)if(s[i]!=="default")n(t,e,s[i]);r(t,e);return t}}();Object.defineProperty(t,"__esModule",{value:true});t.parseRunInstall=parseRunInstall;const o=s(9999);const a=i(s(7669));const c=s(6516);const l=c.z.object({recursive:c.z.boolean().optional(),cwd:c.z.string().optional(),args:c.z.array(c.z.string()).optional()});const u=c.z.union([c.z.null(),c.z.boolean(),l,c.z.array(l)]);function parseRunInstall(e){const t=(0,o.getInput)(e,{required:true});const s=a.parse(t);try{const e=u.parse(s);if(!e)return[];if(e===true)return[{recursive:true}];if(Array.isArray(e))return e;return[e]}catch(s){(0,o.error)(`Error for input "${e}" = ${t}`);if(s instanceof c.ZodError){(0,o.error)(`Errors: ${s.errors}`)}else{(0,o.error)(`Exception: ${s}`)}process.exit(1)}}},3144:function(e,t,s){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.runSelfInstaller=void 0;t.install=install;const r=s(9999);const i=n(s(7053));t.runSelfInstaller=i.default;async function install(e){(0,r.startGroup)("Running self-installer...");const t=await(0,i.default)(e);(0,r.endGroup)();if(t){return(0,r.setFailed)(`Something went wrong, self-installer exits with code ${t}`)}}t["default"]=install},7053:function(e,t,s){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.runSelfInstaller=runSelfInstaller;const r=s(9999);const i=s(5317);const o=s(1943);const a=s(9896);const c=n(s(6928));const l=s(932);const u=n(s(9023));const d=n(s(7669));async function runSelfInstaller(e){const{version:t,dest:s,packageJsonFile:n,standalone:a}=e;await(0,o.rm)(s,{recursive:true,force:true});await(0,o.mkdir)(s,{recursive:true});const u=c.default.join(s,"package.json");await(0,o.writeFile)(u,JSON.stringify({private:true}));const d=await readTarget({version:t,packageJsonFile:n,standalone:a});const f=(0,i.spawn)(l.execPath,[c.default.join(__dirname,"pnpm.cjs"),"install",d,"--no-lockfile"],{cwd:s,stdio:["pipe","inherit","inherit"]});const p=await new Promise(((e,t)=>{f.on("error",t);f.on("close",e)}));if(p===0){const e=c.default.join(s,"node_modules/.bin");(0,r.addPath)(e);(0,r.exportVariable)("PNPM_HOME",e)}return p}async function readTarget(e){const{version:t,packageJsonFile:s,standalone:n}=e;const{GITHUB_WORKSPACE:r}=process.env;let i;if(r){try{const e=(0,a.readFileSync)(c.default.join(r,s),"utf8");({packageManager:i}=s.endsWith(".yaml")?d.default.parse(e,{merge:true}):JSON.parse(e))}catch(e){if(!u.default.types.isNativeError(e)||!("code"in e)||e.code!=="ENOENT")throw e}}if(t){if(typeof i==="string"&&i.replace("pnpm@","")!==t){throw new Error(`Multiple versions of pnpm specified:\n - version ${t} in the GitHub Action config with the key "version"\n - version ${i} in the package.json with the key "packageManager"\nRemove one of these versions to avoid version mismatch errors like ERR_P
Line truncated
|
||||
(()=>{var e={1046:function(e,t,s){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});const r=s(9999);const i=n(s(6414));const o=n(s(3144));const a=n(s(7215));const c=n(s(4728));const l=n(s(6879));async function main(){const e=(0,i.default)();const t=(0,r.getState)("is_post");if(t==="true")return(0,l.default)(e);(0,r.saveState)("is_post","true");await(0,o.default)(e);console.log("Installation Completed!");(0,a.default)(e);(0,c.default)(e)}main().catch((e=>{console.error(e);(0,r.setFailed)(e)}))},6414:function(e,t,s){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.getInputs=void 0;const r=s(9999);const i=n(s(6746));const o=s(9065);const a={required:true};const parseInputPath=e=>(0,i.default)((0,r.getInput)(e,a));const getInputs=()=>({version:(0,r.getInput)("version"),dest:parseInputPath("dest"),runInstall:(0,o.parseRunInstall)("run_install"),packageJsonFile:parseInputPath("package_json_file"),standalone:(0,r.getBooleanInput)("standalone")});t.getInputs=getInputs;t["default"]=t.getInputs},9065:function(e,t,s){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,s,n){if(n===undefined)n=s;var r=Object.getOwnPropertyDescriptor(t,s);if(!r||("get"in r?!t.__esModule:r.writable||r.configurable)){r={enumerable:true,get:function(){return t[s]}}}Object.defineProperty(e,n,r)}:function(e,t,s,n){if(n===undefined)n=s;e[n]=t[s]});var r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var i=this&&this.__importStar||function(){var ownKeys=function(e){ownKeys=Object.getOwnPropertyNames||function(e){var t=[];for(var s in e)if(Object.prototype.hasOwnProperty.call(e,s))t[t.length]=s;return t};return ownKeys(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var s=ownKeys(e),i=0;i<s.length;i++)if(s[i]!=="default")n(t,e,s[i]);r(t,e);return t}}();Object.defineProperty(t,"__esModule",{value:true});t.parseRunInstall=parseRunInstall;const o=s(9999);const a=i(s(7669));const c=s(6516);const l=c.z.object({recursive:c.z.boolean().optional(),cwd:c.z.string().optional(),args:c.z.array(c.z.string()).optional()});const u=c.z.union([c.z.null(),c.z.boolean(),l,c.z.array(l)]);function parseRunInstall(e){const t=(0,o.getInput)(e,{required:true});const s=a.parse(t);try{const e=u.parse(s);if(!e)return[];if(e===true)return[{recursive:true}];if(Array.isArray(e))return e;return[e]}catch(s){(0,o.error)(`Error for input "${e}" = ${t}`);if(s instanceof c.ZodError){(0,o.error)(`Errors: ${s.errors}`)}else{(0,o.error)(`Exception: ${s}`)}process.exit(1)}}},3144:function(e,t,s){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.runSelfInstaller=void 0;t.install=install;const r=s(9999);const i=n(s(7053));t.runSelfInstaller=i.default;async function install(e){(0,r.startGroup)("Running self-installer...");const t=await(0,i.default)(e);(0,r.endGroup)();if(t){return(0,r.setFailed)(`Something went wrong, self-installer exits with code ${t}`)}}t["default"]=install},7053:function(e,t,s){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.runSelfInstaller=runSelfInstaller;const r=s(9999);const i=s(5317);const o=s(1943);const a=s(9896);const c=n(s(6928));const l=s(932);const u=n(s(9023));const d=n(s(7669));async function runSelfInstaller(e){const{version:t,dest:s,packageJsonFile:n,standalone:a}=e;const{GITHUB_WORKSPACE:d}=process.env;await(0,o.rm)(s,{recursive:true,force:true});await(0,o.mkdir)(s,{recursive:true});const f=c.default.join(s,"package.json");await(0,o.writeFile)(f,JSON.stringify({private:true}));if(d){try{await(0,o.copyFile)(c.default.join(d,".npmrc"),c.default.join(s,".npmrc"))}catch(e){if(!u.default.types.isNativeError(e)||!("code"in e)||e.code!=="ENOENT")throw e}}const p=await readTarget({version:t,packageJsonFile:n,standalone:a});const h=(0,i.spawn)(l.execPath,[c.default.join(__dirname,"pnpm.cjs"),"install",p,"--no-lockfile"],{cwd:s,stdio:["pipe","inherit","inherit"]});const m=await new Promise(((e,t)=>{h.on("error",t);h.on("close",e)}));if(m===0){const e=c.default.join(s,"node_modules/.bin");(0,r.addPath)(e);(0,r.exportVariable)("PNPM_HOME",e)}return m}async function readTarget(e){const{version:t,packageJsonFile:s,standalone:n}=e;const{GITHUB_WORKSPACE:r}=process.env;let i;if(r){try{const e=(0,a.readFileSync)(c.default.join(r,s),"utf8");({packageManager:i}=s.endsWith(".yaml")?d.default.parse(e,{merge:true}):JSON.parse(e))}catch(e){if(!u.default.types.isNativeError(e)||!("code"in e)||e.code!=="ENOENT")throw e}}if(t){if(typeof i==="string"&&i.startsWith("pnpm@")&&i.replace("pnpm@","")!==t){throw new Error(`Multiple ver
Line truncated
|
||||
/*!
|
||||
* expand-tilde <https://github.com/jonschlinkert/expand-tilde>
|
||||
*
|
||||
|
||||
+12
-1
@@ -1,6 +1,6 @@
|
||||
import { addPath, exportVariable } from '@actions/core'
|
||||
import { spawn } from 'child_process'
|
||||
import { rm, writeFile, mkdir } from 'fs/promises'
|
||||
import { rm, writeFile, mkdir, copyFile } from 'fs/promises'
|
||||
import { readFileSync } from 'fs'
|
||||
import path from 'path'
|
||||
import { execPath } from 'process'
|
||||
@@ -10,6 +10,7 @@ import YAML from 'yaml'
|
||||
|
||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
const { version, dest, packageJsonFile, standalone } = inputs
|
||||
const { GITHUB_WORKSPACE } = process.env
|
||||
|
||||
// prepare self install
|
||||
await rm(dest, { recursive: true, force: true })
|
||||
@@ -19,6 +20,16 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
// we have ensured the dest directory exists, we can write the file directly
|
||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||
|
||||
// copy .npmrc if it exists to install from custom registry
|
||||
if (GITHUB_WORKSPACE) {
|
||||
try {
|
||||
await copyFile(path.join(GITHUB_WORKSPACE, '.npmrc'), path.join(dest, '.npmrc'))
|
||||
} catch (error) {
|
||||
// Swallow error if .npmrc doesn't exist
|
||||
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
|
||||
}
|
||||
}
|
||||
|
||||
// prepare target pnpm
|
||||
const target = await readTarget({ version, packageJsonFile, standalone })
|
||||
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
|
||||
|
||||
Reference in new issue
Block a user