diff --git a/packages/angular-ivy/package.json b/packages/angular-ivy/package.json index 7bc79f4bf234..192c93145008 100644 --- a/packages/angular-ivy/package.json +++ b/packages/angular-ivy/package.json @@ -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", @@ -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" diff --git a/packages/angular-ivy/scripts/prepack.ts b/packages/angular-ivy/scripts/prepack.ts new file mode 100644 index 000000000000..b9ec3f0d787f --- /dev/null +++ b/packages/angular-ivy/scripts/prepack.ts @@ -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.');