Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
feat(logger): definePackage, the new api for global alwatr
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Oct 23, 2023
1 parent fa38b68 commit e3635e2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/logger/src/define-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {createLogger} from './logger.js';

import type {} from './type.js';

globalThis.Alwatr ??= {packages: {}};
Alwatr.packages ??= {};

const logger = createLogger('logger');

export const definePackage = (packageName: string, version: string) => {
logger.logMethodArgs?.('define-package', {packageName, version});

if (packageName in Alwatr.packages) {
logger.accident?.('define-package', 'duplicate_package_defined', {
packageName,
new: version,
old: Alwatr.packages[packageName],
});
return;
}

Alwatr.packages[packageName] = version;
};
10 changes: 10 additions & 0 deletions packages/logger/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/* eslint-disable no-var */

export interface GlobalAlwatr {
packages: Record<string, string>;
}

declare global {
var Alwatr: GlobalAlwatr;
}

export interface AlwatrLogger {
/**
* Debug state for current scope base on localStorage `ALWATR_LOG` pattern.
Expand Down

0 comments on commit e3635e2

Please sign in to comment.