|
1 |
| -import * as fs from 'node:fs'; |
2 |
| -import * as path from 'node:path'; |
3 | 1 | import * as log4js from 'log4js';
|
4 | 2 | import * as ts from 'typescript';
|
5 | 3 |
|
@@ -153,66 +151,6 @@ export function parseRepository(value: string): { url: string } {
|
153 | 151 | }
|
154 | 152 | }
|
155 | 153 |
|
156 |
| -/** |
157 |
| - * Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory |
158 |
| - * |
159 |
| - * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all |
160 |
| - * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236) |
161 |
| - */ |
162 |
| -export function findDependencyDirectory(dependencyName: string, searchStart: string) { |
163 |
| - // Explicitly do not use 'require("dep/package.json")' because that will fail if the |
164 |
| - // package does not export that particular file. |
165 |
| - const entryPoint = require.resolve(dependencyName, { |
166 |
| - paths: [searchStart], |
167 |
| - }); |
168 |
| - |
169 |
| - // Search up from the given directory, looking for a package.json that matches |
170 |
| - // the dependency name (so we don't accidentally find stray 'package.jsons'). |
171 |
| - const depPkgJsonPath = findPackageJsonUp(dependencyName, path.dirname(entryPoint)); |
172 |
| - |
173 |
| - if (!depPkgJsonPath) { |
174 |
| - throw new Error(`Could not find dependency '${dependencyName}' from '${searchStart}'`); |
175 |
| - } |
176 |
| - |
177 |
| - return depPkgJsonPath; |
178 |
| -} |
179 |
| - |
180 |
| -/** |
181 |
| - * Find the package.json for a given package upwards from the given directory |
182 |
| - * |
183 |
| - * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all |
184 |
| - * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236) |
185 |
| - */ |
186 |
| -export function findPackageJsonUp(packageName: string, directory: string) { |
187 |
| - return findUp(directory, (dir) => { |
188 |
| - const pjFile = path.join(dir, 'package.json'); |
189 |
| - return fs.existsSync(pjFile) && JSON.parse(fs.readFileSync(pjFile, 'utf-8')).name === packageName; |
190 |
| - }); |
191 |
| -} |
192 |
| - |
193 |
| -/** |
194 |
| - * Find a directory up the tree from a starting directory matching a condition |
195 |
| - * |
196 |
| - * Will return `undefined` if no directory matches |
197 |
| - * |
198 |
| - * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all |
199 |
| - * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236) |
200 |
| - */ |
201 |
| -export function findUp(directory: string, pred: (dir: string) => boolean): string | undefined { |
202 |
| - const result = pred(directory); |
203 |
| - |
204 |
| - if (result) { |
205 |
| - return directory; |
206 |
| - } |
207 |
| - |
208 |
| - const parent = path.dirname(directory); |
209 |
| - if (parent === directory) { |
210 |
| - return undefined; |
211 |
| - } |
212 |
| - |
213 |
| - return findUp(parent, pred); |
214 |
| -} |
215 |
| - |
216 | 154 | const ANSI_REGEX =
|
217 | 155 | // eslint-disable-next-line no-control-regex
|
218 | 156 | /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
|
|
0 commit comments