Skip to content

Update the git extension to support esbuild #296355

@mjbvz

Description

@mjbvz

I'm migrating all extensions to build using esbuild instead of webpack. One of the last remaining extension is git. This migration is blocked by its use of const enums evanw/esbuild#4394

Problem

The git.d.ts api file declares the git extension's api. This file defines both pure types as well as a few const enums

In the git extension, the g.d.ts file is imported in a number of other files like this:

import { API, RefType, Repository } from './typings/git';

Because there is only a d.ts file and no actual code file, ESBuild requires that you add a type modifier to these imports:

import type { API, RefType, Repository } from './typings/git';

However the const enums RefType is used at runtime in many places (for example in code such as b.type === RefType.RemoteHead) so we can't actually add the type modifier to the import

Proposal

After a few experiments, here's what I think may work:

  1. In the git extension, add a new file called git.constants.ts that provides runtime declarations of all the const enums from git.d.ts.:
import type * as gitApi from './typings/git.js';

export const RefType = Object.freeze({
	Head: 0,
	RemoteHead: 1,
	Tag: 2
}) satisfies typeof gitApi.RefType;

I think these types should compatible now in any place that expects a RefType at runtime

  1. In the git extension, update all imports of git.d.ts to use import type

  2. In the git extension, for any places that need the const enums value at runtime, import from git.constants.d.ts instead

@lszomoru Let me know if this plan sounds good or if you have ideas on simpler ways to handle this

cc @jrieken

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions