@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.
- package/CHANGELOG.md +342 -0
- package/README.md +175 -0
- package/build/esm/build-plugin/FoundryWidgetBuildPlugin.js +93 -0
- package/build/esm/build-plugin/FoundryWidgetBuildPlugin.js.map +1 -0
- package/build/esm/build-plugin/__tests__/extractBuildOutputs.test.js +133 -0
- package/build/esm/build-plugin/__tests__/extractBuildOutputs.test.js.map +1 -0
- package/build/esm/build-plugin/__tests__/getWidgetBuildOutputs.test.js +148 -0
- package/build/esm/build-plugin/__tests__/getWidgetBuildOutputs.test.js.map +1 -0
- package/build/esm/build-plugin/buildWidgetSetManifest.js +48 -0
- package/build/esm/build-plugin/buildWidgetSetManifest.js.map +1 -0
- package/build/esm/build-plugin/extractBuildOutputs.js +107 -0
- package/build/esm/build-plugin/extractBuildOutputs.js.map +1 -0
- package/build/esm/build-plugin/getWidgetBuildOutputs.js +50 -0
- package/build/esm/build-plugin/getWidgetBuildOutputs.js.map +1 -0
- package/build/esm/build-plugin/isConfigFile.js +22 -0
- package/build/esm/build-plugin/isConfigFile.js.map +1 -0
- package/build/esm/client/app.js +97 -0
- package/build/esm/client/app.js.map +1 -0
- package/build/esm/client/main.js +23 -0
- package/build/esm/client/main.js.map +1 -0
- package/build/esm/common/__tests__/getInputHtmlEntrypoints.test.js +38 -0
- package/build/esm/common/__tests__/getInputHtmlEntrypoints.test.js.map +1 -0
- package/build/esm/common/constants.js +23 -0
- package/build/esm/common/constants.js.map +1 -0
- package/build/esm/common/extractWidgetConfig.js +69 -0
- package/build/esm/common/extractWidgetConfig.js.map +1 -0
- package/build/esm/common/getInputHtmlEntrypoints.js +29 -0
- package/build/esm/common/getInputHtmlEntrypoints.js.map +1 -0
- package/build/esm/common/safeGetEnvVar.js +24 -0
- package/build/esm/common/safeGetEnvVar.js.map +1 -0
- package/build/esm/common/standardizeFileExtension.js +25 -0
- package/build/esm/common/standardizeFileExtension.js.map +1 -0
- package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js +193 -0
- package/build/esm/dev-plugin/FoundryWidgetDevPlugin.js.map +1 -0
- package/build/esm/dev-plugin/__tests__/codeWorkspacesMode.test.js +87 -0
- package/build/esm/dev-plugin/__tests__/codeWorkspacesMode.test.js.map +1 -0
- package/build/esm/dev-plugin/__tests__/extractInjectedScripts.test.js +34 -0
- package/build/esm/dev-plugin/__tests__/extractInjectedScripts.test.js.map +1 -0
- package/build/esm/dev-plugin/__tests__/getBaseHref.test.js +48 -0
- package/build/esm/dev-plugin/__tests__/getBaseHref.test.js.map +1 -0
- package/build/esm/dev-plugin/__tests__/getWidgetIdOverrideMap.test.js +62 -0
- package/build/esm/dev-plugin/__tests__/getWidgetIdOverrideMap.test.js.map +1 -0
- package/build/esm/dev-plugin/codeWorkspacesMode.js +50 -0
- package/build/esm/dev-plugin/codeWorkspacesMode.js.map +1 -0
- package/build/esm/dev-plugin/extractInjectedScripts.js +62 -0
- package/build/esm/dev-plugin/extractInjectedScripts.js.map +1 -0
- package/build/esm/dev-plugin/getBaseHref.js +26 -0
- package/build/esm/dev-plugin/getBaseHref.js.map +1 -0
- package/build/esm/dev-plugin/getFoundryToken.js +28 -0
- package/build/esm/dev-plugin/getFoundryToken.js.map +1 -0
- package/build/esm/dev-plugin/getWidgetIdOverrideMap.js +39 -0
- package/build/esm/dev-plugin/getWidgetIdOverrideMap.js.map +1 -0
- package/build/esm/dev-plugin/network.js +51 -0
- package/build/esm/dev-plugin/network.js.map +1 -0
- package/build/esm/dev-plugin/publishDevModeSettings.js +63 -0
- package/build/esm/dev-plugin/publishDevModeSettings.js.map +1 -0
- package/build/esm/index.js +22 -0
- package/build/esm/index.js.map +1 -0
- package/build/site/assets/allPaths-CoV91acR.js +1 -0
- package/build/site/assets/allPathsLoader-abVMVrnV.js +2 -0
- package/build/site/assets/index-62l0mIXD.css +1 -0
- package/build/site/assets/index-BrAe7gTM.js +1 -0
- package/build/site/assets/index-DLUL2ZpM.js +44 -0
- package/build/site/assets/index-Zx5rUdU4.js +1 -0
- package/build/site/assets/splitPathsBySizeLoader--OyNgZuW.js +1 -0
- package/build/site/index.html +15 -0
- package/build/types/build-plugin/FoundryWidgetBuildPlugin.d.ts +2 -0
- package/build/types/build-plugin/FoundryWidgetBuildPlugin.d.ts.map +1 -0
- package/build/types/build-plugin/__tests__/extractBuildOutputs.test.d.ts +1 -0
- package/build/types/build-plugin/__tests__/extractBuildOutputs.test.d.ts.map +1 -0
- package/build/types/build-plugin/__tests__/getWidgetBuildOutputs.test.d.ts +1 -0
- package/build/types/build-plugin/__tests__/getWidgetBuildOutputs.test.d.ts.map +1 -0
- package/build/types/build-plugin/buildWidgetSetManifest.d.ts +3 -0
- package/build/types/build-plugin/buildWidgetSetManifest.d.ts.map +1 -0
- package/build/types/build-plugin/extractBuildOutputs.d.ts +12 -0
- package/build/types/build-plugin/extractBuildOutputs.d.ts.map +1 -0
- package/build/types/build-plugin/getWidgetBuildOutputs.d.ts +7 -0
- package/build/types/build-plugin/getWidgetBuildOutputs.d.ts.map +1 -0
- package/build/types/build-plugin/isConfigFile.d.ts +1 -0
- package/build/types/build-plugin/isConfigFile.d.ts.map +1 -0
- package/build/types/client/app.d.ts +2 -0
- package/build/types/client/app.d.ts.map +1 -0
- package/build/types/client/main.d.ts +3 -0
- package/build/types/client/main.d.ts.map +1 -0
- package/build/types/common/__tests__/getInputHtmlEntrypoints.test.d.ts +1 -0
- package/build/types/common/__tests__/getInputHtmlEntrypoints.test.d.ts.map +1 -0
- package/build/types/common/constants.d.ts +6 -0
- package/build/types/common/constants.d.ts.map +1 -0
- package/build/types/common/extractWidgetConfig.d.ts +3 -0
- package/build/types/common/extractWidgetConfig.d.ts.map +1 -0
- package/build/types/common/getInputHtmlEntrypoints.d.ts +5 -0
- package/build/types/common/getInputHtmlEntrypoints.d.ts.map +1 -0
- package/build/types/common/safeGetEnvVar.d.ts +1 -0
- package/build/types/common/safeGetEnvVar.d.ts.map +1 -0
- package/build/types/common/standardizeFileExtension.d.ts +6 -0
- package/build/types/common/standardizeFileExtension.d.ts.map +1 -0
- package/build/types/dev-plugin/FoundryWidgetDevPlugin.d.ts +2 -0
- package/build/types/dev-plugin/FoundryWidgetDevPlugin.d.ts.map +1 -0
- package/build/types/dev-plugin/__tests__/codeWorkspacesMode.test.d.ts +1 -0
- package/build/types/dev-plugin/__tests__/codeWorkspacesMode.test.d.ts.map +1 -0
- package/build/types/dev-plugin/__tests__/extractInjectedScripts.test.d.ts +1 -0
- package/build/types/dev-plugin/__tests__/extractInjectedScripts.test.d.ts.map +1 -0
- package/build/types/dev-plugin/__tests__/getBaseHref.test.d.ts +1 -0
- package/build/types/dev-plugin/__tests__/getBaseHref.test.d.ts.map +1 -0
- package/build/types/dev-plugin/__tests__/getWidgetIdOverrideMap.test.d.ts +1 -0
- package/build/types/dev-plugin/__tests__/getWidgetIdOverrideMap.test.d.ts.map +1 -0
- package/build/types/dev-plugin/codeWorkspacesMode.d.ts +8 -0
- package/build/types/dev-plugin/codeWorkspacesMode.d.ts.map +1 -0
- package/build/types/dev-plugin/extractInjectedScripts.d.ts +16 -0
- package/build/types/dev-plugin/extractInjectedScripts.d.ts.map +1 -0
- package/build/types/dev-plugin/getBaseHref.d.ts +2 -0
- package/build/types/dev-plugin/getBaseHref.d.ts.map +1 -0
- package/build/types/dev-plugin/getFoundryToken.d.ts +1 -0
- package/build/types/dev-plugin/getFoundryToken.d.ts.map +1 -0
- package/build/types/dev-plugin/getWidgetIdOverrideMap.d.ts +3 -0
- package/build/types/dev-plugin/getWidgetIdOverrideMap.d.ts.map +1 -0
- package/build/types/dev-plugin/network.d.ts +2 -0
- package/build/types/dev-plugin/network.d.ts.map +1 -0
- package/build/types/dev-plugin/publishDevModeSettings.d.ts +6 -0
- package/build/types/dev-plugin/publishDevModeSettings.d.ts.map +1 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FoundryWidgetDevPlugin.js","names":["path","fileURLToPath","color","sirv","CONFIG_FILE_SUFFIX","ENTRYPOINTS_PATH","FINISH_PATH","SETUP_PATH","VITE_INJECTIONS_PATH","extractWidgetConfig","getInputHtmlEntrypoints","standardizeFileExtension","extractInjectedScripts","getBaseHref","getFoundryToken","getWidgetIdOverrideMap","publishDevModeSettings","DIR_DIST","__dirname","dirname","import","meta","url","FoundryWidgetDevPlugin","htmlEntrypoints","codeEntrypoints","configFileToEntrypoint","configFiles","name","enforce","buildStart","options","config","resolvedConfig","command","process","env","VITEST","mode","configureServer","server","printUrls","printSetupPageUrl","middlewares","use","serverPath","req","res","next","originalUrl","endsWith","statusCode","setHeader","end","resolve","single","dev","_","JSON","stringify","map","entrypoint","numEntrypoints","length","numConfigFiles","Object","keys","status","widgetIdToOverrides","injectedScripts","inlineScripts","join","resolveId","source","importer","standardizedSource","getFullSourcePath","slice","standardizedImporter","includes","replace","fullSourcePath","transform","code","id","configObject","parse","subPath","base","setupRoute","logger","info","green","bold"],"sources":["FoundryWidgetDevPlugin.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type ParameterConfig, type WidgetConfig } from \"@osdk/widget.api\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport color from \"picocolors\";\nimport sirv from \"sirv\";\nimport type { Plugin, ViteDevServer } from \"vite\";\nimport {\n CONFIG_FILE_SUFFIX,\n ENTRYPOINTS_PATH,\n FINISH_PATH,\n SETUP_PATH,\n VITE_INJECTIONS_PATH,\n} from \"../common/constants.js\";\nimport { extractWidgetConfig } from \"../common/extractWidgetConfig.js\";\nimport { getInputHtmlEntrypoints } from \"../common/getInputHtmlEntrypoints.js\";\nimport { standardizeFileExtension } from \"../common/standardizeFileExtension.js\";\nimport { extractInjectedScripts } from \"./extractInjectedScripts.js\";\nimport { getBaseHref } from \"./getBaseHref.js\";\nimport { getFoundryToken } from \"./getFoundryToken.js\";\nimport { getWidgetIdOverrideMap } from \"./getWidgetIdOverrideMap.js\";\nimport { publishDevModeSettings } from \"./publishDevModeSettings.js\";\n\n// Location of the setup page assets\nconst DIR_DIST: string = typeof __dirname !== \"undefined\"\n ? __dirname\n : path.dirname(fileURLToPath(import.meta.url));\n\nexport function FoundryWidgetDevPlugin(): Plugin {\n // The root HTML entrypoints of the build process\n let htmlEntrypoints: string[];\n // Fully resolved paths to the entrypoint files, mapped to relative paths\n const codeEntrypoints: Record<string, string> = {};\n // Store the map of fully resolved config file paths to entrypoint file paths\n const configFileToEntrypoint: Record<string, string> = {};\n // Store the configuration per module ID, e.g. /repo/src/widget-one.config.ts -> { ... }\n const configFiles: Record<string, WidgetConfig<ParameterConfig>> = {};\n\n return {\n name: \"@osdk:widget-dev-plugin\",\n enforce: \"pre\",\n\n /**\n * Capture the entrypoints from the Vite config so that we can manually load them on our\n * setup page and trigger module parsing.\n */\n buildStart(options) {\n htmlEntrypoints = getInputHtmlEntrypoints(options);\n },\n\n /**\n * Check for the required token environment variable in dev mode.\n */\n config(resolvedConfig, { command }) {\n // Only check for the token environment variable when running in dev mode.\n // When command is \"serve\" and not in test mode (VITEST).\n if (command === \"serve\" && process.env.VITEST == null) {\n getFoundryToken(resolvedConfig.mode);\n }\n },\n\n /**\n * Configure the Vite server to serve the setup page and handle the finish endpoint. This\n * endpoint will set the widget overrides in Foundry and enable dev mode.\n */\n configureServer(server) {\n // Override the printUrls function to print the setup page URL\n server.printUrls = () => printSetupPageUrl(server);\n\n /**\n * Redirect `./.palantir/setup` to `./.palantir/setup/` to ensure that relative paths work\n * correctly. Relative paths must be used so that the dev server UI can be accessed on\n * non-root paths.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n (req, res, next) => {\n if (req.originalUrl?.endsWith(serverPath(server, SETUP_PATH))) {\n res.statusCode = 301;\n res.setHeader(\"Location\", `${serverPath(server, SETUP_PATH)}/`);\n res.end();\n } else {\n next();\n }\n },\n );\n\n /**\n * Serve the setup page that will load the entrypoints in iframes and trigger the finish\n * endpoint once widgets have been loaded.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n sirv(path.resolve(DIR_DIST, \"../../site\"), {\n single: true,\n dev: true,\n }),\n );\n\n /**\n * Make the entrypoints available to the setup page so that it can load them in iframes in\n * order to trigger module parsing.\n */\n server.middlewares.use(\n serverPath(server, ENTRYPOINTS_PATH),\n (_, res) => {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(\n JSON.stringify(\n htmlEntrypoints.map((entrypoint) =>\n serverPath(server, entrypoint)\n ),\n ),\n );\n },\n );\n\n /**\n * Finish the setup process by setting the widget overrides in Foundry and enabling dev mode.\n */\n server.middlewares.use(\n serverPath(server, FINISH_PATH),\n async (_, res) => {\n // Wait for the setup page to trigger the parsing of the config files\n const numEntrypoints = htmlEntrypoints.length;\n const numConfigFiles = Object.keys(configFiles).length;\n if (numConfigFiles < numEntrypoints) {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(JSON.stringify({ status: \"pending\" }));\n return;\n }\n\n // Prepare the widget overrides and finish the setup process\n const widgetIdToOverrides = await getWidgetIdOverrideMap(\n server,\n codeEntrypoints,\n configFileToEntrypoint,\n configFiles,\n getBaseHref(server),\n );\n await publishDevModeSettings(\n server,\n widgetIdToOverrides,\n getBaseHref(server),\n res,\n );\n },\n );\n\n /**\n * Serve scripts that would usually be injected into the HTML if Vite had control over the\n * serving of index HTML pages. This is necessary to ensure that plugins like React refresh\n * work correctly.\n */\n server.middlewares.use(\n serverPath(server, VITE_INJECTIONS_PATH),\n async (_, res) => {\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.setHeader(\"Content-Type\", \"application/javascript\");\n const injectedScripts = await extractInjectedScripts(server);\n res.end(injectedScripts.inlineScripts.join(\"\\n\"));\n },\n );\n },\n\n /**\n * As module imports are resolved, we need to capture the entrypoint file paths and the config\n * file paths that are imported from them.\n */\n resolveId(source, importer) {\n if (importer == null) {\n return;\n }\n\n // Standardize the source file extension and get the full path\n const standardizedSource = standardizeFileExtension(\n getFullSourcePath(source.slice(1), importer),\n );\n // Importers are already full paths, so just standardize the extension\n const standardizedImporter = standardizeFileExtension(importer);\n\n // In dev mode all entrypoints have a generic HTML importer value\n if (\n importer.endsWith(\"index.html\") && !standardizedSource.includes(\"@fs\")\n ) {\n // Store the fully resolved path and the relative path, as we need the former for mapping\n // config files to entrypoints and the latter as a dev mode override script\n codeEntrypoints[standardizedSource] = source;\n }\n\n // Look for config files that are imported from an entrypoint file\n if (\n standardizedSource.replace(/\\.[^/.]+$/, \"\").endsWith(CONFIG_FILE_SUFFIX)\n && codeEntrypoints[standardizedImporter] != null\n ) {\n const fullSourcePath = standardizeFileExtension(\n getFullSourcePath(source, standardizedImporter),\n );\n configFileToEntrypoint[fullSourcePath] = standardizedImporter;\n }\n },\n\n /**\n * During dev mode we need to parse the AST of the config files to extract the widget config\n * object manually, as Vite doesn't compile files during dev mode.\n */\n transform(code, id) {\n const standardizedSource = standardizeFileExtension(id);\n if (configFileToEntrypoint[standardizedSource] != null) {\n const configObject = extractWidgetConfig(id, this.parse(code));\n if (configObject != null) {\n configFiles[standardizedSource] = configObject;\n }\n }\n },\n };\n}\n\n/**\n * During the resolution phase source are given as relative paths to the importer\n */\nfunction getFullSourcePath(source: string, importer: string): string {\n return path.resolve(path.dirname(importer), source);\n}\n\nfunction serverPath(server: ViteDevServer, subPath: string): string {\n return path.resolve(server.config.base, subPath);\n}\n\nfunction printSetupPageUrl(server: ViteDevServer) {\n const setupRoute = `${getBaseHref(server)}${SETUP_PATH}/`;\n server.config.logger.info(\n ` ${color.green(\"➜\")} ${\n color.bold(\"Click to enter developer mode for your widget set\")\n }: ${color.green(setupRoute)}`,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,IAAI,MAAM,WAAW;AAC5B,SAASC,aAAa,QAAQ,UAAU;AACxC,OAAOC,KAAK,MAAM,YAAY;AAC9B,OAAOC,IAAI,MAAM,MAAM;AAEvB,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,WAAW,EACXC,UAAU,EACVC,oBAAoB,QACf,wBAAwB;AAC/B,SAASC,mBAAmB,QAAQ,kCAAkC;AACtE,SAASC,uBAAuB,QAAQ,sCAAsC;AAC9E,SAASC,wBAAwB,QAAQ,uCAAuC;AAChF,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,sBAAsB,QAAQ,6BAA6B;AACpE,SAASC,sBAAsB,QAAQ,6BAA6B;;AAEpE;AACA,MAAMC,QAAgB,GAAG,OAAOC,SAAS,KAAK,WAAW,GACrDA,SAAS,GACTlB,IAAI,CAACmB,OAAO,CAAClB,aAAa,CAACmB,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAEhD,OAAO,SAASC,sBAAsBA,CAAA,EAAW;EAC/C;EACA,IAAIC,eAAyB;EAC7B;EACA,MAAMC,eAAuC,GAAG,CAAC,CAAC;EAClD;EACA,MAAMC,sBAA8C,GAAG,CAAC,CAAC;EACzD;EACA,MAAMC,WAA0D,GAAG,CAAC,CAAC;EAErE,OAAO;IACLC,IAAI,EAAE,yBAAyB;IAC/BC,OAAO,EAAE,KAAK;IAEd;AACJ;AACA;AACA;IACIC,UAAUA,CAACC,OAAO,EAAE;MAClBP,eAAe,GAAGd,uBAAuB,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tD,MAAMU,YAAY,GAAG5E,mBAAmB,CAAC2E,EAAE,EAAE,IAAI,CAACE,KAAK,CAACH,IAAI,CAAC,CAAC;QAC9D,IAAIE,YAAY,IAAI,IAAI,EAAE;UACxB1D,WAAW,CAACgD,kBAAkB,CAAC,GAAGU,YAAY;QAChD;MACF;IACF;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA,SAAST,iBAAiBA,CAACH,MAAc,EAAEC,QAAgB,EAAU;EACnE,OAAO1E,IAAI,CAACsD,OAAO,CAACtD,IAAI,CAACmB,OAAO,CAACuD,QAAQ,CAAC,EAAED,MAAM,CAAC;AACrD;AAEA,SAAS5B,UAAUA,CAACL,MAAqB,EAAE+C,OAAe,EAAU;EAClE,OAAOvF,IAAI,CAACsD,OAAO,CAACd,MAAM,CAACR,MAAM,CAACwD,IAAI,EAAED,OAAO,CAAC;AAClD;AAEA,SAAS7C,iBAAiBA,CAACF,MAAqB,EAAE;EAChD,MAAMiD,UAAU,GAAG,GAAG5E,WAAW,CAAC2B,MAAM,CAAC,GAAGjC,UAAU,GAAG;EACzDiC,MAAM,CAACR,MAAM,CAAC0D,MAAM,CAACC,IAAI,CACvB,KAAKzF,KAAK,CAAC0F,KAAK,CAAC,GAAG,CAAC,KACnB1F,KAAK,CAAC2F,IAAI,CAAC,mDAAmD,CAAC,KAC5D3F,KAAK,CAAC0F,KAAK,CAACH,UAAU,CAAC,EAC9B,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,87 @@
|
|
|
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 { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
19
|
+
import * as codeWorkspacesMode from "../codeWorkspacesMode.js";
|
|
20
|
+
const FOUNDRY_PROXY_URL = "foundry.proxy.url";
|
|
21
|
+
const DEV_SERVER_DOMAIN = "workspace.stack.com";
|
|
22
|
+
const DEV_SERVER_BASE_PATH = "/proxy/path";
|
|
23
|
+
const FOUNDRY_PROXY_TOKEN = "/tmp/token.txt";
|
|
24
|
+
const MOCK_TOKEN = "token-value";
|
|
25
|
+
describe("codeWorkspacesMode", () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
vi.restoreAllMocks();
|
|
28
|
+
});
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
vi.unstubAllEnvs();
|
|
31
|
+
});
|
|
32
|
+
describe("isCodeWorkspacesMode", () => {
|
|
33
|
+
test("returns true for 'code-workspaces' mode", () => {
|
|
34
|
+
expect(codeWorkspacesMode.isCodeWorkspacesMode("code-workspaces")).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
test("returns false for other modes", () => {
|
|
37
|
+
expect(codeWorkspacesMode.isCodeWorkspacesMode("dev")).toBe(false);
|
|
38
|
+
expect(codeWorkspacesMode.isCodeWorkspacesMode(undefined)).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("getCodeWorkspacesFoundryUrl", () => {
|
|
42
|
+
test("returns correct URL when env is set", () => {
|
|
43
|
+
vi.stubEnv("FOUNDRY_PROXY_URL", FOUNDRY_PROXY_URL);
|
|
44
|
+
expect(codeWorkspacesMode.getCodeWorkspacesFoundryUrl()).toBe(`https://${FOUNDRY_PROXY_URL}`);
|
|
45
|
+
});
|
|
46
|
+
test("throws if env is missing", () => {
|
|
47
|
+
vi.stubEnv("FOUNDRY_PROXY_URL", undefined);
|
|
48
|
+
expect(() => codeWorkspacesMode.getCodeWorkspacesFoundryUrl()).toThrow();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe("getCodeWorkspacesBaseHref", () => {
|
|
52
|
+
test("returns correct base href when env is set", () => {
|
|
53
|
+
vi.stubEnv("DEV_SERVER_DOMAIN", DEV_SERVER_DOMAIN);
|
|
54
|
+
vi.stubEnv("DEV_SERVER_BASE_PATH", DEV_SERVER_BASE_PATH);
|
|
55
|
+
expect(codeWorkspacesMode.getCodeWorkspacesBaseHref()).toBe(`https://${DEV_SERVER_DOMAIN}${DEV_SERVER_BASE_PATH}`);
|
|
56
|
+
});
|
|
57
|
+
test("throws if DEV_SERVER_DOMAIN is missing", () => {
|
|
58
|
+
vi.stubEnv("DEV_SERVER_DOMAIN", undefined);
|
|
59
|
+
vi.stubEnv("DEV_SERVER_BASE_PATH", DEV_SERVER_BASE_PATH);
|
|
60
|
+
expect(() => codeWorkspacesMode.getCodeWorkspacesBaseHref()).toThrow();
|
|
61
|
+
});
|
|
62
|
+
test("throws if DEV_SERVER_BASE_PATH is missing", () => {
|
|
63
|
+
vi.stubEnv("DEV_SERVER_DOMAIN", DEV_SERVER_DOMAIN);
|
|
64
|
+
vi.stubEnv("DEV_SERVER_BASE_PATH", undefined);
|
|
65
|
+
expect(() => codeWorkspacesMode.getCodeWorkspacesBaseHref()).toThrow();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe("getCodeWorkspacesFoundryToken", () => {
|
|
69
|
+
test("returns token from file when env and file are set", () => {
|
|
70
|
+
vi.stubEnv("FOUNDRY_PROXY_TOKEN", FOUNDRY_PROXY_TOKEN);
|
|
71
|
+
vi.spyOn(fs, "readFileSync").mockReturnValue(MOCK_TOKEN);
|
|
72
|
+
expect(codeWorkspacesMode.getCodeWorkspacesFoundryToken()).toBe(MOCK_TOKEN);
|
|
73
|
+
});
|
|
74
|
+
test("throws if env is missing", () => {
|
|
75
|
+
vi.stubEnv("FOUNDRY_PROXY_TOKEN", undefined);
|
|
76
|
+
expect(() => codeWorkspacesMode.getCodeWorkspacesFoundryToken()).toThrow();
|
|
77
|
+
});
|
|
78
|
+
test("throws if file read fails", () => {
|
|
79
|
+
vi.stubEnv("FOUNDRY_PROXY_TOKEN", FOUNDRY_PROXY_TOKEN);
|
|
80
|
+
vi.spyOn(fs, "readFileSync").mockImplementation(() => {
|
|
81
|
+
throw new Error("fail");
|
|
82
|
+
});
|
|
83
|
+
expect(() => codeWorkspacesMode.getCodeWorkspacesFoundryToken()).toThrow();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=codeWorkspacesMode.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeWorkspacesMode.test.js","names":["fs","afterEach","beforeEach","describe","expect","test","vi","codeWorkspacesMode","FOUNDRY_PROXY_URL","DEV_SERVER_DOMAIN","DEV_SERVER_BASE_PATH","FOUNDRY_PROXY_TOKEN","MOCK_TOKEN","restoreAllMocks","unstubAllEnvs","isCodeWorkspacesMode","toBe","undefined","stubEnv","getCodeWorkspacesFoundryUrl","toThrow","getCodeWorkspacesBaseHref","spyOn","mockReturnValue","getCodeWorkspacesFoundryToken","mockImplementation","Error"],"sources":["codeWorkspacesMode.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 { afterEach, beforeEach, describe, expect, test, vi } from \"vitest\";\nimport * as codeWorkspacesMode from \"../codeWorkspacesMode.js\";\n\nconst FOUNDRY_PROXY_URL = \"foundry.proxy.url\";\nconst DEV_SERVER_DOMAIN = \"workspace.stack.com\";\nconst DEV_SERVER_BASE_PATH = \"/proxy/path\";\nconst FOUNDRY_PROXY_TOKEN = \"/tmp/token.txt\";\nconst MOCK_TOKEN = \"token-value\";\n\ndescribe(\"codeWorkspacesMode\", () => {\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n afterEach(() => {\n vi.unstubAllEnvs();\n });\n\n describe(\"isCodeWorkspacesMode\", () => {\n test(\"returns true for 'code-workspaces' mode\", () => {\n expect(codeWorkspacesMode.isCodeWorkspacesMode(\"code-workspaces\")).toBe(\n true,\n );\n });\n\n test(\"returns false for other modes\", () => {\n expect(codeWorkspacesMode.isCodeWorkspacesMode(\"dev\")).toBe(false);\n expect(codeWorkspacesMode.isCodeWorkspacesMode(undefined)).toBe(false);\n });\n });\n\n describe(\"getCodeWorkspacesFoundryUrl\", () => {\n test(\"returns correct URL when env is set\", () => {\n vi.stubEnv(\"FOUNDRY_PROXY_URL\", FOUNDRY_PROXY_URL);\n expect(codeWorkspacesMode.getCodeWorkspacesFoundryUrl()).toBe(\n `https://${FOUNDRY_PROXY_URL}`,\n );\n });\n\n test(\"throws if env is missing\", () => {\n vi.stubEnv(\"FOUNDRY_PROXY_URL\", undefined);\n expect(() => codeWorkspacesMode.getCodeWorkspacesFoundryUrl()).toThrow();\n });\n });\n\n describe(\"getCodeWorkspacesBaseHref\", () => {\n test(\"returns correct base href when env is set\", () => {\n vi.stubEnv(\"DEV_SERVER_DOMAIN\", DEV_SERVER_DOMAIN);\n vi.stubEnv(\"DEV_SERVER_BASE_PATH\", DEV_SERVER_BASE_PATH);\n expect(codeWorkspacesMode.getCodeWorkspacesBaseHref()).toBe(\n `https://${DEV_SERVER_DOMAIN}${DEV_SERVER_BASE_PATH}`,\n );\n });\n\n test(\"throws if DEV_SERVER_DOMAIN is missing\", () => {\n vi.stubEnv(\"DEV_SERVER_DOMAIN\", undefined);\n vi.stubEnv(\"DEV_SERVER_BASE_PATH\", DEV_SERVER_BASE_PATH);\n expect(() => codeWorkspacesMode.getCodeWorkspacesBaseHref()).toThrow();\n });\n\n test(\"throws if DEV_SERVER_BASE_PATH is missing\", () => {\n vi.stubEnv(\"DEV_SERVER_DOMAIN\", DEV_SERVER_DOMAIN);\n vi.stubEnv(\"DEV_SERVER_BASE_PATH\", undefined);\n expect(() => codeWorkspacesMode.getCodeWorkspacesBaseHref()).toThrow();\n });\n });\n\n describe(\"getCodeWorkspacesFoundryToken\", () => {\n test(\"returns token from file when env and file are set\", () => {\n vi.stubEnv(\"FOUNDRY_PROXY_TOKEN\", FOUNDRY_PROXY_TOKEN);\n vi.spyOn(fs, \"readFileSync\").mockReturnValue(MOCK_TOKEN);\n expect(codeWorkspacesMode.getCodeWorkspacesFoundryToken()).toBe(\n MOCK_TOKEN,\n );\n });\n\n test(\"throws if env is missing\", () => {\n vi.stubEnv(\"FOUNDRY_PROXY_TOKEN\", undefined);\n expect(() => codeWorkspacesMode.getCodeWorkspacesFoundryToken())\n .toThrow();\n });\n\n test(\"throws if file read fails\", () => {\n vi.stubEnv(\"FOUNDRY_PROXY_TOKEN\", FOUNDRY_PROXY_TOKEN);\n vi.spyOn(fs, \"readFileSync\").mockImplementation(() => {\n throw new Error(\"fail\");\n });\n expect(() => codeWorkspacesMode.getCodeWorkspacesFoundryToken())\n .toThrow();\n });\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,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,QAAQ;AAC1E,OAAO,KAAKC,kBAAkB,MAAM,0BAA0B;AAE9D,MAAMC,iBAAiB,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R,MAAM,CAACG,kBAAkB,CAACiB,6BAA6B,CAAC,CAAC,CAAC,CAACR,IAAI,CAC7DJ,UACF,CAAC;IACH,CAAC,CAAC;IAEFP,IAAI,CAAC,0BAA0B,EAAE,MAAM;MACrCC,EAAE,CAACY,OAAO,CAAC,qBAAqB,EAAED,SAAS,CAAC;MAC5Cb,MAAM,CAAC,MAAMG,kBAAkB,CAACiB,6BAA6B,CAAC,CAAC,CAAC,CAC7DJ,OAAO,CAAC,CAAC;IACd,CAAC,CAAC;IAEFf,IAAI,CAAC,2BAA2B,EAAE,MAAM;MACtCC,EAAE,CAACY,OAAO,CAAC,qBAAqB,EAAEP,mBAAmB,CAAC;MACtDL,EAAE,CAACgB,KAAK,CAACtB,EAAE,EAAE,cAAc,CAAC,CAACyB,kBAAkB,CAAC,MAAM;QACpD,MAAM,IAAIC,KAAK,CAAC,MAAM,CAAC;MACzB,CAAC,CAAC;MACFtB,MAAM,CAAC,MAAMG,kBAAkB,CAACiB,6BAA6B,CAAC,CAAC,CAAC,CAC7DJ,OAAO,CAAC,CAAC;IACd,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 } from "vitest";
|
|
18
|
+
import { extractInjectedScripts } from "../extractInjectedScripts.js";
|
|
19
|
+
const EXAMPLE_SCRIPTS = `
|
|
20
|
+
<script src="/src-script.js"></script>
|
|
21
|
+
<script>
|
|
22
|
+
console.log("Hello, world!");
|
|
23
|
+
</script>
|
|
24
|
+
`;
|
|
25
|
+
test("extractInjectedScripts", async () => {
|
|
26
|
+
const result = await extractInjectedScripts({
|
|
27
|
+
transformIndexHtml: () => Promise.resolve(EXAMPLE_SCRIPTS)
|
|
28
|
+
});
|
|
29
|
+
expect(result).toEqual({
|
|
30
|
+
scriptSources: ["/src-script.js"],
|
|
31
|
+
inlineScripts: ["console.log(\"Hello, world!\");"]
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=extractInjectedScripts.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractInjectedScripts.test.js","names":["expect","test","extractInjectedScripts","EXAMPLE_SCRIPTS","result","transformIndexHtml","Promise","resolve","toEqual","scriptSources","inlineScripts"],"sources":["extractInjectedScripts.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 { expect, test } from \"vitest\";\nimport { extractInjectedScripts } from \"../extractInjectedScripts.js\";\n\nconst EXAMPLE_SCRIPTS = `\n<script src=\"/src-script.js\"></script>\n<script>\nconsole.log(\"Hello, world!\");\n</script>\n`;\n\ntest(\"extractInjectedScripts\", async () => {\n const server = {\n transformIndexHtml: () => Promise.resolve(EXAMPLE_SCRIPTS),\n };\n\n const result = await extractInjectedScripts(server);\n expect(result).toEqual({\n scriptSources: [\"/src-script.js\"],\n inlineScripts: [\"console.log(\\\"Hello, world!\\\");\"],\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,MAAM,EAAEC,IAAI,QAAQ,QAAQ;AACrC,SAASC,sBAAsB,QAAQ,8BAA8B;AAErE,MAAMC,eAAe,GAAG;AACxB;AACA;AACA;AACA;AACA,CAAC;AAEDF,IAAI,CAAC,wBAAwB,EAAE,YAAY;EAKzC,MAAMG,MAAM,GAAG,MAAMF,sBAAsB,CAJ5B;IACbG,kBAAkB,EAAEA,CAAA,KAAMC,OAAO,CAACC,OAAO,CAACJ,eAAe;EAC3D,CAEkD,CAAC;EACnDH,MAAM,CAACI,MAAM,CAAC,CAACI,OAAO,CAAC;IACrBC,aAAa,EAAE,CAAC,gBAAgB,CAAC;IACjCC,aAAa,EAAE,CAAC,iCAAiC;EACnD,CAAC,CAAC;AACJ,CAAC,CAAC","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
|
+
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
18
|
+
import * as codeWorkspacesMode from "../codeWorkspacesMode.js";
|
|
19
|
+
import { getBaseHref } from "../getBaseHref.js";
|
|
20
|
+
describe("getBaseHref", () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.restoreAllMocks();
|
|
23
|
+
});
|
|
24
|
+
test("returns localhost URLs in local mode", () => {
|
|
25
|
+
const result = getBaseHref({
|
|
26
|
+
config: {
|
|
27
|
+
mode: "",
|
|
28
|
+
base: "/",
|
|
29
|
+
server: {
|
|
30
|
+
https: false,
|
|
31
|
+
port: 5173
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
expect(result).toEqual("http://localhost:5173/");
|
|
36
|
+
});
|
|
37
|
+
test("returns code workspaces URLs in code workspaces mode", () => {
|
|
38
|
+
// Representative value when running dev mode in Code Workspaces mode
|
|
39
|
+
vi.spyOn(codeWorkspacesMode, "getCodeWorkspacesBaseHref").mockReturnValue("https://workspace.stack.com/proxy/path");
|
|
40
|
+
const result = getBaseHref({
|
|
41
|
+
config: {
|
|
42
|
+
mode: "code-workspaces"
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
expect(result).toEqual("https://workspace.stack.com/proxy/path/");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=getBaseHref.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBaseHref.test.js","names":["beforeEach","describe","expect","test","vi","codeWorkspacesMode","getBaseHref","restoreAllMocks","result","config","mode","base","server","https","port","toEqual","spyOn","mockReturnValue"],"sources":["getBaseHref.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ViteDevServer } from \"vite\";\nimport { beforeEach, describe, expect, test, vi } from \"vitest\";\nimport * as codeWorkspacesMode from \"../codeWorkspacesMode.js\";\nimport { getBaseHref } from \"../getBaseHref.js\";\n\ndescribe(\"getBaseHref\", () => {\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n test(\"returns localhost URLs in local mode\", () => {\n const server = {\n config: {\n mode: \"\",\n base: \"/\",\n server: { https: false, port: 5173 },\n },\n } as unknown as ViteDevServer;\n\n const result = getBaseHref(server);\n expect(result).toEqual(\"http://localhost:5173/\");\n });\n\n test(\"returns code workspaces URLs in code workspaces mode\", () => {\n // Representative value when running dev mode in Code Workspaces mode\n vi.spyOn(codeWorkspacesMode, \"getCodeWorkspacesBaseHref\").mockReturnValue(\n \"https://workspace.stack.com/proxy/path\",\n );\n\n const server = {\n config: { mode: \"code-workspaces\" },\n } as unknown as ViteDevServer;\n\n const result = getBaseHref(server);\n expect(result).toEqual(\"https://workspace.stack.com/proxy/path/\");\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,QAAQ;AAC/D,OAAO,KAAKC,kBAAkB,MAAM,0BAA0B;AAC9D,SAASC,WAAW,QAAQ,mBAAmB;AAE/CL,QAAQ,CAAC,aAAa,EAAE,MAAM;EAC5BD,UAAU,CAAC,MAAM;IACfI,EAAE,CAACG,eAAe,CAAC,CAAC;EACtB,CAAC,CAAC;EAEFJ,IAAI,CAAC,sCAAsC,EAAE,MAAM;IASjD,MAAMK,MAAM,GAAGF,WAAW,CARX;MACbG,MAAM,EAAE;QACNC,IAAI,EAAE,EAAE;QACRC,IAAI,EAAE,GAAG;QACTC,MAAM,EAAE;UAAEC,KAAK,EAAE,KAAK;UAAEC,IAAI,EAAE;QAAK;MACrC;IACF,CAEiC,CAAC;IAClCZ,MAAM,CAACM,MAAM,CAAC,CAACO,OAAO,CAAC,wBAAwB,CAAC;EAClD,CAAC,CAAC;EAEFZ,IAAI,CAAC,sDAAsD,EAAE,MAAM;IACjE;IACAC,EAAE,CAACY,KAAK,CAACX,kBAAkB,EAAE,2BAA2B,CAAC,CAACY,eAAe,CACvE,wCACF,CAAC;IAMD,MAAMT,MAAM,GAAGF,WAAW,CAJX;MACbG,MAAM,EAAE;QAAEC,IAAI,EAAE;MAAkB;IACpC,CAEiC,CAAC;IAClCR,MAAM,CAACM,MAAM,CAAC,CAACO,OAAO,CAAC,yCAAyC,CAAC;EACnE,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
18
|
+
import * as extractInjectedScriptsModule from "../extractInjectedScripts.js";
|
|
19
|
+
import { getWidgetIdOverrideMap } from "../getWidgetIdOverrideMap.js";
|
|
20
|
+
const MOCK_SERVER = {};
|
|
21
|
+
const MOCK_CODE_ENTRYPOINTS = {
|
|
22
|
+
"entry.ts": `/entry.js`
|
|
23
|
+
};
|
|
24
|
+
const MOCK_CONFIG_FILE_TO_ENTRYPOINT = {
|
|
25
|
+
"widget.config.ts": "entry.ts"
|
|
26
|
+
};
|
|
27
|
+
const MOCK_CONFIG_FILES = {
|
|
28
|
+
"widget.config.ts": {
|
|
29
|
+
id: "widgetId"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
describe("getWidgetIdOverrideMap", () => {
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
vi.restoreAllMocks();
|
|
35
|
+
});
|
|
36
|
+
test("localhost dev server URLs", async () => {
|
|
37
|
+
vi.spyOn(extractInjectedScriptsModule, "extractInjectedScripts").mockResolvedValue({
|
|
38
|
+
// Extracted scripts sources start with the base path
|
|
39
|
+
scriptSources: ["/@vite/client"],
|
|
40
|
+
inlineScripts: []
|
|
41
|
+
});
|
|
42
|
+
const baseHref = `http://localhost:5173/`;
|
|
43
|
+
const result = await getWidgetIdOverrideMap(MOCK_SERVER, MOCK_CODE_ENTRYPOINTS, MOCK_CONFIG_FILE_TO_ENTRYPOINT, MOCK_CONFIG_FILES, baseHref);
|
|
44
|
+
expect(result).toEqual({
|
|
45
|
+
"widgetId": [`${baseHref}.palantir/vite-injections.js`, `${baseHref}@vite/client`, `${baseHref}entry.js`]
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
test("remote server URLs", async () => {
|
|
49
|
+
// Representative values when running dev mode in Code Workspaces mode
|
|
50
|
+
vi.spyOn(extractInjectedScriptsModule, "extractInjectedScripts").mockResolvedValue({
|
|
51
|
+
// Extracted scripts sources start with the base path
|
|
52
|
+
scriptSources: [`/proxy/path/@vite/client`],
|
|
53
|
+
inlineScripts: []
|
|
54
|
+
});
|
|
55
|
+
const baseHref = `https://worksapce.stack.com/proxy/path/`;
|
|
56
|
+
const result = await getWidgetIdOverrideMap(MOCK_SERVER, MOCK_CODE_ENTRYPOINTS, MOCK_CONFIG_FILE_TO_ENTRYPOINT, MOCK_CONFIG_FILES, baseHref);
|
|
57
|
+
expect(result).toEqual({
|
|
58
|
+
"widgetId": [`${baseHref}.palantir/vite-injections.js`, `${baseHref}@vite/client`, `${baseHref}entry.js`]
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=getWidgetIdOverrideMap.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getWidgetIdOverrideMap.test.js","names":["beforeEach","describe","expect","test","vi","extractInjectedScriptsModule","getWidgetIdOverrideMap","MOCK_SERVER","MOCK_CODE_ENTRYPOINTS","MOCK_CONFIG_FILE_TO_ENTRYPOINT","MOCK_CONFIG_FILES","id","restoreAllMocks","spyOn","mockResolvedValue","scriptSources","inlineScripts","baseHref","result","toEqual"],"sources":["getWidgetIdOverrideMap.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ParameterConfig, WidgetConfig } from \"@osdk/widget.api\";\nimport type { ViteDevServer } from \"vite\";\nimport { beforeEach, describe, expect, test, vi } from \"vitest\";\nimport * as extractInjectedScriptsModule from \"../extractInjectedScripts.js\";\nimport { getWidgetIdOverrideMap } from \"../getWidgetIdOverrideMap.js\";\n\nconst MOCK_SERVER = {} as ViteDevServer;\nconst MOCK_CODE_ENTRYPOINTS = { \"entry.ts\": `/entry.js` };\nconst MOCK_CONFIG_FILE_TO_ENTRYPOINT = { \"widget.config.ts\": \"entry.ts\" };\nconst MOCK_CONFIG_FILES = {\n \"widget.config.ts\": { id: \"widgetId\" } as WidgetConfig<ParameterConfig>,\n};\n\ndescribe(\"getWidgetIdOverrideMap\", () => {\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n test(\"localhost dev server URLs\", async () => {\n vi.spyOn(extractInjectedScriptsModule, \"extractInjectedScripts\")\n .mockResolvedValue({\n // Extracted scripts sources start with the base path\n scriptSources: [\"/@vite/client\"],\n inlineScripts: [],\n });\n const baseHref = `http://localhost:5173/`;\n\n const result = await getWidgetIdOverrideMap(\n MOCK_SERVER,\n MOCK_CODE_ENTRYPOINTS,\n MOCK_CONFIG_FILE_TO_ENTRYPOINT,\n MOCK_CONFIG_FILES,\n baseHref,\n );\n\n expect(result).toEqual({\n \"widgetId\": [\n `${baseHref}.palantir/vite-injections.js`,\n `${baseHref}@vite/client`,\n `${baseHref}entry.js`,\n ],\n });\n });\n\n test(\"remote server URLs\", async () => {\n // Representative values when running dev mode in Code Workspaces mode\n vi.spyOn(extractInjectedScriptsModule, \"extractInjectedScripts\")\n .mockResolvedValue({\n // Extracted scripts sources start with the base path\n scriptSources: [`/proxy/path/@vite/client`],\n inlineScripts: [],\n });\n const baseHref = `https://worksapce.stack.com/proxy/path/`;\n\n const result = await getWidgetIdOverrideMap(\n MOCK_SERVER,\n MOCK_CODE_ENTRYPOINTS,\n MOCK_CONFIG_FILE_TO_ENTRYPOINT,\n MOCK_CONFIG_FILES,\n baseHref,\n );\n\n expect(result).toEqual({\n \"widgetId\": [\n `${baseHref}.palantir/vite-injections.js`,\n `${baseHref}@vite/client`,\n `${baseHref}entry.js`,\n ],\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,QAAQ;AAC/D,OAAO,KAAKC,4BAA4B,MAAM,8BAA8B;AAC5E,SAASC,sBAAsB,QAAQ,8BAA8B;AA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BAA8B,EAC9BC,iBAAiB,EACjBO,QACF,CAAC;IAEDf,MAAM,CAACgB,MAAM,CAAC,CAACC,OAAO,CAAC;MACrB,UAAU,EAAE,CACV,GAAGF,QAAQ,8BAA8B,EACzC,GAAGA,QAAQ,cAAc,EACzB,GAAGA,QAAQ,UAAU;IAEzB,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -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 fs from "fs";
|
|
18
|
+
import { safeGetEnvVar } from "../common/safeGetEnvVar.js";
|
|
19
|
+
const CODE_WORKSPACES = "code-workspaces";
|
|
20
|
+
|
|
21
|
+
// Environment variable names
|
|
22
|
+
const CODE_WORKSPACES_TOKEN_PATH = "FOUNDRY_PROXY_TOKEN";
|
|
23
|
+
const FOUNDRY_PROXY_URL = "FOUNDRY_PROXY_URL";
|
|
24
|
+
const DEV_SERVER_DOMAIN = "DEV_SERVER_DOMAIN";
|
|
25
|
+
const DEV_SERVER_BASE_PATH = "DEV_SERVER_BASE_PATH";
|
|
26
|
+
export function isCodeWorkspacesMode(mode) {
|
|
27
|
+
return mode === CODE_WORKSPACES;
|
|
28
|
+
}
|
|
29
|
+
export function getCodeWorkspacesFoundryUrl() {
|
|
30
|
+
return `https://${safeGetEnvVar(process.env, FOUNDRY_PROXY_URL, "This value is required when running dev mode in Code Workspaces mode.")}`;
|
|
31
|
+
}
|
|
32
|
+
export function getCodeWorkspacesBaseHref() {
|
|
33
|
+
const devServerDomain = safeGetEnvVar(process.env, DEV_SERVER_DOMAIN, "This value is required when running dev mode in Code Workspaces mode.");
|
|
34
|
+
const devServerPath = safeGetEnvVar(process.env, DEV_SERVER_BASE_PATH, "This value is required when running dev mode in Code Workspaces mode.");
|
|
35
|
+
return `https://${devServerDomain}${devServerPath}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Read the token value from the file specified in the environment variable. The value within this
|
|
40
|
+
* file could change over the lifetime of the workspace container.
|
|
41
|
+
*/
|
|
42
|
+
export function getCodeWorkspacesFoundryToken() {
|
|
43
|
+
const tokenFilePath = safeGetEnvVar(process.env, CODE_WORKSPACES_TOKEN_PATH, "This value is required when running dev mode in Code Workspaces mode.");
|
|
44
|
+
try {
|
|
45
|
+
return fs.readFileSync(tokenFilePath, "utf8");
|
|
46
|
+
} catch (err) {
|
|
47
|
+
throw new Error(`Failed to read Foundry token from '${tokenFilePath}': ${err.message}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=codeWorkspacesMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeWorkspacesMode.js","names":["fs","safeGetEnvVar","CODE_WORKSPACES","CODE_WORKSPACES_TOKEN_PATH","FOUNDRY_PROXY_URL","DEV_SERVER_DOMAIN","DEV_SERVER_BASE_PATH","isCodeWorkspacesMode","mode","getCodeWorkspacesFoundryUrl","process","env","getCodeWorkspacesBaseHref","devServerDomain","devServerPath","getCodeWorkspacesFoundryToken","tokenFilePath","readFileSync","err","Error","message"],"sources":["codeWorkspacesMode.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 { safeGetEnvVar } from \"../common/safeGetEnvVar.js\";\n\nconst CODE_WORKSPACES = \"code-workspaces\";\n\n// Environment variable names\nconst CODE_WORKSPACES_TOKEN_PATH = \"FOUNDRY_PROXY_TOKEN\";\nconst FOUNDRY_PROXY_URL = \"FOUNDRY_PROXY_URL\";\nconst DEV_SERVER_DOMAIN = \"DEV_SERVER_DOMAIN\";\nconst DEV_SERVER_BASE_PATH = \"DEV_SERVER_BASE_PATH\";\n\nexport function isCodeWorkspacesMode(mode: string | undefined): boolean {\n return mode === CODE_WORKSPACES;\n}\n\nexport function getCodeWorkspacesFoundryUrl(): string {\n return `https://${\n safeGetEnvVar(\n process.env,\n FOUNDRY_PROXY_URL,\n \"This value is required when running dev mode in Code Workspaces mode.\",\n )\n }`;\n}\n\nexport function getCodeWorkspacesBaseHref(): string {\n const devServerDomain = safeGetEnvVar(\n process.env,\n DEV_SERVER_DOMAIN,\n \"This value is required when running dev mode in Code Workspaces mode.\",\n );\n const devServerPath = safeGetEnvVar(\n process.env,\n DEV_SERVER_BASE_PATH,\n \"This value is required when running dev mode in Code Workspaces mode.\",\n );\n return `https://${devServerDomain}${devServerPath}`;\n}\n\n/**\n * Read the token value from the file specified in the environment variable. The value within this\n * file could change over the lifetime of the workspace container.\n */\nexport function getCodeWorkspacesFoundryToken(): string {\n const tokenFilePath = safeGetEnvVar(\n process.env,\n CODE_WORKSPACES_TOKEN_PATH,\n \"This value is required when running dev mode in Code Workspaces mode.\",\n );\n try {\n return fs.readFileSync(tokenFilePath, \"utf8\");\n } catch (err) {\n throw new Error(\n `Failed to read Foundry token from '${tokenFilePath}': ${\n (err as Error).message\n }`,\n );\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,aAAa,QAAQ,4BAA4B;AAE1D,MAAMC,eAAe,GAAG,iBAAiB;;AAEzC;AACA,MAAMC,0BAA0B,GAAG,qBAAqB;AACxD,MAAMC,iBAAiB,GAAG,mBAAmB;AAC7C,MAAMC,iBAAiB,GAAG,mBAAmB;AAC7C,MAAMC,oBAAoB,GAAG,sBAAsB;AAEnD,OAAO,SAASC,oBAAoBA,CAACC,IAAwB,EAAW;EACtE,OAAOA,IAAI,KAAKN,eAAe;AACjC;AAEA,OAAO,SAASO,2BAA2BA,CAAA,EAAW;EACpD,OAAO,WACLR,aAAa,CACXS,OAAO,CAACC,GAAG,EACXP,iBAAiB,EACjB,uEACF,CAAC,EACD;AACJ;AAEA,OAAO,SAASQ,yBAAyBA,CAAA,EAAW;EAClD,MAAMC,eAAe,GAAGZ,aAAa,CACnCS,OAAO,CAACC,GAAG,EACXN,iBAAiB,EACjB,uEACF,CAAC;EACD,MAAMS,aAAa,GAAGb,aAAa,CACjCS,OAAO,CAACC,GAAG,EACXL,oBAAoB,EACpB,uEACF,CAAC;EACD,OAAO,WAAWO,eAAe,GAAGC,aAAa,EAAE;AACrD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAAA,EAAW;EACtD,MAAMC,aAAa,GAAGf,aAAa,CACjCS,OAAO,CAACC,GAAG,EACXR,0BAA0B,EAC1B,uEACF,CAAC;EACD,IAAI;IACF,OAAOH,EAAE,CAACiB,YAAY,CAACD,aAAa,EAAE,MAAM,CAAC;EAC/C,CAAC,CAAC,OAAOE,GAAG,EAAE;IACZ,MAAM,IAAIC,KAAK,CACb,sCAAsCH,aAAa,MAChDE,GAAG,CAAWE,OAAO,EAE1B,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { parse as parse5 } from "parse5";
|
|
18
|
+
/**
|
|
19
|
+
* Extracts inline scripts usually injected by Vite plugins during HTML transformation.
|
|
20
|
+
*
|
|
21
|
+
* Vite plugins can inject scripts into the HTML entrypoint. This function captures
|
|
22
|
+
* those injections, specifically inline scripts, which are needed for our server-side
|
|
23
|
+
* rendered pages. It calls the `transformIndexHtml` hook on each plugin, collects
|
|
24
|
+
* the script descriptors, and returns the concatenated inline script contents.
|
|
25
|
+
*
|
|
26
|
+
* See documentation: https://vite.dev/guide/api-plugin#transformindexhtml
|
|
27
|
+
*/
|
|
28
|
+
export async function extractInjectedScripts(server) {
|
|
29
|
+
const result = await server.transformIndexHtml("", "");
|
|
30
|
+
return parseTransformResult(result);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Parse the HTML transform result and extract the injected script details.
|
|
35
|
+
*/
|
|
36
|
+
function parseTransformResult(result) {
|
|
37
|
+
const foundScripts = visitNode(parse5(result));
|
|
38
|
+
return {
|
|
39
|
+
scriptSources: foundScripts.filter(script => script.type === "src").map(script => script.src),
|
|
40
|
+
inlineScripts: foundScripts.filter(script => script.type === "inline").map(script => script.content)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function visitNode(node) {
|
|
44
|
+
if (node.nodeName === "script") {
|
|
45
|
+
return [parseScriptNode(node)];
|
|
46
|
+
}
|
|
47
|
+
if ("childNodes" in node) {
|
|
48
|
+
return node.childNodes.flatMap(childNode => visitNode(childNode));
|
|
49
|
+
}
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
function parseScriptNode(node) {
|
|
53
|
+
const srcAttribute = node.attrs?.find(attribute => attribute.name === "src");
|
|
54
|
+
return srcAttribute != null ? {
|
|
55
|
+
type: "src",
|
|
56
|
+
src: srcAttribute.value
|
|
57
|
+
} : {
|
|
58
|
+
type: "inline",
|
|
59
|
+
content: node.childNodes.filter(childNode => childNode.nodeName === "#text").map(childNode => childNode.value.trim()).join("\n")
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=extractInjectedScripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractInjectedScripts.js","names":["parse","parse5","extractInjectedScripts","server","result","transformIndexHtml","parseTransformResult","foundScripts","visitNode","scriptSources","filter","script","type","map","src","inlineScripts","content","node","nodeName","parseScriptNode","childNodes","flatMap","childNode","srcAttribute","attrs","find","attribute","name","value","trim","join"],"sources":["extractInjectedScripts.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 { DefaultTreeAdapterTypes } from \"parse5\";\nimport { parse as parse5 } from \"parse5\";\nimport type { ViteDevServer } from \"vite\";\n\nexport interface InjectedScripts {\n scriptSources: string[];\n inlineScripts: string[];\n}\n\n/**\n * Extracts inline scripts usually injected by Vite plugins during HTML transformation.\n *\n * Vite plugins can inject scripts into the HTML entrypoint. This function captures\n * those injections, specifically inline scripts, which are needed for our server-side\n * rendered pages. It calls the `transformIndexHtml` hook on each plugin, collects\n * the script descriptors, and returns the concatenated inline script contents.\n *\n * See documentation: https://vite.dev/guide/api-plugin#transformindexhtml\n */\nexport async function extractInjectedScripts(\n server: Pick<ViteDevServer, \"transformIndexHtml\">,\n): Promise<InjectedScripts> {\n const result = await server.transformIndexHtml(\"\", \"\");\n return parseTransformResult(result);\n}\n\n/**\n * Parse the HTML transform result and extract the injected script details.\n */\nfunction parseTransformResult(result: string): InjectedScripts {\n const foundScripts = visitNode(parse5(result));\n return {\n scriptSources: foundScripts.filter((script) => script.type === \"src\").map((\n script,\n ) => script.src),\n inlineScripts: foundScripts.filter((script) => script.type === \"inline\")\n .map((script) => script.content),\n };\n}\n\ntype FoundScript = {\n type: \"src\";\n src: string;\n} | {\n type: \"inline\";\n content: string;\n};\n\nfunction visitNode(node: DefaultTreeAdapterTypes.Node): FoundScript[] {\n if (node.nodeName === \"script\") {\n return [parseScriptNode(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(node: DefaultTreeAdapterTypes.Element): FoundScript {\n const srcAttribute = node.attrs?.find((attribute) =>\n attribute.name === \"src\"\n );\n return srcAttribute != null ? ({ type: \"src\", src: srcAttribute.value }) : ({\n type: \"inline\",\n content: node.childNodes\n .filter((childNode): childNode is DefaultTreeAdapterTypes.TextNode =>\n childNode.nodeName === \"#text\"\n )\n .map((childNode) => childNode.value.trim())\n .join(\"\\n\"),\n });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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AI,GAAI;IAAEX,IAAI,EAAE,KAAK;IAAEE,GAAG,EAAES,YAAY,CAACK;EAAM,CAAC,GAAK;IAC1EhB,IAAI,EAAE,QAAQ;IACdI,OAAO,EAAEC,IAAI,CAACG,UAAU,CACrBV,MAAM,CAAEY,SAAS,IAChBA,SAAS,CAACJ,QAAQ,KAAK,OACzB,CAAC,CACAL,GAAG,CAAES,SAAS,IAAKA,SAAS,CAACM,KAAK,CAACC,IAAI,CAAC,CAAC,CAAC,CAC1CC,IAAI,CAAC,IAAI;EACd,CAAE;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { getCodeWorkspacesBaseHref, isCodeWorkspacesMode } from "./codeWorkspacesMode.js";
|
|
18
|
+
export function getBaseHref(server) {
|
|
19
|
+
const baseHref = isCodeWorkspacesMode(server.config.mode) ? getCodeWorkspacesBaseHref() : getLocalhostBaseHref(server);
|
|
20
|
+
// Ensure that all URLs end with a trailing slash for consistency
|
|
21
|
+
return baseHref.replace(/\/?$/, "/");
|
|
22
|
+
}
|
|
23
|
+
function getLocalhostBaseHref(server) {
|
|
24
|
+
return `${server.config.server.https ? "https" : "http"}://localhost:${server.config.server.port}${server.config.base}`;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=getBaseHref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBaseHref.js","names":["getCodeWorkspacesBaseHref","isCodeWorkspacesMode","getBaseHref","server","baseHref","config","mode","getLocalhostBaseHref","replace","https","port","base"],"sources":["getBaseHref.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ViteDevServer } from \"vite\";\nimport {\n getCodeWorkspacesBaseHref,\n isCodeWorkspacesMode,\n} from \"./codeWorkspacesMode.js\";\n\nexport function getBaseHref(server: ViteDevServer): string {\n const baseHref = isCodeWorkspacesMode(server.config.mode)\n ? getCodeWorkspacesBaseHref()\n : getLocalhostBaseHref(server);\n // Ensure that all URLs end with a trailing slash for consistency\n return baseHref.replace(/\\/?$/, \"/\");\n}\n\nfunction getLocalhostBaseHref(server: ViteDevServer): string {\n return `${\n server.config.server.https ? \"https\" : \"http\"\n }://localhost:${server.config.server.port}${server.config.base}`;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SACEA,yBAAyB,EACzBC,oBAAoB,QACf,yBAAyB;AAEhC,OAAO,SAASC,WAAWA,CAACC,MAAqB,EAAU;EACzD,MAAMC,QAAQ,GAAGH,oBAAoB,CAACE,MAAM,CAACE,MAAM,CAACC,IAAI,CAAC,GACrDN,yBAAyB,CAAC,CAAC,GAC3BO,oBAAoB,CAACJ,MAAM,CAAC;EAChC;EACA,OAAOC,QAAQ,CAACI,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;AACtC;AAEA,SAASD,oBAAoBA,CAACJ,MAAqB,EAAU;EAC3D,OAAO,GACLA,MAAM,CAACE,MAAM,CAACF,MAAM,CAACM,KAAK,GAAG,OAAO,GAAG,MAAM,gBAC/BN,MAAM,CAACE,MAAM,CAACF,MAAM,CAACO,IAAI,GAAGP,MAAM,CAACE,MAAM,CAACM,IAAI,EAAE;AAClE","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { safeGetEnvVar } from "../common/safeGetEnvVar.js";
|
|
18
|
+
import { getCodeWorkspacesFoundryToken, isCodeWorkspacesMode } from "./codeWorkspacesMode.js";
|
|
19
|
+
|
|
20
|
+
// User token environment variable name
|
|
21
|
+
const FOUNDRY_TOKEN = "FOUNDRY_TOKEN";
|
|
22
|
+
export function getFoundryToken(mode) {
|
|
23
|
+
if (isCodeWorkspacesMode(mode)) {
|
|
24
|
+
return getCodeWorkspacesFoundryToken();
|
|
25
|
+
}
|
|
26
|
+
return safeGetEnvVar(process.env, FOUNDRY_TOKEN, "This value is required to run dev mode.");
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=getFoundryToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFoundryToken.js","names":["safeGetEnvVar","getCodeWorkspacesFoundryToken","isCodeWorkspacesMode","FOUNDRY_TOKEN","getFoundryToken","mode","process","env"],"sources":["getFoundryToken.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 { safeGetEnvVar } from \"../common/safeGetEnvVar.js\";\nimport {\n getCodeWorkspacesFoundryToken,\n isCodeWorkspacesMode,\n} from \"./codeWorkspacesMode.js\";\n\n// User token environment variable name\nconst FOUNDRY_TOKEN = \"FOUNDRY_TOKEN\";\n\nexport function getFoundryToken(mode: string | undefined): string {\n if (isCodeWorkspacesMode(mode)) {\n return getCodeWorkspacesFoundryToken();\n }\n return safeGetEnvVar(\n process.env,\n FOUNDRY_TOKEN,\n \"This value is required to run dev mode.\",\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,4BAA4B;AAC1D,SACEC,6BAA6B,EAC7BC,oBAAoB,QACf,yBAAyB;;AAEhC;AACA,MAAMC,aAAa,GAAG,eAAe;AAErC,OAAO,SAASC,eAAeA,CAACC,IAAwB,EAAU;EAChE,IAAIH,oBAAoB,CAACG,IAAI,CAAC,EAAE;IAC9B,OAAOJ,6BAA6B,CAAC,CAAC;EACxC;EACA,OAAOD,aAAa,CAClBM,OAAO,CAACC,GAAG,EACXJ,aAAa,EACb,yCACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { VITE_INJECTIONS_PATH } from "../common/constants.js";
|
|
18
|
+
import { extractInjectedScripts } from "./extractInjectedScripts.js";
|
|
19
|
+
export async function getWidgetIdOverrideMap(server, codeEntrypoints, configFileToEntrypoint, configFiles, baseHref) {
|
|
20
|
+
const widgetIdToEntrypoint = Object.entries(configFiles).reduce((acc, [configFile, config]) => {
|
|
21
|
+
const widgetId = config.id;
|
|
22
|
+
const entrypointFile = configFileToEntrypoint[configFile];
|
|
23
|
+
const entrypointRelativePath = codeEntrypoints[entrypointFile];
|
|
24
|
+
acc[widgetId] = entrypointRelativePath;
|
|
25
|
+
return acc;
|
|
26
|
+
}, {});
|
|
27
|
+
const injectedScripts = await extractInjectedScripts(server);
|
|
28
|
+
const widgetIdToOverrides = Object.entries(widgetIdToEntrypoint).reduce((acc, [widgetId, entrypoint]) => {
|
|
29
|
+
const overrides = [VITE_INJECTIONS_PATH, ...injectedScripts.scriptSources.map(script => removeBasePath(script, baseHref)), entrypoint.slice(1)];
|
|
30
|
+
acc[widgetId] = overrides.map(override => `${baseHref}${override}`);
|
|
31
|
+
return acc;
|
|
32
|
+
}, {});
|
|
33
|
+
return widgetIdToOverrides;
|
|
34
|
+
}
|
|
35
|
+
function removeBasePath(scriptPath, baseHref) {
|
|
36
|
+
const baseHrefPath = new URL(baseHref).pathname;
|
|
37
|
+
return scriptPath.replace(baseHrefPath, "");
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=getWidgetIdOverrideMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getWidgetIdOverrideMap.js","names":["VITE_INJECTIONS_PATH","extractInjectedScripts","getWidgetIdOverrideMap","server","codeEntrypoints","configFileToEntrypoint","configFiles","baseHref","widgetIdToEntrypoint","Object","entries","reduce","acc","configFile","config","widgetId","id","entrypointFile","entrypointRelativePath","injectedScripts","widgetIdToOverrides","entrypoint","overrides","scriptSources","map","script","removeBasePath","slice","override","scriptPath","baseHrefPath","URL","pathname","replace"],"sources":["getWidgetIdOverrideMap.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type ParameterConfig, type WidgetConfig } from \"@osdk/widget.api\";\nimport type { ViteDevServer } from \"vite\";\nimport { VITE_INJECTIONS_PATH } from \"../common/constants.js\";\nimport { extractInjectedScripts } from \"./extractInjectedScripts.js\";\n\nexport async function getWidgetIdOverrideMap(\n server: ViteDevServer,\n codeEntrypoints: Record<string, string>,\n configFileToEntrypoint: Record<string, string>,\n configFiles: Record<string, WidgetConfig<ParameterConfig>>,\n baseHref: string,\n): Promise<Record<string, string[]>> {\n const widgetIdToEntrypoint = Object.entries(configFiles).reduce<\n Record<string, string>\n >(\n (acc, [configFile, config]) => {\n const widgetId = config.id;\n const entrypointFile = configFileToEntrypoint[configFile];\n const entrypointRelativePath = codeEntrypoints[entrypointFile];\n acc[widgetId] = entrypointRelativePath;\n return acc;\n },\n {},\n );\n\n const injectedScripts = await extractInjectedScripts(server);\n const widgetIdToOverrides = Object.entries(widgetIdToEntrypoint).reduce<\n Record<string, string[]>\n >(\n (acc, [widgetId, entrypoint]) => {\n const overrides = [\n VITE_INJECTIONS_PATH,\n ...injectedScripts.scriptSources.map((script) =>\n removeBasePath(script, baseHref)\n ),\n entrypoint.slice(1),\n ];\n acc[widgetId] = overrides.map((override) => `${baseHref}${override}`);\n return acc;\n },\n {},\n );\n\n return widgetIdToOverrides;\n}\n\nfunction removeBasePath(scriptPath: string, baseHref: string): string {\n const baseHrefPath = new URL(baseHref).pathname;\n return scriptPath.replace(baseHrefPath, \"\");\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,sBAAsB,QAAQ,6BAA6B;AAEpE,OAAO,eAAeC,sBAAsBA,CAC1CC,MAAqB,EACrBC,eAAuC,EACvCC,sBAA8C,EAC9CC,WAA0D,EAC1DC,QAAgB,EACmB;EACnC,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,OAAO,CAACJ,WAAW,CAAC,CAACK,MAAM,CAG7D,CAACC,GAAG,EAAE,CAACC,UAAU,EAAEC,MAAM,CAAC,KAAK;IAC7B,MAAMC,QAAQ,GAAGD,MAAM,CAACE,EAAE;IAC1B,MAAMC,cAAc,GAAGZ,sBAAsB,CAACQ,UAAU,CAAC;IACzD,MAAMK,sBAAsB,GAAGd,eAAe,CAACa,cAAc,CAAC;IAC9DL,GAAG,CAACG,QAAQ,CAAC,GAAGG,sBAAsB;IACtC,OAAON,GAAG;EACZ,CAAC,EACD,CAAC,CACH,CAAC;EAED,MAAMO,eAAe,GAAG,MAAMlB,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