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 committed Jun 29, 2020
1 parent 9666433 commit f8b3f81
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/lib/rules/files-property.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs';
import 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
7 changes: 7 additions & 0 deletions source/test/fixtures/files-folder/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "foo",
"files": [
"dist"
],
"types": "dist/index.d.ts"
}
8 changes: 8 additions & 0 deletions source/test/fixtures/files-glob/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "foo",
"files": [
"dist/**/*.d.ts",
"dist/**/*.js"
],
"types": "dist/index.d.ts"
}
12 changes: 12 additions & 0 deletions source/test/test.ts
Original file line number Diff line number Diff line change
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 f8b3f81

Please sign in to comment.