Skip to content

Commit

Permalink
Merge pull request #129 from flatironinstitute/import-aliasing
Browse files Browse the repository at this point in the history
Update to use path aliases and resolver.
  • Loading branch information
jsoules authored Jul 15, 2024
2 parents 7d46efa + 0550ef3 commit c416772
Show file tree
Hide file tree
Showing 42 changed files with 191 additions and 141 deletions.
1 change: 1 addition & 0 deletions gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,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"
}
}
2 changes: 1 addition & 1 deletion gui/src/app/FileEditor/DataFileEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TextEditor, { ToolbarItem } from "@SpComponents/TextEditor";
import { FunctionComponent, useMemo } from "react";
import TextEditor, { ToolbarItem } from "./TextEditor";

type Props = {
fileName: string;
Expand Down
4 changes: 2 additions & 2 deletions gui/src/app/FileEditor/StanCompileResultWindow.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 5 additions & 5 deletions gui/src/app/FileEditor/StanFileEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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,
useEffect,
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;
Expand Down
6 changes: 3 additions & 3 deletions gui/src/app/FileEditor/TextEditor.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/MainWindow.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/Project/FileMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions gui/src/app/Project/ProjectContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
12 changes: 6 additions & 6 deletions gui/src/app/Project/ProjectQueryLoading.ts
Original file line number Diff line number Diff line change
@@ -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/gists/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",
Expand Down
10 changes: 5 additions & 5 deletions gui/src/app/Project/ProjectReducer.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 4 additions & 4 deletions gui/src/app/Project/ProjectSerialization.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import JSZip from "jszip";
import { replaceSpacesWithUnderscores } from "../util/replaceSpaces";
import {
FieldsContentsMap,
FileNames,
FileRegistry,
ProjectFileMap,
mapFileContentsToModel,
mapModelToFileManifest,
} from "./FileMapping";
} from "@SpCore/FileMapping";
import {
ProjectDataModel,
ProjectKnownFiles,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions gui/src/app/RunPanel/RunPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/SamplerOutputView/HistsView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SequenceHistogramWidget from "@SpComponents/SequenceHistogramWidget";
import { FunctionComponent, useMemo } from "react";
import SequenceHistogramWidget from "./SequenceHistogramWidget";

type HistsViewProps = {
width: number;
Expand Down
16 changes: 8 additions & 8 deletions gui/src/app/SamplerOutputView/SamplerOutputView.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/SamplerOutputView/SequenceHistogramWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import LazyPlotlyPlot from "@SpComponents/LazyPlotlyPlot";
import { FunctionComponent, useMemo } from "react";
import LazyPlotlyPlot from "../components/LazyPlotlyPlot";

type Props = {
histData: number[];
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/SamplerOutputView/SequencePlotWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import LazyPlotlyPlot from "@SpComponents/LazyPlotlyPlot";
import { FunctionComponent, useMemo } from "react";
import LazyPlotlyPlot from "../components/LazyPlotlyPlot";

export type PlotSequence = {
label: string;
Expand Down
10 changes: 7 additions & 3 deletions gui/src/app/SamplerOutputView/SummaryView.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions gui/src/app/SamplerOutputView/TracePlotsView.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/SamplingOptsPanel/SamplingOptsPanel.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 3 additions & 3 deletions gui/src/app/StanSampler/StanSampler.ts
Original file line number Diff line number Diff line change
@@ -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 =
| ""
Expand Down
4 changes: 2 additions & 2 deletions gui/src/app/StanSampler/useStanSampler.ts
Original file line number Diff line number Diff line change
@@ -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<StanSampler | undefined>(undefined);
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/Stanc/Linting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StancErrors } from "./Types";
import { StancErrors } from "@SpStanc/Types";

type Position = {
startLineNumber: number;
Expand Down
6 changes: 3 additions & 3 deletions gui/src/app/Stanc/stancWorker.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions gui/src/app/Stanc/useStanc.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/TabWidget/TabWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import TabWidgetTabBar from "@SpComponents/TabWidgetTabBar";
import {
FunctionComponent,
PropsWithChildren,
Expand All @@ -7,7 +8,6 @@ import {
useMemo,
useState,
} from "react";
import TabWidgetTabBar from "./TabWidgetTabBar";

type Props = {
tabs: {
Expand Down
Loading

0 comments on commit c416772

Please sign in to comment.