Skip to content

Commit 1a38a27

Browse files
committed
feat: enable eol by default and generated formatted output when no entities are found in scan
1 parent e9706e1 commit 1a38a27

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@
4949
"@japa/snapshot": "^2.0.9",
5050
"@poppinss/ts-exec": "^1.4.1",
5151
"@release-it/conventional-changelog": "^10.0.1",
52-
"@types/node": "^24.5.2",
52+
"@types/node": "^24.6.0",
5353
"@types/picomatch": "^4.0.2",
5454
"@types/pretty-hrtime": "^1.0.3",
5555
"c8": "^10.1.3",
56-
"cross-env": "^10.0.0",
56+
"cross-env": "^10.1.0",
5757
"del-cli": "^7.0.0",
5858
"eslint": "^9.36.0",
5959
"hot-hook": "^0.4.1-next.0",

src/index_generator/source.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class IndexGeneratorSource {
7979
* content based on configuration, and writes it to disk.
8080
*/
8181
#generateOutput = throttle(async () => {
82-
const buffer = new FileBuffer()
82+
const buffer = new FileBuffer().eol(true)
8383

8484
if (this.#config.as === 'barrelFile') {
8585
this.#asBarrelFile(
@@ -237,6 +237,11 @@ export class IndexGeneratorSource {
237237
return `() => import('${importGenerator(filePath)}')`
238238
},
239239
})
240+
const treeLength = Object.keys(tree).length
241+
if (!treeLength) {
242+
buffer.write(`export const ${exportName} = {}`)
243+
return
244+
}
240245

241246
if (useEagerImports) {
242247
buffer.writeLine(importsBuffer)

tests/index_generator.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ test.group('Index generator', () => {
258258
`)
259259
})
260260

261-
test('create index from without lazy imports', async ({ assert, fs }) => {
261+
test('create index without lazy imports', async ({ assert, fs }) => {
262262
const outputPath = '.adonisjs/backend/controllers.ts'
263263
const source = string.toUnixSlash(fs.basePath)
264264

@@ -298,4 +298,25 @@ test.group('Index generator', () => {
298298
}"
299299
`)
300300
})
301+
302+
test('create index when there is nothing to output', async ({ assert, fs }) => {
303+
const outputPath = '.adonisjs/backend/controllers.ts'
304+
const source = string.toUnixSlash(fs.basePath)
305+
306+
const transformer = new IndexGenerator(source, ui.logger)
307+
transformer.add('controllers', {
308+
as: 'barrelFile',
309+
disableLazyImports: true,
310+
exportName: 'controllers',
311+
output: outputPath,
312+
source: 'app/controllers',
313+
importAlias: '#controllers',
314+
})
315+
await transformer.generate()
316+
317+
assert.snapshot(await fs.contents(outputPath)).matchInline(`
318+
"export const controllers = {}
319+
"
320+
`)
321+
})
301322
})

0 commit comments

Comments
 (0)