Skip to content

ref(build): Introduce central build directory to packages with bundles #4838

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

Merged
merged 8 commits into from
Apr 5, 2022

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Apr 1, 2022

Background

This is the continuation of the build directory restructuring started in #4688. The goal is to put everything building related (i.e. compiled code and non-code assets for NPM tarballs) into one central directory.

Changes

This PR introduces the central build directory to all our packages producing CDN bundles in addition to NPM tarballs:

  • Browser
  • Integrations
  • Tracing
  • WASM

The new build directory for packages with CDN bundles will have the following structure:

<sdk>/
├─ build/
│  ├─ bundles/
│  │  ├─ CDN bundles (rollup) (es5, es6) (+min, maps)
│  ├─ npm/
│  │  ├─ build/ <-- this is just temporary and will be gone with v7
│  │  │  ├─ CDN bundles (rollup) (es5, es6) (+min, maps)
│  │  ├─ cjs/    // dist until v7
│  │  │  ├─ CJS modules (+maps)
│  │  ├─ esm/
│  │  │  ├─ ES6 modules (+maps)
│  │  ├─ types/
│  │  │  ├─ *.d.ts files (+maps)
│  │  ├─ package.json
│  │  ├─ LICENSE
│  |  ├─ README.md
│  ├─ npm-legacy/ <-- this is not included in this PR but will come once we introduce our ES5 legacy NPM tarballs
├─ ...

Inside the tarball, the directory structure is as follows*:

sentry-<sdk>-<version>.tgz/
├─ build/                        // bundles will be removed from the tarball in v7
│  ├─ CDN bundles
├─ dist/                        // will be changed to 'cjs' in v7
│  ├─ CJS modules (+maps)
├─ esm/
│  ├─ ES6 modules (+maps)
├─ types/
│  ├─ *.d.ts files (+maps)
├─ package.json
├─ LICENSE
├─ README.md

A small note here: CDN bundles will be removed from the tarball in v7. Until then, they remain in the build directory in the tarball, which should not be mistaken for the central build directory described above. I know, this is confusing but otherwise, this would be a breaking change for people unofficially using our CDN bundles e.g. via UNPKG.

*for WASM, CDN bundles are not added to the tarball as they were not previously included.

Procedure:

  • running yarn build will start compilation (no changes on this end).
  • running yarn build:npm starts the prepack script and subsequently creates the NPM tarball. The prepack.ts script:
    • copies all additional (non-code) files into build/npm
    • temporarily copies CDN bundles into the build/npm/build until v7
    • adjusts package.json entry points to align with the NPM tarball structure described above
    • deletes unnecessary properties from the copied package.json
  • running yarn build:npm will pack the NPM tarball from inside build/npm and save it in the package root directory.

Additional Information

"But what about Vue and WASM bundles!?" you might ask. Well, it turns out, those are created but not published. So we actually do not need to create them either for every build. To not clutter this PR too much, I'll deactivate the bundle creation by default in a separate one coming soon (TM).

How to best review: Every commit represents the changes for one package. For reviewing, it might be helpful to go through the changes commit-by-commit, starting with fd0da2c. I double and triple checked the correct tarball creation but given that a bug in this PR could easily break users, a second pair of eyes can't hurt.

ref: https://getsentry.atlassian.net/browse/WEB-780

@Lms24 Lms24 changed the title ref(build): convert postbuild.sh to node script ref(build): Introduce central build directory to packages with bundles Apr 1, 2022
@Lms24 Lms24 force-pushed the lms-build-dir-packges-w-bundles branch 7 times, most recently from 173880a to c889c0e Compare April 4, 2022 08:40
@Lms24 Lms24 marked this pull request as ready for review April 4, 2022 09:25
@Lms24 Lms24 requested a review from lobsterkatie April 4, 2022 09:25
@Lms24 Lms24 force-pushed the lms-build-dir-packges-w-bundles branch from c889c0e to 31e1f5d Compare April 4, 2022 16:31
@lobsterkatie
Copy link
Member

In addition, yarn build starts the postbuild script which:

  • copies all additional (non-code) files into build/npm
  • temporarily copies CDN bundles into the build/npm/build until v7
  • adjusts package.json entry points to align with the NPM tarball structure described above

It's fine if you want to leave it like this for this PR (and the one making this same change to the non-bundle packages), and then make a wholesale change separately, but the more I think about it, the more I think this work shouldn't happen on every build, since it's really only relevant to publishing and only a tiny fraction of builds go on to be published.

@lobsterkatie
Copy link
Member

How to best review: Every commit represents the changes for one package. For reviewing, it might be helpful to go through the changes commit-by-commit

Super tiny nit: Especially for a PR where the idea is to have each commit be one idea, and where you want to look at each commit as an entity in and of itself, it'd be great to have the first commit's message explain what that commit is (as all the others' respective messages do), rather than just be the PR title.

Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

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

LGTM!

@Lms24
Copy link
Member Author

Lms24 commented Apr 5, 2022

the more I think about it, the more I think this work shouldn't happen on every build

Yes you're right. My initial idea was to make the postbuild->prepack change in a separate PR but tbh I think this can still fit in this one. Especially, when considering that I'm basing the rest of the build dir conversions on this work here so I'd essentially be adding things to that branch of which I know that I'd change them directly afterwards again.

it'd be great to have the first commit's message explain what that commit is

Good point, thanks for mentioning it. I'll do better with the next PR coming soon.

Lms24 added 5 commits April 5, 2022 09:53
in this commit:
* move browser npm build files to `build/npm`
* adjust `postbuild.ts` for tmp copying of bundles into npm
adjust postbuild.ts to take optional CL arg to not tmp copy CDN bundles
@Lms24 Lms24 force-pushed the lms-build-dir-packges-w-bundles branch from 31e1f5d to 7d62442 Compare April 5, 2022 07:56
Lms24 added 2 commits April 5, 2022 10:00
add postbuild->prepack changes to `@sentry/browser`

add postbuild->prepack changes to `@sentry/integrations`

add postbuild->prepack changes to `@sentry/tracing`

add postbuild->prepack changes to `@sentry/wasm`
@Lms24 Lms24 force-pushed the lms-build-dir-packges-w-bundles branch from b327388 to 148ee3f Compare April 5, 2022 08:17
@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 20.21 KB (0%)
@sentry/browser - ES5 CDN Bundle (minified) 65.26 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.89 KB (-0.01% 🔽)
@sentry/browser - ES6 CDN Bundle (minified) 58.27 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 23.23 KB (0%)
@sentry/browser - Webpack (minified) 82.17 KB (0%)
@sentry/react - Webpack (gzipped + minified) 23.27 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.81 KB (-0.46% 🔽)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.15 KB (-0.01% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.5 KB (-0.01% 🔽)

for some reason, these tests require a `package.json` file in the `build`
directory. The quick fix is to simply run `prepack.ts` in Tracing after building
@Lms24 Lms24 merged commit 14b7962 into master Apr 5, 2022
@Lms24 Lms24 deleted the lms-build-dir-packges-w-bundles branch April 5, 2022 10:47
@AbhiPrasad AbhiPrasad added this to the Pre 7.0.0 Work milestone Apr 6, 2022
AbhiPrasad added a commit that referenced this pull request Apr 6, 2022
…dles (Part 1) (#4854)

This PR is part 1 of adding the `build` directory to packages _without_ CDN bundles. It is split into two parts to make reviewing easier. It covers the following packages:

* Core
* Gatsby
* Hub
* Minimal

Additionally, it adjusts `prepack.ts` to handle both kinds of packages (with/without CDN bundles) via a CL argument. For the Gatsby SDK, additional actions have to be performed which are only relevant for this package. Therefore, `prepack.ts` now supports calling a package-specific `prepack.ts` file located in `<package>/scripts/prepack.ts`. 

While the tarball structure is identical to the structure in #4838 (except for temporary CDN bundles), the `build` directory structure is simplified due to the fact that there are no CDN bundles or legacy NPM packages to be added to it. Therefore we can reduce one hierarchy level, resulting in the following structure:

```
<sdk>/
├─ build/
│  ├─ cjs/    // dist until v7
│  │  ├─ CJS modules (+maps)
│  ├─ esm/
│  │  ├─ ES6 modules (+maps)
│  ├─ types/
│  │  ├─ *.d.ts files (+maps)
│  ├─ package.json
│  ├─ LICENSE
│  ├─ README.md
├─ ...
```

Co-authored-by: Abhijeet Prasad <[email protected]>
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