@ancha-labs/cli 0.4.20 → 0.4.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/ancha.mjs CHANGED
@@ -1,2 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import '../lib/ancha.mjs';
2
+ // Keep this launcher runnable before any Node-24-only bundle import is evaluated.
3
+ const { readFileSync } = await import('node:fs');
4
+ const { engines } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
5
+ const minimum = Number(/^>=(\d+)$/.exec(engines.node)[1]);
6
+ if (Number(process.versions.node.split('.')[0]) < minimum) {
7
+ const message = `ancha needs Node ${minimum} or newer; this is Node ${process.versions.node} (${process.execPath}).`;
8
+ const hint = `Switch to Node ${minimum} (for example \`nvm install ${minimum}\`), then run ancha again.`;
9
+ const end = process.argv.indexOf('--', 2);
10
+ const json = process.argv.slice(2, end < 0 ? undefined : end).includes('--json') || process.env.ANCHA_JSON === '1';
11
+ const stream = json ? process.stdout : process.stderr;
12
+ stream.write(json ? `${JSON.stringify({ error: { code: 'USAGE', message, hint } })}\n` : `${message} ${hint}\n`);
13
+ process.exitCode = 2;
14
+ } else {
15
+ await import('../lib/ancha.mjs');
16
+ }