chore: do not depend on globby in cli
This commit is contained in:
parent
aea90ae036
commit
b2d5472216
5 changed files with 37 additions and 36 deletions
|
|
@ -2,7 +2,6 @@
|
|||
import child_process from 'child_process'; // eslint-disable-line camelcase
|
||||
import path from 'path';
|
||||
|
||||
import { globbySync } from 'globby'; // eslint-disable-line import/no-extraneous-dependencies
|
||||
import { optimisedGlob } from '../program/utils/optimised-glob.js';
|
||||
import { toPosixPath } from '../program/utils/to-posix-path.js';
|
||||
import { LogService } from '../program/core/LogService.js';
|
||||
|
|
@ -46,25 +45,29 @@ export function setQueryMethod(m) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {string} t
|
||||
* @returns {string[]|undefined}
|
||||
* @param {string} targets
|
||||
* @returns {Promise<string[]|undefined>}
|
||||
*/
|
||||
export function pathsArrayFromCs(t, cwd = process.cwd()) {
|
||||
if (!t) {
|
||||
return undefined;
|
||||
}
|
||||
export async function pathsArrayFromCs(targets, cwd = process.cwd()) {
|
||||
if (!targets) return undefined;
|
||||
|
||||
return flatten(
|
||||
t.split(',').map(t => {
|
||||
if (t.startsWith('/')) {
|
||||
return t;
|
||||
}
|
||||
if (t.includes('*')) {
|
||||
return globbySync(t, { cwd, absolute: true, onlyFiles: false }).map(toPosixPath);
|
||||
}
|
||||
return toPosixPath(path.resolve(cwd, t.trim()));
|
||||
}),
|
||||
);
|
||||
const resultPaths = [];
|
||||
|
||||
for (const t of targets.split(',')) {
|
||||
if (t.startsWith('/')) {
|
||||
resultPaths.push(t);
|
||||
continue; // eslint-disable-line no-continue
|
||||
}
|
||||
if (t.includes('*')) {
|
||||
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 {{searchTargetCollections: {[repo:string]:string[]}; referenceCollections:{[repo:string]:string[]}}} [eCfg] external configuration. Usually providence.conf.js
|
||||
* @param {string} [cwd]
|
||||
* @returns {string[]|undefined}
|
||||
* @returns {Promise<string[]|undefined>}
|
||||
*/
|
||||
export function pathsArrayFromCollectionName(
|
||||
export async function pathsArrayFromCollectionName(
|
||||
name,
|
||||
collectionType = 'search-target',
|
||||
eCfg = undefined,
|
||||
|
|
|
|||
|
|
@ -235,8 +235,6 @@ export class InputDataService {
|
|||
* @returns {Promise<ProjectInputDataWithMeta[]>}
|
||||
*/
|
||||
static async createDataObject(projectPaths, gatherFilesConfig = {}) {
|
||||
console.debug('[createDataObject]');
|
||||
|
||||
/** @type {ProjectInputData[]} */
|
||||
const inputData = [];
|
||||
for (const projectPathOrObj of projectPaths) {
|
||||
|
|
@ -474,8 +472,6 @@ export class InputDataService {
|
|||
* @returns {Promise<PathFromSystemRoot[]>} result list of file paths
|
||||
*/
|
||||
static async gatherFilesFromDir(startPath, customConfig = {}) {
|
||||
console.debug('[gatherFilesFromDir]');
|
||||
|
||||
const cfg = {
|
||||
...this.defaultGatherFilesConfig,
|
||||
...customConfig,
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ async function getAllFilesFromStartPath(
|
|||
/** @type {nodeFs.Dirent[]} */
|
||||
const direntsForLvl = await fs.promises.readdir(startPath, { withFileTypes: true });
|
||||
for (const dirent of direntsForLvl) {
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
dirent.parentPath = startPath;
|
||||
dirents.push(dirent);
|
||||
|
||||
|
|
@ -261,14 +261,11 @@ export async function optimisedGlob(globOrGlobs, providedOptions = {}) {
|
|||
}
|
||||
|
||||
if (options.absolute) {
|
||||
console.debug({ 'options.cwd': options.cwd, filteredPathsBefore: filteredPaths });
|
||||
filteredPaths = filteredPaths.map(f => toPosixPath(path.join(options.cwd, f)));
|
||||
console.debug({ filteredPathsAfterAbso: filteredPaths });
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
const driveLetter = path.win32.resolve(options.cwd).slice(0, 1).toUpperCase();
|
||||
filteredPaths = filteredPaths.map(f => `${driveLetter}:${f}`);
|
||||
console.debug({ filteredPathsAfterWin32: filteredPaths });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,22 +52,22 @@ describe('CLI helpers', () => {
|
|||
|
||||
describe('pathsArrayFromCs', () => {
|
||||
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',
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows relative paths', async () => {
|
||||
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`]);
|
||||
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`]);
|
||||
});
|
||||
|
||||
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-analyzer-outputs`,
|
||||
]);
|
||||
|
|
@ -76,7 +76,7 @@ describe('CLI helpers', () => {
|
|||
it('allows multiple comma separated paths', async () => {
|
||||
const paths =
|
||||
'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-analyzer-outputs`,
|
||||
`${rootDir}/test-helpers/project-mocks/importing-target-project`,
|
||||
|
|
@ -88,7 +88,12 @@ describe('CLI helpers', () => {
|
|||
describe('pathsArrayFromCollectionName', () => {
|
||||
it('gets collections from external target config', async () => {
|
||||
expect(
|
||||
pathsArrayFromCollectionName('lion-collection', 'search-target', externalCfgMock, rootDir),
|
||||
await pathsArrayFromCollectionName(
|
||||
'lion-collection',
|
||||
'search-target',
|
||||
externalCfgMock,
|
||||
rootDir,
|
||||
),
|
||||
).to.deep.equal(
|
||||
externalCfgMock.searchTargetCollections['lion-collection'].map(p =>
|
||||
toPosixPath(pathLib.join(rootDir, p)),
|
||||
|
|
@ -98,7 +103,7 @@ describe('CLI helpers', () => {
|
|||
|
||||
it('gets collections from external reference config', async () => {
|
||||
expect(
|
||||
pathsArrayFromCollectionName(
|
||||
await pathsArrayFromCollectionName(
|
||||
'lion-based-ui-collection',
|
||||
'reference',
|
||||
externalCfgMock,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"searchType": "ast-analyzer",
|
||||
"analyzerMeta": {
|
||||
"name": "find-exports",
|
||||
"requiredAst": "swc-to-babel",
|
||||
"requiredAst": "swc",
|
||||
"identifier": "exporting-ref-project_1.0.0__-42206859",
|
||||
"targetProject": {
|
||||
"mainEntry": "./index.js",
|
||||
|
|
|
|||
Loading…
Reference in a new issue