diff --git a/docs/bun.md b/docs/bun.md new file mode 100644 index 0000000..7c7e2b0 --- /dev/null +++ b/docs/bun.md @@ -0,0 +1,39 @@ +# Bun + +## Issues + +Summary: +- `lodash_default is not a function` error when using `lodash.camelcase` package +- Using default import of `lodash` package may cause this issue + +Deployment at: +- https://github.com/thaitype/nammatham/actions/runs/9105382778 +- Executable File from `bun-win-x64` target + - Using bun to compile into single executable file + +Platform: + +- Azure Functions Windows +- Bun v1.1.8 (Windows x64) + +Package: + +- lodash.camelcase v4.3.0 +- nammatham on [commit 3f3b7b7 (2024-05-15)](https://github.com/thaitype/nammatham/commit/96ad8958c843553b0156d968b72e1d285c85041f) + - Build with tsup v8.0.1 + +``` +Bun v1.1.8 (Windows x64) +n/a +at B:/~BUN/root/main.exe:3061:12 +at http (B:/~BUN/root/main.exe:2983:5) +at http (B:/~BUN/root/main.exe:3031:13) +TypeError: lodash_default is not a function. (In 'lodash_default(options.name ?? options.route)', 'lodash_default' is undefined) +^ +3031 | name: lodash_default(options.name ?? options.route), +3030 | this.functions.push({ +3029 | } +3028 | throw new Error("Route or Name is required"); +3027 | if (options.route === undefined && options.name === undefined) { +3026 | http(options) { +``` \ No newline at end of file diff --git a/package.json b/package.json index 8c3a91b..17a0f33 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "tsup": "^8.0.1", "tsx": "^4.7.0", "typescript": "^5.3.3", - "vitest": "^1.1.3" + "vitest": "^1.2.1" }, "publishConfig": { "registry": "https://registry.npmjs.org/" diff --git a/packages/main/package.json b/packages/main/package.json index 5a9a78e..d1aae27 100644 --- a/packages/main/package.json +++ b/packages/main/package.json @@ -17,7 +17,7 @@ } }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "test": "vitest", "prepublishOnly": "npm run build", "build": "run-s build:*", "build:package": "tsup src/main.ts --dts --format esm --external bun,@types/bun", @@ -40,7 +40,6 @@ "esbuild": "^0.20.2", "execa": "^8.0.1", "invariant": "^2.2.4", - "lodash.camelcase": "^4.3.0", "lodash.merge": "^4.6.2", "pino": "^8.17.1", "pino-dev": "^4.0.3", @@ -60,7 +59,6 @@ }, "devDependencies": { "@types/debug": "^4.1.12", - "@types/lodash.camelcase": "^4.3.9", "@types/lodash.merge": "^4.6.9", "hono": "^4.3.6" } diff --git a/packages/main/src/nammatham.ts b/packages/main/src/nammatham.ts index 2cb8a5c..a77f197 100644 --- a/packages/main/src/nammatham.ts +++ b/packages/main/src/nammatham.ts @@ -1,7 +1,7 @@ -import camelCase from 'lodash.camelcase'; - import type { NammathamFunction, HttpTriggerOptions, NammathamTrigger } from './types'; +import { pascalCase } from './utils'; + export class Nammatham implements NammathamTrigger { protected functions: NammathamFunction[] = []; @@ -24,7 +24,7 @@ export class Nammatham implements NammathamTrigger { throw new Error('Route or Name is required'); } this.functions.push({ - name: camelCase(options.name ?? options.route), + name: pascalCase(options.name ?? options.route), metadata: { bindings: [ { diff --git a/packages/main/src/utils.test.ts b/packages/main/src/utils.test.ts new file mode 100644 index 0000000..43b79b7 --- /dev/null +++ b/packages/main/src/utils.test.ts @@ -0,0 +1,31 @@ +import { describe, expect, test } from 'vitest'; +import { pascalCase } from './utils'; + +describe('pascalCase', () => { + test('converts undefined to an empty string', () => { + expect(pascalCase(undefined)).toBe(''); + }); + test('converts a simple sentence to PascalCase', () => { + expect(pascalCase('convert any string to pascal case')).toBe('ConvertAnyStringToPascalCase'); + }); + + test('handles special characters correctly', () => { + expect(pascalCase('convert_any string-to!pascal@case')).toBe('ConvertAnyStringToPascalCase'); + }); + + test('handles a single word correctly', () => { + expect(pascalCase('hello')).toBe('Hello'); + }); + + test('handles an empty string correctly', () => { + expect(pascalCase('')).toBe(''); + }); + + test('handles multiple spaces correctly', () => { + expect(pascalCase(' multiple spaces in string ')).toBe('MultipleSpacesInString'); + }); + + test('handles numbers correctly', () => { + expect(pascalCase('convert 123 number')).toBe('Convert123Number'); + }); +}); diff --git a/packages/main/src/utils.ts b/packages/main/src/utils.ts new file mode 100644 index 0000000..6fa1fb9 --- /dev/null +++ b/packages/main/src/utils.ts @@ -0,0 +1,9 @@ +export function pascalCase(str: string | undefined): string { + if (str === undefined) { + return ''; + } + return str + .split(/[^a-zA-Z0-9]+/) + .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) + .join(''); +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9161bc6..a29e682 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,7 +72,7 @@ importers: specifier: ^5.3.3 version: 5.3.3 vitest: - specifier: ^1.1.3 + specifier: ^1.2.1 version: 1.2.1(@types/node@18.19.8) examples/with-bun: @@ -149,9 +149,6 @@ importers: invariant: specifier: ^2.2.4 version: 2.2.4 - lodash.camelcase: - specifier: ^4.3.0 - version: 4.3.0 lodash.merge: specifier: ^4.6.2 version: 4.6.2 @@ -174,9 +171,6 @@ importers: '@types/debug': specifier: ^4.1.12 version: 4.1.12 - '@types/lodash.camelcase': - specifier: ^4.3.9 - version: 4.3.9 '@types/lodash.merge': specifier: ^4.6.9 version: 4.6.9 @@ -1182,12 +1176,6 @@ packages: '@types/node': 18.19.8 dev: true - /@types/lodash.camelcase@4.3.9: - resolution: {integrity: sha512-ys9/hGBfsKxzmFI8hckII40V0ASQ83UM2pxfQRghHAwekhH4/jWtjz/3/9YDy7ZpUd/H0k2STSqmPR28dnj7Zg==} - dependencies: - '@types/lodash': 4.17.1 - dev: true - /@types/lodash.merge@4.6.9: resolution: {integrity: sha512-23sHDPmzd59kUgWyKGiOMO2Qb9YtqRO/x4IhkgNUiPQ1+5MUVqi6bCZeq9nBJ17msjIMbEIO5u+XW4Kz6aGUhQ==} dependencies: @@ -3415,10 +3403,6 @@ packages: p-locate: 5.0.0 dev: true - /lodash.camelcase@4.3.0: - resolution: {integrity: sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==} - dev: false - /lodash.merge@4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}