Skip to content

Commit fc640f2

Browse files
committed
fix: resolve linting issues in .rcappsconfig implementation
1 parent c965355 commit fc640f2

File tree

3 files changed

+64
-27
lines changed

3 files changed

+64
-27
lines changed

src/compiler/getAppSource.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ import type {
77
ICompilerFile,
88
IMapCompilerFile,
99
} from "../definition";
10-
import { readRcappsConfig, shouldIgnoreFile, type IRcappsConfig } from "../misc/rcappsConfigReader";
11-
12-
async function walkDirectory(directory: string, projectPath: string, rcappsConfig: IRcappsConfig | null): Promise<ICompilerFile[]> {
10+
import {
11+
readRcappsConfig,
12+
shouldIgnoreFile,
13+
type IRcappsConfig,
14+
} from "../misc/rcappsConfigReader";
15+
16+
async function walkDirectory(
17+
directory: string,
18+
projectPath: string,
19+
rcappsConfig: IRcappsConfig | null,
20+
): Promise<ICompilerFile[]> {
1321
const dirents = await fs.readdir(directory, { withFileTypes: true });
1422
const files = await Promise.all(
1523
dirents
@@ -24,7 +32,7 @@ async function walkDirectory(directory: string, projectPath: string, rcappsConfi
2432
}
2533

2634
// Check if this path should be ignored based on .rcappsconfig
27-
if (rcappsConfig && rcappsConfig.ignore) {
35+
if (rcappsConfig?.ignore) {
2836
if (shouldIgnoreFile(relativePath, rcappsConfig.ignore)) {
2937
return null;
3038
}
@@ -105,8 +113,12 @@ function getTypescriptFilesFromProject(
105113
export async function getAppSource(path: string): Promise<IAppSource> {
106114
// Load .rcappsconfig if it exists
107115
const rcappsConfig = await readRcappsConfig(path);
108-
109-
const directoryWalkData: ICompilerFile[] = await walkDirectory(path, path, rcappsConfig);
116+
117+
const directoryWalkData: ICompilerFile[] = await walkDirectory(
118+
path,
119+
path,
120+
rcappsConfig,
121+
);
110122
const projectFiles: ICompilerFile[] = filterProjectFiles(
111123
path,
112124
directoryWalkData,

src/misc/rcappsConfigReader.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@ export interface IRcappsConfig {
1212
* @param projectPath The path to the project directory
1313
* @returns The parsed configuration or null if file doesn't exist
1414
*/
15-
export async function readRcappsConfig(projectPath: string): Promise<IRcappsConfig | null> {
15+
export async function readRcappsConfig(
16+
projectPath: string,
17+
): Promise<IRcappsConfig | null> {
1618
const configPath = path.join(projectPath, ".rcappsconfig");
17-
19+
1820
try {
1921
const configContent = await fs.promises.readFile(configPath, "utf8");
2022
const config = JSON.parse(configContent) as IRcappsConfig;
21-
23+
2224
logger.debug(`Loaded .rcappsconfig from ${configPath}`);
2325
return config;
2426
} catch (error) {
2527
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
26-
logger.debug("No .rcappsconfig file found, using default configuration");
28+
logger.debug(
29+
"No .rcappsconfig file found, using default configuration",
30+
);
2731
return null;
2832
}
29-
33+
3034
logger.warn(`Failed to parse .rcappsconfig file: ${error.message}`);
3135
return null;
3236
}
@@ -38,11 +42,14 @@ export async function readRcappsConfig(projectPath: string): Promise<IRcappsConf
3842
* @param config The .rcappsconfig configuration
3943
* @returns Combined ignore patterns
4044
*/
41-
export function mergeIgnorePatterns(defaultIgnore: string[], config: IRcappsConfig | null): string[] {
42-
if (!config || !config.ignore) {
45+
export function mergeIgnorePatterns(
46+
defaultIgnore: string[],
47+
config: IRcappsConfig | null,
48+
): string[] {
49+
if (!config?.ignore) {
4350
return defaultIgnore;
4451
}
45-
52+
4653
// Combine default ignore patterns with those from .rcappsconfig
4754
// .rcappsconfig patterns take precedence (are added last)
4855
return [...defaultIgnore, ...config.ignore];
@@ -54,16 +61,19 @@ export function mergeIgnorePatterns(defaultIgnore: string[], config: IRcappsConf
5461
* @param ignorePatterns Array of ignore patterns (glob-style)
5562
* @returns true if the file should be ignored
5663
*/
57-
export function shouldIgnoreFile(filePath: string, ignorePatterns: string[]): boolean {
58-
return ignorePatterns.some(pattern => {
64+
export function shouldIgnoreFile(
65+
filePath: string,
66+
ignorePatterns: string[],
67+
): boolean {
68+
return ignorePatterns.some((pattern) => {
5969
// Support both glob patterns and simple directory/file names
6070
// Check for exact matches, basename matches, and path contains matches
6171
const normalizedPath = path.normalize(filePath).replace(/\\/g, "/");
6272
const normalizedPattern = pattern.replace(/\\/g, "/");
63-
73+
6474
// Simple pattern matching - check if the pattern matches the path
6575
let isMatch = false;
66-
76+
6777
// Exact match
6878
if (normalizedPath === normalizedPattern) {
6979
isMatch = true;
@@ -77,25 +87,32 @@ export function shouldIgnoreFile(filePath: string, ignorePatterns: string[]): bo
7787
isMatch = true;
7888
}
7989
// Glob-style patterns
80-
else if (normalizedPattern.includes("*") || normalizedPattern.includes("?")) {
90+
else if (
91+
normalizedPattern.includes("*") ||
92+
normalizedPattern.includes("?")
93+
) {
8194
// Convert simple glob pattern to regex
8295
const regexPattern = normalizedPattern
8396
.replace(/\./g, "\\.")
8497
.replace(/\*/g, ".*")
8598
.replace(/\?/g, ".");
8699
try {
87100
const regex = new RegExp(`^${regexPattern}$`);
88-
isMatch = regex.test(normalizedPath) || regex.test(path.basename(normalizedPath));
101+
isMatch =
102+
regex.test(normalizedPath) ||
103+
regex.test(path.basename(normalizedPath));
89104
} catch (e) {
90105
// If regex fails, fall back to simple contains check
91-
isMatch = normalizedPath.includes(normalizedPattern.replace(/\*/g, ""));
106+
isMatch = normalizedPath.includes(
107+
normalizedPattern.replace(/\*/g, ""),
108+
);
92109
}
93110
}
94-
111+
95112
if (isMatch) {
96113
logger.debug(`File ${filePath} ignored by pattern: ${pattern}`);
97114
}
98-
115+
99116
return isMatch;
100117
});
101-
}
118+
}

src/packager/AppPackager.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import type {
1313
} from "../definition";
1414
import { isBundled } from "../bundler";
1515
import logger from "../misc/logger";
16-
import { readRcappsConfig, mergeIgnorePatterns, type IRcappsConfig } from "../misc/rcappsConfigReader";
16+
import {
17+
readRcappsConfig,
18+
mergeIgnorePatterns,
19+
type IRcappsConfig,
20+
} from "../misc/rcappsConfigReader";
1721

1822
export class AppPackager {
1923
public static DefaultIgnorePatterns: string[] = [
@@ -29,6 +33,7 @@ export class AppPackager {
2933
];
3034

3135
private zip = new Yazl.ZipFile();
36+
3237
private rcappsConfig: IRcappsConfig | null = null;
3338

3439
constructor(
@@ -46,7 +51,10 @@ export class AppPackager {
4651
this.rcappsConfig = await readRcappsConfig(this.fd.folder);
4752
}
4853

49-
const ignorePatterns = mergeIgnorePatterns(AppPackager.DefaultIgnorePatterns, this.rcappsConfig);
54+
const ignorePatterns = mergeIgnorePatterns(
55+
AppPackager.DefaultIgnorePatterns,
56+
this.rcappsConfig,
57+
);
5058

5159
return {
5260
dot: false,
@@ -146,7 +154,7 @@ export class AppPackager {
146154
// tslint:disable-next-line:promise-function-async
147155
private async asyncGlob(): Promise<Array<string>> {
148156
const globOptions = await this.getGlobOptions();
149-
157+
150158
return new Promise((resolve, reject) => {
151159
glob(this.fd.toZip, globOptions, (err, matches) => {
152160
if (err) {

0 commit comments

Comments
 (0)