Skip to content
Merged
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
17 changes: 16 additions & 1 deletion fontes/interface-linha-comando/novo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export async function detectarGerenciadorDePacotes(
gerenciadorDePacotes: string,
diretorioProjeto: string
) {
const caminhoPackageJson = caminho.join(diretorioProjeto, 'package.json');

switch (gerenciadorDePacotes) {
case 'npm': {
execSync('npm init -y', { cwd: diretorioProjeto });
Expand All @@ -113,7 +115,20 @@ export async function detectarGerenciadorDePacotes(
break;
}
case 'bun': {
execSync('bun init -y', { cwd: diretorioProjeto });
if (!sistemaArquivos.existsSync(caminhoPackageJson)) {
const conteudoPackageJson = {
name: caminho.basename(diretorioProjeto),
version: '1.0.0',
private: true,
dependencies: {}
};

await sistemaArquivos.promises.writeFile(
caminhoPackageJson,
JSON.stringify(conteudoPackageJson, null, 2) + '\n'
);
}

execSync('bun add liquido@latest', { cwd: diretorioProjeto });
break;
}
Expand Down
64 changes: 64 additions & 0 deletions testes/liquido.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,70 @@ describe('Liquido', () => {
);

});

it('Deve inicializar projeto com Bun sem criar arquivos desnecessários', async () => {
jest.clearAllMocks();
const caminhoDiretorioBun = caminho.join(
process.cwd(),
'teste-comando-novo-bun'
);

(ChildProcess.execSync as jest.Mock).mockImplementation(
() => Buffer.from('')
);

await sistemaArquivos.promises.rm(
caminhoDiretorioBun,
{ recursive: true, force: true }
);
await sistemaArquivos.promises.mkdir(caminhoDiretorioBun);

try {
await detectarGerenciadorDePacotes(
'bun',
caminhoDiretorioBun
);

const conteudoPackageJson = JSON.parse(
await sistemaArquivos.promises.readFile(
`${caminhoDiretorioBun}/package.json`,
'utf-8'
)
);

expect(ChildProcess.execSync).not.toHaveBeenCalledWith(
'bun init -y',
{ cwd: caminhoDiretorioBun }
);
expect(ChildProcess.execSync).toHaveBeenCalledWith(
'bun add liquido@latest',
{ cwd: caminhoDiretorioBun }
);
expect(conteudoPackageJson).toMatchObject({
name: 'teste-comando-novo-bun',
version: '1.0.0',
private: true,
dependencies: {}
});
expect(conteudoPackageJson).not.toHaveProperty(
'peerDependencies.typescript'
);
expect(
sistemaArquivos.existsSync(`${caminhoDiretorioBun}/tsconfig.json`)
).toBeFalsy();
expect(
sistemaArquivos.existsSync(`${caminhoDiretorioBun}/index.ts`)
).toBeFalsy();
expect(
sistemaArquivos.existsSync(`${caminhoDiretorioBun}/README.md`)
).toBeFalsy();
} finally {
await sistemaArquivos.promises.rm(
caminhoDiretorioBun,
{ recursive: true, force: true }
);
}
});


it('Deve usar o nome da pasta quando o nome do projeto é criado com "." ou "./"', async () => {
Expand Down
Loading