netlify-cli 12.2.6 → 12.2.8

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 (112) hide show
  1. package/bin/run.mjs +2 -3
  2. package/npm-shrinkwrap.json +249 -126
  3. package/package.json +4 -4
  4. package/scripts/postinstall.mjs +2 -2
  5. package/src/commands/base-command.mjs +8 -12
  6. package/src/commands/build/build.mjs +2 -2
  7. package/src/commands/completion/completion.mjs +3 -3
  8. package/src/commands/deploy/deploy.mjs +4 -5
  9. package/src/commands/dev/{dev-exec.cjs → dev-exec.mjs} +5 -5
  10. package/src/commands/dev/{dev.cjs → dev.mjs} +32 -32
  11. package/src/commands/dev/index.mjs +1 -0
  12. package/src/commands/env/{env-clone.cjs → env-clone.mjs} +7 -16
  13. package/src/commands/env/{env-get.cjs → env-get.mjs} +5 -13
  14. package/src/commands/env/{env-import.cjs → env-import.mjs} +8 -15
  15. package/src/commands/env/{env-list.cjs → env-list.mjs} +13 -25
  16. package/src/commands/env/{env-set.cjs → env-set.mjs} +5 -5
  17. package/src/commands/env/{env-unset.cjs → env-unset.mjs} +4 -12
  18. package/src/commands/env/{env.cjs → env.mjs} +7 -9
  19. package/src/commands/env/index.mjs +1 -0
  20. package/src/commands/functions/functions-build.mjs +2 -1
  21. package/src/commands/functions/functions-create.mjs +2 -12
  22. package/src/commands/functions/functions-invoke.mjs +2 -1
  23. package/src/commands/functions/functions-list.mjs +2 -1
  24. package/src/commands/functions/functions-serve.mjs +3 -2
  25. package/src/commands/graph/{graph-config-write.cjs → graph-config-write.mjs} +8 -8
  26. package/src/commands/graph/{graph-edit.cjs → graph-edit.mjs} +9 -14
  27. package/src/commands/graph/{graph-handler.cjs → graph-handler.mjs} +6 -6
  28. package/src/commands/graph/{graph-init.cjs → graph-init.mjs} +12 -20
  29. package/src/commands/graph/{graph-library.cjs → graph-library.mjs} +8 -8
  30. package/src/commands/graph/{graph-operations.cjs → graph-operations.mjs} +7 -7
  31. package/src/commands/graph/{graph-pull.cjs → graph-pull.mjs} +8 -12
  32. package/src/commands/graph/{graph.cjs → graph.mjs} +8 -10
  33. package/src/commands/graph/index.mjs +1 -0
  34. package/src/commands/init/init.mjs +5 -2
  35. package/src/commands/link/index.mjs +1 -0
  36. package/src/commands/link/{link.cjs → link.mjs} +15 -13
  37. package/src/commands/lm/index.mjs +1 -0
  38. package/src/commands/lm/{lm-info.cjs → lm-info.mjs} +4 -6
  39. package/src/commands/lm/{lm-install.cjs → lm-install.mjs} +3 -5
  40. package/src/commands/lm/{lm-setup.cjs → lm-setup.mjs} +8 -8
  41. package/src/commands/lm/{lm-uninstall.cjs → lm-uninstall.mjs} +2 -4
  42. package/src/commands/lm/{lm.cjs → lm.mjs} +5 -7
  43. package/src/commands/logout/logout.mjs +2 -1
  44. package/src/commands/main.mjs +10 -12
  45. package/src/commands/recipes/common.mjs +36 -0
  46. package/src/commands/recipes/index.mjs +1 -0
  47. package/src/commands/recipes/{recipes-list.cjs → recipes-list.mjs} +3 -5
  48. package/src/commands/recipes/{recipes.cjs → recipes.mjs} +12 -10
  49. package/src/commands/sites/sites-create-template.mjs +3 -1
  50. package/src/commands/sites/sites-create.mjs +4 -2
  51. package/src/commands/sites/sites-list.mjs +1 -1
  52. package/src/commands/unlink/unlink.mjs +2 -1
  53. package/src/functions-templates/go/hello-world/go.mod +1 -1
  54. package/src/functions-templates/javascript/stripe-charge/package-lock.json +6 -6
  55. package/src/functions-templates/javascript/stripe-subscription/package-lock.json +6 -6
  56. package/src/functions-templates/javascript/token-hider/package-lock.json +6 -6
  57. package/src/functions-templates/rust/hello-world/Cargo.toml +1 -1
  58. package/src/functions-templates/typescript/hello-world/package-lock.json +6 -6
  59. package/src/lib/account.cjs +0 -3
  60. package/src/lib/{api.cjs → api.mjs} +3 -5
  61. package/src/lib/{build.cjs → build.mjs} +9 -9
  62. package/src/lib/completion/constants.mjs +4 -0
  63. package/src/lib/completion/{generate-autocompletion.cjs → generate-autocompletion.mjs} +6 -6
  64. package/src/lib/completion/{script.cjs → get-autocompletion.mjs} +1 -25
  65. package/src/lib/completion/index.mjs +1 -0
  66. package/src/lib/completion/script.mjs +35 -0
  67. package/src/lib/edge-functions/{editor-helper.cjs → editor-helper.mjs} +4 -6
  68. package/src/lib/edge-functions/index.cjs +1 -2
  69. package/src/lib/exec-fetcher.cjs +0 -2
  70. package/src/lib/functions/{form-submissions-handler.cjs → form-submissions-handler.mjs} +26 -28
  71. package/src/lib/functions/{scheduled.cjs → scheduled.mjs} +6 -8
  72. package/src/lib/functions/{server.cjs → server.mjs} +20 -29
  73. package/src/lib/geo-location.cjs +1 -1
  74. package/src/lib/{http-agent.cjs → http-agent.mjs} +7 -8
  75. package/src/lib/one-graph/{cli-client.cjs → cli-client.mjs} +46 -74
  76. package/src/lib/one-graph/{cli-netlify-graph.cjs → cli-netlify-graph.mjs} +35 -43
  77. package/src/recipes/vscode/{index.cjs → index.mjs} +7 -9
  78. package/src/recipes/vscode/{settings.cjs → settings.mjs} +10 -12
  79. package/src/utils/{create-stream-promise.cjs → create-stream-promise.mjs} +2 -2
  80. package/src/utils/{detect-server-settings.cjs → detect-server-settings.mjs} +14 -20
  81. package/src/utils/functions/constants.mjs +1 -0
  82. package/src/utils/functions/{functions.cjs → functions.mjs} +6 -8
  83. package/src/utils/functions/{get-functions.cjs → get-functions.mjs} +4 -25
  84. package/src/utils/functions/index.mjs +3 -0
  85. package/src/utils/get-package-json.mjs +16 -0
  86. package/src/utils/{get-repo-data.cjs → get-repo-data.mjs} +15 -12
  87. package/src/utils/{gitignore.cjs → gitignore.mjs} +6 -8
  88. package/src/utils/index.cjs +0 -20
  89. package/src/utils/{live-tunnel.cjs → live-tunnel.mjs} +8 -10
  90. package/src/utils/lm/{install.cjs → install.mjs} +26 -25
  91. package/src/utils/lm/{requirements.cjs → requirements.mjs} +6 -13
  92. package/src/utils/lm/{steps.cjs → steps.mjs} +6 -8
  93. package/src/utils/lm/{ui.cjs → ui.mjs} +5 -7
  94. package/src/utils/{proxy.cjs → proxy.mjs} +31 -34
  95. package/src/utils/{read-repo-url.cjs → read-repo-url.mjs} +6 -11
  96. package/src/utils/{state-config.cjs → state-config.mjs} +8 -10
  97. package/src/utils/telemetry/index.mjs +1 -0
  98. package/src/utils/telemetry/{request.cjs → request.mjs} +5 -3
  99. package/src/utils/telemetry/{telemetry.cjs → telemetry.mjs} +12 -14
  100. package/src/utils/telemetry/{validation.cjs → validation.mjs} +2 -2
  101. package/src/commands/dev/index.cjs +0 -5
  102. package/src/commands/env/index.cjs +0 -5
  103. package/src/commands/graph/index.cjs +0 -5
  104. package/src/commands/link/index.cjs +0 -6
  105. package/src/commands/lm/index.cjs +0 -5
  106. package/src/commands/recipes/common.cjs +0 -33
  107. package/src/commands/recipes/index.cjs +0 -8
  108. package/src/lib/completion/constants.cjs +0 -6
  109. package/src/lib/completion/index.cjs +0 -5
  110. package/src/utils/functions/constants.cjs +0 -5
  111. package/src/utils/functions/index.cjs +0 -12
  112. package/src/utils/telemetry/index.cjs +0 -5
@@ -1,23 +1,20 @@
1
1
  /* eslint-disable eslint-comments/disable-enable-pair */
2
2
 
3
3
  // @ts-check
4
- const fs = require('fs')
5
- const path = require('path')
6
- const process = require('process')
7
-
8
- const inquirer = require('inquirer')
9
- const inquirerAutocompletePrompt = require('inquirer-autocomplete-prompt')
10
- const {
11
- // eslint-disable-next-line no-unused-vars
12
- CodegenHelpers,
13
- GraphQL,
14
- GraphQLHelpers,
15
- IncludedCodegen,
16
- InternalConsole,
17
- NetlifyGraph,
18
- } = require('netlify-onegraph-internal')
19
-
20
- const { chalk, detectServerSettings, error, execa, getFunctionsDir, log, warn } = require('../../utils/index.cjs')
4
+ import fs from 'fs'
5
+ import path from 'path'
6
+ import process from 'process'
7
+ import { pathToFileURL } from 'url'
8
+
9
+ import inquirer from 'inquirer'
10
+ import inquirerAutocompletePrompt from 'inquirer-autocomplete-prompt'
11
+ import { GraphQL, GraphQLHelpers, IncludedCodegen, InternalConsole, NetlifyGraph } from 'netlify-onegraph-internal'
12
+
13
+ import detectServerSettings from '../../utils/detect-server-settings.mjs'
14
+ import { getFunctionsDir } from '../../utils/functions/index.mjs'
15
+ import utils from '../../utils/index.cjs'
16
+
17
+ const { chalk, error, execa, log, warn } = utils
21
18
 
22
19
  const { printSchema } = GraphQL
23
20
 
@@ -30,7 +27,8 @@ const internalConsole = {
30
27
 
31
28
  InternalConsole.registerConsole(internalConsole)
32
29
 
33
- const { extractFunctionsFromOperationDoc } = NetlifyGraph
30
+ const { defaultExampleOperationsDoc, extractFunctionsFromOperationDoc, generateHandlerSource } = NetlifyGraph
31
+ const { normalizeOperationsDoc } = GraphQLHelpers
34
32
 
35
33
  /**
36
34
  * Updates the netlify.toml in-place with the `graph.codeGenerator` key set to `codegenModuleImportPath
@@ -370,9 +368,9 @@ const runPrettier = async (filePath) => {
370
368
  * @param {string} input.operationsDoc The GraphQL operations doc to use when generating the functions
371
369
  * @param {Record<string, NetlifyGraph.ExtractedFunction>} input.functions The parsed queries with metadata to use when generating library functions
372
370
  * @param {Record<string, NetlifyGraph.ExtractedFragment>} input.fragments The parsed queries with metadata to use when generating library functions
373
- * @param {CodegenHelpers.GenerateRuntimeFunction} input.generate
371
+ * @param {import('netlify-onegraph-internal').CodegenHelpers.GenerateRuntimeFunction} input.generate
374
372
  * @param {(message: string) => void=} input.logger A function that if provided will be used to log messages
375
- * @returns {Promise<CodegenHelpers.NamedExportedFile[]>} In-memory files
373
+ * @returns {Promise<import('netlify-onegraph-internal').CodegenHelpers.NamedExportedFile[]>} In-memory files
376
374
  */
377
375
  const generateRuntimeSource = async ({
378
376
  fragments,
@@ -406,7 +404,7 @@ const generateRuntimeSource = async ({
406
404
  * @param {string} input.operationsDoc The GraphQL operations doc to use when generating the functions
407
405
  * @param {Record<string, NetlifyGraph.ExtractedFunction>} input.functions The parsed queries with metadata to use when generating library functions
408
406
  * @param {Record<string, NetlifyGraph.ExtractedFragment>} input.fragments The parsed queries with metadata to use when generating library functions
409
- * @param {CodegenHelpers.GenerateRuntimeFunction} input.generate
407
+ * @param {import('netlify-onegraph-internal').CodegenHelpers.GenerateRuntimeFunction} input.generate
410
408
  * @param {(message: string) => void=} input.logger A function that if provided will be used to log messages
411
409
  * @returns {Promise<void>} Void, effectfully writes the generated library to the filesystem
412
410
  */
@@ -543,14 +541,14 @@ const readGraphQLSchemaFile = (netlifyGraphConfig) => {
543
541
  /**
544
542
  * Given a NetlifyGraphConfig, read the appropriate files and write a handler for the given operationId to the filesystem
545
543
  * @param {object} input
546
- * @param {CodegenHelpers.GenerateHandlerFunction} input.generate
544
+ * @param {import('netlify-onegraph-internal').CodegenHelpers.GenerateHandlerFunction} input.generate
547
545
  * @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig
548
546
  * @param {GraphQL.GraphQLSchema} input.schema The GraphQL schema to use when generating the handler
549
547
  * @param {string} input.operationId The operationId to use when generating the handler
550
548
  * @param {string} input.operationsDoc The document containing the operation with operationId and any fragment dependency to use when generating the handler
551
549
  * @param {object} input.handlerOptions The options to use when generating the handler
552
550
  * @param {(message: string) => void=} input.logger A function that if provided will be used to log messages
553
- * @returns {Promise<{exportedFiles: CodegenHelpers.ExportedFile[]; operation: GraphQL.OperationDefinitionNode;} | undefined>} The generated files
551
+ * @returns {Promise<{exportedFiles: import('netlify-onegraph-internal').CodegenHelpers.ExportedFile[]; operation: GraphQL.OperationDefinitionNode;} | undefined>} The generated files
554
552
  */
555
553
  const generateHandlerSourceByOperationId = async ({
556
554
  generate,
@@ -579,7 +577,7 @@ const generateHandlerSourceByOperationId = async ({
579
577
  /**
580
578
  * Given a NetlifyGraphConfig, read the appropriate files and write a handler for the given operationId to the filesystem
581
579
  * @param {object} input
582
- * @param {CodegenHelpers.GenerateHandlerFunction} input.generate
580
+ * @param {import('netlify-onegraph-internal').CodegenHelpers.GenerateHandlerFunction} input.generate
583
581
  * @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig
584
582
  * @param {GraphQL.GraphQLSchema} input.schema The GraphQL schema to use when generating the handler
585
583
  * @param {string} input.operationId The operationId to use when generating the handler
@@ -663,7 +661,7 @@ const generateHandlerByOperationId = async ({ generate, handlerOptions, netlifyG
663
661
  /**
664
662
  * Given a NetlifyGraphConfig, read the appropriate files and write a handler for the given operationId to the filesystem
665
663
  * @param {object} input
666
- * @param {CodegenHelpers.GenerateHandlerFunction} input.generate
664
+ * @param {import('netlify-onegraph-internal').CodegenHelpers.GenerateHandlerFunction} input.generate
667
665
  * @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig
668
666
  * @param {GraphQL.GraphQLSchema} input.schema The GraphQL schema to use when generating the handler
669
667
  * @param {string} input.operationName The name of the operation to use when generating the handler
@@ -715,13 +713,13 @@ const generateHandlerByOperationName = async ({
715
713
  /**
716
714
  * Given a NetlifyGraphConfig, read the appropriate files and write a handler for the given operationId to the filesystem
717
715
  * @param {object} input
718
- * @param {CodegenHelpers.GenerateHandlerPreviewFunction} input.generate
716
+ * @param {import('netlify-onegraph-internal').CodegenHelpers.GenerateHandlerPreviewFunction} input.generate
719
717
  * @param {NetlifyGraph.NetlifyGraphConfig} input.netlifyGraphConfig
720
718
  * @param {GraphQL.GraphQLSchema} input.schema The GraphQL schema to use when generating the handler
721
719
  * @param {string} input.operationName The name of the operation to use when generating the handler
722
720
  * @param {object} input.handlerOptions The options to use when generating the handler
723
721
  * @param {(message: string) => void} input.logger A function that if provided will be used to log messages
724
- * @returns {CodegenHelpers.ExportedFile | undefined}
722
+ * @returns {import('netlify-onegraph-internal').CodegenHelpers.ExportedFile | undefined}
725
723
  */
726
724
  const generateHandlerPreviewByOperationName = ({
727
725
  generate,
@@ -876,7 +874,7 @@ let lastWarnedFailedCodegenModule
876
874
  * @param {object} input
877
875
  * @param {object} input.config The parsed netlify.toml file
878
876
  * @param {string=} input.cwd The optional directory to use as a base path when resolving codegen modules
879
- * @returns {Promise<CodegenHelpers.CodegenModule | void>} codegenModule
877
+ * @returns {Promise<import('netlify-onegraph-internal').CodegenHelpers.CodegenModule | void>} codegenModule
880
878
  */
881
879
  const dynamicallyLoadCodegenModule = async ({ config, cwd }) => {
882
880
  const basePath = cwd || process.cwd()
@@ -909,17 +907,11 @@ const dynamicallyLoadCodegenModule = async ({ config, cwd }) => {
909
907
  const relativePath = path.join(basePath, importPath)
910
908
  const absoluteOrNodePath = path.resolve(...absolute)
911
909
 
912
- const finalPath = fs.existsSync(relativePath) ? relativePath : absoluteOrNodePath
910
+ const finalPath = fs.existsSync(relativePath) ? relativePath : pathToFileURL(absoluteOrNodePath).href
913
911
 
914
- /** @type {CodegenHelpers.CodegenModule | undefined} */
915
- let newModule
916
- try {
917
- // eslint-disable-next-line import/no-dynamic-require, n/global-require
918
- newModule = require(finalPath)
919
- } catch {
920
- // eslint-disable-next-line import/no-dynamic-require
921
- newModule = await import(finalPath)
922
- }
912
+ /** @type {import('netlify-onegraph-internal').CodegenHelpers.CodegenModule | undefined} */
913
+ // eslint-disable-next-line import/no-dynamic-require
914
+ const newModule = await import(finalPath)
923
915
 
924
916
  if (newModule) {
925
917
  const hasGenerators = Array.isArray(newModule.generators)
@@ -1011,14 +1003,14 @@ const autocompleteCodegenModules = async ({ config }) => {
1011
1003
  )
1012
1004
  }
1013
1005
 
1014
- module.exports = {
1006
+ export {
1015
1007
  autocompleteCodegenModules,
1016
1008
  autocompleteOperationNames,
1017
1009
  buildSchema,
1018
- defaultExampleOperationsDoc: NetlifyGraph.defaultExampleOperationsDoc,
1019
- extractFunctionsFromOperationDoc: NetlifyGraph.extractFunctionsFromOperationDoc,
1010
+ defaultExampleOperationsDoc,
1011
+ extractFunctionsFromOperationDoc,
1020
1012
  generateFunctionsFile,
1021
- generateHandlerSource: NetlifyGraph.generateHandlerSource,
1013
+ generateHandlerSource,
1022
1014
  generateHandlerByOperationId,
1023
1015
  generateHandlerByOperationName,
1024
1016
  generateHandlerPreviewByOperationName,
@@ -1031,7 +1023,7 @@ module.exports = {
1031
1023
  getGraphEditUrlBySiteName,
1032
1024
  getNetlifyGraphConfig,
1033
1025
  loadNetlifyGraphConfig,
1034
- normalizeOperationsDoc: GraphQLHelpers.normalizeOperationsDoc,
1026
+ normalizeOperationsDoc,
1035
1027
  parse,
1036
1028
  readGraphQLOperationsSourceFile,
1037
1029
  readGraphQLSchemaFile,
@@ -1,13 +1,13 @@
1
- const { join } = require('path')
1
+ import { join } from 'path'
2
2
 
3
- const execa = require('execa')
4
- const inquirer = require('inquirer')
3
+ import execa from 'execa'
4
+ import inquirer from 'inquirer'
5
5
 
6
- const { NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } = require('../../utils/command-helpers.cjs')
6
+ import { NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } from '../../utils/command-helpers.cjs'
7
7
 
8
- const { applySettings, getSettings, writeSettings } = require('./settings.cjs')
8
+ import { applySettings, getSettings, writeSettings } from './settings.mjs'
9
9
 
10
- const description = 'Create VS Code settings for an optimal experience with Netlify projects'
10
+ export const description = 'Create VS Code settings for an optimal experience with Netlify projects'
11
11
 
12
12
  const getPrompt = ({ fileExists, path }) => {
13
13
  const formattedPath = chalk.underline(path)
@@ -48,7 +48,7 @@ const getDenoExtPrompt = () => {
48
48
  })
49
49
  }
50
50
 
51
- const run = async ({ config, repositoryRoot }) => {
51
+ export const run = async ({ config, repositoryRoot }) => {
52
52
  const { DenoBridge } = await import('@netlify/edge-bundler')
53
53
  const deno = new DenoBridge({
54
54
  onBeforeDownload: () =>
@@ -86,5 +86,3 @@ const run = async ({ config, repositoryRoot }) => {
86
86
  error('Could not write VS Code settings file.')
87
87
  }
88
88
  }
89
-
90
- module.exports = { description, run }
@@ -1,9 +1,9 @@
1
- const { promises: fs } = require('fs')
2
- const { dirname, relative } = require('path')
1
+ import { mkdir, readFile, stat, writeFile } from 'fs/promises'
2
+ import { dirname, relative } from 'path'
3
3
 
4
- const unixify = require('unixify')
4
+ import unixify from 'unixify'
5
5
 
6
- const applySettings = (existingSettings, { denoBinary, edgeFunctionsPath, repositoryRoot }) => {
6
+ export const applySettings = (existingSettings, { denoBinary, edgeFunctionsPath, repositoryRoot }) => {
7
7
  const relativeEdgeFunctionsPath = unixify(relative(repositoryRoot, edgeFunctionsPath))
8
8
  const settings = {
9
9
  ...existingSettings,
@@ -30,15 +30,15 @@ const applySettings = (existingSettings, { denoBinary, edgeFunctionsPath, reposi
30
30
  return settings
31
31
  }
32
32
 
33
- const getSettings = async (settingsPath) => {
33
+ export const getSettings = async (settingsPath) => {
34
34
  try {
35
- const stats = await fs.stat(settingsPath)
35
+ const stats = await stat(settingsPath)
36
36
 
37
37
  if (!stats.isFile()) {
38
38
  throw new Error(`${settingsPath} is not a valid file.`)
39
39
  }
40
40
 
41
- const file = await fs.readFile(settingsPath)
41
+ const file = await readFile(settingsPath)
42
42
 
43
43
  return {
44
44
  fileExists: true,
@@ -56,11 +56,9 @@ const getSettings = async (settingsPath) => {
56
56
  }
57
57
  }
58
58
 
59
- const writeSettings = async ({ settings, settingsPath }) => {
59
+ export const writeSettings = async ({ settings, settingsPath }) => {
60
60
  const serializedSettings = JSON.stringify(settings, null, 2)
61
61
 
62
- await fs.mkdir(dirname(settingsPath), { recursive: true })
63
- await fs.writeFile(settingsPath, serializedSettings)
62
+ await mkdir(dirname(settingsPath), { recursive: true })
63
+ await writeFile(settingsPath, serializedSettings)
64
64
  }
65
-
66
- module.exports = { applySettings, getSettings, writeSettings }
@@ -1,4 +1,4 @@
1
- const { Buffer } = require('buffer')
1
+ import { Buffer } from 'buffer'
2
2
 
3
3
  const SEC_TO_MILLISEC = 1e3
4
4
 
@@ -46,4 +46,4 @@ const createStreamPromise = function (stream, timeoutSeconds, bytesLimit = DEFAU
46
46
  })
47
47
  }
48
48
 
49
- module.exports = { createStreamPromise }
49
+ export default createStreamPromise
@@ -1,18 +1,18 @@
1
1
  // @ts-check
2
- const { EOL } = require('os')
3
- const path = require('path')
4
- const process = require('process')
2
+ import { EOL } from 'os'
3
+ import path from 'path'
4
+ import process from 'process'
5
5
 
6
- const frameworkInfoPromise = import('@netlify/framework-info')
7
- const fuzzy = require('fuzzy')
8
- const getPort = require('get-port')
9
- const isPlainObject = require('is-plain-obj')
6
+ import { getFramework, listFrameworks } from '@netlify/framework-info'
7
+ import fuzzy from 'fuzzy'
8
+ import getPort from 'get-port'
9
+ import isPlainObject from 'is-plain-obj'
10
10
 
11
- const { readFileAsyncCatchError } = require('../lib/fs.cjs')
11
+ import { readFileAsyncCatchError } from '../lib/fs.cjs'
12
12
 
13
- const { NETLIFYDEVWARN, chalk, log } = require('./command-helpers.cjs')
14
- const { acquirePort } = require('./dev.cjs')
15
- const { getInternalFunctionsDir } = require('./functions/index.cjs')
13
+ import { NETLIFYDEVWARN, chalk, log } from './command-helpers.cjs'
14
+ import { acquirePort } from './dev.cjs'
15
+ import { getInternalFunctionsDir } from './functions/index.mjs'
16
16
 
17
17
  const formatProperty = (str) => chalk.magenta(`'${str}'`)
18
18
  const formatValue = (str) => chalk.green(`'${str}'`)
@@ -184,7 +184,6 @@ const getSettingsFromFramework = (framework) => {
184
184
  const hasDevCommand = (framework) => Array.isArray(framework.dev.commands) && framework.dev.commands.length !== 0
185
185
 
186
186
  const detectFrameworkSettings = async ({ projectDir }) => {
187
- const { listFrameworks } = await frameworkInfoPromise
188
187
  const projectFrameworks = await listFrameworks({ projectDir })
189
188
  const frameworks = projectFrameworks.filter((framework) => hasDevCommand(framework))
190
189
 
@@ -194,10 +193,8 @@ const detectFrameworkSettings = async ({ projectDir }) => {
194
193
 
195
194
  if (frameworks.length > 1) {
196
195
  // performance optimization, load inquirer on demand
197
- // eslint-disable-next-line n/global-require
198
- const inquirer = require('inquirer')
199
- // eslint-disable-next-line n/global-require
200
- const inquirerAutocompletePrompt = require('inquirer-autocomplete-prompt')
196
+ const { default: inquirer } = await import('inquirer')
197
+ const { default: inquirerAutocompletePrompt } = await import('inquirer-autocomplete-prompt')
201
198
  /** multiple matching detectors, make the user choose */
202
199
  inquirer.registerPrompt('autocomplete', inquirerAutocompletePrompt)
203
200
  const scriptInquirerOptions = formatSettingsArrForInquirer(frameworks)
@@ -279,7 +276,6 @@ const mergeSettings = async ({ devConfig, frameworkSettings = {} }) => {
279
276
  */
280
277
  const handleForcedFramework = async ({ devConfig, projectDir }) => {
281
278
  // this throws if `devConfig.framework` is not a supported framework
282
- const { getFramework } = await frameworkInfoPromise
283
279
  const frameworkSettings = getSettingsFromFramework(await getFramework(devConfig.framework, { projectDir }))
284
280
  return mergeSettings({ devConfig, frameworkSettings })
285
281
  }
@@ -369,6 +365,4 @@ const formatSettingsArrForInquirer = function (frameworks) {
369
365
  return formattedArr.flat()
370
366
  }
371
367
 
372
- module.exports = {
373
- detectServerSettings,
374
- }
368
+ export default detectServerSettings
@@ -0,0 +1 @@
1
+ export const CLOCKWORK_USERAGENT = 'Netlify Clockwork'
@@ -1,8 +1,8 @@
1
1
  // @ts-check
2
- const { resolve } = require('path')
2
+ import { resolve } from 'path'
3
3
 
4
- const { isDirectoryAsync, isFileAsync } = require('../../lib/fs.cjs')
5
- const { getPathInProject } = require('../../lib/settings.cjs')
4
+ import { isDirectoryAsync, isFileAsync } from '../../lib/fs.cjs'
5
+ import { getPathInProject } from '../../lib/settings.cjs'
6
6
 
7
7
  /**
8
8
  * retrieves the function directory out of the flags or config
@@ -12,25 +12,23 @@ const { getPathInProject } = require('../../lib/settings.cjs')
12
12
  * @param {string} [defaultValue]
13
13
  * @returns {string}
14
14
  */
15
- const getFunctionsDir = ({ config, options }, defaultValue) =>
15
+ export const getFunctionsDir = ({ config, options }, defaultValue) =>
16
16
  options.functions ||
17
17
  (config.dev && config.dev.functions) ||
18
18
  config.functionsDirectory ||
19
19
  (config.dev && config.dev.Functions) ||
20
20
  defaultValue
21
21
 
22
- const getFunctionsManifestPath = async ({ base }) => {
22
+ export const getFunctionsManifestPath = async ({ base }) => {
23
23
  const path = resolve(base, getPathInProject(['functions', 'manifest.json']))
24
24
  const isFile = await isFileAsync(path)
25
25
 
26
26
  return isFile ? path : null
27
27
  }
28
28
 
29
- const getInternalFunctionsDir = async ({ base }) => {
29
+ export const getInternalFunctionsDir = async ({ base }) => {
30
30
  const path = resolve(base, getPathInProject(['functions-internal']))
31
31
  const isDirectory = await isDirectoryAsync(path)
32
32
 
33
33
  return isDirectory ? path : null
34
34
  }
35
-
36
- module.exports = { getFunctionsDir, getInternalFunctionsDir, getFunctionsManifestPath }
@@ -1,9 +1,10 @@
1
1
  // @ts-check
2
- const { fileExistsAsync } = require('../../lib/fs.cjs')
2
+ import { fileExistsAsync } from '../../lib/fs.cjs'
3
3
 
4
4
  const getUrlPath = (functionName) => `/.netlify/functions/${functionName}`
5
5
 
6
- const BACKGROUND = '-background'
6
+ export const BACKGROUND = '-background'
7
+ const JS = 'js'
7
8
 
8
9
  const addFunctionProps = ({ mainFile, name, runtime, schedule }) => {
9
10
  const urlPath = getUrlPath(name)
@@ -11,8 +12,6 @@ const addFunctionProps = ({ mainFile, name, runtime, schedule }) => {
11
12
  return { mainFile, name, runtime, urlPath, isBackground, schedule }
12
13
  }
13
14
 
14
- const JS = 'js'
15
-
16
15
  /**
17
16
  * @param {Record<string, { schedule?: string }>} functionConfigRecord
18
17
  * @returns {Record<string, { schedule?: string }>}
@@ -20,7 +19,7 @@ const JS = 'js'
20
19
  const extractSchedule = (functionConfigRecord) =>
21
20
  Object.fromEntries(Object.entries(functionConfigRecord).map(([name, { schedule }]) => [name, { schedule }]))
22
21
 
23
- const getFunctions = async (functionsSrcDir, config = {}) => {
22
+ export const getFunctions = async (functionsSrcDir, config = {}) => {
24
23
  if (!(await fileExistsAsync(functionsSrcDir))) {
25
24
  return []
26
25
  }
@@ -34,23 +33,3 @@ const getFunctions = async (functionsSrcDir, config = {}) => {
34
33
  const functionsWithProps = functions.filter(({ runtime }) => runtime === JS).map((func) => addFunctionProps(func))
35
34
  return functionsWithProps
36
35
  }
37
-
38
- const getFunctionsAndWatchDirs = async (functionsSrcDir) => {
39
- if (!(await fileExistsAsync(functionsSrcDir))) {
40
- return { functions: [], watchDirs: [functionsSrcDir] }
41
- }
42
-
43
- // performance optimization, load '@netlify/zip-it-and-ship-it' on demand
44
- const { listFunctions } = await import('@netlify/zip-it-and-ship-it')
45
-
46
- // get all functions files so we know which directories to watch
47
- const functions = await listFunctions(functionsSrcDir)
48
- const watchDirs = [functionsSrcDir]
49
-
50
- // filter for only main files to serve
51
- const functionsWithProps = functions.filter(({ runtime }) => runtime === JS).map((func) => addFunctionProps(func))
52
-
53
- return { functions: functionsWithProps, watchDirs }
54
- }
55
-
56
- module.exports = { getFunctions, getFunctionsAndWatchDirs, BACKGROUND }
@@ -0,0 +1,3 @@
1
+ export * from './constants.mjs'
2
+ export * from './functions.mjs'
3
+ export * from './get-functions.mjs'
@@ -0,0 +1,16 @@
1
+ import { readFile } from 'fs/promises'
2
+ import { dirname, join } from 'path'
3
+ import { fileURLToPath } from 'url'
4
+
5
+ let packageJson
6
+
7
+ const getPackageJson = async () => {
8
+ if (!packageJson) {
9
+ const packageJsonPath = join(dirname(fileURLToPath(import.meta.url)), '../../package.json')
10
+ packageJson = JSON.parse(await readFile(packageJsonPath))
11
+ }
12
+
13
+ return packageJson
14
+ }
15
+
16
+ export default getPackageJson
@@ -1,15 +1,14 @@
1
1
  // @ts-check
2
- const { dirname } = require('path')
3
- const process = require('process')
4
- const util = require('util')
2
+ import { dirname } from 'path'
3
+ import process from 'process'
4
+ import util from 'util'
5
5
 
6
- const findUp = require('find-up')
7
- const gitRepoInfo = require('git-repo-info')
8
- const gitconfiglocal = require('gitconfiglocal')
9
- const isEmpty = require('lodash/isEmpty')
10
- const parseGitRemote = require('parse-github-url')
6
+ import findUp from 'find-up'
7
+ import gitRepoInfo from 'git-repo-info'
8
+ import gitconfiglocal from 'gitconfiglocal'
9
+ import parseGitRemote from 'parse-github-url'
11
10
 
12
- const { log } = require('./command-helpers.cjs')
11
+ import { log } from './command-helpers.cjs'
13
12
 
14
13
  /**
15
14
  *
@@ -30,7 +29,7 @@ const getRepoData = async function ({ remoteName } = {}) {
30
29
  log(`Git directory located in ${baseGitPath}`)
31
30
  }
32
31
 
33
- if (isEmpty(gitConfig) || isEmpty(gitConfig.remote)) {
32
+ if (!gitConfig || !gitConfig.remote || Object.keys(gitConfig.remote).length === 0) {
34
33
  throw new Error('No Git remote found')
35
34
  }
36
35
 
@@ -39,7 +38,11 @@ const getRepoData = async function ({ remoteName } = {}) {
39
38
  remoteName = remotes.find((remote) => remote === 'origin') || remotes[0]
40
39
  }
41
40
 
42
- if (!Object.prototype.hasOwnProperty.call(gitConfig.remote, remoteName) || isEmpty(gitConfig.remote[remoteName])) {
41
+ if (
42
+ !Object.prototype.hasOwnProperty.call(gitConfig.remote, remoteName) ||
43
+ !gitConfig.remote[remoteName] ||
44
+ Object.keys(gitConfig.remote[remoteName]).length === 0
45
+ ) {
43
46
  throw new Error(
44
47
  `The specified remote "${remoteName}" is not defined in Git repo. Please use --gitRemoteName flag to specify a remote.`,
45
48
  )
@@ -69,4 +72,4 @@ const PROVIDERS = {
69
72
  'gitlab.com': 'gitlab',
70
73
  }
71
74
 
72
- module.exports = { getRepoData }
75
+ export default getRepoData
@@ -1,12 +1,12 @@
1
1
  // @ts-check
2
- const { readFile, writeFile } = require('fs').promises
3
- const path = require('path')
2
+ import { readFile, writeFile } from 'fs/promises'
3
+ import path from 'path'
4
4
 
5
- const parseIgnore = require('parse-gitignore')
5
+ import parseIgnore from 'parse-gitignore'
6
6
 
7
- const { fileExistsAsync } = require('../lib/fs.cjs')
7
+ import { fileExistsAsync } from '../lib/fs.cjs'
8
8
 
9
- const { log } = require('./command-helpers.cjs')
9
+ import { log } from './command-helpers.cjs'
10
10
 
11
11
  const hasGitIgnore = async function (dir) {
12
12
  const gitIgnorePath = path.join(dir, '.gitignore')
@@ -14,7 +14,7 @@ const hasGitIgnore = async function (dir) {
14
14
  return hasIgnore
15
15
  }
16
16
 
17
- const ensureNetlifyIgnore = async function (dir) {
17
+ export const ensureNetlifyIgnore = async function (dir) {
18
18
  const gitIgnorePath = path.join(dir, '.gitignore')
19
19
  const ignoreContent = '# Local Netlify folder\n.netlify\n'
20
20
 
@@ -40,5 +40,3 @@ const ensureNetlifyIgnore = async function (dir) {
40
40
  await writeFile(gitIgnorePath, newContents, 'utf8')
41
41
  }
42
42
  }
43
-
44
- module.exports = { ensureNetlifyIgnore }
@@ -1,42 +1,22 @@
1
1
  // @ts-check
2
2
  const commandHelpers = require('./command-helpers.cjs')
3
- const createStreamPromise = require('./create-stream-promise.cjs')
4
3
  const deploy = require('./deploy/index.cjs')
5
- const detectServerSettings = require('./detect-server-settings.cjs')
6
4
  const dev = require('./dev.cjs')
7
5
  const env = require('./env/index.cjs')
8
6
  const execa = require('./execa.cjs')
9
- const functions = require('./functions/index.cjs')
10
7
  const getGlobalConfig = require('./get-global-config.cjs')
11
- const getRepoData = require('./get-repo-data.cjs')
12
8
  const ghAuth = require('./gh-auth.cjs')
13
- const gitignore = require('./gitignore.cjs')
14
- const liveTunnel = require('./live-tunnel.cjs')
15
9
  const openBrowser = require('./open-browser.cjs')
16
10
  const parseRawFlags = require('./parse-raw-flags.cjs')
17
- const proxy = require('./proxy.cjs')
18
- const readRepoURL = require('./read-repo-url.cjs')
19
- const StateConfig = require('./state-config.cjs')
20
- const telemetry = require('./telemetry/index.cjs')
21
11
 
22
12
  module.exports = {
23
13
  ...commandHelpers,
24
- ...createStreamPromise,
25
14
  ...deploy,
26
- ...detectServerSettings,
27
15
  ...dev,
28
16
  ...env,
29
- ...functions,
30
- ...getRepoData,
31
17
  ...ghAuth,
32
- ...gitignore,
33
- ...liveTunnel,
34
18
  ...openBrowser,
35
19
  ...parseRawFlags,
36
- ...proxy,
37
- ...readRepoURL,
38
- ...StateConfig,
39
- ...telemetry,
40
20
  execa,
41
21
  getGlobalConfig,
42
22
  }
@@ -1,14 +1,14 @@
1
1
  // @ts-check
2
- const process = require('process')
2
+ import process from 'process'
3
3
 
4
- const fetch = require('node-fetch')
5
- const pWaitFor = require('p-wait-for')
4
+ import fetch from 'node-fetch'
5
+ import pWaitFor from 'p-wait-for'
6
6
 
7
- const { fetchLatestVersion, shouldFetchLatestVersion } = require('../lib/exec-fetcher.cjs')
8
- const { getPathInHome } = require('../lib/settings.cjs')
7
+ import { fetchLatestVersion, shouldFetchLatestVersion } from '../lib/exec-fetcher.cjs'
8
+ import { getPathInHome } from '../lib/settings.cjs'
9
9
 
10
- const { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log } = require('./command-helpers.cjs')
11
- const execa = require('./execa.cjs')
10
+ import { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log } from './command-helpers.cjs'
11
+ import execa from './execa.cjs'
12
12
 
13
13
  const PACKAGE_NAME = 'live-tunnel-client'
14
14
  const EXEC_NAME = PACKAGE_NAME
@@ -87,7 +87,7 @@ const installTunnelClient = async function () {
87
87
  })
88
88
  }
89
89
 
90
- const startLiveTunnel = async ({ localPort, netlifyApiToken, siteId }) => {
90
+ export const startLiveTunnel = async ({ localPort, netlifyApiToken, siteId }) => {
91
91
  const session = await createTunnel({
92
92
  siteId,
93
93
  netlifyApiToken,
@@ -121,5 +121,3 @@ const startLiveTunnel = async ({ localPort, netlifyApiToken, siteId }) => {
121
121
 
122
122
  return session.session_url
123
123
  }
124
-
125
- module.exports = { startLiveTunnel }