Skip to content

Commit

Permalink
Add support for globbing patterns in files property - fixes #69 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lusito authored and SamVerschueren committed Jun 29, 2020
1 parent 9666433 commit 56b90ab
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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';

Expand All @@ -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 [];
Expand Down
6 changes: 6 additions & 0 deletions 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;
3 changes: 3 additions & 0 deletions source/test/fixtures/files-folder/out/index.js
@@ -0,0 +1,3 @@
module.exports.default = (foo, bar) => {
return foo + bar;
};
5 changes: 5 additions & 0 deletions source/test/fixtures/files-folder/out/index.test-d.ts
@@ -0,0 +1,5 @@
import {expectType} from '../../../..';
import concat from '.';

expectType<string>(concat('foo', 'bar'));
expectType<number>(concat(1, 2));
7 changes: 7 additions & 0 deletions source/test/fixtures/files-folder/package.json
@@ -0,0 +1,7 @@
{
"name": "foo",
"files": [
"out"
],
"types": "out/index.d.ts"
}
6 changes: 6 additions & 0 deletions 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;
3 changes: 3 additions & 0 deletions source/test/fixtures/files-glob/out/index.js
@@ -0,0 +1,3 @@
module.exports.default = (foo, bar) => {
return foo + bar;
};
5 changes: 5 additions & 0 deletions source/test/fixtures/files-glob/out/index.test-d.ts
@@ -0,0 +1,5 @@
import {expectType} from '../../../..';
import concat from '.';

expectType<string>(concat('foo', 'bar'));
expectType<number>(concat(1, 2));
8 changes: 8 additions & 0 deletions source/test/fixtures/files-glob/package.json
@@ -0,0 +1,8 @@
{
"name": "foo",
"files": [
"out/**/*.d.ts",
"out/**/*.js"
],
"types": "out/index.d.ts"
}
12 changes: 12 additions & 0 deletions source/test/test.ts
Expand Up @@ -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')});

Expand Down

0 comments on commit 56b90ab

Please sign in to comment.