-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): incorrect temp directory when bundling assets
The `os.tmpdir()` built-in doesn't return the real path when the returned path is a symlink. Add a `FileSystem.tmpdir` that wraps `os.tmpdir()` in a `fs.realpathSync()` and caches the result. Fixes #8465
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as fs from 'fs'; | ||
import { Test } from 'nodeunit'; | ||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
import * as sinon from 'sinon'; | ||
import { FileSystem } from '../../lib/fs'; | ||
|
||
export = { | ||
'tearDown'(callback: any) { | ||
sinon.restore(); | ||
callback(); | ||
}, | ||
|
||
'tmpdir returns a real path and is cached'(test: Test) { | ||
const symlinkTmp = path.join(__dirname, 'fixtures', 'symlinks', 'local-dir-link'); | ||
const tmpdirStub = sinon.stub(os, 'tmpdir').returns(symlinkTmp); | ||
|
||
test.ok(path.isAbsolute(FileSystem.tmpdir)); | ||
|
||
const p = path.join(FileSystem.tmpdir, 'tmpdir-test.txt'); | ||
fs.writeFileSync(p, 'tmpdir-test'); | ||
|
||
test.equal(p, fs.realpathSync(p)); | ||
test.equal(fs.readFileSync(p, 'utf8'), 'tmpdir-test'); | ||
|
||
test.ok(tmpdirStub.calledOnce); // cached result | ||
|
||
fs.unlinkSync(p); | ||
|
||
// @ts-ignore | ||
delete FileSystem._tmpdir; // do not use the wrong cached FileSystem.tmpdir in other tests | ||
|
||
test.done(); | ||
}, | ||
}; |