Init asar support without external .js files
This commit is contained in:
parent
f905bb64f6
commit
45e2dd2ab5
6 changed files with 50 additions and 20 deletions
1
atom.gyp
1
atom.gyp
|
@ -56,6 +56,7 @@
|
||||||
],
|
],
|
||||||
'coffee2c_sources': [
|
'coffee2c_sources': [
|
||||||
'atom/common/lib/asar.coffee',
|
'atom/common/lib/asar.coffee',
|
||||||
|
'atom/common/lib/asar_init.coffee',
|
||||||
],
|
],
|
||||||
'lib_sources': [
|
'lib_sources': [
|
||||||
'atom/app/atom_content_client.cc',
|
'atom/app/atom_content_client.cc',
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "atom_natives.h"
|
||||||
#include "atom/common/asar/archive.h"
|
#include "atom/common/asar/archive.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "native_mate/arguments.h"
|
#include "native_mate/arguments.h"
|
||||||
|
#include "native_mate/callback.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "native_mate/wrappable.h"
|
#include "native_mate/wrappable.h"
|
||||||
|
@ -106,10 +108,33 @@ class Archive : public mate::Wrappable {
|
||||||
DISALLOW_COPY_AND_ASSIGN(Archive);
|
DISALLOW_COPY_AND_ASSIGN(Archive);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void InitAsarSupport(v8::Isolate* isolate,
|
||||||
|
v8::Handle<v8::Value> process,
|
||||||
|
v8::Handle<v8::Value> require) {
|
||||||
|
// Evaluate asar_init.coffee.
|
||||||
|
v8::Local<v8::Script> asar_init = v8::Script::Compile(v8::String::NewFromUtf8(
|
||||||
|
isolate,
|
||||||
|
node::asar_init_native,
|
||||||
|
v8::String::kNormalString,
|
||||||
|
sizeof(node::asar_init_native) -1));
|
||||||
|
v8::Local<v8::Value> result = asar_init->Run();
|
||||||
|
|
||||||
|
// Initialize asar support.
|
||||||
|
base::Callback<void(v8::Handle<v8::Value>,
|
||||||
|
v8::Handle<v8::Value>,
|
||||||
|
std::string)> init;
|
||||||
|
if (mate::ConvertFromV8(isolate, result, &init)) {
|
||||||
|
init.Run(process,
|
||||||
|
require,
|
||||||
|
std::string(node::asar_native, sizeof(node::asar_native) - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
||||||
v8::Handle<v8::Context> context, void* priv) {
|
v8::Handle<v8::Context> context, void* priv) {
|
||||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||||
dict.SetMethod("createArchive", &Archive::Create);
|
dict.SetMethod("createArchive", &Archive::Create);
|
||||||
|
dict.SetMethod("initAsarSupport", &InitAsarSupport);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
asar = process.atomBinding 'asar'
|
asar = process.binding 'atom_common_asar'
|
||||||
child_process = require 'child_process'
|
child_process = require 'child_process'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
util = require 'util'
|
util = require 'util'
|
||||||
|
|
22
atom/common/lib/asar_init.coffee
Normal file
22
atom/common/lib/asar_init.coffee
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
return (process, require, asarSource) ->
|
||||||
|
{createArchive} = process.binding 'atom_common_asar'
|
||||||
|
|
||||||
|
# Make asar.coffee accessible via "require".
|
||||||
|
process.binding('natives').ATOM_SHELL_ASAR = asarSource
|
||||||
|
|
||||||
|
# Monkey-patch the fs module.
|
||||||
|
require('ATOM_SHELL_ASAR').wrapFsWithAsar require('fs')
|
||||||
|
|
||||||
|
# Make graceful-fs work with asar.
|
||||||
|
source = process.binding 'natives'
|
||||||
|
source.originalFs = source.fs
|
||||||
|
source.fs = """
|
||||||
|
var src = '(function (exports, require, module, __filename, __dirname) { ' +
|
||||||
|
process.binding('natives').originalFs +
|
||||||
|
' });';
|
||||||
|
var vm = require('vm');
|
||||||
|
var fn = vm.runInThisContext(src, { filename: 'fs.js' });
|
||||||
|
fn(exports, require, module);
|
||||||
|
var asar = require('ATOM_SHELL_ASAR');
|
||||||
|
asar.wrapFsWithAsar(exports);
|
||||||
|
"""
|
|
@ -35,21 +35,3 @@ global.clearImmediate = timers.clearImmediate
|
||||||
if process.type is 'browser'
|
if process.type is 'browser'
|
||||||
global.setTimeout = wrapWithActivateUvLoop timers.setTimeout
|
global.setTimeout = wrapWithActivateUvLoop timers.setTimeout
|
||||||
global.setInterval = wrapWithActivateUvLoop timers.setInterval
|
global.setInterval = wrapWithActivateUvLoop timers.setInterval
|
||||||
|
|
||||||
# Add support for asar packages.
|
|
||||||
asar = require './asar'
|
|
||||||
asar.wrapFsWithAsar fs
|
|
||||||
|
|
||||||
# Make graceful-fs work with asar.
|
|
||||||
source = process.binding 'natives'
|
|
||||||
source.originalFs = source.fs
|
|
||||||
source.fs = """
|
|
||||||
var src = '(function (exports, require, module, __filename, __dirname) { ' +
|
|
||||||
process.binding('natives').originalFs +
|
|
||||||
' });';
|
|
||||||
var vm = require('vm');
|
|
||||||
var fn = vm.runInThisContext(src, { filename: 'fs.js' });
|
|
||||||
fn(exports, require, module);
|
|
||||||
var asar = require(#{JSON.stringify(__dirname)} + '/asar');
|
|
||||||
asar.wrapFsWithAsar(exports);
|
|
||||||
"""
|
|
||||||
|
|
2
vendor/node
vendored
2
vendor/node
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 70498428ced2b8ae4ce020051f06d104b5c6c4de
|
Subproject commit 9cd0fad904c3ebf0af0aeec2097cad3e039a7c6d
|
Loading…
Reference in a new issue