From 7baf01b389706c0eb2dce0d0d0bf9574071b391a Mon Sep 17 00:00:00 2001 From: Jeff Soules Date: Fri, 12 Jul 2024 16:43:17 -0400 Subject: [PATCH 1/2] Update to use path aliases and resolver. --- gui/package.json | 3 +- gui/src/app/FileEditor/DataFileEditor.tsx | 2 +- .../FileEditor/StanCompileResultWindow.tsx | 4 +- gui/src/app/FileEditor/StanFileEditor.tsx | 10 ++--- gui/src/app/FileEditor/TextEditor.tsx | 6 +-- gui/src/app/MainWindow.tsx | 2 +- gui/src/app/Project/FileMapping.ts | 2 +- .../app/Project/ProjectContextProvider.tsx | 24 ++++++------ gui/src/app/Project/ProjectQueryLoading.ts | 12 +++--- gui/src/app/Project/ProjectReducer.ts | 10 ++--- gui/src/app/Project/ProjectSerialization.ts | 8 ++-- gui/src/app/RunPanel/RunPanel.tsx | 8 ++-- gui/src/app/SamplerOutputView/HistsView.tsx | 2 +- .../SamplerOutputView/SamplerOutputView.tsx | 16 ++++---- .../SequenceHistogramWidget.tsx | 2 +- .../SamplerOutputView/SequencePlotWidget.tsx | 2 +- gui/src/app/SamplerOutputView/SummaryView.tsx | 10 +++-- .../app/SamplerOutputView/TracePlotsView.tsx | 4 +- .../SamplingOptsPanel/SamplingOptsPanel.tsx | 2 +- gui/src/app/StanSampler/StanSampler.ts | 6 +-- gui/src/app/StanSampler/useStanSampler.ts | 4 +- gui/src/app/Stanc/Linting.ts | 2 +- gui/src/app/Stanc/stancWorker.ts | 6 +-- gui/src/app/Stanc/useStanc.ts | 8 +++- gui/src/app/TabWidget/TabWidget.tsx | 2 +- gui/src/app/pages/HomePage/HomePage.tsx | 38 +++++++++---------- gui/src/app/pages/HomePage/LeftPanel.tsx | 10 ++--- .../app/pages/HomePage/LoadProjectWindow.tsx | 21 +++++----- .../app/pages/HomePage/SaveProjectWindow.tsx | 13 +++---- gui/src/app/pages/HomePage/TopBar.tsx | 4 +- .../stan_stats/fft.ts | 0 .../stan_stats/stan_stats.ts | 2 +- .../stan_stats/summaryStats.ts} | 0 gui/test/app/Project/ProjectDataModel.test.ts | 4 +- .../app/Project/ProjectQueryLoading.test.ts | 4 +- gui/test/app/StanSampler/MockStanModel.ts | 4 +- .../app/StanSampler/useStanSampler.test.ts | 12 +++--- gui/test/app/Stanc/Linting.test.ts | 5 +-- gui/test/app/Stanc/useStanc.test.ts | 6 +-- gui/tsconfig.json | 28 +++++++++++++- gui/vite.config.ts | 6 ++- gui/yarn.lock | 19 ++++++++++ 42 files changed, 191 insertions(+), 142 deletions(-) rename gui/src/app/{SamplerOutputView => util}/stan_stats/fft.ts (100%) rename gui/src/app/{SamplerOutputView => util}/stan_stats/stan_stats.ts (99%) rename gui/src/app/{SamplerOutputView/util.ts => util/stan_stats/summaryStats.ts} (100%) diff --git a/gui/package.json b/gui/package.json index 0ce489ca..fabbdc25 100644 --- a/gui/package.json +++ b/gui/package.json @@ -38,7 +38,8 @@ "react-plotly.js": "^2.6.0", "react-router-dom": "^6.17.0", "react-visibility-sensor": "^5.1.1", - "tinystan": "^0.0.2" + "tinystan": "^0.0.2", + "vite-tsconfig-paths": "^4.3.2" }, "devDependencies": { "@testing-library/dom": "^10.1.0", diff --git a/gui/src/app/FileEditor/DataFileEditor.tsx b/gui/src/app/FileEditor/DataFileEditor.tsx index e188bdf2..11535ffd 100644 --- a/gui/src/app/FileEditor/DataFileEditor.tsx +++ b/gui/src/app/FileEditor/DataFileEditor.tsx @@ -1,5 +1,5 @@ +import TextEditor, { ToolbarItem } from "@SpComponents/TextEditor"; import { FunctionComponent, useMemo } from "react"; -import TextEditor, { ToolbarItem } from "./TextEditor"; type Props = { fileName: string; diff --git a/gui/src/app/FileEditor/StanCompileResultWindow.tsx b/gui/src/app/FileEditor/StanCompileResultWindow.tsx index 81bc4cc7..83714873 100644 --- a/gui/src/app/FileEditor/StanCompileResultWindow.tsx +++ b/gui/src/app/FileEditor/StanCompileResultWindow.tsx @@ -1,7 +1,7 @@ +import { StancErrors } from "@SpStanc/Types"; +import { SmallIconButton } from "@fi-sci/misc"; import { Close, Done } from "@mui/icons-material"; import { FunctionComponent } from "react"; -import { StancErrors } from "../Stanc/Types"; -import { SmallIconButton } from "@fi-sci/misc"; type Props = { width: number; diff --git a/gui/src/app/FileEditor/StanFileEditor.tsx b/gui/src/app/FileEditor/StanFileEditor.tsx index f6bfa2db..243e8817 100644 --- a/gui/src/app/FileEditor/StanFileEditor.tsx +++ b/gui/src/app/FileEditor/StanFileEditor.tsx @@ -1,5 +1,10 @@ import { Splitter } from "@fi-sci/splitter"; import { AutoFixHigh, Cancel, Settings } from "@mui/icons-material"; +import StanCompileResultWindow from "@SpComponents/StanCompileResultWindow"; +import TextEditor, { ToolbarItem } from "@SpComponents/TextEditor"; +import compileStanProgram from "@SpStanc/compileStanProgram"; +import { stancErrorsToCodeMarkers } from "@SpStanc/Linting"; +import useStanc from "@SpStanc/useStanc"; import { FunctionComponent, useCallback, @@ -7,11 +12,6 @@ import { useMemo, useState, } from "react"; -import StanCompileResultWindow from "./StanCompileResultWindow"; -import useStanc from "../Stanc/useStanc"; -import TextEditor, { ToolbarItem } from "./TextEditor"; -import compileStanProgram from "../compileStanProgram/compileStanProgram"; -import { stancErrorsToCodeMarkers } from "../Stanc/Linting"; type Props = { fileName: string; diff --git a/gui/src/app/FileEditor/TextEditor.tsx b/gui/src/app/FileEditor/TextEditor.tsx index c42036d1..c09b9407 100644 --- a/gui/src/app/FileEditor/TextEditor.tsx +++ b/gui/src/app/FileEditor/TextEditor.tsx @@ -1,6 +1,9 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import { Hyperlink, SmallIconButton } from "@fi-sci/misc"; import { Editor } from "@monaco-editor/react"; import { Refresh, Save } from "@mui/icons-material"; +import { highlightJsData } from "@SpComponents/stanLang"; +import { CodeMarker } from "@SpStanc/Linting"; import { editor } from "monaco-editor"; import * as monaco from "monaco-editor/esm/vs/editor/editor.api"; import { @@ -10,9 +13,6 @@ import { useEffect, useState, } from "react"; -import { highlightJsData } from "./stanLang"; -import { Hyperlink, SmallIconButton } from "@fi-sci/misc"; -import { CodeMarker } from "../Stanc/Linting"; type Monaco = typeof monaco; diff --git a/gui/src/app/MainWindow.tsx b/gui/src/app/MainWindow.tsx index 97003793..7c0e89fd 100644 --- a/gui/src/app/MainWindow.tsx +++ b/gui/src/app/MainWindow.tsx @@ -1,7 +1,7 @@ import { useWindowDimensions } from "@fi-sci/misc"; +import HomePage from "@SpPages/HomePage"; import { FunctionComponent } from "react"; import StatusBar, { statusBarHeight } from "./StatusBar"; -import HomePage from "./pages/HomePage/HomePage"; type Props = { // none diff --git a/gui/src/app/Project/FileMapping.ts b/gui/src/app/Project/FileMapping.ts index 40ff1dad..e3c88b2c 100644 --- a/gui/src/app/Project/FileMapping.ts +++ b/gui/src/app/Project/FileMapping.ts @@ -2,7 +2,7 @@ import { ProjectDataModel, ProjectPersistentDataModel, stringifyField, -} from "./ProjectDataModel"; +} from "@SpCore/ProjectDataModel"; // This code exists to provide rigorous definitions for the mappings between // the in-memory representation of a Stan Playground project (i.e. the diff --git a/gui/src/app/Project/ProjectContextProvider.tsx b/gui/src/app/Project/ProjectContextProvider.tsx index c11069ea..8ecffaff 100644 --- a/gui/src/app/Project/ProjectContextProvider.tsx +++ b/gui/src/app/Project/ProjectContextProvider.tsx @@ -1,26 +1,26 @@ -import { - createContext, - FunctionComponent, - PropsWithChildren, - useEffect, - useReducer, -} from "react"; -import { useSearchParams } from "react-router-dom"; -import { initialDataModel, ProjectDataModel } from "./ProjectDataModel"; +import { initialDataModel, ProjectDataModel } from "@SpCore/ProjectDataModel"; import { fetchRemoteProject, fromQueryParams, queryStringHasParameters, -} from "./ProjectQueryLoading"; +} from "@SpCore/ProjectQueryLoading"; import { ProjectReducer, ProjectReducerAction, ProjectReducerType, -} from "./ProjectReducer"; +} from "@SpCore/ProjectReducer"; import { deserializeProjectFromLocalStorage, serializeProjectToLocalStorage, -} from "./ProjectSerialization"; +} from "@SpCore/ProjectSerialization"; +import { + createContext, + FunctionComponent, + PropsWithChildren, + useEffect, + useReducer, +} from "react"; +import { useSearchParams } from "react-router-dom"; type ProjectContextType = { data: ProjectDataModel; diff --git a/gui/src/app/Project/ProjectQueryLoading.ts b/gui/src/app/Project/ProjectQueryLoading.ts index b8355e65..9503e8c7 100644 --- a/gui/src/app/Project/ProjectQueryLoading.ts +++ b/gui/src/app/Project/ProjectQueryLoading.ts @@ -1,14 +1,14 @@ -import loadFilesFromGist from "../gists/loadFilesFromGist"; -import { deepCopy } from "../util/deepCopy"; -import { tryFetch } from "../util/tryFetch"; -import { mapFileContentsToModel } from "./FileMapping"; +import { mapFileContentsToModel } from "@SpCore/FileMapping"; +import loadFilesFromGist from "@SpCore/loadFilesFromGist"; import { ProjectDataModel, initialDataModel, parseSamplingOpts, persistStateToEphemera, -} from "./ProjectDataModel"; -import { loadFromProjectFiles } from "./ProjectSerialization"; +} from "@SpCore/ProjectDataModel"; +import { loadFromProjectFiles } from "@SpCore/ProjectSerialization"; +import { deepCopy } from "@SpUtil/deepCopy"; +import { tryFetch } from "@SpUtil/tryFetch"; export enum QueryParamKeys { Project = "project", diff --git a/gui/src/app/Project/ProjectReducer.ts b/gui/src/app/Project/ProjectReducer.ts index 4032dab3..28c60c13 100644 --- a/gui/src/app/Project/ProjectReducer.ts +++ b/gui/src/app/Project/ProjectReducer.ts @@ -1,14 +1,14 @@ -import { Reducer } from "react"; -import { Stanie } from "../exampleStanies/exampleStanies"; -import { FieldsContentsMap } from "./FileMapping"; +import { FieldsContentsMap } from "@SpCore/FileMapping"; import { defaultSamplingOpts, initialDataModel, ProjectDataModel, ProjectKnownFiles, SamplingOpts, -} from "./ProjectDataModel"; -import { loadFromProjectFiles } from "./ProjectSerialization"; +} from "@SpCore/ProjectDataModel"; +import { loadFromProjectFiles } from "@SpCore/ProjectSerialization"; +import { Stanie } from "@SpExamples/exampleStanies"; +import { Reducer } from "react"; export type ProjectReducerType = Reducer< ProjectDataModel, diff --git a/gui/src/app/Project/ProjectSerialization.ts b/gui/src/app/Project/ProjectSerialization.ts index b4cd1336..45cbff21 100644 --- a/gui/src/app/Project/ProjectSerialization.ts +++ b/gui/src/app/Project/ProjectSerialization.ts @@ -1,5 +1,3 @@ -import JSZip from "jszip"; -import { replaceSpacesWithUnderscores } from "../util/replaceSpaces"; import { FieldsContentsMap, FileNames, @@ -7,7 +5,7 @@ import { ProjectFileMap, mapFileContentsToModel, mapModelToFileManifest, -} from "./FileMapping"; +} from "@SpCore/FileMapping"; import { ProjectDataModel, ProjectKnownFiles, @@ -17,7 +15,9 @@ import { isProjectMetaData, parseSamplingOpts, persistStateToEphemera, -} from "./ProjectDataModel"; +} from "@SpCore/ProjectDataModel"; +import { replaceSpacesWithUnderscores } from "@SpUtil/replaceSpaces"; +import JSZip from "jszip"; export const serializeProjectToLocalStorage = ( data: ProjectDataModel, diff --git a/gui/src/app/RunPanel/RunPanel.tsx b/gui/src/app/RunPanel/RunPanel.tsx index 63d0a488..72315530 100644 --- a/gui/src/app/RunPanel/RunPanel.tsx +++ b/gui/src/app/RunPanel/RunPanel.tsx @@ -6,13 +6,13 @@ import LinearProgress, { import Typography from "@mui/material/Typography"; import { FunctionComponent, useCallback } from "react"; -import { SamplingOpts } from "../Project/ProjectDataModel"; -import { Progress } from "../StanSampler/StanModelWorker"; -import StanSampler from "../StanSampler/StanSampler"; +import { SamplingOpts } from "@SpCore/ProjectDataModel"; +import { Progress } from "@SpStanSampler/StanModelWorker"; +import StanSampler from "@SpStanSampler/StanSampler"; import { useSamplerProgress, useSamplerStatus, -} from "../StanSampler/useStanSampler"; +} from "@SpStanSampler/useStanSampler"; type RunPanelProps = { width: number; diff --git a/gui/src/app/SamplerOutputView/HistsView.tsx b/gui/src/app/SamplerOutputView/HistsView.tsx index 2657b86c..5c844b39 100644 --- a/gui/src/app/SamplerOutputView/HistsView.tsx +++ b/gui/src/app/SamplerOutputView/HistsView.tsx @@ -1,5 +1,5 @@ +import SequenceHistogramWidget from "@SpComponents/SequenceHistogramWidget"; import { FunctionComponent, useMemo } from "react"; -import SequenceHistogramWidget from "./SequenceHistogramWidget"; type HistsViewProps = { width: number; diff --git a/gui/src/app/SamplerOutputView/SamplerOutputView.tsx b/gui/src/app/SamplerOutputView/SamplerOutputView.tsx index 1c2f2cbd..4abd6eb4 100644 --- a/gui/src/app/SamplerOutputView/SamplerOutputView.tsx +++ b/gui/src/app/SamplerOutputView/SamplerOutputView.tsx @@ -1,15 +1,15 @@ import { SmallIconButton } from "@fi-sci/misc"; import { Download } from "@mui/icons-material"; +import HistsView from "@SpComponents/HistsView"; +import SummaryView from "@SpComponents/SummaryView"; +import TabWidget from "@SpComponents/TabWidget"; +import TracePlotsView from "@SpComponents/TracePlotsView"; +import { SamplingOpts } from "@SpCore/ProjectDataModel"; +import StanSampler from "@SpStanSampler/StanSampler"; +import { useSamplerOutput } from "@SpStanSampler/useStanSampler"; +import { triggerDownload } from "@SpUtil/triggerDownload"; import JSZip from "jszip"; import { FunctionComponent, useCallback, useMemo, useState } from "react"; -import { SamplingOpts } from "../Project/ProjectDataModel"; -import StanSampler from "../StanSampler/StanSampler"; -import { useSamplerOutput } from "../StanSampler/useStanSampler"; -import TabWidget from "../TabWidget/TabWidget"; -import { triggerDownload } from "../util/triggerDownload"; -import HistsView from "./HistsView"; -import SummaryView from "./SummaryView"; -import TracePlotsView from "./TracePlotsView"; type SamplerOutputViewProps = { width: number; diff --git a/gui/src/app/SamplerOutputView/SequenceHistogramWidget.tsx b/gui/src/app/SamplerOutputView/SequenceHistogramWidget.tsx index ec4f8729..ae42c18a 100644 --- a/gui/src/app/SamplerOutputView/SequenceHistogramWidget.tsx +++ b/gui/src/app/SamplerOutputView/SequenceHistogramWidget.tsx @@ -1,5 +1,5 @@ +import LazyPlotlyPlot from "@SpComponents/LazyPlotlyPlot"; import { FunctionComponent, useMemo } from "react"; -import LazyPlotlyPlot from "../components/LazyPlotlyPlot"; type Props = { histData: number[]; diff --git a/gui/src/app/SamplerOutputView/SequencePlotWidget.tsx b/gui/src/app/SamplerOutputView/SequencePlotWidget.tsx index 5642afbd..8cf86d91 100644 --- a/gui/src/app/SamplerOutputView/SequencePlotWidget.tsx +++ b/gui/src/app/SamplerOutputView/SequencePlotWidget.tsx @@ -1,5 +1,5 @@ +import LazyPlotlyPlot from "@SpComponents/LazyPlotlyPlot"; import { FunctionComponent, useMemo } from "react"; -import LazyPlotlyPlot from "../components/LazyPlotlyPlot"; export type PlotSequence = { label: string; diff --git a/gui/src/app/SamplerOutputView/SummaryView.tsx b/gui/src/app/SamplerOutputView/SummaryView.tsx index c9820dcc..c8c5f3aa 100644 --- a/gui/src/app/SamplerOutputView/SummaryView.tsx +++ b/gui/src/app/SamplerOutputView/SummaryView.tsx @@ -1,9 +1,13 @@ -import { FunctionComponent, useMemo } from "react"; -import { computeMean, computePercentile, computeStdDev } from "./util"; import { compute_effective_sample_size, compute_split_potential_scale_reduction, -} from "./stan_stats/stan_stats"; +} from "@SpStanStats/stan_stats"; +import { + computeMean, + computePercentile, + computeStdDev, +} from "@SpStanStats/summaryStats"; +import { FunctionComponent, useMemo } from "react"; type SummaryViewProps = { width: number; diff --git a/gui/src/app/SamplerOutputView/TracePlotsView.tsx b/gui/src/app/SamplerOutputView/TracePlotsView.tsx index c0f1e407..305d42f8 100644 --- a/gui/src/app/SamplerOutputView/TracePlotsView.tsx +++ b/gui/src/app/SamplerOutputView/TracePlotsView.tsx @@ -1,6 +1,6 @@ +import SequencePlotWidget from "@SpComponents/SequencePlotWidget"; +import { chainColorForIndex } from "@SpComponents/chainColorList"; import { FunctionComponent, useMemo, useState } from "react"; -import SequencePlotWidget from "./SequencePlotWidget"; -import { chainColorForIndex } from "./chainColorList"; import ReactVisibilitySensor from "react-visibility-sensor"; type TracePlotsViewProps = { diff --git a/gui/src/app/SamplingOptsPanel/SamplingOptsPanel.tsx b/gui/src/app/SamplingOptsPanel/SamplingOptsPanel.tsx index f0aa24cc..7b350518 100644 --- a/gui/src/app/SamplingOptsPanel/SamplingOptsPanel.tsx +++ b/gui/src/app/SamplingOptsPanel/SamplingOptsPanel.tsx @@ -1,7 +1,7 @@ import { Hyperlink } from "@fi-sci/misc"; import { Grid } from "@mui/material"; +import { defaultSamplingOpts, SamplingOpts } from "@SpCore/ProjectDataModel"; import { FunctionComponent, useCallback } from "react"; -import { defaultSamplingOpts, SamplingOpts } from "../Project/ProjectDataModel"; type SamplingOptsPanelProps = { samplingOpts: SamplingOpts; diff --git a/gui/src/app/StanSampler/StanSampler.ts b/gui/src/app/StanSampler/StanSampler.ts index eedaf3af..2b596c2d 100644 --- a/gui/src/app/StanSampler/StanSampler.ts +++ b/gui/src/app/StanSampler/StanSampler.ts @@ -1,7 +1,7 @@ +import { defaultSamplingOpts, SamplingOpts } from "@SpCore/ProjectDataModel"; +import { Progress, Replies, Requests } from "@SpStanSampler/StanModelWorker"; +import StanWorkerUrl from "@SpStanSampler/StanModelWorker?worker&url"; import type { SamplerParams } from "tinystan"; -import { defaultSamplingOpts, SamplingOpts } from "../Project/ProjectDataModel"; -import { Progress, Replies, Requests } from "./StanModelWorker"; -import StanWorkerUrl from "./StanModelWorker?worker&url"; export type StanSamplerStatus = | "" diff --git a/gui/src/app/StanSampler/useStanSampler.ts b/gui/src/app/StanSampler/useStanSampler.ts index 4f08fa0f..49065376 100644 --- a/gui/src/app/StanSampler/useStanSampler.ts +++ b/gui/src/app/StanSampler/useStanSampler.ts @@ -1,6 +1,6 @@ +import { Progress } from "@SpStanSampler/StanModelWorker"; +import StanSampler, { StanSamplerStatus } from "@SpStanSampler/StanSampler"; import { useEffect, useState } from "react"; -import StanSampler, { StanSamplerStatus } from "./StanSampler"; -import { Progress } from "./StanModelWorker"; const useStanSampler = (compiledMainJsUrl: string | undefined) => { const [sampler, setSampler] = useState(undefined); diff --git a/gui/src/app/Stanc/Linting.ts b/gui/src/app/Stanc/Linting.ts index 6f3ab939..4b8aafa9 100644 --- a/gui/src/app/Stanc/Linting.ts +++ b/gui/src/app/Stanc/Linting.ts @@ -1,4 +1,4 @@ -import { StancErrors } from "./Types"; +import { StancErrors } from "@SpStanc/Types"; type Position = { startLineNumber: number; diff --git a/gui/src/app/Stanc/stancWorker.ts b/gui/src/app/Stanc/stancWorker.ts index d5745d35..a133edb3 100644 --- a/gui/src/app/Stanc/stancWorker.ts +++ b/gui/src/app/Stanc/stancWorker.ts @@ -1,10 +1,10 @@ import { StancFunction, + StancReplyMessage, StancRequestMessage, StancWorkerRequests, - StancReplyMessage, -} from "./Types"; -import rawStancJS from "./stanc.js?raw"; // https://vitejs.dev/guide/assets#importing-asset-as-string +} from "@SpStanc/Types"; +import rawStancJS from "@SpStanc/stanc.js?raw"; // https://vitejs.dev/guide/assets#importing-asset-as-string let stanc: undefined | StancFunction; try { diff --git a/gui/src/app/Stanc/useStanc.ts b/gui/src/app/Stanc/useStanc.ts index e04596e6..5cde0fab 100644 --- a/gui/src/app/Stanc/useStanc.ts +++ b/gui/src/app/Stanc/useStanc.ts @@ -1,8 +1,12 @@ +import { + StancErrors, + StancReplyMessage, + StancWorkerRequests, +} from "@SpStanc/Types"; import { useCallback, useEffect, useState } from "react"; -import { StancReplyMessage, StancErrors, StancWorkerRequests } from "./Types"; // https://vitejs.dev/guide/assets#importing-script-as-a-worker // https://vitejs.dev/guide/assets#importing-asset-as-url -import stancWorkerURL from "./stancWorker?worker&url"; +import stancWorkerURL from "@SpStanc/stancWorker?worker&url"; const useStanc = ( modelName: string, diff --git a/gui/src/app/TabWidget/TabWidget.tsx b/gui/src/app/TabWidget/TabWidget.tsx index 512721d5..b583eecf 100644 --- a/gui/src/app/TabWidget/TabWidget.tsx +++ b/gui/src/app/TabWidget/TabWidget.tsx @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import TabWidgetTabBar from "@SpComponents/TabWidgetTabBar"; import { FunctionComponent, PropsWithChildren, @@ -7,7 +8,6 @@ import { useMemo, useState, } from "react"; -import TabWidgetTabBar from "./TabWidgetTabBar"; type Props = { tabs: { diff --git a/gui/src/app/pages/HomePage/HomePage.tsx b/gui/src/app/pages/HomePage/HomePage.tsx index 25e5eb03..5c3787e6 100644 --- a/gui/src/app/pages/HomePage/HomePage.tsx +++ b/gui/src/app/pages/HomePage/HomePage.tsx @@ -1,32 +1,32 @@ import { Splitter } from "@fi-sci/splitter"; -import { - FunctionComponent, - useCallback, - useContext, - useEffect, - useMemo, - useRef, - useState, -} from "react"; -import DataFileEditor from "../../FileEditor/DataFileEditor"; -import StanFileEditor from "../../FileEditor/StanFileEditor"; +import DataFileEditor from "@SpComponents/DataFileEditor"; +import RunPanel from "@SpComponents/RunPanel"; +import SamplerOutputView from "@SpComponents/SamplerOutputView"; +import SamplingOptsPanel from "@SpComponents/SamplingOptsPanel"; +import StanFileEditor from "@SpComponents/StanFileEditor"; import ProjectContextProvider, { ProjectContext, -} from "../../Project/ProjectContextProvider"; +} from "@SpCore/ProjectContextProvider"; import { modelHasUnsavedChanges, modelHasUnsavedDataFileChanges, ProjectKnownFiles, SamplingOpts, -} from "../../Project/ProjectDataModel"; -import RunPanel from "../../RunPanel/RunPanel"; -import SamplerOutputView from "../../SamplerOutputView/SamplerOutputView"; -import SamplingOptsPanel from "../../SamplingOptsPanel/SamplingOptsPanel"; +} from "@SpCore/ProjectDataModel"; +import LeftPanel from "@SpPages/LeftPanel"; +import TopBar from "@SpPages/TopBar"; import useStanSampler, { useSamplerStatus, -} from "../../StanSampler/useStanSampler"; -import LeftPanel from "./LeftPanel"; -import TopBar from "./TopBar"; +} from "@SpStanSampler/useStanSampler"; +import { + FunctionComponent, + useCallback, + useContext, + useEffect, + useMemo, + useRef, + useState, +} from "react"; type Props = { width: number; diff --git a/gui/src/app/pages/HomePage/LeftPanel.tsx b/gui/src/app/pages/HomePage/LeftPanel.tsx index 4ad7c1b4..3bec5cb1 100644 --- a/gui/src/app/pages/HomePage/LeftPanel.tsx +++ b/gui/src/app/pages/HomePage/LeftPanel.tsx @@ -1,11 +1,11 @@ +import { ProjectContext } from "@SpCore/ProjectContextProvider"; +import examplesStanies, { Stanie } from "@SpExamples/exampleStanies"; +import LoadProjectWindow from "@SpPages/LoadProjectWindow"; +import SaveProjectWindow from "@SpPages/SaveProjectWindow"; import { Hyperlink, SmallIconButton } from "@fi-sci/misc"; import ModalWindow, { useModalWindow } from "@fi-sci/modal-window"; -import { FunctionComponent, useCallback, useContext } from "react"; -import examplesStanies, { Stanie } from "../../exampleStanies/exampleStanies"; -import { ProjectContext } from "../../Project/ProjectContextProvider"; -import SaveProjectWindow from "./SaveProjectWindow"; -import LoadProjectWindow from "./LoadProjectWindow"; import { ChevronLeft, ChevronRight } from "@mui/icons-material"; +import { FunctionComponent, useCallback, useContext } from "react"; type LeftPanelProps = { width: number; diff --git a/gui/src/app/pages/HomePage/LoadProjectWindow.tsx b/gui/src/app/pages/HomePage/LoadProjectWindow.tsx index fc31ec11..10eeb1ee 100644 --- a/gui/src/app/pages/HomePage/LoadProjectWindow.tsx +++ b/gui/src/app/pages/HomePage/LoadProjectWindow.tsx @@ -1,3 +1,12 @@ +import { + FieldsContentsMap, + FileNames, + FileRegistry, + mapFileContentsToModel, +} from "@SpCore/FileMapping"; +import { ProjectContext } from "@SpCore/ProjectContextProvider"; +import { deserializeZipToFiles, parseFile } from "@SpCore/ProjectSerialization"; +import UploadFilesArea from "@SpPages/UploadFilesArea"; import { FunctionComponent, useCallback, @@ -5,18 +14,6 @@ import { useEffect, useState, } from "react"; -import { - FieldsContentsMap, - FileNames, - FileRegistry, - mapFileContentsToModel, -} from "../../Project/FileMapping"; -import { ProjectContext } from "../../Project/ProjectContextProvider"; -import { - deserializeZipToFiles, - parseFile, -} from "../../Project/ProjectSerialization"; -import UploadFilesArea from "./UploadFilesArea"; type LoadProjectWindowProps = { onClose: () => void; diff --git a/gui/src/app/pages/HomePage/SaveProjectWindow.tsx b/gui/src/app/pages/HomePage/SaveProjectWindow.tsx index dd05401d..e151c3d1 100644 --- a/gui/src/app/pages/HomePage/SaveProjectWindow.tsx +++ b/gui/src/app/pages/HomePage/SaveProjectWindow.tsx @@ -1,13 +1,10 @@ import { FunctionComponent, useCallback, useContext, useState } from "react"; -import { - FileRegistry, - mapModelToFileManifest, -} from "../../Project/FileMapping"; -import { ProjectContext } from "../../Project/ProjectContextProvider"; -import { serializeAsZip } from "../../Project/ProjectSerialization"; -import { triggerDownload } from "../../util/triggerDownload"; -import saveAsGitHubGist from "../../gists/saveAsGitHubGist"; +import { serializeAsZip } from "@SpCore//ProjectSerialization"; +import { FileRegistry, mapModelToFileManifest } from "@SpCore/FileMapping"; +import { ProjectContext } from "@SpCore/ProjectContextProvider"; +import saveAsGitHubGist from "@SpCore/saveAsGitHubGist"; +import { triggerDownload } from "@SpUtil/triggerDownload"; type SaveProjectWindowProps = { onClose: () => void; diff --git a/gui/src/app/pages/HomePage/TopBar.tsx b/gui/src/app/pages/HomePage/TopBar.tsx index 3c363eee..b941b58b 100644 --- a/gui/src/app/pages/HomePage/TopBar.tsx +++ b/gui/src/app/pages/HomePage/TopBar.tsx @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { FunctionComponent } from "react"; -import CompilationServerConnectionControl from "../../CompilationServerConnectionControl/CompilationServerConnectionControl"; +import CompilationServerConnectionControl from "@SpStanc/CompilationServerConnectionControl"; import { SmallIconButton } from "@fi-sci/misc"; import { QuestionMark } from "@mui/icons-material"; import { Toolbar } from "@mui/material"; +import { FunctionComponent } from "react"; type TopBarProps = { title: string; diff --git a/gui/src/app/SamplerOutputView/stan_stats/fft.ts b/gui/src/app/util/stan_stats/fft.ts similarity index 100% rename from gui/src/app/SamplerOutputView/stan_stats/fft.ts rename to gui/src/app/util/stan_stats/fft.ts diff --git a/gui/src/app/SamplerOutputView/stan_stats/stan_stats.ts b/gui/src/app/util/stan_stats/stan_stats.ts similarity index 99% rename from gui/src/app/SamplerOutputView/stan_stats/stan_stats.ts rename to gui/src/app/util/stan_stats/stan_stats.ts index dc0b2937..26ff18e3 100644 --- a/gui/src/app/SamplerOutputView/stan_stats/stan_stats.ts +++ b/gui/src/app/util/stan_stats/stan_stats.ts @@ -10,7 +10,7 @@ https://github.com/stan-dev/stan/blob/develop/src/stan/analyze/mcmc/compute_pote import { transform as inPlaceFftTransform, inverseTransform as inPlaceInverseFftTransform, -} from "./fft"; +} from "@SpStanStats/fft"; /** * Computes the effective sample size (ESS) for the specified diff --git a/gui/src/app/SamplerOutputView/util.ts b/gui/src/app/util/stan_stats/summaryStats.ts similarity index 100% rename from gui/src/app/SamplerOutputView/util.ts rename to gui/src/app/util/stan_stats/summaryStats.ts diff --git a/gui/test/app/Project/ProjectDataModel.test.ts b/gui/test/app/Project/ProjectDataModel.test.ts index 15463275..af6b766f 100644 --- a/gui/test/app/Project/ProjectDataModel.test.ts +++ b/gui/test/app/Project/ProjectDataModel.test.ts @@ -1,4 +1,3 @@ -import { afterEach, assert, describe, expect, test, vi } from "vitest"; import { exportedForTesting, getStringKnownFileKeys, @@ -12,7 +11,8 @@ import { ProjectKnownFiles, SamplingOpts, stringifyField, -} from "../../../src/app/Project/ProjectDataModel"; +} from "@SpCore/ProjectDataModel"; +import { afterEach, assert, describe, expect, test, vi } from "vitest"; const { baseObjectCheck, diff --git a/gui/test/app/Project/ProjectQueryLoading.test.ts b/gui/test/app/Project/ProjectQueryLoading.test.ts index 47916a69..44810953 100644 --- a/gui/test/app/Project/ProjectQueryLoading.test.ts +++ b/gui/test/app/Project/ProjectQueryLoading.test.ts @@ -1,10 +1,10 @@ -import { afterEach, describe, expect, test, vi } from "vitest"; import { fromQueryParams, // fetchRemoteProject, QueryParamKeys, queryStringHasParameters, -} from "../../../src/app/Project/ProjectQueryLoading"; +} from "@SpCore/ProjectQueryLoading"; +import { afterEach, describe, expect, test, vi } from "vitest"; class MockSearchParams { keysDict: { [key: string]: string }; diff --git a/gui/test/app/StanSampler/MockStanModel.ts b/gui/test/app/StanSampler/MockStanModel.ts index 81a449cf..964c585e 100644 --- a/gui/test/app/StanSampler/MockStanModel.ts +++ b/gui/test/app/StanSampler/MockStanModel.ts @@ -1,12 +1,12 @@ import { vi } from "vitest"; +import { defaultSamplingOpts } from "@SpCore/ProjectDataModel"; import type StanModel from "tinystan"; import type { PrintCallback } from "tinystan"; -import { defaultSamplingOpts } from "../../../src/app/Project/ProjectDataModel"; import fakeURL from "./empty.ts?url"; -import erroringURL from "./fail.ts?url"; import failSentinel from "./fail.ts"; +import erroringURL from "./fail.ts?url"; export const mockCompiledMainJsUrl = fakeURL; export const erroringCompiledMainJsUrl = erroringURL; diff --git a/gui/test/app/StanSampler/useStanSampler.test.ts b/gui/test/app/StanSampler/useStanSampler.test.ts index 75495a54..66903ccd 100644 --- a/gui/test/app/StanSampler/useStanSampler.test.ts +++ b/gui/test/app/StanSampler/useStanSampler.test.ts @@ -1,24 +1,24 @@ // @vitest-environment jsdom -import { expect, test, describe, vi, afterEach, onTestFinished } from "vitest"; +import { act, renderHook, waitFor } from "@testing-library/react"; import "@vitest/web-worker"; -import { renderHook, waitFor, act } from "@testing-library/react"; +import { afterEach, describe, expect, onTestFinished, test, vi } from "vitest"; import mockedLoad, { - mockCompiledMainJsUrl, erroringCompiledMainJsUrl, erroringSamplingOpts, + mockCompiledMainJsUrl, mockedDraws, mockedParamNames, mockedProgress, } from "./MockStanModel"; +import { defaultSamplingOpts } from "@SpCore/ProjectDataModel"; +import type StanSampler from "@SpStanSampler/StanSampler"; import useStanSampler, { useSamplerOutput, useSamplerProgress, useSamplerStatus, -} from "../../../src/app/StanSampler/useStanSampler"; -import { defaultSamplingOpts } from "../../../src/app/Project/ProjectDataModel"; -import type StanSampler from "../../../src/app/StanSampler/StanSampler"; +} from "@SpStanSampler/useStanSampler"; const mockedStdout = vi .spyOn(console, "log") diff --git a/gui/test/app/Stanc/Linting.test.ts b/gui/test/app/Stanc/Linting.test.ts index 7b4f77f4..c61105e0 100644 --- a/gui/test/app/Stanc/Linting.test.ts +++ b/gui/test/app/Stanc/Linting.test.ts @@ -1,8 +1,5 @@ +import { exportedForTesting, stancErrorsToCodeMarkers } from "@SpStanc/Linting"; import { assert, describe, expect, test } from "vitest"; -import { - exportedForTesting, - stancErrorsToCodeMarkers, -} from "../../../src/app/Stanc/Linting"; const { locationFromMessage, getWarningMessage, getErrorMessage } = exportedForTesting; diff --git a/gui/test/app/Stanc/useStanc.test.ts b/gui/test/app/Stanc/useStanc.test.ts index c88762b6..8100fcef 100644 --- a/gui/test/app/Stanc/useStanc.test.ts +++ b/gui/test/app/Stanc/useStanc.test.ts @@ -1,9 +1,9 @@ // @vitest-environment jsdom -import { expect, test, describe, vi, afterEach } from "vitest"; -import "@vitest/web-worker"; +import useStanc from "@SpStanc/useStanc"; import { act, renderHook, waitFor } from "@testing-library/react"; -import useStanc from "../../../src/app/Stanc/useStanc"; +import "@vitest/web-worker"; +import { afterEach, describe, expect, test, vi } from "vitest"; const mockedStdout = vi .spyOn(console, "log") diff --git a/gui/tsconfig.json b/gui/tsconfig.json index 81c2887a..c2a16f44 100644 --- a/gui/tsconfig.json +++ b/gui/tsconfig.json @@ -19,7 +19,33 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + + /* Imports */ + "baseUrl": "./src", + "paths": { + "@SpComponents/*": [ + /* This implies a certain reorganization/recollection process */ + "app/components/*", + "app/FileEditor/*", + "app/RunPanel/*", + "app/SamplerOutputView/*", + "app/SamplingOptsPanel/*", + "app/TabWidget/*" + ], + "@SpCore/*": ["app/Project/*", "app/gists/*"], + /* We are playing a bit fast and loose with the distinction */ + "@SpPages/*": ["app/pages/HomePage/*"], + "@SpStanc/*": [ + "app/Stanc/*", + "app/CompilationServerConnectionControl/*", + "app/compileStanProgram/*" + ], + "@SpStanSampler/*": ["app/StanSampler/*"], + "@SpUtil/*": ["app/util/*"], + "@SpStanStats/*": ["app/util/stan_stats/*"], + "@SpExamples/*": ["app/exampleStanies/*"] + } }, "include": ["src", "test"], "references": [{ "path": "./tsconfig.node.json" }] diff --git a/gui/vite.config.ts b/gui/vite.config.ts index 63ae5a6b..2c39fdfb 100644 --- a/gui/vite.config.ts +++ b/gui/vite.config.ts @@ -1,5 +1,6 @@ import react from "@vitejs/plugin-react"; import { defineConfig } from "vite"; +import tsconfigPaths from "vite-tsconfig-paths"; import { configDefaults, coverageConfigDefaults } from "vitest/config"; // https://vitejs.dev/config/ @@ -37,8 +38,11 @@ export default defineConfig({ }, exclude: [...configDefaults.exclude], }, - plugins: [react()], + plugins: [react(), tsconfigPaths()], server: { host: "127.0.0.1", }, + worker: { + plugins: () => [tsconfigPaths()], + }, }); diff --git a/gui/yarn.lock b/gui/yarn.lock index be356d9c..c4e8fc64 100644 --- a/gui/yarn.lock +++ b/gui/yarn.lock @@ -2265,6 +2265,11 @@ globby@^11.1.0: merge2 "^1.4.1" slash "^3.0.0" +globrex@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/globrex/-/globrex-0.1.2.tgz#dd5d9ec826232730cd6793a5e33a9302985e6098" + integrity sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg== + gopd@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.0.1.tgz#29ff76de69dac7489b7c0918a5788e56477c332c" @@ -3751,6 +3756,11 @@ ts-api-utils@^1.0.1: resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.3.0.tgz#4b490e27129f1e8e686b45cc4ab63714dc60eea1" integrity sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ== +tsconfck@^3.0.3: + version "3.1.1" + resolved "https://registry.yarnpkg.com/tsconfck/-/tsconfck-3.1.1.tgz#c7284913262c293b43b905b8b034f524de4a3162" + integrity sha512-00eoI6WY57SvZEVjm13stEVE90VkEdJAFGgpFLTsZbJyW/LwFQ7uQxJHWpZ2hzSWgCPKc9AnBnNP+0X7o3hAmQ== + tslib@^2.4.0: version "2.6.3" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0" @@ -3891,6 +3901,15 @@ vite-node@1.6.0: picocolors "^1.0.0" vite "^5.0.0" +vite-tsconfig-paths@^4.3.2: + version "4.3.2" + resolved "https://registry.yarnpkg.com/vite-tsconfig-paths/-/vite-tsconfig-paths-4.3.2.tgz#321f02e4b736a90ff62f9086467faf4e2da857a9" + integrity sha512-0Vd/a6po6Q+86rPlntHye7F31zA2URZMbH8M3saAZ/xR9QoGN/L21bxEGfXdWmFdNkqPpRdxFT7nmNe12e9/uA== + dependencies: + debug "^4.1.1" + globrex "^0.1.2" + tsconfck "^3.0.3" + vite@^5.0.0, vite@^5.2.12: version "5.3.1" resolved "https://registry.yarnpkg.com/vite/-/vite-5.3.1.tgz#bb2ca6b5fd7483249d3e86b25026e27ba8a663e6" From 0550ef3a89703a659428c6174ac014511d8bcda8 Mon Sep 17 00:00:00 2001 From: Jeff Soules Date: Mon, 15 Jul 2024 10:47:21 -0400 Subject: [PATCH 2/2] Slight tweaks per WardBrian comments. --- gui/package.json | 4 ++-- gui/src/app/Project/ProjectQueryLoading.ts | 2 +- gui/src/app/pages/HomePage/SaveProjectWindow.tsx | 2 +- gui/tsconfig.json | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/gui/package.json b/gui/package.json index fabbdc25..529056a1 100644 --- a/gui/package.json +++ b/gui/package.json @@ -38,8 +38,7 @@ "react-plotly.js": "^2.6.0", "react-router-dom": "^6.17.0", "react-visibility-sensor": "^5.1.1", - "tinystan": "^0.0.2", - "vite-tsconfig-paths": "^4.3.2" + "tinystan": "^0.0.2" }, "devDependencies": { "@testing-library/dom": "^10.1.0", @@ -61,6 +60,7 @@ "prettier": "^3.3.2", "typescript": "^5.0.2", "vite": "^5.2.12", + "vite-tsconfig-paths": "^4.3.2", "vitest": "^1.6.0" } } diff --git a/gui/src/app/Project/ProjectQueryLoading.ts b/gui/src/app/Project/ProjectQueryLoading.ts index 9503e8c7..c83242ce 100644 --- a/gui/src/app/Project/ProjectQueryLoading.ts +++ b/gui/src/app/Project/ProjectQueryLoading.ts @@ -1,5 +1,5 @@ import { mapFileContentsToModel } from "@SpCore/FileMapping"; -import loadFilesFromGist from "@SpCore/loadFilesFromGist"; +import loadFilesFromGist from "@SpCore/gists/loadFilesFromGist"; import { ProjectDataModel, initialDataModel, diff --git a/gui/src/app/pages/HomePage/SaveProjectWindow.tsx b/gui/src/app/pages/HomePage/SaveProjectWindow.tsx index e151c3d1..704af62d 100644 --- a/gui/src/app/pages/HomePage/SaveProjectWindow.tsx +++ b/gui/src/app/pages/HomePage/SaveProjectWindow.tsx @@ -3,7 +3,7 @@ import { FunctionComponent, useCallback, useContext, useState } from "react"; import { serializeAsZip } from "@SpCore//ProjectSerialization"; import { FileRegistry, mapModelToFileManifest } from "@SpCore/FileMapping"; import { ProjectContext } from "@SpCore/ProjectContextProvider"; -import saveAsGitHubGist from "@SpCore/saveAsGitHubGist"; +import saveAsGitHubGist from "@SpCore/gists/saveAsGitHubGist"; import { triggerDownload } from "@SpUtil/triggerDownload"; type SaveProjectWindowProps = { diff --git a/gui/tsconfig.json b/gui/tsconfig.json index c2a16f44..af2d2595 100644 --- a/gui/tsconfig.json +++ b/gui/tsconfig.json @@ -33,7 +33,8 @@ "app/SamplingOptsPanel/*", "app/TabWidget/*" ], - "@SpCore/*": ["app/Project/*", "app/gists/*"], + "@SpCore/*": ["app/Project/*"], + "@SpCore/gists/*": ["app/gists/*"], /* We are playing a bit fast and loose with the distinction */ "@SpPages/*": ["app/pages/HomePage/*"], "@SpStanc/*": [