@osdk/widget.vite-plugin 3.2.0-beta.2 → 3.2.0-beta.4

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/build/esm/common/__tests__/extractWidgetConfig.test.js +22 -0
  3. package/build/esm/common/__tests__/extractWidgetConfig.test.js.map +1 -1
  4. package/build/esm/common/__tests__/validateWidgetConfig.test.js +109 -0
  5. package/build/esm/common/__tests__/validateWidgetConfig.test.js.map +1 -0
  6. package/build/esm/common/extractWidgetConfig.js +2 -0
  7. package/build/esm/common/extractWidgetConfig.js.map +1 -1
  8. package/build/esm/common/validateWidgetConfig.js +60 -0
  9. package/build/esm/common/validateWidgetConfig.js.map +1 -0
  10. package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js +7 -3
  11. package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js.map +1 -1
  12. package/build/esm/dev-plugin/__tests__/getWidgetIdOverrideMap.test.js +5 -1
  13. package/build/esm/dev-plugin/__tests__/getWidgetIdOverrideMap.test.js.map +1 -1
  14. package/build/site/assets/{allPaths-DcyFnTvZ.js → allPaths-C9RDB26n.js} +1 -1
  15. package/build/site/assets/{allPathsLoader-DHYhi3rh.js → allPathsLoader-DXy-gD-r.js} +2 -2
  16. package/build/site/assets/index-B-fsa5Ru.js +1 -0
  17. package/build/site/assets/index-CxjWve_y.css +1 -0
  18. package/build/site/assets/index-D9t4xczX.js +44 -0
  19. package/build/site/assets/index-DLOviMB1.js +1 -0
  20. package/build/site/assets/{splitPathsBySizeLoader-CtOeozdm.js → splitPathsBySizeLoader-CEcIKoAH.js} +1 -1
  21. package/build/site/index.html +2 -2
  22. package/build/types/common/__tests__/validateWidgetConfig.test.d.ts +1 -0
  23. package/build/types/common/__tests__/validateWidgetConfig.test.d.ts.map +1 -0
  24. package/build/types/common/extractWidgetConfig.d.ts.map +1 -1
  25. package/build/types/common/validateWidgetConfig.d.ts +6 -0
  26. package/build/types/common/validateWidgetConfig.d.ts.map +1 -0
  27. package/package.json +15 -15
  28. package/build/site/assets/index-62l0mIXD.css +0 -1
  29. package/build/site/assets/index-BrAe7gTM.js +0 -1
  30. package/build/site/assets/index-Dm4x3YrF.js +0 -44
  31. package/build/site/assets/index-Zx5rUdU4.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @osdk/widget.vite-plugin
2
2
 
3
+ ## 3.2.0-beta.4
4
+
5
+ ### Minor Changes
6
+
7
+ - 34df269: Fix widgets dev mode on Windows
8
+
9
+ ### Patch Changes
10
+
11
+ - @osdk/widget.api@3.2.0-beta.4
12
+
13
+ ## 3.2.0-beta.3
14
+
15
+ ### Minor Changes
16
+
17
+ - 71fc408: Validate camelCase for widget/parameter IDs
18
+
19
+ ### Patch Changes
20
+
21
+ - @osdk/widget.api@3.2.0-beta.3
22
+
3
23
  ## 3.2.0-beta.2
4
24
 
5
25
  ### Minor Changes
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { beforeEach, describe, expect, test, vi } from "vitest";
18
18
  import { extractWidgetConfig } from "../extractWidgetConfig.js";
19
+ import * as validateWidgetConfigModule from "../validateWidgetConfig.js";
19
20
  const MOCK_SERVER = {
20
21
  ssrLoadModule: vi.fn()
21
22
  };
@@ -27,8 +28,29 @@ describe("extractWidgetConfig", () => {
27
28
  vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({
28
29
  default: MOCK_CONFIG
29
30
  });
31
+ const validateSpy = vi.spyOn(validateWidgetConfigModule, "validateWidgetConfig");
30
32
  const result = await extractWidgetConfig("/path/to/config.ts", MOCK_SERVER);
31
33
  expect(result).toEqual(MOCK_CONFIG);
34
+ expect(validateSpy).toHaveBeenCalledWith(MOCK_CONFIG);
35
+ });
36
+ test("throws for invalid widget configuration", async () => {
37
+ vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({
38
+ default: {
39
+ id: "Invalid-Id",
40
+ name: "Test Widget",
41
+ type: "workshop",
42
+ parameters: {}
43
+ }
44
+ });
45
+ vi.spyOn(validateWidgetConfigModule, "validateWidgetConfig").mockImplementation(config => {
46
+ throw new Error(`Widget id "${config.id}" does not match allowed pattern (must be camelCase)`);
47
+ });
48
+ await expect(extractWidgetConfig("/path/to/config.ts", MOCK_SERVER)).rejects.toThrow(expect.objectContaining({
49
+ message: "Failed to load widget config from /path/to/config.ts",
50
+ cause: expect.objectContaining({
51
+ message: `Widget id "Invalid-Id" does not match allowed pattern (must be camelCase)`
52
+ })
53
+ }));
32
54
  });
33
55
  test("throws for missing default export", async () => {
34
56
  vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({
@@ -1 +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,CAAC,qBAAqB,EAAE,MA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I,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":[]}
1
+ {"version":3,"file":"extractWidgetConfig.test.js","names":["beforeEach","describe","expect","test","vi","extractWidgetConfig","validateWidgetConfigModule","MOCK_SERVER","ssrLoadModule","fn","restoreAllMocks","mocked","mockResolvedValue","default","MOCK_CONFIG","validateSpy","spyOn","result","toEqual","toHaveBeenCalledWith","id","name","type","parameters","mockImplementation","config","Error","rejects","toThrow","objectContaining","message","cause","notDefault","mockRejectedValue","description","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\";\nimport * as validateWidgetConfigModule from \"../validateWidgetConfig.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 validateSpy = vi.spyOn(\n validateWidgetConfigModule,\n \"validateWidgetConfig\",\n );\n\n const result = await extractWidgetConfig(\"/path/to/config.ts\", MOCK_SERVER);\n expect(result).toEqual(MOCK_CONFIG);\n expect(validateSpy).toHaveBeenCalledWith(MOCK_CONFIG);\n });\n\n test(\"throws for invalid widget configuration\", async () => {\n const INVALID_CONFIG = {\n id: \"Invalid-Id\",\n name: \"Test Widget\",\n type: \"workshop\",\n parameters: {},\n };\n\n vi.mocked(MOCK_SERVER.ssrLoadModule).mockResolvedValue({\n default: INVALID_CONFIG,\n });\n\n vi.spyOn(validateWidgetConfigModule, \"validateWidgetConfig\")\n .mockImplementation(config => {\n throw new Error(\n `Widget id \"${config.id}\" does not match allowed pattern (must be camelCase)`,\n );\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:\n `Widget id \"Invalid-Id\" does not match allowed pattern (must be camelCase)`,\n }),\n }),\n );\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;AAC/D,OAAO,KAAKC,0BAA0B,MAAM,4BAA4B;AAExE,MAAMC,WAAW,GAAG;EAClBC,aAAa,EAAEJ,EAAE,CAACK,EAAE,CAAC;AACvB,CAA6B;AAE7BR,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpCD,UAAU,CAAC,MAAM;IACfI,EAAE,CAACM,eAAe,CAAC,CAAC;EACtB,CAAC,CAAC;EAEFP,IAAI,CAAC,qCAAqC,EAAE,YAAY;IACtDC,EAAE,CAACO,MAAM,CAACJ,WAAW,CAACC,aAAa,CAAC,CAACI,iBAAiB,CAAC;MACrDC,OAAO,EAAEC;IACX,CAAC,CAAC;IAEF,MAAMC,WAAW,GAAGX,EAAE,CAACY,KAAK,CAC1BV,0BAA0B,EAC1B,sBACF,CAAC;IAED,MAAMW,MAAM,GAAG,MAAMZ,mBAAmB,CAAC,oBAAoB,EAAEE,WAAW,CAAC;IAC3EL,MAAM,CAACe,MAAM,CAAC,CAACC,OAAO,CAACJ,WAAW,CAAC;IACnCZ,MAAM,CAACa,WAAW,CAAC,CAACI,oBAAoB,CAACL,WAAW,CAAC;EACvD,CAAC,CAAC;EAEFX,IAAI,CAAC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EAAE,CAACO,MAAM,CAACJ,WAAW,CAACC,aAAa,CAAC,CAACyB,iBAAiB,CACpD,IAAIP,KAAK,CAAC,uBAAuB,CACnC,CAAC;IAED,MAAMxB,MAAM,CAACG,mBAAmB,CAAC,yBAAyB,EAAEE,WAAW,CAAC,CAAC,CACtEoB,OAAO,CAACC,OAAO,CAAC,8BAA8B,CAAC;EACpD,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAMd,WAAW,GAAG;EAClBM,EAAE,EAAE,YAAY;EAChBC,IAAI,EAAE,aAAa;EACnBa,WAAW,EAAE,eAAe;EAC5BZ,IAAI,EAAE,UAAU;EAChBC,UAAU,EAAE;IACVY,QAAQ,EAAE;MACRC,WAAW,EAAE,eAAe;MAC5Bd,IAAI,EAAE;IACR,CAAC;IACDe,QAAQ,EAAE;MACRD,WAAW,EAAE,eAAe;MAC5Bd,IAAI,EAAE;IACR;EACF,CAAC;EACDgB,MAAM,EAAE;IACNC,gBAAgB,EAAE;MAChBH,WAAW,EAAE,mBAAmB;MAChCI,kBAAkB,EAAE,CAAC,UAAU,EAAE,UAAU;IAC7C;EACF;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,109 @@
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 { describe, expect, test } from "vitest";
18
+ import { validateWidgetConfig } from "../validateWidgetConfig.js";
19
+ describe("validateWidgetConfig", () => {
20
+ test("accepts valid widget configuration", () => {
21
+ const validConfig = getValidConfig();
22
+ expect(() => validateWidgetConfig(validConfig)).not.toThrow();
23
+ });
24
+ test("throws for widget id that exceeds max length", () => {
25
+ const invalidConfig = getValidConfig();
26
+ invalidConfig.id = "a".repeat(101);
27
+ expect(() => validateWidgetConfig(invalidConfig)).toThrow("Widget id length can be at most 100 characters");
28
+ });
29
+ test("throws for widget id that is not camelCase", () => {
30
+ const testCases = [{
31
+ id: "TestWidget",
32
+ message: "does not match allowed pattern"
33
+ }, {
34
+ id: "test-widget",
35
+ message: "does not match allowed pattern"
36
+ }, {
37
+ id: "test_widget",
38
+ message: "does not match allowed pattern"
39
+ }, {
40
+ id: "1testWidget",
41
+ message: "does not match allowed pattern"
42
+ }];
43
+ for (const {
44
+ id,
45
+ message
46
+ } of testCases) {
47
+ const invalidConfig = getValidConfig();
48
+ invalidConfig.id = id;
49
+ expect(() => validateWidgetConfig(invalidConfig)).toThrow(message);
50
+ }
51
+ });
52
+ test("throws for widget name that exceeds max length", () => {
53
+ const invalidConfig = getValidConfig();
54
+ invalidConfig.name = "A".repeat(101);
55
+ expect(() => validateWidgetConfig(invalidConfig)).toThrow("Widget name length can be at most 100 characters");
56
+ });
57
+ test("throws for widget description that exceeds max length", () => {
58
+ const invalidConfig = getValidConfig();
59
+ invalidConfig.description = "A".repeat(251);
60
+ expect(() => validateWidgetConfig(invalidConfig)).toThrow("Widget description length can be at most 250 characters");
61
+ });
62
+ test("accepts undefined widget description", () => {
63
+ const validConfig = getValidConfig();
64
+ delete validConfig.description;
65
+ expect(() => validateWidgetConfig(validConfig)).not.toThrow();
66
+ });
67
+ test("throws for parameter id that is not camelCase", () => {
68
+ const invalidConfig = getValidConfig();
69
+ invalidConfig.parameters = {
70
+ "Invalid-Param": {
71
+ displayName: "Invalid Parameter",
72
+ type: "string"
73
+ }
74
+ };
75
+ expect(() => validateWidgetConfig(invalidConfig)).toThrow("Parameter id \"Invalid-Param\" does not match allowed pattern (must be camelCase)");
76
+ });
77
+ test("throws for parameter id that exceeds max length", () => {
78
+ const invalidConfig = getValidConfig();
79
+ const longParamId = "param" + "a".repeat(96); // 101 chars total
80
+ invalidConfig.parameters = {
81
+ [longParamId]: {
82
+ displayName: "Long Parameter",
83
+ type: "string"
84
+ }
85
+ };
86
+ expect(() => validateWidgetConfig(invalidConfig)).toThrow("Parameter id length can be at most 100 characters");
87
+ });
88
+ });
89
+ function getValidConfig() {
90
+ return {
91
+ id: "testWidget",
92
+ name: "Test Widget",
93
+ description: "A test widget",
94
+ type: "workshop",
95
+ parameters: {
96
+ paramOne: {
97
+ displayName: "Parameter One",
98
+ type: "string"
99
+ }
100
+ },
101
+ events: {
102
+ updateParameters: {
103
+ displayName: "Update Parameters",
104
+ parameterUpdateIds: ["paramOne"]
105
+ }
106
+ }
107
+ };
108
+ }
109
+ //# sourceMappingURL=validateWidgetConfig.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateWidgetConfig.test.js","names":["describe","expect","test","validateWidgetConfig","validConfig","getValidConfig","not","toThrow","invalidConfig","id","repeat","testCases","message","name","description","parameters","displayName","type","longParamId","paramOne","events","updateParameters","parameterUpdateIds"],"sources":["validateWidgetConfig.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 { describe, expect, test } from \"vitest\";\nimport { validateWidgetConfig } from \"../validateWidgetConfig.js\";\n\ndescribe(\"validateWidgetConfig\", () => {\n test(\"accepts valid widget configuration\", () => {\n const validConfig = getValidConfig();\n expect(() => validateWidgetConfig(validConfig)).not.toThrow();\n });\n\n test(\"throws for widget id that exceeds max length\", () => {\n const invalidConfig = getValidConfig();\n invalidConfig.id = \"a\".repeat(101);\n\n expect(() => validateWidgetConfig(invalidConfig)).toThrow(\n \"Widget id length can be at most 100 characters\",\n );\n });\n\n test(\"throws for widget id that is not camelCase\", () => {\n const testCases = [\n { id: \"TestWidget\", message: \"does not match allowed pattern\" },\n { id: \"test-widget\", message: \"does not match allowed pattern\" },\n { id: \"test_widget\", message: \"does not match allowed pattern\" },\n { id: \"1testWidget\", message: \"does not match allowed pattern\" },\n ];\n\n for (const { id, message } of testCases) {\n const invalidConfig = getValidConfig();\n invalidConfig.id = id;\n expect(() => validateWidgetConfig(invalidConfig)).toThrow(message);\n }\n });\n\n test(\"throws for widget name that exceeds max length\", () => {\n const invalidConfig = getValidConfig();\n invalidConfig.name = \"A\".repeat(101);\n\n expect(() => validateWidgetConfig(invalidConfig)).toThrow(\n \"Widget name length can be at most 100 characters\",\n );\n });\n\n test(\"throws for widget description that exceeds max length\", () => {\n const invalidConfig = getValidConfig();\n invalidConfig.description = \"A\".repeat(251);\n\n expect(() => validateWidgetConfig(invalidConfig)).toThrow(\n \"Widget description length can be at most 250 characters\",\n );\n });\n\n test(\"accepts undefined widget description\", () => {\n const validConfig = getValidConfig();\n delete validConfig.description;\n\n expect(() => validateWidgetConfig(validConfig)).not.toThrow();\n });\n\n test(\"throws for parameter id that is not camelCase\", () => {\n const invalidConfig = getValidConfig();\n invalidConfig.parameters = {\n \"Invalid-Param\": {\n displayName: \"Invalid Parameter\",\n type: \"string\",\n },\n };\n\n expect(() => validateWidgetConfig(invalidConfig)).toThrow(\n \"Parameter id \\\"Invalid-Param\\\" does not match allowed pattern (must be camelCase)\",\n );\n });\n\n test(\"throws for parameter id that exceeds max length\", () => {\n const invalidConfig = getValidConfig();\n const longParamId = \"param\" + \"a\".repeat(96); // 101 chars total\n invalidConfig.parameters = {\n [longParamId]: {\n displayName: \"Long Parameter\",\n type: \"string\",\n },\n };\n\n expect(() => validateWidgetConfig(invalidConfig)).toThrow(\n \"Parameter id length can be at most 100 characters\",\n );\n });\n});\n\nfunction getValidConfig(): WidgetConfig<ParameterConfig> {\n return {\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 },\n events: {\n updateParameters: {\n displayName: \"Update Parameters\",\n parameterUpdateIds: [\"paramOne\"],\n },\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,IAAI,QAAQ,QAAQ;AAC/C,SAASC,oBAAoB,QAAQ,4BAA4B;AAEjEH,QAAQ,CAAC,sBAAsB,EAAE,MAAM;EACrCE,IAAI,CAAC,oCAAoC,EAAE,MAAM;IAC/C,MAAME,WAAW,GAAGC,cAAc,CAAC,CAAC;IACpCJ,MAAM,CAAC,MAAME,oBAAoB,CAACC,WAAW,CAAC,CAAC,CAACE,GAAG,CAACC,OAAO,CAAC,CAAC;EAC/D,CAAC,CAAC;EAEFL,IAAI,CAAC,8CAA8C,EAAE,MAAM;IACzD,MAAMM,aAAa,GAAGH,cAAc,CAAC,CAAC;IACtCG,aAAa,CAACC,EAAE,GAAG,GAAG,CAACC,MAAM,CAAC,GAAG,CAAC;IAElCT,MAAM,CAAC,MAAME,oBAAoB,CAACK,aAAa,CAAC,CAAC,CAACD,OAAO,CACvD,gDACF,CAAC;EACH,CAAC,CAAC;EAEFL,IAAI,CAAC,4CAA4C,EAAE,MAAM;IACvD,MAAMS,SAAS,GAAG,CAChB;MAAEF,EAAE,EAAE,YAAY;MAAEG,OAAO,EAAE;IAAiC,CAAC,EAC/D;MAAEH,EAAE,EAAE,aAAa;MAAEG,OAAO,EAAE;IAAiC,CAAC,EAChE;MAAEH,EAAE,EAAE,aAAa;MAAEG,OAAO,EAAE;IAAiC,CAA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E,mBAAmB;QAChCC,IAAI,EAAE;MACR;IACF,CAAC;IAEDhB,MAAM,CAAC,MAAME,oBAAoB,CAACK,aAAa,CAAC,CAAC,CAACD,OAAO,CACvD,mFACF,CAAC;EACH,CAAC,CAAC;EAEFL,IAAI,CAAC,iDAAiD,EAAE,MAAM;IAC5D,MAAMM,aAAa,GAAGH,cAAc,CAAC,CAAC;IACtC,MAAMa,WAAW,GAAG,OAAO,GAAG,GAAG,CAACR,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9CF,aAAa,CAACO,UAAU,GAAG;MACzB,CAACG,WAAW,GAAG;QACbF,WAAW,EAAE,gBAAgB;QAC7BC,IAAI,EAAE;MACR;IACF,CAAC;IAEDhB,MAAM,CAAC,MAAME,oBAAoB,CAACK,aAAa,CAAC,CAAC,CAACD,OAAO,CACvD,mDACF,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,SAASF,cAAcA,CAAA,EAAkC;EACvD,OAAO;IACLI,EAAE,EAAE,YAAY;IAChBI,IAAI,EAAE,aAAa;IACnBC,WAAW,EAAE,eAAe;IAC5BG,IAAI,EAAE,UAAU;IAChBF,UAAU,EAAE;MACVI,QAAQ,EAAE;QACRH,WAAW,EAAE,eAAe;QAC5BC,IAAI,EAAE;MACR;IACF,CAAC;IACDG,MAAM,EAAE;MACNC,gBAAgB,EAAE;QAChBL,WAAW,EAAE,mBAAmB;QAChCM,kBAAkB,EAAE,CAAC,UAAU;MACjC;IACF;EACF,CAAC;AACH","ignoreList":[]}
@@ -14,6 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ import { validateWidgetConfig } from "./validateWidgetConfig.js";
17
18
  export async function extractWidgetConfig(moduleId, server) {
18
19
  try {
19
20
  const configModule = await server.ssrLoadModule(moduleId);
@@ -21,6 +22,7 @@ export async function extractWidgetConfig(moduleId, server) {
21
22
  if (config == null) {
22
23
  throw new Error(`No default export found in ${moduleId}`);
23
24
  }
25
+ validateWidgetConfig(config);
24
26
  return config;
25
27
  } catch (error) {
26
28
  throw new Error(`Failed to load widget config from ${moduleId}`, {
@@ -1 +1 @@
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":[]}
1
+ {"version":3,"file":"extractWidgetConfig.js","names":["validateWidgetConfig","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\";\nimport { validateWidgetConfig } from \"./validateWidgetConfig.js\";\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 validateWidgetConfig(config);\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;;AAIA,SAASA,oBAAoB,QAAQ,2BAA2B;AAEhE,OAAO,eAAeC,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;IAEAF,oBAAoB,CAACM,MAAM,CAAC;IAC5B,OAAOA,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,60 @@
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
+ const ID_PATTERN = /^([a-z][a-z0-9]*)([A-Z][a-z0-9]*)*$/;
18
+ const ID_MAX_LENGTH = 100;
19
+ const NAME_MAX_LENGTH = 100;
20
+ const DESCRIPTION_MAX_LENGTH = 250;
21
+
22
+ /**
23
+ * Validates the requirements that can't be expressed via TypeScript type-checking
24
+ * for a widget config (e.g. that widget IDs and parameter IDs are camelCase.)
25
+ */
26
+ export function validateWidgetConfig(config) {
27
+ validateWidgetId(config.id);
28
+ validateWidgetName(config.name);
29
+ validateWidgetDescription(config.description);
30
+ validateWidgetParameters(config.parameters);
31
+ }
32
+ function validateWidgetId(id) {
33
+ if (id.length > ID_MAX_LENGTH) {
34
+ throw new Error(`Widget id length can be at most ${ID_MAX_LENGTH} characters`);
35
+ }
36
+ if (!ID_PATTERN.test(id)) {
37
+ throw new Error(`Widget id "${id}" does not match allowed pattern (must be camelCase)`);
38
+ }
39
+ }
40
+ function validateWidgetName(name) {
41
+ if (name.length > NAME_MAX_LENGTH) {
42
+ throw new Error(`Widget name length can be at most ${NAME_MAX_LENGTH} characters`);
43
+ }
44
+ }
45
+ function validateWidgetDescription(description) {
46
+ if (description != null && description.length > DESCRIPTION_MAX_LENGTH) {
47
+ throw new Error(`Widget description length can be at most ${DESCRIPTION_MAX_LENGTH} characters`);
48
+ }
49
+ }
50
+ function validateWidgetParameters(parameters) {
51
+ for (const parameterId of Object.keys(parameters)) {
52
+ if (parameterId.length > ID_MAX_LENGTH) {
53
+ throw new Error(`Parameter id length can be at most ${ID_MAX_LENGTH} characters`);
54
+ }
55
+ if (!ID_PATTERN.test(parameterId)) {
56
+ throw new Error(`Parameter id "${parameterId}" does not match allowed pattern (must be camelCase)`);
57
+ }
58
+ }
59
+ }
60
+ //# sourceMappingURL=validateWidgetConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateWidgetConfig.js","names":["ID_PATTERN","ID_MAX_LENGTH","NAME_MAX_LENGTH","DESCRIPTION_MAX_LENGTH","validateWidgetConfig","config","validateWidgetId","id","validateWidgetName","name","validateWidgetDescription","description","validateWidgetParameters","parameters","length","Error","test","parameterId","Object","keys"],"sources":["validateWidgetConfig.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\";\n\nconst ID_PATTERN = /^([a-z][a-z0-9]*)([A-Z][a-z0-9]*)*$/;\nconst ID_MAX_LENGTH = 100;\nconst NAME_MAX_LENGTH = 100;\nconst DESCRIPTION_MAX_LENGTH = 250;\n\n/**\n * Validates the requirements that can't be expressed via TypeScript type-checking\n * for a widget config (e.g. that widget IDs and parameter IDs are camelCase.)\n */\nexport function validateWidgetConfig(\n config: WidgetConfig<ParameterConfig>,\n): void {\n validateWidgetId(config.id);\n validateWidgetName(config.name);\n validateWidgetDescription(config.description);\n validateWidgetParameters(config.parameters);\n}\n\nfunction validateWidgetId(id: string): void {\n if (id.length > ID_MAX_LENGTH) {\n throw new Error(\n `Widget id length can be at most ${ID_MAX_LENGTH} characters`,\n );\n }\n if (!ID_PATTERN.test(id)) {\n throw new Error(\n `Widget id \"${id}\" does not match allowed pattern (must be camelCase)`,\n );\n }\n}\n\nfunction validateWidgetName(name: string): void {\n if (name.length > NAME_MAX_LENGTH) {\n throw new Error(\n `Widget name length can be at most ${NAME_MAX_LENGTH} characters`,\n );\n }\n}\n\nfunction validateWidgetDescription(description?: string): void {\n if (description != null && description.length > DESCRIPTION_MAX_LENGTH) {\n throw new Error(\n `Widget description length can be at most ${DESCRIPTION_MAX_LENGTH} characters`,\n );\n }\n}\n\nfunction validateWidgetParameters(parameters: ParameterConfig): void {\n for (const parameterId of Object.keys(parameters)) {\n if (parameterId.length > ID_MAX_LENGTH) {\n throw new Error(\n `Parameter id length can be at most ${ID_MAX_LENGTH} characters`,\n );\n }\n if (!ID_PATTERN.test(parameterId)) {\n throw new Error(\n `Parameter id \"${parameterId}\" does not match allowed pattern (must be camelCase)`,\n );\n }\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,MAAMA,UAAU,GAAG,qCAAqC;AACxD,MAAMC,aAAa,GAAG,GAAG;AACzB,MAAMC,eAAe,GAAG,GAAG;AAC3B,MAAMC,sBAAsB,GAAG,GAAG;;AAElC;AACA;AAC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AAC;IACH;EACF;AACF","ignoreList":[]}
@@ -144,9 +144,12 @@ export function FoundryWidgetDevPlugin() {
144
144
  }
145
145
 
146
146
  // Standardize the source file extension and get the full path
147
- const standardizedSource = standardizeFileExtension(getFullSourcePath(source.slice(1), importer));
147
+ const standardizedSource = standardizeFileExtension(getFullSourcePath(
148
+ // If the source path is absolute, resolve it against the current working directory
149
+ source.startsWith("/") ? path.join(process.cwd(), source) : source, importer));
148
150
  // Importers are already full paths, so just standardize the extension
149
- const standardizedImporter = standardizeFileExtension(importer);
151
+ // Normalize to ensure consistent path separators on Windows
152
+ const standardizedImporter = standardizeFileExtension(path.normalize(importer));
150
153
 
151
154
  // In dev mode all entrypoints have a generic HTML importer value
152
155
  if (importer.endsWith("index.html") && !standardizedSource.includes("@fs")) {
@@ -171,7 +174,8 @@ function getFullSourcePath(source, importer) {
171
174
  return path.resolve(path.dirname(importer), source);
172
175
  }
173
176
  function serverPath(server, subPath) {
174
- return path.resolve(server.config.base, subPath);
177
+ // Don't use Windows-style paths when constructing URL paths for the HTTP server
178
+ return path.posix.resolve(server.config.base, subPath);
175
179
  }
176
180
  function printSetupPageUrl(server) {
177
181
  const setupRoute = `${getBaseHref(server)}${SETUP_PATH}/`;
@@ -1 +1 @@
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,6BAA6B;AACpE,SAASC,sBAAsB,QAAQ,6BAA6B;;AAEpE;AACA,MAAMC,QAAgB,GAAG,OAAOC,SAAS,KAAK,WAAW,GACrDA,SAAS,GACTnB,IAAI,CAACo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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":[]}
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","startsWith","cwd","standardizedImporter","normalize","includes","replace","fullSourcePath","subPath","posix","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(\n // If the source path is absolute, resolve it against the current working directory\n source.startsWith(\"/\") ? path.join(process.cwd(), source) : source,\n importer,\n ),\n );\n // Importers are already full paths, so just standardize the extension\n // Normalize to ensure consistent path separators on Windows\n const standardizedImporter = standardizeFileExtension(\n path.normalize(importer),\n );\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 // Don't use Windows-style paths when constructing URL paths for the HTTP server\n return path.posix.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,QAC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AGhC,UAAU,GAAG;EACzDgC,MAAM,CAACV,MAAM,CAAC0D,MAAM,CAACC,IAAI,CACvB,KAAKxF,KAAK,CAACyF,KAAK,CAAC,GAAG,CAAC,KACnBzF,KAAK,CAAC0F,IAAI,CAAC,mDAAmD,CAAC,KAC5D1F,KAAK,CAACyF,KAAK,CAACH,UAAU,CAAC,EAC9B,CAAC;AACH","ignoreList":[]}
@@ -18,7 +18,11 @@ import { beforeEach, describe, expect, test, vi } from "vitest";
18
18
  import * as extractInjectedScriptsModule from "../extractInjectedScripts.js";
19
19
  import { getWidgetIdOverrideMap } from "../getWidgetIdOverrideMap.js";
20
20
  const MOCK_WIDGET_CONFIG = {
21
- id: "widgetId"
21
+ id: "widgetId",
22
+ name: "Widget Name",
23
+ type: "workshop",
24
+ parameters: {},
25
+ events: {}
22
26
  };
23
27
  const MOCK_SERVER = {
24
28
  ssrLoadModule: vi.fn().mockResolvedValue({
@@ -1 +1 @@
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":[]}
1
+ {"version":3,"file":"getWidgetIdOverrideMap.test.js","names":["beforeEach","describe","expect","test","vi","extractInjectedScriptsModule","getWidgetIdOverrideMap","MOCK_WIDGET_CONFIG","id","name","type","parameters","events","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 = {\n id: \"widgetId\",\n name: \"Widget Name\",\n type: \"workshop\",\n parameters: {},\n events: {},\n} 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;EACzBC,EAAE,EAAE,UAAU;EACdC,IAAI,EAAE,aAAa;EACnBC,IAAI,EAAE,UAAU;EAChBC,UAAU,EAAE,CAAC,CAAC;EACdC,MAAM,EAAE,CAAC;AACX,CAAkC;AAClC,MAAMC,WAAW,GAAG;EAClBC,aAAa,EAAEV,EAAE,CAACW,EAAE,CAAC,CAAC,CAACC,iBAAiB,CAAC;IAAEC,OAAO,EAAEV;EAAmB,CAAC;AAC1E,CAA6B;AAC7B,MAAMW,qBAAqB,GAAG;EAAE,UAAU,EAAE;AAAY,CAAC;AACzD,MAAMC,8BAA8B,GAAG;EAAE,kBAAkB,EAAE;AAAW,CAAC;AAEzElB,QAAQ,CAAC,wBAAwB,EAAE,M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Q,UAAU;IAEzB,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","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-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
+ import{I as n}from"./index-DLOviMB1.js";import{I as e}from"./index-B-fsa5Ru.js";import{p as r,I as s}from"./index-D9t4xczX.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-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};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./allPaths-C9RDB26n.js","./index-DLOviMB1.js","./index-B-fsa5Ru.js","./index-D9t4xczX.js","./index-CxjWve_y.css"])))=>i.map(i=>d[i]);
2
+ import{_ as o,a as i,b as n}from"./index-D9t4xczX.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-C9RDB26n.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};