-
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
55cd826
055c400
1fcae1c
e1bad67
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,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({ | ||
| entryPoints, | ||
| bundle: false, | ||
| platform: 'node', | ||
| target: 'node22', | ||
| outdir: 'dist', | ||
| format: 'esm', | ||
| }) | ||
| 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?
Contributor
Author
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 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`) | ||
| } | ||
|
|
||
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.
@JosueModesto eu baixei seu branch local e encontrei alguns problemas:
bundle: false, o único arquivo transpilado foi o.index.js, o restente não. Acredito que o que você precisa fazer é passar o valor deentryPointsusando glob..jse.ts,.ejs,.tsxe vários outros juntos, então precisamos transpilar todos eles, não somente arquivos.js.Uh oh!
There was an error while loading. Please reload this page.
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.
@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