Compiler: add default export even if there's an export already in the code (strict check for default export, not just /export/)
@doc-han is already working on this.
Since Nov 23, 2024.
- Dominant language
- TypeScript
- Stars
- 21
- Forks
- 23
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 17
Description
Description.
Runtime seems to always require a compiled job to have a default export of an array. Hence, those without a default export break the runtime.
Because
- we access the default export.
https://github.com/OpenFn/kit/blob/4376f7b3e615c0b0144deecf6d65d4a03dbb3abf/packages/runtime/src/execute/expression.ts#L146 - we expect an array and want to iterate it
https://github.com/OpenFn/kit/blob/4376f7b3e615c0b0144deecf6d65d4a03dbb3abf/packages/runtime/src/execute/expression.ts#L53
Currently,
We create a default export and then put all top-level-expressions in it. If there's no top-level-expression and empty array is exported to make the runtime happy.
export default []; // to make runtime happy!
But,
when there's an export (either named or not) that isn't a default export, we ignore the creation of the default export which makes the runtime sad.
There might be programs to be run in this job but because of a single non-default export. They don't get executed.
eg.
import {fn} from "@openfn/common"
fn(state => {
state.data.name = "doc-han"
return state;
})
export const han = "Han"; // prevents our runtime from running
fn(() => {
state.data.isGithub = true;
return state;
})
Is there a reason we don't accommodate this? @josephjclark
I feel we can have other exports and still generate our default export. Also, if the user provides a default export(which isn't encouraged) we can also check if it exports an Array.
Here we do a regex match.
https://github.com/OpenFn/kit/blob/4376f7b3e615c0b0144deecf6d65d4a03dbb3abf/packages/compiler/src/transforms/ensure-exports.ts#L15
For the concern of having several types of export nodes. A default export seems to always have only one type of Node representation. The name of the node only changes across ast-generator.
Proposed solution.
- Instead of regex matching the type 'Export ', Look for default export node instead.
- check if the default export node has declaration that's an Array
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.