Skip to content

Commit 899ed8f

Browse files
committed
fix: enhance file exclusion logic to prevent copying package.json and lock files
1 parent 0fdd74a commit 899ed8f

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

adminforth/modules/codeInjector.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,7 @@ class CodeInjector implements ICodeInjector {
446446
const spaDir = this.getSpaDir();
447447

448448
afLogger.trace(`🪲⚙️ fsExtra.copy from ${spaDir} -> ${this.spaTmpPath()}`);
449-
let isPackageJsonInSpaFolder = false;
450449

451-
try {
452-
await fs.promises.access(path.join(this.spaTmpPath(), 'package.json'));
453-
isPackageJsonInSpaFolder = true;
454-
afLogger.trace('🪲⚙️ package.json is in spa tmp folder, will not copy package.json from user spa folder to not break cache');
455-
} catch (e) {
456-
afLogger.trace('🪲⚙️ package.json is not in spa tmp folder, will copy package.json from user spa folder if it exists');
457-
}
458450
// try to rm <spa tmp path>/src/types directory
459451
try {
460452
await fs.promises.rm(path.join(this.spaTmpPath(), 'src', 'types'), { recursive: true });
@@ -468,8 +460,7 @@ class CodeInjector implements ICodeInjector {
468460
filter: (src) => {
469461
// /adminforth/* used for local development and /dist/* used for production
470462
const filterPasses = !src.includes(`${path.sep}adminforth${path.sep}spa${path.sep}node_modules`) && !src.includes(`${path.sep}adminforth${path.sep}spa${path.sep}dist`)
471-
&& !src.includes(`${path.sep}dist${path.sep}spa${path.sep}node_modules`) && !src.includes(`${path.sep}dist${path.sep}spa${path.sep}dist`)
472-
&& !(isPackageJsonInSpaFolder && (src.endsWith('package.json') || src.endsWith('package-lock.json') || src.endsWith('pnpm-lock.yaml'))); // if package.json is in spa folder, don't copy it, to not break cache
463+
&& !src.includes(`${path.sep}dist${path.sep}spa${path.sep}node_modules`) && !src.includes(`${path.sep}dist${path.sep}spa${path.sep}dist`);
473464
if (!filterPasses) {
474465
afLogger.trace(`🪲⚙️ fsExtra.copy filtered out, ${src}`);
475466
}
@@ -960,7 +951,9 @@ class CodeInjector implements ICodeInjector {
960951

961952
// 🚫 Skip big files or files which might be dynamic
962953
if (file.name === 'node_modules' || file.name === 'dist' ||
963-
file.name === 'i18n-messages.json' || file.name === 'i18n-empty.json' || file.name === 'hashes.json') {
954+
file.name === 'i18n-messages.json' || file.name === 'i18n-empty.json' ||
955+
file.name === 'hashes.json' || file.name === 'package.json' ||
956+
file.name === 'pnpm-lock.yaml' || file.name === 'package-lock.json') {
964957
return '';
965958
}
966959

@@ -988,7 +981,9 @@ class CodeInjector implements ICodeInjector {
988981

989982
// 🚫 Skip big/dynamic folders or files
990983
if (file.name === 'node_modules' || file.name === 'dist' ||
991-
file.name === 'i18n-messages.json' || file.name === 'i18n-empty.json' || file.name === 'hashes.json') {
984+
file.name === 'i18n-messages.json' || file.name === 'i18n-empty.json' ||
985+
file.name === 'hashes.json' || file.name === 'package.json' ||
986+
file.name === 'pnpm-lock.yaml' || file.name === 'package-lock.json') {
992987
return;
993988
}
994989

0 commit comments

Comments
 (0)