From 0e868eb96eed3e99fc59aa9f335f1b5a7a4f789d Mon Sep 17 00:00:00 2001 From: x1unix Date: Tue, 9 Jan 2024 13:56:23 -0500 Subject: [PATCH 1/3] feat: move wasm files to separate dir --- build.mk | 4 ++-- build/Dockerfile | 4 ++-- build/release.dockerfile | 4 ++-- web/public/index.html | 2 +- web/public/{ => wasm}/.gitignore | 2 +- web/src/service-worker.ts | 2 +- web/src/services/api/index.ts | 2 +- web/src/services/api/{utils.ts => resources.ts} | 7 ++++++- web/src/services/gorepl/worker/worker.ts | 2 +- web/src/workers/analyzer.worker.ts | 4 ++-- web/src/workers/repl.worker.ts | 3 ++- 11 files changed, 21 insertions(+), 15 deletions(-) rename web/public/{ => wasm}/.gitignore (65%) rename web/src/services/api/{utils.ts => resources.ts} (61%) diff --git a/build.mk b/build.mk index 4f1bfc65..9a0e4161 100644 --- a/build.mk +++ b/build.mk @@ -10,7 +10,7 @@ WASM_API_VER ?= $(shell cat ./cmd/wasm/api-version.txt) define build_wasm_worker @echo ":: Building WebAssembly worker '$(1)' ..." GOOS=js GOARCH=wasm $(GO) build -buildvcs=false -ldflags "-s -w" -trimpath \ - $(2) -o $(PUBLIC_DIR)/$(1)@$(WASM_API_VER).wasm ./cmd/wasm/$(1) + $(2) -o $(PUBLIC_DIR)/wasm/$(1)@$(WASM_API_VER).wasm ./cmd/wasm/$(1) endef define check_tool @@ -59,7 +59,7 @@ build-ui: .PHONY: wasm_exec.js wasm_exec.js: - @cp "$(GOROOT)/misc/wasm/wasm_exec.js" $(PUBLIC_DIR) + @cp "$(GOROOT)/misc/wasm/wasm_exec.js" $(PUBLIC_DIR)/wasm/ .PHONY:build-webworker analyzer.wasm: diff --git a/build/Dockerfile b/build/Dockerfile index d62d44ed..1091b395 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -60,8 +60,8 @@ ENV APP_GTAG_ID='' COPY data ./data COPY --from=ui-build /tmp/web/build ./public COPY --from=build /tmp/playground/server . -COPY --from=build /tmp/playground/*.wasm ./public -COPY --from=build /tmp/playground/wasm_exec.js ./public +COPY --from=build /tmp/playground/*.wasm ./public/wasm/ +COPY --from=build /tmp/playground/wasm_exec.js ./public/wasm/wasm_exec.js EXPOSE 8000 ENTRYPOINT /opt/playground/server \ -f='/opt/playground/data/packages.json' \ diff --git a/build/release.dockerfile b/build/release.dockerfile index dd42214c..135ccaf0 100644 --- a/build/release.dockerfile +++ b/build/release.dockerfile @@ -47,8 +47,8 @@ ENV APP_GTAG_ID='' COPY data ./data COPY web/build ./public COPY --from=build /tmp/playground/server . -COPY --from=build /tmp/playground/*.wasm ./public -COPY --from=build /tmp/playground/wasm_exec.js ./public +COPY --from=build /tmp/playground/*.wasm ./public/wasm/ +COPY --from=build /tmp/playground/wasm_exec.js ./public/wasm/wasm_exec.js EXPOSE 8000 ENTRYPOINT /opt/playground/server \ -f='/opt/playground/data/packages.json' \ diff --git a/web/public/index.html b/web/public/index.html index 90895f4d..ec372573 100644 --- a/web/public/index.html +++ b/web/public/index.html @@ -123,7 +123,7 @@ - + <% if (process.env.NODE_ENV === 'production') { %> {{ if .GoogleTagID }} diff --git a/web/public/.gitignore b/web/public/wasm/.gitignore similarity index 65% rename from web/public/.gitignore rename to web/public/wasm/.gitignore index 9005298d..6f7e788d 100644 --- a/web/public/.gitignore +++ b/web/public/wasm/.gitignore @@ -1,2 +1,2 @@ wasm_exec.js -*.wasm \ No newline at end of file +*.wasm diff --git a/web/src/service-worker.ts b/web/src/service-worker.ts index d13a122c..7cfeeea5 100644 --- a/web/src/service-worker.ts +++ b/web/src/service-worker.ts @@ -70,7 +70,7 @@ registerRoute( ); // Cache WebAssembly and Go assets -const goWasmAssetsRegExp = new RegExp('^/(wasm_exec.js|go-repl.wasm|worker.wasm)$'); +const goWasmAssetsRegExp = new RegExp('^/wasm/(.*)(.js|.wasm)$', 'i'); const DAY_IN_SECONDS = 24 * 60 * 60; registerRoute( ({ url }) => url.origin === self.location.origin && goWasmAssetsRegExp.test(url.pathname), diff --git a/web/src/services/api/index.ts b/web/src/services/api/index.ts index 0dc5d49e..97b58360 100644 --- a/web/src/services/api/index.ts +++ b/web/src/services/api/index.ts @@ -2,5 +2,5 @@ export { default } from "./singleton"; export * from "./models"; export * from "./client"; export * from "./interface"; -export * from "./utils"; +export * from "./resources"; export * from "./provider"; diff --git a/web/src/services/api/utils.ts b/web/src/services/api/resources.ts similarity index 61% rename from web/src/services/api/utils.ts rename to web/src/services/api/resources.ts index 1dba78ff..27407680 100644 --- a/web/src/services/api/utils.ts +++ b/web/src/services/api/resources.ts @@ -1,6 +1,6 @@ const { REACT_APP_WASM_API_VER: wasmApiVersion = 'v1', - REACT_APP_WASM_BASE_URL: wasmBaseUrl = '', + REACT_APP_WASM_BASE_URL: wasmBaseUrl = '/wasm', } = process.env; /** @@ -9,3 +9,8 @@ const { * @param name */ export const getWasmUrl = name => `${wasmBaseUrl}/${name}@${wasmApiVersion}.wasm`; + +/** + * URL for Go Wasm executor + */ +export const wasmExecUrl = `${wasmBaseUrl}/wasm_exec.js`; diff --git a/web/src/services/gorepl/worker/worker.ts b/web/src/services/gorepl/worker/worker.ts index bea5301e..466990c8 100644 --- a/web/src/services/gorepl/worker/worker.ts +++ b/web/src/services/gorepl/worker/worker.ts @@ -13,7 +13,7 @@ import { BrowserFSBinding } from "~/lib/gowasm/bindings/browserfs"; import { PackageDBBinding } from "~/lib/gowasm/bindings/packagedb"; import { Worker, WorkerBinding } from "~/lib/gowasm/bindings/worker"; -import { getWasmUrl } from "~/services/api/utils"; +import { getWasmUrl } from "~/services/api/resources"; import { wrapResponseWithProgress } from "~/utils/http"; import { FileSystemWrapper } from "~/services/go/fs"; import ProcessStub from "~/services/go/process"; diff --git a/web/src/workers/analyzer.worker.ts b/web/src/workers/analyzer.worker.ts index 4fcc5855..900c7f48 100644 --- a/web/src/workers/analyzer.worker.ts +++ b/web/src/workers/analyzer.worker.ts @@ -1,5 +1,5 @@ import { instantiateStreaming } from "~/lib/go/common"; -import { getWasmUrl } from "~/services/api/utils"; +import { getWasmUrl, wasmExecUrl } from "~/services/api/resources"; declare const self: DedicatedWorkerGlobalScope; export default {} as typeof Worker & { new (): Worker }; @@ -9,7 +9,7 @@ const FN_EXIT = 'exit'; const TYPE_ANALYZE = 'ANALYZE'; const TYPE_EXIT = 'EXIT'; -self.importScripts('/wasm_exec.js'); +self.importScripts(wasmExecUrl); function wrapModule(module) { const wrapped = { diff --git a/web/src/workers/repl.worker.ts b/web/src/workers/repl.worker.ts index c2b90fa9..8731ec58 100644 --- a/web/src/workers/repl.worker.ts +++ b/web/src/workers/repl.worker.ts @@ -5,11 +5,12 @@ import { GoReplWorker, startGoWorker, WorkerConfig, } from "~/services/gorepl/worker"; +import { wasmExecUrl } from "~/services/api/resources"; declare const self: DedicatedWorkerGlobalScope; export default {} as typeof Worker & { new (): Worker }; -self.importScripts('/wasm_exec.js'); +self.importScripts(wasmExecUrl); let worker: GoReplWorker|null = null; const rpcClient = new Client(globalThis, { From b2c992e0ee74a68c4163d3a6b9c1991f16ea138f Mon Sep 17 00:00:00 2001 From: x1unix Date: Tue, 9 Jan 2024 14:18:52 -0500 Subject: [PATCH 2/3] feat: add WASM api ver to wasm_exec.js --- .github/workflows/release.yml | 1 + Makefile | 3 ++- build.mk | 2 +- build/Dockerfile | 5 +++-- build/release.dockerfile | 4 ++-- web/public/index.html | 2 +- web/public/wasm/.gitignore | 2 +- web/src/services/api/resources.ts | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8e7e48ca..764b3a75 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -85,6 +85,7 @@ jobs: REACT_APP_GO_VERSION: "${{ env.GO_VERSION }}" REACT_APP_PREV_GO_VERSION: "${{ env.PREV_GO_VERSION }}" REACT_APP_WASM_API_VER: "${{ env.WASM_API_VER }}" + REACT_APP_WASM_BASE_URL: "/wasm" - name: Build and push image uses: docker/build-push-action@v5 diff --git a/Makefile b/Makefile index 4a375b8d..f4b850ff 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,9 @@ include docker.mk # Exports export REACT_APP_VERSION=$(APP_VERSION) -export REACT_APP_WASM_API_VER=$(WASM_API_VER) export REACT_APP_GITHUB_URL=$(REPO_URL) +export REACT_APP_WASM_API_VER=$(WASM_API_VER) +export REACT_APP_WASM_BASE_URL=/wasm .PHONY:run run: diff --git a/build.mk b/build.mk index 9a0e4161..809bae23 100644 --- a/build.mk +++ b/build.mk @@ -59,7 +59,7 @@ build-ui: .PHONY: wasm_exec.js wasm_exec.js: - @cp "$(GOROOT)/misc/wasm/wasm_exec.js" $(PUBLIC_DIR)/wasm/ + @cp "$(GOROOT)/misc/wasm/wasm_exec.js" $(PUBLIC_DIR)/wasm/wasm_exec@$(WASM_API_VER).js .PHONY:build-webworker analyzer.wasm: diff --git a/build/Dockerfile b/build/Dockerfile index 1091b395..dda5cd51 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -21,6 +21,7 @@ RUN yarn install --silent && \ REACT_APP_GO_VERSION=$GO_VERSION \ REACT_APP_PREV_GO_VERSION=$PREV_GO_VERSION \ REACT_APP_WASM_API_VER=$WASM_API_VER \ + REACT_APP_WASM_BASE_URL=/wasm \ yarn build FROM golang:${GO_VERSION}-alpine as build @@ -45,7 +46,7 @@ RUN echo "Building server with version $APP_VERSION" && \ -ldflags "-s -w" \ -trimpath \ -o ./analyzer@$WASM_API_VER.wasm ./cmd/wasm/analyzer && \ - cp $(go env GOROOT)/misc/wasm/wasm_exec.js . + cp $(go env GOROOT)/misc/wasm/wasm_exec.js ./wasm_exec@$WASM_API_VER.js FROM golang:${GO_VERSION}-alpine as production ARG GO_VERSION @@ -61,7 +62,7 @@ COPY data ./data COPY --from=ui-build /tmp/web/build ./public COPY --from=build /tmp/playground/server . COPY --from=build /tmp/playground/*.wasm ./public/wasm/ -COPY --from=build /tmp/playground/wasm_exec.js ./public/wasm/wasm_exec.js +COPY --from=build /tmp/playground/*.js ./public/wasm/ EXPOSE 8000 ENTRYPOINT /opt/playground/server \ -f='/opt/playground/data/packages.json' \ diff --git a/build/release.dockerfile b/build/release.dockerfile index 135ccaf0..1ee236dd 100644 --- a/build/release.dockerfile +++ b/build/release.dockerfile @@ -33,7 +33,7 @@ RUN echo "Building server with version $APP_VERSION" && \ -ldflags "-s -w" \ -trimpath \ -o ./analyzer@$WASM_API_VER.wasm ./cmd/wasm/analyzer && \ - cp $(go env GOROOT)/misc/wasm/wasm_exec.js . + cp $(go env GOROOT)/misc/wasm/wasm_exec.js ./wasm_exec@$WASM_API_VER.js FROM golang:${GO_VERSION}-alpine as production ARG GO_VERSION @@ -48,7 +48,7 @@ COPY data ./data COPY web/build ./public COPY --from=build /tmp/playground/server . COPY --from=build /tmp/playground/*.wasm ./public/wasm/ -COPY --from=build /tmp/playground/wasm_exec.js ./public/wasm/wasm_exec.js +COPY --from=build /tmp/playground/*.js ./public/wasm/ EXPOSE 8000 ENTRYPOINT /opt/playground/server \ -f='/opt/playground/data/packages.json' \ diff --git a/web/public/index.html b/web/public/index.html index ec372573..008f9e69 100644 --- a/web/public/index.html +++ b/web/public/index.html @@ -123,7 +123,7 @@ - + <% if (process.env.NODE_ENV === 'production') { %> {{ if .GoogleTagID }} diff --git a/web/public/wasm/.gitignore b/web/public/wasm/.gitignore index 6f7e788d..8fa7eb9d 100644 --- a/web/public/wasm/.gitignore +++ b/web/public/wasm/.gitignore @@ -1,2 +1,2 @@ -wasm_exec.js +*.js *.wasm diff --git a/web/src/services/api/resources.ts b/web/src/services/api/resources.ts index 27407680..7864e593 100644 --- a/web/src/services/api/resources.ts +++ b/web/src/services/api/resources.ts @@ -13,4 +13,4 @@ export const getWasmUrl = name => `${wasmBaseUrl}/${name}@${wasmApiVersion}.wasm /** * URL for Go Wasm executor */ -export const wasmExecUrl = `${wasmBaseUrl}/wasm_exec.js`; +export const wasmExecUrl = `${wasmBaseUrl}/wasm_exec@${wasmApiVersion}.js`; From 068a9c01368f3c8575940fd839cbda3c71eef4d7 Mon Sep 17 00:00:00 2001 From: x1unix Date: Tue, 9 Jan 2024 14:27:09 -0500 Subject: [PATCH 3/3] chore: update browserlist --- web/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/yarn.lock b/web/yarn.lock index 52e9691b..c1dacc63 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -3198,9 +3198,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001286, caniuse-lite@^1.0.30001297: - version "1.0.30001479" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001479.tgz" - integrity sha512-6nuRFim5dx8Eu2tO+KJ9PiBdPHs7WB5Hdf+klDcyefyEuOAcfhihIv7pS+JFknJLUiNQbm1AJYKm0c9QOlQS/Q== + version "1.0.30001576" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001576.tgz" + integrity sha512-ff5BdakGe2P3SQsMsiqmt1Lc8221NR1VzHj5jXN5vBny9A6fpze94HiVV/n7XRosOlsShJcvMv5mdnpjOGCEgg== case-sensitive-paths-webpack-plugin@^2.4.0: version "2.4.0"