Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/on-push-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
with:
title: 'chore: version packages'
commit: 'chore: version packages'
cwd: "./dev"
publish: pnpm changeset:release
version: pnpm changeset:version
env:
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions dev/.changeset/tidy-drinks-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"abitype": patch
---

Moves configuration files into dedicated `dev` folder
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions tsconfig.build.json → dev/configs/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
// This file is used to compile the for cjs and esm (see package.json build scripts). It should exclude all test files.
"extends": "./tsconfig.base.json",
"include": ["src"],
"include": ["../../src"],
"exclude": [
"src/**/*.test.ts",
"src/**/*.test-d.ts",
"src/**/*.bench.ts",
"src/_test"
"../../src/**/*.test.ts",
"../../src/**/*.test-d.ts",
"../../src/**/*.bench.ts",
"../../src/_test"
],
"compilerOptions": {
"sourceMap": true,
"rootDir": "./src"
"rootDir": "../../src"
}
}
5 changes: 3 additions & 2 deletions tsconfig.node.json → dev/configs/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
// This configuration is used for local development and type checking of configuration and script files that are not part of the build.
"include": ["vite.config.ts", "scripts"],
"include": ["vite.config.ts", "../scripts/**.ts", "../utils/**.ts"],
"compilerOptions": {
"strict": true,
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"rootDir": "../"
}
}
2 changes: 1 addition & 1 deletion vitest.config.ts → dev/configs/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export default defineConfig({
},
environment: 'node',
include: ['src/**/*.test.ts'],
setupFiles: ['./src/_test/setup.ts'],
setupFiles: ['src/_test/setup.ts'],
},
})
14 changes: 14 additions & 0 deletions dev/scripts/changeset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { repoDirs } from '../utils/path.js'
import { fromHere, shell } from '../utils/utils.js'

shell(
`node ${fromHere(
'..',
'..',
'node_modules',
'@changesets',
'cli',
'bin.js',
)} ${process.argv.slice(2).join(' ')}`,
{ cwd: repoDirs.dev },
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ generatePackageJson()

// Generates a package.json to be published to NPM with only the necessary fields.
function generatePackageJson() {
const packageJsonPath = path.join(__dirname, '../package.json')
const packageJsonPath = path.join(__dirname, '../../package.json')
const tmpPackageJson = readJsonSync(packageJsonPath)

writeJsonSync(`${packageJsonPath}.tmp`, tmpPackageJson, { spaces: 2 })
Expand Down
4 changes: 2 additions & 2 deletions scripts/updateVersion.ts → dev/scripts/updateVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { readJsonSync, writeFileSync } from 'fs-extra'
import path from 'path'

// Writes the current package.json version to `./src/version.ts`.
const versionFilePath = path.join(__dirname, '../src/version.ts')
const packageJsonPath = path.join(__dirname, '../package.json')
const versionFilePath = path.join(__dirname, '../../src/version.ts')
const packageJsonPath = path.join(__dirname, '../../package.json')
const packageVersion = readJsonSync(packageJsonPath).version

writeFileSync(versionFilePath, `export const version = '${packageVersion}'\n`)
103 changes: 103 additions & 0 deletions dev/utils/caller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copied from arktype https://github.com/arktypeio/arktype/tree/main/dev/attest/src

import { getCurrentLine, getFramesFromError } from './getCurrentLine.js'
import path from 'node:path'
import * as process from 'node:process'
import { fileURLToPath } from 'node:url'
import { isDeepStrictEqual } from 'node:util'

export type GetCallStackOptions = {
offset?: number
}

export const getCallStack = ({ offset = 0 }: GetCallStackOptions = {}) => {
const frames = getFramesFromError(new Error())
frames.splice(1, 1 + offset)
return frames
}

export type LinePosition = {
line: number
char: number
}

export type SourcePosition = LinePosition & {
file: string
method: string
}

export type CallerOfOptions = {
formatPath?: FormatFilePathOptions
upStackBy?: number
skip?: (position: SourcePosition) => boolean
methodName?: string
}

const nonexistentCurrentLine = {
line: -1,
char: -1,
method: '',
file: '',
}

export type FormatFilePathOptions = {
relative?: string | boolean
seperator?: string
}

export const formatFilePath = (
original: string,
{ relative, seperator }: FormatFilePathOptions,
) => {
let formatted = original
if (original.startsWith('file:///')) {
formatted = fileURLToPath(original)
}
if (relative) {
formatted = path.relative(
typeof relative === 'string' ? relative : process.cwd(),
formatted,
)
}
if (seperator) {
formatted = formatted.replace(new RegExp(`\\${path.sep}`, 'g'), seperator)
}
return formatted
}

export const caller = (options: CallerOfOptions = {}): SourcePosition => {
let upStackBy = options.upStackBy ?? 0
if (!options.methodName) {
upStackBy = 3
}
let match: SourcePosition | undefined
while (!match) {
const location = getCurrentLine({
method: options.methodName as string,
frames: upStackBy,
})

if (!location || isDeepStrictEqual(location, nonexistentCurrentLine)) {
throw new Error(
`No caller of '${
options.methodName
}' matches given options: ${JSON.stringify(options, null, 4)}.`,
)
}
const candidate = {
...location,
file: formatFilePath(location.file, options.formatPath ?? {}),
}
if (options.skip?.(candidate)) {
upStackBy++
} else {
match = candidate
}
}
return match
}

export const callsAgo = (
num: number,
options: Omit<CallerOfOptions, 'upStackBy'> = {},
) => caller({ methodName: 'callsAgo', upStackBy: num, ...options })
Loading