forked from highlight/highlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolving highlight client from firstload - attempt 2 (highlight#4958)
## Summary <!-- Ideally, there is an attached GitHub issue that will describe the "why". If relevant, use this section to call out any additional information you'd like to _highlight_ to the reviewer. --> This is another attempt at highlight#4851, which had to be [reverted](highlight#4950) because it broke type declarations. 😞 TypeScript isn't planning to officially support import path rewriting in declarations (see microsoft/TypeScript#31643 (comment)), so to fully support arbitrary path remappings (like the ones to `@highlight-run/client`), the most promising solution I could find involved a combination of [ttypescript](https://github.com/cevek/ttypescript), [ts-transform-paths](https://github.com/zerkalica/zerollup/tree/master/packages/ts-transform-paths), and [rollup-plugin-typescript2](https://github.com/ezolenko/rollup-plugin-typescript2). However in our case, we're only looking to remap a single reference, so a dumb script that looks for the reference and replaces them feels like a much simpler & lower risk solution. That's what I added in this PR in addition to the previously reverted changes. Let me know if y'all would prefer looking into the other approach instead, which might be worthwhile if we wanted to start using arbitrary path remappings in libraries (say, to be able use absolute imports everywhere). ## How did you test this change? <!-- Frontend - Leave a screencast or a screenshot to visually describe the changes. --> I ran `yarn build && yarn typegen` in both main and this branch, and ran `diff -rq` to compare both dist folders. There were no differences in any of the .d.ts files (indicating the import replacement script gave us the correct output), and the only differences were in `index.js`, `indexESM.js`, and their respective importmaps, due to the changes in the package.json file that ends up getting bundled. ![Screenshot 2023-04-12 at 4 43 37 PM](https://user-images.githubusercontent.com/6934200/231610022-ac690d7c-860b-419b-ba96-1287e296b491.png) ## Are there any deployment considerations? <!-- Backend - Do we need to consider migrations or backfilling data? --> This time I did make sure to include type declarations in the build output comparison, so I have pretty high confidence they'll behave identically this time. Though one thing I couldn't confirm was whether the CI process that publishes this module runs the `yarn typegen` command or `yarn tsc` directly. The latter could produce the same problematic output as before since we depend on the script specified in `yarn typegen` to rewrite imports. Would appreciate it if someone could double check. 🙏
- Loading branch information
1 parent
3cdcf40
commit 59247b5
Showing
9 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import readdirp from 'readdirp' | ||
import * as path from 'node:path' | ||
import * as fs from 'node:fs' | ||
|
||
const workingDirectory = path.join(process.cwd(), './dist/firstload') | ||
const clientDirectory = path.join(process.cwd(), './dist/client') | ||
|
||
const files = await readdirp.promise(workingDirectory, { | ||
fileFilter: '**/**.d.ts', | ||
}) | ||
|
||
const text = ` from '@highlight-run/client/` | ||
await Promise.all( | ||
files.map(async ({ fullPath }) => { | ||
const content = await fs.promises.readFile(fullPath, 'utf-8') | ||
|
||
if (!content.includes(text)) return | ||
|
||
return fs.promises.writeFile( | ||
fullPath, | ||
content.replaceAll( | ||
text, | ||
` from '${path.relative( | ||
path.dirname(fullPath), | ||
clientDirectory, | ||
)}/`, | ||
), | ||
) | ||
}), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters