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

Cannot resolve JSON file starting with a dot #7673

Open
mrtnzlml opened this issue Apr 26, 2019 · 12 comments
Open

Cannot resolve JSON file starting with a dot #7673

mrtnzlml opened this issue Apr 26, 2019 · 12 comments

Comments

@mrtnzlml
Copy link
Contributor

Flow version:

version 0.97.0

Flow cannot resolve require with JSON filename starting with a dot:

const meta = require('../.meta.json');

It results in this error:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/apps/graphql-skymock/datasets/__tests__/MetafileConsistency.test.js:7:22

Cannot resolve module ../.meta.json.

      4│ import path from 'path';
      5│ import Ajv from 'ajv';
      6│
      7│ const meta = require('../.meta.json');
      8│
      9│ test('every dataset defined in metafile should exist', () => {
     10│   expect.hasAssertions();

However, when I remove the dot (and rename the file) everything is fine:

const meta = require('../meta.json');
No errors!

Thank you very much for checking it! :)

@mrtnzlml
Copy link
Contributor Author

This is true even for JS files (.meta.js).

@goodmind
Copy link
Contributor

goodmind commented May 1, 2019

Yeah, Flow ignores all dotfiles, it probably should check if they have extension .meta vs .meta.js

@mrtnzlml
Copy link
Contributor Author

mrtnzlml commented May 1, 2019

Can I opt-out from this? I know it's unusual to start with a dot so it's not very common but it really makes sense in my case. Why does Flow ignore dot files by default?

@goodmind
Copy link
Contributor

goodmind commented May 1, 2019

No idea, it also wouldn't work with [include]

@goodmind
Copy link
Contributor

goodmind commented May 1, 2019

Maybe you can try symlinks

@gabrielrumiranda
Copy link
Contributor

Hi, can I work on this ?

@goodmind
Copy link
Contributor

@gabrielrumiranda Sure you can, what you want to know about codebase?

@gabrielrumiranda
Copy link
Contributor

@goodmind is my first contribution in project, i don't know much about codebase. The module who works with imports is flow/src/typing/import_export.ml ?

@goodmind
Copy link
Contributor

@gabrielrumiranda

flow/src/common/files.ml

Lines 97 to 102 in 95ef246

fun ~options ->
let file_exts = get_all_watched_extensions options in
fun path ->
let basename = Filename.basename path in
not (is_dot_file basename) && (check_ext file_exts basename || basename = "package.json")

This should be here I think

@gabrielrumiranda
Copy link
Contributor

@goodmind the tests of this part of code is in tests/declarations_files_node ?

@goodmind
Copy link
Contributor

Not sure where the tests should be, maybe new folder?

@gabrielrumiranda
Copy link
Contributor

I create a PR, #8045

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

No branches or pull requests

3 participants