Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: node prefix lint #9514

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
const { builtinModules } = require('node:module')
const { defineConfig } = require('eslint-define-config')

module.exports = defineConfig({
Expand Down Expand Up @@ -81,6 +82,10 @@ module.exports = defineConfig({
{ prefer: 'type-imports' }
],

'import/no-nodejs-modules': [
'error',
{ allow: builtinModules.map((mod) => `node:${mod}`) }
],
'import/no-duplicates': 'error',
'import/order': 'error',
'sort-imports': [
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/bin/vite.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if (profileIndex > 0) {
if (next && !next.startsWith('-')) {
process.argv.splice(profileIndex, 1)
}
const inspector = await import('inspector').then((r) => r.default)
const inspector = await import('node:inspector').then((r) => r.default)
const session = (global.__vite_profile_session = new inspector.Session())
session.connect()
session.post('Profiler.enable', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ export async function resolveHttpServer(
httpsOptions?: HttpsServerOptions
): Promise<HttpServer> {
if (!httpsOptions) {
const { createServer } = await import('http')
const { createServer } = await import('node:http')
return createServer(app)
}

// #484 fallback to http1 when proxy is needed.
if (proxy) {
const { createServer } = await import('https')
const { createServer } = await import('node:https')
return createServer(httpsOptions, app)
} else {
const { createSecureServer } = await import('http2')
const { createSecureServer } = await import('node:http2')
return createSecureServer(
{
// Manually increase the session memory to prevent 502 ENHANCE_YOUR_CALM
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-console: 0 */

import readline from 'readline'
import readline from 'node:readline'
import colors from 'picocolors'
import type { RollupError } from 'rollup'
import type { ResolvedServerUrls } from './server'
Expand Down
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/ssrRequireHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ type NodeResolveFilename = (
/** Respect the `resolve.dedupe` option in production SSR. */
function dedupeRequire(dedupe: string[]) {
// eslint-disable-next-line no-restricted-globals
const Module = require('module') as { _resolveFilename: NodeResolveFilename }
const Module = require('node:module') as {
_resolveFilename: NodeResolveFilename
}
const resolveFilename = Module._resolveFilename
Module._resolveFilename = function (request, parent, isMain, options) {
if (request[0] !== '.' && request[0] !== '/') {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/types/ws.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
} from 'node:http'
import type { Server as HTTPSServer } from 'node:https'
import type { Duplex, DuplexOptions } from 'node:stream'
import type { SecureContextOptions } from 'tls'
import type { SecureContextOptions } from 'node:tls'
import type { URL } from 'node:url'
import type { ZlibOptions } from 'node:zlib'

Expand Down
2 changes: 1 addition & 1 deletion playground/alias/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path')
const path = require('node:path')

/**
* @type {import('vite').UserConfig}
Expand Down
2 changes: 1 addition & 1 deletion playground/assets/vite.config-runtime-base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path')
const path = require('node:path')

const dynamicBaseAssetsCode = `
globalThis.__toAssetUrl = url => '/' + url
Expand Down
2 changes: 1 addition & 1 deletion playground/assets/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path')
const path = require('node:path')

/**
* @type {import('vite').UserConfig}
Expand Down
2 changes: 1 addition & 1 deletion playground/backend-integration/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path')
const path = require('node:path')
const glob = require('fast-glob')
const normalizePath = require('vite').normalizePath

Expand Down
2 changes: 1 addition & 1 deletion playground/css-codesplit-cjs/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { resolve } = require('path')
const { resolve } = require('node:path')

module.exports = {
build: {
Expand Down
2 changes: 1 addition & 1 deletion playground/css-codesplit/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { resolve } = require('path')
const { resolve } = require('node:path')

module.exports = {
build: {
Expand Down
4 changes: 2 additions & 2 deletions playground/css/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module.exports = {
plugins: [require('postcss-nested'), testDirDep, testSourceInput]
}

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const glob = require('fast-glob')
const { normalizePath } = require('vite')

Expand Down
2 changes: 1 addition & 1 deletion playground/css/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path')
const path = require('node:path')

/**
* @type {import('vite').UserConfig}
Expand Down
4 changes: 2 additions & 2 deletions playground/dynamic-import/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const vite = require('vite')

module.exports = vite.defineConfig({
Expand Down
2 changes: 1 addition & 1 deletion playground/fs-serve/root/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path')
const path = require('node:path')

/**
* @type {import('vite').UserConfig}
Expand Down
2 changes: 1 addition & 1 deletion playground/html/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { resolve } = require('path')
const { resolve } = require('node:path')

/**
* @type {import('vite').UserConfig}
Expand Down
4 changes: 2 additions & 2 deletions playground/json/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const express = require('express')

const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD
Expand Down
4 changes: 2 additions & 2 deletions playground/legacy/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const legacy = require('@vitejs/plugin-legacy').default

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions playground/lib/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

/**
* @type {import('vite').UserConfig}
Expand Down
4 changes: 2 additions & 2 deletions playground/lib/vite.dyimport.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

/**
* @type {import('vite').UserConfig}
Expand Down
4 changes: 2 additions & 2 deletions playground/multiple-entrypoints/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { resolve } = require('path')
const fs = require('fs')
const { resolve } = require('node:path')
const fs = require('node:fs')

module.exports = {
build: {
Expand Down
2 changes: 2 additions & 0 deletions playground/optimize-deps/dep-with-builtin-module-cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// no node: protocol intentionally
// eslint-disable-next-line import/no-nodejs-modules
const fs = require('fs')
// eslint-disable-next-line import/no-nodejs-modules
const path = require('path')

// NOTE: require destructure would error immediately because of how esbuild
Expand Down
2 changes: 2 additions & 0 deletions playground/optimize-deps/dep-with-builtin-module-esm/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// no node: protocol intentionally
// eslint-disable-next-line import/no-nodejs-modules
import { readFileSync } from 'fs'
// eslint-disable-next-line import/no-nodejs-modules
import path from 'path'

// access from named import
Expand Down
2 changes: 1 addition & 1 deletion playground/optimize-deps/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs')
const fs = require('node:fs')
const vue = require('@vitejs/plugin-vue')

// Overriding the NODE_ENV set by vitest
Expand Down
2 changes: 1 addition & 1 deletion playground/optimize-missing-deps/multi-entry-dep/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const path = require('path')
const path = require('node:path')

exports.name = path.normalize('./Server')
4 changes: 2 additions & 2 deletions playground/optimize-missing-deps/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const express = require('express')

const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion playground/resolve/browser-field/multiple.dot.path.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const fs = require('fs')
const fs = require('node:fs')
console.log('this should not run in the browser')
2 changes: 1 addition & 1 deletion playground/resolve/browser-field/not-browser.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const fs = require('fs')
const fs = require('node:fs')
console.log('this should not run in the browser')
2 changes: 1 addition & 1 deletion playground/ssr-deps/import-builtin-cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.stream = require('stream')
exports.stream = require('node:stream')

exports.hello = function () {
return 'Hello World!'
Expand Down
6 changes: 3 additions & 3 deletions playground/ssr-deps/read-file-content/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path')
const path = require('node:path')

module.exports = async function readFileContent(filePath) {
const fs =
process.versions.node.split('.')[0] >= '14'
? require('fs/promises')
: require('fs').promises
? require('node:fs/promises')
: require('node:fs').promises
return await fs.readFile(path.resolve(filePath), 'utf-8')
}
2 changes: 1 addition & 1 deletion playground/ssr-deps/require-absolute/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const path = require('path')
const path = require('node:path')

module.exports.hello = () => require(path.resolve(__dirname, './foo.js')).hello
2 changes: 1 addition & 1 deletion playground/ssr-deps/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import express from 'express'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
Expand Down
2 changes: 1 addition & 1 deletion playground/ssr-html/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import express from 'express'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
Expand Down
2 changes: 1 addition & 1 deletion playground/ssr-pug/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import path from 'node:path'
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import pug from 'pug'
import express from 'express'

Expand Down
2 changes: 1 addition & 1 deletion playground/ssr-react/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const toAbsolute = (p) => path.resolve(__dirname, p)
Expand Down
2 changes: 1 addition & 1 deletion playground/ssr-react/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import express from 'express'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
Expand Down
2 changes: 1 addition & 1 deletion playground/ssr-vue/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import express from 'express'

const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion playground/ssr-vue/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'
import { defineConfig } from 'vite'
import vuePlugin from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
Expand Down
2 changes: 1 addition & 1 deletion playground/ssr-webworker/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import { Miniflare } from 'miniflare'

Expand Down
2 changes: 1 addition & 1 deletion playground/worker/vite.config-relative-base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('path')
const path = require('node:path')
const vueJsx = require('@vitejs/plugin-vue-jsx')
const vite = require('vite')

Expand Down