Skip to content

Commit 9e9cd23

Browse files
authored
chore: node prefix lint (#9514)
1 parent 1983cf4 commit 9e9cd23

File tree

41 files changed

+61
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+61
-50
lines changed

.eslintrc.cjs

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @ts-check
2+
const { builtinModules } = require('node:module')
23
const { defineConfig } = require('eslint-define-config')
34

45
module.exports = defineConfig({
@@ -81,6 +82,10 @@ module.exports = defineConfig({
8182
{ prefer: 'type-imports' }
8283
],
8384

85+
'import/no-nodejs-modules': [
86+
'error',
87+
{ allow: builtinModules.map((mod) => `node:${mod}`) }
88+
],
8489
'import/no-duplicates': 'error',
8590
'import/order': 'error',
8691
'sort-imports': [

packages/vite/bin/vite.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if (profileIndex > 0) {
5050
if (next && !next.startsWith('-')) {
5151
process.argv.splice(profileIndex, 1)
5252
}
53-
const inspector = await import('inspector').then((r) => r.default)
53+
const inspector = await import('node:inspector').then((r) => r.default)
5454
const session = (global.__vite_profile_session = new inspector.Session())
5555
session.connect()
5656
session.post('Profiler.enable', () => {

packages/vite/src/node/http.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ export async function resolveHttpServer(
9595
httpsOptions?: HttpsServerOptions
9696
): Promise<HttpServer> {
9797
if (!httpsOptions) {
98-
const { createServer } = await import('http')
98+
const { createServer } = await import('node:http')
9999
return createServer(app)
100100
}
101101

102102
// #484 fallback to http1 when proxy is needed.
103103
if (proxy) {
104-
const { createServer } = await import('https')
104+
const { createServer } = await import('node:https')
105105
return createServer(httpsOptions, app)
106106
} else {
107-
const { createSecureServer } = await import('http2')
107+
const { createSecureServer } = await import('node:http2')
108108
return createSecureServer(
109109
{
110110
// Manually increase the session memory to prevent 502 ENHANCE_YOUR_CALM

packages/vite/src/node/logger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint no-console: 0 */
22

3-
import readline from 'readline'
3+
import readline from 'node:readline'
44
import colors from 'picocolors'
55
import type { RollupError } from 'rollup'
66
import type { ResolvedServerUrls } from './server'

packages/vite/src/node/plugins/ssrRequireHook.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ type NodeResolveFilename = (
5353
/** Respect the `resolve.dedupe` option in production SSR. */
5454
function dedupeRequire(dedupe: string[]) {
5555
// eslint-disable-next-line no-restricted-globals
56-
const Module = require('module') as { _resolveFilename: NodeResolveFilename }
56+
const Module = require('node:module') as {
57+
_resolveFilename: NodeResolveFilename
58+
}
5759
const resolveFilename = Module._resolveFilename
5860
Module._resolveFilename = function (request, parent, isMain, options) {
5961
if (request[0] !== '.' && request[0] !== '/') {

packages/vite/types/ws.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type {
2626
} from 'node:http'
2727
import type { Server as HTTPSServer } from 'node:https'
2828
import type { Duplex, DuplexOptions } from 'node:stream'
29-
import type { SecureContextOptions } from 'tls'
29+
import type { SecureContextOptions } from 'node:tls'
3030
import type { URL } from 'node:url'
3131
import type { ZlibOptions } from 'node:zlib'
3232

playground/alias/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path')
1+
const path = require('node:path')
22

33
/**
44
* @type {import('vite').UserConfig}

playground/assets/vite.config-runtime-base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path')
1+
const path = require('node:path')
22

33
const dynamicBaseAssetsCode = `
44
globalThis.__toAssetUrl = url => '/' + url

playground/assets/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path')
1+
const path = require('node:path')
22

33
/**
44
* @type {import('vite').UserConfig}

playground/backend-integration/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path')
1+
const path = require('node:path')
22
const glob = require('fast-glob')
33
const normalizePath = require('vite').normalizePath
44

playground/css-codesplit-cjs/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { resolve } = require('path')
1+
const { resolve } = require('node:path')
22

33
module.exports = {
44
build: {

playground/css-codesplit/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { resolve } = require('path')
1+
const { resolve } = require('node:path')
22

33
module.exports = {
44
build: {

playground/css/postcss.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module.exports = {
22
plugins: [require('postcss-nested'), testDirDep, testSourceInput]
33
}
44

5-
const fs = require('fs')
6-
const path = require('path')
5+
const fs = require('node:fs')
6+
const path = require('node:path')
77
const glob = require('fast-glob')
88
const { normalizePath } = require('vite')
99

playground/css/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path')
1+
const path = require('node:path')
22

33
/**
44
* @type {import('vite').UserConfig}

playground/dynamic-import/vite.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs = require('fs')
2-
const path = require('path')
1+
const fs = require('node:fs')
2+
const path = require('node:path')
33
const vite = require('vite')
44

55
module.exports = vite.defineConfig({

playground/fs-serve/root/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path')
1+
const path = require('node:path')
22

33
/**
44
* @type {import('vite').UserConfig}

playground/html/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { resolve } = require('path')
1+
const { resolve } = require('node:path')
22

33
/**
44
* @type {import('vite').UserConfig}

playground/json/server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
2-
const fs = require('fs')
3-
const path = require('path')
2+
const fs = require('node:fs')
3+
const path = require('node:path')
44
const express = require('express')
55

66
const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD

playground/legacy/vite.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs = require('fs')
2-
const path = require('path')
1+
const fs = require('node:fs')
2+
const path = require('node:path')
33
const legacy = require('@vitejs/plugin-legacy').default
44

55
module.exports = {

playground/lib/vite.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs = require('fs')
2-
const path = require('path')
1+
const fs = require('node:fs')
2+
const path = require('node:path')
33

44
/**
55
* @type {import('vite').UserConfig}

playground/lib/vite.dyimport.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs = require('fs')
2-
const path = require('path')
1+
const fs = require('node:fs')
2+
const path = require('node:path')
33

44
/**
55
* @type {import('vite').UserConfig}

playground/multiple-entrypoints/vite.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { resolve } = require('path')
2-
const fs = require('fs')
1+
const { resolve } = require('node:path')
2+
const fs = require('node:fs')
33

44
module.exports = {
55
build: {

playground/optimize-deps/dep-with-builtin-module-cjs/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// no node: protocol intentionally
2+
// eslint-disable-next-line import/no-nodejs-modules
23
const fs = require('fs')
4+
// eslint-disable-next-line import/no-nodejs-modules
35
const path = require('path')
46

57
// NOTE: require destructure would error immediately because of how esbuild

playground/optimize-deps/dep-with-builtin-module-esm/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// no node: protocol intentionally
2+
// eslint-disable-next-line import/no-nodejs-modules
23
import { readFileSync } from 'fs'
4+
// eslint-disable-next-line import/no-nodejs-modules
35
import path from 'path'
46

57
// access from named import

playground/optimize-deps/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs')
1+
const fs = require('node:fs')
22
const vue = require('@vitejs/plugin-vue')
33

44
// Overriding the NODE_ENV set by vitest
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const path = require('path')
1+
const path = require('node:path')
22

33
exports.name = path.normalize('./Server')

playground/optimize-missing-deps/server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
2-
const fs = require('fs')
3-
const path = require('path')
2+
const fs = require('node:fs')
3+
const path = require('node:path')
44
const express = require('express')
55

66
const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const fs = require('fs')
1+
const fs = require('node:fs')
22
console.log('this should not run in the browser')
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const fs = require('fs')
1+
const fs = require('node:fs')
22
console.log('this should not run in the browser')

playground/ssr-deps/import-builtin-cjs/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exports.stream = require('stream')
1+
exports.stream = require('node:stream')
22

33
exports.hello = function () {
44
return 'Hello World!'
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const path = require('path')
1+
const path = require('node:path')
22

33
module.exports = async function readFileContent(filePath) {
44
const fs =
55
process.versions.node.split('.')[0] >= '14'
6-
? require('fs/promises')
7-
: require('fs').promises
6+
? require('node:fs/promises')
7+
: require('node:fs').promises
88
return await fs.readFile(path.resolve(filePath), 'utf-8')
99
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const path = require('path')
1+
const path = require('node:path')
22

33
module.exports.hello = () => require(path.resolve(__dirname, './foo.js')).hello

playground/ssr-deps/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22
import fs from 'node:fs'
33
import path from 'node:path'
4-
import { fileURLToPath } from 'url'
4+
import { fileURLToPath } from 'node:url'
55
import express from 'express'
66

77
const __dirname = path.dirname(fileURLToPath(import.meta.url))

playground/ssr-html/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
3-
import { fileURLToPath } from 'url'
3+
import { fileURLToPath } from 'node:url'
44
import express from 'express'
55

66
const __dirname = path.dirname(fileURLToPath(import.meta.url))

playground/ssr-pug/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22
import path from 'node:path'
3-
import { fileURLToPath } from 'url'
3+
import { fileURLToPath } from 'node:url'
44
import pug from 'pug'
55
import express from 'express'
66

playground/ssr-react/prerender.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import fs from 'node:fs'
55
import path from 'node:path'
6-
import { fileURLToPath } from 'url'
6+
import { fileURLToPath } from 'node:url'
77

88
const __dirname = path.dirname(fileURLToPath(import.meta.url))
99
const toAbsolute = (p) => path.resolve(__dirname, p)

playground/ssr-react/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
3-
import { fileURLToPath } from 'url'
3+
import { fileURLToPath } from 'node:url'
44
import express from 'express'
55

66
const __dirname = path.dirname(fileURLToPath(import.meta.url))

playground/ssr-vue/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22
import fs from 'node:fs'
33
import path from 'node:path'
4-
import { fileURLToPath } from 'url'
4+
import { fileURLToPath } from 'node:url'
55
import express from 'express'
66

77
const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD

playground/ssr-vue/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path'
1+
import path from 'node:path'
22
import { defineConfig } from 'vite'
33
import vuePlugin from '@vitejs/plugin-vue'
44
import vueJsx from '@vitejs/plugin-vue-jsx'

playground/ssr-webworker/worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fileURLToPath } from 'url'
1+
import { fileURLToPath } from 'node:url'
22
import path from 'node:path'
33
import { Miniflare } from 'miniflare'
44

playground/worker/vite.config-relative-base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require('path')
1+
const path = require('node:path')
22
const vueJsx = require('@vitejs/plugin-vue-jsx')
33
const vite = require('vite')
44

0 commit comments

Comments
 (0)