Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

studio-ui bundling #368

Merged
merged 31 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fd30305
move files to studio-ui
oshi97 Sep 1, 2023
8bc097e
separate out virtual modules from studio-ui and move generateTailwind…
oshi97 Sep 1, 2023
19108c2
good to remove setInitialState yay!
oshi97 Sep 1, 2023
4de6c48
remove workflows for now also extra gitData slice
oshi97 Sep 1, 2023
a2a94cc
tests working?
oshi97 Sep 1, 2023
b50a731
Automated linting update and features.json sync
github-actions[bot] Sep 1, 2023
a295c06
Update run-tests.yml
oshi97 Sep 1, 2023
92eef74
Update tsconfig.json
oshi97 Sep 1, 2023
d1fff41
add proper content path
oshi97 Sep 5, 2023
1545a64
Merge branch 'main' into dev/separate-ui-package
oshi97 Sep 6, 2023
716e133
respond to alex's comments!
oshi97 Sep 8, 2023
7115dba
Merge branch 'main' into dev/separate-ui-package
oshi97 Sep 8, 2023
c4b5dc0
comments
oshi97 Sep 8, 2023
edd0977
Merge branch 'main' into dev/separate-ui-package
oshi97 Sep 14, 2023
3ef9211
fix tests
oshi97 Sep 14, 2023
0f9da96
update script
oshi97 Sep 14, 2023
954beef
Merge branch 'main' into dev/separate-ui-package
oshi97 Sep 14, 2023
77893ec
Update update-minor-versions.mjs
oshi97 Sep 15, 2023
927c6ec
Add HMR for layouts and remove top-level fragments (#373)
nmanu1 Sep 15, 2023
a685d3a
delete page slice
oshi97 Sep 15, 2023
bf4476c
Merge branch 'main' into dev/separate-ui-package
oshi97 Sep 18, 2023
b2433b8
Automated linting update and features.json sync
github-actions[bot] Sep 18, 2023
238b504
Merge branch 'main' into dev/separate-ui-package
oshi97 Sep 19, 2023
99469fb
Automated linting update and features.json sync
github-actions[bot] Sep 19, 2023
76bf68a
remove empty file
oshi97 Sep 19, 2023
0eb59ff
wip
oshi97 Sep 5, 2023
50bfd20
squash
oshi97 Sep 14, 2023
480a54d
update parsing o import path
oshi97 Sep 18, 2023
c1fbea2
move to dev deps
oshi97 Sep 19, 2023
d957f41
update package lock
oshi97 Sep 19, 2023
5bf6e25
Merge branch 'main' into dev/bundling
oshi97 Sep 20, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ jobs:
- run: npm run build
- run: npm run build-test-site -w=apps/test-site
- run: npm run typecheck-jest
- run: npm run size-limit -w=packages/studio-ui
2,040 changes: 1,305 additions & 735 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions packages/studio-plugin/src/parsers/ComponentTreeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { v4 } from "uuid";
import { FileMetadataKind, TypelessPropVal } from "../types";
import StudioSourceFileParser from "./StudioSourceFileParser";
import StaticParsingHelpers from "./helpers/StaticParsingHelpers";
import TypeGuards from "../utils/TypeGuards";
import ParsingOrchestrator from "../orchestrators/ParsingOrchestrator";
import MissingPropsChecker from "./MissingPropsChecker";

Expand Down Expand Up @@ -77,7 +76,7 @@ export default class ComponentTreeParser {
);
}

if (!TypeGuards.isNotFragmentElement(component)) {
if (!ComponentTreeParser.isNotFragmentElement(component)) {
return {
...commonComponentState,
kind: ComponentStateKind.Fragment,
Expand All @@ -98,6 +97,19 @@ export default class ComponentTreeParser {
};
}

private static isNotFragmentElement(
element: JsxElement | JsxSelfClosingElement | JsxFragment
): element is JsxElement | JsxSelfClosingElement {
if (element.isKind(SyntaxKind.JsxFragment)) {
return false;
}
if (element.isKind(SyntaxKind.JsxSelfClosingElement)) {
return true;
}
const name = StaticParsingHelpers.parseJsxElementName(element);
return !["Fragment", "React.Fragment"].includes(name);
}

private parseElement(
component: JsxElement | JsxSelfClosingElement,
componentName: string,
Expand Down
20 changes: 0 additions & 20 deletions packages/studio-plugin/src/utils/TypeGuards.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import {
JsxElement,
JsxFragment,
JsxSelfClosingElement,
SyntaxKind,
} from "ts-morph";
import {
ComponentState,
ComponentStateKind,
Expand All @@ -18,7 +12,6 @@ import {
SiteSettingsValues,
} from "../types";

import StaticParsingHelpers from "../parsers/helpers/StaticParsingHelpers";
import {
SiteSettingsExpression,
StreamsDataExpression,
Expand Down Expand Up @@ -159,19 +152,6 @@ export default class TypeGuards {
return typeof value === "string" && value.startsWith("siteSettings.");
}

static isNotFragmentElement(
element: JsxElement | JsxSelfClosingElement | JsxFragment
): element is JsxElement | JsxSelfClosingElement {
if (element.isKind(SyntaxKind.JsxFragment)) {
return false;
}
if (element.isKind(SyntaxKind.JsxSelfClosingElement)) {
return true;
}
const name = StaticParsingHelpers.parseJsxElementName(element);
return !["Fragment", "React.Fragment"].includes(name);
}

static isSiteSettingsValues(
propValues: PropValues
): propValues is SiteSettingsValues {
Expand Down
1 change: 1 addition & 0 deletions packages/studio-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stats.html
7 changes: 7 additions & 0 deletions packages/studio-ui/.size-limit.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = [
{
path: "lib/src/index.js",
limit: "700 kB",
gzip: false,
},
];
13 changes: 10 additions & 3 deletions packages/studio-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"scripts": {
"dev": "npm run copy-svg && tsc --watch --preserveWatchOutput -p tsconfig.json",
"copy-svg": "npx copyfiles \"src/**/*.svg\" lib",
"build": "rimraf lib && npm run copy-svg && tsc -p tsconfig.json",
"build": "vite build",
"test": "jest",
"typecheck-jest": "npx tsc -p tests/tsconfig.json"
"typecheck-jest": "npx tsc -p tests/tsconfig.json",
"size-limit": "size-limit"
},
"dependencies": {
"@dhmk/zustand-lens": "^2.0.5",
Expand Down Expand Up @@ -49,6 +50,7 @@
"@babel/plugin-syntax-flow": "^7.18.6",
"@babel/plugin-transform-react-jsx": "^7.19.0",
"@rollup/plugin-typescript": "^10.0.1",
"@size-limit/file": "^9.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
Expand All @@ -64,7 +66,12 @@
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.3.1",
"resize-observer-polyfill": "^1.5.1",
"vite-plugin-svgr": "^3.2.0"
"rollup-plugin-visualizer": "^5.9.2",
"size-limit": "^9.0.0",
"vite": "^4.4.7",
"vite-plugin-css-injected-by-js": "^3.3.0",
"vite-plugin-dts": "^3.5.3",
"vite-plugin-svgr": "^2.4.0"
},
"peerDependencies": {
"@yext/studio-plugin": "*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, MouseEvent, CSSProperties } from "react";
import { ReactComponent as VectorIcon } from "../../icons/vector.svg";
import { startCase } from "lodash";
import startCase from "lodash/startCase";

const listStyles: CSSProperties = {
minWidth: "200px",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEqual } from "lodash";
import isEqual from "lodash/isEqual";
import { Component, PropsWithChildren, ReactInstance } from "react";
import DOMRectProperties from "../store/models/DOMRectProperties";
import useStudioStore from "../store/useStudioStore";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { StaticPageSettings } from "./StaticPageModal";
import { streamScopeFormData } from "../AddPageButton/StreamScopeCollector";
import PageDataValidator from "../../utils/PageDataValidator";
import { toast } from "react-toastify";
import { isEqual } from "lodash";
import isEqual from "lodash/isEqual";

type EntityPageSettings = StaticPageSettings & StreamScopeForm;

Expand Down
2 changes: 1 addition & 1 deletion packages/studio-ui/src/components/SiteSettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SiteSettingsVal,
} from "@yext/studio-plugin";
import React, { useCallback } from "react";
import { startCase } from "lodash";
import startCase from "lodash/startCase";
import useStudioStore from "../store/useStudioStore";
import PropInput from "./PropInput";

Expand Down
2 changes: 1 addition & 1 deletion packages/studio-ui/src/components/common/ColorPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeEvent, useEffect, useMemo, useState } from "react";
import { debounce } from "lodash";
import debounce from "lodash/debounce";
import PropValueHelpers from "../../utils/PropValueHelpers";
import { PropValueKind, PropValueType } from "@yext/studio-plugin";

Expand Down
2 changes: 1 addition & 1 deletion packages/studio-ui/src/hooks/useFuncWithZundoBatching.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useMemo } from "react";
import useTemporalStore from "../store/useTemporalStore";
import { debounce } from "lodash";
import debounce from "lodash/debounce";

/**
* Updates a function so it doesn't trigger Zundo store updates until after a
Expand Down
2 changes: 1 addition & 1 deletion packages/studio-ui/src/hooks/useHasChanges.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useStudioStore from "../store/useStudioStore";
import { isEqual } from "lodash";
import isEqual from "lodash/isEqual";

export default function useHasChanges() {
// TODO(SLAP-2556) Refactor pendingChanges to use PreviousSaveSlice
Expand Down
1 change: 1 addition & 0 deletions packages/studio-ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as App } from "./App";
export { default as hotReloadStore } from "./store/hotReloadStore";
export { StudioHMRUpdateID } from "@yext/studio-plugin";
2 changes: 1 addition & 1 deletion packages/studio-ui/src/store/StudioActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import FileMetadataSlice from "./models/slices/FileMetadataSlice";
import PageSlice from "./models/slices/PageSlice";
import sendMessage from "../messaging/sendMessage";
import { cloneDeep } from "lodash";
import cloneDeep from "lodash/cloneDeep";
import SiteSettingsSlice from "./models/slices/SiteSettingsSlice";
import PreviousSaveSlice from "./models/slices/PreviousSaveSlice";
import StudioConfigSlice from "./models/slices/StudioConfigSlice";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { Stream } from "@yext/pages";
import PageSlice from "../models/slices/PageSlice";
import sendMessage from "../../messaging/sendMessage";
import { isEqual } from "lodash";
import isEqual from "lodash/isEqual";
import StudioActions from "../StudioActions";

export default class GenerateTestDataAction {
Expand Down
2 changes: 1 addition & 1 deletion packages/studio-ui/src/store/slices/createPageSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PageState,
StreamScope,
} from "@yext/studio-plugin";
import { isEqual } from "lodash";
import isEqual from "lodash/isEqual";
import initialStudioData from "virtual_yext-studio";
import DOMRectProperties from "../models/DOMRectProperties";
import PageSlice, { PageSliceStates } from "../models/slices/PageSlice";
Expand Down
2 changes: 1 addition & 1 deletion packages/studio-ui/src/store/zundoMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PageSlice from "./models/slices/PageSlice";
import SiteSettingSlice from "./models/slices/SiteSettingsSlice";
import { StudioStore } from "./models/StudioStore";
import { isEqual } from "lodash";
import isEqual from "lodash/isEqual";
import { ZundoOptions, temporal } from "zundo";
import { TemporalStudioStore } from "./useTemporalStore";
import { StateCreator } from "zustand";
Expand Down
2 changes: 1 addition & 1 deletion packages/studio-ui/src/utils/getPropsForPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PropVal,
PropType,
} from "@yext/studio-plugin";
import { get } from "lodash";
import get from "lodash/get";
import TemplateExpressionFormatter from "./TemplateExpressionFormatter";

/**
Expand Down
35 changes: 35 additions & 0 deletions packages/studio-ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// vite.config.js
import { resolve } from "path";
import { defineConfig, PluginOption } from "vite";
import svgr from "vite-plugin-svgr";
import { visualizer } from "rollup-plugin-visualizer";
import dts from "vite-plugin-dts";
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";

export default defineConfig({
plugins: [
svgr(),
dts(),
cssInjectedByJsPlugin(),
visualizer() as PluginOption,
],
build: {
outDir: "lib",
sourcemap: true,
lib: {
entry: resolve(__dirname, "src/index.ts"),
formats: ["es"],
fileName: "src/index",
},
rollupOptions: {
external: [
"virtual_yext-studio-git-data",
"virtual_yext-studio",
"@pathToUserProjectRoot/tailwind.config",
"react",
"react-dom",
"react/jsx-runtime",
],
},
},
});
4 changes: 2 additions & 2 deletions packages/studio/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { App, hotReloadStore } from "@yext/studio-ui";
import { StudioHMRPayload, StudioHMRUpdateID } from "@yext/studio-plugin";
tmeyer2115 marked this conversation as resolved.
Show resolved Hide resolved
import { App, hotReloadStore, StudioHMRUpdateID } from "@yext/studio-ui";
import type { StudioHMRPayload } from "@yext/studio-plugin";
import "./tailwind-directives.css";

if (import.meta.hot) {
Expand Down