From e8b47a9b5af4bea25d6d159c473b6bc586274db2 Mon Sep 17 00:00:00 2001 From: jmbuss Date: Wed, 15 Jan 2025 13:29:19 -0700 Subject: [PATCH] fix: ensure protected packages do not have devDeps on pack --- .../vite-config/src/scripts/prepack.ts | 31 ++++++++++++++++++- package-lock.json | 4 +-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/configuration/vite-config/src/scripts/prepack.ts b/configuration/vite-config/src/scripts/prepack.ts index b291b30d3..a0b81a74a 100755 --- a/configuration/vite-config/src/scripts/prepack.ts +++ b/configuration/vite-config/src/scripts/prepack.ts @@ -4,7 +4,7 @@ import { listRegisteredPackages } from '../packageRegistry'; import { getShortName, type PackageName } from '../package'; import type { PackageJson } from 'type-fest'; import { validateBuildArtifacts } from '../validation/validateBuildArtifacts'; -import { readPackageJson } from '../packageJson'; +import { LocalPackageJson, readPackageJson } from '../packageJson'; import { listInstalledPackages } from '../installedPackages'; prepack(); @@ -13,10 +13,39 @@ function prepack() { console.info('*** Starting prepack. ***'); referenceCopiedProtectedPackages(); validateBuildArtifacts(); + removeDevDependenciesFromProtectedPackages(); validatePrepack(); console.info('*** Ending prepack. ***'); } +/** + * @remarks + * + * Remove the devDependencies for the copied protected packages. + * This is to fix a bug where subsequent installs of the consuming + * package fail because it tries to read the devDependencies + */ +function removeDevDependenciesFromProtectedPackages () { + const packageJson = fse.readJSONSync('./package.json') as LocalPackageJson; + + const protectedPackageNames = listInstalledPackages( + packageJson, + { + filter: { scope: 'protected', dependencyType: 'dependencies' }, + } + ).map(installedPackage => installedPackage.name); + + protectedPackageNames.forEach(protectedPackageName => { + const protectedPackageShortName = getShortName( + protectedPackageName + ); + const jsonPath = `./dist/${protectedPackageShortName}/package.json`; + const json = fse.readJSONSync(jsonPath) as PackageJson; + json.devDependencies = {}; + fse.writeJSONSync(jsonPath, json, { spaces: 2 }); + }); +} + /** * @remarks * diff --git a/package-lock.json b/package-lock.json index 294bfd25a..6863af57b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36696,6 +36696,7 @@ "license": "Apache-2.0", "dependencies": { "@iot-app-kit/core": "*", + "@iot-app-kit/helpers": "*", "lodash-es": "^4.17.21", "pako": "^2.1.0", "parse-duration": "^1.0.3", @@ -36704,7 +36705,6 @@ "devDependencies": { "@aws-sdk/types": "^3.696.0", "@iot-app-kit/eslint-config": "*", - "@iot-app-kit/helpers": "*", "@iot-app-kit/ts-config": "*", "@iot-app-kit/vite-config": "*", "@types/lodash-es": "^4.17.12", @@ -37045,6 +37045,7 @@ "@iot-app-kit/charts-core": "^2.1.2", "@iot-app-kit/core": "*", "@iot-app-kit/core-util": "*", + "@iot-app-kit/helpers": "*", "@iot-app-kit/source-iotsitewise": "*", "@iot-app-kit/source-iottwinmaker": "*", "@popperjs/core": "^2.11.8", @@ -37082,7 +37083,6 @@ "devDependencies": { "@iot-app-kit/core": "*", "@iot-app-kit/eslint-config": "*", - "@iot-app-kit/helpers": "*", "@iot-app-kit/testing-util": "*", "@iot-app-kit/ts-config": "*", "@iot-app-kit/vite-config": "*",