New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Create subpackages for internal-ish code #2351
base: master
Are you sure you want to change the base?
[WIP] Create subpackages for internal-ish code #2351
Conversation
|
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @steveluscher and the rest of your teammates on Graphite |
@@ -3,7 +3,6 @@ | |||
"version": "0.0.0", | |||
"private": true, | |||
"files": [ | |||
"add-js-extension-to-types.mjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nuked this, in favour of actually adding the .js extension everywhere.
@@ -25,7 +25,7 @@ export function getBaseConfig(platform: Platform, formats: Format[], _options: O | |||
__REACTNATIVE__: `${platform === 'native'}`, | |||
__VERSION__: `"${env.npm_package_version}"`, | |||
}, | |||
entry: [`./src/index.ts`], | |||
entry: ['./src/index.ts', './src/__internal.ts'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the build pick up this __internal.ts
entrypoint if it exists.
@@ -70,6 +70,7 @@ export function getBaseConfig(platform: Platform, formats: Format[], _options: O | |||
platform: platform === 'node' ? 'node' : 'browser', | |||
pure: ['process'], | |||
sourcemap: format !== 'iife' || isDebugBuild, | |||
splitting: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prevents tsup
from doing fancy bundle splitting between entrypoints.
@@ -0,0 +1 @@ | |||
export * from './stack-trace.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's that new ‘internal stuff’ entrypoint.
@@ -1,4 +1,5 @@ | |||
import { safeCaptureStackTrace, SOLANA_ERROR__RPC__INTEGER_OVERFLOW, SolanaError } from '@solana/errors'; | |||
import { SOLANA_ERROR__RPC__INTEGER_OVERFLOW, SolanaError } from '@solana/errors'; | |||
import { safeCaptureStackTrace } from '@solana/errors/internal'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example of making use of the internal subpackage.
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fancy new resolution strategy that allows all of this to work.
moduleNameMapper: { | ||
// Strip `.js` from imports | ||
// https://github.com/swc-project/jest/issues/64#issuecomment-1029753225 | ||
'^(\\.{1,2}/.*)\\.js$': '$1', | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course Jest doesn't know any of this, so we have to re-strip the .js extensions.
Ugh it's so sad because I do love the end result but I cannot bear having to use Is there no way we can do this as a build step instead? |
Do what; add the extensions? No, because once you change to |
2f890a3
to
e057dc3
Compare
Well, adding What I'm saying is, instead of using the module resolution, can we not replicate the changes that this does at compile time to make subpackages work properly? What exactly is |
Oh I see, as a consumer of our own API, we need |
e057dc3
to
39c0653
Compare
Summary
The entire problem that this PR tries to solve is this.
export * from '@solana/errors'
inpackages/library/
safeCaptureStackTrace()
from being exported frompackages/library/
The steps taken to that end were:
moduleResolution
everywhere toNodeNext
. This enables subpackage exports.js
extensions everywhere to satisfy that resolution regime@solana/errors
for all of the stuff that we want to share internally but not to export frompackages/library/
Now any package in the
@solana
scope can use@solana/errors/internal
but we can still enjoy the simplicity ofexport * from '@solana/errors'
inpackages/library/