Skip to content

Commit 4223b9a

Browse files
committed
feat: support import.meta.glob
1 parent f78606e commit 4223b9a

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

client.d.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
interface ImportGlobOptions<Eager extends boolean> {
2+
/**
3+
* Import as static or dynamic
4+
*
5+
* @default false
6+
*/
7+
eager?: Eager
8+
/**
9+
* Import only the specific named export. Set to `default` to import the default export.
10+
*/
11+
import?: string
12+
/**
13+
* Custom queries
14+
*/
15+
query?: string | Record<string, string | number | boolean>
16+
/**
17+
* Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
18+
*
19+
* @default false
20+
*/
21+
exhaustive?: boolean
22+
/**
23+
* Base path to resolve relative paths.
24+
*/
25+
base?: string
26+
}
27+
28+
type GeneralImportGlobOptions = ImportGlobOptions<boolean>
29+
30+
interface KnownAsTypeMap {
31+
raw: string
32+
url: string
33+
}
34+
35+
interface ImportGlobFunction {
36+
/**
37+
* Import a list of files with a glob pattern.
38+
*
39+
* Overload 1: Module generic provided, infer the type from `eager: false`
40+
*/
41+
<M>(
42+
glob: string | string[],
43+
options?: ImportGlobOptions<false>,
44+
): Record<string, () => Promise<M>>
45+
/**
46+
* Import a list of files with a glob pattern.
47+
*
48+
* Overload 2: Module generic provided, infer the type from `eager: true`
49+
*/
50+
<M>(
51+
glob: string | string[],
52+
options: ImportGlobOptions<true>,
53+
): Record<string, M>
54+
}
55+
56+
interface ImportMeta {
57+
glob: ImportGlobFunction
58+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"author": "三咲智子 Kevin Deng <[email protected]>",
1717
"funding": "https://github.com/sponsors/sxzz",
1818
"files": [
19+
"client.d.ts",
1920
"dist",
2021
"esm-shims.js"
2122
],
@@ -27,7 +28,8 @@
2728
"./config": "./dist/config.mjs",
2829
"./plugins": "./dist/plugins.mjs",
2930
"./run": "./dist/run.mjs",
30-
"./package.json": "./package.json"
31+
"./package.json": "./package.json",
32+
"./client": "./client.d.ts"
3133
},
3234
"typesVersions": {
3335
"*": {

src/features/rolldown.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Debug from 'debug'
2+
import { importGlobPlugin } from 'rolldown/experimental'
23
import {
34
mergeUserOptions,
45
type DtsOptions,
@@ -125,7 +126,10 @@ export async function resolveInputOptions(
125126
await LightningCSSPlugin({ target }),
126127
)
127128
}
128-
plugins.push(ShebangPlugin(logger, cwd, name, isMultiFormat))
129+
plugins.push(
130+
ShebangPlugin(logger, cwd, name, isMultiFormat),
131+
importGlobPlugin(),
132+
)
129133
}
130134

131135
if (report && LogLevels[logger.level] >= 3 /* info */) {

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"verbatimModuleSyntax": true,
1717
"skipLibCheck": true
1818
},
19-
"include": ["src", "tests"],
19+
"include": ["src", "tests", "client.d.ts"],
2020
"exclude": ["**/temp", "**/fixtures"]
2121
}

tsdown.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ export default defineConfig({
1111
],
1212
},
1313
publint: true,
14-
exports: true,
14+
exports: {
15+
customExports(exports) {
16+
exports['./client'] = './client.d.ts'
17+
return exports
18+
},
19+
},
1520
fixedExtension: true,
1621
onSuccess() {
1722
console.info('🙏 Build succeeded!')

0 commit comments

Comments
 (0)