Skip to content

Commit af71c15

Browse files
committed
Use node: for Node.js builtin modules
Use the the `node:` protocol when importing Node.js builtin modules and enable rule in eslint to enforce. The `node:` protocol for Node.js builtin modules has been available since Node.js v14. See: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/enforce-node-protocol-usage.md
1 parent 67a17e4 commit af71c15

File tree

8 files changed

+25
-17
lines changed

8 files changed

+25
-17
lines changed

.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@
253253
"forceSingleLine": true
254254
}
255255
],
256+
"import/enforce-node-protocol-usage": [
257+
"error",
258+
"always"
259+
],
256260

257261
"unused-imports/no-unused-imports": "error",
258262
"lodash/import-scope": [

cypress/plugins/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs');
1+
const fs = require('node:fs');
22

33
// These two global variables are used to store information about the REST API used
44
// by these e2e tests. They are filled out prior to running any tests in the before()

lint/generate-docs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
readFileSync,
1313
rmSync,
1414
writeFileSync,
15-
} from 'fs';
16-
import { join } from 'path';
15+
} from 'node:fs';
16+
import { join } from 'node:path';
1717

1818
import { default as htmlPlugin } from './src/rules/html';
1919
import { default as tsPlugin } from './src/rules/ts';

lint/src/util/theme-support.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
* http://www.dspace.org/license/
77
*/
88

9+
import { readFileSync } from 'node:fs';
10+
import { basename } from 'node:path';
11+
912
import { TSESTree } from '@typescript-eslint/utils';
1013
import { RuleContext } from '@typescript-eslint/utils/ts-eslint';
11-
import { readFileSync } from 'fs';
12-
import { basename } from 'path';
1314
import ts, { Identifier } from 'typescript';
1415

1516
import {

src/app/core/services/server-xhr.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
* http://www.dspace.org/license/
77
*/
88

9-
import { XhrFactory } from '@angular/common';
10-
import { Injectable } from '@angular/core';
119
import {
1210
Agent as HttpAgent,
1311
AgentOptions as HttpAgentOptions,
14-
} from 'http';
15-
import { Agent as HttpsAgent } from 'https';
12+
} from 'node:http';
13+
import { Agent as HttpsAgent } from 'node:https';
14+
15+
import { XhrFactory } from '@angular/common';
16+
import { Injectable } from '@angular/core';
1617
import {
1718
prototype,
1819
XMLHttpRequest,

src/backend/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ITEMS from './data/items.json';
88
import { fakeDataBase } from './db';
99

1010
const { Router } = require('express');
11-
const util = require('util');
11+
const util = require('node:util');
1212

1313
// you would use cookies/token etc
1414
const USER_ID = 'f9d98cf1-1b96-464e-8755-bcc2a5c09077'; // hardcoded as an example

src/config/config.server.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import {
2+
existsSync,
3+
readFileSync,
4+
writeFileSync,
5+
} from 'node:fs';
6+
import { join } from 'node:path';
7+
18
import {
29
blue,
310
bold,
411
green,
512
red,
613
} from 'colors';
7-
import {
8-
existsSync,
9-
readFileSync,
10-
writeFileSync,
11-
} from 'fs';
1214
import { load } from 'js-yaml';
13-
import { join } from 'path';
1415

1516
import { isNotEmpty } from '../app/shared/empty.util';
1617
import { AppConfig } from './app-config.interface';

src/ngx-translate-loaders/translate-server.loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { readFileSync } from 'node:fs';
2+
13
import { TransferState } from '@angular/core';
24
import { TranslateLoader } from '@ngx-translate/core';
3-
import { readFileSync } from 'fs';
45
import {
56
Observable,
67
of,

0 commit comments

Comments
 (0)