Skip to content

Commit 0cf8a36

Browse files
committed
fix(*): fix automatic imports (paths)
#1
1 parent a55b4f7 commit 0cf8a36

23 files changed

+124
-65
lines changed

.moon/toolchain.yml

+4
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ bun:
44
version: "1.1.8"
55
dependencyVersionFormat: "workspace"
66
syncProjectWorkspaceDependencies: true
7+
8+
typescript:
9+
syncProjectReferences: true
10+
syncProjectReferencesToPaths: false

bun.lockb

60 Bytes
Binary file not shown.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
"scripts": {
1616
"prepare": "husky",
1717
"commit": "commit"
18-
}
18+
},
19+
"trustedDependencies": [
20+
"@biomejs/biome"
21+
]
1922
}

packages/core/moon.yml

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ tasks:
1010
- "builder:build"
1111
inputs:
1212
- "src/**/*"
13-
- "types/**/*"
1413
outputs:
1514
- "dist/**"
1615
watch:
@@ -21,4 +20,3 @@ tasks:
2120
local: true
2221
inputs:
2322
- "src/**/*"
24-
- "types/**/*"

packages/core/package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{
22
"name": "@sirutils/core",
33
"version": "0.0.1",
4-
"type": "module",
54

6-
"main": "dist/index.js",
7-
"module": "dist/index.js",
8-
"types": "dist/index.d.ts",
9-
"files": ["dist", "src"],
5+
"type": "module",
6+
"files": ["dist"],
7+
"exports": {
8+
".": {
9+
"default": "./dist/index.js",
10+
"types": "./dist/index.d.ts"
11+
}
12+
},
1013

1114
"devDependencies": {
1215
"@sirutils/builder": "workspace:*"

packages/seql/moon.yml

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ tasks:
1111
- "core:build"
1212
inputs:
1313
- "src/**/*"
14-
- "types/**/*"
1514
outputs:
1615
- "dist/**"
1716
watch:
@@ -23,4 +22,3 @@ tasks:
2322
local: true
2423
inputs:
2524
- "src/**/*"
26-
- "types/**/*"

packages/seql/package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{
22
"name": "@sirutils/seql",
33
"version": "0.0.1",
4-
"type": "module",
54

6-
"main": "dist/index.js",
7-
"module": "dist/index.js",
8-
"types": "dist/index.d.ts",
9-
"files": ["dist", "src"],
5+
"type": "module",
6+
"files": ["dist"],
7+
"exports": {
8+
".": {
9+
"default": "./dist/index.js",
10+
"types": "./dist/index.d.ts"
11+
}
12+
},
1013

1114
"devDependencies": {
1215
"@sirutils/builder": "workspace:*"

packages/seql/src/definitions/seql.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare global {
3131
}
3232

3333
export interface AdapterOptions {
34-
paramterPattern: (str: string) => string
34+
parameterPattern: (str: string) => string
3535
}
3636

3737
export interface Env {

packages/seql/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { query } from './seql'
77
// biome-ignore lint/style/noNamespaceImport: For re-export as Seql
88
import * as builder from './utils/builder'
99
// biome-ignore lint/style/noNamespaceImport: For re-export as Seql
10-
import * as generater from './utils/generater'
10+
import * as generator from './utils/generator'
1111
// biome-ignore lint/style/noNamespaceImport: For re-export as Seql
1212
import * as operations from './utils/operations'
1313

1414
export const Seql = {
1515
query,
1616

1717
...builder,
18-
...generater,
18+
...generator,
1919
...operations,
2020
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const mysqlAdapter: Sirutils.Seql.AdapterOptions = {
2-
paramterPattern: () => '?',
2+
parameterPattern: () => '?',
33
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const postgresAdapter: Sirutils.Seql.AdapterOptions = {
2-
paramterPattern: str => `$${str}`,
2+
parameterPattern: str => `$${str}`,
33
}

packages/seql/src/seql.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { BlobType } from '@sirutils/core'
22

33
import { buildAll } from './utils/builder'
4-
import { generate } from './utils/generater'
4+
import { generate } from './utils/generator'
55

66
/**
77
* Use this for creating queries

packages/seql/src/utils/builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { BUILDER, CACHEABLE_OPERATIONS } from '../internal/consts'
55
import { logger } from '../internal/logger'
66
import { isObject, unique } from '../internal/utils'
77
import { seqlTags } from '../tag'
8-
import { generateCacheKey, isGenerated } from './generater'
8+
import { generateCacheKey, isGenerated } from './generator'
99

1010
/**
1111
* Base builder all other builds have to rely on this!
@@ -55,7 +55,7 @@ export const safe = <T>(value: T, key: string | null = null, include: true | str
5555
Array.isArray(include) ? (key ? include.includes(key) : false) : include,
5656
])
5757
: [[key, value, Array.isArray(include) ? (key ? include.includes(key) : false) : include]],
58-
nextParamID => selectedAdapter.paramterPattern(nextParamID.toString())
58+
nextParamID => selectedAdapter.parameterPattern(nextParamID.toString())
5959
)
6060
}
6161

packages/seql/src/utils/generater.ts packages/seql/src/utils/generator.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { BlobType } from '@sirutils/core'
2+
23
import { GENERATED } from '../internal/consts'
34
import { unique } from '../internal/utils'
45

packages/seql/src/utils/operations.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { buildAll, isBuilder, join, raw, safe, toSqlBuilder } from './builder'
2-
31
import { AND, INSERT, OR, UPDATE } from '../internal/consts'
42
import { extractKeys, filterUndefined } from '../internal/utils'
5-
import { isGenerated } from './generater'
3+
import { buildAll, isBuilder, join, raw, safe, toSqlBuilder } from './builder'
4+
import { isGenerated } from './generator'
65

76
/**
87
* Object to chained AND (use after WHERE)

packages/seql/test/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Seql } from '../src'
2-
import { generateCacheKey } from '../src/utils/generater'
2+
import { generateCacheKey } from '../src/utils/generator'
33

44
export const query = Seql.query`SELECT * FROM users WHERE ${Seql.or([
55
Seql.and({

tools/builder/moon.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ platform: "bun"
44

55
tasks:
66
build:
7-
command: "bun"
7+
command: "bun run src/index.ts build src/index.ts -a"
88
deps:
99
- "builder:clean"
10-
args:
11-
- "run"
12-
- "src/index.ts"
13-
- "build"
14-
- "src/index.ts"
15-
- "-a"
1610
inputs:
1711
- "src/**/*"
1812
outputs:

tools/builder/package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{
22
"name": "@sirutils/builder",
3-
"type": "module",
43
"version": "0.0.1",
54

65
"bin": {
76
"builder": "./command.js"
87
},
98

10-
"main": "dist/index.js",
11-
"module": "dist/index.js",
12-
"types": "dist/index.d.ts",
13-
"files": ["dist", "./command.js", "src"],
9+
"type": "module",
10+
"files": ["dist", "./command.js"],
11+
"exports": {
12+
".": {
13+
"default": "./dist/index.js",
14+
"types": "./dist/index.d.ts"
15+
}
16+
},
1417

1518
"devDependencies": {},
1619
"dependencies": {

tools/builder/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ program
1515
.option('--cwd <string>', 'cwd', process.cwd())
1616
.option('-a --external-all', 'externals', false)
1717
.option('-e --external <numbers...>', 'externals', [])
18+
.option('--no-dts', 'bundled .d.ts file', true)
1819
.action(async (paths: string[], options) => {
1920
const externals = [
2021
...(options.externalAll ? await dependencies(options.cwd) : []),
2122
...(options.external || []),
2223
]
2324

24-
await build(paths, options.cwd, externals)
25+
await build(paths, options.cwd, externals, options.dts)
2526

2627
if (options.watch) {
2728
watch(options.cwd, { recursive: true }, async (event, filename) => {
2829
if (typeof filename === 'string' && !filename.includes('dist')) {
29-
await build(paths, options.cwd, externals)
30+
await build(paths, options.cwd, externals, options.dts)
3031
}
3132
})
3233
}

tools/builder/src/plugins.ts

+44-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
1-
import { existsSync, mkdirSync } from 'node:fs'
2-
import { join } from 'path'
1+
import fs from 'fs'
2+
import path from 'path'
3+
import {
4+
type CompilationOptions,
5+
type EntryPointConfig,
6+
generateDtsBundle,
7+
} from 'dts-bundle-generator'
8+
import { getTsconfig } from 'get-tsconfig'
39

4-
import type { BunPlugin } from 'bun'
5-
6-
export const definitionGeneratorPlugin: BunPlugin = {
7-
name: 'Definition Generator Plugin',
8-
async setup(build) {
9-
const entrypoints = [...build.config.entrypoints].sort()
10+
type Options = Omit<EntryPointConfig, 'filePath'> & {
11+
compilationOptions?: CompilationOptions
12+
}
1013

11-
const outDir = build.config.outdir || './dist'
12-
if (!existsSync(outDir)) {
13-
mkdirSync(outDir)
14-
}
14+
export const dts = (options?: Options): import('bun').BunPlugin => {
15+
return {
16+
name: 'bun-plugin-dts',
17+
async setup(build) {
18+
const { compilationOptions, ...rest } = options || {}
1519

16-
await Promise.all(
17-
entrypoints.map(entry => {
18-
const srcFile = entry.replace(/^.*\//, '')
19-
const dtsFile = srcFile.replace(/\.[jtm]s$/, '.d.ts')
20-
const outFile = join(outDir, dtsFile)
20+
const entrypoints = [...build.config.entrypoints].sort()
21+
const entries = entrypoints.map(entry => {
22+
return {
23+
filePath: entry,
24+
...rest,
25+
}
26+
})
2127

22-
return Bun.write(outFile, `export * from "../src/${srcFile}"`)
28+
const tsconfig = compilationOptions?.preferredConfigPath ?? getTsconfig()?.path
29+
const result = generateDtsBundle(entries, {
30+
...compilationOptions,
31+
preferredConfigPath: tsconfig,
2332
})
24-
)
25-
},
33+
34+
const outDir = build.config.outdir || './dist'
35+
if (!fs.existsSync(outDir)) {
36+
fs.mkdirSync(outDir)
37+
}
38+
39+
await Promise.all(
40+
entrypoints.map((entry, index) => {
41+
const dtsFile = entry.replace(/^.*\//, '').replace(/\.[jtm]s$/, '.d.ts')
42+
const outFile = path.join(outDir, dtsFile)
43+
44+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
45+
return Bun.write(outFile, result[index] as any)
46+
})
47+
)
48+
},
49+
}
2650
}

tools/builder/src/utils.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join } from 'path'
22
import type { BunPlugin } from 'bun'
33

4-
import { definitionGeneratorPlugin } from './plugins'
4+
import { dts } from './plugins'
55

66
export const dependencies = async (cwd = process.cwd()): Promise<string[]> => {
77
const pkg = await Bun.file(join(cwd, './package.json')).json()
@@ -21,11 +21,28 @@ export const build = async (
2121
paths: string[],
2222
cwd: string = process.cwd(),
2323
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
24-
external = [] as any[]
24+
external = [] as any[],
25+
buildDts = true
2526
) => {
2627
const entryPoints = paths.map(p => join(cwd, p))
2728
const outDir = join(cwd, './dist')
28-
const plugins: BunPlugin[] = [definitionGeneratorPlugin]
29+
const plugins: BunPlugin[] = []
30+
31+
if (buildDts) {
32+
plugins.push(
33+
dts({
34+
output: {
35+
noBanner: true,
36+
inlineDeclareGlobals: true,
37+
exportReferencedTypes: false,
38+
},
39+
compilationOptions: {
40+
preferredConfigPath: join(cwd, 'tsconfig.json'),
41+
followSymlinks: false,
42+
},
43+
})
44+
)
45+
}
2946

3047
await Bun.build({
3148
entrypoints: entryPoints,

tsconfig.base.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"strict": true,
2525
"noUncheckedIndexedAccess": true,
2626
"strictNullChecks": true,
27+
"noImplicitAny": true,
2728

2829
"moduleResolution": "Bundler",
2930
"module": "esnext",

tsconfig.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
22
"extends": "./tsconfig.base.json",
3-
"references": []
3+
"references": [
4+
{
5+
"path": "packages/core"
6+
},
7+
{
8+
"path": "packages/seql"
9+
},
10+
{
11+
"path": "tools/builder"
12+
}
13+
]
414
}

0 commit comments

Comments
 (0)