Skip to content

Commit 71d9471

Browse files
Moving requrieById into an isolated folder which will allow for string useage without importing anything else inside RUC, like flow types
1 parent 8250c35 commit 71d9471

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

__tests__/utils.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { createPath } from '../__test-helpers__'
22

3-
import {
4-
tryRequire,
5-
requireById,
6-
resolveExport,
7-
findExport
8-
} from '../src/utils'
3+
import { tryRequire, resolveExport, findExport } from '../src/utils'
4+
5+
import requireById from '../src/requireById'
96

107
test('tryRequire: requires module using key export finder + calls onLoad with module', () => {
118
const moduleEs6 = createPath('es6')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
],
3030
"scripts": {
3131
"build": "babel src -d dist",
32-
"flow-copy": "flow-copy-source src dist",
32+
"flow-copy": "flow-copy-source src dist -i 'requireById/index.js'",
3333
"flow-watch": "clear; printf \"\\033[3J\" & npm run flow & fswatch -o ./ | xargs -n1 -I{} sh -c 'clear; printf \"\\033[3J\" && npm run flow'",
3434
"flow": "flow; test $? -eq 0 -o $? -eq 2",
3535
"clean": "rimraf dist && mkdir dist",

src/requireById/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { isWebpack } from '../utils'
2+
3+
const requireById = id => {
4+
if (!isWebpack() && typeof id === 'string') {
5+
return module.require(`${id}`)
6+
}
7+
8+
return __webpack_require__(`${id}`)
9+
}
10+
11+
export default requireById

src/utils.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
22
import * as React from 'react'
3+
import requireById from './requireById'
34

45
import type {
56
Id,
@@ -48,14 +49,6 @@ export const tryRequire = (id: Id): ?any => {
4849
return null
4950
}
5051

51-
export const requireById = (id: Id): ?any => {
52-
if (!isWebpack() && typeof id === 'string') {
53-
return module.require(`${id}`)
54-
}
55-
56-
return __webpack_require__(`${id}`)
57-
}
58-
5952
export const resolveExport = (
6053
mod: ?Mod,
6154
key: ?Key,

0 commit comments

Comments
 (0)