You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(build): set executable permissions on CLI bin files (#359)
TypeScript's tsc compiler does not preserve executable permissions on output files, requiring explicit chmod in build scripts.
Changes:
- Add chmod +x to build scripts for CLI packages (cli, device-profiler, mqtt-bridge)
- Set executable permissions on both ESM and CJS bin files
- Simplify mqtt-bridge prepublishOnly script (no longer needs separate chmod)
- Document CLI package requirements and shebang requirement in package-creation.md
- Add comprehensive CLI package section to NEW-PACKAGE.md
TypeScript does not support preserving executable permissions (see TypeScript issues #37583, #16257, #26060). The chmod approach in build scripts is the industry-standard solution.
Related: #360, #361
Copy file name to clipboardExpand all lines: docs/NEW-PACKAGE.md
+42-1Lines changed: 42 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -318,11 +318,52 @@ This pattern ensures the factory defaults are always valid according to the devi
318
318
319
319
See `packages/driver-xymd1` for reference implementation.
320
320
321
+
### CLI Package
322
+
323
+
CLI packages expose executable commands via the npm `bin` field.
324
+
325
+
**Required configuration**:
326
+
327
+
```json
328
+
{
329
+
"bin": {
330
+
"command-name": "./dist/esm/bin/command.js"
331
+
}
332
+
}
333
+
```
334
+
335
+
**Required structure**:
336
+
337
+
-`bin/` directory with executable TypeScript source files
338
+
- Each bin file MUST start with shebang: `#!/usr/bin/env node`
339
+
- TypeScript config MUST use `"rootDir": "."` to include both `src` and `bin`
340
+
- Build script MUST set executable permissions after compilation
341
+
342
+
**Example build script**:
343
+
344
+
```json
345
+
{
346
+
"scripts": {
347
+
"build": "npm run build:esm && npm run build:cjs && npm run build:package-json && chmod +x dist/esm/bin/*.js dist/cjs/bin/*.js"
348
+
}
349
+
}
350
+
```
351
+
352
+
**Why chmod is required**: TypeScript's `tsc` compiler does not preserve executable permissions on output files. The build script must explicitly set permissions after compilation.
353
+
354
+
**Reference implementations**:
355
+
356
+
-`packages/cli` - Main CLI tool
357
+
-`packages/device-profiler` - Profiling CLI
358
+
-`packages/mqtt-bridge` - Bridge CLI
359
+
360
+
See `docs/agents/package-creation.md` for technical details on CLI package structure.
361
+
321
362
### Utility Package
322
363
323
364
Utility packages should use scoped naming: `@ya-modbus/<name>`
0 commit comments