Merge pull request #1136 from atom/no-js
Bundle all the .js files in asar archive
This commit is contained in:
commit
f1ad8836d1
7 changed files with 110 additions and 59 deletions
51
atom.gyp
51
atom.gyp
|
@ -625,40 +625,31 @@
|
||||||
{
|
{
|
||||||
'target_name': 'compile_coffee',
|
'target_name': 'compile_coffee',
|
||||||
'type': 'none',
|
'type': 'none',
|
||||||
'sources': [
|
'actions': [
|
||||||
'<@(coffee_sources)',
|
|
||||||
],
|
|
||||||
'rules': [
|
|
||||||
{
|
{
|
||||||
'rule_name': 'coffee',
|
'action_name': 'compile_coffee',
|
||||||
'extension': 'coffee',
|
'variables': {
|
||||||
|
'conditions': [
|
||||||
|
['OS=="mac"', {
|
||||||
|
'resources_path': '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources',
|
||||||
|
},{
|
||||||
|
'resources_path': '<(PRODUCT_DIR)/resources',
|
||||||
|
}],
|
||||||
|
],
|
||||||
|
},
|
||||||
'inputs': [
|
'inputs': [
|
||||||
'tools/compile-coffee.py',
|
'<@(coffee_sources)',
|
||||||
],
|
],
|
||||||
'conditions': [
|
'outputs': [
|
||||||
['OS=="mac"', {
|
'<(resources_path)/atom.asar',
|
||||||
'outputs': [
|
|
||||||
'<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
|
|
||||||
],
|
|
||||||
'action': [
|
|
||||||
'python',
|
|
||||||
'tools/compile-coffee.py',
|
|
||||||
'<(RULE_INPUT_PATH)',
|
|
||||||
'<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
|
|
||||||
],
|
|
||||||
},{ # OS=="mac"
|
|
||||||
'outputs': [
|
|
||||||
'<(PRODUCT_DIR)/resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
|
|
||||||
],
|
|
||||||
'action': [
|
|
||||||
'python',
|
|
||||||
'tools/compile-coffee.py',
|
|
||||||
'<(RULE_INPUT_PATH)',
|
|
||||||
'<(PRODUCT_DIR)/resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
|
|
||||||
],
|
|
||||||
}], # OS=="win" or OS=="linux"
|
|
||||||
],
|
],
|
||||||
},
|
'action': [
|
||||||
|
'python',
|
||||||
|
'tools/coffee2asar.py',
|
||||||
|
'<@(_outputs)',
|
||||||
|
'<@(_inputs)',
|
||||||
|
],
|
||||||
|
}
|
||||||
],
|
],
|
||||||
}, # target compile_coffee
|
}, # target compile_coffee
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,10 +3,6 @@ path = require 'path'
|
||||||
module = require 'module'
|
module = require 'module'
|
||||||
util = require 'util'
|
util = require 'util'
|
||||||
|
|
||||||
# Expose information of current process.
|
|
||||||
process.type = 'browser'
|
|
||||||
process.resourcesPath = path.resolve process.argv[1], '..', '..', '..', '..'
|
|
||||||
|
|
||||||
# We modified the original process.argv to let node.js load the atom.js,
|
# We modified the original process.argv to let node.js load the atom.js,
|
||||||
# we need to restore it here.
|
# we need to restore it here.
|
||||||
process.argv.splice 1, 1
|
process.argv.splice 1, 1
|
||||||
|
@ -21,7 +17,7 @@ process.argv.splice startMark, endMark - startMark + 1
|
||||||
# Add browser/api/lib to require's search paths,
|
# Add browser/api/lib to require's search paths,
|
||||||
# which contains javascript part of Atom's built-in libraries.
|
# which contains javascript part of Atom's built-in libraries.
|
||||||
globalPaths = module.globalPaths
|
globalPaths = module.globalPaths
|
||||||
globalPaths.push path.join process.resourcesPath, 'atom', 'browser', 'api', 'lib'
|
globalPaths.push path.resolve(__dirname, '..', 'api', 'lib')
|
||||||
|
|
||||||
# Import common settings.
|
# Import common settings.
|
||||||
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init')
|
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init')
|
||||||
|
|
|
@ -12,7 +12,7 @@ process.atomBinding = (name) ->
|
||||||
|
|
||||||
# Add common/api/lib to module search paths.
|
# Add common/api/lib to module search paths.
|
||||||
globalPaths = Module.globalPaths
|
globalPaths = Module.globalPaths
|
||||||
globalPaths.push path.join(process.resourcesPath, 'atom', 'common', 'api', 'lib')
|
globalPaths.push path.resolve(__dirname, '..', 'api', 'lib')
|
||||||
|
|
||||||
# setImmediate and process.nextTick makes use of uv_check and uv_prepare to
|
# setImmediate and process.nextTick makes use of uv_check and uv_prepare to
|
||||||
# run the callbacks, however since we only run uv loop on requests, the
|
# run the callbacks, however since we only run uv loop on requests, the
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "base/base_paths.h"
|
#include "base/base_paths.h"
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "native_mate/locker.h"
|
#include "native_mate/locker.h"
|
||||||
|
#include "native_mate/dictionary.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
|
@ -110,6 +112,20 @@ std::vector<std::string> String16VectorToStringVector(
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
base::FilePath GetResourcesPath(CommandLine* command_line, bool is_browser) {
|
||||||
|
base::FilePath exec_path(command_line->argv()[0]);
|
||||||
|
PathService::Get(base::FILE_EXE, &exec_path);
|
||||||
|
base::FilePath resources_path =
|
||||||
|
#if defined(OS_MACOSX)
|
||||||
|
is_browser ? exec_path.DirName().DirName().Append("Resources") :
|
||||||
|
exec_path.DirName().DirName().DirName().DirName().DirName()
|
||||||
|
.Append("Resources");
|
||||||
|
#else
|
||||||
|
exec_path.DirName().Append(FILE_PATH_LITERAL("resources"));
|
||||||
|
#endif
|
||||||
|
return resources_path;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
node::Environment* global_env = nullptr;
|
node::Environment* global_env = nullptr;
|
||||||
|
@ -158,31 +174,25 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Feed node the path to initialization script.
|
// Feed node the path to initialization script.
|
||||||
base::FilePath exec_path(command_line->argv()[0]);
|
const char* process_type = is_browser_ ? "browser" : "renderer";
|
||||||
PathService::Get(base::FILE_EXE, &exec_path);
|
base::FilePath resources_path = GetResourcesPath(command_line, is_browser_);
|
||||||
base::FilePath resources_path =
|
|
||||||
#if defined(OS_MACOSX)
|
|
||||||
is_browser_ ? exec_path.DirName().DirName().Append("Resources") :
|
|
||||||
exec_path.DirName().DirName().DirName().DirName().DirName()
|
|
||||||
.Append("Resources");
|
|
||||||
#else
|
|
||||||
exec_path.DirName().Append(FILE_PATH_LITERAL("resources"));
|
|
||||||
#endif
|
|
||||||
base::FilePath script_path =
|
base::FilePath script_path =
|
||||||
resources_path.Append(FILE_PATH_LITERAL("atom"))
|
resources_path.Append(FILE_PATH_LITERAL("atom.asar"))
|
||||||
.Append(is_browser_ ? FILE_PATH_LITERAL("browser") :
|
.Append(FILE_PATH_LITERAL(process_type))
|
||||||
FILE_PATH_LITERAL("renderer"))
|
|
||||||
.Append(FILE_PATH_LITERAL("lib"))
|
.Append(FILE_PATH_LITERAL("lib"))
|
||||||
.Append(FILE_PATH_LITERAL("init.js"));
|
.Append(FILE_PATH_LITERAL("init.js"));
|
||||||
std::string script_path_str = script_path.AsUTF8Unsafe();
|
std::string script_path_str = script_path.AsUTF8Unsafe();
|
||||||
args.insert(args.begin() + 1, script_path_str.c_str());
|
args.insert(args.begin() + 1, script_path_str.c_str());
|
||||||
|
|
||||||
scoped_ptr<const char*[]> c_argv = StringVectorToArgArray(args);
|
scoped_ptr<const char*[]> c_argv = StringVectorToArgArray(args);
|
||||||
return node::CreateEnvironment(context->GetIsolate(),
|
node::Environment* env = node::CreateEnvironment(
|
||||||
uv_default_loop(),
|
context->GetIsolate(), uv_default_loop(), context,
|
||||||
context,
|
args.size(), c_argv.get(), 0, nullptr);
|
||||||
args.size(), c_argv.get(),
|
|
||||||
0, nullptr);
|
mate::Dictionary process(context->GetIsolate(), env->process_object());
|
||||||
|
process.Set("type", process_type);
|
||||||
|
process.Set("resourcesPath", resources_path);
|
||||||
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBindings::LoadEnvironment(node::Environment* env) {
|
void NodeBindings::LoadEnvironment(node::Environment* env) {
|
||||||
|
|
|
@ -4,10 +4,6 @@ path = require 'path'
|
||||||
url = require 'url'
|
url = require 'url'
|
||||||
Module = require 'module'
|
Module = require 'module'
|
||||||
|
|
||||||
# Expose information of current process.
|
|
||||||
process.type = 'renderer'
|
|
||||||
process.resourcesPath = path.resolve process.argv[1], '..', '..', '..', '..'
|
|
||||||
|
|
||||||
# We modified the original process.argv to let node.js load the
|
# We modified the original process.argv to let node.js load the
|
||||||
# atom-renderer.js, we need to restore it here.
|
# atom-renderer.js, we need to restore it here.
|
||||||
process.argv.splice 1, 1
|
process.argv.splice 1, 1
|
||||||
|
@ -15,9 +11,10 @@ process.argv.splice 1, 1
|
||||||
# Add renderer/api/lib to require's search paths, which contains javascript part
|
# Add renderer/api/lib to require's search paths, which contains javascript part
|
||||||
# of Atom's built-in libraries.
|
# of Atom's built-in libraries.
|
||||||
globalPaths = Module.globalPaths
|
globalPaths = Module.globalPaths
|
||||||
globalPaths.push path.join(process.resourcesPath, 'atom', 'renderer', 'api', 'lib')
|
globalPaths.push path.resolve(__dirname, '..', 'api', 'lib')
|
||||||
# And also app.
|
# And also app.
|
||||||
globalPaths.push path.join(process.resourcesPath, 'app')
|
globalPaths.push path.join(process.resourcesPath, 'app')
|
||||||
|
globalPaths.push path.join(process.resourcesPath, 'app.asar')
|
||||||
|
|
||||||
# Import common settings.
|
# Import common settings.
|
||||||
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init')
|
require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init')
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"atom-package-manager": "0.126.0",
|
"atom-package-manager": "0.126.0",
|
||||||
|
"asar": "0.2.2",
|
||||||
"coffee-script": "~1.7.1",
|
"coffee-script": "~1.7.1",
|
||||||
"coffeelint": "~1.3.0",
|
"coffeelint": "~1.3.0",
|
||||||
"request": "*"
|
"request": "*"
|
||||||
|
|
56
tools/coffee2asar.py
Executable file
56
tools/coffee2asar.py
Executable file
|
@ -0,0 +1,56 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
|
SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
archive = sys.argv[1]
|
||||||
|
coffee_source_files = sys.argv[2:]
|
||||||
|
|
||||||
|
output_dir = tempfile.mkdtemp()
|
||||||
|
compile_coffee(coffee_source_files, output_dir)
|
||||||
|
call_asar(archive, output_dir)
|
||||||
|
shutil.rmtree(output_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def compile_coffee(coffee_source_files, output_dir):
|
||||||
|
for source_file in coffee_source_files:
|
||||||
|
output_filename = os.path.splitext(source_file)[0] + '.js'
|
||||||
|
output_path = os.path.join(output_dir, output_filename)
|
||||||
|
call_compile_coffee(source_file, output_path)
|
||||||
|
|
||||||
|
|
||||||
|
def call_compile_coffee(source_file, output_filename):
|
||||||
|
compile_coffee = os.path.join(SOURCE_ROOT, 'tools', 'compile-coffee.py')
|
||||||
|
subprocess.check_call([sys.executable, compile_coffee, source_file,
|
||||||
|
output_filename])
|
||||||
|
|
||||||
|
|
||||||
|
def call_asar(archive, output_dir):
|
||||||
|
js_dir = os.path.join(output_dir, 'atom')
|
||||||
|
asar = os.path.join(SOURCE_ROOT, 'node_modules', 'asar', 'bin', 'asar')
|
||||||
|
subprocess.check_call([find_node(), asar, 'pack', js_dir, archive])
|
||||||
|
|
||||||
|
|
||||||
|
def find_node():
|
||||||
|
WINDOWS_NODE_PATHs = [
|
||||||
|
'C:/Program Files (x86)/nodejs',
|
||||||
|
'C:/Program Files/nodejs',
|
||||||
|
] + os.environ['PATH'].split(os.pathsep)
|
||||||
|
|
||||||
|
if sys.platform in ['win32', 'cygwin']:
|
||||||
|
for path in WINDOWS_NODE_PATHs:
|
||||||
|
full_path = os.path.join(path, 'node.exe')
|
||||||
|
if os.path.exists(full_path):
|
||||||
|
return full_path
|
||||||
|
return 'node'
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
Loading…
Reference in a new issue