Use node: protocol (#12373)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-03-02 13:44:00 +08:00
1 parent cbd6d42893
commit 3bb69beabf
33 files changed
+50 -45

No files matched your search

-7
View File
@@ -187,13 +187,6 @@ module.exports = {
"unicorn/prefer-module": "off",
},
},
// `esbuild` don't support
{
files: ["bin/**/*.js", "src/**/*.js"],
rules: {
"unicorn/prefer-node-protocol": "off",
},
},
{
files: [
"tests/format/**/jsfmt.spec.js",
+2
View File
@@ -11,6 +11,7 @@ import esbuildPluginLicense from "./esbuild-plugins/license.mjs";
import esbuildPluginUmd from "./esbuild-plugins/umd.mjs";
import esbuildPluginInteropDefault from "./esbuild-plugins/interop-default.mjs";
import esbuildPluginVisualizer from "./esbuild-plugins/visualizer.mjs";
import esbuildPluginStripNodeProtocol from "./esbuild-plugins/strip-node-protocol.mjs";
import bundles from "./config.mjs";
const { __dirname, readJsonSync, require } = createEsmUtils(import.meta);
@@ -121,6 +122,7 @@ function* getEsbuildOptions(bundle, buildOptions) {
metafile: true,
plugins: [
esbuildPluginEvaluate(),
esbuildPluginStripNodeProtocol(),
esbuildPluginReplaceModule({ ...replaceModule, ...bundle.replaceModule }),
bundle.target === "universal" && esbuildPluginNodeModulePolyfills(),
esbuildPluginTextReplace({
@@ -0,0 +1,10 @@
export default function esbuildPluginStripNodeProtocol() {
return {
name: "strip-node-protocol",
setup(build) {
build.onResolve({ filter: /^node:/ }, ({ path }) =>
build.resolve(path.slice(5))
);
},
};
}
+2 -2
View File
@@ -1,5 +1,5 @@
import path from "path";
import { promises as fs } from "fs";
import path from "node:path";
import { promises as fs } from "node:fs";
import fastGlob from "fast-glob";
/** @typedef {import('./context').Context} Context */
+1 -1
View File
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import prettier from "../index.js";
async function logResolvedConfigPathOrDie(context) {
+2 -2
View File
@@ -1,5 +1,5 @@
import { promises as fs } from "fs";
import path from "path";
import { promises as fs } from "node:fs";
import path from "node:path";
import chalk from "chalk";
import prettier from "../index.js";
import thirdParty from "../common/third-party.cjs";
+1 -1
View File
@@ -1,4 +1,4 @@
import readline from "readline";
import readline from "node:readline";
import chalk from "chalk";
import stripAnsi from "strip-ansi";
import wcwidth from "wcwidth";
+1 -1
View File
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import ignore from "ignore";
import getFileContentOrNull from "../utils/get-file-content-or-null.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import { inferParser } from "../main/options.js";
import * as config from "../config/resolve-config.js";
import createIgnorer from "./create-ignorer.js";
+4 -4
View File
@@ -1,7 +1,7 @@
import { createRequire } from "module";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { createRequire } from "node:module";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { uniqBy, partition } from "lodash-es";
import fastGlob from "fast-glob";
import mem, { memClear } from "mem";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
+2 -2
View File
@@ -1,8 +1,8 @@
// Simple version of `find-project-root`
// https://github.com/kirstein/find-project-root/blob/master/index.js
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
const MARKERS = [".git", ".hg"];
+1 -1
View File
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import editorconfig from "editorconfig";
import editorConfigToPrettier from "editorconfig-to-prettier";
+2 -2
View File
@@ -1,5 +1,5 @@
import { createRequire } from "module";
import path from "path";
import { createRequire } from "node:module";
import path from "node:path";
import micromatch from "micromatch";
import mem, { memClear } from "mem";
import thirdParty from "../common/third-party.cjs";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import core from "./main/core.js";
import { getSupportInfo } from "./main/support.js";
import getFileInfo from "./common/get-file-info.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import createLanguage from "../utils/create-language.js";
import printer from "./printer-postcss.js";
import options from "./options.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import createLanguage from "../utils/create-language.js";
import printer from "./printer-graphql.js";
import options from "./options.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import createLanguage from "../utils/create-language.js";
import printer from "./printer-glimmer.js";
import parsers from "./parsers.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import createLanguage from "../utils/create-language.js";
import printer from "./printer-html.js";
import options from "./options.js";
+1 -1
View File
@@ -2,7 +2,7 @@
* @typedef {import("../../document").Doc} Doc
*/
import assert from "assert";
import assert from "node:assert";
import { isNonEmptyArray } from "../../common/util.js";
import doc from "../../document/index.js";
import { locStart, locEnd } from "../loc.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import createLanguage from "../utils/create-language.js";
import estreePrinter from "./printer-estree.js";
import estreeJsonPrinter from "./printer-estree-json.js";
+1 -1
View File
@@ -1,6 +1,6 @@
/** @typedef {import("../../document").Doc} Doc */
import assert from "assert";
import assert from "node:assert";
import { printDanglingComments } from "../../main/comments.js";
import { printString, printNumber } from "../../common/util.js";
import doc from "../../document/index.js";
+1 -1
View File
@@ -1,6 +1,6 @@
/** @typedef {import("../../document/doc-builders").Doc} Doc */
import assert from "assert";
import assert from "node:assert";
import {
printDanglingComments,
printCommentsSeparately,
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import createLanguage from "../utils/create-language.js";
import printer from "./printer-markdown.js";
import options from "./options.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import createLanguage from "../utils/create-language.js";
import printer from "./printer-yaml.js";
import options from "./options.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "node:assert";
import doc from "../document/index.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import { UndefinedParserError } from "../common/errors.js";
import { getSupportInfo } from "../main/support.js";
import getInterpreter from "../utils/get-interpreter.js";
+2 -2
View File
@@ -1,5 +1,5 @@
import { createRequire } from "module";
import path from "path";
import { createRequire } from "node:module";
import path from "node:path";
import { ConfigError } from "../common/errors.js";
import { locStart, locEnd } from "../language-js/loc.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "node:assert";
import { getSortedChildNodes } from "./comments.js";
const isJsonParser = ({ parser }) =>
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import semverCompare from "semver/functions/compare.js";
import semverGte from "semver/functions/gte.js";
import semverLt from "semver/functions/lt.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import { createRequire } from "module";
import { createRequire } from "node:module";
import core from "./main/core.js";
import { getSupportInfo } from "./main/support.js";
import * as sharedUtil from "./common/util-shared.js";
+1 -1
View File
@@ -1,4 +1,4 @@
import fs from "fs";
import fs from "node:fs";
const fsAsync = fs.promises;
/**
+1 -1
View File
@@ -1,4 +1,4 @@
import fs from "fs";
import fs from "node:fs";
import readlines from "n-readlines";
function getInterpreter(filepath) {