diff --git a/source/lib/rules/files-property.ts b/source/lib/rules/files-property.ts index c0e9f9fd..946a8984 100644 --- a/source/lib/rules/files-property.ts +++ b/source/lib/rules/files-property.ts @@ -1,5 +1,6 @@ import * as path from 'path'; import * as fs from 'fs'; +import * as globby from 'globby'; import {Context, Diagnostic} from '../interfaces'; import {getJSONPropertyPosition} from '../utils'; @@ -17,7 +18,7 @@ export default (context: Context): Diagnostic[] => { } const normalizedTypingsFile = path.normalize(typingsFile); - const normalizedFiles = (pkg.files as string[]).map(path.normalize); + const normalizedFiles = globby.sync(pkg.files as string[], {cwd: context.cwd}).map(path.normalize); if (normalizedFiles.includes(normalizedTypingsFile)) { return []; diff --git a/source/test/fixtures/files-folder/out/index.d.ts b/source/test/fixtures/files-folder/out/index.d.ts new file mode 100644 index 00000000..266914ab --- /dev/null +++ b/source/test/fixtures/files-folder/out/index.d.ts @@ -0,0 +1,6 @@ +declare const concat: { + (foo: string, bar: string): string; + (foo: number, bar: number): number; +}; + +export default concat; diff --git a/source/test/fixtures/files-folder/out/index.js b/source/test/fixtures/files-folder/out/index.js new file mode 100644 index 00000000..f17717f5 --- /dev/null +++ b/source/test/fixtures/files-folder/out/index.js @@ -0,0 +1,3 @@ +module.exports.default = (foo, bar) => { + return foo + bar; +}; diff --git a/source/test/fixtures/files-folder/out/index.test-d.ts b/source/test/fixtures/files-folder/out/index.test-d.ts new file mode 100644 index 00000000..66ad1b38 --- /dev/null +++ b/source/test/fixtures/files-folder/out/index.test-d.ts @@ -0,0 +1,5 @@ +import {expectType} from '../../../..'; +import concat from '.'; + +expectType(concat('foo', 'bar')); +expectType(concat(1, 2)); diff --git a/source/test/fixtures/files-folder/package.json b/source/test/fixtures/files-folder/package.json new file mode 100644 index 00000000..8c8701df --- /dev/null +++ b/source/test/fixtures/files-folder/package.json @@ -0,0 +1,7 @@ +{ + "name": "foo", + "files": [ + "out" + ], + "types": "out/index.d.ts" +} diff --git a/source/test/fixtures/files-glob/out/index.d.ts b/source/test/fixtures/files-glob/out/index.d.ts new file mode 100644 index 00000000..266914ab --- /dev/null +++ b/source/test/fixtures/files-glob/out/index.d.ts @@ -0,0 +1,6 @@ +declare const concat: { + (foo: string, bar: string): string; + (foo: number, bar: number): number; +}; + +export default concat; diff --git a/source/test/fixtures/files-glob/out/index.js b/source/test/fixtures/files-glob/out/index.js new file mode 100644 index 00000000..f17717f5 --- /dev/null +++ b/source/test/fixtures/files-glob/out/index.js @@ -0,0 +1,3 @@ +module.exports.default = (foo, bar) => { + return foo + bar; +}; diff --git a/source/test/fixtures/files-glob/out/index.test-d.ts b/source/test/fixtures/files-glob/out/index.test-d.ts new file mode 100644 index 00000000..66ad1b38 --- /dev/null +++ b/source/test/fixtures/files-glob/out/index.test-d.ts @@ -0,0 +1,5 @@ +import {expectType} from '../../../..'; +import concat from '.'; + +expectType(concat('foo', 'bar')); +expectType(concat(1, 2)); diff --git a/source/test/fixtures/files-glob/package.json b/source/test/fixtures/files-glob/package.json new file mode 100644 index 00000000..f2d92f28 --- /dev/null +++ b/source/test/fixtures/files-glob/package.json @@ -0,0 +1,8 @@ +{ + "name": "foo", + "files": [ + "out/**/*.d.ts", + "out/**/*.js" + ], + "types": "out/index.d.ts" +} diff --git a/source/test/test.ts b/source/test/test.ts index ebe99335..2e9af6b7 100644 --- a/source/test/test.ts +++ b/source/test/test.ts @@ -36,6 +36,18 @@ test('fail if typings file is not part of `files` list', async t => { ]); }); +test('allow specifying folders containing typings file in `files` list', async t => { + const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/files-folder')}); + + verify(t, diagnostics, []); +}); + +test('allow specifying glob patterns containing typings file in `files` list', async t => { + const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/files-glob')}); + + verify(t, diagnostics, []); +}); + test('fail if `typings` property is used instead of `types`', async t => { const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/types-property/typings')});