Skip to content

Converted @tryghost/tpl to TypeScript#720

Open
EvanHahn wants to merge 1 commit into
mainfrom
convert-tpl-to-typescript
Open

Converted @tryghost/tpl to TypeScript#720
EvanHahn wants to merge 1 commit into
mainfrom
convert-tpl-to-typescript

Conversation

@EvanHahn

Copy link
Copy Markdown
Contributor

no ref

This converts @tryghost/tpl to TypeScript, and exports type definitions with the package. This should be backwards-compatible.

@coderabbitai

This comment was marked as low quality.

@EvanHahn EvanHahn force-pushed the convert-tpl-to-typescript branch from a548827 to 6a562dd Compare June 10, 2026 19:16
@codecov-commenter

codecov-commenter commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.04%. Comparing base (b21d63d) to head (e8523eb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #720      +/-   ##
==========================================
- Coverage   98.05%   98.04%   -0.01%     
==========================================
  Files          85       84       -1     
  Lines        2770     2759      -11     
  Branches      508      506       -2     
==========================================
- Hits         2716     2705      -11     
  Misses         12       12              
  Partials       42       42              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR converts the @tryghost/tpl workspace package from JavaScript to TypeScript and starts publishing generated .d.ts type definitions alongside the compiled JavaScript, while aiming to preserve the existing CommonJS consumption pattern.

Changes:

  • Add TypeScript project configuration for packages/tpl (build + test typecheck).
  • Replace the implementation entrypoints with TypeScript sources and emit .js/.d.ts via tsc.
  • Update package metadata/scripts to build before tests and publish type declarations.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pnpm-lock.yaml Updates the lockfile for packages/tpl dev dependency changes (TypeScript + Node types).
packages/tpl/vitest.config.ts Adds per-package Vitest config merged from the repo root configuration.
packages/tpl/tsconfig.test.json Adds a test-specific TS config enabling Node + Vitest global typings.
packages/tpl/tsconfig.json Adds the package TS build configuration extending the shared packages/tsconfig.json.
packages/tpl/test/tpl.test.ts Migrates tests from CommonJS require to ES imports and minor const cleanups.
packages/tpl/package.json Publishes generated .d.ts, adds build/prepare scripts, and adds TS-related dev deps.
packages/tpl/lib/tpl.ts Converts implementation to TypeScript and switches to export = for CJS compatibility.
packages/tpl/index.ts Adds TS entrypoint re-exporting the implementation with export =.
packages/tpl/index.js Removes the committed JS entrypoint (now generated by tsc).
packages/tpl/.gitignore Ignores generated build artifacts (.js, .d.ts, maps) in the package folder.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

packages/tpl/lib/tpl.ts:10

  • The exported tpl type currently restricts data values to string, but in-repo callers pass non-string values (e.g. numeric {max} in packages/validator/lib/validate.js). This makes the new published typings unnecessarily breaking for TypeScript consumers. Widening the value type and explicitly stringifying replacements keeps runtime behavior the same while improving the public typings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@EvanHahn EvanHahn requested a review from 9larsons June 10, 2026 19:25
@EvanHahn

Copy link
Copy Markdown
Contributor Author

I requested a review from Copilot because CodeRabbit didn't work (hit a usage limit).

@EvanHahn EvanHahn force-pushed the convert-tpl-to-typescript branch from 6a562dd to d0efb99 Compare June 10, 2026 19:27
no ref

This converts `@tryghost/tpl` to TypeScript, and exports type
definitions with the package. This should be backwards-compatible.
@EvanHahn EvanHahn force-pushed the convert-tpl-to-typescript branch from d0efb99 to e8523eb Compare June 14, 2026 02:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/tpl/lib/tpl.ts`:
- Line 23: The explicit String() call on line 23 in the tpl.ts file changes the
runtime behavior for edge cases like Symbol values, breaking the legacy coercion
semantics. Remove the String() wrapper and instead return the raw value
data[trimmed] directly, allowing the replacer callback to handle the coercion
naturally as it did in the original implementation. This preserves the 1:1
behavior required for this migration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 606ea290-03a2-44e3-84b7-9bf68940494d

📥 Commits

Reviewing files that changed from the base of the PR and between b21d63d and e8523eb.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • packages/tpl/.gitignore
  • packages/tpl/index.js
  • packages/tpl/index.ts
  • packages/tpl/lib/tpl.ts
  • packages/tpl/package.json
  • packages/tpl/test/tpl.test.ts
  • packages/tpl/tsconfig.json
  • packages/tpl/tsconfig.test.json
  • packages/tpl/vitest.config.ts
💤 Files with no reviewable changes (1)
  • packages/tpl/index.js

Comment thread packages/tpl/lib/tpl.ts
throw new ReferenceError(`${trimmed} is not defined`);
}
return data[trimmed];
return String(data[trimmed]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Preserve legacy interpolation coercion behavior (avoid explicit String() here).

Line 23 introduces a runtime behavior change in a migration that should stay 1:1: explicit String(data[trimmed]) no longer matches legacy replacement semantics for edge cases (e.g., Symbol values). Keep the legacy coercion path by returning the raw value through the replacer callback.

Suggested fix
-        return String(data[trimmed]);
+        return data[trimmed] as string;

Based on learnings: Wave 1 TS+ESM migrations should preserve runtime behavior and avoid logic changes.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return String(data[trimmed]);
return data[trimmed] as string;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/tpl/lib/tpl.ts` at line 23, The explicit String() call on line 23 in
the tpl.ts file changes the runtime behavior for edge cases like Symbol values,
breaking the legacy coercion semantics. Remove the String() wrapper and instead
return the raw value data[trimmed] directly, allowing the replacer callback to
handle the coercion naturally as it did in the original implementation. This
preserves the 1:1 behavior required for this migration.

Source: Learnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants