question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

projen deletes .projenrc.js if it contains "~~ Generated by projen"

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Chriscbrcommented, Mar 24, 2021

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. 🙂

0reactions
github-actions[bot]commented, Jul 8, 2021

Closing this issue as it hasn’t seen activity for a while. Please add a comment @mentioning a maintainer to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Projen: NodeJS project boilerplating | by Mykhailo Gorianskyi
First off — you might have already noticed that most of the generated (“synthesized”) files are read-only. This is a nod to the...
Read more >
How to simplify project setup with Projen - Tidy Cloud AWS
I will delete the generated sample files (src and test), and I will change the cdkVersion property in .projenrc.js to use a release...
Read more >
projenrc.gitignore entries ordering unexpected, ...
I'm evaluating projen for a CDK-Construct Lib project. Due to project requirements I have some .gitignore entries that conflict with the ...
Read more >
API Reference | projen
The Dependencies component is responsible to track the list of dependencies a project has, and then used by project types as the model...
Read more >
A Beginner's Guide to Create AWS CDK Construct Library ...
projen does not only generate various files during project ... Once you have edited .projenrc.js , run the projen command to reflect the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found