@osdk/widget.vite-plugin 3.3.0-beta.1 → 3.3.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +76 -0
- package/build/esm/build-plugin/__tests__/validateWidgetSet.test.js +44 -0
- package/build/esm/build-plugin/__tests__/validateWidgetSet.test.js.map +1 -0
- package/build/esm/build-plugin/buildWidgetSetManifest.js +2 -0
- package/build/esm/build-plugin/buildWidgetSetManifest.js.map +1 -1
- package/build/esm/build-plugin/validateWidgetSet.js +30 -0
- package/build/esm/build-plugin/validateWidgetSet.js.map +1 -0
- package/build/esm/client/app.js +22 -6
- package/build/esm/client/app.js.map +1 -1
- package/build/esm/common/__tests__/extractWidgetConfig.test.js +3 -3
- package/build/esm/common/__tests__/extractWidgetConfig.test.js.map +1 -1
- package/build/esm/common/__tests__/standardizePathAndFileExtension.test.js +77 -0
- package/build/esm/common/__tests__/standardizePathAndFileExtension.test.js.map +1 -0
- package/build/esm/common/extractWidgetConfig.js +4 -1
- package/build/esm/common/extractWidgetConfig.js.map +1 -1
- package/build/esm/common/{standardizeFileExtension.js → standardizePathAndFileExtension.js} +13 -4
- package/build/esm/common/standardizePathAndFileExtension.js.map +1 -0
- package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js +41 -11
- package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js.map +1 -1
- package/build/esm/dev-plugin/__tests__/validateDevEnvironment.test.js +66 -0
- package/build/esm/dev-plugin/__tests__/validateDevEnvironment.test.js.map +1 -0
- package/build/esm/dev-plugin/publishDevModeSettings.js +19 -3
- package/build/esm/dev-plugin/publishDevModeSettings.js.map +1 -1
- package/build/esm/dev-plugin/validateDevEnvironment.js +33 -0
- package/build/esm/dev-plugin/validateDevEnvironment.js.map +1 -0
- package/build/site/assets/{allPaths-C9RDB26n.js → allPaths-DAStXfot.js} +1 -1
- package/build/site/assets/{allPathsLoader-DXy-gD-r.js → allPathsLoader-Xesz75gG.js} +2 -2
- package/build/site/assets/{index-D9t4xczX.js → index-C5U_5Xge.js} +10 -10
- package/build/site/assets/{index-CxjWve_y.css → index-DjCw4U9Z.css} +1 -1
- package/build/site/assets/{splitPathsBySizeLoader-CEcIKoAH.js → splitPathsBySizeLoader-DLaQMX-t.js} +1 -1
- package/build/site/index.html +2 -2
- package/build/types/build-plugin/__tests__/validateWidgetSet.test.d.ts +1 -0
- package/build/types/build-plugin/__tests__/validateWidgetSet.test.d.ts.map +1 -0
- package/build/types/build-plugin/buildWidgetSetManifest.d.ts.map +1 -1
- package/build/types/build-plugin/validateWidgetSet.d.ts +2 -0
- package/build/types/build-plugin/validateWidgetSet.d.ts.map +1 -0
- package/build/types/client/app.d.ts.map +1 -1
- package/build/types/common/__tests__/standardizePathAndFileExtension.test.d.ts +1 -0
- package/build/types/common/__tests__/standardizePathAndFileExtension.test.d.ts.map +1 -0
- package/build/types/common/standardizePathAndFileExtension.d.ts +9 -0
- package/build/types/common/standardizePathAndFileExtension.d.ts.map +1 -0
- package/build/types/dev-plugin/FoundryWidgetDevPlugin.d.ts.map +1 -1
- package/build/types/dev-plugin/__tests__/validateDevEnvironment.test.d.ts +1 -0
- package/build/types/dev-plugin/__tests__/validateDevEnvironment.test.d.ts.map +1 -0
- package/build/types/dev-plugin/publishDevModeSettings.d.ts.map +1 -1
- package/build/types/dev-plugin/validateDevEnvironment.d.ts +2 -0
- package/build/types/dev-plugin/validateDevEnvironment.d.ts.map +1 -0
- package/package.json +4 -4
- package/build/esm/common/standardizeFileExtension.js.map +0 -1
- package/build/types/common/standardizeFileExtension.d.ts +0 -6
- package/build/types/common/standardizeFileExtension.d.ts.map +0 -1
|
@@ -20,12 +20,14 @@ import color from "picocolors";
|
|
|
20
20
|
import sirv from "sirv";
|
|
21
21
|
import { CONFIG_FILE_SUFFIX, DEV_PLUGIN_ID, ENTRYPOINTS_PATH, FINISH_PATH, MODULE_EVALUATION_MODE, SETUP_PATH, VITE_INJECTIONS_PATH } from "../common/constants.js";
|
|
22
22
|
import { getInputHtmlEntrypoints } from "../common/getInputHtmlEntrypoints.js";
|
|
23
|
-
import {
|
|
23
|
+
import { standardizePathAndFileExtension } from "../common/standardizePathAndFileExtension.js";
|
|
24
|
+
import { isCodeWorkspacesMode } from "./codeWorkspacesMode.js";
|
|
24
25
|
import { extractInjectedScripts } from "./extractInjectedScripts.js";
|
|
25
26
|
import { getBaseHref } from "./getBaseHref.js";
|
|
26
27
|
import { getFoundryToken } from "./getFoundryToken.js";
|
|
27
28
|
import { getWidgetIdOverrideMap } from "./getWidgetIdOverrideMap.js";
|
|
28
29
|
import { publishDevModeSettings } from "./publishDevModeSettings.js";
|
|
30
|
+
import { warnIfWrongDevCommand } from "./validateDevEnvironment.js";
|
|
29
31
|
|
|
30
32
|
// Location of the setup page assets
|
|
31
33
|
const DIR_DIST = typeof __dirname !== "undefined" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -58,7 +60,8 @@ export function FoundryWidgetDevPlugin() {
|
|
|
58
60
|
/**
|
|
59
61
|
* Check for the required token environment variable in dev mode.
|
|
60
62
|
*/
|
|
61
|
-
|
|
63
|
+
configResolved(resolvedConfig) {
|
|
64
|
+
warnIfWrongDevCommand(resolvedConfig.mode, resolvedConfig.logger);
|
|
62
65
|
getFoundryToken(resolvedConfig.mode);
|
|
63
66
|
},
|
|
64
67
|
/**
|
|
@@ -105,11 +108,30 @@ export function FoundryWidgetDevPlugin() {
|
|
|
105
108
|
/**
|
|
106
109
|
* Finish the setup process by setting the widget overrides in Foundry and enabling dev mode.
|
|
107
110
|
*/
|
|
108
|
-
server.middlewares.use(serverPath(server, FINISH_PATH), async (
|
|
111
|
+
server.middlewares.use(serverPath(server, FINISH_PATH), async (req, res) => {
|
|
112
|
+
// Check for too many attempts
|
|
113
|
+
if (req.url == null) {
|
|
114
|
+
throw new Error("Request URL is undefined");
|
|
115
|
+
}
|
|
116
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
117
|
+
const numAttempts = parseInt(url.searchParams.get("attempt") ?? "0");
|
|
118
|
+
if (numAttempts >= 10) {
|
|
119
|
+
const errorMessage = "Timed out waiting for widget config files to be parsed. Are you sure a widget config is imported?";
|
|
120
|
+
server.config.logger.error(errorMessage);
|
|
121
|
+
res.setHeader("Content-Type", "application/json");
|
|
122
|
+
res.statusCode = 500;
|
|
123
|
+
res.end(JSON.stringify({
|
|
124
|
+
status: "error",
|
|
125
|
+
error: errorMessage
|
|
126
|
+
}));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
109
130
|
// Wait for the setup page to trigger the parsing of the config files
|
|
110
131
|
const numEntrypoints = htmlEntrypoints.length;
|
|
111
132
|
const numConfigFiles = Object.keys(configFileToEntrypoint).length;
|
|
112
133
|
if (numConfigFiles < numEntrypoints) {
|
|
134
|
+
server.config.logger.info(`Waiting for widget config files to be parsed, found ${numConfigFiles} config files out of` + ` ${numEntrypoints} HTML entrypoints.`);
|
|
113
135
|
res.setHeader("Content-Type", "application/json");
|
|
114
136
|
res.end(JSON.stringify({
|
|
115
137
|
status: "pending"
|
|
@@ -144,23 +166,27 @@ export function FoundryWidgetDevPlugin() {
|
|
|
144
166
|
}
|
|
145
167
|
|
|
146
168
|
// Standardize the source file extension and get the full path
|
|
147
|
-
const standardizedSource =
|
|
169
|
+
const standardizedSource = standardizePathAndFileExtension(getFullSourcePath(
|
|
148
170
|
// If the source path is absolute, resolve it against the current working directory
|
|
149
171
|
source.startsWith("/") ? path.join(process.cwd(), source) : source, importer));
|
|
150
172
|
// Importers are already full paths, so just standardize the extension
|
|
151
|
-
|
|
152
|
-
const standardizedImporter = standardizeFileExtension(path.normalize(importer));
|
|
173
|
+
const standardizedImporter = standardizePathAndFileExtension(importer);
|
|
153
174
|
|
|
154
175
|
// In dev mode all entrypoints have a generic HTML importer value
|
|
155
|
-
if (importer.endsWith("index.html") && !standardizedSource.includes("@fs")
|
|
176
|
+
if (importer.endsWith("index.html") && !standardizedSource.includes("@fs")
|
|
177
|
+
// In a cold start, Vite may try to resolve files (e.g. a widget.html) before the user even accesses the dev mode server.
|
|
178
|
+
// These files are not valid code entrypoints, so we ignore them here.
|
|
179
|
+
&& path.extname(standardizedSource) !== ".html") {
|
|
156
180
|
// Store the fully resolved path and the relative path, as we need the former for mapping
|
|
157
181
|
// config files to entrypoints and the latter as a dev mode override script
|
|
158
182
|
codeEntrypoints[standardizedSource] = source;
|
|
159
183
|
}
|
|
160
184
|
|
|
161
185
|
// Look for config files that are imported from an entrypoint file
|
|
162
|
-
|
|
163
|
-
|
|
186
|
+
// Also check the config file being imported is in src to avoid picking up imports for other
|
|
187
|
+
// project files like foundry.config.json / eslint.config.mjs when tailwind is used.
|
|
188
|
+
if (standardizedSource.replace(/\.[^/.]+$/, "").endsWith(CONFIG_FILE_SUFFIX) && standardizedSource.includes("/src/") && codeEntrypoints[standardizedImporter] != null) {
|
|
189
|
+
const fullSourcePath = standardizePathAndFileExtension(getFullSourcePath(source, standardizedImporter));
|
|
164
190
|
configFileToEntrypoint[fullSourcePath] = standardizedImporter;
|
|
165
191
|
}
|
|
166
192
|
}
|
|
@@ -178,7 +204,11 @@ function serverPath(server, subPath) {
|
|
|
178
204
|
return path.posix.resolve(server.config.base, subPath);
|
|
179
205
|
}
|
|
180
206
|
function printSetupPageUrl(server) {
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
if (isCodeWorkspacesMode(server.config.mode)) {
|
|
208
|
+
server.config.logger.info(` ${color.green("➜")} ${color.bold("Select a widget from the preview panel to enter developer mode")}`);
|
|
209
|
+
} else {
|
|
210
|
+
const setupRoute = `${getBaseHref(server)}${SETUP_PATH}/`;
|
|
211
|
+
server.config.logger.info(` ${color.green("➜")} ${color.bold("Click to enter developer mode for your widget set")}: ${color.green(setupRoute)}`);
|
|
212
|
+
}
|
|
183
213
|
}
|
|
184
214
|
//# sourceMappingURL=FoundryWidgetDevPlugin.js.map
|
|
@@ -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","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;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B,EAAE4C,OAAe,EAAU;EAClE;EACA,OAAOrF,IAAI,CAACsF,KAAK,CAAC/B,OAAO,CAACd,MAAM,CAACV,MAAM,CAACwD,IAAI,EAAEF,OAAO,CAAC;AACxD;AAEA,SAAS1C,iBAAiBA,CAACF,MAAqB,EAAE;EAChD,MAAM+C,UAAU,GAAG,GAAG1E,WAAW,CAAC2B,MAAM,CAAC,GAAGhC,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":[]}
|
|
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","standardizePathAndFileExtension","isCodeWorkspacesMode","extractInjectedScripts","getBaseHref","getFoundryToken","getWidgetIdOverrideMap","publishDevModeSettings","warnIfWrongDevCommand","DIR_DIST","__dirname","dirname","import","meta","url","FoundryWidgetDevPlugin","htmlEntrypoints","codeEntrypoints","configFileToEntrypoint","name","enforce","apply","config","command","mode","process","env","VITEST","buildStart","options","configResolved","resolvedConfig","logger","configureServer","server","printUrls","printSetupPageUrl","middlewares","use","serverPath","req","res","next","originalUrl","endsWith","statusCode","setHeader","end","resolve","single","dev","_","JSON","stringify","map","entrypoint","Error","URL","headers","host","numAttempts","parseInt","searchParams","get","errorMessage","error","status","numEntrypoints","length","numConfigFiles","Object","keys","info","widgetIdToOverrides","injectedScripts","inlineScripts","join","resolveId","source","importer","standardizedSource","getFullSourcePath","startsWith","cwd","standardizedImporter","includes","extname","replace","fullSourcePath","subPath","posix","base","green","bold","setupRoute"],"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 { standardizePathAndFileExtension } from \"../common/standardizePathAndFileExtension.js\";\nimport { isCodeWorkspacesMode } from \"./codeWorkspacesMode.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\";\nimport { warnIfWrongDevCommand } from \"./validateDevEnvironment.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 configResolved(resolvedConfig) {\n warnIfWrongDevCommand(resolvedConfig.mode, resolvedConfig.logger);\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 (req, res) => {\n // Check for too many attempts\n if (req.url == null) {\n throw new Error(\"Request URL is undefined\");\n }\n const url = new URL(req.url, `http://${req.headers.host}`);\n const numAttempts = parseInt(url.searchParams.get(\"attempt\") ?? \"0\");\n if (numAttempts >= 10) {\n const errorMessage =\n \"Timed out waiting for widget config files to be parsed. Are you sure a widget config is imported?\";\n server.config.logger.error(errorMessage);\n res.setHeader(\"Content-Type\", \"application/json\");\n res.statusCode = 500;\n res.end(\n JSON.stringify({\n status: \"error\",\n error: errorMessage,\n }),\n );\n return;\n }\n\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 server.config.logger.info(\n `Waiting for widget config files to be parsed, found ${numConfigFiles} config files out of`\n + ` ${numEntrypoints} HTML entrypoints.`,\n );\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 = standardizePathAndFileExtension(\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 const standardizedImporter = standardizePathAndFileExtension(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 // In a cold start, Vite may try to resolve files (e.g. a widget.html) before the user even accesses the dev mode server.\n // These files are not valid code entrypoints, so we ignore them here.\n && path.extname(standardizedSource) !== \".html\"\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 // Also check the config file being imported is in src to avoid picking up imports for other\n // project files like foundry.config.json / eslint.config.mjs when tailwind is used.\n if (\n standardizedSource.replace(/\\.[^/.]+$/, \"\").endsWith(CONFIG_FILE_SUFFIX)\n && standardizedSource.includes(\"/src/\")\n && codeEntrypoints[standardizedImporter] != null\n ) {\n const fullSourcePath = standardizePathAndFileExtension(\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 if (isCodeWorkspacesMode(server.config.mode)) {\n server.config.logger.info(\n ` ${color.green(\"➜\")} ${\n color.bold(\n \"Select a widget from the preview panel to enter developer mode\",\n )\n }`,\n );\n } else {\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}\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,+BAA+B,QAAQ,8CAA8C;AAC9F,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,qBAAqB,QAAQ,6BAA6B;;AAEnE;AACA,MAAMC,QAAgB,GAAG,OAAOC,SAAS,KAAK,WAAW,GACrDA,SAAS,GACTrB,IAAI,CAACsB,OAAO,CAACrB,aAAa,CAACsB,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAEhD,OAAO,SAASC,sBAAsBA,CAAA,EAAW;EAC/C;EACA,IAAIC,eAAyB;EAC7B;EACA,MAAMC,eAAuC,GAAG,CAAC,CAAC;EAClD;EACA,MAAMC,sBAA8C,GAAG,CAAC,CAAC;EAEzD,OAAO;IACLC,IAAI,EAAEzB,aAAa;IACnB0B,OAAO,EAAE,KAAK;IACd;IACAC,KAAKA,CAACC,MAAM,EAAE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AO,CAACoE,QAAQ,CAAC,EAAED,MAAM,CAAC;AACrD;AAEA,SAASvC,UAAUA,CAACL,MAAqB,EAAEuD,OAAe,EAAU;EAClE;EACA,OAAOpG,IAAI,CAACqG,KAAK,CAAC1C,OAAO,CAACd,MAAM,CAACZ,MAAM,CAACqE,IAAI,EAAEF,OAAO,CAAC;AACxD;AAEA,SAASrD,iBAAiBA,CAACF,MAAqB,EAAE;EAChD,IAAIhC,oBAAoB,CAACgC,MAAM,CAACZ,MAAM,CAACE,IAAI,CAAC,EAAE;IAC5CU,MAAM,CAACZ,MAAM,CAACU,MAAM,CAACwC,IAAI,CACvB,KAAKjF,KAAK,CAACqG,KAAK,CAAC,GAAG,CAAC,KACnBrG,KAAK,CAACsG,IAAI,CACR,gEACF,CAAC,EAEL,CAAC;EACH,CAAC,MAAM;IACL,MAAMC,UAAU,GAAG,GAAG1F,WAAW,CAAC8B,MAAM,CAAC,GAAGpC,UAAU,GAAG;IACzDoC,MAAM,CAACZ,MAAM,CAACU,MAAM,CAACwC,IAAI,CACvB,KAAKjF,KAAK,CAACqG,KAAK,CAAC,GAAG,CAAC,KACnBrG,KAAK,CAACsG,IAAI,CAAC,mDAAmD,CAAC,KAC5DtG,KAAK,CAACqG,KAAK,CAACE,UAAU,CAAC,EAC9B,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
18
|
+
import * as validateDevEnvironment from "../validateDevEnvironment.js";
|
|
19
|
+
function createMockLogger() {
|
|
20
|
+
return {
|
|
21
|
+
info: vi.fn(),
|
|
22
|
+
warn: vi.fn(),
|
|
23
|
+
warnOnce: vi.fn(),
|
|
24
|
+
error: vi.fn(),
|
|
25
|
+
clearScreen: vi.fn(),
|
|
26
|
+
hasErrorLogged: vi.fn(),
|
|
27
|
+
hasWarned: false
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
describe("validateDevEnvironment", () => {
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
vi.restoreAllMocks();
|
|
33
|
+
});
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
vi.unstubAllEnvs();
|
|
36
|
+
});
|
|
37
|
+
describe("warnIfWrongDevCommand", () => {
|
|
38
|
+
test("warns when in Code Workspaces env but not using code-workspaces mode", () => {
|
|
39
|
+
vi.stubEnv("FOUNDRY_CONTAINER_RUNTIME_TYPE", "CODE_WORKSPACE");
|
|
40
|
+
const mockLogger = createMockLogger();
|
|
41
|
+
validateDevEnvironment.warnIfWrongDevCommand("development", mockLogger);
|
|
42
|
+
expect(mockLogger.warn).toHaveBeenCalledTimes(1);
|
|
43
|
+
expect(mockLogger.warn).toHaveBeenCalledWith(expect.stringContaining(`You should probably be using "npm run dev:remote" instead`));
|
|
44
|
+
});
|
|
45
|
+
test("warns when using code-workspaces mode but not in Code Workspaces env", () => {
|
|
46
|
+
vi.stubEnv("FOUNDRY_CONTAINER_RUNTIME_TYPE", undefined);
|
|
47
|
+
const mockLogger = createMockLogger();
|
|
48
|
+
validateDevEnvironment.warnIfWrongDevCommand("code-workspaces", mockLogger);
|
|
49
|
+
expect(mockLogger.warn).toHaveBeenCalledTimes(1);
|
|
50
|
+
expect(mockLogger.warn).toHaveBeenCalledWith(expect.stringContaining(`You should probably be using "npm run dev" instead`));
|
|
51
|
+
});
|
|
52
|
+
test("does not warn when in Code Workspaces env and using code-workspaces mode", () => {
|
|
53
|
+
vi.stubEnv("FOUNDRY_CONTAINER_RUNTIME_TYPE", "CODE_WORKSPACE");
|
|
54
|
+
const mockLogger = createMockLogger();
|
|
55
|
+
validateDevEnvironment.warnIfWrongDevCommand("code-workspaces", mockLogger);
|
|
56
|
+
expect(mockLogger.warn).not.toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
test("does not warn when not in Code Workspaces env and not using code-workspaces mode", () => {
|
|
59
|
+
vi.stubEnv("FOUNDRY_CONTAINER_RUNTIME_TYPE", undefined);
|
|
60
|
+
const mockLogger = createMockLogger();
|
|
61
|
+
validateDevEnvironment.warnIfWrongDevCommand("development", mockLogger);
|
|
62
|
+
expect(mockLogger.warn).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=validateDevEnvironment.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateDevEnvironment.test.js","names":["afterEach","beforeEach","describe","expect","test","vi","validateDevEnvironment","createMockLogger","info","fn","warn","warnOnce","error","clearScreen","hasErrorLogged","hasWarned","restoreAllMocks","unstubAllEnvs","stubEnv","mockLogger","warnIfWrongDevCommand","toHaveBeenCalledTimes","toHaveBeenCalledWith","stringContaining","undefined","not","toHaveBeenCalled"],"sources":["validateDevEnvironment.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 { Logger } from \"vite\";\nimport { afterEach, beforeEach, describe, expect, test, vi } from \"vitest\";\nimport * as validateDevEnvironment from \"../validateDevEnvironment.js\";\n\nfunction createMockLogger(): Logger {\n return {\n info: vi.fn(),\n warn: vi.fn(),\n warnOnce: vi.fn(),\n error: vi.fn(),\n clearScreen: vi.fn(),\n hasErrorLogged: vi.fn(),\n hasWarned: false,\n };\n}\n\ndescribe(\"validateDevEnvironment\", () => {\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n afterEach(() => {\n vi.unstubAllEnvs();\n });\n\n describe(\"warnIfWrongDevCommand\", () => {\n test(\"warns when in Code Workspaces env but not using code-workspaces mode\", () => {\n vi.stubEnv(\"FOUNDRY_CONTAINER_RUNTIME_TYPE\", \"CODE_WORKSPACE\");\n const mockLogger = createMockLogger();\n\n validateDevEnvironment.warnIfWrongDevCommand(\"development\", mockLogger);\n\n expect(mockLogger.warn).toHaveBeenCalledTimes(1);\n expect(mockLogger.warn).toHaveBeenCalledWith(\n expect.stringContaining(\n `You should probably be using \"npm run dev:remote\" instead`,\n ),\n );\n });\n\n test(\"warns when using code-workspaces mode but not in Code Workspaces env\", () => {\n vi.stubEnv(\"FOUNDRY_CONTAINER_RUNTIME_TYPE\", undefined);\n const mockLogger = createMockLogger();\n\n validateDevEnvironment.warnIfWrongDevCommand(\n \"code-workspaces\",\n mockLogger,\n );\n\n expect(mockLogger.warn).toHaveBeenCalledTimes(1);\n expect(mockLogger.warn).toHaveBeenCalledWith(\n expect.stringContaining(\n `You should probably be using \"npm run dev\" instead`,\n ),\n );\n });\n\n test(\"does not warn when in Code Workspaces env and using code-workspaces mode\", () => {\n vi.stubEnv(\"FOUNDRY_CONTAINER_RUNTIME_TYPE\", \"CODE_WORKSPACE\");\n const mockLogger = createMockLogger();\n\n validateDevEnvironment.warnIfWrongDevCommand(\n \"code-workspaces\",\n mockLogger,\n );\n\n expect(mockLogger.warn).not.toHaveBeenCalled();\n });\n\n test(\"does not warn when not in Code Workspaces env and not using code-workspaces mode\", () => {\n vi.stubEnv(\"FOUNDRY_CONTAINER_RUNTIME_TYPE\", undefined);\n const mockLogger = createMockLogger();\n\n validateDevEnvironment.warnIfWrongDevCommand(\"development\", mockLogger);\n\n expect(mockLogger.warn).not.toHaveBeenCalled();\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,QAAQ;AAC1E,OAAO,KAAKC,sBAAsB,MAAM,8BAA8B;AAEtE,SAASC,gBAAgBA,CAAA,EAAW;EAClC,OAAO;IACLC,IAAI,EAAEH,EAAE,CAACI,EAAE,CAAC,CAAC;IACbC,IAAI,EAAEL,EAAE,CAACI,EAAE,CAAC,CAAC;IACbE,QAAQ,EAAEN,EAAE,CAACI,EAAE,CAAC,CAAC;IACjBG,KAAK,EAAEP,EAAE,CAACI,EAAE,CAAC,CAAC;IACdI,WAAW,EAAER,EAAE,CAACI,EAAE,CAAC,CAAC;IACpBK,cAAc,EAAET,EAAE,CAACI,EAAE,CAAC,CAAC;IACvBM,SAAS,EAAE;EACb,CAAC;AACH;AAEAb,QAAQ,CAAC,wBAAwB,EAAE,MAAM;EACvCD,UAAU,CAAC,MAAM;IACfI,EAAE,CAACW,eAAe,CAAC,CAAC;EACtB,CAAC,CAAC;EAEFhB,SAAS,CAAC,MAAM;IACdK,EAAE,CAACY,aAAa,CAAC,CAAC;EACpB,CAAC,CAAC;EAEFf,QAAQ,CAAC,uBAAuB,EAAE,MAAM;IACtCE,IAAI,CAAC,sEAAsE,EAAE,MAAM;MACjFC,EAAE,CAACa,OAAO,CAAC,gCAAgC,EAAE,gBAAgB,CAAC;MAC9D,MAAMC,UAAU,GAAGZ,gBAAgB,CA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B,MAAM,CAACgB,UAAU,CAACT,IAAI,CAAC,CAACe,GAAG,CAACC,gBAAgB,CAAC,CAAC;IAChD,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -18,6 +18,21 @@ import { loadFoundryConfig } from "@osdk/foundry-config-json";
|
|
|
18
18
|
import { inspect } from "node:util";
|
|
19
19
|
import { getCodeWorkspacesFoundryUrl, isCodeWorkspacesMode } from "./codeWorkspacesMode.js";
|
|
20
20
|
import { enableDevMode, setWidgetSetSettings } from "./network.js";
|
|
21
|
+
class ResponseError extends Error {
|
|
22
|
+
// To avoid inspect() from logging the error response since it's already logged
|
|
23
|
+
#response;
|
|
24
|
+
constructor(message, response) {
|
|
25
|
+
super(message);
|
|
26
|
+
try {
|
|
27
|
+
this.#response = JSON.stringify(JSON.parse(response), null, 4);
|
|
28
|
+
} catch {
|
|
29
|
+
this.#response = response;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
get response() {
|
|
33
|
+
return this.#response;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
21
36
|
|
|
22
37
|
/**
|
|
23
38
|
* Finish the setup process by setting the widget overrides in Foundry and enabling dev mode.
|
|
@@ -35,14 +50,14 @@ export async function publishDevModeSettings(server, widgetIdToOverrides, baseHr
|
|
|
35
50
|
server.config.logger.warn(`Unable to set widget settings in Foundry: ${settingsResponse.statusText}`);
|
|
36
51
|
const responseContent = await settingsResponse.text();
|
|
37
52
|
server.config.logger.warn(responseContent);
|
|
38
|
-
throw new
|
|
53
|
+
throw new ResponseError(`Unable to set widget settings in Foundry: ${settingsResponse.statusText}`, responseContent);
|
|
39
54
|
}
|
|
40
55
|
const enableResponse = await enableDevMode(foundryUrl, server.config.mode);
|
|
41
56
|
if (enableResponse.status !== 200) {
|
|
42
57
|
server.config.logger.warn(`Unable to enable dev mode in Foundry: ${enableResponse.statusText}`);
|
|
43
58
|
const responseContent = await enableResponse.text();
|
|
44
59
|
server.config.logger.warn(responseContent);
|
|
45
|
-
throw new
|
|
60
|
+
throw new ResponseError(`Unable to enable dev mode in Foundry: ${enableResponse.statusText}`, responseContent);
|
|
46
61
|
}
|
|
47
62
|
res.setHeader("Content-Type", "application/json");
|
|
48
63
|
res.end(JSON.stringify({
|
|
@@ -56,7 +71,8 @@ export async function publishDevModeSettings(server, widgetIdToOverrides, baseHr
|
|
|
56
71
|
res.statusCode = 500;
|
|
57
72
|
res.end(JSON.stringify({
|
|
58
73
|
status: "error",
|
|
59
|
-
error: inspect(error)
|
|
74
|
+
error: inspect(error),
|
|
75
|
+
response: error instanceof ResponseError ? error.response : undefined
|
|
60
76
|
}));
|
|
61
77
|
}
|
|
62
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publishDevModeSettings.js","names":["loadFoundryConfig","inspect","getCodeWorkspacesFoundryUrl","isCodeWorkspacesMode","enableDevMode","setWidgetSetSettings","publishDevModeSettings","server","widgetIdToOverrides","baseHref","res","foundryConfig","
|
|
1
|
+
{"version":3,"file":"publishDevModeSettings.js","names":["loadFoundryConfig","inspect","getCodeWorkspacesFoundryUrl","isCodeWorkspacesMode","enableDevMode","setWidgetSetSettings","ResponseError","Error","response","constructor","message","JSON","stringify","parse","publishDevModeSettings","server","widgetIdToOverrides","baseHref","res","foundryConfig","foundryUrl","config","mode","widgetSetRid","widgetSet","rid","settingsResponse","status","logger","warn","statusText","responseContent","text","enableResponse","setHeader","end","redirectUrl","error","statusCode","undefined"],"sources":["publishDevModeSettings.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { loadFoundryConfig } from \"@osdk/foundry-config-json\";\nimport type { ServerResponse } from \"node:http\";\nimport { inspect } from \"node:util\";\nimport type { ViteDevServer } from \"vite\";\nimport {\n getCodeWorkspacesFoundryUrl,\n isCodeWorkspacesMode,\n} from \"./codeWorkspacesMode.js\";\nimport { enableDevMode, setWidgetSetSettings } from \"./network.js\";\n\nclass ResponseError extends Error {\n // To avoid inspect() from logging the error response since it's already logged\n #response: string;\n\n constructor(message: string, response: string) {\n super(message);\n try {\n this.#response = JSON.stringify(JSON.parse(response), null, 4);\n } catch {\n this.#response = response;\n }\n }\n\n get response(): string {\n return this.#response;\n }\n}\n\n/**\n * Finish the setup process by setting the widget overrides in Foundry and enabling dev mode.\n */\nexport async function publishDevModeSettings(\n server: ViteDevServer,\n widgetIdToOverrides: Record<string, string[]>,\n baseHref: string,\n res: ServerResponse,\n): Promise<void> {\n try {\n const foundryConfig = await loadFoundryConfig(\"widgetSet\");\n if (foundryConfig == null) {\n throw new Error(\n \"foundry.config.json file not found.\",\n );\n }\n const foundryUrl = isCodeWorkspacesMode(server.config.mode)\n ? getCodeWorkspacesFoundryUrl()\n : foundryConfig.foundryConfig.foundryUrl;\n\n const widgetSetRid = foundryConfig.foundryConfig.widgetSet.rid;\n const settingsResponse = await setWidgetSetSettings(\n foundryUrl,\n widgetSetRid,\n widgetIdToOverrides,\n baseHref,\n server.config.mode,\n );\n if (settingsResponse.status !== 200) {\n server.config.logger.warn(\n `Unable to set widget settings in Foundry: ${settingsResponse.statusText}`,\n );\n const responseContent = await settingsResponse.text();\n server.config.logger.warn(responseContent);\n throw new ResponseError(\n `Unable to set widget settings in Foundry: ${settingsResponse.statusText}`,\n responseContent,\n );\n }\n\n const enableResponse = await enableDevMode(\n foundryUrl,\n server.config.mode,\n );\n if (enableResponse.status !== 200) {\n server.config.logger.warn(\n `Unable to enable dev mode in Foundry: ${enableResponse.statusText}`,\n );\n const responseContent = await enableResponse.text();\n server.config.logger.warn(responseContent);\n throw new ResponseError(\n `Unable to enable dev mode in Foundry: ${enableResponse.statusText}`,\n responseContent,\n );\n }\n\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(JSON.stringify({\n status: \"success\",\n // In Code Workspaces the preview UI automatically handles this redirect\n redirectUrl: isCodeWorkspacesMode(server.config.mode)\n ? null\n : `${foundryUrl}/workspace/custom-widgets/preview/${widgetSetRid}`,\n }));\n } catch (error: unknown) {\n server.config.logger.error(\n `Failed to start dev mode: ${(error as Error)}\\n\\n${inspect(error)}`,\n );\n res.setHeader(\"Content-Type\", \"application/json\");\n res.statusCode = 500;\n res.end(\n JSON.stringify(\n {\n status: \"error\",\n error: inspect(error),\n response: error instanceof ResponseError ? error.response : undefined,\n },\n ),\n );\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,iBAAiB,QAAQ,2BAA2B;AAE7D,SAASC,OAAO,QAAQ,WAAW;AAEnC,SACEC,2BAA2B,EAC3BC,oBAAoB,QACf,yBAAyB;AAChC,SAASC,aAAa,EAAEC,oBAAoB,QAAQ,cAAc;AAElE,MAAMC,aAAa,SAASC,KAAK,CAAC;EAChC;EACA,CAACC,QAAQ;EAETC,WAAWA,CAACC,OAAe,EAAEF,QAAgB,EAAE;IAC7C,KAAK,CAACE,OAAO,CAAC;IACd,IAAI;MACF,IAAI,CAAC,CAACF,QAAQ,GAAGG,IAAI,CAACC,SAAS,CAACD,IAAI,CAACE,KAAK,CAACL,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC,MAAM;MACN,IAAI,CAAC,CAACA,QAAQ,GAAGA,QAAQ;IAC3B;EACF;EAEA,IAAIA,QAAQA,CAAA,EAAW;IACrB,OAAO,IAAI,CAAC,CAACA,QAAQ;EACvB;AACF;;AAEA;AACA;AACA;AACA,OAAO,eAAeM,sBAAsBA,CAC1CC,MAAq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CAAC,CAAC;MACnDjB,MAAM,CAACM,MAAM,CAACO,MAAM,CAACC,IAAI,CAACE,eAAe,CAAC;MAC1C,MAAM,IAAIzB,aAAa,CACrB,yCAAyC2B,cAAc,CAACH,UAAU,EAAE,EACpEC,eACF,CAAC;IACH;IAEAb,GAAG,CAACgB,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC;IACjDhB,GAAG,CAACiB,GAAG,CAACxB,IAAI,CAACC,SAAS,CAAC;MACrBe,MAAM,EAAE,SAAS;MACjB;MACAS,WAAW,EAAEjC,oBAAoB,CAACY,MAAM,CAACM,MAAM,CAACC,IAAI,CAAC,GACjD,IAAI,GACJ,GAAGF,UAAU,qCAAqCG,YAAY;IACpE,CAAC,CAAC,CAAC;EACL,CAAC,CAAC,OAAOc,KAAc,EAAE;IACvBtB,MAAM,CAACM,MAAM,CAACO,MAAM,CAACS,KAAK,CACxB,6BAA8BA,KAAK,OAAiBpC,OAAO,CAACoC,KAAK,CAAC,EACpE,CAAC;IACDnB,GAAG,CAACgB,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC;IACjDhB,GAAG,CAACoB,UAAU,GAAG,GAAG;IACpBpB,GAAG,CAACiB,GAAG,CACLxB,IAAI,CAACC,SAAS,CACZ;MACEe,MAAM,EAAE,OAAO;MACfU,KAAK,EAAEpC,OAAO,CAACoC,KAAK,CAAC;MACrB7B,QAAQ,EAAE6B,KAAK,YAAY/B,aAAa,GAAG+B,KAAK,CAAC7B,QAAQ,GAAG+B;IAC9D,CACF,CACF,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 color from "picocolors";
|
|
18
|
+
import { isCodeWorkspacesMode } from "./codeWorkspacesMode.js";
|
|
19
|
+
const FOUNDRY_CONTAINER_RUNTIME_TYPE = "FOUNDRY_CONTAINER_RUNTIME_TYPE";
|
|
20
|
+
const CODE_WORKSPACE_RUNTIME = "CODE_WORKSPACE";
|
|
21
|
+
export function warnIfWrongDevCommand(mode, logger) {
|
|
22
|
+
const isInCodeWorkspacesEnv = isCodeWorkspacesEnvironment();
|
|
23
|
+
const isUsingCodeWorkspacesMode = isCodeWorkspacesMode(mode);
|
|
24
|
+
if (isInCodeWorkspacesEnv && !isUsingCodeWorkspacesMode) {
|
|
25
|
+
logger.warn(color.yellow(`\n⚠️ You appear to be running in a Code Workspaces environment but are using "npm run dev".\n` + ` You should probably be using "npm run dev:remote" instead.\n`));
|
|
26
|
+
} else if (!isInCodeWorkspacesEnv && isUsingCodeWorkspacesMode) {
|
|
27
|
+
logger.warn(color.yellow(`\n⚠️ You are using "npm run dev:remote" but do not appear to be in a Code Workspaces environment.\n` + ` You should probably be using "npm run dev" instead.\n`));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function isCodeWorkspacesEnvironment() {
|
|
31
|
+
return process.env[FOUNDRY_CONTAINER_RUNTIME_TYPE] === CODE_WORKSPACE_RUNTIME;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=validateDevEnvironment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateDevEnvironment.js","names":["color","isCodeWorkspacesMode","FOUNDRY_CONTAINER_RUNTIME_TYPE","CODE_WORKSPACE_RUNTIME","warnIfWrongDevCommand","mode","logger","isInCodeWorkspacesEnv","isCodeWorkspacesEnvironment","isUsingCodeWorkspacesMode","warn","yellow","process","env"],"sources":["validateDevEnvironment.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 color from \"picocolors\";\nimport type { Logger } from \"vite\";\nimport { isCodeWorkspacesMode } from \"./codeWorkspacesMode.js\";\n\nconst FOUNDRY_CONTAINER_RUNTIME_TYPE = \"FOUNDRY_CONTAINER_RUNTIME_TYPE\";\nconst CODE_WORKSPACE_RUNTIME = \"CODE_WORKSPACE\";\n\nexport function warnIfWrongDevCommand(\n mode: string | undefined,\n logger: Logger,\n): void {\n const isInCodeWorkspacesEnv = isCodeWorkspacesEnvironment();\n const isUsingCodeWorkspacesMode = isCodeWorkspacesMode(mode);\n\n if (isInCodeWorkspacesEnv && !isUsingCodeWorkspacesMode) {\n logger.warn(\n color.yellow(\n `\\n⚠️ You appear to be running in a Code Workspaces environment but are using \"npm run dev\".\\n`\n + ` You should probably be using \"npm run dev:remote\" instead.\\n`,\n ),\n );\n } else if (!isInCodeWorkspacesEnv && isUsingCodeWorkspacesMode) {\n logger.warn(\n color.yellow(\n `\\n⚠️ You are using \"npm run dev:remote\" but do not appear to be in a Code Workspaces environment.\\n`\n + ` You should probably be using \"npm run dev\" instead.\\n`,\n ),\n );\n }\n}\n\nfunction isCodeWorkspacesEnvironment(): boolean {\n return process.env[FOUNDRY_CONTAINER_RUNTIME_TYPE] === CODE_WORKSPACE_RUNTIME;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,MAAM,YAAY;AAE9B,SAASC,oBAAoB,QAAQ,yBAAyB;AAE9D,MAAMC,8BAA8B,GAAG,gCAAgC;AACvE,MAAMC,sBAAsB,GAAG,gBAAgB;AAE/C,OAAO,SAASC,qBAAqBA,CACnCC,IAAwB,EACxBC,MAAc,EACR;EACN,MAAMC,qBAAqB,GAAGC,2BAA2B,CAAC,CAAC;EAC3D,MAAMC,yBAAyB,GAAGR,oBAAoB,CAACI,IAAI,CAAC;EAE5D,IAAIE,qBAAqB,IAAI,CAACE,yBAAyB,EAAE;IACvDH,MAAM,CAACI,IAAI,CACTV,KAAK,CAACW,MAAM,CACV,gGAAgG,GAC5F,iEACN,CACF,CAAC;EACH,CAAC,MAAM,IAAI,CAACJ,qBAAqB,IAAIE,yBAAyB,EAAE;IAC9DH,MAAM,CAACI,IAAI,CACTV,KAAK,CAACW,MAAM,CACV,sGAAsG,GAClG,0DACN,CACF,CAAC;EACH;AACF;AAEA,SAASH,2BAA2BA,CAAA,EAAY;EAC9C,OAAOI,OAAO,CAACC,GAAG,CAACX,8BAA8B,CAAC,KAAKC,sBAAsB;AAC/E","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
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-
|
|
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-C5U_5Xge.js";function I(o,t){var a=r(o);return t===s.STANDARD?n[a]:e[a]}function p(o){return r(o)}export{n as IconSvgPaths16,e as IconSvgPaths20,I as getIconPaths,p as iconNameToPathsRecordKey};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./allPaths-
|
|
2
|
-
import{_ as o,a as i,b as n}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./allPaths-DAStXfot.js","./index-DLOviMB1.js","./index-B-fsa5Ru.js","./index-C5U_5Xge.js","./index-DjCw4U9Z.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as o,a as i,b as n}from"./index-C5U_5Xge.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-DAStXfot.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};
|