style: configure deno fmt to use single quotes
All checks were successful
CI / Build All Platforms (Tag/Main only) (push) Has been skipped
CI / Type Check & Lint (push) Successful in 6s
CI / Build Test (Current Platform) (push) Successful in 6s

- Add singleQuote: true to deno.json fmt configuration
- Reformat all files with single quotes using deno fmt
This commit is contained in:
2025-10-19 13:14:18 +00:00
parent b935087d50
commit 071ded9c41
24 changed files with 1094 additions and 672 deletions

View File

@@ -1,8 +1,8 @@
# NUPST Migration Plan: Node.js → Deno v4.0.0
**Migration Goal**: Convert NUPST from Node.js to Deno with single-executable distribution
**Version**: 3.1.2 → 4.0.0 (breaking changes)
**Platforms**: Linux x64/ARM64, macOS x64/ARM64, Windows x64
**Version**: 3.1.2 → 4.0.0 (breaking changes) **Platforms**: Linux x64/ARM64, macOS x64/ARM64,
Windows x64
---
@@ -20,10 +20,12 @@
## Phase 1: Dependency Migration (4-6 hours)
### 1.1 Analyze Current Dependencies
- [ ] List all production dependencies from `package.json`
- Current: `net-snmp@3.20.0`
- [ ] List all dev dependencies to be removed
- `@git.zone/tsbuild`, `@git.zone/tsrun`, `@git.zone/tstest`, `@push.rocks/qenv`, `@push.rocks/tapbundle`, `@types/node`
- `@git.zone/tsbuild`, `@git.zone/tsrun`, `@git.zone/tstest`, `@push.rocks/qenv`,
`@push.rocks/tapbundle`, `@types/node`
- [ ] Identify Node.js built-in module usage
- `child_process` (execSync)
- `https` (for version checking)
@@ -31,6 +33,7 @@
- `path` (join, dirname, resolve)
### 1.2 Create Deno Configuration
- [ ] Create `deno.json` with project configuration
```json
{
@@ -68,15 +71,20 @@
```
### 1.3 Update Import Statements
- [ ] `ts/snmp/manager.ts`: Change `import * as snmp from 'net-snmp'` to `import * as snmp from "npm:net-snmp@3.20.0"`
- [ ] `ts/cli.ts`: Change `import { execSync } from 'child_process'` to `import { execSync } from "node:child_process"`
- [ ] `ts/nupst.ts`: Change `import * as https from 'https'` to `import * as https from "node:https"`
- [ ] `ts/snmp/manager.ts`: Change `import * as snmp from 'net-snmp'` to
`import * as snmp from "npm:net-snmp@3.20.0"`
- [ ] `ts/cli.ts`: Change `import { execSync } from 'child_process'` to
`import { execSync } from "node:child_process"`
- [ ] `ts/nupst.ts`: Change `import * as https from 'https'` to
`import * as https from "node:https"`
- [ ] Search for all `fs` imports and update to `node:fs`
- [ ] Search for all `path` imports and update to `node:path`
- [ ] Update all relative imports to use `.ts` extension instead of `.js`
- Example: `'./nupst.js'` → `'./nupst.ts'`
### 1.4 Test npm: Specifier Compatibility
- [ ] Create test file: `tests/snmp_compatibility_test.ts`
- [ ] Test SNMP v1 connection with npm:net-snmp
- [ ] Test SNMP v2c connection with npm:net-snmp
@@ -88,6 +96,7 @@
## Phase 2: Code Structure Refactoring (3-4 hours)
### 2.1 Create Main Entry Point
- [ ] Create `mod.ts` as main Deno entry point:
```typescript
#!/usr/bin/env -S deno run --allow-all
@@ -111,7 +120,9 @@
```
### 2.2 Update All Import Extensions
Files to update (change .js → .ts in imports):
- [ ] `ts/index.ts`
- [ ] `ts/cli.ts` (imports from ./nupst.js, ./logger.js)
- [ ] `ts/nupst.ts` (imports from ./snmp/manager.js, ./daemon.js, etc.)
@@ -127,10 +138,13 @@ Files to update (change .js → .ts in imports):
- [ ] `ts/logger.ts`
### 2.3 Update process.argv References
- [ ] `ts/cli.ts`: Replace `process.argv` with `Deno.args` (adjust indexing: process.argv[2] → Deno.args[0])
- [ ] `ts/cli.ts`: Replace `process.argv` with `Deno.args` (adjust indexing: process.argv[2] →
Deno.args[0])
- [ ] Update parseAndExecute method to work with Deno.args (0-indexed vs 2-indexed)
### 2.4 Update File System Operations
- [ ] Search for `fs.readFileSync()` → Consider using `Deno.readTextFile()` or keep node:fs
- [ ] Search for `fs.writeFileSync()` → Consider using `Deno.writeTextFile()` or keep node:fs
- [ ] Search for `fs.existsSync()` → Keep node:fs or use Deno.stat
@@ -138,10 +152,12 @@ Files to update (change .js → .ts in imports):
- [ ] Decision: Keep node:fs for consistency or migrate to Deno APIs?
### 2.5 Update Path Operations
- [ ] Verify all `path.join()`, `path.resolve()`, `path.dirname()` work with node:path
- [ ] Consider using `@std/path` from JSR for better Deno integration
### 2.6 Handle __dirname and __filename
- [ ] Find all `__dirname` usage
- [ ] Replace with `import.meta.dirname` (Deno) or `dirname(fromFileUrl(import.meta.url))`
- [ ] Find all `__filename` usage
@@ -152,7 +168,9 @@ Files to update (change .js → .ts in imports):
## Phase 3: CLI Command Simplification (3-4 hours)
### 3.1 Design New Command Structure
Current → New mapping:
```
OLD NEW
=== ===
@@ -184,6 +202,7 @@ nupst help → nupst help / nupst --help
```
### 3.2 Update CLI Parser (ts/cli.ts)
- [ ] Refactor `parseAndExecute()` to handle new command structure
- [ ] Add `service` subcommand handler
- [ ] Add `ups` subcommand handler
@@ -195,11 +214,13 @@ nupst help → nupst help / nupst --help
- [ ] Add `--json` flag for machine-readable output (future enhancement)
### 3.3 Update Command Handlers
- [ ] `ts/cli/service-handler.ts`: Update method names if needed
- [ ] `ts/cli/ups-handler.ts`: Rename `delete()` → `remove()`, remove `setup` method
- [ ] `ts/cli/group-handler.ts`: Rename `delete()` → `remove()`
### 3.4 Improve Help Messages
- [ ] Update `showHelp()` in ts/cli.ts with new command structure
- [ ] Update `showGroupHelp()` in ts/cli.ts
- [ ] Add `showServiceHelp()` method
@@ -208,6 +229,7 @@ nupst help → nupst help / nupst --help
- [ ] Include usage examples in help text
### 3.5 Add Version Command
- [ ] Read version from deno.json
- [ ] Create `--version` handler in CLI
- [ ] Display version with build info
@@ -217,6 +239,7 @@ nupst help → nupst help / nupst --help
## Phase 4: Compilation & Distribution (2-3 hours)
### 4.1 Create Compilation Script
- [ ] Create directory: `scripts/`
- [ ] Create `scripts/compile-all.sh`:
```bash
@@ -261,12 +284,14 @@ nupst help → nupst help / nupst --help
- [ ] Make script executable: `chmod +x scripts/compile-all.sh`
### 4.2 Test Local Compilation
- [ ] Run `deno task compile` to compile for all platforms
- [ ] Verify all 5 binaries are created
- [ ] Check binary sizes (should be reasonable, < 100MB each)
- [ ] Test local binary on current platform: `./dist/binaries/nupst-linux-x64 --version`
### 4.3 Update Installation Scripts
- [ ] Update `install.sh`:
- Remove Node.js download logic (lines dealing with vendor/node-*)
- Add detection for binary download from GitHub releases
@@ -283,6 +308,7 @@ nupst help → nupst help / nupst --help
- Update paths to new binary location
### 4.4 Update Systemd Service
- [ ] Update systemd service file path in `ts/systemd.ts`
- [ ] Verify ExecStart points to correct binary location: `/opt/nupst/bin/nupst daemon-start`
- [ ] Remove Node.js environment variables if any
@@ -293,6 +319,7 @@ nupst help → nupst help / nupst --help
## Phase 5: Testing & Validation (4-6 hours)
### 5.1 Create Deno Test Suite
- [ ] Create `tests/` directory (or migrate from existing `test/`)
- [ ] Create `tests/snmp_test.ts`: Test SNMP manager functionality
- [ ] Create `tests/config_test.ts`: Test configuration loading/saving
@@ -302,6 +329,7 @@ nupst help → nupst help / nupst --help
- [ ] Use Deno's built-in test runner (`Deno.test()`)
### 5.2 Unit Tests
- [ ] Test SNMP connection with mock responses
- [ ] Test configuration validation
- [ ] Test UPS status parsing for different models
@@ -310,6 +338,7 @@ nupst help → nupst help / nupst --help
- [ ] Test version comparison logic
### 5.3 Integration Tests
- [ ] Test CLI command parsing for all commands
- [ ] Test config file creation and updates
- [ ] Test UPS add/edit/remove operations
@@ -317,6 +346,7 @@ nupst help → nupst help / nupst --help
- [ ] Mock systemd operations for testing
### 5.4 Binary Testing
- [ ] Test compiled binary on Linux x64
- [ ] Test compiled binary on Linux ARM64 (if available)
- [ ] Test compiled binary on macOS x64 (if available)
@@ -327,6 +357,7 @@ nupst help → nupst help / nupst --help
- [ ] Test systemd integration with compiled binary
### 5.5 Performance Testing
- [ ] Measure binary size for each platform
- [ ] Measure startup time: `time ./nupst-linux-x64 --version`
- [ ] Measure memory footprint during daemon operation
@@ -334,6 +365,7 @@ nupst help → nupst help / nupst --help
- [ ] Document performance metrics
### 5.6 Upgrade Path Testing
- [ ] Create test with v3.x config
- [ ] Verify v4.x can read existing config
- [ ] Test migration from old commands to new commands
@@ -344,6 +376,7 @@ nupst help → nupst help / nupst --help
## Phase 6: Distribution Strategy (2-3 hours)
### 6.1 GitHub Actions Workflow
- [ ] Create `.github/workflows/release.yml`:
```yaml
name: Release
@@ -373,6 +406,7 @@ nupst help → nupst help / nupst --help
```
### 6.2 Update package.json for npm
- [ ] Update version to 4.0.0
- [ ] Update description to mention Deno
- [ ] Add postinstall script to symlink appropriate binary:
@@ -398,6 +432,7 @@ nupst help → nupst help / nupst --help
- [ ] Create `bin/nupst-npm-wrapper.js` as entry point
### 6.3 Verify Distribution Methods
- [ ] Test GitHub release download and installation
- [ ] Test npm install from tarball
- [ ] Test direct install.sh script
@@ -408,6 +443,7 @@ nupst help → nupst help / nupst --help
## Phase 7: Documentation Updates (2-3 hours)
### 7.1 Update README.md
- [ ] Remove Node.js requirements section
- [ ] Update features list (mention Deno, single executable)
- [ ] Update installation methods:
@@ -422,6 +458,7 @@ nupst help → nupst help / nupst --help
- [ ] Update uninstallation instructions
### 7.2 Create MIGRATION.md
- [ ] Create detailed migration guide from v3.x to v4.x
- [ ] List all breaking changes:
1. CLI command structure reorganization
@@ -434,6 +471,7 @@ nupst help → nupst help / nupst --help
- [ ] Add rollback instructions
### 7.3 Update CHANGELOG.md
- [ ] Add v4.0.0 section with all breaking changes
- [ ] List new features (Deno, single executable)
- [ ] List improvements (startup time, binary size)
@@ -441,6 +479,7 @@ nupst help → nupst help / nupst --help
- [ ] Migration guide reference
### 7.4 Update Help Text
- [ ] Ensure all help commands show new structure
- [ ] Add examples for common operations
- [ ] Include migration notes in help output
@@ -450,6 +489,7 @@ nupst help → nupst help / nupst --help
## Phase 8: Cleanup & Finalization (1 hour)
### 8.1 Remove Obsolete Files
- [ ] Delete `vendor/` directory (Node.js binaries)
- [ ] Delete `dist/` directory (old compiled JS)
- [ ] Delete `dist_ts/` directory (old compiled TS)
@@ -460,6 +500,7 @@ nupst help → nupst help / nupst --help
- [ ] Delete `pnpm-lock.yaml`
### 8.2 Update Git Configuration
- [ ] Update `.gitignore`:
```
# Deno
@@ -480,6 +521,7 @@ nupst help → nupst help / nupst --help
- [ ] Create `.denoignore` if needed
### 8.3 Final Validation
- [ ] Run `deno check mod.ts` - verify no type errors
- [ ] Run `deno lint` - verify code quality
- [ ] Run `deno fmt --check` - verify formatting
@@ -488,6 +530,7 @@ nupst help → nupst help / nupst --help
- [ ] Test each binary manually
### 8.4 Prepare for Release
- [ ] Create git tag: `v4.0.0`
- [ ] Push to main branch
- [ ] Push tags to trigger release workflow
@@ -502,6 +545,7 @@ nupst help → nupst help / nupst --help
## Rollback Strategy
If critical issues are discovered:
- [ ] Keep `v3.1.2` tag available for rollback
- [ ] Create `v3-stable` branch for continued v3 maintenance
- [ ] Update install.sh to offer v3/v4 choice
@@ -547,6 +591,7 @@ If critical issues are discovered:
## Notes & Decisions
### Key Decisions Made:
1. ✅ Use npm:net-snmp (no pure Deno SNMP library available)
2. ✅ Major version bump to 4.0.0 (breaking changes)
3. ✅ CLI reorganization with subcommands
@@ -554,12 +599,14 @@ If critical issues are discovered:
5. ✅ 5 platform targets (Windows ARM not supported by Deno yet)
### Open Questions:
- [ ] Should we keep tsconfig.json for npm package compatibility?
- [ ] Should we fully migrate to Deno APIs (Deno.readFile) or keep node:fs?
- [ ] Should we remove the `bin/nupst` wrapper or keep it?
- [ ] Should setup.sh be completely removed or kept for dependencies?
### Risk Areas:
- ⚠️ SNMP native addon compatibility in compiled binaries (HIGH PRIORITY TO TEST)
- ⚠️ Systemd integration with new binary structure
- ⚠️ Config migration from v3 to v4