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

Weird behavior with path.resolve #444

Open
alexindigo opened this issue Jun 29, 2019 · 6 comments
Open

Weird behavior with path.resolve #444

alexindigo opened this issue Jun 29, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@alexindigo
Copy link

alexindigo commented Jun 29, 2019

Switched from @zeit/ncc@^0.11.0 to @zeit/ncc@0.20.2 and observing weird behavior with path.resolve:

js file

var fileWithExt = filename + '.' + ext;
console.log('- 1:', path.resolve(dir, fileWithExt));
console.log('- 2:', path.resolve(dir, filename + '.' + ext));

Run it with ./node_modules/.bin/ncc run test.js

Output:

- 1: /Users/alex/Projects/configly/test/fixtures/config/basic/runtime.js
- 2: /private/var/folders/zb/mp_ksxdx4p14t518_6d523lr0000gn/T/e022a7461cd2d3e99b8a466628324dbc/configly/./test/fixtures/config/basic/runtime.js

And if I run ./node_modules/.bin/ncc build test.js, this is what I get:

var fileWithExt = filename + '.' + ext;
console.log('- 1:', path.resolve(dir, fileWithExt));
console.log('- 2:', __webpack_require__.ab + "configly/" + dir + '/' + filename + '.' + ext);

Above are not full files, but lines of code in question.

Thank you.

@guybedford
Copy link
Contributor

This is by design - assets are emitted wherever referenced as file paths will not work out otherwise.

Can you perhaps share where dir and filename are being assigned here, as that will affect the emission analysis considerably and determine whether this is a bug or expected behaviour?

@alexindigo
Copy link
Author

it's the same reference both times, so the difference is in variables names? :)

And this is the code in question https://github.com/alexindigo/configly/blob/master/lib/load_files.js#L39-L44

Thank you.

@guybedford
Copy link
Contributor

I tried to replicate this with the following code:

git clone git@github.com:alexindigo/configly
cd configly
yarn install
sudo npm install -g @zeit/ncc
ncc build lib/load_files.js -o lf
cat lf/index.js

when observing the outputted source I don't see the rewriting you are referring to at all here.

Can you perhaps clarify how I could replicate your case.

@alexindigo
Copy link
Author

@guybedford Yes, because I added workaround in the latest version,
you can try to check out v5.0.1 tag, where it works with 0.11 version of ncc, but breaks in 0.20 version – https://github.com/alexindigo/configly/tree/v5.0.1
Thank you.

@guybedford
Copy link
Contributor

Ah perfect, yes I can confirm this is a bug thanks.

@guybedford guybedford added the bug Something isn't working label Jul 4, 2019
@alexindigo
Copy link
Author

alexindigo commented Jul 4, 2019

Thank you @guybedford

Probably don't need that "need more info" label :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants