Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor, extract read-dir-ignore-ds-store to a new component #8647

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .bitmap
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,14 @@
"mainFile": "index.ts",
"rootDir": "scopes/toolbox/time/time-format"
},
"fs/readdir-skip-system-files": {
"name": "fs/readdir-skip-system-files",
"scope": "",
"version": "",
"defaultScope": "teambit.toolbox",
"mainFile": "index.ts",
"rootDir": "scopes/toolbox/fs/readdir-skip-system-files"
},
"tracker": {
"name": "tracker",
"scope": "teambit.component",
Expand Down Expand Up @@ -1992,4 +2000,4 @@
"rootDir": "scopes/dependencies/yarn"
},
"$schema-version": "17.0.0"
}
}
1 change: 1 addition & 0 deletions scopes/toolbox/fs/readdir-skip-system-files/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { readDirIgnoreSystemFiles, readDirIgnoreSystemFilesSync } from './readdir-skip-system-files';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fs from 'fs-extra';

const systemFiles = ['.DS_Store'];

export async function readDirIgnoreSystemFiles(dirPath: string): Promise<string[]> {
const files = await fs.readdir(dirPath);
return files.filter((file) => !systemFiles.includes(file));
}

export function readDirIgnoreSystemFilesSync(dirPath: string): string[] {
const files = fs.readdirSync(dirPath);
return files.filter((file) => !systemFiles.includes(file));
}
4 changes: 2 additions & 2 deletions src/scope/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import semver from 'semver';
import { BitError } from '@teambit/bit-error';
import { findScopePath } from '@teambit/scope.modules.find-scope-path';
import { isTag } from '@teambit/component-version';
import { readDirIgnoreSystemFilesSync } from '@teambit/toolbox.fs.readdir-skip-system-files';
import { Analytics } from '../analytics/analytics';
import {
BIT_GIT_DIR,
Expand All @@ -26,7 +27,6 @@ import Component from '../consumer/component/consumer-component';
import { ExtensionDataEntry } from '../consumer/config';
import Consumer from '../consumer/consumer';
import logger from '../logger/logger';
import { readDirSyncIgnoreDsStore } from '../utils';
import { PathOsBasedAbsolute } from '../utils/path';
import RemoveModelComponents from './component-ops/remove-model-components';
import ScopeComponentsImporter from './component-ops/scope-components-importer';
Expand Down Expand Up @@ -228,7 +228,7 @@ export default class Scope {
}
const componentFullPath = pathLib.join(scopePath, Scope.getComponentsRelativePath(), relativePath);
if (!fs.existsSync(componentFullPath)) return '';
const versions = readDirSyncIgnoreDsStore(componentFullPath);
const versions = readDirIgnoreSystemFilesSync(componentFullPath);
const latestVersion = semver.maxSatisfying(versions, '*', { includePrerelease: true });
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return pathLib.join(relativePath, latestVersion!);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/fs/is-dir-empty.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import readDirIgnoreDsStore from './read-dir-ignore-ds-store';
import { readDirIgnoreSystemFiles } from '@teambit/toolbox.fs.readdir-skip-system-files';

export default async function isDirEmpty(dirPath: string): Promise<boolean> {
const files = await readDirIgnoreDsStore(dirPath);
const files = await readDirIgnoreSystemFiles(dirPath);
return !files.length;
}
11 changes: 0 additions & 11 deletions src/utils/fs/read-dir-ignore-ds-store.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { checksum, checksumFile } from './checksum';
import getWithoutExt from './fs/fs-no-ext';
import getExt from './fs/get-ext';
import isDirEmpty from './fs/is-dir-empty';
import readDirIgnoreDsStore, { readDirSyncIgnoreDsStore } from './fs/read-dir-ignore-ds-store';
import glob from './glob';
import retrieveIgnoreList from './ignore/ignore';
import immutableUnshift from './immutable-unshift';
Expand Down Expand Up @@ -59,8 +58,6 @@ export {
checksumFile,
writeFile,
cleanObject,
readDirIgnoreDsStore,
readDirSyncIgnoreDsStore,
cleanBang,
prependBang,
isBitUrl,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/is-dir-empty-sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readDirSyncIgnoreDsStore } from './fs/read-dir-ignore-ds-store';
import { readDirIgnoreSystemFilesSync } from '@teambit/toolbox.fs.readdir-skip-system-files';

export default function isDirEmptySync(dirPath: string): boolean {
return !readDirSyncIgnoreDsStore(dirPath).length;
return !readDirIgnoreSystemFilesSync(dirPath).length;
}