Skip to content

Instantly share code, notes, and snippets.

@ry
Created August 10, 2018 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ry/e35a9f1ddb40e323f0e3ee3d5f66148d to your computer and use it in GitHub Desktop.
Save ry/e35a9f1ddb40e323f0e3ee3d5f66148d to your computer and use it in GitHub Desktop.
From b6877e4d47f473b4185b317d9310470093bfcca5 Mon Sep 17 00:00:00 2001
From: Ryan Dahl <ry@tinyclouds.org>
Date: Fri, 10 Aug 2018 11:32:00 -0400
Subject: [PATCH] Enable source map support for deno_ns
---
BUILD.gn | 13 ++++++++++---
src/from_filesystem.cc | 10 +++++++++-
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/BUILD.gn b/BUILD.gn
index ee3caab..32d1b52 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -321,6 +321,11 @@ run_node("bundle") {
}
source_set("libdeno_nosnapshot") {
+ bundle_outputs = get_target_outputs(":bundle")
+ bundle_location = rebase_path(bundle_outputs[0])
+ bundle_rel_location = rebase_path(bundle_outputs[0], root_build_dir)
+ bundle_map_location = rebase_path(bundle_outputs[1])
+ inputs = bundle_outputs
sources = [
"src/from_filesystem.cc",
]
@@ -329,9 +334,11 @@ source_set("libdeno_nosnapshot") {
":deno_bindings",
]
configs += [ ":deno_config" ]
- bundle_outputs = get_target_outputs(":bundle")
- bundle_location = rebase_path(bundle_outputs[0])
- defines = [ "BUNDLE_LOCATION=\"$bundle_location\"" ]
+ defines = [
+ "BUNDLE_LOCATION=\"$bundle_location\"",
+ "BUNDLE_REL_LOCATION=\"$bundle_rel_location\"",
+ "BUNDLE_MAP_LOCATION=\"$bundle_map_location\"",
+ ]
}
ts_flatbuffer("msg_ts") {
diff --git a/src/from_filesystem.cc b/src/from_filesystem.cc
index 797659d..fa50c05 100644
--- a/src/from_filesystem.cc
+++ b/src/from_filesystem.cc
@@ -1,4 +1,5 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
+// This file is used to load the bundle at start for deno_ns.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -17,6 +18,9 @@ Deno* NewFromFileSystem(void* data, deno_recv_cb cb) {
std::string js_source;
CHECK(deno::ReadFileToString(BUNDLE_LOCATION, &js_source));
+ std::string js_source_map;
+ CHECK(deno::ReadFileToString(BUNDLE_MAP_LOCATION, &js_source_map));
+
Deno* d = new Deno;
d->currentArgs = nullptr;
d->cb = cb;
@@ -32,7 +36,11 @@ Deno* NewFromFileSystem(void* data, deno_recv_cb cb) {
{
v8::HandleScope handle_scope(isolate);
auto context = v8::Context::New(isolate);
- InitializeContext(isolate, context, BUNDLE_LOCATION, js_source, nullptr);
+ // BUNDLE_LOCATION is absolute so deno_ns can load the bundle independently
+ // of the cwd. However for source maps to work, the bundle location relative
+ // to the build path must be supplied: BUNDLE_REL_LOCATION.
+ InitializeContext(isolate, context, BUNDLE_REL_LOCATION, js_source,
+ &js_source_map);
d->context.Reset(d->isolate, context);
}
--
2.15.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment