Skip to content
Closed
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
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ jobs:
- name: Run lint
run: yarn lint

types:
name: Type check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

- name: Setup node
uses: ./.github/actions/setup-node

- name: Run type check
run: yarn types

build:
name: Build
runs-on: ubuntu-latest
Expand All @@ -56,5 +69,8 @@ jobs:
- name: Setup node
uses: ./.github/actions/setup-node

- name: Install playwright dependencies
run: yarn playwright install --with-deps chromium

- name: Run test
run: yarn test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ tsconfig*.tsbuildinfo
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Vitest browser test attachments (screenshots, traces)
.vitest-attachments
**/__screenshots__
11 changes: 11 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
"plugins": ["eslint", "import", "oxc", "react", "typescript"],
"categories": {
"correctness": "error"
},
"rules": {
"eslint/no-unused-vars": [
"error",
{
"caughtErrors": "none",
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_"
}
]
}
}
9 changes: 0 additions & 9 deletions jest.config.ts

This file was deleted.

67 changes: 38 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
{
"name": "@sigmacomputing/plugin",
"version": "1.1.1",
"version": "2.0.0-alpha.0",
"description": "Sigma Computing Plugin Client API",
"license": "MIT",
"homepage": "https://github.com/sigmacomputing/plugin",
"main": "./dist/index.js",
"type": "module",
"main": "./dist/cjs/index.cjs",
"module": "./dist/esm/index.js",
"types": "./dist/cjs/index.d.cts",
"unpkg": "./dist/umd/sigmacomputing-plugin.umd.js",
"jsdelivr": "./dist/umd/sigmacomputing-plugin.umd.js",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
},
"./package.json": "./package.json"
},
"repository": {
"type": "git",
"url": "https://github.com/sigmacomputing/plugin.git"
Expand All @@ -15,55 +33,46 @@
},
"packageManager": "yarn@4.13.0",
"files": [
"dist/**/*"
"dist/**/*",
"src/**/*",
"!src/**/__tests__/**/*"
],
"typesVersions": {
"*": {
"react": [
"dist/react/index.d.ts"
]
}
},
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "yarn tsc --build tsconfig.build.json",
"build:watch": "yarn build --watch",
"build": "tsdown",
"build:watch": "tsdown --watch",
"format": "yarn oxfmt",
"lint": "yarn oxlint",
"precommit": "lint-staged",
"publish": "yarn build && yarn npm publish",
"test": "jest --ci",
"test:watch": "yarn test --watch"
"test": "vitest run",
"test:watch": "vitest",
"types": "tsc --noEmit"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
},
"peerDependenciesMeta": {
"react": {
"optional": true
},
"react-dom": {
"optional": true
}
},
"devDependencies": {
"@jest/types": "^27.5.1",
"@types/jest": "^27.5.1",
"@types/node": "^18.7.14",
"@arethetypeswrong/core": "^0.18.2",
"@types/node": "^24.0.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"jest": "^30.3.0",
"jest-environment-jsdom": "^30.3.0",
"jest-watch-typeahead": "^2.1.1",
"@vitest/browser-playwright": "^4.1.5",
"lint-staged": "^13.0.3",
"oxfmt": "^0.38.0",
"oxlint": "^1.53.0",
"oxlint-tsgolint": "^0.16.0",
"ts-jest": "^29.4.6",
"ts-node": "^10.9.2",
"typescript": "^4.8.2"
"playwright": "^1.49.0",
"publint": "^0.3.18",
"tsdown": "^0.21.10",
"typescript": "^6.0.2",
"unplugin-unused": "^0.5.7",
"vitest": "^4.1.5"
}
}
6 changes: 3 additions & 3 deletions src/client/__tests__/initialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ describe('initialize', () => {
beforeAll(() => {
originalAddEventListener = window.addEventListener;
originalRemoveEventListener = window.removeEventListener;
window.addEventListener = jest.fn();
window.removeEventListener = jest.fn();
window.addEventListener = vi.fn();
window.removeEventListener = vi.fn();
});

beforeEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

it('should initialize and be destroyable', () => {
Expand Down
23 changes: 15 additions & 8 deletions src/client/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ export function initialize<T = {}>(): PluginInstance<T> {
[event: string]: Function[];
} = {};

for (const [key, value] of new URL(
document.location.toString(),
).searchParams.entries())
pluginConfig[key] = JSON.parse(value);
const location = new URL(document.location.href);
for (const [key, value] of location.searchParams.entries()) {
try {
pluginConfig[key] = JSON.parse(value);
} catch (_err: unknown) {
if (__VITEST_BROWSER__ && (key === 'frameId' || key === 'sessionId')) {
// noop: vitest browser injects these into the test iframe URL
} else {
console.error(
`Failed to parse URL param ${key} with value ${value} as JSON.`,
);
}
}
}

const listener = (e: PluginMessageResponse) => {
emit(e.data.type, e.data.result, e.data.error);
Expand All @@ -41,10 +51,7 @@ export function initialize<T = {}>(): PluginInstance<T> {
});

// send initialize event
void execPromise(
'wb:plugin:init',
require('../../package.json').version,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version thing is a feature we previously had for plugins that we removed (like 3 years ago) so removing this here shouldn't cause any issues.

It was causing issues with the test environment which is why it is being removed in this PR.

).then(config => {
void execPromise('wb:plugin:init').then(config => {
Object.assign(pluginConfig, config);
emit('init', pluginConfig);
emit('config', pluginConfig.config);
Expand Down
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare const __VITEST_BROWSER__: boolean;
6 changes: 2 additions & 4 deletions src/react.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from './react/hooks';
export {
SigmaClientProviderProps,
SigmaClientProvider,
} from './react/Provider';
export type { SigmaClientProviderProps } from './react/Provider';
export { SigmaClientProvider } from './react/Provider';
4 changes: 2 additions & 2 deletions src/react/Context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext } from 'react';
import * as React from 'react';

import { client } from '../client';
import { PluginInstance } from '../types';

export const PluginContext = createContext<PluginInstance>(client);
export const PluginContext = React.createContext<PluginInstance>(client);
4 changes: 2 additions & 2 deletions src/react/Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ReactNode } from 'react';
import * as React from 'react';

import { PluginInstance } from '../types';

import { PluginContext } from './Context';

export interface SigmaClientProviderProps<T = any> {
client: PluginInstance<T>;
children?: ReactNode;
children?: React.ReactNode;
}

export function SigmaClientProvider<T = any>(
Expand Down
Loading
Loading