Skip to content

Commit f9615b1

Browse files
committed
fix: full paths in gitignore, and ignore .yarn for lint
1 parent a92e20c commit f9615b1

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

eslint.config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export default defineConfig([
1212
},
1313
tseslint.configs.recommended,
1414
{
15-
ignores: ["./build/**", "node_modules/**"],
15+
ignores: ["./build/**", "node_modules/**", ".yarn/**"],
1616
},
1717
]);

src/cli.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ describe('cli', () => {
4747
);
4848

4949
const gitignore = await readFile(path.join(cwd, '.gitignore'), 'utf8');
50-
expect(gitignore).toContain('secrets/.env');
51-
expect(gitignore).toContain('config/app.json');
50+
expect(gitignore).toContain('/secrets/.env');
51+
expect(gitignore).toContain('/config/app.json');
5252

5353
expect(stdout.toString()).toMatch(/cpconfig apply/);
5454
});
@@ -89,7 +89,7 @@ describe('cli', () => {
8989
'from module',
9090
);
9191
const gitignore = await readFile(path.join(cwd, '.gitignore'), 'utf8');
92-
expect(gitignore).toContain('module-output.txt');
92+
expect(gitignore).toContain('/module-output.txt');
9393
expect(stdout.toString()).toContain('cpconfig apply');
9494
expect(stdout.toString()).toContain('cpconfig.config.mjs');
9595
});
@@ -133,7 +133,7 @@ describe('cli', () => {
133133
);
134134

135135
const gitignore = await readFile(path.join(cwd, '.gitignore'), 'utf8');
136-
expect(gitignore).toContain('ts-output.txt');
136+
expect(gitignore).toContain('/ts-output.txt');
137137
});
138138
});
139139

@@ -184,7 +184,7 @@ describe('cli', () => {
184184
expect(deserialised.cliArgs).toEqual(['--json']);
185185

186186
const gitignore = await readFile(path.join(cwd, 'generated.ignore'), 'utf8');
187-
expect(gitignore).toContain('factory.txt');
187+
expect(gitignore).toContain('/factory.txt');
188188
const stdoutJson = JSON.parse(stdout.toString()) as {
189189
gitignore: { path: string };
190190
};

src/index.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('syncConfigs', () => {
2121

2222
expect(result.files.map(({ action }) => action)).toEqual(['created', 'created']);
2323
expect(result.gitignore.updated).toBe(true);
24-
expect(result.gitignore.added).toEqual(['env/.env.local', '.secrets.yml']);
24+
expect(result.gitignore.added).toEqual(['/env/.env.local', '/.secrets.yml']);
2525

2626
await expect(readFile(path.join(rootDir, 'env/.env.local'), 'utf8')).resolves.toBe(
2727
'TOKEN=secret',
@@ -32,8 +32,8 @@ describe('syncConfigs', () => {
3232

3333
const gitignore = await readFile(path.join(rootDir, '.gitignore'), 'utf8');
3434
expect(gitignore).toContain('# Managed by cpconfig');
35-
expect(gitignore).toContain('env/.env.local');
36-
expect(gitignore).toContain('.secrets.yml');
35+
expect(gitignore).toContain('/env/.env.local');
36+
expect(gitignore).toContain('/.secrets.yml');
3737
});
3838
});
3939

@@ -74,11 +74,11 @@ describe('syncConfigs', () => {
7474
]);
7575
expect(result.gitignore.updated).toBe(true);
7676
expect(result.gitignore.added).toEqual([]);
77-
expect(result.gitignore.removed).toEqual(['config/b.json']);
77+
expect(result.gitignore.removed).toEqual(['/config/b.json']);
7878

7979
const gitignore = await readFile(path.join(rootDir, '.gitignore'), 'utf8');
80-
expect(gitignore).toContain('config/a.json');
81-
expect(gitignore).not.toContain('config/b.json');
80+
expect(gitignore).toContain('/config/a.json');
81+
expect(gitignore).not.toContain('/config/b.json');
8282
});
8383
});
8484

@@ -116,8 +116,8 @@ describe('syncConfigs', () => {
116116
);
117117

118118
const gitignore = await readFile(path.join(rootDir, '.gitignore'), 'utf8');
119-
expect(gitignore).toContain('secret.log');
120-
expect(gitignore).not.toContain('visible.log');
119+
expect(gitignore).toContain('/secret.log');
120+
expect(gitignore).not.toContain('/visible.log');
121121
});
122122
});
123123

src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,14 @@ function normalizeFiles(files: ConfigMap, rootDir: string): NormalizedConfigFile
242242
}
243243
}
244244

245+
const gitignoreEntry =
246+
entry.gitignore === false ? null : formatGitignoreEntry(normalizedRelative);
247+
245248
return {
246249
absolutePath,
247250
relativePath: normalizedRelative,
248251
contents,
249-
gitignoreEntry: entry.gitignore === false ? null : normalizedRelative,
252+
gitignoreEntry,
250253
mode: entry.mode,
251254
sentinel,
252255
} satisfies NormalizedConfigFile;
@@ -284,6 +287,14 @@ function normalizeRelativePath(relativePath: string): string {
284287
return posix.replace(/^\.\/(.*)/, '$1');
285288
}
286289

290+
function formatGitignoreEntry(relativePath: string): string {
291+
if (relativePath.startsWith('/')) {
292+
return relativePath;
293+
}
294+
295+
return `/${relativePath}`;
296+
}
297+
287298
async function syncFile(
288299
file: NormalizedConfigFile,
289300
options: { dryRun: boolean; encoding: BufferEncoding },

0 commit comments

Comments
 (0)