Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Make plugin version optional #133

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## UNRELEASED

- Add functions and example for accessing PostgreSQL [#119](https://github.com/hypermodeAI/functions-as/pull/119)
- Make plugin version optional [#133](https://github.com/hypermodeAI/functions-as/pull/133)

## 2024-07-10 - Version 0.9.4

Expand Down
1 change: 0 additions & 1 deletion examples/classification/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/classification/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "classification-example",
"private": true,
"version": "1.0.0",
"description": "Hypermode Functions Classification Example",
"author": "Hypermode, Inc.",
"license": "MIT",
Expand Down
1 change: 0 additions & 1 deletion examples/collection/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/collection/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "collection-example",
"private": true,
"version": "1.0.0",
"description": "Hypermode Functions Collection Example",
"author": "Hypermode, Inc.",
"license": "MIT",
Expand Down
1 change: 0 additions & 1 deletion examples/embedding/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/embedding/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "embedding-example",
"private": true,
"version": "1.0.0",
"description": "Hypermode Functions Embedding Example",
"author": "Hypermode, Inc.",
"license": "MIT",
Expand Down
1 change: 0 additions & 1 deletion examples/graphql/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/graphql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "graphql-example",
"private": true,
"version": "1.0.0",
"description": "Hypermode Functions GraphQL Example",
"author": "Hypermode, Inc.",
"license": "MIT",
Expand Down
1 change: 0 additions & 1 deletion examples/http/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/http/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "http-example",
"private": true,
"version": "1.0.0",
"description": "Hypermode Functions HTTP Example",
"author": "Hypermode, Inc.",
"license": "MIT",
Expand Down
1 change: 0 additions & 1 deletion examples/postgresql/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/postgresql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "postgresql-example",
"private": true,
"version": "1.0.0",
"description": "Hypermode Functions Example using PostgreSQL database",
"author": "Hypermode, Inc.",
"license": "MIT",
Expand Down
1 change: 0 additions & 1 deletion examples/simple/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/simple/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "simple-example",
"private": true,
"version": "1.0.0",
"description": "Hypermode Functions Simple Example",
"author": "Hypermode, Inc.",
"license": "MIT",
Expand Down
1 change: 0 additions & 1 deletion examples/textgeneration/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/textgeneration/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "text-generation-example",
"private": true,
"version": "1.0.0",
"description": "Hypermode Functions Text Generation Example",
"author": "Hypermode, Inc.",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/bin/build-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ if (!npmPath) {
process.exit(1);
}

if (!pkg || !ver) {
console.error("A package name and version must be defined in package.json.");
if (!pkg) {
console.error("A package name must be defined in package.json.");
process.exit(1);
}

Expand Down
22 changes: 16 additions & 6 deletions src/transform/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class HypermodeMetadata {
buildId: string;
buildTs: string;
plugin: string;
library: string;
sdk: string;
gitRepo?: string;
gitCommit?: string;
functions: FunctionSignature[] = [];
Expand All @@ -26,7 +26,7 @@ export class HypermodeMetadata {
m.buildId = new Xid().toString();
m.buildTs = new Date().toISOString();
m.plugin = getPluginInfo();
m.library = getHypermodeInfo();
m.sdk = getSdkInfo();

if (isGitRepo()) {
m.gitRepo = getGitRepo();
Expand Down Expand Up @@ -104,8 +104,8 @@ export class HypermodeMetadata {

writeHeader("Plugin Metadata:");
writeTable([
["Plugin Name", this.plugin],
["Library", this.library],
["Name", this.plugin],
["SDK", this.sdk],
["Build ID", this.buildId],
["Build Timestamp", this.buildTs],
this.gitRepo ? ["Git Repo", this.gitRepo] : undefined,
Expand All @@ -132,7 +132,7 @@ export class HypermodeMetadata {
}
}

function getHypermodeInfo(): string {
function getSdkInfo(): string {
const filePath = path.join(
path.dirname(fileURLToPath(import.meta.url)),
"..",
Expand All @@ -141,12 +141,22 @@ function getHypermodeInfo(): string {
);
const json = readFileSync(filePath).toString();
const lib = JSON.parse(json);
return `${lib.name}@${lib.version}`;
return `${lib.name.split("/")[1]}@${lib.version}`;
}

function getPluginInfo(): string {
const pluginName = process.env.npm_package_name;
const pluginVersion = process.env.npm_package_version;

if (!pluginName) {
throw new Error("Missing name in package.json");
}

if (!pluginVersion) {
// versionless plugins are allowed
return pluginName;
}

return `${pluginName}@${pluginVersion}`;
}

Expand Down