Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate BaseCommand and postinstall to esm (#5167)
* chore: rename files * chore: migrate BaseCommand and postinstall to esm
- Loading branch information
Showing
14 changed files
with
137 additions
and
140 deletions.
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 was deleted.
Oops, something went wrong.
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,60 @@ | ||
import process from 'process' | ||
|
||
const id = (message) => message | ||
|
||
/** | ||
* | ||
* @param {string} message | ||
* @param {Array<chalk['Color'] | chalk['Modifiers']>} styles | ||
* @returns | ||
*/ | ||
const format = async (message, styles) => { | ||
let func = id | ||
try { | ||
// this fails sometimes on outdated npm versions | ||
const chalk = await import('chalk') | ||
func = chalk.default | ||
styles.forEach((style) => { | ||
func = func[style] | ||
}) | ||
} catch {} | ||
return func(message) | ||
} | ||
|
||
const postInstall = async () => { | ||
// yarn plug and play seems to have an issue with reading an esm file by building up the cache. | ||
// as yarn pnp analyzes everything inside the postinstall | ||
// yarn pnp executes it out of a .yarn folder .yarn/unplugged/netlify-cli-file-fb026a3a6d/node_modules/netlify-cli/scripts/postinstall.mjs | ||
if (!process.argv[1].includes('.yarn')) { | ||
const { createMainCommand } = await import('../src/commands/index.mjs') | ||
// TODO: use destructuring again once the imported file is esm | ||
const completion = await import('../src/lib/completion/index.cjs') | ||
|
||
// create or update the autocompletion definition | ||
const program = createMainCommand() | ||
completion.createAutocompletion(program) | ||
} | ||
|
||
console.log('') | ||
console.log(await format('Success! Netlify CLI has been installed!', ['greenBright', 'bold', 'underline'])) | ||
console.log('') | ||
console.log('Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.') | ||
console.log('') | ||
console.log('Next steps:') | ||
console.log('') | ||
console.log( | ||
` ${await format('netlify init', [ | ||
'cyanBright', | ||
'bold', | ||
])} Connect or create a Netlify site from current directory`, | ||
) | ||
console.log( | ||
` ${await format('netlify deploy', ['cyanBright', 'bold'])} Deploy the latest changes to your Netlify site`, | ||
) | ||
console.log('') | ||
console.log(`For more information on the CLI run ${await format('netlify help', ['cyanBright', 'bold'])}`) | ||
console.log(`Or visit the docs at ${await format('https://cli.netlify.com', ['cyanBright', 'bold'])}`) | ||
console.log('') | ||
} | ||
|
||
await postInstall() |
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 was deleted.
Oops, something went wrong.
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,2 @@ | ||
export { default as BaseCommand } from './base-command.mjs' | ||
export { createMainCommand } from './main.mjs' |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const generateAutocompletion = require('./generate-autocompletion.cjs') | ||
const { createAutocompletion } = require('./generate-autocompletion.cjs') | ||
|
||
module.exports = { | ||
...generateAutocompletion, | ||
createAutocompletion, | ||
} |
Oops, something went wrong.
9261bc3
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.
📊 Benchmark results
Package size: 233 MB