@osdk/widget.vite-plugin 3.1.0-beta.3 → 3.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/build/esm/build-plugin/FoundryWidgetBuildPlugin.js +40 -30
- package/build/esm/build-plugin/FoundryWidgetBuildPlugin.js.map +1 -1
- package/build/esm/build-plugin/__tests__/getWidgetBuildOutputs.test.js +25 -20
- package/build/esm/build-plugin/__tests__/getWidgetBuildOutputs.test.js.map +1 -1
- package/build/esm/build-plugin/__tests__/getWidgetSetInputSpec.test.js +96 -0
- package/build/esm/build-plugin/__tests__/getWidgetSetInputSpec.test.js.map +1 -0
- package/build/esm/build-plugin/__tests__/isConfigFile.test.js +26 -0
- package/build/esm/build-plugin/__tests__/isConfigFile.test.js.map +1 -0
- package/build/esm/build-plugin/buildWidgetSetManifest.js +3 -2
- package/build/esm/build-plugin/buildWidgetSetManifest.js.map +1 -1
- package/build/esm/build-plugin/getWidgetBuildOutputs.js +6 -10
- package/build/esm/build-plugin/getWidgetBuildOutputs.js.map +1 -1
- package/build/esm/build-plugin/getWidgetSetInputSpec.js +44 -0
- package/build/esm/build-plugin/getWidgetSetInputSpec.js.map +1 -0
- package/build/esm/build-plugin/isConfigFile.js +1 -1
- package/build/esm/build-plugin/isConfigFile.js.map +1 -1
- package/build/esm/client/app.js +11 -8
- package/build/esm/client/app.js.map +1 -1
- package/build/esm/client/entrypointIframe.js +41 -0
- package/build/esm/client/entrypointIframe.js.map +1 -0
- package/build/esm/common/PackageJson.js +2 -0
- package/build/esm/common/PackageJson.js.map +1 -0
- package/build/esm/common/__tests__/extractWidgetConfig.test.js +73 -0
- package/build/esm/common/__tests__/extractWidgetConfig.test.js.map +1 -0
- package/build/esm/common/__tests__/visitNpmPackages.test.js +74 -0
- package/build/esm/common/__tests__/visitNpmPackages.test.js.map +1 -0
- package/build/esm/common/constants.js +5 -0
- package/build/esm/common/constants.js.map +1 -1
- package/build/esm/common/extractWidgetConfig.js +11 -49
- package/build/esm/common/extractWidgetConfig.js.map +1 -1
- package/build/esm/common/visitNpmPackages.js +62 -0
- package/build/esm/common/visitNpmPackages.js.map +1 -0
- package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js +15 -28
- package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js.map +1 -1
- package/build/esm/dev-plugin/__tests__/getWidgetIdOverrideMap.test.js +13 -8
- package/build/esm/dev-plugin/__tests__/getWidgetIdOverrideMap.test.js.map +1 -1
- package/build/esm/dev-plugin/getWidgetIdOverrideMap.js +6 -6
- package/build/esm/dev-plugin/getWidgetIdOverrideMap.js.map +1 -1
- package/build/esm/dev-plugin/publishDevModeSettings.js +4 -4
- package/build/esm/dev-plugin/publishDevModeSettings.js.map +1 -1
- package/build/site/assets/{allPaths--FceqVry.js → allPaths-DcyFnTvZ.js} +1 -1
- package/build/site/assets/{allPathsLoader-DZfabLiK.js → allPathsLoader-DHYhi3rh.js} +2 -2
- package/build/site/assets/{index-npVd4hRG.js → index-Dm4x3YrF.js} +9 -9
- package/build/site/assets/{splitPathsBySizeLoader-CCtHMC1A.js → splitPathsBySizeLoader-CtOeozdm.js} +1 -1
- package/build/site/index.html +1 -1
- package/build/types/build-plugin/FoundryWidgetBuildPlugin.d.ts.map +1 -1
- package/build/types/build-plugin/__tests__/getWidgetSetInputSpec.test.d.ts +1 -0
- package/build/types/build-plugin/__tests__/getWidgetSetInputSpec.test.d.ts.map +1 -0
- package/build/types/build-plugin/__tests__/isConfigFile.test.d.ts +1 -0
- package/build/types/build-plugin/__tests__/isConfigFile.test.d.ts.map +1 -0
- package/build/types/build-plugin/buildWidgetSetManifest.d.ts +2 -2
- package/build/types/build-plugin/buildWidgetSetManifest.d.ts.map +1 -1
- package/build/types/build-plugin/getWidgetBuildOutputs.d.ts +2 -2
- package/build/types/build-plugin/getWidgetBuildOutputs.d.ts.map +1 -1
- package/build/types/build-plugin/getWidgetSetInputSpec.d.ts +2 -0
- package/build/types/build-plugin/getWidgetSetInputSpec.d.ts.map +1 -0
- package/build/types/client/app.d.ts.map +1 -1
- package/build/types/client/entrypointIframe.d.ts +4 -0
- package/build/types/client/entrypointIframe.d.ts.map +1 -0
- package/build/types/common/PackageJson.d.ts +10 -0
- package/build/types/common/PackageJson.d.ts.map +1 -0
- package/build/types/common/__tests__/extractWidgetConfig.test.d.ts +1 -0
- package/build/types/common/__tests__/extractWidgetConfig.test.d.ts.map +1 -0
- package/build/types/common/__tests__/visitNpmPackages.test.d.ts +1 -0
- package/build/types/common/__tests__/visitNpmPackages.test.d.ts.map +1 -0
- package/build/types/common/constants.d.ts +3 -0
- package/build/types/common/constants.d.ts.map +1 -1
- package/build/types/common/extractWidgetConfig.d.ts +2 -2
- package/build/types/common/extractWidgetConfig.d.ts.map +1 -1
- package/build/types/common/visitNpmPackages.d.ts +4 -0
- package/build/types/common/visitNpmPackages.d.ts.map +1 -0
- package/build/types/dev-plugin/FoundryWidgetDevPlugin.d.ts.map +1 -1
- package/build/types/dev-plugin/getWidgetIdOverrideMap.d.ts +1 -2
- package/build/types/dev-plugin/getWidgetIdOverrideMap.d.ts.map +1 -1
- package/build/types/dev-plugin/publishDevModeSettings.d.ts.map +1 -1
- package/package.json +4 -6
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { visitNpmPackages } from "../common/visitNpmPackages.js";
|
|
18
|
+
export async function getWidgetSetInputSpec(packageJsonPath) {
|
|
19
|
+
const sdks = await discoverOntologySdkInputSpecs(packageJsonPath);
|
|
20
|
+
return {
|
|
21
|
+
discovered: {
|
|
22
|
+
sdks
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async function discoverOntologySdkInputSpecs(packageJsonPath) {
|
|
27
|
+
const sdks = new Set();
|
|
28
|
+
await visitNpmPackages(packageJsonPath, (_packageJsonPath, packageJson) => {
|
|
29
|
+
if (packageJson.osdk?.packageRid != null) {
|
|
30
|
+
sdks.add(toKey(packageJson.osdk.packageRid, packageJson.version));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return [...sdks].map(fromKey);
|
|
34
|
+
}
|
|
35
|
+
const SEPARATOR = "//";
|
|
36
|
+
const toKey = (rid, version) => `${rid}${SEPARATOR}${version}`;
|
|
37
|
+
const fromKey = key => {
|
|
38
|
+
const [rid, version] = key.split(SEPARATOR);
|
|
39
|
+
return {
|
|
40
|
+
rid,
|
|
41
|
+
version
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=getWidgetSetInputSpec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getWidgetSetInputSpec.js","names":["visitNpmPackages","getWidgetSetInputSpec","packageJsonPath","sdks","discoverOntologySdkInputSpecs","discovered","Set","_packageJsonPath","packageJson","osdk","packageRid","add","toKey","version","map","fromKey","SEPARATOR","rid","key","split"],"sources":["getWidgetSetInputSpec.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n OntologySdkInputSpec,\n WidgetSetInputSpec,\n} from \"@osdk/widget.api\";\nimport type { PackageJson } from \"../common/PackageJson.js\";\nimport { visitNpmPackages } from \"../common/visitNpmPackages.js\";\n\nexport async function getWidgetSetInputSpec(\n packageJsonPath: string,\n): Promise<WidgetSetInputSpec> {\n const sdks = await discoverOntologySdkInputSpecs(packageJsonPath);\n return {\n discovered: {\n sdks,\n },\n };\n}\n\nasync function discoverOntologySdkInputSpecs(\n packageJsonPath: string,\n): Promise<Array<OntologySdkInputSpec>> {\n const sdks = new Set<string>();\n const onVisit = (_packageJsonPath: string, packageJson: PackageJson) => {\n if (packageJson.osdk?.packageRid != null) {\n sdks.add(toKey(packageJson.osdk.packageRid, packageJson.version));\n }\n };\n await visitNpmPackages(packageJsonPath, onVisit);\n return [...sdks].map(fromKey);\n}\n\nconst SEPARATOR = \"//\";\nconst toKey = (rid: string, version: string) => `${rid}${SEPARATOR}${version}`;\nconst fromKey = (key: string): OntologySdkInputSpec => {\n const [rid, version] = key.split(SEPARATOR);\n return {\n rid,\n version,\n };\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,gBAAgB,QAAQ,+BAA+B;AAEhE,OAAO,eAAeC,qBAAqBA,CACzCC,eAAuB,EACM;EAC7B,MAAMC,IAAI,GAAG,MAAMC,6BAA6B,CAACF,eAAe,CAAC;EACjE,OAAO;IACLG,UAAU,EAAE;MACVF;IACF;EACF,CAAC;AACH;AAEA,eAAeC,6BAA6BA,CAC1CF,eAAuB,EACe;EACtC,MAAMC,IAAI,GAAG,IAAIG,GAAG,CAAS,CAAC;EAM9B,MAAMN,gBAAgB,CAACE,eAAe,EALtB,CAACK,gBAAwB,EAAEC,WAAwB,KAAK;IACtE,IAAIA,WAAW,CAACC,IAAI,EAAEC,UAAU,IAAI,IAAI,EAAE;MACxCP,IAAI,CAACQ,GAAG,CAACC,KAAK,CAACJ,WAAW,CAACC,IAAI,CAACC,UAAU,EAAEF,WAAW,CAACK,OAAO,CAAC,CAAC;IACnE;EACF,CAC+C,CAAC;EAChD,OAAO,CAAC,GAAGV,IAAI,CAAC,CAACW,GAAG,CAACC,OAAO,CAAC;AAC/B;AAEA,MAAMC,SAAS,GAAG,IAAI;AACtB,MAAMJ,KAAK,GAAGA,CAACK,GAAW,EAAEJ,OAAe,KAAK,GAAGI,GAAG,GAAGD,SAAS,GAAGH,OAAO,EAAE;AAC9E,MAAME,OAAO,GAAIG,GAAW,IAA2B;EACrD,MAAM,CAACD,GAAG,EAAEJ,OAAO,CAAC,GAAGK,GAAG,CAACC,KAAK,CAACH,SAAS,CAAC;EAC3C,OAAO;IACLC,GAAG;IACHJ;EACF,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
import { CONFIG_FILE_SUFFIX } from "../common/constants.js";
|
|
18
18
|
export function isConfigFile(filePath) {
|
|
19
19
|
const trimmedFilePath = filePath.replace(/\.[^/.]+$/, "");
|
|
20
|
-
return trimmedFilePath.endsWith(CONFIG_FILE_SUFFIX);
|
|
20
|
+
return filePath.endsWith(CONFIG_FILE_SUFFIX) || trimmedFilePath.endsWith(CONFIG_FILE_SUFFIX);
|
|
21
21
|
}
|
|
22
22
|
//# sourceMappingURL=isConfigFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isConfigFile.js","names":["CONFIG_FILE_SUFFIX","isConfigFile","filePath","trimmedFilePath","replace","endsWith"],"sources":["isConfigFile.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CONFIG_FILE_SUFFIX } from \"../common/constants.js\";\n\nexport function isConfigFile(filePath: string): boolean {\n const trimmedFilePath = filePath.replace(/\\.[^/.]+$/, \"\");\n return trimmedFilePath.endsWith(CONFIG_FILE_SUFFIX);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,kBAAkB,QAAQ,wBAAwB;AAE3D,OAAO,SAASC,YAAYA,CAACC,QAAgB,EAAW;EACtD,MAAMC,eAAe,GAAGD,QAAQ,CAACE,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;EACzD,
|
|
1
|
+
{"version":3,"file":"isConfigFile.js","names":["CONFIG_FILE_SUFFIX","isConfigFile","filePath","trimmedFilePath","replace","endsWith"],"sources":["isConfigFile.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CONFIG_FILE_SUFFIX } from \"../common/constants.js\";\n\nexport function isConfigFile(filePath: string): boolean {\n const trimmedFilePath = filePath.replace(/\\.[^/.]+$/, \"\");\n return filePath.endsWith(CONFIG_FILE_SUFFIX)\n || trimmedFilePath.endsWith(CONFIG_FILE_SUFFIX);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,kBAAkB,QAAQ,wBAAwB;AAE3D,OAAO,SAASC,YAAYA,CAACC,QAAgB,EAAW;EACtD,MAAMC,eAAe,GAAGD,QAAQ,CAACE,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;EACzD,OAAOF,QAAQ,CAACG,QAAQ,CAACL,kBAAkB,CAAC,IACvCG,eAAe,CAACE,QAAQ,CAACL,kBAAkB,CAAC;AACnD","ignoreList":[]}
|
package/build/esm/client/app.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { NonIdealState, Spinner, SpinnerSize } from "@blueprintjs/core";
|
|
18
18
|
import React, { useEffect } from "react";
|
|
19
|
+
import { EntrypointIframe } from "./entrypointIframe.js";
|
|
19
20
|
const POLLING_INTERVAL = 250;
|
|
20
21
|
const REDIRECT_DELAY = 500;
|
|
21
22
|
export const App = () => {
|
|
@@ -36,15 +37,15 @@ export const App = () => {
|
|
|
36
37
|
if (result.status === "pending") {
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
40
|
+
if (result.status === "error") {
|
|
41
|
+
throw new Error(result.error);
|
|
42
|
+
}
|
|
39
43
|
|
|
40
|
-
// On success
|
|
44
|
+
// On success, we clear the poll and end the loading state
|
|
41
45
|
window.clearInterval(poll);
|
|
42
|
-
setPageState(
|
|
46
|
+
setPageState({
|
|
43
47
|
state: "success",
|
|
44
48
|
isRedirecting: result.redirectUrl != null
|
|
45
|
-
} : {
|
|
46
|
-
state: "failed",
|
|
47
|
-
error: result.error
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
// When running in Code Workspaces the parent app will handle the redirect
|
|
@@ -55,6 +56,8 @@ export const App = () => {
|
|
|
55
56
|
}
|
|
56
57
|
}).catch(error => {
|
|
57
58
|
window.clearInterval(poll);
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.error("Failed to finish dev mode setup:", error);
|
|
58
61
|
setPageState({
|
|
59
62
|
state: "failed",
|
|
60
63
|
error: error instanceof Error ? error.message : undefined
|
|
@@ -83,9 +86,9 @@ export const App = () => {
|
|
|
83
86
|
title: "Failed to start dev mode",
|
|
84
87
|
icon: "error",
|
|
85
88
|
description: pageState.error
|
|
86
|
-
}), entrypointPaths.map(entrypointPath => /*#__PURE__*/React.createElement(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
}), entrypointPaths.map(entrypointPath => /*#__PURE__*/React.createElement(EntrypointIframe, {
|
|
90
|
+
src: entrypointPath,
|
|
91
|
+
key: entrypointPath
|
|
89
92
|
})));
|
|
90
93
|
};
|
|
91
94
|
function loadEntrypoints() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","names":["NonIdealState","Spinner","SpinnerSize","React","useEffect","POLLING_INTERVAL","REDIRECT_DELAY","App","entrypointPaths","setEntrypointPaths","useState","pageState","setPageState","state","loadEntrypoints","then","poll","window","setInterval","finish","result","status","clearInterval","isRedirecting","redirectUrl","
|
|
1
|
+
{"version":3,"file":"app.js","names":["NonIdealState","Spinner","SpinnerSize","React","useEffect","EntrypointIframe","POLLING_INTERVAL","REDIRECT_DELAY","App","entrypointPaths","setEntrypointPaths","useState","pageState","setPageState","state","loadEntrypoints","then","poll","window","setInterval","finish","result","status","Error","error","clearInterval","isRedirecting","redirectUrl","setTimeout","location","href","catch","console","message","undefined","createElement","className","title","icon","intent","description","size","SMALL","map","entrypointPath","src","key","fetch","res","json"],"sources":["app.tsx"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { NonIdealState, Spinner, SpinnerSize } from \"@blueprintjs/core\";\nimport React, { useEffect } from \"react\";\nimport { EntrypointIframe } from \"./entrypointIframe.js\";\n\ntype PageState =\n | {\n state: \"loading\";\n }\n | {\n state: \"failed\";\n error?: string;\n }\n | {\n state: \"success\";\n isRedirecting: boolean;\n };\n\nconst POLLING_INTERVAL = 250;\nconst REDIRECT_DELAY = 500;\n\nexport const App: React.FC = () => {\n const [entrypointPaths, setEntrypointPaths] = React.useState<string[]>([]);\n const [pageState, setPageState] = React.useState<PageState>({\n state: \"loading\",\n });\n\n // Load entrypoints values on mount\n useEffect(() => {\n void loadEntrypoints().then(setEntrypointPaths);\n }, []);\n\n // Poll the finish endpoint until it returns a success or error\n useEffect(() => {\n const poll = window.setInterval(() => {\n void finish()\n .then((result) => {\n if (result.status === \"pending\") {\n return;\n }\n if (result.status === \"error\") {\n throw new Error(result.error);\n }\n\n // On success, we clear the poll and end the loading state\n window.clearInterval(poll);\n setPageState({\n state: \"success\",\n isRedirecting: result.redirectUrl != null,\n });\n\n // When running in Code Workspaces the parent app will handle the redirect\n if (result.status === \"success\" && result.redirectUrl != null) {\n setTimeout(() => {\n window.location.href = result.redirectUrl!;\n }, REDIRECT_DELAY);\n }\n })\n .catch((error: unknown) => {\n window.clearInterval(poll);\n // eslint-disable-next-line no-console\n console.error(\"Failed to finish dev mode setup:\", error);\n setPageState({\n state: \"failed\",\n error: error instanceof Error ? error.message : undefined,\n });\n });\n }, POLLING_INTERVAL);\n return () => window.clearInterval(poll);\n }, []);\n\n return (\n <div className=\"body\">\n {pageState.state === \"loading\" && (\n <NonIdealState\n title=\"Generating developer mode manifest…\"\n icon={<Spinner intent=\"primary\" />}\n />\n )}\n {pageState.state === \"success\" && (\n <NonIdealState\n title=\"Started dev mode\"\n icon=\"tick-circle\"\n description={\n <div className=\"description\">\n <Spinner intent=\"primary\" size={SpinnerSize.SMALL} />{\" \"}\n {pageState.isRedirecting\n ? <span>Redirecting you…</span>\n : <span>Loading preview…</span>}\n </div>\n }\n />\n )}\n {pageState.state === \"failed\" && (\n <NonIdealState\n title=\"Failed to start dev mode\"\n icon=\"error\"\n description={pageState.error}\n />\n )}\n {/* 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 */}\n {entrypointPaths.map((entrypointPath) => (\n <EntrypointIframe src={entrypointPath} key={entrypointPath} />\n ))}\n </div>\n );\n};\n\nfunction loadEntrypoints(): Promise<string[]> {\n return fetch(\"../entrypoints\").then((res) => res.json());\n}\n\nfunction finish(): Promise<\n | {\n status: \"success\";\n redirectUrl: string | null;\n }\n | {\n status: \"error\";\n error: string;\n }\n | {\n status: \"pending\";\n }\n> {\n return fetch(\"../finish\").then((res) => res.json());\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,aAAa,EAAEC,OAAO,EAAEC,WAAW,QAAQ,mBAAmB;AACvE,OAAOC,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,SAASC,gBAAgB,QAAQ,uBAAuB;AAexD,MAAMC,gBAAgB,GAAG,GAAG;AAC5B,MAAMC,cAAc,GAAG,GAAG;AAE1B,OAAO,MAAMC,GAAa,GAAGA,CAAA,KAAM;EACjC,MAAM,CAACC,eAAe,EAAEC,kBAAkB,CAAC,GAAGP,KAAK,CAACQ,QAAQ,CAAW,EAAE,CAAC;EAC1E,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGV,KAAK,CAACQ,QAAQ,CAAY;IAC1DG,KAAK,EAAE;EACT,CAAC,CAAC;;EAEF;EACAV,SAAS,CAAC,MAAM;IACd,KAAKW,eAAe,CAAC,CAAC,CAACC,IAAI,CAACN,kBAAkB,CAAC;EACjD,CAAC,EAAE,EAAE,CAAC;;EAEN;EACAN,SAAS,CA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,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC;AACrD","ignoreList":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { useEffect, useRef } from "react";
|
|
18
|
+
export const EntrypointIframe = ({
|
|
19
|
+
src
|
|
20
|
+
}) => {
|
|
21
|
+
// We expect the widget to not load properly as we don't provide the proper runtime.
|
|
22
|
+
// These errors are not useful to the user as we just put this iframe on the page to
|
|
23
|
+
// trigger vite to load the entrypoints.
|
|
24
|
+
const iframeRef = useRef(null);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (iframeRef.current?.contentWindow != null) {
|
|
27
|
+
const iframeWindow = iframeRef.current.contentWindow;
|
|
28
|
+
iframeWindow.console.log = () => {};
|
|
29
|
+
iframeWindow.console.warn = () => {};
|
|
30
|
+
iframeWindow.console.error = () => {};
|
|
31
|
+
iframeWindow.onerror = () => {
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}, []);
|
|
36
|
+
return /*#__PURE__*/React.createElement("iframe", {
|
|
37
|
+
ref: iframeRef,
|
|
38
|
+
src: src
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=entrypointIframe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entrypointIframe.js","names":["React","useEffect","useRef","EntrypointIframe","src","iframeRef","current","contentWindow","iframeWindow","console","log","warn","error","onerror","createElement","ref"],"sources":["entrypointIframe.tsx"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useEffect, useRef } from \"react\";\n\nexport const EntrypointIframe: React.FC<{ src: string }> = ({ src }) => {\n // We expect the widget to not load properly as we don't provide the proper runtime.\n // These errors are not useful to the user as we just put this iframe on the page to\n // trigger vite to load the entrypoints.\n const iframeRef = useRef<HTMLIFrameElement>(null);\n useEffect(() => {\n if (iframeRef.current?.contentWindow != null) {\n const iframeWindow = iframeRef.current.contentWindow as Window & {\n console: Console;\n };\n iframeWindow.console.log = () => {};\n iframeWindow.console.warn = () => {};\n iframeWindow.console.error = () => {};\n iframeWindow.onerror = () => {\n return true;\n };\n }\n }, []);\n return <iframe ref={iframeRef} src={src} />;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAEhD,OAAO,MAAMC,gBAA2C,GAAGA,CAAC;EAAEC;AAAI,CAAC,KAAK;EACtE;EACA;EACA;EACA,MAAMC,SAAS,GAAGH,MAAM,CAAoB,IAAI,CAAC;EACjDD,SAAS,CAAC,MAAM;IACd,IAAII,SAAS,CAACC,OAAO,EAAEC,aAAa,IAAI,IAAI,EAAE;MAC5C,MAAMC,YAAY,GAAGH,SAAS,CAACC,OAAO,CAACC,aAEtC;MACDC,YAAY,CAACC,OAAO,CAACC,GAAG,GAAG,MAAM,CAAC,CAAC;MACnCF,YAAY,CAACC,OAAO,CAACE,IAAI,GAAG,MAAM,CAAC,CAAC;MACpCH,YAAY,CAACC,OAAO,CAACG,KAAK,GAAG,MAAM,CAAC,CAAC;MACrCJ,YAAY,CAACK,OAAO,GAAG,MAAM;QAC3B,OAAO,IAAI;MACb,CAAC;IACH;EACF,CAAC,EAAE,EAAE,CAAC;EACN,oBAAOb,KAAA,CAAAc,aAAA;IAAQC,GAAG,EAAEV,SAAU;IAACD,GAAG,EAAEA;EAAI,CAAE,CAAC;AAC7C,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PackageJson.js","names":[],"sources":["PackageJson.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface PackageJson {\n name: string;\n version: string;\n osdk?: {\n packageRid?: string;\n };\n dependencies?: {\n [key: string]: string;\n };\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
18
|
+
import { extractWidgetConfig } from "../extractWidgetConfig.js";
|
|
19
|
+
const MOCK_SERVER = {
|
|
20
|
+
ssrLoadModule: vi.fn()
|
|
21
|
+
};
|
|
22
|
+
describe("extractWidgetConfig", () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
vi.restoreAllMocks();
|
|
25
|
+
});
|
|
26
|
+
test("extracts valid widget configuration", async () => {
|
|
27
|
+
vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({
|
|
28
|
+
default: MOCK_CONFIG
|
|
29
|
+
});
|
|
30
|
+
const result = await extractWidgetConfig("/path/to/config.ts", MOCK_SERVER);
|
|
31
|
+
expect(result).toEqual(MOCK_CONFIG);
|
|
32
|
+
});
|
|
33
|
+
test("throws for missing default export", async () => {
|
|
34
|
+
vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({
|
|
35
|
+
notDefault: {
|
|
36
|
+
id: "test"
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
await expect(extractWidgetConfig("/path/to/config.ts", MOCK_SERVER)).rejects.toThrow(expect.objectContaining({
|
|
40
|
+
message: "Failed to load widget config from /path/to/config.ts",
|
|
41
|
+
cause: expect.objectContaining({
|
|
42
|
+
message: "No default export found in /path/to/config.ts"
|
|
43
|
+
})
|
|
44
|
+
}));
|
|
45
|
+
});
|
|
46
|
+
test("throws for invalid module path", async () => {
|
|
47
|
+
vi.mocked(MOCK_SERVER.ssrLoadModule).mockRejectedValue(new Error("Module loading failed"));
|
|
48
|
+
await expect(extractWidgetConfig("/invalid/path/config.ts", MOCK_SERVER)).rejects.toThrow("Failed to load widget config");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
const MOCK_CONFIG = {
|
|
52
|
+
id: "testWidget",
|
|
53
|
+
name: "Test Widget",
|
|
54
|
+
description: "A test widget",
|
|
55
|
+
type: "workshop",
|
|
56
|
+
parameters: {
|
|
57
|
+
paramOne: {
|
|
58
|
+
displayName: "Parameter One",
|
|
59
|
+
type: "string"
|
|
60
|
+
},
|
|
61
|
+
paramTwo: {
|
|
62
|
+
displayName: "Parameter Two",
|
|
63
|
+
type: "string"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
events: {
|
|
67
|
+
updateParameters: {
|
|
68
|
+
displayName: "Update Parameters",
|
|
69
|
+
parameterUpdateIds: ["paramOne", "paramTwo"]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=extractWidgetConfig.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractWidgetConfig.test.js","names":["beforeEach","describe","expect","test","vi","extractWidgetConfig","MOCK_SERVER","ssrLoadModule","fn","restoreAllMocks","mocked","mockResolvedValue","default","MOCK_CONFIG","result","toEqual","notDefault","id","rejects","toThrow","objectContaining","message","cause","mockRejectedValue","Error","name","description","type","parameters","paramOne","displayName","paramTwo","events","updateParameters","parameterUpdateIds"],"sources":["extractWidgetConfig.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ViteDevServer } from \"vite\";\nimport { beforeEach, describe, expect, test, vi } from \"vitest\";\nimport { extractWidgetConfig } from \"../extractWidgetConfig.js\";\n\nconst MOCK_SERVER = {\n ssrLoadModule: vi.fn(),\n} as unknown as ViteDevServer;\n\ndescribe(\"extractWidgetConfig\", () => {\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n test(\"extracts valid widget configuration\", async () => {\n vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({\n default: MOCK_CONFIG,\n });\n\n const result = await extractWidgetConfig(\"/path/to/config.ts\", MOCK_SERVER);\n expect(result).toEqual(MOCK_CONFIG);\n });\n\n test(\"throws for missing default export\", async () => {\n vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({\n notDefault: { id: \"test\" },\n });\n\n await expect(extractWidgetConfig(\"/path/to/config.ts\", MOCK_SERVER))\n .rejects.toThrow(\n expect.objectContaining({\n message: \"Failed to load widget config from /path/to/config.ts\",\n cause: expect.objectContaining({\n message: \"No default export found in /path/to/config.ts\",\n }),\n }),\n );\n });\n\n test(\"throws for invalid module path\", async () => {\n vi.mocked(MOCK_SERVER.ssrLoadModule).mockRejectedValue(\n new Error(\"Module loading failed\"),\n );\n\n await expect(extractWidgetConfig(\"/invalid/path/config.ts\", MOCK_SERVER))\n .rejects.toThrow(\"Failed to load widget config\");\n });\n});\n\nconst MOCK_CONFIG = {\n id: \"testWidget\",\n name: \"Test Widget\",\n description: \"A test widget\",\n type: \"workshop\",\n parameters: {\n paramOne: {\n displayName: \"Parameter One\",\n type: \"string\",\n },\n paramTwo: {\n displayName: \"Parameter Two\",\n type: \"string\",\n },\n },\n events: {\n updateParameters: {\n displayName: \"Update Parameters\",\n parameterUpdateIds: [\"paramOne\", \"paramTwo\"],\n },\n },\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,UAAU,EAAEC,QAAQ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ED,MAAMtB,MAAM,CAACG,mBAAmB,CAAC,yBAAyB,EAAEC,WAAW,CAAC,CAAC,CACtEY,OAAO,CAACC,OAAO,CAAC,8BAA8B,CAAC;EACpD,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAMN,WAAW,GAAG;EAClBI,EAAE,EAAE,YAAY;EAChBQ,IAAI,EAAE,aAAa;EACnBC,WAAW,EAAE,eAAe;EAC5BC,IAAI,EAAE,UAAU;EAChBC,UAAU,EAAE;IACVC,QAAQ,EAAE;MACRC,WAAW,EAAE,eAAe;MAC5BH,IAAI,EAAE;IACR,CAAC;IACDI,QAAQ,EAAE;MACRD,WAAW,EAAE,eAAe;MAC5BH,IAAI,EAAE;IACR;EACF,CAAC;EACDK,MAAM,EAAE;IACNC,gBAAgB,EAAE;MAChBH,WAAW,EAAE,mBAAmB;MAChCI,kBAAkB,EAAE,CAAC,UAAU,EAAE,UAAU;IAC7C;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { readFile } from "fs/promises";
|
|
18
|
+
import resolvePackagePath from "resolve-package-path";
|
|
19
|
+
import { expect, test, vi } from "vitest";
|
|
20
|
+
import { visitNpmPackages } from "../visitNpmPackages.js";
|
|
21
|
+
vi.mock("fs/promises");
|
|
22
|
+
vi.mock("resolve-package-path");
|
|
23
|
+
test("visitNpmPackages", async () => {
|
|
24
|
+
const packageJson1 = {
|
|
25
|
+
name: "package1",
|
|
26
|
+
version: "0.1.0",
|
|
27
|
+
dependencies: {
|
|
28
|
+
"package2": "0.2.0",
|
|
29
|
+
"package3": "0.3.0"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const packageJson2 = {
|
|
33
|
+
name: "package2",
|
|
34
|
+
version: "0.2.0",
|
|
35
|
+
dependencies: {
|
|
36
|
+
"package3": "0.3.0"
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const packageJson3 = {
|
|
40
|
+
name: "package3",
|
|
41
|
+
version: "0.3.0"
|
|
42
|
+
};
|
|
43
|
+
const packageJsonPaths = {
|
|
44
|
+
[packageJson1.name]: "/path/to/package.json",
|
|
45
|
+
[packageJson2.name]: "/path/to/node_modules/package2/package.json",
|
|
46
|
+
[packageJson3.name]: "/path/to/node_modules/package3/package.json"
|
|
47
|
+
};
|
|
48
|
+
const packageJsons = {
|
|
49
|
+
[packageJsonPaths[packageJson1.name]]: packageJson1,
|
|
50
|
+
[packageJsonPaths[packageJson2.name]]: packageJson2,
|
|
51
|
+
[packageJsonPaths[packageJson3.name]]: packageJson3
|
|
52
|
+
};
|
|
53
|
+
vi.mocked(resolvePackagePath).mockImplementation(target => {
|
|
54
|
+
const path = packageJsonPaths[target];
|
|
55
|
+
if (path == null) {
|
|
56
|
+
throw new Error(`Unexpected target: ${target}`);
|
|
57
|
+
}
|
|
58
|
+
return path;
|
|
59
|
+
});
|
|
60
|
+
vi.mocked(readFile).mockImplementation(path => {
|
|
61
|
+
const packageJson = packageJsons[path.toString()];
|
|
62
|
+
if (packageJson == null) {
|
|
63
|
+
throw new Error(`Unexpected path: ${path.toString()}`);
|
|
64
|
+
}
|
|
65
|
+
return Promise.resolve(JSON.stringify(packageJson));
|
|
66
|
+
});
|
|
67
|
+
const onVisit = vi.fn();
|
|
68
|
+
await visitNpmPackages("/path/to/package.json", onVisit);
|
|
69
|
+
expect(onVisit).toHaveBeenCalledTimes(3);
|
|
70
|
+
expect(onVisit).toHaveBeenNthCalledWith(1, "/path/to/package.json", packageJson1);
|
|
71
|
+
expect(onVisit).toHaveBeenNthCalledWith(2, "/path/to/node_modules/package2/package.json", packageJson2);
|
|
72
|
+
expect(onVisit).toHaveBeenNthCalledWith(3, "/path/to/node_modules/package3/package.json", packageJson3);
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=visitNpmPackages.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitNpmPackages.test.js","names":["readFile","resolvePackagePath","expect","test","vi","visitNpmPackages","mock","packageJson1","name","version","dependencies","packageJson2","packageJson3","packageJsonPaths","packageJsons","mocked","mockImplementation","target","path","Error","packageJson","toString","Promise","resolve","JSON","stringify","onVisit","fn","toHaveBeenCalledTimes","toHaveBeenNthCalledWith"],"sources":["visitNpmPackages.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { readFile } from \"fs/promises\";\nimport resolvePackagePath from \"resolve-package-path\";\nimport { expect, test, vi } from \"vitest\";\nimport type { PackageJson } from \"../../common/PackageJson.js\";\nimport { visitNpmPackages } from \"../visitNpmPackages.js\";\n\nvi.mock(\"fs/promises\");\nvi.mock(\"resolve-package-path\");\n\ntest(\"visitNpmPackages\", async () => {\n const packageJson1: PackageJson = {\n name: \"package1\",\n version: \"0.1.0\",\n dependencies: {\n \"package2\": \"0.2.0\",\n \"package3\": \"0.3.0\",\n },\n };\n const packageJson2: PackageJson = {\n name: \"package2\",\n version: \"0.2.0\",\n dependencies: {\n \"package3\": \"0.3.0\",\n },\n };\n const packageJson3: PackageJson = {\n name: \"package3\",\n version: \"0.3.0\",\n };\n\n const packageJsonPaths: Record<string, string> = {\n [packageJson1.name]: \"/path/to/package.json\",\n [packageJson2.name]: \"/path/to/node_modules/package2/package.json\",\n [packageJson3.name]: \"/path/to/node_modules/package3/package.json\",\n } as const;\n const packageJsons: Record<typeof packageJsonPaths[string], PackageJson> = {\n [packageJsonPaths[packageJson1.name]]: packageJson1,\n [packageJsonPaths[packageJson2.name]]: packageJson2,\n [packageJsonPaths[packageJson3.name]]: packageJson3,\n } as const;\n\n vi.mocked(resolvePackagePath).mockImplementation((target) => {\n const path = packageJsonPaths[target];\n if (path == null) {\n throw new Error(`Unexpected target: ${target}`);\n }\n return path;\n });\n vi.mocked(readFile).mockImplementation((path) => {\n const packageJson = packageJsons[path.toString()];\n if (packageJson == null) {\n throw new Error(`Unexpected path: ${path.toString()}`);\n }\n return Promise.resolve(JSON.stringify(packageJson));\n });\n\n const onVisit = vi.fn();\n await visitNpmPackages(\"/path/to/package.json\", onVisit);\n\n expect(onVisit).toHaveBeenCalledTimes(3);\n expect(onVisit).toHaveBeenNthCalledWith(\n 1,\n \"/path/to/package.json\",\n packageJson1,\n );\n expect(onVisit).toHaveBeenNthCalledWith(\n 2,\n \"/path/to/node_modules/package2/package.json\",\n packageJson2,\n );\n expect(onVisit).toHaveBeenNthCalledWith(\n 3,\n \"/path/to/node_modules/package3/package.json\",\n packageJson3,\n );\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,aAAa;AACtC,OAAOC,kBAAkB,MAAM,sBAAsB;AACrD,SAASC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QA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ACf,QAAQ,CAAC,CAACgB,kBAAkB,CAAEE,IAAI,IAAK;IAC/C,MAAME,WAAW,GAAGN,YAAY,CAACI,IAAI,CAACG,QAAQ,CAAC,CAAC,CAAC;IACjD,IAAID,WAAW,IAAI,IAAI,EAAE;MACvB,MAAM,IAAID,KAAK,CAAC,oBAAoBD,IAAI,CAACG,QAAQ,CAAC,CAAC,EAAE,CAAC;IACxD;IACA,OAAOC,OAAO,CAACC,OAAO,CAACC,IAAI,CAACC,SAAS,CAACL,WAAW,CAAC,CAAC;EACrD,CAAC,CAAC;EAEF,MAAMM,OAAO,GAAGtB,EAAE,CAACuB,EAAE,CAAC,CAAC;EACvB,MAAMtB,gBAAgB,CAAC,uBAAuB,EAAEqB,OAAO,CAAC;EAExDxB,MAAM,CAACwB,OAAO,CAAC,CAACE,qBAAqB,CAAC,CAAC,CAAC;EACxC1B,MAAM,CAACwB,OAAO,CAAC,CAACG,uBAAuB,CACrC,CAAC,EACD,uBAAuB,EACvBtB,YACF,CAAC;EACDL,MAAM,CAACwB,OAAO,CAAC,CAACG,uBAAuB,CACrC,CAAC,EACD,6CAA6C,EAC7ClB,YACF,CAAC;EACDT,MAAM,CAACwB,OAAO,CAAC,CAACG,uBAAuB,CACrC,CAAC,EACD,6CAA6C,EAC7CjB,YACF,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -20,4 +20,9 @@ export const ENTRYPOINTS_PATH = `${PALANTIR_PATH}/entrypoints`;
|
|
|
20
20
|
export const FINISH_PATH = `${PALANTIR_PATH}/finish`;
|
|
21
21
|
export const VITE_INJECTIONS_PATH = `${PALANTIR_PATH}/vite-injections.js`;
|
|
22
22
|
export const CONFIG_FILE_SUFFIX = ".config";
|
|
23
|
+
export const BUILD_PLUGIN_ID = "@osdk:widget-build-plugin";
|
|
24
|
+
export const DEV_PLUGIN_ID = "@osdk:widget-dev-plugin";
|
|
25
|
+
|
|
26
|
+
// Custom Vite mode for widget config module evaluation during build
|
|
27
|
+
export const MODULE_EVALUATION_MODE = "build-module-evaluation-mode";
|
|
23
28
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["PALANTIR_PATH","SETUP_PATH","ENTRYPOINTS_PATH","FINISH_PATH","VITE_INJECTIONS_PATH","CONFIG_FILE_SUFFIX"],"sources":["constants.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const PALANTIR_PATH: string = \".palantir\";\nexport const SETUP_PATH: string = `${PALANTIR_PATH}/setup`;\nexport const ENTRYPOINTS_PATH: string = `${PALANTIR_PATH}/entrypoints`;\nexport const FINISH_PATH: string = `${PALANTIR_PATH}/finish`;\nexport const VITE_INJECTIONS_PATH: string =\n `${PALANTIR_PATH}/vite-injections.js`;\nexport const CONFIG_FILE_SUFFIX = \".config\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,aAAqB,GAAG,WAAW;AAChD,OAAO,MAAMC,UAAkB,GAAG,GAAGD,aAAa,QAAQ;AAC1D,OAAO,MAAME,gBAAwB,GAAG,GAAGF,aAAa,cAAc;AACtE,OAAO,MAAMG,WAAmB,GAAG,GAAGH,aAAa,SAAS;AAC5D,OAAO,MAAMI,oBAA4B,GACvC,GAAGJ,aAAa,qBAAqB;AACvC,OAAO,MAAMK,kBAAkB,GAAG,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"constants.js","names":["PALANTIR_PATH","SETUP_PATH","ENTRYPOINTS_PATH","FINISH_PATH","VITE_INJECTIONS_PATH","CONFIG_FILE_SUFFIX","BUILD_PLUGIN_ID","DEV_PLUGIN_ID","MODULE_EVALUATION_MODE"],"sources":["constants.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const PALANTIR_PATH: string = \".palantir\";\nexport const SETUP_PATH: string = `${PALANTIR_PATH}/setup`;\nexport const ENTRYPOINTS_PATH: string = `${PALANTIR_PATH}/entrypoints`;\nexport const FINISH_PATH: string = `${PALANTIR_PATH}/finish`;\nexport const VITE_INJECTIONS_PATH: string =\n `${PALANTIR_PATH}/vite-injections.js`;\nexport const CONFIG_FILE_SUFFIX = \".config\";\n\nexport const BUILD_PLUGIN_ID = \"@osdk:widget-build-plugin\";\nexport const DEV_PLUGIN_ID = \"@osdk:widget-dev-plugin\";\n\n// Custom Vite mode for widget config module evaluation during build\nexport const MODULE_EVALUATION_MODE = \"build-module-evaluation-mode\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,aAAqB,GAAG,WAAW;AAChD,OAAO,MAAMC,UAAkB,GAAG,GAAGD,aAAa,QAAQ;AAC1D,OAAO,MAAME,gBAAwB,GAAG,GAAGF,aAAa,cAAc;AACtE,OAAO,MAAMG,WAAmB,GAAG,GAAGH,aAAa,SAAS;AAC5D,OAAO,MAAMI,oBAA4B,GACvC,GAAGJ,aAAa,qBAAqB;AACvC,OAAO,MAAMK,kBAAkB,GAAG,SAAS;AAE3C,OAAO,MAAMC,eAAe,GAAG,2BAA2B;AAC1D,OAAO,MAAMC,aAAa,GAAG,yBAAyB;;AAEtD;AACA,OAAO,MAAMC,sBAAsB,GAAG,8BAA8B","ignoreList":[]}
|
|
@@ -14,56 +14,18 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
throw new Error("Widget configuration object must be the default export in " + moduleId);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* export default defineConfig({
|
|
28
|
-
* })
|
|
29
|
-
*/
|
|
30
|
-
if (defaultExport.declaration.type === "CallExpression" && defaultExport.declaration.callee.type === "Identifier" && defaultExport.declaration.callee.name === DEFINE_CONFIG_FUNCTION && defaultExport.declaration.arguments[0].type === "ObjectExpression") {
|
|
31
|
-
return parseWidgetConfig(defaultExport.declaration.arguments[0]);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* const MyConfig = defineConfig({
|
|
36
|
-
* })
|
|
37
|
-
* export default MyConfig;
|
|
38
|
-
*/
|
|
39
|
-
if (defaultExport.declaration.type === "Identifier") {
|
|
40
|
-
const variableName = defaultExport.declaration.name;
|
|
41
|
-
for (const node of ast?.body ?? []) {
|
|
42
|
-
const declaration = node.type === "VariableDeclaration" ? node : node.type === "ExportNamedDeclaration" ? node.declaration : undefined;
|
|
43
|
-
if (declaration == null || declaration.type !== "VariableDeclaration") {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (declaration.declarations.some(inner => inner.id.type === "Identifier" && inner.id.name === variableName)) {
|
|
47
|
-
const variableDeclarator = declaration.declarations.find(declarator => declarator.id.type === "Identifier" && declarator.id.name === variableName);
|
|
48
|
-
if (variableDeclarator?.init?.type === "CallExpression" && variableDeclarator.init.callee.type === "Identifier" && variableDeclarator.init.callee.name === DEFINE_CONFIG_FUNCTION && variableDeclarator.init.arguments[0].type === "ObjectExpression") {
|
|
49
|
-
return parseWidgetConfig(variableDeclarator.init.arguments[0]);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
17
|
+
export async function extractWidgetConfig(moduleId, server) {
|
|
18
|
+
try {
|
|
19
|
+
const configModule = await server.ssrLoadModule(moduleId);
|
|
20
|
+
const config = configModule.default;
|
|
21
|
+
if (config == null) {
|
|
22
|
+
throw new Error(`No default export found in ${moduleId}`);
|
|
52
23
|
}
|
|
24
|
+
return config;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new Error(`Failed to load widget config from ${moduleId}`, {
|
|
27
|
+
cause: error
|
|
28
|
+
});
|
|
53
29
|
}
|
|
54
30
|
}
|
|
55
|
-
function parseWidgetConfig(objectExpression) {
|
|
56
|
-
// Convert from AST -> JS string
|
|
57
|
-
let widgetConfigString = escodegen.generate(objectExpression);
|
|
58
|
-
// The output JS string is not valid JSON, so we force it into JSON that we can then print out into a JSON file
|
|
59
|
-
|
|
60
|
-
// Wrap keys in double quotes
|
|
61
|
-
widgetConfigString = widgetConfigString.replace(/([^\s:]+):/g, "\"$1\":");
|
|
62
|
-
// Convert single quote string values to double quotes
|
|
63
|
-
widgetConfigString = widgetConfigString.replace(/: '(.+)'/g, ": \"$1\"");
|
|
64
|
-
|
|
65
|
-
// Convert single quote string values in arrays to double quotes
|
|
66
|
-
widgetConfigString = widgetConfigString.replace(/: \['(.+)'\]/g, ": [\"$1\"]");
|
|
67
|
-
return JSON.parse(widgetConfigString);
|
|
68
|
-
}
|
|
69
31
|
//# sourceMappingURL=extractWidgetConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractWidgetConfig.js","names":["
|
|
1
|
+
{"version":3,"file":"extractWidgetConfig.js","names":["extractWidgetConfig","moduleId","server","configModule","ssrLoadModule","config","default","Error","error","cause"],"sources":["extractWidgetConfig.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ParameterConfig, WidgetConfig } from \"@osdk/widget.api\";\nimport type { ViteDevServer } from \"vite\";\n\nexport async function extractWidgetConfig(\n moduleId: string,\n server: ViteDevServer,\n): Promise<WidgetConfig<ParameterConfig>> {\n try {\n const configModule = await server.ssrLoadModule(moduleId);\n const config = configModule.default;\n\n if (config == null) {\n throw new Error(`No default export found in ${moduleId}`);\n }\n\n return config as WidgetConfig<ParameterConfig>;\n } catch (error) {\n throw new Error(`Failed to load widget config from ${moduleId}`, {\n cause: error,\n });\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,OAAO,eAAeA,mBAAmBA,CACvCC,QAAgB,EAChBC,MAAqB,EACmB;EACxC,IAAI;IACF,MAAMC,YAAY,GAAG,MAAMD,MAAM,CAACE,aAAa,CAACH,QAAQ,CAAC;IACzD,MAAMI,MAAM,GAAGF,YAAY,CAACG,OAAO;IAEnC,IAAID,MAAM,IAAI,IAAI,EAAE;MAClB,MAAM,IAAIE,KAAK,CAAC,8BAA8BN,QAAQ,EAAE,CAAC;IAC3D;IAEA,OAAOI,MAAM;EACf,CAAC,CAAC,OAAOG,KAAK,EAAE;IACd,MAAM,IAAID,KAAK,CAAC,qCAAqCN,QAAQ,EAAE,EAAE;MAC/DQ,KAAK,EAAED;IACT,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { readFile } from "fs/promises";
|
|
18
|
+
import path from "path";
|
|
19
|
+
import resolvePackagePath from "resolve-package-path";
|
|
20
|
+
export async function visitNpmPackages(rootPackageJsonPath, onVisit) {
|
|
21
|
+
const visited = new Set();
|
|
22
|
+
const visitNpmPackagesInternal = async function (packageJsonPath) {
|
|
23
|
+
if (visited.has(packageJsonPath)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const packageJson = await parsePackageJson(packageJsonPath);
|
|
27
|
+
onVisit(packageJsonPath, packageJson);
|
|
28
|
+
visited.add(packageJsonPath);
|
|
29
|
+
const context = path.dirname(packageJsonPath);
|
|
30
|
+
const npmDependencies = Object.keys(packageJson.dependencies ?? {});
|
|
31
|
+
for (const childName of npmDependencies) {
|
|
32
|
+
const childPackageJsonPath = findPackageJsonPath(childName, context);
|
|
33
|
+
await visitNpmPackagesInternal(childPackageJsonPath);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return visitNpmPackagesInternal(rootPackageJsonPath);
|
|
37
|
+
}
|
|
38
|
+
export function findPackageJsonPath(dependency, baseDir) {
|
|
39
|
+
const packagePath = resolvePackagePath(dependency, baseDir);
|
|
40
|
+
if (packagePath == null) {
|
|
41
|
+
throw new Error(`Could not resolve ${dependency} from ${baseDir}`);
|
|
42
|
+
}
|
|
43
|
+
return packagePath;
|
|
44
|
+
}
|
|
45
|
+
export async function parsePackageJson(packageJsonPath) {
|
|
46
|
+
let packageJsonContent;
|
|
47
|
+
try {
|
|
48
|
+
packageJsonContent = await readFile(packageJsonPath, "utf-8");
|
|
49
|
+
} catch (err) {
|
|
50
|
+
throw new Error(`Failed to read file at path. Does it exist?: "${packageJsonPath}"`, {
|
|
51
|
+
cause: err
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(packageJsonContent);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
throw new Error(`Failed to parse package.json content from file "${packageJsonPath}"`, {
|
|
58
|
+
cause: err
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=visitNpmPackages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitNpmPackages.js","names":["readFile","path","resolvePackagePath","visitNpmPackages","rootPackageJsonPath","onVisit","visited","Set","visitNpmPackagesInternal","packageJsonPath","has","packageJson","parsePackageJson","add","context","dirname","npmDependencies","Object","keys","dependencies","childName","childPackageJsonPath","findPackageJsonPath","dependency","baseDir","packagePath","Error","packageJsonContent","err","cause","JSON","parse"],"sources":["visitNpmPackages.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { readFile } from \"fs/promises\";\nimport path from \"path\";\nimport resolvePackagePath from \"resolve-package-path\";\nimport type { PackageJson } from \"./PackageJson.js\";\n\nexport async function visitNpmPackages(\n rootPackageJsonPath: string,\n onVisit: (packageJsonPath: string, packageJson: PackageJson) => void,\n): Promise<void> {\n const visited = new Set<string>();\n\n const visitNpmPackagesInternal = async function(\n packageJsonPath: string,\n ): Promise<void> {\n if (visited.has(packageJsonPath)) {\n return;\n }\n\n const packageJson = await parsePackageJson(packageJsonPath);\n onVisit(\n packageJsonPath,\n packageJson,\n );\n visited.add(packageJsonPath);\n\n const context = path.dirname(packageJsonPath);\n const npmDependencies = Object.keys(packageJson.dependencies ?? {});\n for (const childName of npmDependencies) {\n const childPackageJsonPath = findPackageJsonPath(\n childName,\n context,\n );\n await visitNpmPackagesInternal(childPackageJsonPath);\n }\n };\n\n return visitNpmPackagesInternal(rootPackageJsonPath);\n}\n\nexport function findPackageJsonPath(\n dependency: string,\n baseDir: string,\n): string {\n const packagePath = resolvePackagePath(dependency, baseDir);\n if (packagePath == null) {\n throw new Error(`Could not resolve ${dependency} from ${baseDir}`);\n }\n return packagePath;\n}\n\nexport async function parsePackageJson(\n packageJsonPath: string,\n): Promise<PackageJson> {\n let packageJsonContent;\n try {\n packageJsonContent = await readFile(packageJsonPath, \"utf-8\");\n } catch (err) {\n throw new Error(\n `Failed to read file at path. Does it exist?: \"${packageJsonPath}\"`,\n { cause: err },\n );\n }\n try {\n return JSON.parse(packageJsonContent);\n } catch (err) {\n throw new Error(\n `Failed to parse package.json content from file \"${packageJsonPath}\"`,\n { cause: err },\n );\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,aAAa;AACtC,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,kBAAkB,MAAM,sBAAsB;AAGrD,OAAO,eAAeC,gBAAgBA,CACpCC,mBAA2B,EAC3BC,OAAoE,EACrD;EACf,MAAMC,OAAO,GAAG,IAAIC,GAAG,CAAS,CAAC;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