Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(gatsby): load config and plugins in worker #31773

Merged
merged 9 commits into from
Jun 10, 2021

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Jun 4, 2021

Description

This PR allows worker process to load gatsby-config and therefore also execute node APIs

[ch32027]

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 4, 2021
@pieh pieh added status: blocked This issue/PR can't be solved at the moment and shouldn't be closed/merged and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jun 4, 2021
@pieh pieh force-pushed the pieh/load-config-in-worker branch from 1fa55f5 to 6f1b0df Compare June 4, 2021 15:21
@pieh pieh changed the title refactor(gatsby): single function to load config and plugins refactor(gatsby): load config and plugins in worker Jun 5, 2021
@@ -71,9 +71,9 @@ export function resolvePlugin(
rootDir = (!_.isString(plugin) && plugin.parentDir) || rootDir

// Only find plugins when we're not given an absolute path
if (!existsSync(pluginName)) {
if (!existsSync(pluginName) && rootDir) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to appease TS as rootDir can be undefined - this need some verification if it will do what is expected tho before this PR is ready

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my testing it seems correct, but will leave this unresolved for now

@pieh pieh force-pushed the pieh/load-config-in-worker branch 2 times, most recently from 416b86c to 86eda16 Compare June 8, 2021 08:20
@pieh pieh changed the base branch from pieh/worker-tests to pieh/reporter-in-worker-doesnt-crash June 8, 2021 08:20
@pieh pieh force-pushed the pieh/reporter-in-worker-doesnt-crash branch from 13a4be3 to c699a8f Compare June 8, 2021 08:36
@pieh pieh force-pushed the pieh/load-config-in-worker branch from 86eda16 to 091592f Compare June 8, 2021 08:36
Comment on lines +112 to +124
if (frame.getFileName().includes(`webpack:`)) {
// if source-map-register is initiated, stack traces would already be converted
return {
column: frame.getColumnNumber() - 1,
line: frame.getLineNumber(),
source: frame
.getFileName()
.substr(frame.getFileName().indexOf(`webpack:`))
.replace(/webpack:\/+/g, `webpack://`),
name: null,
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is interesting - once we import (directly or indirectly) gatsby-telemetry in worker, stack traces are different (due to @turist/fetch installing source map handler that map stack traces to source files). This just adjust stack traces produced this way so they are still compatible with our codeframe printer for html generation errors

@pieh pieh force-pushed the pieh/reporter-in-worker-doesnt-crash branch from c699a8f to 52157ae Compare June 8, 2021 14:23
@pieh pieh force-pushed the pieh/load-config-in-worker branch from 091592f to ef9c739 Compare June 8, 2021 14:24
Base automatically changed from pieh/reporter-in-worker-doesnt-crash to master June 8, 2021 15:07
@pieh pieh force-pushed the pieh/load-config-in-worker branch from ef9c739 to ce916eb Compare June 8, 2021 15:09
@pieh pieh removed the status: blocked This issue/PR can't be solved at the moment and shouldn't be closed/merged label Jun 8, 2021
@pieh pieh marked this pull request as ready for review June 8, 2021 15:10
Comment on lines +15 to +17
logs.should.contain(
`success open and validate gatsby-configs, load plugins`
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged 2 activities together as loading config and plugins really seem like single step (and it was just cleaner code-wise after putting it in single function to be executed by worker) - can backtrack from it to go back to current 2 steps (or maybe just figure out better label than currently used one for merged activity)

Copy link
Contributor

@LekoArts LekoArts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

siteDirectory: string
processFlags: boolean
}): Promise<{
config: any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can't type config at the moment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could, but requires more effort that is "tangential" to this PR (IMO) - it's any currently in master branch too ( configModule type in

export async function getConfigFile(
rootDir: string,
configName: string,
distance: number = 3
): Promise<{
configModule: any
configFilePath: string
}> {
)

We do have config type for what we store in redux -

export interface IGatsbyConfig {
plugins?: Array<{
// This is the name of the plugin like `gatsby-plugin-manifest
resolve: string
options: {
[key: string]: unknown
}
}>
siteMetadata?: {
title?: string
author?: string
description?: string
siteUrl?: string
// siteMetadata is free form
[key: string]: unknown
}
// @deprecated
polyfill?: boolean
developMiddleware?: any
proxy?: any
pathPrefix?: string
mapping?: Record<string, string>
}

but this doesn't contain for example flags (I did look to have it type briefly, but saw there is lot of unrelated things to handle, so decided to not pursue it for this PR)

@pieh pieh merged commit 81458a0 into master Jun 10, 2021
@pieh pieh deleted the pieh/load-config-in-worker branch June 10, 2021 08:22
pieh added a commit that referenced this pull request Jun 10, 2021
* refactor(gatsby): single function to load config and plugins

* expose loadConfigAndPlugins function in worker

* don't rely on cwd when loading plugins

* add test veryfing config can be loaded and APIs executed in worker

* adjust cli integration tests to cover for activity change (merging loading config and plugins

* fix functions (flag need to be handled before plugins loading)

* fix build error stack traces when ... gatsby-telemetry is imported in worker

* satisfy ts

* ensure double slashes (?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants