|
| 1 | +# 📁 Configuração de Arquivos - NFE.io SDK v3 |
| 2 | + |
| 3 | +Este documento descreve a configuração de arquivos de controle do projeto para o SDK v3. |
| 4 | + |
| 5 | +## 📋 Arquivos de Configuração |
| 6 | + |
| 7 | +### `.gitignore` |
| 8 | +**Propósito**: Define quais arquivos/diretórios o Git deve ignorar. |
| 9 | + |
| 10 | +**Principais exclusões**: |
| 11 | +- ✅ `node_modules/` - Dependências (instaladas via npm) |
| 12 | +- ✅ `dist/` - Código compilado (gerado pelo build) |
| 13 | +- ✅ `coverage/` - Relatórios de cobertura de testes |
| 14 | +- ✅ `*.tgz` - Pacotes NPM gerados |
| 15 | +- ✅ `.env*` - Variáveis de ambiente |
| 16 | +- ✅ IDE configs - `.vscode/`, `.idea/`, `*.iml` |
| 17 | +- ✅ OS files - `.DS_Store`, `Thumbs.db` |
| 18 | +- ✅ Logs - `*.log`, `npm-debug.log*` |
| 19 | + |
| 20 | +**O que é versionado**: |
| 21 | +- ✅ `src/` - Código-fonte TypeScript |
| 22 | +- ✅ `tests/` - Testes |
| 23 | +- ✅ Arquivos de configuração (`.eslintrc.cjs`, `tsconfig.json`, etc) |
| 24 | +- ✅ Documentação (`README.md`, `CHANGELOG.md`, etc) |
| 25 | +- ✅ Scripts (`scripts/`) |
| 26 | + |
| 27 | +### `.npmignore` |
| 28 | +**Propósito**: Define o que **não** será publicado no NPM. |
| 29 | + |
| 30 | +**Excluído do pacote NPM**: |
| 31 | +- ❌ `src/` - Código-fonte (publicamos apenas `dist/`) |
| 32 | +- ❌ `tests/` - Testes unitários |
| 33 | +- ❌ `examples/` - Exemplos de código |
| 34 | +- ❌ `scripts/` - Scripts de desenvolvimento |
| 35 | +- ❌ Configs de desenvolvimento (`.eslintrc`, `tsconfig.json`, etc) |
| 36 | +- ❌ Documentação interna (`AGENTS.md`, `CONTRIBUTING.md`, etc) |
| 37 | +- ❌ CI/CD configs (`.github/`, `.travis.yml`) |
| 38 | +- ❌ Arquivos legados (`lib/`, `VERSION`, `CHANGELOG` sem extensão) |
| 39 | + |
| 40 | +**Incluído no pacote NPM** (via `package.json` "files"): |
| 41 | +- ✅ `dist/` - Código compilado (ESM + CommonJS + Types) |
| 42 | +- ✅ `README.md` - Documentação principal |
| 43 | +- ✅ `CHANGELOG.md` - Histórico de versões |
| 44 | +- ✅ `MIGRATION.md` - Guia de migração v2→v3 |
| 45 | +- ✅ `package.json` - Metadados do pacote |
| 46 | +- ✅ `LICENSE` (se presente) |
| 47 | + |
| 48 | +### `.gitattributes` |
| 49 | +**Propósito**: Controla como o Git trata diferentes tipos de arquivo. |
| 50 | + |
| 51 | +**Configurações**: |
| 52 | +- ✅ **Line endings**: LF para código (`*.ts`, `*.js`, `*.json`) |
| 53 | +- ✅ **PowerShell**: CRLF para `*.ps1` (Windows) |
| 54 | +- ✅ **Diff patterns**: TypeScript, JavaScript, JSON, Markdown |
| 55 | +- ✅ **Binary files**: Imagens, fontes, arquivos compactados |
| 56 | +- ✅ **Export-ignore**: Arquivos de dev não incluídos em archives |
| 57 | +- ✅ **Merge strategies**: `package-lock.json` usa merge=ours |
| 58 | + |
| 59 | +### `.editorconfig` |
| 60 | +**Propósito**: Mantém estilo de código consistente entre editores. |
| 61 | + |
| 62 | +**Configurações**: |
| 63 | +- ✅ **Charset**: UTF-8 |
| 64 | +- ✅ **Indentação**: 2 espaços (TypeScript, JavaScript, JSON) |
| 65 | +- ✅ **Line endings**: LF (exceto PowerShell = CRLF) |
| 66 | +- ✅ **Trim trailing whitespace**: Sim |
| 67 | +- ✅ **Insert final newline**: Sim |
| 68 | +- ✅ **Max line length**: 100 (TypeScript/JavaScript) |
| 69 | + |
| 70 | +### `package.json` - Campo "files" |
| 71 | +**Propósito**: Lista explícita de arquivos/diretórios publicados no NPM. |
| 72 | + |
| 73 | +```json |
| 74 | +{ |
| 75 | + "files": [ |
| 76 | + "dist", // Código compilado |
| 77 | + "README.md", // Documentação |
| 78 | + "CHANGELOG.md", // Release notes |
| 79 | + "MIGRATION.md" // Guia v2→v3 |
| 80 | + ] |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +## 📊 Tamanho do Pacote NPM |
| 85 | + |
| 86 | +``` |
| 87 | +Arquivo Tamanho |
| 88 | +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 89 | +dist/index.js 70.5 KB (ESM) |
| 90 | +dist/index.cjs 72.2 KB (CommonJS) |
| 91 | +dist/index.d.ts 50.9 KB (TypeScript types) |
| 92 | +dist/*.map 286.3 KB (Source maps) |
| 93 | +README.md 13.0 KB |
| 94 | +CHANGELOG.md 5.5 KB |
| 95 | +MIGRATION.md 15.2 KB |
| 96 | +package.json 2.2 KB |
| 97 | +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
| 98 | +Total (tarball) 109.4 KB |
| 99 | +Total (unpacked) 566.5 KB |
| 100 | +``` |
| 101 | + |
| 102 | +## ✅ Validação |
| 103 | + |
| 104 | +### Verificar o que será publicado no NPM |
| 105 | +```bash |
| 106 | +npm pack --dry-run |
| 107 | +``` |
| 108 | + |
| 109 | +### Testar instalação local |
| 110 | +```bash |
| 111 | +# 1. Criar tarball |
| 112 | +npm pack |
| 113 | + |
| 114 | +# 2. Instalar em projeto teste |
| 115 | +cd ../test-project |
| 116 | +npm install ../client-nodejs/nfe-io-sdk-3.0.0.tgz |
| 117 | + |
| 118 | +# 3. Verificar imports |
| 119 | +node --input-type=module --eval "import { NfeClient } from '@nfe-io/sdk'; console.log('OK');" |
| 120 | +``` |
| 121 | + |
| 122 | +### Verificar arquivos ignorados pelo Git |
| 123 | +```bash |
| 124 | +git status --ignored |
| 125 | +``` |
| 126 | + |
| 127 | +## 🎯 Comparação v2 vs v3 |
| 128 | + |
| 129 | +| Aspecto | v2 (Legado) | v3 (Atual) | |
| 130 | +|---------|-------------|------------| |
| 131 | +| **Código publicado** | `lib/*.js` | `dist/*.{js,cjs,d.ts}` | |
| 132 | +| **Line endings** | Inconsistente | LF (via .gitattributes) | |
| 133 | +| **Indentação** | Mista | 2 espaços (via .editorconfig) | |
| 134 | +| **Docs incluídas** | README | README + CHANGELOG + MIGRATION | |
| 135 | +| **Source maps** | ❌ Não | ✅ Sim (.map files) | |
| 136 | +| **TypeScript types** | ❌ Não | ✅ Sim (.d.ts files) | |
| 137 | +| **Dual package** | ❌ Não | ✅ ESM + CommonJS | |
| 138 | +| **Tamanho tarball** | ~50 KB | 109 KB (+docs +types) | |
| 139 | + |
| 140 | +## 🔍 Troubleshooting |
| 141 | + |
| 142 | +### Arquivo não ignorado pelo Git |
| 143 | +```bash |
| 144 | +# Remover arquivo do cache do Git |
| 145 | +git rm --cached path/to/file |
| 146 | + |
| 147 | +# Re-adicionar respeitando .gitignore |
| 148 | +git add . |
| 149 | +``` |
| 150 | + |
| 151 | +### Arquivo indesejado no pacote NPM |
| 152 | +1. Verificar `.npmignore` |
| 153 | +2. Verificar campo `"files"` no `package.json` |
| 154 | +3. Testar: `npm pack --dry-run` |
| 155 | + |
| 156 | +### Line endings incorretos |
| 157 | +```bash |
| 158 | +# Re-normalizar todos os arquivos |
| 159 | +git add --renormalize . |
| 160 | +git commit -m "Normalize line endings" |
| 161 | +``` |
| 162 | + |
| 163 | +### EditorConfig não funcionando |
| 164 | +- Instalar plugin EditorConfig no seu editor |
| 165 | +- VSCode: `EditorConfig for VS Code` |
| 166 | +- JetBrains: Built-in |
| 167 | +- Vim: `editorconfig-vim` |
| 168 | + |
| 169 | +## 📚 Referências |
| 170 | + |
| 171 | +- **Git**: https://git-scm.com/docs/gitignore |
| 172 | +- **NPM**: https://docs.npmjs.com/cli/v9/using-npm/developers#keeping-files-out-of-your-package |
| 173 | +- **EditorConfig**: https://editorconfig.org/ |
| 174 | +- **Git Attributes**: https://git-scm.com/docs/gitattributes |
| 175 | + |
| 176 | +--- |
| 177 | + |
| 178 | +**Última atualização**: 2025-11-12 |
| 179 | +**Versão**: 3.0.0 |
0 commit comments