Skip to content

Commit

Permalink
Merge pull request #724 from OpenFn/fix-common-exports
Browse files Browse the repository at this point in the history
describe-package: include common functions
  • Loading branch information
josephjclark authored Jun 27, 2024
2 parents d156311 + dac3ce1 commit b03f622
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 18 deletions.
7 changes: 7 additions & 0 deletions examples/dts-inspector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# dts-inspector

## 1.0.18

### Patch Changes

- Updated dependencies [6d01592]
- @openfn/describe-package@0.1.0

## 1.0.17

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/dts-inspector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dts-inspector",
"version": "1.0.17",
"version": "1.0.18",
"description": "",
"main": "index.js",
"type": "module",
Expand Down
8 changes: 8 additions & 0 deletions integration-tests/worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @openfn/integration-tests-worker

## 1.0.49

### Patch Changes

- @openfn/engine-multi@1.1.12
- @openfn/lightning-mock@2.0.12
- @openfn/ws-worker@1.2.2

## 1.0.48

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/worker/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openfn/integration-tests-worker",
"private": true,
"version": "1.0.48",
"version": "1.0.49",
"description": "Lightning WOrker integration tests",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @openfn/cli

## 1.4.2

### Patch Changes

- Updated dependencies [6d01592]
- @openfn/describe-package@0.1.0
- @openfn/compiler@0.1.4

## 1.4.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/cli",
"version": "1.4.1",
"version": "1.4.2",
"description": "CLI devtools for the openfn toolchain.",
"engines": {
"node": ">=18",
Expand Down
7 changes: 7 additions & 0 deletions packages/compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @openfn/compiler

## 0.1.4

### Patch Changes

- Updated dependencies [6d01592]
- @openfn/describe-package@0.1.0

## 0.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/compiler",
"version": "0.1.3",
"version": "0.1.4",
"description": "Compiler and language tooling for openfn jobs.",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
6 changes: 6 additions & 0 deletions packages/describe-package/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfn/describe-package

## 0.1.0

### Minor Changes

- 6d01592: Include common functions in the exported definitions

## 0.0.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/describe-package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/describe-package",
"version": "0.0.20",
"version": "0.1.0",
"description": "Utilities to inspect an npm package.",
"author": "Open Function Group <[email protected]>",
"license": "ISC",
Expand Down
18 changes: 17 additions & 1 deletion packages/describe-package/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type FunctionDescription = {
description: string;
examples: ExampleDescription[];
parent?: string;
package?: string; // the npm package that this definition came from
};

export type NamespaceDescription = {
Expand Down Expand Up @@ -69,6 +70,8 @@ export const describePackage = async (
const { name, version } = getNameAndVersion(specifier);
const project = new Project();

const commonFunctions: Record<string, FunctionDescription> = {};

if (name != '@openfn/language-common') {
// Include language-common in the project model
// (I don't expect this to be permanent)
Expand All @@ -95,6 +98,14 @@ export const describePackage = async (
f,
relativeFileName
);
project.createFile(f, fileName);

describeProject(project, fileName).forEach((member) => {
if (member.type === 'function') {
member.package = '@openfn/language-common';
commonFunctions[member.name] = member;
}
});
}
}
}
Expand All @@ -112,9 +123,14 @@ export const describePackage = async (

describeProject(project, fileName).forEach((member) => {
if (member.type === 'function') {
member.package = name;
functions.push(member);
} else if (member.type === 'namespace') {
namespaces.push(member);
if (commonFunctions[member.name]) {
functions.push(commonFunctions[member.name]);
} else {
namespaces.push(member);
}
}
});
}
Expand Down
8 changes: 0 additions & 8 deletions packages/describe-package/src/describe-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ const describeFunction = (
symbol: WrappedSymbol,
moduleName?: string
): FunctionDescription => {
let parent = undefined;
// If this is an export alias (exported from another package) say where it came from
if (symbol.isExportAlias) {
// @ts-ignore symbol.parent
[parent] = symbol.symbol.parent.escapedName.match(/(language-\w+)/);
}

return {
type: 'function',
name: moduleName ? `${moduleName}.${symbol.name}` : symbol.name,
Expand All @@ -64,7 +57,6 @@ const describeFunction = (
}
return { code: eg.trim() };
}),
parent,
};
};

Expand Down
1 change: 0 additions & 1 deletion packages/describe-package/test/describe-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ test('Load an example with caption', async (t) => {
test('Load common fn', async (t) => {
const fn = get('fn');
t.truthy(fn);
t.is(fn.parent, 'language-common');
});

test('Recognise a magic function', async (t) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/engine-multi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# engine-multi

## 1.1.12

### Patch Changes

- @openfn/compiler@0.1.4

## 1.1.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-multi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/engine-multi",
"version": "1.1.11",
"version": "1.1.12",
"description": "Multi-process runtime engine",
"main": "dist/index.js",
"type": "module",
Expand Down
6 changes: 6 additions & 0 deletions packages/lightning-mock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfn/lightning-mock

## 2.0.12

### Patch Changes

- @openfn/engine-multi@1.1.12

## 2.0.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/lightning-mock/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/lightning-mock",
"version": "2.0.11",
"version": "2.0.12",
"private": true,
"description": "A mock Lightning server",
"main": "dist/index.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/ws-worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ws-worker

## 1.2.2

### Patch Changes

- @openfn/engine-multi@1.1.12

## 1.2.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/ws-worker",
"version": "1.2.1",
"version": "1.2.2",
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
"main": "dist/index.js",
"type": "module",
Expand Down

0 comments on commit b03f622

Please sign in to comment.