Skip to content

fix: convert library to module#431

Merged
kanadgupta merged 3 commits intomainfrom
convert-to-module
Sep 27, 2023
Merged

fix: convert library to module#431
kanadgupta merged 3 commits intomainfrom
convert-to-module

Conversation

@kanadgupta
Copy link
Copy Markdown
Contributor

@kanadgupta kanadgupta commented Sep 27, 2023

🧰 Changes

Turns out that I got so lost in the sauce in #427 that this commit ended up breaking things for the Node ESM usage 😭 I for some reason assumed that tsup properly transpiles the require statements but evidently not...

Here's the stack trace of the error you see when running node example.mjs on the main branch:

Error: Dynamic require of "undici" is not supported
    at file:///Users/kanadg/Code/readmeio/fetch-har/dist/index.mjs:25:9
    at file:///Users/kanadg/Code/readmeio/fetch-har/dist/index.mjs:39:23
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
file:///Users/kanadg/Code/readmeio/fetch-har/dist/index.mjs:42
    throw new Error("The File API is required for this library. https://developer.mozilla.org/en-US/docs/Web/API/File");

The main function is now async since we're doing dynamic imports, but it has always returned a Promise<Response> so I think this should be a patch change?

🧬 QA & Testing

Check out this branch and try running the following commands to ensure they succeed:

# install + build
npm ci && npm run build

# run example scripts
node example.mjs
node example.cjs
deno run -A example.mjs
bun example.mjs
bun example.cjs

@kanadgupta kanadgupta added bug Something isn't working refactor Issues about tackling technical debt labels Sep 27, 2023
Comment thread src/index.ts
}

export default function fetchHAR(har: Har, opts: FetchHAROptions = {}) {
export default async function fetchHAR(har: Har, opts: FetchHAROptions = {}): Promise<Response> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is now async since we're doing dynamic imports, but it has always returned a Promise so I think this should be a patch change?

Comment thread test/index.test.ts
expect(fetchHAR).rejects.toThrow('Missing HAR definition');
// @ts-expect-error deliberately bad data
expect(fetchHAR.bind(null, { log: {} })).toThrow('Missing log.entries array');
expect(fetchHAR.bind(null, { log: {} })).rejects.toThrow('Missing log.entries array');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests needed to be refactored slightly in order to work again, but honestly I'm a little confused on why they were passing in the first place 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

believe they were passing before because fetcHAR wasn't async at that point that that invalid HAR error is thrown.

@kanadgupta kanadgupta marked this pull request as ready for review September 27, 2023 15:29
@kanadgupta kanadgupta merged commit 3cd0c58 into main Sep 27, 2023
@kanadgupta kanadgupta deleted the convert-to-module branch September 27, 2023 18:11
@kanadgupta kanadgupta mentioned this pull request Oct 5, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working refactor Issues about tackling technical debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants