netlify-cli 12.2.9 → 12.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/npm-shrinkwrap.json +255 -1458
  2. package/package.json +3 -7
  3. package/src/commands/addons/addons-auth.mjs +2 -3
  4. package/src/commands/addons/addons-config.mjs +2 -3
  5. package/src/commands/addons/addons-create.mjs +2 -3
  6. package/src/commands/addons/addons-delete.mjs +1 -3
  7. package/src/commands/addons/addons-list.mjs +1 -3
  8. package/src/commands/api/api.mjs +1 -3
  9. package/src/commands/base-command.mjs +3 -3
  10. package/src/commands/build/build.mjs +3 -3
  11. package/src/commands/deploy/deploy.mjs +13 -16
  12. package/src/commands/dev/dev-exec.mjs +2 -3
  13. package/src/commands/dev/dev.mjs +15 -21
  14. package/src/commands/env/env-clone.mjs +2 -3
  15. package/src/commands/env/env-get.mjs +2 -3
  16. package/src/commands/env/env-import.mjs +2 -3
  17. package/src/commands/env/env-list.mjs +2 -4
  18. package/src/commands/env/env-set.mjs +3 -8
  19. package/src/commands/env/env-unset.mjs +2 -3
  20. package/src/commands/functions/functions-build.mjs +1 -3
  21. package/src/commands/functions/functions-create.mjs +3 -3
  22. package/src/commands/functions/functions-invoke.mjs +1 -3
  23. package/src/commands/functions/functions-list.mjs +1 -3
  24. package/src/commands/functions/functions-serve.mjs +1 -2
  25. package/src/commands/functions/functions.mjs +1 -1
  26. package/src/commands/graph/graph-config-write.mjs +1 -3
  27. package/src/commands/graph/graph-edit.mjs +2 -3
  28. package/src/commands/graph/graph-handler.mjs +1 -3
  29. package/src/commands/graph/graph-init.mjs +2 -3
  30. package/src/commands/graph/graph-library.mjs +1 -3
  31. package/src/commands/graph/graph-operations.mjs +1 -3
  32. package/src/commands/graph/graph-pull.mjs +1 -3
  33. package/src/commands/init/init.mjs +2 -4
  34. package/src/commands/link/link.mjs +1 -3
  35. package/src/commands/lm/lm-setup.mjs +2 -3
  36. package/src/commands/login/login.mjs +1 -3
  37. package/src/commands/logout/logout.mjs +1 -3
  38. package/src/commands/main.mjs +3 -3
  39. package/src/commands/open/open-admin.mjs +2 -3
  40. package/src/commands/open/open-site.mjs +2 -3
  41. package/src/commands/open/open.mjs +1 -3
  42. package/src/commands/recipes/recipes.mjs +3 -3
  43. package/src/commands/sites/sites-create-template.mjs +7 -8
  44. package/src/commands/sites/sites-create.mjs +2 -4
  45. package/src/commands/sites/sites-delete.mjs +1 -3
  46. package/src/commands/sites/sites-list.mjs +1 -3
  47. package/src/commands/status/status-hooks.mjs +1 -3
  48. package/src/commands/status/status.mjs +1 -3
  49. package/src/commands/switch/switch.mjs +1 -3
  50. package/src/commands/unlink/unlink.mjs +1 -3
  51. package/src/commands/watch/watch.mjs +1 -3
  52. package/src/lib/account.mjs +14 -0
  53. package/src/lib/api.mjs +1 -1
  54. package/src/lib/completion/generate-autocompletion.mjs +1 -1
  55. package/src/lib/edge-functions/consts.mjs +4 -0
  56. package/src/lib/edge-functions/{deploy.cjs → deploy.mjs} +7 -13
  57. package/src/lib/edge-functions/{headers.cjs → headers.mjs} +3 -1
  58. package/src/lib/edge-functions/{internal.cjs → internal.mjs} +24 -20
  59. package/src/lib/edge-functions/{proxy.cjs → proxy.mjs} +18 -20
  60. package/src/lib/edge-functions/{registry.cjs → registry.mjs} +16 -7
  61. package/src/lib/{exec-fetcher.cjs → exec-fetcher.mjs} +17 -12
  62. package/src/lib/functions/{background.cjs → background.mjs} +4 -6
  63. package/src/lib/functions/{config.cjs → config.mjs} +1 -3
  64. package/src/lib/functions/form-submissions-handler.mjs +2 -2
  65. package/src/lib/functions/{local-proxy.cjs → local-proxy.mjs} +4 -6
  66. package/src/lib/functions/{memoized-build.cjs → memoized-build.mjs} +1 -3
  67. package/src/lib/functions/{netlify-function.cjs → netlify-function.mjs} +5 -8
  68. package/src/lib/functions/{registry.cjs → registry.mjs} +12 -14
  69. package/src/lib/functions/runtimes/go/{index.cjs → index.mjs} +10 -10
  70. package/src/lib/functions/runtimes/{index.cjs → index.mjs} +12 -7
  71. package/src/lib/functions/runtimes/js/builders/{netlify-lambda.cjs → netlify-lambda.mjs} +13 -10
  72. package/src/lib/functions/runtimes/js/builders/{zisi.cjs → zisi.mjs} +15 -13
  73. package/src/lib/functions/runtimes/js/{index.cjs → index.mjs} +12 -12
  74. package/src/lib/functions/runtimes/rust/{index.cjs → index.mjs} +15 -15
  75. package/src/lib/functions/scheduled.mjs +1 -1
  76. package/src/lib/functions/server.mjs +6 -7
  77. package/src/lib/functions/{synchronous.cjs → synchronous.mjs} +5 -7
  78. package/src/lib/functions/{utils.cjs → utils.mjs} +6 -21
  79. package/src/lib/{geo-location.cjs → geo-location.mjs} +3 -5
  80. package/src/lib/http-agent.mjs +1 -1
  81. package/src/lib/{log.cjs → log.mjs} +3 -7
  82. package/src/lib/one-graph/cli-client.mjs +2 -2
  83. package/src/lib/one-graph/cli-netlify-graph.mjs +2 -3
  84. package/src/lib/path.mjs +1 -0
  85. package/src/lib/{render-error-remplate.cjs → render-error-template.mjs} +8 -4
  86. package/src/lib/{string.cjs → string.mjs} +1 -3
  87. package/src/recipes/vscode/index.mjs +1 -1
  88. package/src/utils/addons/diffs/options.mjs +1 -1
  89. package/src/utils/addons/prepare.mjs +1 -1
  90. package/src/utils/addons/prompts.mjs +1 -1
  91. package/src/utils/addons/render.mjs +1 -1
  92. package/src/utils/{command-helpers.cjs → command-helpers.mjs} +45 -64
  93. package/src/utils/{deferred.cjs → create-deferred.mjs} +1 -1
  94. package/src/utils/deploy/constants.mjs +19 -0
  95. package/src/utils/deploy/{deploy-site.cjs → deploy-site.mjs} +15 -17
  96. package/src/utils/deploy/{hash-files.cjs → hash-files.mjs} +7 -5
  97. package/src/utils/deploy/{hash-fns.cjs → hash-fns.mjs} +11 -8
  98. package/src/utils/deploy/{hasher-segments.cjs → hasher-segments.mjs} +10 -17
  99. package/src/utils/deploy/{upload-files.cjs → upload-files.mjs} +5 -5
  100. package/src/utils/deploy/{util.cjs → util.mjs} +8 -20
  101. package/src/utils/detect-server-settings.mjs +2 -2
  102. package/src/utils/{dev.cjs → dev.mjs} +13 -21
  103. package/src/utils/{dot-env.cjs → dot-env.mjs} +7 -9
  104. package/src/utils/env/{index.cjs → index.mjs} +11 -24
  105. package/src/utils/execa.mjs +17 -0
  106. package/src/utils/get-global-config.mjs +40 -0
  107. package/src/utils/get-repo-data.mjs +1 -1
  108. package/src/utils/{gh-auth.cjs → gh-auth.mjs} +10 -12
  109. package/src/utils/gitignore.mjs +1 -1
  110. package/src/utils/{headers.cjs → headers.mjs} +4 -11
  111. package/src/utils/init/{config-github.cjs → config-github.mjs} +6 -8
  112. package/src/utils/init/{config-manual.cjs → config-manual.mjs} +4 -4
  113. package/src/utils/init/{config.cjs → config.mjs} +4 -5
  114. package/src/utils/init/{frameworks.cjs → frameworks.mjs} +2 -5
  115. package/src/utils/init/{node-version.cjs → node-version.mjs} +6 -8
  116. package/src/utils/init/{plugins.cjs → plugins.mjs} +3 -5
  117. package/src/utils/init/{utils.cjs → utils.mjs} +27 -23
  118. package/src/utils/live-tunnel.mjs +3 -3
  119. package/src/utils/lm/install.mjs +3 -3
  120. package/src/utils/lm/requirements.mjs +1 -1
  121. package/src/utils/lm/steps.mjs +1 -1
  122. package/src/utils/lm/ui.mjs +1 -1
  123. package/src/utils/{open-browser.cjs → open-browser.mjs} +5 -5
  124. package/src/utils/{parse-raw-flags.cjs → parse-raw-flags.mjs} +2 -7
  125. package/src/utils/proxy.mjs +14 -10
  126. package/src/utils/{redirects.cjs → redirects.mjs} +3 -7
  127. package/src/utils/{rules-proxy.cjs → rules-proxy.mjs} +19 -19
  128. package/src/utils/sites/{utils.cjs → utils.mjs} +6 -6
  129. package/src/utils/telemetry/telemetry.mjs +2 -2
  130. package/src/utils/telemetry/validation.mjs +1 -1
  131. package/src/lib/account.cjs +0 -9
  132. package/src/lib/edge-functions/consts.cjs +0 -11
  133. package/src/lib/edge-functions/index.cjs +0 -6
  134. package/src/lib/path.cjs +0 -3
  135. package/src/utils/deploy/constants.cjs +0 -31
  136. package/src/utils/deploy/index.cjs +0 -4
  137. package/src/utils/execa.cjs +0 -12
  138. package/src/utils/get-global-config.cjs +0 -47
  139. package/src/utils/index.cjs +0 -22
@@ -1,14 +1,14 @@
1
1
  // @ts-check
2
- const { readFile } = require('fs').promises
3
- const path = require('path')
2
+ import { readFile } from 'fs/promises'
3
+ import path from 'path'
4
4
 
5
- const dotenv = require('dotenv')
5
+ import dotenv from 'dotenv'
6
6
 
7
- const { isFileAsync } = require('../lib/fs.cjs')
7
+ import { isFileAsync } from '../lib/fs.cjs'
8
8
 
9
- const { warn } = require('./command-helpers.cjs')
9
+ import { warn } from './command-helpers.mjs'
10
10
 
11
- const loadDotEnvFiles = async function ({ envFiles, projectDir }) {
11
+ export const loadDotEnvFiles = async function ({ envFiles, projectDir }) {
12
12
  const response = await tryLoadDotEnvFiles({ projectDir, dotenvFiles: envFiles })
13
13
 
14
14
  const filesWithWarning = response.filter((el) => el.warning)
@@ -22,7 +22,7 @@ const loadDotEnvFiles = async function ({ envFiles, projectDir }) {
22
22
  // in the user configuration, the order is highest to lowest
23
23
  const defaultEnvFiles = ['.env.development.local', '.env.local', '.env.development', '.env']
24
24
 
25
- const tryLoadDotEnvFiles = async ({ projectDir, dotenvFiles = defaultEnvFiles }) => {
25
+ export const tryLoadDotEnvFiles = async ({ projectDir, dotenvFiles = defaultEnvFiles }) => {
26
26
  const results = await Promise.all(
27
27
  dotenvFiles.map(async (file) => {
28
28
  const filepath = path.resolve(projectDir, file)
@@ -45,5 +45,3 @@ const tryLoadDotEnvFiles = async ({ projectDir, dotenvFiles = defaultEnvFiles })
45
45
  // we return in order of lowest to highest priority
46
46
  return results.filter(Boolean).reverse()
47
47
  }
48
-
49
- module.exports = { loadDotEnvFiles, tryLoadDotEnvFiles }
@@ -1,13 +1,13 @@
1
- const { error } = require('../command-helpers.cjs')
1
+ import { error } from '../command-helpers.mjs'
2
2
 
3
- const AVAILABLE_CONTEXTS = ['all', 'production', 'deploy-preview', 'branch-deploy', 'dev']
4
- const AVAILABLE_SCOPES = ['builds', 'functions', 'runtime', 'post_processing']
3
+ export const AVAILABLE_CONTEXTS = ['all', 'production', 'deploy-preview', 'branch-deploy', 'dev']
4
+ export const AVAILABLE_SCOPES = ['builds', 'functions', 'runtime', 'post_processing']
5
5
 
6
6
  /**
7
7
  * @param {string|undefined} context - The deploy context or branch of the environment variable value
8
8
  * @returns {Array<string|undefined>} The normalized context or branch name
9
9
  */
10
- const normalizeContext = (context) => {
10
+ export const normalizeContext = (context) => {
11
11
  if (!context) {
12
12
  return context
13
13
  }
@@ -33,7 +33,7 @@ const normalizeContext = (context) => {
33
33
  * @param {string} context - The deploy context or branch of the environment variable value
34
34
  * @returns {object<context: enum<dev,branch-deploy,deploy-preview,production,branch>, context_parameter: <string>, value: string>} The matching environment variable value object
35
35
  */
36
- const findValueInValues = (values, context) =>
36
+ export const findValueInValues = (values, context) =>
37
37
  values.find((val) => {
38
38
  if (!AVAILABLE_CONTEXTS.includes(context)) {
39
39
  // the "context" option passed in is actually the name of a branch
@@ -48,7 +48,7 @@ const findValueInValues = (values, context) =>
48
48
  * @param {enum<general,account,addons,ui,configFile>} source - The source of the environment variable
49
49
  * @returns {object} The dictionary of env vars that match the given source
50
50
  */
51
- const filterEnvBySource = (env, source) =>
51
+ export const filterEnvBySource = (env, source) =>
52
52
  Object.fromEntries(Object.entries(env).filter(([, variable]) => variable.sources[0] === source))
53
53
 
54
54
  /**
@@ -102,7 +102,7 @@ const fetchEnvelopeItems = async function ({ accountId, api, key, siteId }) {
102
102
  * },
103
103
  * }
104
104
  */
105
- const formatEnvelopeData = ({ context = 'dev', envelopeItems = [], scope = 'any', source }) =>
105
+ export const formatEnvelopeData = ({ context = 'dev', envelopeItems = [], scope = 'any', source }) =>
106
106
  envelopeItems
107
107
  // filter by context
108
108
  .filter(({ values }) => Boolean(findValueInValues(values, context)))
@@ -135,7 +135,7 @@ const formatEnvelopeData = ({ context = 'dev', envelopeItems = [], scope = 'any'
135
135
  * @param {object} siteInfo - The site object
136
136
  * @returns {object} An object of environment variables keys and their metadata
137
137
  */
138
- const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', scope = 'any', siteInfo }) => {
138
+ export const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', scope = 'any', siteInfo }) => {
139
139
  const { account_slug: accountId, id: siteId } = siteInfo
140
140
 
141
141
  const [accountEnvelopeItems, siteEnvelopeItems] = await Promise.all([
@@ -167,7 +167,7 @@ const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', scope = 'an
167
167
  * @param {Array<enum<builds,functions,runtime,post_processing>>} scopes - An array of scopes
168
168
  * @returns {string} A human-readable, comma-separated list of scopes
169
169
  */
170
- const getHumanReadableScopes = (scopes) => {
170
+ export const getHumanReadableScopes = (scopes) => {
171
171
  const HUMAN_SCOPES = ['Builds', 'Functions', 'Runtime', 'Post processing']
172
172
  const SCOPES_MAP = {
173
173
  builds: HUMAN_SCOPES[0],
@@ -193,7 +193,7 @@ const getHumanReadableScopes = (scopes) => {
193
193
  * @param {object} env - The site's env as it exists in Mongo
194
194
  * @returns {Array<object>} The array of Envelope env vars
195
195
  */
196
- const translateFromMongoToEnvelope = (env = {}) => {
196
+ export const translateFromMongoToEnvelope = (env = {}) => {
197
197
  const envVars = Object.entries(env).map(([key, value]) => ({
198
198
  key,
199
199
  scopes: AVAILABLE_SCOPES,
@@ -214,7 +214,7 @@ const translateFromMongoToEnvelope = (env = {}) => {
214
214
  * @param {string} context - The deploy context or branch of the environment variable
215
215
  * @returns {object} The env object as compatible with Mongo
216
216
  */
217
- const translateFromEnvelopeToMongo = (envVars = [], context = 'dev') =>
217
+ export const translateFromEnvelopeToMongo = (envVars = [], context = 'dev') =>
218
218
  envVars
219
219
  .sort((left, right) => (left.key.toLowerCase() < right.key.toLowerCase() ? -1 : 1))
220
220
  .reduce((acc, cur) => {
@@ -227,16 +227,3 @@ const translateFromEnvelopeToMongo = (envVars = [], context = 'dev') =>
227
227
  }
228
228
  return acc
229
229
  }, {})
230
-
231
- module.exports = {
232
- AVAILABLE_CONTEXTS,
233
- AVAILABLE_SCOPES,
234
- findValueInValues,
235
- filterEnvBySource,
236
- formatEnvelopeData,
237
- getEnvelopeEnv,
238
- getHumanReadableScopes,
239
- normalizeContext,
240
- translateFromEnvelopeToMongo,
241
- translateFromMongoToEnvelope,
242
- }
@@ -0,0 +1,17 @@
1
+ import { env } from 'process'
2
+ // This is a thin layer on top of `execa` that allows consumers to provide an
3
+ // alternative path to the module location, making it easier to mock its logic
4
+ // in tests (see `tests/utils/mock-execa.js`).
5
+ // eslint-disable-next-line import/no-mutable-exports
6
+ let execa
7
+
8
+ if (env.NETLIFY_CLI_EXECA_PATH) {
9
+ // eslint-disable-next-line import/no-dynamic-require
10
+ const execaMock = await import(env.NETLIFY_CLI_EXECA_PATH)
11
+ execa = execaMock.default
12
+ } else {
13
+ const execaLib = await import('execa')
14
+ execa = execaLib.default
15
+ }
16
+
17
+ export default execa
@@ -0,0 +1,40 @@
1
+ import { readFile } from 'fs/promises'
2
+
3
+ import Configstore from 'configstore'
4
+ import { v4 as uuidv4 } from 'uuid'
5
+
6
+ import { getLegacyPathInHome, getPathInHome } from '../lib/settings.cjs'
7
+
8
+ const globalConfigDefaults = {
9
+ /* disable stats from being sent to Netlify */
10
+ telemetryDisabled: false,
11
+ /* cliId */
12
+ cliId: uuidv4(),
13
+ }
14
+
15
+ // Memoise config result so that we only load it once
16
+ let configStore
17
+
18
+ const getGlobalConfig = async function () {
19
+ if (!configStore) {
20
+ const configPath = getPathInHome(['config.json'])
21
+ // Legacy config file in home ~/.netlify/config.json
22
+ const legacyPath = getLegacyPathInHome(['config.json'])
23
+ let legacyConfig
24
+ // Read legacy config if exists
25
+ try {
26
+ legacyConfig = JSON.parse(await readFile(legacyPath))
27
+ } catch {}
28
+ // Use legacy config as default values
29
+ const defaults = { ...globalConfigDefaults, ...legacyConfig }
30
+ configStore = new Configstore(null, defaults, { configPath })
31
+ }
32
+
33
+ return configStore
34
+ }
35
+
36
+ export const resetConfigCache = () => {
37
+ configStore = undefined
38
+ }
39
+
40
+ export default getGlobalConfig
@@ -8,7 +8,7 @@ import gitRepoInfo from 'git-repo-info'
8
8
  import gitconfiglocal from 'gitconfiglocal'
9
9
  import parseGitRemote from 'parse-github-url'
10
10
 
11
- import { log } from './command-helpers.cjs'
11
+ import { log } from './command-helpers.mjs'
12
12
 
13
13
  /**
14
14
  *
@@ -1,15 +1,15 @@
1
1
  // @ts-check
2
2
  // A simple ghauth inspired library for getting a personal access token
3
- const http = require('http')
4
- const process = require('process')
3
+ import http from 'http'
4
+ import process from 'process'
5
5
 
6
- const { Octokit } = require('@octokit/rest')
7
- const getPort = require('get-port')
8
- const inquirer = require('inquirer')
6
+ import { Octokit } from '@octokit/rest'
7
+ import getPort from 'get-port'
8
+ import inquirer from 'inquirer'
9
9
 
10
- const { log } = require('./command-helpers.cjs')
11
- const { createDeferred } = require('./deferred.cjs')
12
- const { openBrowser } = require('./open-browser.cjs')
10
+ import { log } from './command-helpers.mjs'
11
+ import createDeferred from './create-deferred.mjs'
12
+ import openBrowser from './open-browser.mjs'
13
13
 
14
14
  const SERVER_PORT = 3000
15
15
 
@@ -44,7 +44,7 @@ const promptForAuthMethod = async () => {
44
44
  * Authenticate with the netlify app
45
45
  * @returns {Promise<Token>} Returns a Promise with a token object
46
46
  */
47
- const authWithNetlify = async () => {
47
+ export const authWithNetlify = async () => {
48
48
  const port = await getPort({ port: SERVER_PORT })
49
49
  const { promise: deferredPromise, reject: deferredReject, resolve: deferredResolve } = createDeferred()
50
50
 
@@ -116,12 +116,10 @@ const authWithToken = async () => {
116
116
  * Get a GitHub token
117
117
  * @returns {Promise<Token>} Returns a Promise with a token object
118
118
  */
119
- const getGitHubToken = async () => {
119
+ export const getGitHubToken = async () => {
120
120
  log('')
121
121
 
122
122
  const withNetlify = await promptForAuthMethod()
123
123
 
124
124
  return withNetlify ? await authWithNetlify() : await authWithToken()
125
125
  }
126
-
127
- module.exports = { getGitHubToken, authWithNetlify }
@@ -6,7 +6,7 @@ import parseIgnore from 'parse-gitignore'
6
6
 
7
7
  import { fileExistsAsync } from '../lib/fs.cjs'
8
8
 
9
- import { log } from './command-helpers.cjs'
9
+ import { log } from './command-helpers.mjs'
10
10
 
11
11
  const hasGitIgnore = async function (dir) {
12
12
  const gitIgnorePath = path.join(dir, '.gitignore')
@@ -1,7 +1,6 @@
1
- // TODO: use static `import` after migrating this repository to pure ES modules
2
- const netlifyHeadersParser = import('netlify-headers-parser')
1
+ import { parseAllHeaders } from 'netlify-headers-parser'
3
2
 
4
- const { NETLIFYDEVERR, log } = require('./command-helpers.cjs')
3
+ import { NETLIFYDEVERR, log } from './command-helpers.mjs'
5
4
 
6
5
  /**
7
6
  * Get the matching headers for `path` given a set of `rules`.
@@ -14,7 +13,7 @@ const { NETLIFYDEVERR, log } = require('./command-helpers.cjs')
14
13
  *
15
14
  * @returns {Object<string,string[]>}
16
15
  */
17
- const headersForPath = function (headers, path) {
16
+ export const headersForPath = function (headers, path) {
18
17
  const matchingHeaders = headers.filter(({ forRegExp }) => forRegExp.test(path)).map(getHeaderValues)
19
18
  const headersRules = Object.assign({}, ...matchingHeaders)
20
19
  return headersRules
@@ -24,8 +23,7 @@ const getHeaderValues = function ({ values }) {
24
23
  return values
25
24
  }
26
25
 
27
- const parseHeaders = async function ({ configPath, headersFiles }) {
28
- const { parseAllHeaders } = await netlifyHeadersParser
26
+ export const parseHeaders = async function ({ configPath, headersFiles }) {
29
27
  const { errors, headers } = await parseAllHeaders({
30
28
  headersFiles,
31
29
  netlifyConfigPath: configPath,
@@ -47,8 +45,3 @@ const handleHeadersErrors = function (errors) {
47
45
  const getErrorMessage = function ({ message }) {
48
46
  return message
49
47
  }
50
-
51
- module.exports = {
52
- headersForPath,
53
- parseHeaders,
54
- }
@@ -1,10 +1,10 @@
1
1
  // @ts-check
2
- const { Octokit } = require('@octokit/rest')
2
+ import { Octokit } from '@octokit/rest'
3
3
 
4
- const { chalk, error: failAndExit, log } = require('../command-helpers.cjs')
5
- const { getGitHubToken: ghauth } = require('../gh-auth.cjs')
4
+ import { chalk, error as failAndExit, log } from '../command-helpers.mjs'
5
+ import { getGitHubToken as ghauth } from '../gh-auth.mjs'
6
6
 
7
- const { createDeployKey, formatErrorMessage, getBuildSettings, saveNetlifyToml, setupSite } = require('./utils.cjs')
7
+ import { createDeployKey, formatErrorMessage, getBuildSettings, saveNetlifyToml, setupSite } from './utils.mjs'
8
8
 
9
9
  /**
10
10
  * @typedef Token
@@ -25,7 +25,7 @@ const PAGE_SIZE = 100
25
25
  * Get a valid GitHub token
26
26
  * @returns {Promise<string>}
27
27
  */
28
- const getGitHubToken = async ({ globalConfig }) => {
28
+ export const getGitHubToken = async ({ globalConfig }) => {
29
29
  const userId = globalConfig.get('userId')
30
30
 
31
31
  /** @type {Token} */
@@ -203,7 +203,7 @@ const addNotificationHooks = async ({ api, siteId, token }) => {
203
203
  * @param {string} config.repoOwner
204
204
  * @param {string} config.siteId
205
205
  */
206
- const configGithub = async ({ command, repoName, repoOwner, siteId }) => {
206
+ export const configGithub = async ({ command, repoName, repoOwner, siteId }) => {
207
207
  const { netlify } = command
208
208
  const {
209
209
  api,
@@ -256,5 +256,3 @@ const configGithub = async ({ command, repoName, repoOwner, siteId }) => {
256
256
  log()
257
257
  await addNotificationHooks({ siteId, api, token })
258
258
  }
259
-
260
- module.exports = { configGithub, getGitHubToken }
@@ -1,9 +1,9 @@
1
1
  // @ts-check
2
- const inquirer = require('inquirer')
2
+ import inquirer from 'inquirer'
3
3
 
4
- const { exit, log } = require('../command-helpers.cjs')
4
+ import { exit, log } from '../command-helpers.mjs'
5
5
 
6
- const { createDeployKey, getBuildSettings, saveNetlifyToml, setupSite } = require('./utils.cjs')
6
+ import { createDeployKey, getBuildSettings, saveNetlifyToml, setupSite } from './utils.mjs'
7
7
 
8
8
  const addDeployKey = async ({ deployKey }) => {
9
9
  log('\nGive this Netlify SSH public key access to your repository:\n')
@@ -58,7 +58,7 @@ const addDeployHook = async ({ deployHook }) => {
58
58
  * @param {*} config.repoData
59
59
  * @param {string} config.siteId
60
60
  */
61
- module.exports = async function configManual({ command, repoData, siteId }) {
61
+ export default async function configManual({ command, repoData, siteId }) {
62
62
  const { netlify } = command
63
63
  const {
64
64
  api,
@@ -1,8 +1,8 @@
1
1
  // @ts-check
2
- const { chalk, log } = require('../command-helpers.cjs')
2
+ import { chalk, log } from '../command-helpers.mjs'
3
3
 
4
- const { configGithub } = require('./config-github.cjs')
5
- const configManual = require('./config-manual.cjs')
4
+ import { configGithub } from './config-github.mjs'
5
+ import configManual from './config-manual.mjs'
6
6
 
7
7
  const logSuccess = (repoData) => {
8
8
  log()
@@ -24,7 +24,7 @@ const logSuccess = (repoData) => {
24
24
  * @param {*} config.repoData
25
25
  * @param {string} config.siteId
26
26
  */
27
- const configureRepo = async ({ command, manual, repoData, siteId }) => {
27
+ export const configureRepo = async ({ command, manual, repoData, siteId }) => {
28
28
  if (manual) {
29
29
  await configManual({ command, siteId, repoData })
30
30
  } else if (repoData.provider === 'github') {
@@ -36,4 +36,3 @@ const configureRepo = async ({ command, manual, repoData, siteId }) => {
36
36
 
37
37
  logSuccess(repoData)
38
38
  }
39
- module.exports = { configureRepo }
@@ -1,8 +1,7 @@
1
1
  // @ts-check
2
- const frameworkInfoPromise = import('@netlify/framework-info')
2
+ import { listFrameworks } from '@netlify/framework-info'
3
3
 
4
- const getFrameworkInfo = async ({ baseDirectory, nodeVersion }) => {
5
- const { listFrameworks } = await frameworkInfoPromise
4
+ export const getFrameworkInfo = async ({ baseDirectory, nodeVersion }) => {
6
5
  const frameworks = await listFrameworks({ projectDir: baseDirectory, nodeVersion })
7
6
  // several frameworks can be detected - first one has highest priority
8
7
  if (frameworks.length !== 0) {
@@ -22,5 +21,3 @@ const getFrameworkInfo = async ({ baseDirectory, nodeVersion }) => {
22
21
  }
23
22
  return {}
24
23
  }
25
-
26
- module.exports = { getFrameworkInfo }
@@ -1,11 +1,11 @@
1
1
  // @ts-check
2
- const { readFile } = require('fs').promises
2
+ import { readFile } from 'fs/promises'
3
3
 
4
- const { get } = require('dot-prop')
5
- const locatePath = require('locate-path')
6
- const nodeVersionAlias = require('node-version-alias')
4
+ import { get } from 'dot-prop'
5
+ import locatePath from 'locate-path'
6
+ import nodeVersionAlias from 'node-version-alias'
7
7
 
8
- const { warn } = require('../command-helpers.cjs')
8
+ import { warn } from '../command-helpers.mjs'
9
9
 
10
10
  const DEFAULT_NODE_VERSION = '12.18.0'
11
11
  const NVM_FLAG_PREFIX = '--'
@@ -14,7 +14,7 @@ const NVM_FLAG_PREFIX = '--'
14
14
  const normalizeConfiguredVersion = (version) =>
15
15
  version.startsWith(NVM_FLAG_PREFIX) ? version.slice(NVM_FLAG_PREFIX.length) : version
16
16
 
17
- const detectNodeVersion = async ({ baseDirectory, env }) => {
17
+ export const detectNodeVersion = async ({ baseDirectory, env }) => {
18
18
  try {
19
19
  const nodeVersionFile = await locatePath(['.nvmrc', '.node-version'], { cwd: baseDirectory })
20
20
  const configuredVersion =
@@ -31,5 +31,3 @@ const detectNodeVersion = async ({ baseDirectory, env }) => {
31
31
  return DEFAULT_NODE_VERSION
32
32
  }
33
33
  }
34
-
35
- module.exports = { detectNodeVersion }
@@ -1,10 +1,8 @@
1
1
  const isPluginInstalled = (configPlugins, plugin) =>
2
2
  configPlugins.some(({ package: configPlugin }) => configPlugin === plugin)
3
3
 
4
- const getRecommendPlugins = (frameworkPlugins, config) =>
4
+ export const getRecommendPlugins = (frameworkPlugins, config) =>
5
5
  frameworkPlugins.filter((plugin) => !isPluginInstalled(config.plugins, plugin))
6
6
 
7
- const getUIPlugins = (configPlugins) =>
8
- configPlugins.filter(({ origin }) => origin === 'ui').map(({ package }) => ({ package }))
9
-
10
- module.exports = { getRecommendPlugins, getUIPlugins }
7
+ export const getUIPlugins = (configPlugins) =>
8
+ configPlugins.filter(({ origin }) => origin === 'ui').map(({ package: pkg }) => ({ package: pkg }))
@@ -1,20 +1,18 @@
1
1
  // @ts-check
2
- const { existsSync } = require('fs')
3
- const { writeFile } = require('fs').promises
4
- const path = require('path')
5
- const process = require('process')
2
+ import { writeFile } from 'fs/promises'
3
+ import path from 'path'
4
+ import process from 'process'
6
5
 
7
- const cleanDeep = require('clean-deep')
8
- const inquirer = require('inquirer')
9
- const isEmpty = require('lodash/isEmpty')
6
+ import cleanDeep from 'clean-deep'
7
+ import inquirer from 'inquirer'
10
8
 
11
- const { normalizeBackslash } = require('../../lib/path.cjs')
12
- const { log } = require('../command-helpers.cjs')
13
- const { chalk, error: failAndExit, warn } = require('../command-helpers.cjs')
9
+ import { fileExistsAsync } from '../../lib/fs.cjs'
10
+ import { normalizeBackslash } from '../../lib/path.mjs'
11
+ import { chalk, error as failAndExit, log, warn } from '../command-helpers.mjs'
14
12
 
15
- const { getFrameworkInfo } = require('./frameworks.cjs')
16
- const { detectNodeVersion } = require('./node-version.cjs')
17
- const { getRecommendPlugins, getUIPlugins } = require('./plugins.cjs')
13
+ import { getFrameworkInfo } from './frameworks.mjs'
14
+ import { detectNodeVersion } from './node-version.mjs'
15
+ import { getRecommendPlugins, getUIPlugins } from './plugins.mjs'
18
16
 
19
17
  const normalizeDir = ({ baseDirectory, defaultValue, dir }) => {
20
18
  if (dir === undefined) {
@@ -85,7 +83,7 @@ const getPromptInputs = ({ defaultBaseDir, defaultBuildCmd, defaultBuildDir }) =
85
83
  const getBaseDirectory = ({ repositoryRoot, siteRoot }) =>
86
84
  path.normalize(repositoryRoot) === path.normalize(siteRoot) ? process.cwd() : siteRoot
87
85
 
88
- const getBuildSettings = async ({ config, env, repositoryRoot, siteRoot }) => {
86
+ export const getBuildSettings = async ({ config, env, repositoryRoot, siteRoot }) => {
89
87
  const baseDirectory = getBaseDirectory({ repositoryRoot, siteRoot })
90
88
  const nodeVersion = await detectNodeVersion({ baseDirectory, env })
91
89
  const {
@@ -153,17 +151,25 @@ const getNetlifyToml = ({
153
151
  ## more info on configuring this file: https://docs.netlify.com/configure-builds/file-based-configuration/
154
152
  `
155
153
 
156
- const saveNetlifyToml = async ({ baseDir, buildCmd, buildDir, config, configPath, functionsDir, repositoryRoot }) => {
154
+ export const saveNetlifyToml = async ({
155
+ baseDir,
156
+ buildCmd,
157
+ buildDir,
158
+ config,
159
+ configPath,
160
+ functionsDir,
161
+ repositoryRoot,
162
+ }) => {
157
163
  const tomlPathParts = [repositoryRoot, baseDir, 'netlify.toml'].filter(Boolean)
158
164
  const tomlPath = path.join(...tomlPathParts)
159
- if (existsSync(tomlPath)) {
165
+ if (await fileExistsAsync(tomlPath)) {
160
166
  return
161
167
  }
162
168
 
163
169
  // We don't want to create a `netlify.toml` file that overrides existing configuration
164
170
  // In a monorepo the configuration can come from a repo level netlify.toml
165
171
  // so we make sure it doesn't by checking `configPath === undefined`
166
- if (configPath === undefined && !isEmpty(cleanDeep(config))) {
172
+ if (configPath === undefined && Object.keys(cleanDeep(config)).length !== 0) {
167
173
  return
168
174
  }
169
175
 
@@ -188,14 +194,14 @@ const saveNetlifyToml = async ({ baseDir, buildCmd, buildDir, config, configPath
188
194
  }
189
195
  }
190
196
 
191
- const formatErrorMessage = ({ error, message }) => {
197
+ export const formatErrorMessage = ({ error, message }) => {
192
198
  const errorMessage = error.json ? `${error.message} - ${JSON.stringify(error.json)}` : error.message
193
199
  return `${message} with error: ${chalk.red(errorMessage)}`
194
200
  }
195
201
 
196
202
  const formatTitle = (title) => chalk.cyan(title)
197
203
 
198
- const createDeployKey = async ({ api }) => {
204
+ export const createDeployKey = async ({ api }) => {
199
205
  try {
200
206
  const deployKey = await api.createDeployKey()
201
207
  return deployKey
@@ -205,7 +211,7 @@ const createDeployKey = async ({ api }) => {
205
211
  }
206
212
  }
207
213
 
208
- const updateSite = async ({ api, options, siteId }) => {
214
+ export const updateSite = async ({ api, options, siteId }) => {
209
215
  try {
210
216
  const updatedSite = await api.updateSite({ siteId, body: options })
211
217
  return updatedSite
@@ -215,7 +221,7 @@ const updateSite = async ({ api, options, siteId }) => {
215
221
  }
216
222
  }
217
223
 
218
- const setupSite = async ({ api, configPlugins, pluginsToInstall, repo, siteId }) => {
224
+ export const setupSite = async ({ api, configPlugins, pluginsToInstall, repo, siteId }) => {
219
225
  const updatedSite = await updateSite({
220
226
  siteId,
221
227
  api,
@@ -225,5 +231,3 @@ const setupSite = async ({ api, configPlugins, pluginsToInstall, repo, siteId })
225
231
 
226
232
  return updatedSite
227
233
  }
228
-
229
- module.exports = { getBuildSettings, saveNetlifyToml, formatErrorMessage, createDeployKey, updateSite, setupSite }
@@ -4,11 +4,11 @@ import process from 'process'
4
4
  import fetch from 'node-fetch'
5
5
  import pWaitFor from 'p-wait-for'
6
6
 
7
- import { fetchLatestVersion, shouldFetchLatestVersion } from '../lib/exec-fetcher.cjs'
7
+ import { fetchLatestVersion, shouldFetchLatestVersion } from '../lib/exec-fetcher.mjs'
8
8
  import { getPathInHome } from '../lib/settings.cjs'
9
9
 
10
- import { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log } from './command-helpers.cjs'
11
- import execa from './execa.cjs'
10
+ import { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log } from './command-helpers.mjs'
11
+ import execa from './execa.mjs'
12
12
 
13
13
  const PACKAGE_NAME = 'live-tunnel-client'
14
14
  const EXEC_NAME = PACKAGE_NAME
@@ -10,11 +10,11 @@ import hasbin from 'hasbin'
10
10
  import Listr from 'listr'
11
11
  import pathKey from 'path-key'
12
12
 
13
- import { fetchLatestVersion, shouldFetchLatestVersion } from '../../lib/exec-fetcher.cjs'
13
+ import { fetchLatestVersion, shouldFetchLatestVersion } from '../../lib/exec-fetcher.mjs'
14
14
  import { fileExistsAsync, rmdirRecursiveAsync } from '../../lib/fs.cjs'
15
- import { normalizeBackslash } from '../../lib/path.cjs'
15
+ import { normalizeBackslash } from '../../lib/path.mjs'
16
16
  import { getLegacyPathInHome, getPathInHome } from '../../lib/settings.cjs'
17
- import { chalk } from '../command-helpers.cjs'
17
+ import { chalk } from '../command-helpers.mjs'
18
18
 
19
19
  import { checkGitLFSVersionStep, checkGitVersionStep, checkLFSFiltersStep } from './steps.mjs'
20
20
 
@@ -1,7 +1,7 @@
1
1
  // @ts-check
2
2
  import semver from 'semver'
3
3
 
4
- import execa from '../execa.cjs'
4
+ import execa from '../execa.mjs'
5
5
 
6
6
  export const checkLFSFilters = async function () {
7
7
  try {
@@ -1,4 +1,4 @@
1
- import { chalk } from '../command-helpers.cjs'
1
+ import { chalk } from '../command-helpers.mjs'
2
2
 
3
3
  import { checkGitVersion, checkHelperVersion, checkLFSFilters, checkLFSVersion } from './requirements.mjs'
4
4
 
@@ -2,7 +2,7 @@ import os from 'os'
2
2
 
3
3
  import boxen from 'boxen'
4
4
 
5
- import { chalk, log } from '../command-helpers.cjs'
5
+ import { chalk, log } from '../command-helpers.mjs'
6
6
 
7
7
  import { getShellInfo, isBinInPath } from './install.mjs'
8
8
 
@@ -1,9 +1,9 @@
1
- const process = require('process')
1
+ import process from 'process'
2
2
 
3
- const open = require('better-opn')
4
- const isDockerContainer = require('is-docker')
3
+ import open from 'better-opn'
4
+ import isDockerContainer from 'is-docker'
5
5
 
6
- const { chalk, log } = require('./command-helpers.cjs')
6
+ import { chalk, log } from './command-helpers.mjs'
7
7
 
8
8
  const unableToOpenBrowserMessage = function ({ message, url }) {
9
9
  log('---------------------------')
@@ -39,4 +39,4 @@ const openBrowser = async function ({ silentBrowserNoneError, url }) {
39
39
  }
40
40
  }
41
41
 
42
- module.exports = { openBrowser }
42
+ export default openBrowser