@thiagodiogo/psjava 0.0.1-beta.2 → 0.0.1-beta.3

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/dist/cli.js CHANGED
@@ -3,16 +3,16 @@ import { runFile } from './commands/run.js';
3
3
  import { runDoctor } from './commands/doctor.js';
4
4
  export function buildProgram() {
5
5
  const program = new Command();
6
- program.name('psjava').description('Roda arquivos .psjava').version('0.1.0');
6
+ program.name('psjava').description('Run .psjava files').version('0.1.0');
7
7
  program
8
- .argument('[file]', 'arquivo .psjava')
9
- .option('-d, --debug', 'imprime o tempo da execução ao final')
8
+ .argument('[file]', '.psjava file')
9
+ .option('-d, --debug', 'print the elapsed time at the end')
10
10
  .action(async (file, opts) => {
11
11
  if (!file)
12
12
  return program.help();
13
13
  await runFile(file, opts.debug);
14
14
  });
15
- program.command('doctor').description('Verifica o JDK (jshell)').action(runDoctor);
15
+ program.command('doctor').description('Check the JDK (jshell)').action(runDoctor);
16
16
  return program;
17
17
  }
18
18
  export async function runCli(argv = process.argv) {
@@ -20,7 +20,7 @@ export async function runCli(argv = process.argv) {
20
20
  await buildProgram().parseAsync(argv);
21
21
  }
22
22
  catch (err) {
23
- console.error(`\nErro: ${err instanceof Error ? err.message : String(err)}`);
23
+ console.error(`\nError: ${err instanceof Error ? err.message : String(err)}`);
24
24
  process.exitCode = 1;
25
25
  }
26
26
  }
@@ -3,7 +3,7 @@ import { resolveJshell } from '../core/jdk.js';
3
3
  export async function runDoctor() {
4
4
  try {
5
5
  await resolveJshell();
6
- console.log(chalk.green('✓ jshell encontradopronto pra rodar .psjava'));
6
+ console.log(chalk.green('✓ jshell foundready to run .psjava'));
7
7
  }
8
8
  catch (err) {
9
9
  console.log(chalk.red(`✗ ${err instanceof Error ? err.message : String(err)}`));
@@ -13,11 +13,11 @@ export function scriptCandidates(file) {
13
13
  export async function runFile(file, debug = false) {
14
14
  const tried = scriptCandidates(file);
15
15
  if (tried.length === 0) {
16
- throw new Error(`psjava roda arquivos .psjava (recebi: ${file})`);
16
+ throw new Error(`psjava only runs .psjava files (got: ${file})`);
17
17
  }
18
18
  const found = tried.find((f) => existsSync(f));
19
19
  if (!found) {
20
- throw new Error(`não encontrei o arquivo. Tentei: ${tried.join(', ')}`);
20
+ throw new Error(`file not found. Tried: ${tried.join(', ')}`);
21
21
  }
22
22
  const source = await readFile(found, 'utf8');
23
23
  const code = await runSource(source, debug);
@@ -1,2 +1,2 @@
1
- /** Acha o jshell no PATH e confirma que roda. Lança erro amigável se faltar. */
1
+ /** Finds jshell on the PATH and confirms it runs. Throws a friendly error if missing. */
2
2
  export declare function resolveJshell(): Promise<string>;
package/dist/core/jdk.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { execFile } from 'child_process';
2
2
  import { promisify } from 'util';
3
3
  const exec = promisify(execFile);
4
- /** Acha o jshell no PATH e confirma que roda. Lança erro amigável se faltar. */
4
+ /** Finds jshell on the PATH and confirms it runs. Throws a friendly error if missing. */
5
5
  export async function resolveJshell() {
6
6
  try {
7
7
  await exec('jshell', ['--version']);
8
8
  return 'jshell';
9
9
  }
10
10
  catch {
11
- throw new Error('jshell não encontrado. Instale um JDK (11+) e garanta que o jshell está no PATH.');
11
+ throw new Error('jshell not found. Install a JDK (11+) and make sure jshell is on your PATH.');
12
12
  }
13
13
  }
@@ -11,18 +11,28 @@ const PRELUDE = [
11
11
  export function buildSession(source) {
12
12
  return `${PRELUDE}\n${source.replace(/^/, '')}`; // ponytail: BOM é lixo de encoding, não é edição do código
13
13
  }
14
+ // Força UTF-8 na entrada e na saída do jshell — sem isso, em locale não-UTF-8 (ex: runner Linux
15
+ // em latin1) o `á` sai como byte solto e vira "ol�". -J = VM do jshell (escreve a saída final);
16
+ // -R = VM de execução (roda o System.out). file.encoding cobre Java 11; stdout/stderr.encoding cobre 18+.
17
+ const UTF8_FLAGS = [
18
+ '-J-Dfile.encoding=UTF-8',
19
+ '-J-Dstdout.encoding=UTF-8',
20
+ '-J-Dstderr.encoding=UTF-8',
21
+ '-R-Dfile.encoding=UTF-8',
22
+ '-R-Dstdout.encoding=UTF-8',
23
+ ];
14
24
  export async function runSource(source, debug = false) {
15
25
  const jshell = await resolveJshell(); // erro amigável se faltar JDK
16
26
  const code = buildSession(source);
17
27
  const start = performance.now();
18
28
  return new Promise((resolve) => {
19
29
  // -s: modo script silencioso (sem banner/prompt); lê de stdin e sai sozinho
20
- const p = spawn(jshell, ['-s', '-'], { stdio: ['pipe', 'inherit', 'inherit'] });
30
+ const p = spawn(jshell, ['-s', ...UTF8_FLAGS, '-'], { stdio: ['pipe', 'inherit', 'inherit'] });
21
31
  p.stdin.end(code + '\n');
22
32
  p.on('close', (c) => {
23
33
  if (debug) {
24
34
  const s = ((performance.now() - start) / 1000).toFixed(2);
25
- console.error(chalk.dim(`[psjava] concluído em ${s}s`));
35
+ console.error(chalk.dim(`[psjava] done in ${s}s`));
26
36
  }
27
37
  resolve(c ?? 0);
28
38
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thiagodiogo/psjava",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.3",
4
4
  "description": "Run .psjava files as scripts — plain Java, no ceremony, on top of JShell.",
5
5
  "keywords": [
6
6
  "psjava",