From 59a2dd07549a8ef3c68c4ad277aac83fd13a6061 Mon Sep 17 00:00:00 2001 From: Chad Nehemiah Date: Thu, 20 Jun 2024 14:40:11 -0400 Subject: [PATCH] chore!: add debug logger for fuel-ts ecosystem (#2366) * chore: added initial logger * docs: add changeset * fix: added enginge to package.json * docs: updated changeset * test: add more tests * build: undo coverage changes * feat: fix build issues * feat: update BN formatter * build: update lockfile * test: add more tests * docs: update changeset * test: add test environment config * test: remove browser testing * docs: revert changeset * test: add formatter tests --- .changeset/stupid-steaks-count.md | 5 + packages/logger/CHANGELOG.md | 0 packages/logger/LICENSE | 202 +++++++++++++++++++++++++++ packages/logger/README.md | 34 +++++ packages/logger/package.json | 42 ++++++ packages/logger/src/index.ts | 216 +++++++++++++++++++++++++++++ packages/logger/src/utils.ts | 17 +++ packages/logger/test/index.test.ts | 139 +++++++++++++++++++ packages/logger/test/utils.test.ts | 26 ++++ packages/logger/tsconfig.dts.json | 9 ++ packages/logger/tsconfig.json | 7 + packages/logger/tsdoc.json | 4 + packages/logger/tsup.config.ts | 3 + pnpm-lock.yaml | 19 +++ 14 files changed, 723 insertions(+) create mode 100644 .changeset/stupid-steaks-count.md create mode 100644 packages/logger/CHANGELOG.md create mode 100644 packages/logger/LICENSE create mode 100644 packages/logger/README.md create mode 100644 packages/logger/package.json create mode 100644 packages/logger/src/index.ts create mode 100644 packages/logger/src/utils.ts create mode 100644 packages/logger/test/index.test.ts create mode 100644 packages/logger/test/utils.test.ts create mode 100644 packages/logger/tsconfig.dts.json create mode 100644 packages/logger/tsconfig.json create mode 100644 packages/logger/tsdoc.json create mode 100644 packages/logger/tsup.config.ts diff --git a/.changeset/stupid-steaks-count.md b/.changeset/stupid-steaks-count.md new file mode 100644 index 00000000000..aaff9944a7c --- /dev/null +++ b/.changeset/stupid-steaks-count.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/logger": minor +--- + +chore!: add debug logger for fuel-ts ecosystem \ No newline at end of file diff --git a/packages/logger/CHANGELOG.md b/packages/logger/CHANGELOG.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/logger/LICENSE b/packages/logger/LICENSE new file mode 100644 index 00000000000..57bc88a15a0 --- /dev/null +++ b/packages/logger/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/packages/logger/README.md b/packages/logger/README.md new file mode 100644 index 00000000000..843d96819a5 --- /dev/null +++ b/packages/logger/README.md @@ -0,0 +1,34 @@ +# `@fuel-ts/logger` + +**@fuel-ts/logger** is a sub-module for logging within the **Fuel** TS ecosystem. + +A logging component that can be used to log messages to the console or to a file. + +# Table of contents + +- [`@fuel-ts/logger`](#fuel-tslogger) +- [Table of contents](#table-of-contents) + - [Installation](#installation) + - [Contributing](#contributing) + - [Changelog](#changelog) + - [License](#license) + +## Installation + +```sh +pnpm add @fuel-ts/logger +# or +npm add @fuel-ts/logger +``` + +## Contributing + +In order to contribute to `@fuel-ts/logger`, please see the main [fuels-ts](https://github.com/FuelLabs/fuels-ts) monorepo. + +## Changelog + +The `@fuel-ts/logger` changelog can be found at [CHANGELOG](./CHANGELOG.md). + +## License + +The primary license for `@fuel-ts/logger` is `Apache 2.0`, see [LICENSE](./LICENSE). diff --git a/packages/logger/package.json b/packages/logger/package.json new file mode 100644 index 00000000000..6e692a8d346 --- /dev/null +++ b/packages/logger/package.json @@ -0,0 +1,42 @@ +{ + "name": "@fuel-ts/logger", + "version": "0.89.2", + "author": "Fuel Labs (https://fuel.network/)", + "description": "A logger for the Fuel-TS ecosystem", + "main": "dist/index.js", + "module": "dist/index.mjs", + "types": "dist/index.d.ts", + "bugs": { + "url": "https://github.com/FuelLabs/fuels-ts/issues" + }, + "engines": { + "node": "^18.18.2 || ^20.0.0" + }, + "exports": { + ".": { + "require": "./dist/index.js", + "import": "./dist/index.mjs", + "types": "./dist/index.d.ts" + } + }, + "scripts": { + "build": "tsup", + "postbuild": "tsx ../../scripts/postbuild.ts" + }, + "keywords": [ + "Fuel" + ], + "files": [ + "dist" + ], + "dependencies": { + "debug": "^4.3.4", + "@fuel-ts/address": "workspace:*", + "@fuel-ts/interfaces": "workspace:*", + "@fuel-ts/math": "workspace:*" + }, + "devDependencies": { + "@types/debug": "^4.1.12" + }, + "license": "Apache-2.0" +} diff --git a/packages/logger/src/index.ts b/packages/logger/src/index.ts new file mode 100644 index 00000000000..a93a53989c5 --- /dev/null +++ b/packages/logger/src/index.ts @@ -0,0 +1,216 @@ +/* eslint-disable @typescript-eslint/no-shadow */ +/** + * @packageDocumentation + * + * A logger for fuel based on the [debug](https://www.npmjs.com/package/debug) module. + * + * @example + * + * ```TypeScript + * import { logger } from '@fuel-ts/logger' + * + * const log = logger('fuel-ts:my:package:name') + * + * try { + * // an operation + * log('something happened: %s', 'it was ok') + * } catch (err) { + * log.error('something bad happened: %o', err) + * } + * + * log('with this walletAddress: %w', address) + * log('and this B256: %b', address) + * log('and this bech32 address : %n', address) + * ``` + * + * ```console + * $ DEBUG=fuel-ts:* node index.js + * something happened: it was ok + * something bad happened: + * with this walletAddress: 0xf212....3aDc + * ``` + */ + +import { toBech32 } from '@fuel-ts/address'; +import type { Address } from '@fuel-ts/address'; +import type { AbstractAddress } from '@fuel-ts/interfaces'; +import type { BN } from '@fuel-ts/math'; +import { bn } from '@fuel-ts/math'; +import debug from 'debug'; + +import { truncateWalletAddress } from './utils'; + +function createDisabledLogger(namespace: string): debug.Debugger { + const logger = (): void => {}; + logger.enabled = false; + logger.color = ''; + logger.diff = 0; + logger.log = (): void => {}; + logger.namespace = namespace; + logger.destroy = () => true; + logger.extend = () => logger; + + return logger; +} + +/** + * Creates a logger for the passed component name. + * + * @example + * + * ```TypeScript + * import { logger } from '@fuel-ts/logger' + * + * const log = logger('my-component') + * log.info('hello world') + * // logs "my-component hello world" + * ``` + */ +export function logger(name: string): Logger { + // info logging is a no-op by default + let info: debug.Debugger = createDisabledLogger(`${name}:info`); + + // look at all the debug names and see if info logging has explicitly been enabled + if ( + debug.enabled(`${name}:info`) && + debug.names.map((r) => r.toString()).find((n) => n.includes(':info')) != null + ) { + info = debug(`${name}:info`); + } + + return Object.assign(debug(name), { + error: debug(`${name}:error`), + warn: debug(`${name}:warn`), + info, + }); +} + +export function disable(): void { + debug.disable(); +} + +export function enable(namespaces: string): void { + debug.enable(namespaces); +} + +export function enabled(namespaces: string): boolean { + return debug.enabled(namespaces); +} + +// Add a formatter for outputting a comma separated BN string +debug.formatters.a = (v?: BN): string => { + if (!v) { + return 'undefined'; + } + return v.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); +}; + +// Add a formatter for converting to a b256 string +debug.formatters.b = (v?: AbstractAddress): string => (v == null ? 'undefined' : v.toB256()); + +// Add a formatter for outputting a bech32 address +debug.formatters.c = (v?: AbstractAddress): string => + v == null ? 'undefined' : toBech32(v.toString()); + +// Add a formatter for outputting a BN hex string +debug.formatters.h = (v?: BN): string => (v == null ? 'undefined' : v.toHex()); + +// Converts a hex string to a BN string +debug.formatters.n = (hex: string): string => { + if (!hex) { + return 'undefined'; + } + try { + const bnValue = bn(hex, 'hex'); + return bnValue.toString(); + } catch (error) { + return 'invalid hex'; + } +}; + +export interface Logger { + (formatter: unknown, ...args: unknown[]): void; + error(formatter: unknown, ...args: unknown[]): void; + warn(formatter: unknown, ...args: unknown[]): void; + info(formatter: unknown, ...args: unknown[]): void; + enabled: boolean; +} + +export interface ComponentLogger { + forComponent(name: string): Logger; +} + +export interface AddressLoggerOptions { + prefixLength: number; + suffixLength: number; +} + +/** + * Create a component logger that will prefix any log messages with the passed + * string. + * + * @example + * + * ```TypeScript + * import { prefixLogger } from '@fuel-ts/logger' + * + * const logger = prefixLogger('my-node') + * + * const log = logger.forComponent('my-component') + * log.info('hello world') + * // logs "my-node:my-component hello world" + * ``` + */ +export function prefixLogger(prefix: string): ComponentLogger { + return { + forComponent(name: string) { + return logger(`${prefix}:${name}`); + }, + }; +} + +/** + * Create a component logger that will prefix any log messages with a truncated + * wallet address. + * + * @example + * + * ```TypeScript + * import { walletLogger } from '@fuel-ts/logger' + * + * const walletAddress = wallet.address.toAddress() + * const logger = walletLogger(walletAddress) + * + * const log = logger.forComponent('my-component') + * log.info('hello world') + * ``` + */ +export function walletLogger( + walletAddress: Address, + options: Partial = {} +): ComponentLogger { + return prefixLogger(truncateWalletAddress(walletAddress, options)); +} + +/** + * Create a component logger + * + * @example + * + * ```TypeScript + * import { defaultLogger } from '@fuel-ts/logger' + * + * const logger = defaultLogger() + * + * const log = logger.forComponent('my-package') + * log.info('hello world') + * // logs "my-package hello world" + * ``` + */ +export function defaultLogger(): ComponentLogger { + return { + forComponent(name: string) { + return logger(name); + }, + }; +} diff --git a/packages/logger/src/utils.ts b/packages/logger/src/utils.ts new file mode 100644 index 00000000000..fdb24729cbb --- /dev/null +++ b/packages/logger/src/utils.ts @@ -0,0 +1,17 @@ +import type { Address } from '@fuel-ts/address'; + +import type { AddressLoggerOptions } from './index'; + +export function truncateWalletAddress( + walletAddress: Address, + options: Partial = {} +): string { + const prefixLength = options.prefixLength ?? 2; + const suffixLength = options.suffixLength ?? 4; + + const walletAddressString = walletAddress.toString(); + return `${walletAddressString.substring(0, prefixLength)}…${walletAddressString.substring( + walletAddressString.length, + walletAddressString.length - suffixLength + )}`; +} diff --git a/packages/logger/test/index.test.ts b/packages/logger/test/index.test.ts new file mode 100644 index 00000000000..d458df5e663 --- /dev/null +++ b/packages/logger/test/index.test.ts @@ -0,0 +1,139 @@ +import type { AbstractAddress } from '@fuel-ts/interfaces'; +import { BN } from '@fuel-ts/math'; +import debug from 'debug'; + +import { logger, prefixLogger, defaultLogger } from '../src/index'; + +/** + * @group node + */ +describe('Logger Tests', () => { + let debugSpy; + + beforeEach(() => { + debug.enable('test'); + debugSpy = vi.spyOn(debug, 'log'); + }); + + afterEach(() => { + debugSpy.mockRestore(); + }); + + it('should log info messages correctly', () => { + const log = logger('test'); + const message = 'This is a message'; + log(message); + const callArgs = debugSpy.mock.calls[0][0]; + expect(callArgs).toContain(`test ${message}`); + }); + + it('should format a b256 string correctly', () => { + const log = logger('test'); + const mockAddress = { + toB256: () => '0x123456789abcdef', + toAddress: () => '0x12345678abcdef', + }; + const formattedMessage = 'test: %b'; + + log(formattedMessage, mockAddress); + + const callArgs = debugSpy.mock.calls[0][0]; + expect(callArgs).toContain('0x123456789abcdef'); + }); + + it('should prefix log messages correctly using prefixLogger', () => { + const prefix = 'my-node'; + const component = 'my-component'; + const message = 'hello world'; + const prefixedLogger = prefixLogger(prefix); + const log = prefixedLogger.forComponent(component); + + debug.enable('my-node:my-component'); + + log(message); + const callArgs = debugSpy.mock.calls[0][0]; + expect(callArgs).toContain(`${prefix}:${component} ${message}`); + }); + + it('should create a default logger and log messages correctly', () => { + const defaultLog = defaultLogger(); + const log = defaultLog.forComponent('test-component'); + debug.enable('test-component'); + const message = 'default logger test message'; + + log(message); + + const callArgs = debugSpy.mock.calls[0][0]; + expect(callArgs).toContain(`test-component ${message}`); + }); + + it('should format BN values with commas correctly using formatter a', () => { + const bnValue = new BN('1000000'); + const formatted = debug.formatters.a(bnValue); + expect(formatted).toBe('1,000,000'); + }); + + it('should return undefined for null input using formatter a', () => { + const formatted = debug.formatters.a(null); + expect(formatted).toBe('undefined'); + }); + + it('should format AbstractAddress to b256 string using formatter b', () => { + const mockAddress = { + toB256: () => '0xabcdef1234567890', + }; + const formatted = debug.formatters.b(mockAddress); + expect(formatted).toBe('0xabcdef1234567890'); + }); + + it('should return undefined for null input using formatter b', () => { + const formatted = debug.formatters.b(null); + expect(formatted).toBe('undefined'); + }); + + it('should format AbstractAddress to bech32 string using formatter c', () => { + const mockAddress: AbstractAddress = { + toJSON: () => '', + toString: () => '0x000000000000000000000000000000000000000000000000000000000000002a', + toAddress: () => 'fuel1xyzabc123', + toB256: () => '', + toHexString: () => '', + toBytes: () => new Uint8Array(), + equals: () => false, + }; + const formatted = debug.formatters.c(mockAddress); + expect(formatted).toBe('fuel1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq4qvpkv30'); + }); + + it('should return undefined for null input using formatter c', () => { + const formatted = debug.formatters.c(null); + expect(formatted).toBe('undefined'); + }); + + it('should format BN to hex string using formatter h', () => { + const bnValue = new BN('255'); + const formatted = debug.formatters.h(bnValue); + expect(formatted).toBe('0xff'); + }); + + it('should return undefined for null input using formatter h', () => { + const formatted = debug.formatters.h(null); + expect(formatted).toBe('undefined'); + }); + + it('should convert hex string to BN string using formatter n', () => { + const hex = '0xff'; + const formatted = debug.formatters.n(hex); + expect(formatted).toBe('255'); + }); + + it('should return undefined for empty input using formatter n', () => { + const formatted = debug.formatters.n(''); + expect(formatted).toBe('undefined'); + }); + + it('should return invalid hex for invalid input using formatter n', () => { + const formatted = debug.formatters.n('zzz'); + expect(formatted).toBe('invalid hex'); + }); +}); diff --git a/packages/logger/test/utils.test.ts b/packages/logger/test/utils.test.ts new file mode 100644 index 00000000000..aa90837ad35 --- /dev/null +++ b/packages/logger/test/utils.test.ts @@ -0,0 +1,26 @@ +import type { Address } from '@fuel-ts/address'; + +import { truncateWalletAddress } from '../src/utils'; + +/** + * @group node + * @group browser + */ +describe('truncateWalletAddress Tests', () => { + it('should correctly truncate a wallet address', () => { + const mockAddress: Address = { + toString: () => '0x1234567890abcdef1234567890abcdef', + }; + const options = { prefixLength: 6, suffixLength: 4 }; + const result = truncateWalletAddress(mockAddress, options); + expect(result).toBe('0x1234…cdef'); + }); + + it('should handle default options if none provided', () => { + const mockAddress: Address = { + toString: () => '0x1234567890abcdef1234567890abcdef', + }; + const result = truncateWalletAddress(mockAddress); + expect(result).toBe('0x…cdef'); + }); +}); diff --git a/packages/logger/tsconfig.dts.json b/packages/logger/tsconfig.dts.json new file mode 100644 index 00000000000..ccca2ac1f3e --- /dev/null +++ b/packages/logger/tsconfig.dts.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src" + }, + "include": ["src"], + "exclude": ["**/*.test.ts"] +} diff --git a/packages/logger/tsconfig.json b/packages/logger/tsconfig.json new file mode 100644 index 00000000000..b0fced27d72 --- /dev/null +++ b/packages/logger/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./dist" + }, + "include": ["src"] +} diff --git a/packages/logger/tsdoc.json b/packages/logger/tsdoc.json new file mode 100644 index 00000000000..4514b072727 --- /dev/null +++ b/packages/logger/tsdoc.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json", + "extends": ["../../tsdoc.base.json"] +} diff --git a/packages/logger/tsup.config.ts b/packages/logger/tsup.config.ts new file mode 100644 index 00000000000..4c7f2f0354f --- /dev/null +++ b/packages/logger/tsup.config.ts @@ -0,0 +1,3 @@ +import { index } from '@internal/tsup'; + +export default index; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d31579933f0..4cb3d669894 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1015,6 +1015,25 @@ importers: packages/interfaces: {} + packages/logger: + dependencies: + '@fuel-ts/address': + specifier: workspace:* + version: link:../address + '@fuel-ts/interfaces': + specifier: workspace:* + version: link:../interfaces + '@fuel-ts/math': + specifier: workspace:* + version: link:../math + debug: + specifier: ^4.3.4 + version: 4.3.4(supports-color@5.5.0) + devDependencies: + '@types/debug': + specifier: ^4.1.12 + version: 4.1.12 + packages/math: dependencies: '@fuel-ts/errors':