@osdk/widget.vite-plugin 2.1.0

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 (123) hide show
  1. package/CHANGELOG.md +342 -0
  2. package/README.md +175 -0
  3. package/build/esm/build-plugin/FoundryWidgetBuildPlugin.js +93 -0
  4. package/build/esm/build-plugin/FoundryWidgetBuildPlugin.js.map +1 -0
  5. package/build/esm/build-plugin/__tests__/extractBuildOutputs.test.js +133 -0
  6. package/build/esm/build-plugin/__tests__/extractBuildOutputs.test.js.map +1 -0
  7. package/build/esm/build-plugin/__tests__/getWidgetBuildOutputs.test.js +148 -0
  8. package/build/esm/build-plugin/__tests__/getWidgetBuildOutputs.test.js.map +1 -0
  9. package/build/esm/build-plugin/buildWidgetSetManifest.js +48 -0
  10. package/build/esm/build-plugin/buildWidgetSetManifest.js.map +1 -0
  11. package/build/esm/build-plugin/extractBuildOutputs.js +107 -0
  12. package/build/esm/build-plugin/extractBuildOutputs.js.map +1 -0
  13. package/build/esm/build-plugin/getWidgetBuildOutputs.js +50 -0
  14. package/build/esm/build-plugin/getWidgetBuildOutputs.js.map +1 -0
  15. package/build/esm/build-plugin/isConfigFile.js +22 -0
  16. package/build/esm/build-plugin/isConfigFile.js.map +1 -0
  17. package/build/esm/client/app.js +97 -0
  18. package/build/esm/client/app.js.map +1 -0
  19. package/build/esm/client/main.js +23 -0
  20. package/build/esm/client/main.js.map +1 -0
  21. package/build/esm/common/__tests__/getInputHtmlEntrypoints.test.js +38 -0
  22. package/build/esm/common/__tests__/getInputHtmlEntrypoints.test.js.map +1 -0
  23. package/build/esm/common/constants.js +23 -0
  24. package/build/esm/common/constants.js.map +1 -0
  25. package/build/esm/common/extractWidgetConfig.js +69 -0
  26. package/build/esm/common/extractWidgetConfig.js.map +1 -0
  27. package/build/esm/common/getInputHtmlEntrypoints.js +29 -0
  28. package/build/esm/common/getInputHtmlEntrypoints.js.map +1 -0
  29. package/build/esm/common/safeGetEnvVar.js +24 -0
  30. package/build/esm/common/safeGetEnvVar.js.map +1 -0
  31. package/build/esm/common/standardizeFileExtension.js +25 -0
  32. package/build/esm/common/standardizeFileExtension.js.map +1 -0
  33. package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js +193 -0
  34. package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js.map +1 -0
  35. package/build/esm/dev-plugin/__tests__/codeWorkspacesMode.test.js +87 -0
  36. package/build/esm/dev-plugin/__tests__/codeWorkspacesMode.test.js.map +1 -0
  37. package/build/esm/dev-plugin/__tests__/extractInjectedScripts.test.js +34 -0
  38. package/build/esm/dev-plugin/__tests__/extractInjectedScripts.test.js.map +1 -0
  39. package/build/esm/dev-plugin/__tests__/getBaseHref.test.js +48 -0
  40. package/build/esm/dev-plugin/__tests__/getBaseHref.test.js.map +1 -0
  41. package/build/esm/dev-plugin/__tests__/getWidgetIdOverrideMap.test.js +62 -0
  42. package/build/esm/dev-plugin/__tests__/getWidgetIdOverrideMap.test.js.map +1 -0
  43. package/build/esm/dev-plugin/codeWorkspacesMode.js +50 -0
  44. package/build/esm/dev-plugin/codeWorkspacesMode.js.map +1 -0
  45. package/build/esm/dev-plugin/extractInjectedScripts.js +62 -0
  46. package/build/esm/dev-plugin/extractInjectedScripts.js.map +1 -0
  47. package/build/esm/dev-plugin/getBaseHref.js +26 -0
  48. package/build/esm/dev-plugin/getBaseHref.js.map +1 -0
  49. package/build/esm/dev-plugin/getFoundryToken.js +28 -0
  50. package/build/esm/dev-plugin/getFoundryToken.js.map +1 -0
  51. package/build/esm/dev-plugin/getWidgetIdOverrideMap.js +39 -0
  52. package/build/esm/dev-plugin/getWidgetIdOverrideMap.js.map +1 -0
  53. package/build/esm/dev-plugin/network.js +51 -0
  54. package/build/esm/dev-plugin/network.js.map +1 -0
  55. package/build/esm/dev-plugin/publishDevModeSettings.js +63 -0
  56. package/build/esm/dev-plugin/publishDevModeSettings.js.map +1 -0
  57. package/build/esm/index.js +22 -0
  58. package/build/esm/index.js.map +1 -0
  59. package/build/site/assets/allPaths-CoV91acR.js +1 -0
  60. package/build/site/assets/allPathsLoader-abVMVrnV.js +2 -0
  61. package/build/site/assets/index-62l0mIXD.css +1 -0
  62. package/build/site/assets/index-BrAe7gTM.js +1 -0
  63. package/build/site/assets/index-DLUL2ZpM.js +44 -0
  64. package/build/site/assets/index-Zx5rUdU4.js +1 -0
  65. package/build/site/assets/splitPathsBySizeLoader--OyNgZuW.js +1 -0
  66. package/build/site/index.html +15 -0
  67. package/build/types/build-plugin/FoundryWidgetBuildPlugin.d.ts +2 -0
  68. package/build/types/build-plugin/FoundryWidgetBuildPlugin.d.ts.map +1 -0
  69. package/build/types/build-plugin/__tests__/extractBuildOutputs.test.d.ts +1 -0
  70. package/build/types/build-plugin/__tests__/extractBuildOutputs.test.d.ts.map +1 -0
  71. package/build/types/build-plugin/__tests__/getWidgetBuildOutputs.test.d.ts +1 -0
  72. package/build/types/build-plugin/__tests__/getWidgetBuildOutputs.test.d.ts.map +1 -0
  73. package/build/types/build-plugin/buildWidgetSetManifest.d.ts +3 -0
  74. package/build/types/build-plugin/buildWidgetSetManifest.d.ts.map +1 -0
  75. package/build/types/build-plugin/extractBuildOutputs.d.ts +12 -0
  76. package/build/types/build-plugin/extractBuildOutputs.d.ts.map +1 -0
  77. package/build/types/build-plugin/getWidgetBuildOutputs.d.ts +7 -0
  78. package/build/types/build-plugin/getWidgetBuildOutputs.d.ts.map +1 -0
  79. package/build/types/build-plugin/isConfigFile.d.ts +1 -0
  80. package/build/types/build-plugin/isConfigFile.d.ts.map +1 -0
  81. package/build/types/client/app.d.ts +2 -0
  82. package/build/types/client/app.d.ts.map +1 -0
  83. package/build/types/client/main.d.ts +3 -0
  84. package/build/types/client/main.d.ts.map +1 -0
  85. package/build/types/common/__tests__/getInputHtmlEntrypoints.test.d.ts +1 -0
  86. package/build/types/common/__tests__/getInputHtmlEntrypoints.test.d.ts.map +1 -0
  87. package/build/types/common/constants.d.ts +6 -0
  88. package/build/types/common/constants.d.ts.map +1 -0
  89. package/build/types/common/extractWidgetConfig.d.ts +3 -0
  90. package/build/types/common/extractWidgetConfig.d.ts.map +1 -0
  91. package/build/types/common/getInputHtmlEntrypoints.d.ts +5 -0
  92. package/build/types/common/getInputHtmlEntrypoints.d.ts.map +1 -0
  93. package/build/types/common/safeGetEnvVar.d.ts +1 -0
  94. package/build/types/common/safeGetEnvVar.d.ts.map +1 -0
  95. package/build/types/common/standardizeFileExtension.d.ts +6 -0
  96. package/build/types/common/standardizeFileExtension.d.ts.map +1 -0
  97. package/build/types/dev-plugin/FoundryWidgetDevPlugin.d.ts +2 -0
  98. package/build/types/dev-plugin/FoundryWidgetDevPlugin.d.ts.map +1 -0
  99. package/build/types/dev-plugin/__tests__/codeWorkspacesMode.test.d.ts +1 -0
  100. package/build/types/dev-plugin/__tests__/codeWorkspacesMode.test.d.ts.map +1 -0
  101. package/build/types/dev-plugin/__tests__/extractInjectedScripts.test.d.ts +1 -0
  102. package/build/types/dev-plugin/__tests__/extractInjectedScripts.test.d.ts.map +1 -0
  103. package/build/types/dev-plugin/__tests__/getBaseHref.test.d.ts +1 -0
  104. package/build/types/dev-plugin/__tests__/getBaseHref.test.d.ts.map +1 -0
  105. package/build/types/dev-plugin/__tests__/getWidgetIdOverrideMap.test.d.ts +1 -0
  106. package/build/types/dev-plugin/__tests__/getWidgetIdOverrideMap.test.d.ts.map +1 -0
  107. package/build/types/dev-plugin/codeWorkspacesMode.d.ts +8 -0
  108. package/build/types/dev-plugin/codeWorkspacesMode.d.ts.map +1 -0
  109. package/build/types/dev-plugin/extractInjectedScripts.d.ts +16 -0
  110. package/build/types/dev-plugin/extractInjectedScripts.d.ts.map +1 -0
  111. package/build/types/dev-plugin/getBaseHref.d.ts +2 -0
  112. package/build/types/dev-plugin/getBaseHref.d.ts.map +1 -0
  113. package/build/types/dev-plugin/getFoundryToken.d.ts +1 -0
  114. package/build/types/dev-plugin/getFoundryToken.d.ts.map +1 -0
  115. package/build/types/dev-plugin/getWidgetIdOverrideMap.d.ts +3 -0
  116. package/build/types/dev-plugin/getWidgetIdOverrideMap.d.ts.map +1 -0
  117. package/build/types/dev-plugin/network.d.ts +2 -0
  118. package/build/types/dev-plugin/network.d.ts.map +1 -0
  119. package/build/types/dev-plugin/publishDevModeSettings.d.ts +6 -0
  120. package/build/types/dev-plugin/publishDevModeSettings.d.ts.map +1 -0
  121. package/build/types/index.d.ts +2 -0
  122. package/build/types/index.d.ts.map +1 -0
  123. package/package.json +89 -0
@@ -0,0 +1,133 @@
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 fs from "fs";
18
+ import { expect, test, vi } from "vitest";
19
+ import { extractBuildOutputs } from "../extractBuildOutputs.js";
20
+ vi.mock("fs");
21
+ const EXAMPLE_HTML = `
22
+ <!DOCTYPE html>
23
+ <html>
24
+ <head>
25
+ <script src="/script1.js" type="text/javascript"></script>
26
+ <script src="/script2.js" type="module"></script>
27
+ <script src="/script3.js"></script>
28
+ <link rel="stylesheet" href="/styles.css">
29
+ <link rel="stylesheet" href="/more-styles.css">
30
+ </head>
31
+ <body>
32
+ <script src="/script4.js" type="text/javascript"></script>
33
+ </body>
34
+ </html>
35
+ `;
36
+ test("extractBuildOutputs with scripts and stylesheets", () => {
37
+ vi.mocked(fs.readFileSync).mockReturnValue(EXAMPLE_HTML);
38
+ const result = extractBuildOutputs("dummy/path.html");
39
+ expect(result).toEqual({
40
+ scripts: [{
41
+ type: "script",
42
+ src: "/script1.js",
43
+ scriptType: "text/javascript"
44
+ }, {
45
+ type: "script",
46
+ src: "/script2.js",
47
+ scriptType: "module"
48
+ }, {
49
+ type: "script",
50
+ src: "/script3.js",
51
+ scriptType: "text/javascript"
52
+ }, {
53
+ type: "script",
54
+ src: "/script4.js",
55
+ scriptType: "text/javascript"
56
+ }],
57
+ stylesheets: ["/styles.css", "/more-styles.css"]
58
+ });
59
+ });
60
+ test("extractBuildOutputs with no scripts or stylesheets", () => {
61
+ vi.mocked(fs.readFileSync).mockReturnValue("<html><body></body></html>");
62
+ const result = extractBuildOutputs("dummy/path.html");
63
+ expect(result).toEqual({
64
+ scripts: [],
65
+ stylesheets: []
66
+ });
67
+ });
68
+ test("extractBuildOutputs throws error for inline scripts", () => {
69
+ vi.mocked(fs.readFileSync).mockReturnValue(`
70
+ <html>
71
+ <body>
72
+ <script>console.log("inline");</script>
73
+ </body>
74
+ </html>
75
+ `);
76
+ expect(() => extractBuildOutputs("dummy/path.html")).toThrow("Unexpected inline content found in Vite HTML output");
77
+ });
78
+ test("extractBuildOutputs throws error for invalid script type", () => {
79
+ vi.mocked(fs.readFileSync).mockReturnValue(`
80
+ <html>
81
+ <head>
82
+ <script src="/script.js" type="text/unknown"></script>
83
+ </head>
84
+ </html>
85
+ `);
86
+ expect(() => extractBuildOutputs("dummy/path.html")).toThrow("Invalid script type attribute found in Vite HTML output: text/unknown");
87
+ });
88
+ test("extractBuildOutputs throws error for unexpected script attributes", () => {
89
+ vi.mocked(fs.readFileSync).mockReturnValue(`
90
+ <html>
91
+ <head>
92
+ <script src="/script.js" type="module" async></script>
93
+ </head>
94
+ </html>
95
+ `);
96
+ expect(() => extractBuildOutputs("dummy/path.html")).toThrow("Unexpected async attribute found in Vite HTML output");
97
+ });
98
+ test("extractBuildOutputs throws error for stylesheet without href", () => {
99
+ vi.mocked(fs.readFileSync).mockReturnValue(`
100
+ <html>
101
+ <head>
102
+ <link rel="stylesheet">
103
+ </head>
104
+ </html>
105
+ `);
106
+ expect(() => extractBuildOutputs("dummy/path.html")).toThrow("Missing href attribute in Vite HTML output");
107
+ });
108
+ test("extractBuildOutputs ignores non-stylesheet links", () => {
109
+ vi.mocked(fs.readFileSync).mockReturnValue(`
110
+ <html>
111
+ <head>
112
+ <link rel="icon" href="/favicon.ico">
113
+ <link rel="stylesheet" href="/styles.css">
114
+ </head>
115
+ </html>
116
+ `);
117
+ const result = extractBuildOutputs("dummy/path.html");
118
+ expect(result).toEqual({
119
+ scripts: [],
120
+ stylesheets: ["/styles.css"]
121
+ });
122
+ });
123
+ test("extractBuildOutputs throws error for unexpected link attributes", () => {
124
+ vi.mocked(fs.readFileSync).mockReturnValue(`
125
+ <html>
126
+ <head>
127
+ <link rel="stylesheet" href="/styles.css" async>
128
+ </head>
129
+ </html>
130
+ `);
131
+ expect(() => extractBuildOutputs("dummy/path.html")).toThrow("Unexpected async attribute found in Vite HTML output");
132
+ });
133
+ //# sourceMappingURL=extractBuildOutputs.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractBuildOutputs.test.js","names":["fs","expect","test","vi","extractBuildOutputs","mock","EXAMPLE_HTML","mocked","readFileSync","mockReturnValue","result","toEqual","scripts","type","src","scriptType","stylesheets","toThrow"],"sources":["extractBuildOutputs.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 fs from \"fs\";\nimport { expect, test, vi } from \"vitest\";\nimport { extractBuildOutputs } from \"../extractBuildOutputs.js\";\n\nvi.mock(\"fs\");\n\nconst EXAMPLE_HTML = `\n<!DOCTYPE html>\n<html>\n<head>\n <script src=\"/script1.js\" type=\"text/javascript\"></script>\n <script src=\"/script2.js\" type=\"module\"></script>\n <script src=\"/script3.js\"></script>\n <link rel=\"stylesheet\" href=\"/styles.css\">\n <link rel=\"stylesheet\" href=\"/more-styles.css\">\n</head>\n<body>\n <script src=\"/script4.js\" type=\"text/javascript\"></script>\n</body>\n</html>\n`;\n\ntest(\"extractBuildOutputs with scripts and stylesheets\", () => {\n vi.mocked(fs.readFileSync).mockReturnValue(EXAMPLE_HTML);\n const result = extractBuildOutputs(\"dummy/path.html\");\n expect(result).toEqual({\n scripts: [\n { type: \"script\", src: \"/script1.js\", scriptType: \"text/javascript\" },\n { type: \"script\", src: \"/script2.js\", scriptType: \"module\" },\n { type: \"script\", src: \"/script3.js\", scriptType: \"text/javascript\" },\n { type: \"script\", src: \"/script4.js\", scriptType: \"text/javascript\" },\n ],\n stylesheets: [\"/styles.css\", \"/more-styles.css\"],\n });\n});\n\ntest(\"extractBuildOutputs with no scripts or stylesheets\", () => {\n vi.mocked(fs.readFileSync).mockReturnValue(\"<html><body></body></html>\");\n const result = extractBuildOutputs(\"dummy/path.html\");\n expect(result).toEqual({\n scripts: [],\n stylesheets: [],\n });\n});\n\ntest(\"extractBuildOutputs throws error for inline scripts\", () => {\n vi.mocked(fs.readFileSync).mockReturnValue(`\n <html>\n <body>\n <script>console.log(\"inline\");</script>\n </body>\n </html>\n `);\n expect(() => extractBuildOutputs(\"dummy/path.html\")).toThrow(\n \"Unexpected inline content found in Vite HTML output\",\n );\n});\n\ntest(\"extractBuildOutputs throws error for invalid script type\", () => {\n vi.mocked(fs.readFileSync).mockReturnValue(`\n <html>\n <head>\n <script src=\"/script.js\" type=\"text/unknown\"></script>\n </head>\n </html>\n `);\n expect(() => extractBuildOutputs(\"dummy/path.html\")).toThrow(\n \"Invalid script type attribute found in Vite HTML output: text/unknown\",\n );\n});\n\ntest(\"extractBuildOutputs throws error for unexpected script attributes\", () => {\n vi.mocked(fs.readFileSync).mockReturnValue(`\n <html>\n <head>\n <script src=\"/script.js\" type=\"module\" async></script>\n </head>\n </html>\n `);\n expect(() => extractBuildOutputs(\"dummy/path.html\")).toThrow(\n \"Unexpected async attribute found in Vite HTML output\",\n );\n});\n\ntest(\"extractBuildOutputs throws error for stylesheet without href\", () => {\n vi.mocked(fs.readFileSync).mockReturnValue(`\n <html>\n <head>\n <link rel=\"stylesheet\">\n </head>\n </html>\n `);\n expect(() => extractBuildOutputs(\"dummy/path.html\")).toThrow(\n \"Missing href attribute in Vite HTML output\",\n );\n});\n\ntest(\"extractBuildOutputs ignores non-stylesheet links\", () => {\n vi.mocked(fs.readFileSync).mockReturnValue(`\n <html>\n <head>\n <link rel=\"icon\" href=\"/favicon.ico\">\n <link rel=\"stylesheet\" href=\"/styles.css\">\n </head>\n </html>\n `);\n const result = extractBuildOutputs(\"dummy/path.html\");\n expect(result).toEqual({\n scripts: [],\n stylesheets: [\"/styles.css\"],\n });\n});\n\ntest(\"extractBuildOutputs throws error for unexpected link attributes\", () => {\n vi.mocked(fs.readFileSync).mockReturnValue(`\n <html>\n <head>\n <link rel=\"stylesheet\" href=\"/styles.css\" async>\n </head>\n </html>\n `);\n expect(() => extractBuildOutputs(\"dummy/path.html\")).toThrow(\n \"Unexpected async attribute found in Vite HTML output\",\n );\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,IAAI;AACnB,SAASC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,QAAQ;AACzC,SAASC,mBAAmB,QAAQ,2BAA2B;AAE/DD,EAAE,CAACE,IAAI,CAAC,IAAI,CAAC;AAEb,MAAMC,YAAY,GAAG;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAEDJ,IAAI,CAAC,kDAAkD,EAAE,MAAM;EAC7DC,EAAE,CAACI,MAAM,CAACP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ACC,eAAe,CAAC;AAC7C;AACA;AACA;AACA;AACA;AACA,GAAG,CAAC;EACFR,MAAM,CAAC,MAAMG,mBAAmB,CAAC,iBAAiB,CAAC,CAAC,CAACa,OAAO,CAC1D,sDACF,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,148 @@
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 { expect, test, vi } from "vitest";
18
+ import * as extractBuildOutputsModule from "../extractBuildOutputs.js";
19
+ import { getWidgetBuildOutputs } from "../getWidgetBuildOutputs.js";
20
+ vi.mock("../extractBuildOutputs.js");
21
+ const MOCK_BUILD_DIR = "/build";
22
+ const MOCK_INPUT = "index.html";
23
+ const MOCK_WIDGET_ID = "widget-id";
24
+ test("getWidgetBuildOutputs successfully matches widget build outputs", () => {
25
+ const mockBuildOutputs = {
26
+ scripts: [{
27
+ type: "script",
28
+ scriptType: "module",
29
+ src: "/chunk.js"
30
+ }],
31
+ stylesheets: ["/styles.css"]
32
+ };
33
+ vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue(mockBuildOutputs);
34
+ const configFile = "/src/widget.config.js";
35
+ const widgetConfig = mockWidgetConfig(MOCK_WIDGET_ID);
36
+ const entryChunk = mockChunk({
37
+ fileName: "chunk.js",
38
+ isEntry: true,
39
+ facadeModuleId: "/src/widget.js",
40
+ moduleIds: [configFile]
41
+ });
42
+ const result = getWidgetBuildOutputs({
43
+ "chunk.js": entryChunk
44
+ }, MOCK_INPUT, MOCK_BUILD_DIR, {
45
+ [configFile]: widgetConfig
46
+ });
47
+ expect(result).toEqual({
48
+ ...mockBuildOutputs,
49
+ widgetConfig
50
+ });
51
+ });
52
+ test("getWidgetBuildOutputs throws error when entrypoint chunk not found", () => {
53
+ vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue({
54
+ scripts: [{
55
+ type: "script",
56
+ scriptType: "module",
57
+ src: "/non-existent.js"
58
+ }],
59
+ stylesheets: []
60
+ });
61
+ const nonEntryChunk = mockChunk({
62
+ fileName: "chunk.js",
63
+ isEntry: true,
64
+ facadeModuleId: "/src/widget.js",
65
+ moduleIds: []
66
+ });
67
+ expect(() => getWidgetBuildOutputs({
68
+ "chunk.js": nonEntryChunk
69
+ }, MOCK_INPUT, MOCK_BUILD_DIR, {})).toThrow("Entrypoint chunk not found for input file: index.html");
70
+ });
71
+ test("getWidgetBuildOutputs throws error when no config file found", () => {
72
+ vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue({
73
+ scripts: [{
74
+ type: "script",
75
+ scriptType: "module",
76
+ src: "/chunk.js"
77
+ }],
78
+ stylesheets: []
79
+ });
80
+ const entryChunk = mockChunk({
81
+ fileName: "chunk.js",
82
+ isEntry: true,
83
+ facadeModuleId: "/src/widget.js",
84
+ moduleIds: []
85
+ });
86
+ expect(() => getWidgetBuildOutputs({
87
+ "chunk.js": entryChunk
88
+ }, MOCK_INPUT, MOCK_BUILD_DIR, {})).toThrow("No widget config files found for entrypoint /src/widget.js");
89
+ });
90
+ test("getWidgetBuildOutputs throws error when multiple config files found", () => {
91
+ vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue({
92
+ scripts: [{
93
+ type: "script",
94
+ scriptType: "module",
95
+ src: "/chunk.js"
96
+ }],
97
+ stylesheets: []
98
+ });
99
+ const entryChunk = mockChunk({
100
+ fileName: "chunk.js",
101
+ isEntry: true,
102
+ facadeModuleId: "/src/widget.js",
103
+ moduleIds: ["/src/widget.config.js", "/src/widget.config.ts"]
104
+ });
105
+ expect(() => getWidgetBuildOutputs({
106
+ "chunk.js": entryChunk
107
+ }, MOCK_INPUT, MOCK_BUILD_DIR, {})).toThrow("Multiple widget config files found for entrypoint /src/widget.js");
108
+ });
109
+ test("getWidgetBuildOutputs throws error when config file not found in configFiles", () => {
110
+ vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue({
111
+ scripts: [{
112
+ type: "script",
113
+ scriptType: "module",
114
+ src: "/chunk.js"
115
+ }],
116
+ stylesheets: []
117
+ });
118
+ const entryChunk = mockChunk({
119
+ fileName: "chunk.js",
120
+ isEntry: true,
121
+ facadeModuleId: "/src/widget.js",
122
+ moduleIds: ["/src/widget.config.js"]
123
+ });
124
+ expect(() => getWidgetBuildOutputs({
125
+ "chunk.js": entryChunk
126
+ }, MOCK_INPUT, MOCK_BUILD_DIR, {})).toThrow("No config file found for entrypoint /src/widget.js");
127
+ });
128
+ function mockChunk(props) {
129
+ return {
130
+ type: "chunk",
131
+ fileName: "chunk.js",
132
+ isEntry: false,
133
+ facadeModuleId: null,
134
+ moduleIds: [],
135
+ ...props
136
+ };
137
+ }
138
+ function mockWidgetConfig(id) {
139
+ return {
140
+ id,
141
+ name: id,
142
+ description: id,
143
+ type: "workshop",
144
+ parameters: {},
145
+ events: {}
146
+ };
147
+ }
148
+ //# sourceMappingURL=getWidgetBuildOutputs.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWidgetBuildOutputs.test.js","names":["expect","test","vi","extractBuildOutputsModule","getWidgetBuildOutputs","mock","MOCK_BUILD_DIR","MOCK_INPUT","MOCK_WIDGET_ID","mockBuildOutputs","scripts","type","scriptType","src","stylesheets","mocked","extractBuildOutputs","mockReturnValue","configFile","widgetConfig","mockWidgetConfig","entryChunk","mockChunk","fileName","isEntry","facadeModuleId","moduleIds","result","toEqual","nonEntryChunk","toThrow","props","id","name","description","parameters","events"],"sources":["getWidgetBuildOutputs.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 { Rollup } from \"vite\";\nimport { expect, test, vi } from \"vitest\";\nimport * as extractBuildOutputsModule from \"../extractBuildOutputs.js\";\nimport { getWidgetBuildOutputs } from \"../getWidgetBuildOutputs.js\";\n\nvi.mock(\"../extractBuildOutputs.js\");\n\nconst MOCK_BUILD_DIR = \"/build\";\nconst MOCK_INPUT = \"index.html\";\nconst MOCK_WIDGET_ID = \"widget-id\";\n\ntest(\"getWidgetBuildOutputs successfully matches widget build outputs\", () => {\n const mockBuildOutputs = {\n scripts: [{\n type: \"script\" as const,\n scriptType: \"module\" as const,\n src: \"/chunk.js\",\n }],\n stylesheets: [\"/styles.css\"],\n };\n vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue(\n mockBuildOutputs,\n );\n\n const configFile = \"/src/widget.config.js\";\n const widgetConfig = mockWidgetConfig(MOCK_WIDGET_ID);\n const configFiles = { [configFile]: widgetConfig };\n\n const entryChunk = mockChunk({\n fileName: \"chunk.js\",\n isEntry: true,\n facadeModuleId: \"/src/widget.js\",\n moduleIds: [configFile],\n });\n\n const result = getWidgetBuildOutputs(\n { \"chunk.js\": entryChunk },\n MOCK_INPUT,\n MOCK_BUILD_DIR,\n configFiles,\n );\n expect(result).toEqual({\n ...mockBuildOutputs,\n widgetConfig,\n });\n});\n\ntest(\"getWidgetBuildOutputs throws error when entrypoint chunk not found\", () => {\n vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue({\n scripts: [{\n type: \"script\" as const,\n scriptType: \"module\" as const,\n src: \"/non-existent.js\",\n }],\n stylesheets: [],\n });\n\n const nonEntryChunk = mockChunk({\n fileName: \"chunk.js\",\n isEntry: true,\n facadeModuleId: \"/src/widget.js\",\n moduleIds: [],\n });\n\n expect(() =>\n getWidgetBuildOutputs(\n { \"chunk.js\": nonEntryChunk },\n MOCK_INPUT,\n MOCK_BUILD_DIR,\n {},\n )\n )\n .toThrow(\"Entrypoint chunk not found for input file: index.html\");\n});\n\ntest(\"getWidgetBuildOutputs throws error when no config file found\", () => {\n vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue({\n scripts: [{\n type: \"script\" as const,\n scriptType: \"module\" as const,\n src: \"/chunk.js\",\n }],\n stylesheets: [],\n });\n\n const entryChunk = mockChunk({\n fileName: \"chunk.js\",\n isEntry: true,\n facadeModuleId: \"/src/widget.js\",\n moduleIds: [],\n });\n\n expect(() =>\n getWidgetBuildOutputs(\n { \"chunk.js\": entryChunk },\n MOCK_INPUT,\n MOCK_BUILD_DIR,\n {},\n )\n )\n .toThrow(\"No widget config files found for entrypoint /src/widget.js\");\n});\n\ntest(\"getWidgetBuildOutputs throws error when multiple config files found\", () => {\n vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue({\n scripts: [{\n type: \"script\" as const,\n scriptType: \"module\" as const,\n src: \"/chunk.js\",\n }],\n stylesheets: [],\n });\n\n const entryChunk = mockChunk({\n fileName: \"chunk.js\",\n isEntry: true,\n facadeModuleId: \"/src/widget.js\",\n moduleIds: [\"/src/widget.config.js\", \"/src/widget.config.ts\"],\n });\n\n expect(() =>\n getWidgetBuildOutputs(\n { \"chunk.js\": entryChunk },\n MOCK_INPUT,\n MOCK_BUILD_DIR,\n {},\n )\n )\n .toThrow(\n \"Multiple widget config files found for entrypoint /src/widget.js\",\n );\n});\n\ntest(\"getWidgetBuildOutputs throws error when config file not found in configFiles\", () => {\n vi.mocked(extractBuildOutputsModule.extractBuildOutputs).mockReturnValue({\n scripts: [{\n type: \"script\" as const,\n scriptType: \"module\" as const,\n src: \"/chunk.js\",\n }],\n stylesheets: [],\n });\n\n const configFile = \"/src/widget.config.js\";\n const entryChunk = mockChunk({\n fileName: \"chunk.js\",\n isEntry: true,\n facadeModuleId: \"/src/widget.js\",\n moduleIds: [configFile],\n });\n\n expect(() =>\n getWidgetBuildOutputs(\n { \"chunk.js\": entryChunk },\n MOCK_INPUT,\n MOCK_BUILD_DIR,\n {},\n )\n )\n .toThrow(\"No config file found for entrypoint /src/widget.js\");\n});\n\nfunction mockChunk(props: Partial<Rollup.OutputChunk>): Rollup.OutputChunk {\n return {\n type: \"chunk\",\n fileName: \"chunk.js\",\n isEntry: false,\n facadeModuleId: null,\n moduleIds: [],\n ...props,\n } as Rollup.OutputChunk;\n}\n\nfunction mockWidgetConfig(id: string): WidgetConfig<ParameterConfig> {\n return {\n id,\n name: id,\n description: id,\n type: \"workshop\",\n parameters: {},\n events: {},\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,QAAQ;AACzC,OAAO,KAAKC,yBAAyB,MAAM,2BAA2B;AACtE,SAASC,qBAAqB,QAAQ,6BAA6B;AAEnEF,EAAE,CAACG,IAAI,CAAC,2BAA2B,CAAC;AAEpC,MAAMC,cAAc,GAAG,QAAQ;AAC/B,MAAMC,UAAU,GAAG,YAAY;AAC/B,MAAMC,cAAc,GAAG,WAAW;AAElCP,IAAI,CAAC,iEAAiE,EAAE,MAAM;EAC5E,MAAMQ,gBAAgB,GAAG;IACvBC,OAAO,EAAE,CAAC;MACRC,IAAI,EAAE,QAAiB;MACvBC,UAAU,EAAE,QAAiB;MAC7BC,GAAG,EAAE;IACP,CAAC,CAAC;IACFC,WAAW,EAAE,CAAC,aAAa;EAC7B,CAAC;EACDZ,EAAE,CAACa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,EAAE,MAAM;EACzFC,EAAE,CAACa,MAAM,CAACZ,yBAAyB,CAACa,mBAAmB,CAAC,CAACC,eAAe,CAAC;IACvEP,OAAO,EAAE,CAAC;MACRC,IAAI,EAAE,QAAiB;MACvBC,UAAU,EAAE,QAAiB;MAC7BC,GAAG,EAAE;IACP,CAAC,CAAC;IACFC,WAAW,EAAE;EACf,CAAC,CAAC;EAGF,MAAMO,UAAU,GAAGC,SAAS,CAAC;IAC3BC,QAAQ,EAAE,UAAU;IACpBC,OAAO,EAAE,IAAI;IACbC,cAAc,EAAE,gBAAgB;IAChCC,SAAS,EAAE,CALM,uBAAuB;EAM1C,CAAC,CAAC;EAEF1B,MAAM,CAAC,MACLI,qBAAqB,CACnB;IAAE,UAAU,EAAEiB;EAAW,CAAC,EAC1Bd,UAAU,EACVD,cAAc,EACd,CAAC,CACH,CACF,CAAC,CACEwB,OAAO,CAAC,oDAAoD,CAAC;AAClE,CAAC,CAAC;AAEF,SAASR,SAASA,CAACS,KAAkC,EAAsB;EACzE,OAAO;IACLpB,IAAI,EAAE,OAAO;IACbY,QAAQ,EAAE,UAAU;IACpBC,OAAO,EAAE,KAAK;IACdC,cAAc,EAAE,IAAI;IACpBC,SAAS,EAAE,EAAE;IACb,GAAGK;EACL,CAAC;AACH;AAEA,SAASX,gBAAgBA,CAACY,EAAU,EAAiC;EACnE,OAAO;IACLA,EAAE;IACFC,IAAI,EAAED,EAAE;IACRE,WAAW,EAAEF,EAAE;IACfrB,IAAI,EAAE,UAAU;IAChBwB,UAAU,EAAE,CAAC,CAAC;IACdC,MAAM,EAAE,CAAC;EACX,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,48 @@
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
+ export function buildWidgetSetManifest(widgetSetRid, widgetSetVersion, widgetBuilds) {
18
+ return {
19
+ manifestVersion: "1.0.0",
20
+ widgetSet: {
21
+ rid: widgetSetRid,
22
+ version: widgetSetVersion,
23
+ widgets: Object.fromEntries(widgetBuilds.map(buildWidgetManifest).map(widgetManifest => [widgetManifest.id, widgetManifest]))
24
+ }
25
+ };
26
+ }
27
+ function buildWidgetManifest(widgetBuild) {
28
+ const widgetConfig = widgetBuild.widgetConfig;
29
+ return {
30
+ id: widgetConfig.id,
31
+ name: widgetConfig.name,
32
+ description: widgetConfig.description,
33
+ type: "workshopWidgetV1",
34
+ entrypointJs: widgetBuild.scripts.map(script => ({
35
+ path: trimLeadingSlash(script.src),
36
+ type: script.scriptType
37
+ })),
38
+ entrypointCss: widgetBuild.stylesheets.map(path => ({
39
+ path: trimLeadingSlash(path)
40
+ })),
41
+ parameters: widgetConfig.parameters,
42
+ events: widgetConfig.events
43
+ };
44
+ }
45
+ function trimLeadingSlash(path) {
46
+ return path.startsWith("/") ? path.slice(1) : path;
47
+ }
48
+ //# sourceMappingURL=buildWidgetSetManifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildWidgetSetManifest.js","names":["buildWidgetSetManifest","widgetSetRid","widgetSetVersion","widgetBuilds","manifestVersion","widgetSet","rid","version","widgets","Object","fromEntries","map","buildWidgetManifest","widgetManifest","id","widgetBuild","widgetConfig","name","description","type","entrypointJs","scripts","script","path","trimLeadingSlash","src","scriptType","entrypointCss","stylesheets","parameters","events","startsWith","slice"],"sources":["buildWidgetSetManifest.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 { WidgetManifestConfig, WidgetSetManifest } from \"@osdk/widget.api\";\nimport type { WidgetBuildOutputs } from \"./getWidgetBuildOutputs.js\";\n\nexport function buildWidgetSetManifest(\n widgetSetRid: string,\n widgetSetVersion: string,\n widgetBuilds: WidgetBuildOutputs[],\n): WidgetSetManifest {\n return {\n manifestVersion: \"1.0.0\",\n widgetSet: {\n rid: widgetSetRid,\n version: widgetSetVersion,\n widgets: Object.fromEntries(\n widgetBuilds\n .map(buildWidgetManifest)\n .map((widgetManifest) => [widgetManifest.id, widgetManifest]),\n ),\n },\n };\n}\n\nfunction buildWidgetManifest(\n widgetBuild: WidgetBuildOutputs,\n): WidgetManifestConfig {\n const widgetConfig = widgetBuild.widgetConfig;\n return {\n id: widgetConfig.id,\n name: widgetConfig.name,\n description: widgetConfig.description,\n type: \"workshopWidgetV1\",\n entrypointJs: widgetBuild.scripts.map((script) => ({\n path: trimLeadingSlash(script.src),\n type: script.scriptType,\n })),\n entrypointCss: widgetBuild.stylesheets.map((path) => ({\n path: trimLeadingSlash(path),\n })),\n parameters: widgetConfig.parameters,\n events: widgetConfig.events,\n };\n}\n\nfunction trimLeadingSlash(path: string): string {\n return path.startsWith(\"/\") ? path.slice(1) : path;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,OAAO,SAASA,sBAAsBA,CACpCC,YAAoB,EACpBC,gBAAwB,EACxBC,YAAkC,EACf;EACnB,OAAO;IACLC,eAAe,EAAE,OAAO;IACxBC,SAAS,EAAE;MACTC,GAAG,EAAEL,YAAY;MACjBM,OAAO,EAAEL,gBAAgB;MACzBM,OAAO,EAAEC,MAAM,CAACC,WAAW,CACzBP,YAAY,CACTQ,GAAG,CAACC,mBAAmB,CAAC,CACxBD,GAAG,CAAEE,cAAc,IAAK,CAACA,cAAc,CAACC,EAAE,EAAED,cAAc,CAAC,CAChE;IACF;EACF,CAAC;AACH;AAEA,SAASD,mBAAmBA,CAC1BG,WAA+B,EACT;EACtB,MAAMC,YAAY,GAAGD,WAAW,CAACC,YAAY;EAC7C,OAAO;IACLF,EAAE,EAAEE,YAAY,CAACF,EAAE;IACnBG,IAAI,EAAED,YAAY,CAACC,IAAI;IACvBC,WAAW,EAAEF,YAAY,CAACE,WAAW;IACrCC,IAAI,EAAE,kBAAkB;IACxBC,YAAY,EAAEL,WAAW,CAACM,OAAO,CAACV,GAAG,CAAEW,MAAM,KAAM;MACjDC,IAAI,EAAEC,gBAAgB,CAACF,MAAM,CAACG,GAAG,CAAC;MAClCN,IAAI,EAAEG,MAAM,CAACI;IACf,CAAC,CAAC,CAAC;IACHC,aAAa,EAAEZ,WAAW,CAACa,WAAW,CAACjB,GAAG,CAAEY,IAAI,KAAM;MACpDA,IAAI,EAAEC,gBAAgB,CAACD,IAAI;IAC7B,CAAC,CAAC,CAAC;IACHM,UAAU,EAAEb,YAAY,CAACa,UAAU;IACnCC,MAAM,EAAEd,YAAY,CAACc;EACvB,CAAC;AACH;AAEA,SAASN,gBAAgBA,CAACD,IAAY,EAAU;EAC9C,OAAOA,IAAI,CAACQ,UAAU,CAAC,GAAG,CAAC,GAAGR,IAAI,CAACS,KAAK,CAAC,CAAC,CAAC,GAAGT,IAAI;AACpD","ignoreList":[]}
@@ -0,0 +1,107 @@
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 fs from "fs";
18
+ import { parse as parse5 } from "parse5";
19
+ export function extractBuildOutputs(htmlFilePath) {
20
+ const htmlContent = fs.readFileSync(htmlFilePath, "utf-8");
21
+ return parseTransformResult(htmlContent);
22
+ }
23
+
24
+ /**
25
+ * Parse the HTML transform result and extract the injected script details.
26
+ */
27
+ function parseTransformResult(result) {
28
+ const outputs = visitNode(parse5(result));
29
+ return {
30
+ scripts: outputs.filter(output => output.type === "script"),
31
+ stylesheets: outputs.filter(output => output.type === "stylesheet").map(output => output.src)
32
+ };
33
+ }
34
+ function visitNode(node) {
35
+ if (node.nodeName === "script") {
36
+ return [parseScriptNode(node)];
37
+ }
38
+ if (node.nodeName === "link" && getAttribute(node, "rel") === "stylesheet") {
39
+ return [parseStylesheetNode(node)];
40
+ }
41
+ if ("childNodes" in node) {
42
+ return node.childNodes.flatMap(childNode => visitNode(childNode));
43
+ }
44
+ return [];
45
+ }
46
+ function parseScriptNode(node) {
47
+ assertEmptyNode(node);
48
+ assertMinAttributes(node, ["src"]);
49
+ assertMaxAttributes(node, ["src", "type", "crossorigin"]);
50
+ const srcAttribute = getAttribute(node, "src");
51
+ const typeAttribute = getAttributeOrDefault(node, "type", "text/javascript");
52
+ if (!isValidScriptType(typeAttribute)) {
53
+ throw new Error(`Invalid script type attribute found in Vite HTML output: ${typeAttribute}`);
54
+ }
55
+ return {
56
+ type: "script",
57
+ scriptType: typeAttribute ?? "text/javascript",
58
+ src: srcAttribute
59
+ };
60
+ }
61
+ function parseStylesheetNode(node) {
62
+ assertEmptyNode(node);
63
+ assertMinAttributes(node, ["rel", "href"]);
64
+ // We don't handle media queries or other attributes on the link tag
65
+ assertMaxAttributes(node, ["rel", "href", "crossorigin"]);
66
+ const srcAttribute = getAttribute(node, "href");
67
+ return {
68
+ type: "stylesheet",
69
+ src: srcAttribute
70
+ };
71
+ }
72
+ function isValidScriptType(type) {
73
+ return type === "text/javascript" || type === "module";
74
+ }
75
+ function assertMinAttributes(node, requiredAttributeNames) {
76
+ const actualAttributeNames = new Set(node.attrs?.map(attr => attr.name));
77
+ requiredAttributeNames.forEach(requiredAttributeName => {
78
+ if (!actualAttributeNames.has(requiredAttributeName)) {
79
+ throw new Error(`Missing ${requiredAttributeName} attribute in Vite HTML output`);
80
+ }
81
+ });
82
+ }
83
+ function assertMaxAttributes(node, allowedAttributeNames) {
84
+ const actualAttributeNames = new Set(node.attrs?.map(attr => attr.name));
85
+ actualAttributeNames.forEach(actualAttributeName => {
86
+ if (!allowedAttributeNames.includes(actualAttributeName)) {
87
+ throw new Error(`Unexpected ${actualAttributeName} attribute found in Vite HTML output`);
88
+ }
89
+ });
90
+ }
91
+ function assertEmptyNode(node) {
92
+ if ("childNodes" in node && node.childNodes.length > 0) {
93
+ throw new Error("Unexpected inline content found in Vite HTML output");
94
+ }
95
+ }
96
+ function assertValue(actual, allowedValues) {
97
+ if (!allowedValues.includes(actual)) {
98
+ throw new Error(`Invalid value found in Vite HTML output: ${actual}`);
99
+ }
100
+ }
101
+ function getAttribute(node, attributeName) {
102
+ return node.attrs?.find(attribute => attribute.name === attributeName)?.value;
103
+ }
104
+ function getAttributeOrDefault(node, attributeName, defaultValue) {
105
+ return getAttribute(node, attributeName) ?? defaultValue;
106
+ }
107
+ //# sourceMappingURL=extractBuildOutputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractBuildOutputs.js","names":["fs","parse","parse5","extractBuildOutputs","htmlFilePath","htmlContent","readFileSync","parseTransformResult","result","outputs","visitNode","scripts","filter","output","type","stylesheets","map","src","node","nodeName","parseScriptNode","getAttribute","parseStylesheetNode","childNodes","flatMap","childNode","assertEmptyNode","assertMinAttributes","assertMaxAttributes","srcAttribute","typeAttribute","getAttributeOrDefault","isValidScriptType","Error","scriptType","requiredAttributeNames","actualAttributeNames","Set","attrs","attr","name","forEach","requiredAttributeName","has","allowedAttributeNames","actualAttributeName","includes","length","assertValue","actual","allowedValues","attributeName","find","attribute","value","defaultValue"],"sources":["extractBuildOutputs.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 fs from \"fs\";\nimport type { DefaultTreeAdapterTypes } from \"parse5\";\nimport { parse as parse5 } from \"parse5\";\n\nexport interface BuildOutputs {\n scripts: Array<ScriptBuildOutput>;\n stylesheets: string[];\n}\n\ntype BuildOutput = ScriptBuildOutput | StylesheetBuildOutput;\n\ntype ScriptType = \"text/javascript\" | \"module\";\ntype ScriptBuildOutput = {\n type: \"script\";\n scriptType: ScriptType;\n src: string;\n};\n\ntype StylesheetBuildOutput = {\n type: \"stylesheet\";\n src: string;\n};\n\nexport function extractBuildOutputs(\n htmlFilePath: string,\n): BuildOutputs {\n const htmlContent = fs.readFileSync(htmlFilePath, \"utf-8\");\n return parseTransformResult(htmlContent);\n}\n\n/**\n * Parse the HTML transform result and extract the injected script details.\n */\nfunction parseTransformResult(result: string): BuildOutputs {\n const outputs = visitNode(parse5(result));\n return {\n scripts: outputs.filter((output) =>\n output.type === \"script\"\n ) as ScriptBuildOutput[],\n stylesheets: outputs.filter((output) => output.type === \"stylesheet\").map((\n output,\n ) => output.src),\n };\n}\n\nfunction visitNode(node: DefaultTreeAdapterTypes.Node): BuildOutput[] {\n if (node.nodeName === \"script\") {\n return [parseScriptNode(node as DefaultTreeAdapterTypes.Element)];\n }\n if (node.nodeName === \"link\" && getAttribute(node, \"rel\") === \"stylesheet\") {\n return [parseStylesheetNode(node as DefaultTreeAdapterTypes.Element)];\n }\n if (\"childNodes\" in node) {\n return node.childNodes.flatMap((childNode) => visitNode(childNode));\n }\n return [];\n}\n\nfunction parseScriptNode(\n node: DefaultTreeAdapterTypes.Element,\n): ScriptBuildOutput {\n assertEmptyNode(node);\n assertMinAttributes(node, [\"src\"]);\n assertMaxAttributes(node, [\"src\", \"type\", \"crossorigin\"]);\n const srcAttribute = getAttribute(node, \"src\")!;\n const typeAttribute = getAttributeOrDefault(node, \"type\", \"text/javascript\");\n if (!isValidScriptType(typeAttribute)) {\n throw new Error(\n `Invalid script type attribute found in Vite HTML output: ${typeAttribute}`,\n );\n }\n return {\n type: \"script\",\n scriptType: typeAttribute ?? \"text/javascript\",\n src: srcAttribute,\n };\n}\n\nfunction parseStylesheetNode(\n node: DefaultTreeAdapterTypes.Element,\n): StylesheetBuildOutput {\n assertEmptyNode(node);\n assertMinAttributes(node, [\"rel\", \"href\"]);\n // We don't handle media queries or other attributes on the link tag\n assertMaxAttributes(node, [\"rel\", \"href\", \"crossorigin\"]);\n const srcAttribute = getAttribute(node, \"href\")!;\n return { type: \"stylesheet\", src: srcAttribute };\n}\n\nfunction isValidScriptType(type: string): type is ScriptType {\n return type === \"text/javascript\" || type === \"module\";\n}\n\nfunction assertMinAttributes(\n node: DefaultTreeAdapterTypes.Element,\n requiredAttributeNames: string[],\n): void {\n const actualAttributeNames = new Set(node.attrs?.map((attr) => attr.name));\n requiredAttributeNames.forEach((requiredAttributeName) => {\n if (!actualAttributeNames.has(requiredAttributeName)) {\n throw new Error(\n `Missing ${requiredAttributeName} attribute in Vite HTML output`,\n );\n }\n });\n}\n\nfunction assertMaxAttributes(\n node: DefaultTreeAdapterTypes.Element,\n allowedAttributeNames: string[],\n): void {\n const actualAttributeNames = new Set(node.attrs?.map((attr) => attr.name));\n actualAttributeNames.forEach((actualAttributeName) => {\n if (!allowedAttributeNames.includes(actualAttributeName)) {\n throw new Error(\n `Unexpected ${actualAttributeName} attribute found in Vite HTML output`,\n );\n }\n });\n}\n\nfunction assertEmptyNode(node: DefaultTreeAdapterTypes.Node): void {\n if (\"childNodes\" in node && node.childNodes.length > 0) {\n throw new Error(\"Unexpected inline content found in Vite HTML output\");\n }\n}\n\nfunction assertValue(\n actual: string,\n allowedValues: string[],\n) {\n if (!allowedValues.includes(actual)) {\n throw new Error(\n `Invalid value found in Vite HTML output: ${actual}`,\n );\n }\n}\n\nfunction getAttribute(\n node: DefaultTreeAdapterTypes.Element,\n attributeName: string,\n): string | undefined {\n return node.attrs?.find((attribute) => attribute.name === attributeName)\n ?.value;\n}\n\nfunction getAttributeOrDefault(\n node: DefaultTreeAdapterTypes.Element,\n attributeName: string,\n defaultValue: string,\n): string {\n return getAttribute(node, attributeName) ?? defaultValue;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,IAAI;AAEnB,SAASC,KAAK,IAAIC,MAAM,QAAQ,QAAQ;AAqBxC,OAAO,SAASC,mBAAmBA,CACjCC,YAAoB,EACN;EACd,MAAMC,WAAW,GAAGL,EAAE,CAACM,YAAY,CAACF,YAAY,EAAE,OAAO,CAAC;EAC1D,OAAOG,oBAAoB,CAACF,WAAW,CAAC;AAC1C;;AAEA;AACA;AACA;AACA,SAASE,oBAAoBA,CAACC,MAAc,EAAgB;EAC1D,MAAMC,OAAO,GAAGC,SAAS,CAACR,MAAM,CAACM,MAAM,CAAC,CAAC;EACzC,OAAO;IACLG,OAAO,EAAEF,OAAO,CAACG,MAAM,CAAEC,MAAM,IAC7BA,MAAM,CAACC,IAAI,KAAK,QAClB,CAAwB;IACxBC,WAAW,EAAEN,OAAO,CAACG,MAAM,CAAEC,MAAM,IAAKA,MAAM,CAACC,IAAI,KAAK,YAAY,CAAC,CAACE,GAAG,CACvEH,MAAM,IAC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,UAAU,CAACwB,MAAM,GAAG,CAAC,EAAE;IACtD,MAAM,IAAId,KAAK,CAAC,qDAAqD,CAAC;EACxE;AACF;AAEA,SAASe,WAAWA,CAClBC,MAAc,EACdC,aAAuB,EACvB;EACA,IAAI,CAACA,aAAa,CAACJ,QAAQ,CAACG,MAAM,CAAC,EAAE;IACnC,MAAM,IAAIhB,KAAK,CACb,4CAA4CgB,MAAM,EACpD,CAAC;EACH;AACF;AAEA,SAAS5B,YAAYA,CACnBH,IAAqC,EACrCiC,aAAqB,EACD;EACpB,OAAOjC,IAAI,CAACoB,KAAK,EAAEc,IAAI,CAAEC,SAAS,IAAKA,SAAS,CAACb,IAAI,KAAKW,aAAa,CAAC,EACpEG,KAAK;AACX;AAEA,SAASvB,qBAAqBA,CAC5Bb,IAAqC,EACrCiC,aAAqB,EACrBI,YAAoB,EACZ;EACR,OAAOlC,YAAY,CAACH,IAAI,EAAEiC,aAAa,CAAC,IAAII,YAAY;AAC1D","ignoreList":[]}
@@ -0,0 +1,50 @@
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 path from "path";
18
+ import { standardizeFileExtension } from "../common/standardizeFileExtension.js";
19
+ import { extractBuildOutputs } from "./extractBuildOutputs.js";
20
+ import { isConfigFile } from "./isConfigFile.js";
21
+ export function getWidgetBuildOutputs(bundle, input, buildDir, configFiles) {
22
+ const inputHtmlFilePath = path.resolve(buildDir, path.relative(process.cwd(), input));
23
+ const buildOutputs = extractBuildOutputs(inputHtmlFilePath);
24
+ const scriptPaths = new Set(buildOutputs.scripts.map(script => script.src.slice(1)));
25
+ const entrypointChunk = Object.values(bundle).find(chunk => chunk.type === "chunk" && chunk.isEntry && scriptPaths.has(chunk.fileName));
26
+ if (entrypointChunk == null) {
27
+ throw new Error(`Entrypoint chunk not found for input file: ${input}`);
28
+ }
29
+ const widgetConfig = getChunkConfigFile(entrypointChunk, configFiles);
30
+ return {
31
+ ...buildOutputs,
32
+ widgetConfig
33
+ };
34
+ }
35
+ function getChunkConfigFile(chunk, configFiles) {
36
+ const configModuleIds = chunk.moduleIds.filter(isConfigFile);
37
+ if (configModuleIds.length === 0) {
38
+ throw new Error(`No widget config files found for entrypoint ${chunk.facadeModuleId}`);
39
+ }
40
+ if (configModuleIds.length > 1) {
41
+ throw new Error(`Multiple widget config files found for entrypoint ${chunk.facadeModuleId}`);
42
+ }
43
+ const standardizedSource = standardizeFileExtension(configModuleIds[0]);
44
+ const configFile = configFiles[standardizedSource];
45
+ if (configFile == null) {
46
+ throw new Error(`No config file found for entrypoint ${chunk.facadeModuleId}`);
47
+ }
48
+ return configFile;
49
+ }
50
+ //# sourceMappingURL=getWidgetBuildOutputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getWidgetBuildOutputs.js","names":["path","standardizeFileExtension","extractBuildOutputs","isConfigFile","getWidgetBuildOutputs","bundle","input","buildDir","configFiles","inputHtmlFilePath","resolve","relative","process","cwd","buildOutputs","scriptPaths","Set","scripts","map","script","src","slice","entrypointChunk","Object","values","find","chunk","type","isEntry","has","fileName","Error","widgetConfig","getChunkConfigFile","configModuleIds","moduleIds","filter","length","facadeModuleId","standardizedSource","configFile"],"sources":["getWidgetBuildOutputs.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 path from \"path\";\nimport type { Rollup } from \"vite\";\nimport { standardizeFileExtension } from \"../common/standardizeFileExtension.js\";\nimport type { BuildOutputs } from \"./extractBuildOutputs.js\";\nimport { extractBuildOutputs } from \"./extractBuildOutputs.js\";\nimport { isConfigFile } from \"./isConfigFile.js\";\n\nexport interface WidgetBuildOutputs extends BuildOutputs {\n widgetConfig: WidgetConfig<ParameterConfig>;\n}\n\nexport function getWidgetBuildOutputs(\n bundle: Rollup.OutputBundle,\n input: string,\n buildDir: string,\n configFiles: Record<string, WidgetConfig<ParameterConfig>>,\n): WidgetBuildOutputs {\n const inputHtmlFilePath = path.resolve(\n buildDir,\n path.relative(process.cwd(), input),\n );\n const buildOutputs = extractBuildOutputs(inputHtmlFilePath);\n const scriptPaths = new Set(\n buildOutputs.scripts.map((script) => script.src.slice(1)),\n );\n const entrypointChunk = Object.values(bundle).find((\n chunk,\n ): chunk is Rollup.OutputChunk =>\n chunk.type === \"chunk\" && chunk.isEntry\n && scriptPaths.has(chunk.fileName)\n );\n if (entrypointChunk == null) {\n throw new Error(`Entrypoint chunk not found for input file: ${input}`);\n }\n const widgetConfig = getChunkConfigFile(entrypointChunk, configFiles);\n return { ...buildOutputs, widgetConfig };\n}\n\nfunction getChunkConfigFile(\n chunk: Rollup.OutputChunk,\n configFiles: Record<string, WidgetConfig<ParameterConfig>>,\n): WidgetConfig<ParameterConfig> {\n const configModuleIds = chunk.moduleIds.filter(isConfigFile);\n if (configModuleIds.length === 0) {\n throw new Error(\n `No widget config files found for entrypoint ${chunk.facadeModuleId}`,\n );\n }\n if (configModuleIds.length > 1) {\n throw new Error(\n `Multiple widget config files found for entrypoint ${chunk.facadeModuleId}`,\n );\n }\n\n const standardizedSource = standardizeFileExtension(configModuleIds[0]);\n const configFile = configFiles[standardizedSource];\n if (configFile == null) {\n throw new Error(\n `No config file found for entrypoint ${chunk.facadeModuleId}`,\n );\n }\n\n return configFile;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,IAAI,MAAM,MAAM;AAEvB,SAASC,wBAAwB,QAAQ,uCAAuC;AAEhF,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,YAAY,QAAQ,mBAAmB;AAMhD,OAAO,SAASC,qBAAqBA,CACnCC,MAA2B,EAC3BC,KAAa,EACbC,QAAgB,EAChBC,WAA0D,EACtC;EACpB,MAAMC,iBAAiB,GAAGT,IAAI,CAACU,OAAO,CACpCH,QAAQ,EACRP,IAAI,CAACW,QAAQ,CAACC,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEP,KAAK,CACpC,CAAC;EACD,MAAMQ,YAAY,GAAGZ,mBAAmB,CAACO,iBAAiB,CAAC;EAC3D,MAAMM,WAAW,GAAG,IAAIC,GAAG,CACzBF,YAAY,CAACG,OAAO,CAACC,GAAG,CAAEC,MAAM,IAAKA,MAAM,CAACC,GAAG,CAACC,KAAK,CAAC,CAAC,CAAC,CAC1D,CAAC;EACD,MAAMC,eAAe,GAAGC,MAAM,CAACC,MAAM,CAACnB,MAAM,CAAC,CAACoB,IAAI,CAChDC,KAAK,IAELA,KAAK,CAACC,IAAI,KAAK,OAAO,IAAID,KAAK,CAACE,OAAO,IACpCb,WAAW,CAACc,GAAG,CAACH,KAAK,CAACI,QAAQ,CACnC,CAAC;EACD,IAAIR,eAAe,IAAI,IAAI,EAAE;IAC3B,MAAM,IAAIS,KAAK,CAAC,8CAA8CzB,KAAK,EAAE,CAAC;EACxE;EACA,MAAM0B,YAAY,GAAGC,kBAAkB,CAACX,eAAe,EAAEd,WAAW,CAAC;EACrE,OAAO;IAAE,GAAGM,YAAY;IAAEkB;EAAa,CAAC;AAC1C;AAEA,SAASC,kBAAkBA,CACzBP,KAAyB,EACzBlB,WAA0D,EAC3B;EAC/B,MAAM0B,eAAe,GAAGR,KAAK,CAACS,SAAS,CAACC,MAAM,CAACjC,YAAY,CAAC;EAC5D,IAAI+B,eAAe,CAACG,MAAM,KAAK,CAAC,EAAE;IAChC,MAAM,IAAIN,KAAK,CACb,+CAA+CL,KAAK,CAACY,cAAc,EACrE,CAAC;EACH;EACA,IAAIJ,eAAe,CAACG,MAAM,GAAG,CAAC,EAAE;IAC9B,MAAM,IAAIN,KAAK,CACb,qDAAqDL,KAAK,CAACY,cAAc,EAC3E,CAAC;EACH;EAEA,MAAMC,kBAAkB,GAAGtC,wBAAwB,CAACiC,eAAe,CAAC,CAAC,CAAC,CAAC;EACvE,MAAMM,UAAU,GAAGhC,WAAW,CAAC+B,kBAAkB,CAAC;EAClD,IAAIC,UAAU,IAAI,IAAI,EAAE;IACtB,MAAM,IAAIT,KAAK,CACb,uCAAuCL,KAAK,CAACY,cAAc,EAC7D,CAAC;EACH;EAEA,OAAOE,UAAU;AACnB","ignoreList":[]}
@@ -0,0 +1,22 @@
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 { CONFIG_FILE_SUFFIX } from "../common/constants.js";
18
+ export function isConfigFile(filePath) {
19
+ const trimmedFilePath = filePath.replace(/\.[^/.]+$/, "");
20
+ return trimmedFilePath.endsWith(CONFIG_FILE_SUFFIX);
21
+ }
22
+ //# sourceMappingURL=isConfigFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isConfigFile.js","names":["CONFIG_FILE_SUFFIX","isConfigFile","filePath","trimmedFilePath","replace","endsWith"],"sources":["isConfigFile.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CONFIG_FILE_SUFFIX } from \"../common/constants.js\";\n\nexport function isConfigFile(filePath: string): boolean {\n const trimmedFilePath = filePath.replace(/\\.[^/.]+$/, \"\");\n return trimmedFilePath.endsWith(CONFIG_FILE_SUFFIX);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,kBAAkB,QAAQ,wBAAwB;AAE3D,OAAO,SAASC,YAAYA,CAACC,QAAgB,EAAW;EACtD,MAAMC,eAAe,GAAGD,QAAQ,CAACE,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;EACzD,OAAOD,eAAe,CAACE,QAAQ,CAACL,kBAAkB,CAAC;AACrD","ignoreList":[]}