Skip to content

Commit c1871c9

Browse files
authored
Merge pull request #1922 from cjihrig/core-imports
refactor Node core module imports
2 parents 03aad44 + 695673a commit c1871c9

37 files changed

+58
-72
lines changed

examples/typescript/apply/apply-from-file-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// in a real program use require('@kubernetes/client-node')
22
import * as k8s from '../../../dist';
33
import * as yaml from 'js-yaml';
4-
import { promises as fs } from 'fs';
4+
import * as fs from 'node:fs/promises';
55

66
/**
77
* Replicate the functionality of `kubectl apply`. That is, create the resources defined in the `specFile` if they do
@@ -51,4 +51,4 @@ export async function apply(specPath: string): Promise<k8s.KubernetesObject[]> {
5151
}
5252

5353
return created;
54-
}
54+
}

examples/typescript/exec/exec-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// in a real program use require('@kubernetes/client-node')
22
import * as k8s from '../../../dist';
3-
import * as stream from 'stream';
3+
import * as stream from 'node:stream';
44

55
const command = process.argv[2];
66

examples/typescript/port-forward/port-forward.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// in a real program use require('@kubernetes/client-node')
22
import * as k8s from '../../../dist';
3-
import * as net from 'net';
3+
import * as net from 'node:net';
44

55
const kc = new k8s.KubeConfig();
66
kc.loadFromDefault();

src/attach.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import WebSocket = require('isomorphic-ws');
2-
import querystring = require('querystring');
3-
import stream = require('stream');
2+
import querystring = require('node:querystring');
3+
import stream = require('node:stream');
44

55
import { KubeConfig } from './config';
66
import { isResizable, ResizableStream, TerminalSizeQueue } from './terminal-size-queue';

src/auth.ts

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

33
import { User } from './config_types';
44
import WebSocket = require('isomorphic-ws');

src/azure_auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as proc from 'child_process';
2-
import https = require('https');
1+
import * as proc from 'node:child_process';
2+
import https = require('node:https');
33
import * as jsonpath from 'jsonpath-plus';
44

55
import { Authenticator } from './auth';

src/azure_auth_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { use, expect } from 'chai';
22
import chaiAsPromised from 'chai-as-promised';
3-
import { join } from 'path';
3+
import { join } from 'node:path';
44

55
import { User, Cluster } from './config_types';
66
import { AzureAuth } from './azure_auth';

src/cache_test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import chaiAsPromised = require('chai-as-promised');
33

44
import * as mock from 'ts-mockito';
55

6-
import http = require('http');
7-
86
import { V1ListMeta, V1Namespace, V1NamespaceList, V1ObjectMeta, V1Pod } from './api';
97
import { deleteItems, deleteObject, ListWatch } from './cache';
108
import { KubeConfig } from './config';

src/config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import fs = require('fs');
2-
import https = require('https');
1+
import fs = require('node:fs');
2+
import https = require('node:https');
33
import yaml = require('js-yaml');
4-
import net = require('net');
5-
import path = require('path');
4+
import net = require('node:net');
5+
import path = require('node:path');
66

77
import { Headers, RequestInit } from 'node-fetch';
88
import * as api from './api';
@@ -32,7 +32,7 @@ import {
3232
} from './gen';
3333
import { OpenIDConnectAuth } from './oidc_auth';
3434
import WebSocket = require('isomorphic-ws');
35-
import child_process = require('child_process');
35+
import child_process = require('node:child_process');
3636

3737
const SERVICEACCOUNT_ROOT: string = '/var/run/secrets/kubernetes.io/serviceaccount';
3838
const SERVICEACCOUNT_CA_PATH: string = SERVICEACCOUNT_ROOT + '/ca.crt';

src/config_test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { readFileSync } from 'fs';
2-
import * as https from 'https';
3-
import { Agent, RequestOptions } from 'https';
4-
import { join } from 'path';
1+
import { readFileSync } from 'node:fs';
2+
import * as https from 'node:https';
3+
import { Agent, RequestOptions } from 'node:https';
4+
import { join } from 'node:path';
55

66
import { expect, use } from 'chai';
77
import chaiAsPromised from 'chai-as-promised';
88
import mockfs = require('mock-fs');
9-
import * as path from 'path';
9+
import * as path from 'node:path';
1010

1111
import { Headers } from 'node-fetch';
1212
import { HttpMethod } from '.';

src/config_types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs';
1+
import * as fs from 'node:fs';
22

33
export enum ActionOnInvalid {
44
THROW = 'throw',

src/cp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs';
1+
import * as fs from 'node:fs';
22
import { WritableStreamBuffer } from 'stream-buffers';
33
import * as tar from 'tar';
44
import * as tmp from 'tmp-promise';

src/cp_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { anything, anyFunction, instance, mock, verify, when } from 'ts-mockito';
2-
import * as querystring from 'querystring';
2+
import * as querystring from 'node:querystring';
33
import WebSocket = require('isomorphic-ws');
44

55
import { CallAwaiter } from '../test';

src/exec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import WebSocket = require('isomorphic-ws');
2-
import querystring = require('querystring');
2+
import querystring = require('node:querystring');
33
import stream = require('stream');
44

55
import { V1Status } from './api';

src/exec_auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { OutgoingHttpHeaders } from 'http';
2-
import https = require('https');
1+
import { OutgoingHttpHeaders } from 'node:http';
2+
import https = require('node:https');
33

44
import { Authenticator } from './auth';
55
import { User } from './config_types';
66

7-
import child_process = require('child_process');
7+
import child_process = require('node:child_process');
88

99
export interface CredentialStatus {
1010
readonly token: string;

src/exec_auth_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { expect, use } from 'chai';
22
import chaiAsPromised from 'chai-as-promised';
33
use(chaiAsPromised);
44

5-
import https from 'https';
6-
import { OutgoingHttpHeaders } from 'http';
5+
import https from 'node:https';
6+
import { OutgoingHttpHeaders } from 'node:http';
77

88
import { ExecAuth } from './exec_auth';
99
import { User } from './config_types';
10-
import { fail } from 'assert';
10+
import { fail } from 'node:assert';
1111

12-
import child_process = require('child_process');
12+
import child_process = require('node:child_process');
1313

1414
describe('ExecAuth', () => {
1515
it('should claim correctly', () => {

src/file_auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs = require('fs');
2-
import https = require('https');
1+
import fs = require('node:fs');
2+
import https = require('node:https');
33

44
import { Authenticator } from './auth';
55
import { User } from './config_types';

src/file_auth_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
2-
import { OutgoingHttpHeaders } from 'http';
3-
import https from 'https';
2+
import { OutgoingHttpHeaders } from 'node:http';
3+
import https from 'node:https';
44
import mockfs from 'mock-fs';
55

66
import { User } from './config_types';

src/gcp_auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as proc from 'child_process';
2-
import https = require('https');
1+
import * as proc from 'node:child_process';
2+
import https = require('node:https');
33
import * as jsonpath from 'jsonpath-plus';
44

55
import { Authenticator } from './auth';

src/gcp_auth_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { expect } from 'chai';
2-
import { join } from 'path';
2+
import { join } from 'node:path';
33

44
import { User, Cluster } from './config_types';
55
import { GoogleCloudPlatformAuth } from './gcp_auth';
66
import { KubeConfig } from './config';
77
import { HttpMethod, RequestContext } from './gen';
8-
import { Agent } from 'https';
8+
import { Agent } from 'node:https';
99

1010
describe('GoogleCloudPlatformAuth', () => {
1111
const testUrl1 = 'https://test-gcp.com';

src/log.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fetch from 'node-fetch';
22
import { AbortSignal } from 'node-fetch/externals';
3-
import { Writable } from 'stream';
4-
import { URL, URLSearchParams } from 'url';
3+
import { Writable } from 'node:stream';
54
import { ApiException } from './api';
65
import { KubeConfig } from './config';
76
import { V1Status } from './gen';

src/log_test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from 'chai';
22
import { AddOptionsToSearchParams, LogOptions } from './log';
3-
import { URLSearchParams } from 'url';
43

54
describe('Log', () => {
65
describe('AddOptionsToSearchParams', () => {

src/metrics_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { fail } from 'assert';
1+
import { fail } from 'node:assert';
22
import { expect } from 'chai';
33
import nock = require('nock');
44
import { KubeConfig } from './config';
5-
import { V1Status, HttpException, ApiException } from './gen';
5+
import { V1Status, ApiException } from './gen';
66
import { Metrics, NodeMetricsList, PodMetricsList } from './metrics';
77

88
const emptyPodMetrics: PodMetricsList = {

src/object_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fail } from 'assert';
1+
import { fail } from 'node:assert';
22
import { expect } from 'chai';
33
import nock = require('nock');
44
import { Configuration, V1APIResource, V1APIResourceList, V1Secret } from './api';

src/oidc_auth.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import https from 'https';
1+
import https from 'node:https';
22
import { Client, Issuer } from 'openid-client';
33
import { base64url } from 'rfc4648';
4-
import { TextDecoder } from 'util';
54

65
import { Authenticator } from './auth';
76
import { User } from './config_types';

src/oidc_auth_test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { expect } from 'chai';
2-
import { OutgoingHttpHeaders } from 'http';
3-
import https from 'https';
2+
import { OutgoingHttpHeaders } from 'node:http';
3+
import https from 'node:https';
44
import { base64url } from 'rfc4648';
5-
import { TextEncoder } from 'util';
65

76
import { User } from './config_types';
87
import { OpenIDConnectAuth } from './oidc_auth';

src/package_test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect } from 'chai';
2-
import { URL } from 'url';
32

43
// Generic set of tests to verify the package is built and configured correctly
54
describe('package', () => {

src/portforward.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import WebSocket = require('isomorphic-ws');
2-
import querystring = require('querystring');
3-
import stream = require('stream');
2+
import querystring = require('node:querystring');
3+
import stream = require('node:stream');
44

55
import { KubeConfig } from './config';
66
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler';

src/portforward_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers';
3-
import { anyFunction, capture, instance, mock, reset, verify } from 'ts-mockito';
3+
import { anyFunction, capture, instance, mock, verify } from 'ts-mockito';
44

55
import { KubeConfig } from './config';
66
import { PortForward } from './portforward';

src/proto-client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import http = require('http');
2-
import url = require('url');
1+
import http = require('node:http');
32

43
import { KubeConfig } from './config';
54

@@ -8,7 +7,7 @@ export class ProtoClient {
87

98
public async get(msgType: any, requestPath: string): Promise<any> {
109
const server = this.config.getCurrentCluster()!.server;
11-
const u = new url.URL(server);
10+
const u = new URL(server);
1211
const options = {
1312
path: requestPath,
1413
hostname: u.hostname,

src/terminal-size-queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Readable, ReadableOptions } from 'stream';
1+
import { Readable, ReadableOptions } from 'node:stream';
22

33
export interface ResizableStream {
44
columns: number;

src/watch.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createInterface } from 'node:readline';
22
import fetch from 'node-fetch';
33
import { AbortSignal } from 'node-fetch/externals';
4-
import { URL } from 'url';
54
import { KubeConfig } from './config';
65

76
export class Watch {

src/watch_test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { expect } from 'chai';
2-
// import { anything, capture, instance, mock, spy, verify, when } from 'ts-mockito';
3-
42
import nock = require('nock');
5-
import { PassThrough } from 'stream';
3+
import { PassThrough } from 'node:stream';
64
import { KubeConfig } from './config';
75
import { Cluster, Context, User } from './config_types';
86
import { Watch } from './watch';
9-
import { IncomingMessage } from 'http';
7+
import { IncomingMessage } from 'node:http';
108

119
const server = 'http://foo.company.com';
1210

src/web-socket-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import WebSocket = require('isomorphic-ws');
2-
import stream = require('stream');
2+
import stream = require('node:stream');
33

44
import { V1Status } from './api';
55
import { KubeConfig } from './config';

src/web-socket-handler_test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Readable } from 'node:stream';
2-
import { promisify } from 'util';
2+
import { setImmediate as setImmediatePromise } from 'node:timers/promises';
33
import { expect } from 'chai';
44
import WebSocket = require('isomorphic-ws');
55
import { WritableStreamBuffer } from 'stream-buffers';
@@ -9,8 +9,6 @@ import { KubeConfig } from './config';
99
import { Cluster, Context, User } from './config_types';
1010
import { WebSocketHandler } from './web-socket-handler';
1111

12-
const setImmediatePromise = promisify(setImmediate);
13-
1412
describe('WebSocket', () => {
1513
it('should throw on unknown code', () => {
1614
const osStream = new WritableStreamBuffer();

test/call-awaiter.ts

Lines changed: 1 addition & 1 deletion
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
export class CallAwaiter extends EventEmitter {
44
public awaitCall(event: string) {

test/match-buffer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { deepStrictEqual } from 'assert';
21
import { expect } from 'chai';
3-
import { RequestOptions, Agent } from 'https';
2+
import { RequestOptions, Agent } from 'node:https';
43
import { Matcher } from 'ts-mockito/lib/matcher/type/Matcher';
54

65
export function matchBuffer(channel: number, contents: string): StringBufferMatcher {

0 commit comments

Comments
 (0)