diff --git a/js_modules/dagster-ui/package.json b/js_modules/dagster-ui/package.json index db989254a728d..cf8091d46db86 100644 --- a/js_modules/dagster-ui/package.json +++ b/js_modules/dagster-ui/package.json @@ -3,7 +3,8 @@ "version": "0.1.0", "private": true, "scripts": { - "build": "yarn workspace @dagster-io/app-oss build && yarn post-build", + "build": "yarn workspace @dagster-io/app-oss build && yarn replace-asset-prefix && yarn post-build", + "replace-asset-prefix": "node ./packages/app-oss/replace-asset-prefix.js", "build-with-profiling": "yarn workspace @dagster-io/app-oss build --profile && yarn post-build", "post-build": "cd ../../python_modules/dagster-webserver/dagster_webserver && rm -rf webapp && mkdir -p webapp && cp -r ../../../js_modules/dagster-ui/packages/app-oss/build ./webapp/ && mkdir -p webapp/build/vendor && cp -r graphql-playground ./webapp/build/vendor && cp ../../../js_modules/dagster-ui/packages/app-oss/csp-header.txt ./webapp/build", "lint": "yarn workspace @dagster-io/app-oss lint && yarn workspace @dagster-io/ui-core lint && yarn workspace @dagster-io/ui-components lint", diff --git a/js_modules/dagster-ui/packages/app-oss/replace-asset-prefix.js b/js_modules/dagster-ui/packages/app-oss/replace-asset-prefix.js new file mode 100644 index 0000000000000..512faf7866f54 --- /dev/null +++ b/js_modules/dagster-ui/packages/app-oss/replace-asset-prefix.js @@ -0,0 +1,34 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const fs = require('fs'); +const path = require('path'); + +function replaceStringInFile(filePath, searchString, replacement) { + const fileContent = fs.readFileSync(filePath, 'utf8'); + const replacedContent = fileContent.replace(new RegExp(searchString, 'g'), replacement); + fs.writeFileSync(filePath, replacedContent); +} + +function processDirectory(directory) { + const files = fs.readdirSync(directory); + + for (const file of files) { + const filePath = path.join(directory, file); + + const isDirectory = fs.statSync(filePath).isDirectory(); + + if (isDirectory) { + // Recursively process subdirectories + processDirectory(filePath); + } else if (file.endsWith('.js')) { + replaceStringInFile( + filePath, + '"BUILDTIME_ASSETPREFIX_REPLACE_ME', + // if typeof window === "undefined" then we are inside a web worker + // Grab the path from the location object + '(() => {if (typeof window === "undefined") {return self.location.pathname.split("/_next/")[0]} return self.__webpack_public_path__ || "";})() + "', + ); + } + } +} + +processDirectory(__dirname + '/build/'); diff --git a/js_modules/dagster-ui/packages/app-oss/src/pages/_document.tsx b/js_modules/dagster-ui/packages/app-oss/src/pages/_document.tsx index d2c201eebccb1..b3b8fe3d427dc 100644 --- a/js_modules/dagster-ui/packages/app-oss/src/pages/_document.tsx +++ b/js_modules/dagster-ui/packages/app-oss/src/pages/_document.tsx @@ -14,6 +14,12 @@ export default function Document() { return (
+ {/* Not sure if we need the following script */}