Skip to content

Commit a4e61c9

Browse files
authored
Merge pull request #1296 from joshunrau/serve-instrument
rewrite serve-instrument as standalone dev server
2 parents 6e029e7 + 756b33a commit a4e61c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4739
-5284
lines changed

apps/gateway/vite.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default defineConfig(({ mode }) => ({
99
build: {
1010
chunkSizeWarningLimit: 1000,
1111
emptyOutDir: false,
12+
rollupOptions: {
13+
external: ['esbuild']
14+
},
1215
sourcemap: true,
1316
target: 'es2022'
1417
},
@@ -21,7 +24,8 @@ export default defineConfig(({ mode }) => ({
2124
plugins: [
2225
react(),
2326
runtime({
24-
disabled: mode === 'test'
27+
disabled: mode === 'test',
28+
rootDir: import.meta.dirname
2529
}) as any,
2630
tailwindcss()
2731
],

apps/playground/src/components/Header/ActionsDropdown/StorageUsageDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { formatByteSize } from '@douglasneuroinformatics/libjs';
44
import { Button, Dialog } from '@douglasneuroinformatics/libui/components';
55

66
import { useAppStore } from '@/store';
7+
78
export type StorageUsageDialogProps = {
89
isOpen: boolean;
910
setIsOpen: (value: boolean) => void;
@@ -17,7 +18,7 @@ export const StorageUsageDialog = ({ isOpen, setIsOpen }: StorageUsageDialogProp
1718
const updateStorage = async () => {
1819
setMessage('Loading...');
1920
const [updated] = await Promise.all([
20-
await navigator.storage.estimate(),
21+
navigator.storage.estimate(),
2122
new Promise((resolve) => setTimeout(resolve, 500))
2223
]);
2324
setStorageEstimate(updated);
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { ViewerErrorFallback } from './ViewerErrorFallback';
1+
import { InstrumentErrorFallback } from '@opendatacapture/react-core';
2+
import type { InstrumentErrorFallbackProps } from '@opendatacapture/react-core';
23

3-
import type { ViewerErrorFallbackProps } from './ViewerErrorFallback';
4-
5-
export const CompileErrorFallback = (props: Omit<ViewerErrorFallbackProps, 'title'>) => {
6-
return <ViewerErrorFallback title="Failed to Compile" {...props} />;
4+
export const CompileErrorFallback = (props: Omit<InstrumentErrorFallbackProps, 'title'>) => {
5+
return <InstrumentErrorFallback title="Failed to Compile" {...props} />;
76
};

apps/playground/src/components/Viewer/RuntimeErrorFallback.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { ViewerErrorFallback } from './ViewerErrorFallback';
1+
import { InstrumentErrorFallback } from '@opendatacapture/react-core';
2+
import type { InstrumentErrorFallbackProps } from '@opendatacapture/react-core';
23

3-
import type { ViewerErrorFallbackProps } from './ViewerErrorFallback';
4-
5-
export const RuntimeErrorFallback = (props: Omit<ViewerErrorFallbackProps, 'title'>) => {
4+
export const RuntimeErrorFallback = (props: Omit<InstrumentErrorFallbackProps, 'title'>) => {
65
return (
7-
<ViewerErrorFallback
6+
<InstrumentErrorFallback
87
description="This means that your instrument successfully compiled, but caused an unexpected exception to be thrown in the browser. For example, this could happen in the render function of a dynamic form field. Although the bundler attempts to validate the structure of instruments at compile time, it is not possible to evaluate the runtime behavior of arbitrary JavaScript code."
98
title="Unhandled Runtime Error"
109
{...props}

apps/playground/src/components/Viewer/Viewer.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import { editorFileToInput, hashFiles } from '@/utils/file';
1515

1616
import { CompileErrorFallback } from './CompileErrorFallback';
1717
import { RuntimeErrorFallback } from './RuntimeErrorFallback';
18+
1819
export const Viewer = () => {
1920
const editorFilesRef = useFilesRef();
21+
const indexFilename = useAppStore((store) => store.indexFilename);
2022
const refreshInterval = useAppStore((store) => store.settings.refreshInterval);
2123
const [filesHash, setFilesHash] = useState<string>('');
2224

@@ -58,7 +60,11 @@ export const Viewer = () => {
5860
>
5961
{match(state)
6062
.with({ status: 'built' }, ({ bundle }) => (
61-
<ErrorBoundary FallbackComponent={RuntimeErrorFallback}>
63+
<ErrorBoundary
64+
FallbackComponent={(props) => (
65+
<RuntimeErrorFallback context={{ files: editorFilesRef.current, indexFilename }} {...props} />
66+
)}
67+
>
6268
<ScalarInstrumentRenderer
6369
options={{ validate: true }}
6470
target={{ bundle, id: null! }}
@@ -70,7 +76,9 @@ export const Viewer = () => {
7076
/>
7177
</ErrorBoundary>
7278
))
73-
.with({ status: 'error' }, CompileErrorFallback)
79+
.with({ status: 'error' }, (props) => (
80+
<CompileErrorFallback context={{ files: editorFilesRef.current, indexFilename }} {...props} />
81+
))
7482
.with({ status: P.union('building', 'initial') }, () => <Spinner />)
7583
.exhaustive()}
7684
</div>

apps/playground/src/components/Viewer/ViewerErrorFallback/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/playground/src/pages/IndexPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const IndexPage = () => {
2929
}
3030
for (const fileA of instrumentA.files) {
3131
const fileB = instrumentB.files.find((file) => file.name === fileA.name);
32-
if (!fileB || fileA.content !== fileB.content) {
32+
if (fileA.content !== fileB?.content) {
3333
return false;
3434
}
3535
}

apps/playground/src/vim/operators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const operators: { [key: string]: OperatorFunc } = {
3333
if (!vim.visualMode) {
3434
text = adapter.getRange(anchor, head);
3535
const lastState = vim.lastEditInputState;
36-
if (lastState && lastState.motion === 'moveByWords' && !isWhiteSpaceString(text)) {
36+
if (lastState?.motion === 'moveByWords' && !isWhiteSpaceString(text)) {
3737
// Exclude trailing whitespace if the range is not all whitespace.
3838
const match = /\s+$/.exec(text);
3939
if (match && lastState.motionArgs?.forward) {

apps/playground/src/vim/register-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class Register implements IRegister {
9393
*/
9494
export function defineRegister(name: string, register: IRegister) {
9595
const registers = vimGlobalState.registerController.registers;
96-
if (!name || name.length != 1) {
96+
if (name?.length != 1) {
9797
throw Error('Register name must be 1 character');
9898
}
9999
if (registers[name]) {

apps/playground/vite.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default defineConfig(({ mode }) => ({
99
build: {
1010
chunkSizeWarningLimit: 1000,
1111
emptyOutDir: false,
12+
rollupOptions: {
13+
external: ['esbuild']
14+
},
1215
sourcemap: true,
1316
target: 'es2022'
1417
},
@@ -25,7 +28,8 @@ export default defineConfig(({ mode }) => ({
2528
plugins: [
2629
react(),
2730
runtime({
28-
disabled: mode === 'test'
31+
disabled: mode === 'test',
32+
rootDir: import.meta.dirname
2933
}),
3034
tailwindcss()
3135
],

0 commit comments

Comments
 (0)