Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .babelrc

This file was deleted.

Binary file added .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ FROM node:jod-slim AS build

WORKDIR /usr/src/app

COPY package.json yarn.lock tsconfig.json .babelrc ./
COPY package.json yarn.lock tsconfig.json build.mjs ./

RUN yarn install --production=false
RUN yarn install --production=false

COPY ./src/ ./src/

Expand Down
18 changes: 18 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { rmSync } from 'node:fs'
import { globSync } from 'glob'
import { build } from 'esbuild'
import fs from 'node:fs'
import path from 'node:path'

rmSync('dist', { recursive: true, force: true }) // Limpa a pasta dist antes de gerar novo build

const entryPoints = globSync('src/**/*.{js,ts,tsx}') // Encontra todos os arquivos a serem transpilados

await build({
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.

@JosueModesto eu baixei seu branch local e encontrei alguns problemas:

  • Quando mudamos para bundle: false, o único arquivo transpilado foi o .index.js, o restente não. Acredito que o que você precisa fazer é passar o valor de entryPoints usando glob.
  • Você precisa lembrar que temos arquivos de vários tipos, por exemplo, .js e .ts, .ejs, .tsx e vários outros juntos, então precisamos transpilar todos eles, não somente arquivos .js.

Copy link
Copy Markdown
Contributor Author

@JosueModesto JosueModesto May 20, 2026

Choose a reason for hiding this comment

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

@edvaldoszy Eu fiz as mudanças subi o código porem ele esta dando erro e eu tentei consertar de várias formas mas não consegui, não sei o que faço, eu adicionei o valor do entryPoints com o glob pra .js,.ts e .tsx, com o .ejs o yarn build quebra, pelo o que o chat falou é o pq o esbuild é compilador de Java/TypeScript então ele não entende a sintaxe do .ejs, só que quando eu executo o docker compose up --build, ele não esta resolvendo as extensões, por estar com o bundle:false e esm, ele não resolve as extensões dos imports, e dai o build vai procurar os arquivos, ele procura por exemplo app e não app.js não encontra e quebra. E dai eu não sei o que fazer, já tentei fazer um plugin para ele adicionar as extensões mas não funcionou e eu realmente não sei o que fazer. Para ficar claro o docker compose up --build, ele builda tudo, quando vai subir o docker ele da este erro: Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/hcf_api/app/dist/app' imported from /home/hcf_api/app/dist/index.js

entryPoints,
bundle: false,
platform: 'node',
target: 'node22',
outdir: 'dist',
format: 'esm',
})
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
POSTGRES_USER: $PG_USERNAME
POSTGRES_PASSWORD: $PG_PASSWORD
volumes:
- postgres_data:/var/lib/postgresql/data
- postgres_data:/var/lib/postgresql
ports:
- ${PG_PORT:-5432}:5432
shm_size: 128mb
Expand Down
7 changes: 4 additions & 3 deletions eslint.config.mts → eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import js from '@eslint/js'
import stylistic from '@stylistic/eslint-plugin'
import type { ESLint } from 'eslint'
// @ts-expect-error: No declaration file found
import importHelpers from 'eslint-plugin-import-helpers'
import { defineConfig } from 'eslint/config'
Expand All @@ -14,7 +13,9 @@ export default defineConfig([
'mysql/',
'public/',
'coverage/',
'node_modules/'
'node_modules/',
'build.mjs',
'eslint.config.mjs',
]
},
{
Expand All @@ -23,7 +24,7 @@ export default defineConfig([
js,
stylistic,
tseslint,
'import-helpers': importHelpers as unknown as ESLint.Plugin
"import-helpers": importHelpers
},
languageOptions: {
parserOptions: {
Expand Down
21 changes: 5 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
"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",
"start": "tsx --watch --env-file=.env src/index.js",
"build": "node build.mjs",
"test": "vitest --run",
"test:coverage": "vitest --run --coverage",
"prepare": "husky",
Expand Down Expand Up @@ -57,35 +55,26 @@
"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",
"eslint": "9.39.1",
"eslint-plugin-import-helpers": "2.0.1",
"glob": "^10.3.10",
"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",
"typescript": "5.9.3",
"typescript-eslint": "8.46.3",
"vitest": "4.0.7"
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/tombos-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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,
ColecaoAnexa, Especie, Herbario, Tombo, Alteracao, TomboIdentificador, ColetorComplementar, Sequelize: { Op, fn, col },
ColecaoAnexa, Especie, Herbario, Tombo, Alteracao, TomboIdentificador, ColetorComplementar, Sequelize: { Op },
} = models;

function parseDataTombo(valor) {
Expand Down
16 changes: 13 additions & 3 deletions src/database/migration-file-system.ts
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
Expand Down Expand Up @@ -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)

Expand All @@ -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)
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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Por algum motivo que eu não sei explicar, ele estava reclamando que não conseguia encontrar o caminho para fazer as migrações devido a windows ser \ e não /, dai para rodar na minha máquina eu alterei.


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`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import './setup';
import './setup.js';
import cluster from 'cluster';
import http from 'http';
import os from 'os';
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"include": [
"src/",
"test/",
"eslint.config.mts",
"eslint.config.mjs",
Comment thread
JosueModesto marked this conversation as resolved.
"vitest.config.mts"
],
"exclude": [
Expand Down
Loading
Loading