Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/clean-install-hook-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'agoda-devfeedback-common': minor
---

Add a `devfeedback-install` CLI for invoking the exact install hooks from a
consuming repository without an inline `node -e` wrapper.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ Two tiers, and the first one needs nothing from you.
```json
{
"scripts": {
"preinstall": "node -e \"try{require('agoda-devfeedback-common/hooks/preinstall')}catch(e){}\"",
"postinstall": "node -e \"try{require('agoda-devfeedback-common/hooks/postinstall')}catch(e){}\""
"preinstall": "devfeedback-install preinstall || exit 0",
"postinstall": "devfeedback-install postinstall"
},
"devDependencies": {
"agoda-devfeedback-common": "^2.0.0"
Expand Down
5 changes: 4 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
"devfeedback-install": "./dist/cli/install.cjs"
},
"exports": {
"./package.json": "./package.json",
".": {
Expand All @@ -24,7 +27,7 @@
"dev": "tsup --watch",
"check-types": "tsc --noEmit",
"test": "vitest",
"postinstall": "node ./dist/hooks/postinstall.cjs --self || exit 0"
"postinstall": "node ./dist/cli/install.cjs postinstall --self || exit 0"
},
"dependencies": {
"axios": "1.8.4",
Expand Down
30 changes: 30 additions & 0 deletions packages/common/src/cli/install.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env node

type InstallHook = 'preinstall' | 'postinstall';

const usage = () => {
process.stderr.write('Usage: devfeedback-install <preinstall|postinstall> [--self]\n');
};

const run = async (hook: InstallHook): Promise<void> => {
if (hook === 'preinstall') {
await import('../hooks/preinstall');
} else {
await import('../hooks/postinstall');
}
};

const hook = process.argv[2];

if (hook !== 'preinstall' && hook !== 'postinstall') {
usage();
process.exitCode = 1;
} else {
void run(hook).catch((error: unknown) => {
// The hook modules are deliberately best-effort. This is only a guard for
// unexpected module-loading failures in the CLI itself.
const message = error instanceof Error ? error.message : String(error);
process.stderr.write(`[devfeedback] install hook error: ${message}\n`);
process.exitCode = 0;
});
}
1 change: 1 addition & 0 deletions packages/common/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
// they need their own stable entry points under dist/hooks
'hooks/preinstall': 'src/hooks/preinstall.ts',
'hooks/postinstall': 'src/hooks/postinstall.ts',
'cli/install': 'src/cli/install.ts',
},
format: ['cjs', 'esm'],
splitting: true,
Expand Down
Loading