Skip to content

Commit

Permalink
fix: ensure protected packages do not have devDeps on pack
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbuss committed Jan 15, 2025
1 parent a9de562 commit e8b47a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion configuration/vite-config/src/scripts/prepack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 7 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Import "LocalPackageJson" is only used as types

Check failure on line 7 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Import "LocalPackageJson" is only used as types
import { listInstalledPackages } from '../installedPackages';

prepack();
Expand All @@ -13,10 +13,39 @@ function prepack() {
console.info('*** Starting prepack. ***');
referenceCopiedProtectedPackages();
validateBuildArtifacts();
removeDevDependenciesFromProtectedPackages();
validatePrepack();
console.info('*** Ending prepack. ***');
}

/**
* @remarks
*

Check failure on line 23 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Delete `·`

Check failure on line 23 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Delete `·`
* 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 () {

Check failure on line 28 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Delete `·`

Check failure on line 28 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Delete `·`
const packageJson = fse.readJSONSync('./package.json') as LocalPackageJson;

const protectedPackageNames = listInstalledPackages(

Check failure on line 31 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Replace `⏎····packageJson,⏎···` with `packageJson,`

Check failure on line 31 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Replace `⏎····packageJson,⏎···` with `packageJson,`
packageJson,
{
filter: { scope: 'protected', dependencyType: 'dependencies' },

Check failure on line 34 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Delete `··`

Check failure on line 34 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Delete `··`
}

Check failure on line 35 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Replace `··}⏎··).map(installedPackage` with `}).map((installedPackage)`

Check failure on line 35 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Replace `··}⏎··).map(installedPackage` with `}).map((installedPackage)`
).map(installedPackage => installedPackage.name);

protectedPackageNames.forEach(protectedPackageName => {

Check failure on line 38 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Replace `protectedPackageName` with `(protectedPackageName)`

Check failure on line 38 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Replace `protectedPackageName` with `(protectedPackageName)`
const protectedPackageShortName = getShortName(

Check failure on line 39 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Replace `⏎······protectedPackageName⏎····` with `protectedPackageName`

Check failure on line 39 in configuration/vite-config/src/scripts/prepack.ts

View workflow job for this annotation

GitHub Actions / lint (vite-config)

Replace `⏎······protectedPackageName⏎····` with `protectedPackageName`
protectedPackageName
);
const jsonPath = `./dist/${protectedPackageShortName}/package.json`;
const json = fse.readJSONSync(jsonPath) as PackageJson;
json.devDependencies = {};
fse.writeJSONSync(jsonPath, json, { spaces: 2 });
});
}

/**
* @remarks
*
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e8b47a9

Please sign in to comment.