From f72f045de586a7d0e428b77f6a3e381178cc6674 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Mon, 20 Apr 2020 21:30:52 +0300 Subject: [PATCH] std/node: require_ -> require (#4828) --- std/node/README.md | 8 ++++---- std/node/module.ts | 8 ++++---- std/node/module_test.ts | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/std/node/README.md b/std/node/README.md index 1c561be4f4..bbd1688254 100644 --- a/std/node/README.md +++ b/std/node/README.md @@ -74,11 +74,11 @@ modules. ```ts import { createRequire } from "https://deno.land/std/node/module.ts"; -const require_ = createRequire(import.meta.url); +const require = createRequire(import.meta.url); // Loads native module polyfill. -const path = require_("path"); +const path = require("path"); // Loads extensionless module. -const cjsModule = require_("./my_mod"); +const cjsModule = require("./my_mod"); // Visits node_modules. -const leftPad = require_("left-pad"); +const leftPad = require("left-pad"); ``` diff --git a/std/node/module.ts b/std/node/module.ts index 138cf916e0..b7a0107d02 100644 --- a/std/node/module.ts +++ b/std/node/module.ts @@ -510,10 +510,10 @@ class Module { * with `node_modules` lookup and `index.js` lookup support. * Also injects available Node.js builtin module polyfills. * - * const require_ = createRequire(import.meta.url); - * const fs = require_("fs"); - * const leftPad = require_("left-pad"); - * const cjsModule = require_("./cjs_mod"); + * const require = createRequire(import.meta.url); + * const fs = require("fs"); + * const leftPad = require("left-pad"); + * const cjsModule = require("./cjs_mod"); * * @param filename path or URL to current module * @return Require function to import CJS modules diff --git a/std/node/module_test.ts b/std/node/module_test.ts index be36a8b6d2..590172a7aa 100644 --- a/std/node/module_test.ts +++ b/std/node/module_test.ts @@ -1,14 +1,14 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ + const { test } = Deno; import { assertEquals, assert, assertStrContains } from "../testing/asserts.ts"; import { createRequire } from "./module.ts"; -// TS compiler would try to resolve if function named "require" -// Thus suffixing it with require_ to fix this... -const require_ = createRequire(import.meta.url); +const require = createRequire(import.meta.url); test(function requireSuccess() { // Relative to import.meta.url - const result = require_("./tests/cjs/cjs_a.js"); + const result = require("./tests/cjs/cjs_a.js"); assert("helloA" in result); assert("helloB" in result); assert("C" in result); @@ -20,16 +20,16 @@ test(function requireSuccess() { }); test(function requireCycle() { - const resultA = require_("./tests/cjs/cjs_cycle_a"); - const resultB = require_("./tests/cjs/cjs_cycle_b"); + const resultA = require("./tests/cjs/cjs_cycle_a"); + const resultB = require("./tests/cjs/cjs_cycle_b"); assert(resultA); assert(resultB); }); test(function requireBuiltin() { - const fs = require_("fs"); + const fs = require("fs"); assert("readFileSync" in fs); - const { readFileSync, isNull, extname } = require_("./tests/cjs/cjs_builtin"); + const { readFileSync, isNull, extname } = require("./tests/cjs/cjs_builtin"); assertEquals( readFileSync("./node/_fs/testdata/hello.txt", { encoding: "utf8" }), "hello world" @@ -39,18 +39,18 @@ test(function requireBuiltin() { }); test(function requireIndexJS() { - const { isIndex } = require_("./tests/cjs"); + const { isIndex } = require("./tests/cjs"); assert(isIndex); }); test(function requireNodeOs() { - const os = require_("os"); + const os = require("os"); assert(os.arch); assert(typeof os.arch() == "string"); }); test(function requireStack() { - const { hello } = require_("./tests/cjs/cjs_throw"); + const { hello } = require("./tests/cjs/cjs_throw"); try { hello(); } catch (e) {