Skip to content

fix(angular-ivy): Adjust package entry points to support Angular 17 with SSR config #9412

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 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.');