|
5 | 5 |
|
6 | 6 | import * as fs from 'fs-extra';
|
7 | 7 | import * as glob from 'glob';
|
| 8 | +import * as minimatch from 'minimatch'; |
8 | 9 | import * as path from 'path';
|
9 | 10 | import * as prettier from 'prettier';
|
10 | 11 | import * as ts from 'typescript';
|
@@ -438,6 +439,58 @@ export async function ensurePackage(
|
438 | 439 | }
|
439 | 440 | }
|
440 | 441 |
|
| 442 | + // Ensure style and lib are included in files metadata. |
| 443 | + const filePatterns: string[] = data.files || []; |
| 444 | + |
| 445 | + // Function to get all of the files in a directory, recursively. |
| 446 | + function recurseDir(dirname: string, files: string[]) { |
| 447 | + if (!fs.existsSync(dirname)) { |
| 448 | + return files; |
| 449 | + } |
| 450 | + fs.readdirSync(dirname).forEach(fpath => { |
| 451 | + const absolute = path.join(dirname, fpath); |
| 452 | + if (fs.statSync(absolute).isDirectory()) |
| 453 | + return recurseDir(absolute, files); |
| 454 | + else return files.push(absolute); |
| 455 | + }); |
| 456 | + return files; |
| 457 | + } |
| 458 | + |
| 459 | + // Ensure style files are included by pattern. |
| 460 | + const styleFiles = recurseDir(path.join(pkgPath, 'style'), []); |
| 461 | + styleFiles.forEach(fpath => { |
| 462 | + const basePath = fpath.slice(pkgPath.length + 1); |
| 463 | + let found = false; |
| 464 | + filePatterns.forEach(fpattern => { |
| 465 | + if (minimatch.default(basePath, fpattern)) { |
| 466 | + found = true; |
| 467 | + } |
| 468 | + }); |
| 469 | + if (!found) { |
| 470 | + messages.push(`File ${basePath} not included in files`); |
| 471 | + } |
| 472 | + }); |
| 473 | + |
| 474 | + // Ensure source TS files are included in lib (.js, .js.map, .d.ts) |
| 475 | + const srcFiles = recurseDir(path.join(pkgPath, 'src'), []); |
| 476 | + srcFiles.forEach(fpath => { |
| 477 | + const basePath = fpath.slice(pkgPath.length + 1).replace('src', 'lib'); |
| 478 | + ['.js', '.js.map', '.d.ts'].forEach(ending => { |
| 479 | + let found = false; |
| 480 | + const targetPattern = basePath |
| 481 | + .replace('.tsx', ending) |
| 482 | + .replace('.ts', ending); |
| 483 | + filePatterns.forEach(fpattern => { |
| 484 | + if (minimatch.default(targetPattern, fpattern)) { |
| 485 | + found = true; |
| 486 | + } |
| 487 | + }); |
| 488 | + if (!found) { |
| 489 | + messages.push(`File ${targetPattern} not included in files`); |
| 490 | + } |
| 491 | + }); |
| 492 | + }); |
| 493 | + |
441 | 494 | // Ensure dependencies and dev dependencies.
|
442 | 495 | data.dependencies = deps;
|
443 | 496 | data.devDependencies = devDeps;
|
|
0 commit comments