fix: tar bug (#3891)

This commit is contained in:
jack zhang 2024-04-01 23:04:11 +08:00 committed by GitHub
parent 85f33cedbe
commit ea5565b571
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -52,5 +52,5 @@ export const getCjsPackages = (packages: Package[]) =>
.filter((item) => !CJS_EXCLUDE_PACKAGES.includes(item.location));
// tar
export const tarIncludesFiles = ['package.json', 'README.md', 'LICENSE', 'dist', '!node_modules', '!src'];
export const tarIncludesFiles = ['package.json', 'README.md', 'LICENSE', 'dist', '!node_modules'];
export const TAR_OUTPUT_DIR = process.env.TAR_PATH ? process.env.TAR_PATH : path.join(ROOT_PATH, 'storage', 'tar');

View File

@ -12,13 +12,16 @@ export function tarPlugin(cwd: string, log: PkgLog) {
const npmIgnore = path.join(cwd, '.npmignore');
let files = pkg.files || [];
if (fs.existsSync(npmIgnore)) {
files = fs.readFileSync(npmIgnore, 'utf-8').split('\n').filter((item) => item.trim()).map(item => `!${item}`);
files = fs.readFileSync(npmIgnore, 'utf-8')
.split('\n')
.filter((item) => item.trim())
.map(item => item.startsWith('/') ? `.${item}` : item)
.map(item => `!${item}`);
files.push('**/*');
}
// 必须包含的文件
files.push(...tarIncludesFiles);
files = files.map((item: string) => item !== '**/*' && fs.existsSync(path.join(cwd, item.replace('!', ''))) && fs.statSync(path.join(cwd, item.replace('!', ''))).isDirectory() ? `${item}/**/*` : item);
const tarball = path.join(TAR_OUTPUT_DIR, `${pkg.name}-${pkg.version}.tgz`);