openapi-typesafe 1.0.0-rc.5 → 1.0.0-rc.6
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/CHANGELOG.md +73 -0
- package/dist/adapters/redocly-loader/query-document-names.cjs +50 -0
- package/dist/adapters/redocly-loader/query-document-names.cjs.map +1 -0
- package/dist/adapters/redocly-loader/query-document-names.mjs +48 -0
- package/dist/adapters/redocly-loader/query-document-names.mjs.map +1 -0
- package/dist/adapters/redocly-loader/query-named-components.cjs +29 -37
- package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -1
- package/dist/adapters/redocly-loader/query-named-components.mjs +29 -37
- package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-config-source.cjs +3 -0
- package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-config-source.mjs +4 -1
- package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +16 -7
- package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +17 -8
- package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.cjs +9 -1
- package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
- package/dist/adapters/redocly-loader/ref-access.mjs +10 -2
- package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.cjs +16 -1
- package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
- package/dist/adapters/redocly-loader/remote-fetch.mjs +16 -2
- package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
- package/dist/api/cwd-option.cjs +58 -0
- package/dist/api/cwd-option.cjs.map +1 -0
- package/dist/api/cwd-option.mjs +52 -0
- package/dist/api/cwd-option.mjs.map +1 -0
- package/dist/api/default-ports.cjs +15 -7
- package/dist/api/default-ports.cjs.map +1 -1
- package/dist/api/default-ports.mjs +14 -8
- package/dist/api/default-ports.mjs.map +1 -1
- package/dist/api/document-run.cjs +2 -16
- package/dist/api/document-run.cjs.map +1 -1
- package/dist/api/document-run.mjs +2 -12
- package/dist/api/document-run.mjs.map +1 -1
- package/dist/api/legacy-utils.cjs +1 -1
- package/dist/api/legacy-utils.cjs.map +1 -1
- package/dist/api/legacy-utils.mjs +1 -1
- package/dist/api/legacy-utils.mjs.map +1 -1
- package/dist/api/openapi-ts.cjs.map +1 -1
- package/dist/api/openapi-ts.mjs.map +1 -1
- package/dist/api/option-errors.cjs +24 -0
- package/dist/api/option-errors.cjs.map +1 -0
- package/dist/api/option-errors.mjs +21 -0
- package/dist/api/option-errors.mjs.map +1 -0
- package/dist/api/ref-limit-options.cjs +19 -24
- package/dist/api/ref-limit-options.cjs.map +1 -1
- package/dist/api/ref-limit-options.mjs +15 -20
- package/dist/api/ref-limit-options.mjs.map +1 -1
- package/dist/application/transform/document/path-template-refs.cjs +12 -2
- package/dist/application/transform/document/path-template-refs.cjs.map +1 -1
- package/dist/application/transform/document/path-template-refs.mjs +12 -2
- package/dist/application/transform/document/path-template-refs.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.cjs +28 -10
- package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/generated-shape.mjs +29 -11
- package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/original-index.cjs +1 -1
- package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/original-index.mjs +1 -1
- package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/property-shape.cjs +5 -0
- package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/property-shape.mjs +5 -1
- package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -1
- package/dist/application/transform/ref-pointer/typed-walk.cjs +11 -1
- package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
- package/dist/application/transform/ref-pointer/typed-walk.mjs +12 -2
- package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
- package/dist/cli/api-settings.cjs +3 -2
- package/dist/cli/api-settings.cjs.map +1 -1
- package/dist/cli/api-settings.mjs +2 -1
- package/dist/cli/api-settings.mjs.map +1 -1
- package/dist/cli/api-writes.cjs +7 -1
- package/dist/cli/api-writes.cjs.map +1 -1
- package/dist/cli/api-writes.mjs +7 -1
- package/dist/cli/api-writes.mjs.map +1 -1
- package/dist/cli/cli-arguments.cjs +25 -107
- package/dist/cli/cli-arguments.cjs.map +1 -1
- package/dist/cli/cli-arguments.mjs +18 -100
- package/dist/cli/cli-arguments.mjs.map +1 -1
- package/dist/cli/cli-errors.cjs +1 -0
- package/dist/cli/cli-errors.cjs.map +1 -1
- package/dist/cli/cli-errors.mjs +1 -0
- package/dist/cli/cli-errors.mjs.map +1 -1
- package/dist/cli/cli-flag-names.cjs +77 -0
- package/dist/cli/cli-flag-names.cjs.map +1 -0
- package/dist/cli/cli-flag-names.mjs +64 -0
- package/dist/cli/cli-flag-names.mjs.map +1 -0
- package/dist/cli/cli-output.cjs +7 -2
- package/dist/cli/cli-output.cjs.map +1 -1
- package/dist/cli/cli-output.mjs +7 -2
- package/dist/cli/cli-output.mjs.map +1 -1
- package/dist/cli/main.cjs +1 -1
- package/dist/cli/main.cjs.map +1 -1
- package/dist/cli/main.mjs +1 -1
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/redocly-apis.cjs +14 -4
- package/dist/cli/redocly-apis.cjs.map +1 -1
- package/dist/cli/redocly-apis.mjs +14 -4
- package/dist/cli/redocly-apis.mjs.map +1 -1
- package/dist/cli/written-flags.cjs +83 -0
- package/dist/cli/written-flags.cjs.map +1 -0
- package/dist/cli/written-flags.mjs +77 -0
- package/dist/cli/written-flags.mjs.map +1 -0
- package/dist/domain/errors.cjs +1 -0
- package/dist/domain/errors.cjs.map +1 -1
- package/dist/domain/errors.mjs +1 -0
- package/dist/domain/errors.mjs.map +1 -1
- package/dist/domain/location-text.cjs +7 -1
- package/dist/domain/location-text.cjs.map +1 -1
- package/dist/domain/location-text.mjs +7 -1
- package/dist/domain/location-text.mjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/adapters/redocly-loader/query-document-names.ts +79 -0
- package/src/adapters/redocly-loader/query-named-components.ts +48 -49
- package/src/adapters/redocly-loader/redocly-config-source.ts +11 -1
- package/src/adapters/redocly-loader/redocly-schema-loader.ts +20 -6
- package/src/adapters/redocly-loader/ref-access.ts +16 -2
- package/src/adapters/redocly-loader/remote-fetch.ts +26 -0
- package/src/api/cwd-option.ts +76 -0
- package/src/api/default-ports.ts +33 -10
- package/src/api/document-run.ts +2 -17
- package/src/api/legacy-utils.ts +1 -1
- package/src/api/openapi-ts.ts +14 -1
- package/src/api/option-errors.ts +22 -0
- package/src/api/ref-limit-options.ts +17 -24
- package/src/application/ports/redocly-config-source.ts +5 -0
- package/src/application/transform/document/path-template-refs.ts +28 -7
- package/src/application/transform/ref-pointer/generated-shape.ts +57 -14
- package/src/application/transform/ref-pointer/original-index.ts +6 -3
- package/src/application/transform/ref-pointer/property-shape.ts +9 -0
- package/src/application/transform/ref-pointer/typed-walk.ts +26 -4
- package/src/cli/api-writes.ts +11 -3
- package/src/cli/cli-arguments.ts +42 -153
- package/src/cli/cli-errors.ts +1 -0
- package/src/cli/cli-flag-names.ts +99 -0
- package/src/cli/cli-output.ts +20 -6
- package/src/cli/main.ts +2 -1
- package/src/cli/redocly-apis.ts +21 -5
- package/src/cli/written-flags.ts +131 -0
- package/src/domain/errors.ts +1 -0
- package/src/domain/location-text.ts +17 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-errors.mjs","sources":["../../src/cli/cli-errors.ts"],"sourcesContent":["import {\n ERROR_CODES,\n type ErrorCode,\n isOpenAPITypesafeError,\n OpenAPITypesafeError,\n} from \"../domain/errors.js\";\n\n/**\n * How the CLI reports a failure (ENGINEERING_PLAN 4.6, ADR-011): each error code maps to a process\n * exit code and the line printed for it. The table is exhaustive, so a new error code does not\n * compile until the CLI handles it.\n */\n\n/** Process exit codes of the CLI, documented in docs/cli.md. */\nexport const EXIT_CODES = {\n SUCCESS: 0,\n /** `--check` found output that differs from the generated types (as in the original CLI). */\n OUTPUT_STALE: 1,\n /** A flag, the Redocly config, the environment or a callback is wrong. */\n USAGE: 2,\n /** The OpenAPI document cannot be read, is invalid, or cannot be converted. */\n SCHEMA: 3,\n /** An output file cannot be read or written. */\n OUTPUT: 4,\n /** An unexpected failure: a bug in the generator (sysexits `EX_SOFTWARE`). */\n INTERNAL: 70,\n} as const;\n\nexport type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];\n\ninterface CliErrorReport {\n readonly exitCode: ExitCode;\n /** The printed text; the error's own message when absent. */\n readonly message?: (error: OpenAPITypesafeError) => string;\n}\n\n/** Problems are printed one by one while linting, so the summary only counts them. */\nfunction schemaInvalidMessage(error: OpenAPITypesafeError): string {\n const count = Array.isArray(error.details.problems) ? error.details.problems.length : 1;\n return `The OpenAPI document has ${count} ${count === 1 ? \"error\" : \"errors\"} (see above)`;\n}\n\n/**\n * Node's `fetch` fails with only \"fetch failed\"; the network reason (refused, DNS, TLS) is the\n * cause of that error. The Node API keeps the original message, so only the CLI adds it.\n */\nfunction loadFailedMessage(error: OpenAPITypesafeError): string {\n const reason = error.cause instanceof Error ? error.cause.cause : undefined;\n if (!(reason instanceof Error)) {\n return error.message;\n }\n // `loadFailedError`, the only source of this code, always sets the source.\n return `${error.message}: ${reason.message} (${String(error.details.source)})`;\n}\n\n/** The message js-yaml throws at its nesting limit (docs/security/threat-model.md T2). */\nconst YAML_DEPTH_LIMIT_MESSAGE = /nesting exceeded maxDepth \\((\\d+)\\)/;\n\n/** The parser's message says the limit, not how to stay under it. */\nfunction parseFailedMessage(error: OpenAPITypesafeError): string {\n const limit = YAML_DEPTH_LIMIT_MESSAGE.exec(error.message)?.[1];\n if (limit === undefined) {\n return error.message;\n }\n return (\n `${error.message}. The YAML parser reads at most ${limit} nested levels: ` +\n \"move nested schemas to `components` and reference them with `$ref`\"\n );\n}\n\n/**\n * Text piped into stdin that is only a YAML string (`echo api.yaml | openapi-typesafe`) gets the\n * CLI's advice, not the Node API's (`openapiTS(pathToFileURL(path))`).\n */\nfunction sourceInvalidMessage(error: OpenAPITypesafeError): string {\n const { received, text } = error.details;\n if (received !== \"stream\" || typeof text !== \"string\") {\n return error.message;\n }\n return (\n `stdin held only the YAML string \"${text}\", not an OpenAPI document. To read a file, pass ` +\n \"its path or URL as the first argument: openapi-typesafe ./openapi.yaml -o ./schema.ts\"\n );\n}\n\nconst CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {\n SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: sourceInvalidMessage },\n SCHEMA_LOAD_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: loadFailedMessage },\n SCHEMA_PARSE_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: parseFailedMessage },\n SCHEMA_VERSION_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: schemaInvalidMessage },\n SCHEMA_REF_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_REF_FORBIDDEN: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_OBJECT_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_PROPERTY_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_TOO_DEEP: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_KEY_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },\n ENUM_NAME_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n CALLBACK_RESULT_UNREADABLE: { exitCode: EXIT_CODES.USAGE },\n OPTION_FIX_UNKNOWN: { exitCode: EXIT_CODES.USAGE },\n OPTION_INVALID: { exitCode: EXIT_CODES.USAGE },\n TYPESCRIPT_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },\n CLI_FLAG_REMOVED: { exitCode: EXIT_CODES.USAGE },\n CLI_FLAG_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_GLOB_UNSUPPORTED: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_CHECK_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_INPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_IS_INPUT: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_DUPLICATE: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_LOCATION_INVALID: { exitCode: EXIT_CODES.USAGE },\n OUTPUT_STALE: { exitCode: EXIT_CODES.OUTPUT_STALE },\n OUTPUT_READ_FAILED: { exitCode: EXIT_CODES.OUTPUT },\n OUTPUT_WRITE_FAILED: { exitCode: EXIT_CODES.OUTPUT },\n};\n\n/** What the CLI prints and returns for a thrown value. */\nexport interface CliFailure {\n readonly exitCode: ExitCode;\n readonly message: string;\n}\n\n/**\n * Map a thrown value to the CLI's output. A typed error prints one line with its code; anything\n * else is a bug and prints its stack, so it can be reported.\n */\nexport function describeCliFailure(error: unknown): CliFailure {\n if (error instanceof ApiFailure) {\n const failure = describeCliFailure(error.cause);\n return { ...failure, message: `API ${error.apiName}: ${failure.message}` };\n }\n if (!isOpenAPITypesafeError(error)) {\n const text = error instanceof Error ? (error.stack ?? error.message) : String(error);\n return { exitCode: EXIT_CODES.INTERNAL, message: `Unexpected error: ${text}` };\n }\n const report = CLI_ERROR_REPORTS[error.code];\n const message = report.message?.(error) ?? error.message;\n return { exitCode: report.exitCode, message: `${message} (${error.code})` };\n}\n\n/**\n * A failure of one API of a Redocly config. The CLI reports its cause with the API named first,\n * as the config errors of an API are; the cause keeps its code and so its exit code.\n */\nexport class ApiFailure extends Error {\n override readonly name = \"ApiFailure\";\n override readonly cause: unknown;\n readonly apiName: string;\n\n constructor(apiName: string, cause: unknown) {\n super(`API ${apiName} failed`, { cause });\n this.apiName = apiName;\n this.cause = cause;\n }\n}\n\n/** Errors of the CLI itself; its messages are the original CLI's messages. */\nexport function cliError(\n code: Extract<ErrorCode, `CLI_${string}` | `OUTPUT_${string}`>,\n message: string,\n cause?: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES[code], message, cause });\n}\n"],"names":[],"mappings":";;AAcO,MAAM,UAAA,GAAa;AAAA,EACxB,OAAA,EAAS,CAAA;AAAA;AAAA,EAET,YAAA,EAAc,CAAA;AAAA;AAAA,EAEd,KAAA,EAAO,CAAA;AAAA;AAAA,EAEP,MAAA,EAAQ,CAAA;AAAA;AAAA,EAER,MAAA,EAAQ,CAAA;AAAA;AAAA,EAER,QAAA,EAAU;AACZ;AAWA,SAAS,qBAAqB,KAAA,EAAqC;AACjE,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,OAAA,CAAQ,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,GAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,CAAS,MAAA,GAAS,CAAA;AACtF,EAAA,OAAO,4BAA4B,KAAK,CAAA,CAAA,EAAI,KAAA,KAAU,CAAA,GAAI,UAAU,QAAQ,CAAA,YAAA,CAAA;AAC9E;AAMA,SAA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AAO,iBAAiB,KAAA,GAAS,KAAA,CAAM,SAAS,KAAA,CAAM,OAAA,GAAW,OAAO,KAAK,CAAA;AACnF,IAAA,OAAO,EAAE,QAAA,EAAU,UAAA,CAAW,UAAU,OAAA,EAAS,CAAA,kBAAA,EAAqB,IAAI,CAAA,CAAA,EAAG;AAAA,EAC/E;AACA,EAAA,MAAM,MAAA,GAAS,iBAAA,CAAkB,KAAA,CAAM,IAAI,CAAA;AAC3C,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,GAAU,KAAK,KAAK,KAAA,CAAM,OAAA;AACjD,EAAA,OAAO,EAAE,QAAA,EAAU,MAAA,CAAO,QAAA,EAAU,OAAA,EAAS,GAAG,OAAO,CAAA,EAAA,EAAK,KAAA,CAAM,IAAI,CAAA,CAAA,CAAA,EAAI;AAC5E;AAMO,MAAM,mBAAmB,KAAA,CAAM;AAAA,EAClB,IAAA,GAAO,YAAA;AAAA,EACP,KAAA;AAAA,EACT,OAAA;AAAA,EAET,WAAA,CAAY,SAAiB,KAAA,EAAgB;AAC3C,IAAA,KAAA,CAAM,CAAA,IAAA,EAAO,OAAO,CAAA,OAAA,CAAA,EAAW,EAAE,OAAO,CAAA;AACxC,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AACF;AAGO,SAAS,QAAA,CACd,IAAA,EACA,OAAA,EACA,KAAA,EACsB;AACtB,EAAA,OAAO,IAAI,qBAAqB,EAAE,IAAA,EAAM,YAAY,IAAI,CAAA,EAAG,OAAA,EAAS,KAAA,EAAO,CAAA;AAC7E;;"}
|
|
1
|
+
{"version":3,"file":"cli-errors.mjs","sources":["../../src/cli/cli-errors.ts"],"sourcesContent":["import {\n ERROR_CODES,\n type ErrorCode,\n isOpenAPITypesafeError,\n OpenAPITypesafeError,\n} from \"../domain/errors.js\";\n\n/**\n * How the CLI reports a failure (ENGINEERING_PLAN 4.6, ADR-011): each error code maps to a process\n * exit code and the line printed for it. The table is exhaustive, so a new error code does not\n * compile until the CLI handles it.\n */\n\n/** Process exit codes of the CLI, documented in docs/cli.md. */\nexport const EXIT_CODES = {\n SUCCESS: 0,\n /** `--check` found output that differs from the generated types (as in the original CLI). */\n OUTPUT_STALE: 1,\n /** A flag, the Redocly config, the environment or a callback is wrong. */\n USAGE: 2,\n /** The OpenAPI document cannot be read, is invalid, or cannot be converted. */\n SCHEMA: 3,\n /** An output file cannot be read or written. */\n OUTPUT: 4,\n /** An unexpected failure: a bug in the generator (sysexits `EX_SOFTWARE`). */\n INTERNAL: 70,\n} as const;\n\nexport type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];\n\ninterface CliErrorReport {\n readonly exitCode: ExitCode;\n /** The printed text; the error's own message when absent. */\n readonly message?: (error: OpenAPITypesafeError) => string;\n}\n\n/** Problems are printed one by one while linting, so the summary only counts them. */\nfunction schemaInvalidMessage(error: OpenAPITypesafeError): string {\n const count = Array.isArray(error.details.problems) ? error.details.problems.length : 1;\n return `The OpenAPI document has ${count} ${count === 1 ? \"error\" : \"errors\"} (see above)`;\n}\n\n/**\n * Node's `fetch` fails with only \"fetch failed\"; the network reason (refused, DNS, TLS) is the\n * cause of that error. The Node API keeps the original message, so only the CLI adds it.\n */\nfunction loadFailedMessage(error: OpenAPITypesafeError): string {\n const reason = error.cause instanceof Error ? error.cause.cause : undefined;\n if (!(reason instanceof Error)) {\n return error.message;\n }\n // `loadFailedError`, the only source of this code, always sets the source.\n return `${error.message}: ${reason.message} (${String(error.details.source)})`;\n}\n\n/** The message js-yaml throws at its nesting limit (docs/security/threat-model.md T2). */\nconst YAML_DEPTH_LIMIT_MESSAGE = /nesting exceeded maxDepth \\((\\d+)\\)/;\n\n/** The parser's message says the limit, not how to stay under it. */\nfunction parseFailedMessage(error: OpenAPITypesafeError): string {\n const limit = YAML_DEPTH_LIMIT_MESSAGE.exec(error.message)?.[1];\n if (limit === undefined) {\n return error.message;\n }\n return (\n `${error.message}. The YAML parser reads at most ${limit} nested levels: ` +\n \"move nested schemas to `components` and reference them with `$ref`\"\n );\n}\n\n/**\n * Text piped into stdin that is only a YAML string (`echo api.yaml | openapi-typesafe`) gets the\n * CLI's advice, not the Node API's (`openapiTS(pathToFileURL(path))`).\n */\nfunction sourceInvalidMessage(error: OpenAPITypesafeError): string {\n const { received, text } = error.details;\n if (received !== \"stream\" || typeof text !== \"string\") {\n return error.message;\n }\n return (\n `stdin held only the YAML string \"${text}\", not an OpenAPI document. To read a file, pass ` +\n \"its path or URL as the first argument: openapi-typesafe ./openapi.yaml -o ./schema.ts\"\n );\n}\n\nconst CLI_ERROR_REPORTS: Readonly<Record<ErrorCode, CliErrorReport>> = {\n SCHEMA_SOURCE_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_SOURCE_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: sourceInvalidMessage },\n SCHEMA_LOAD_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: loadFailedMessage },\n SCHEMA_PARSE_FAILED: { exitCode: EXIT_CODES.SCHEMA, message: parseFailedMessage },\n SCHEMA_VERSION_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_INVALID: { exitCode: EXIT_CODES.SCHEMA, message: schemaInvalidMessage },\n SCHEMA_REF_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_REF_FORBIDDEN: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_OBJECT_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_PROPERTY_INVALID: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_TOO_DEEP: { exitCode: EXIT_CODES.SCHEMA },\n SCHEMA_KEY_UNSUPPORTED: { exitCode: EXIT_CODES.SCHEMA },\n ENUM_NAME_EMPTY: { exitCode: EXIT_CODES.SCHEMA },\n CALLBACK_RESULT_UNREADABLE: { exitCode: EXIT_CODES.USAGE },\n OPTION_FIX_UNKNOWN: { exitCode: EXIT_CODES.USAGE },\n OPTION_INVALID: { exitCode: EXIT_CODES.USAGE },\n TYPESCRIPT_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },\n CLI_FLAG_REMOVED: { exitCode: EXIT_CODES.USAGE },\n CLI_FLAG_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_GLOB_UNSUPPORTED: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_NOT_FOUND: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_CONFIG_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_CHECK_OUTPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_INPUT_MISSING: { exitCode: EXIT_CODES.USAGE },\n CLI_INPUT_EXTRA: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_IS_INPUT: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_DUPLICATE: { exitCode: EXIT_CODES.USAGE },\n CLI_OUTPUT_INVALID: { exitCode: EXIT_CODES.USAGE },\n CLI_LOCATION_INVALID: { exitCode: EXIT_CODES.USAGE },\n OUTPUT_STALE: { exitCode: EXIT_CODES.OUTPUT_STALE },\n OUTPUT_READ_FAILED: { exitCode: EXIT_CODES.OUTPUT },\n OUTPUT_WRITE_FAILED: { exitCode: EXIT_CODES.OUTPUT },\n};\n\n/** What the CLI prints and returns for a thrown value. */\nexport interface CliFailure {\n readonly exitCode: ExitCode;\n readonly message: string;\n}\n\n/**\n * Map a thrown value to the CLI's output. A typed error prints one line with its code; anything\n * else is a bug and prints its stack, so it can be reported.\n */\nexport function describeCliFailure(error: unknown): CliFailure {\n if (error instanceof ApiFailure) {\n const failure = describeCliFailure(error.cause);\n return { ...failure, message: `API ${error.apiName}: ${failure.message}` };\n }\n if (!isOpenAPITypesafeError(error)) {\n const text = error instanceof Error ? (error.stack ?? error.message) : String(error);\n return { exitCode: EXIT_CODES.INTERNAL, message: `Unexpected error: ${text}` };\n }\n const report = CLI_ERROR_REPORTS[error.code];\n const message = report.message?.(error) ?? error.message;\n return { exitCode: report.exitCode, message: `${message} (${error.code})` };\n}\n\n/**\n * A failure of one API of a Redocly config. The CLI reports its cause with the API named first,\n * as the config errors of an API are; the cause keeps its code and so its exit code.\n */\nexport class ApiFailure extends Error {\n override readonly name = \"ApiFailure\";\n override readonly cause: unknown;\n readonly apiName: string;\n\n constructor(apiName: string, cause: unknown) {\n super(`API ${apiName} failed`, { cause });\n this.apiName = apiName;\n this.cause = cause;\n }\n}\n\n/** Errors of the CLI itself; its messages are the original CLI's messages. */\nexport function cliError(\n code: Extract<ErrorCode, `CLI_${string}` | `OUTPUT_${string}`>,\n message: string,\n cause?: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES[code], message, cause });\n}\n"],"names":[],"mappings":";;AAcO,MAAM,UAAA,GAAa;AAAA,EACxB,OAAA,EAAS,CAAA;AAAA;AAAA,EAET,YAAA,EAAc,CAAA;AAAA;AAAA,EAEd,KAAA,EAAO,CAAA;AAAA;AAAA,EAEP,MAAA,EAAQ,CAAA;AAAA;AAAA,EAER,MAAA,EAAQ,CAAA;AAAA;AAAA,EAER,QAAA,EAAU;AACZ;AAWA,SAAS,qBAAqB,KAAA,EAAqC;AACjE,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,OAAA,CAAQ,KAAA,CAAM,OAAA,CAAQ,QAAQ,CAAA,GAAI,KAAA,CAAM,OAAA,CAAQ,QAAA,CAAS,MAAA,GAAS,CAAA;AACtF,EAAA,OAAO,4BAA4B,KAAK,CAAA,CAAA,EAAI,KAAA,KAAU,CAAA,GAAI,UAAU,QAAQ,CAAA,YAAA,CAAA;AAC9E;AAMA,SAAS,kBAAkB,KAAA,EAAqC;AAC9D,EAAA,MAAM,SAAS,KAAA,CAAM,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,MAAM,KAAA,GAAQ,MAAA;AAClE,EAAA,IAAI,EAA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,CAAA;AACnF,IAAA,OAAO,EAAE,QAAA,EAAU,UAAA,CAAW,UAAU,OAAA,EAAS,CAAA,kBAAA,EAAqB,IAAI,CAAA,CAAA,EAAG;AAAA,EAC/E;AACA,EAAA,MAAM,MAAA,GAAS,iBAAA,CAAkB,KAAA,CAAM,IAAI,CAAA;AAC3C,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,GAAU,KAAK,KAAK,KAAA,CAAM,OAAA;AACjD,EAAA,OAAO,EAAE,QAAA,EAAU,MAAA,CAAO,QAAA,EAAU,OAAA,EAAS,GAAG,OAAO,CAAA,EAAA,EAAK,KAAA,CAAM,IAAI,CAAA,CAAA,CAAA,EAAI;AAC5E;AAMO,MAAM,mBAAmB,KAAA,CAAM;AAAA,EAClB,IAAA,GAAO,YAAA;AAAA,EACP,KAAA;AAAA,EACT,OAAA;AAAA,EAET,WAAA,CAAY,SAAiB,KAAA,EAAgB;AAC3C,IAAA,KAAA,CAAM,CAAA,IAAA,EAAO,OAAO,CAAA,OAAA,CAAA,EAAW,EAAE,OAAO,CAAA;AACxC,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAAA,EACf;AACF;AAGO,SAAS,QAAA,CACd,IAAA,EACA,OAAA,EACA,KAAA,EACsB;AACtB,EAAA,OAAO,IAAI,qBAAqB,EAAE,IAAA,EAAM,YAAY,IAAI,CAAA,EAAG,OAAA,EAAS,KAAA,EAAO,CAAA;AAC7E;;"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const scule = require('scule');
|
|
4
|
+
|
|
5
|
+
const GENERATOR_FLAGS = [
|
|
6
|
+
"additionalProperties",
|
|
7
|
+
"alphabetize",
|
|
8
|
+
"arrayLength",
|
|
9
|
+
"binaryAsBlob",
|
|
10
|
+
"conditionalEnums",
|
|
11
|
+
"dedupeEnums",
|
|
12
|
+
"defaultNonNullable",
|
|
13
|
+
"emptyObjectsUnknown",
|
|
14
|
+
"enum",
|
|
15
|
+
"enumValues",
|
|
16
|
+
"excludeDeprecated",
|
|
17
|
+
"exportType",
|
|
18
|
+
"generatePathParams",
|
|
19
|
+
"immutable",
|
|
20
|
+
"lint",
|
|
21
|
+
"makePathsEnum",
|
|
22
|
+
"pathParamsAsTypes",
|
|
23
|
+
"propertiesRequiredByDefault",
|
|
24
|
+
"readWriteMarkers",
|
|
25
|
+
"rootTypes",
|
|
26
|
+
"rootTypesKeepCasing",
|
|
27
|
+
"rootTypesNoSchemaPrefix"
|
|
28
|
+
];
|
|
29
|
+
const CAMEL_CASE_BOOLEAN_FLAGS = [...GENERATOR_FLAGS, "check", "contentNever", "help"];
|
|
30
|
+
const BOOLEAN_FLAGS = [
|
|
31
|
+
...CAMEL_CASE_BOOLEAN_FLAGS,
|
|
32
|
+
...CAMEL_CASE_BOOLEAN_FLAGS.map((flag) => scule.kebabCase(flag))
|
|
33
|
+
];
|
|
34
|
+
const ALIASES = { redocly: ["c"], exportType: ["t"], output: ["o"] };
|
|
35
|
+
const CAMEL_CASE_STRING_FLAGS = ["output", "redocly", "fix", "localRefRoot", "remoteRefHosts"];
|
|
36
|
+
const STRING_FLAGS = [
|
|
37
|
+
...CAMEL_CASE_STRING_FLAGS,
|
|
38
|
+
...CAMEL_CASE_STRING_FLAGS.map((flag) => scule.kebabCase(flag))
|
|
39
|
+
];
|
|
40
|
+
const KNOWN_FLAGS = /* @__PURE__ */ new Set([
|
|
41
|
+
...BOOLEAN_FLAGS,
|
|
42
|
+
...STRING_FLAGS,
|
|
43
|
+
...Object.values(ALIASES).flat(),
|
|
44
|
+
"version"
|
|
45
|
+
]);
|
|
46
|
+
const LONG_PREFIX = "--";
|
|
47
|
+
const SHORT_PREFIX = "-";
|
|
48
|
+
const NEGATION_PREFIX = "--no-";
|
|
49
|
+
function aliasesOf(flags) {
|
|
50
|
+
return Object.entries(ALIASES).filter(([flag]) => flags.includes(flag)).flatMap(([, aliases]) => aliases.map((alias) => `${SHORT_PREFIX}${alias}`));
|
|
51
|
+
}
|
|
52
|
+
const BOOLEAN_FLAG_NAMES = /* @__PURE__ */ new Set([
|
|
53
|
+
...BOOLEAN_FLAGS.map((flag) => `${LONG_PREFIX}${flag}`),
|
|
54
|
+
...aliasesOf(CAMEL_CASE_BOOLEAN_FLAGS)
|
|
55
|
+
]);
|
|
56
|
+
const VALUE_FLAG_NAMES = /* @__PURE__ */ new Set([
|
|
57
|
+
...CAMEL_CASE_STRING_FLAGS.map((flag) => `${LONG_PREFIX}${scule.kebabCase(flag)}`),
|
|
58
|
+
...aliasesOf(CAMEL_CASE_STRING_FLAGS).map((alias) => `${SHORT_PREFIX}${alias}`)
|
|
59
|
+
]);
|
|
60
|
+
const KNOWN_LONG_FLAG_NAMES = new Set(
|
|
61
|
+
[...KNOWN_FLAGS].filter((flag) => flag.length > 1).map((flag) => `${LONG_PREFIX}${scule.kebabCase(flag)}`)
|
|
62
|
+
);
|
|
63
|
+
const KNOWN_SHORT_FLAGS = new Set(Object.values(ALIASES).flat());
|
|
64
|
+
|
|
65
|
+
exports.ALIASES = ALIASES;
|
|
66
|
+
exports.BOOLEAN_FLAGS = BOOLEAN_FLAGS;
|
|
67
|
+
exports.BOOLEAN_FLAG_NAMES = BOOLEAN_FLAG_NAMES;
|
|
68
|
+
exports.GENERATOR_FLAGS = GENERATOR_FLAGS;
|
|
69
|
+
exports.KNOWN_FLAGS = KNOWN_FLAGS;
|
|
70
|
+
exports.KNOWN_LONG_FLAG_NAMES = KNOWN_LONG_FLAG_NAMES;
|
|
71
|
+
exports.KNOWN_SHORT_FLAGS = KNOWN_SHORT_FLAGS;
|
|
72
|
+
exports.LONG_PREFIX = LONG_PREFIX;
|
|
73
|
+
exports.NEGATION_PREFIX = NEGATION_PREFIX;
|
|
74
|
+
exports.SHORT_PREFIX = SHORT_PREFIX;
|
|
75
|
+
exports.STRING_FLAGS = STRING_FLAGS;
|
|
76
|
+
exports.VALUE_FLAG_NAMES = VALUE_FLAG_NAMES;
|
|
77
|
+
//# sourceMappingURL=cli-flag-names.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-flag-names.cjs","sources":["../../src/cli/cli-flag-names.ts"],"sourcesContent":["import { kebabCase } from \"scule\";\n\n/** The names of the CLI's flags, in the spellings yargs-parser is told about. */\n\n/** Boolean flags that become generator options (camelCase; yargs also accepts kebab-case). */\nexport const GENERATOR_FLAGS = [\n \"additionalProperties\",\n \"alphabetize\",\n \"arrayLength\",\n \"binaryAsBlob\",\n \"conditionalEnums\",\n \"dedupeEnums\",\n \"defaultNonNullable\",\n \"emptyObjectsUnknown\",\n \"enum\",\n \"enumValues\",\n \"excludeDeprecated\",\n \"exportType\",\n \"generatePathParams\",\n \"immutable\",\n \"lint\",\n \"makePathsEnum\",\n \"pathParamsAsTypes\",\n \"propertiesRequiredByDefault\",\n \"readWriteMarkers\",\n \"rootTypes\",\n \"rootTypesKeepCasing\",\n \"rootTypesNoSchemaPrefix\",\n] as const;\n\nexport type GeneratorFlag = (typeof GENERATOR_FLAGS)[number];\n\nexport type GeneratorFlags = Readonly<Partial<Record<GeneratorFlag, boolean>>>;\n\n// `contentNever` was a boolean flag of the original CLI that no code reads; it stays in the list\n// so that `--content-never <input>` keeps parsing as a flag and an input.\nconst CAMEL_CASE_BOOLEAN_FLAGS = [...GENERATOR_FLAGS, \"check\", \"contentNever\", \"help\"];\n\n// yargs-parser matches the `boolean` list by the exact spelling of the flag: with camelCase names\n// only, `--root-types schema.yaml` took the path as the flag's value (upstream #2523). Both\n// spellings are listed.\nexport const BOOLEAN_FLAGS = [\n ...CAMEL_CASE_BOOLEAN_FLAGS,\n ...CAMEL_CASE_BOOLEAN_FLAGS.map((flag) => kebabCase(flag)),\n];\n\nexport const ALIASES = { redocly: [\"c\"], exportType: [\"t\"], output: [\"o\"] };\n\nconst CAMEL_CASE_STRING_FLAGS = [\"output\", \"redocly\", \"fix\", \"localRefRoot\", \"remoteRefHosts\"];\n\n/** String flags, in both spellings, so that a value such as `8080` is not read as a number. */\nexport const STRING_FLAGS = [\n ...CAMEL_CASE_STRING_FLAGS,\n ...CAMEL_CASE_STRING_FLAGS.map((flag) => kebabCase(flag)),\n];\n\n/** Every name yargs-parser can return for a flag this CLI reads. */\nexport const KNOWN_FLAGS: ReadonlySet<string> = new Set<string>([\n ...BOOLEAN_FLAGS,\n ...STRING_FLAGS,\n ...Object.values(ALIASES).flat(),\n \"version\",\n]);\n\nexport const LONG_PREFIX = \"--\";\nexport const SHORT_PREFIX = \"-\";\nexport const NEGATION_PREFIX = \"--no-\";\n\n/** The short aliases of `flags`, as written on the command line (`-t`). */\nfunction aliasesOf(flags: readonly string[]): string[] {\n return Object.entries(ALIASES)\n .filter(([flag]) => flags.includes(flag))\n .flatMap(([, aliases]) => aliases.map((alias) => `${SHORT_PREFIX}${alias}`));\n}\n\n/** The boolean flags as written, `--` and `-` included; they take `=true` or `=false`. */\nexport const BOOLEAN_FLAG_NAMES: ReadonlySet<string> = new Set([\n ...BOOLEAN_FLAGS.map((flag) => `${LONG_PREFIX}${flag}`),\n ...aliasesOf(CAMEL_CASE_BOOLEAN_FLAGS),\n]);\n\n/**\n * The flags that take a value, as `canonicalFlagName` gives them: kebab-case, and the short\n * aliases with `--`, since yargs-parser reads `--no-o` as the negation of `-o`.\n */\nexport const VALUE_FLAG_NAMES: ReadonlySet<string> = new Set([\n ...CAMEL_CASE_STRING_FLAGS.map((flag) => `${LONG_PREFIX}${kebabCase(flag)}`),\n ...aliasesOf(CAMEL_CASE_STRING_FLAGS).map((alias) => `${SHORT_PREFIX}${alias}`),\n]);\n\n/** The long flags this CLI reads, as `canonicalFlagName` gives them. */\nexport const KNOWN_LONG_FLAG_NAMES: ReadonlySet<string> = new Set(\n [...KNOWN_FLAGS]\n .filter((flag) => flag.length > 1)\n .map((flag) => `${LONG_PREFIX}${kebabCase(flag)}`),\n);\n\n/** The short flags this CLI reads, without the `-`. */\nexport const KNO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AE,MAAM;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { kebabCase } from 'scule';
|
|
2
|
+
|
|
3
|
+
const GENERATOR_FLAGS = [
|
|
4
|
+
"additionalProperties",
|
|
5
|
+
"alphabetize",
|
|
6
|
+
"arrayLength",
|
|
7
|
+
"binaryAsBlob",
|
|
8
|
+
"conditionalEnums",
|
|
9
|
+
"dedupeEnums",
|
|
10
|
+
"defaultNonNullable",
|
|
11
|
+
"emptyObjectsUnknown",
|
|
12
|
+
"enum",
|
|
13
|
+
"enumValues",
|
|
14
|
+
"excludeDeprecated",
|
|
15
|
+
"exportType",
|
|
16
|
+
"generatePathParams",
|
|
17
|
+
"immutable",
|
|
18
|
+
"lint",
|
|
19
|
+
"makePathsEnum",
|
|
20
|
+
"pathParamsAsTypes",
|
|
21
|
+
"propertiesRequiredByDefault",
|
|
22
|
+
"readWriteMarkers",
|
|
23
|
+
"rootTypes",
|
|
24
|
+
"rootTypesKeepCasing",
|
|
25
|
+
"rootTypesNoSchemaPrefix"
|
|
26
|
+
];
|
|
27
|
+
const CAMEL_CASE_BOOLEAN_FLAGS = [...GENERATOR_FLAGS, "check", "contentNever", "help"];
|
|
28
|
+
const BOOLEAN_FLAGS = [
|
|
29
|
+
...CAMEL_CASE_BOOLEAN_FLAGS,
|
|
30
|
+
...CAMEL_CASE_BOOLEAN_FLAGS.map((flag) => kebabCase(flag))
|
|
31
|
+
];
|
|
32
|
+
const ALIASES = { redocly: ["c"], exportType: ["t"], output: ["o"] };
|
|
33
|
+
const CAMEL_CASE_STRING_FLAGS = ["output", "redocly", "fix", "localRefRoot", "remoteRefHosts"];
|
|
34
|
+
const STRING_FLAGS = [
|
|
35
|
+
...CAMEL_CASE_STRING_FLAGS,
|
|
36
|
+
...CAMEL_CASE_STRING_FLAGS.map((flag) => kebabCase(flag))
|
|
37
|
+
];
|
|
38
|
+
const KNOWN_FLAGS = /* @__PURE__ */ new Set([
|
|
39
|
+
...BOOLEAN_FLAGS,
|
|
40
|
+
...STRING_FLAGS,
|
|
41
|
+
...Object.values(ALIASES).flat(),
|
|
42
|
+
"version"
|
|
43
|
+
]);
|
|
44
|
+
const LONG_PREFIX = "--";
|
|
45
|
+
const SHORT_PREFIX = "-";
|
|
46
|
+
const NEGATION_PREFIX = "--no-";
|
|
47
|
+
function aliasesOf(flags) {
|
|
48
|
+
return Object.entries(ALIASES).filter(([flag]) => flags.includes(flag)).flatMap(([, aliases]) => aliases.map((alias) => `${SHORT_PREFIX}${alias}`));
|
|
49
|
+
}
|
|
50
|
+
const BOOLEAN_FLAG_NAMES = /* @__PURE__ */ new Set([
|
|
51
|
+
...BOOLEAN_FLAGS.map((flag) => `${LONG_PREFIX}${flag}`),
|
|
52
|
+
...aliasesOf(CAMEL_CASE_BOOLEAN_FLAGS)
|
|
53
|
+
]);
|
|
54
|
+
const VALUE_FLAG_NAMES = /* @__PURE__ */ new Set([
|
|
55
|
+
...CAMEL_CASE_STRING_FLAGS.map((flag) => `${LONG_PREFIX}${kebabCase(flag)}`),
|
|
56
|
+
...aliasesOf(CAMEL_CASE_STRING_FLAGS).map((alias) => `${SHORT_PREFIX}${alias}`)
|
|
57
|
+
]);
|
|
58
|
+
const KNOWN_LONG_FLAG_NAMES = new Set(
|
|
59
|
+
[...KNOWN_FLAGS].filter((flag) => flag.length > 1).map((flag) => `${LONG_PREFIX}${kebabCase(flag)}`)
|
|
60
|
+
);
|
|
61
|
+
const KNOWN_SHORT_FLAGS = new Set(Object.values(ALIASES).flat());
|
|
62
|
+
|
|
63
|
+
export { ALIASES, BOOLEAN_FLAGS, BOOLEAN_FLAG_NAMES, GENERATOR_FLAGS, KNOWN_FLAGS, KNOWN_LONG_FLAG_NAMES, KNOWN_SHORT_FLAGS, LONG_PREFIX, NEGATION_PREFIX, SHORT_PREFIX, STRING_FLAGS, VALUE_FLAG_NAMES };
|
|
64
|
+
//# sourceMappingURL=cli-flag-names.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-flag-names.mjs","sources":["../../src/cli/cli-flag-names.ts"],"sourcesContent":["import { kebabCase } from \"scule\";\n\n/** The names of the CLI's flags, in the spellings yargs-parser is told about. */\n\n/** Boolean flags that become generator options (camelCase; yargs also accepts kebab-case). */\nexport const GENERATOR_FLAGS = [\n \"additionalProperties\",\n \"alphabetize\",\n \"arrayLength\",\n \"binaryAsBlob\",\n \"conditionalEnums\",\n \"dedupeEnums\",\n \"defaultNonNullable\",\n \"emptyObjectsUnknown\",\n \"enum\",\n \"enumValues\",\n \"excludeDeprecated\",\n \"exportType\",\n \"generatePathParams\",\n \"immutable\",\n \"lint\",\n \"makePathsEnum\",\n \"pathParamsAsTypes\",\n \"propertiesRequiredByDefault\",\n \"readWriteMarkers\",\n \"rootTypes\",\n \"rootTypesKeepCasing\",\n \"rootTypesNoSchemaPrefix\",\n] as const;\n\nexport type GeneratorFlag = (typeof GENERATOR_FLAGS)[number];\n\nexport type GeneratorFlags = Readonly<Partial<Record<GeneratorFlag, boolean>>>;\n\n// `contentNever` was a boolean flag of the original CLI that no code reads; it stays in the list\n// so that `--content-never <input>` keeps parsing as a flag and an input.\nconst CAMEL_CASE_BOOLEAN_FLAGS = [...GENERATOR_FLAGS, \"check\", \"contentNever\", \"help\"];\n\n// yargs-parser matches the `boolean` list by the exact spelling of the flag: with camelCase names\n// only, `--root-types schema.yaml` took the path as the flag's value (upstream #2523). Both\n// spellings are listed.\nexport const BOOLEAN_FLAGS = [\n ...CAMEL_CASE_BOOLEAN_FLAGS,\n ...CAMEL_CASE_BOOLEAN_FLAGS.map((flag) => kebabCase(flag)),\n];\n\nexport const ALIASES = { redocly: [\"c\"], exportType: [\"t\"], output: [\"o\"] };\n\nconst CAMEL_CASE_STRING_FLAGS = [\"output\", \"redocly\", \"fix\", \"localRefRoot\", \"remoteRefHosts\"];\n\n/** String flags, in both spellings, so that a value such as `8080` is not read as a number. */\nexport const STRING_FLAGS = [\n ...CAMEL_CASE_STRING_FLAGS,\n ...CAMEL_CASE_STRING_FLAGS.map((flag) => kebabCase(flag)),\n];\n\n/** Every name yargs-parser can return for a flag this CLI reads. */\nexport const KNOWN_FLAGS: ReadonlySet<string> = new Set<string>([\n ...BOOLEAN_FLAGS,\n ...STRING_FLAGS,\n ...Object.values(ALIASES).flat(),\n \"version\",\n]);\n\nexport const LONG_PREFIX = \"--\";\nexport const SHORT_PREFIX = \"-\";\nexport const NEGATION_PREFIX = \"--no-\";\n\n/** The short aliases of `flags`, as written on the command line (`-t`). */\nfunction aliasesOf(flags: readonly string[]): string[] {\n return Object.entries(ALIASES)\n .filter(([flag]) => flags.includes(flag))\n .flatMap(([, aliases]) => aliases.map((alias) => `${SHORT_PREFIX}${alias}`));\n}\n\n/** The boolean flags as written, `--` and `-` included; they take `=true` or `=false`. */\nexport const BOOLEAN_FLAG_NAMES: ReadonlySet<string> = new Set([\n ...BOOLEAN_FLAGS.map((flag) => `${LONG_PREFIX}${flag}`),\n ...aliasesOf(CAMEL_CASE_BOOLEAN_FLAGS),\n]);\n\n/**\n * The flags that take a value, as `canonicalFlagName` gives them: kebab-case, and the short\n * aliases with `--`, since yargs-parser reads `--no-o` as the negation of `-o`.\n */\nexport const VALUE_FLAG_NAMES: ReadonlySet<string> = new Set([\n ...CAMEL_CASE_STRING_FLAGS.map((flag) => `${LONG_PREFIX}${kebabCase(flag)}`),\n ...aliasesOf(CAMEL_CASE_STRING_FLAGS).map((alias) => `${SHORT_PREFIX}${alias}`),\n]);\n\n/** The long flags this CLI reads, as `canonicalFlagName` gives them. */\nexport const KNOWN_LONG_FLAG_NAMES: ReadonlySet<string> = new Set(\n [...KNOWN_FLAGS]\n .filter((flag) => flag.length > 1)\n .map((flag) => `${LONG_PREFIX}${kebabCase(flag)}`),\n);\n\n/** The short flags this CLI reads, without the `-`. */\nexport const KNOWN_SHORT_FLAGS: ReadonlySet<string> = new Set(Object.values(ALIASES).flat());\n"],"names":[],"mappings":";;AAKO,MAAM,eAAA,GAAkB;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
|
function duplicateOutputError(output, others) {
|
|
103
103
|
return cliErrors.cliError(
|
|
104
104
|
"CLI_OUTPUT_DUPLICATE",
|
|
105
|
-
`The output ${output.output}
|
|
105
|
+
`The output ${output.output} is also the output of ${others.join(", ")}: they would overwrite each other. Give each API its own output file.`
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
function parseLocationUrl(location, base) {
|
|
@@ -118,9 +118,14 @@ function printDone(run, output) {
|
|
|
118
118
|
const duration = style.dim(`[${terminalLogger.formatDuration(now() - run.startedAt)}]`);
|
|
119
119
|
run.deps.console.info(`\u{1F680} ${target} ${duration}`);
|
|
120
120
|
}
|
|
121
|
+
const CRLF = /\r\n/g;
|
|
122
|
+
const LF = "\n";
|
|
123
|
+
function withLfLineEnds(text) {
|
|
124
|
+
return text.replace(CRLF, LF);
|
|
125
|
+
}
|
|
121
126
|
function emitOutput(run, output, contents) {
|
|
122
127
|
if (run.args.isCheck) {
|
|
123
|
-
if (run.deps.files.readText(output.file) !== contents) {
|
|
128
|
+
if (withLfLineEnds(run.deps.files.readText(output.file)) !== withLfLineEnds(contents)) {
|
|
124
129
|
throw cliErrors.cliError(
|
|
125
130
|
"OUTPUT_STALE",
|
|
126
131
|
`Generated types are not up-to-date! ${output.output} differs from its schema.`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-output.cjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { redactUnparsedUrl, redactUrlSecrets } from \"../domain/url-secrets.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies, GeneratedTypes } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */\nexport interface NamedOutput {\n readonly source: string;\n readonly output: string;\n}\n\n/** A generated file: an output with the location of its local file. */\nexport interface OutputFile extends NamedOutput {\n readonly file: URL;\n}\n\n/**\n * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the\n * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves\n * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`\n * are part of the file name. A location with a scheme that does not parse as a URL\n * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (hasUrlScheme(location)) {\n const url = URL.parse(location, base.href);\n if (url === null) {\n const shown = redactUnparsedUrl(location);\n throw cliError(\"CLI_LOCATION_INVALID\", `The location ${shown} is not a valid URL`);\n }\n return url;\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** Segments that name a directory: the directory itself and its parent. */\nconst DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([\".\", \"..\"]);\n\n/**\n * Whether the location names a directory as written, before resolving drops the sign: a trailing\n * `/` (or `\\\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL\n * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.\n */\nfunction namesDirectory(location: string, file: URL): boolean {\n const lastSegment = location\n .split(path.sep)\n .flatMap((part) => part.split(\"/\"))\n .at(-1);\n return (\n lastSegment === \"\" || DIRECTORY_SEGMENTS.has(lastSegment ?? \"\") || file.pathname.endsWith(\"/\")\n );\n}\n\nfunction invalidOutput(output: string, reason: string): Error {\n return cliError(\"CLI_OUTPUT_INVALID\", `The output ${output} ${reason}`);\n}\n\n/** The URL of the output, if it is a local file that can be written; it may not exist yet. */\nfunction outputUrlOf(run: CliRun, output: string, base: URL): URL {\n const file = parseLocationUrl(output, base);\n if (file?.protocol !== FILE_PROTOCOL) {\n throw invalidOutput(\n output,\n \"is not a local file. Write the types to a file path or a file: URL.\",\n );\n }\n if (!isLocalFile(file)) {\n throw invalidOutput(output, \"names no file on this computer. Use a file path instead.\");\n }\n if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {\n throw invalidOutput(output, \"is a directory. Name the file to write the types to in it.\");\n }\n return file;\n}\n\n/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */\nfunction isLocalFile(file: URL): boolean {\n try {\n fileURLToPath(file);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with\n * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of\n * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a\n * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.\n */\nexport function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {\n return { ...named, file: outputUrlOf(run, named.output, base) };\n}\n\n/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */\nexport interface NamedFile {\n readonly name: string;\n readonly location: URL;\n}\n\n/** The `files` that are the local file `output`, also through a link or in another letter case. */\nfunction filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {\n return files.filter(\n ({ location }) =>\n location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),\n );\n}\n\n/** A location as a path relative to the working directory, as error messages name files. */\nfunction displayPathOf(run: CliRun, location: URL): string {\n return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || \".\";\n}\n\n/** The Redocly config file the run read, if any: no output may replace it. */\nexport function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {\n if (!redocly.configFile) {\n return [];\n }\n const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);\n return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];\n}\n\n/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */\nexport function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {\n return types.localFiles.map((location) => ({\n name: `schema ${displayPathOf(run, location)} that ${owner} reads`,\n location,\n }));\n}\n\n/**\n * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).\n * Writing it would replace that file with the types, which upstream did without a word. The CLI\n * checks the files it knows before generating, so nothing is loaded or written, and the files\n * that `$ref`s loaded after generating, before anything is written.\n */\nexport function ensureOutputIsNotSchema(\n run: CliRun,\n output: OutputFile,\n schemas: readonly NamedFile[],\n): void {\n const [schema] = filesAtOutput(run, output, schemas);\n if (schema) {\n throw cliError(\n \"CLI_OUTPUT_IS_INPUT\",\n `The output ${output.output} is the ${schema.name}: writing the types would ` +\n \"overwrite it. Choose another output file.\",\n );\n }\n}\n\n/**\n * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.\n * Whichever write came last would win, so every API with that output fails, before anything is\n * generated.\n */\nexport function ensureOutputIsOwn(\n run: CliRun,\n output: OutputFile,\n otherOutputs: readonly NamedFile[],\n): void {\n const clashes = filesAtOutput(run, output, otherOutputs);\n if (clashes.length > 0) {\n throw duplicateOutputError(\n output,\n clashes.map(({ name }) => name),\n );\n }\n}\n\n/** `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). */\nexport function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {\n return cliError(\n \"CLI_OUTPUT_DUPLICATE\",\n `The output ${output.output} of API ${output.source} is also the output of ` +\n `${others.join(\", \")}: they would overwrite each other. Give each API its own output file.`,\n );\n}\n\n/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */\nexport function parseLocationUrl(location: string, base: URL): URL | undefined {\n if (hasUrlScheme(location)) {\n return URL.parse(location, base.href) ?? undefined;\n }\n return resolveLocationUrl(location, base);\n}\n\n/**\n * The line for a written file. It goes to the job log, so a source URL shows no secrets, and a\n * line break or escape sequence in a name cannot start a forged line.\n */\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const source = terminalSafeText(redactUrlSecrets(output.source));\n const target = style.green(`${source} → ${style.bold(terminalSafeText(output.output))}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` and leave it\n * alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (run.deps.files.readText(output.file) !== contents) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n\n/** Write (or `--check`) the types, unless the output is one of the files the run read. */\nexport function writeOutput(\n run: CliRun,\n output: OutputFile,\n types: GeneratedTypes,\n readFiles: readonly NamedFile[],\n): void {\n ensureOutputIsNotSchema(run, output, readFiles);\n emitOutput(run, output, types.contents);\n}\n"],"names":["hasUrlScheme","redactUnparsedUrl","cliError","fileURLToPath","pathToFileURL","path","terminalSafeText","redactUrlSecrets","formatDuration"],"mappings":";;;;;;;;;;;;;;AAsCO,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAIA,yBAAA,CAAa,QAAQ,CAAA,EAAG;AAC1B,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,QAAA,EAAU,KAAK,IAAI,CAAA;AACzC,IAAA,IAAI,QAAQ,IAAA,EAAM;AAChB,MAAA,MAAM,KAAA,GAAQC,6BAAkB,QAAQ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AK,OAAA,EAAS;AACpB,IAAA,IAAI,IAAI,IAAA,CAAK,KAAA,CAAM,SAAS,MAAA,CAAO,IAAI,MAAM,QAAA,EAAU;AAErD,MAAA,MAAMN,kBAAA;AAAA,QACJ,cAAA;AAAA,QACA,CAAA,oCAAA,EAAuC,OAAO,MAAM,CAAA,yBAAA;AAAA,OACtD;AAAA,IACF;AACA,IAAA;AAAA,EACF;AACA,EAAA,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,MAAM,QAAQ,CAAA;AAC9C,EAAA,SAAA,CAAU,KAAK,MAAM,CAAA;AACvB;AAGO,SAAS,WAAA,CACd,GAAA,EACA,MAAA,EACA,KAAA,EACA,SAAA,EACM;AACN,EAAA,uBAAA,CAAwB,GAAA,EAAK,QAAQ,SAAS,CAAA;AAC9C,EAAA,UAAA,CAAW,GAAA,EAAK,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AACxC;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"cli-output.cjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { redactUnparsedUrl, redactUrlSecrets } from \"../domain/url-secrets.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies, GeneratedTypes } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */\nexport interface NamedOutput {\n readonly source: string;\n readonly output: string;\n}\n\n/** A generated file: an output with the location of its local file. */\nexport interface OutputFile extends NamedOutput {\n readonly file: URL;\n}\n\n/**\n * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the\n * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves\n * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`\n * are part of the file name. A location with a scheme that does not parse as a URL\n * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (hasUrlScheme(location)) {\n const url = URL.parse(location, base.href);\n if (url === null) {\n const shown = redactUnparsedUrl(location);\n throw cliError(\"CLI_LOCATION_INVALID\", `The location ${shown} is not a valid URL`);\n }\n return url;\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** Segments that name a directory: the directory itself and its parent. */\nconst DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([\".\", \"..\"]);\n\n/**\n * Whether the location names a directory as written, before resolving drops the sign: a trailing\n * `/` (or `\\\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL\n * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.\n */\nfunction namesDirectory(location: string, file: URL): boolean {\n const lastSegment = location\n .split(path.sep)\n .flatMap((part) => part.split(\"/\"))\n .at(-1);\n return (\n lastSegment === \"\" || DIRECTORY_SEGMENTS.has(lastSegment ?? \"\") || file.pathname.endsWith(\"/\")\n );\n}\n\nfunction invalidOutput(output: string, reason: string): Error {\n return cliError(\"CLI_OUTPUT_INVALID\", `The output ${output} ${reason}`);\n}\n\n/** The URL of the output, if it is a local file that can be written; it may not exist yet. */\nfunction outputUrlOf(run: CliRun, output: string, base: URL): URL {\n const file = parseLocationUrl(output, base);\n if (file?.protocol !== FILE_PROTOCOL) {\n throw invalidOutput(\n output,\n \"is not a local file. Write the types to a file path or a file: URL.\",\n );\n }\n if (!isLocalFile(file)) {\n throw invalidOutput(output, \"names no file on this computer. Use a file path instead.\");\n }\n if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {\n throw invalidOutput(output, \"is a directory. Name the file to write the types to in it.\");\n }\n return file;\n}\n\n/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */\nfunction isLocalFile(file: URL): boolean {\n try {\n fileURLToPath(file);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with\n * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of\n * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a\n * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.\n */\nexport function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {\n return { ...named, file: outputUrlOf(run, named.output, base) };\n}\n\n/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */\nexport interface NamedFile {\n readonly name: string;\n readonly location: URL;\n}\n\n/** The `files` that are the local file `output`, also through a link or in another letter case. */\nfunction filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {\n return files.filter(\n ({ location }) =>\n location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),\n );\n}\n\n/** A location as a path relative to the working directory, as error messages name files. */\nfunction displayPathOf(run: CliRun, location: URL): string {\n return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || \".\";\n}\n\n/** The Redocly config file the run read, if any: no output may replace it. */\nexport function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {\n if (!redocly.configFile) {\n return [];\n }\n const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);\n return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];\n}\n\n/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */\nexport function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {\n return types.localFiles.map((location) => ({\n name: `schema ${displayPathOf(run, location)} that ${owner} reads`,\n location,\n }));\n}\n\n/**\n * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).\n * Writing it would replace that file with the types, which upstream did without a word. The CLI\n * checks the files it knows before generating, so nothing is loaded or written, and the files\n * that `$ref`s loaded after generating, before anything is written.\n */\nexport function ensureOutputIsNotSchema(\n run: CliRun,\n output: OutputFile,\n schemas: readonly NamedFile[],\n): void {\n const [schema] = filesAtOutput(run, output, schemas);\n if (schema) {\n throw cliError(\n \"CLI_OUTPUT_IS_INPUT\",\n `The output ${output.output} is the ${schema.name}: writing the types would ` +\n \"overwrite it. Choose another output file.\",\n );\n }\n}\n\n/**\n * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.\n * Whichever write came last would win, so every API with that output fails, before anything is\n * generated.\n */\nexport function ensureOutputIsOwn(\n run: CliRun,\n output: OutputFile,\n otherOutputs: readonly NamedFile[],\n): void {\n const clashes = filesAtOutput(run, output, otherOutputs);\n if (clashes.length > 0) {\n throw duplicateOutputError(\n output,\n clashes.map(({ name }) => name),\n );\n }\n}\n\n/**\n * `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). Only\n * APIs share outputs, and the CLI names the API before the message (`ApiFailure`).\n */\nexport function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {\n return cliError(\n \"CLI_OUTPUT_DUPLICATE\",\n `The output ${output.output} is also the output of ${others.join(\", \")}: they would ` +\n \"overwrite each other. Give each API its own output file.\",\n );\n}\n\n/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */\nexport function parseLocationUrl(location: string, base: URL): URL | undefined {\n if (hasUrlScheme(location)) {\n return URL.parse(location, base.href) ?? undefined;\n }\n return resolveLocationUrl(location, base);\n}\n\n/**\n * The line for a written file. It goes to the job log, so a source URL shows no secrets, and a\n * line break or escape sequence in a name cannot start a forged line.\n */\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const source = terminalSafeText(redactUrlSecrets(output.source));\n const target = style.green(`${source} → ${style.bold(terminalSafeText(output.output))}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\nconst CRLF = /\\r\\n/g;\nconst LF = \"\\n\";\n\n/**\n * The text with LF line ends. Git with `core.autocrlf` checks a committed file out with CRLF on\n * Windows, so `--check` compares lines, not line ends.\n */\nfunction withLfLineEnds(text: string): string {\n return text.replace(CRLF, LF);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` (line ends\n * aside) and leave it alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (withLfLineEnds(run.deps.files.readText(output.file)) !== withLfLineEnds(contents)) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n\n/** Write (or `--check`) the types, unless the output is one of the files the run read. */\nexport function writeOutput(\n run: CliRun,\n output: OutputFile,\n types: GeneratedTypes,\n readFiles: readonly NamedFile[],\n): void {\n ensureOutputIsNotSchema(run, output, readFiles);\n emitOutput(run, output, types.contents);\n}\n"],"names":["hasUrlScheme","redactUnparsedUrl","cliError","fileURLToPath","pathToFileURL","path","terminalSafeText","redactUrlSecrets","formatDuration"],"mappings":";;;;;;;;;;;;;;AAsCO,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAIA,yBAAA,CAAa,QAAQ,CAAA,EAAG;AAC1B,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,QAAA,EAAU,KAAK,IAAI,CAAA;AACzC,IAAA,IAAI,QAAQ,IAAA,EAAM;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AAA,CAAK,OAAA,CAAQ,IAAA,EAAM,EAAE,CAAA;AAC9B;AAMO,SAAS,UAAA,CAAW,GAAA,EAAa,MAAA,EAAoB,QAAA,EAAwB;AAClF,EAAA,IAAI,GAAA,CAAI,KAAK,OAAA,EAAS;AACpB,IAAA,IAAI,cAAA,CAAe,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,QAAA,CAAS,MAAA,CAAO,IAAI,CAAC,CAAA,KAAM,cAAA,CAAe,QAAQ,CAAA,EAAG;AAErF,MAAA,MAAMN,kBAAA;AAAA,QACJ,cAAA;AAAA,QACA,CAAA,oCAAA,EAAuC,OAAO,MAAM,CAAA,yBAAA;AAAA,OACtD;AAAA,IACF;AACA,IAAA;AAAA,EACF;AACA,EAAA,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,SAAA,CAAU,MAAA,CAAO,MAAM,QAAQ,CAAA;AAC9C,EAAA,SAAA,CAAU,KAAK,MAAM,CAAA;AACvB;AAGO,SAAS,WAAA,CACd,GAAA,EACA,MAAA,EACA,KAAA,EACA,SAAA,EACM;AACN,EAAA,uBAAA,CAAwB,GAAA,EAAK,QAAQ,SAAS,CAAA;AAC9C,EAAA,UAAA,CAAW,GAAA,EAAK,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AACxC;;;;;;;;;;;"}
|
package/dist/cli/cli-output.mjs
CHANGED
|
@@ -96,7 +96,7 @@ function ensureOutputIsOwn(run, output, otherOutputs) {
|
|
|
96
96
|
function duplicateOutputError(output, others) {
|
|
97
97
|
return cliError(
|
|
98
98
|
"CLI_OUTPUT_DUPLICATE",
|
|
99
|
-
`The output ${output.output}
|
|
99
|
+
`The output ${output.output} is also the output of ${others.join(", ")}: they would overwrite each other. Give each API its own output file.`
|
|
100
100
|
);
|
|
101
101
|
}
|
|
102
102
|
function parseLocationUrl(location, base) {
|
|
@@ -112,9 +112,14 @@ function printDone(run, output) {
|
|
|
112
112
|
const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);
|
|
113
113
|
run.deps.console.info(`\u{1F680} ${target} ${duration}`);
|
|
114
114
|
}
|
|
115
|
+
const CRLF = /\r\n/g;
|
|
116
|
+
const LF = "\n";
|
|
117
|
+
function withLfLineEnds(text) {
|
|
118
|
+
return text.replace(CRLF, LF);
|
|
119
|
+
}
|
|
115
120
|
function emitOutput(run, output, contents) {
|
|
116
121
|
if (run.args.isCheck) {
|
|
117
|
-
if (run.deps.files.readText(output.file) !== contents) {
|
|
122
|
+
if (withLfLineEnds(run.deps.files.readText(output.file)) !== withLfLineEnds(contents)) {
|
|
118
123
|
throw cliError(
|
|
119
124
|
"OUTPUT_STALE",
|
|
120
125
|
`Generated types are not up-to-date! ${output.output} differs from its schema.`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-output.mjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { redactUnparsedUrl, redactUrlSecrets } from \"../domain/url-secrets.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies, GeneratedTypes } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */\nexport interface NamedOutput {\n readonly source: string;\n readonly output: string;\n}\n\n/** A generated file: an output with the location of its local file. */\nexport interface OutputFile extends NamedOutput {\n readonly file: URL;\n}\n\n/**\n * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the\n * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves\n * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`\n * are part of the file name. A location with a scheme that does not parse as a URL\n * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (hasUrlScheme(location)) {\n const url = URL.parse(location, base.href);\n if (url === null) {\n const shown = redactUnparsedUrl(location);\n throw cliError(\"CLI_LOCATION_INVALID\", `The location ${shown} is not a valid URL`);\n }\n return url;\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** Segments that name a directory: the directory itself and its parent. */\nconst DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([\".\", \"..\"]);\n\n/**\n * Whether the location names a directory as written, before resolving drops the sign: a trailing\n * `/` (or `\\\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL\n * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.\n */\nfunction namesDirectory(location: string, file: URL): boolean {\n const lastSegment = location\n .split(path.sep)\n .flatMap((part) => part.split(\"/\"))\n .at(-1);\n return (\n lastSegment === \"\" || DIRECTORY_SEGMENTS.has(lastSegment ?? \"\") || file.pathname.endsWith(\"/\")\n );\n}\n\nfunction invalidOutput(output: string, reason: string): Error {\n return cliError(\"CLI_OUTPUT_INVALID\", `The output ${output} ${reason}`);\n}\n\n/** The URL of the output, if it is a local file that can be written; it may not exist yet. */\nfunction outputUrlOf(run: CliRun, output: string, base: URL): URL {\n const file = parseLocationUrl(output, base);\n if (file?.protocol !== FILE_PROTOCOL) {\n throw invalidOutput(\n output,\n \"is not a local file. Write the types to a file path or a file: URL.\",\n );\n }\n if (!isLocalFile(file)) {\n throw invalidOutput(output, \"names no file on this computer. Use a file path instead.\");\n }\n if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {\n throw invalidOutput(output, \"is a directory. Name the file to write the types to in it.\");\n }\n return file;\n}\n\n/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */\nfunction isLocalFile(file: URL): boolean {\n try {\n fileURLToPath(file);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with\n * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of\n * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a\n * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.\n */\nexport function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {\n return { ...named, file: outputUrlOf(run, named.output, base) };\n}\n\n/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */\nexport interface NamedFile {\n readonly name: string;\n readonly location: URL;\n}\n\n/** The `files` that are the local file `output`, also through a link or in another letter case. */\nfunction filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {\n return files.filter(\n ({ location }) =>\n location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),\n );\n}\n\n/** A location as a path relative to the working directory, as error messages name files. */\nfunction displayPathOf(run: CliRun, location: URL): string {\n return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || \".\";\n}\n\n/** The Redocly config file the run read, if any: no output may replace it. */\nexport function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {\n if (!redocly.configFile) {\n return [];\n }\n const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);\n return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];\n}\n\n/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */\nexport function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {\n return types.localFiles.map((location) => ({\n name: `schema ${displayPathOf(run, location)} that ${owner} reads`,\n location,\n }));\n}\n\n/**\n * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).\n * Writing it would replace that file with the types, which upstream did without a word. The CLI\n * checks the files it knows before generating, so nothing is loaded or written, and the files\n * that `$ref`s loaded after generating, before anything is written.\n */\nexport function ensureOutputIsNotSchema(\n run: CliRun,\n output: OutputFile,\n schemas: readonly NamedFile[],\n): void {\n const [schema] = filesAtOutput(run, output, schemas);\n if (schema) {\n throw cliError(\n \"CLI_OUTPUT_IS_INPUT\",\n `The output ${output.output} is the ${schema.name}: writing the types would ` +\n \"overwrite it. Choose another output file.\",\n );\n }\n}\n\n/**\n * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.\n * Whichever write came last would win, so every API with that output fails, before anything is\n * generated.\n */\nexport function ensureOutputIsOwn(\n run: CliRun,\n output: OutputFile,\n otherOutputs: readonly NamedFile[],\n): void {\n const clashes = filesAtOutput(run, output, otherOutputs);\n if (clashes.length > 0) {\n throw duplicateOutputError(\n output,\n clashes.map(({ name }) => name),\n );\n }\n}\n\n/** `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). */\nexport function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {\n return cliError(\n \"CLI_OUTPUT_DUPLICATE\",\n `The output ${output.output} of API ${output.source} is also the output of ` +\n `${others.join(\", \")}: they would overwrite each other. Give each API its own output file.`,\n );\n}\n\n/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */\nexport function parseLocationUrl(location: string, base: URL): URL | undefined {\n if (hasUrlScheme(location)) {\n return URL.parse(location, base.href) ?? undefined;\n }\n return resolveLocationUrl(location, base);\n}\n\n/**\n * The line for a written file. It goes to the job log, so a source URL shows no secrets, and a\n * line break or escape sequence in a name cannot start a forged line.\n */\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const source = terminalSafeText(redactUrlSecrets(output.source));\n const target = style.green(`${source} → ${style.bold(terminalSafeText(output.output))}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` and leave it\n * alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (run.deps.files.readText(output.file) !== contents) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n\n/** Write (or `--check`) the types, unless the output is one of the files the run read. */\nexport function writeOutput(\n run: CliRun,\n output: OutputFile,\n types: GeneratedTypes,\n readFiles: readonly NamedFile[],\n): void {\n ensureOutputIsNotSchema(run, output, readFiles);\n emitOutput(run, output, types.contents);\n}\n"],"names":[],"mappings":";;;;;;;;AAsCO,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAI,YAAA,CAAa,QAAQ,CAAA,EAAG;AAC1B,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,QAAA,EAAU,KAAK,IAAI,CAAA;AACzC,IAAA,IAAI,QAAQ,IAAA,EAAM;AAChB,MAAA,MAAM,KAAA,GAAQ,kBAAkB,QAAQ,CAAA;AACxC,MAAA,MAAM,QAAA,CAAS,sBAAA,EAAwB,CAAA,aAAA,EAAgB,KAAK,CAAA,mBAAA,CAAqB,CAAA;AAAA,IACnF;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,MAAM,gBAAgB,aAAA,CAAc,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAC,CAAA;AACtD,EAAA,OAAO,aAAA,CAAc,IAAA,CAAK,OAAA,CAAQ,aAAA,EAAe,QAAQ,CAAC,CAAA;AAC5D;AAEA,MAAM,aAAA,GAAgB,OAAA;AAGtB,MAAM,qCAA0C,IAAI,GAAA,CAAI,CAAC,GAAA,EAAK,IAAI,CAAC,CA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,uBAAA,CAAwB,GAAA,EAAK,QAAQ,SAAS,CAAA;AAC9C,EAAA,UAAA,CAAW,GAAA,EAAK,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AACxC;;"}
|
|
1
|
+
{"version":3,"file":"cli-output.mjs","sources":["../../src/cli/cli-output.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { formatDuration } from \"../adapters/terminal-logger/terminal-logger.js\";\nimport type { RedoclyConfig } from \"../application/ports/redocly-config-source.js\";\nimport { hasUrlScheme } from \"../domain/location-text.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { redactUnparsedUrl, redactUrlSecrets } from \"../domain/url-secrets.js\";\nimport type { CliArguments } from \"./cli-arguments.js\";\nimport type { CliDependencies, GeneratedTypes } from \"./cli-dependencies.js\";\nimport { cliError } from \"./cli-errors.js\";\n\n/** Writing one generated file, or checking it with `--check`, and the line printed for it. */\n\n/** One CLI run: its dependencies, its arguments and when it started. */\nexport interface CliRun {\n readonly deps: CliDependencies;\n readonly args: CliArguments;\n readonly startedAt: number;\n}\n\n/** An output as the user wrote it: `source` names the schema, `output` is the path or URL. */\nexport interface NamedOutput {\n readonly source: string;\n readonly output: string;\n}\n\n/** A generated file: an output with the location of its local file. */\nexport interface OutputFile extends NamedOutput {\n readonly file: URL;\n}\n\n/**\n * The URL of a location the user wrote: a URL, else a file path, absolute or relative to the\n * directory of `base` (a directory or file URL). A relative `file:` URL (`file:api.yaml`) resolves\n * against `base` too, as in openapi-typescript. A path is not parsed as a URL, so `#`, `?` and `%`\n * are part of the file name. A location with a scheme that does not parse as a URL\n * (`http://[::1/x`) fails with `CLI_LOCATION_INVALID`.\n */\nexport function resolveLocationUrl(location: string, base: URL): URL {\n if (hasUrlScheme(location)) {\n const url = URL.parse(location, base.href);\n if (url === null) {\n const shown = redactUnparsedUrl(location);\n throw cliError(\"CLI_LOCATION_INVALID\", `The location ${shown} is not a valid URL`);\n }\n return url;\n }\n const baseDirectory = fileURLToPath(new URL(\".\", base));\n return pathToFileURL(path.resolve(baseDirectory, location));\n}\n\nconst FILE_PROTOCOL = \"file:\";\n\n/** Segments that name a directory: the directory itself and its parent. */\nconst DIRECTORY_SEGMENTS: ReadonlySet<string> = new Set([\".\", \"..\"]);\n\n/**\n * Whether the location names a directory as written, before resolving drops the sign: a trailing\n * `/` (or `\\\\` on Windows), or a last segment `.` or `..` (`-o gen/.`, `-o a/b/..`). For a URL\n * the parsed path tells it too, since the URL parser drops `.`, `..` and their `%2E` forms.\n */\nfunction namesDirectory(location: string, file: URL): boolean {\n const lastSegment = location\n .split(path.sep)\n .flatMap((part) => part.split(\"/\"))\n .at(-1);\n return (\n lastSegment === \"\" || DIRECTORY_SEGMENTS.has(lastSegment ?? \"\") || file.pathname.endsWith(\"/\")\n );\n}\n\nfunction invalidOutput(output: string, reason: string): Error {\n return cliError(\"CLI_OUTPUT_INVALID\", `The output ${output} ${reason}`);\n}\n\n/** The URL of the output, if it is a local file that can be written; it may not exist yet. */\nfunction outputUrlOf(run: CliRun, output: string, base: URL): URL {\n const file = parseLocationUrl(output, base);\n if (file?.protocol !== FILE_PROTOCOL) {\n throw invalidOutput(\n output,\n \"is not a local file. Write the types to a file path or a file: URL.\",\n );\n }\n if (!isLocalFile(file)) {\n throw invalidOutput(output, \"names no file on this computer. Use a file path instead.\");\n }\n if (namesDirectory(output, file) || run.deps.files.isDirectory(file)) {\n throw invalidOutput(output, \"is a directory. Name the file to write the types to in it.\");\n }\n return file;\n}\n\n/** A `file:` URL with a host, or with an encoded slash, names no path on this platform. */\nfunction isLocalFile(file: URL): boolean {\n try {\n fileURLToPath(file);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The output file of `source`, as the user wrote it in `output`, relative to `base`. Fails with\n * `CLI_OUTPUT_INVALID` before anything is generated when it is not a local file (a URL of\n * another scheme) or is a directory (a trailing separator, a last segment `.` or `..`, or a\n * directory on disk). Without this check, `-o dir/` and `-o dir/.` wrote a file named `dir`.\n */\nexport function outputFileOf(run: CliRun, named: NamedOutput, base: URL): OutputFile {\n return { ...named, file: outputUrlOf(run, named.output, base) };\n}\n\n/** A file the CLI reads or writes: `name` is how an error names it, `location` where it is. */\nexport interface NamedFile {\n readonly name: string;\n readonly location: URL;\n}\n\n/** The `files` that are the local file `output`, also through a link or in another letter case. */\nfunction filesAtOutput(run: CliRun, output: OutputFile, files: readonly NamedFile[]): NamedFile[] {\n return files.filter(\n ({ location }) =>\n location.protocol === FILE_PROTOCOL && run.deps.files.isSameFile(location, output.file),\n );\n}\n\n/** A location as a path relative to the working directory, as error messages name files. */\nfunction displayPathOf(run: CliRun, location: URL): string {\n return path.relative(fileURLToPath(run.deps.cwd), fileURLToPath(location)) || \".\";\n}\n\n/** The Redocly config file the run read, if any: no output may replace it. */\nexport function redoclyConfigFiles(run: CliRun, redocly: RedoclyConfig): NamedFile[] {\n if (!redocly.configFile) {\n return [];\n }\n const location = resolveLocationUrl(redocly.configFile, run.deps.cwd);\n return [{ name: `Redocly config ${displayPathOf(run, location)}`, location }];\n}\n\n/** The local files that `owner` (a schema or an API) was generated from, `$ref`'d ones too. */\nexport function filesReadBy(run: CliRun, types: GeneratedTypes, owner: string): NamedFile[] {\n return types.localFiles.map((location) => ({\n name: `schema ${displayPathOf(run, location)} that ${owner} reads`,\n location,\n }));\n}\n\n/**\n * Fail with `CLI_OUTPUT_IS_INPUT` when `output` is one of the `schemas` (or the Redocly config).\n * Writing it would replace that file with the types, which upstream did without a word. The CLI\n * checks the files it knows before generating, so nothing is loaded or written, and the files\n * that `$ref`s loaded after generating, before anything is written.\n */\nexport function ensureOutputIsNotSchema(\n run: CliRun,\n output: OutputFile,\n schemas: readonly NamedFile[],\n): void {\n const [schema] = filesAtOutput(run, output, schemas);\n if (schema) {\n throw cliError(\n \"CLI_OUTPUT_IS_INPUT\",\n `The output ${output.output} is the ${schema.name}: writing the types would ` +\n \"overwrite it. Choose another output file.\",\n );\n }\n}\n\n/**\n * Fail with `CLI_OUTPUT_DUPLICATE` when the output of an API is also one of `otherOutputs`.\n * Whichever write came last would win, so every API with that output fails, before anything is\n * generated.\n */\nexport function ensureOutputIsOwn(\n run: CliRun,\n output: OutputFile,\n otherOutputs: readonly NamedFile[],\n): void {\n const clashes = filesAtOutput(run, output, otherOutputs);\n if (clashes.length > 0) {\n throw duplicateOutputError(\n output,\n clashes.map(({ name }) => name),\n );\n }\n}\n\n/**\n * `CLI_OUTPUT_DUPLICATE` for `output`, which is also the output of the `others` (named). Only\n * APIs share outputs, and the CLI names the API before the message (`ApiFailure`).\n */\nexport function duplicateOutputError(output: NamedOutput, others: readonly string[]): Error {\n return cliError(\n \"CLI_OUTPUT_DUPLICATE\",\n `The output ${output.output} is also the output of ${others.join(\", \")}: they would ` +\n \"overwrite each other. Give each API its own output file.\",\n );\n}\n\n/** As `resolveLocationUrl`, but undefined for a URL that does not parse instead of a throw. */\nexport function parseLocationUrl(location: string, base: URL): URL | undefined {\n if (hasUrlScheme(location)) {\n return URL.parse(location, base.href) ?? undefined;\n }\n return resolveLocationUrl(location, base);\n}\n\n/**\n * The line for a written file. It goes to the job log, so a source URL shows no secrets, and a\n * line break or escape sequence in a name cannot start a forged line.\n */\nfunction printDone(run: CliRun, output: OutputFile): void {\n const { style, now } = run.deps;\n const source = terminalSafeText(redactUrlSecrets(output.source));\n const target = style.green(`${source} → ${style.bold(terminalSafeText(output.output))}`);\n const duration = style.dim(`[${formatDuration(now() - run.startedAt)}]`);\n run.deps.console.info(`🚀 ${target} ${duration}`);\n}\n\nconst CRLF = /\\r\\n/g;\nconst LF = \"\\n\";\n\n/**\n * The text with LF line ends. Git with `core.autocrlf` checks a committed file out with CRLF on\n * Windows, so `--check` compares lines, not line ends.\n */\nfunction withLfLineEnds(text: string): string {\n return text.replace(CRLF, LF);\n}\n\n/**\n * With `--check`, fail with `OUTPUT_STALE` when the file differs from `contents` (line ends\n * aside) and leave it alone otherwise. Without it, write the file and print where it went.\n */\nexport function emitOutput(run: CliRun, output: OutputFile, contents: string): void {\n if (run.args.isCheck) {\n if (withLfLineEnds(run.deps.files.readText(output.file)) !== withLfLineEnds(contents)) {\n // The original message, then the file: with several APIs it tells which one is stale.\n throw cliError(\n \"OUTPUT_STALE\",\n `Generated types are not up-to-date! ${output.output} differs from its schema.`,\n );\n }\n return;\n }\n run.deps.files.writeText(output.file, contents);\n printDone(run, output);\n}\n\n/** Write (or `--check`) the types, unless the output is one of the files the run read. */\nexport function writeOutput(\n run: CliRun,\n output: OutputFile,\n types: GeneratedTypes,\n readFiles: readonly NamedFile[],\n): void {\n ensureOutputIsNotSchema(run, output, readFiles);\n emitOutput(run, output, types.contents);\n}\n"],"names":[],"mappings":";;;;;;;;AAsCO,SAAS,kBAAA,CAAmB,UAAkB,IAAA,EAAgB;AACnE,EAAA,IAAI,YAAA,CAAa,QAAQ,CAAA,EAAG;AAC1B,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,QAAA,EAAU,KAAK,IAAI,CAAA;AACzC,IAAA,IAAI,QAAQ,IAAA,EAAM;AAChB,MAAA,MAAM,KAAA,GAAQ,kBAAkB,QAAQ,CAAA;AACxC,MAAA,MAAM,QAAA,CAAS,sBAAA,EAAwB,CAAA,aAAA,EAAgB,KAAK,CAAA,mBAAA,CAAqB,CAAA;AAAA,IACnF;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,MAAM,gBAAgB,aAAA,CAAc,IAAI,GAAA,CAAI,GAAA,EAAK,IAAI,CAAC,CAAA;AACtD,EAAA,OAAO,aAAA,CAAc,IAAA,CAAK,OAAA,CAAQ,aAAA,EAAe,QAAQ,CAAC,CAAA;AAC5D;AAEA,MAAM,aAAA,GAAgB,OAAA;AAGtB,MAAM,qCAA0C,IAAI,GAAA,CAAI,CAAC,GAAA,EAAK,IAAI,CAAC,CAAA;AAOnE,SAAS,cAAA,CAAe,UAAkB,IAAA,EAAoB;AAC5D,EAAA,MAAM,WAAA,GAAc,QAAA,CAC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O,SAAS,WAAA,CACd,GAAA,EACA,MAAA,EACA,KAAA,EACA,SAAA,EACM;AACN,EAAA,uBAAA,CAAwB,GAAA,EAAK,QAAQ,SAAS,CAAA;AAC9C,EAAA,UAAA,CAAW,GAAA,EAAK,MAAA,EAAQ,KAAA,CAAM,QAAQ,CAAA;AACxC;;"}
|
package/dist/cli/main.cjs
CHANGED
|
@@ -28,7 +28,7 @@ function readVersion() {
|
|
|
28
28
|
}
|
|
29
29
|
function terminalStyle() {
|
|
30
30
|
const palette = colors__default.create();
|
|
31
|
-
palette.enabled = defaultPorts.terminalSupportsColor();
|
|
31
|
+
palette.enabled = defaultPorts.terminalSupportsColor("stdout");
|
|
32
32
|
return {
|
|
33
33
|
bold: (text) => palette.bold(text),
|
|
34
34
|
green: (text) => palette.green(text),
|
package/dist/cli/main.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.cjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createPipeSafeWriter } from \"../adapters/pipe-safe-writer/pipe-safe-writer.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { apiLogger } from \"./api-logger.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor();\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options, apiName) => {\n const terminalLogger = defaultLogger(options.silent ?? false);\n const logger = apiName === undefined ? terminalLogger : apiLogger(terminalLogger, apiName);\n const ports = await defaultGeneratorPorts(options, logger);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // A notice names flags and API names as written, so it is shown as one plain line.\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(terminalSafeText(text)),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: createPipeSafeWriter(process.stdout),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":["fs","colors","terminalSupportsColor","defaultLogger","apiLogger","defaultGeneratorPorts","generateDocument","COMMENT_HEADER","astToString","terminalSafeText","pathToFileURL","createPipeSafeWriter","isatty","createNodeFileSystem","createRedoclyConfigSource","monotonicNow","runCli"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,oBAAA,EAAsB,8PAAe,CAAA;AAElE,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,cAAmC,IAAA,CAAK,KAAA,CAAMA,YAAG,YAAA,CAAa,YAAA,EAAc,MAAM,CAAC,CAAA;AACzF,EAAA,OAAO,WAAA,CAAY,OAAA;AACrB;
|
|
1
|
+
{"version":3,"file":"main.cjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createPipeSafeWriter } from \"../adapters/pipe-safe-writer/pipe-safe-writer.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { apiLogger } from \"./api-logger.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\n/** The style of the CLI's own lines, which go to stdout. */\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor(\"stdout\");\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options, apiName) => {\n const terminalLogger = defaultLogger(options.silent ?? false);\n const logger = apiName === undefined ? terminalLogger : apiLogger(terminalLogger, apiName);\n const ports = await defaultGeneratorPorts(options, logger);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // A notice names flags and API names as written, so it is shown as one plain line.\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(terminalSafeText(text)),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: createPipeSafeWriter(process.stdout),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":["fs","colors","terminalSupportsColor","defaultLogger","apiLogger","defaultGeneratorPorts","generateDocument","COMMENT_HEADER","astToString","terminalSafeText","pathToFileURL","createPipeSafeWriter","isatty","createNodeFileSystem","createRedoclyConfigSource","monotonicNow","runCli"],"mappings":";;;;;;;;;;;;;;;;;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A,GAA8B;AACrC,EAAA,OAAO;AAAA;AAAA,IAEL,IAAA,EAAM,CAAC,IAAA,KAAS,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA;AAAA;AAAA,IAGjC,QAAQ,CAAC,IAAA,KAAS,QAAQ,IAAA,CAAKC,6BAAA,CAAiB,IAAI,CAAC;AAAA,GACvD;AACF;AAEA,SAAS,mBAAA,GAAuC;AAC9C,EAAA,MAAM,GAAA,GAAM,QAAQ,GAAA,EAAI;AACxB,EAAA,OAAO;AAAA,IACL,GAAA,EAAKC,sBAAA,CAAc,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG,CAAA;AAAA,IAC5B,SAAS,WAAA,EAAY;AAAA,IACrB,MAAA,EAAQP,2BAAc,KAAK,CAAA;AAAA,IAC3B,SAAS,eAAA,EAAgB;AAAA,IACzB,WAAA,EAAaQ,mCAAA,CAAqB,OAAA,CAAQ,MAAM,CAAA;AAAA,IAChD,KAAA,EAAO,MAAM,OAAA,CAAQ,KAAA;AAAA;AAAA;AAAA,IAGrB,eAAA,EAAiB,MAAMC,eAAA,CAAO,gBAAgB,CAAA;AAAA,IAC9C,OAAOC,mCAAA,EAAqB;AAAA,IAC5B,cAAA,EAAgBC,8CAA0B,GAAG,CAAA;AAAA,IAC7C,QAAA,EAAU,aAAA;AAAA,IACV,GAAA,EAAKC,yBAAA;AAAA,IACL,OAAO,aAAA;AAAc,GACvB;AACF;AAEAC,aAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,EAAG,qBAAqB,CAAA,CAAE,IAAA,CAAK,CAAC,QAAA,KAAa;AACtE,EAAA,OAAA,CAAQ,QAAA,GAAW,QAAA;AACrB,CAAC,CAAA"}
|
package/dist/cli/main.mjs
CHANGED
|
@@ -20,7 +20,7 @@ function readVersion() {
|
|
|
20
20
|
}
|
|
21
21
|
function terminalStyle() {
|
|
22
22
|
const palette = colors.create();
|
|
23
|
-
palette.enabled = terminalSupportsColor();
|
|
23
|
+
palette.enabled = terminalSupportsColor("stdout");
|
|
24
24
|
return {
|
|
25
25
|
bold: (text) => palette.bold(text),
|
|
26
26
|
green: (text) => palette.green(text),
|
package/dist/cli/main.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createPipeSafeWriter } from \"../adapters/pipe-safe-writer/pipe-safe-writer.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { apiLogger } from \"./api-logger.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor();\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options, apiName) => {\n const terminalLogger = defaultLogger(options.silent ?? false);\n const logger = apiName === undefined ? terminalLogger : apiLogger(terminalLogger, apiName);\n const ports = await defaultGeneratorPorts(options, logger);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // A notice names flags and API names as written, so it is shown as one plain line.\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(terminalSafeText(text)),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: createPipeSafeWriter(process.stdout),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,oBAAA,EAAsB,YAAY,GAAG,CAAA;AAElE,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,cAAmC,IAAA,CAAK,KAAA,CAAM,GAAG,YAAA,CAAa,YAAA,EAAc,MAAM,CAAC,CAAA;AACzF,EAAA,OAAO,WAAA,CAAY,OAAA;AACrB;
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":["../../src/cli/main.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { isatty } from \"node:tty\";\nimport { pathToFileURL } from \"node:url\";\nimport colors from \"ansi-colors\";\nimport { createNodeFileSystem } from \"../adapters/node-file-system/node-file-system.js\";\nimport { createPipeSafeWriter } from \"../adapters/pipe-safe-writer/pipe-safe-writer.js\";\nimport { createRedoclyConfigSource } from \"../adapters/redocly-loader/redocly-config-source.js\";\nimport { astToString } from \"../api/ast-to-string.js\";\nimport { COMMENT_HEADER } from \"../api/comment-header.js\";\nimport { defaultLogger, monotonicNow, terminalSupportsColor } from \"../api/default-ports.js\";\nimport { defaultGeneratorPorts, generateDocument } from \"../api/openapi-ts.js\";\nimport { terminalSafeText } from \"../domain/terminal-text.js\";\nimport { apiLogger } from \"./api-logger.js\";\nimport type { CliConsole, CliDependencies, GenerateTypes, TextStyle } from \"./cli-dependencies.js\";\nimport { runCli } from \"./run-cli.js\";\n\n/**\n * The CLI's composition root (ENGINEERING_PLAN 4.5, ADR-012): the only CLI module that touches the\n * process. `bin/cli.js` imports the built copy of this module.\n */\n\n/** The same path from `src/cli/` and from the built `dist/cli/`. */\nconst PACKAGE_JSON = new URL(\"../../package.json\", import.meta.url);\n\nfunction readVersion(): string {\n const packageJson: { version: string } = JSON.parse(fs.readFileSync(PACKAGE_JSON, \"utf8\"));\n return packageJson.version;\n}\n\n/** The style of the CLI's own lines, which go to stdout. */\nfunction terminalStyle(): TextStyle {\n const palette = colors.create();\n palette.enabled = terminalSupportsColor(\"stdout\");\n return {\n bold: (text) => palette.bold(text),\n green: (text) => palette.green(text),\n dim: (text) => palette.dim(text),\n };\n}\n\nconst STDIN_DESCRIPTOR = 0;\n\nconst generateTypes: GenerateTypes = async (source, options, apiName) => {\n const terminalLogger = defaultLogger(options.silent ?? false);\n const logger = apiName === undefined ? terminalLogger : apiLogger(terminalLogger, apiName);\n const ports = await defaultGeneratorPorts(options, logger);\n const { declarations, localFiles } = await generateDocument(source, options, ports);\n return { contents: `${COMMENT_HEADER}${astToString(declarations)}`, localFiles };\n};\n\nfunction terminalConsole(): CliConsole {\n return {\n // biome-ignore lint/suspicious/noConsole: the CLI's own output lines\n info: (text) => console.info(text),\n // A notice names flags and API names as written, so it is shown as one plain line.\n // biome-ignore lint/suspicious/noConsole: the CLI's own notices\n notice: (text) => console.warn(terminalSafeText(text)),\n };\n}\n\nfunction processDependencies(): CliDependencies {\n const cwd = process.cwd();\n return {\n cwd: pathToFileURL(`${cwd}/`),\n version: readVersion(),\n logger: defaultLogger(false),\n console: terminalConsole(),\n writeStdout: createPipeSafeWriter(process.stdout),\n stdin: () => process.stdin,\n // `isatty` reads the descriptor without opening `process.stdin`, which would keep the\n // process alive.\n isStdinTerminal: () => isatty(STDIN_DESCRIPTOR),\n files: createNodeFileSystem(),\n redoclyConfigs: createRedoclyConfigSource(cwd),\n generate: generateTypes,\n now: monotonicNow,\n style: terminalStyle(),\n };\n}\n\nrunCli(process.argv.slice(2), processDependencies()).then((exitCode) => {\n process.exitCode = exitCode;\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,oBAAA,EAAsB,YAAY,GAAG,CAAA;AAElE,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,cAAmC,IAAA,CAAK,KAAA,CAAM,GAAG,YAAA,CAAa,YAAA,EAAc,MAAM,CAAC,CAAA;AACzF,EAAA,OAAO,WAAA,CAAY,OAAA;AACrB;AAGA,SAAS,aAAA,GAA2B;AAClC,EAAA,MAAM,OAAA,GAAU,OAAO,MAAA,EAAO;AAC9B,EAAA,OAAA,CAAQ,OAAA,GAAU,sBAAsB,QAAQ,CAAA;AAChD,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,CAAC,IAAA,KAAS,OAAA,CAAQ,KAAK,IAAI,CAAA;AAAA,IACjC,KAAA,EAAO,CAAC,IAAA,KAAS,OAAA,CAAQ,MAAM,IAAI,CAAA;AAAA,IACnC,GAAA,EAAK,CAAC,IAAA,KAAS,OAAA,CAAQ,IAAI,IAAI;AAAA,GACjC;AACF;AAEA,MAAM,gBAAA,GAAmB,CAAA;AAEzB,MAAM,aAAA,GAA+B,OAAO,MAAA,EAAQ,O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,IAC5B,cAAA,EAAgB,0BAA0B,GAAG,CAAA;AAAA,IAC7C,QAAA,EAAU,aAAA;AAAA,IACV,GAAA,EAAK,YAAA;AAAA,IACL,OAAO,aAAA;AAAc,GACvB;AACF;AAEA,MAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,EAAG,qBAAqB,CAAA,CAAE,IAAA,CAAK,CAAC,QAAA,KAAa;AACtE,EAAA,OAAA,CAAQ,QAAA,GAAW,QAAA;AACrB,CAAC,CAAA"}
|
|
@@ -55,7 +55,7 @@ function apiOptions(run, apiRun, target) {
|
|
|
55
55
|
...apiRun.refLimits,
|
|
56
56
|
...apiSettings.apiRefLimitOptions(name, settings, configRoot),
|
|
57
57
|
...fixOption.fixOption(apiSettings.apiFixNames(name, settings) ?? run.args.fix),
|
|
58
|
-
redocly: apiRun.redocly
|
|
58
|
+
redocly: run.deps.redoclyConfigs.forApi(apiRun.redocly, name)
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function otherOutputs(files, apiName) {
|
|
@@ -67,9 +67,12 @@ async function generateApi(run, apiRun, target) {
|
|
|
67
67
|
run.deps.logger.warn(warning);
|
|
68
68
|
}
|
|
69
69
|
const output = apiSettings.apiOutputOf(target.name, target.settings);
|
|
70
|
-
const outputFile =
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const outputFile = failingAsApi(target.name, () => {
|
|
71
|
+
const file = cliOutput.outputFileOf(run, { source: target.name, output }, target.configRoot);
|
|
72
|
+
cliOutput.ensureOutputIsNotSchema(run, file, files.schemas);
|
|
73
|
+
cliOutput.ensureOutputIsOwn(run, file, otherOutputs(files, target.name));
|
|
74
|
+
return file;
|
|
75
|
+
});
|
|
73
76
|
const source = cliOutput.resolveLocationUrl(target.root, target.configRoot);
|
|
74
77
|
const options = apiOptions(run, apiRun, target);
|
|
75
78
|
try {
|
|
@@ -79,6 +82,13 @@ async function generateApi(run, apiRun, target) {
|
|
|
79
82
|
throw new cliErrors.ApiFailure(target.name, error);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
85
|
+
function failingAsApi(apiName, step) {
|
|
86
|
+
try {
|
|
87
|
+
return step();
|
|
88
|
+
} catch (error) {
|
|
89
|
+
throw new cliErrors.ApiFailure(apiName, error);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
82
92
|
function configFilesOf(run, redocly, apis) {
|
|
83
93
|
const configRoot = configRootOf(redocly, run.deps.cwd);
|
|
84
94
|
const roots = apis.flatMap(({ name, root }) => {
|