From d34f9c4a1367d9b74803a1b703c05d379176beec Mon Sep 17 00:00:00 2001 From: Robbert Broersma Date: Sun, 23 Jun 2024 18:50:39 +0200 Subject: [PATCH 1/2] build: use pnpm `publishConfig.directory` feature for Angular This way we don't need to copy the package.json config from dist/ to the config in the root of the package. --- packages/component-library-angular/package.json | 16 ++++------------ pnpm-lock.yaml | 3 ++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/component-library-angular/package.json b/packages/component-library-angular/package.json index cb3e8a6485d..c0d1be5b35d 100644 --- a/packages/component-library-angular/package.json +++ b/packages/component-library-angular/package.json @@ -9,7 +9,9 @@ ], "private": false, "publishConfig": { - "access": "public" + "access": "public", + "directory": "dist", + "linkDirectory": true }, "repository": { "type": "git+ssh", @@ -94,15 +96,5 @@ }, "module": "dist/fesm2022/utrecht-component-library-angular.mjs", "typings": "dist/index.d.ts", - "exports": { - "./package.json": { - "default": "./dist/package.json" - }, - ".": { - "types": "./dist/index.d.ts", - "esm2022": "./dist/esm2022/utrecht-component-library-angular.mjs", - "esm": "./dist/esm2022/utrecht-component-library-angular.mjs", - "default": "./dist/fesm2022/utrecht-component-library-angular.mjs" - } - } + "exports": {} } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 77a69fb4422..5ff6ef007fa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1200,6 +1200,7 @@ importers: zone.js: specifier: 0.14.3 version: 0.14.3 + publishDirectory: dist packages/component-library-css: devDependencies: @@ -4466,7 +4467,7 @@ importers: version: link:../../components/button '@utrecht/component-library-angular': specifier: workspace:* - version: link:../component-library-angular + version: link:../component-library-angular/dist '@utrecht/design-tokens': specifier: workspace:* version: link:../../proprietary/design-tokens From 35aa00aea0172eacaf027638ccbff1d36ae2d55f Mon Sep 17 00:00:00 2001 From: Robbert Broersma Date: Sun, 23 Jun 2024 18:57:14 +0200 Subject: [PATCH 2/2] chore: remove `package.json` testing script for Angular Now that we use `publishConfig.directory` we no longer need this. --- .../component-library-angular/CONTRIBUTING.md | 11 ---- .../component-library-angular/package.json | 1 - .../test-exports.mjs | 58 ------------------- 3 files changed, 70 deletions(-) delete mode 100644 packages/component-library-angular/CONTRIBUTING.md delete mode 100644 packages/component-library-angular/test-exports.mjs diff --git a/packages/component-library-angular/CONTRIBUTING.md b/packages/component-library-angular/CONTRIBUTING.md deleted file mode 100644 index 2ef832ac272..00000000000 --- a/packages/component-library-angular/CONTRIBUTING.md +++ /dev/null @@ -1,11 +0,0 @@ -# Contributing to the Angular component library - -## npm package - -The Angular packager builds a `package.json` file in the `dist/` directory. The Angular build process takes the responsibility to configure the exports in various properties (such as the `exports` and `typings` properties). - -We haven't found a way to publish the package from `dist/` using our current setup, so as a workaround we have manually copied the export properties from `dist/package.json` to `package.json` and corrected the paths to point to the `dist/` directory. - -When you upgrade Angular, you will need to manually ensure the configurations are still in sync. - -We included a test script `test-export.mjs` to warn when the configurations are out of sync. diff --git a/packages/component-library-angular/package.json b/packages/component-library-angular/package.json index c0d1be5b35d..2d676ab35ba 100644 --- a/packages/component-library-angular/package.json +++ b/packages/component-library-angular/package.json @@ -29,7 +29,6 @@ "watch:build": "ng build --watch", "test-results": "jest --json --outputFile=dist/.jest-test-results.json --silent", "test": "jest --coverage --verbose", - "test-build": "node test-exports.mjs", "watch:test": "NODE_OPTIONS=--experimental-vm-modules jest --verbose --watch" }, "dependencies": { diff --git a/packages/component-library-angular/test-exports.mjs b/packages/component-library-angular/test-exports.mjs deleted file mode 100644 index 3059d7229a6..00000000000 --- a/packages/component-library-angular/test-exports.mjs +++ /dev/null @@ -1,58 +0,0 @@ -import { resolve } from 'node:path'; -import { readFile } from 'node:fs/promises'; -import { access, constants } from 'node:fs/promises'; -import isEqual from 'lodash.isequal'; -import cloneDeepWith from 'lodash.clonedeepwith'; - -const getSubset = (pkg) => ({ - module: pkg.module, - typings: pkg.typings, - exports: pkg.exports, -}); - -const getAbsoluteSubset = (base, pkg) => - cloneDeepWith(getSubset(pkg), (value) => (typeof value === 'string' ? resolve(base, value) : undefined)); - -const getPaths = (pkg) => - [ - pkg.module, - pkg.typings, - ...(pkg.exports - ? Object.values(pkg.exports) - .map((item) => Object.values(item)) - .reduce((a, b) => [...a, ...b], []) - : []), - ].filter(Boolean); - -const getAbsolutePaths = (base, pkg) => getPaths(pkg).map((path) => resolve(base, path)); - -const testPathExistence = (paths) => - paths - .map((path) => resolve(path)) - .forEach(async (path) => { - try { - await access(path, constants.R_OK); - console.log(`File exists: ${path}`); - } catch (e) { - throw new Error(`Cannot find file mentioned in package.json: ${path}`); - } - }); - -const init = async () => { - const packageJSON = JSON.parse(await readFile('./package.json', 'utf-8')); - const distPackageJSON = JSON.parse(await readFile('./dist/package.json', 'utf-8')); - - const subset = getAbsoluteSubset('', packageJSON); - const referenceSubset = getAbsoluteSubset('dist/', distPackageJSON); - - if (!isEqual(subset, referenceSubset)) { - console.log(`package.json:\n${JSON.stringify(subset, null, 2)}`); - console.log(`dist/package.json:\n${JSON.stringify(referenceSubset, null, 2)}`); - - throw new Error( - 'Exports of package.json and dist/package.json are not in sync. See CONTRIBUTING.md for more info.', - ); - } -}; - -init();