anatine / esbuildnx Goto Github PK
View Code? Open in Web Editor NEWEsbuild plugin for Nx
Esbuild plugin for Nx
Need CI/CD pipelines for the following processes
import path from 'path';
import { esbuildDecorators } from '@anatine/esbuild-decorators';
import { build } from "esbuild"
build({
entryPoints: [path.resolve('src/server/main.ts')],
bundle: true,
outfile: 'out.js',
platform: 'node',
target: 'node14',
bundle: true,
sourcemap: 'external',
plugins: [
esbuildDecorators({
tsconfigPath: path.resolve('tsconfig.server.json'),
force: true,
}),
],
})
.catch(() => process.exit(1));
▲ [WARNING] Top-level "this" will be replaced with undefined since this file is an ECMAScript module
src/server/controller/HomeController.ts:1:18:
1 │ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
│ ~~~~
╵ undefined
This file is considered to be an ECMAScript module because of the "export" keyword here:
src/server/controller/HomeController.ts:25:0:
25 │ export { HomeController };
╵ ~~~~~~
Done in 1.67s.
config
// esbuild-runner.config.js
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const { esbuildDecorators } = require('@anatine/esbuild-decorators');
const tsconfig = path.resolve(__dirname, './tsconfig.json');
const getEsbuildOptions = async () => ({
// Any esbuild build or transform options go here
platform: 'node',
target: 'esnext',
sourcemap: false,
plugins: [esbuildDecorators({ tsconfig, cwd: process.cwd() })],
});
const getConfig = async () => ({
type: 'bundle', // bundle or transform (see description above)
esbuild: await getEsbuildOptions(),
});
module.exports = getConfig();
bin.js
if (typeof process.env.NODE_ENV === 'undefined') {
process.env.NODE_ENV = 'development';
}
require('esbuild-runner/register');
require('module-alias/register');
error
ColumnTypeUndefinedError: Column type for PostEntity#title is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.
at new Co
Code Position: esbuild-decorators.ts
Regular expressions don't work when decorator functions start with '$'. for example:
function Test(target: any, key?: string, pKey?: any) {
if(!key) {
return
}
console.log(">>>", Reflect.getMetadata("design:type", target, key))
}
@$Test
class Nardy {
@$Test
private name: Date = new Date()
@$Test
setName() {}
}
I think we should judge the legal function name instead of limiting it to letters, numbers and underscores next the '@' character
When the tsconfig
option is ignored, the current behaviour is to assume ./tsconfig.json
.
But for workspaces, it should in fact search for the closest parent directory with a package.json.
There are existing packages that do the job already,
Hello!
We used this plugin for our project, but It seems that the peer dependency of esbuild is very specific "esbuild": "~0.12.17"
. We upgraded to 0.14.25
and I'm wondering if you have any idea or we could tackle this? Did you test already this plugin with the latest version of esbuild
?
Thank you 😊
I install this package and I used typescript in global and when run show error:
Error: Cannot find module 'typescript'
when I install typescript in project this error gone
Hi, I've been trying to use your nx build executor and wanted to use your plugin for decorators.
The matter is that the executor only supports a json config which is not enough to import a plugin.
What do you think of a js / ts config file that would use a default export to provide an usable config ?
There is a problem when compiling files with generics on lambda-functions.
Example:
const fn = <T>(Dependency: Constructable<T>, hint?: string): T =>
ensureInjector().get(Dependency, hint);
It transpiles to this:
const fn = React.createElement(
T,
null,
"(Dependency: Constructable",
React.createElement(
T,
null,
", hint?: string): T => ensureInjector().get(Dependency, hint); // function fn",
React.createElement(
T,
null,
"(Dependency: Constructable",
React.createElement(
T,
null,
", hint?: string): T ",
fn.reset = () => {
injector = void 0;
},
"; return fn; })();"
)
)
)
);
When changing the function to this it works:
function fn<T>(Dependency: Constructable<T>, hint?: string): T {
return ensureInjector().get(Dependency, hint);
}
Nx creates a project in the /tmp
directory to run e2e tests against.
There is a consistent issue with the monorepo requiring packages from one another failing to be found in the e2e testing.
Currently, creating a link from @anatine/esbuild-decorators
to the build directory of @anatine/esbuildnx
then removing it after the test. The E2E testing should properly find package dependencies that exist within the same mono repo.
Might be loosely related to: nrwl/nx#5065
Issue with Nx here: nrwl/nx#5639
Getting build errors (Error: ENOENT: no such file or directory, open /protos/app_engine_key.proto'. I have seen some discussions around this. Wondering if there is a workaround for this?
When I'm using the plugin I saw that the resulting sourcemaps are incorrect,
I'm opening this issue with a reproduction.
And I'll open a PR with a suggested fix 😄
https://stackblitz.com/edit/nestjs-typescript-starter-hrbgzh?file=dist/main.js.map
It should automatically run npm run build
.
Then go to dist/main.js.map
And you can see that in the sourceContent
instead of the decorator e.g.
@Controller()
it has the transpiled code:
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
For better collaboration set up:
With last version of esbuild this package ends with conflicts on installs
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.