Repository navigation
Fix/multiple build target #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c084712
update
Armadillidiid af7cf20
update
Armadillidiid 1f2e8c2
update
Armadillidiid d863af2
update
Armadillidiid 340ee27
update
Armadillidiid 28244ff
Potential fix for pull request finding
Armadillidiid 2da4d09
refactor: add publish script
Armadillidiid 3dd19e9
feat: switch temp switch to npm for publishing
Armadillidiid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "cmdly": patch | ||
| --- | ||
|
|
||
| Add postinstall to build for other platforms and arch other than linux-x64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { | ||
| chmodSync, | ||
| copyFileSync, | ||
| existsSync, | ||
| mkdirSync, | ||
| renameSync, | ||
| } from "node:fs"; | ||
| import { dirname, join } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const packageRoot = join(__dirname, ".."); | ||
| const binDir = join(packageRoot, "bin"); | ||
| const binPath = join(binDir, "cmdly"); | ||
| const supportedTargets = ["linux-x64", "linux-arm64", "darwin-arm64"]; | ||
|
|
||
| const detectTarget = () => { | ||
| if (process.platform === "linux" && process.arch === "x64") { | ||
| return "linux-x64"; | ||
| } | ||
| if (process.platform === "linux" && process.arch === "arm64") { | ||
| return "linux-arm64"; | ||
| } | ||
| if (process.platform === "darwin" && process.arch === "arm64") { | ||
| return "darwin-arm64"; | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| const installBinary = (sourcePath) => { | ||
| if (!existsSync(sourcePath)) { | ||
| throw new Error(`missing target binary in package: ${sourcePath}`); | ||
| } | ||
|
|
||
| mkdirSync(binDir, { recursive: true }); | ||
| const tempTarget = join(binDir, ".cmdly.tmp"); | ||
| copyFileSync(sourcePath, tempTarget); | ||
| chmodSync(tempTarget, 0o755); | ||
| renameSync(tempTarget, binPath); | ||
| }; | ||
|
|
||
| const main = () => { | ||
| const target = detectTarget(); | ||
|
|
||
| if (!target) { | ||
| console.warn( | ||
| `[postinstall] skipping unsupported target ${process.platform}-${process.arch}; supported: ${supportedTargets.join(", ")}`, | ||
| ); | ||
| return; | ||
| } | ||
|
Comment on lines
+47
to
+52
|
||
|
|
||
| if (target === "linux-x64" && existsSync(binPath)) { | ||
| // The binary is already included in the package and bin field points to it | ||
| // No postinstall setup needed | ||
| console.log( | ||
| `[postinstall] skipping install for ${target} since binary already exists`, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| const sourcePath = join(packageRoot, "dist", target, "cmdly"); | ||
| installBinary(sourcePath); | ||
|
Comment on lines
+63
to
+64
|
||
|
|
||
| console.log(`[postinstall] installed ${target} binary`); | ||
| }; | ||
|
|
||
| try { | ||
| main(); | ||
| } catch (error) { | ||
| const target = detectTarget(); | ||
| const message = error instanceof Error ? error.message : String(error); | ||
|
|
||
| if (target) { | ||
| console.error(`[postinstall] native install failed for ${target}: ${message}`); | ||
| process.exit(1); | ||
|
Comment on lines
+63
to
+77
|
||
| } | ||
|
|
||
| console.warn(`[postinstall] native install failed on unsupported target: ${message}`); | ||
| process.exit(0); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { writeFileSync } from "node:fs"; | ||
| import { spawnSync } from "node:child_process"; | ||
| import { dirname, join, resolve } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import pkg from "../package.json" with { type: "json" }; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| const rootDir = resolve(__dirname, ".."); | ||
| const pkgPath = join(rootDir, "package.json"); | ||
|
|
||
| const run = (cmd, args, opts) => { | ||
| const result = spawnSync(cmd, args, { | ||
| cwd: rootDir, | ||
| stdio: "inherit", | ||
| ...opts, | ||
| }); | ||
| if (result.status !== 0) { | ||
| process.exit(result.status ?? 1); | ||
| } | ||
|
Comment on lines
+12
to
+20
|
||
| }; | ||
|
|
||
| const getNpmVersion = () => { | ||
| const result = spawnSync("npm", ["--version"], { | ||
| cwd: rootDir, | ||
| encoding: "utf8", | ||
| stdio: "pipe", | ||
| }); | ||
| return result.stdout.trim(); | ||
|
|
||
| }; | ||
|
|
||
| // @changesets/cli currently only supports npm so we need to temporarily change our package manager | ||
| const npmVersion = getNpmVersion(); | ||
| const original = JSON.parse(JSON.stringify(pkg)); | ||
| const savedPackageManager = pkg.packageManager; | ||
| const savedDevEnginesPackageManager = JSON.parse( | ||
| JSON.stringify(pkg.devEngines?.packageManager), | ||
| ); | ||
|
Comment on lines
+36
to
+38
|
||
|
|
||
| original.scripts.postinstall = "node scripts/postinstall.mjs"; | ||
| original.packageManager = `npm@${npmVersion}`; | ||
| if (original.devEngines) { | ||
| original.devEngines.packageManager = { | ||
| name: "npm", | ||
| version: npmVersion, | ||
| }; | ||
| } | ||
| writeFileSync(pkgPath, `${JSON.stringify(original, null, "\t")}\n`, "utf8"); | ||
|
|
||
| run("pnpm", ["build"]); | ||
| run("pnpm", ["stage:bin"]); | ||
| run("pnpm", ["vitest"]); | ||
|
|
||
| run("changeset", ["publish"]); | ||
| run("changeset", ["tag"]); | ||
| run("git", ["push", "--tags"]); | ||
|
Comment on lines
+40
to
+55
|
||
|
|
||
| delete original.scripts.postinstall; | ||
| original.packageManager = savedPackageManager; | ||
| if (original.devEngines) { | ||
| original.devEngines.packageManager = savedDevEnginesPackageManager; | ||
| } | ||
| writeFileSync(pkgPath, `${JSON.stringify(original, null, "\t")}\n`, "utf8"); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { chmodSync, copyFileSync, mkdirSync, rmSync } from "node:fs"; | ||
| import { dirname, join, resolve } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| const rootDir = resolve(__dirname, ".."); | ||
|
|
||
| const source = join(rootDir, "dist", "linux-x64", "cmdly"); | ||
|
|
||
| const targetDir = join(rootDir, "bin"); | ||
| const target = join(targetDir, "cmdly"); | ||
|
|
||
| mkdirSync(targetDir, { recursive: true }); | ||
| rmSync(target, { force: true }); | ||
| copyFileSync(source, target); | ||
| chmodSync(target, 0o755); | ||
|
Comment on lines
+9
to
+16
|
||
|
|
||
| console.log(`[stage:bin] staged ${source} -> ${target}`); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.