From ea5565b571c80f86af12457f7c45c13126a9a49a Mon Sep 17 00:00:00 2001 From: jack zhang <1098626505@qq.com> Date: Mon, 1 Apr 2024 23:04:11 +0800 Subject: [PATCH] fix: tar bug (#3891) --- packages/core/build/src/constant.ts | 2 +- packages/core/build/src/tarPlugin.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/core/build/src/constant.ts b/packages/core/build/src/constant.ts index 0fb14c46cd..3b91cbd397 100644 --- a/packages/core/build/src/constant.ts +++ b/packages/core/build/src/constant.ts @@ -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'); diff --git a/packages/core/build/src/tarPlugin.ts b/packages/core/build/src/tarPlugin.ts index bc869593b1..900ab8c30c 100644 --- a/packages/core/build/src/tarPlugin.ts +++ b/packages/core/build/src/tarPlugin.ts @@ -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`);