Skip to content
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: load command's actions async to improve performance #6180

Merged
merged 70 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
95cc3cd
feat: convert addon-auth
sarahetter Nov 16, 2023
8602912
feat: convert addons:config
sarahetter Nov 16, 2023
0c7d81b
feat: convert addons:create
sarahetter Nov 16, 2023
9ecf1c3
feat: convert addons:delete
sarahetter Nov 16, 2023
4f6d088
feat: convert addons:list
sarahetter Nov 16, 2023
a5ff286
feat: convert api
sarahetter Nov 16, 2023
ac00447
feat: types
sarahetter Nov 16, 2023
b0eed4b
feat: convert build, and types
sarahetter Nov 16, 2023
86e8016
feat: convert blobs:delelte
sarahetter Nov 16, 2023
4dc736c
feat: convert blobs:get
sarahetter Nov 16, 2023
3aa9002
feat: convert blobs:list
sarahetter Nov 16, 2023
263d107
feat: convert blobs:set
sarahetter Nov 16, 2023
197f996
feat: remove import
sarahetter Nov 16, 2023
3819fe5
feat: convert completion
sarahetter Nov 16, 2023
0f83440
feat: convert deploy
sarahetter Nov 16, 2023
e56e4c0
feat: convert dev
sarahetter Nov 16, 2023
24b05e2
feat: convert env:get
sarahetter Nov 16, 2023
443e21f
feat: convert env:import
sarahetter Nov 16, 2023
d54ad4b
feat: convert env:list
sarahetter Nov 16, 2023
068f730
feat: convert env:set
sarahetter Nov 16, 2023
079e097
feat: convert env:unset
sarahetter Nov 16, 2023
81c0e28
feat: convert env:clone
sarahetter Nov 16, 2023
bd351d4
feat: convert functions:build
sarahetter Nov 16, 2023
c3c0140
feat: convert functions:create
sarahetter Nov 16, 2023
21db904
feat: convert functions:invoke
sarahetter Nov 16, 2023
8363827
feat: convert functions:list
sarahetter Nov 16, 2023
3896e25
feat: convert functions: serve
sarahetter Nov 16, 2023
bbad02c
feat: convert init
sarahetter Nov 16, 2023
36ca6a8
chore: format
sarahetter Nov 16, 2023
3519b19
feat: convert integration
sarahetter Nov 16, 2023
8b9c32f
feat: convert link
sarahetter Nov 16, 2023
fe01541
feat: convert lm:info
sarahetter Nov 16, 2023
7c4258a
feat: convert lm:install
sarahetter Nov 16, 2023
b1f8e34
feat: convert lm:setup
sarahetter Nov 16, 2023
03f6033
feat: convert lm:uninstall
sarahetter Nov 16, 2023
9730c7d
feat: convert login
sarahetter Nov 16, 2023
1786651
feat: convert logout
sarahetter Nov 16, 2023
7d02439
feat: convert logs:deploy
sarahetter Nov 16, 2023
29788c5
feat: convert logs:functions
sarahetter Nov 16, 2023
0d5d00e
feat: convert open
sarahetter Nov 16, 2023
33e0dfc
feat: convert recipes
sarahetter Nov 16, 2023
998df3d
feat: convert serve
sarahetter Nov 16, 2023
95ecbb7
feat: convert sites:create
sarahetter Nov 16, 2023
fee8cbb
feat: convert sites:create-template
sarahetter Nov 16, 2023
653de4b
feat: convert sites:list
sarahetter Nov 16, 2023
b47bf77
feat: convert sites:delete
sarahetter Nov 16, 2023
2934bca
feat: convert status
sarahetter Nov 16, 2023
1f17237
feat: convert switch
sarahetter Nov 16, 2023
5b09944
feat: convert unlink
sarahetter Nov 16, 2023
91b4cdb
feat: convert watch
sarahetter Nov 16, 2023
3062f12
test: fix test for sites:create-template
sarahetter Nov 16, 2023
b725a60
test: fix tests for logs:
sarahetter Nov 16, 2023
aef5612
test: sites:create
sarahetter Nov 16, 2023
be1b204
test: loogs
sarahetter Nov 16, 2023
8a50759
test: integration
sarahetter Nov 16, 2023
fac8ecc
Merge branch 'main' into sarahetter/ct-276-improve-performance
sarahetter Nov 17, 2023
ca739d5
chore: prettier
sarahetter Nov 17, 2023
a9dbed4
chore: up timeout for start dev server in test utils
sarahetter Nov 17, 2023
6fd7917
chore: return to original value
sarahetter Nov 17, 2023
d655ea1
chore: try await execa
sarahetter Nov 17, 2023
a4c7e2e
feat: nope, not that
sarahetter Nov 17, 2023
02285d2
Merge branch 'main' into sarahetter/ct-276-improve-performance
sarahetter Nov 20, 2023
bcca563
Merge branch 'main' into sarahetter/ct-276-improve-performance
sarahetter Nov 21, 2023
3f10923
chore: merge conflict stuff
sarahetter Nov 21, 2023
5669348
chore: package lock from main
sarahetter Nov 21, 2023
a712bf9
chore: merge conflict stuff
sarahetter Nov 21, 2023
4854f86
test: fix test import
sarahetter Nov 22, 2023
c811a49
test: fix wrong import
sarahetter Nov 22, 2023
33fe45c
chore: revert dev because dev server tests are timing out, moving to …
sarahetter Nov 22, 2023
8a11d17
chore: missing things
sarahetter Nov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions src/commands/addons/addons-auth.mts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@

import { OptionValues } from 'commander'

import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs'
import { exit, log } from '../../utils/command-helpers.mjs'
import openBrowser from '../../utils/open-browser.mjs'
import BaseCommand from '../base-command.mjs'


/**
* The addons:auth command
* @param {string} addonName
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
* @returns {Promise<boolean>}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
const addonsAuth = async (addonName, options, command) => {
export const addonsAuth = async (addonName: string, options: OptionValues, command: BaseCommand) => {
const { addon } = await prepareAddonCommand({
command,
addonName,
Expand All @@ -32,20 +27,3 @@ const addonsAuth = async (addonName, options, command) => {
await openBrowser({ url: addon.auth_url })
exit()
}

/**
* Creates the `netlify addons:auth` command
* @param {import('../base-command.mjs').default} program
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
export const createAddonsAuthCommand = (program) =>
program
.command('addons:auth', { hidden: true })
.alias('addon:auth')
.argument('<name>', 'Add-on slug')
.description('Login to add-on provider')
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
.action(async (addonName, options, command) => {
await addonsAuth(addonName, options, command)
})
33 changes: 4 additions & 29 deletions src/commands/addons/addons-config.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


import { OptionValues } from 'commander'
import inquirer from 'inquirer'
import isEmpty from 'lodash/isEmpty.js'

Expand All @@ -10,6 +11,7 @@ import { renderConfigValues } from '../../utils/addons/render.mjs'
import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.mjs'
import { chalk, error, log } from '../../utils/command-helpers.mjs'
import { parseRawFlags } from '../../utils/parse-raw-flags.mjs'
import BaseCommand from '../base-command.mjs'

// @ts-expect-error TS(7031) FIXME: Binding element 'addonName' implicitly has an 'any... Remove this comment to see the full error message
const update = async function ({ addonName, api, currentConfig, instanceId, newConfig, siteId }) {
Expand Down Expand Up @@ -39,15 +41,7 @@ const update = async function ({ addonName, api, currentConfig, instanceId, newC
}
}

/**
* The addons:config command
* @param {string} addonName
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
* @returns {Promise<boolean>}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
const addonsConfig = async (addonName, options, command) => {
export const addonsConfig = async (addonName: string, options: OptionValues, command: BaseCommand) => {
const { addon, manifest, siteData } = await prepareAddonCommand({
command,
addonName,
Expand Down Expand Up @@ -165,22 +159,3 @@ const addonsConfig = async (addonName, options, command) => {
})
}
}

/**
* Creates the `netlify addons:config` command
* @param {import('../base-command.mjs').default} program
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
export const createAddonsConfigCommand = (program) =>
program
.command('addons:config', { hidden: true })
.alias('addon:config')
.argument('<name>', 'Add-on namespace')
.description('Configure add-on settings')
// allow for any flags. Handy for variadic configuration options
.allowUnknownOption(true)
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
.action(async (addonName, options, command) => {
await addonsConfig(addonName, options, command)
})
36 changes: 4 additions & 32 deletions src/commands/addons/addons-create.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OptionValues } from 'commander'
import inquirer from 'inquirer'
import isEmpty from 'lodash/isEmpty.js'

Expand All @@ -8,6 +8,7 @@ import { renderConfigValues, renderMissingValues } from '../../utils/addons/rend
import { missingConfigValues, requiredConfigValues, updateConfigValues } from '../../utils/addons/validation.mjs'
import { chalk, error, log } from '../../utils/command-helpers.mjs'
import { parseRawFlags } from '../../utils/parse-raw-flags.mjs'
import BaseCommand from '../base-command.mjs'

// @ts-expect-error TS(7031) FIXME: Binding element 'addonName' implicitly has an 'any... Remove this comment to see the full error message
const createAddon = async ({ addonName, api, config, siteData, siteId }) => {
Expand All @@ -28,15 +29,8 @@ const createAddon = async ({ addonName, api, config, siteData, siteId }) => {
}
}

/**
* The addons:create command
* @param {string} addonName
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
* @returns {Promise<boolean>}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
const addonsCreate = async (addonName, options, command) => {

export const addonsCreate = async (addonName: string, options: OptionValues, command: BaseCommand) => {
const { manifest, siteData } = await prepareAddonCommand({
command,
addonName,
Expand Down Expand Up @@ -112,25 +106,3 @@ const addonsCreate = async (addonName, options, command) => {

await createAddon({ api, siteId, addonName, config: configValues, siteData })
}

/**
* Creates the `netlify addons:create` command
* @param {import('../base-command.mjs').default} program
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
export const createAddonsCreateCommand = (program) =>
program
.command('addons:create', { hidden: true })
.alias('addon:create')
.argument('<name>', 'Add-on namespace')
.description(
`Add an add-on extension to your site
Add-ons are a way to extend the functionality of your Netlify site`,
)
// allow for any flags. Handy for variadic configuration options
.allowUnknownOption(true)
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
.action(async (addonName, options, command) => {
await addonsCreate(addonName, options, command)
})
29 changes: 3 additions & 26 deletions src/commands/addons/addons-delete.mts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { OptionValues } from 'commander'
import inquirer from 'inquirer'

import { ADDON_VALIDATION, prepareAddonCommand } from '../../utils/addons/prepare.mjs'
import { error, exit, log } from '../../utils/command-helpers.mjs'
import BaseCommand from '../base-command.mjs'

/**
* The addons:delete command
* @param {string} addonName
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'addonName' implicitly has an 'any' type... Remove this comment to see the full error message
const addonsDelete = async (addonName, options, command) => {
export const addonsDelete = async (addonName: string, options: OptionValues, command: BaseCommand) => {
const { addon } = await prepareAddonCommand({
command,
addonName,
Expand Down Expand Up @@ -41,20 +35,3 @@ const addonsDelete = async (addonName, options, command) => {
error(error_.message)
}
}

/**
* Creates the `netlify addons:delete` command
* @param {import('../base-command.mjs').default} program
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
export const createAddonsDeleteCommand = (program) =>
program
.command('addons:delete', { hidden: true })
.alias('addon:delete')
.argument('<name>', 'Add-on namespace')
.description(
`Remove an add-on extension to your site\nAdd-ons are a way to extend the functionality of your Netlify site`,
)
.option('-f, --force', 'delete without prompting (useful for CI)')
.action(addonsDelete)
14 changes: 4 additions & 10 deletions src/commands/addons/addons-list.mts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@


import AsciiTable from 'ascii-table'
import { OptionValues } from 'commander'

import { prepareAddonCommand } from '../../utils/addons/prepare.mjs'
import { log, logJson } from '../../utils/command-helpers.mjs'
import BaseCommand from '../base-command.mjs'

/**
* The addons:list command
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
* @returns {Promise<boolean>}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
const addonsList = async (options, command) => {

export const addonsList = async (options: OptionValues, command: BaseCommand) => {
// @ts-expect-error TS(2345) FIXME: Argument of type '{ command: any; }' is not assign... Remove this comment to see the full error message
const { addons, siteData } = await prepareAddonCommand({ command })
// Return json response for piping commands
Expand Down
92 changes: 66 additions & 26 deletions src/commands/addons/addons.mts
Original file line number Diff line number Diff line change
@@ -1,32 +1,72 @@

import { createAddonsAuthCommand } from './addons-auth.mjs'
import { createAddonsConfigCommand } from './addons-config.mjs'
import { createAddonsCreateCommand } from './addons-create.mjs'
import { createAddonsDeleteCommand } from './addons-delete.mjs'
import { createAddonsListCommand } from './addons-list.mjs'

/**
* The addons command
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
const addons = (options, command) => {
import { OptionValues } from 'commander'

import BaseCommand from '../base-command.mjs'

const addons = (options: OptionValues, command: BaseCommand) => {
command.help()
}

/**
* Creates the `netlify addons` command
* @param {import('../base-command.mjs').default} program
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
export const createAddonsCommand = (program) => {
createAddonsAuthCommand(program)
createAddonsConfigCommand(program)
createAddonsCreateCommand(program)
createAddonsDeleteCommand(program)
createAddonsListCommand(program)
export const createAddonsCommand = (program: BaseCommand) => {
program
.command('addons:auth', { hidden: true })
.alias('addon:auth')
.argument('<name>', 'Add-on slug')
.description('Login to add-on provider')
.action(async (addonName: string, options: OptionValues, command: BaseCommand) => {
const { addonsAuth } = await import('./addons-auth.mjs')
await addonsAuth(addonName, options, command)
})

program
.command('addons:config', { hidden: true })
.alias('addon:config')
.argument('<name>', 'Add-on namespace')
.description('Configure add-on settings')
// allow for any flags. Handy for variadic configuration options
.allowUnknownOption(true)
.action(async (addonName: string, options: OptionValues, command: BaseCommand) => {
const { addonsConfig } = await import('./addons-config.mjs')
await addonsConfig(addonName, options, command)
})

program
.command('addons:create', { hidden: true })
.alias('addon:create')
.argument('<name>', 'Add-on namespace')
.description(
`Add an add-on extension to your site
Add-ons are a way to extend the functionality of your Netlify site`,
)
// allow for any flags. Handy for variadic configuration options
.allowUnknownOption(true)
.action(async (addonName: string, options: OptionValues, command: BaseCommand) => {
const { addonsCreate } = await import('./addons-create.mjs')
await addonsCreate(addonName, options, command)
})

program
.command('addons:delete', { hidden: true })
.alias('addon:delete')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation looks a bit off here. I don't think we've changed the Prettier settings to run on .mts files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah @ericapisani is this in the plans with what you're doing now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need to add the new extensions here:

"prettier": "--ignore-path .eslintignore --loglevel=warn \"{src,tools,scripts,tests,.github}/**/*.{mjs,cjs,js,md,yml,json,html}\" \"*.{mjs,cjs,js,yml,json,html}\" \".*.{mjs,cjs,js,yml,json,html}\" \"!CHANGELOG.md\" \"!**/*/package-lock.json\" \"!.github/**/*.md\""
.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added config in #6187, and ran format. Should be prettier now :D

.argument('<name>', 'Add-on namespace')
.description(
`Remove an add-on extension to your site\nAdd-ons are a way to extend the functionality of your Netlify site`,
)
.option('-f, --force', 'delete without prompting (useful for CI)')
.action(async (addonName: string, options: OptionValues, command: BaseCommand) => {
const { addonsDelete } = await import('./addons-delete.mjs')
await addonsDelete(addonName, options, command)
})


program
.command('addons:list', { hidden: true })
.alias('addon:list')
.description(`List currently installed add-ons for site`)
.option('--json', 'Output add-on data as JSON')
.action(async (options: OptionValues, command: BaseCommand) => {
const {addonsList} = await import('./addons-list.mjs')
await addonsList(options, command)
})

return program
.command('addons', { hidden: true })
Expand Down
34 changes: 4 additions & 30 deletions src/commands/api/api.mts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@


import AsciiTable from 'ascii-table'
import { OptionValues } from 'commander'
import { methods } from 'netlify'

import { chalk, error, exit, log, logJson } from '../../utils/command-helpers.mjs'
import BaseCommand from '../base-command.mjs'

/**
* The api command
* @param {string} apiMethod
* @param {import('commander').OptionValues} options
* @param {import('../base-command.mjs').default} command
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'apiMethod' implicitly has an 'any' type... Remove this comment to see the full error message
const apiCommand = async (apiMethod, options, command) => {

export const apiCommand = async (apiMethod: string, options: OptionValues, command: BaseCommand) => {
const { api } = command.netlify

if (options.list) {
Expand Down Expand Up @@ -52,23 +46,3 @@ const apiCommand = async (apiMethod, options, command) => {
}
}

/**
* Creates the `netlify api` command
* @param {import('../base-command.mjs').default} program
* @returns
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
export const createApiCommand = (program) =>
program
.command('api')
.argument('[apiMethod]', 'Open API method to run')
.description(
`Run any Netlify API method
For more information on available methods checkout https://open-api.netlify.com/ or run '${chalk.grey(
'netlify api --list',
)}'`,
)
.option('-d, --data <data>', 'Data to use')
.option('--list', 'List out available API methods', false)
.addExamples(['netlify api --list', `netlify api getSite --data '{ "site_id": "123456" }'`])
.action(apiCommand)
21 changes: 20 additions & 1 deletion src/commands/api/index.mts
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
export { createApiCommand } from './api.mjs'
import { chalk } from '../../utils/command-helpers.mjs'
import BaseCommand from "../base-command.mjs";

export const createApiCommand = (program: BaseCommand) =>
program
.command('api')
.argument('[apiMethod]', 'Open API method to run')
.description(
`Run any Netlify API method
For more information on available methods checkout https://open-api.netlify.com/ or run '${chalk.grey(
'netlify api --list',
)}'`,
)
.option('-d, --data <data>', 'Data to use')
.option('--list', 'List out available API methods', false)
.addExamples(['netlify api --list', `netlify api getSite --data '{ "site_id": "123456" }'`])
.action(async (apiMethod, options, command) => {
const { apiCommand } = await import('./api.mjs')
await apiCommand(apiMethod, options, command )
} )
Loading
Loading