Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ Interactive session. Run the source/bootstrap checks with
`pnpm run test:sess-source`, or just the base-R identity checks with
`pnpm run test:sess-identity`.

## Updating the webR viewer dependency

The data and list viewers use a private copy of jsonlite's Wasm namespace so
they can open before a user installs any packages. When updating the jsonlite
entry in `src/webr/packages.json`, run `python3 scripts/update-webr-viewer-jsonlite.py`
and commit the regenerated archive. The script verifies the upstream digest.
A local copy of the upstream archive can be passed as its first argument.

## Testing the webR language service

After compiling the extension, set `VSCR_ACTIVATION_CASES=webr-language` and run
Expand Down
60 changes: 60 additions & 0 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,63 @@ authors. The distribution's licensing terms are included in
dist/resources/webr-LICENSE.md. Runtime binaries and additional R packages are retrieved
from their upstream distributions when the user starts webR.
https://github.com/r-wasm/webr/tree/v0.6.1

jsonlite Wasm viewer runtime
---------------------------

The viewer runtime includes a reduced copy of the jsonlite Wasm package.
The source distribution is https://cran.r-project.org/package=jsonlite.
The Wasm binary and checksum are pinned in src/webr/packages.json.

Copyright 2020 Jeroen Ooms.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

YAJL
Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
Copyright (c) 2010-2011, Florian Forster <ff at octo.it>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Base64 encoding/decoding (RFC1341)
Copyright (c) 2005, Jouni Malinen <jkmaline@cc.hut.fi>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.

Alternatively, this software may be distributed under the terms of BSD
license.

See README and COPYING for more details.

Copyright (c) 2007, Nick Galbreath -- nickg [at] client9 [dot] com
All rights reserved.
http://code.google.com/p/stringencoders/
Released under the MIT license.
8 changes: 8 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ function copyResources() {
}
}
fs.copyFileSync(path.join(__dirname, 'node_modules/webr/LICENSE.md'), path.join(destDir, 'webr-LICENSE.md'));
const viewerLibrary = fs.readFileSync(path.join(__dirname, 'src/webr/resources/viewer-jsonlite.tgz'));
fs.writeFileSync(path.join(destDir, 'webr-viewer-jsonlite.json'), JSON.stringify(viewerLibrary.toString('base64')));
// The detached agent and the browser extension embed the same R viewer
// helpers as sess. The Node test build reads the generated resource directly.
const viewerSource = ['dispatch.R', 'handlers.R', 'inspection_call.R', 'interactive_viewers.R']
.map(file => fs.readFileSync(path.join(__dirname, 'sess', 'R', file), 'utf8'))
.join('\n');
fs.writeFileSync(path.join(destDir, 'webr-viewers.json'), JSON.stringify(viewerSource));
console.log('Resources copied.');
}

Expand Down
40 changes: 40 additions & 0 deletions scripts/update-webr-viewer-jsonlite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Regenerate the small offline viewer dependency from vscode-R's pinned webR package."""
import argparse
import gzip
import hashlib
import io
import json
from pathlib import Path
import tarfile
from urllib.request import urlopen

root = Path(__file__).resolve().parents[1]
packages = json.loads((root / "src/webr/packages.json").read_text())
package = next(entry for entry in packages if entry["name"] == "jsonlite")
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("archive", nargs="?", type=Path, help="use a local copy of the official archive")
args = parser.parse_args()
if args.archive:
original = args.archive.read_bytes()
else:
with urlopen(package["url"], timeout=60) as response:
original = response.read()
if hashlib.sha256(original).hexdigest() != package["sha256"]:
raise SystemExit("The archive does not match src/webr/packages.json")

# Preserve the namespace, lazy-load databases and compiled Wasm routines.
# Package help, examples and vignettes are available from the full distribution.
metadata = {"jsonlite/DESCRIPTION", "jsonlite/LICENSE", "jsonlite/NAMESPACE"}
directories = ("jsonlite/Meta/", "jsonlite/R/", "jsonlite/libs/")
out = root / "src/webr/resources/viewer-jsonlite.tgz"
with tarfile.open(fileobj=io.BytesIO(original), mode="r:gz") as source, out.open("wb") as stream:
with gzip.GzipFile(filename="", fileobj=stream, mode="wb", mtime=0) as compressed:
with tarfile.open(fileobj=compressed, mode="w", format=tarfile.USTAR_FORMAT) as target:
for member in sorted(source.getmembers(), key=lambda entry: entry.name):
if member.name not in metadata and not member.name.startswith(directories):
continue
if member.isfile():
entry = tarfile.TarInfo(member.name)
entry.size = member.size
target.addfile(entry, source.extractfile(member))
print(out)
106 changes: 0 additions & 106 deletions sess/R/hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,112 +110,6 @@ runtime_start <- function(
.runtime_set_field("dataview_registry", new.env(parent = emptyenv()))
}

show_dataview <- function(x, title = deparse(substitute(x))) {
# Capture the root before forcing x so View(x$a) shares the viewer for x.
original_expression <- substitute(x)
expression <- original_expression
while (
is.call(expression) &&
is.symbol(expression[[1L]]) &&
as.character(expression[[1L]]) %in% c("$", "[[", "@")
) {
expression <- expression[[2L]]
}
owner <- .sess_env$view_owner
if (is.null(owner) && missing(title) && is.symbol(expression)) {
owner <- as.character(expression)
}
force(title)
# Resolve the variable behind View(<symbol>) before x is forced, so jdv can
# follow it. The lookup starts at the caller, never at this function's frame.
tracked_binding <- .jdv_track_binding(original_expression, parent.frame())

view_type <- if (dataview_is_table(x)) {
"table"
} else if (listview_supported(x)) {
"list"
} else {
"object"
}
title_key <- paste(as.character(title), collapse = "\n")
if (
(view_type %in% c("table", "list") || .jdv_is_arrow(x)) &&
.jdv_show(x, title_key, tracked_binding)
) {
return(invisible(NULL))
}
# Explicit View() in Interactive should open the normal data viewer when
# jdv is available. Inline rich output remains the fallback when it is not.
if (
is.null(.sess_env$view_owner) &&
isTRUE(.sess_env$interactive_connected) &&
.interactive_rich_value(x)
) {
return(invisible(NULL))
}
owner <- owner %||% title_key
registry_key <- paste0(view_type, ":", owner)
dataview_registry <- .sess_env$dataview_registry
view_id <- if (
nzchar(title_key) && exists(registry_key, envir = dataview_registry, inherits = FALSE)
) {
get(registry_key, envir = dataview_registry, inherits = FALSE)
} else {
id <- dataview_new_id()
if (nzchar(title_key)) {
assign(registry_key, id, envir = dataview_registry)
}
id
}

if (view_type == "table") {
registration <- dataview_register(x, view_id = view_id)

notify_client(
"dataview",
list(
title = title,
source = "table",
type = "json",
view_id = registration$view_id,
state_generation = registration$state_generation
)
)
} else if (view_type == "list") {
context <- .sess_env$listview_context
if (is.null(context) && missing(title)) {
context <- listview_expression_context(original_expression, parent.frame(), owner, x)
}
root <- if (is.null(context)) listview_state(x, title_key, owner) else context$root
navigation <- if (is.null(context)) {
listview_navigation(listview_location(root))
} else {
context$navigation
}
root <- dataview_set_state(view_id, root)
notify_client(
"dataview",
list(
title = title,
source = view_type,
type = "json",
view_id = view_id,
state_generation = root$state_generation,
navigation = navigation
)
)
} else {
code <- if (is.primitive(x)) utils::capture.output(print(x)) else deparse(x)
file_path <- .sess_env$dataviews[[view_id]]$file %||%
tempfile(tmpdir = .sess_env$tempdir, fileext = ".R")
writeLines(code, file_path)
.sess_env$dataviews[[view_id]] <- list(type = "object", file = file_path)
notify_client(
"dataview",
list(title = title, file = file_path, source = "object", type = "R")
)
}
}
.runtime_rebind("View", show_dataview, ns = "utils")

# 2. Browser & Webview Options
Expand Down
Loading
Loading