initial release of @git.zone/tsdeno - deno compile wrapper that strips package.json to prevent devDependency bloat

This commit is contained in:
2026-03-15 14:03:38 +00:00
commit b64232ebe3
15 changed files with 8382 additions and 0 deletions

21
.gitignore vendored Normal file
View File

@@ -0,0 +1,21 @@
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom
.claude

4
cli.child.ts Normal file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env node
process.env.CLI_CALL = 'true';
import * as cliTool from './ts/index.js';
cliTool.runCli();

4
cli.js Normal file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env node
process.env.CLI_CALL = 'true';
const cliTool = await import('./dist_ts/index.js');
cliTool.runCli();

4
cli.ts.js Normal file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env node
process.env.CLI_CALL = 'true';
import * as tsrun from '@git.zone/tsrun';
tsrun.runPath('./cli.child.js', import.meta.url);

28
npmextra.json Normal file
View File

@@ -0,0 +1,28 @@
{
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "git.zone",
"gitrepo": "tsdeno",
"description": "A helper tool for deno compile that strips package.json to prevent devDependency bloat in compiled binaries.",
"npmPackagename": "@git.zone/tsdeno",
"license": "MIT",
"keywords": [
"deno",
"compile",
"bundle",
"binary",
"devDependencies",
"optimization"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
}
}

41
package.json Normal file
View File

@@ -0,0 +1,41 @@
{
"name": "@git.zone/tsdeno",
"version": "1.0.0",
"private": false,
"description": "A helper tool for deno compile that strips package.json to prevent devDependency bloat in compiled binaries.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"bin": {
"tsdeno": "./cli.js"
},
"scripts": {
"test": "tstest test/ --verbose",
"build": "tsbuild --web",
"buildDocs": "tsdoc"
},
"author": "Task Venture Capital GmbH",
"license": "MIT",
"files": [
"ts/**/*",
"dist_ts/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"dependencies": {
"@push.rocks/early": "^4.0.4",
"@push.rocks/smartcli": "^4.0.20",
"@push.rocks/smartfile": "^11.2.0",
"@push.rocks/smartlog": "^3.2.1",
"@push.rocks/smartlog-destination-local": "^9.0.2",
"@push.rocks/smartpath": "^6.0.0",
"@push.rocks/smartshell": "^3.3.0"
},
"devDependencies": {
"@git.zone/tsbuild": "^4.1.2",
"@git.zone/tsrun": "^2.0.1",
"@git.zone/tstest": "^3.1.8",
"@types/node": "^22.0.0"
}
}

7967
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

159
readme.md Normal file
View File

@@ -0,0 +1,159 @@
# @git.zone/tsdeno
A smart wrapper around `deno compile` that isolates `package.json` during compilation — preventing devDependencies from inflating your binary by hundreds of megabytes.
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
## Install
```bash
# Global install (recommended for CLI usage)
npm install -g @git.zone/tsdeno
# Or as a project dev dependency
pnpm install --save-dev @git.zone/tsdeno
```
## 🔥 The Problem
When you run `deno compile` in a project that has a `package.json`, Deno resolves **every** dependency listed — including `devDependencies`. It does **not** distinguish between `dependencies` and `devDependencies`. This means build tools like:
- 📦 `rspack` (~110 MB of native binaries)
- 📦 `rolldown` (~40 MB of native binaries)
- 📦 `esbuild` (~11 MB)
- 📦 `typescript` (~23 MB)
- 📦 `tswatch`, `tsbundle`, and their entire transitive trees
...all get bundled into your compiled executable, even though they're **never imported at runtime**.
A real-world example: a Deno server binary went from **596 MB** to **1022 MB** — with 426 MB of pure dead weight from dev-only build tools.
The root cause: Deno reads `package.json` and resolves the full dependency graph into its global cache, then embeds everything when compiling. There is no `--omit=dev` flag, no config to skip devDependencies, and `--node-modules-dir=none` alone doesn't help if `package.json` is present.
## ✅ The Solution
`tsdeno compile` wraps `deno compile` with a simple but effective strategy:
1. **Temporarily renames** `package.json``package.json.bak`
2. **Adds** `--node-modules-dir=none` automatically (uses Deno's global cache instead of local `node_modules`)
3. **Runs** `deno compile` with all your arguments passed through
4. **Restores** `package.json` — guaranteed, even if compilation fails (try/finally)
With `package.json` hidden, Deno only resolves dependencies declared in `deno.json` via `npm:` specifiers — which are your actual runtime dependencies.
## Usage
### CLI
Drop-in replacement — just swap `deno compile` for `tsdeno compile`:
```bash
# Before (bloated binary):
deno compile --allow-all --no-check --output myapp mod.ts
# After (lean binary):
tsdeno compile --allow-all --no-check --output myapp mod.ts
```
All `deno compile` flags are passed through untouched. Cross-compilation works the same way:
```bash
tsdeno compile --allow-all --no-check \
--output dist/myapp-linux-x64 \
--target x86_64-unknown-linux-gnu \
mod.ts
tsdeno compile --allow-all --no-check \
--output dist/myapp-macos-arm64 \
--target aarch64-apple-darwin \
mod.ts
```
### Programmatic API
You can also use `tsdeno` as a library in your build scripts:
```typescript
import { TsDeno } from '@git.zone/tsdeno';
const tsDeno = new TsDeno(); // uses process.cwd()
// or: new TsDeno('/path/to/project')
await tsDeno.compile([
'--allow-all',
'--no-check',
'--output', 'dist/myapp',
'--target', 'x86_64-unknown-linux-gnu',
'mod.ts',
]);
```
The `TsDeno` class handles the full package.json isolation lifecycle automatically.
### CI/CD Integration
Example Gitea/GitHub Actions workflow:
```yaml
steps:
- name: Set up Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install tsdeno
run: npm install -g @git.zone/tsdeno
- name: Compile binary
run: tsdeno compile --allow-all --no-check --output myapp mod.ts
```
## 🧠 How It Works — Deep Dive
### Why `package.json` Causes Bloat
Deno projects often have both `deno.json` (with `npm:` import specifiers for runtime deps) **and** a `package.json` (for npm publishing, scripts like `tswatch`/`tsbundle`, etc.). When `deno compile` runs:
1. Deno discovers `package.json` and resolves **all** listed packages (deps + devDeps)
2. These get cached in Deno's global npm cache
3. `deno compile` embeds everything it resolved — the full transitive closure
4. Your binary now contains build tools, linters, test frameworks, etc.
### What tsdeno Does Differently
By hiding `package.json` during compilation, Deno falls back to resolving **only** the `npm:` specifiers in your `deno.json`. These are your intentionally declared runtime dependencies. Combined with `--node-modules-dir=none` (which prevents Deno from creating/reading a local `node_modules`), the result is a clean binary with only what you actually import.
### Safety Guarantees
- **Atomic restore**: `package.json` is restored in a `finally` block — it will be put back even if `deno compile` crashes
- **No-op when absent**: If there's no `package.json`, tsdeno runs `deno compile` normally
- **Exit code passthrough**: If `deno compile` fails, tsdeno exits with the same code
- **Transparent**: All output from `deno compile` is streamed through to your terminal
## License and Legal Information
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
### Company Information
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
For any legal inquiries or further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

14
test/test.ts Normal file
View File

@@ -0,0 +1,14 @@
import { tap, expect } from '@git.zone/tstest/tapbundle';
import { TsDeno } from '../ts/tsdeno.classes.tsdeno.js';
tap.test('should create TsDeno instance', async () => {
const tsDeno = new TsDeno('/tmp');
expect(tsDeno.cwd).toEqual('/tmp');
});
tap.test('should create TsDeno instance with default cwd', async () => {
const tsDeno = new TsDeno();
expect(tsDeno.cwd).toEqual(process.cwd());
});
export default tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@@ -0,0 +1,8 @@
/**
* autocreated commitance info data by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@git.zone/tsdeno',
version: '1.0.0',
description: 'A helper tool for deno compile that strips package.json to prevent devDependency bloat in compiled binaries.',
};

7
ts/index.ts Normal file
View File

@@ -0,0 +1,7 @@
import * as early from '@push.rocks/early';
early.start('tsdeno');
export * from './tsdeno.classes.tsdeno.js';
export { runCli } from './tsdeno.cli.js';
early.stop();

21
ts/plugins.ts Normal file
View File

@@ -0,0 +1,21 @@
// node native
import * as path from 'path';
import * as fs from 'fs/promises';
export { path, fs };
// @push.rocks scope
import * as smartcli from '@push.rocks/smartcli';
import * as smartfile from '@push.rocks/smartfile';
import * as smartlog from '@push.rocks/smartlog';
import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local';
import * as smartpath from '@push.rocks/smartpath';
import * as smartshell from '@push.rocks/smartshell';
export {
smartcli,
smartfile,
smartlog,
smartlogDestinationLocal,
smartpath,
smartshell,
};

View File

@@ -0,0 +1,59 @@
import * as plugins from './plugins.js';
const shell = new plugins.smartshell.Smartshell({
executor: 'bash',
});
export class TsDeno {
public cwd: string;
constructor(cwdArg?: string) {
this.cwd = cwdArg || process.cwd();
}
/**
* Wraps `deno compile` with package.json isolation.
* Temporarily removes package.json so Deno doesn't resolve devDependencies
* into the compiled binary, then restores it afterwards.
*/
public async compile(args: string[]): Promise<void> {
const packageJsonPath = plugins.path.join(this.cwd, 'package.json');
const backupPath = plugins.path.join(this.cwd, 'package.json.bak');
let hasPackageJson = false;
try {
await plugins.fs.access(packageJsonPath);
hasPackageJson = true;
} catch {
hasPackageJson = false;
}
// Ensure --node-modules-dir=none is present
if (!args.some((arg) => arg.startsWith('--node-modules-dir'))) {
args = ['--node-modules-dir=none', ...args];
}
// Temporarily hide package.json from Deno
if (hasPackageJson) {
console.log('tsdeno: temporarily hiding package.json to exclude devDependencies from bundle');
await plugins.fs.rename(packageJsonPath, backupPath);
}
try {
const shellCommand = `cd ${this.cwd} && deno compile ${args.join(' ')}`;
console.log(`tsdeno: running deno compile ${args.join(' ')}`);
const result = await shell.execPassthrough(shellCommand);
if (result.exitCode !== 0) {
console.error(`tsdeno: deno compile exited with code ${result.exitCode}`);
process.exit(result.exitCode);
}
} finally {
// Always restore package.json
if (hasPackageJson) {
await plugins.fs.rename(backupPath, packageJsonPath);
console.log('tsdeno: restored package.json');
}
}
}
}

33
ts/tsdeno.cli.ts Normal file
View File

@@ -0,0 +1,33 @@
import * as plugins from './plugins.js';
import { TsDeno } from './tsdeno.classes.tsdeno.js';
import { commitinfo } from './00_commitinfo_data.js';
const tsdenoCli = new plugins.smartcli.Smartcli();
tsdenoCli.addVersion(commitinfo.version);
tsdenoCli.standardCommand().subscribe(async (argvArg) => {
console.log(`@git.zone/tsdeno v${commitinfo.version}`);
console.log('');
console.log('Usage:');
console.log(' tsdeno compile [deno compile args...] Compile with package.json isolation');
console.log('');
console.log('The compile command temporarily removes package.json before running');
console.log('deno compile, preventing devDependencies from bloating the binary.');
console.log('--node-modules-dir=none is added automatically.');
});
tsdenoCli.addCommand('compile').subscribe(async (argvArg) => {
const tsDeno = new TsDeno();
// Pass through all args after "compile" to deno compile
const rawArgs = process.argv.slice(3);
await tsDeno.compile(rawArgs);
});
export { tsdenoCli };
export const runCli = async () => {
tsdenoCli.startParse();
};

12
tsconfig.json Normal file
View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}