New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rosetta): Rosetta manages dependencies automatically #3269
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ed33b57
feat(rosetta): Rosetta manages dependencies automatically
rix0rrr 98fe670
Merge remote-tracking branch 'origin/main' into huijbers/rosetta-own-…
rix0rrr 0d576e6
VEndor file
rix0rrr 360b752
Add tests
rix0rrr 49bf75b
Raise test timeouts
rix0rrr 710b259
Try again with more logging
rix0rrr e78c46e
Do symlink ourselves if we can
rix0rrr 684569a
symlink other way around
rix0rrr 5255b35
Nope this is the right way around
rix0rrr 541846d
Account for packages in scopes
rix0rrr 44ba25b
Merge branch 'main' into huijbers/rosetta-own-deps
rix0rrr 0bae475
Create dir
rix0rrr 7028fba
Skip if unnecessary
rix0rrr 0544bb4
Merge remote-tracking branch 'origin/main' into huijbers/rosetta-own-…
rix0rrr 65f396e
More logging
rix0rrr 4555716
Fix import order
rix0rrr 3faaa31
Thanks fastGlob
rix0rrr 2612b83
Review comments
rix0rrr 7058535
Merge remote-tracking branch 'origin/main' into huijbers/rosetta-own-…
rix0rrr 6c3d255
sync -> async
rix0rrr 5fe0205
Merge remote-tracking branch 'origin/main' into huijbers/rosetta-own-…
rix0rrr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
|
||
/** | ||
* Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory | ||
* | ||
* (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all | ||
* 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236) | ||
*/ | ||
export async function findDependencyDirectory(dependencyName: string, searchStart: string) { | ||
// Explicitly do not use 'require("dep/package.json")' because that will fail if the | ||
// package does not export that particular file. | ||
const entryPoint = require.resolve(dependencyName, { | ||
paths: [searchStart], | ||
}); | ||
|
||
// Search up from the given directory, looking for a package.json that matches | ||
// the dependency name (so we don't accidentally find stray 'package.jsons'). | ||
const depPkgJsonPath = await findPackageJsonUp(dependencyName, path.dirname(entryPoint)); | ||
|
||
if (!depPkgJsonPath) { | ||
throw new Error(`Could not find dependency '${dependencyName}' from '${searchStart}'`); | ||
} | ||
|
||
return depPkgJsonPath; | ||
} | ||
|
||
/** | ||
* Find the package.json for a given package upwards from the given directory | ||
* | ||
* (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all | ||
* 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236) | ||
*/ | ||
export async function findPackageJsonUp(packageName: string, directory: string) { | ||
return findUp(directory, async (dir) => { | ||
const pjFile = path.join(dir, 'package.json'); | ||
return (await fs.pathExists(pjFile)) && (await fs.readJson(pjFile)).name === packageName; | ||
}); | ||
} | ||
|
||
/** | ||
* Find a directory up the tree from a starting directory matching a condition | ||
* | ||
* Will return `undefined` if no directory matches | ||
* | ||
* (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all | ||
* 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236) | ||
*/ | ||
export function findUp(directory: string, pred: (dir: string) => Promise<boolean>): Promise<string | undefined>; | ||
export function findUp(directory: string, pred: (dir: string) => boolean): string | undefined; | ||
// eslint-disable-next-line @typescript-eslint/promise-function-async | ||
export function findUp( | ||
directory: string, | ||
pred: (dir: string) => boolean | Promise<boolean>, | ||
): Promise<string | undefined> | string | undefined { | ||
const result = pred(directory); | ||
if (result instanceof Promise) { | ||
return result.then((thisDirectory) => (thisDirectory ? directory : recurse())); | ||
} | ||
|
||
return result ? directory : recurse(); | ||
|
||
function recurse() { | ||
const parent = path.dirname(directory); | ||
if (parent === directory) { | ||
return undefined; | ||
} | ||
return findUp(parent, pred as any); | ||
RomainMuller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
/** | ||
* Whether the given dependency is a built-in | ||
* | ||
* Some dependencies that occur in `package.json` are also built-ins in modern Node | ||
* versions (most egregious example: 'punycode'). Detect those and filter them out. | ||
*/ | ||
export function isBuiltinModule(depName: string) { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires | ||
const { builtinModules } = require('module'); | ||
return (builtinModules ?? []).includes(depName); | ||
} | ||
RomainMuller marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allTypeScriptSnippets
returns a promise to an array already...