mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
Publish pmg to npm (#50)
* feat: pmg publish to npm * feat: add github action for publishing to npm * Update publish/npm/install.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> * Update .github/workflows/publish-npm.yml Co-authored-by: Omkar Phansopkar <omkarphansopkar@gmail.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> * refactor: define constants * refactor: improve npm package reliability with removing dynamic handlers and better error handling and validation * fix: publish-npm workflow * Update publish/npm/test.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> * refactor(npm-workflow): use a more portable loop construct * refactor: remove version field from package.json * feat: use os.tmpdir() with mkdtempSync for cleaner temp directory handling * fix: add redirect limit and cleanup to prevent infinite redirects and resource leaks * remove test.js for npm publisher pack * chore: test cmd cleanup --------- Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Omkar Phansopkar <omkarphansopkar@gmail.com>
This commit is contained in:
co-authored by
Copilot
Omkar Phansopkar
parent
ca752edf79
commit
74248cd74a
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { spawn } = require("child_process");
|
||||
const { ORG_NAME, PACKAGE_NAME, BINARY_NAME } = require("../config");
|
||||
|
||||
const BINARY_NAME_WITH_EXT =
|
||||
process.platform === "win32" ? `${BINARY_NAME}.exe` : BINARY_NAME;
|
||||
const BINARY_PATH = path.join(__dirname, BINARY_NAME_WITH_EXT);
|
||||
|
||||
function main() {
|
||||
// Check if binary exists
|
||||
if (!fs.existsSync(BINARY_PATH)) {
|
||||
console.error(`❌ ${BINARY_NAME_WITH_EXT} binary not found`);
|
||||
console.error(
|
||||
`Try reinstalling: npm install -g ${ORG_NAME}/${PACKAGE_NAME}`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Verify binary is executable
|
||||
try {
|
||||
fs.accessSync(BINARY_PATH, fs.constants.F_OK | fs.constants.X_OK);
|
||||
} catch (error) {
|
||||
console.error(`❌ ${BINARY_NAME_WITH_EXT} is not executable`);
|
||||
console.error(
|
||||
`Try reinstalling: npm install -g ${ORG_NAME}/${PACKAGE_NAME}`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Pass all arguments to the binary
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
// Spawn the binary with inherited stdio for proper terminal interaction
|
||||
const child = spawn(BINARY_PATH, args, {
|
||||
stdio: "inherit",
|
||||
windowsHide: false,
|
||||
});
|
||||
|
||||
// Handle process termination
|
||||
child.on("error", (error) => {
|
||||
console.error(
|
||||
`❌ Failed to execute ${BINARY_NAME_WITH_EXT}: ${error.message}`,
|
||||
);
|
||||
console.error(
|
||||
`Try reinstalling: npm install -g ${ORG_NAME}/${PACKAGE_NAME}`,
|
||||
);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Exit with the same code as the child process
|
||||
child.on("exit", (code, signal) => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
} else {
|
||||
process.exit(code || 0);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle termination signals
|
||||
process.on("SIGTERM", () => {
|
||||
child.kill("SIGTERM");
|
||||
});
|
||||
|
||||
process.on("SIGINT", () => {
|
||||
child.kill("SIGINT");
|
||||
});
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
||||
|
||||
module.exports = { main };
|
||||
Reference in New Issue
Block a user