summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-04-25 21:54:57 +0100
committerGitHub <noreply@github.com>2021-04-26 06:54:57 +1000
commitfb1ccc3d8898e71f068a3d2e2b0e5f1da5731444 (patch)
tree136206913b6ab45daaf097439f4d3640e0746fd4
parent83bece56b01f6997cb71e9289a4d83a398cde0c8 (diff)
refactor(cli): rename Deno.emit() bundle options to "module" and "classic" (#10332)
-rw-r--r--cli/dts/lib.deno.unstable.d.ts8
-rw-r--r--cli/module_graph.rs23
-rw-r--r--cli/ops/runtime_compiler.rs12
-rw-r--r--cli/tests/compiler_api_test.ts16
-rw-r--r--docs/typescript/runtime.md18
-rw-r--r--runtime/js/40_compiler_api.js12
6 files changed, 46 insertions, 43 deletions
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts
index 908c433bf..d955a825f 100644
--- a/cli/dts/lib.deno.unstable.d.ts
+++ b/cli/dts/lib.deno.unstable.d.ts
@@ -441,10 +441,10 @@ declare namespace Deno {
*/
export interface EmitOptions {
/** Indicate that the source code should be emitted to a single file
- * JavaScript bundle that is a single ES module (`"esm"`) or a single file
- * self contained script we executes in an immediately invoked function
- * when loaded (`"iife"`). */
- bundle?: "esm" | "iife";
+ * JavaScript bundle that is a single ES module (`"module"`) or a single
+ * file self contained script we executes in an immediately invoked function
+ * when loaded (`"classic"`). */
+ bundle?: "module" | "classic";
/** If `true` then the sources will be typed checked, returning any
* diagnostic errors in the result. If `false` type checking will be
* skipped. Defaults to `true`.
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index 51e257339..93930c8a5 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -606,11 +606,11 @@ pub struct CheckOptions {
pub enum BundleType {
/// Return the emitted contents of the program as a single "flattened" ES
/// module.
- Esm,
+ Module,
/// Return the emitted contents of the program as a single script that
/// executes the program using an immediately invoked function execution
/// (IIFE).
- Iife,
+ Classic,
/// Do not bundle the emit, instead returning each of the modules that are
/// part of the program as individual files.
None,
@@ -776,8 +776,11 @@ impl Graph {
let maybe_ignored_options =
ts_config.merge_tsconfig(options.maybe_config_path)?;
- let s =
- self.emit_bundle(&root_specifier, &ts_config.into(), &BundleType::Esm)?;
+ let s = self.emit_bundle(
+ &root_specifier,
+ &ts_config.into(),
+ &BundleType::Module,
+ )?;
let stats = Stats(vec![
("Files".to_string(), self.modules.len() as u32),
("Total time".to_string(), start.elapsed().as_millis() as u32),
@@ -952,7 +955,7 @@ impl Graph {
"useDefineForClassFields": true,
}));
let opts = match options.bundle_type {
- BundleType::Esm | BundleType::Iife => json!({
+ BundleType::Module | BundleType::Classic => json!({
"noEmit": true,
}),
BundleType::None => json!({
@@ -993,7 +996,7 @@ impl Graph {
let graph = graph.lock().unwrap();
match options.bundle_type {
- BundleType::Esm | BundleType::Iife => {
+ BundleType::Module | BundleType::Classic => {
assert!(
response.emitted_files.is_empty(),
"No files should have been emitted from tsc."
@@ -1049,7 +1052,7 @@ impl Graph {
let start = Instant::now();
let mut emit_count = 0_u32;
match options.bundle_type {
- BundleType::Esm | BundleType::Iife => {
+ BundleType::Module | BundleType::Classic => {
assert_eq!(
self.roots.len(),
1,
@@ -1122,8 +1125,8 @@ impl Graph {
let loader = BundleLoader::new(self, emit_options, &globals, cm.clone());
let hook = Box::new(BundleHook);
let module = match bundle_type {
- BundleType::Esm => swc_bundler::ModuleType::Es,
- BundleType::Iife => swc_bundler::ModuleType::Iife,
+ BundleType::Module => swc_bundler::ModuleType::Es,
+ BundleType::Classic => swc_bundler::ModuleType::Iife,
_ => unreachable!("invalid bundle type"),
};
let bundler = swc_bundler::Bundler::new(
@@ -2381,7 +2384,7 @@ pub mod tests {
let (emitted_files, result_info) = graph
.emit(EmitOptions {
check: true,
- bundle_type: BundleType::Esm,
+ bundle_type: BundleType::Module,
debug: false,
maybe_user_config: None,
})
diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs
index dc9cd2163..4865c1045 100644
--- a/cli/ops/runtime_compiler.rs
+++ b/cli/ops/runtime_compiler.rs
@@ -33,10 +33,10 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
#[derive(Debug, Deserialize)]
enum RuntimeBundleType {
- #[serde(rename = "esm")]
- Esm,
- #[serde(rename = "iife")]
- Iife,
+ #[serde(rename = "module")]
+ Module,
+ #[serde(rename = "classic")]
+ Classic,
}
#[derive(Debug, Deserialize)]
@@ -108,8 +108,8 @@ async fn op_emit(
))
})?;
let bundle_type = match args.bundle {
- Some(RuntimeBundleType::Esm) => BundleType::Esm,
- Some(RuntimeBundleType::Iife) => BundleType::Iife,
+ Some(RuntimeBundleType::Module) => BundleType::Module,
+ Some(RuntimeBundleType::Classic) => BundleType::Classic,
None => BundleType::None,
};
let graph = builder.get_graph();
diff --git a/cli/tests/compiler_api_test.ts b/cli/tests/compiler_api_test.ts
index 427d3af54..04a4675b8 100644
--- a/cli/tests/compiler_api_test.ts
+++ b/cli/tests/compiler_api_test.ts
@@ -173,12 +173,12 @@ Deno.test({
});
Deno.test({
- name: "Deno.emit() - bundle esm - with sources",
+ name: "Deno.emit() - bundle as module script - with sources",
async fn() {
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
"/foo.ts",
{
- bundle: "esm",
+ bundle: "module",
sources: {
"/foo.ts": `export * from "./bar.ts";\n`,
"/bar.ts": `export const bar = "bar";\n`,
@@ -194,12 +194,12 @@ Deno.test({
});
Deno.test({
- name: "Deno.emit() - bundle esm - no sources",
+ name: "Deno.emit() - bundle as module script - no sources",
async fn() {
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
"./subdir/mod1.ts",
{
- bundle: "esm",
+ bundle: "module",
},
);
assertEquals(diagnostics.length, 0);
@@ -211,12 +211,12 @@ Deno.test({
});
Deno.test({
- name: "Deno.emit() - bundle esm - include js modules",
+ name: "Deno.emit() - bundle as module script - include js modules",
async fn() {
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
"/foo.js",
{
- bundle: "esm",
+ bundle: "module",
sources: {
"/foo.js": `export * from "./bar.js";\n`,
"/bar.js": `export const bar = "bar";\n`,
@@ -321,10 +321,10 @@ Deno.test({
});
Deno.test({
- name: `Deno.emit() - bundle supports iife`,
+ name: `Deno.emit() - bundle as classic script iife`,
async fn() {
const { diagnostics, files } = await Deno.emit("/a.ts", {
- bundle: "iife",
+ bundle: "classic",
sources: {
"/a.ts": `import { b } from "./b.ts";
console.log(b);`,
diff --git a/docs/typescript/runtime.md b/docs/typescript/runtime.md
index aa45b2521..c672dafd8 100644
--- a/docs/typescript/runtime.md
+++ b/docs/typescript/runtime.md
@@ -23,10 +23,10 @@ The emit options are defined in the `Deno` namespace as:
```ts
interface EmitOptions {
/** Indicate that the source code should be emitted to a single file
- * JavaScript bundle that is a single ES module (`"esm"`) or a single file
- * self contained script we executes in an immediately invoked function
- * when loaded (`"iife"`). */
- bundle?: "esm" | "iife";
+ * JavaScript bundle that is a single ES module (`"module"`) or a single
+ * file self contained script we executes in an immediately invoked function
+ * when loaded (`"classic"`). */
+ bundle?: "module" | "classic";
/** If `true` then the sources will be typed checked, returning any
* diagnostic errors in the result. If `false` type checking will be
* skipped. Defaults to `true`.
@@ -181,13 +181,13 @@ if (diagnostics.length) {
### Bundling
`Deno.emit()` is also capable of providing output similar to `deno bundle` on
-the command line. This is enabled by setting the _bundle_ option to `"esm"` or
-`"iife"`. Currently Deno supports bundling as a single file ES module (`"esm"`)
-or a single file self contained legacy script (`"iife"`).
+the command line. This is enabled by setting the _bundle_ option to `"module"`
+or `"classic"`. Currently Deno supports bundling as a single file ES module
+(`"module"`) or a single file self contained legacy script (`"classic"`).
```ts
const { files, diagnostics } = await Deno.emit("./mod.ts", {
- bundle: "esm",
+ bundle: "module",
});
```
@@ -215,7 +215,7 @@ version of _lodash_ I am using with my project. I could do the following:
```ts
const { files } = await Deno.emit("mod.ts", {
- bundle: "esm",
+ bundle: "module",
importMap: {
imports: {
"lodash": "https://deno.land/x/lodash",
diff --git a/runtime/js/40_compiler_api.js b/runtime/js/40_compiler_api.js
index b30ffc5d5..75c21b8dd 100644
--- a/runtime/js/40_compiler_api.js
+++ b/runtime/js/40_compiler_api.js
@@ -17,7 +17,7 @@
/**
* @typedef {object} OpEmitRequest
- * @property {"esm"=} bundle
+ * @property {"module" | "classic"=} bundle
* @property {boolean=} check
* @property {Record<string, any>=} compilerOptions
* @property {ImportMap=} importMap
@@ -35,7 +35,7 @@
*/
/**
- * @param {OpEmitRequest} request
+ * @param {OpEmitRequest} request
* @returns {Promise<OpEmitResponse>}
*/
function opEmit(request) {
@@ -43,7 +43,7 @@
}
/**
- * @param {string} specifier
+ * @param {string} specifier
* @returns {string}
*/
function checkRelative(specifier) {
@@ -54,7 +54,7 @@
/**
* @typedef {object} EmitOptions
- * @property {"esm"=} bundle
+ * @property {"module" | "classic"=} bundle
* @property {boolean=} check
* @property {Record<string, any>=} compilerOptions
* @property {ImportMap=} importMap
@@ -63,9 +63,9 @@
*/
/**
- * @param {string | URL} rootSpecifier
+ * @param {string | URL} rootSpecifier
* @param {EmitOptions=} options
- * @returns {Promise<OpEmitResponse>}
+ * @returns {Promise<OpEmitResponse>}
*/
function emit(rootSpecifier, options = {}) {
util.log(`Deno.emit`, { rootSpecifier });