Skip to content

Commit 63e5890

Browse files
committed
revert: "fix: clear js file cache when next load this file (#47)"
This reverts commit cc90b5f. closes #50, closes #42
1 parent a499e65 commit 63e5890

File tree

3 files changed

+6
-36
lines changed

3 files changed

+6
-36
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,3 @@ dist
7979

8080
# IDE
8181
.idea
82-
83-
# test
84-
packages/unconfig/test/fixtures/cache

packages/unconfig/src/index.ts

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,55 +35,28 @@ const loadConfigFile = quansync(async <T>(
3535
return code
3636
})
3737

38-
const clearCache = (cache: any, paths: string[]) => {
39-
for (const path of paths) {
40-
if (cache[path]) {
41-
delete cache[path]
42-
}
43-
}
44-
}
45-
4638
const importModule = quansync({
4739
sync: () => {
4840
const { createJiti } = require('jiti') as typeof import('jiti')
49-
50-
// Clear Node.js require cache for the target file before loading
51-
// This is crucial for hot-reload scenarios where file content changes
52-
clearCache(require.cache, [bundleFilepath, filepath])
53-
54-
const jiti = createJiti(filepath, {
41+
const jiti = createJiti(import.meta.url, {
5542
fsCache: false,
5643
moduleCache: false,
5744
interopDefault: true,
5845
})
59-
60-
// Clear jiti cache for the target file
61-
clearCache(jiti.cache, [bundleFilepath, filepath])
62-
6346
config = interopDefault(jiti(bundleFilepath))
64-
dependencies = Object.values(jiti.cache || {})
47+
dependencies = Object.values(jiti.cache)
6548
.map(i => i.filename)
6649
.filter(Boolean)
6750
},
6851
async: async () => {
6952
const { createJiti } = await import('jiti')
70-
71-
// Clear Node.js require cache for the target file before loading
72-
clearCache(require.cache, [bundleFilepath, filepath])
73-
74-
const jiti = createJiti(filepath, {
53+
const jiti = createJiti(import.meta.url, {
7554
fsCache: false,
7655
moduleCache: false,
7756
interopDefault: true,
7857
})
79-
80-
// Clear jiti cache for the target file
81-
clearCache(jiti.cache, [bundleFilepath, filepath])
82-
83-
// Use sync jiti() instead of jiti.import() to avoid ESM cache issues
84-
// jiti() uses CommonJS require which can be invalidated via require.cache
85-
config = interopDefault(jiti(bundleFilepath))
86-
dependencies = Object.values(jiti.cache || {})
58+
config = interopDefault(await jiti.import(bundleFilepath, { default: true }))
59+
dependencies = Object.values(jiti.cache)
8760
.map(i => i.filename)
8861
.filter(Boolean)
8962
},

packages/unconfig/test/run.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ it('array', async () => {
8787
.toMatchSnapshot()
8888
})
8989

90-
describe.each([
90+
describe.skip.each([
9191
'js',
9292
'ts',
9393
])('config ext: %s', async (ext) => {

0 commit comments

Comments
 (0)