-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Conversation
1fa55f5
to
6f1b0df
Compare
@@ -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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
416b86c
to
86eda16
Compare
13a4be3
to
c699a8f
Compare
86eda16
to
091592f
Compare
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, | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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
c699a8f
to
52157ae
Compare
091592f
to
ef9c739
Compare
…ading config and plugins
ef9c739
to
ce916eb
Compare
logs.should.contain( | ||
`success open and validate gatsby-configs, load plugins` | ||
) |
There was a problem hiding this comment.
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)
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
gatsby/packages/gatsby/src/bootstrap/get-config-file.ts
Lines 17 to 24 in db946a5
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 -
gatsby/packages/gatsby/src/redux/types.ts
Lines 60 to 82 in db946a5
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)
* 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 (?)
Description
This PR allows worker process to load
gatsby-config
and therefore also execute node APIs[ch32027]