Skip to content

Commit

Permalink
fix(angular-ivy): Adjust package entry points to support Angular 17 w…
Browse files Browse the repository at this point in the history
…ith SSR config (#9412)

Adjust the entry points of `@sentry/angular-ivy`'s
`package.json` to point directly to FESM2015 bundles (= bundled ESM2015
code) instead of the UMD bundles. This fixes an error when the old (no
longer supported) UMD bundles were picked up by Vite in Angular apps
with SSR config (#9376).

A proper long term fix to this is to bump to Angular 15 in this package
which we can only do in a new major.
  • Loading branch information
Lms24 committed Oct 31, 2023
1 parent a8cf899 commit 1005925
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/angular-ivy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"build:watch": "yarn build:syncSymlinks && yarn build:transpile:watch",
"build:dev:watch": "yarn build:watch",
"build:transpile:watch": "ng build --watch",
"build:tarball": "npm pack ./build",
"build:tarball": "ts-node ./scripts/prepack.ts && npm pack ./build",
"build:syncSymlinks": "ts-node ./scripts/syncSourceFiles.ts",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage sentry-angular-ivy-*.tgz",
Expand All @@ -56,7 +56,7 @@
"lint": "run-s lint:prettier lint:eslint",
"lint:eslint": "eslint . --format stylish",
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"",
"yalc:publish": "yalc publish build --push --sig"
"yalc:publish": "ts-node ./scripts/prepack.ts && yalc publish build --push --sig"
},
"volta": {
"extends": "../../package.json"
Expand Down
27 changes: 27 additions & 0 deletions packages/angular-ivy/scripts/prepack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as fs from 'fs';
import * as path from 'path';

type PackageJson = {
main?: string;
type?: string;
nx?: string;
volta?: any;
};

const buildDir = path.join(process.cwd(), 'build');
const pkjJsonPath = path.join(buildDir, 'package.json');
const pkgJson: PackageJson = JSON.parse(fs.readFileSync(pkjJsonPath).toString());

// This is necessary for Angular 17+ compatibility when SSR is configured which switches dev mode to using Vite.
// Deleting "main" and adding "type": "module" will direct Vite to
// use the fesm2015 bundle instead of the UMD bundle.
delete pkgJson.main;
pkgJson.type = 'module';

// no need to keep around other properties that are only relevant for our reop:
delete pkgJson.nx;
delete pkgJson.volta;

fs.writeFileSync(pkjJsonPath, JSON.stringify(pkgJson, null, 2));

console.log('Adjusted package.json for Angular 17+ compatibility.');

0 comments on commit 1005925

Please sign in to comment.