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
feat(api): add Node-compatible fs module #10998
Conversation
|
67ba094
to
df5b325
Compare
df5b325
to
8f94f70
Compare
8f94f70
to
23d080a
Compare
* @return {Ti.Filesystem.File} | ||
*/ | ||
function getTiFileFromPathLikeValue(path) { | ||
// Android can't properly handle file: URIs if they don't have trailing '//' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you have actually fixed that in the Android implementation, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an open PR for it (I don't think it's been merged yet)
I pushed up come commits to address the first round of feedback... |
|
||
it('truncates to 0 bytes by default', finished => { | ||
const dest = Ti.Filesystem.tempDirectory + `truncate_${Date.now()}.js`; | ||
fs.copyFileSync(thisFilePath, dest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ tests/Resources/fs.addontest.js line 997 – The 'fs.copyFileSync' is not supported until Node.js 8.5.0. The configured version range is '>=8'. (node/no-unsupported-features/node-builtins)
}); | ||
|
||
it('checks that non-existent file returns false', finished => { | ||
fs.exists('/some/made/up/path', exists => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ tests/Resources/fs.addontest.js line 244 – 'fs.exists' was deprecated since v4.0.0. Use 'fs.stat()' or 'fs.access()' instead. (node/no-deprecated-api)
|
||
it('truncates to 0 bytes by default', () => { | ||
const dest = Ti.Filesystem.tempDirectory + `truncateSync_${Date.now()}.js`; | ||
fs.copyFileSync(thisFilePath, dest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ tests/Resources/fs.addontest.js line 1033 – The 'fs.copyFileSync' is not supported until Node.js 8.5.0. The configured version range is '>=8'. (node/no-unsupported-features/node-builtins)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
All right, need to land one of the bugfixes in this PR (as #11098) and rebase all these commits down, then I'll merge it in... |
071a358
to
151b792
Compare
|
||
describe('#copyFile()', () => { | ||
it('is a function', () => { | ||
should(fs.copyFile).be.a.Function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ tests/Resources/fs.addontest.js line 176 – The 'fs.copyFile' is not supported until Node.js 8.5.0. The configured version range is '>=8'. (node/no-unsupported-features/node-builtins)
|
||
describe('#copyFileSync()', () => { | ||
it('is a function', () => { | ||
should(fs.copyFileSync).be.a.Function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ tests/Resources/fs.addontest.js line 206 – The 'fs.copyFileSync' is not supported until Node.js 8.5.0. The configured version range is '>=8'. (node/no-unsupported-features/node-builtins)
151b792
to
5c04349
Compare
|
||
it('truncates to specified number of bytes', finished => { | ||
const dest = Ti.Filesystem.tempDirectory + `truncate_bytes_${Date.now()}.js`; | ||
fs.copyFileSync(thisFilePath, dest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ tests/Resources/fs.addontest.js line 1011 – The 'fs.copyFileSync' is not supported until Node.js 8.5.0. The configured version range is '>=8'. (node/no-unsupported-features/node-builtins)
JIRA: https://jira.appcelerator.org/browse/TIMOB-18583
Description:
This adds a node-compatible
fs
module in our common JS code shipped with the SDK.The goal is to have a compatible shim that allows use of more npm packages out there since this is a pretty heavily used core module of Node. When possible I attempted to make the async variants more than simple wrappers that scheduled the sync version in a
setTimeout()
call (though I used that pattern for a number of the simpler ones).For example the basic read/write/copy operations I attempt to make use of our async stream APIs.
Note that the async variants are overall slower than the sync variants, but give the main thread/app time to "breathe" - which should make the app more usable from an end user perspective. I used
setTimeout
with a minimum wait threshold, so async variants will have an initial delay from the scheduling and enforcement of a minimum wait time - and that may be compounded if the implementation uses other async methods that use setTimeout to schedule.CAN'T/WON'T DO:
FOR LATER:
REQUIRES SDK CHANGES TO DO:
utimes
REQUIRES OTHER SHIMS TO DO:
createReadStream
createWriteStream
Both of these require creation of a
stream
shim first.