Skip to content
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

Merged
merged 2 commits into from Oct 15, 2019

Conversation

sgtcoolguy
Copy link
Contributor

@sgtcoolguy sgtcoolguy commented Jun 26, 2019

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:

  • chown/chmod
  • watch/unwatch

FOR LATER:

  • New promises API/FileHandle

REQUIRES SDK CHANGES TO DO:

  • utimes
  • Any link related methods (link, lstat, symlink, readLink) - though, how relevant are these in actual apps?

REQUIRES OTHER SHIMS TO DO:

  • createReadStream
  • createWriteStream

Both of these require creation of a stream shim first.

@build
Copy link
Contributor

build commented Jun 26, 2019

Warnings
⚠️

common/Resources/ti.internal/extensions/node/buffer.js#L76 - common/Resources/ti.internal/extensions/node/buffer.js line 76 – Missing JSDoc parameter description for 'arg'. (valid-jsdoc)

⚠️

common/Resources/ti.internal/extensions/node/buffer.js#L77 - common/Resources/ti.internal/extensions/node/buffer.js line 77 – Missing JSDoc parameter description for 'encodingOrOffset'. (valid-jsdoc)

⚠️

common/Resources/ti.internal/extensions/node/buffer.js#L78 - common/Resources/ti.internal/extensions/node/buffer.js line 78 – Missing JSDoc parameter description for 'length'. (valid-jsdoc)

⚠️

tests/Resources/fs.addontest.js#L191 - tests/Resources/fs.addontest.js line 191 – The 'fs.copyFile' is not supported until Node.js 8.5.0. The configured version range is '>=8'. (node/no-unsupported-features/node-builtins)

⚠️

tests/Resources/fs.addontest.js#L218 - tests/Resources/fs.addontest.js line 218 – The 'fs.copyFileSync' is not supported until Node.js 8.5.0. The configured version range is '>=8'. (node/no-unsupported-features/node-builtins)

⚠️

tests/Resources/fs.addontest.js#L229 - tests/Resources/fs.addontest.js line 229 – 'fs.exists' was deprecated since v4.0.0. Use 'fs.stat()' or 'fs.access()' instead. (node/no-deprecated-api)

⚠️

tests/Resources/fs.addontest.js#L233 - tests/Resources/fs.addontest.js line 233 – 'fs.exists' was deprecated since v4.0.0. Use 'fs.stat()' or 'fs.access()' instead. (node/no-deprecated-api)

⚠️

tests/Resources/fs.addontest.js#L1040 - tests/Resources/fs.addontest.js line 1040 – The 'fs.copyFileSync' is not supported until Node.js 8.5.0. The configured version range is '>=8'. (node/no-unsupported-features/node-builtins)

Messages
📖

💾 Here's the generated SDK zipfile.

📖

✅ All tests are passing
Nice one! All 4403 tests are passing.
(There are 479 skipped tests not included in that total)

📖 ✊ The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.

Generated by 🚫 dangerJS against 5c04349

common/Resources/ti.internal/extensions/node/fs.js Outdated Show resolved Hide resolved
common/Resources/ti.internal/extensions/node/fs.js Outdated Show resolved Hide resolved
common/Resources/ti.internal/extensions/node/fs.js Outdated Show resolved Hide resolved
common/Resources/ti.internal/extensions/node/fs.js Outdated Show resolved Hide resolved
common/Resources/ti.internal/extensions/node/fs.js Outdated Show resolved Hide resolved
* @return {Ti.Filesystem.File}
*/
function getTiFileFromPathLikeValue(path) {
// Android can't properly handle file: URIs if they don't have trailing '//'
Copy link
Contributor

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?

Copy link
Contributor Author

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)

common/Resources/ti.internal/extensions/node/fs.js Outdated Show resolved Hide resolved
common/Resources/ti.internal/extensions/node/fs.js Outdated Show resolved Hide resolved
@sgtcoolguy
Copy link
Contributor Author

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);
Copy link
Contributor

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 => {
Copy link
Contributor

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);
Copy link
Contributor

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)

Copy link
Contributor

@janvennemann janvennemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sgtcoolguy
Copy link
Contributor Author

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...


describe('#copyFile()', () => {
it('is a function', () => {
should(fs.copyFile).be.a.Function;
Copy link
Contributor

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;
Copy link
Contributor

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)


it('truncates to specified number of bytes', finished => {
const dest = Ti.Filesystem.tempDirectory + `truncate_bytes_${Date.now()}.js`;
fs.copyFileSync(thisFilePath, dest);
Copy link
Contributor

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)

@sgtcoolguy sgtcoolguy merged commit 74d07c1 into tidev:master Oct 15, 2019
@sgtcoolguy sgtcoolguy deleted the node-fs-rebased branch October 15, 2019 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants