-
Notifications
You must be signed in to change notification settings - Fork 11
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(cli): get latest dependencies versions from npm #77
Conversation
Couldn't find any way to get versions for multiple packages with one request to npm APIs, and I couldn't find any alternative that supports it as well... I followed the instructions here for the metadata request: |
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.
How fast is it?
@@ -9,7 +8,7 @@ const dirname = process | |||
.pop() as string; | |||
|
|||
export default () => | |||
execa('npm', ['run', 'plop', 'component', process.cwd(), uppercamelcase(dirname)], { | |||
execa('npm', ['run', 'plop', 'component', process.cwd(), dirname], { |
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.
Should we do lower tho?
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.
not sure... at this point it just shows the name of the folder... I'm running lower in the name property in package.json file... I'm considering whether or not we should auto kebab-case it...?
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.
Nah I think it's fine to leave it be
import fetch from 'node-fetch'; | ||
|
||
const getDependencyMetadata = async (name: string) => | ||
fetch(`https://registry.npmjs.org/${name}`, { |
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.
Remove async
client/cli/plop/utils.ts
Outdated
}).then(r => r.json()); | ||
|
||
export const getVersionsForDependencies = async (deps: string[]) => { | ||
return (await Promise.all(deps.map(d => getDependencyMetadata(d)))).reduce( |
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.
One line
client/cli/plop/utils.ts
Outdated
|
||
export const getVersionsForDependencies = async (deps: string[]) => { | ||
return (await Promise.all(deps.map(d => getDependencyMetadata(d)))).reduce( | ||
(soFar: Record<string, string>, current: any) => ({ |
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.
Why any?
matter of seconds on WiFi... |
f4d8e96
to
f3714df
Compare
client/cli/plop/component/index.ts
Outdated
const { dependencies, devDependencies, peerDependencies } = JSON.parse( | ||
plop.renderString(readFileSync(`./plop/component/${data.framework}/package.hbs`, 'utf-8'), data) | ||
); | ||
return await getVersionsForDependencies( |
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.
I don't think we need async await here
}).then(r => r.json()); | ||
|
||
export const getVersionsForDependencies = async (deps: string[]) => | ||
(await Promise.all(deps.map(d => getDependencyMetadata(d)))).reduce( |
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.
Also here do we have to use async await?
Returning promise is enough imo
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.
So I can ‘reduce’ on the promise.all result to a name:version object
* Read package file and get versions for required dependencies * Lowercase package name
f3714df
to
c1c4729
Compare
solves When initializing a new component dependencies versions should be up-to-date #71