This guide explains how to compile the TypeScript source code for @oresoftware/linked-queue.
This project supports both CommonJS and ES Module formats.
- Node.js (v12 or higher)
- npm or yarn
- TypeScript (installed as dev dependency)
npm installThis will install all dependencies including:
- TypeScript (
typescript@^5.9.3) - Type definitions (
@types/node@^12.6.1) - Development dependencies (suman, uuid)
# Install dependencies
npm install
# Build both CommonJS and ESM formats (if npm run build is configured)
npm run build
# Or compile directly with TypeScript
npx tscThe build process uses TypeScript configuration:
- tsconfig.json - Compiles to CommonJS in
dist/ - If ESM support is needed, a separate
tsconfig.esm.jsoncan compile to ES2020 modules indist/esm/
Compile TypeScript source files to JavaScript:
npx tscThis will:
- Read
tsconfig.jsonconfiguration - Compile all
.tsfiles fromsrc/directory - Output compiled
.jsand.d.tsfiles todist/directory - Generate type declarations for TypeScript consumers
- Source Directory:
src/ - Output Directory:
dist/ - Target: ES2020
- Module System: CommonJS
- Type Declarations: Enabled (
.d.tsfiles generated)
After compilation, you'll find in dist/:
linked-queue.js- Main compiled JavaScript file (CommonJS)linked-queue.d.ts- TypeScript type definitionsexample.js- Example fileexample.d.ts- Example type definitionsiterator.js- Iterator implementationiterator.d.ts- Iterator type definitions
If ESM build is configured:
dist/esm/linked-queue.js- ES Module build
# Test CommonJS
node -e "const {LinkedQueue} = require('@oresoftware/linked-queue'); console.log('CommonJS works!');"
# Test ESM (if ESM build exists)
node --input-type=module -e "import {LinkedQueue} from '@oresoftware/linked-queue'; console.log('ESM works!');"The project uses tsconfig.json with the following key settings:
- Target: ES2020
- Module: CommonJS
- Strict Mode: Enabled (
noImplicitAny: true) - Declaration: Enabled (generates
.d.tsfiles) - Root Directory:
src/ - Output Directory:
dist/
After compilation, verify the output:
ls -la dist/You should see:
- Compiled JavaScript files (
.js) - Type declaration files (
.d.ts)
For development, you can use TypeScript's watch mode:
npx tsc --watchThis will automatically recompile when source files change.
- Module not found errors: Run
npm installto ensure all dependencies are installed - Type errors: Check
tsconfig.jsonsettings and ensure source files are insrc/ - Output directory issues: Ensure
dist/directory exists or is writable
To start fresh:
rm -rf dist/
npx tscThe compiled output is referenced in package.json:
{
"main": "dist/linked-queue.js",
"types": "dist/linked-queue.d.ts",
"typings": "dist/linked-queue.d.ts"
}This allows the package to be imported as:
const {LinkedQueue} = require('@oresoftware/linked-queue');Or in TypeScript:
import {LinkedQueue} from '@oresoftware/linked-queue';