Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

style: apply prefer-node-protocol lint rule (#5627)

LongYinanfa8655e43ecd
diff --git a/.eslintrc.js b/.eslintrc.js
index 240f89f93f..aeefc341d1 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -217,6 +217,7 @@ const config = {
'unicorn/no-useless-promise-resolve-reject': 'error',
'unicorn/no-new-array': 'error',
'unicorn/new-for-builtins': 'error',
+ 'unicorn/prefer-node-protocol': 'error',
'sonarjs/no-all-duplicated-branches': 'error',
'sonarjs/no-element-overwrite': 'error',
'sonarjs/no-empty-collection': 'error',
diff --git a/packages/backend/server/src/fundamentals/graphql/index.ts b/packages/backend/server/src/fundamentals/graphql/index.ts
index 5f1b055638..dc168e939b 100644
--- a/packages/backend/server/src/fundamentals/graphql/index.ts
+++ b/packages/backend/server/src/fundamentals/graphql/index.ts
@@ -1,10 +1,11 @@
+import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
import type { ApolloDriverConfig } from '@nestjs/apollo';
import { ApolloDriver } from '@nestjs/apollo';
import { Global, Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { Request, Response } from 'express';
-import { join } from 'path';
-import { fileURLToPath } from 'url';
import { Config } from '../config';
import { GQLLoggerPlugin } from './logger-plugin';
diff --git a/packages/backend/server/src/fundamentals/storage/providers/fs.ts b/packages/backend/server/src/fundamentals/storage/providers/fs.ts
index 46dbe0cdea..6358ee6b93 100644
--- a/packages/backend/server/src/fundamentals/storage/providers/fs.ts
+++ b/packages/backend/server/src/fundamentals/storage/providers/fs.ts
@@ -11,9 +11,9 @@ import {
writeFileSync,
} from 'node:fs';
import { join, parse, resolve } from 'node:path';
+import { Readable } from 'node:stream';
import { Logger } from '@nestjs/common';
-import { Readable } from 'stream';
import { FsStorageConfig } from '../../config/storage';
import {
diff --git a/packages/common/infra/src/__tests__/migration.spec.ts b/packages/common/infra/src/__tests__/migration.spec.ts
index a133950c93..df2cadf10b 100644
--- a/packages/common/infra/src/__tests__/migration.spec.ts
+++ b/packages/common/infra/src/__tests__/migration.spec.ts
@@ -1,6 +1,7 @@
-import { readFileSync } from 'fs';
-import { dirname, resolve } from 'path';
-import { fileURLToPath } from 'url';
+import { readFileSync } from 'node:fs';
+import { dirname, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
import { describe, expect, test } from 'vitest';
import type { Array as YArray, Map as YMap } from 'yjs';
import { applyUpdate, Doc } from 'yjs';
diff --git a/packages/common/y-indexeddb/vite.config.ts b/packages/common/y-indexeddb/vite.config.ts
index 8c9713f7b9..8a52a8de64 100644
--- a/packages/common/y-indexeddb/vite.config.ts
+++ b/packages/common/y-indexeddb/vite.config.ts
@@ -1,6 +1,6 @@
import { resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
-import { fileURLToPath } from 'url';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
diff --git a/packages/common/y-provider/vite.config.ts b/packages/common/y-provider/vite.config.ts
index 25d98e4169..bd7ae60c81 100644
--- a/packages/common/y-provider/vite.config.ts
+++ b/packages/common/y-provider/vite.config.ts
@@ -1,6 +1,6 @@
import { resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
-import { fileURLToPath } from 'url';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
diff --git a/packages/frontend/electron/scripts/dev.ts b/packages/frontend/electron/scripts/dev.ts
index afba0df2df..3b990341c9 100644
--- a/packages/frontend/electron/scripts/dev.ts
+++ b/packages/frontend/electron/scripts/dev.ts
@@ -1,7 +1,7 @@
+import type { ChildProcessWithoutNullStreams } from 'node:child_process';
import { spawn } from 'node:child_process';
import { resolve } from 'node:path';
-import type { ChildProcessWithoutNullStreams } from 'child_process';
import type { BuildContext } from 'esbuild';
import * as esbuild from 'esbuild';
import kill from 'tree-kill';
diff --git a/packages/frontend/electron/scripts/make-squirrel.ts b/packages/frontend/electron/scripts/make-squirrel.ts
index d85b9b2d51..52aeacb0b5 100644
--- a/packages/frontend/electron/scripts/make-squirrel.ts
+++ b/packages/frontend/electron/scripts/make-squirrel.ts
@@ -1,7 +1,8 @@
+import path from 'node:path';
+
import type { Options as ElectronWinstallerOptions } from 'electron-winstaller';
import { convertVersion, createWindowsInstaller } from 'electron-winstaller';
import fs from 'fs-extra';
-import path from 'path';
import {
arch,
diff --git a/packages/frontend/electron/src/main/config-storage/persist.ts b/packages/frontend/electron/src/main/config-storage/persist.ts
index fe3621ee8a..78fe9bfb5b 100644
--- a/packages/frontend/electron/src/main/config-storage/persist.ts
+++ b/packages/frontend/electron/src/main/config-storage/persist.ts
@@ -1,10 +1,11 @@
+import fs from 'node:fs';
+import path from 'node:path';
+
import {
AppConfigStorage,
defaultAppConfig,
} from '@toeverything/infra/app-config-storage';
import { app } from 'electron';
-import fs from 'fs';
-import path from 'path';
const FILENAME = 'config.json';
const FILEPATH = path.join(app.getPath('userData'), FILENAME);
diff --git a/packages/frontend/electron/src/main/main-window.ts b/packages/frontend/electron/src/main/main-window.ts
index 9372b00831..cdf23271d9 100644
--- a/packages/frontend/electron/src/main/main-window.ts
+++ b/packages/frontend/electron/src/main/main-window.ts
@@ -1,8 +1,8 @@
import assert from 'node:assert';
+import { join } from 'node:path';
import { BrowserWindow, type CookiesSetDetails, nativeTheme } from 'electron';
import electronWindowState from 'electron-window-state';
-import { join } from 'path';
import { isMacOS, isWindows } from '../shared/utils';
import { mainWindowOrigin } from './constants';
diff --git a/packages/frontend/electron/src/main/onboarding.ts b/packages/frontend/electron/src/main/onboarding.ts
index 57b3adb625..a2923ea373 100644
--- a/packages/frontend/electron/src/main/onboarding.ts
+++ b/packages/frontend/electron/src/main/onboarding.ts
@@ -1,5 +1,6 @@
+import { join } from 'node:path';
+
import { BrowserWindow, type Display, screen } from 'electron';
-import { join } from 'path';
import { isMacOS } from '../shared/utils';
import { mainWindowOrigin } from './constants';
diff --git a/packages/frontend/electron/src/main/protocol.ts b/packages/frontend/electron/src/main/protocol.ts
index 2af632983c..ec1d875ec1 100644
--- a/packages/frontend/electron/src/main/protocol.ts
+++ b/packages/frontend/electron/src/main/protocol.ts
@@ -1,5 +1,6 @@
+import { join } from 'node:path';
+
import { net, protocol, session } from 'electron';
-import { join } from 'path';
import { CLOUD_BASE_URL } from './config';
import { logger } from './logger';
diff --git a/packages/frontend/electron/src/main/ui/google-auth.ts b/packages/frontend/electron/src/main/ui/google-auth.ts
index 833220bc89..4846e55e0f 100644
--- a/packages/frontend/electron/src/main/ui/google-auth.ts
+++ b/packages/frontend/electron/src/main/ui/google-auth.ts
@@ -1,5 +1,6 @@
+import { parse } from 'node:url';
+
import { app, BrowserWindow, shell } from 'electron';
-import { parse } from 'url';
import { logger } from '../logger';
diff --git a/packages/frontend/electron/test/main/mocks/updater.ts b/packages/frontend/electron/test/main/mocks/updater.ts
index f3fd31bd61..9cf65fac0c 100644
--- a/packages/frontend/electron/test/main/mocks/updater.ts
+++ b/packages/frontend/electron/test/main/mocks/updater.ts
@@ -1,7 +1,8 @@
import 'electron-updater'; // Prevent BaseUpdater is undefined.
+import { randomBytes } from 'node:crypto';
+
import { type AllPublishOptions, UUID } from 'builder-util-runtime';
-import { randomBytes } from 'crypto';
import type { AppAdapter } from 'electron-updater/out/AppAdapter';
import type { DownloadUpdateOptions } from 'electron-updater/out/AppUpdater';
import type { InstallOptions } from 'electron-updater/out/BaseUpdater';
diff --git a/packages/frontend/i18n/build.mjs b/packages/frontend/i18n/build.mjs
index 2b4069efeb..f6857cbf45 100644
--- a/packages/frontend/i18n/build.mjs
+++ b/packages/frontend/i18n/build.mjs
@@ -1,5 +1,6 @@
+import { fileURLToPath } from 'node:url';
+
import { runCli } from '@magic-works/i18n-codegen';
-import { fileURLToPath } from 'url';
runCli(
{
diff --git a/packages/frontend/i18n/dev.mjs b/packages/frontend/i18n/dev.mjs
index 0bc530e1df..8282704458 100644
--- a/packages/frontend/i18n/dev.mjs
+++ b/packages/frontend/i18n/dev.mjs
@@ -1,5 +1,6 @@
+import { fileURLToPath } from 'node:url';
+
import { runCli } from '@magic-works/i18n-codegen';
-import { fileURLToPath } from 'url';
runCli(
{
diff --git a/packages/frontend/templates/build.mjs b/packages/frontend/templates/build.mjs
index 8b59728a11..26769eff55 100644
--- a/packages/frontend/templates/build.mjs
+++ b/packages/frontend/templates/build.mjs
@@ -1,6 +1,7 @@
-import fs from 'fs';
+import fs from 'node:fs';
+import path from 'node:path';
+
import * as glob from 'glob';
-import path from 'path';
// purpose: bundle all json files into one json file in onboarding folder
const __dirname = new URL('.', import.meta.url).pathname;
diff --git a/tests/affine-cloud/e2e/collaboration.spec.ts b/tests/affine-cloud/e2e/collaboration.spec.ts
index 15a62e1b4d..d8ceb8966a 100644
--- a/tests/affine-cloud/e2e/collaboration.spec.ts
+++ b/tests/affine-cloud/e2e/collaboration.spec.ts
@@ -1,3 +1,5 @@
+import { resolve } from 'node:path';
+
import { skipOnboarding, test } from '@affine-test/kit/playwright';
import {
addUserToWorkspace,
@@ -16,7 +18,6 @@ import { clickUserInfoCard } from '@affine-test/kit/utils/setting';
import { clickSideBarSettingButton } from '@affine-test/kit/utils/sidebar';
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
import { expect } from '@playwright/test';
-import { resolve } from 'path';
let user: {
id: string;
diff --git a/tests/affine-local/e2e/image-preview.spec.ts b/tests/affine-local/e2e/image-preview.spec.ts
index a1e2e1245b..61850d9281 100644
--- a/tests/affine-local/e2e/image-preview.spec.ts
+++ b/tests/affine-local/e2e/image-preview.spec.ts
@@ -1,4 +1,6 @@
/* eslint-disable unicorn/prefer-dom-node-dataset */
+import fs from 'node:fs';
+
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
@@ -7,7 +9,6 @@ import {
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { expect, type Page } from '@playwright/test';
-import fs from 'fs';
async function importImage(page: Page, url: string) {
await page.evaluate(