Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support emitDecoratorMetadata #347

Open
pincman opened this issue Jun 16, 2022 · 20 comments
Open

Support emitDecoratorMetadata #347

pincman opened this issue Jun 16, 2022 · 20 comments
Labels
blocked enhancement New feature or request

Comments

@pincman
Copy link

pincman commented Jun 16, 2022

some typescript and node framework (like nestjs) use emitDecoratorMetadata , but esbuild not support it, and @anatine/esbuild-decorators plugin can solve it .
but esbuild's transform api not support plugin,some can change the api to use build?

like the follow code

async function transpile(code, filename, options = {}) {
    const ext = path.extname(filename);

    const loaders = getLoaders(options);

    const builded = await build({
        ...commonOptions,
        platform: 'node',
        ...options,
        ...{
            loader: loaders,
            bundle: true,
            stdin: {
                sourcefile: filename,
                contents: code,
                resolveDir: path.dirname(filename),
                loader: loaders[ext],
            },
            external: [...externals, ...(options.external ?? [])],
            write: false,
            plugins: [
                ...(options.plugins ?? []),
                esbuildDecorators({ tsconfig: options.tsconfig ?? undefined }),
            ],
        },
    });
    return builded.outputFiles.map((f) => f.text).join('\n');
}
@privatenumber
Copy link
Owner

We can't use the Build API because it would bypass Node.js' resolver, and add overhead writing/reading disk.

To do what that plugin does, we don't technically need to use the Build API. We just need to re-implement the TypeScript transformation on the file when emitDecoratorMetadata is enabled.

However, this will require TypeScript to be a dependency, and add a bottleneck to transformation, which defeats the point of using esbuild (and this entire module).

Alternatively, we can consider leveraging SWC for this part but this should be investigated first. esbuild is not planning to support it.

@privatenumber privatenumber changed the title transformSync not support esbuild plugin Support emitDecoratorMetadata Jun 16, 2022
@privatenumber privatenumber added the enhancement New feature or request label Jun 16, 2022
@wenerme
Copy link

wenerme commented Jun 1, 2023

Is it possible to some how enable the tsc for this like https://github.com/thomaschaaf/esbuild-plugin-tsc ?

@privatenumber privatenumber transferred this issue from esbuild-kit/core-utils Oct 18, 2023
@tianyingchun

This comment was marked as spam.

1 similar comment
@tianyingchun

This comment was marked as off-topic.

@wenerme

This comment was marked as off-topic.

@tianyingchun

This comment was marked as off-topic.

@tianyingchun

This comment was marked as off-topic.

@wenerme

This comment was marked as off-topic.

@privatenumber
Copy link
Owner

I'd like to reserve Issues for those interested in contributing, and discussions constructive towards addressing the issue (e.g. implementing fixes or features). Please discuss workarounds elsewhere.

@privatenumber
Copy link
Owner

@wenerme:

Is it possible to some how enable the tsc for this like thomaschaaf/esbuild-plugin-tsc ?

This is already answered above:

However, this will require TypeScript to be a dependency, and add a bottleneck to transformation, which defeats the point of using esbuild (and this entire module).

@cayter

This comment was marked as off-topic.

@privatenumber
Copy link
Owner

Is it that same thing as this issue? I've personally never used decorators so I'm not sure.

As I understand, what shipped in terms of tsconfig.json is support for experimentalDecorators (JS spec), rather than emitDecoratorMetadata (TS spec), which is what this thread is about.


I published the esbuild v0.21 upgrade in tsx 4.10.0-rc.1 through the development repo (sponsors only). Holding official release for a few weeks since it's still seems to require further testing.

@cayter

This comment was marked as off-topic.

@privatenumber

This comment was marked as off-topic.

@cayter

This comment was marked as off-topic.

@privatenumber

This comment was marked as off-topic.

@cayter

This comment was marked as off-topic.

@privatenumber

This comment was marked as off-topic.

@cayter

This comment was marked as off-topic.

@privatenumber

This comment was marked as off-topic.

Repository owner locked and limited conversation to collaborators May 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants