Skip to content

substituir pipeline babel por tsx + esbuild (#91)#421

Open
JosueModesto wants to merge 1 commit intodevelopmentfrom
91-substituir-pipeline-babel-por-tsx-esbuild
Open

substituir pipeline babel por tsx + esbuild (#91)#421
JosueModesto wants to merge 1 commit intodevelopmentfrom
91-substituir-pipeline-babel-por-tsx-esbuild

Conversation

@JosueModesto
Copy link
Copy Markdown

O que foi feito

Substituição completa da pipeline Babel por tsx + esbuild, conforme issue #91.

Removido

  • @babel/cli, @babel/core, @babel/node, @babel/plugin-proposal-class-properties, @babel/preset-env, @babel/preset-react, @babel/preset-typescript
  • babel-plugin-module-resolver, jiti, nodemon
  • Arquivo .babelrc

Adicionado / Atualizado

  • esbuild adicionado em devDependencies
  • tsx movido de dependencies para devDependencies
  • Criado build.mjs: executa limpeza da pasta dist via rmSync e gera bundle com esbuild (elimina necessidade de rimraf e script clean)
  • Script start atualizado para tsx --watch --env-file=.env src/index.js
  • Script build:app atualizado para node build.mjs
  • eslint.config.mts renomeado para eslint.config.mjs (remove dependência de jiti no ESLint 9)

Validação

  • yarn build
  • yarn lint
  • yarn test 27/27

],
raw: true,
})
.then(resultado => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fazer o uso de async/await ao invés de .then.


export const getProximoNumeroTomboEndPoint = (request, response, next) => {
getProximoNumeroTombo()
.then(proximoNumero => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fazer o uso de async/await com try/catch ao invés de then/catch

const callback = transaction =>
Promise.resolve()
.then(() => {
if (isNovoTombo) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Esta lógica aqui não deveria existir, você deve aceitar o valor que o frontend está enviando, e não gerar outro aqui. O cálculo do próximo número acontece na outra rota e é devolvido para o frontend, o valor que é recebido na requisição deve ser usado para inserir o tombo.


private async importMigrationModule(name: string): Promise<{ run: (knex: Knex) => Promise<void> }> {
const filePathWithoutExtension = path.join(this.migrationsPath, name)
const isAbsolute = path.isAbsolute(this.migrationsPath)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Qual problema existia aqui? Por que foi necessário esta alteração?

Comment thread src/routes/tombos.js
getUltimoNumeroTombo,
]);

app.route('/tombos/proximo_numero')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Esta rota precisa de autenticação.

Comment thread tsconfig.json
"src/",
"test/",
"eslint.config.mts",
"eslint.config.mjs",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Por que mudar de .mts para .mjs?

Comment thread package.json
"nodemon": "3.1.10",
"npm-run-all": "4.1.5",
"rimraf": "6.1.2",
"tsx": "^4.21.0",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Por favor, usar a versão exata, sem o ^

Comment thread package.json
"babel-plugin-module-resolver": "5.0.2",
"chai": "6.2.0",
"chai-http": "^5.1.2",
"esbuild": "^0.28.0",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Usar a versão exata, sem o ^

Comment thread package.json
"build": "run-s clean build:app",
"build:app": "node build.mjs",
"start": "tsx --watch --env-file=.env src/index.js",
"build": "run-s build:app",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Uma vez que o script build só executa uma coisa, que nesse caso é executar build:app, você não precisa mais do build:app, você pode trazer o node build.mjs aqui para o script build

Comment thread build.mjs
// Prefere entrada CJS dos pacotes para evitar problemas de interop de default export
mainFields: ['main', 'module'],
// Dialetos opcionais do knex/sequelize não instalados no projeto
external: [
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ao invés de colocar dependencias como externas, você pode simplesmente colocar a configuração bundle como false, e o esbuild vai se comportar semelhante ao babel, fazendo a compilação dos arquivos somente, sem a necessidade de configurar as bibliotecas externas.

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.

2 participants