Skip to content

Commit

Permalink
refactor: import with node: protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Dec 3, 2024
1 parent c80f9ab commit 9c3a471
Show file tree
Hide file tree
Showing 32 changed files with 49 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path'
import path from 'node:path'
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
import MarkdownItGitHubAlerts from 'markdown-it-github-alerts'
import { defineConfig } from 'vitepress'
Expand Down
1 change: 0 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default antfu(
{
rules: {
'node/prefer-global/process': 'off',
'unicorn/prefer-node-protocol': 'off',
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions scripts/buildFixtures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from 'child_process'
import { join, resolve } from 'path'
import process from 'process'
import { execSync } from 'node:child_process'
import { join, resolve } from 'node:path'
import process from 'node:process'
import fs from 'fs-extra'
import c from 'picocolors'

Expand Down
4 changes: 2 additions & 2 deletions src/esbuild/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
UnpluginInstance,
UnpluginOptions,
} from '../types'
import fs from 'fs'
import path from 'path'
import fs from 'node:fs'
import path from 'node:path'
import { toArray } from '../utils/general'
import {
combineSourcemaps,
Expand Down
6 changes: 3 additions & 3 deletions src/esbuild/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { Loader, Location, Message, PartialMessage } from 'esbuild'
import type { SourceMap } from 'rollup'
import type { EsbuildPluginBuild } from '.'
import type { UnpluginBuildContext, UnpluginContext, UnpluginMessage } from '../types'
import { Buffer } from 'buffer'
import fs from 'fs'
import path from 'path'
import { Buffer } from 'node:buffer'
import fs from 'node:fs'
import path from 'node:path'
import remapping from '@ampproject/remapping'
import { parse } from '../utils/context'

Expand Down
4 changes: 2 additions & 2 deletions src/farm/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CompilationContext } from '@farmfe/core'
import type { UnpluginBuildContext, UnpluginContext } from '../types'
import { Buffer } from 'buffer'
import { extname } from 'path'
import { Buffer } from 'node:buffer'
import { extname } from 'node:path'
import { parse } from '../utils/context'

export function createFarmContext(
Expand Down
4 changes: 2 additions & 2 deletions src/rspack/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Compilation, Compiler, LoaderContext } from '@rspack/core'
import type { UnpluginBuildContext, UnpluginContext, UnpluginMessage } from '../types'
import { Buffer } from 'buffer'
import { resolve } from 'path'
import { Buffer } from 'node:buffer'
import { resolve } from 'node:path'
import { parse } from '../utils/context'

export function createBuildContext(compiler: Compiler, compilation: Compilation, loaderContext?: LoaderContext): UnpluginBuildContext {
Expand Down
4 changes: 2 additions & 2 deletions src/rspack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
UnpluginFactory,
UnpluginInstance,
} from '../types'
import fs from 'fs'
import { resolve } from 'path'
import fs from 'node:fs'
import { resolve } from 'node:path'
import { toArray } from '../utils/general'
import { normalizeAbsolutePath, transformUse } from '../utils/webpack-like'
import { createBuildContext, normalizeMessage } from './context'
Expand Down
4 changes: 2 additions & 2 deletions src/rspack/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Compiler } from '@rspack/core'
import type { ResolvedUnpluginOptions } from '../types'
import fs from 'fs'
import { basename, dirname, resolve } from 'path'
import fs from 'node:fs'
import { basename, dirname, resolve } from 'node:path'

export function encodeVirtualModuleId(id: string, plugin: ResolvedUnpluginOptions): string {
return resolve(plugin.__virtualModulePrefix, encodeURIComponent(id))
Expand Down
2 changes: 1 addition & 1 deletion src/utils/webpack-like.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RuleSetUseItem } from '@rspack/core'
import type { ResolvedUnpluginOptions } from '../types'
import { isAbsolute, normalize } from 'path'
import { isAbsolute, normalize } from 'node:path'

export function transformUse(
data: { resource?: string, resourceQuery?: string },
Expand Down
8 changes: 4 additions & 4 deletions src/webpack/context.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Compilation, Compiler, LoaderContext, sources } from 'webpack'
import type { UnpluginBuildContext, UnpluginContext, UnpluginMessage } from '../types'
import { Buffer } from 'buffer'
import { createRequire } from 'module'
import { resolve } from 'path'
import process from 'process'
import { Buffer } from 'node:buffer'
import { createRequire } from 'node:module'
import { resolve } from 'node:path'
import process from 'node:process'
import { parse } from '../utils/context'

interface ContextOptions {
Expand Down
6 changes: 3 additions & 3 deletions src/webpack/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ResolvePluginInstance, Resolver } from 'webpack'
import type { ResolvedUnpluginOptions, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginInstance, WebpackCompiler } from '../types'
import fs from 'fs'
import { resolve } from 'path'
import process from 'process'
import fs from 'node:fs'
import { resolve } from 'node:path'
import process from 'node:process'
import VirtualModulesPlugin from 'webpack-virtual-modules'
import { toArray } from '../utils/general'
import { normalizeAbsolutePath, transformUse } from '../utils/webpack-like'
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/load/__test__/build.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 fs from 'fs-extra'
import { describe, expect, it } from 'vitest'

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/load/rspack.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')
const { rspack } = require('./unplugin')

/** @type {import('@rspack/core').Configuration} */
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/load/unplugin.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 MagicString = require('magic-string')
const { createUnplugin } = require('unplugin')

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/load/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')
const { vite } = require('./unplugin')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/load/webpack.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')
const { webpack } = require('./unplugin')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/transform/__test__/build.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 fs from 'fs-extra'
import { describe, expect, it } from 'vitest'

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/transform/rspack.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')
const { rspack } = require('./unplugin')

/** @type {import('@rspack/core').Configuration} */
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/transform/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')
const { vite } = require('./unplugin')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/transform/webpack.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')
const { webpack } = require('./unplugin')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/virtual-module/__test__/build.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 fs from 'fs-extra'
import { describe, expect, it } from 'vitest'

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/virtual-module/rspack.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')
const { rspack } = require('./unplugin')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/virtual-module/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')
const { vite } = require('./unplugin')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/virtual-module/webpack.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')
const { webpack } = require('./unplugin')

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/id-consistency/id-consistency.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { UnpluginOptions, VitePlugin } from 'unplugin'
import type { Mock } from 'vitest'
import * as path from 'path'
import * as path from 'node:path'
import { createUnplugin } from 'unplugin'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { build, toArray } from '../utils'

const entryFilePath = path.resolve(__dirname, './test-src/entry.js')
const externals = ['path']
const externals = ['node:path']

function createUnpluginWithCallback(
resolveIdCallback: UnpluginOptions['resolveId'],
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/id-consistency/test-src/entry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from 'path'
import * as path from 'node:path'

// test external modules
import { named, proxiedDefault } from './proxy-export'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { VitePlugin } from 'unplugin'
import * as path from 'path'
import * as path from 'node:path'
import { createUnplugin } from 'unplugin'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { build, toArray } from '../utils'

const entryFilePath = path.resolve(__dirname, './test-src/entry.js')
const externals = ['path']
const externals = ['node:path']

describe('load hook should not be called when resolveId hook returned `external: true`', () => {
const mockResolveIdHook = vi.fn((id: string) => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/resolve-id/resolve-id.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnpluginBuildContext, UnpluginContext, UnpluginOptions, VitePlugin } from 'unplugin'
import type { Mock } from 'vitest'
import * as path from 'path'
import * as path from 'node:path'
import { createUnplugin } from 'unplugin'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { build, toArray } from '../utils'
Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/virtual-id/virtual-id.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { UnpluginOptions, VitePlugin } from 'unplugin'
import type { Mock } from 'vitest'
import * as fs from 'fs'
import * as path from 'path'
import * as fs from 'node:fs'
import * as path from 'node:path'
import { createUnplugin } from 'unplugin'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { build, toArray } from '../utils'
Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/write-bundle/write-bundle.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { RspackOptions } from '@rspack/core'
import type { UnpluginOptions, VitePlugin } from 'unplugin'
import type { Mock } from 'vitest'
import * as fs from 'fs'
import * as path from 'path'
import * as fs from 'node:fs'
import * as path from 'node:path'
import { createUnplugin } from 'unplugin'
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
import { build, toArray, webpackVersion } from '../utils'
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'

export default defineConfig({
Expand Down

0 comments on commit 9c3a471

Please sign in to comment.