|
1 | 1 | let url = require('url'); |
2 | 2 | let compile = require('./compile'); |
3 | 3 | let path = require('path'); |
4 | | -let findNodeModules = require('findup-sync'); |
5 | 4 | let fs = require('fs'); |
6 | 5 | let util = require('util'); |
7 | 6 | let writeFile = util.promisify(fs.writeFile); |
@@ -30,7 +29,7 @@ async function runSingle(schemaTs) { |
30 | 29 | } |
31 | 30 | console.log(`Orange: found schema ${schemaTs}`); |
32 | 31 | if (!schemaJsPath) { |
33 | | - let nodeModules = findNodeModules('node_modules', { cwd: schemaTs }); |
| 32 | + let nodeModules = findClosestNodeModules(schemaTs); |
34 | 33 | outDir = path.join(nodeModules, '/.rdb', '/' + new Date().getUTCMilliseconds()); |
35 | 34 | schemaJsPath = compile(schemaTs, { outDir }); |
36 | 35 | } |
@@ -112,6 +111,21 @@ function findClosestPackageJson(startDir) { |
112 | 111 | return null; |
113 | 112 | } |
114 | 113 |
|
| 114 | +function findClosestNodeModules(startPath) { |
| 115 | + const startDir = fs.statSync(startPath).isDirectory() ? startPath : path.dirname(startPath); |
| 116 | + let currentDir = startDir; |
| 117 | + while (true) { |
| 118 | + const nodeModulesPath = path.join(currentDir, 'node_modules'); |
| 119 | + if (fs.existsSync(nodeModulesPath)) |
| 120 | + return nodeModulesPath; |
| 121 | + |
| 122 | + const parentDir = path.dirname(currentDir); |
| 123 | + if (parentDir === currentDir) |
| 124 | + return path.join(startDir, 'node_modules'); |
| 125 | + currentDir = parentDir; |
| 126 | + } |
| 127 | +} |
| 128 | + |
115 | 129 | async function findSchemaJs(cwd) { |
116 | 130 | let ignoredDirNames = { |
117 | 131 | node_modules: true, |
|
0 commit comments