From 8db1f39b33a8de8e9d136b939b84046f43c78079 Mon Sep 17 00:00:00 2001 From: vectronic Date: Wed, 5 Mar 2025 23:16:47 +0000 Subject: [PATCH 1/2] feat: migrate to bun --- .github/workflows/check-bun-dependencies.yml | 9 + .github/workflows/lint-pr-message.yml | 11 ++ .github/workflows/release-bun-library.yml | 8 + .github/workflows/validate-bun-library-pr.yml | 8 + .gitignore | 177 ++++++++++++++++++ README.md | 65 ++++++- bun.lock | 35 ++++ index.ts | 1 + package.json | 19 ++ src/ExamplePlugin.ts | 42 +++++ tests/ExamplePlugin_test.ts | 26 +++ tsconfig.json | 27 +++ 12 files changed, 427 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check-bun-dependencies.yml create mode 100644 .github/workflows/lint-pr-message.yml create mode 100644 .github/workflows/release-bun-library.yml create mode 100644 .github/workflows/validate-bun-library-pr.yml create mode 100644 .gitignore create mode 100644 bun.lock create mode 100644 index.ts create mode 100644 package.json create mode 100644 src/ExamplePlugin.ts create mode 100644 tests/ExamplePlugin_test.ts create mode 100644 tsconfig.json diff --git a/.github/workflows/check-bun-dependencies.yml b/.github/workflows/check-bun-dependencies.yml new file mode 100644 index 0000000..7948077 --- /dev/null +++ b/.github/workflows/check-bun-dependencies.yml @@ -0,0 +1,9 @@ +name: check-bun-dependencies +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * *" +jobs: + call-check-bun-dependencies: + uses: flowscripter/.github/.github/workflows/check-bun-dependencies.yml@v1 + secrets: inherit diff --git a/.github/workflows/lint-pr-message.yml b/.github/workflows/lint-pr-message.yml new file mode 100644 index 0000000..8d79430 --- /dev/null +++ b/.github/workflows/lint-pr-message.yml @@ -0,0 +1,11 @@ +name: lint-pr-message +on: + pull_request_target: + types: + - opened + - edited + - synchronize +jobs: + call-lint-pr-message: + uses: flowscripter/.github/.github/workflows/lint-pr-message.yml@v1 + secrets: inherit diff --git a/.github/workflows/release-bun-library.yml b/.github/workflows/release-bun-library.yml new file mode 100644 index 0000000..ae35384 --- /dev/null +++ b/.github/workflows/release-bun-library.yml @@ -0,0 +1,8 @@ +name: release-bun-library +on: + push: + branches: [main] +jobs: + call-release-bun-library: + uses: flowscripter/.github/.github/workflows/release-bun-library.yml@v1 + secrets: inherit diff --git a/.github/workflows/validate-bun-library-pr.yml b/.github/workflows/validate-bun-library-pr.yml new file mode 100644 index 0000000..c97ba7e --- /dev/null +++ b/.github/workflows/validate-bun-library-pr.yml @@ -0,0 +1,8 @@ +name: validate-bun-library-pr +on: + pull_request: + branches: [main] +jobs: + call-validate-bun-library-pr: + uses: flowscripter/.github/.github/workflows/validate-bun-library-pr.yml@v1 + secrets: inherit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85949d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,177 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store +docs/ +/.releaserc diff --git a/README.md b/README.md index 09e70a7..b4feb92 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,65 @@ # example-plugin -Example plugin for the (https://github.com/flowscripter/dynamic-plugin-framework + +[![version](https://img.shields.io/github/v/release/flowscripter/example-plugin?sort=semver)](https://github.com/flowscripter/example-plugin/releases) +[![build](https://img.shields.io/github/actions/workflow/status/flowscripter/example-plugin/release-bun-library.yml)](https://github.com/flowscripter/example-plugin/actions/workflows/release-bun-library.yml) +[![coverage](https://codecov.io/gh/flowscripter/example-plugin/branch/main/graph/badge.svg?token=EMFT2938ZF)](https://codecov.io/gh/flowscripter/example-plugin) +[![docs](https://img.shields.io/badge/docs-API-blue)](https://flowscripter.github.io/example-plugin/index.html) +[![license: MIT](https://img.shields.io/github/license/flowscripter/example-plugin)](https://github.com/flowscripter/example-plugin/blob/main/LICENSE) + +> Example plugin for the +> [dynamic-plugin-framework](https://github.com/flowscripter/dynamic-plugin-framework) + +## Bun Module Usage + +Add the module: + +`bun add @flowscripter/example-plugin` + +Use the module: + +```typescript +import { ExampleExtension } from "@flowscripter/example-plugin"; + +const extension = new ExampleExtension(); + +extension.sayHello(); +``` + +## Development + +Test: + +`bun test` + +**NOTE**: The following tasks use Deno as it excels at these and Bun does not +currently provide such functionality: + +Format: + +`deno fmt` + +Lint: + +`deno lint index.ts src/ tests/` + +Generate HTML API Documentation: + +`deno doc --html --name=example-plugin index.ts` + +## Documentation + +### Overview + +Refer to the +[dynamic-plugin-framework](https://github.com/flowscripter/dynamic-plugin-framework) +for an overview of what this example is demonstrating. + +### API + +Link to auto-generated API docs for the library: + +[API Documentation](https://flowscripter.github.io/example-plugin/index.html) + +## License + +MIT © Flowscripter diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..7c2b875 --- /dev/null +++ b/bun.lock @@ -0,0 +1,35 @@ +{ + "lockfileVersion": 1, + "workspaces": { + "": { + "name": "@flowscripter/example-plugin", + "dependencies": { + "@flowscripter/dynamic-plugin-framework": "^1.3.8", + "@flowscripter/example-plugin-api": "^1.0.0", + }, + "devDependencies": { + "@types/bun": "^1.2.4", + }, + "peerDependencies": { + "typescript": "^5.8.2", + }, + }, + }, + "packages": { + "@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@1.3.8", "", { "peerDependencies": { "typescript": "^5.8.2" } }, "sha512-/XEYnDORtgazu/7lOcqhwbnwyyErzs3p3aMfzRXFDtJNi+uBwNdJDVw81huHOqaf+UDoUPFu3L6SwSZv6LXFMg=="], + + "@flowscripter/example-plugin-api": ["@flowscripter/example-plugin-api@1.0.0", "", { "peerDependencies": { "typescript": "^5.8.2" } }, "sha512-6IND3SxnkIKspmmRUQqe3lITS+tQNNa7gKEkROSu1G1FYae8Gi5AnLDUOx1+JwhcHha+607az+ciXZ35Q/gNtw=="], + + "@types/bun": ["@types/bun@1.2.4", "", { "dependencies": { "bun-types": "1.2.4" } }, "sha512-QtuV5OMR8/rdKJs213iwXDpfVvnskPXY/S0ZiFbsTjQZycuqPbMW8Gf/XhLfwE5njW8sxI2WjISURXPlHypMFA=="], + + "@types/node": ["@types/node@22.13.9", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-acBjXdRJ3A6Pb3tqnw9HZmyR3Fiol3aGxRCK1x3d+6CDAMjl7I649wpSd+yNURCjbOUGu9tqtLKnTGxmK6CyGw=="], + + "@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="], + + "bun-types": ["bun-types@1.2.4", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-nDPymR207ZZEoWD4AavvEaa/KZe/qlrbMSchqpQwovPZCKc7pwMoENjEtHgMKaAjJhy+x6vfqSBA1QU3bJgs0Q=="], + + "typescript": ["typescript@5.8.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ=="], + + "undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="], + } +} diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..eed6bae --- /dev/null +++ b/index.ts @@ -0,0 +1 @@ +export { default, exampleExtension } from "./src/ExamplePlugin.ts"; diff --git a/package.json b/package.json new file mode 100644 index 0000000..332663e --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "@flowscripter/example-plugin", + "module": "index.ts", + "type": "module", + "version": "0.0.0", + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@types/bun": "^1.2.4" + }, + "peerDependencies": { + "typescript": "^5.8.2" + }, + "dependencies": { + "@flowscripter/dynamic-plugin-framework": "^1.3.8", + "@flowscripter/example-plugin-api": "^1.0.0" + } +} diff --git a/src/ExamplePlugin.ts b/src/ExamplePlugin.ts new file mode 100644 index 0000000..45d0b33 --- /dev/null +++ b/src/ExamplePlugin.ts @@ -0,0 +1,42 @@ +import { + EXTENSION_POINT_1, + type ExtensionPoint1, +} from "@flowscripter/example-plugin-api"; +import type { + ExtensionDescriptor, + ExtensionFactory, + Plugin, +} from "@flowscripter/dynamic-plugin-framework"; + +export const exampleExtension: ExtensionPoint1 = { + sayHello: () => { + console.info("hello world"); + }, +}; + +const exampleExtensionFactory: ExtensionFactory = { + create: () => { + return Promise.resolve(exampleExtension); + }, +}; + +const exampleExtensionDescriptor: ExtensionDescriptor = { + extensionPoint: EXTENSION_POINT_1, + + factory: exampleExtensionFactory, + + extensionData: new Map([[ + "extension_foo", + "extension_bar", + ]]), +}; + +const examplePlugin: Plugin = { + extensionDescriptors: [ + exampleExtensionDescriptor, + ], + + pluginData: new Map([["plugin_foo", "plugin_bar"]]), +}; + +export default examplePlugin; diff --git a/tests/ExamplePlugin_test.ts b/tests/ExamplePlugin_test.ts new file mode 100644 index 0000000..a5d1a80 --- /dev/null +++ b/tests/ExamplePlugin_test.ts @@ -0,0 +1,26 @@ +import { describe, expect, test } from "bun:test"; +import { default as examplePlugin, exampleExtension } from "../index.ts"; +import type { ExtensionPoint1 } from "@flowscripter/example-plugin-api"; + +describe("ExamplePlugin Tests", () => { + test("Access extension implementation via plugin", async () => { + expect(examplePlugin.pluginData?.get("plugin_foo")).toEquals("plugin_bar"); + + const extensionDescriptor = examplePlugin.extensionDescriptors[0]; + + expect( + extensionDescriptor.extensionData?.get("extension_foo"), + ).toEqual( + "extension_bar", + ); + + const extension = await extensionDescriptor.factory + .create() as ExtensionPoint1; + + extension.sayHello(); + }); + + test("Access extension implementation directly", () => { + exampleExtension.sayHello(); + }); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..238655f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} From cf50f1c8c3fc163b969ac109365f76c63247873d Mon Sep 17 00:00:00 2001 From: vectronic Date: Thu, 6 Mar 2025 09:03:39 +0000 Subject: [PATCH 2/2] fix: fix test code --- tests/ExamplePlugin_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ExamplePlugin_test.ts b/tests/ExamplePlugin_test.ts index a5d1a80..82d008d 100644 --- a/tests/ExamplePlugin_test.ts +++ b/tests/ExamplePlugin_test.ts @@ -4,7 +4,7 @@ import type { ExtensionPoint1 } from "@flowscripter/example-plugin-api"; describe("ExamplePlugin Tests", () => { test("Access extension implementation via plugin", async () => { - expect(examplePlugin.pluginData?.get("plugin_foo")).toEquals("plugin_bar"); + expect(examplePlugin.pluginData?.get("plugin_foo")).toEqual("plugin_bar"); const extensionDescriptor = examplePlugin.extensionDescriptors[0];