Skip to content

Commit

Permalink
Fix monorepo npm release, bring in incompatible nodenext timestamp fn (
Browse files Browse the repository at this point in the history
…#16)

* use lerna for additional npm release, add verification via tsc, bring in timestamp fn that was incompatible with nodenext

* timestamp only test utc values due to CI difference in time zone settings
  • Loading branch information
rosskevin authored Jan 22, 2025
1 parent e5a29c5 commit f10faca
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ jobs:

# cannot run this on branches because it doesn't keep the canary version from auto shipit, can only secondarily publish to npm for main branch
- name: Publish secondarily to npm
run: npm publish --access=public --ignore-scripts --@alienfast:registry='https://registry.npmjs.org'
run: lerna exec --stream --parallel -- npm publish --access=public --ignore-scripts --@alienfast:registry='https://registry.npmjs.org'
if: github.ref == 'refs/heads/main'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"clean:yarn": "node ./scripts/clean-yarn.js",
"reset": "node ./scripts/reset.js",
"lint:fix": "eslint . --cache --fix",
"test": "lerna exec --stream --parallel -- yarn test",
"test": "yarn build:ide && lerna exec --stream --parallel -- yarn test",
"release": "yarn auto shipit",
"build:finalize": "lerna exec --stream --parallel -- buildFinalize"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/logger-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"postpack": "clean-package restore -c ../../.clean-package.json"
},
"dependencies": {
"chalk": "^5.4.1",
"time-stamp": "^2.2.0"
"chalk": "^5.4.1"
},
"devDependencies": {
"@alienfast/logger": "^11.0.31",
Expand Down
3 changes: 2 additions & 1 deletion packages/logger-node/src/NodeLogWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
/* eslint-disable no-console */
import { Level, LogWriter } from '@alienfast/logger'
import chalk, { ChalkInstance } from 'chalk'
import timestamp from 'time-stamp'

import { timestamp } from './timestamp.js'

// chalk.enabled = true

Expand Down
16 changes: 16 additions & 0 deletions packages/logger-node/src/__tests__/timestamp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest'

import { timestamp } from '../timestamp.js'

describe('timestamp', () => {
// const date = new Date('2025-01-02T03:04:05.006Z')
const date = new Date(Date.UTC(2025, 0, 2, 3, 4, 5, 6))
it('should format date', () => {
// CI gives me grief on these values when using non-utc, so just test utc

// expect(timestamp('YYYY-MM-DD HH:mm:ss.ms', false, date)).toEqual('2025-01-01 21:04:05.006')
expect(timestamp('YYYY-MM-DD HH:mm:ss.ms', true, date)).toEqual('2025-01-02 03:04:05.006')
// expect(timestamp('HH:mm:ss', false, date)).toEqual('21:04:05')
expect(timestamp('HH:mm:ss', true, date)).toEqual('03:04:05')
})
})
40 changes: 40 additions & 0 deletions packages/logger-node/src/timestamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*!
* time-stamp <https://github.com/jonschlinkert/time-stamp>
*
* Copyright (c) 2015-2018, Jon Schlinkert.
* Released under the MIT License.
*/
const dateRegex = /(?=(YYYY|YY|MM|DD|HH|mm|ss|ms))\1([:/]*)/g
const timespan = {
YYYY: ['getFullYear', 4],
YY: ['getFullYear', 2],
MM: ['getMonth', 2, 1], // getMonth is zero-based, thus the extra increment field
DD: ['getDate', 2],
HH: ['getHours', 2],
mm: ['getMinutes', 2],
ss: ['getSeconds', 2],
ms: ['getMilliseconds', 3],
} as const

type timespanKeys = keyof typeof timespan

export const timestamp = function (format: string, utc: boolean = false, date?: Date) {
// if (typeof format !== 'string') {
// date = format
// format = 'YYYY-MM-DD'
// }
if (!date) date = new Date()
return format.replace(dateRegex, function (match: string, key: timespanKeys, rest) {
const args = timespan[key]
let name = args[0]
const chars = args[1]
if (utc === true) name = 'getUTC' + name.slice(3)
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
const val = '00' + String((date as any)[name]() + (args[2] || 0))
return val.slice(-chars) + (rest || '')
})
}

// timestamp.utc = function (str, date) {
// return timestamp(str, date, true)
// }
14 changes: 3 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@alienfast/logger-browser@workspace:packages/logger-browser"
dependencies:
"@alienfast/logger": "npm:^11.0.30"
"@alienfast/logger": "npm:^11.0.31"
clean-package: "npm:^2.2.0"
vite: "npm:^6.0.11"
vitest: "npm:^3.0.3"
Expand All @@ -128,18 +128,17 @@ __metadata:
version: 0.0.0-use.local
resolution: "@alienfast/logger-node@workspace:packages/logger-node"
dependencies:
"@alienfast/logger": "npm:^11.0.30"
"@alienfast/logger": "npm:^11.0.31"
chalk: "npm:^5.4.1"
clean-package: "npm:^2.2.0"
time-stamp: "npm:^2.2.0"
vite: "npm:^6.0.11"
vitest: "npm:^3.0.3"
peerDependencies:
"@alienfast/logger": "*"
languageName: unknown
linkType: soft

"@alienfast/logger@npm:^11.0.30, @alienfast/logger@workspace:*, @alienfast/logger@workspace:packages/logger":
"@alienfast/logger@npm:^11.0.31, @alienfast/logger@workspace:*, @alienfast/logger@workspace:packages/logger":
version: 0.0.0-use.local
resolution: "@alienfast/logger@workspace:packages/logger"
dependencies:
Expand Down Expand Up @@ -9789,13 +9788,6 @@ __metadata:
languageName: node
linkType: hard

"time-stamp@npm:^2.2.0":
version: 2.2.0
resolution: "time-stamp@npm:2.2.0"
checksum: 10/b602ea7c86793989fb22cf5aec35307e78af3e3c4f9ef7efdf0dabe296def23684985a55fb56a37143d80256f07f17768916d80995cd197aa3a811470d2e6f54
languageName: node
linkType: hard

"tinybench@npm:^2.9.0":
version: 2.9.0
resolution: "tinybench@npm:2.9.0"
Expand Down

0 comments on commit f10faca

Please sign in to comment.