-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use memfs for ts artifacts to prevent mtime conflict
When ts-loader uses projectReferences mode, it writes down .js and .d.ts files. If it does it faster than the plugin, the typescript instance in the plugin is confused and doesn't work properly. To fix that, let's use memfs for dirs and files that are detected as a project artifacts.
- Loading branch information
1 parent
c297d58
commit a24fe1c
Showing
13 changed files
with
348 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
interface Dependencies { | ||
interface FilesMatch { | ||
files: string[]; | ||
dirs: string[]; | ||
extensions: string[]; | ||
} | ||
|
||
export { Dependencies }; | ||
export { FilesMatch }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { dirname } from 'path'; | ||
import { fs as mem } from 'memfs'; | ||
import { FileSystem } from './FileSystem'; | ||
// eslint-disable-next-line node/no-unsupported-features/node-builtins | ||
import { Dirent, Stats } from 'fs'; | ||
|
||
/** | ||
* It's an implementation of FileSystem interface which reads and writes to the in-memory file system. | ||
* | ||
* @param realFileSystem | ||
*/ | ||
function createMemFileSystem(realFileSystem: FileSystem): FileSystem { | ||
function exists(path: string): boolean { | ||
return mem.existsSync(realFileSystem.normalizePath(path)); | ||
} | ||
|
||
function readStats(path: string): Stats | undefined { | ||
return exists(path) ? mem.statSync(realFileSystem.normalizePath(path)) : undefined; | ||
} | ||
|
||
function readFile(path: string, encoding?: string): string | undefined { | ||
const stats = readStats(path); | ||
|
||
if (stats && stats.isFile()) { | ||
return mem | ||
.readFileSync(realFileSystem.normalizePath(path), { encoding: encoding as BufferEncoding }) | ||
.toString(); | ||
} | ||
} | ||
|
||
function readDir(path: string): Dirent[] { | ||
const stats = readStats(path); | ||
|
||
if (stats && stats.isDirectory()) { | ||
return mem.readdirSync(realFileSystem.normalizePath(path), { | ||
withFileTypes: true, | ||
}) as Dirent[]; | ||
} | ||
|
||
return []; | ||
} | ||
|
||
function createDir(path: string) { | ||
mem.mkdirSync(realFileSystem.normalizePath(path), { recursive: true }); | ||
} | ||
|
||
function writeFile(path: string, data: string) { | ||
if (!exists(dirname(path))) { | ||
createDir(dirname(path)); | ||
} | ||
|
||
mem.writeFileSync(realFileSystem.normalizePath(path), data); | ||
} | ||
|
||
function deleteFile(path: string) { | ||
if (exists(path)) { | ||
mem.unlinkSync(realFileSystem.normalizePath(path)); | ||
} | ||
} | ||
|
||
function updateTimes(path: string, atime: Date, mtime: Date) { | ||
if (exists(path)) { | ||
mem.utimesSync(realFileSystem.normalizePath(path), atime, mtime); | ||
} | ||
} | ||
|
||
return { | ||
...realFileSystem, | ||
exists(path: string) { | ||
return exists(realFileSystem.realPath(path)); | ||
}, | ||
readFile(path: string, encoding?: string) { | ||
return readFile(realFileSystem.realPath(path), encoding); | ||
}, | ||
readDir(path: string) { | ||
return readDir(realFileSystem.realPath(path)); | ||
}, | ||
readStats(path: string) { | ||
return readStats(realFileSystem.realPath(path)); | ||
}, | ||
writeFile(path: string, data: string) { | ||
writeFile(realFileSystem.realPath(path), data); | ||
}, | ||
deleteFile(path: string) { | ||
deleteFile(realFileSystem.realPath(path)); | ||
}, | ||
createDir(path: string) { | ||
createDir(realFileSystem.realPath(path)); | ||
}, | ||
updateTimes(path: string, atime: Date, mtime: Date) { | ||
updateTimes(realFileSystem.realPath(path), atime, mtime); | ||
}, | ||
clearCache() { | ||
realFileSystem.clearCache(); | ||
}, | ||
}; | ||
} | ||
|
||
export { createMemFileSystem }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.