Skip to content

gurucore/lakdak

Repository files navigation

Lakdak: The common NodeJS utilities library

Common and best practices code are accumulated here in a NodeJS Lib for writting backend (API) services

Usage

In any TypeScript (or JavaScript) project, run:

npm i lakdak

Then in your code

import { FileHelper } from 'lakdak'
console.log(FileHelper())

If you cannot see the code suggestion (with comment), add this to tsconfig.json

{
  "compilerOptions": {
    "paths": {
      "lakdak": ["./node_modules/lakdak/dist/types/index.d.ts"]
    } // tells TypeScript: "When you see an import for 'lakdak', look exactly here for the types"
  }
}

To benefit tree-shaking, add this to tsconfig.json

{
  "compilerOptions": {
    "module": "ES2022",
    "moduleResolution": "bundler"
    // This will give you better tree-shaking and modern module benefits
  }
}

Developments

Project Setup for contribution

pnpm i

Compile and Hot-Reload for Development

pnpm dev

Test

  • Run pnpm test (watch mode) and change a test or source code to see HMR in action!

Build for production release

Support Type-Check, Compile and Minify for Production Support tree-shaking, each helper stays in its own file and can be imported separately Build to output both ES and UMD module.

  1. When introducing new class that need to expose, remember to export what you want to expose in index.ts
  2. Change package.json version string

NOTE about package.json - "type": "module"

Make this library intended to be consumed as an ES module. This setting ensures that Node.js treats .js files as ES modules by default.

We want to support both CommonJS and ES module consumers The build process outputs both module formats (already does this by specifying both main and module fields)

  • CommonJS consumers to use the main entry point
  • and ES module consumers to use the module entry point.

NOTE: about releasing

To avoid setup npm build and deploy, we can research to use deps like this: "@vbee-holding/node-shared-lib": "github:vbee-holding/vbee-node-shared-lib#v0.1.0" But this require the lib to be in public repo

  1. Run pnpm release
  2. The output will be put to /dist (support both ESM-MJS and CommonJS-CJS-UMD)
  3. commit the .dist folder to repo to publish it on Github
  4. create new versioned tag for the release (E.g.: v0.2.3)