-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[widgets] Support serving a basic widget manifest in vite serve mode (#…
…1022) * [widgets] Support serving a basic widget manifest in vite serve mode * comments * changeset * better error message * handle 204 * cleanup lockfile * exclude from mrl * lint * drop sampling
- Loading branch information
Showing
16 changed files
with
918 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@osdk/widget-manifest-vite-plugin": minor | ||
--- | ||
|
||
Support basic manifest in vite serve mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"foundryUrl": "https://fake.palantirfoundry.com/", | ||
"widget": { | ||
"rid": "ri.viewregistry..view.fake", | ||
"directory": "./dist", | ||
"autoVersion": { | ||
"type": "git-describe", | ||
"tagPrefix": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright 2024 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { NonIdealState, Spinner, SpinnerSize } from "@blueprintjs/core"; | ||
import React, { useEffect } from "react"; | ||
|
||
export const App: React.FC = () => { | ||
const [entrypointPaths, setEntrypointPaths] = React.useState<string[]>([]); | ||
const [loading, setLoading] = React.useState< | ||
| { state: "success" } | ||
| { state: "failed"; error: string } | ||
| { state: "loading" } | ||
| { state: "not-started" } | ||
>({ state: "not-started" }); | ||
useEffect(() => { | ||
fetch("./entrypoints") | ||
.then((res) => res.json()) | ||
.then(({ entrypoints }: { entrypoints: string[] }) => { | ||
setEntrypointPaths(entrypoints); | ||
// Poll the manifest endpoint until all entrypoints have JS files listed for them | ||
let poll = window.setInterval(() => { | ||
fetch("./manifest") | ||
.then((res) => res.json()) | ||
.then(({ manifest }) => { | ||
let clearInterval = true; | ||
for (const entrypoint of entrypoints) { | ||
if ( | ||
manifest[entrypoint] == null | ||
|| manifest[entrypoint].length === 0 | ||
) { | ||
clearInterval = false; | ||
} | ||
} | ||
if (clearInterval) { | ||
window.clearInterval(poll); | ||
setLoading({ state: "loading" }); | ||
// Tell the vite server to start dev mode for the specified entrypoint | ||
fetch("./finish", { | ||
// TODO: Actually handle multiple entrypoints | ||
body: JSON.stringify({ entrypoint: entrypoints[0] }), | ||
method: "POST", | ||
}).then((res) => { | ||
if (res.status !== 200) { | ||
setLoading({ state: "failed", error: res.statusText }); | ||
} else { | ||
setLoading({ state: "success" }); | ||
setTimeout(() => { | ||
res | ||
.json() | ||
.then( | ||
( | ||
{ redirectUrl }, | ||
) => (window.location.href = redirectUrl), | ||
); | ||
}, 500); | ||
} | ||
}); | ||
} | ||
}); | ||
}, 100); | ||
}); | ||
}, []); | ||
return ( | ||
<div className="body"> | ||
{(loading.state === "loading" || loading.state === "not-started") && ( | ||
<NonIdealState | ||
title="Generating developer mode manifest…" | ||
icon={<Spinner intent="primary" />} | ||
/> | ||
)} | ||
{loading.state === "success" && ( | ||
<NonIdealState | ||
title="Started dev mode" | ||
icon="tick-circle" | ||
description={ | ||
<div className="description"> | ||
<Spinner intent="primary" size={SpinnerSize.SMALL} />{" "} | ||
Redirecting you… | ||
</div> | ||
} | ||
/> | ||
)} | ||
{loading.state === "failed" && ( | ||
<NonIdealState | ||
title="Failed to start dev mode" | ||
icon="error" | ||
description={loading.error} | ||
/> | ||
)} | ||
{/* To load the entrypoint info, we have to actually load it in the browser to get vite to follow the module graph. Since we know these files will fail, we just load them in iframes set to display: none to trigger the load hook in vite */} | ||
{entrypointPaths.map((entrypointPath) => ( | ||
<iframe key={entrypointPath} src={`/${entrypointPath}`} /> | ||
))} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.body { | ||
align-items: center; | ||
display: flex; | ||
height: 100%; | ||
} | ||
|
||
body, | ||
html { | ||
height: 100%; | ||
} | ||
|
||
iframe { | ||
display: none; | ||
} | ||
|
||
.description { | ||
display: flex; | ||
align-items: center; | ||
gap: 5px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2024 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import "@blueprintjs/core/lib/css/blueprint.css"; | ||
import "./main.css"; | ||
|
||
import React from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import { App } from "./app.js"; | ||
|
||
const root = document.querySelector("body")!; | ||
|
||
createRoot(root).render( | ||
<App />, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Palantir: Widget dev mode setup</title> | ||
</head> | ||
<body> | ||
<div id="root-container"> | ||
<div id="root"></div> | ||
</div> | ||
<script type="module" src="/client/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2024 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export const PALANTIR_PATH = ".palantir"; | ||
export const SETUP_PATH = `${PALANTIR_PATH}/setup`; |
Oops, something went wrong.