Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for eager via the { eager: true } argument to import.meta.glob in Jest #51

Merged
merged 4 commits into from
Dec 26, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const modules = import.meta.glob("./fixtures/**/*", { eager: true })

↓ ↓ ↓ ↓ ↓ ↓

import * as __glob__0_0 from './fixtures/file1.ts'
import * as __glob__0_1 from './fixtures/file2.ts'
import * as __glob__0_2 from './fixtures/file3.ts'
const __glob__0_0 = require('./fixtures/file1.ts')
const __glob__0_1 = require('./fixtures/file2.ts')
const __glob__0_2 = require('./fixtures/file3.ts')
const modules = {
'./fixtures/file1.ts': __glob__0_0,
'./fixtures/file2.ts': __glob__0_1,
Expand Down Expand Up @@ -113,8 +113,8 @@ const modules = import.meta.glob("./fixtures/**/*{1,3}*", { eager: true })

↓ ↓ ↓ ↓ ↓ ↓

import * as __glob__0_0 from './fixtures/file1.ts'
import * as __glob__0_1 from './fixtures/file3.ts'
const __glob__0_0 = require('./fixtures/file1.ts')
const __glob__0_1 = require('./fixtures/file3.ts')
const modules = {
'./fixtures/file1.ts': __glob__0_0,
'./fixtures/file3.ts': __glob__0_1
Expand Down
8 changes: 6 additions & 2 deletions packages/babel-plugin-transform-vite-meta-glob/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ export default function viteMetaGlobBabelPlugin({
const identifiers = globPaths.map((_, idx) => t.identifier(`__glob__0_${idx}`))

const imports = globPaths.map((globPath, idx) => {
const specifier = t.importNamespaceSpecifier(identifiers[idx])
const modulePath = t.stringLiteral(globPath)
return t.importDeclaration([specifier], modulePath)
return t.variableDeclaration('const', [
t.variableDeclarator(
identifiers[idx],
t.callExpression(t.identifier('require'), [modulePath])
)
]);
})

const variable = t.variableDeclaration('const', [
Expand Down
Loading