netlify-cli 17.10.2 → 17.11.0

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.
@@ -6,21 +6,9 @@ import getPort from 'get-port';
6
6
  import { detectFrameworkSettings } from './build-info.js';
7
7
  import { NETLIFYDEVWARN, chalk, log } from './command-helpers.js';
8
8
  import { acquirePort } from './dev.js';
9
- import { getInternalFunctionsDir } from './functions/functions.js';
10
9
  import { getPluginsToAutoInstall } from './init/utils.js';
11
- /** @param {string} str */
12
- // @ts-expect-error TS(7006) FIXME: Parameter 'str' implicitly has an 'any' type.
13
10
  const formatProperty = (str) => chalk.magenta(`'${str}'`);
14
- /** @param {string} str */
15
- // @ts-expect-error TS(7006) FIXME: Parameter 'str' implicitly has an 'any' type.
16
11
  const formatValue = (str) => chalk.green(`'${str}'`);
17
- /**
18
- * @param {object} options
19
- * @param {string} options.keyFile
20
- * @param {string} options.certFile
21
- * @returns {Promise<{ key: string, cert: string, keyFilePath: string, certFilePath: string }>}
22
- */
23
- // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
24
12
  const readHttpsSettings = async (options) => {
25
13
  if (typeof options !== 'object' || !options.keyFile || !options.certFile) {
26
14
  throw new TypeError(`https options should be an object with ${formatProperty('keyFile')} and ${formatProperty('certFile')} string properties`);
@@ -43,23 +31,13 @@ const readHttpsSettings = async (options) => {
43
31
  };
44
32
  /**
45
33
  * Validates a property inside the devConfig to be of a given type
46
- * @param {import('../commands/dev/types.js').DevConfig} devConfig The devConfig
47
- * @param {keyof import('../commands/dev/types.js').DevConfig} property The property to validate
48
- * @param {'string' | 'number'} type The type it should have
49
34
  */
50
- // @ts-expect-error TS(7006) FIXME: Parameter 'devConfig' implicitly has an 'any' type... Remove this comment to see the full error message
51
35
  function validateProperty(devConfig, property, type) {
52
36
  if (devConfig[property] && typeof devConfig[property] !== type) {
53
37
  const formattedProperty = formatProperty(property);
54
38
  throw new TypeError(`Invalid ${formattedProperty} option provided in config. The value of ${formattedProperty} option must be of type ${type}`);
55
39
  }
56
40
  }
57
- /**
58
- *
59
- * @param {object} config
60
- * @param {import('../commands/dev/types.js').DevConfig} config.devConfig
61
- */
62
- // @ts-expect-error TS(7031) FIXME: Binding element 'devConfig' implicitly has an 'any... Remove this comment to see the full error message
63
41
  const validateFrameworkConfig = ({ devConfig }) => {
64
42
  validateProperty(devConfig, 'command', 'string');
65
43
  validateProperty(devConfig, 'port', 'number');
@@ -68,12 +46,6 @@ const validateFrameworkConfig = ({ devConfig }) => {
68
46
  throw new Error(`${formatProperty('port')} and ${formatProperty('targetPort')} options cannot have same values. Please consult the documentation for more details: https://ntl.fyi/ports-and-netlify-dev`);
69
47
  }
70
48
  };
71
- /**
72
- * @param {object} config
73
- * @param {import('../commands/dev/types.js').DevConfig} config.devConfig
74
- * @param {number=} config.detectedPort
75
- */
76
- // @ts-expect-error TS(7031) FIXME: Binding element 'detectedPort' implicitly has an '... Remove this comment to see the full error message
77
49
  const validateConfiguredPort = ({ detectedPort, devConfig }) => {
78
50
  if (devConfig.port && devConfig.port === detectedPort) {
79
51
  const formattedPort = formatProperty('port');
@@ -84,21 +56,13 @@ const DEFAULT_PORT = 8888;
84
56
  const DEFAULT_STATIC_PORT = 3999;
85
57
  /**
86
58
  * Logs a message that it was unable to determine the dist directory and falls back to the workingDir
87
- * @param {string} workingDir
88
59
  */
89
- // @ts-expect-error TS(7006) FIXME: Parameter 'workingDir' implicitly has an 'any' typ... Remove this comment to see the full error message
90
60
  const getDefaultDist = (workingDir) => {
91
61
  log(`${NETLIFYDEVWARN} Unable to determine public folder to serve files from. Using current working directory`);
92
62
  log(`${NETLIFYDEVWARN} Setup a netlify.toml file with a [dev] section to specify your dev server settings.`);
93
63
  log(`${NETLIFYDEVWARN} See docs at: https://cli.netlify.com/netlify-dev#project-detection`);
94
64
  return workingDir;
95
65
  };
96
- /**
97
- * @param {object} config
98
- * @param {import('../commands/dev/types.js').DevConfig} config.devConfig
99
- * @returns {Promise<number>}
100
- */
101
- // @ts-expect-error TS(7031) FIXME: Binding element 'devConfig' implicitly has an 'any... Remove this comment to see the full error message
102
66
  const getStaticServerPort = async ({ devConfig }) => {
103
67
  const port = await acquirePort({
104
68
  configuredPort: devConfig.staticServerPort,
@@ -107,16 +71,7 @@ const getStaticServerPort = async ({ devConfig }) => {
107
71
  });
108
72
  return port;
109
73
  };
110
- /**
111
- *
112
- * @param {object} config
113
- * @param {import('../commands/dev/types.js').DevConfig} config.devConfig
114
- * @param {import('commander').OptionValues} config.flags
115
- * @param {string} config.workingDir
116
- * @returns {Promise<Omit<import('./types.js').BaseServerSettings, 'command'> & {command?: string}>}
117
- */
118
- // @ts-expect-error TS(7031) FIXME: Binding element 'devConfig' implicitly has an 'any... Remove this comment to see the full error message
119
- const handleStaticServer = async ({ devConfig, flags, workingDir }) => {
74
+ const handleStaticServer = async ({ devConfig, flags, workingDir, }) => {
120
75
  validateProperty(devConfig, 'staticServerPort', 'number');
121
76
  if (flags.dir) {
122
77
  log(`${NETLIFYDEVWARN} Using simple static server because ${formatProperty('--dir')} flag was specified`);
@@ -156,20 +111,11 @@ const getSettingsFromDetectedSettings = (command, settings) => {
156
111
  clearPublishDirectory: settings.clearPublishDirectory,
157
112
  };
158
113
  };
159
- /**
160
- * @param {import('../commands/dev/types.js').DevConfig} devConfig
161
- */
162
- // @ts-expect-error TS(7006) FIXME: Parameter 'devConfig' implicitly has an 'any' type... Remove this comment to see the full error message
163
114
  const hasCommandAndTargetPort = (devConfig) => devConfig.command && devConfig.targetPort;
164
115
  /**
165
116
  * Creates settings for the custom framework
166
- * @param {object} config
167
- * @param {import('../commands/dev/types.js').DevConfig} config.devConfig
168
- * @param {string} config.workingDir
169
- * @returns {import('./types.js').BaseServerSettings}
170
117
  */
171
- // @ts-expect-error TS(7031) FIXME: Binding element 'devConfig' implicitly has an 'any... Remove this comment to see the full error message
172
- const handleCustomFramework = ({ devConfig, workingDir }) => {
118
+ const handleCustomFramework = ({ devConfig, workingDir, }) => {
173
119
  if (!hasCommandAndTargetPort(devConfig)) {
174
120
  throw new Error(`${formatProperty('command')} and ${formatProperty('targetPort')} properties are required when ${formatProperty('framework')} is set to ${formatValue('#custom')}`);
175
121
  }
@@ -183,10 +129,6 @@ const handleCustomFramework = ({ devConfig, workingDir }) => {
183
129
  };
184
130
  /**
185
131
  * Merges the framework settings with the devConfig
186
- * @param {object} config
187
- * @param {import('../commands/dev/types.js').DevConfig} config.devConfig
188
- * @param {string} config.workingDir
189
- * @param {Partial<import('./types.js').BaseServerSettings>=} config.frameworkSettings
190
132
  */
191
133
  const mergeSettings = async ({ devConfig, frameworkSettings = {}, workingDir, }) => {
192
134
  const command = devConfig.command || frameworkSettings.command;
@@ -267,25 +209,19 @@ const detectServerSettings = async (devConfig, flags, command) => {
267
209
  });
268
210
  // @ts-expect-error TS(2339) FIXME: Property 'functions' does not exist on type '{}'.
269
211
  const functionsDir = devConfig.functions || settings.functions;
270
- // @ts-expect-error TS(2345) FIXME: Argument of type '{ base: any; }' is not assignabl... Remove this comment to see the full error message
271
- const internalFunctionsDir = await getInternalFunctionsDir({ base: command.workingDir });
272
- const shouldStartFunctionsServer = Boolean(functionsDir || internalFunctionsDir);
273
212
  return {
274
213
  ...settings,
275
214
  port: acquiredPort,
276
215
  jwtSecret: devConfig.jwtSecret || 'secret',
277
216
  jwtRolePath: devConfig.jwtRolePath || 'app_metadata.authorization.roles',
278
217
  functions: functionsDir,
279
- ...(shouldStartFunctionsServer && { functionsPort: await getPort({ port: devConfig.functionsPort || 0 }) }),
218
+ functionsPort: await getPort({ port: devConfig.functionsPort || 0 }),
280
219
  ...(devConfig.https && { https: await readHttpsSettings(devConfig.https) }),
281
220
  };
282
221
  };
283
222
  /**
284
223
  * Returns a copy of the provided config with any plugins provided by the
285
224
  * server settings
286
- * @param {*} config
287
- * @param {Partial<import('./types.js').ServerSettings>} settings
288
- * @returns {*} Modified config
289
225
  */
290
226
  // @ts-expect-error TS(7006) FIXME: Parameter 'config' implicitly has an 'any' type.
291
227
  export const getConfigWithPlugins = (config, settings) => {
@@ -300,7 +236,6 @@ export const getConfigWithPlugins = (config, settings) => {
300
236
  // @ts-expect-error TS(7006) FIXME: Parameter 'plugin' implicitly has an 'any' type.
301
237
  const existingPluginNames = new Set(existingPlugins.map((plugin) => plugin.package));
302
238
  const newPlugins = settings.plugins
303
- // @ts-expect-error TS(7006) FIXME: Parameter 'pluginName' implicitly has an 'any' typ... Remove this comment to see the full error message
304
239
  .map((pluginName) => {
305
240
  if (existingPluginNames.has(pluginName)) {
306
241
  return;
@@ -33,18 +33,11 @@ export const getFunctionsServePath = ({ base, packagePath = '' }) => {
33
33
  };
34
34
  /**
35
35
  * Retrieves the internal functions directory and creates it if ensureExists is provided
36
- * @param {object} config
37
- * @param {string} config.base
38
- * @param {boolean=} config.ensureExists
39
- * @param {string} config.packagePath
40
- * @returns
41
36
  */
42
- // @ts-expect-error TS(7031) FIXME: Binding element 'base' implicitly has an 'any' typ... Remove this comment to see the full error message
43
- export const getInternalFunctionsDir = async ({ base, ensureExists, packagePath = '' }) => {
37
+ export const getInternalFunctionsDir = async ({ base, ensureExists, packagePath = '', }) => {
44
38
  const path = resolve(base, packagePath, getPathInProject([INTERNAL_FUNCTIONS_FOLDER]));
45
39
  if (ensureExists) {
46
40
  await fs.mkdir(path, { recursive: true });
47
41
  }
48
- const isDirectory = await isDirectoryAsync(path);
49
- return isDirectory ? path : null;
42
+ return path;
50
43
  };
@@ -1,46 +0,0 @@
1
- import { readFile, stat } from 'fs/promises';
2
- import { dirname, join, resolve } from 'path';
3
- import { getPathInProject } from '../settings.js';
4
- import { INTERNAL_EDGE_FUNCTIONS_FOLDER } from './consts.js';
5
- /**
6
- * @param {string} workingDir
7
- */
8
- // @ts-expect-error TS(7006) FIXME: Parameter 'workingDir' implicitly has an 'any' typ... Remove this comment to see the full error message
9
- export const getInternalFunctions = async (workingDir) => {
10
- const path = join(workingDir, getPathInProject([INTERNAL_EDGE_FUNCTIONS_FOLDER]));
11
- try {
12
- const stats = await stat(path);
13
- if (!stats.isDirectory()) {
14
- throw new Error('Internal edge functions directory expected');
15
- }
16
- }
17
- catch {
18
- return {
19
- functions: [],
20
- path: null,
21
- };
22
- }
23
- try {
24
- const manifestPath = join(path, 'manifest.json');
25
- // @ts-expect-error TS(2345) FIXME: Argument of type 'Buffer' is not assignable to par... Remove this comment to see the full error message
26
- const manifest = JSON.parse(await readFile(manifestPath));
27
- if (manifest.version !== 1) {
28
- throw new Error('Unsupported manifest format');
29
- }
30
- const data = {
31
- functions: manifest.functions || [],
32
- path,
33
- };
34
- if (manifest.import_map) {
35
- // @ts-expect-error TS(2339) FIXME: Property 'importMap' does not exist on type '{ fun... Remove this comment to see the full error message
36
- data.importMap = resolve(dirname(manifestPath), manifest.import_map);
37
- }
38
- return data;
39
- }
40
- catch {
41
- return {
42
- functions: [],
43
- path,
44
- };
45
- }
46
- };