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

feat(next): codegenDir and update .astro paths #11963

Open
wants to merge 18 commits into
base: next
Choose a base branch
from

Conversation

florian-lefebvre
Copy link
Member

@florian-lefebvre florian-lefebvre commented Sep 10, 2024

Changes

  • Moves dts from .astro/astro to .astro. My original plan in 4.14 was to move stuff from .astro to .astro/astro. I did that partially back then (for content, env and actions) but I revert it in this PR (see comments)
  • Adds codegenDir to astro:config:setup. Points to .astro/integrations/<normalized_integration_name>. This is convenient for integrations authors to be able to put files in a folder where they're sure they can't override files generated by Astro (eg. .astro/types.d.ts), nor files generated by another integration. In 4.14, we introduced injectTypes which writes files to this codegenDir directory already, so we just expose it now

Testing

Should still pass

Docs

Changeset, integration API docs. Will be done after this PR is approved

Copy link

changeset-bot bot commented Sep 10, 2024

🦋 Changeset detected

Latest commit: 0c30ceb

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Sep 10, 2024
@github-actions github-actions bot added the semver: major Change triggers a `major` release label Sep 10, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a major changeset. A reviewer will merge this at the next release if approved.

@florian-lefebvre florian-lefebvre marked this pull request as ready for review September 11, 2024 12:27
@Princesseuh
Copy link
Member

@florian-lefebvre
Copy link
Member Author

Done in withastro/language-tools#951

@bluwy
Copy link
Member

bluwy commented Sep 12, 2024

Why are we moving all the files one-level down? Don't we control .astro so we are free to structure it however we want? Is this making way for other integrations to put stuff in .astro without naming collisions? If that's true, I don't think we should be explicitly catering it as they should be using a unique enough name (like .astro/my-integration-special-data.json) to prevent collision chances.

@florian-lefebvre
Copy link
Member Author

ATM we can't control where people put stuff. I'm in favor of creating somle kind of convention (.astro/astro for core) there. At least that was the intent when doing injectTypes in 4.14. To protect ourselves even more, we'd need a injectAsset (probably bad name) that would do basically the same as injectTypes BUT for any file and without creating references.

@bluwy
Copy link
Member

bluwy commented Sep 12, 2024

Do we want to say that it's safe to put your stuff in .astro? There's always a risk borrowing a folder you don't own and putting stuff there, and I think it should apply here too.

Astro owns the .astro folder so I don't think we need to protect ourselves from integrations tampering it. If an integration caused a name conflict in the .astro folder or something else that caused Astro to crash, the integration should be fixing it, not us.

For injectTypes, I see it more as a way for integrations to easily add types and sync with our command. And deduplicates the same amount of work to construct and write types.

@florian-lefebvre
Copy link
Member Author

There's always a risk borrowing a folder you don't own and putting stuff there, and I think it should apply here too

It makes sense to me, as an integration author, to want to put codegen files in there since that's where astro does it. otherwise, that means you need to create your own .folder, add it to gitignore etc


As for the rest, I get your point, I guess we could move things outside of .astro/astro instead. I'd like to at least expose the directory .astro/integrations/<normalized> to integrations authors so that they can put stuff in there without conflicting with astro. wdyt?

@bluwy
Copy link
Member

bluwy commented Sep 12, 2024

I think it's fine for integrations to put stuff into .astro, just that we can't guarantee to not break your integration if we decide to add certain file names that could collide with yours. So if integrations want to avoid that risk, the names that they put in there should be unique enough.

For .astro/integrations/, I'm fine with that if it's only documentation that you're encouraged to put your assets there if needed. I'm not so sure about codifying the guarantee or like helping generate the folder. Maybe others having different thoughts on this.

@florian-lefebvre
Copy link
Member Author

Doesn't have to be in the beta so not urgent to answer. @Princesseuh when you have some time I'd like your opinion on that

@Princesseuh
Copy link
Member

I don't see a big need for the PR to be done now, as it seems very unlikely for integrations to conflict with our files. Perhaps in the future if we see a lot of code gen being done. I think this can also somewhat be done in a non-breaking way? It's only the JSON schemas that are breaking

I'm personally in favour of a dedicated .astro/integrations/{integration name} folder with an API for codegen, I think it makes it nicer for both end users and integration authors, since you don't need to manage .gitignore or folder creation and the structure is previsible for debugging (ah, all the files for {integration} are in this folder)

@florian-lefebvre
Copy link
Member Author

florian-lefebvre commented Sep 13, 2024

Alright then if you're both okay with that, I'll do the following:

  • close the language tools PR
  • move dts from .astro/astro to .astro
  • expose the integration dir as URL in astro:config:setup

But yeah it doesn't have to be a 5.0 thing

@florian-lefebvre florian-lefebvre changed the title feat(next): update .astro paths feat(next): codegenDir and update .astro paths Sep 18, 2024
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, with the little knowledge I have of injectTypes when I read this changeset, I failed to understand what codegenDir is for and how it is related to injectTypes.

For example, the following phrase doesn't say anything to me. I don't understand what space you're referring to, and how other integrations are involved in this feature.

It allows you to have space without risking being overriden by another integration

I would try to help with the review, but the poor description of the PR and the changeset don't help.

Can I ask you to revisit the changeset, and make a ELI5 version of it?

@florian-lefebvre
Copy link
Member Author

@ematipico I clarified both PR desc and changeset, thanks for the feedback!

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a suggestion. In the changeset you highlight the fact that integrations now don't conflict with each other, and the hook provide the reserved directory to do so.

However, nothing blocks users from doing new URL("../other-integration", codegenDir), and that's how integrations can tamper with each other. Sure, integrations shouldn't do that.

Instead, I think we should be stricter and provide callbacks so we have finer control, for example:

const integration = {
    name: 'my-integration',
    hooks: {
        'astro:config:setup': ({ writeToCodegenDir, purgeCodegenDir, readFromCodegeDir }) => {
						purgeCodegenDir();
						writeToCodegenDir(() => {
							return { filename: "file.ts", contents: "{}" }
						});
						const map = await readFromCodegeDir();
						for (const [filePath, contents] of map) {

						}
        }
    }
}

@ematipico ematipico dismissed their stale review September 19, 2024 08:32

No need to block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr pkg: astro Related to the core `astro` package (scope) semver: major Change triggers a `major` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants