From c160ea11e4ece4db52731ac8b83dd09ca2d1ef11 Mon Sep 17 00:00:00 2001 From: Oisin Canty Date: Mon, 24 May 2021 09:01:42 +0000 Subject: [PATCH] Node.js: renamed "require_shim" to "loader". --- docs/changes.xml | 2 +- src/nodejs/unit-http/{require_shim.js => loader.js} | 4 ++-- .../unit-http/{require_shim.mjs => loader.mjs} | 0 .../{require_shim => loader}/es_modules_http/app.mjs | 0 .../es_modules_http_indirect/app.js | 0 .../es_modules_http_indirect/module.mjs | 0 .../es_modules_websocket/app.mjs | 0 .../es_modules_websocket_indirect/app.js | 0 .../es_modules_websocket_indirect/module.mjs | 0 .../transitive_dependency/app.js | 0 .../transitive_dependency/transitive_http.js | 0 test/node/{require_shim => loader}/unit_http/app.js | 0 test/test_node_application.py | 8 ++++---- test/test_node_es_modules.py | 12 ++++++------ test/unit/applications/lang/node.py | 6 +++--- 15 files changed, 16 insertions(+), 16 deletions(-) rename src/nodejs/unit-http/{require_shim.js => loader.js} (86%) rename src/nodejs/unit-http/{require_shim.mjs => loader.mjs} (100%) rename test/node/{require_shim => loader}/es_modules_http/app.mjs (100%) rename test/node/{require_shim => loader}/es_modules_http_indirect/app.js (100%) rename test/node/{require_shim => loader}/es_modules_http_indirect/module.mjs (100%) rename test/node/{require_shim => loader}/es_modules_websocket/app.mjs (100%) rename test/node/{require_shim => loader}/es_modules_websocket_indirect/app.js (100%) rename test/node/{require_shim => loader}/es_modules_websocket_indirect/module.mjs (100%) rename test/node/{require_shim => loader}/transitive_dependency/app.js (100%) rename test/node/{require_shim => loader}/transitive_dependency/transitive_http.js (100%) rename test/node/{require_shim => loader}/unit_http/app.js (100%) diff --git a/docs/changes.xml b/docs/changes.xml index 528ab483..58181173 100644 --- a/docs/changes.xml +++ b/docs/changes.xml @@ -39,7 +39,7 @@ multiple "targets" in Python applications. -a shim for automatic overriding "http" and "websocket" modules in Node.js. +a loader for automatic overriding "http" and "websocket" modules in Node.js. diff --git a/src/nodejs/unit-http/require_shim.js b/src/nodejs/unit-http/loader.js similarity index 86% rename from src/nodejs/unit-http/require_shim.js rename to src/nodejs/unit-http/loader.js index 2b307629..e5aa3558 100644 --- a/src/nodejs/unit-http/require_shim.js +++ b/src/nodejs/unit-http/loader.js @@ -2,7 +2,7 @@ if (module.parent && module.parent.id === "internal/preload") { const { Module } = require("module") - if (!Module.prototype.require.__unit_shim) { + if (!Module.prototype.require.__unit_loader) { const http = require("./http") const websocket = require("./websocket") @@ -22,6 +22,6 @@ if (module.parent && module.parent.id === "internal/preload") { return original.apply(this, arguments); } - Module.prototype.require.__unit_shim = true; + Module.prototype.require.__unit_loader = true; } } diff --git a/src/nodejs/unit-http/require_shim.mjs b/src/nodejs/unit-http/loader.mjs similarity index 100% rename from src/nodejs/unit-http/require_shim.mjs rename to src/nodejs/unit-http/loader.mjs diff --git a/test/node/require_shim/es_modules_http/app.mjs b/test/node/loader/es_modules_http/app.mjs similarity index 100% rename from test/node/require_shim/es_modules_http/app.mjs rename to test/node/loader/es_modules_http/app.mjs diff --git a/test/node/require_shim/es_modules_http_indirect/app.js b/test/node/loader/es_modules_http_indirect/app.js similarity index 100% rename from test/node/require_shim/es_modules_http_indirect/app.js rename to test/node/loader/es_modules_http_indirect/app.js diff --git a/test/node/require_shim/es_modules_http_indirect/module.mjs b/test/node/loader/es_modules_http_indirect/module.mjs similarity index 100% rename from test/node/require_shim/es_modules_http_indirect/module.mjs rename to test/node/loader/es_modules_http_indirect/module.mjs diff --git a/test/node/require_shim/es_modules_websocket/app.mjs b/test/node/loader/es_modules_websocket/app.mjs similarity index 100% rename from test/node/require_shim/es_modules_websocket/app.mjs rename to test/node/loader/es_modules_websocket/app.mjs diff --git a/test/node/require_shim/es_modules_websocket_indirect/app.js b/test/node/loader/es_modules_websocket_indirect/app.js similarity index 100% rename from test/node/require_shim/es_modules_websocket_indirect/app.js rename to test/node/loader/es_modules_websocket_indirect/app.js diff --git a/test/node/require_shim/es_modules_websocket_indirect/module.mjs b/test/node/loader/es_modules_websocket_indirect/module.mjs similarity index 100% rename from test/node/require_shim/es_modules_websocket_indirect/module.mjs rename to test/node/loader/es_modules_websocket_indirect/module.mjs diff --git a/test/node/require_shim/transitive_dependency/app.js b/test/node/loader/transitive_dependency/app.js similarity index 100% rename from test/node/require_shim/transitive_dependency/app.js rename to test/node/loader/transitive_dependency/app.js diff --git a/test/node/require_shim/transitive_dependency/transitive_http.js b/test/node/loader/transitive_dependency/transitive_http.js similarity index 100% rename from test/node/require_shim/transitive_dependency/transitive_http.js rename to test/node/loader/transitive_dependency/transitive_http.js diff --git a/test/node/require_shim/unit_http/app.js b/test/node/loader/unit_http/app.js similarity index 100% rename from test/node/require_shim/unit_http/app.js rename to test/node/loader/unit_http/app.js diff --git a/test/test_node_application.py b/test/test_node_application.py index 59601ff0..48ed8d3d 100644 --- a/test/test_node_application.py +++ b/test/test_node_application.py @@ -19,13 +19,13 @@ class TestNodeApplication(TestApplicationNode): self.assert_basic_application() - def test_node_application_require_shim_unit_http(self): - self.load('require_shim/unit_http') + def test_node_application_loader_unit_http(self): + self.load('loader/unit_http') self.assert_basic_application() - def test_node_application_require_shim_transitive_dependency(self): - self.load('require_shim/transitive_dependency') + def test_node_application_loader_transitive_dependency(self): + self.load('loader/transitive_dependency') self.assert_basic_application() diff --git a/test/test_node_es_modules.py b/test/test_node_es_modules.py index ce27e474..0945a967 100644 --- a/test/test_node_es_modules.py +++ b/test/test_node_es_modules.py @@ -20,18 +20,18 @@ class TestNodeESModules(TestApplicationNode): assert resp['headers']['Content-Type'] == 'text/plain', 'basic header' assert resp['body'] == 'Hello World\n', 'basic body' - def test_node_es_modules_require_shim_http(self): - self.load('require_shim/es_modules_http', name="app.mjs") + def test_node_es_modules_loader_http(self): + self.load('loader/es_modules_http', name="app.mjs") self.assert_basic_application() - def test_node_es_modules_require_shim_http_indirect(self): - self.load('require_shim/es_modules_http_indirect', name="app.js") + def test_node_es_modules_loader_http_indirect(self): + self.load('loader/es_modules_http_indirect', name="app.js") self.assert_basic_application() - def test_node_es_modules_require_shim_websockets(self): - self.load('require_shim/es_modules_websocket', name="app.mjs") + def test_node_es_modules_loader_websockets(self): + self.load('loader/es_modules_websocket', name="app.mjs") message = 'blah' diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index 3254f3d4..5d05c70c 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -31,14 +31,14 @@ class TestApplicationNode(TestApplicationProto): arguments = [ "node", "--loader", - "unit-http/require_shim.mjs", + "unit-http/loader.mjs", "--require", - "unit-http/require_shim", + "unit-http/loader", name, ] else: - arguments = ["node", "--require", "unit-http/require_shim", name] + arguments = ["node", "--require", "unit-http/loader", name] self._load_conf( {