thomaschaaf / esbuild-plugin-tsc Goto Github PK
View Code? Open in Web Editor NEWAn esbuild plugin which uses tsc to compile typescript files.
License: MIT License
An esbuild plugin which uses tsc to compile typescript files.
License: MIT License
Just curious if there's any way hook this up with esbuild-kit/tsx
Getting two different errors so far I know when enabling "bundle: true" , and without that would be fine
Class constructor BaseEntity cannot be invoked without 'new'",
Entity metadata for BaseEntity#Metric was not found. Check if you specified a correct entity object and if it's connected in the connection options.",
"options": {
"platform": "node",
"outputPath": "dist/apps/api",
"format": ["cjs"],
"bundle": true,
"sourcemap": true,
"main": "apps/api/src/main.ts",
"tsConfig": "apps/api/tsconfig.app.json",
"esbuildConfig": "apps/api/esbuild.config.js",
"assets": ["apps/api/src/assets", "apps/api/src/views/**"]
},
Manual/readme is not correct here: https://github.com/thomaschaaf/esbuild-plugin-tsc#basic-usage
Doesn't work:
import { esbuildPluginTsc } from 'esbuild-plugin-tsc';
esbuild.build({
...
plugins: [
esbuildPluginTsc(),
]
...
});
Works:
import esbuildPluginTsc from 'esbuild-plugin-tsc';
esbuild.build({
...
plugins: [
esbuildPluginTsc(),
]
...
});
If I pot that to nuxt config I see nothing
vite: {
optimizeDeps: {
esbuildOptions: {
plugins: [
esbuildPluginTsc(),
],
},
},
}
Don't know where to add it.
Hello,
Thx for your work, it's a step further to enable typescript decorator in esbuild ;)
I still got the error Reflect.hasOwnMetadata
is not a function. I added your plugin in my configuration for Esbuild (I am using Vite JS for bundling), so here is my vite.config.ts file.
import { defineConfig } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import NodeModulePolyfill from '@esbuild-plugins/node-modules-polyfill';
import NodeGlobalsPolyfill from '@esbuild-plugins/node-globals-polyfill';
import EsbuildTypescript from 'esbuild-plugin-tsc';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [reactRefresh()],
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
},
optimizeDeps: {
esbuildOptions: {
plugins: [
EsbuildTypescript(),
NodeModulePolyfill(),
NodeGlobalsPolyfill(),
],
},
},
});
And here is my tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"include": ["./src"]
}
Do you have any idea why i still got an error ? I thought that your plugin would fix the problem of Typescript decorator.
Anyway, thanks again for your work ;)
Best regards,
Thanks for writing this plugin - it's ideal for the use case I'm after.
I was checking the implementation of force: true and noticed on line 50 of the current release it will return if a file doesn't contain any decorators. My initial understanding of force: true
is that it would run all files through tsc regardless of whether they have decorators. Is that the intention?
I'm happy to raise a PR if so although I know it's a quick change to fix this. But I wanted to check first whether I understood the goal behind the force option.
I came across this plugin when I was trying to get TypeGraphQL to work with SST which under the hood uses AWS CDK which internally uses esbuild
.
I was wondering if it's possible you were trying to accomplish the same thing and found a way to get emitDecoratorMetadata
working in an SST app. My project currently uses a combination of the serverless framework and serverless-bundle to build my code but would like to use SST instead.
I thought it was worth a shot to check to see if you are in fact trying to do the same, if not, don't mind me!
source: https://github.com/thomaschaaf/esbuild-plugin-tsc/blob/main/src/index.js#L54
In typescript compiler api d.ts, the second param of transpileModule
is:
interface TranspileOptions {
compilerOptions?: CompilerOptions;
fileName?: string;
reportDiagnostics?: boolean;
moduleName?: string;
renamedDependencies?: MapLike<string>;
transformers?: CustomTransformers;
}
So it should not directly pass the parsedTsConfig
to it or it will use default empty config for transpiling. The correct way is:
const program = typescript.transpileModule(ts, { compilerOptions: parsedTsConfig.options });
When using typescript version 5.2.2 in combination with the esbuild-plugin-tsc my ci/cd deployment fails at deployment step. When going down to version 5.0.4 pipeline deploys successfull.
Unfortunately the serverless-framework logs in their ci/cd does not give any hint about what is causing it
Hi :),
I am using this plugin with serverless-esbuild to add support for decorator metadata, but I am hitting a block road and I am unsure if this is related to this or something else.
I am using it with MikroORM, which accepts properties that are functions:
@ManyToOne({entity: () => RelatedEntity, mappedBy: 'foo'})
MikroORM also supports setting string properties, which works:
@ManyToOne({entity: 'RelatedEntity', mappedBy: 'foo'})
But I would prefer using the function one, as it helps TypeScript to figure out the entity properties.
When ESBuild attempts to read the data from a function attribute, it raises errors like this:
โ Cannot read properties of undefined (reading 'name')
I wonder if this is a limitation of this plugin that only support scalar values, or if this is completely unrelated :).
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.