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

[TIMOB-27206] Unable to require files under node_modules #131

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

brentonhouse
Copy link
Contributor

@brentonhouse brentonhouse commented Jan 7, 2020

  • Added support for finding files located in node_modules
  • Some formatting changes occurred due to eslint scripts (eslint config was not changed)

Note:

There are several areas that I need to investigate to improve performance of this. Right now, it is checking to see if a file exists but is having to do it multiple times for each request because it doesn't know what files exists. I need to get access to (or create) a cache of JS files and native modules so that LiveView can just check this instead of the more time consuming check I implemented.

@brentonhouse brentonhouse self-assigned this Jan 7, 2020
@brentonhouse
Copy link
Contributor Author

@ewanharris - Is this PR waiting on anything? LiveView doesn't work without it if you use npm modules at all.

@ewanharris
Copy link
Contributor

@brentonhouse, I just haven't had time to review it yet. I gave preference to Ebenezer's PRs as he will be finishing on our team at the start of next week and I wanted to get him some product development before switching.

What ticket is this PR associated with?

@brentonhouse brentonhouse changed the title Node modules update [TIMOB-27206] Unable to require files under node_modules Feb 25, 2020
@brentonhouse
Copy link
Contributor Author

associated with: https://jira.appcelerator.org/browse/TIMOB-27206

Copy link
Contributor

@ewanharris ewanharris left a comment

Choose a reason for hiding this comment

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

Took an initial run through the code changes, need to pull this down and test it

file = Ti.Filesystem.getFile(path);
const idPath = path.parse(id);

// TIBUG: Fix for path.parse bug
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a ticket for this bug? I'd prefer to schedule a fix alongside this change to liveview rather than add fixes in liveview

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if there is a ticket for this. It probably involves replacing our custom "path" module with the open-source path module.

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed TIMOB-27899 to fix this in 9.1.0

// want to add these into a classic apps Resources dir
const buildNodeModulesPath = join(RESOURCE_DIR, '..', 'build', 'node_modules', uri);
const buildNodeModulesPath = join(RESOURCE_DIR, '..', 'build', 'node_modules', uri + urlPath.ext);
Copy link
Contributor

Choose a reason for hiding this comment

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

I need to double check but I think we can remove this now as we're bundling the sdk core JS code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I can remove it.

lib/fserver.js Outdated
} else {

let filename = join(RESOURCE_DIR, uri);
let filename = join(RESOURCE_DIR, uri + urlPath.ext);
log('[LiveView]'.green, 'filename: ' + filename);
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume these will be removed before merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@ewanharris ewanharris left a comment

Choose a reason for hiding this comment

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

Testing locally it seems like KS-v2 is erroring out on startup on Android with these changes, need to dig in to find the problem.

@brentonhouse, is your sample app working fine on Android?

const platformFilepath = join(RESOURCE_DIR, requestPlatform, uri + urlPath.ext);
const platformFilepath2 = join(RESOURCE_DIR, requestPlatform, uri, 'index' + urlPath.ext);
const overridePath = join(__dirname, 'overrides', uri + urlPath.ext);
const projectNodeModulesMainPath = join(RESOURCE_DIR, requestPlatform, 'node_modules', uri + urlPath.ext);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking up under Resources/<platform> is only correct for Alloy apps, we need to ensure this works for both Classic and Alloy.

Also, after testing this out I think only going on node_modules level deep might also be problematic, seeing as the algorithm we use in the SDK is pretty much the same as node (minus the loading of .node files) I think we could maybe use require.resolve with the paths set to the directory name

@ewanharris
Copy link
Contributor

@brentonhouse I've been trying this out in classic and there seems to be some issues around requiring files. If I create Resources/test.js and then do require('test') an error gets thrown, but require('test.js') works ok.

However if I then rebuild require('test') will work just fine, I'm guessing this is down to the on-device lookup that's performed in the liveview runtime and there being a difference in what gets sent to the liveview server.

I haven't tested yet but I'm going to guess that'll extend to alloy libs too

@brentonhouse
Copy link
Contributor Author

@ewanharris - I have had to change this around significantly in order for it to work with all the latest code. I ended up just doing the changes in the combined file instead of the split code files so I would work faster and test things easier. I would have to back track this to each of the separate files unless we are finally ready to get rid of those.

@ewanharris
Copy link
Contributor

@brentonhouse, I think I'm fine with removing the multiple files + concat build process. However I don't think it should be done in this PR as it would just add a ton of noise and make it difficult to review the require resolution changes

@ewanharris
Copy link
Contributor

@brentonhouse, if you want. Send me the build/liveview.js you have that's working and I can work on applying the changes back to the right places

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants