diff --git a/integration-tests/gatsby-cli/__tests__/build.js b/integration-tests/gatsby-cli/__tests__/build.js index e31a54dee070a..f1a0a648df841 100644 --- a/integration-tests/gatsby-cli/__tests__/build.js +++ b/integration-tests/gatsby-cli/__tests__/build.js @@ -12,9 +12,8 @@ describe(`gatsby build`, () => { it(`creates a built gatsby site`, () => { const [code, logs] = GatsbyCLI.from(cwd).invoke(`build`) - logs.should.contain( - `success open and validate gatsby-configs, load plugins` - ) + logs.should.contain(`success load gatsby config`) + logs.should.contain(`success load plugins`) logs.should.contain(`success onPreInit`) logs.should.contain(`success initialize cache`) logs.should.contain(`success copy gatsby files`) diff --git a/integration-tests/gatsby-cli/__tests__/develop.js b/integration-tests/gatsby-cli/__tests__/develop.js index db41335abe2f7..591b83aabb577 100644 --- a/integration-tests/gatsby-cli/__tests__/develop.js +++ b/integration-tests/gatsby-cli/__tests__/develop.js @@ -26,9 +26,8 @@ describe(`gatsby develop`, () => { // 3. Make sure logs for the user contain expected results const logs = getLogs() - logs.should.contain( - `success open and validate gatsby-configs, load plugins` - ) + logs.should.contain(`success load gatsby config`) + logs.should.contain(`success load plugins`) logs.should.contain(`success onPreInit`) logs.should.contain(`success initialize cache`) logs.should.contain(`success copy gatsby files`) diff --git a/integration-tests/gatsby-cli/__tests__/repl.js b/integration-tests/gatsby-cli/__tests__/repl.js index 9eec28120ea7f..55ff0a8dfc0ad 100644 --- a/integration-tests/gatsby-cli/__tests__/repl.js +++ b/integration-tests/gatsby-cli/__tests__/repl.js @@ -21,9 +21,8 @@ describe(`gatsby repl`, () => { // 3. Make assertions const logs = getLogs() - logs.should.contain( - `success open and validate gatsby-configs, load plugins` - ) + logs.should.contain(`success load gatsby config`) + logs.should.contain(`success load plugins`) logs.should.contain(`success onPreInit`) logs.should.contain(`success initialize cache`) logs.should.contain(`success copy gatsby files`) diff --git a/packages/gatsby/src/bootstrap/load-config-and-plugins.ts b/packages/gatsby/src/bootstrap/load-config/index.ts similarity index 73% rename from packages/gatsby/src/bootstrap/load-config-and-plugins.ts rename to packages/gatsby/src/bootstrap/load-config/index.ts index 51dc308bb1992..baf6eef4b61fc 100644 --- a/packages/gatsby/src/bootstrap/load-config-and-plugins.ts +++ b/packages/gatsby/src/bootstrap/load-config/index.ts @@ -1,19 +1,15 @@ import reporter from "gatsby-cli/lib/reporter" import telemetry from "gatsby-telemetry" +import { preferDefault } from "../prefer-default" +import { getConfigFile } from "../get-config-file" +import { internalActions } from "../../redux/actions" +import loadThemes from "../load-themes" +import { store } from "../../redux" +import handleFlags from "../../utils/handle-flags" +import availableFlags from "../../utils/flags" +import { IProgram } from "../../commands/types" -import { IFlattenedPlugin } from "./load-plugins/types" - -import { preferDefault } from "../bootstrap/prefer-default" -import { getConfigFile } from "../bootstrap/get-config-file" -import { loadPlugins } from "../bootstrap/load-plugins" -import { internalActions } from "../redux/actions" -import loadThemes from "../bootstrap/load-themes" -import { store } from "../redux" -import handleFlags from "../utils/handle-flags" -import availableFlags from "../utils/flags" -import { IProgram } from "../commands/types" - -export async function loadConfigAndPlugins({ +export async function loadConfig({ siteDirectory, processFlags = false, }: { @@ -22,7 +18,6 @@ export async function loadConfigAndPlugins({ program?: IProgram }): Promise<{ config: any - flattenedPlugins: Array }> { // Try opening the site's gatsby-config.js file. const { configModule, configFilePath } = await getConfigFile( @@ -94,7 +89,5 @@ export async function loadConfigAndPlugins({ store.dispatch(internalActions.setSiteConfig(config)) - const flattenedPlugins = await loadPlugins(config, siteDirectory) - - return { config, flattenedPlugins } + return { config } } diff --git a/packages/gatsby/src/services/initialize.ts b/packages/gatsby/src/services/initialize.ts index d0e3da2c6de7a..71594ae6507b4 100644 --- a/packages/gatsby/src/services/initialize.ts +++ b/packages/gatsby/src/services/initialize.ts @@ -19,7 +19,8 @@ import { IPluginInfoOptions } from "../bootstrap/load-plugins/types" import { IGatsbyState, IStateProgram } from "../redux/types" import { IBuildContext } from "./types" import { detectLmdbStore } from "../datastore" -import { loadConfigAndPlugins } from "../bootstrap/load-config-and-plugins" +import { loadConfig } from "../bootstrap/load-config" +import { loadPlugins } from "../bootstrap/load-plugins" import type { InternalJob } from "../utils/jobs/types" import { enableNodeMutationsDetection } from "../utils/detect-node-mutations" import { resolveModule } from "../utils/module-resolver" @@ -160,20 +161,27 @@ export async function initialize({ emitter.on(`END_JOB`, onEndJob) - // Try opening the site's gatsby-config.js file. - let activity = reporter.activityTimer( - `open and validate gatsby-configs, load plugins`, - { - parentSpan, - } - ) + // Load gatsby config + let activity = reporter.activityTimer(`load gatsby config`, { + parentSpan, + }) activity.start() - const { config, flattenedPlugins } = await loadConfigAndPlugins({ - siteDirectory: program.directory, + const siteDirectory = program.directory + const { config } = await loadConfig({ + siteDirectory, processFlags: true, }) + activity.end() + + // Load plugins + activity = reporter.activityTimer(`load plugins`, { + parentSpan, + }) + const flattenedPlugins = await loadPlugins(config, siteDirectory) + activity.end() + // TODO: figure out proper way of disabling loading indicator // for now GATSBY_QUERY_ON_DEMAND_LOADING_INDICATOR=false gatsby develop // will work, but we don't want to force users into using env vars @@ -197,8 +205,6 @@ export async function initialize({ ) } - activity.end() - if (process.env.GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND) { if (process.env.gatsby_executing_command !== `develop`) { // we don't want to ever have this flag enabled for anything than develop diff --git a/packages/gatsby/src/utils/worker/__tests__/queries.ts b/packages/gatsby/src/utils/worker/__tests__/queries.ts index 961fb82c945cb..a9d92ad9cb5b3 100644 --- a/packages/gatsby/src/utils/worker/__tests__/queries.ts +++ b/packages/gatsby/src/utils/worker/__tests__/queries.ts @@ -10,7 +10,8 @@ import { emitter, loadPartialStateFromDisk, } from "../../../redux" -import { loadConfigAndPlugins } from "../../../bootstrap/load-config-and-plugins" +import { loadConfig } from "../../../bootstrap/load-config" +import { loadPlugins } from "../../../bootstrap/load-plugins" import { createTestWorker, describeWhenLMDB, @@ -124,7 +125,10 @@ describeWhenLMDB(`worker (queries)`, () => { worker = createTestWorker() const siteDirectory = path.join(__dirname, `fixtures`, `sample-site`) - await loadConfigAndPlugins({ siteDirectory }) + const { config } = await loadConfig({ + siteDirectory, + }) + await loadPlugins(config, siteDirectory) await Promise.all(worker.all.loadConfigAndPlugins({ siteDirectory })) await sourceNodesAndRemoveStaleNodes({ webhookBody: {} }) await getDataStore().ready() diff --git a/packages/gatsby/src/utils/worker/__tests__/schema.ts b/packages/gatsby/src/utils/worker/__tests__/schema.ts index 33e42dc742ae5..2025f08d36cec 100644 --- a/packages/gatsby/src/utils/worker/__tests__/schema.ts +++ b/packages/gatsby/src/utils/worker/__tests__/schema.ts @@ -6,7 +6,8 @@ import { CombinedState } from "redux" import { build } from "../../../schema" import sourceNodesAndRemoveStaleNodes from "../../source-nodes" import { savePartialStateToDisk, store } from "../../../redux" -import { loadConfigAndPlugins } from "../../../bootstrap/load-config-and-plugins" +import { loadConfig } from "../../../bootstrap/load-config" +import { loadPlugins } from "../../../bootstrap/load-plugins" import { createTestWorker, describeWhenLMDB, @@ -56,7 +57,10 @@ describeWhenLMDB(`worker (schema)`, () => { worker = createTestWorker() const siteDirectory = path.join(__dirname, `fixtures`, `sample-site`) - await loadConfigAndPlugins({ siteDirectory }) + const { config } = await loadConfig({ + siteDirectory, + }) + await loadPlugins(config, siteDirectory) await Promise.all(worker.all.loadConfigAndPlugins({ siteDirectory })) await sourceNodesAndRemoveStaleNodes({ webhookBody: {} }) await getDataStore().ready() diff --git a/packages/gatsby/src/utils/worker/child/load-config-and-plugins.ts b/packages/gatsby/src/utils/worker/child/load-config-and-plugins.ts index 7af88996f8fed..afbd24a41c3aa 100644 --- a/packages/gatsby/src/utils/worker/child/load-config-and-plugins.ts +++ b/packages/gatsby/src/utils/worker/child/load-config-and-plugins.ts @@ -1,9 +1,10 @@ -import { loadConfigAndPlugins as internalLoadConfigAndPlugins } from "../../../bootstrap/load-config-and-plugins" +import { loadConfig } from "../../../bootstrap/load-config" +import { loadPlugins } from "../../../bootstrap/load-plugins" import { store } from "../../../redux" import apiRunnerNode from "../../api-runner-node" export async function loadConfigAndPlugins( - ...args: Parameters + ...args: Parameters ): Promise { const [{ siteDirectory, program }] = args @@ -14,7 +15,8 @@ export async function loadConfigAndPlugins( directory: siteDirectory, }, }) - await internalLoadConfigAndPlugins(...args) + const { config } = await loadConfig(...args) + await loadPlugins(config, siteDirectory) // Cache is already initialized if (_CFLAGS_.GATSBY_MAJOR === `4`) {