Skip to content

Commit

Permalink
node16, better info
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed Apr 17, 2024
1 parent 5e525e3 commit 48691ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Think of it as doing code-splitting 'last', rather than first.

## Requirements

Node 14+.
Node 16+.

Kuto works best on large (>1mb) singular JS bundles 'bundled' to ESM — the tool works on a statement level, and an IIFE/webpack output is one giant statement.

Expand Down
10 changes: 10 additions & 0 deletions app/cmd/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,18 @@ export default async function cmdInfo(args: InfoArgs) {
console.info(`- ${g}${rw ? ' (written)' : ''}`);
}

console.info('\nImports used at top-level:');
for (const g of toplevelFind.imports.keys()) {
console.info(`- ${g}`);
}

console.info('\nGlobals used in callables:');
for (const [g, rw] of nestedFind.globals) {
console.info(`- ${g}${rw ? ' (written)' : ''}`);
}

console.info('\nImports used in callables:');
for (const g of nestedFind.imports.keys()) {
console.info(`- ${g}`);
}
}
16 changes: 6 additions & 10 deletions app/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/usr/bin/env node

import * as cmd from './lib/cmd.ts';
import cmdSplit from './cmd/split.ts';
import cmdInfo from './cmd/info.ts';

cmd.register('info', {
description: 'Show information about a JS module file',
positional: true,
usageSuffix: '<path>',
handler(res) {
async handler(res) {
if (res.positionals.length !== 1) {
throw new cmd.CommandError();
}

const { default: cmdInfo } = await import('./cmd/info.ts');
return cmdInfo({ path: res.positionals[0] });
},
});
Expand Down Expand Up @@ -49,15 +48,16 @@ cmd.register('split', {
default: '',
short: 'n',
help: 'output basename (default to basename of source)',
}
},
},
positional: true,
usageSuffix: '<source> <outdir/>',
handler(res) {
async handler(res) {
if (res.positionals.length !== 2) {
throw new cmd.CommandError();
}

const { default: cmdSplit } = await import('./cmd/split.ts');
return cmdSplit({
min: +(res.values['min'] ?? 0),
keep: +(res.values['keep'] ?? 0),
Expand All @@ -70,8 +70,4 @@ cmd.register('split', {
},
});

// TODO: until we rev from node14
const p = Promise.resolve(cmd.run());
p.catch((e) => {
throw e;
});
await cmd.run();
2 changes: 1 addition & 1 deletion app/lib/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ export const run = (argv = process.argv.slice(2)): any => {
process.exit(v['help'] ? 0 : 1);
};

export class CommandError extends Error { }
export class CommandError extends Error {}

0 comments on commit 48691ed

Please sign in to comment.