diff options
-rw-r--r-- | packages/bun-npm/.gitignore | 1 | ||||
-rw-r--r-- | packages/bun-npm/scripts/npm-build.ts | 13 | ||||
-rw-r--r-- | packages/bun-npm/src/util.ts | 21 |
3 files changed, 32 insertions, 3 deletions
diff --git a/packages/bun-npm/.gitignore b/packages/bun-npm/.gitignore index 39931eeba..4c021cb09 100644 --- a/packages/bun-npm/.gitignore +++ b/packages/bun-npm/.gitignore @@ -3,3 +3,4 @@ node_modules /npm/**/bin /npm/**/*.js +/npm/**/.npmrc diff --git a/packages/bun-npm/scripts/npm-build.ts b/packages/bun-npm/scripts/npm-build.ts index 34598b92c..5cc5aa51e 100644 --- a/packages/bun-npm/scripts/npm-build.ts +++ b/packages/bun-npm/scripts/npm-build.ts @@ -1,5 +1,5 @@ import type { Endpoints } from "@octokit/types"; -import { fetch, spawn } from "../src/util"; +import { copy, exists, fetch, spawn } from "../src/util"; import type { JSZipObject } from "jszip"; import { loadAsync } from "jszip"; import { join } from "node:path"; @@ -85,6 +85,9 @@ async function buildBasePackage() { os, cpu, }); + if (exists(".npmrc")) { + copy(".npmrc", join(cwd, ".npmrc")); + } done(); } @@ -96,7 +99,8 @@ async function buildPackage( const done = log("Building:", `${npmPackage}@${npmVersion}`); const asset = release.assets.find(({ name }) => name === `${bin}.zip`); if (!asset) { - throw new Error(`No asset found: ${bin}`); + console.warn(`No asset found: ${bin}`); + return; } const bun = await extractFromZip(asset.browser_download_url, `${bin}/bun`); const cwd = join("npm", npmPackage); @@ -109,6 +113,9 @@ async function buildPackage( os: [os], cpu: [arch], }); + if (exists(".npmrc")) { + copy(".npmrc", join(cwd, ".npmrc")); + } done(); } @@ -132,7 +139,7 @@ function publishPackage(name: string, dryRun?: boolean): void { done(); return; } - throw new Error(stdout || stderr); + console.warn(stdout || stderr); } async function extractFromZip( diff --git a/packages/bun-npm/src/util.ts b/packages/bun-npm/src/util.ts index c36bda2b7..e2cf19ee0 100644 --- a/packages/bun-npm/src/util.ts +++ b/packages/bun-npm/src/util.ts @@ -103,6 +103,27 @@ export function chmod(path: string, mode: fs.Mode): void { fs.chmodSync(path, mode); } +export function copy(path: string, newPath: string): void { + console.debug("copy", path, newPath); + try { + fs.copyFileSync(path, newPath); + return; + } catch (error) { + console.debug("copyFileSync failed", error); + } + write(newPath, read(path)); +} + +export function exists(path: string): boolean { + console.debug("exists", path); + try { + return fs.existsSync(path); + } catch (error) { + console.debug("existsSync failed", error); + } + return false; +} + export function spawn( cmd: string, args: string[], |