@osdk/widget.vite-plugin 3.1.0-beta.4 → 3.2.0-beta.1
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 +12 -0
- package/build/esm/build-plugin/FoundryWidgetBuildPlugin.js +39 -31
- 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/getWidgetBuildOutputs.js +6 -10
- package/build/esm/build-plugin/getWidgetBuildOutputs.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/__tests__/extractWidgetConfig.test.js +73 -0
- package/build/esm/common/__tests__/extractWidgetConfig.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/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/getWidgetBuildOutputs.d.ts +2 -2
- package/build/types/build-plugin/getWidgetBuildOutputs.d.ts.map +1 -1
- 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/__tests__/extractWidgetConfig.test.d.ts +1 -0
- package/build/types/common/__tests__/extractWidgetConfig.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/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 +5 -8
|
@@ -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,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,QAAQ;AAC/D,SAASC,mBAAmB,QAAQ,2BAA2B;AAE/D,MAAMC,WAAW,GAAG;EAClBC,aAAa,EAAEH,EAAE,CAACI,EAAE,CAAC;AACvB,CAA6B;AAE7BP,QAAQ,CAA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,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":[]}
|
|
@@ -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":[]}
|
|
@@ -18,8 +18,7 @@ import path from "node:path";
|
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import color from "picocolors";
|
|
20
20
|
import sirv from "sirv";
|
|
21
|
-
import { CONFIG_FILE_SUFFIX, ENTRYPOINTS_PATH, FINISH_PATH, SETUP_PATH, VITE_INJECTIONS_PATH } from "../common/constants.js";
|
|
22
|
-
import { extractWidgetConfig } from "../common/extractWidgetConfig.js";
|
|
21
|
+
import { CONFIG_FILE_SUFFIX, DEV_PLUGIN_ID, ENTRYPOINTS_PATH, FINISH_PATH, MODULE_EVALUATION_MODE, SETUP_PATH, VITE_INJECTIONS_PATH } from "../common/constants.js";
|
|
23
22
|
import { getInputHtmlEntrypoints } from "../common/getInputHtmlEntrypoints.js";
|
|
24
23
|
import { standardizeFileExtension } from "../common/standardizeFileExtension.js";
|
|
25
24
|
import { extractInjectedScripts } from "./extractInjectedScripts.js";
|
|
@@ -37,11 +36,18 @@ export function FoundryWidgetDevPlugin() {
|
|
|
37
36
|
const codeEntrypoints = {};
|
|
38
37
|
// Store the map of fully resolved config file paths to entrypoint file paths
|
|
39
38
|
const configFileToEntrypoint = {};
|
|
40
|
-
// Store the configuration per module ID, e.g. /repo/src/widget-one.config.ts -> { ... }
|
|
41
|
-
const configFiles = {};
|
|
42
39
|
return {
|
|
43
|
-
name:
|
|
40
|
+
name: DEV_PLUGIN_ID,
|
|
44
41
|
enforce: "pre",
|
|
42
|
+
// Only apply this plugin during development, skip during tests and build-mode module evaluation
|
|
43
|
+
apply(config, {
|
|
44
|
+
command
|
|
45
|
+
}) {
|
|
46
|
+
if (config.mode === MODULE_EVALUATION_MODE || process.env.VITEST != null) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return command === "serve";
|
|
50
|
+
},
|
|
45
51
|
/**
|
|
46
52
|
* Capture the entrypoints from the Vite config so that we can manually load them on our
|
|
47
53
|
* setup page and trigger module parsing.
|
|
@@ -52,14 +58,8 @@ export function FoundryWidgetDevPlugin() {
|
|
|
52
58
|
/**
|
|
53
59
|
* Check for the required token environment variable in dev mode.
|
|
54
60
|
*/
|
|
55
|
-
config(resolvedConfig
|
|
56
|
-
|
|
57
|
-
}) {
|
|
58
|
-
// Only check for the token environment variable when running in dev mode.
|
|
59
|
-
// When command is "serve" and not in test mode (VITEST).
|
|
60
|
-
if (command === "serve" && process.env.VITEST == null) {
|
|
61
|
-
getFoundryToken(resolvedConfig.mode);
|
|
62
|
-
}
|
|
61
|
+
config(resolvedConfig) {
|
|
62
|
+
getFoundryToken(resolvedConfig.mode);
|
|
63
63
|
},
|
|
64
64
|
/**
|
|
65
65
|
* Configure the Vite server to serve the setup page and handle the finish endpoint. This
|
|
@@ -108,7 +108,7 @@ export function FoundryWidgetDevPlugin() {
|
|
|
108
108
|
server.middlewares.use(serverPath(server, FINISH_PATH), async (_, res) => {
|
|
109
109
|
// Wait for the setup page to trigger the parsing of the config files
|
|
110
110
|
const numEntrypoints = htmlEntrypoints.length;
|
|
111
|
-
const numConfigFiles = Object.keys(
|
|
111
|
+
const numConfigFiles = Object.keys(configFileToEntrypoint).length;
|
|
112
112
|
if (numConfigFiles < numEntrypoints) {
|
|
113
113
|
res.setHeader("Content-Type", "application/json");
|
|
114
114
|
res.end(JSON.stringify({
|
|
@@ -118,7 +118,7 @@ export function FoundryWidgetDevPlugin() {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// Prepare the widget overrides and finish the setup process
|
|
121
|
-
const widgetIdToOverrides = await getWidgetIdOverrideMap(server, codeEntrypoints, configFileToEntrypoint,
|
|
121
|
+
const widgetIdToOverrides = await getWidgetIdOverrideMap(server, codeEntrypoints, configFileToEntrypoint, getBaseHref(server));
|
|
122
122
|
await publishDevModeSettings(server, widgetIdToOverrides, getBaseHref(server), res);
|
|
123
123
|
});
|
|
124
124
|
|
|
@@ -160,19 +160,6 @@ export function FoundryWidgetDevPlugin() {
|
|
|
160
160
|
const fullSourcePath = standardizeFileExtension(getFullSourcePath(source, standardizedImporter));
|
|
161
161
|
configFileToEntrypoint[fullSourcePath] = standardizedImporter;
|
|
162
162
|
}
|
|
163
|
-
},
|
|
164
|
-
/**
|
|
165
|
-
* During dev mode we need to parse the AST of the config files to extract the widget config
|
|
166
|
-
* object manually, as Vite doesn't compile files during dev mode.
|
|
167
|
-
*/
|
|
168
|
-
transform(code, id) {
|
|
169
|
-
const standardizedSource = standardizeFileExtension(id);
|
|
170
|
-
if (configFileToEntrypoint[standardizedSource] != null) {
|
|
171
|
-
const configObject = extractWidgetConfig(id, this.parse(code));
|
|
172
|
-
if (configObject != null) {
|
|
173
|
-
configFiles[standardizedSource] = configObject;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
163
|
}
|
|
177
164
|
};
|
|
178
165
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FoundryWidgetDevPlugin.js","names":["path","fileURLToPath","color","sirv","CONFIG_FILE_SUFFIX","ENTRYPOINTS_PATH","FINISH_PATH","SETUP_PATH","VITE_INJECTIONS_PATH","extractWidgetConfig","getInputHtmlEntrypoints","standardizeFileExtension","extractInjectedScripts","getBaseHref","getFoundryToken","getWidgetIdOverrideMap","publishDevModeSettings","DIR_DIST","__dirname","dirname","import","meta","url","FoundryWidgetDevPlugin","htmlEntrypoints","codeEntrypoints","configFileToEntrypoint","configFiles","name","enforce","buildStart","options","config","resolvedConfig","command","process","env","VITEST","mode","configureServer","server","printUrls","printSetupPageUrl","middlewares","use","serverPath","req","res","next","originalUrl","endsWith","statusCode","setHeader","end","resolve","single","dev","_","JSON","stringify","map","entrypoint","numEntrypoints","length","numConfigFiles","Object","keys","status","widgetIdToOverrides","injectedScripts","inlineScripts","join","resolveId","source","importer","standardizedSource","getFullSourcePath","slice","standardizedImporter","includes","replace","fullSourcePath","transform","code","id","configObject","parse","subPath","base","setupRoute","logger","info","green","bold"],"sources":["FoundryWidgetDevPlugin.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, type WidgetConfig } from \"@osdk/widget.api\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport color from \"picocolors\";\nimport sirv from \"sirv\";\nimport type { Plugin, ViteDevServer } from \"vite\";\nimport {\n CONFIG_FILE_SUFFIX,\n ENTRYPOINTS_PATH,\n FINISH_PATH,\n SETUP_PATH,\n VITE_INJECTIONS_PATH,\n} from \"../common/constants.js\";\nimport { extractWidgetConfig } from \"../common/extractWidgetConfig.js\";\nimport { getInputHtmlEntrypoints } from \"../common/getInputHtmlEntrypoints.js\";\nimport { standardizeFileExtension } from \"../common/standardizeFileExtension.js\";\nimport { extractInjectedScripts } from \"./extractInjectedScripts.js\";\nimport { getBaseHref } from \"./getBaseHref.js\";\nimport { getFoundryToken } from \"./getFoundryToken.js\";\nimport { getWidgetIdOverrideMap } from \"./getWidgetIdOverrideMap.js\";\nimport { publishDevModeSettings } from \"./publishDevModeSettings.js\";\n\n// Location of the setup page assets\nconst DIR_DIST: string = typeof __dirname !== \"undefined\"\n ? __dirname\n : path.dirname(fileURLToPath(import.meta.url));\n\nexport function FoundryWidgetDevPlugin(): Plugin {\n // The root HTML entrypoints of the build process\n let htmlEntrypoints: string[];\n // Fully resolved paths to the entrypoint files, mapped to relative paths\n const codeEntrypoints: Record<string, string> = {};\n // Store the map of fully resolved config file paths to entrypoint file paths\n const configFileToEntrypoint: Record<string, string> = {};\n // Store the configuration per module ID, e.g. /repo/src/widget-one.config.ts -> { ... }\n const configFiles: Record<string, WidgetConfig<ParameterConfig>> = {};\n\n return {\n name: \"@osdk:widget-dev-plugin\",\n enforce: \"pre\",\n\n /**\n * Capture the entrypoints from the Vite config so that we can manually load them on our\n * setup page and trigger module parsing.\n */\n buildStart(options) {\n htmlEntrypoints = getInputHtmlEntrypoints(options);\n },\n\n /**\n * Check for the required token environment variable in dev mode.\n */\n config(resolvedConfig, { command }) {\n // Only check for the token environment variable when running in dev mode.\n // When command is \"serve\" and not in test mode (VITEST).\n if (command === \"serve\" && process.env.VITEST == null) {\n getFoundryToken(resolvedConfig.mode);\n }\n },\n\n /**\n * Configure the Vite server to serve the setup page and handle the finish endpoint. This\n * endpoint will set the widget overrides in Foundry and enable dev mode.\n */\n configureServer(server) {\n // Override the printUrls function to print the setup page URL\n server.printUrls = () => printSetupPageUrl(server);\n\n /**\n * Redirect `./.palantir/setup` to `./.palantir/setup/` to ensure that relative paths work\n * correctly. Relative paths must be used so that the dev server UI can be accessed on\n * non-root paths.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n (req, res, next) => {\n if (req.originalUrl?.endsWith(serverPath(server, SETUP_PATH))) {\n res.statusCode = 301;\n res.setHeader(\"Location\", `${serverPath(server, SETUP_PATH)}/`);\n res.end();\n } else {\n next();\n }\n },\n );\n\n /**\n * Serve the setup page that will load the entrypoints in iframes and trigger the finish\n * endpoint once widgets have been loaded.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n sirv(path.resolve(DIR_DIST, \"../../site\"), {\n single: true,\n dev: true,\n }),\n );\n\n /**\n * Make the entrypoints available to the setup page so that it can load them in iframes in\n * order to trigger module parsing.\n */\n server.middlewares.use(\n serverPath(server, ENTRYPOINTS_PATH),\n (_, res) => {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(\n JSON.stringify(\n htmlEntrypoints.map((entrypoint) =>\n serverPath(server, entrypoint)\n ),\n ),\n );\n },\n );\n\n /**\n * Finish the setup process by setting the widget overrides in Foundry and enabling dev mode.\n */\n server.middlewares.use(\n serverPath(server, FINISH_PATH),\n async (_, res) => {\n // Wait for the setup page to trigger the parsing of the config files\n const numEntrypoints = htmlEntrypoints.length;\n const numConfigFiles = Object.keys(configFiles).length;\n if (numConfigFiles < numEntrypoints) {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(JSON.stringify({ status: \"pending\" }));\n return;\n }\n\n // Prepare the widget overrides and finish the setup process\n const widgetIdToOverrides = await getWidgetIdOverrideMap(\n server,\n codeEntrypoints,\n configFileToEntrypoint,\n configFiles,\n getBaseHref(server),\n );\n await publishDevModeSettings(\n server,\n widgetIdToOverrides,\n getBaseHref(server),\n res,\n );\n },\n );\n\n /**\n * Serve scripts that would usually be injected into the HTML if Vite had control over the\n * serving of index HTML pages. This is necessary to ensure that plugins like React refresh\n * work correctly.\n */\n server.middlewares.use(\n serverPath(server, VITE_INJECTIONS_PATH),\n async (_, res) => {\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.setHeader(\"Content-Type\", \"application/javascript\");\n const injectedScripts = await extractInjectedScripts(server);\n res.end(injectedScripts.inlineScripts.join(\"\\n\"));\n },\n );\n },\n\n /**\n * As module imports are resolved, we need to capture the entrypoint file paths and the config\n * file paths that are imported from them.\n */\n resolveId(source, importer) {\n if (importer == null) {\n return;\n }\n\n // Standardize the source file extension and get the full path\n const standardizedSource = standardizeFileExtension(\n getFullSourcePath(source.slice(1), importer),\n );\n // Importers are already full paths, so just standardize the extension\n const standardizedImporter = standardizeFileExtension(importer);\n\n // In dev mode all entrypoints have a generic HTML importer value\n if (\n importer.endsWith(\"index.html\") && !standardizedSource.includes(\"@fs\")\n ) {\n // Store the fully resolved path and the relative path, as we need the former for mapping\n // config files to entrypoints and the latter as a dev mode override script\n codeEntrypoints[standardizedSource] = source;\n }\n\n // Look for config files that are imported from an entrypoint file\n if (\n standardizedSource.replace(/\\.[^/.]+$/, \"\").endsWith(CONFIG_FILE_SUFFIX)\n && codeEntrypoints[standardizedImporter] != null\n ) {\n const fullSourcePath = standardizeFileExtension(\n getFullSourcePath(source, standardizedImporter),\n );\n configFileToEntrypoint[fullSourcePath] = standardizedImporter;\n }\n },\n\n /**\n * During dev mode we need to parse the AST of the config files to extract the widget config\n * object manually, as Vite doesn't compile files during dev mode.\n */\n transform(code, id) {\n const standardizedSource = standardizeFileExtension(id);\n if (configFileToEntrypoint[standardizedSource] != null) {\n const configObject = extractWidgetConfig(id, this.parse(code));\n if (configObject != null) {\n configFiles[standardizedSource] = configObject;\n }\n }\n },\n };\n}\n\n/**\n * During the resolution phase source are given as relative paths to the importer\n */\nfunction getFullSourcePath(source: string, importer: string): string {\n return path.resolve(path.dirname(importer), source);\n}\n\nfunction serverPath(server: ViteDevServer, subPath: string): string {\n return path.resolve(server.config.base, subPath);\n}\n\nfunction printSetupPageUrl(server: ViteDevServer) {\n const setupRoute = `${getBaseHref(server)}${SETUP_PATH}/`;\n server.config.logger.info(\n ` ${color.green(\"➜\")} ${\n color.bold(\"Click to enter developer mode for your widget set\")\n }: ${color.green(setupRoute)}`,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,IAAI,MAAM,WAAW;AAC5B,SAASC,aAAa,QAAQ,UAAU;AACxC,OAAOC,KAAK,MAAM,YAAY;AAC9B,OAAOC,IAAI,MAAM,MAAM;AAEvB,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,WAAW,EACXC,UAAU,EACVC,oBAAoB,QACf,wBAAwB;AAC/B,SAASC,mBAAmB,QAAQ,kCAAkC;AACtE,SAASC,uBAAuB,QAAQ,sCAAsC;AAC9E,SAASC,wBAAwB,QAAQ,uCAAuC;AAChF,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,sBAAsB,QAAQ,6BAA6B;;AAEpE;AACA,MAAMC,QAAgB,GAAG,OAAOC,SAAS,KAAK,WAAW,GACrDA,SAAS,GACTlB,IAAI,CAACmB,OAAO,CAAClB,aAAa,CAACmB,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAEhD,OAAO,SAASC,sBAAsBA,CAAA,EAAW;EAC/C;EACA,IAAIC,eAAyB;EAC7B;EACA,MAAMC,eAAuC,GAAG,CAAC,CAAC;EAClD;EACA,MAAMC,sBAA8C,GAAG,CAAC,CAAC;EACzD;EACA,MAAMC,WAA0D,GAAG,CAAC,CAAC;EAErE,OAAO;IACLC,IAAI,EAAE,yBAAyB;IAC/BC,OAAO,EAAE,KAAK;IAEd;AACJ;AACA;AACA;IACIC,UAAUA,CAACC,OAAO,EAAE;MAClBP,eAAe,GAAGd,uBAA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;QACtD,MAAMU,YAAY,GAAG5E,mBAAmB,CAAC2E,EAAE,EAAE,IAAI,CAACE,KAAK,CAACH,IAAI,CAAC,CAAC;QAC9D,IAAIE,YAAY,IAAI,IAAI,EAAE;UACxB1D,WAAW,CAACgD,kBAAkB,CAAC,GAAGU,YAAY;QAChD;MACF;IACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA,SAAST,iBAAiBA,CAACH,MAAc,EAAEC,QAAgB,EAAU;EACnE,OAAO1E,IAAI,CAACsD,OAAO,CAACtD,IAAI,CAACmB,OAAO,CAACuD,QAAQ,CAAC,EAAED,MAAM,CAAC;AACrD;AAEA,SAAS5B,UAAUA,CAACL,MAAqB,EAAE+C,OAAe,EAAU;EAClE,OAAOvF,IAAI,CAACsD,OAAO,CAACd,MAAM,CAACR,MAAM,CAACwD,IAAI,EAAED,OAAO,CAAC;AAClD;AAEA,SAAS7C,iBAAiBA,CAACF,MAAqB,EAAE;EAChD,MAAMiD,UAAU,GAAG,GAAG5E,WAAW,CAAC2B,MAAM,CAAC,GAAGjC,UAAU,GAAG;EACzDiC,MAAM,CAACR,MAAM,CAAC0D,MAAM,CAACC,IAAI,CACvB,KAAKzF,KAAK,CAAC0F,KAAK,CAAC,GAAG,CAAC,KACnB1F,KAAK,CAAC2F,IAAI,CAAC,mDAAmD,CAAC,KAC5D3F,KAAK,CAAC0F,KAAK,CAACH,UAAU,CAAC,EAC9B,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"FoundryWidgetDevPlugin.js","names":["path","fileURLToPath","color","sirv","CONFIG_FILE_SUFFIX","DEV_PLUGIN_ID","ENTRYPOINTS_PATH","FINISH_PATH","MODULE_EVALUATION_MODE","SETUP_PATH","VITE_INJECTIONS_PATH","getInputHtmlEntrypoints","standardizeFileExtension","extractInjectedScripts","getBaseHref","getFoundryToken","getWidgetIdOverrideMap","publishDevModeSettings","DIR_DIST","__dirname","dirname","import","meta","url","FoundryWidgetDevPlugin","htmlEntrypoints","codeEntrypoints","configFileToEntrypoint","name","enforce","apply","config","command","mode","process","env","VITEST","buildStart","options","resolvedConfig","configureServer","server","printUrls","printSetupPageUrl","middlewares","use","serverPath","req","res","next","originalUrl","endsWith","statusCode","setHeader","end","resolve","single","dev","_","JSON","stringify","map","entrypoint","numEntrypoints","length","numConfigFiles","Object","keys","status","widgetIdToOverrides","injectedScripts","inlineScripts","join","resolveId","source","importer","standardizedSource","getFullSourcePath","slice","standardizedImporter","includes","replace","fullSourcePath","subPath","base","setupRoute","logger","info","green","bold"],"sources":["FoundryWidgetDevPlugin.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 path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport color from \"picocolors\";\nimport sirv from \"sirv\";\nimport type { Plugin, ViteDevServer } from \"vite\";\nimport {\n CONFIG_FILE_SUFFIX,\n DEV_PLUGIN_ID,\n ENTRYPOINTS_PATH,\n FINISH_PATH,\n MODULE_EVALUATION_MODE,\n SETUP_PATH,\n VITE_INJECTIONS_PATH,\n} from \"../common/constants.js\";\nimport { getInputHtmlEntrypoints } from \"../common/getInputHtmlEntrypoints.js\";\nimport { standardizeFileExtension } from \"../common/standardizeFileExtension.js\";\nimport { extractInjectedScripts } from \"./extractInjectedScripts.js\";\nimport { getBaseHref } from \"./getBaseHref.js\";\nimport { getFoundryToken } from \"./getFoundryToken.js\";\nimport { getWidgetIdOverrideMap } from \"./getWidgetIdOverrideMap.js\";\nimport { publishDevModeSettings } from \"./publishDevModeSettings.js\";\n\n// Location of the setup page assets\nconst DIR_DIST: string = typeof __dirname !== \"undefined\"\n ? __dirname\n : path.dirname(fileURLToPath(import.meta.url));\n\nexport function FoundryWidgetDevPlugin(): Plugin {\n // The root HTML entrypoints of the build process\n let htmlEntrypoints: string[];\n // Fully resolved paths to the entrypoint files, mapped to relative paths\n const codeEntrypoints: Record<string, string> = {};\n // Store the map of fully resolved config file paths to entrypoint file paths\n const configFileToEntrypoint: Record<string, string> = {};\n\n return {\n name: DEV_PLUGIN_ID,\n enforce: \"pre\",\n // Only apply this plugin during development, skip during tests and build-mode module evaluation\n apply(config, { command }) {\n if (\n config.mode === MODULE_EVALUATION_MODE || process.env.VITEST != null\n ) {\n return false;\n }\n return command === \"serve\";\n },\n\n /**\n * Capture the entrypoints from the Vite config so that we can manually load them on our\n * setup page and trigger module parsing.\n */\n buildStart(options) {\n htmlEntrypoints = getInputHtmlEntrypoints(options);\n },\n\n /**\n * Check for the required token environment variable in dev mode.\n */\n config(resolvedConfig) {\n getFoundryToken(resolvedConfig.mode);\n },\n\n /**\n * Configure the Vite server to serve the setup page and handle the finish endpoint. This\n * endpoint will set the widget overrides in Foundry and enable dev mode.\n */\n configureServer(server) {\n // Override the printUrls function to print the setup page URL\n server.printUrls = () => printSetupPageUrl(server);\n\n /**\n * Redirect `./.palantir/setup` to `./.palantir/setup/` to ensure that relative paths work\n * correctly. Relative paths must be used so that the dev server UI can be accessed on\n * non-root paths.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n (req, res, next) => {\n if (req.originalUrl?.endsWith(serverPath(server, SETUP_PATH))) {\n res.statusCode = 301;\n res.setHeader(\"Location\", `${serverPath(server, SETUP_PATH)}/`);\n res.end();\n } else {\n next();\n }\n },\n );\n\n /**\n * Serve the setup page that will load the entrypoints in iframes and trigger the finish\n * endpoint once widgets have been loaded.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n sirv(path.resolve(DIR_DIST, \"../../site\"), {\n single: true,\n dev: true,\n }),\n );\n\n /**\n * Make the entrypoints available to the setup page so that it can load them in iframes in\n * order to trigger module parsing.\n */\n server.middlewares.use(\n serverPath(server, ENTRYPOINTS_PATH),\n (_, res) => {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(\n JSON.stringify(\n htmlEntrypoints.map((entrypoint) =>\n serverPath(server, entrypoint)\n ),\n ),\n );\n },\n );\n\n /**\n * Finish the setup process by setting the widget overrides in Foundry and enabling dev mode.\n */\n server.middlewares.use(\n serverPath(server, FINISH_PATH),\n async (_, res) => {\n // Wait for the setup page to trigger the parsing of the config files\n const numEntrypoints = htmlEntrypoints.length;\n const numConfigFiles = Object.keys(configFileToEntrypoint).length;\n if (numConfigFiles < numEntrypoints) {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(JSON.stringify({ status: \"pending\" }));\n return;\n }\n\n // Prepare the widget overrides and finish the setup process\n const widgetIdToOverrides = await getWidgetIdOverrideMap(\n server,\n codeEntrypoints,\n configFileToEntrypoint,\n getBaseHref(server),\n );\n await publishDevModeSettings(\n server,\n widgetIdToOverrides,\n getBaseHref(server),\n res,\n );\n },\n );\n\n /**\n * Serve scripts that would usually be injected into the HTML if Vite had control over the\n * serving of index HTML pages. This is necessary to ensure that plugins like React refresh\n * work correctly.\n */\n server.middlewares.use(\n serverPath(server, VITE_INJECTIONS_PATH),\n async (_, res) => {\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.setHeader(\"Content-Type\", \"application/javascript\");\n const injectedScripts = await extractInjectedScripts(server);\n res.end(injectedScripts.inlineScripts.join(\"\\n\"));\n },\n );\n },\n\n /**\n * As module imports are resolved, we need to capture the entrypoint file paths and the config\n * file paths that are imported from them.\n */\n resolveId(source, importer) {\n if (importer == null) {\n return;\n }\n\n // Standardize the source file extension and get the full path\n const standardizedSource = standardizeFileExtension(\n getFullSourcePath(source.slice(1), importer),\n );\n // Importers are already full paths, so just standardize the extension\n const standardizedImporter = standardizeFileExtension(importer);\n\n // In dev mode all entrypoints have a generic HTML importer value\n if (\n importer.endsWith(\"index.html\") && !standardizedSource.includes(\"@fs\")\n ) {\n // Store the fully resolved path and the relative path, as we need the former for mapping\n // config files to entrypoints and the latter as a dev mode override script\n codeEntrypoints[standardizedSource] = source;\n }\n\n // Look for config files that are imported from an entrypoint file\n if (\n standardizedSource.replace(/\\.[^/.]+$/, \"\").endsWith(CONFIG_FILE_SUFFIX)\n && codeEntrypoints[standardizedImporter] != null\n ) {\n const fullSourcePath = standardizeFileExtension(\n getFullSourcePath(source, standardizedImporter),\n );\n configFileToEntrypoint[fullSourcePath] = standardizedImporter;\n }\n },\n };\n}\n\n/**\n * During the resolution phase source are given as relative paths to the importer\n */\nfunction getFullSourcePath(source: string, importer: string): string {\n return path.resolve(path.dirname(importer), source);\n}\n\nfunction serverPath(server: ViteDevServer, subPath: string): string {\n return path.resolve(server.config.base, subPath);\n}\n\nfunction printSetupPageUrl(server: ViteDevServer) {\n const setupRoute = `${getBaseHref(server)}${SETUP_PATH}/`;\n server.config.logger.info(\n ` ${color.green(\"➜\")} ${\n color.bold(\"Click to enter developer mode for your widget set\")\n }: ${color.green(setupRoute)}`,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,WAAW;AAC5B,SAASC,aAAa,QAAQ,UAAU;AACxC,OAAOC,KAAK,MAAM,YAAY;AAC9B,OAAOC,IAAI,MAAM,MAAM;AAEvB,SACEC,kBAAkB,EAClBC,aAAa,EACbC,gBAAgB,EAChBC,WAAW,EACXC,sBAAsB,EACtBC,UAAU,EACVC,oBAAoB,QACf,wBAAwB;AAC/B,SAASC,uBAAuB,QAAQ,sCAAsC;AAC9E,SAASC,wBAAwB,QAAQ,uCAAuC;AAChF,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,sBAAsB,QAAQ,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QAAQ,CAAC,KAAK,CAAC,EACtE;QACA;QACA;QACAtD,eAAe,CAACkD,kBAAkB,CAAC,GAAGF,MAAM;MAC9C;;MAEA;MACA,IACEE,kBAAkB,CAACK,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC9B,QAAQ,CAAC/C,kBAAkB,CAAC,IACrEsB,eAAe,CAACqD,oBAAoB,CAAC,IAAI,IAAI,EAChD;QACA,MAAMG,cAAc,GAAGtE,wBAAwB,CAC7CiE,iBAAiB,CAACH,MAAM,EAAEK,oBAAoB,CAChD,CAAC;QACDpD,sBAAsB,CAACuD,cAAc,CAAC,GAAGH,oBAAoB;MAC/D;IACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA,SAASF,iBAAiBA,CAACH,MAAc,EAAEC,QAAgB,EAAU;EACnE,OAAO3E,IAAI,CAACuD,OAAO,CAACvD,IAAI,CAACoB,OAAO,CAACuD,QAAQ,CAAC,EAAED,MAAM,CAAC;AACrD;AAEA,SAAS5B,UAAUA,CAACL,MAAqB,EAAE0C,OAAe,EAAU;EAClE,OAAOnF,IAAI,CAACuD,OAAO,CAACd,MAAM,CAACV,MAAM,CAACqD,IAAI,EAAED,OAAO,CAAC;AAClD;AAEA,SAASxC,iBAAiBA,CAACF,MAAqB,EAAE;EAChD,MAAM4C,UAAU,GAAG,GAAGvE,WAAW,CAAC2B,MAAM,CAAC,GAAGhC,UAAU,GAAG;EACzDgC,MAAM,CAACV,MAAM,CAACuD,MAAM,CAACC,IAAI,CACvB,KAAKrF,KAAK,CAACsF,KAAK,CAAC,GAAG,CAAC,KACnBtF,KAAK,CAACuF,IAAI,CAAC,mDAAmD,CAAC,KAC5DvF,KAAK,CAACsF,KAAK,CAACH,UAAU,CAAC,EAC9B,CAAC;AACH","ignoreList":[]}
|
|
@@ -17,21 +17,26 @@
|
|
|
17
17
|
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
18
18
|
import * as extractInjectedScriptsModule from "../extractInjectedScripts.js";
|
|
19
19
|
import { getWidgetIdOverrideMap } from "../getWidgetIdOverrideMap.js";
|
|
20
|
-
const
|
|
20
|
+
const MOCK_WIDGET_CONFIG = {
|
|
21
|
+
id: "widgetId"
|
|
22
|
+
};
|
|
23
|
+
const MOCK_SERVER = {
|
|
24
|
+
ssrLoadModule: vi.fn().mockResolvedValue({
|
|
25
|
+
default: MOCK_WIDGET_CONFIG
|
|
26
|
+
})
|
|
27
|
+
};
|
|
21
28
|
const MOCK_CODE_ENTRYPOINTS = {
|
|
22
29
|
"entry.ts": `/entry.js`
|
|
23
30
|
};
|
|
24
31
|
const MOCK_CONFIG_FILE_TO_ENTRYPOINT = {
|
|
25
32
|
"widget.config.ts": "entry.ts"
|
|
26
33
|
};
|
|
27
|
-
const MOCK_CONFIG_FILES = {
|
|
28
|
-
"widget.config.ts": {
|
|
29
|
-
id: "widgetId"
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
34
|
describe("getWidgetIdOverrideMap", () => {
|
|
33
35
|
beforeEach(() => {
|
|
34
36
|
vi.restoreAllMocks();
|
|
37
|
+
vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({
|
|
38
|
+
default: MOCK_WIDGET_CONFIG
|
|
39
|
+
});
|
|
35
40
|
});
|
|
36
41
|
test("localhost dev server URLs", async () => {
|
|
37
42
|
vi.spyOn(extractInjectedScriptsModule, "extractInjectedScripts").mockResolvedValue({
|
|
@@ -40,7 +45,7 @@ describe("getWidgetIdOverrideMap", () => {
|
|
|
40
45
|
inlineScripts: []
|
|
41
46
|
});
|
|
42
47
|
const baseHref = `http://localhost:5173/`;
|
|
43
|
-
const result = await getWidgetIdOverrideMap(MOCK_SERVER, MOCK_CODE_ENTRYPOINTS, MOCK_CONFIG_FILE_TO_ENTRYPOINT,
|
|
48
|
+
const result = await getWidgetIdOverrideMap(MOCK_SERVER, MOCK_CODE_ENTRYPOINTS, MOCK_CONFIG_FILE_TO_ENTRYPOINT, baseHref);
|
|
44
49
|
expect(result).toEqual({
|
|
45
50
|
"widgetId": [`${baseHref}.palantir/vite-injections.js`, `${baseHref}@vite/client`, `${baseHref}entry.js`]
|
|
46
51
|
});
|
|
@@ -53,7 +58,7 @@ describe("getWidgetIdOverrideMap", () => {
|
|
|
53
58
|
inlineScripts: []
|
|
54
59
|
});
|
|
55
60
|
const baseHref = `https://worksapce.stack.com/proxy/path/`;
|
|
56
|
-
const result = await getWidgetIdOverrideMap(MOCK_SERVER, MOCK_CODE_ENTRYPOINTS, MOCK_CONFIG_FILE_TO_ENTRYPOINT,
|
|
61
|
+
const result = await getWidgetIdOverrideMap(MOCK_SERVER, MOCK_CODE_ENTRYPOINTS, MOCK_CONFIG_FILE_TO_ENTRYPOINT, baseHref);
|
|
57
62
|
expect(result).toEqual({
|
|
58
63
|
"widgetId": [`${baseHref}.palantir/vite-injections.js`, `${baseHref}@vite/client`, `${baseHref}entry.js`]
|
|
59
64
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWidgetIdOverrideMap.test.js","names":["beforeEach","describe","expect","test","vi","extractInjectedScriptsModule","getWidgetIdOverrideMap","MOCK_SERVER","
|
|
1
|
+
{"version":3,"file":"getWidgetIdOverrideMap.test.js","names":["beforeEach","describe","expect","test","vi","extractInjectedScriptsModule","getWidgetIdOverrideMap","MOCK_WIDGET_CONFIG","id","MOCK_SERVER","ssrLoadModule","fn","mockResolvedValue","default","MOCK_CODE_ENTRYPOINTS","MOCK_CONFIG_FILE_TO_ENTRYPOINT","restoreAllMocks","mocked","spyOn","scriptSources","inlineScripts","baseHref","result","toEqual"],"sources":["getWidgetIdOverrideMap.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 { ParameterConfig, WidgetConfig } from \"@osdk/widget.api\";\nimport type { ViteDevServer } from \"vite\";\nimport { beforeEach, describe, expect, test, vi } from \"vitest\";\nimport * as extractInjectedScriptsModule from \"../extractInjectedScripts.js\";\nimport { getWidgetIdOverrideMap } from \"../getWidgetIdOverrideMap.js\";\n\nconst MOCK_WIDGET_CONFIG = { id: \"widgetId\" } as WidgetConfig<ParameterConfig>;\nconst MOCK_SERVER = {\n ssrLoadModule: vi.fn().mockResolvedValue({ default: MOCK_WIDGET_CONFIG }),\n} as unknown as ViteDevServer;\nconst MOCK_CODE_ENTRYPOINTS = { \"entry.ts\": `/entry.js` };\nconst MOCK_CONFIG_FILE_TO_ENTRYPOINT = { \"widget.config.ts\": \"entry.ts\" };\n\ndescribe(\"getWidgetIdOverrideMap\", () => {\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({\n default: MOCK_WIDGET_CONFIG,\n });\n });\n\n test(\"localhost dev server URLs\", async () => {\n vi.spyOn(extractInjectedScriptsModule, \"extractInjectedScripts\")\n .mockResolvedValue({\n // Extracted scripts sources start with the base path\n scriptSources: [\"/@vite/client\"],\n inlineScripts: [],\n });\n const baseHref = `http://localhost:5173/`;\n\n const result = await getWidgetIdOverrideMap(\n MOCK_SERVER,\n MOCK_CODE_ENTRYPOINTS,\n MOCK_CONFIG_FILE_TO_ENTRYPOINT,\n baseHref,\n );\n\n expect(result).toEqual({\n \"widgetId\": [\n `${baseHref}.palantir/vite-injections.js`,\n `${baseHref}@vite/client`,\n `${baseHref}entry.js`,\n ],\n });\n });\n\n test(\"remote server URLs\", async () => {\n // Representative values when running dev mode in Code Workspaces mode\n vi.spyOn(extractInjectedScriptsModule, \"extractInjectedScripts\")\n .mockResolvedValue({\n // Extracted scripts sources start with the base path\n scriptSources: [`/proxy/path/@vite/client`],\n inlineScripts: [],\n });\n const baseHref = `https://worksapce.stack.com/proxy/path/`;\n\n const result = await getWidgetIdOverrideMap(\n MOCK_SERVER,\n MOCK_CODE_ENTRYPOINTS,\n MOCK_CONFIG_FILE_TO_ENTRYPOINT,\n baseHref,\n );\n\n expect(result).toEqual({\n \"widgetId\": [\n `${baseHref}.palantir/vite-injections.js`,\n `${baseHref}@vite/client`,\n `${baseHref}entry.js`,\n ],\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,QAAQ;AAC/D,OAAO,KAAKC,4BAA4B,MAAM,8BAA8B;AAC5E,SAASC,sBAAsB,QAAQ,8BAA8B;AAErE,MAAMC,kBAAkB,GAAG;EAAEC,EAAE,EAAE;AAAW,CAAkC;AAC9E,MAAMC,WAAW,GAAG;EAClBC,aAAa,EAAEN,EAAE,CAACO,EAAE,CAAC,CAAC,CAACC,iBAAiB,CAAC;IAAEC,OAAO,EAAEN;EAAmB,CAAC;AAC1E,CAA6B;AAC7B,MAAMO,qBAAqB,GAAG;EAAE,UAAU,EAAE;AAAY,CAAC;AACzD,MAAMC,8BAA8B,GAAG;EAAE,kBAAkB,EAAE;AAAW,CAAC;AAEzEd,QAAQ,CAAC,wBAAwB,EAAE,MAAM;EACvCD,UAAU,CAAC,MAAM;IACfI,EAAE,CAACY,eAAe,CAAC,CAAC;IACpBZ,EAAE,CAACa,MAAM,CAACR,WAAW,CAACC,aAAa,CAAC,CAACE,iBAAiB,CAAC;MACrDC,OAAO,EAAEN;IACX,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFJ,IAAI,CAAC,2BAA2B,EAAE,YAAY;IAC5CC,EAAE,CAACc,KAAK,CAACb,4BAA4B,EAAE,wBAAwB,CAAC,CAC7DO,iBAAiB,CAAC;MACjB;MACAO,aAAa,EAAE,CAAC,eAAe,CAAC;MAChCC,aAAa,EAAE;IACjB,CAAC,CAAC;IACJ,MAAMC,QAAQ,GAAG,wBAAwB;IAEzC,MAAMC,MAAM,GAAG,MAAMhB,sBAAsB,CACzCG,WAAW,EACXK,qBAAqB,EACrBC,8BAA8B,EAC9BM,QACF,CAAC;IAEDnB,MAAM,CAACoB,MAAM,CAAC,CAACC,OAAO,CAAC;MACrB,UAAU,EAAE,CACV,GAAGF,QAAQ,8BAA8B,EACzC,GAAGA,QAAQ,cAAc,EACzB,GAAGA,QAAQ,UAAU;IAEzB,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFlB,IAAI,CAAC,oBAAoB,EAAE,YAAY;IACrC;IACAC,EAAE,CAACc,KAAK,CAACb,4BAA4B,EAAE,wBAAwB,CAAC,CAC7DO,iBAAiB,CAAC;MACjB;MACAO,aAAa,EAAE,CAAC,0BAA0B,CAAC;MAC3CC,aAAa,EAAE;IACjB,CAAC,CAAC;IACJ,MAAMC,QAAQ,GAAG,yCAAyC;IAE1D,MAAMC,MAAM,GAAG,MAAMhB,sBAAsB,CACzCG,WAAW,EACXK,qBAAqB,EACrBC,8BAA8B,EAC9BM,QACF,CAAC;IAEDnB,MAAM,CAACoB,MAAM,CAAC,CAACC,OAAO,CAAC;MACrB,UAAU,EAAE,CACV,GAAGF,QAAQ,8BAA8B,EACzC,GAAGA,QAAQ,cAAc,EACzB,GAAGA,QAAQ,UAAU;IAEzB,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { VITE_INJECTIONS_PATH } from "../common/constants.js";
|
|
18
|
+
import { extractWidgetConfig } from "../common/extractWidgetConfig.js";
|
|
18
19
|
import { extractInjectedScripts } from "./extractInjectedScripts.js";
|
|
19
|
-
export async function getWidgetIdOverrideMap(server, codeEntrypoints, configFileToEntrypoint,
|
|
20
|
-
const widgetIdToEntrypoint = Object.
|
|
21
|
-
const
|
|
20
|
+
export async function getWidgetIdOverrideMap(server, codeEntrypoints, configFileToEntrypoint, baseHref) {
|
|
21
|
+
const widgetIdToEntrypoint = Object.fromEntries(await Promise.all(Object.keys(configFileToEntrypoint).map(async configFile => {
|
|
22
|
+
const widgetConfig = await extractWidgetConfig(configFile, server);
|
|
22
23
|
const entrypointFile = configFileToEntrypoint[configFile];
|
|
23
24
|
const entrypointRelativePath = codeEntrypoints[entrypointFile];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}, {});
|
|
25
|
+
return [widgetConfig.id, entrypointRelativePath];
|
|
26
|
+
})));
|
|
27
27
|
const injectedScripts = await extractInjectedScripts(server);
|
|
28
28
|
const widgetIdToOverrides = Object.entries(widgetIdToEntrypoint).reduce((acc, [widgetId, entrypoint]) => {
|
|
29
29
|
const overrides = [VITE_INJECTIONS_PATH, ...injectedScripts.scriptSources.map(script => removeBasePath(script, baseHref)), entrypoint.slice(1)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWidgetIdOverrideMap.js","names":["VITE_INJECTIONS_PATH","extractInjectedScripts","getWidgetIdOverrideMap","server","codeEntrypoints","configFileToEntrypoint","
|
|
1
|
+
{"version":3,"file":"getWidgetIdOverrideMap.js","names":["VITE_INJECTIONS_PATH","extractWidgetConfig","extractInjectedScripts","getWidgetIdOverrideMap","server","codeEntrypoints","configFileToEntrypoint","baseHref","widgetIdToEntrypoint","Object","fromEntries","Promise","all","keys","map","configFile","widgetConfig","entrypointFile","entrypointRelativePath","id","injectedScripts","widgetIdToOverrides","entries","reduce","acc","widgetId","entrypoint","overrides","scriptSources","script","removeBasePath","slice","override","scriptPath","baseHrefPath","URL","pathname","replace"],"sources":["getWidgetIdOverrideMap.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 { VITE_INJECTIONS_PATH } from \"../common/constants.js\";\nimport { extractWidgetConfig } from \"../common/extractWidgetConfig.js\";\nimport { extractInjectedScripts } from \"./extractInjectedScripts.js\";\n\nexport async function getWidgetIdOverrideMap(\n server: ViteDevServer,\n codeEntrypoints: Record<string, string>,\n configFileToEntrypoint: Record<string, string>,\n baseHref: string,\n): Promise<Record<string, string[]>> {\n const widgetIdToEntrypoint: Record<string, string> = Object.fromEntries(\n await Promise.all(\n Object.keys(configFileToEntrypoint).map(async (configFile) => {\n const widgetConfig = await extractWidgetConfig(\n configFile,\n server,\n );\n const entrypointFile = configFileToEntrypoint[configFile];\n const entrypointRelativePath = codeEntrypoints[entrypointFile];\n return [widgetConfig.id, entrypointRelativePath];\n }),\n ),\n );\n\n const injectedScripts = await extractInjectedScripts(server);\n const widgetIdToOverrides = Object.entries(widgetIdToEntrypoint).reduce<\n Record<string, string[]>\n >(\n (acc, [widgetId, entrypoint]) => {\n const overrides = [\n VITE_INJECTIONS_PATH,\n ...injectedScripts.scriptSources.map((script) =>\n removeBasePath(script, baseHref)\n ),\n entrypoint.slice(1),\n ];\n acc[widgetId] = overrides.map((override) => `${baseHref}${override}`);\n return acc;\n },\n {},\n );\n\n return widgetIdToOverrides;\n}\n\nfunction removeBasePath(scriptPath: string, baseHref: string): string {\n const baseHrefPath = new URL(baseHref).pathname;\n return scriptPath.replace(baseHrefPath, \"\");\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,oBAAoB,QAAQ,wBAAwB;AAC7D,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B,EAAE1B,QAAgB,EAAU;EACpE,MAAM2B,YAAY,GAAG,IAAIC,GAAG,CAAC5B,QAAQ,CAAC,CAAC6B,QAAQ;EAC/C,OAAOH,UAAU,CAACI,OAAO,CAACH,YAAY,EAAE,EAAE,CAAC;AAC7C","ignoreList":[]}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { loadFoundryConfig } from "@osdk/foundry-config-json";
|
|
18
|
+
import { inspect } from "node:util";
|
|
18
19
|
import { getCodeWorkspacesFoundryUrl, isCodeWorkspacesMode } from "./codeWorkspacesMode.js";
|
|
19
20
|
import { enableDevMode, setWidgetSetSettings } from "./network.js";
|
|
20
21
|
|
|
@@ -50,13 +51,12 @@ export async function publishDevModeSettings(server, widgetIdToOverrides, baseHr
|
|
|
50
51
|
redirectUrl: isCodeWorkspacesMode(server.config.mode) ? null : `${foundryUrl}/workspace/custom-widgets/preview/${widgetSetRid}`
|
|
51
52
|
}));
|
|
52
53
|
} catch (error) {
|
|
53
|
-
|
|
54
|
-
server.config.logger.warn(`Failed to start dev mode: ${error.message}`);
|
|
54
|
+
server.config.logger.error(`Failed to start dev mode: ${error}\n\n${inspect(error)}`);
|
|
55
55
|
res.setHeader("Content-Type", "application/json");
|
|
56
56
|
res.statusCode = 500;
|
|
57
57
|
res.end(JSON.stringify({
|
|
58
|
-
status: "
|
|
59
|
-
error: error
|
|
58
|
+
status: "error",
|
|
59
|
+
error: inspect(error)
|
|
60
60
|
}));
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publishDevModeSettings.js","names":["loadFoundryConfig","getCodeWorkspacesFoundryUrl","isCodeWorkspacesMode","enableDevMode","setWidgetSetSettings","publishDevModeSettings","server","widgetIdToOverrides","baseHref","res","foundryConfig","Error","foundryUrl","config","mode","widgetSetRid","widgetSet","rid","settingsResponse","status","logger","warn","statusText","responseContent","text","enableResponse","setHeader","end","JSON","stringify","redirectUrl","error","
|
|
1
|
+
{"version":3,"file":"publishDevModeSettings.js","names":["loadFoundryConfig","inspect","getCodeWorkspacesFoundryUrl","isCodeWorkspacesMode","enableDevMode","setWidgetSetSettings","publishDevModeSettings","server","widgetIdToOverrides","baseHref","res","foundryConfig","Error","foundryUrl","config","mode","widgetSetRid","widgetSet","rid","settingsResponse","status","logger","warn","statusText","responseContent","text","enableResponse","setHeader","end","JSON","stringify","redirectUrl","error","statusCode"],"sources":["publishDevModeSettings.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 { loadFoundryConfig } from \"@osdk/foundry-config-json\";\nimport type { ServerResponse } from \"node:http\";\nimport { inspect } from \"node:util\";\nimport type { ViteDevServer } from \"vite\";\nimport {\n getCodeWorkspacesFoundryUrl,\n isCodeWorkspacesMode,\n} from \"./codeWorkspacesMode.js\";\nimport { enableDevMode, setWidgetSetSettings } from \"./network.js\";\n\n/**\n * Finish the setup process by setting the widget overrides in Foundry and enabling dev mode.\n */\nexport async function publishDevModeSettings(\n server: ViteDevServer,\n widgetIdToOverrides: Record<string, string[]>,\n baseHref: string,\n res: ServerResponse,\n): Promise<void> {\n try {\n const foundryConfig = await loadFoundryConfig(\"widgetSet\");\n if (foundryConfig == null) {\n throw new Error(\n \"foundry.config.json file not found.\",\n );\n }\n const foundryUrl = isCodeWorkspacesMode(server.config.mode)\n ? getCodeWorkspacesFoundryUrl()\n : foundryConfig.foundryConfig.foundryUrl;\n\n const widgetSetRid = foundryConfig.foundryConfig.widgetSet.rid;\n const settingsResponse = await setWidgetSetSettings(\n foundryUrl,\n widgetSetRid,\n widgetIdToOverrides,\n baseHref,\n server.config.mode,\n );\n if (settingsResponse.status !== 200) {\n server.config.logger.warn(\n `Unable to set widget settings in Foundry: ${settingsResponse.statusText}`,\n );\n const responseContent = await settingsResponse.text();\n server.config.logger.warn(responseContent);\n throw new Error(\n `Unable to set widget settings in Foundry: ${settingsResponse.statusText}`,\n );\n }\n\n const enableResponse = await enableDevMode(\n foundryUrl,\n server.config.mode,\n );\n if (enableResponse.status !== 200) {\n server.config.logger.warn(\n `Unable to enable dev mode in Foundry: ${enableResponse.statusText}`,\n );\n const responseContent = await enableResponse.text();\n server.config.logger.warn(responseContent);\n throw new Error(\n `Unable to enable dev mode in Foundry: ${enableResponse.statusText}`,\n );\n }\n\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(JSON.stringify({\n status: \"success\",\n // In Code Workspaces the preview UI automatically handles this redirect\n redirectUrl: isCodeWorkspacesMode(server.config.mode)\n ? null\n : `${foundryUrl}/workspace/custom-widgets/preview/${widgetSetRid}`,\n }));\n } catch (error: unknown) {\n server.config.logger.error(\n `Failed to start dev mode: ${(error as Error)}\\n\\n${inspect(error)}`,\n );\n res.setHeader(\"Content-Type\", \"application/json\");\n res.statusCode = 500;\n res.end(\n JSON.stringify({ status: \"error\", error: inspect(error) }),\n );\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,iBAAiB,QAAQ,2BAA2B;AAE7D,SAASC,OAAO,QAAQ,WAAW;AAEnC,SACEC,2BAA2B,EAC3BC,oBAAoB,QACf,yBAAyB;AAChC,SAASC,aAAa,EAAEC,oBAAoB,QAAQ,cAAc;;AAElE;AACA;AACA;AACA,OAAO,eAAeC,sBAAsBA,CAC1CC,MAAqB,EACrBC,mBAA6C,EAC7CC,QAAgB,EAChBC,GAAmB,EACJ;EACf,IAAI;IACF,MAAMC,aAAa,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,CACb,yCAAyCc,cAAc,CAACH,UAAU,EACpE,CAAC;IACH;IAEAb,GAAG,CAACiB,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC;IACjDjB,GAAG,CAACkB,GAAG,CAACC,IAAI,CAACC,SAAS,CAAC;MACrBV,MAAM,EAAE,SAAS;MACjB;MACAW,WAAW,EAAE5B,oBAAoB,CAACI,MAAM,CAACO,MAAM,CAACC,IAAI,CAAC,GACjD,IAAI,GACJ,GAAGF,UAAU,qCAAqCG,YAAY;IACpE,CAAC,CAAC,CAAC;EACL,CAAC,CAAC,OAAOgB,KAAc,EAAE;IACvBzB,MAAM,CAACO,MAAM,CAACO,MAAM,CAACW,KAAK,CACxB,6BAA8BA,KAAK,OAAiB/B,OAAO,CAAC+B,KAAK,CAAC,EACpE,CAAC;IACDtB,GAAG,CAACiB,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC;IACjDjB,GAAG,CAACuB,UAAU,GAAG,GAAG;IACpBvB,GAAG,CAACkB,GAAG,CACLC,IAAI,CAACC,SAAS,CAAC;MAAEV,MAAM,EAAE,OAAO;MAAEY,KAAK,EAAE/B,OAAO,CAAC+B,KAAK;IAAE,CAAC,CAC3D,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as n}from"./index-Zx5rUdU4.js";import{I as e}from"./index-BrAe7gTM.js";import{p as r,I as s}from"./index-
|
|
1
|
+
import{I as n}from"./index-Zx5rUdU4.js";import{I as e}from"./index-BrAe7gTM.js";import{p as r,I as s}from"./index-Dm4x3YrF.js";function I(o,t){var a=r(o);return t===s.STANDARD?n[a]:e[a]}function p(o){return r(o)}export{n as IconSvgPaths16,e as IconSvgPaths20,I as getIconPaths,p as iconNameToPathsRecordKey};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./allPaths
|
|
2
|
-
import{_ as o,a as i,b as n}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./allPaths-DcyFnTvZ.js","./index-Zx5rUdU4.js","./index-BrAe7gTM.js","./index-Dm4x3YrF.js","./index-62l0mIXD.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as o,a as i,b as n}from"./index-Dm4x3YrF.js";var _=function(e,a){return o(void 0,void 0,void 0,function(){var t;return i(this,function(r){switch(r.label){case 0:return[4,n(()=>import("./allPaths-DcyFnTvZ.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url)];case 1:return t=r.sent().getIconPaths,[2,t(e,a)]}})})};export{_ as allPathsLoader};
|