Kyt Utilities
raw JSON →Kyt Utilities (`kyt-utils`) is an internal utility library developed by The New York Times, forming a core component of the `kyt` ecosystem, which is a React starter kit and framework. This package provides specialized helper functions designed for internal use within `kyt`-based applications and the `kyt` build system. Its functionalities include resolving project configurations, managing webpack setup, and handling environment variables and port assignments. The current stable version is 1.3.34. While it doesn't follow an independent public release cadence, it is actively maintained as part of the larger `kyt` mono-repository. Its primary purpose is to support the `kyt` framework, making it distinct from general-purpose utility libraries.
Common errors
error Module not found: Error: Can't resolve 'kyt-utils' ↓
import { someFunction } from 'kyt-utils/utils'; or import { anotherFunction } from 'kyt-utils/config'; error TypeError: someUtilityFunction is not a function ↓
import { someUtilityFunction } from '...') and that the import path precisely matches where the function is exported (e.g., /utils, /webpack, /config). Consult the kyt-utils source code for the exact export definitions. error ReferenceError: process is not defined ↓
kyt's client-side runtime for such features. Warnings
gotcha Kyt Utilities (`kyt-utils`) is primarily an internal package of the `kyt` framework. Its public API is not explicitly documented or guaranteed to be stable across `kyt` major versions. Direct consumption should be approached with caution as functions and their signatures may change without typical semver adherence for external consumers. ↓
breaking Prior to version 1.0.0, the utilities might have been exposed differently or were part of the main `kyt` package. The transition to a dedicated `kyt-utils` package (around 1.0.0) could have introduced breaking changes for existing code that relied on previous internal structures. ↓
gotcha Many exports from `kyt-utils` are from specific subpaths (e.g., `kyt-utils/utils`, `kyt-utils/webpack`, `kyt-utils/config`). Incorrect import paths will result in module not found errors or undefined imports, as the root `kyt-utils` package typically doesn't re-export all its internal modules directly. ↓
gotcha The package depends on `lodash`. While convenient, this adds `lodash`'s full bundle size to any client-side bundles if these utilities are inadvertently bundled for the browser. This can significantly impact client-side performance and bundle size. ↓
Install
npm install kyt-utils yarn add kyt-utils pnpm add kyt-utils Imports
- resolveCwd wrong
import { resolveCwd } from 'kyt-utils'; // Incorrect subpath const { resolveCwd } = require('kyt-utils/utils'); // CommonJS in an ESM-only contextcorrectimport { resolveCwd } from 'kyt-utils/utils'; - getWebpackConfig wrong
import getWebpackConfig from 'kyt-utils/webpack'; // Not a default export const getWebpackConfig = require('kyt-utils/webpack'); // CommonJS import of named exportcorrectimport { getWebpackConfig } from 'kyt-utils/webpack'; - getPort wrong
import * as config from 'kyt-utils/config'; // While technically correct, not idiomatic for single symbol import getPort from 'kyt-utils/config'; // Not a default exportcorrectimport { getPort } from 'kyt-utils/config';
Quickstart
import { resolveCwd, resolveAppConfig } from 'kyt-utils/utils';
import { getPort } from 'kyt-utils/config';
// Resolve the current working directory of the project.
const projectRoot = resolveCwd();
console.log(`Project root resolved to: ${projectRoot}`);
// Resolve the application-specific configuration. This typically involves
// loading and merging various config files based on environment.
const appConfig = resolveAppConfig();
console.log('Resolved Application Config:', appConfig);
// Asynchronously find an available port, often for a development server.
// getPort typically returns a Promise that resolves with an available port.
async function findAndLogPort() {
try {
const suggestedPort = parseInt(process.env.PORT ?? '3000', 10);
const availablePort = await getPort({ port: suggestedPort, host: 'localhost' });
console.log(`An available port found at: ${availablePort}`);
} catch (error) {
console.error('Failed to find an available port:', error instanceof Error ? error.message : String(error));
}
}
findAndLogPort();