gcanti / flow-static-land

[DEPRECATED, please check out fp-ts] Implementation of common algebraic types in JavaScript + Flow
MIT License
408 stars 22 forks source link

Presence of .flowconfig causing module resolve issues #21

Closed mwalkerwells closed 7 years ago

mwalkerwells commented 7 years ago

Not sure what the fix is (other than removing the .flowconfig file on a build step), but wanted to bring this to your attention.

Flow 0.32.0

Error:

This modules resolves to "<>/../assert/package.json", which is outside both your root directory and all of the entries in the [include] section of your .flowconfig. You should either add this directory to the [include] section of your .flowconfig, move your .flowconfig file higher in the project directory tree, or move this package under your Flow root directory.

Files: test.zip

Read up on something similar here: https://github.com/facebook/flow/issues/1891

Before removing .flowconfig in /node_modules/flow-static-land/ screen shot 2016-09-09 at 7 38 46 pm

After removing .flowconfig in /node_modules/flow-static-land/ screen shot 2016-09-09 at 7 39 35 pm

mwalkerwells commented 7 years ago

I couldn't figure out a way to tell Flow not to actually type check the library, yet still get the type definitions on module import. Removing the .flowconfig file was the way I accomplished this.

There is the new "flow gen-flow-files": https://github.com/facebook/flow/releases/tag/v0.32.0

gcanti commented 7 years ago

Being this repo experimental I didn't put much love in the distribution problem so far. I guess it's time to publish a first release.

Here's my plan:

Then, as usual, one can install flow-static-land with npm install flow-static-land --save and use it like this

// @flow
import * as arr from 'flow-static-land/lib/Arr' // <= note the /lib here

arr.map(n => n * 2, arr.inj(['a'])) // <= error
mwalkerwells commented 7 years ago

My 2 cents re: module imports:

import { Monad, Monoid, Functor } from './flow-static-land';
gcanti commented 7 years ago

That would be handy but it means you end up importing all the modules, even those which you don't actually use in your app.

Another option, which seems more flexible, is to define your own prelude. So instead of:

// app.js
import * as arr from 'flow-static-land/lib/Arr'
import * as maybe from 'flow-static-land/lib/Maybe'
import * as tuple from 'flow-static-land/lib/Tuple'

// your code here

you first define a prelude.js containing only the relevant modules for your app and then you just import the prelude

// prelude.js
import type { Arr } from 'flow-static-land/lib/Arr'
import type { Maybe } from 'flow-static-land/lib/Maybe'
import type { Tuple } from 'flow-static-land/lib/Tuple'

import * as arr from 'flow-static-land/lib/Arr'
import * as maybe from 'flow-static-land/lib/Maybe'
import * as tuple from 'flow-static-land/lib/Tuple'

export type {
  Arr,
  Maybe,
  Tuple
}

export {
  arr,
  maybe,
  tuple
}
// app.js
import { arr, maybe, tuple } from './prelude'

// your code here
gcanti commented 7 years ago

Published a first version on npm (https://github.com/gcanti/flow-static-land/releases/tag/0.1.0)