Skip to content

Commit f26e0c7

Browse files
committed
feat: support new URL(url, import.meta.url) pattern by default
closes #491
1 parent cc30d98 commit f26e0c7

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/features/rolldown.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ export async function resolveInputOptions(
183183
defaultHandler(level, log)
184184
}
185185
: undefined,
186+
experimental: {
187+
resolveNewUrlToAsset: true,
188+
},
186189
},
187190
config.inputOptions,
188191
[format, { cjsDts }],
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## assets/mod-BCOeK2IZ.ts
2+
3+
```ts
4+
export const foo = 42
5+
```
6+
## assets/text-gNTN1G_6.txt
7+
8+
```txt
9+
Just some text
10+
```
11+
## index.js
12+
13+
```js
14+
const modUrl = new URL("assets/mod-BCOeK2IZ.ts", import.meta.url);
15+
const textUrl = new URL("assets/text-gNTN1G_6.txt", import.meta.url);
16+
export { modUrl, textUrl };
17+
18+
```

tests/index.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,22 @@ test('dts not enabled when exports["."] is string instead of object', async (con
537537
expect(outputFiles).not.toContain('index.d.mts')
538538
expect(outputFiles).toContain('index.mjs')
539539
})
540+
541+
test('new URL(url, import.meta.url) pattern', async (context) => {
542+
const files = {
543+
'index.ts': `
544+
export const modUrl = new URL('./mod.ts', import.meta.url);
545+
export const textUrl = new URL('./text.txt', import.meta.url);
546+
`,
547+
'mod.ts': 'export const foo = 42',
548+
'text.txt': 'Just some text',
549+
}
550+
551+
await testBuild({
552+
context,
553+
files,
554+
options: {
555+
minify: 'dce-only',
556+
},
557+
})
558+
})

0 commit comments

Comments
 (0)