chore: do not depend on globby in cli

This commit is contained in:
Thijs Louisse 2024-05-14 14:08:14 +02:00
parent aea90ae036
commit b2d5472216
5 changed files with 37 additions and 36 deletions

View file

@ -2,7 +2,6 @@
import child_process from 'child_process'; // eslint-disable-line camelcase import child_process from 'child_process'; // eslint-disable-line camelcase
import path from 'path'; import path from 'path';
import { globbySync } from 'globby'; // eslint-disable-line import/no-extraneous-dependencies
import { optimisedGlob } from '../program/utils/optimised-glob.js'; import { optimisedGlob } from '../program/utils/optimised-glob.js';
import { toPosixPath } from '../program/utils/to-posix-path.js'; import { toPosixPath } from '../program/utils/to-posix-path.js';
import { LogService } from '../program/core/LogService.js'; import { LogService } from '../program/core/LogService.js';
@ -46,25 +45,29 @@ export function setQueryMethod(m) {
} }
/** /**
* @param {string} t * @param {string} targets
* @returns {string[]|undefined} * @returns {Promise<string[]|undefined>}
*/ */
export function pathsArrayFromCs(t, cwd = process.cwd()) { export async function pathsArrayFromCs(targets, cwd = process.cwd()) {
if (!t) { if (!targets) return undefined;
return undefined;
}
return flatten( const resultPaths = [];
t.split(',').map(t => {
if (t.startsWith('/')) { for (const t of targets.split(',')) {
return t; if (t.startsWith('/')) {
} resultPaths.push(t);
if (t.includes('*')) { continue; // eslint-disable-line no-continue
return globbySync(t, { cwd, absolute: true, onlyFiles: false }).map(toPosixPath); }
} if (t.includes('*')) {
return toPosixPath(path.resolve(cwd, t.trim())); const x = (await optimisedGlob(t, { cwd, absolute: true, onlyFiles: false })).map(
}), toPosixPath,
); );
resultPaths.push(...x);
continue; // eslint-disable-line no-continue
}
resultPaths.push(toPosixPath(path.resolve(cwd, t.trim())));
}
return resultPaths;
} }
/** /**
@ -72,9 +75,9 @@ export function pathsArrayFromCs(t, cwd = process.cwd()) {
* @param {'search-target'|'reference'} collectionType collection type * @param {'search-target'|'reference'} collectionType collection type
* @param {{searchTargetCollections: {[repo:string]:string[]}; referenceCollections:{[repo:string]:string[]}}} [eCfg] external configuration. Usually providence.conf.js * @param {{searchTargetCollections: {[repo:string]:string[]}; referenceCollections:{[repo:string]:string[]}}} [eCfg] external configuration. Usually providence.conf.js
* @param {string} [cwd] * @param {string} [cwd]
* @returns {string[]|undefined} * @returns {Promise<string[]|undefined>}
*/ */
export function pathsArrayFromCollectionName( export async function pathsArrayFromCollectionName(
name, name,
collectionType = 'search-target', collectionType = 'search-target',
eCfg = undefined, eCfg = undefined,

View file

@ -235,8 +235,6 @@ export class InputDataService {
* @returns {Promise<ProjectInputDataWithMeta[]>} * @returns {Promise<ProjectInputDataWithMeta[]>}
*/ */
static async createDataObject(projectPaths, gatherFilesConfig = {}) { static async createDataObject(projectPaths, gatherFilesConfig = {}) {
console.debug('[createDataObject]');
/** @type {ProjectInputData[]} */ /** @type {ProjectInputData[]} */
const inputData = []; const inputData = [];
for (const projectPathOrObj of projectPaths) { for (const projectPathOrObj of projectPaths) {
@ -474,8 +472,6 @@ export class InputDataService {
* @returns {Promise<PathFromSystemRoot[]>} result list of file paths * @returns {Promise<PathFromSystemRoot[]>} result list of file paths
*/ */
static async gatherFilesFromDir(startPath, customConfig = {}) { static async gatherFilesFromDir(startPath, customConfig = {}) {
console.debug('[gatherFilesFromDir]');
const cfg = { const cfg = {
...this.defaultGatherFilesConfig, ...this.defaultGatherFilesConfig,
...customConfig, ...customConfig,

View file

@ -140,7 +140,7 @@ async function getAllFilesFromStartPath(
/** @type {nodeFs.Dirent[]} */ /** @type {nodeFs.Dirent[]} */
const direntsForLvl = await fs.promises.readdir(startPath, { withFileTypes: true }); const direntsForLvl = await fs.promises.readdir(startPath, { withFileTypes: true });
for (const dirent of direntsForLvl) { for (const dirent of direntsForLvl) {
// @ts-ignore // @ts-expect-error
dirent.parentPath = startPath; dirent.parentPath = startPath;
dirents.push(dirent); dirents.push(dirent);
@ -261,14 +261,11 @@ export async function optimisedGlob(globOrGlobs, providedOptions = {}) {
} }
if (options.absolute) { if (options.absolute) {
console.debug({ 'options.cwd': options.cwd, filteredPathsBefore: filteredPaths });
filteredPaths = filteredPaths.map(f => toPosixPath(path.join(options.cwd, f))); filteredPaths = filteredPaths.map(f => toPosixPath(path.join(options.cwd, f)));
console.debug({ filteredPathsAfterAbso: filteredPaths });
if (process.platform === 'win32') { if (process.platform === 'win32') {
const driveLetter = path.win32.resolve(options.cwd).slice(0, 1).toUpperCase(); const driveLetter = path.win32.resolve(options.cwd).slice(0, 1).toUpperCase();
filteredPaths = filteredPaths.map(f => `${driveLetter}:${f}`); filteredPaths = filteredPaths.map(f => `${driveLetter}:${f}`);
console.debug({ filteredPathsAfterWin32: filteredPaths });
} }
} }

View file

@ -52,22 +52,22 @@ describe('CLI helpers', () => {
describe('pathsArrayFromCs', () => { describe('pathsArrayFromCs', () => {
it('allows absolute paths', async () => { it('allows absolute paths', async () => {
expect(pathsArrayFromCs('/mocked/path/example-project', rootDir)).to.deep.equal([ expect(await pathsArrayFromCs('/mocked/path/example-project', rootDir)).to.deep.equal([
'/mocked/path/example-project', '/mocked/path/example-project',
]); ]);
}); });
it('allows relative paths', async () => { it('allows relative paths', async () => {
expect( expect(
pathsArrayFromCs('./test-helpers/project-mocks/importing-target-project', rootDir), await pathsArrayFromCs('./test-helpers/project-mocks/importing-target-project', rootDir),
).to.deep.equal([`${rootDir}/test-helpers/project-mocks/importing-target-project`]); ).to.deep.equal([`${rootDir}/test-helpers/project-mocks/importing-target-project`]);
expect( expect(
pathsArrayFromCs('test-helpers/project-mocks/importing-target-project', rootDir), await pathsArrayFromCs('test-helpers/project-mocks/importing-target-project', rootDir),
).to.deep.equal([`${rootDir}/test-helpers/project-mocks/importing-target-project`]); ).to.deep.equal([`${rootDir}/test-helpers/project-mocks/importing-target-project`]);
}); });
it('allows globs', async () => { it('allows globs', async () => {
expect(pathsArrayFromCs('test-helpers/project-mocks*', rootDir)).to.deep.equal([ expect(await pathsArrayFromCs('test-helpers/project-mocks*', rootDir)).to.deep.equal([
`${rootDir}/test-helpers/project-mocks`, `${rootDir}/test-helpers/project-mocks`,
`${rootDir}/test-helpers/project-mocks-analyzer-outputs`, `${rootDir}/test-helpers/project-mocks-analyzer-outputs`,
]); ]);
@ -76,7 +76,7 @@ describe('CLI helpers', () => {
it('allows multiple comma separated paths', async () => { it('allows multiple comma separated paths', async () => {
const paths = const paths =
'test-helpers/project-mocks*, ./test-helpers/project-mocks/importing-target-project,/mocked/path/example-project'; 'test-helpers/project-mocks*, ./test-helpers/project-mocks/importing-target-project,/mocked/path/example-project';
expect(pathsArrayFromCs(paths, rootDir)).to.deep.equal([ expect(await pathsArrayFromCs(paths, rootDir)).to.deep.equal([
`${rootDir}/test-helpers/project-mocks`, `${rootDir}/test-helpers/project-mocks`,
`${rootDir}/test-helpers/project-mocks-analyzer-outputs`, `${rootDir}/test-helpers/project-mocks-analyzer-outputs`,
`${rootDir}/test-helpers/project-mocks/importing-target-project`, `${rootDir}/test-helpers/project-mocks/importing-target-project`,
@ -88,7 +88,12 @@ describe('CLI helpers', () => {
describe('pathsArrayFromCollectionName', () => { describe('pathsArrayFromCollectionName', () => {
it('gets collections from external target config', async () => { it('gets collections from external target config', async () => {
expect( expect(
pathsArrayFromCollectionName('lion-collection', 'search-target', externalCfgMock, rootDir), await pathsArrayFromCollectionName(
'lion-collection',
'search-target',
externalCfgMock,
rootDir,
),
).to.deep.equal( ).to.deep.equal(
externalCfgMock.searchTargetCollections['lion-collection'].map(p => externalCfgMock.searchTargetCollections['lion-collection'].map(p =>
toPosixPath(pathLib.join(rootDir, p)), toPosixPath(pathLib.join(rootDir, p)),
@ -98,7 +103,7 @@ describe('CLI helpers', () => {
it('gets collections from external reference config', async () => { it('gets collections from external reference config', async () => {
expect( expect(
pathsArrayFromCollectionName( await pathsArrayFromCollectionName(
'lion-based-ui-collection', 'lion-based-ui-collection',
'reference', 'reference',
externalCfgMock, externalCfgMock,

View file

@ -3,7 +3,7 @@
"searchType": "ast-analyzer", "searchType": "ast-analyzer",
"analyzerMeta": { "analyzerMeta": {
"name": "find-exports", "name": "find-exports",
"requiredAst": "swc-to-babel", "requiredAst": "swc",
"identifier": "exporting-ref-project_1.0.0__-42206859", "identifier": "exporting-ref-project_1.0.0__-42206859",
"targetProject": { "targetProject": {
"mainEntry": "./index.js", "mainEntry": "./index.js",