Skip to content

Bug: Generated .ts files contain CRLF line endings + apostrophe in JSDoc, breaking vue-tsc #180

Description

@zengyishou

Environment

  • wormajs@0.2.5
  • macOS (also reproducible on Linux)
  • Using alova() plugin with swagger() input, typescript template

Steps to reproduce

  1. Start a backend that serves an OpenAPI 3.1 spec at http://localhost:3000/openapi.json
  2. Run npx wormajs gen -p . with output src/api/generated
  3. Run vue-tsc --noEmit (or tsc --noEmit) against the generated code

Expected behavior

Generated .ts files use LF line endings, and JSDoc comments contain no characters that trip the TypeScript lexer. TypeScript compilation should pass cleanly.

Actual behavior

Generated .ts files contain \r\n (CRLF) line endings. Combined with the alova's apostrophe in the JSDoc header:

 * NOTE: This file is auto generated by the alova's vscode plugin.

vue-tsc reports errors like:

src/api/generated/services/ping.ts(11,8): error TS1005: ';' expected.
src/api/generated/services/ping.ts(11,67): error TS1002: Unterminated string literal.
src/api/generated/services/ping.ts(13,2): error TS1109: Expression expected.

Root cause analysis

Two separate issues that compound each other:

1. CRLF from endOfLine: 'auto' in utils/format.js

// utils/format.js:51
endOfLine: 'auto',

When prettier's endOfLine is set to 'auto', and the template content or runtime environment triggers CRLF detection, generated files contain \r\n. The TypeScript compiler and vue-tsc handle CRLF inconsistently when mixed with certain characters in JSDoc.

Notably, /core/loader/callingCodeLoader/index.js:31 already uses endOfLine: 'lf' — this should be the default everywhere for code generation output.

2. Apostrophe in comment.handlebars

<!-- template/presets/alova/partials/comment.handlebars:14 -->
 * NOTE: This file is auto generated by the alova's vscode plugin.

The alova's apostrophe, when inside a multi-line JSDoc comment with CRLF line endings, causes the TypeScript lexer to go into an error state (it appears to interpret the ' as a string delimiter).

The same apostrophe appears in other preset partials (alova-globals, fetch, axios, ky).

Proposed fix

Fix 1 — utils/format.js

Change endOfLine: 'auto'endOfLine: 'lf'

This forces all generated code to use consistent LF line endings regardless of OS.

Fix 2 — comment.handlebars (all presets)

Change the alova's vscode pluginthe alova team (https://alova.js.org) or simply remove the apostrophe:

- * NOTE: This file is auto generated by the alova's vscode plugin.
+ * NOTE: This file is auto generated by the alova team (https://alova.js.org).

This is cleaner and avoids the apostrophe entirely. It also keeps the attribution while using a URL users can actually visit (the current text references "vscode plugin" which doesn't tell users where to find more info).

Affected files

  • packages/wormajs/src/utils/format.ts (source) → dist/utils/format.js
  • packages/wormajs/src/template/presets/alova/partials/comment.handlebars
  • packages/wormajs/src/template/presets/alova-globals/partials/comment.handlebars
  • packages/wormajs/src/template/presets/fetch/partials/comment.handlebars
  • packages/wormajs/src/template/presets/axios/partials/comment.handlebars
  • packages/wormajs/src/template/presets/ky/partials/comment.handlebars

Happy to submit a PR for both fixes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions