Skip to content
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

Fix alias exports #652

Merged
merged 7 commits into from
Apr 11, 2024
Merged

Fix alias exports #652

merged 7 commits into from
Apr 11, 2024

Conversation

josephjclark
Copy link
Collaborator

@josephjclark josephjclark commented Apr 9, 2024

This PR adds a little fix to describe-package which allows us to track export * as http from './http' style export aliases.

This has been a big problem and stops us using eg http.get in jobs.

The problem is that our wrapped-symbol.ts, which wraps up a TS symbol into something more manageable, is failing to recognise exports of the type export * as . Two small tweaks to wrapped-symbol fix it.

One thing to note is that the generated package description now includes a namespaces array as well as a functions array. The nice thing about this is that the new exports won't break anything unexpected - we're adding new information to an export, we're not changing existing information,

This fix will apply to the CLI and worker.

Related issue

Fixes #238 #363

@josephjclark josephjclark changed the base branch from main to release/next April 11, 2024 09:16
@josephjclark josephjclark marked this pull request as ready for review April 11, 2024 10:22
@josephjclark
Copy link
Collaborator Author

This job now works:

fn(async (state) => {
  const response = await http.get({ url: 'https://jsonplaceholder.typicode.com/todos/1' })(state);
  return {
    ...state,
    data: response.data
  }
})

Output:

[CLI] ♦ Versions:
         ▸ node.js                    18.12.1
         ▸ cli                        1.1.4
         ▸ @openfn/language-common    latest
[CLI] ✔ Installing packages...
[CLI] ✔ Installation complete in 336ms
[CLI] ✔ Compiled all expressions in workflow
The common.http.¬get function has been deprecated. This adaptor should migrate to use common.util.http instead.
[R/T] ✔ Completed step job-1 in 231ms
[CLI] ✔ Result: 
[CLI] ♦ {
  "data": {
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false
  }
}
[CLI] ✔ Finished in 650ms ✨

The same job against the production CLI fails (http not defined)

@josephjclark
Copy link
Collaborator Author

This works with the new common helpers (but only if I edit the adaptor to support the helpers, see OpenFn/adaptors#507 )

fn(async (state) => {
  const response = await util.request('GET', 'https://jsonplaceholder.typicode.com/todos/1');
  return {
    data: response.body
  }
})

@josephjclark josephjclark merged commit 3119323 into release/next Apr 11, 2024
5 checks passed
@josephjclark josephjclark deleted the fix-alias-exports branch April 12, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

describe-package: re-exported packages are not tracked
1 participant