diff --git a/src/DeclarationIndex.ts b/src/DeclarationIndex.ts index ca16a03..9a94afa 100644 --- a/src/DeclarationIndex.ts +++ b/src/DeclarationIndex.ts @@ -383,7 +383,7 @@ export class DeclarationIndex { if (!index[declaration.name]) { index[declaration.name] = []; } - const from = key.replace(/[/]?index$/, '') || '/'; + const from = key.replace(/\/index$/, '') || '/'; if (!index[declaration.name].some( o => o.declaration.constructor === declaration.constructor && o.from === from, )) { diff --git a/test/_workspace/declaration-index/_index.ts b/test/_workspace/declaration-index/_index.ts new file mode 100644 index 0000000..c5eec96 --- /dev/null +++ b/test/_workspace/declaration-index/_index.ts @@ -0,0 +1 @@ +export let _index; diff --git a/test/_workspace/declaration-index/index.ts b/test/_workspace/declaration-index/index.ts new file mode 100644 index 0000000..4d8b863 --- /dev/null +++ b/test/_workspace/declaration-index/index.ts @@ -0,0 +1 @@ +export let barrelExport; diff --git a/test/declaration-index/DeclarationIndex.spec.ts b/test/declaration-index/DeclarationIndex.spec.ts index 069665e..eafa7dc 100644 --- a/test/declaration-index/DeclarationIndex.spec.ts +++ b/test/declaration-index/DeclarationIndex.spec.ts @@ -40,6 +40,8 @@ describe('DeclarationIndex', () => { join(rootPath, 'helper-functions.ts'), join(rootPath, 'myReactTemplate.tsx'), join(rootPath, 'prototype-funcs.ts'), + join(rootPath, 'index.ts'), + join(rootPath, '_index.ts'), ]; beforeEach(async () => { @@ -84,6 +86,14 @@ describe('DeclarationIndex', () => { expect(resource).toMatchSnapshot(); }); + it('should properly index non-barrel files ending in `index`', () => { + const barrelExport = declarationIndex.index!['barrelExport']; + expect(barrelExport).toMatchSnapshot(); + + const _index = declarationIndex.index!['_index']; + expect(_index).toMatchSnapshot(); + }); + }); describe('reindexForChanges()', () => { @@ -183,7 +193,7 @@ describe('DeclarationIndex', () => { export class FancierLibraryClass { public doSomethingAwesome(): void { } } - + export * from './foobar'`, }); @@ -265,7 +275,7 @@ describe('DeclarationIndex', () => { export class FancierLibraryClass { public doSomethingAwesome(): void { } } - + export * from './foobar'`, }); @@ -290,7 +300,7 @@ describe('DeclarationIndex', () => { export class FancierLibraryClass { public doSomethingAwesome(): void { } } - + export * from './foobar'`, }); diff --git a/test/declaration-index/__snapshots__/DeclarationIndex.spec.ts.snap b/test/declaration-index/__snapshots__/DeclarationIndex.spec.ts.snap index a2c99fe..d3ba399 100644 --- a/test/declaration-index/__snapshots__/DeclarationIndex.spec.ts.snap +++ b/test/declaration-index/__snapshots__/DeclarationIndex.spec.ts.snap @@ -66,6 +66,8 @@ Array [ "/helper-functions", "/myReactTemplate", "/prototype-funcs", + "/index", + "/_index", ] `; @@ -127,6 +129,38 @@ Array [ ] `; +exports[`DeclarationIndex buildIndex() should properly index non-barrel files ending in \`index\` 1`] = ` +Array [ + DeclarationInfo { + "declaration": VariableDeclaration { + "end": 24, + "isConst": false, + "isExported": true, + "name": "barrelExport", + "start": 0, + "type": undefined, + }, + "from": "/", + }, +] +`; + +exports[`DeclarationIndex buildIndex() should properly index non-barrel files ending in \`index\` 2`] = ` +Array [ + DeclarationInfo { + "declaration": VariableDeclaration { + "end": 18, + "isConst": false, + "isExported": true, + "name": "_index", + "start": 0, + "type": undefined, + }, + "from": "/_index", + }, +] +`; + exports[`DeclarationIndex calculateIndexDelta() should calculate a newly added declaration 1`] = ` Object { "added": Object {