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

[internal] Add more injection points #121

Merged
merged 18 commits into from
Feb 6, 2025

Conversation

yoannmoinet
Copy link
Member

@yoannmoinet yoannmoinet commented Dec 9, 2024

What and why?

Here we are again, rewriting the injection plugin for the 18th time.
We'd need to inject code banner and footer, but also within the context of the bundle, being able to add new import instructions for instance.

Especially for [rum] Inject browser sdk

How?

Some small update and fixes:

  • Factorise some helpers (esbuild entry parsing, unique id generation).
  • Fix some working directory issue with rollup and vite.
  • Detect duplicate plugin names, otherwise the previous ones get overridden by the new ones.

Big refactor of the injection plugin:

  • Split implementation of the injection plugin.
    • Each bundler is very much different, especially with the new needs of positional injection.
    • Re-implement some banner plugins closer to the bundler's API, to better support banner and footer (esbuild, webpack, rspack).
  • Create new injection points, START, MIDDLE and END.
  • Add more tests.

Note

Tests are refactored in #123

@yoannmoinet yoannmoinet force-pushed the yoann/add-more-injection-points branch from a331ba9 to bbe728b Compare December 9, 2024 15:28
@yoannmoinet yoannmoinet marked this pull request as ready for review January 16, 2025 10:24
@yoannmoinet yoannmoinet requested a review from elbywan January 16, 2025 10:24
@@ -24,12 +24,14 @@
},
"dependencies": {
"async-retry": "1.3.3",
"chalk": "2.3.1"
"chalk": "2.3.1",
"glob": "11.0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI node now supports OOTB glob (but it requires specific node version)

I'm not asking to change it, but just sharing knowledge hehehe

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh that's super nice, I didn't know.
I'm planning on bumping node version at some point this quarter.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Edit: it's still experimental TIL – link

image

Comment on lines +32 to +33
if (!filepath.includes('*')) {
return [filepath];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is enough to know if this is a valid path / something that has to be globed. For instance hello.{js,ts} has to go through glob

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a subset of glob for eslint.
From the link in the comment above, it only support * and /**/.

Comment on lines +57 to +58
entryPaths.push(
...Object.entries(entryPoints).map(([name, filepath]) => ({ name, path: filepath })),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Idk if this can happen, but if entryPoints is null, this will crash (typeof null is object)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, it can happen (according to the types).

// Resolve all the paths.
const proms = entryPaths
.flatMap((entry) =>
getAllEntryFiles(entry.path).map<[{ name?: string; path: string }, string]>((p) => [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pro tip: you can label tuples (not a request for change, just knowledge sharing):
getAllEntryFiles(entry.path).map<[entry: { name?: string; path: string }, path: string]>((p) => [

Comment on lines 144 to 145
},
...rollupPlugin(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to put ...rollupPlugin() before config(config) { to avoid having a field name config in rollupPlugin() overriding your config

onResolve: jest.fn(),
onLoad: jest.fn(),
onDispose: jest.fn(),
...options,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to move ...options to the 1st element to avoid being able to override the other fields. And if you want that to be its behavior, you should add a comment saying "All the methods before can be overridden in options" or something like that

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed options for overrides.

Copy link
Member

@elbywan elbywan left a comment

Choose a reason for hiding this comment

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

🔥

Base automatically changed from yoann/move-sourcemaps to master February 6, 2025 21:24
[tests] A better sandboxing of tests and builds
@yoannmoinet yoannmoinet requested a review from a team as a code owner February 6, 2025 21:24
@yoannmoinet yoannmoinet requested review from jckr and removed request for a team and jckr February 6, 2025 21:24
@yoannmoinet yoannmoinet merged commit 0558ca7 into master Feb 6, 2025
3 checks passed
@yoannmoinet yoannmoinet deleted the yoann/add-more-injection-points branch February 6, 2025 21:35
@yoannmoinet yoannmoinet mentioned this pull request Feb 9, 2025
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

Successfully merging this pull request may close these issues.

3 participants