Skip to content

Commit

Permalink
Fix(Cross Import): Require the old module
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Apr 11, 2023
1 parent 99e6586 commit efa86d8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
**/*node_modules
**/*.turbo
**/*out
**/*config-tmp.*

# Only exists if Bazel was run
/bazel-out
Expand Down
1 change: 1 addition & 0 deletions packages/cross-import/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function crossImport(
if (!filePath) return
const resolvedFilePath = upath.resolve(options.cwd, filePath)
try {
delete require.cache[resolvedFilePath]
return require(resolvedFilePath)
} catch {
return jiti(__dirname, {
Expand Down
13 changes: 13 additions & 0 deletions packages/cross-import/tests/no-cache/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import crossImport from '../../src'
import fs from 'fs'
import path from 'path'

it('require without cache', () => {
const configPath = path.join(__dirname, 'config-tmp.js')

fs.writeFileSync(configPath, 'module.exports = { a: 0 }')
expect(crossImport(configPath)).toEqual({ a: 0 })
jest.resetModules()
fs.writeFileSync(configPath, 'module.exports = { b: 0 }')
expect(crossImport(configPath)).toEqual({ b: 0 })
})

0 comments on commit efa86d8

Please sign in to comment.