@sebbo2002/semantic-release-jsr
Version:
Small `semantic-release` plugin, which adjusts the version in the `jsr.json` file and executes `jsr publish` to publish the module on jsr.io as well.
2 lines • 2.92 kB
JavaScript
import e from"@semantic-release/error";import{publish as t}from"jsr";import{existsSync as n,mkdtempSync as r}from"node:fs";import{readFile as i,rm as a,writeFile as o}from"node:fs/promises";import{tmpdir as s}from"node:os";import{join as c}from"node:path";async function l(t,r){let a=t.cwd||r?.cwd||process.cwd(),o=t.pkgJsonPath||c(a,`package.json`);!t.pkgJsonPath&&!n(o)&&(o=null);let s,l=[],u=c(a,`jsr.json`),d=c(a,`deno.json`);n(u)&&l.push(u),n(d)&&l.push(d),o&&l.push(o);for(let e of l){let t=await i(e,`utf8`),n=JSON.parse(t);!s&&n.name&&(s=n.name)}if(!s)throw new e(`No name found in jsr.json or deno.json`,`ERR_NO_NAME`,`A package name is required to publish to JSR.io`);let p=t.publishArgs?.slice(0)||[];return(t.allowDirty===void 0||t.allowDirty)&&!p.includes(`--allow-dirty`)&&p.push(`--allow-dirty`),{cwd:a,name:s,prepare:{versionJsonPaths:l},publish:{binFolder:f(),canary:!1,pkgJsonPath:o,publishArgs:p}}}let u;function d(e,t){let n=`https://jsr.io/${e.name}/versions`;return t.nextRelease&&(n=`https://jsr.io/${e.name}@${t.nextRelease.version}`),{name:`JSR.io`,url:n}}function f(){if(u)return u;let e=r(c(s(),`semantic-release-jsr-`));return u=e,e}async function p(e,n){n.logger.log(`Run jsr publish in ${e.cwd} with ${JSON.stringify(e.publish)}`);let r=Date.now();try{await t(e.cwd,e.publish),n.logger.log(`jsr publish run successfully (took ${Date.now()-r} ms)`)}catch(e){throw n.logger.log(`jsr publish failed after ${Date.now()-r} ms:`),n.logger.error(e instanceof Error?e.stack:e),e}}async function m(){u&&=(await a(u,{force:!0,recursive:!0}),void 0)}async function h(t,n){if(!n.nextRelease)return;n.logger.log(`Updating version in ${t}`);let r=n.nextRelease.version,a=await i(t,`utf8`);if(JSON.parse(a).version===r){n.logger.log(`Skipped, ${t} is already up to date`);return}let s=a.replace(/^([\s\S]*"version"\s*:\s*")([^"]+)("[\s\S]*$)/,`$1${r}$3`);if(JSON.parse(s).version!==r)throw new e(`Failed to replace version in ${t}`,`ERR_VERSION_REPLACE`,`The version in ${t} could not be updated to ${r}. Please check if the file is valid JSON and contains a "version" field.`);await o(t,s,`utf8`),n.logger.log(`Wrote new version to ${t}`)}async function g(e,t){t.logger.log(`Removing temporary folder`),await m()}async function _(e,t){let n=await l(e,t);for(let e of n.prepare.versionJsonPaths)await h(e,t)}async function v(e,t){let n=await l(e,t);return await p(n,t),d(n,t)}async function y(e,t){t.logger.log(`Removing temporary folder`),await m()}async function b(e,t){let n=await l(e,t);t.logger.info(`Run jsr publish --dry-run to verify configuration`),await p({...n,publish:{...n.publish,publishArgs:[...n.publish.publishArgs,`--dry-run`]}},t)}export{g as fail,d as generatePublishResponse,f as getTemporaryBinFolder,p as jsrPublish,l as parseConfig,_ as prepare,v as publish,m as removeTemporaryBinFolder,y as success,h as updateVersionJson,b as verifyConditions};
//# sourceMappingURL=index.mjs.map