Skip to content

Commit 5cbcf52

Browse files
authored
Meta: Use node: protocol for imports (sindresorhus#1892)
1 parent c25e707 commit 5cbcf52

24 files changed

+61
-61
lines changed

benchmark/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {URL} from 'url';
2-
import https from 'https';
1+
import {URL} from 'node:url';
2+
import https from 'node:https';
33
import axios from 'axios';
44
import Benchmark from 'benchmark';
55
import fetch from 'node-fetch';

benchmark/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {AddressInfo} from 'net';
2-
import https from 'https';
1+
import {AddressInfo} from 'node:net';
2+
import https from 'node:https';
33
// @ts-expect-error No types
44
import createCert from 'create-cert';
55

documentation/3-streams.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ This constructor takes the same arguments as the Got promise.
2323
> If the `body`, `json` or `form` option is used, this stream will be read-only.
2424
2525
```js
26-
import {promisify} from 'util';
27-
import stream from 'stream';
28-
import fs from 'fs';
26+
import {promisify} from 'node:util';
27+
import stream from 'node:stream';
28+
import fs from 'node:fs';
2929
import got from 'got';
3030

3131
const pipeline = promisify(stream.pipeline);
@@ -204,7 +204,7 @@ The error that caused this retry.
204204
**Type: `(options?: OptionsInit) => Request`**
205205

206206
```js
207-
import fs from 'fs';
207+
import fs from 'node:fs';
208208
import got from 'got';
209209

210210
let writeStream;

documentation/cache.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ View the [Keyv docs](https://github.com/lukechilds/keyv) for more information on
6666
The `request` function may return an instance of `IncomingMessage`-like class.
6767

6868
```js
69-
import https from 'https';
70-
import {Readable} from 'stream';
69+
import https from 'node:https';
70+
import {Readable} from 'node:stream';
7171
import got from 'got';
7272

7373
const getCachedResponse = (url, options) => {
@@ -106,8 +106,8 @@ console.log(body);
106106
If you don't want to alter the `request` function, you can return a cached response in a `beforeRequest` hook:
107107

108108
```js
109-
import https from 'https';
110-
import {Readable} from 'stream';
109+
import https from 'node:https';
110+
import {Readable} from 'node:stream';
111111
import got from 'got';
112112

113113
const getCachedResponse = (url, options) => {

documentation/examples/advanced-creation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const httpbin = got.extend({
8989
});
9090

9191
// Signing requests
92-
import crypto from 'crypto';
92+
import crypto from 'node:crypto';
9393

9494
const getMessageSignature = (data, secret) => crypto.createHmac('sha256', secret).update(data).digest('hex').toUpperCase();
9595
const signRequest = got.extend({

documentation/examples/uppercase-headers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import http from 'http';
1+
import http from 'node:http';
22
import got from '../../dist/source/index.js';
33

44
// Wraps an existing Agent instance

documentation/migration-guides/nodejs.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Let's make a simple request. With Node.js, this is:
1010

1111
```js
12-
import http from 'http';
12+
import http from 'node:http';
1313

1414
const request = http.request('https://httpbin.org/anything', response => {
1515
if (response.statusCode >= 400) {
@@ -60,8 +60,8 @@ try {
6060
Much cleaner. But what about streams?
6161

6262
```js
63-
import http from 'http';
64-
import fs from 'fs';
63+
import http from 'node:http';
64+
import fs from 'node:fs';
6565

6666
const source = fs.createReadStream('article.txt');
6767

@@ -78,8 +78,8 @@ Well, it's easy as that:
7878

7979
```js
8080
import got from 'got';
81-
import stream from 'stream';
82-
import fs from 'fs';
81+
import stream from 'node:stream';
82+
import fs from 'node:fs';
8383

8484
await stream.promises.pipeline(
8585
fs.createReadStream('article.txt'),

documentation/migration-guides/request.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ http.createServer((serverRequest, serverResponse) => {
113113
The cool feature here is that Request can proxy headers with the stream, but Got can do that too!
114114

115115
```js
116-
import {promisify} from 'util';
117-
import stream from 'stream';
116+
import {promisify} from 'node:util';
117+
import stream from 'node:stream';
118118
import got from 'got';
119119

120120
const pipeline = promisify(stream.pipeline);

documentation/tips.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Got supports cookies out of box. There is no need to parse them manually.\
4343
In order to use cookies, pass a `CookieJar` instance from the [`tough-cookie`](https://github.com/salesforce/tough-cookie) package.
4444

4545
```js
46-
import {promisify} from 'util';
46+
import {promisify} from 'node:util';
4747
import got from 'got';
4848
import {CookieJar} from 'tough-cookie';
4949

source/as-promise/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {EventEmitter} from 'events';
1+
import {EventEmitter} from 'node:events';
22
import is from '@sindresorhus/is';
33
import PCancelable from 'p-cancelable';
44
import {

source/as-promise/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Buffer} from 'buffer';
1+
import type {Buffer} from 'node:buffer';
22
import PCancelable from 'p-cancelable';
33
import {RequestError} from '../core/errors.js';
44
import type Request from '../core/index.js';

source/core/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import process from 'process';
2-
import {Buffer} from 'buffer';
3-
import {Duplex, Writable, Readable} from 'stream';
4-
import {URL, URLSearchParams} from 'url';
5-
import http, {ServerResponse} from 'http';
6-
import type {ClientRequest, RequestOptions} from 'http';
7-
import type {Socket} from 'net';
1+
import process from 'node:process';
2+
import {Buffer} from 'node:buffer';
3+
import {Duplex, Writable, Readable} from 'node:stream';
4+
import {URL, URLSearchParams} from 'node:url';
5+
import http, {ServerResponse} from 'node:http';
6+
import type {ClientRequest, RequestOptions} from 'node:http';
7+
import type {Socket} from 'node:net';
88
import timer from '@szmarczak/http-timer';
99
import CacheableRequest from 'cacheable-request';
1010
import decompressResponse from 'decompress-response';

source/core/options.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import process from 'process';
2-
import {Buffer} from 'buffer';
3-
import {promisify, inspect} from 'util';
4-
import {URL, URLSearchParams} from 'url';
5-
import {checkServerIdentity} from 'tls';
6-
import {request as httpRequest} from 'http';
7-
import {request as httpsRequest} from 'https';
8-
import type {Readable} from 'stream';
9-
import type {Socket} from 'net';
10-
import type {SecureContextOptions, DetailedPeerCertificate} from 'tls';
1+
import process from 'node:process';
2+
import {Buffer} from 'node:buffer';
3+
import {promisify, inspect} from 'node:util';
4+
import {URL, URLSearchParams} from 'node:url';
5+
import {checkServerIdentity} from 'node:tls';
6+
import {request as httpRequest} from 'node:http';
7+
import {request as httpsRequest} from 'node:https';
8+
import type {Readable} from 'node:stream';
9+
import type {Socket} from 'node:net';
10+
import type {SecureContextOptions, DetailedPeerCertificate} from 'node:tls';
1111
import type {
1212
Agent as HttpAgent,
1313
ClientRequest,
14-
} from 'http';
14+
} from 'node:http';
1515
import type {
1616
RequestOptions as HttpsRequestOptions,
1717
Agent as HttpsAgent,
18-
} from 'https';
19-
import type {InspectOptions} from 'util';
18+
} from 'node:https';
19+
import type {InspectOptions} from 'node:util';
2020
import is, {assert} from '@sindresorhus/is';
2121
import lowercaseKeys from 'lowercase-keys';
2222
import CacheableLookup from 'cacheable-lookup';

source/core/response.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type {Buffer} from 'buffer';
2-
import type {URL} from 'url';
1+
import type {Buffer} from 'node:buffer';
2+
import type {URL} from 'node:url';
33
import type {IncomingMessageWithTimings, Timings} from '@szmarczak/http-timer';
44
import {RequestError} from './errors.js';
55
import type {ParseJsonFunction, ResponseType} from './options.js';

source/core/timed-out.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import net from 'net';
2-
import {ClientRequest, IncomingMessage} from 'http';
1+
import net from 'node:net';
2+
import {ClientRequest, IncomingMessage} from 'node:http';
33
import unhandler from './utils/unhandle.js';
44

55
const reentry: unique symbol = Symbol('reentry');

source/core/utils/get-body-size.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Buffer} from 'buffer';
2-
import {promisify} from 'util';
3-
import {ClientRequestArgs} from 'http';
1+
import {Buffer} from 'node:buffer';
2+
import {promisify} from 'node:util';
3+
import {ClientRequestArgs} from 'node:http';
44
import is from '@sindresorhus/is';
55
import isFormData from './is-form-data.js';
66

source/core/utils/is-client-request.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type {Writable, Readable} from 'stream';
2-
import type {ClientRequest} from 'http';
1+
import type {Writable, Readable} from 'node:stream';
2+
import type {ClientRequest} from 'node:http';
33

44
function isClientRequest(clientRequest: Writable | Readable): clientRequest is ClientRequest {
55
return (clientRequest as Writable).writable && !(clientRequest as Writable).writableEnded;

source/core/utils/is-form-data.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Readable} from 'stream';
1+
import {Readable} from 'node:stream';
22
import is from '@sindresorhus/is';
33

44
interface FormData extends Readable {

source/core/utils/options-to-url.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* istanbul ignore file: deprecated */
2-
import {URL} from 'url';
2+
import {URL} from 'node:url';
33

44
export interface URLOptions {
55
href?: string;

source/core/utils/proxy-events.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {EventEmitter} from 'events';
1+
import {EventEmitter} from 'node:events';
22

33
type Fn = (...args: unknown[]) => void;
44
type Fns = Record<string, Fn>;

source/core/utils/unhandle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {EventEmitter} from 'events';
1+
import {EventEmitter} from 'node:events';
22

33
type Origin = EventEmitter;
44
type Event = string | symbol;

source/core/utils/url-to-options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {URL, UrlWithStringQuery} from 'url';
1+
import {URL, UrlWithStringQuery} from 'node:url';
22
import is from '@sindresorhus/is';
33

44
// TODO: Deprecate legacy URL at some point

source/create.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {URL} from 'url';
1+
import {URL} from 'node:url';
22
import is, {assert} from '@sindresorhus/is';
33
import asPromise from './as-promise/index.js';
44
import {

source/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type {Buffer} from 'buffer';
2-
import type {URL} from 'url';
1+
import type {Buffer} from 'node:buffer';
2+
import type {URL} from 'node:url';
33
import type {CancelableRequest} from './as-promise/types.js';
44
import type {Response} from './core/response.js';
55
import type Options from './core/options.js';

0 commit comments

Comments
 (0)