Skip to content

Commit b59312f

Browse files
authored
Expose the R version on webR an in the Wasm environment (#577)
* Expose the R version on webR an in environment * Update NEWS.md
1 parent 07022a5 commit b59312f

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
* Proxy Web Worker communication through the main thread when using the `SharedArrayBuffer` communication channel (#576).
1010

11+
* The R version is now exposed at `webR.versionR` and as the `R_VERSION` environment variable (#577).
12+
1113
# webR 0.5.5
1214

1315
## New features

src/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TS_SOURCES = $(shell find $(ROOT) \
1818
BASE_URL ?= "./"
1919
PKG_BASE_URL ?= "https://repo.r-wasm.org"
2020
WEBR_VERSION ?= $(shell node -p "require('./package.json').version")
21+
R_VERSION = $(shell cat ../R/R-VERSION)
2122

2223
HTML_DIST = $(addprefix $(DIST)/,$(HTML_TEMPLATES))
2324
$(DIST)/webr.mjs: $(TS_SOURCES) $(HTML_DIST) \
@@ -30,12 +31,14 @@ $(DIST)/webr.mjs: $(TS_SOURCES) $(HTML_DIST) \
3031
$(DIST)/%.html: templates/%.html
3132
sed -e "s|@@BASE_URL@@|$(BASE_URL)|" \
3233
-e "s|@@PKG_BASE_URL@@|$(PKG_BASE_URL)|" \
33-
-e "s|@@WEBR_VERSION@@|$(WEBR_VERSION)|" $< > $@
34+
-e "s|@@WEBR_VERSION@@|$(WEBR_VERSION)|" \
35+
-e "s|@@R_VERSION@@|$(R_VERSION)|" $< > $@
3436

3537
webR/config.ts: webR/config.ts.in
3638
sed -e "s|@@BASE_URL@@|$(BASE_URL)|" \
3739
-e "s|@@PKG_BASE_URL@@|$(PKG_BASE_URL)|" \
38-
-e "s|@@WEBR_VERSION@@|$(WEBR_VERSION)|" webR/config.ts.in > webR/config.ts
40+
-e "s|@@WEBR_VERSION@@|$(WEBR_VERSION)|" \
41+
-e "s|@@R_VERSION@@|$(R_VERSION)|" webR/config.ts.in > webR/config.ts
3942

4043
.PHONY: lint
4144
lint: $(DIST)

src/webR/config.ts.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ import { IN_NODE } from './compat';
33
export const BASE_URL = IN_NODE ? __dirname + '/' : '@@BASE_URL@@';
44
export const PKG_BASE_URL = '@@PKG_BASE_URL@@';
55
export const WEBR_VERSION = '@@WEBR_VERSION@@';
6+
export const R_VERSION = '@@R_VERSION@@';

src/webR/webr-main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { ChannelMain } from './chan/channel';
77
import { newChannelMain, ChannelType } from './chan/channel-common';
88
import { CloseWebSocketMessage, Message, PostMessageWorkerMessage, ProxyWebSocketMessage, ProxyWorkerMessage, SendWebSocketMessage, TerminateWorkerMessage } from './chan/message';
9-
import { BASE_URL, PKG_BASE_URL, WEBR_VERSION } from './config';
9+
import { BASE_URL, PKG_BASE_URL, WEBR_VERSION, R_VERSION } from './config';
1010
import { EmPtr } from './emscripten';
1111
import { WebRPayloadPtr } from './payload';
1212
import { newRProxy, newRClassProxy } from './proxy';
@@ -209,6 +209,7 @@ const defaultEnv = {
209209
ALL_PROXY: 'socks5h://localhost:8580',
210210
WEBR: '1',
211211
WEBR_VERSION: WEBR_VERSION,
212+
R_VERSION: R_VERSION,
212213
};
213214

214215
const defaultOptions = {
@@ -237,6 +238,7 @@ export class WebR {
237238
#initialised: Promise<unknown>;
238239
globalShelter!: Shelter;
239240
version: string = WEBR_VERSION;
241+
versionR: string = R_VERSION;
240242

241243
RObject!: ReturnType<typeof newRClassProxy<typeof RWorker.RObject, RObject>>;
242244
RLogical!: ReturnType<typeof newRClassProxy<typeof RWorker.RLogical, RLogical>>;

0 commit comments

Comments
 (0)