Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerunning projen cannot proceed due to existing license. #3533

Closed
raurir opened this issue Apr 19, 2024 · 10 comments
Closed

Rerunning projen cannot proceed due to existing license. #3533

raurir opened this issue Apr 19, 2024 · 10 comments

Comments

@raurir
Copy link

raurir commented Apr 19, 2024

Projen can no longer synth. Issue surfaced when upgrading from 0.79.24 to 0.81.0.

Error is:
Error: There is already a file under LICENSE (

throw new Error(`There is already a file under ${rootProjectPath}`);
)

I looked through code changes since .79.24 but to no avail, sorry.

Macos, node v21.2.0

@mrgrain
Copy link
Contributor

mrgrain commented Apr 19, 2024

Thanks for reporting. We'll need your project type and config.

@mrgrain
Copy link
Contributor

mrgrain commented Apr 19, 2024

You can probably fix this by removing your LICENSE file manually.

@raurir
Copy link
Author

raurir commented Apr 20, 2024

You can probably fix this by removing your LICENSE file manually.

Hi, that was my first attempt... no luck. I have tried quite a few more tricks to narrow down the scope of the problem... no luck.

Re: project type (easy enough) and config, do you want the whole projenrc.ts?

@mrgrain
Copy link
Contributor

mrgrain commented Apr 20, 2024

As much as you can share. I'll just need to reproduce the issue somehow.

@raurir
Copy link
Author

raurir commented Apr 22, 2024

As much as you can share. I'll just need to reproduce the issue somehow.

This is a recently adopted project on my half, so not entirely sure for the reasoning behind this approach we are using, but I have narrowed it down to some custom license generation code:

export const licenseFile = (project: Project) => {
  project.tryRemoveFile("LICENSE");
  new TextFile(project, "LICENSE", { lines: getLongLicense() }); // line 3
};

Since we are running a monorepo with multiple projects, the license files were wanted to be added in many places. (ie licenseFile is called in multiple spots like licenseFile(api), licenseFile(website) etc. Disabling line 3 above fixes the projen synth, but then apache licenses show up everywhere in the repository :)

Created a repo which demonstrates the above. Thanks in advance!

@mrgrain
Copy link
Contributor

mrgrain commented Apr 22, 2024

Thanks for the reproduction! I'll have a look.

so not entirely sure for the reasoning behind this approach we are using

My best guess is that you are using a custom/customized license (as in a license text that is not supported by projen).

@raurir
Copy link
Author

raurir commented Apr 22, 2024

My best guess is that you are using a custom/customized license (as in a license text that is not supported by projen).

It is simply plain text, I am unsure how it could be unsupported. Anyhow thanks for looking, keen to hear your feedback. :)

@raurir
Copy link
Author

raurir commented Apr 29, 2024

Thanks for the reproduction! I'll have a look.

Hi, were you able to reproduce this issue? Thanks in advance.

@mrgrain
Copy link
Contributor

mrgrain commented Apr 29, 2024

Yes, apologies. Here's what's happening:

  1. Your code is adding a LICENSE file
  2. Your code attempts to remove an existing license with project.tryRemoveFile("LICENSE");, but it's executed first, so this has no effect.
  3. PDK is then attempting to add a LICENSE file as part of preSynthesize. This is kind of bad, because if it is doing it there it should check if a license already exists. It kind of does that, but only on a component level, not a file level. PDK checks for instanceof projen.License but you have just added a textfile.
  4. 💥

To fix this, you need to tell PDK to not add licenses:

const monorepo = new MonorepoTsProject({
 // other options
  licenseOptions: {
    disableDefaultLicenses: true,
  },
});

This is not really a bug in projen, but the error could be much better.
You should consider re-opening this issue in the PDK repo: https://github.com/aws/aws-pdk (cc @agdimech)

@mrgrain mrgrain closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
@raurir
Copy link
Author

raurir commented May 21, 2024

Unfortunately we are stuck in an upgrade loop, and we need the latest version of pdk to fix this (licenseOptions does not exist...)

Referencing that upgrade issue here: aws/aws-pdk#784

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants