Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bburns committed Jul 5, 2024
1 parent 00e0bd4 commit 2d9c392
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 38 deletions.
46 changes: 9 additions & 37 deletions packages/cli/lib/services/compile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ export interface ListedFile {
baseName: string;
}

// inputPath - absolute platform path
// outputPath - absolute platform path
export function getFileToCompile({ fullPath, filePath }: { fullPath: string; filePath: string }): ListedFile {
const baseName = path.basename(filePath, '.ts');
return {
Expand Down Expand Up @@ -349,43 +351,13 @@ export function listFilesToCompile({
});
}

// get array of file paths that match the given path parts.
// last part is treated as a file extension.
// eg getMatchingFiles('foo', 'ts') -> glob.sync('foo/*.ts')
// get absolute platform file paths that match the given path parts,
// with last part treated as a file extension.
// eg getMatchingFiles('/foo', 'bar', 'ts') -> glob.sync('/foo/bar/*.ts')
// returns ['/foo/bar/baz.ts', '/foo/bar/pok.ts', ...]
function getMatchingFiles(...args: string[]): string[] {
args.splice(-1, 1, `*.${args.slice(-1)[0]}`);
// console.log('args', args);
const pattern = args.join('/');
// console.log('pattern', pattern);
// return glob.sync(pattern, { posix: true });
return glob.sync(pattern);

// const pattern = path.join(...args);
// console.log('pattern', pattern);

// windowsPathsNoEscape
// Use \\ as a path separator only, and never as an escape
// character.
// If set, all \\ characters are replaced with / in the
// pattern. Note that this makes it impossible to match
// against paths containing literal glob pattern characters,
// but allows matching with patterns constructed using
// path.join() and path.resolve() on Windows platforms,
// mimicking the (buggy!) behavior of Glob v7 and before on
// Windows.

// absolute
// Set to false to always return relative paths. When
// this option is not set, absolute paths are returned for
// patterns that are absolute, and otherwise paths are
// returned that are relative to the cwd setting.

// posix
// Return / delimited paths, even on Windows.
// On posix systems, this has no effect. But, on Windows, it
// means that paths will be / delimited, and absolute paths
// will be their full resolved UNC forms, eg instead of
// 'C:\\foo\\bar', it would return '//?/C:/foo/bar'

// return glob.sync(pattern, { windowsPathsNoEscape: true, absolute: false, posix: true });
// glob prefers posix paths as input
const pattern = args.join('/'); // eg '/foo/bar/*.ts'
return glob.sync(pattern, { absolute: true });
}
8 changes: 7 additions & 1 deletion packages/cli/lib/services/compile.service.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getFileToCompile, listFilesToCompile } from './compile.service';
import { fileURLToPath } from 'node:url';
import type { NangoYamlParsed } from '@nangohq/types';

// eg "C:\Users\bburns\Workspace\test\various\src"
// eg "C:\\Users\bburns\\Workspace\\forks\\nango\\packages\\cli\\lib\\services"
const thisFolder = path.dirname(fileURLToPath(import.meta.url));

describe('listFiles', () => {
Expand All @@ -14,6 +14,12 @@ describe('listFiles', () => {
//. why should this be the first entry?
expect(files[0]).toStrictEqual({
baseName: 'verification.service',
//. but listFiles gives
// 'packages\\cli\\lib\\services\\verification.service.ts'
// why?
// that's relative to curdir, not fullpath
// oh, that's what glob does - wew
// path.relative(join..., '')
inputPath: join(thisFolder, 'verification.service.ts'),
outputPath: join(thisFolder, 'dist/verification.service.js')
});
Expand Down

0 comments on commit 2d9c392

Please sign in to comment.