-
Notifications
You must be signed in to change notification settings - Fork 0
substituir pipeline babel por tsx + esbuild (#91) #421
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
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| nodeLinker: node-modules |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { rmSync } from 'node:fs' | ||
| import { build } from 'esbuild' | ||
|
|
||
| // Limpa a pasta dist antes de gerar novo build | ||
| rmSync('dist', { recursive: true, force: true }) | ||
|
|
||
| await build({ | ||
| entryPoints: ['src/index.js'], | ||
| bundle: true, | ||
| platform: 'node', | ||
| target: 'node22', | ||
| outdir: 'dist', | ||
| format: 'esm', | ||
| // 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: [ | ||
| 'throttled-queue', | ||
| 'tedious', | ||
| 'pg-hstore', | ||
| 'pg-query-stream', | ||
| 'better-sqlite3', | ||
| 'sqlite3', | ||
| 'mysql', | ||
| 'oracledb', | ||
| ], | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,9 @@ | |
| "tsc:check": "tsc --noEmit", | ||
| "lint:eslint": "eslint --cache", | ||
| "lint": "run-p tsc:check lint:eslint", | ||
| "clean": "rimraf dist", | ||
| "build:app": "babel -d ./dist -x '.js,.ts,.tsx' --copy-files --no-copy-ignored ./src", | ||
| "start": "nodemon --ext 'js,ts,tsx' --exec babel-node --extensions '.js,.ts,.tsx' ./src/index.js", | ||
| "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", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uma vez que o script |
||
| "test": "vitest --run", | ||
| "test:coverage": "vitest --run --coverage", | ||
| "prepare": "husky", | ||
|
|
@@ -57,37 +56,28 @@ | |
| "swagger-jsdoc": "6.2.8", | ||
| "swagger-ui-express": "5.0.1", | ||
| "throttled-queue": "3.0.0", | ||
| "tsx": "4.20.6", | ||
| "uuid": "13.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/cli": "7.28.3", | ||
| "@babel/core": "7.28.5", | ||
| "@babel/node": "7.28.0", | ||
| "@babel/plugin-proposal-class-properties": "7.18.6", | ||
| "@babel/preset-env": "7.28.5", | ||
| "@babel/preset-react": "7.28.5", | ||
| "@babel/preset-typescript": "7.28.5", | ||
| "@eslint/js": "9.39.1", | ||
| "@stylistic/eslint-plugin": "5.5.0", | ||
| "@types/express": "5.0.5", | ||
| "@types/pg": "^8.16.0", | ||
| "@types/react": "19.2.2", | ||
| "@types/react-dom": "19.2.2", | ||
| "@vitest/coverage-v8": "4.0.7", | ||
| "babel-plugin-module-resolver": "5.0.2", | ||
| "chai": "6.2.0", | ||
| "chai-http": "^5.1.2", | ||
| "esbuild": "^0.28.0", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usar a versão exata, sem o |
||
| "eslint": "9.39.1", | ||
| "eslint-plugin-import-helpers": "2.0.1", | ||
| "globals": "16.5.0", | ||
| "husky": "9.1.7", | ||
| "jiti": "2.6.1", | ||
| "nodemon": "3.1.10", | ||
| "npm-run-all": "4.1.5", | ||
| "rimraf": "6.1.2", | ||
| "tsx": "^4.21.0", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por favor, usar a versão exata, sem o |
||
| "typescript": "5.9.3", | ||
| "typescript-eslint": "8.46.3", | ||
| "vitest": "4.0.7" | ||
| } | ||
| }, | ||
| "packageManager": "yarn@4.13.0+sha512.5c20ba010c99815433e5c8453112165e673f1c7948d8d2b267f4b5e52097538658388ebc9f9580656d9b75c5cc996f990f611f99304a2197d4c56d21eea370e7" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por que você mudou a versão do yarn? Não é necessário para migração do babel. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,6 @@ import models from '../models'; | |
| import codigos from '../resources/codigos-http'; | ||
| import verifyRecaptcha from '../utils/verify-recaptcha'; | ||
| import { aprovarPendencia } from './pendencias-controller'; | ||
|
|
||
| const { | ||
| Solo, Relevo, Cidade, Estado, Vegetacao, FaseSucessional, Pais, Tipo, LocalColeta, Familia, sequelize, | ||
| Genero, Subfamilia, Autor, Coletor, Variedade, Subespecie, TomboFoto, Identificador, | ||
|
|
@@ -35,6 +34,27 @@ function parseDataTombo(valor) { | |
| return null; | ||
| } | ||
|
|
||
| const getProximoNumeroTombo = () => { | ||
| return Tombo.findOne({ | ||
| attributes: [ | ||
| [fn('MAX', col('hcf')), 'max_hcf'], | ||
| ], | ||
| raw: true, | ||
| }) | ||
| .then(resultado => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fazer o uso de async/await ao invés de .then. |
||
| const maxNumero = resultado?.max_hcf; | ||
| return maxNumero ? Number(maxNumero) + 1 : 1; | ||
| }); | ||
| }; | ||
|
|
||
| export const getProximoNumeroTomboEndPoint = (request, response, next) => { | ||
| getProximoNumeroTombo() | ||
| .then(proximoNumero => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fazer o uso de |
||
| response.status(codigos.BUSCAR_UM_ITEM).json({ hcf: proximoNumero }); | ||
| }) | ||
| .catch(next); | ||
| }; | ||
|
|
||
| export const cadastro = (request, response, next) => { | ||
| const { | ||
| principal, | ||
|
|
@@ -51,8 +71,22 @@ export const cadastro = (request, response, next) => { | |
| } = request.body.json; | ||
| let tomboCriado = null; | ||
|
|
||
| const isNovoTombo = !principal.hcf; | ||
|
|
||
| const callback = transaction => | ||
| Promise.resolve() | ||
| .then(() => { | ||
| if (isNovoTombo) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| return getProximoNumeroTombo(); | ||
| } | ||
| return principal.hcf; | ||
| }) | ||
| .then(hcfGerado => { | ||
| if (isNovoTombo) { | ||
| principal.hcf = hcfGerado; | ||
| } | ||
| return undefined; | ||
| }) | ||
| .then(() => { | ||
| if (!paisagem || !paisagem.solo_id) { | ||
| return undefined; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { Knex } from 'knex' | ||
| import fs from 'node:fs' | ||
| import path from 'node:path' | ||
| import { pathToFileURL } from 'node:url' | ||
|
|
||
| interface Dependencies { | ||
| knex: Knex | ||
|
|
@@ -30,6 +31,7 @@ export class MigrationFileSystem { | |
| const fileName = `${timestamp}_${name}` | ||
|
|
||
| const upFilePath = path.join(this.migrationsPath, `${fileName}.ts`) | ||
| .replace(/\\/g, '/') | ||
|
|
||
| fs.writeFileSync(upFilePath, MIGRATION_TEMPLATE) | ||
|
|
||
|
|
@@ -41,17 +43,25 @@ export class MigrationFileSystem { | |
| return files | ||
| .filter(file => /\.[jt]s$/.test(file)) | ||
| .sort() | ||
| .map(file => path.join(this.migrationsPath, file)) | ||
| .map(file => path.join(this.migrationsPath, file).replace(/\\/g, '/')) | ||
| } | ||
|
|
||
| private async importMigrationModule(name: string): Promise<{ run: (knex: Knex) => Promise<void> }> { | ||
| const filePathWithoutExtension = path.join(this.migrationsPath, name) | ||
| const isAbsolute = path.isAbsolute(this.migrationsPath) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Qual problema existia aqui? Por que foi necessário esta alteração? |
||
|
|
||
| const toSpecifier = (fsPath: string): string => { | ||
| if (isAbsolute) { | ||
| return pathToFileURL(fsPath).href | ||
| } | ||
| return fsPath.replace(/\\/g, '/') | ||
| } | ||
|
|
||
| let migrationModule: { run: (knex: Knex) => Promise<void> } | ||
| if (fs.existsSync(`${filePathWithoutExtension}.ts`)) { | ||
| migrationModule = await import(`${filePathWithoutExtension}.ts`) as { run: (knex: Knex) => Promise<void> } | ||
| migrationModule = await import(toSpecifier(`${filePathWithoutExtension}.ts`)) as { run: (knex: Knex) => Promise<void> } | ||
| } else if (fs.existsSync(`${filePathWithoutExtension}.js`)) { | ||
| migrationModule = await import(`${filePathWithoutExtension}.js`) as { run: (knex: Knex) => Promise<void> } | ||
| migrationModule = await import(toSpecifier(`${filePathWithoutExtension}.js`)) as { run: (knex: Knex) => Promise<void> } | ||
| } else { | ||
| throw new Error(`Migration file ${name} not found`) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { | |
| alteracao, getNumeroColetor, getUltimoNumeroTombo, getCodigoBarraTombo, | ||
| editarCodigoBarra, getUltimoNumeroCodigoBarras, postCodigoBarraTombo, | ||
| verificarCoordenada, getUltimoCodigoBarra, deletarCodigoBarras, listagemTombosPorIdentificador, | ||
| relatorioPorPeriodo, | ||
| relatorioPorPeriodo, getProximoNumeroTomboEndPoint, | ||
| } from '../controllers/tombos-controller'; | ||
| import exportarTombosController from '../controllers/tombos-exportacoes-controller'; | ||
| import criaJsonMiddleware from '../middlewares/json-middleware'; | ||
|
|
@@ -21,6 +21,7 @@ import coletorCadastro from '../validators/coletor-cadastro'; | |
| import cadastrarTipoEsquema from '../validators/tipo-cadastro'; | ||
| import cadastrarTomboEsquema from '../validators/tombo-cadastro'; | ||
| import listagemTombo from '../validators/tombo-listagem'; | ||
|
|
||
| /** | ||
| * @swagger | ||
| * tags: | ||
|
|
@@ -355,6 +356,11 @@ export default app => { | |
| getUltimoNumeroTombo, | ||
| ]); | ||
|
|
||
| app.route('/tombos/proximo_numero') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esta rota precisa de autenticação. |
||
| .get([ | ||
| getProximoNumeroTomboEndPoint, | ||
| ]); | ||
|
|
||
| /** | ||
| * @swagger | ||
| * /tombos/ultimo_codigo_barra: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ | |
| "include": [ | ||
| "src/", | ||
| "test/", | ||
| "eslint.config.mts", | ||
| "eslint.config.mjs", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por que mudar de |
||
| "vitest.config.mts" | ||
| ], | ||
| "exclude": [ | ||
|
|
||
There was a problem hiding this comment.
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
bundlecomofalse, e o esbuild vai se comportar semelhante aobabel, fazendo a compilação dos arquivos somente, sem a necessidade de configurar as bibliotecas externas.