diff --git a/README.md b/README.md index 737a96c..0d5d471 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/app/cmd/info.ts b/app/cmd/info.ts index b892907..598976a 100644 --- a/app/cmd/info.ts +++ b/app/cmd/info.ts @@ -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}`); + } } diff --git a/app/index.ts b/app/index.ts index 6526192..d34102f 100644 --- a/app/index.ts +++ b/app/index.ts @@ -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: '', - 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] }); }, }); @@ -49,15 +48,16 @@ cmd.register('split', { default: '', short: 'n', help: 'output basename (default to basename of source)', - } + }, }, positional: true, usageSuffix: ' ', - 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), @@ -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(); diff --git a/app/lib/cmd.ts b/app/lib/cmd.ts index d564ebd..9351c0a 100644 --- a/app/lib/cmd.ts +++ b/app/lib/cmd.ts @@ -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 {}