diff --git a/BUILD.gn b/BUILD.gn index ee3caab5c0..32d1b527c1 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 797659de09..fa50c05151 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 #include #include @@ -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); }