Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] build: add cargo feature to drop various tools #8381

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d49ccda
Feature gate tools
bartlomieju Nov 14, 2020
2531c45
Temp
bartlomieju Nov 14, 2020
9e82c61
dedup
bartlomieju Nov 14, 2020
d689693
more feature gating
bartlomieju Nov 14, 2020
d630f3b
format
bartlomieju Nov 14, 2020
cc4f148
Merge branch 'master' into cargo_features
bartlomieju Nov 14, 2020
85ae68b
rename
bartlomieju Nov 14, 2020
ffe81e7
fix
bartlomieju Nov 14, 2020
8188dcc
temp
bartlomieju Nov 15, 2020
3e90841
Merge branch 'master' into cargo_features
bartlomieju Nov 17, 2020
bef9b85
fmt and lint
bartlomieju Nov 17, 2020
1f8a821
strip more
bartlomieju Nov 17, 2020
858b966
lint
bartlomieju Nov 18, 2020
20abe7a
Merge branch 'master' into cargo_features
bartlomieju Nov 19, 2020
3465d6b
fix
bartlomieju Nov 19, 2020
8dda9d7
Merge branch 'master' into cargo_features
bartlomieju Nov 20, 2020
3a4aaab
remove cfg from inspector
bartlomieju Nov 20, 2020
b696cc5
Merge branch 'master' into cargo_features
bartlomieju Nov 22, 2020
fdc131c
reorg imports
bartlomieju Nov 22, 2020
954def6
wildcard match
bartlomieju Nov 22, 2020
a2780c4
reorg main.rs
bartlomieju Nov 22, 2020
d4b5ca2
remove unwrap
bartlomieju Nov 22, 2020
9d53924
Merge branch 'master' into cargo_features
bartlomieju Nov 25, 2020
b4c3289
Merge branch 'master' into cargo_features
bartlomieju Nov 25, 2020
08c2c15
fix
bartlomieju Nov 25, 2020
ee97a22
Merge branch 'master' into cargo_features
bartlomieju Nov 26, 2020
20fc996
fixes
bartlomieju Nov 26, 2020
470e9c4
fixes
bartlomieju Nov 26, 2020
78ef2a3
Merge branch 'master' into cargo_features
bartlomieju Nov 27, 2020
c8239c9
Merge branch 'master' into cargo_features
bartlomieju Nov 28, 2020
fc67677
Merge branch 'master' into cargo_features
bartlomieju Nov 28, 2020
9d70130
fmt
bartlomieju Nov 28, 2020
93b3a5c
factor out lib
bartlomieju Nov 28, 2020
aa8a1f0
lint
bartlomieju Nov 28, 2020
3e885d4
add basic ci check for "no-tools" mode
bartlomieju Nov 28, 2020
2eee3b2
dont remap stack trace if no tools
bartlomieju Nov 28, 2020
623faaa
Merge branch 'master' into cargo_features
bartlomieju Nov 30, 2020
f9c8251
Merge branch 'master' into cargo_features
bartlomieju Dec 1, 2020
259e849
lint notools
bartlomieju Dec 1, 2020
c4923d3
Merge branch 'master' into cargo_features
bartlomieju Dec 2, 2020
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
Prev Previous commit
Next Next commit
Merge branch 'master' into cargo_features
  • Loading branch information
bartlomieju committed Nov 30, 2020
commit 623faaa202e94d48a1830b2a3abb8c3d4f2406a7
10 changes: 5 additions & 5 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ winapi = "0.3.9"
[dependencies]
deno_crypto = { path = "../op_crates/crypto", version = "0.3.0" }
deno_core = { path = "../core", version = "0.69.0" }
deno_doc = { version = "0.1.16", optional = true }
deno_lint = { version = "0.2.11", optional = true }
deno_doc = { version = "0.1.17", optional = true }
deno_lint = { version = "0.2.12", optional = true }
deno_web = { path = "../op_crates/web", version = "0.20.0" }
deno_fetch = { path = "../op_crates/fetch", version = "0.12.0" }

Expand All @@ -55,7 +55,7 @@ clap = "2.33.3"
dissimilar = "1.0.2"
dlopen = "0.1.8"
encoding_rs = "0.8.24"
dprint-plugin-typescript = { version = "0.32.9", optional = true }
dprint-plugin-typescript = { version = "0.35.0", optional = true }
filetime = "0.2.12"
http = "0.2.1"
indexmap = "1.6.0"
Expand All @@ -74,8 +74,8 @@ shell-escape = "0.1.5"
sys-info = "0.7.0"
sourcemap = "6.0.1"
swc_bundler = { version = "=0.17.1", optional = true }
swc_common = { version = "=0.10.5", features = ["sourcemap"], optional = true }
swc_ecmascript = { version = "=0.14.1", features = ["codegen", "dep_graph", "parser", "react", "transforms", "visit"], optional = true }
swc_common = { version = "0.10.6", features = ["sourcemap"], optional = true }
swc_ecmascript = { version = "0.14.4", features = ["codegen", "dep_graph", "parser", "react", "transforms", "visit"], optional = true }
tempfile = "3.1.0"
termcolor = "1.1.0"
tokio = { version = "0.2.22", features = ["full"] }
Expand Down
167 changes: 129 additions & 38 deletions cli/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod permissions;
pub mod program_state;
pub mod resolve_addr;
pub mod signal;
pub mod standalone;
pub mod text_encoding;
pub mod tokio_util;
pub mod version;
Expand Down Expand Up @@ -169,6 +170,61 @@ pub fn get_types(unstable: bool) -> String {
types
}

#[cfg(feature = "tools")]
pub async fn compile_command(
flags: Flags,
source_file: String,
out_file: Option<String>,
) -> Result<(), AnyError> {
if !flags.unstable {
exit_unstable("compile");
}

let debug = flags.log_level == Some(log::Level::Debug);

let module_specifier = ModuleSpecifier::resolve_url_or_path(&source_file)?;
let program_state = ProgramState::new(flags.clone())?;

let out_file = out_file.or_else(|| {
tools::installer::infer_name_from_url(module_specifier.as_url())
});
let out_file = match out_file {
Some(out_file) => out_file,
None => return Err(generic_error(
"An executable name was not provided. One could not be inferred from the URL. Aborting.",
)),
};

let module_graph = create_module_graph_and_maybe_check(
module_specifier.clone(),
program_state.clone(),
debug,
)
.await?;

info!(
"{} {}",
colors::green("Bundle"),
module_specifier.to_string()
);
let bundle_str = bundle_module_graph(module_graph, flags, debug)?;

info!(
"{} {}",
colors::green("Compile"),
module_specifier.to_string()
);
standalone::create_standalone_binary(
bundle_str.as_bytes().to_vec(),
out_file.clone(),
)
.await?;

info!("{} {}", colors::green("Emit"), out_file);

Ok(())
}

#[cfg(feature = "tools")]
pub async fn info_command(
flags: Flags,
Expand Down Expand Up @@ -324,6 +380,73 @@ pub async fn eval_command(
Ok(())
}

async fn create_module_graph_and_maybe_check(
module_specifier: ModuleSpecifier,
program_state: Arc<ProgramState>,
debug: bool,
) -> Result<module_graph::Graph, AnyError> {
let handler = Rc::new(RefCell::new(FetchHandler::new(
&program_state,
// when bundling, dynamic imports are only access for their type safety,
// therefore we will allow the graph to access any module.
Permissions::allow_all(),
)?));
let mut builder = module_graph::GraphBuilder::new(
handler,
program_state.maybe_import_map.clone(),
program_state.lockfile.clone(),
);
builder.add(&module_specifier, false).await?;
let module_graph = builder.get_graph();

if !program_state.flags.no_check {
// TODO(@kitsonk) support bundling for workers
let lib = if program_state.flags.unstable {
module_graph::TypeLib::UnstableDenoWindow
} else {
module_graph::TypeLib::DenoWindow
};
let result_info =
module_graph.clone().check(module_graph::CheckOptions {
debug,
emit: false,
lib,
maybe_config_path: program_state.flags.config_path.clone(),
reload: program_state.flags.reload,
})?;

debug!("{}", result_info.stats);
if let Some(ignored_options) = result_info.maybe_ignored_options {
eprintln!("{}", ignored_options);
}
if !result_info.diagnostics.is_empty() {
return Err(generic_error(result_info.diagnostics.to_string()));
}
}

Ok(module_graph)
}

fn bundle_module_graph(
module_graph: module_graph::Graph,
flags: Flags,
debug: bool,
) -> Result<String, AnyError> {
let (bundle, stats, maybe_ignored_options) =
module_graph.bundle(module_graph::BundleOptions {
debug,
maybe_config_path: flags.config_path,
})?;
match maybe_ignored_options {
Some(ignored_options) if flags.no_check => {
eprintln!("{}", ignored_options);
}
_ => {}
}
debug!("{}", stats);
Ok(bundle)
}

#[cfg(feature = "tools")]
pub async fn bundle_command(
flags: Flags,
Expand All @@ -349,44 +472,12 @@ pub async fn bundle_command(
module_specifier.to_string()
);

let handler = Rc::new(RefCell::new(FetchHandler::new(
&program_state,
// when bundling, dynamic imports are only access for their type safety,
// therefore we will allow the graph to access any module.
Permissions::allow_all(),
)?));
let mut builder = module_graph::GraphBuilder::new(
handler,
program_state.maybe_import_map.clone(),
program_state.lockfile.clone(),
);
builder.add(&module_specifier, false).await?;
let module_graph = builder.get_graph();

if !flags.no_check {
// TODO(@kitsonk) support bundling for workers
let lib = if flags.unstable {
module_graph::TypeLib::UnstableDenoWindow
} else {
module_graph::TypeLib::DenoWindow
};
let result_info =
module_graph.clone().check(module_graph::CheckOptions {
debug,
emit: false,
lib,
maybe_config_path: flags.config_path.clone(),
reload: flags.reload,
})?;

debug!("{}", result_info.stats);
if let Some(ignored_options) = result_info.maybe_ignored_options {
eprintln!("{}", ignored_options);
}
if !result_info.diagnostics.is_empty() {
return Err(generic_error(result_info.diagnostics.to_string()));
}
}
let module_graph = create_module_graph_and_maybe_check(
module_specifier,
program_state.clone(),
debug,
)
.await?;

let mut paths_to_watch: Vec<PathBuf> = module_graph
.get_modules()
Expand Down
5 changes: 5 additions & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ pub fn main() {
colors::enable_ansi(); // For Windows 10

let args: Vec<String> = env::args().collect();
if let Err(err) = deno::standalone::try_run_standalone_binary(args.clone()) {
eprintln!("{}: {}", colors::red_bold("error"), err.to_string());
std::process::exit(1);
}

let flags = flags::flags_from_vec(args);
if let Some(ref v8_flags) = flags.v8_flags {
init_v8_flags(v8_flags);
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.