@jcoreio/toolchain-flow 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ module.exports = {
2
+ plugins: ['eslint-plugin-flowtype'],
3
+ rules: {
4
+ 'flowtype/boolean-style': [2, 'boolean'],
5
+ 'flowtype/define-flow-type': 1,
6
+ 'flowtype/delimiter-dangle': [2, 'always-multiline'],
7
+ 'flowtype/no-dupe-keys': 2,
8
+ 'flowtype/no-primitive-constructor-types': 2,
9
+ 'flowtype/require-parameter-type': [
10
+ 2,
11
+ {
12
+ excludeArrowFunctions: 'expressionsOnly',
13
+ },
14
+ ],
15
+ 'flowtype/require-return-type': [
16
+ 2,
17
+ 'always',
18
+ {
19
+ annotateUndefined: 'ignore',
20
+ excludeArrowFunctions: 'expressionsOnly',
21
+ },
22
+ ],
23
+ 'flowtype/require-valid-file-annotation': 2,
24
+ 'flowtype/semi': [2, 'never'],
25
+ 'flowtype/space-after-type-colon': [
26
+ 2,
27
+ 'always',
28
+ {
29
+ allowLineBreak: true,
30
+ },
31
+ ],
32
+ 'flowtype/space-before-generic-bracket': [2, 'never'],
33
+ 'flowtype/space-before-type-colon': [2, 'never'],
34
+ 'flowtype/union-intersection-spacing': [2, 'always'],
35
+ 'flowtype/use-flow-type': 1,
36
+ },
37
+ settings: {
38
+ flowtype: {
39
+ onlyFilesWithFlowAnnotation: true,
40
+ },
41
+ },
42
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@jcoreio/toolchain-flow",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Flow JS build toolchain",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/jcoreio/toolchains.git",
8
+ "directory": "packages/flow"
9
+ },
10
+ "author": "Andy Edwards",
11
+ "license": "MIT",
12
+ "bugs": {
13
+ "url": "https://github.com/jcoreio/toolchains/issues"
14
+ },
15
+ "homepage": "https://github.com/jcoreio/toolchains/tree/beta/packages/flow",
16
+ "dependencies": {
17
+ "@babel/core": "^7.16.5",
18
+ "@babel/preset-flow": "^7.16.5",
19
+ "glob": "^7.2.0"
20
+ },
21
+ "peerDependencies": {
22
+ "@babel/core": "^7.0.0",
23
+ "eslint": "^8.0.0",
24
+ "eslint-plugin-flowtype": "^8.0.3",
25
+ "@jcoreio/toolchain": "1.0.0-beta.1",
26
+ "@jcoreio/toolchain-esnext": "1.0.0-beta.1"
27
+ }
28
+ }
@@ -0,0 +1,10 @@
1
+ const hasTSSourcesSync = require('@jcoreio/toolchain/util/hasTSSourcesSync.cjs')
2
+
3
+ module.exports = hasTSSourcesSync()
4
+ ? []
5
+ : [
6
+ [
7
+ () => [require.resolve('@babel/preset-flow')],
8
+ { after: '@jcoreio/toolchain-esnext' },
9
+ ],
10
+ ]
@@ -0,0 +1,33 @@
1
+ const Path = require('path')
2
+ const glob = require('@jcoreio/toolchain/util/glob.cjs')
3
+ const fs = require('@jcoreio/toolchain/util/projectFs.cjs')
4
+ const hasTSSourcesSync = require('@jcoreio/toolchain/util/hasTSSourcesSync.cjs')
5
+ const resolveImportsCodemod = require('@jcoreio/toolchain-esnext/util/resolveImportsCodemod.cjs')
6
+
7
+ module.exports = [
8
+ [
9
+ async function build(args = []) {
10
+ if (!hasTSSourcesSync()) {
11
+ const jsFiles = await glob(Path.join('src', '**', '*.{js,cjs,mjs}'))
12
+ for (const ext of ['.js.flow', '.mjs.flow']) {
13
+ await Promise.all(
14
+ jsFiles.map(async (src) => {
15
+ const dest = Path.join('dist', Path.relative('src', src)).replace(
16
+ /\.[cm]?js$/,
17
+ ext
18
+ )
19
+ // eslint-disable-next-line no-console
20
+ console.error(src, '->', dest)
21
+ await fs.copy(src, dest)
22
+ })
23
+ )
24
+ }
25
+ const flowFiles = await glob(
26
+ Path.join('dist', '**', '*.{js,cjs,mjs}.flow')
27
+ )
28
+ await resolveImportsCodemod(flowFiles)
29
+ }
30
+ },
31
+ { after: ['@jcoreio/toolchain', '@jcoreio/toolchain-esnext'] },
32
+ ],
33
+ ]
@@ -0,0 +1 @@
1
+ module.exports = [() => ['flow']]
@@ -0,0 +1,53 @@
1
+ const dedent = require('dedent-js')
2
+ const fs = require('@jcoreio/toolchain/util/projectFs.cjs')
3
+ const INI = require('@jcoreio/toolchain/util/ini.cjs')
4
+
5
+ const defaultFlowConfig = dedent`
6
+ [ignore]
7
+ <PROJECT_ROOT>/dist/.*
8
+ .*/malformed_package_json/.*
9
+
10
+ [include]
11
+ ./src
12
+ ./test
13
+
14
+ [libs]
15
+
16
+ [options]
17
+ `
18
+
19
+ module.exports = [
20
+ async function getConfigFiles() {
21
+ let flowconfig
22
+ if (await fs.pathExists('.flowconfig')) {
23
+ flowconfig = await fs.readFile('.flowconfig', 'utf8')
24
+ const parsed = INI.parse(flowconfig)
25
+ const parsedDefault = INI.parse(defaultFlowConfig)
26
+
27
+ let changed = false
28
+ for (const key in parsedDefault) {
29
+ if (parsed[key]) {
30
+ for (const item of parsedDefault[key]) {
31
+ if (!parsed[key].includes(item)) {
32
+ parsed[key].push(item)
33
+ changed = true
34
+ }
35
+ }
36
+ } else {
37
+ parsed[key] = parsedDefault[key]
38
+ changed = true
39
+ }
40
+ }
41
+ if (changed) flowconfig = INI.stringify(parsed)
42
+ } else {
43
+ flowconfig = defaultFlowConfig
44
+ }
45
+ const files = {
46
+ '.flowconfig': {
47
+ content: flowconfig,
48
+ overwrite: true,
49
+ },
50
+ }
51
+ return files
52
+ },
53
+ ]
@@ -0,0 +1 @@
1
+ module.exports = [() => [require.resolve('../eslint.extends.cjs')]]