projen deletes .projenrc.js if it contains "~~ Generated by projen"
See original GitHub issueI ran into this footgun while setting up projen for a Python project. I needed a .ini config file for flake8, but there didn’t seem to be an designated way to make one, so I figured I’d just use a TextFile
for the time being, and included the ~~ Generated by projen
comment I’d seen put into other files (the TextFile
doesn’t have an option to add it automatically):
// .projenrc.js
const { python, tasks, TextFile } = require('projen');
const project = new python.PythonProject({
jsiiFqn: "projen.python.PythonProject",
name: 'example',
version: '0.1.0',
moduleName: 'example',
});
// Including the ~~ Generated by ... line makes projen treat this file as
// generated, so it deletes it when synthesizing
new TextFile(project, '.flake8', {
lines: `\
; ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".
[flake8]
exclude = .git,__pycache__,.env,dist
max-line-length = 80
select = C,E,F,W,B,B950
ignore = E203, E501, W503
`.split('\n')
});
project.synth();
When I ran projen I found it’d deleted .projenrc.js
.
After poking around, I see that cleanup.ts uses this comment to identify and remove generated files. So I can avoid it getting deleted like this:
const { python, tasks, TextFile, PROJEN_MARKER } = require('projen');
// [...]
new TextFile(project, '.flake8', {
lines: `\
; ${PROJEN_MARKER}. To modify, edit .projenrc.js and run "npx projen".
[flake8]
; [...]
`.split('\n')
});
I don’t know the project well enough to suggest a good solution. But simply excluding .projenrc.js
from cleanup seems reasonable, as presumably it always has to exist.
Another thought would be to require confirmation before deleting files with uncommitted changes, but that would result in projen complaining when tweaking a projen config & synthesizing a few times between commits.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Ah, sorry if that caused some frustration. It’s also possible to use
TextFile.PROJEN_MARKER
to access the magic string for your own components.This issue is also similar to #609 - you can also use the suggestion posted there (
project.addExcludeFromCleanup(pattern)
) if you run into further problems. We should document the cleanup behavior at some point.I think I agree, it makes sense for .projenrc.js to be excluded from the default cleanup processes. This should be a simple fix, I can’t immediately think of any reasons why not.
I’ve also gone ahead and created an issue to track adding a dedicated
IniFile
component in #646. 🙂Closing this issue as it hasn’t seen activity for a while. Please add a comment @mentioning a maintainer to reopen.