microsoft / rushstack

Monorepo for tools developed by the Rush Stack community
https://rushstack.io/
Other
5.82k stars 592 forks source link

[@rushstack/rush-sdk] No longer supports deep references to internal APIs. #4308

Open StarFishing opened 1 year ago

StarFishing commented 1 year ago

Problem: rush-sdk has added the exports field in his package.json field, which will make it unable to work as expected.

Summary

rush-sdk provide the ability to call the internal API, but the increase of the exports field leads to errors in the following usage methods.

image

Repro steps

Add a new node package and create a entry: src/index.ts

rush version: 5.100.2 @rushstack/rush-sdk:5.100.2 usage:

import { RushConfiguration } from '@rushstack/rush-sdk/lib/api/RushConfiguration';
console.log(RushConfiguration)

Expected result: I can still use the internal API in the way of path import.

rush version: 5.104.0 @rushstack/rush-sdk:5.104.0 usage:

import { RushConfiguration } from '@rushstack/rush-sdk/lib/api/RushConfiguration';
console.log(RushConfiguration)

Actual result: I got the error that the path has not been exported.

Details

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
Package name: @rushstack/rush-sdk
Package version? 5.104.0
Operating system? Mac
Would you consider contributing a PR? Yes
Node.js version (node -v)? 16.18.0
octogonz-dev commented 11 months ago

@StarFishing Could you add some repro steps to this issue so that we can debug it more easily?

Show some code that compiles successfully using the old version of rush-sdk, but the same code fails when using the latest rush-sdk. Thanks!

StarFishing commented 11 months ago

Supplement the reproduction steps

iclanton commented 11 months ago

RushConfiguration is exported directly from rush-sdk's index. Which exports specifically are you looking for? rush-sdk is intended to be very stable, since it's a wrapper around rush-lib provided to plugins at runtime, so the plugin may not exactly match the version of rush-lib specified in rush.json.

The issue with adding this back is that exports seems to require an exhaustive list, so we'd have to do this with a pre-pack script (similar to https://github.com/microsoft/rushstack/blob/main/libraries/rush-lib/scripts/plugins-prepublish.js). @StarFishing - would you be willing to put that together?

StarFishing commented 11 months ago

I used these api.

import { RushConfiguration } from '@rushstack/rush-sdk/lib/api/RushConfiguration';
import { PublishUtilities } from '@rushstack/rush-sdk/lib/logic/PublishUtilities';
import { Utilities } from '@rushstack/rush-sdk/lib/utilities/Utilities';
import { ChangeFile } from '@rushstack/rush-sdk/lib/api/ChangeFile';

If this way is abandoned, it seems that the package needs to be adjusted readme

image
kenrick95 commented 2 months ago

The other day I encountered this issue too while implementing a repo tool on top of Rush SDK.

The quick workaround that I use is to do a rush-pnpm patch @rushstack/rush-sdk, edit its package.json to remove the "exports" field.