Skip to content

Commit 56b90ab

Browse files
LusitoSamVerschueren
authored andcommitted
Add support for globbing patterns in files property - fixes #69 (#70)
1 parent 9666433 commit 56b90ab

File tree

10 files changed

+57
-1
lines changed

10 files changed

+57
-1
lines changed

source/lib/rules/files-property.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from 'path';
22
import * as fs from 'fs';
3+
import * as globby from 'globby';
34
import {Context, Diagnostic} from '../interfaces';
45
import {getJSONPropertyPosition} from '../utils';
56

@@ -17,7 +18,7 @@ export default (context: Context): Diagnostic[] => {
1718
}
1819

1920
const normalizedTypingsFile = path.normalize(typingsFile);
20-
const normalizedFiles = (pkg.files as string[]).map(path.normalize);
21+
const normalizedFiles = globby.sync(pkg.files as string[], {cwd: context.cwd}).map(path.normalize);
2122

2223
if (normalizedFiles.includes(normalizedTypingsFile)) {
2324
return [];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare const concat: {
2+
(foo: string, bar: string): string;
3+
(foo: number, bar: number): number;
4+
};
5+
6+
export default concat;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports.default = (foo, bar) => {
2+
return foo + bar;
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {expectType} from '../../../..';
2+
import concat from '.';
3+
4+
expectType<string>(concat('foo', 'bar'));
5+
expectType<number>(concat(1, 2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "foo",
3+
"files": [
4+
"out"
5+
],
6+
"types": "out/index.d.ts"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare const concat: {
2+
(foo: string, bar: string): string;
3+
(foo: number, bar: number): number;
4+
};
5+
6+
export default concat;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports.default = (foo, bar) => {
2+
return foo + bar;
3+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {expectType} from '../../../..';
2+
import concat from '.';
3+
4+
expectType<string>(concat('foo', 'bar'));
5+
expectType<number>(concat(1, 2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "foo",
3+
"files": [
4+
"out/**/*.d.ts",
5+
"out/**/*.js"
6+
],
7+
"types": "out/index.d.ts"
8+
}

source/test/test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ test('fail if typings file is not part of `files` list', async t => {
3636
]);
3737
});
3838

39+
test('allow specifying folders containing typings file in `files` list', async t => {
40+
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/files-folder')});
41+
42+
verify(t, diagnostics, []);
43+
});
44+
45+
test('allow specifying glob patterns containing typings file in `files` list', async t => {
46+
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/files-glob')});
47+
48+
verify(t, diagnostics, []);
49+
});
50+
3951
test('fail if `typings` property is used instead of `types`', async t => {
4052
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/types-property/typings')});
4153

0 commit comments

Comments
 (0)