netlify-cli 10.18.0 → 11.0.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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
- "version": "10.18.0",
3
+ "version": "11.0.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "netlify-cli",
9
- "version": "10.18.0",
9
+ "version": "11.0.0",
10
10
  "hasInstallScript": true,
11
11
  "license": "MIT",
12
12
  "dependencies": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
3
  "description": "Netlify command line tool",
4
- "version": "10.18.0",
4
+ "version": "11.0.0",
5
5
  "author": "Netlify Inc.",
6
6
  "contributors": [
7
7
  "@whitep4nth3r (https://twitter.com/whitep4nth3r)",
@@ -54,6 +54,8 @@ const {
54
54
 
55
55
  const { createDevExecCommand } = require('./dev-exec')
56
56
 
57
+ const netlifyBuildPromise = import('@netlify/build')
58
+
57
59
  const startStaticServer = async ({ settings }) => {
58
60
  const server = new StaticServer({
59
61
  rootPath: settings.dist,
@@ -417,7 +419,8 @@ const validateGeoCountryCode = (arg) => {
417
419
  */
418
420
  const dev = async (options, command) => {
419
421
  log(`${NETLIFYDEV}`)
420
- const { api, config, repositoryRoot, site, siteInfo, state } = command.netlify
422
+ const { api, cachedConfig, config, repositoryRoot, site, siteInfo, state } = command.netlify
423
+ const netlifyBuild = await netlifyBuildPromise
421
424
  config.dev = { ...config.dev }
422
425
  config.build = { ...config.build }
423
426
  /** @type {import('./types').DevConfig} */
@@ -429,7 +432,7 @@ const dev = async (options, command) => {
429
432
  ...options,
430
433
  }
431
434
 
432
- let { env } = command.netlify.cachedConfig
435
+ let { env } = cachedConfig
433
436
  if (!options.offline && siteInfo.use_envelope) {
434
437
  env = await getEnvelopeEnv({ api, context: options.context, env, siteInfo })
435
438
  }
@@ -449,6 +452,26 @@ const dev = async (options, command) => {
449
452
  let settings = {}
450
453
  try {
451
454
  settings = await detectServerSettings(devConfig, options, site.root)
455
+
456
+ // If there are plugins that we should be running for this site, add them
457
+ // to the config as if they were declared in netlify.toml. We must check
458
+ // whether the plugin has already been added by another source (like the
459
+ // TOML file or the UI), as we don't want to run the same plugin twice.
460
+ if (settings.plugins) {
461
+ const { plugins: existingPlugins = [] } = cachedConfig.config
462
+ const existingPluginNames = new Set(existingPlugins.map((plugin) => plugin.package))
463
+ const newPlugins = settings.plugins
464
+ .map((pluginName) => {
465
+ if (existingPluginNames.has(pluginName)) {
466
+ return
467
+ }
468
+
469
+ return { package: pluginName, origin: 'config', inputs: {} }
470
+ })
471
+ .filter(Boolean)
472
+
473
+ cachedConfig.config.plugins = [...newPlugins, ...cachedConfig.config.plugins]
474
+ }
452
475
  } catch (error_) {
453
476
  log(NETLIFYDEVERR, error_.message)
454
477
  exit(1)
@@ -472,7 +495,19 @@ const dev = async (options, command) => {
472
495
  capabilities,
473
496
  timeouts,
474
497
  })
475
- await startFrameworkServer({ settings })
498
+
499
+ log(`${NETLIFYDEVWARN} Setting up local development server`)
500
+
501
+ const devCommand = () => startFrameworkServer({ settings })
502
+ const startDevOptions = getBuildOptions({
503
+ cachedConfig,
504
+ options,
505
+ })
506
+ const { error: startDevError, success } = await netlifyBuild.startDev(devCommand, startDevOptions)
507
+
508
+ if (!success) {
509
+ error(`Could not start local development server\n\n${startDevError.message}\n\n${startDevError.stack}`)
510
+ }
476
511
 
477
512
  // TODO: We should consolidate this with the existing config watcher.
478
513
  const getUpdatedConfig = async () => {
@@ -612,6 +647,19 @@ const dev = async (options, command) => {
612
647
  printBanner({ url })
613
648
  }
614
649
 
650
+ const getBuildOptions = ({ cachedConfig, options: { context, cwd = process.cwd(), debug, dry, offline }, token }) => ({
651
+ cachedConfig,
652
+ token,
653
+ dry,
654
+ debug,
655
+ context,
656
+ mode: 'cli',
657
+ telemetry: false,
658
+ buffer: false,
659
+ offline,
660
+ cwd,
661
+ })
662
+
615
663
  /**
616
664
  * Creates the `netlify dev` command
617
665
  * @param {import('../base-command').BaseCommand} program
@@ -167,6 +167,7 @@ const getSettingsFromFramework = (framework) => {
167
167
  name: frameworkName,
168
168
  staticAssetsDirectory: staticDir,
169
169
  env = {},
170
+ plugins,
170
171
  } = framework
171
172
 
172
173
  return {
@@ -176,6 +177,7 @@ const getSettingsFromFramework = (framework) => {
176
177
  framework: frameworkName,
177
178
  env,
178
179
  pollingStrategies: pollingStrategies.map(({ name }) => name),
180
+ plugins,
179
181
  }
180
182
  }
181
183
 
@@ -311,6 +313,8 @@ const detectServerSettings = async (devConfig, options, projectDir) => {
311
313
  validateFrameworkConfig({ devConfig })
312
314
  settings = await mergeSettings({ devConfig, frameworkSettings })
313
315
  }
316
+
317
+ settings.plugins = frameworkSettings && frameworkSettings.plugins
314
318
  } else if (devConfig.framework === '#custom') {
315
319
  validateFrameworkConfig({ devConfig })
316
320
  // when the users wants to configure `command` and `targetPort`