Skip to content

Commit

Permalink
Convert to typescript (#287)
Browse files Browse the repository at this point in the history
* Convert expiring map to JS

* Conver option list to TypeScript

* Fix ESM plugin loading

This doesn’t seem to actually have any side-effects but typescript has revealed possible issues here

* Convert plugin loading to typescript

* Convert config loading to typescript

* Convert sorting code to typescript

* Convert utils to typescript

* Add types

* Convert main file to typescript

* wip

* Make package type: module

* Switch to vitest

* Update lockfile

* Run fixture tests concurrently

* Use tsup for building dts files

Can’t use it to bundle just yet

* Bump test timeout

* Use Node 18 in CI

* Use Node v22 in CI

Worth seeing if it makes things faster

* Remove expired data from maps to prevent memory leaks

* Update comments

* Remove comments

Probably isn’t any reason for this actually

* Add better types to `prefixCandidate`
  • Loading branch information
thecrypticace committed Jun 11, 2024
1 parent aa6ec0a commit 5e7b8b5
Show file tree
Hide file tree
Showing 28 changed files with 4,386 additions and 5,706 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:
env:
CI: true
CACHE_PREFIX: stable
NODE_VERSION: 16
NODE_VERSION: 22

jobs:
build:
Expand Down
25 changes: 4 additions & 21 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import * as fs from 'node:fs'
import * as path from 'node:path'
import { fileURLToPath } from 'node:url'
import esbuild from 'esbuild'

/**
Expand Down Expand Up @@ -62,23 +62,6 @@ function patchCjsInterop() {
}
}

/**
* @returns {import('esbuild').Plugin}
*/
function copyTypes() {
return {
name: 'copy-types',
setup(build) {
build.onEnd(() =>
fs.promises.copyFile(
path.resolve(__dirname, './src/index.d.ts'),
path.resolve(__dirname, './dist/index.d.ts'),
),
)
},
}
}

const __dirname = path.dirname(fileURLToPath(import.meta.url))

let context = await esbuild.context({
Expand All @@ -90,7 +73,7 @@ let context = await esbuild.context({
entryPoints: [path.resolve(__dirname, './src/index.js')],
outfile: path.resolve(__dirname, './dist/index.mjs'),
format: 'esm',
plugins: [patchRecast(), patchCjsInterop(), copyTypes()],
plugins: [patchRecast(), patchCjsInterop()],
})

await context.rebuild()
Expand Down
Loading

0 comments on commit 5e7b8b5

Please sign in to comment.