Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

chore: use node: prefix for built-in modules #4384

Merged
merged 4 commits into from
Apr 15, 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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"plugin:import/typescript"
],
"rules": {
"unicorn/prefer-node-protocol": "error",
"no-console": "off",
"vue/multi-word-component-names": "off",
"vue/one-component-per-file": "off",
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.guide/3.directory-structure/4.components.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Imagine a directory structure like this:
Then in `awesome-ui/nuxt.js` you can use the `components:dirs` hook:

```js
import { join } from 'path'
import { join } from 'node:path'
import { defineNuxtModule } from '@nuxt/kit'

export default defineNuxtModule({
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.guide/5.deployment/99.presets/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default myPreset
Then in your `nuxt.config` you can specify that Nitro should use your custom preset:

```ts [nuxt.config.js|ts]
import { resolve } from 'path'
import { resolve } from 'node:path'

export default {
nitro: {
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.guide/5.deployment/99.presets/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ app.listen(3000)
### Node server

```js
import { createServer } from 'http'
import { createServer } from 'node:http'
import handler from './.output/server'

const server = createServer(handler)
Expand Down
6 changes: 3 additions & 3 deletions docs/content/2.guide/6.going-further/5.esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ const { __dirname, __filename, require } = createCommonJS(import.meta.url)
```

```js [manual]
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import { createRequire } from 'module'
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'
import { createRequire } from 'node:module'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
Expand Down
2 changes: 1 addition & 1 deletion docs/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import { withDocus } from '@docus/app'

export default withDocus({
Expand Down
4 changes: 2 additions & 2 deletions docs/scripts/gen-docs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile, writeFile, mkdir } from 'fs/promises'
import { dirname } from 'path'
import { readFile, writeFile, mkdir } from 'node:fs/promises'
import { dirname } from 'node:path'
import type { Schema } from 'untyped'
import { resolve } from 'pathe'
import { upperFirst } from 'scule'
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/testing/tests/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { setup, $fetch, isDev } from '@nuxt/test-utils'

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/ignore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, readFileSync } from 'fs'
import { existsSync, readFileSync } from 'node:fs'
import ignore from 'ignore'
import { join, relative } from 'pathe'
import { tryUseNuxt } from './context'
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/internal/cjs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathToFileURL } from 'url'
import { pathToFileURL } from 'node:url'
import { join, normalize } from 'pathe'
import { interopDefault } from 'mlly'
import jiti from 'jiti'
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/internal/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises as fsp } from 'fs'
import { promises as fsp } from 'node:fs'
import lodashTemplate from 'lodash.template'
import hash from 'hash-sum'
import { camelCase } from 'scule'
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/module/define.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises as fsp } from 'fs'
import { promises as fsp } from 'node:fs'
import defu from 'defu'
import { applyDefaults } from 'untyped'
import { dirname } from 'pathe'
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fsp, existsSync } from 'fs'
import { fileURLToPath } from 'url'
import { promises as fsp, existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { basename, dirname, resolve, join, normalize, isAbsolute } from 'pathe'
import { globby } from 'globby'
import { tryUseNuxt, useNuxt } from './context'
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from 'fs'
import { existsSync } from 'node:fs'
import { basename, parse, resolve } from 'pathe'
import hash from 'hash-sum'
import type { NuxtTemplate } from '@nuxt/schema'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxi/src/commands/add.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, promises as fsp } from 'fs'
import { existsSync, promises as fsp } from 'node:fs'
import { resolve, dirname } from 'pathe'
import consola from 'consola'
import { loadKit } from '../utils/kit'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxi/src/commands/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises as fsp } from 'fs'
import { promises as fsp } from 'node:fs'
import { join, resolve } from 'pathe'
import { createApp, lazyHandle } from 'h3'
import { listen } from 'listhen'
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxi/src/commands/info.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'os'
import { existsSync, readFileSync } from 'fs'
import { createRequire } from 'module'
import os from 'node:os'
import { existsSync, readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { resolve } from 'pathe'
import jiti from 'jiti'
import destr from 'destr'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxi/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, readdirSync } from 'fs'
import { existsSync, readdirSync } from 'node:fs'
import createTiged from 'tiged'
import { relative, resolve } from 'pathe'
import superb from 'superb'
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxi/src/commands/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync, promises as fsp } from 'fs'
import { dirname, relative } from 'path'
import { existsSync, promises as fsp } from 'node:fs'
import { dirname, relative } from 'node:path'
import { execa } from 'execa'
import { loadDotenv } from 'c12'
import { resolve } from 'pathe'
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxi/src/commands/upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from 'child_process'
import { promises as fsp, existsSync } from 'fs'
import { execSync } from 'node:child_process'
import { promises as fsp, existsSync } from 'node:fs'
import consola from 'consola'
import { resolve } from 'pathe'
import { resolveModule } from '../utils/cjs'
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxi/src/utils/cjs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRequire } from 'module'
import { pathToFileURL } from 'url'
import { createRequire } from 'node:module'
import { pathToFileURL } from 'node:url'
import { normalize, dirname } from 'pathe'

export function getModulePaths (paths?: string | string[]): string[] {
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxi/src/utils/fs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises as fsp } from 'fs'
import { promises as fsp } from 'node:fs'
import { dirname } from 'pathe'

// Check if a file exists
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxi/src/utils/packageManagers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from 'child_process'
import { existsSync } from 'fs'
import { execSync } from 'node:child_process'
import { existsSync } from 'node:fs'
import { resolve } from 'pathe'
import { findup } from './fs'

Expand Down
2 changes: 1 addition & 1 deletion packages/nuxi/src/utils/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises as fsp } from 'fs'
import { promises as fsp } from 'node:fs'
import { isAbsolute, join, relative, resolve } from 'pathe'
import { Nuxt, TSReference } from '@nuxt/schema'
import defu from 'defu'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/app/compat/legacy-app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IncomingMessage, ServerResponse } from 'http'
import type { IncomingMessage, ServerResponse } from 'node:http'
import type { App } from 'vue'
import type { Component } from '@vue/runtime-core'
import mockContext from 'unenv/runtime/mock/proxy'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/auto-imports/composables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises as fsp, existsSync } from 'fs'
import { promises as fsp, existsSync } from 'node:fs'
import { parse as parsePath } from 'pathe'
import { findExports } from 'mlly'
import { camelCase } from 'scule'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/auto-imports/transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathToFileURL } from 'url'
import { pathToFileURL } from 'node:url'
import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL } from 'ufo'
import { Unimport } from 'unimport'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/components/loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathToFileURL } from 'url'
import { pathToFileURL } from 'node:url'
import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL } from 'ufo'
import { Component } from '@nuxt/schema'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/components/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { statSync } from 'fs'
import { statSync } from 'node:fs'
import { resolve, basename } from 'pathe'
import { defineNuxtModule, resolveAlias, addVitePlugin, addWebpackPlugin, addTemplate, addPluginTemplate } from '@nuxt/kit'
import type { Component, ComponentsDir, ComponentsOptions } from '@nuxt/schema'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/core/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { promises as fsp } from 'fs'
import { promises as fsp } from 'node:fs'
import { dirname, resolve, basename, extname } from 'pathe'
import defu from 'defu'
import { kebabCase } from 'scule'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/core/nitro.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from 'fs'
import { existsSync } from 'node:fs'
import { resolve, join } from 'pathe'
import { createNitro, createDevServer, build, prepare, copyPublicAssets, writeTypes, scanHandlers, prerender } from 'nitropack'
import type { NitroEventHandler, NitroDevEventHandler, NitroConfig } from 'nitropack'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/core/plugins/import-protection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRequire } from 'module'
import { createRequire } from 'node:module'
import { createUnplugin } from 'unplugin'
import { logger } from '@nuxt/kit'
import { isAbsolute, relative, resolve } from 'pathe'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/dirs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'pathe'

let _distDir = dirname(fileURLToPath(import.meta.url))
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/pages/macros.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathToFileURL } from 'url'
import { pathToFileURL } from 'node:url'
import { createUnplugin } from 'unplugin'
import { parseQuery, parseURL, withQuery } from 'ufo'
import { findStaticImports, findExports } from 'mlly'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/pages/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from 'fs'
import { existsSync } from 'node:fs'
import { defineNuxtModule, addTemplate, addPlugin, addVitePlugin, addWebpackPlugin, findPath } from '@nuxt/kit'
import { resolve } from 'pathe'
import { genDynamicImport, genString, genArrayFromRaw, genImport, genObjectFromRawEntries } from 'knitwork'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/test/auto-imports.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync } from 'fs'
import { readFileSync } from 'node:fs'
import { expect, describe, it } from 'vitest'
import { join } from 'pathe'
import { createCommonJS, findExports } from 'mlly'
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/test/scan-components.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import { ComponentsDir } from '@nuxt/schema'
import { expect, it, vi } from 'vitest'
import { scanComponents } from '../src/components/scan'
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/config/_app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve, join } from 'pathe'
import { existsSync, readdirSync } from 'fs'
import { existsSync, readdirSync } from 'node:fs'
import defu from 'defu'

export default {
Expand Down
6 changes: 3 additions & 3 deletions packages/schema/src/config/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,9 @@ export default {
* object in `nuxt.config` (as below).
*
* @example
* ```js
* import fs from 'fs'
* import path from 'path'
* ```js'node:fs'
* import fs from 'node:fs'
* import path from 'node:path'
* export default {
* hooks: {
* build: {
Expand Down
4 changes: 2 additions & 2 deletions packages/schema/src/types/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Server as HttpServer, IncomingMessage, ServerResponse } from 'http'
import type { Server as HttpsServer } from 'https'
import type { Server as HttpServer, IncomingMessage, ServerResponse } from 'node:http'
import type { Server as HttpsServer } from 'node:https'
import type { Compiler, Configuration, Stats } from 'webpack'
import type { TSConfig } from 'pkg-types'
import type { ModuleContainer } from './module'
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import defu from 'defu'
import type { TestContext, TestOptions, TestRunner } from './types'

Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/src/nuxt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync, promises as fsp } from 'fs'
import { resolve } from 'path'
import { existsSync, promises as fsp } from 'node:fs'
import { resolve } from 'node:path'
import * as _kit from '@nuxt/kit'
import { useTestContext } from './context'

Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import { execa } from 'execa'
import { getRandomPort, waitForPort } from 'get-port-please'
import { fetch as _fetch, $fetch as _$fetch, FetchOptions } from 'ohmyfetch'
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/dev-bundler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { pathToFileURL } from 'url'
import { existsSync } from 'fs'
import { builtinModules } from 'module'
import { pathToFileURL } from 'node:url'
import { existsSync } from 'node:fs'
import { builtinModules } from 'node:module'
import { resolve } from 'pathe'
import * as vite from 'vite'
import { ExternalsOptions, isExternal as _isExternal, ExternalsDefaults } from 'externality'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/dirs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'pathe'

export const distDir = dirname(fileURLToPath(import.meta.url))
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHash } from 'crypto'
import { promises as fsp, readdirSync, statSync } from 'fs'
import { createHash } from 'node:crypto'
import { promises as fsp, readdirSync, statSync } from 'node:fs'
import { join } from 'pathe'

export function uniq<T> (arr: T[]): T[] {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/src/configs/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import querystring from 'querystring'
import querystring from 'node:querystring'
import { resolve } from 'pathe'
import webpack from 'webpack'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/src/webpack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IncomingMessage, ServerResponse } from 'http'
import type { IncomingMessage, ServerResponse } from 'node:http'
import pify from 'pify'
import webpack from 'webpack'
import webpackDevMiddleware, { API } from 'webpack-dev-middleware'
Expand Down
4 changes: 2 additions & 2 deletions scripts/bump-edge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fsp } from 'fs'
import { execSync } from 'child_process'
import { promises as fsp } from 'node:fs'
import { execSync } from 'node:child_process'
import { resolve } from 'pathe'
import { globby } from 'globby'

Expand Down
4 changes: 2 additions & 2 deletions scripts/update-examples.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'url'
import { promises as fs } from 'fs'
import { fileURLToPath } from 'node:url'
import { promises as fs } from 'node:fs'
import { resolve } from 'pathe'

async function run () {
Expand Down
2 changes: 1 addition & 1 deletion test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileURLToPath } from 'url'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
// import { isWindows } from 'std-env'
import { setup, fetch, $fetch, startServer } from '@nuxt/test-utils'
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/basic/extends/foo/server/middleware/foo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ServerResponse } from 'http'
import type { ServerResponse } from 'node:http'

export default (_, res: ServerResponse, next) => {
res.setHeader('injected-header', 'foo')
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import { isWindows } from 'std-env'

Expand Down