From e55b448730160a6e4df9815a268d4049ac89deab Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Fri, 17 Mar 2023 12:22:15 -0600 Subject: feat(core) deno_core::extension! macro to simplify extension registration (#18210) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This implements two macros to simplify extension registration and centralize a lot of the boilerplate as a base for future improvements: * `deno_core::ops!` registers a block of `#[op]`s, optionally with type parameters, useful for places where we share lists of ops * `deno_core::extension!` is used to register an extension, and creates two methods that can be used at runtime/snapshot generation time: `init_ops` and `init_ops_and_esm`. --------- Co-authored-by: Bartek IwaƄczuk --- ext/console/lib.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'ext/console/lib.rs') diff --git a/ext/console/lib.rs b/ext/console/lib.rs index a9a30c328..a45b856cd 100644 --- a/ext/console/lib.rs +++ b/ext/console/lib.rs @@ -1,22 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. - -use deno_core::include_js_files; -use deno_core::Extension; -use deno_core::ExtensionBuilder; use std::path::PathBuf; -fn ext() -> ExtensionBuilder { - Extension::builder(env!("CARGO_PKG_NAME")) -} -pub fn init() -> Extension { - ext().build() -} - -pub fn init_esm() -> Extension { - ext() - .esm(include_js_files!("01_colors.js", "02_console.js",)) - .build() -} +deno_core::extension!(deno_console, esm = ["01_colors.js", "02_console.js"],); pub fn get_declaration() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_console.d.ts") -- cgit v1.2.3