Skip to content

Commit 4df8a35

Browse files
authored
Merge pull request #1141 from OpenFn/export-functions
Allow functions to be exported from job code
2 parents c263183 + 059cdcb commit 4df8a35

File tree

20 files changed

+89
-43
lines changed

20 files changed

+89
-43
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
This is a suite of examples of jobs.
22

3-
We don't really have a place where we can just write and test arbtirary job code with compilation.
3+
We don't really have a place where we can just write and test arbitrary job code with compilation.
44

55
You can do it through the CLI or worker but they have significant overheads.

integration-tests/execute/test/execute.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ test.serial('should return state', async (t) => {
2020
t.deepEqual(state, result);
2121
});
2222

23+
test.serial('allow export statements and functions', async (t) => {
24+
const state = {};
25+
26+
const job = `
27+
export const x = () => ({ x: 90 })
28+
fn(() => x())
29+
`;
30+
const result = await execute(job, state);
31+
32+
t.deepEqual(result, { x: 90 });
33+
});
34+
2335
test.serial('should use .then()', async (t) => {
2436
const state = { data: { x: 1 } };
2537

packages/cli/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @openfn/cli
22

3+
## 1.18.6
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [6bd4210]
8+
- @openfn/compiler@1.2.0
9+
310
## 1.18.5
411

512
### Patch Changes

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/cli",
3-
"version": "1.18.5",
3+
"version": "1.18.6",
44
"description": "CLI devtools for the OpenFn toolchain",
55
"engines": {
66
"node": ">=18",

packages/compiler/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @openfn/compiler
22

3+
## 1.2.0
4+
5+
### Minor Changes
6+
7+
- 6bd4210: Allow expressions to export named identifiers
8+
39
## 1.1.5
410

511
### Patch Changes

packages/compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/compiler",
3-
"version": "1.1.5",
3+
"version": "1.2.0",
44
"description": "Compiler and language tooling for openfn jobs.",
55
"author": "Open Function Group <admin@openfn.org>",
66
"license": "ISC",

packages/compiler/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import compile from './compile';
2-
export { default as getExports } from './getExports';
2+
export { default as getExports } from './get-exports';
33

44
export * from './util';
55
export type { TransformOptions } from './transform';

packages/compiler/src/transforms/ensure-exports.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import type { Transformer } from '../transform';
1111

1212
function visitor(path: NodePath<namedTypes.Program>) {
1313
// check the export statements
14-
// if we find any, we do nothing
15-
const currentExport = path.node.body.find(({ type }) => type.match(/Export/));
14+
// if we find any export default, assume this code is compiled
15+
// and do nothing
16+
const currentExport = path.node.body.find(({ type }) =>
17+
type.match(/ExportDefault/)
18+
);
1619
if (currentExport) {
1720
return true;
1821
}

packages/compiler/test/compile.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ test('ensure default exports is created', (t) => {
4444
t.is(result, expected);
4545
});
4646

47-
test('do not add default exports if exports exist', (t) => {
48-
const source = 'export const x = 10;';
49-
const expected = 'export const x = 10;';
47+
test('do not add default exports if default exports exist', (t) => {
48+
const source = 'export const x = 10;export default [];';
49+
const expected = 'export const x = 10;export default [];';
5050
const { code: result } = compile(source);
5151
t.is(result, expected);
5252
});

0 commit comments

Comments
 (0)