Skip to content

Commit

Permalink
Migrate to ESM (#291)
Browse files Browse the repository at this point in the history
* Migrate to ESM

* Migrate to eslint flat config
  • Loading branch information
int128 authored Apr 13, 2024
1 parent 8a5faef commit bce4f8a
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 96 deletions.
14 changes: 0 additions & 14 deletions .eslintrc.json

This file was deleted.

21 changes: 21 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-check

import eslint from '@eslint/js'
import jest from 'eslint-plugin-jest'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{
ignores: ['.git/', 'node_modules/', 'dist/', 'eslint.config.js'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
jest.configs['flat/recommended'],
{
languageOptions: {
parserOptions: {
project: true,
},
},
},
)
12 changes: 7 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = {
preset: 'ts-jest',
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest/presets/default-esm',
clearMocks: true,
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
verbose: true
// https://kulshekhar.github.io/ts-jest/docs/guides/esm-support/
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"private": true,
"scripts": {
"format": "prettier --write **/*.ts",
"lint": "eslint **/*.ts",
"lint": "eslint .",
"build": "ncc build --source-map --license licenses.txt src/main.ts",
"test": "jest"
},
"type": "module",
"dependencies": {
"@actions/core": "1.10.1",
"@actions/glob": "0.4.0",
Expand All @@ -15,14 +16,13 @@
"@tsconfig/node20": "20.1.4",
"@types/jest": "29.5.12",
"@types/node": "20.12.5",
"@typescript-eslint/eslint-plugin": "7.5.0",
"@typescript-eslint/parser": "7.5.0",
"@vercel/ncc": "0.38.1",
"eslint": "9.0.0",
"eslint-plugin-jest": "28.2.0",
"jest": "29.7.0",
"prettier": "3.2.5",
"ts-jest": "29.1.2",
"typescript": "5.4.4"
"typescript": "5.4.4",
"typescript-eslint": "^7.6.0"
}
}
127 changes: 79 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import * as fs from 'fs/promises'
import * as glob from '@actions/glob'
import { v1 } from '@datadog/datadog-api-client'
import assert from 'assert'
import { Series } from '@datadog/datadog-api-client/dist/packages/datadog-api-client-v1'

export type MetricsFromCsvInputs = {
metricsCsvPath: string
}

export const sendMetricsFromCsv = async (api: v1.MetricsApi, inputs: MetricsFromCsvInputs) => {
const unixTime = Date.now() / 1000
const series: Series[] = []
const series: v1.Series[] = []

const csvGrobber = await glob.create(inputs.metricsCsvPath, { matchDirectories: false })
for await (const csvPath of csvGrobber.globGenerator()) {
Expand All @@ -24,8 +23,8 @@ export const sendMetricsFromCsv = async (api: v1.MetricsApi, inputs: MetricsFrom
core.info(`Sent the metrics: ${String(metricsResponse.status)}`)
}

export const parseMetricsCsv = async (csvPath: string, unixTime: number): Promise<Series[]> => {
const series: Series[] = []
export const parseMetricsCsv = async (csvPath: string, unixTime: number): Promise<v1.Series[]> => {
const series: v1.Series[] = []
const f = await fs.open(csvPath, 'r')
for await (const line of f.readLines()) {
const columns = line.split(',')
Expand Down
Loading

0 comments on commit bce4f8a

Please sign in to comment.