@optique/man 1.0.0-dev.771 → 1.0.0-dev.783
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.cjs +84 -9
- package/dist/cli.js +84 -9
- package/package.json +3 -3
package/dist/cli.cjs
CHANGED
|
@@ -17,7 +17,7 @@ const node_url = require_man.__toESM(require("node:url"));
|
|
|
17
17
|
|
|
18
18
|
//#region deno.json
|
|
19
19
|
var name = "@optique/man";
|
|
20
|
-
var version = "1.0.0-dev.
|
|
20
|
+
var version = "1.0.0-dev.783+64de3665";
|
|
21
21
|
var license = "MIT";
|
|
22
22
|
var exports$1 = {
|
|
23
23
|
".": "./src/index.ts",
|
|
@@ -56,6 +56,7 @@ var deno_default = {
|
|
|
56
56
|
|
|
57
57
|
//#endregion
|
|
58
58
|
//#region src/cli.ts
|
|
59
|
+
const jsxTsxPattern = /\.[mc]?[jt]sx$/;
|
|
59
60
|
const EXIT_FILE_NOT_FOUND = 1;
|
|
60
61
|
const EXIT_EXPORT_NOT_FOUND = 2;
|
|
61
62
|
const EXIT_NOT_PROGRAM_OR_PARSER = 3;
|
|
@@ -203,7 +204,7 @@ an Optique parser (e.g., from ${(0, __optique_core_message.commandLine)("object(
|
|
|
203
204
|
${(0, __optique_core_message.commandLine)("command()")}, etc.).`, { exitCode: EXIT_NOT_PROGRAM_OR_PARSER });
|
|
204
205
|
}
|
|
205
206
|
/**
|
|
206
|
-
* Error handler for missing tsx.
|
|
207
|
+
* Error handler for missing tsx for TypeScript files.
|
|
207
208
|
*/
|
|
208
209
|
function tsxRequiredError(filePath) {
|
|
209
210
|
const version$1 = getNodeMajorMinor();
|
|
@@ -216,6 +217,22 @@ Install tsx as a dev dependency:
|
|
|
216
217
|
|
|
217
218
|
Or upgrade to Node.js 25.2.0 or later, which supports TypeScript natively.
|
|
218
219
|
|
|
220
|
+
Alternatively, use a pre-compiled JavaScript file instead.`, { exitCode: EXIT_TSX_REQUIRED });
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Error handler for missing tsx for JSX/TSX files.
|
|
224
|
+
*/
|
|
225
|
+
function jsxLoaderRequiredError(filePath) {
|
|
226
|
+
const version$1 = getNodeMajorMinor();
|
|
227
|
+
const versionStr = version$1 ? `${version$1[0]}.${version$1[1]}` : "unknown";
|
|
228
|
+
const isTsx = /\.[mc]?tsx$/.test(filePath);
|
|
229
|
+
const fileKind = isTsx ? "TSX" : "JSX";
|
|
230
|
+
(0, __optique_run.printError)(__optique_core_message.message`${fileKind} file ${filePath} cannot be loaded on Node.js ${versionStr}.
|
|
231
|
+
|
|
232
|
+
Install tsx as a dev dependency:
|
|
233
|
+
|
|
234
|
+
${(0, __optique_core_message.commandLine)("npm install -D tsx")}
|
|
235
|
+
|
|
219
236
|
Alternatively, use a pre-compiled JavaScript file instead.`, { exitCode: EXIT_TSX_REQUIRED });
|
|
220
237
|
}
|
|
221
238
|
/**
|
|
@@ -234,22 +251,80 @@ Make sure you have write permission and the parent directory exists.`, { exitCod
|
|
|
234
251
|
}
|
|
235
252
|
/**
|
|
236
253
|
* Imports a module from the given file path.
|
|
237
|
-
* Handles TypeScript files on Node.js by using tsx if needed.
|
|
254
|
+
* Handles TypeScript and JSX files on Node.js by using tsx if needed.
|
|
255
|
+
* @param filePath The path to the module file.
|
|
256
|
+
* @returns The imported module's exports.
|
|
257
|
+
* @throws If the module fails to import for reasons other than a missing
|
|
258
|
+
* tsx loader (which causes the process to exit instead).
|
|
238
259
|
*/
|
|
239
260
|
async function importModule(filePath) {
|
|
240
261
|
const absolutePath = (0, node_path.resolve)(filePath);
|
|
241
262
|
if (!(0, node_fs.existsSync)(absolutePath)) fileNotFoundError(filePath);
|
|
242
|
-
const
|
|
263
|
+
const isPlainTs = /\.[mc]?ts$/.test(filePath);
|
|
264
|
+
const isJsxOrTsx = jsxTsxPattern.test(filePath);
|
|
243
265
|
const isDeno = "Deno" in globalThis;
|
|
244
266
|
const isBun = "Bun" in globalThis;
|
|
245
|
-
if (!isDeno && !isBun &&
|
|
267
|
+
if (!isDeno && !isBun && (isJsxOrTsx || isPlainTs && !nodeSupportsNativeTypeScript())) await registerTsx(filePath, isJsxOrTsx);
|
|
268
|
+
else if (!isDeno && !isBun) await tryRegisterTsx();
|
|
269
|
+
const fileUrl = (0, node_url.pathToFileURL)(absolutePath).href;
|
|
270
|
+
try {
|
|
271
|
+
return await import(fileUrl);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (!isDeno && !isBun && isNodeError(error) && error.code === "ERR_UNKNOWN_FILE_EXTENSION") {
|
|
274
|
+
const failedPath = extractPathFromExtensionError(error.message);
|
|
275
|
+
if (failedPath != null && jsxTsxPattern.test(failedPath)) jsxLoaderRequiredError(failedPath);
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Checks whether an error is a Node.js system error with a string `code`.
|
|
282
|
+
* @param error The value to check.
|
|
283
|
+
* @returns `true` if the error has a string `code` property.
|
|
284
|
+
*/
|
|
285
|
+
function isNodeError(error) {
|
|
286
|
+
return error instanceof Error && "code" in error && typeof error.code === "string";
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Extracts the file path from a Node.js `ERR_UNKNOWN_FILE_EXTENSION` error
|
|
290
|
+
* message, which has the format `Unknown file extension ".ext" for /path`.
|
|
291
|
+
* @param message The error message string.
|
|
292
|
+
* @returns The file path, or null if the message format is unexpected.
|
|
293
|
+
*/
|
|
294
|
+
function extractPathFromExtensionError(message$1) {
|
|
295
|
+
const match = /^Unknown file extension "\.[^"]*" for (.+)$/.exec(message$1);
|
|
296
|
+
return match?.[1] ?? null;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Registers the tsx loader for TypeScript/JSX/TSX support on Node.js.
|
|
300
|
+
* @param filePath The file path being loaded (used for error messages).
|
|
301
|
+
* @param isJsxOrTsx Whether the file uses a JSX or TSX extension.
|
|
302
|
+
*/
|
|
303
|
+
async function registerTsx(filePath, isJsxOrTsx) {
|
|
304
|
+
try {
|
|
246
305
|
const tsx = await import("tsx/esm/api");
|
|
247
306
|
tsx.register();
|
|
248
|
-
} catch {
|
|
249
|
-
|
|
307
|
+
} catch (error) {
|
|
308
|
+
if (!isNodeError(error) || error.code !== "ERR_MODULE_NOT_FOUND") throw error;
|
|
309
|
+
if (isJsxOrTsx) jsxLoaderRequiredError(filePath);
|
|
310
|
+
else tsxRequiredError(filePath);
|
|
250
311
|
}
|
|
251
|
-
|
|
252
|
-
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Tries to register the tsx loader, silently ignoring all failures.
|
|
315
|
+
* Used on Node.js for entries that may have transitive JSX/TSX dependencies.
|
|
316
|
+
*
|
|
317
|
+
* All errors are suppressed because this is a best-effort preload: the
|
|
318
|
+
* entry file itself does not require tsx, and failing here would be a
|
|
319
|
+
* regression for environments where tsx is absent, incompatible, or
|
|
320
|
+
* broken. If a transitive JSX/TSX dependency is later encountered
|
|
321
|
+
* without a loader, the caller's catch block produces a helpful error.
|
|
322
|
+
*/
|
|
323
|
+
async function tryRegisterTsx() {
|
|
324
|
+
try {
|
|
325
|
+
const tsx = await import("tsx/esm/api");
|
|
326
|
+
tsx.register();
|
|
327
|
+
} catch {}
|
|
253
328
|
}
|
|
254
329
|
/**
|
|
255
330
|
* Checks if a value is a Program object.
|
package/dist/cli.js
CHANGED
|
@@ -17,7 +17,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
17
17
|
|
|
18
18
|
//#region deno.json
|
|
19
19
|
var name = "@optique/man";
|
|
20
|
-
var version = "1.0.0-dev.
|
|
20
|
+
var version = "1.0.0-dev.783+64de3665";
|
|
21
21
|
var license = "MIT";
|
|
22
22
|
var exports = {
|
|
23
23
|
".": "./src/index.ts",
|
|
@@ -56,6 +56,7 @@ var deno_default = {
|
|
|
56
56
|
|
|
57
57
|
//#endregion
|
|
58
58
|
//#region src/cli.ts
|
|
59
|
+
const jsxTsxPattern = /\.[mc]?[jt]sx$/;
|
|
59
60
|
const EXIT_FILE_NOT_FOUND = 1;
|
|
60
61
|
const EXIT_EXPORT_NOT_FOUND = 2;
|
|
61
62
|
const EXIT_NOT_PROGRAM_OR_PARSER = 3;
|
|
@@ -203,7 +204,7 @@ an Optique parser (e.g., from ${commandLine("object()")},
|
|
|
203
204
|
${commandLine("command()")}, etc.).`, { exitCode: EXIT_NOT_PROGRAM_OR_PARSER });
|
|
204
205
|
}
|
|
205
206
|
/**
|
|
206
|
-
* Error handler for missing tsx.
|
|
207
|
+
* Error handler for missing tsx for TypeScript files.
|
|
207
208
|
*/
|
|
208
209
|
function tsxRequiredError(filePath) {
|
|
209
210
|
const version$1 = getNodeMajorMinor();
|
|
@@ -216,6 +217,22 @@ Install tsx as a dev dependency:
|
|
|
216
217
|
|
|
217
218
|
Or upgrade to Node.js 25.2.0 or later, which supports TypeScript natively.
|
|
218
219
|
|
|
220
|
+
Alternatively, use a pre-compiled JavaScript file instead.`, { exitCode: EXIT_TSX_REQUIRED });
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Error handler for missing tsx for JSX/TSX files.
|
|
224
|
+
*/
|
|
225
|
+
function jsxLoaderRequiredError(filePath) {
|
|
226
|
+
const version$1 = getNodeMajorMinor();
|
|
227
|
+
const versionStr = version$1 ? `${version$1[0]}.${version$1[1]}` : "unknown";
|
|
228
|
+
const isTsx = /\.[mc]?tsx$/.test(filePath);
|
|
229
|
+
const fileKind = isTsx ? "TSX" : "JSX";
|
|
230
|
+
printError(message`${fileKind} file ${filePath} cannot be loaded on Node.js ${versionStr}.
|
|
231
|
+
|
|
232
|
+
Install tsx as a dev dependency:
|
|
233
|
+
|
|
234
|
+
${commandLine("npm install -D tsx")}
|
|
235
|
+
|
|
219
236
|
Alternatively, use a pre-compiled JavaScript file instead.`, { exitCode: EXIT_TSX_REQUIRED });
|
|
220
237
|
}
|
|
221
238
|
/**
|
|
@@ -234,22 +251,80 @@ Make sure you have write permission and the parent directory exists.`, { exitCod
|
|
|
234
251
|
}
|
|
235
252
|
/**
|
|
236
253
|
* Imports a module from the given file path.
|
|
237
|
-
* Handles TypeScript files on Node.js by using tsx if needed.
|
|
254
|
+
* Handles TypeScript and JSX files on Node.js by using tsx if needed.
|
|
255
|
+
* @param filePath The path to the module file.
|
|
256
|
+
* @returns The imported module's exports.
|
|
257
|
+
* @throws If the module fails to import for reasons other than a missing
|
|
258
|
+
* tsx loader (which causes the process to exit instead).
|
|
238
259
|
*/
|
|
239
260
|
async function importModule(filePath) {
|
|
240
261
|
const absolutePath = resolve(filePath);
|
|
241
262
|
if (!existsSync(absolutePath)) fileNotFoundError(filePath);
|
|
242
|
-
const
|
|
263
|
+
const isPlainTs = /\.[mc]?ts$/.test(filePath);
|
|
264
|
+
const isJsxOrTsx = jsxTsxPattern.test(filePath);
|
|
243
265
|
const isDeno = "Deno" in globalThis;
|
|
244
266
|
const isBun = "Bun" in globalThis;
|
|
245
|
-
if (!isDeno && !isBun &&
|
|
267
|
+
if (!isDeno && !isBun && (isJsxOrTsx || isPlainTs && !nodeSupportsNativeTypeScript())) await registerTsx(filePath, isJsxOrTsx);
|
|
268
|
+
else if (!isDeno && !isBun) await tryRegisterTsx();
|
|
269
|
+
const fileUrl = pathToFileURL(absolutePath).href;
|
|
270
|
+
try {
|
|
271
|
+
return await import(fileUrl);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (!isDeno && !isBun && isNodeError(error) && error.code === "ERR_UNKNOWN_FILE_EXTENSION") {
|
|
274
|
+
const failedPath = extractPathFromExtensionError(error.message);
|
|
275
|
+
if (failedPath != null && jsxTsxPattern.test(failedPath)) jsxLoaderRequiredError(failedPath);
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Checks whether an error is a Node.js system error with a string `code`.
|
|
282
|
+
* @param error The value to check.
|
|
283
|
+
* @returns `true` if the error has a string `code` property.
|
|
284
|
+
*/
|
|
285
|
+
function isNodeError(error) {
|
|
286
|
+
return error instanceof Error && "code" in error && typeof error.code === "string";
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Extracts the file path from a Node.js `ERR_UNKNOWN_FILE_EXTENSION` error
|
|
290
|
+
* message, which has the format `Unknown file extension ".ext" for /path`.
|
|
291
|
+
* @param message The error message string.
|
|
292
|
+
* @returns The file path, or null if the message format is unexpected.
|
|
293
|
+
*/
|
|
294
|
+
function extractPathFromExtensionError(message$1) {
|
|
295
|
+
const match = /^Unknown file extension "\.[^"]*" for (.+)$/.exec(message$1);
|
|
296
|
+
return match?.[1] ?? null;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Registers the tsx loader for TypeScript/JSX/TSX support on Node.js.
|
|
300
|
+
* @param filePath The file path being loaded (used for error messages).
|
|
301
|
+
* @param isJsxOrTsx Whether the file uses a JSX or TSX extension.
|
|
302
|
+
*/
|
|
303
|
+
async function registerTsx(filePath, isJsxOrTsx) {
|
|
304
|
+
try {
|
|
246
305
|
const tsx = await import("tsx/esm/api");
|
|
247
306
|
tsx.register();
|
|
248
|
-
} catch {
|
|
249
|
-
|
|
307
|
+
} catch (error) {
|
|
308
|
+
if (!isNodeError(error) || error.code !== "ERR_MODULE_NOT_FOUND") throw error;
|
|
309
|
+
if (isJsxOrTsx) jsxLoaderRequiredError(filePath);
|
|
310
|
+
else tsxRequiredError(filePath);
|
|
250
311
|
}
|
|
251
|
-
|
|
252
|
-
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Tries to register the tsx loader, silently ignoring all failures.
|
|
315
|
+
* Used on Node.js for entries that may have transitive JSX/TSX dependencies.
|
|
316
|
+
*
|
|
317
|
+
* All errors are suppressed because this is a best-effort preload: the
|
|
318
|
+
* entry file itself does not require tsx, and failing here would be a
|
|
319
|
+
* regression for environments where tsx is absent, incompatible, or
|
|
320
|
+
* broken. If a transitive JSX/TSX dependency is later encountered
|
|
321
|
+
* without a loader, the caller's catch block produces a helpful error.
|
|
322
|
+
*/
|
|
323
|
+
async function tryRegisterTsx() {
|
|
324
|
+
try {
|
|
325
|
+
const tsx = await import("tsx/esm/api");
|
|
326
|
+
tsx.register();
|
|
327
|
+
} catch {}
|
|
253
328
|
}
|
|
254
329
|
/**
|
|
255
330
|
* Checks if a value is a Program object.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/man",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.783+64de3665",
|
|
4
4
|
"description": "Man page generator for Optique CLI parsers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
"optique-man": "./dist/cli.js"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@optique/core": "1.0.0-dev.
|
|
88
|
-
"@optique/run": "1.0.0-dev.
|
|
87
|
+
"@optique/core": "1.0.0-dev.783+64de3665",
|
|
88
|
+
"@optique/run": "1.0.0-dev.783+64de3665"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@types/node": "^20.19.9",
|