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

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();
};