netlify-cli 17.26.3 → 17.28.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,6 +1,7 @@
1
1
  import { Project } from '@netlify/build-info';
2
2
  import { resolveConfig } from '@netlify/config';
3
3
  import { Command, Help } from 'commander';
4
+ import { FeatureFlags } from '../utils/feature-flags.js';
4
5
  import { type NetlifyOptions } from './types.js';
5
6
  type Analytics = {
6
7
  startTime: bigint;
@@ -26,6 +27,8 @@ export default class BaseCommand extends Command {
26
27
  jsWorkspaceRoot?: string;
27
28
  /** The current workspace package we should execute the commands in */
28
29
  workspacePackage?: string;
30
+ featureFlags: FeatureFlags;
31
+ siteId?: string;
29
32
  /**
30
33
  * IMPORTANT this function will be called for each command!
31
34
  * Don't do anything expensive in there.
@@ -53,7 +56,6 @@ export default class BaseCommand extends Command {
53
56
  getConfig(config: {
54
57
  cwd: string;
55
58
  token?: string | null;
56
- state?: any;
57
59
  offline?: boolean;
58
60
  /** An optional path to the netlify configuration file e.g. netlify.toml */
59
61
  configFilePath?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"base-command.d.ts","sourceRoot":"","sources":["../../src/commands/base-command.ts"],"names":[],"mappings":"AAOA,OAAO,EAAiB,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAU,MAAM,WAAW,CAAA;AAgCjD,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,KAAK,SAAS,GAAG;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC,CAAA;AAkGD,0EAA0E;AAC1E,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,OAAO;;IAC9C,4DAA4D;IAE5D,OAAO,EAAE,cAAc,CAA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AK9B,iEAAiE;IACjE,UAAU,IAAI,IAAI;IAgIlB,kEAAkE;IAC5D,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO;IAwBtB,YAAY,CAAC,aAAa,CAAC,EAAE,MAAM;IAQnC,uBAAuB;IA4D7B,8CAA8C;IAC9C,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAOpD;;OAEG;YACW,IAAI;IAyLlB,iDAAiD;IAC3C,SAAS,CAAC,MAAM,EAAE;QACtB,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;QACrB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,2EAA2E;QAC3E,cAAc,CAAC,EAAE,MAAM,CAAA;QACvB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,cAAc,CAAC,EAAE,MAAM,CAAA;QACvB,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC;IAgDpC;;OAEG;IACH,gBAAgB,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IAI5C;;;;OAIG;IACH,iBAAiB,IAAI,YAAY,GAAG,KAAK;IAIzC;;OAEG;IACH,cAAc,CAAC,CAAC,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC;CAGjE"}
@@ -53,6 +53,10 @@ const HELP_SEPARATOR_WIDTH = 5;
53
53
  * workspace aware.
54
54
  */
55
55
  const COMMANDS_WITHOUT_WORKSPACE_OPTIONS = new Set(['api', 'recipes', 'completion', 'status', 'switch', 'login', 'lm']);
56
+ /**
57
+ * A list of commands where we need to fetch featureflags for config resolution
58
+ */
59
+ const COMMANDS_WITH_FEATURE_FLAGS = new Set(['build', 'dev', 'deploy']);
56
60
  /** Formats a help list correctly with the correct indent */
57
61
  const formatHelpList = (textArray) => textArray.join('\n').replace(/^/gm, ' '.repeat(HELP_INDENT_WIDTH));
58
62
  /** Get the duration between a start time and the current time */
@@ -121,6 +125,7 @@ class BaseCommand extends Command {
121
125
  // here we actually want to disable the lint rule as its value is set
122
126
  // eslint-disable-next-line workspace/no-process-cwd
123
127
  this.workingDir = process.cwd();
128
+ this.featureFlags = {};
124
129
  _BaseCommand_noBaseOptions.set(this, false
125
130
  /** don't show help options on command overview (mostly used on top commands like `addons` where options only apply on children) */
126
131
  );
@@ -431,6 +436,24 @@ class BaseCommand extends Command {
431
436
  apiUrlOpts.pathPrefix =
432
437
  process.env.NETLIFY_API_URL === `${apiUrl.protocol}//${apiUrl.host}` ? '/api/v1' : apiUrl.pathname;
433
438
  }
439
+ const agent = await getAgent({
440
+ httpProxy: flags.httpProxy,
441
+ certificateFile: flags.httpProxyCertificateFilename,
442
+ });
443
+ const apiOpts = { ...apiUrlOpts, agent };
444
+ // TODO: remove typecast once we have proper types for the API
445
+ const api = new NetlifyAPI(token || '', apiOpts);
446
+ actionCommand.siteId = flags.siteId || (typeof flags.site === 'string' && flags.site) || state.get('siteId');
447
+ const needsFeatureFlagsToResolveConfig = COMMANDS_WITH_FEATURE_FLAGS.has(actionCommand.name());
448
+ if (api.accessToken && !flags.offline && needsFeatureFlagsToResolveConfig && actionCommand.siteId) {
449
+ try {
450
+ const site = await api.getSite({ siteId: actionCommand.siteId, feature_flags: 'cli' });
451
+ actionCommand.featureFlags = site.feature_flags;
452
+ }
453
+ catch {
454
+ // if the site is not found, that could mean that the user passed a site name, not an ID
455
+ }
456
+ }
434
457
  // ==================================================
435
458
  // Start retrieving the configuration through the
436
459
  // configuration file and the API
@@ -441,20 +464,12 @@ class BaseCommand extends Command {
441
464
  packagePath: this.workspacePackage,
442
465
  // The config flag needs to be resolved from the actual process working directory
443
466
  configFilePath: packageConfig,
444
- state,
445
467
  token,
446
468
  ...apiUrlOpts,
447
469
  });
448
470
  const { buildDir, config, configPath, env, repositoryRoot, siteInfo } = cachedConfig;
449
471
  env.NETLIFY_CLI_VERSION = { sources: ['internal'], value: version };
450
472
  const normalizedConfig = normalizeConfig(config);
451
- const agent = await getAgent({
452
- httpProxy: flags.httpProxy,
453
- certificateFile: flags.httpProxyCertificateFilename,
454
- });
455
- const apiOpts = { ...apiUrlOpts, agent };
456
- // TODO: remove typecast once we have proper types for the API
457
- const api = new NetlifyAPI(token || '', apiOpts);
458
473
  // If a user passes a site name as an option instead of a site ID to options.site, the siteInfo object
459
474
  // will only have the property siteInfo.id. Checking for one of the other properties ensures that we can do
460
475
  // a re-call of the api.getSite() that is done in @netlify/config so we have the proper site object in all
@@ -531,7 +546,7 @@ class BaseCommand extends Command {
531
546
  cwd: config.cwd,
532
547
  context: flags.context || process.env.CONTEXT || this.getDefaultContext(),
533
548
  debug: flags.debug,
534
- siteId: flags.siteId || (typeof flags.site === 'string' && flags.site) || config.state.get('siteId'),
549
+ siteId: this.siteId,
535
550
  token: config.token,
536
551
  mode: 'cli',
537
552
  host: config.host,
@@ -539,6 +554,7 @@ class BaseCommand extends Command {
539
554
  scheme: config.scheme,
540
555
  offline: config.offline ?? flags.offline,
541
556
  siteFeatureFlagPrefix: 'cli',
557
+ featureFlags: this.featureFlags,
542
558
  });
543
559
  }
544
560
  catch (error_) {
@@ -164,7 +164,6 @@ export const dev = async (options, command) => {
164
164
  const { config: newConfig } = await command.getConfig({
165
165
  cwd: command.workingDir,
166
166
  offline: true,
167
- state,
168
167
  });
169
168
  const normalizedNewConfig = normalizeConfig(newConfig);
170
169
  return normalizedNewConfig;
@@ -172,6 +171,7 @@ export const dev = async (options, command) => {
172
171
  const inspectSettings = generateInspectSettings(options.edgeInspect, options.edgeInspectBrk);
173
172
  await startProxyServer({
174
173
  addonsUrls,
174
+ api,
175
175
  blobsContext,
176
176
  command,
177
177
  config: mutatedConfig,
@@ -109,7 +109,7 @@ export const serve = async (options, command) => {
109
109
  }
110
110
  // TODO: We should consolidate this with the existing config watcher.
111
111
  const getUpdatedConfig = async () => {
112
- const { config: newConfig } = await command.getConfig({ cwd: command.workingDir, offline: true, state });
112
+ const { config: newConfig } = await command.getConfig({ cwd: command.workingDir, offline: true });
113
113
  const normalizedNewConfig = normalizeConfig(newConfig);
114
114
  return normalizedNewConfig;
115
115
  };