Skip to content

Commit

Permalink
feat: ✨ implement npm package files using blacklist way (#426)
Browse files Browse the repository at this point in the history
Co-authored-by: pshu <[email protected]>
  • Loading branch information
2 people authored and sorrycc committed Jun 23, 2022
1 parent b5b9de7 commit 63f0c50
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"jest": "^27.5.1",
"lerna": "^4.0.0",
"lint-staged": "^12.3.4",
"matcher": "^5.0.0",
"only-allow": "^1.1.0",
"prettier": "^2.5.1",
"prettier-plugin-organize-imports": "^2.3.4",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 31 additions & 4 deletions scripts/checkPackageFiles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
import * as logger from '@umijs/utils/src/logger';
import { readdirSync } from 'fs';
import { isMatch } from 'matcher';
import path from 'path';
import { eachPkg, getPkgs } from './utils';

const COMMON_IGNORES = [
'src',
'*.md',
'tsconfig*.json',
'fixtures',
'node_modules',
'package.json',
];

const cwd = process.cwd();
let missingDetected = false;
eachPkg(getPkgs(), (opts) => {
console.log('Checking package:', opts.pkg);
const pkg = require(path.join(cwd, 'packages', opts.pkg, 'package.json'));
pkg.files;
// TODO
// 检测 pkg.files 是否包含必要的和当前 pkg 下的文件和目录
const base = path.join(cwd, 'packages', opts.pkg);

const files = readdirSync(base).filter((f) => !isMatch(f, COMMON_IGNORES));
const missingAddFiles = files.filter((f) => !isMatch(f, pkg.files));

if (missingAddFiles.length > 0) {
logger.error('Checking package:', opts.pkg);
logger.error(
` "${missingAddFiles.join(
', ',
)}" missing in the package.json files field`,
);
missingDetected = true;
}
});

if (missingDetected) {
process.exit(1);
}

0 comments on commit 63f0c50

Please sign in to comment.