Skip to content

src: convert project from CJS to ESM #2062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@kubernetes/client-node",
"version": "1.0.0-rc7",
"description": "NodeJS client for kubernetes",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/kubernetes-client/javascript.git"
Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './gen';
export * from './gen/index.js';
6 changes: 3 additions & 3 deletions src/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import WebSocket from 'isomorphic-ws';
import querystring from 'node:querystring';
import stream from 'node:stream';

import { KubeConfig } from './config';
import { isResizable, ResizableStream, TerminalSizeQueue } from './terminal-size-queue';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler';
import { KubeConfig } from './config.js';
import { isResizable, ResizableStream, TerminalSizeQueue } from './terminal-size-queue.js';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler.js';

export class Attach {
public 'handler': WebSocketInterface;
Expand Down
8 changes: 4 additions & 4 deletions src/attach_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers';
import { anyFunction, anything, capture, instance, mock, verify, when } from 'ts-mockito';

import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from '../test';
import { Attach } from './attach';
import { KubeConfig } from './config';
import { TerminalSize } from './terminal-size-queue';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler';
import { Attach } from './attach.js';
import { KubeConfig } from './config.js';
import { TerminalSize } from './terminal-size-queue.js';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler.js';

describe('Attach', () => {
describe('basic', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import https from 'node:https';

import { User } from './config_types';
import { User } from './config_types.js';
import WebSocket from 'isomorphic-ws';

export interface Authenticator {
Expand Down
6 changes: 3 additions & 3 deletions src/azure_auth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import proc from 'node:child_process';
import https from 'node:https';
import jsonpath from 'jsonpath-plus';
import * as jsonpath from 'jsonpath-plus';

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

/* FIXME: maybe we can extend the User and User.authProvider type to have a proper type.
Currently user.authProvider has `any` type and so we don't have a type for user.authProvider.config.
Expand Down
13 changes: 8 additions & 5 deletions src/azure_auth_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { use, expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { join } from 'node:path';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

import { User, Cluster } from './config_types';
import { AzureAuth } from './azure_auth';
import { KubeConfig } from './config';
import { HttpMethod, RequestContext } from '.';
import { User, Cluster } from './config_types.js';
import { AzureAuth } from './azure_auth.js';
import { KubeConfig } from './config.js';
import { HttpMethod, RequestContext } from './index.js';

const __dirname = dirname(fileURLToPath(import.meta.url));

use(chaiAsPromised);

Expand Down
8 changes: 4 additions & 4 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
ListPromise,
ObjectCallback,
UPDATE,
} from './informer';
import { KubernetesObject } from './types';
import { ObjectSerializer } from './serializer';
import { Watch } from './watch';
} from './informer.js';
import { KubernetesObject } from './types.js';
import { ObjectSerializer } from './serializer.js';
import { Watch } from './watch.js';

export interface ObjectCache<T> {
get(name: string, namespace?: string): T | undefined;
Expand Down
19 changes: 13 additions & 6 deletions src/cache_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ import chaiAsPromised from 'chai-as-promised';

import mock from 'ts-mockito';

import { V1Namespace, V1NamespaceList, V1ObjectMeta, V1Pod, V1PodList, V1ListMeta } from './api';
import { deleteObject, ListWatch, deleteItems, CacheMap, cacheMapFromList, addOrUpdateObject } from './cache';
import { KubeConfig } from './config';
import { Cluster, Context, User } from './config_types';
import { ListPromise } from './informer';
import { V1Namespace, V1NamespaceList, V1ObjectMeta, V1Pod, V1PodList, V1ListMeta } from './api.js';
import {
deleteObject,
ListWatch,
deleteItems,
CacheMap,
cacheMapFromList,
addOrUpdateObject,
} from './cache.js';
import { KubeConfig } from './config.js';
import { Cluster, Context, User } from './config_types.js';
import { ListPromise } from './informer.js';

use(chaiAsPromised);

import nock from 'nock';
import { Watch } from './watch';
import { Watch } from './watch.js';

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

Expand Down
18 changes: 9 additions & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import net from 'node:net';
import path from 'node:path';

import { Headers, RequestInit } from 'node-fetch';
import { RequestContext } from './api';
import { Authenticator } from './auth';
import { AzureAuth } from './azure_auth';
import { RequestContext } from './api.js';
import { Authenticator } from './auth.js';
import { AzureAuth } from './azure_auth.js';
import {
Cluster,
ConfigOptions,
Expand All @@ -19,18 +19,18 @@ import {
newContexts,
newUsers,
User,
} from './config_types';
import { ExecAuth } from './exec_auth';
import { FileAuth } from './file_auth';
import { GoogleCloudPlatformAuth } from './gcp_auth';
} from './config_types.js';
import { ExecAuth } from './exec_auth.js';
import { FileAuth } from './file_auth.js';
import { GoogleCloudPlatformAuth } from './gcp_auth.js';
import {
AuthMethodsConfiguration,
Configuration,
createConfiguration,
SecurityAuthentication,
ServerConfiguration,
} from './gen';
import { OpenIDConnectAuth } from './oidc_auth';
} from './gen/index.js';
import { OpenIDConnectAuth } from './oidc_auth.js';
import WebSocket from 'isomorphic-ws';
import child_process from 'node:child_process';

Expand Down
15 changes: 9 additions & 6 deletions src/config_test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { readFileSync } from 'node:fs';
import https from 'node:https';
import { Agent, RequestOptions } from 'node:https';
import path, { join } from 'node:path';
import path, { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

import { expect, use } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import mockfs from 'mock-fs';

import { Headers } from 'node-fetch';
import { HttpMethod } from '.';
import { HttpMethod } from './index.js';
import { assertRequestAgentsEqual, assertRequestOptionsEqual } from '../test/match-buffer';
import { CoreV1Api, RequestContext } from './api';
import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolutePath } from './config';
import { ActionOnInvalid, Cluster, newClusters, newContexts, newUsers, User } from './config_types';
import { ExecAuth } from './exec_auth';
import { CoreV1Api, RequestContext } from './api.js';
import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolutePath } from './config.js';
import { ActionOnInvalid, Cluster, newClusters, newContexts, newUsers, User } from './config_types.js';
import { ExecAuth } from './exec_auth.js';

const kcFileName = 'testdata/kubeconfig.yaml';
const kc2FileName = 'testdata/kubeconfig-2.yaml';
Expand All @@ -26,6 +27,8 @@ const kcInvalidContextFileName = 'testdata/empty-context-kubeconfig.yaml';
const kcInvalidClusterFileName = 'testdata/empty-cluster-kubeconfig.yaml';
const kcTlsServerNameFileName = 'testdata/tls-server-name-kubeconfig.yaml';

const __dirname = dirname(fileURLToPath(import.meta.url));

use(chaiAsPromised);

/* tslint:disable: no-empty */
Expand Down
4 changes: 2 additions & 2 deletions src/cp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { WritableStreamBuffer } from 'stream-buffers';
import * as tar from 'tar';
import tmp from 'tmp-promise';

import { KubeConfig } from './config';
import { Exec } from './exec';
import { KubeConfig } from './config.js';
import { Exec } from './exec.js';

export class Cp {
public execInstance: Exec;
Expand Down
8 changes: 4 additions & 4 deletions src/cp_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import querystring from 'node:querystring';
import WebSocket from 'isomorphic-ws';

import { CallAwaiter } from '../test';
import { KubeConfig } from './config';
import { Exec } from './exec';
import { Cp } from './cp';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler';
import { KubeConfig } from './config.js';
import { Exec } from './exec.js';
import { Cp } from './cp.js';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler.js';

describe('Cp', () => {
describe('cpFromPod', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import WebSocket from 'isomorphic-ws';
import querystring from 'node:querystring';
import stream from 'stream';

import { V1Status } from './api';
import { KubeConfig } from './config';
import { isResizable, ResizableStream, TerminalSizeQueue } from './terminal-size-queue';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler';
import { V1Status } from './api.js';
import { KubeConfig } from './config.js';
import { isResizable, ResizableStream, TerminalSizeQueue } from './terminal-size-queue.js';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler.js';

export class Exec {
public 'handler': WebSocketInterface;
Expand Down
4 changes: 2 additions & 2 deletions src/exec_auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { OutgoingHttpHeaders } from 'node:http';
import https from 'node:https';

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

import child_process from 'node:child_process';

Expand Down
4 changes: 2 additions & 2 deletions src/exec_auth_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use(chaiAsPromised);
import https from 'node:https';
import { OutgoingHttpHeaders } from 'node:http';

import { ExecAuth } from './exec_auth';
import { User } from './config_types';
import { ExecAuth } from './exec_auth.js';
import { User } from './config_types.js';

import child_process from 'node:child_process';

Expand Down
10 changes: 5 additions & 5 deletions src/exec_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers';
import { anyFunction, anything, capture, instance, mock, verify, when } from 'ts-mockito';

import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from '../test';
import { V1Status } from './api';
import { KubeConfig } from './config';
import { Exec } from './exec';
import { TerminalSize } from './terminal-size-queue';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler';
import { V1Status } from './api.js';
import { KubeConfig } from './config.js';
import { Exec } from './exec.js';
import { TerminalSize } from './terminal-size-queue.js';
import { WebSocketHandler, WebSocketInterface } from './web-socket-handler.js';

describe('Exec', () => {
describe('basic', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/file_auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'node:fs';
import https from 'node:https';

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

export class FileAuth implements Authenticator {
private token: string | null = null;
Expand Down
4 changes: 2 additions & 2 deletions src/file_auth_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { OutgoingHttpHeaders } from 'node:http';
import https from 'node:https';
import mockfs from 'mock-fs';

import { User } from './config_types';
import { FileAuth } from './file_auth';
import { User } from './config_types.js';
import { FileAuth } from './file_auth.js';

describe('FileAuth', () => {
it('should refresh when null', async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/gcp_auth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import proc from 'node:child_process';
import https from 'node:https';
import jsonpath from 'jsonpath-plus';
import * as jsonpath from 'jsonpath-plus';

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

/* FIXME: maybe we can extend the User and User.authProvider type to have a proper type.
Currently user.authProvider has `any` type and so we don't have a type for user.authProvider.config.
Expand Down
13 changes: 8 additions & 5 deletions src/gcp_auth_test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { expect } from 'chai';
import { join } from 'node:path';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

import { User, Cluster } from './config_types';
import { GoogleCloudPlatformAuth } from './gcp_auth';
import { KubeConfig } from './config';
import { HttpMethod, RequestContext } from './gen';
import { User, Cluster } from './config_types.js';
import { GoogleCloudPlatformAuth } from './gcp_auth.js';
import { KubeConfig } from './config.js';
import { HttpMethod, RequestContext } from './gen/index.js';
import { Agent } from 'node:https';

const __dirname = dirname(fileURLToPath(import.meta.url));

describe('GoogleCloudPlatformAuth', () => {
const testUrl1 = 'https://test-gcp.com';
var auth: GoogleCloudPlatformAuth;
Expand Down
4 changes: 2 additions & 2 deletions src/health.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetch, { AbortError } from 'node-fetch';
import { KubeConfig } from './config';
import fetch from 'node-fetch';
import { KubeConfig } from './config.js';
import { RequestOptions } from 'node:https';

export class Health {
Expand Down
6 changes: 3 additions & 3 deletions src/health_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from 'chai';
import nock from 'nock';

import { KubeConfig } from './config';
import { Health } from './health';
import { Cluster, User } from './config_types';
import { KubeConfig } from './config.js';
import { Health } from './health.js';
import { Cluster, User } from './config_types.js';

describe('Health', () => {
describe('livez', () => {
Expand Down
40 changes: 20 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
export * from './config';
export * from './cache';
export * from './api';
export * from './attach';
export * from './watch';
export * from './exec';
export * from './portforward';
export * from './types';
export * from './yaml';
export * from './log';
export * from './informer';
export * from './top';
export * from './cp';
export * from './patch';
export * from './metrics';
export * from './object';
export * from './health';
export { ConfigOptions, User, Cluster, Context } from './config_types';
export * from './config.js';
export * from './cache.js';
export * from './api.js';
export * from './attach.js';
export * from './watch.js';
export * from './exec.js';
export * from './portforward.js';
export * from './types.js';
export * from './yaml.js';
export * from './log.js';
export * from './informer.js';
export * from './top.js';
export * from './cp.js';
export * from './patch.js';
export * from './metrics.js';
export * from './object.js';
export * from './health.js';
export { type ConfigOptions, type User, type Cluster, type Context } from './config_types.js';

// Export AbortError and FetchError so that instanceof checks in user code will definitely use the same instances
export { AbortError, FetchError } from 'node-fetch';
// Export FetchError so that instanceof checks in user code will definitely use the same instance
Copy link
Contributor

@xkabylgSICKAG xkabylgSICKAG May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cjihrig why was this export of AbortError removed? We didn't update to the proper non-rc 1.x.x release before now, so didn't see this earlier.

The commit message says:

Remove the AbortError export originating from node-fetch. Apparently this is not actually there.

But as far as I can tell, this export definitely exists in node-fetch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xkabylgSICKAG I must have missed it. If you want to PR it back, that would be welcome.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export { FetchError } from 'node-fetch';
Loading
Loading