How can I properly configure the package.json file in an npm monorepo to ensure that locally referenced packages resolve directly to their .ts files for IDE and build tooling compatibility (such as vscode, tsx, ts-node, vite, jest, tsc, etc.)?
I want to avoid local Typescript tasks (such as bundling, ts-jest testing, debugging) resolving to transpiled .js files in the dist folder or the .d.ts artifacts. These files may be out of date if the author forgets to rebuild after editing .ts files in src, or doesn't have a watch procedure in place. Ideally, these tasks should resolve directly to the original .ts files.
To better understand how to achieve this, I have created a sample monorepo at this link, focusing on how to point to Typescript source files within an npm-compatible package.json (not pnpm). You can view the example package.json for "@starter/multiply" and "@starter/sum" from the same repo to see how local resolutions work in various tools.
In the past, I relied on pnpm's tooling, which allows the "main" field of package.json to be overridden during publishing. The "main" field was set to "src/index.ts" during development and changed to "dist/index.cjs" later in the release process.
However, I am now exploring ways to achieve similar results with npm, as it does not support overriding the main field through publishConfig. I am unsure if there is a npm postpack step where I could script changes to the tar to set "main" permanently to "src/index.ts" locally and switch to .js before publishing.
The reference npm monorepo I provided has functioning tests, cached build tasks, and sourcemapping for debugging. However, the loaded source is not the .ts files even within the monorepo. Instead, main resolves to src/index.mjs, which imports from dist/index.js with sourcemapping back to src/index.ts. This leads to issues when the background build isn't rerun, resulting in outdated .js files.
I have raised a related ticket at https://github.com/microsoft/TypeScript/issues/51750 to suggest a solution, but I am curious if there are conventional approaches or tricks that others are using.