From 43ddbb67543bd9ce0dcb89353e0a15758792eff7 Mon Sep 17 00:00:00 2001 From: Zearin Date: Sat, 15 Apr 2023 15:07:34 -0400 Subject: [PATCH] chore: Use `node:` protocol in imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The official docs have used the prefix in examples for years. According to the NodeJS docs for [Modules (§Core Modules)](https://nodejs.org/dist/latest-v18.x/docs/api/modules.html#core-modules), the `node:` “protocol” was added in NodeJS v16.0.0 (initial release 2021-04-20; [source](https://nodejs.dev/en/about/releases/)) and (probably experimentally…?) v14.18.0 (released 2021-09-08; [source](https://nodejs.org/en/blog/release/v14.18.0)). Personally, I like how it makes it easy to distinguish 3rd party modules (no prefix) from core modules (`node:` prefix) and local modules (`./` or `../` prefix). --- src/ast.js | 4 ++-- src/componentManager.js | 4 ++-- src/fasterVmContext.cjs | 4 ++-- src/fsCache.js | 4 ++-- src/moduleResolution.js | 2 +- src/moduleScript.cjs | 4 ++-- src/path.js | 4 ++-- src/streams.js | 4 ++-- src/util.js | 4 ++-- webc.js | 8 ++++---- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/ast.js b/src/ast.js index ea47803..8d483be 100644 --- a/src/ast.js +++ b/src/ast.js @@ -1,5 +1,5 @@ -import path from "path"; -import os from "os"; +import path from "node:path"; +import os from "node:os"; import { DepGraph } from "dependency-graph"; import { WebC } from "../webc.js"; diff --git a/src/componentManager.js b/src/componentManager.js index 9cf9689..7efda5f 100644 --- a/src/componentManager.js +++ b/src/componentManager.js @@ -1,4 +1,4 @@ -import { createHash } from "crypto"; +import { createHash } from "node:crypto"; import { WebC } from "../webc.js"; import { AstQuery } from "./astQuery.js"; @@ -252,4 +252,4 @@ class ComponentManager { } } -export { ComponentManager }; \ No newline at end of file +export { ComponentManager }; diff --git a/src/fasterVmContext.cjs b/src/fasterVmContext.cjs index 0678a35..472158b 100644 --- a/src/fasterVmContext.cjs +++ b/src/fasterVmContext.cjs @@ -1,4 +1,4 @@ -const vm = require("vm"); +const vm = require("node:vm"); class ContextInstance { constructor() { @@ -74,4 +74,4 @@ class FasterVmContext { } } -module.exports = { FasterVmContext }; \ No newline at end of file +module.exports = { FasterVmContext }; diff --git a/src/fsCache.js b/src/fsCache.js index 05cd681..495166b 100644 --- a/src/fsCache.js +++ b/src/fsCache.js @@ -1,5 +1,5 @@ -import fs from "fs"; -import path from "path"; +import fs from "node:fs"; +import path from "node:path"; class FileSystemCache { constructor() { diff --git a/src/moduleResolution.js b/src/moduleResolution.js index 3fcfc0c..9bc35c3 100644 --- a/src/moduleResolution.js +++ b/src/moduleResolution.js @@ -1,5 +1,5 @@ import { TemplatePath } from "@11ty/eleventy-utils"; -import path from "path"; +import path from "node:path"; import { Path } from "./path.js"; class ModuleResolution { diff --git a/src/moduleScript.cjs b/src/moduleScript.cjs index 9fd8ac2..dc4382d 100644 --- a/src/moduleScript.cjs +++ b/src/moduleScript.cjs @@ -1,5 +1,5 @@ -const { Module } = require("module"); -const vm = require("vm"); +const { Module } = require("node:module"); +const vm = require("node:vm"); const { RetrieveGlobals } = require("node-retrieve-globals"); const { ProxyData } = require("./proxyData.cjs"); diff --git a/src/path.js b/src/path.js index 800c95c..c1b78c1 100644 --- a/src/path.js +++ b/src/path.js @@ -1,4 +1,4 @@ -import path from "path"; +import path from "node:path"; import { TemplatePath } from "@11ty/eleventy-utils"; class Path { @@ -11,4 +11,4 @@ class Path { } } -export { Path }; \ No newline at end of file +export { Path }; diff --git a/src/streams.js b/src/streams.js index 24f78a4..ad044fa 100644 --- a/src/streams.js +++ b/src/streams.js @@ -1,4 +1,4 @@ -import Stream from "stream"; +import Stream from "node:stream"; class Streams { constructor(buckets = []) { @@ -55,4 +55,4 @@ class Streams { } } -export { Streams }; \ No newline at end of file +export { Streams }; diff --git a/src/util.js b/src/util.js index f52d6bf..2d5c0b9 100644 --- a/src/util.js +++ b/src/util.js @@ -1,4 +1,4 @@ -import util from "util"; +import util from "node:util"; import { AstQuery } from "./astQuery.js"; class Util { @@ -38,4 +38,4 @@ class Util { } } -export { Util }; \ No newline at end of file +export { Util }; diff --git a/webc.js b/webc.js index 74d9062..118f47b 100644 --- a/webc.js +++ b/webc.js @@ -1,7 +1,7 @@ -import fs from "fs"; +import fs from "node:fs"; import fastglob from "fast-glob"; import isGlob from "is-glob"; -import path from "path"; +import path from "node:path"; import { Path } from "./src/path.js"; import { AstSerializer } from "./src/ast.js"; @@ -82,7 +82,7 @@ class WebC { if(mode === "component" || !content.startsWith("${content}`; } - + return { content, mode, @@ -288,4 +288,4 @@ class WebC { } } -export { WebC, ModuleScript, ComponentManager }; \ No newline at end of file +export { WebC, ModuleScript, ComponentManager };