Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

fix: check pkg main #797

Merged
merged 4 commits into from
Sep 16, 2017
Merged

fix: check pkg main #797

merged 4 commits into from
Sep 16, 2017

Conversation

calebboyd
Copy link
Contributor

@calebboyd calebboyd commented Sep 14, 2017

This correctly identifies the main file (afaict)

But its still not resolving to the correct module. (null at runtime), so some tests are probably broken

@nchanged
Copy link
Contributor

Seems like a legit fix to me, let's figure out what's wrong with tests, we need to make them pass

@calebboyd
Copy link
Contributor Author

linking: #795

@calebboyd
Copy link
Contributor Author

calebboyd commented Sep 14, 2017

So this fix doesn't work.. It works in the context of "testFolder" But the require statement is not resolving the correct file. If you can point me in the right direction I can continue to investigate, but Im not very familiar with this portion of fusebox

@nchanged
Copy link
Contributor

well it should be here

if (fs.existsSync(folder)) {
for (let i = 0; i < extensions.length; i++) {
let ext = extensions[i];
const index = `index.${ext}`;
const target = path.join(folder, index);
if (fs.existsSync(target)) {
let result = path.join(name, index);
let startsWithDot = result[0] === "."; // After transformation we need to bring the dot back
if (startsWithDot) {
result = `./${result}`;
}
return result;
}
}

That's for sure, and has to return alias:

return {
resolved: path.resolve(root, name, folderJSON.main),
alias: this.ensureNodeModuleExtension(name)
}

Actually, alias should come here:

const folderPath = this.testFolder(folder, name);
if (folderPath) {
return { resolved: folderPath }

@calebboyd
Copy link
Contributor Author

I'm out for the night. I think I've fixed the issue. Please review!

@@ -326,12 +326,8 @@ gulp.task("installDevDeps", function(done) {
"buble",
];

if (os.platform().match(/^win/)) {
let windowsCommands = ["start", "cmd.exe", "/K", "npm", "install", "--no-save", ...deps];
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you remove that one?

Copy link
Contributor Author

@calebboyd calebboyd Sep 15, 2017

Choose a reason for hiding this comment

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

I replaced it with spawn('npm.cmd', ...) on windows

This avoids a shell popping up, that has to be closed manually before the task will finish

validPath = $pathJoin(filePath, "/", "index.js");
file = pkg.f[validPath];

if (!file && pkg.s && pkg.s.entry) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's that? Why did you modify the loader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the path is fully relative it will land here. See:
https://github.com/calebboyd/fuse-test

If its not the index it must be an entry file. Specifically, a fully relative name.

'..' or '../../'. As a guard an isRelative check could be made..

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

But what if there a package.json with a different entry? that's why we had that alias thingy in PathMaster, that overrides it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you have an idea of what alias needs to be set to, any tips would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I can tell providing an alias does nothing -- The property is set but then it is never used again...
Is that correct?

if (absPath.alias) {
data.fuseBoxAlias = absPath.alias;
}

@calebboyd calebboyd force-pushed the resolve-pkg branch 2 times, most recently from fb01ea7 to ce8fd28 Compare September 15, 2017 18:59
@@ -328,7 +328,7 @@ export class PathMaster {
let folder = path.isAbsolute(name) ? name : path.join(root, name);
const folderPath = this.testFolder(folder, name);
if (folderPath) {
return { resolved: folderPath }
return { resolved: folderPath, alias: name }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding alias here doesn't really do anything

let result
const pkg = this.tryReadPkg(folder)
if (pkg && pkg.main) {
result = path.join(name, pkg.main)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should return an alias (FuseBox will regenerate the code and point to a correct file)

@calebboyd calebboyd force-pushed the resolve-pkg branch 2 times, most recently from 4aa79c4 to 424a01a Compare September 16, 2017 16:14
validPath = $pathJoin(filePath, "/", "index.js");
file = pkg.f[validPath];

if (!file && filePath === ".") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to modify the loader? Which case does it cover? require(".")?
Shouldn't it require index if exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, So here is an example of it being hit
https://github.com/calebboyd/fuse-test

Adding a log in that if block (L301)
console.log('loading: "', name, '" filePath: "', filePath, '" entry: "', pkg.s.entry, '"')

->

loading: " ../ " filePath: " . " entry: " test.js "
loading: " ../../ " filePath: " . " entry: " test.js "

Copy link
Contributor Author

@calebboyd calebboyd Sep 16, 2017

Choose a reason for hiding this comment

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

It covers any fully relative path that resolves to the package.json in the root of the package (".")

@nchanged
Copy link
Contributor

Amazing, almost there, let's verify a few things before merging

@nchanged nchanged merged commit 3c219de into fuse-box:master Sep 16, 2017
@calebboyd calebboyd deleted the resolve-pkg branch September 16, 2017 17:28
@dgreif
Copy link
Contributor

dgreif commented Sep 22, 2017

Bundled a new project with fusebox today. It uses request-promise, which does some interesting require paths in require-promise-core. It failed with 2.2.31, but worked with 2.3.1-beta.14. This is a real-world case where @calebboyd's fix is needed.

@calebboyd calebboyd mentioned this pull request Oct 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants