@tostudy-ai/cli 0.18.5 → 0.18.7
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 +25 -14
- package/dist/cli.js.map +2 -2
- package/dist/main.js +185 -147
- package/dist/main.js.map +4 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -21,6 +21,29 @@ function canRunOnNode(version) {
|
|
|
21
21
|
}
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
|
+
var INSTALL_UNIX = "curl -fsSL https://tostudy.ai/install.sh | sh";
|
|
25
|
+
var INSTALL_WINDOWS = "irm https://tostudy.ai/install.ps1 | iex";
|
|
26
|
+
function nodeGuardMessage(mode, version, pt) {
|
|
27
|
+
const installers = ` macOS/Linux: ${INSTALL_UNIX}
|
|
28
|
+
Windows (PowerShell): ${INSTALL_WINDOWS}
|
|
29
|
+
`;
|
|
30
|
+
if (mode === "block") {
|
|
31
|
+
return pt ? `Erro: o ToStudy CLI precisa do Node.js ${MIN_NODE_MAJOR} ou superior.
|
|
32
|
+
Voc\xEA est\xE1 no Node.js ${version}.
|
|
33
|
+
Para atualizar, rode o instalador de novo:
|
|
34
|
+
${installers}Ou atualize em https://nodejs.org. Depois rode o comando de novo.
|
|
35
|
+
` : `Error: the ToStudy CLI requires Node.js ${MIN_NODE_MAJOR} or newer.
|
|
36
|
+
You are on Node.js ${version}.
|
|
37
|
+
To update, run the installer again:
|
|
38
|
+
${installers}Or update at https://nodejs.org. Then run the command again.
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
return pt ? `Aviso: o Node.js ${version} n\xE3o \xE9 mais suportado pelo ToStudy CLI. Atualize para o Node.js ${MIN_NODE_MAJOR} ou superior rodando o instalador de novo:
|
|
42
|
+
${installers}Ou atualize em https://nodejs.org.
|
|
43
|
+
` : `Warning: Node.js ${version} is no longer supported by the ToStudy CLI. Update to Node.js ${MIN_NODE_MAJOR} or newer by running the installer again:
|
|
44
|
+
${installers}Or update at https://nodejs.org.
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
24
47
|
|
|
25
48
|
// src/cli-entry.ts
|
|
26
49
|
if (!process.env.LOG_LEVEL) {
|
|
@@ -31,22 +54,10 @@ if (!meetsNodeFloor(process.versions.node)) {
|
|
|
31
54
|
const localeFlag = localeFlagIdx !== -1 && localeFlagIdx + 1 < process.argv.length ? process.argv[localeFlagIdx + 1] : void 0;
|
|
32
55
|
const pt = localeFlag === "pt-BR" || localeFlag === "en-US" ? localeFlag === "pt-BR" : !(process.env["LANG"] ?? "").toLowerCase().startsWith("en");
|
|
33
56
|
if (!canRunOnNode(process.versions.node)) {
|
|
34
|
-
process.stderr.write(
|
|
35
|
-
pt ? `Erro: o ToStudy CLI precisa do Node.js ${MIN_NODE_MAJOR} ou superior.
|
|
36
|
-
Voc\xEA est\xE1 no Node.js ${process.versions.node}.
|
|
37
|
-
Atualize em https://nodejs.org e rode o comando de novo.
|
|
38
|
-
` : `Error: the ToStudy CLI requires Node.js ${MIN_NODE_MAJOR} or newer.
|
|
39
|
-
You are on Node.js ${process.versions.node}.
|
|
40
|
-
Update at https://nodejs.org and run the command again.
|
|
41
|
-
`
|
|
42
|
-
);
|
|
57
|
+
process.stderr.write(nodeGuardMessage("block", process.versions.node, pt));
|
|
43
58
|
process.exit(1);
|
|
44
59
|
}
|
|
45
|
-
process.stderr.write(
|
|
46
|
-
pt ? `Aviso: o Node.js ${process.versions.node} n\xE3o \xE9 mais suportado pelo ToStudy CLI. Atualize para o Node.js ${MIN_NODE_MAJOR} ou superior em https://nodejs.org.
|
|
47
|
-
` : `Warning: Node.js ${process.versions.node} is no longer supported by the ToStudy CLI. Update to Node.js ${MIN_NODE_MAJOR} or newer at https://nodejs.org.
|
|
48
|
-
`
|
|
49
|
-
);
|
|
60
|
+
process.stderr.write(nodeGuardMessage("warn", process.versions.node, pt));
|
|
50
61
|
}
|
|
51
62
|
if (!process.env["TOSTUDY_LOCALE"]) {
|
|
52
63
|
try {
|
package/dist/cli.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/node-floor.ts", "../src/cli-entry.ts"],
|
|
4
|
-
"sourcesContent": ["// GH #2114 \u2014 the Node floors of the CLI, read by the runtime guard (cli-entry.ts),\n// `tostudy doctor` (installer/node-detector.ts) and the label doctor prints.\n//\n// Two floors on purpose:\n// - MIN_NODE_MAJOR is the supported floor (Node 20 is EOL since 2026-04-30). It must\n// match `engines` in package.json and the esbuild target in build-npm.mjs.\n// - MIN_NODE_RUNTIME is where the bundle actually loads (undici 7 needs 20.18.1). The\n// guard blocks below it and only warns between the two, so students on Node 20, who\n// ran 0.18.0 fine, are not locked out by the auto-update.\n//\n// Leaf module on purpose: cli-entry.ts imports it before the bundle loads, so it must\n// not import anything (the guard has to run on runtimes the rest of the CLI rejects).\nexport const MIN_NODE_MAJOR = 22;\nexport const MIN_NODE_RUNTIME = \"20.18.1\";\n\nfunction parseVersion(version: string): [number, number, number] | null {\n const match = /^v?(\\d+)\\.(\\d+)\\.(\\d+)/.exec(version.trim());\n if (!match) return null;\n return [Number(match[1]), Number(match[2]), Number(match[3])];\n}\n\n/** Supported floor. Accepts `process.versions.node` (\"22.1.0\") or `node --version` (\"v22.1.0\"). */\nexport function meetsNodeFloor(version: string): boolean {\n const parsed = parseVersion(version);\n return parsed !== null && parsed[0] >= MIN_NODE_MAJOR;\n}\n\n/** Hard floor: false means the bundle cannot run on this Node at all. */\nexport function canRunOnNode(version: string): boolean {\n const parsed = parseVersion(version);\n const floor = parseVersion(MIN_NODE_RUNTIME);\n if (!parsed || !floor) return false;\n for (let i = 0; i < 3; i++) {\n if (parsed[i]! !== floor[i]!) return parsed[i]! > floor[i]!;\n }\n return true;\n}\n", "/**\n * Entry point for the bundled npm CLI.\n * This file is used by build-npm.mjs as the esbuild entrypoint.\n *\n * Uses dynamic import so LOG_LEVEL is set BEFORE any module loads\n * (ESM static imports are hoisted and run before top-level code).\n */\n\n// The only static import: a leaf with no imports and no side effects (see node-floor.ts).\nimport {
|
|
5
|
-
"mappings": ";;;AAYO,IAAM,iBAAiB;AACvB,IAAM,mBAAmB;AAEhC,SAAS,aAAa,SAAkD;AACtE,QAAM,QAAQ,yBAAyB,KAAK,QAAQ,KAAK,CAAC;AAC1D,MAAI,CAAC,MAAO,QAAO;AACnB,SAAO,CAAC,OAAO,MAAM,CAAC,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC,CAAC;AAC9D;AAGO,SAAS,eAAe,SAA0B;AACvD,QAAM,SAAS,aAAa,OAAO;AACnC,SAAO,WAAW,QAAQ,OAAO,CAAC,KAAK;AACzC;AAGO,SAAS,aAAa,SAA0B;AACrD,QAAM,SAAS,aAAa,OAAO;AACnC,QAAM,QAAQ,aAAa,gBAAgB;AAC3C,MAAI,CAAC,UAAU,CAAC,MAAO,QAAO;AAC9B,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,QAAI,OAAO,CAAC,MAAO,MAAM,CAAC,EAAI,QAAO,OAAO,CAAC,IAAK,MAAM,CAAC;AAAA,EAC3D;AACA,SAAO;AACT;;;
|
|
4
|
+
"sourcesContent": ["// GH #2114 \u2014 the Node floors of the CLI, read by the runtime guard (cli-entry.ts),\n// `tostudy doctor` (installer/node-detector.ts) and the label doctor prints.\n//\n// Two floors on purpose:\n// - MIN_NODE_MAJOR is the supported floor (Node 20 is EOL since 2026-04-30). It must\n// match `engines` in package.json and the esbuild target in build-npm.mjs.\n// - MIN_NODE_RUNTIME is where the bundle actually loads (undici 7 needs 20.18.1). The\n// guard blocks below it and only warns between the two, so students on Node 20, who\n// ran 0.18.0 fine, are not locked out by the auto-update.\n//\n// Leaf module on purpose: cli-entry.ts imports it before the bundle loads, so it must\n// not import anything (the guard has to run on runtimes the rest of the CLI rejects).\nexport const MIN_NODE_MAJOR = 22;\nexport const MIN_NODE_RUNTIME = \"20.18.1\";\n\nfunction parseVersion(version: string): [number, number, number] | null {\n const match = /^v?(\\d+)\\.(\\d+)\\.(\\d+)/.exec(version.trim());\n if (!match) return null;\n return [Number(match[1]), Number(match[2]), Number(match[3])];\n}\n\n/** Supported floor. Accepts `process.versions.node` (\"22.1.0\") or `node --version` (\"v22.1.0\"). */\nexport function meetsNodeFloor(version: string): boolean {\n const parsed = parseVersion(version);\n return parsed !== null && parsed[0] >= MIN_NODE_MAJOR;\n}\n\n/** Hard floor: false means the bundle cannot run on this Node at all. */\nexport function canRunOnNode(version: string): boolean {\n const parsed = parseVersion(version);\n const floor = parseVersion(MIN_NODE_RUNTIME);\n if (!parsed || !floor) return false;\n for (let i = 0; i < 3; i++) {\n if (parsed[i]! !== floor[i]!) return parsed[i]! > floor[i]!;\n }\n return true;\n}\n\n// GH-2130 \u2014 since GH-2115 install.sh / install.ps1 upgrade Node below 22, so the guard\n// sends the student back to them first, with nodejs.org as the manual path. Lives here\n// (a leaf) so it is testable without running the guard. The English phrases\n// \"requires Node.js N or newer\" and \"Update to Node.js N or newer\" are asserted by the\n// CI job in .github/scripts/tostudy-cli-assert-node-guard.sh.\nconst INSTALL_UNIX = \"curl -fsSL https://tostudy.ai/install.sh | sh\";\nconst INSTALL_WINDOWS = \"irm https://tostudy.ai/install.ps1 | iex\";\n\n/** Text the runtime guard prints: `block` below MIN_NODE_RUNTIME, `warn` up to MIN_NODE_MAJOR. */\nexport function nodeGuardMessage(mode: \"block\" | \"warn\", version: string, pt: boolean): string {\n const installers = ` macOS/Linux: ${INSTALL_UNIX}\\n Windows (PowerShell): ${INSTALL_WINDOWS}\\n`;\n if (mode === \"block\") {\n return pt\n ? `Erro: o ToStudy CLI precisa do Node.js ${MIN_NODE_MAJOR} ou superior.\\nVoc\u00EA est\u00E1 no Node.js ${version}.\\nPara atualizar, rode o instalador de novo:\\n${installers}Ou atualize em https://nodejs.org. Depois rode o comando de novo.\\n`\n : `Error: the ToStudy CLI requires Node.js ${MIN_NODE_MAJOR} or newer.\\nYou are on Node.js ${version}.\\nTo update, run the installer again:\\n${installers}Or update at https://nodejs.org. Then run the command again.\\n`;\n }\n return pt\n ? `Aviso: o Node.js ${version} n\u00E3o \u00E9 mais suportado pelo ToStudy CLI. Atualize para o Node.js ${MIN_NODE_MAJOR} ou superior rodando o instalador de novo:\\n${installers}Ou atualize em https://nodejs.org.\\n`\n : `Warning: Node.js ${version} is no longer supported by the ToStudy CLI. Update to Node.js ${MIN_NODE_MAJOR} or newer by running the installer again:\\n${installers}Or update at https://nodejs.org.\\n`;\n}\n", "/**\n * Entry point for the bundled npm CLI.\n * This file is used by build-npm.mjs as the esbuild entrypoint.\n *\n * Uses dynamic import so LOG_LEVEL is set BEFORE any module loads\n * (ESM static imports are hoisted and run before top-level code).\n */\n\n// The only static import: a leaf with no imports and no side effects (see node-floor.ts).\nimport { canRunOnNode, meetsNodeFloor, nodeGuardMessage } from \"./node-floor\";\n\n// Suppress @repo/logger output in CLI mode\nif (!process.env.LOG_LEVEL) {\n process.env.LOG_LEVEL = \"fatal\";\n}\n\n// GH #1414 \u2014 guard de versao ANTES de qualquer import. O CLI exige Node >= 22\n// (`engines`, node-detector.ts, build target `node22`) mas nada checava em runtime:\n// o aluno com Node antigo levava um erro cru de sintaxe/referencia, sem saber que a\n// causa era a versao. Mensagem simples e sem dependencia \u2014 o bundle de erros vive\n// dentro de ./cli, que e justamente o que nao pode carregar aqui.\n//\n// GH #2114 \u2014 o piso real das dependencias e 20.18.1 (undici 7; commander 14 pede 20),\n// e o Node 20 esta em EOL desde 2026-04-30, entao o piso suportado e 22: abaixo de\n// 20.18.1 o guard bloqueia, entre 20.18.1 e 21 ele so avisa (node-floor.ts). O guard so\n// roda antes do undici porque o resto do CLI mora em dist/main.js (build-npm.mjs): num\n// arquivo unico o esbuild subia os imports externos para o topo de dist/cli.js e o Node\n// 18 quebrava dentro do undici.\n//\n// GH #2130 \u2014 desde a GH #2115 o install.sh e o install.ps1 atualizam o Node abaixo do\n// 22, entao a mensagem manda rodar o instalador de novo e deixa o nodejs.org como\n// caminho manual (texto em node-floor.ts:nodeGuardMessage).\n//\n// A resolucao de idioma espelha `errors/index.ts:resolveLocale()` de proposito:\n// `--locale` > `LANG` > pt-BR (o CLI e pt-BR-first, CHORE-1571 Fase D). Nao da\n// para reusar a funcao \u2014 ela vive no bundle que este guard existe para nao\n// carregar. Sem o passo do `--locale` este era o unico ponto do CLI que ignorava\n// a flag (GH #1414).\nif (!meetsNodeFloor(process.versions.node)) {\n const localeFlagIdx = process.argv.indexOf(\"--locale\");\n const localeFlag =\n localeFlagIdx !== -1 && localeFlagIdx + 1 < process.argv.length\n ? process.argv[localeFlagIdx + 1]\n : undefined;\n const pt =\n localeFlag === \"pt-BR\" || localeFlag === \"en-US\"\n ? localeFlag === \"pt-BR\"\n : !(process.env[\"LANG\"] ?? \"\").toLowerCase().startsWith(\"en\");\n // GH #2114 \u2014 below MIN_NODE_RUNTIME the bundle cannot load (undici 7): stop here.\n // Between it and MIN_NODE_MAJOR (Node 20.18.1+) the CLI still works, so warn and go\n // on: those students ran 0.18.0 fine and get this version through the auto-update.\n if (!canRunOnNode(process.versions.node)) {\n process.stderr.write(nodeGuardMessage(\"block\", process.versions.node, pt));\n process.exit(1);\n }\n process.stderr.write(nodeGuardMessage(\"warn\", process.versions.node, pt));\n}\n\n// GH #1414 item 7 \u2014 account locale captured by `tostudy login` (config.json)\n// beats the OS LANG. Read here, before the bundle loads, and handed over via\n// env so errors/index.ts stays a leaf (no errors \u2192 auth import edge).\nif (!process.env[\"TOSTUDY_LOCALE\"]) {\n try {\n const { readFileSync } = await import(\"node:fs\");\n const { join } = await import(\"node:path\");\n const { homedir } = await import(\"node:os\");\n const xdg = process.env[\"XDG_CONFIG_HOME\"];\n const dir =\n process.platform === \"linux\" && xdg ? join(xdg, \"tostudy\") : join(homedir(), \".tostudy\");\n const { locale } = JSON.parse(readFileSync(join(dir, \"config.json\"), \"utf-8\")) as {\n locale?: unknown;\n };\n if (locale === \"pt-BR\" || locale === \"en-US\") process.env[\"TOSTUDY_LOCALE\"] = locale;\n } catch {\n // No session yet, or unreadable \u2014 LANG / pt-BR fallback applies.\n }\n}\n\nconst { createProgram, CLI_VERSION, checkForUpdates, maybeAutoUpdate } = await import(\"./main\");\n\n// GH #1419 item 3 \u2014 `.action(async \u2026)` + `parse()` means a rejected command\n// promise is an unhandled rejection: Node dumps a raw stack. One net, in the\n// student's language, instead of a try/catch per command.\nprocess.on(\"unhandledRejection\", (reason) => {\n const msg = reason instanceof Error ? reason.message : String(reason);\n process.stderr.write(`Erro: ${msg}\\n Se o problema continuar, rode: tostudy doctor\\n`);\n process.exit(1);\n});\n\nconst program = createProgram();\nprogram.parse();\n\ncheckForUpdates(CLI_VERSION);\nmaybeAutoUpdate(CLI_VERSION);\n\nexport {};\n"],
|
|
5
|
+
"mappings": ";;;AAYO,IAAM,iBAAiB;AACvB,IAAM,mBAAmB;AAEhC,SAAS,aAAa,SAAkD;AACtE,QAAM,QAAQ,yBAAyB,KAAK,QAAQ,KAAK,CAAC;AAC1D,MAAI,CAAC,MAAO,QAAO;AACnB,SAAO,CAAC,OAAO,MAAM,CAAC,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC,CAAC;AAC9D;AAGO,SAAS,eAAe,SAA0B;AACvD,QAAM,SAAS,aAAa,OAAO;AACnC,SAAO,WAAW,QAAQ,OAAO,CAAC,KAAK;AACzC;AAGO,SAAS,aAAa,SAA0B;AACrD,QAAM,SAAS,aAAa,OAAO;AACnC,QAAM,QAAQ,aAAa,gBAAgB;AAC3C,MAAI,CAAC,UAAU,CAAC,MAAO,QAAO;AAC9B,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,QAAI,OAAO,CAAC,MAAO,MAAM,CAAC,EAAI,QAAO,OAAO,CAAC,IAAK,MAAM,CAAC;AAAA,EAC3D;AACA,SAAO;AACT;AAOA,IAAM,eAAe;AACrB,IAAM,kBAAkB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