gatsby 4.25.1 → 4.25.2
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.
- package/dist/bootstrap/load-config/index.js +2 -2
- package/dist/bootstrap/load-config/index.js.map +1 -1
- package/dist/bootstrap/load-plugins/load-internal-plugins.js +6 -1
- package/dist/bootstrap/load-plugins/load-internal-plugins.js.map +1 -1
- package/dist/bootstrap/load-themes/index.d.ts +17 -0
- package/dist/bootstrap/load-themes/index.js +58 -41
- package/dist/bootstrap/load-themes/index.js.map +1 -1
- package/dist/schema/graphql-engine/entry.js +20 -8
- package/dist/schema/graphql-engine/entry.js.map +1 -1
- package/dist/schema/graphql-engine/print-plugins.js +11 -11
- package/dist/schema/graphql-engine/print-plugins.js.map +1 -1
- package/dist/schema/graphql-engine/standalone-regenerate.js +2 -1
- package/dist/schema/graphql-engine/standalone-regenerate.js.map +1 -1
- package/dist/utils/merge-gatsby-config.d.ts +5 -4
- package/dist/utils/merge-gatsby-config.js +1 -26
- package/dist/utils/merge-gatsby-config.js.map +1 -1
- package/dist/utils/require-gatsby-plugin.d.ts +2 -0
- package/dist/utils/require-gatsby-plugin.js +7 -1
- package/dist/utils/require-gatsby-plugin.js.map +1 -1
- package/package.json +3 -3
|
@@ -15,7 +15,7 @@ var _getConfigFile = require("../get-config-file");
|
|
|
15
15
|
|
|
16
16
|
var _actions = require("../../redux/actions");
|
|
17
17
|
|
|
18
|
-
var _loadThemes =
|
|
18
|
+
var _loadThemes = require("../load-themes");
|
|
19
19
|
|
|
20
20
|
var _redux = require("../../redux");
|
|
21
21
|
|
|
@@ -87,7 +87,7 @@ async function loadConfig({
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
if (config) {
|
|
90
|
-
const plugins = await (0, _loadThemes.
|
|
90
|
+
const plugins = await (0, _loadThemes.loadThemes)(config, {
|
|
91
91
|
configFilePath,
|
|
92
92
|
rootDir: siteDirectory
|
|
93
93
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["loadConfig","siteDirectory","processFlags","configModule","configFilePath","getConfigFile","config","preferDefault","reporter","panic","id","context","configName","enabledConfigFlags","unknownFlagMessage","unfitFlagMessage","message","handleFlags","availableFlags","flags","warn","forEach","flag","process","env","info","telemetryId","telemetry","trackFeatureIsUsed","plugins","loadThemes","rootDir","store","dispatch","internalActions","setSiteConfig"],"sources":["../../../src/bootstrap/load-config/index.ts"],"sourcesContent":["import reporter from \"gatsby-cli/lib/reporter\"\nimport telemetry from \"gatsby-telemetry\"\nimport { preferDefault } from \"../prefer-default\"\nimport { getConfigFile } from \"../get-config-file\"\nimport { internalActions } from \"../../redux/actions\"\nimport loadThemes from \"../load-themes\"\nimport { store } from \"../../redux\"\nimport handleFlags from \"../../utils/handle-flags\"\nimport availableFlags from \"../../utils/flags\"\nimport { IProgram } from \"../../commands/types\"\nimport { IGatsbyConfig } from \"../../internal\"\n\nexport async function loadConfig({\n siteDirectory,\n processFlags = false,\n}: {\n siteDirectory: string\n processFlags?: boolean\n program?: IProgram\n}): Promise<IGatsbyConfig> {\n // Try opening the site's gatsby-config.js file.\n const { configModule, configFilePath } = await getConfigFile(\n siteDirectory,\n `gatsby-config`\n )\n let config = preferDefault(configModule)\n\n // The root config cannot be exported as a function, only theme configs\n if (typeof config === `function`) {\n reporter.panic({\n id: `10126`,\n context: {\n configName: `gatsby-config`,\n siteDirectory,\n },\n })\n }\n\n if (config && processFlags) {\n // Setup flags\n if (config) {\n // Get flags\n const {\n enabledConfigFlags,\n unknownFlagMessage,\n unfitFlagMessage,\n message,\n } = handleFlags(availableFlags, config.flags)\n\n if (unknownFlagMessage !== ``) {\n reporter.warn(unknownFlagMessage)\n }\n if (unfitFlagMessage !== ``) {\n reporter.warn(unfitFlagMessage)\n }\n // set process.env for each flag\n enabledConfigFlags.forEach(flag => {\n process.env[flag.env] = `true`\n })\n\n // Print out message.\n if (message !== ``) {\n reporter.info(message)\n }\n\n // track usage of feature\n enabledConfigFlags.forEach(flag => {\n if (flag.telemetryId) {\n telemetry.trackFeatureIsUsed(flag.telemetryId)\n }\n })\n\n // Track the usage of config.flags\n if (config.flags) {\n telemetry.trackFeatureIsUsed(`ConfigFlags`)\n }\n }\n }\n\n // theme gatsby configs can be functions or objects\n if (config) {\n const plugins = await loadThemes(config, {\n configFilePath,\n rootDir: siteDirectory,\n })\n config = plugins.config\n }\n\n store.dispatch(internalActions.setSiteConfig(config))\n\n return config\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAIO,eAAeA,UAAf,CAA0B;EAC/BC,aAD+B;EAE/BC,YAAY,GAAG;AAFgB,CAA1B,EAOoB;EACzB;EACA,MAAM;IAAEC,YAAF;IAAgBC;EAAhB,IAAmC,MAAM,IAAAC,4BAAA,EAC7CJ,aAD6C,EAE5C,eAF4C,CAA/C;EAIA,IAAIK,MAAM,GAAG,IAAAC,4BAAA,EAAcJ,YAAd,CAAb,CANyB,CAQzB;;EACA,IAAI,OAAOG,MAAP,KAAmB,UAAvB,EAAkC;IAChCE,iBAAA,CAASC,KAAT,CAAe;MACbC,EAAE,EAAG,OADQ;MAEbC,OAAO,EAAE;QACPC,UAAU,EAAG,eADN;QAEPX;MAFO;IAFI,CAAf;EAOD;;EAED,IAAIK,MAAM,IAAIJ,YAAd,EAA4B;IAC1B;IACA,IAAII,MAAJ,EAAY;MACV;MACA,MAAM;QACJO,kBADI;QAEJC,kBAFI;QAGJC,gBAHI;QAIJC;MAJI,IAKF,IAAAC,oBAAA,EAAYC,cAAZ,EAA4BZ,MAAM,CAACa,KAAnC,CALJ;;MAOA,IAAIL,kBAAkB,KAAM,EAA5B,EAA+B;QAC7BN,iBAAA,CAASY,IAAT,CAAcN,kBAAd;MACD;;MACD,IAAIC,gBAAgB,KAAM,EAA1B,EAA6B;QAC3BP,iBAAA,CAASY,IAAT,CAAcL,gBAAd;MACD,CAdS,CAeV;;;MACAF,kBAAkB,CAACQ,OAAnB,CAA2BC,IAAI,IAAI;QACjCC,OAAO,CAACC,GAAR,CAAYF,IAAI,CAACE,GAAjB,IAAyB,MAAzB;MACD,CAFD,EAhBU,CAoBV;;MACA,IAAIR,OAAO,KAAM,EAAjB,EAAoB;QAClBR,iBAAA,CAASiB,IAAT,CAAcT,OAAd;MACD,CAvBS,CAyBV;;;MACAH,kBAAkB,CAACQ,OAAnB,CAA2BC,IAAI,IAAI;QACjC,IAAIA,IAAI,CAACI,WAAT,EAAsB;UACpBC,wBAAA,CAAUC,kBAAV,CAA6BN,IAAI,CAACI,WAAlC;QACD;MACF,CAJD,EA1BU,CAgCV;;MACA,IAAIpB,MAAM,CAACa,KAAX,EAAkB;QAChBQ,wBAAA,CAAUC,kBAAV,CAA8B,aAA9B;MACD;IACF;EACF,CA1DwB,CA4DzB;;;EACA,IAAItB,MAAJ,EAAY;IACV,MAAMuB,OAAO,GAAG,MAAM,IAAAC,
|
|
1
|
+
{"version":3,"file":"index.js","names":["loadConfig","siteDirectory","processFlags","configModule","configFilePath","getConfigFile","config","preferDefault","reporter","panic","id","context","configName","enabledConfigFlags","unknownFlagMessage","unfitFlagMessage","message","handleFlags","availableFlags","flags","warn","forEach","flag","process","env","info","telemetryId","telemetry","trackFeatureIsUsed","plugins","loadThemes","rootDir","store","dispatch","internalActions","setSiteConfig"],"sources":["../../../src/bootstrap/load-config/index.ts"],"sourcesContent":["import reporter from \"gatsby-cli/lib/reporter\"\nimport telemetry from \"gatsby-telemetry\"\nimport { preferDefault } from \"../prefer-default\"\nimport { getConfigFile } from \"../get-config-file\"\nimport { internalActions } from \"../../redux/actions\"\nimport { loadThemes } from \"../load-themes\"\nimport { store } from \"../../redux\"\nimport handleFlags from \"../../utils/handle-flags\"\nimport availableFlags from \"../../utils/flags\"\nimport { IProgram } from \"../../commands/types\"\nimport { IGatsbyConfig } from \"../../internal\"\n\nexport async function loadConfig({\n siteDirectory,\n processFlags = false,\n}: {\n siteDirectory: string\n processFlags?: boolean\n program?: IProgram\n}): Promise<IGatsbyConfig> {\n // Try opening the site's gatsby-config.js file.\n const { configModule, configFilePath } = await getConfigFile(\n siteDirectory,\n `gatsby-config`\n )\n let config = preferDefault(configModule)\n\n // The root config cannot be exported as a function, only theme configs\n if (typeof config === `function`) {\n reporter.panic({\n id: `10126`,\n context: {\n configName: `gatsby-config`,\n siteDirectory,\n },\n })\n }\n\n if (config && processFlags) {\n // Setup flags\n if (config) {\n // Get flags\n const {\n enabledConfigFlags,\n unknownFlagMessage,\n unfitFlagMessage,\n message,\n } = handleFlags(availableFlags, config.flags)\n\n if (unknownFlagMessage !== ``) {\n reporter.warn(unknownFlagMessage)\n }\n if (unfitFlagMessage !== ``) {\n reporter.warn(unfitFlagMessage)\n }\n // set process.env for each flag\n enabledConfigFlags.forEach(flag => {\n process.env[flag.env] = `true`\n })\n\n // Print out message.\n if (message !== ``) {\n reporter.info(message)\n }\n\n // track usage of feature\n enabledConfigFlags.forEach(flag => {\n if (flag.telemetryId) {\n telemetry.trackFeatureIsUsed(flag.telemetryId)\n }\n })\n\n // Track the usage of config.flags\n if (config.flags) {\n telemetry.trackFeatureIsUsed(`ConfigFlags`)\n }\n }\n }\n\n // theme gatsby configs can be functions or objects\n if (config) {\n const plugins = await loadThemes(config, {\n configFilePath,\n rootDir: siteDirectory,\n })\n config = plugins.config\n }\n\n store.dispatch(internalActions.setSiteConfig(config))\n\n return config\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAIO,eAAeA,UAAf,CAA0B;EAC/BC,aAD+B;EAE/BC,YAAY,GAAG;AAFgB,CAA1B,EAOoB;EACzB;EACA,MAAM;IAAEC,YAAF;IAAgBC;EAAhB,IAAmC,MAAM,IAAAC,4BAAA,EAC7CJ,aAD6C,EAE5C,eAF4C,CAA/C;EAIA,IAAIK,MAAM,GAAG,IAAAC,4BAAA,EAAcJ,YAAd,CAAb,CANyB,CAQzB;;EACA,IAAI,O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B;IAF8B,CAAnB,CAAtB;IAIAK,MAAM,GAAGuB,OAAO,CAACvB,MAAjB;EACD;;EAED0B,YAAA,CAAMC,QAAN,CAAeC,wBAAA,CAAgBC,aAAhB,CAA8B7B,MAA9B,CAAf;;EAEA,OAAOA,MAAP;AACD"}
|
|
@@ -5,6 +5,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.loadInternalPlugins = loadInternalPlugins;
|
|
7
7
|
|
|
8
|
+
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
9
|
+
|
|
10
|
+
var _uniqWith2 = _interopRequireDefault(require("lodash/uniqWith"));
|
|
11
|
+
|
|
8
12
|
var _gatsbyCoreUtils = require("gatsby-core-utils");
|
|
9
13
|
|
|
10
14
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -125,6 +129,7 @@ function loadInternalPlugins(config = {}, rootDir) {
|
|
|
125
129
|
// collect scripts that users might inject in their `wrapRootElement`
|
|
126
130
|
|
|
127
131
|
plugins.push((0, _processPlugin.processPlugin)(_path.default.join(__dirname, `../../internal-plugins/partytown`), rootDir));
|
|
128
|
-
|
|
132
|
+
const uniquePlugins = (0, _uniqWith2.default)(plugins, _isEqual2.default);
|
|
133
|
+
return uniquePlugins;
|
|
129
134
|
}
|
|
130
135
|
//# sourceMappingURL=load-internal-plugins.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-internal-plugins.js","names":["TYPESCRIPT_PLUGIN_NAME","loadInternalPlugins","config","rootDir","plugins","configuredPluginNames","Set","internalPlugins","filter","Boolean","forEach","relPath","absPath","path","join","__dirname","push","processPlugin","plugin","processedPlugin","add","name","resolve","require","options","slash","pathCheck","has","GATSBY_CLOUD_PLUGIN_NAME","incompatibleGatsbyCloudPlugin","reporter","panic","process","env","GATSBY_CLOUD","addGatsbyPluginCloudPluginWhenInstalled","GATSBY_PLUGIN_PREVIEW_NAME","addGatsbyPluginPreviewWhenInstalled","processedTypeScriptPlugin","allExtensions","isTSX","jsxPragma","cwd","id","createPluginId","version","createFileContentHash","pluginOptions","getResolvedFieldsForPlugin","program","store","getState","pageCreatorOptions","directory","pageCreatorPlugin","find","processedPageCreatorPlugin"],"sources":["../../../src/bootstrap/load-plugins/load-internal-plugins.ts"],"sourcesContent":["import { slash } from \"gatsby-core-utils\"\nimport path from \"path\"\nimport reporter from \"gatsby-cli/lib/reporter\"\nimport { store } from \"../../redux\"\nimport {\n IPluginInfo,\n IPluginRefObject,\n IPluginRefOptions,\n ISiteConfig,\n} from \"./types\"\nimport { processPlugin } from \"./process-plugin\"\nimport { createPluginId } from \"./utils/create-id\"\nimport { createFileContentHash } from \"./utils/create-hash\"\nimport {\n addGatsbyPluginCloudPluginWhenInstalled,\n addGatsbyPluginPreviewWhenInstalled,\n incompatibleGatsbyCloudPlugin,\n GATSBY_CLOUD_PLUGIN_NAME,\n GATSBY_PLUGIN_PREVIEW_NAME,\n} from \"./utils/handle-gatsby-cloud\"\nimport { getResolvedFieldsForPlugin } from \"../../utils/parcel/compile-gatsby-files\"\n\nconst TYPESCRIPT_PLUGIN_NAME = `gatsby-plugin-typescript`\n\nexport function loadInternalPlugins(\n config: ISiteConfig = {},\n rootDir: string\n): Array<IPluginInfo> {\n // Instantiate plugins.\n const plugins: Array<IPluginInfo> = []\n const configuredPluginNames = new Set()\n\n // Add internal plugins\n const internalPlugins = [\n `../../internal-plugins/dev-404-page`,\n `../../internal-plugins/load-babel-config`,\n `../../internal-plugins/internal-data-bridge`,\n `../../internal-plugins/prod-404-500`,\n `../../internal-plugins/webpack-theme-component-shadowing`,\n `../../internal-plugins/bundle-optimisations`,\n `../../internal-plugins/functions`,\n ].filter(Boolean) as Array<string>\n\n internalPlugins.forEach(relPath => {\n const absPath = path.join(__dirname, relPath)\n plugins.push(processPlugin(absPath, rootDir))\n })\n\n // Add plugins from the site config.\n if (config.plugins) {\n config.plugins.forEach(plugin => {\n const processedPlugin = processPlugin(plugin, rootDir)\n plugins.push(processedPlugin)\n configuredPluginNames.add(processedPlugin.name)\n })\n }\n\n // the order of all of these page-creators matters. The \"last plugin wins\",\n // so the user's site comes last, and each page-creator instance has to\n // match the plugin definition order before that. This works fine for themes\n // because themes have already been added in the proper order to the plugins\n // array\n plugins.forEach(plugin => {\n plugins.push(\n processPlugin(\n {\n resolve: require.resolve(`gatsby-plugin-page-creator`),\n options: {\n path: slash(path.join(plugin.resolve, `src/pages`)),\n pathCheck: false,\n },\n },\n rootDir\n )\n )\n })\n\n if (\n configuredPluginNames.has(GATSBY_CLOUD_PLUGIN_NAME) &&\n incompatibleGatsbyCloudPlugin(plugins)\n ) {\n reporter.panic(\n `Plugin gatsby-plugin-gatsby-cloud is not compatible with your gatsby version. Please upgrade to gatsby-plugin-gatsby-cloud@next`\n )\n }\n\n if (\n !configuredPluginNames.has(GATSBY_CLOUD_PLUGIN_NAME) &&\n (process.env.GATSBY_CLOUD === `true` || process.env.GATSBY_CLOUD === `1`)\n ) {\n addGatsbyPluginCloudPluginWhenInstalled(plugins, rootDir)\n }\n\n if (\n !configuredPluginNames.has(GATSBY_PLUGIN_PREVIEW_NAME) &&\n (process.env.GATSBY_CLOUD === `true` || process.env.GATSBY_CLOUD === `1`)\n ) {\n addGatsbyPluginPreviewWhenInstalled(plugins, rootDir)\n }\n\n // Support Typescript by default but allow users to override it\n if (!configuredPluginNames.has(TYPESCRIPT_PLUGIN_NAME)) {\n const processedTypeScriptPlugin = processPlugin(\n {\n resolve: require.resolve(TYPESCRIPT_PLUGIN_NAME),\n options: {\n // TODO(@mxstbr): Do not hard-code these defaults but infer them from the\n // pluginOptionsSchema of gatsby-plugin-typescript\n allExtensions: false,\n isTSX: false,\n jsxPragma: `React`,\n },\n },\n rootDir\n )\n plugins.push(processedTypeScriptPlugin)\n }\n\n // Add the site's default \"plugin\" i.e. gatsby-x files in root of site.\n plugins.push({\n resolve: slash(process.cwd()),\n id: createPluginId(`default-site-plugin`),\n name: `default-site-plugin`,\n version: createFileContentHash(process.cwd(), `gatsby-*`),\n pluginOptions: {\n plugins: [],\n },\n ...getResolvedFieldsForPlugin(rootDir, `default-site-plugin`),\n })\n\n const program = store.getState().program\n\n // default options for gatsby-plugin-page-creator\n let pageCreatorOptions: IPluginRefOptions | undefined = {\n path: slash(path.join(program.directory, `src/pages`)),\n pathCheck: false,\n }\n\n if (config.plugins) {\n const pageCreatorPlugin = config.plugins.find(\n (plugin): plugin is IPluginRefObject =>\n typeof plugin !== `string` &&\n plugin.resolve === `gatsby-plugin-page-creator` &&\n slash((plugin.options && plugin.options.path) || ``) ===\n slash(path.join(program.directory, `src/pages`))\n )\n if (pageCreatorPlugin) {\n // override the options if there are any user specified options\n pageCreatorOptions = pageCreatorPlugin.options\n }\n }\n\n const processedPageCreatorPlugin = processPlugin(\n {\n resolve: require.resolve(`gatsby-plugin-page-creator`),\n options: pageCreatorOptions,\n },\n rootDir\n )\n\n plugins.push(processedPageCreatorPlugin)\n\n // Partytown plugin collects usage of <Script strategy={\"off-main-thread\"} />\n // in `wrapRootElement`, so we have to make sure it's the last one running to be able to\n // collect scripts that users might inject in their `wrapRootElement`\n plugins.push(\n processPlugin(\n path.join(__dirname, `../../internal-plugins/partytown`),\n rootDir\n )\n )\n\n return plugins\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAOA;;AACA;;AACA;;AACA;;AAOA;;AAEA,MAAMA,sBAAsB,GAAI,0BAAhC;;AAEO,SAASC,mBAAT,CACLC,MAAmB,GAAG,EADjB,EAELC,OAFK,EAGe;EACpB;EACA,MAAMC,OAA2B,GAAG,EAApC;EACA,MAAMC,qBAAqB,GAAG,IAAIC,GAAJ,EAA9B,CAHoB,CAKpB;;EACA,MAAMC,eAAe,GAAG,CACrB,qCADqB,EAErB,0CAFqB,EAGrB,6CAHqB,EAIrB,qCAJqB,EAKrB,0DALqB,EAMrB,6CANqB,EAOrB,kCAPqB,EAQtBC,MARsB,CAQfC,OARe,C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IAAAY,sBAAA,EAAMZ,aAAA,CAAKC,IAAL,CAAUmC,OAAO,CAACI,SAAlB,EAA8B,WAA9B,CAAN,CADgD;IAEtD3B,SAAS,EAAE;EAF2C,CAAxD;;EAKA,IAAIxB,MAAM,CAACE,OAAX,EAAoB;IAClB,MAAMkD,iBAAiB,GAAGpD,MAAM,CAACE,OAAP,CAAemD,IAAf,CACvBrC,MAAD,IACE,OAAOA,MAAP,KAAmB,QAAnB,IACAA,MAAM,CAACI,OAAP,KAAoB,4BADpB,IAEA,IAAAG,sBAAA,EAAOP,MAAM,CAACM,OAAP,IAAkBN,MAAM,CAACM,OAAP,CAAeX,IAAlC,IAA4C,EAAlD,MACE,IAAAY,sBAAA,EAAMZ,aAAA,CAAKC,IAAL,CAAUmC,OAAO,CAACI,SAAlB,EAA8B,WAA9B,CAAN,CALoB,CAA1B;;IAOA,IAAIC,iBAAJ,EAAuB;MACrB;MACAF,kBAAkB,GAAGE,iBAAiB,CAAC9B,OAAvC;IACD;EACF;;EAED,MAAMgC,0BAA0B,GAAG,IAAAvC,4BAAA,EACjC;IACEK,OAAO,EAAEC,OAAO,CAACD,OAAR,CAAiB,4BAAjB,CADX;IAEEE,OAAO,EAAE4B;EAFX,CADiC,EAKjCjD,OALiC,CAAnC;EAQAC,OAAO,CAACY,IAAR,CAAawC,0BAAb,EArIoB,CAuIpB;EACA;EACA;;EACApD,OAAO,CAACY,IAAR,CACE,IAAAC,4BAAA,EACEJ,aAAA,CAAKC,IAAL,CAAUC,SAAV,EAAsB,kCAAtB,CADF,EAEEZ,OAFF,CADF;EAOA,OAAOC,OAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"load-internal-plugins.js","names":["TYPESCRIPT_PLUGIN_NAME","loadInternalPlugins","config","rootDir","plugins","configuredPluginNames","Set","internalPlugins","filter","Boolean","forEach","relPath","absPath","path","join","__dirname","push","processPlugin","plugin","processedPlugin","add","name","resolve","require","options","slash","pathCheck","has","GATSBY_CLOUD_PLUGIN_NAME","incompatibleGatsbyCloudPlugin","reporter","panic","process","env","GATSBY_CLOUD","addGatsbyPluginCloudPluginWhenInstalled","GATSBY_PLUGIN_PREVIEW_NAME","addGatsbyPluginPreviewWhenInstalled","processedTypeScriptPlugin","allExtensions","isTSX","jsxPragma","cwd","id","createPluginId","version","createFileContentHash","pluginOptions","getResolvedFieldsForPlugin","program","store","getState","pageCreatorOptions","directory","pageCreatorPlugin","find","processedPageCreatorPlugin","uniquePlugins"],"sources":["../../../src/bootstrap/load-plugins/load-internal-plugins.ts"],"sourcesContent":["import { slash } from \"gatsby-core-utils\"\nimport { uniqWith, isEqual } from \"lodash\"\nimport path from \"path\"\nimport reporter from \"gatsby-cli/lib/reporter\"\nimport { store } from \"../../redux\"\nimport {\n IPluginInfo,\n IPluginRefObject,\n IPluginRefOptions,\n ISiteConfig,\n} from \"./types\"\nimport { processPlugin } from \"./process-plugin\"\nimport { createPluginId } from \"./utils/create-id\"\nimport { createFileContentHash } from \"./utils/create-hash\"\nimport {\n addGatsbyPluginCloudPluginWhenInstalled,\n addGatsbyPluginPreviewWhenInstalled,\n incompatibleGatsbyCloudPlugin,\n GATSBY_CLOUD_PLUGIN_NAME,\n GATSBY_PLUGIN_PREVIEW_NAME,\n} from \"./utils/handle-gatsby-cloud\"\nimport { getResolvedFieldsForPlugin } from \"../../utils/parcel/compile-gatsby-files\"\n\nconst TYPESCRIPT_PLUGIN_NAME = `gatsby-plugin-typescript`\n\nexport function loadInternalPlugins(\n config: ISiteConfig = {},\n rootDir: string\n): Array<IPluginInfo> {\n // Instantiate plugins.\n const plugins: Array<IPluginInfo> = []\n const configuredPluginNames = new Set()\n\n // Add internal plugins\n const internalPlugins = [\n `../../internal-plugins/dev-404-page`,\n `../../internal-plugins/load-babel-config`,\n `../../internal-plugins/internal-data-bridge`,\n `../../internal-plugins/prod-404-500`,\n `../../internal-plugins/webpack-theme-component-shadowing`,\n `../../internal-plugins/bundle-optimisations`,\n `../../internal-plugins/functions`,\n ].filter(Boolean) as Array<string>\n\n internalPlugins.forEach(relPath => {\n const absPath = path.join(__dirname, relPath)\n plugins.push(processPlugin(absPath, rootDir))\n })\n\n // Add plugins from the site config.\n if (config.plugins) {\n config.plugins.forEach(plugin => {\n const processedPlugin = processPlugin(plugin, rootDir)\n plugins.push(processedPlugin)\n configuredPluginNames.add(processedPlugin.name)\n })\n }\n\n // the order of all of these page-creators matters. The \"last plugin wins\",\n // so the user's site comes last, and each page-creator instance has to\n // match the plugin definition order before that. This works fine for themes\n // because themes have already been added in the proper order to the plugins\n // array\n plugins.forEach(plugin => {\n plugins.push(\n processPlugin(\n {\n resolve: require.resolve(`gatsby-plugin-page-creator`),\n options: {\n path: slash(path.join(plugin.resolve, `src/pages`)),\n pathCheck: false,\n },\n },\n rootDir\n )\n )\n })\n\n if (\n configuredPluginNames.has(GATSBY_CLOUD_PLUGIN_NAME) &&\n incompatibleGatsbyCloudPlugin(plugins)\n ) {\n reporter.panic(\n `Plugin gatsby-plugin-gatsby-cloud is not compatible with your gatsby version. Please upgrade to gatsby-plugin-gatsby-cloud@next`\n )\n }\n\n if (\n !configuredPluginNames.has(GATSBY_CLOUD_PLUGIN_NAME) &&\n (process.env.GATSBY_CLOUD === `true` || process.env.GATSBY_CLOUD === `1`)\n ) {\n addGatsbyPluginCloudPluginWhenInstalled(plugins, rootDir)\n }\n\n if (\n !configuredPluginNames.has(GATSBY_PLUGIN_PREVIEW_NAME) &&\n (process.env.GATSBY_CLOUD === `true` || process.env.GATSBY_CLOUD === `1`)\n ) {\n addGatsbyPluginPreviewWhenInstalled(plugins, rootDir)\n }\n\n // Support Typescript by default but allow users to override it\n if (!configuredPluginNames.has(TYPESCRIPT_PLUGIN_NAME)) {\n const processedTypeScriptPlugin = processPlugin(\n {\n resolve: require.resolve(TYPESCRIPT_PLUGIN_NAME),\n options: {\n // TODO(@mxstbr): Do not hard-code these defaults but infer them from the\n // pluginOptionsSchema of gatsby-plugin-typescript\n allExtensions: false,\n isTSX: false,\n jsxPragma: `React`,\n },\n },\n rootDir\n )\n plugins.push(processedTypeScriptPlugin)\n }\n\n // Add the site's default \"plugin\" i.e. gatsby-x files in root of site.\n plugins.push({\n resolve: slash(process.cwd()),\n id: createPluginId(`default-site-plugin`),\n name: `default-site-plugin`,\n version: createFileContentHash(process.cwd(), `gatsby-*`),\n pluginOptions: {\n plugins: [],\n },\n ...getResolvedFieldsForPlugin(rootDir, `default-site-plugin`),\n })\n\n const program = store.getState().program\n\n // default options for gatsby-plugin-page-creator\n let pageCreatorOptions: IPluginRefOptions | undefined = {\n path: slash(path.join(program.directory, `src/pages`)),\n pathCheck: false,\n }\n\n if (config.plugins) {\n const pageCreatorPlugin = config.plugins.find(\n (plugin): plugin is IPluginRefObject =>\n typeof plugin !== `string` &&\n plugin.resolve === `gatsby-plugin-page-creator` &&\n slash((plugin.options && plugin.options.path) || ``) ===\n slash(path.join(program.directory, `src/pages`))\n )\n if (pageCreatorPlugin) {\n // override the options if there are any user specified options\n pageCreatorOptions = pageCreatorPlugin.options\n }\n }\n\n const processedPageCreatorPlugin = processPlugin(\n {\n resolve: require.resolve(`gatsby-plugin-page-creator`),\n options: pageCreatorOptions,\n },\n rootDir\n )\n\n plugins.push(processedPageCreatorPlugin)\n\n // Partytown plugin collects usage of <Script strategy={\"off-main-thread\"} />\n // in `wrapRootElement`, so we have to make sure it's the last one running to be able to\n // collect scripts that users might inject in their `wrapRootElement`\n plugins.push(\n processPlugin(\n path.join(__dirname, `../../internal-plugins/partytown`),\n rootDir\n )\n )\n\n const uniquePlugins = uniqWith(plugins, isEqual)\n\n return uniquePlugins\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AAOA;;AACA;;AACA;;AACA;;AAOA;;AAEA,MAAMA,sBAAsB,GAAI,0BAAhC;;AAEO,SAASC,mBAAT,CACLC,MAAmB,GAAG,EADjB,EAELC,OAFK,EAGe;EACpB;EACA,MAAMC,OAA2B,GAAG,EAApC;EACA,MAAMC,qBAAqB,GAAG,IAAIC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AACD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IGatsbyConfigInput, PluginEntry } from "../../utils/merge-gatsby-config";
|
|
2
|
+
interface IThemeObj {
|
|
3
|
+
themeName: string;
|
|
4
|
+
themeConfig: IGatsbyConfigInput;
|
|
5
|
+
themeDir: string;
|
|
6
|
+
themeSpec: PluginEntry;
|
|
7
|
+
parentDir: string;
|
|
8
|
+
configFilePath?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function loadThemes(config: IGatsbyConfigInput, { configFilePath, rootDir }: {
|
|
11
|
+
configFilePath: string;
|
|
12
|
+
rootDir: string;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
config: IGatsbyConfigInput;
|
|
15
|
+
themes: Array<IThemeObj>;
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
@@ -1,34 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.loadThemes = loadThemes;
|
|
7
|
+
|
|
8
|
+
var _uniqWith2 = _interopRequireDefault(require("lodash/uniqWith"));
|
|
9
|
+
|
|
10
|
+
var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
|
|
11
|
+
|
|
12
|
+
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
13
|
+
|
|
14
|
+
var _flattenDeep2 = _interopRequireDefault(require("lodash/flattenDeep"));
|
|
15
|
+
|
|
16
|
+
var _gatsbyCoreUtils = require("gatsby-core-utils");
|
|
17
|
+
|
|
18
|
+
var path = _interopRequireWildcard(require("path"));
|
|
19
|
+
|
|
3
20
|
var _mergeGatsbyConfig = require("../../utils/merge-gatsby-config");
|
|
4
21
|
|
|
22
|
+
var _bluebird = require("bluebird");
|
|
23
|
+
|
|
24
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
25
|
+
|
|
5
26
|
var _preferDefault = require("../prefer-default");
|
|
6
27
|
|
|
7
28
|
var _getConfigFile = require("../get-config-file");
|
|
8
29
|
|
|
9
30
|
var _resolvePlugin = require("../load-plugins/resolve-plugin");
|
|
10
31
|
|
|
11
|
-
|
|
12
|
-
createRequireFromPath
|
|
13
|
-
} = require(`gatsby-core-utils`);
|
|
14
|
-
|
|
15
|
-
const path = require(`path`);
|
|
16
|
-
|
|
17
|
-
const Promise = require(`bluebird`);
|
|
32
|
+
var _reporter = _interopRequireDefault(require("gatsby-cli/lib/reporter"));
|
|
18
33
|
|
|
19
|
-
|
|
34
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
35
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const reporter = require(`gatsby-cli/lib/reporter`); // get the gatsby-config file for a theme
|
|
36
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
24
37
|
|
|
38
|
+
const debug = (0, _debug.default)(`gatsby:load-themes`);
|
|
25
39
|
|
|
40
|
+
// get the gatsby-config file for a theme
|
|
26
41
|
const resolveTheme = async (themeSpec, configFileThatDeclaredTheme, isMainConfig = false, rootDir) => {
|
|
27
|
-
const themeName = themeSpec
|
|
42
|
+
const themeName = typeof themeSpec === `string` ? themeSpec : themeSpec.resolve;
|
|
28
43
|
let themeDir;
|
|
29
44
|
|
|
30
45
|
try {
|
|
31
|
-
const scopedRequire = createRequireFromPath(`${rootDir}/:internal:`); // theme is an node-resolvable module
|
|
46
|
+
const scopedRequire = (0, _gatsbyCoreUtils.createRequireFromPath)(`${rootDir}/:internal:`); // theme is an node-resolvable module
|
|
32
47
|
|
|
33
48
|
themeDir = path.dirname(scopedRequire.resolve(themeName));
|
|
34
49
|
} catch (e) {
|
|
@@ -47,13 +62,14 @@ const resolveTheme = async (themeSpec, configFileThatDeclaredTheme, isMainConfig
|
|
|
47
62
|
} = (0, _resolvePlugin.resolvePlugin)(themeName, rootDir);
|
|
48
63
|
themeDir = resolve;
|
|
49
64
|
} catch (localErr) {
|
|
50
|
-
|
|
65
|
+
_reporter.default.panic(`Failed to resolve ${themeName}`, localErr);
|
|
51
66
|
}
|
|
52
67
|
}
|
|
53
68
|
|
|
54
69
|
if (!themeDir) {
|
|
55
70
|
const nodeResolutionPaths = module.paths.map(p => path.join(p, themeName));
|
|
56
|
-
|
|
71
|
+
|
|
72
|
+
_reporter.default.panic({
|
|
57
73
|
id: `10226`,
|
|
58
74
|
context: {
|
|
59
75
|
themeName,
|
|
@@ -71,12 +87,7 @@ const resolveTheme = async (themeSpec, configFileThatDeclaredTheme, isMainConfig
|
|
|
71
87
|
} = await (0, _getConfigFile.getConfigFile)(themeDir, `gatsby-config`);
|
|
72
88
|
const theme = (0, _preferDefault.preferDefault)(configModule); // if theme is a function, call it with the themeConfig
|
|
73
89
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (_.isFunction(theme)) {
|
|
77
|
-
themeConfig = theme(themeSpec.options || {});
|
|
78
|
-
}
|
|
79
|
-
|
|
90
|
+
const themeConfig = (0, _isFunction2.default)(theme) ? theme(typeof themeSpec === `string` ? {} : themeSpec.options) : theme;
|
|
80
91
|
return {
|
|
81
92
|
themeName,
|
|
82
93
|
themeConfig,
|
|
@@ -110,46 +121,54 @@ const processTheme = ({
|
|
|
110
121
|
if (themeConfig && themesList) {
|
|
111
122
|
// for every parent theme a theme defines, resolve the parent's
|
|
112
123
|
// gatsby config and return it in order [parentA, parentB, child]
|
|
113
|
-
return
|
|
124
|
+
return (0, _bluebird.mapSeries)(themesList, async spec => {
|
|
114
125
|
const themeObj = await resolveTheme(spec, configFilePath, false, themeDir);
|
|
115
126
|
return processTheme(themeObj, {
|
|
116
127
|
rootDir: themeDir
|
|
117
128
|
});
|
|
118
|
-
}).then(arr => arr.concat([{
|
|
129
|
+
}).then(arr => (0, _flattenDeep2.default)(arr.concat([{
|
|
119
130
|
themeName,
|
|
120
131
|
themeConfig,
|
|
121
132
|
themeSpec,
|
|
122
133
|
themeDir,
|
|
123
134
|
parentDir: rootDir
|
|
124
|
-
}]));
|
|
135
|
+
}])));
|
|
125
136
|
} else {
|
|
126
137
|
// if a theme doesn't define additional themes, return the original theme
|
|
127
|
-
return [{
|
|
138
|
+
return Promise.resolve([{
|
|
128
139
|
themeName,
|
|
129
140
|
themeConfig,
|
|
130
141
|
themeSpec,
|
|
131
142
|
themeDir,
|
|
132
143
|
parentDir: rootDir
|
|
133
|
-
}];
|
|
144
|
+
}]);
|
|
134
145
|
}
|
|
135
146
|
};
|
|
136
147
|
|
|
137
|
-
|
|
148
|
+
function normalizePluginEntry(plugin, parentDir) {
|
|
149
|
+
return {
|
|
150
|
+
resolve: typeof plugin === `string` ? plugin : plugin.resolve,
|
|
151
|
+
options: typeof plugin === `string` ? {} : plugin.options || {},
|
|
152
|
+
parentDir
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function loadThemes(config, {
|
|
138
157
|
configFilePath,
|
|
139
158
|
rootDir
|
|
140
|
-
})
|
|
141
|
-
const themesA = await
|
|
159
|
+
}) {
|
|
160
|
+
const themesA = await (0, _bluebird.mapSeries)(config.plugins || [], async themeSpec => {
|
|
142
161
|
const themeObj = await resolveTheme(themeSpec, configFilePath, true, rootDir);
|
|
143
162
|
return processTheme(themeObj, {
|
|
144
163
|
rootDir
|
|
145
164
|
});
|
|
146
|
-
}).then(arr =>
|
|
165
|
+
}).then(arr => (0, _flattenDeep2.default)(arr)); // log out flattened themes list to aid in debugging
|
|
147
166
|
|
|
148
167
|
debug(themesA); // map over each theme, adding the theme itself to the plugins
|
|
149
168
|
// list in the config for the theme. This enables the usage of
|
|
150
169
|
// gatsby-node, etc in themes.
|
|
151
170
|
|
|
152
|
-
return
|
|
171
|
+
return (0, _bluebird.mapSeries)(themesA, ({
|
|
153
172
|
themeName,
|
|
154
173
|
themeConfig = {},
|
|
155
174
|
themeSpec,
|
|
@@ -157,16 +176,10 @@ module.exports = async (config, {
|
|
|
157
176
|
parentDir
|
|
158
177
|
}) => {
|
|
159
178
|
return { ...themeConfig,
|
|
160
|
-
plugins: [...(themeConfig.plugins || []).map(plugin =>
|
|
161
|
-
return {
|
|
162
|
-
resolve: typeof plugin === `string` ? plugin : plugin.resolve,
|
|
163
|
-
options: plugin.options || {},
|
|
164
|
-
parentDir: themeDir
|
|
165
|
-
};
|
|
166
|
-
}), // theme plugin is last so it's gatsby-node, etc can override it's declared plugins, like a normal site.
|
|
179
|
+
plugins: [...(themeConfig.plugins || []).map(plugin => normalizePluginEntry(plugin, themeDir)), // theme plugin is last so it's gatsby-node, etc can override it's declared plugins, like a normal site.
|
|
167
180
|
{
|
|
168
181
|
resolve: themeName,
|
|
169
|
-
options: themeSpec
|
|
182
|
+
options: typeof themeSpec === `string` ? {} : themeSpec.options,
|
|
170
183
|
parentDir
|
|
171
184
|
}]
|
|
172
185
|
};
|
|
@@ -178,10 +191,14 @@ module.exports = async (config, {
|
|
|
178
191
|
* children, can override functionality in earlier themes.
|
|
179
192
|
*/
|
|
180
193
|
.reduce(_mergeGatsbyConfig.mergeGatsbyConfig, {}).then(newConfig => {
|
|
194
|
+
const mergedConfig = (0, _mergeGatsbyConfig.mergeGatsbyConfig)(newConfig, { ...config,
|
|
195
|
+
plugins: [...(config.plugins || []).map(plugin => normalizePluginEntry(plugin, rootDir))]
|
|
196
|
+
});
|
|
197
|
+
mergedConfig.plugins = (0, _uniqWith2.default)(mergedConfig.plugins, _isEqual2.default);
|
|
181
198
|
return {
|
|
182
|
-
config:
|
|
199
|
+
config: mergedConfig,
|
|
183
200
|
themes: themesA
|
|
184
201
|
};
|
|
185
202
|
});
|
|
186
|
-
}
|
|
203
|
+
}
|
|
187
204
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createRequireFromPath","require","path","Promise","_","debug","reporter","resolveTheme","themeSpec","configFileThatDeclaredTheme","isMainConfig","rootDir","themeName","resolve","themeDir","scopedRequire","dirname","e","pathToLocalTheme","join","resolvePlugin","localErr","panic","nodeResolutionPaths","module","paths","map","p","id","context","configFilePath","configModule","getConfigFile","theme","preferDefault","themeConfig","isFunction","options","parentDir","processTheme","themesList","plugins","mapSeries","spec","themeObj","then","arr","concat","exports","config","themesA","flattenDeep","plugin","reduce","mergeGatsbyConfig","newConfig","themes"],"sources":["../../../src/bootstrap/load-themes/index.js"],"sourcesContent":["const { createRequireFromPath } = require(`gatsby-core-utils`)\nconst path = require(`path`)\nimport { mergeGatsbyConfig } from \"../../utils/merge-gatsby-config\"\nconst Promise = require(`bluebird`)\nconst _ = require(`lodash`)\nconst debug = require(`debug`)(`gatsby:load-themes`)\nimport { preferDefault } from \"../prefer-default\"\nimport { getConfigFile } from \"../get-config-file\"\nimport { resolvePlugin } from \"../load-plugins/resolve-plugin\"\nconst reporter = require(`gatsby-cli/lib/reporter`)\n\n// get the gatsby-config file for a theme\nconst resolveTheme = async (\n themeSpec,\n configFileThatDeclaredTheme,\n isMainConfig = false,\n rootDir\n) => {\n const themeName = themeSpec.resolve || themeSpec\n let themeDir\n try {\n const scopedRequire = createRequireFromPath(`${rootDir}/:internal:`)\n // theme is an node-resolvable module\n themeDir = path.dirname(scopedRequire.resolve(themeName))\n } catch (e) {\n let pathToLocalTheme\n\n // only try to look for local theme in main site\n // local themes nested in other themes is potential source of problems:\n // because those are not hosted by npm, there is potential for multiple\n // local themes with same name that do different things and name being\n // main identifier that Gatsby uses right now, it's safer not to support it for now.\n if (isMainConfig) {\n pathToLocalTheme = path.join(rootDir, `plugins`, themeName)\n // is a local plugin OR it doesn't exist\n try {\n const { resolve } = resolvePlugin(themeName, rootDir)\n themeDir = resolve\n } catch (localErr) {\n reporter.panic(`Failed to resolve ${themeName}`, localErr)\n }\n }\n\n if (!themeDir) {\n const nodeResolutionPaths = module.paths.map(p => path.join(p, themeName))\n reporter.panic({\n id: `10226`,\n context: {\n themeName,\n configFilePath: configFileThatDeclaredTheme,\n pathToLocalTheme,\n nodeResolutionPaths,\n },\n })\n }\n }\n\n const { configModule, configFilePath } = await getConfigFile(\n themeDir,\n `gatsby-config`\n )\n const theme = preferDefault(configModule)\n\n // if theme is a function, call it with the themeConfig\n let themeConfig = theme\n if (_.isFunction(theme)) {\n themeConfig = theme(themeSpec.options || {})\n }\n return {\n themeName,\n themeConfig,\n themeSpec,\n themeDir,\n parentDir: rootDir,\n configFilePath,\n }\n}\n\n// single iteration of a recursive function that resolve parent themes\n// It's recursive because we support child themes declaring parents and\n// have to resolve all the way `up the tree` of parent/children relationships\n//\n// Theoretically, there could be an infinite loop here but in practice there is\n// no use case for a loop so I expect that to only happen if someone is very\n// off track and creating their own set of themes\nconst processTheme = (\n { themeName, themeConfig, themeSpec, themeDir, configFilePath },\n { rootDir }\n) => {\n const themesList = themeConfig && themeConfig.plugins\n // Gatsby themes don't have to specify a gatsby-config.js (they might only use gatsby-node, etc)\n // in this case they're technically plugins, but we should support it anyway\n // because we can't guarantee which files theme creators create first\n if (themeConfig && themesList) {\n // for every parent theme a theme defines, resolve the parent's\n // gatsby config and return it in order [parentA, parentB, child]\n return Promise.mapSeries(themesList, async spec => {\n const themeObj = await resolveTheme(spec, configFilePath, false, themeDir)\n return processTheme(themeObj, { rootDir: themeDir })\n }).then(arr =>\n arr.concat([\n { themeName, themeConfig, themeSpec, themeDir, parentDir: rootDir },\n ])\n )\n } else {\n // if a theme doesn't define additional themes, return the original theme\n return [{ themeName, themeConfig, themeSpec, themeDir, parentDir: rootDir }]\n }\n}\n\nmodule.exports = async (config, { configFilePath, rootDir }) => {\n const themesA = await Promise.mapSeries(\n config.plugins || [],\n async themeSpec => {\n const themeObj = await resolveTheme(\n themeSpec,\n configFilePath,\n true,\n rootDir\n )\n return processTheme(themeObj, { rootDir })\n }\n ).then(arr => _.flattenDeep(arr))\n\n // log out flattened themes list to aid in debugging\n debug(themesA)\n\n // map over each theme, adding the theme itself to the plugins\n // list in the config for the theme. This enables the usage of\n // gatsby-node, etc in themes.\n return (\n Promise.mapSeries(\n themesA,\n ({ themeName, themeConfig = {}, themeSpec, themeDir, parentDir }) => {\n return {\n ...themeConfig,\n plugins: [\n ...(themeConfig.plugins || []).map(plugin => {\n return {\n resolve: typeof plugin === `string` ? plugin : plugin.resolve,\n options: plugin.options || {},\n parentDir: themeDir,\n }\n }),\n // theme plugin is last so it's gatsby-node, etc can override it's declared plugins, like a normal site.\n { resolve: themeName, options: themeSpec.options || {}, parentDir },\n ],\n }\n }\n )\n /**\n * themes resolve to a gatsby-config, so here we merge all of the configs\n * into a single config, making sure to maintain the order in which\n * they were defined so that later configs, like the user's site and\n * children, can override functionality in earlier themes.\n */\n .reduce(mergeGatsbyConfig, {})\n .then(newConfig => {\n return {\n config: mergeGatsbyConfig(newConfig, config),\n themes: themesA,\n }\n })\n )\n}\n"],"mappings":";;AAEA;;AAIA;;AACA;;AACA;;AARA,MAAM;EAAEA;AAAF,IAA4BC,OAAO,CAAE,mBAAF,CAAzC;;AACA,MAAMC,IAAI,GAAGD,OAAO,CAAE,MAAF,CAApB;;AAEA,MAAME,OAAO,GAAGF,OAAO,CAAE,UAAF,CAAvB;;AACA,MAAMG,CAAC,GAAGH,OAAO,CAAE,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;UAELwB,OAAO,EAAEe,MAAM,CAACf,OAAP,IAAkB,EAFtB;UAGLC,SAAS,EAAExB;QAHN,CAAP;MAKD,CANE,CADI,EAQP;MACA;QAAED,OAAO,EAAED,SAAX;QAAsByB,OAAO,EAAE7B,SAAS,CAAC6B,OAAV,IAAqB,EAApD;QAAwDC;MAAxD,CATO;IAFJ,CAAP;EAcD,CAjBH;EAmBE;AACN;AACA;AACA;AACA;AACA;EAxBI,CAyBGe,MAzBH,CAyBUC,oCAzBV,EAyB6B,EAzB7B,EA0BGT,IA1BH,CA0BQU,SAAS,IAAI;IACjB,OAAO;MACLN,MAAM,EAAE,IAAAK,oCAAA,EAAkBC,SAAlB,EAA6BN,MAA7B,CADH;MAELO,MAAM,EAAEN;IAFH,CAAP;EAID,CA/BH,CADF;AAkCD,CAtDD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["debug","DebugCtor","resolveTheme","themeSpec","configFileThatDeclaredTheme","isMainConfig","rootDir","themeName","resolve","themeDir","scopedRequire","createRequireFromPath","path","dirname","e","pathToLocalTheme","join","resolvePlugin","localErr","reporter","panic","nodeResolutionPaths","module","paths","map","p","id","context","configFilePath","configModule","getConfigFile","theme","preferDefault","themeConfig","options","parentDir","processTheme","themesList","plugins","mapSeries","spec","themeObj","then","arr","concat","Promise","normalizePluginEntry","plugin","loadThemes","config","themesA","reduce","mergeGatsbyConfig","newConfig","mergedConfig","themes"],"sources":["../../../src/bootstrap/load-themes/index.ts"],"sourcesContent":["import { createRequireFromPath } from \"gatsby-core-utils\"\nimport * as path from \"path\"\nimport {\n IGatsbyConfigInput,\n mergeGatsbyConfig,\n PluginEntry,\n IPluginEntryWithParentDir,\n} from \"../../utils/merge-gatsby-config\"\nimport { mapSeries } from \"bluebird\"\nimport { flattenDeep, isEqual, isFunction, uniqWith } from \"lodash\"\nimport DebugCtor from \"debug\"\nimport { preferDefault } from \"../prefer-default\"\nimport { getConfigFile } from \"../get-config-file\"\nimport { resolvePlugin } from \"../load-plugins/resolve-plugin\"\nimport reporter from \"gatsby-cli/lib/reporter\"\n\nconst debug = DebugCtor(`gatsby:load-themes`)\n\ninterface IThemeObj {\n themeName: string\n themeConfig: IGatsbyConfigInput\n themeDir: string\n themeSpec: PluginEntry\n parentDir: string\n configFilePath?: string\n}\n\n// get the gatsby-config file for a theme\nconst resolveTheme = async (\n themeSpec: PluginEntry,\n configFileThatDeclaredTheme: string | undefined,\n isMainConfig: boolean = false,\n rootDir: string\n): Promise<IThemeObj> => {\n const themeName =\n typeof themeSpec === `string` ? themeSpec : themeSpec.resolve\n let themeDir\n try {\n const scopedRequire = createRequireFromPath(`${rootDir}/:internal:`)\n // theme is an node-resolvable module\n themeDir = path.dirname(scopedRequire.resolve(themeName))\n } catch (e) {\n let pathToLocalTheme\n\n // only try to look for local theme in main site\n // local themes nested in other themes is potential source of problems:\n // because those are not hosted by npm, there is potential for multiple\n // local themes with same name that do different things and name being\n // main identifier that Gatsby uses right now, it's safer not to support it for now.\n if (isMainConfig) {\n pathToLocalTheme = path.join(rootDir, `plugins`, themeName)\n // is a local plugin OR it doesn't exist\n try {\n const { resolve } = resolvePlugin(themeName, rootDir)\n themeDir = resolve\n } catch (localErr) {\n reporter.panic(`Failed to resolve ${themeName}`, localErr)\n }\n }\n\n if (!themeDir) {\n const nodeResolutionPaths = module.paths.map(p => path.join(p, themeName))\n reporter.panic({\n id: `10226`,\n context: {\n themeName,\n configFilePath: configFileThatDeclaredTheme,\n pathToLocalTheme,\n nodeResolutionPaths,\n },\n })\n }\n }\n\n const { configModule, configFilePath } = await getConfigFile(\n themeDir,\n `gatsby-config`\n )\n const theme:\n | IGatsbyConfigInput\n | ((options?: Record<string, unknown>) => IGatsbyConfigInput) =\n preferDefault(configModule)\n\n // if theme is a function, call it with the themeConfig\n const themeConfig = isFunction(theme)\n ? theme(typeof themeSpec === `string` ? {} : themeSpec.options)\n : theme\n\n return {\n themeName,\n themeConfig,\n themeSpec,\n themeDir,\n parentDir: rootDir,\n configFilePath,\n }\n}\n\n// single iteration of a recursive function that resolve parent themes\n// It's recursive because we support child themes declaring parents and\n// have to resolve all the way `up the tree` of parent/children relationships\n//\n// Theoretically, there could be an infinite loop here but in practice there is\n// no use case for a loop so I expect that to only happen if someone is very\n// off track and creating their own set of themes\nconst processTheme = (\n { themeName, themeConfig, themeSpec, themeDir, configFilePath }: IThemeObj,\n { rootDir }: { rootDir: string }\n): Promise<Array<IThemeObj>> => {\n const themesList = themeConfig && themeConfig.plugins\n // Gatsby themes don't have to specify a gatsby-config.js (they might only use gatsby-node, etc)\n // in this case they're technically plugins, but we should support it anyway\n // because we can't guarantee which files theme creators create first\n if (themeConfig && themesList) {\n // for every parent theme a theme defines, resolve the parent's\n // gatsby config and return it in order [parentA, parentB, child]\n return mapSeries(\n themesList,\n async (spec: PluginEntry): Promise<Array<IThemeObj>> => {\n const themeObj = await resolveTheme(\n spec,\n configFilePath,\n false,\n themeDir\n )\n return processTheme(themeObj, { rootDir: themeDir })\n }\n ).then(arr =>\n flattenDeep(\n arr.concat([\n { themeName, themeConfig, themeSpec, themeDir, parentDir: rootDir },\n ])\n )\n )\n } else {\n // if a theme doesn't define additional themes, return the original theme\n return Promise.resolve([\n { themeName, themeConfig, themeSpec, themeDir, parentDir: rootDir },\n ])\n }\n}\n\nfunction normalizePluginEntry(\n plugin: PluginEntry,\n parentDir: string\n): IPluginEntryWithParentDir {\n return {\n resolve: typeof plugin === `string` ? plugin : plugin.resolve,\n options: typeof plugin === `string` ? {} : plugin.options || {},\n parentDir,\n }\n}\n\nexport async function loadThemes(\n config: IGatsbyConfigInput,\n { configFilePath, rootDir }: { configFilePath: string; rootDir: string }\n): Promise<{\n config: IGatsbyConfigInput\n themes: Array<IThemeObj>\n}> {\n const themesA = await mapSeries(\n config.plugins || [],\n async (themeSpec: PluginEntry) => {\n const themeObj = await resolveTheme(\n themeSpec,\n configFilePath,\n true,\n rootDir\n )\n return processTheme(themeObj, { rootDir })\n }\n ).then(arr => flattenDeep(arr))\n\n // log out flattened themes list to aid in debugging\n debug(themesA)\n\n // map over each theme, adding the theme itself to the plugins\n // list in the config for the theme. This enables the usage of\n // gatsby-node, etc in themes.\n return (\n mapSeries(\n themesA,\n ({ themeName, themeConfig = {}, themeSpec, themeDir, parentDir }) => {\n return {\n ...themeConfig,\n plugins: [\n ...(themeConfig.plugins || []).map(plugin =>\n normalizePluginEntry(plugin, themeDir)\n ),\n // theme plugin is last so it's gatsby-node, etc can override it's declared plugins, like a normal site.\n {\n resolve: themeName,\n options: typeof themeSpec === `string` ? {} : themeSpec.options,\n parentDir,\n },\n ],\n }\n }\n )\n /**\n * themes resolve to a gatsby-config, so here we merge all of the configs\n * into a single config, making sure to maintain the order in which\n * they were defined so that later configs, like the user's site and\n * children, can override functionality in earlier themes.\n */\n .reduce(mergeGatsbyConfig, {})\n .then(newConfig => {\n const mergedConfig = mergeGatsbyConfig(newConfig, {\n ...config,\n plugins: [\n ...(config.plugins || []).map(plugin =>\n normalizePluginEntry(plugin, rootDir)\n ),\n ],\n })\n\n mergedConfig.plugins = uniqWith(mergedConfig.plugins, isEqual)\n\n return {\n config: mergedConfig,\n themes: themesA,\n }\n })\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAMA;;AAEA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,oBAAX,CAAd;;AAWA;AACA,MAAMC,YAAY,GAAG,OACnBC,SADmB,EAEnBC,2BAFmB,EAGnBC,YAAqB,GAAG,KAHL,EAInBC,OAJmB,KAKI;EACvB,MAAMC,SAAS,GACb,OAAOJ,SAAP,KAAsB,QAAtB,GAAgCA,SAAhC,GAA4CA,SAAS,CAACK,OADxD;EAEA,IAAIC,QAAJ;;EACA,IAAI;IACF,MAAMC,aAAa,GAAG,IAAAC,sCAAA,EAAuB,GAAEL,OAAQ,aAAjC,CAAtB,CADE,CAEF;;IACAG,QAAQ,GAAGG,IAAI,CAACC,OAAL,CAAa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W,SAAS,IAAI;IACjB,MAAMC,YAAY,GAAG,IAAAF,oCAAA,EAAkBC,SAAlB,EAA6B,EAChD,GAAGJ,MAD6C;MAEhDX,OAAO,EAAE,CACP,GAAG,CAACW,MAAM,CAACX,OAAP,IAAkB,EAAnB,EAAuBd,GAAvB,CAA2BuB,MAAM,IAClCD,oBAAoB,CAACC,MAAD,EAASzC,OAAT,CADnB,CADI;IAFuC,CAA7B,CAArB;IASAgD,YAAY,CAAChB,OAAb,GAAuB,wBAASgB,YAAY,CAAChB,OAAtB,oBAAvB;IAEA,OAAO;MACLW,MAAM,EAAEK,YADH;MAELC,MAAM,EAAEL;IAFH,CAAP;EAID,CA1CH,CADF;AA6CD"}
|
|
@@ -71,18 +71,30 @@ class GraphQLEngine {
|
|
|
71
71
|
payload: _queryEnginePlugins.flattenedPlugins
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
for (const
|
|
74
|
+
for (const plugin of _queryEnginePlugins.gatsbyNodes) {
|
|
75
|
+
const {
|
|
76
|
+
name,
|
|
77
|
+
module,
|
|
78
|
+
importKey
|
|
79
|
+
} = plugin;
|
|
75
80
|
(0, _requireGatsbyPlugin.setGatsbyPluginCache)({
|
|
76
|
-
name
|
|
77
|
-
resolve:
|
|
78
|
-
|
|
81
|
+
name,
|
|
82
|
+
resolve: ``,
|
|
83
|
+
importKey
|
|
84
|
+
}, `gatsby-node`, module);
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
for (const
|
|
87
|
+
for (const plugin of _queryEnginePlugins.gatsbyWorkers) {
|
|
88
|
+
const {
|
|
89
|
+
name,
|
|
90
|
+
module,
|
|
91
|
+
importKey
|
|
92
|
+
} = plugin;
|
|
82
93
|
(0, _requireGatsbyPlugin.setGatsbyPluginCache)({
|
|
83
|
-
name
|
|
84
|
-
resolve:
|
|
85
|
-
|
|
94
|
+
name,
|
|
95
|
+
resolve: ``,
|
|
96
|
+
importKey
|
|
97
|
+
}, `gatsby-worker`, module);
|
|
86
98
|
}
|
|
87
99
|
|
|
88
100
|
await (0, _apiRunnerNode.default)(`onPluginInit`, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","names":["tracerReadyPromise","initTracer","process","env","GATSBY_OPEN_TRACING_CONFIG_FILE","GraphQLEngine","constructor","dbPath","setupLmdbStore","getRunner","_doGetRunner","wrapActivity","reporter","phantomActivity","start","store","dispatch","actions","createTypes","SCHEMA_SNAPSHOT","type","payload","flattenedPlugins","pluginName","Object","keys","gatsbyNodes","setGatsbyPluginCache","name","resolve","gatsbyWorkers","apiRunnerNode","parentSpan","span","build","fullMetadataBuild","GraphQLRunner","end","runnerPromise","ready","runQuery","query","context","opts","engineContext","requestId","uuid","v4","doRunQuery","queryName","undefined","gettingRunnerActivity","graphqlRunner","result","waitingForJobsCreatedByCurrentRequestActivity","waitJobsByRequest","runWithEngineContext","findPageByPath","pathName","state","pages","get","getDataStore","getNode","values","iterateNodesByType"],"sources":["../../../src/schema/graphql-engine/entry.ts"],"sourcesContent":["// \"bootstrap\" must be first import, as it sets up multiple globals that need to be set early\n// see details in that module\nimport \"./bootstrap\"\n\nimport { ExecutionResult, Source } from \"graphql\"\nimport { uuid } from \"gatsby-core-utils\"\nimport { build } from \"../index\"\nimport { setupLmdbStore } from \"../../datastore/lmdb/lmdb-datastore\"\nimport { store } from \"../../redux\"\nimport { actions } from \"../../redux/actions\"\nimport reporter from \"gatsby-cli/lib/reporter\"\nimport { GraphQLRunner, IQueryOptions } from \"../../query/graphql-runner\"\nimport { waitJobsByRequest } from \"../../utils/wait-until-jobs-complete\"\nimport { setGatsbyPluginCache } from \"../../utils/require-gatsby-plugin\"\nimport apiRunnerNode from \"../../utils/api-runner-node\"\nimport type { IGatsbyPage, IGatsbyState } from \"../../redux/types\"\nimport { findPageByPath } from \"../../utils/find-page-by-path\"\nimport { runWithEngineContext } from \"../../utils/engine-context\"\nimport { getDataStore } from \"../../datastore\"\nimport {\n gatsbyNodes,\n gatsbyWorkers,\n flattenedPlugins,\n // @ts-ignore\n} from \".cache/query-engine-plugins\"\nimport { initTracer } from \"../../utils/tracer\"\n\ntype MaybePhantomActivity =\n | ReturnType<typeof reporter.phantomActivity>\n | undefined\n\nconst tracerReadyPromise = initTracer(\n process.env.GATSBY_OPEN_TRACING_CONFIG_FILE ?? ``\n)\n\nexport class GraphQLEngine {\n // private schema: GraphQLSchema\n private runnerPromise?: Promise<GraphQLRunner>\n\n constructor({ dbPath }: { dbPath: string }) {\n setupLmdbStore({ dbPath })\n // start initializing runner ASAP\n this.getRunner()\n }\n\n private async _doGetRunner(): Promise<GraphQLRunner> {\n await tracerReadyPromise\n\n const wrapActivity = reporter.phantomActivity(`Initializing GraphQL Engine`)\n wrapActivity.start()\n try {\n // @ts-ignore SCHEMA_SNAPSHOT is being \"inlined\" by bundler\n store.dispatch(actions.createTypes(SCHEMA_SNAPSHOT))\n\n // TODO: FLATTENED_PLUGINS needs to be merged with plugin options from gatsby-config\n // (as there might be non-serializable options, i.e. functions)\n store.dispatch({\n type: `SET_SITE_FLATTENED_PLUGINS`,\n payload: flattenedPlugins,\n })\n\n for (const pluginName of Object.keys(gatsbyNodes)) {\n setGatsbyPluginCache(\n { name: pluginName, resolve: `` },\n `gatsby-node`,\n gatsbyNodes[pluginName]\n )\n }\n for (const pluginName of Object.keys(gatsbyWorkers)) {\n setGatsbyPluginCache(\n { name: pluginName, resolve: `` },\n `gatsby-worker`,\n gatsbyWorkers[pluginName]\n )\n }\n\n await apiRunnerNode(`onPluginInit`, { parentSpan: wrapActivity.span })\n await apiRunnerNode(`createSchemaCustomization`, {\n parentSpan: wrapActivity.span,\n })\n\n // Build runs\n // Note: skipping inference metadata because we rely on schema snapshot\n await build({ fullMetadataBuild: false, parentSpan: wrapActivity.span })\n\n return new GraphQLRunner(store)\n } finally {\n wrapActivity.end()\n }\n }\n\n private async getRunner(): Promise<GraphQLRunner> {\n if (!this.runnerPromise) {\n this.runnerPromise = this._doGetRunner()\n }\n return this.runnerPromise\n }\n\n public async ready(): Promise<void> {\n // We don't want to expose internal runner freely. We do expose `runQuery` function already.\n // The way internal runner works can change, so we should not make it a public API.\n // Here we just want to expose way to await it being ready\n await this.getRunner()\n }\n\n public async runQuery(\n query: string | Source,\n context: Record<string, any> = {},\n opts?: IQueryOptions\n ): Promise<ExecutionResult> {\n const engineContext = {\n requestId: uuid.v4(),\n }\n\n const doRunQuery = async (): Promise<ExecutionResult> => {\n if (!opts) {\n opts = {\n queryName: `GraphQL Engine query`,\n parentSpan: undefined,\n }\n }\n\n let gettingRunnerActivity: MaybePhantomActivity\n let graphqlRunner: GraphQLRunner\n try {\n if (opts.parentSpan) {\n gettingRunnerActivity = reporter.phantomActivity(\n `Waiting for graphql runner to init`,\n {\n parentSpan: opts.parentSpan,\n }\n )\n gettingRunnerActivity.start()\n }\n graphqlRunner = await this.getRunner()\n } finally {\n if (gettingRunnerActivity) {\n gettingRunnerActivity.end()\n }\n }\n\n // graphqlRunner creates it's own Span as long as we pass `parentSpan`\n const result = await graphqlRunner.query(query, context, opts)\n\n let waitingForJobsCreatedByCurrentRequestActivity: MaybePhantomActivity\n try {\n if (opts.parentSpan) {\n waitingForJobsCreatedByCurrentRequestActivity =\n reporter.phantomActivity(`Waiting for jobs to finish`, {\n parentSpan: opts.parentSpan,\n })\n waitingForJobsCreatedByCurrentRequestActivity.start()\n }\n await waitJobsByRequest(engineContext.requestId)\n } finally {\n if (waitingForJobsCreatedByCurrentRequestActivity) {\n waitingForJobsCreatedByCurrentRequestActivity.end()\n }\n }\n return result\n }\n\n try {\n return await runWithEngineContext(engineContext, doRunQuery)\n } finally {\n // Reset job-to-request mapping\n store.dispatch({\n type: `CLEAR_JOB_V2_CONTEXT`,\n payload: engineContext,\n })\n }\n }\n\n public findPageByPath(pathName: string): IGatsbyPage | undefined {\n // adapter so `findPageByPath` use SitePage nodes in datastore\n // instead of `pages` redux slice\n const state = {\n pages: {\n get(pathName: string): IGatsbyPage | undefined {\n return getDataStore().getNode(`SitePage ${pathName}`) as\n | IGatsbyPage\n | undefined\n },\n values(): Iterable<IGatsbyPage> {\n return getDataStore().iterateNodesByType(\n `SitePage`\n ) as Iterable<IGatsbyPage>\n },\n },\n } as unknown as IGatsbyState\n\n return findPageByPath(state, pathName, false)\n }\n}\n\nexport default { GraphQLEngine }\n"],"mappings":";;;;;;;AAEA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAMA;;;;AAMA,MAAMA,kBAAkB,GAAG,IAAAC,kBAAA,2BACzBC,OAAO,CAACC,GAAR,CAAYC,+BADa,yEACuB,EADvB,CAA3B;;AAIO,MAAMC,aAAN,CAAoB;EACzB;EAGAC,WAAW,CAAC;IAAEC;EAAF,CAAD,EAAiC;IAC1C,IAAAC,6BAAA,EAAe;MAAED;IAAF,CAAf,EAD0C,CAE1C;;IACA,KAAKE,SAAL;EACD;;EAEyB,MAAZC,YAAY,GAA2B;IACnD,MAAMV,kBAAN;;IAEA,MAAMW,YAAY,GAAGC,iBAAA,CAASC,eAAT,CAA0B,6BAA1B,CAArB;;IACAF,YAAY,CAACG,KAAb;;IACA,IAAI;MACF;MACAC,YAAA,CAAMC,QAAN,CAAeC,gBAAA,CAAQC,WAAR,CAAoBC,eAApB,CAAf,EAFE,CAIF;MACA;;;MACAJ,YAAA,CAAMC,QAAN,CAAe;QACbI,IAAI,EAAG,4BADM;QAEbC,OAAO,EAAEC;MAFI,CAAf;;MAKA,KAAK,MAAMC,UAAX,IAAyBC,MAAM,CAACC,IAAP,CAAYC,+BAAZ,CAAzB,EAAmD;QACjD,IAAAC,yCAAA,EACE;UAAEC,IAAI,EAAEL,UAAR;UAAoBM,OAAO,EAAG;QAA9B,CADF,EAEG,aAFH,EAGEH,+BAAA,CAAYH,UAAZ,CAHF;MAKD;;MACD,KAAK,MAAMA,UAAX,IAAyBC,MAAM,CAACC,IAAP,CAAYK,iCAAZ,CAAzB,EAAqD;QACnD,IAAAH,yCA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G,kBAAf,CACJ,UADI,CAAP;QAGD;;MAVI;IADK,CAAd;IAeA,OAAO,IAAAR,8BAAA,EAAeE,KAAf,EAAsBD,QAAtB,EAAgC,KAAhC,CAAP;EACD;;AA7JwB;;;eAgKZ;EAAErD;AAAF,C"}
|
|
1
|
+
{"version":3,"file":"entry.js","names":["tracerReadyPromise","initTracer","process","env","GATSBY_OPEN_TRACING_CONFIG_FILE","GraphQLEngine","constructor","dbPath","setupLmdbStore","getRunner","_doGetRunner","wrapActivity","reporter","phantomActivity","start","store","dispatch","actions","createTypes","SCHEMA_SNAPSHOT","type","payload","flattenedPlugins","plugin","gatsbyNodes","name","module","importKey","setGatsbyPluginCache","resolve","gatsbyWorkers","apiRunnerNode","parentSpan","span","build","fullMetadataBuild","GraphQLRunner","end","runnerPromise","ready","runQuery","query","context","opts","engineContext","requestId","uuid","v4","doRunQuery","queryName","undefined","gettingRunnerActivity","graphqlRunner","result","waitingForJobsCreatedByCurrentRequestActivity","waitJobsByRequest","runWithEngineContext","findPageByPath","pathName","state","pages","get","getDataStore","getNode","values","iterateNodesByType"],"sources":["../../../src/schema/graphql-engine/entry.ts"],"sourcesContent":["// \"bootstrap\" must be first import, as it sets up multiple globals that need to be set early\n// see details in that module\nimport \"./bootstrap\"\n\nimport { ExecutionResult, Source } from \"graphql\"\nimport { uuid } from \"gatsby-core-utils\"\nimport { build } from \"../index\"\nimport { setupLmdbStore } from \"../../datastore/lmdb/lmdb-datastore\"\nimport { store } from \"../../redux\"\nimport { actions } from \"../../redux/actions\"\nimport reporter from \"gatsby-cli/lib/reporter\"\nimport { GraphQLRunner, IQueryOptions } from \"../../query/graphql-runner\"\nimport { waitJobsByRequest } from \"../../utils/wait-until-jobs-complete\"\nimport { setGatsbyPluginCache } from \"../../utils/require-gatsby-plugin\"\nimport apiRunnerNode from \"../../utils/api-runner-node\"\nimport type { IGatsbyPage, IGatsbyState } from \"../../redux/types\"\nimport { findPageByPath } from \"../../utils/find-page-by-path\"\nimport { runWithEngineContext } from \"../../utils/engine-context\"\nimport { getDataStore } from \"../../datastore\"\nimport {\n gatsbyNodes,\n gatsbyWorkers,\n flattenedPlugins,\n // @ts-ignore\n} from \".cache/query-engine-plugins\"\nimport { initTracer } from \"../../utils/tracer\"\n\ntype MaybePhantomActivity =\n | ReturnType<typeof reporter.phantomActivity>\n | undefined\n\nconst tracerReadyPromise = initTracer(\n process.env.GATSBY_OPEN_TRACING_CONFIG_FILE ?? ``\n)\n\nexport class GraphQLEngine {\n // private schema: GraphQLSchema\n private runnerPromise?: Promise<GraphQLRunner>\n\n constructor({ dbPath }: { dbPath: string }) {\n setupLmdbStore({ dbPath })\n // start initializing runner ASAP\n this.getRunner()\n }\n\n private async _doGetRunner(): Promise<GraphQLRunner> {\n await tracerReadyPromise\n\n const wrapActivity = reporter.phantomActivity(`Initializing GraphQL Engine`)\n wrapActivity.start()\n try {\n // @ts-ignore SCHEMA_SNAPSHOT is being \"inlined\" by bundler\n store.dispatch(actions.createTypes(SCHEMA_SNAPSHOT))\n\n // TODO: FLATTENED_PLUGINS needs to be merged with plugin options from gatsby-config\n // (as there might be non-serializable options, i.e. functions)\n store.dispatch({\n type: `SET_SITE_FLATTENED_PLUGINS`,\n payload: flattenedPlugins,\n })\n\n for (const plugin of gatsbyNodes) {\n const { name, module, importKey } = plugin\n setGatsbyPluginCache(\n { name, resolve: ``, importKey },\n `gatsby-node`,\n module\n )\n }\n for (const plugin of gatsbyWorkers) {\n const { name, module, importKey } = plugin\n setGatsbyPluginCache(\n { name, resolve: ``, importKey },\n `gatsby-worker`,\n module\n )\n }\n\n await apiRunnerNode(`onPluginInit`, { parentSpan: wrapActivity.span })\n await apiRunnerNode(`createSchemaCustomization`, {\n parentSpan: wrapActivity.span,\n })\n\n // Build runs\n // Note: skipping inference metadata because we rely on schema snapshot\n await build({ fullMetadataBuild: false, parentSpan: wrapActivity.span })\n\n return new GraphQLRunner(store)\n } finally {\n wrapActivity.end()\n }\n }\n\n private async getRunner(): Promise<GraphQLRunner> {\n if (!this.runnerPromise) {\n this.runnerPromise = this._doGetRunner()\n }\n return this.runnerPromise\n }\n\n public async ready(): Promise<void> {\n // We don't want to expose internal runner freely. We do expose `runQuery` function already.\n // The way internal runner works can change, so we should not make it a public API.\n // Here we just want to expose way to await it being ready\n await this.getRunner()\n }\n\n public async runQuery(\n query: string | Source,\n context: Record<string, any> = {},\n opts?: IQueryOptions\n ): Promise<ExecutionResult> {\n const engineContext = {\n requestId: uuid.v4(),\n }\n\n const doRunQuery = async (): Promise<ExecutionResult> => {\n if (!opts) {\n opts = {\n queryName: `GraphQL Engine query`,\n parentSpan: undefined,\n }\n }\n\n let gettingRunnerActivity: MaybePhantomActivity\n let graphqlRunner: GraphQLRunner\n try {\n if (opts.parentSpan) {\n gettingRunnerActivity = reporter.phantomActivity(\n `Waiting for graphql runner to init`,\n {\n parentSpan: opts.parentSpan,\n }\n )\n gettingRunnerActivity.start()\n }\n graphqlRunner = await this.getRunner()\n } finally {\n if (gettingRunnerActivity) {\n gettingRunnerActivity.end()\n }\n }\n\n // graphqlRunner creates it's own Span as long as we pass `parentSpan`\n const result = await graphqlRunner.query(query, context, opts)\n\n let waitingForJobsCreatedByCurrentRequestActivity: MaybePhantomActivity\n try {\n if (opts.parentSpan) {\n waitingForJobsCreatedByCurrentRequestActivity =\n reporter.phantomActivity(`Waiting for jobs to finish`, {\n parentSpan: opts.parentSpan,\n })\n waitingForJobsCreatedByCurrentRequestActivity.start()\n }\n await waitJobsByRequest(engineContext.requestId)\n } finally {\n if (waitingForJobsCreatedByCurrentRequestActivity) {\n waitingForJobsCreatedByCurrentRequestActivity.end()\n }\n }\n return result\n }\n\n try {\n return await runWithEngineContext(engineContext, doRunQuery)\n } finally {\n // Reset job-to-request mapping\n store.dispatch({\n type: `CLEAR_JOB_V2_CONTEXT`,\n payload: engineContext,\n })\n }\n }\n\n public findPageByPath(pathName: string): IGatsbyPage | undefined {\n // adapter so `findPageByPath` use SitePage nodes in datastore\n // instead of `pages` redux slice\n const state = {\n pages: {\n get(pathName: string): IGatsbyPage | undefined {\n return getDataStore().getNode(`SitePage ${pathName}`) as\n | IGatsbyPage\n | undefined\n },\n values(): Iterable<IGatsbyPage> {\n return getDataStore().iterateNodesByType(\n `SitePage`\n ) as Iterable<IGatsbyPage>\n },\n },\n } as unknown as IGatsbyState\n\n return findPageByPath(state, pathName, false)\n }\n}\n\nexport default { GraphQLEngine }\n"],"mappings":";;;;;;;AAEA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAMA;;;;AAMA,MAAMA,kBAAkB,GAAG,IAAAC,kBAAA,2BACzBC,OAAO,CAACC,GAAR,CAAYC,+BADa,yEACuB,EADvB,CAA3B;;AAIO,MAAMC,aAAN,CAAoB;EACzB;EAGAC,WAAW,CAAC;IAAEC;EAAF,CAAD,EAAiC;IAC1C,IAAAC,6BAAA,EAAe;MAAED;IAAF,CAAf,EAD0C,CAE1C;;IACA,KAAKE,SAAL;EACD;;EAEyB,MAAZC,YAAY,GAA2B;IACnD,MAAMV,kBAAN;;IAEA,MAAMW,YAAY,GAAGC,iBAAA,CAASC,eAAT,CAA0B,6BAA1B,CAArB;;IACAF,YAAY,CAACG,KAAb;;IACA,IAAI;MACF;MACAC,YAAA,CAAMC,QAAN,CAAeC,gBAAA,CAAQC,WAAR,CAAoBC,eAApB,CAAf,EAFE,CAIF;MACA;;;MACAJ,YAAA,CAAMC,QAAN,CAAe;QACbI,IAAI,EAAG,4BADM;QAEbC,OAAO,EAAEC;MAFI,CAAf;;MAKA,KAAK,MAAMC,MAAX,IAAqBC,+BAArB,EAAkC;QAChC,MAAM;UAAEC,IAAF;UAAQC,MAAR;UAAgBC;QAAhB,IAA8BJ,MAApC;QACA,IAAAK,yCAAA,EACE;UAAEH,IAAF;UAAQI,OAAO,EAAG,EAAlB;UAAqBF;QAArB,CADF,EAEG,aAFH,EAGED,MAHF;MAKD;;MACD,KAAK,MA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AAwB,YAAWL,QAAS,EAA5C,CAAP;QAGD,CALI;;QAMLM,MAAM,GAA0B;UAC9B,OAAO,IAAAF,uBAAA,IAAeG,kBAAf,CACJ,UADI,CAAP;QAGD;;MAVI;IADK,CAAd;IAeA,OAAO,IAAAR,8BAAA,EAAeE,KAAf,EAAsBD,QAAtB,EAAgC,KAAhC,CAAP;EACD;;AA/JwB;;;eAkKZ;EAAErD;AAAF,C"}
|
|
@@ -54,35 +54,35 @@ function relativePluginPath(resolve) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function render(usedPlugins, usedSubPlugins) {
|
|
57
|
-
const uniqGatsbyNode = uniq(usedPlugins);
|
|
58
57
|
const uniqSubPlugins = uniq(usedSubPlugins);
|
|
59
|
-
const sanitizedUsedPlugins = usedPlugins.map(plugin => {
|
|
58
|
+
const sanitizedUsedPlugins = usedPlugins.map((plugin, i) => {
|
|
60
59
|
// TODO: We don't support functions in pluginOptions here
|
|
61
60
|
return { ...plugin,
|
|
62
61
|
resolve: ``,
|
|
63
62
|
pluginFilepath: ``,
|
|
64
|
-
subPluginPaths: undefined
|
|
63
|
+
subPluginPaths: undefined,
|
|
64
|
+
importKey: i + 1
|
|
65
65
|
};
|
|
66
66
|
});
|
|
67
|
-
const pluginsWithWorkers = filterPluginsWithWorkers(
|
|
67
|
+
const pluginsWithWorkers = filterPluginsWithWorkers(usedPlugins);
|
|
68
68
|
const subPluginModuleToImportNameMapping = new Map();
|
|
69
|
-
const imports = [...
|
|
69
|
+
const imports = [...usedPlugins.map((plugin, i) => `import * as pluginGatsbyNode${i} from "${relativePluginPath(plugin.resolve)}/gatsby-node"`), ...pluginsWithWorkers.map((plugin, i) => `import * as pluginGatsbyWorker${i} from "${relativePluginPath(plugin.resolve)}/gatsby-worker"`), ...uniqSubPlugins.map((plugin, i) => {
|
|
70
70
|
const importName = `subPlugin${i}`;
|
|
71
71
|
subPluginModuleToImportNameMapping.set(plugin.modulePath, importName);
|
|
72
72
|
return `import * as ${importName} from "${relativePluginPath(plugin.modulePath)}"`;
|
|
73
73
|
})];
|
|
74
|
-
const gatsbyNodeExports =
|
|
75
|
-
const gatsbyWorkerExports = pluginsWithWorkers.map((plugin, i) => `"${plugin.name}": pluginGatsbyWorker${i},`);
|
|
74
|
+
const gatsbyNodeExports = usedPlugins.map((plugin, i) => `{ name: "${plugin.name}", module: pluginGatsbyNode${i}, importKey: ${i + 1} },`);
|
|
75
|
+
const gatsbyWorkerExports = pluginsWithWorkers.map((plugin, i) => `{ name: "${plugin.name}", module: pluginGatsbyWorker${i}, importKey: ${i + 1} },`);
|
|
76
76
|
const output = `
|
|
77
77
|
${imports.join(`\n`)}
|
|
78
78
|
|
|
79
|
-
export const gatsbyNodes =
|
|
79
|
+
export const gatsbyNodes = [
|
|
80
80
|
${gatsbyNodeExports.join(`\n`)}
|
|
81
|
-
|
|
81
|
+
]
|
|
82
82
|
|
|
83
|
-
export const gatsbyWorkers =
|
|
83
|
+
export const gatsbyWorkers = [
|
|
84
84
|
${gatsbyWorkerExports.join(`\n`)}
|
|
85
|
-
|
|
85
|
+
]
|
|
86
86
|
|
|
87
87
|
export const flattenedPlugins =
|
|
88
88
|
${JSON.stringify(sanitizedUsedPlugins.map(plugin => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-plugins.js","names":["schemaCustomizationAPIs","Set","excludePlugins","includePlugins","schemaCustomizationPluginsPath","process","cwd","printQueryEnginePlugins","fs","remove","e","writeFile","renderQueryEnginePlugins","flattenedPlugins","store","getState","usedPlugins","filter","p","has","name","nodeAPIs","some","api","usedSubPlugins","findSubPlugins","render","relativePluginPath","resolve","slash","path","relative","dirname","uniqGatsbyNode","uniq","uniqSubPlugins","sanitizedUsedPlugins","map","plugin","pluginFilepath","subPluginPaths","undefined","pluginsWithWorkers","filterPluginsWithWorkers","subPluginModuleToImportNameMapping","Map","imports","i","importName","set","modulePath","gatsbyNodeExports","gatsbyWorkerExports","output","join","JSON","stringify","pluginOptions","value","module","subPlugin","get","replace","plugins","Boolean","requireGatsbyPlugin","err","getSubpluginsByPluginPath","parentPlugin","segments","split","roots","segment","flat","root","allFlattenedPlugins","usedSubPluginResolves","flatMap","subPlugins","subPluginPath","push","Array","from","values"],"sources":["../../../src/schema/graphql-engine/print-plugins.ts"],"sourcesContent":["/* eslint @typescript-eslint/no-unused-vars: [\"error\", { \"ignoreRestSiblings\": true }] */\nimport * as fs from \"fs-extra\"\nimport * as path from \"path\"\nimport * as _ from \"lodash\"\nimport { slash } from \"gatsby-core-utils\"\nimport { store } from \"../../redux\"\nimport { IGatsbyState } from \"../../redux/types\"\nimport { requireGatsbyPlugin } from \"../../utils/require-gatsby-plugin\"\n\nexport const schemaCustomizationAPIs = new Set([\n `setFieldsOnGraphQLNodeType`,\n `createSchemaCustomization`,\n `createResolvers`,\n])\n\nconst excludePlugins = new Set([`internal-data-bridge`])\nconst includePlugins = new Set([`gatsby-plugin-sharp`])\n\n// Emit file that imports required node APIs\nconst schemaCustomizationPluginsPath =\n process.cwd() + `/.cache/query-engine-plugins.js`\n\nexport async function printQueryEnginePlugins(): Promise<void> {\n try {\n await fs.remove(schemaCustomizationPluginsPath)\n } catch (e) {\n // no-op\n }\n return await fs.writeFile(\n schemaCustomizationPluginsPath,\n renderQueryEnginePlugins()\n )\n}\n\nfunction renderQueryEnginePlugins(): string {\n const { flattenedPlugins } = store.getState()\n const usedPlugins = flattenedPlugins.filter(\n p =>\n includePlugins.has(p.name) ||\n (!excludePlugins.has(p.name) &&\n p.nodeAPIs.some(api => schemaCustomizationAPIs.has(api)))\n )\n const usedSubPlugins = findSubPlugins(usedPlugins, flattenedPlugins)\n return render(usedPlugins, usedSubPlugins)\n}\n\nfunction relativePluginPath(resolve: string): string {\n return slash(\n path.relative(path.dirname(schemaCustomizationPluginsPath), resolve)\n )\n}\n\nfunction render(\n usedPlugins: IGatsbyState[\"flattenedPlugins\"],\n usedSubPlugins: IGatsbyState[\"flattenedPlugins\"]\n): string {\n const uniqGatsbyNode = uniq(usedPlugins)\n const uniqSubPlugins = uniq(usedSubPlugins)\n\n const sanitizedUsedPlugins = usedPlugins.map(plugin => {\n // TODO: We don't support functions in pluginOptions here\n return {\n ...plugin,\n resolve: ``,\n pluginFilepath: ``,\n subPluginPaths: undefined,\n }\n })\n\n const pluginsWithWorkers = filterPluginsWithWorkers(uniqGatsbyNode)\n\n const subPluginModuleToImportNameMapping = new Map<string, string>()\n const imports: Array<string> = [\n ...uniqGatsbyNode.map(\n (plugin, i) =>\n `import * as pluginGatsbyNode${i} from \"${relativePluginPath(\n plugin.resolve\n )}/gatsby-node\"`\n ),\n ...pluginsWithWorkers.map(\n (plugin, i) =>\n `import * as pluginGatsbyWorker${i} from \"${relativePluginPath(\n plugin.resolve\n )}/gatsby-worker\"`\n ),\n ...uniqSubPlugins.map((plugin, i) => {\n const importName = `subPlugin${i}`\n subPluginModuleToImportNameMapping.set(plugin.modulePath!, importName)\n return `import * as ${importName} from \"${relativePluginPath(\n plugin.modulePath!\n )}\"`\n }),\n ]\n const gatsbyNodeExports = uniqGatsbyNode.map(\n (plugin, i) => `\"${plugin.name}\": pluginGatsbyNode${i},`\n )\n const gatsbyWorkerExports = pluginsWithWorkers.map(\n (plugin, i) => `\"${plugin.name}\": pluginGatsbyWorker${i},`\n )\n const output = `\n${imports.join(`\\n`)}\n\nexport const gatsbyNodes = {\n${gatsbyNodeExports.join(`\\n`)}\n}\n\nexport const gatsbyWorkers = {\n${gatsbyWorkerExports.join(`\\n`)}\n}\n\nexport const flattenedPlugins =\n ${JSON.stringify(\n sanitizedUsedPlugins.map(plugin => {\n return {\n ...plugin,\n pluginOptions: _.cloneDeepWith(\n plugin.pluginOptions,\n (value: any): any => {\n if (\n typeof value === `object` &&\n value !== null &&\n value.module &&\n value.modulePath\n ) {\n const { module, modulePath, ...subPlugin } = value\n return {\n ...subPlugin,\n module: `_SKIP_START_${subPluginModuleToImportNameMapping.get(\n modulePath\n )}_SKIP_END_`,\n resolve: ``,\n pluginFilepath: ``,\n }\n }\n return undefined\n }\n ),\n }\n }),\n null,\n 2\n ).replace(/\"_SKIP_START_|_SKIP_END_\"/g, ``)}\n`\n return output\n}\n\nfunction filterPluginsWithWorkers(\n plugins: IGatsbyState[\"flattenedPlugins\"]\n): IGatsbyState[\"flattenedPlugins\"] {\n return plugins.filter(plugin => {\n try {\n return Boolean(requireGatsbyPlugin(plugin, `gatsby-worker`))\n } catch (err) {\n return false\n }\n })\n}\n\ntype ArrayElement<ArrayType extends Array<unknown>> = ArrayType extends Array<\n infer ElementType\n>\n ? ElementType\n : never\n\nfunction getSubpluginsByPluginPath(\n parentPlugin: ArrayElement<IGatsbyState[\"flattenedPlugins\"]>,\n path: string\n): IGatsbyState[\"flattenedPlugins\"] {\n const segments = path.split(`.`)\n let roots: Array<any> = [parentPlugin.pluginOptions]\n\n for (const segment of segments) {\n if (segment === `[]`) {\n roots = roots.flat()\n } else {\n roots = roots.map(root => root[segment])\n }\n }\n roots = roots.flat()\n\n return roots\n}\n\nfunction findSubPlugins(\n plugins: IGatsbyState[\"flattenedPlugins\"],\n allFlattenedPlugins: IGatsbyState[\"flattenedPlugins\"]\n): IGatsbyState[\"flattenedPlugins\"] {\n const usedSubPluginResolves = new Set<string>(\n plugins\n .flatMap(plugin => {\n if (plugin.subPluginPaths) {\n const subPlugins: IGatsbyState[\"flattenedPlugins\"] = []\n for (const subPluginPath of plugin.subPluginPaths) {\n subPlugins.push(...getSubpluginsByPluginPath(plugin, subPluginPath))\n }\n return subPlugins\n }\n\n return []\n })\n .map(plugin => plugin[`resolve`])\n .filter((p: unknown): p is string => typeof p === `string`)\n )\n return allFlattenedPlugins.filter(\n p => usedSubPluginResolves.has(p.resolve) && !!p.modulePath\n )\n}\n\nfunction uniq(\n plugins: IGatsbyState[\"flattenedPlugins\"]\n): IGatsbyState[\"flattenedPlugins\"] {\n return Array.from(new Map(plugins.map(p => [p.resolve, p])).values())\n}\n"],"mappings":";;;;;;;;;;AACA;;AACA;;AAEA;;AACA;;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AAI0D,qBAAqB,CAACzD,GAAtB,CAA0BD,CAAC,CAACU,OAA5B,KAAwC,CAAC,CAACV,CAAC,CAACgC,UAD5C,CAAP;AAGD;;AAED,SAAShB,IAAT,CACE6B,OADF,EAEoC;EAClC,OAAOkB,KAAK,CAACC,IAAN,CAAW,IAAIrC,GAAJ,CAAQkB,OAAO,CAAC1B,GAAR,CAAYnB,CAAC,IAAI,CAACA,CAAC,CAACU,OAAH,EAAYV,CAAZ,CAAjB,CAAR,EAA0CiE,MAA1C,EAAX,CAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"print-plugins.js","names":["schemaCustomizationAPIs","Set","excludePlugins","includePlugins","schemaCustomizationPluginsPath","process","cwd","printQueryEnginePlugins","fs","remove","e","writeFile","renderQueryEnginePlugins","flattenedPlugins","store","getState","usedPlugins","filter","p","has","name","nodeAPIs","some","api","usedSubPlugins","findSubPlugins","render","relativePluginPath","resolve","slash","path","relative","dirname","uniqSubPlugins","uniq","sanitizedUsedPlugins","map","plugin","i","pluginFilepath","subPluginPaths","undefined","importKey","pluginsWithWorkers","filterPluginsWithWorkers","subPluginModuleToImportNameMapping","Map","imports","importName","set","modulePath","gatsbyNodeExports","gatsbyWorkerExports","output","join","JSON","stringify","pluginOptions","value","module","subPlugin","get","replace","plugins","Boolean","requireGatsbyPlugin","err","getSubpluginsByPluginPath","parentPlugin","segments","split","roots","segment","flat","root","allFlattenedPlugins","usedSubPluginResolves","flatMap","subPlugins","subPluginPath","push","Array","from","values"],"sources":["../../../src/schema/graphql-engine/print-plugins.ts"],"sourcesContent":["/* eslint @typescript-eslint/no-unused-vars: [\"error\", { \"ignoreRestSiblings\": true }] */\nimport * as fs from \"fs-extra\"\nimport * as path from \"path\"\nimport * as _ from \"lodash\"\nimport { slash } from \"gatsby-core-utils\"\nimport { store } from \"../../redux\"\nimport { IGatsbyState } from \"../../redux/types\"\nimport { requireGatsbyPlugin } from \"../../utils/require-gatsby-plugin\"\n\nexport const schemaCustomizationAPIs = new Set([\n `setFieldsOnGraphQLNodeType`,\n `createSchemaCustomization`,\n `createResolvers`,\n])\n\nconst excludePlugins = new Set([`internal-data-bridge`])\nconst includePlugins = new Set([`gatsby-plugin-sharp`])\n\n// Emit file that imports required node APIs\nconst schemaCustomizationPluginsPath =\n process.cwd() + `/.cache/query-engine-plugins.js`\n\nexport async function printQueryEnginePlugins(): Promise<void> {\n try {\n await fs.remove(schemaCustomizationPluginsPath)\n } catch (e) {\n // no-op\n }\n return await fs.writeFile(\n schemaCustomizationPluginsPath,\n renderQueryEnginePlugins()\n )\n}\n\nfunction renderQueryEnginePlugins(): string {\n const { flattenedPlugins } = store.getState()\n const usedPlugins = flattenedPlugins.filter(\n p =>\n includePlugins.has(p.name) ||\n (!excludePlugins.has(p.name) &&\n p.nodeAPIs.some(api => schemaCustomizationAPIs.has(api)))\n )\n const usedSubPlugins = findSubPlugins(usedPlugins, flattenedPlugins)\n return render(usedPlugins, usedSubPlugins)\n}\n\nfunction relativePluginPath(resolve: string): string {\n return slash(\n path.relative(path.dirname(schemaCustomizationPluginsPath), resolve)\n )\n}\n\nfunction render(\n usedPlugins: IGatsbyState[\"flattenedPlugins\"],\n usedSubPlugins: IGatsbyState[\"flattenedPlugins\"]\n): string {\n const uniqSubPlugins = uniq(usedSubPlugins)\n\n const sanitizedUsedPlugins = usedPlugins.map((plugin, i) => {\n // TODO: We don't support functions in pluginOptions here\n return {\n ...plugin,\n resolve: ``,\n pluginFilepath: ``,\n subPluginPaths: undefined,\n importKey: i + 1,\n }\n })\n\n const pluginsWithWorkers = filterPluginsWithWorkers(usedPlugins)\n\n const subPluginModuleToImportNameMapping = new Map<string, string>()\n const imports: Array<string> = [\n ...usedPlugins.map(\n (plugin, i) =>\n `import * as pluginGatsbyNode${i} from \"${relativePluginPath(\n plugin.resolve\n )}/gatsby-node\"`\n ),\n ...pluginsWithWorkers.map(\n (plugin, i) =>\n `import * as pluginGatsbyWorker${i} from \"${relativePluginPath(\n plugin.resolve\n )}/gatsby-worker\"`\n ),\n ...uniqSubPlugins.map((plugin, i) => {\n const importName = `subPlugin${i}`\n subPluginModuleToImportNameMapping.set(plugin.modulePath!, importName)\n return `import * as ${importName} from \"${relativePluginPath(\n plugin.modulePath!\n )}\"`\n }),\n ]\n const gatsbyNodeExports = usedPlugins.map(\n (plugin, i) =>\n `{ name: \"${plugin.name}\", module: pluginGatsbyNode${i}, importKey: ${\n i + 1\n } },`\n )\n const gatsbyWorkerExports = pluginsWithWorkers.map(\n (plugin, i) =>\n `{ name: \"${plugin.name}\", module: pluginGatsbyWorker${i}, importKey: ${\n i + 1\n } },`\n )\n const output = `\n${imports.join(`\\n`)}\n\nexport const gatsbyNodes = [\n${gatsbyNodeExports.join(`\\n`)}\n]\n\nexport const gatsbyWorkers = [\n${gatsbyWorkerExports.join(`\\n`)}\n]\n\nexport const flattenedPlugins =\n ${JSON.stringify(\n sanitizedUsedPlugins.map(plugin => {\n return {\n ...plugin,\n pluginOptions: _.cloneDeepWith(\n plugin.pluginOptions,\n (value: any): any => {\n if (\n typeof value === `object` &&\n value !== null &&\n value.module &&\n value.modulePath\n ) {\n const { module, modulePath, ...subPlugin } = value\n return {\n ...subPlugin,\n module: `_SKIP_START_${subPluginModuleToImportNameMapping.get(\n modulePath\n )}_SKIP_END_`,\n resolve: ``,\n pluginFilepath: ``,\n }\n }\n return undefined\n }\n ),\n }\n }),\n null,\n 2\n ).replace(/\"_SKIP_START_|_SKIP_END_\"/g, ``)}\n`\n return output\n}\n\nfunction filterPluginsWithWorkers(\n plugins: IGatsbyState[\"flattenedPlugins\"]\n): IGatsbyState[\"flattenedPlugins\"] {\n return plugins.filter(plugin => {\n try {\n return Boolean(requireGatsbyPlugin(plugin, `gatsby-worker`))\n } catch (err) {\n return false\n }\n })\n}\n\ntype ArrayElement<ArrayType extends Array<unknown>> = ArrayType extends Array<\n infer ElementType\n>\n ? ElementType\n : never\n\nfunction getSubpluginsByPluginPath(\n parentPlugin: ArrayElement<IGatsbyState[\"flattenedPlugins\"]>,\n path: string\n): IGatsbyState[\"flattenedPlugins\"] {\n const segments = path.split(`.`)\n let roots: Array<any> = [parentPlugin.pluginOptions]\n\n for (const segment of segments) {\n if (segment === `[]`) {\n roots = roots.flat()\n } else {\n roots = roots.map(root => root[segment])\n }\n }\n roots = roots.flat()\n\n return roots\n}\n\nfunction findSubPlugins(\n plugins: IGatsbyState[\"flattenedPlugins\"],\n allFlattenedPlugins: IGatsbyState[\"flattenedPlugins\"]\n): IGatsbyState[\"flattenedPlugins\"] {\n const usedSubPluginResolves = new Set<string>(\n plugins\n .flatMap(plugin => {\n if (plugin.subPluginPaths) {\n const subPlugins: IGatsbyState[\"flattenedPlugins\"] = []\n for (const subPluginPath of plugin.subPluginPaths) {\n subPlugins.push(...getSubpluginsByPluginPath(plugin, subPluginPath))\n }\n return subPlugins\n }\n\n return []\n })\n .map(plugin => plugin[`resolve`])\n .filter((p: unknown): p is string => typeof p === `string`)\n )\n return allFlattenedPlugins.filter(\n p => usedSubPluginResolves.has(p.resolve) && !!p.modulePath\n )\n}\n\nfunction uniq(\n plugins: IGatsbyState[\"flattenedPlugins\"]\n): IGatsbyState[\"flattenedPlugins\"] {\n return Array.from(new Map(plugins.map(p => [p.resolve, p])).values())\n}\n"],"mappings":";;;;;;;;;;AACA;;AACA;;AAEA;;AACA;;AAEA;;;;;;AAPA;AASO,MAAMA,uBAAuB,GAAG,IAAIC,GAAJ,CAAQ,CAC5C,4BAD4C,EAE5C,2BAF4C,EAG5C,iBAH4C,CAAR,CAAhC;;AAMP,MAAMC,cAAc,GAAG,IAAID,GAAJ,CAAQ,CAAE,sBAAF,CAAR,CAAvB;AACA,MAAME,cAAc,GAAG,IAAIF,GAAJ,CAAQ,CAAE,qBAAF,CAAR,CAAvB,C,CAEA;;AACA,MAAMG,8BAA8B,GAClCC,OAAO,CAACC,GAAR,KAAiB,iCADnB;;AAGO,eAAeC,uBAAf,GAAwD;EAC7D,IAAI;IACF,MAAMC,EAAE,CAACC,MAAH,CAAUL,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 function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
39
39
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
40
40
|
|
|
41
41
|
async function run() {
|
|
42
|
-
// load config
|
|
42
|
+
process.env.GATSBY_SLICES = `1`; // load config
|
|
43
|
+
|
|
43
44
|
console.log(`loading config and plugins`);
|
|
44
45
|
await (0, _loadConfigAndPlugins.loadConfigAndPlugins)({
|
|
45
46
|
siteDirectory: process.cwd()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalone-regenerate.js","names":["run","console","log","loadConfigAndPlugins","siteDirectory","
|
|
1
|
+
{"version":3,"file":"standalone-regenerate.js","names":["run","process","env","GATSBY_SLICES","console","log","loadConfigAndPlugins","siteDirectory","cwd","fs","remove","e","state","store","getState","buildActivityTimer","reporter","activityTimer","start","Promise","all","createGraphqlEngineBundle","createPageSSRBundle","rootDir","components","staticQueriesByTemplate","webpackCompilationHash","isVerbose","program","verbose","err","panic","end","validateEnginesActivity","validateEngines","error","id","context"],"sources":["../../../src/schema/graphql-engine/standalone-regenerate.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/*\nthis is used for development purposes only\nto be able to run `gatsby build` once to source data\nand print schema and then just rebundle graphql-engine\nwith source file changes and test re-built engine quickly\n\nUsage:\nThere need to be at least one successful `gatsby build`\nbefore starting to use this script (warm up datastore,\ngenerate \"page-ssr\" bundle). Once that's done you can\nrun following command in test site directory:\n\n```shell\nnode node_modules/gatsby/dist/schema/graphql-engine/standalone-regenerate.js\n```\n*/\n\nimport { createGraphqlEngineBundle } from \"./bundle-webpack\"\nimport { createPageSSRBundle } from \"./../../utils/page-ssr-module/bundle-webpack\"\nimport reporter from \"gatsby-cli/lib/reporter\"\nimport { loadConfigAndPlugins } from \"../../utils/worker/child/load-config-and-plugins\"\nimport * as fs from \"fs-extra\"\nimport { store } from \"../../redux\"\nimport { validateEngines } from \"../../utils/validate-engines\"\n\nasync function run(): Promise<void> {\n process.env.GATSBY_SLICES = `1`\n // load config\n console.log(`loading config and plugins`)\n await loadConfigAndPlugins({\n siteDirectory: process.cwd(),\n })\n\n try {\n console.log(`clearing webpack cache\\n\\n`)\n // get rid of cache if it exist\n await fs.remove(process.cwd() + `/.cache/webpack/query-engine`)\n await fs.remove(process.cwd() + `/.cache/webpack/page-ssr`)\n } catch (e) {\n // eslint-disable no-empty\n }\n\n const state = store.getState()\n\n // recompile\n const buildActivityTimer = reporter.activityTimer(\n `Building Rendering Engines`\n )\n try {\n buildActivityTimer.start()\n await Promise.all([\n createGraphqlEngineBundle(process.cwd(), reporter, true),\n createPageSSRBundle({\n rootDir: process.cwd(),\n components: store.getState().components,\n staticQueriesByTemplate: state.staticQueriesByTemplate,\n webpackCompilationHash: state.webpackCompilationHash, // we set webpackCompilationHash above\n reporter,\n isVerbose: state.program.verbose,\n }),\n ])\n } catch (err) {\n buildActivityTimer.panic(err)\n } finally {\n buildActivityTimer.end()\n }\n\n // validate\n const validateEnginesActivity = reporter.activityTimer(\n `Validating Rendering Engines`\n )\n validateEnginesActivity.start()\n try {\n await validateEngines(process.cwd())\n } catch (error) {\n validateEnginesActivity.panic({ id: `98001`, context: {}, error })\n } finally {\n validateEnginesActivity.end()\n }\n\n console.log(`DONE`)\n}\n\nrun()\n"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA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;EAWD,CAbD,CAaE,OAAOC,GAAP,EAAY;IACZf,kBAAkB,CAACgB,KAAnB,CAAyBD,GAAzB;EACD,CAfD,SAeU;IACRf,kBAAkB,CAACiB,GAAnB;EACD,CAxCiC,CA0ClC;;;EACA,MAAMC,uBAAuB,GAAGjB,iBAAA,CAASC,aAAT,CAC7B,8BAD6B,CAAhC;;EAGAgB,uBAAuB,CAACf,KAAxB;;EACA,IAAI;IACF,MAAM,IAAAgB,gCAAA,EAAgBjC,OAAO,CAACO,GAAR,EAAhB,CAAN;EACD,CAFD,CAEE,OAAO2B,KAAP,EAAc;IACdF,uBAAuB,CAACF,KAAxB,CAA8B;MAAEK,EAAE,EAAG,OAAP;MAAeC,OAAO,EAAE,EAAxB;MAA4BF;IAA5B,CAA9B;EACD,CAJD,SAIU;IACRF,uBAAuB,CAACD,GAAxB;EACD;;EAED5B,OAAO,CAACC,GAAR,CAAa,MAAb;AACD;;AAEDL,GAAG"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Express } from "express";
|
|
2
2
|
import type { TrailingSlash } from "gatsby-page-utils";
|
|
3
|
-
|
|
3
|
+
export interface IPluginEntryWithParentDir {
|
|
4
4
|
resolve: string;
|
|
5
5
|
options?: Record<string, unknown>;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
parentDir: string;
|
|
7
|
+
}
|
|
8
|
+
export declare type PluginEntry = string | IPluginEntryWithParentDir;
|
|
9
|
+
export interface IGatsbyConfigInput {
|
|
8
10
|
siteMetadata?: Record<string, unknown>;
|
|
9
11
|
plugins?: Array<PluginEntry>;
|
|
10
12
|
pathPrefix?: string;
|
|
@@ -24,4 +26,3 @@ interface IGatsbyConfigInput {
|
|
|
24
26
|
* Defines how a theme object is merged with the user's config
|
|
25
27
|
*/
|
|
26
28
|
export declare const mergeGatsbyConfig: (a: IGatsbyConfigInput, b: IGatsbyConfigInput) => IGatsbyConfigInput;
|
|
27
|
-
export {};
|
|
@@ -7,33 +7,8 @@ exports.mergeGatsbyConfig = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _uniq2 = _interopRequireDefault(require("lodash/uniq"));
|
|
9
9
|
|
|
10
|
-
var _pick2 = _interopRequireDefault(require("lodash/pick"));
|
|
11
|
-
|
|
12
|
-
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
13
|
-
|
|
14
|
-
var _uniqWith2 = _interopRequireDefault(require("lodash/uniqWith"));
|
|
15
|
-
|
|
16
10
|
var _merge2 = _interopRequireDefault(require("lodash/merge"));
|
|
17
11
|
|
|
18
|
-
var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
|
|
19
|
-
|
|
20
|
-
var _isString2 = _interopRequireDefault(require("lodash/isString"));
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Normalize plugin spec before comparing so
|
|
24
|
-
* - `gatsby-plugin-name`
|
|
25
|
-
* - { resolve: `gatsby-plugin-name` }
|
|
26
|
-
* - { resolve: `gatsby-plugin-name`, options: {} }
|
|
27
|
-
* are all considered equal
|
|
28
|
-
*/
|
|
29
|
-
const normalizePluginEntry = entry => (0, _isString2.default)(entry) ? {
|
|
30
|
-
resolve: entry,
|
|
31
|
-
options: {}
|
|
32
|
-
} : (0, _isObject2.default)(entry) ? {
|
|
33
|
-
options: {},
|
|
34
|
-
...entry
|
|
35
|
-
} : entry;
|
|
36
|
-
|
|
37
12
|
const howToMerge = {
|
|
38
13
|
/**
|
|
39
14
|
* pick a truthy value by default.
|
|
@@ -43,7 +18,7 @@ const howToMerge = {
|
|
|
43
18
|
byDefault: (a, b) => b || a,
|
|
44
19
|
siteMetadata: (objA, objB) => (0, _merge2.default)({}, objA, objB),
|
|
45
20
|
// plugins are concatenated and uniq'd, so we don't get two of the same plugin value
|
|
46
|
-
plugins: (a = [], b = []) =>
|
|
21
|
+
plugins: (a = [], b = []) => a.concat(b),
|
|
47
22
|
mapping: (objA, objB) => (0, _merge2.default)({}, objA, objB)
|
|
48
23
|
};
|
|
49
24
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-gatsby-config.js","names":["
|
|
1
|
+
{"version":3,"file":"merge-gatsby-config.js","names":["howToMerge","byDefault","a","b","siteMetadata","objA","objB","plugins","concat","mapping","mergeGatsbyConfig","allGatsbyConfigKeysWithAValue","Object","keys","mergedConfig","reduce","config","gatsbyConfigKey","mergeFn"],"sources":["../../src/utils/merge-gatsby-config.ts"],"sourcesContent":["import _ from \"lodash\"\nimport { Express } from \"express\"\nimport type { TrailingSlash } from \"gatsby-page-utils\"\n\nexport interface IPluginEntryWithParentDir {\n resolve: string\n options?: Record<string, unknown>\n parentDir: string\n}\n// TODO export it in index.d.ts\nexport type PluginEntry = string | IPluginEntryWithParentDir\n\nexport interface IGatsbyConfigInput {\n siteMetadata?: Record<string, unknown>\n plugins?: Array<PluginEntry>\n pathPrefix?: string\n assetPrefix?: string\n polyfill?: boolean\n mapping?: Record<string, string>\n proxy?: {\n prefix: string\n url: string\n }\n developMiddleware?(app: Express): void\n jsxRuntime?: \"classic\" | \"automatic\"\n jsxImportSource?: string\n trailingSlash?: TrailingSlash\n}\n\ntype ConfigKey = keyof IGatsbyConfigInput\ntype Metadata = IGatsbyConfigInput[\"siteMetadata\"]\ntype Mapping = IGatsbyConfigInput[\"mapping\"]\n\nconst howToMerge = {\n /**\n * pick a truthy value by default.\n * This makes sure that if a single value is defined, that one it used.\n * We prefer the \"right\" value, because the user's config will be \"on the right\"\n */\n byDefault: (a: ConfigKey, b: ConfigKey): ConfigKey => b || a,\n siteMetadata: (objA: Metadata, objB: Metadata): Metadata =>\n _.merge({}, objA, objB),\n // plugins are concatenated and uniq'd, so we don't get two of the same plugin value\n plugins: (\n a: Array<PluginEntry> = [],\n b: Array<PluginEntry> = []\n ): Array<PluginEntry> => a.concat(b),\n mapping: (objA: Mapping, objB: Mapping): Mapping => _.merge({}, objA, objB),\n} as const\n\n/**\n * Defines how a theme object is merged with the user's config\n */\nexport const mergeGatsbyConfig = (\n a: IGatsbyConfigInput,\n b: IGatsbyConfigInput\n): IGatsbyConfigInput => {\n // a and b are gatsby configs, If they have keys, that means there are values to merge\n const allGatsbyConfigKeysWithAValue = _.uniq(\n Object.keys(a).concat(Object.keys(b))\n ) as Array<ConfigKey>\n\n // reduce the array of mergable keys into a single gatsby config object\n const mergedConfig = allGatsbyConfigKeysWithAValue.reduce(\n (config, gatsbyConfigKey) => {\n // choose a merge function for the config key if there's one defined,\n // otherwise use the default value merge function\n const mergeFn = howToMerge[gatsbyConfigKey] || howToMerge.byDefault\n return {\n ...config,\n [gatsbyConfigKey]: mergeFn(a[gatsbyConfigKey], b[gatsbyConfigKey]),\n }\n },\n {} as IGatsbyConfigInput\n )\n\n // return the fully merged config\n return mergedConfig\n}\n"],"mappings":";;;;;;;;;;;AAiCA,MAAMA,UAAU,GAAG;EACjB;AACF;AACA;AACA;AACA;EACEC,SAAS,EAAE,CAACC,CAAD,EAAeC,CAAf,KAA2CA,CAAC,IAAID,CAN1C;EAOjBE,YAAY,EAAE,CAACC,IAAD,EAAiBC,IAAjB,KACZ,qBAAQ,EAAR,EAAYD,IAAZ,EAAkBC,IAAlB,CARe;EASjB;EACAC,OAAO,EAAE,CACPL,CAAqB,GAAG,EADjB,EAEPC,CAAqB,GAAG,EAFjB,KAGgBD,CAAC,CAACM,MAAF,CAASL,CAAT,CAbR;EAcjBM,OAAO,EAAE,CAACJ,IAAD,EAAgBC,IAAhB,KAA2C,qBAAQ,EAAR,EAAYD,IAAZ,EAAkBC,IAAlB;AAdnC,CAAnB;AAiBA;AACA;AACA;;AACO,MAAMI,iBAAiB,GAAG,CAC/BR,CAD+B,EAE/BC,CAF+B,KAGR;EACvB;EACA,MAAMQ,6BAA6B,GAAG,oBACpCC,MAAM,CAACC,IAAP,CAAYX,CAAZ,EAAeM,MAAf,CAAsBI,MAAM,CAACC,IAAP,CAAYV,CAAZ,CAAtB,CADoC,CAAtC,CAFuB,CAMvB;;EACA,MAAMW,YAAY,GAAGH,6BAA6B,CAACI,MAA9B,CACnB,CAACC,MAAD,EAASC,eAAT,KAA6B;IAC3B;IACA;IACA,MAAMC,OAAO,GAAGlB,UAAU,CAACiB,eAAD,CAAV,IAA+BjB,UAAU,CAACC,SAA1D;IACA,OAAO,EACL,GAAGe,MADE;MAEL,CAACC,eAAD,GAAmBC,OAAO,CAAChB,CAAC,CAACe,eAAD,CAAF,EAAqBd,CAAC,CAACc,eAAD,CAAtB;IAFrB,CAAP;EAID,CATkB,EAUnB,EAVmB,CAArB,CAPuB,CAoBvB;;EACA,OAAOH,YAAP;AACD,CAzBM"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export declare function setGatsbyPluginCache(plugin: {
|
|
2
2
|
name: string;
|
|
3
3
|
resolve: string;
|
|
4
|
+
importKey?: string;
|
|
4
5
|
}, module: string, moduleObject: any): void;
|
|
5
6
|
export declare function requireGatsbyPlugin(plugin: {
|
|
6
7
|
name: string;
|
|
7
8
|
resolve: string;
|
|
8
9
|
resolvedCompiledGatsbyNode?: string;
|
|
10
|
+
importKey?: string;
|
|
9
11
|
}, module: string): any;
|
|
@@ -8,10 +8,16 @@ const pluginModuleCache = new Map();
|
|
|
8
8
|
function setGatsbyPluginCache(plugin, module, moduleObject) {
|
|
9
9
|
const key = `${plugin.name}/${module}`;
|
|
10
10
|
pluginModuleCache.set(key, moduleObject);
|
|
11
|
+
const additionalPrefix = plugin.importKey || plugin.resolve;
|
|
12
|
+
|
|
13
|
+
if (additionalPrefix) {
|
|
14
|
+
const key = `${additionalPrefix}/${module}`;
|
|
15
|
+
pluginModuleCache.set(key, moduleObject);
|
|
16
|
+
}
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
function requireGatsbyPlugin(plugin, module) {
|
|
14
|
-
const key = `${plugin.name}/${module}`;
|
|
20
|
+
const key = `${plugin.importKey || plugin.resolve || plugin.name}/${module}`;
|
|
15
21
|
let pluginModule = pluginModuleCache.get(key);
|
|
16
22
|
|
|
17
23
|
if (!pluginModule) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-gatsby-plugin.js","names":["pluginModuleCache","Map","setGatsbyPluginCache","plugin","module","moduleObject","key","name","set","requireGatsbyPlugin","pluginModule","get","require","resolvedCompiledGatsbyNode"
|
|
1
|
+
{"version":3,"file":"require-gatsby-plugin.js","names":["pluginModuleCache","Map","setGatsbyPluginCache","plugin","module","moduleObject","key","name","set","additionalPrefix","importKey","resolve","requireGatsbyPlugin","pluginModule","get","require","resolvedCompiledGatsbyNode"],"sources":["../../src/utils/require-gatsby-plugin.ts"],"sourcesContent":["const pluginModuleCache = new Map<string, any>()\n\nexport function setGatsbyPluginCache(\n plugin: { name: string; resolve: string; importKey?: string },\n module: string,\n moduleObject: any\n): void {\n const key = `${plugin.name}/${module}`\n pluginModuleCache.set(key, moduleObject)\n\n const additionalPrefix = plugin.importKey || plugin.resolve\n if (additionalPrefix) {\n const key = `${additionalPrefix}/${module}`\n pluginModuleCache.set(key, moduleObject)\n }\n}\n\nexport function requireGatsbyPlugin(\n plugin: {\n name: string\n resolve: string\n resolvedCompiledGatsbyNode?: string\n importKey?: string\n },\n module: string\n): any {\n const key = `${plugin.importKey || plugin.resolve || plugin.name}/${module}`\n\n let pluginModule = pluginModuleCache.get(key)\n if (!pluginModule) {\n pluginModule = require(module === `gatsby-node` &&\n plugin.resolvedCompiledGatsbyNode\n ? plugin.resolvedCompiledGatsbyNode\n : `${plugin.resolve}/${module}`)\n pluginModuleCache.set(key, pluginModule)\n }\n return pluginModule\n}\n"],"mappings":";;;;;AAAA,MAAMA,iBAAiB,GAAG,IAAIC,GAAJ,EAA1B;;AAEO,SAASC,oBAAT,CACLC,MADK,EAELC,MAFK,EAGLC,YAHK,EAIC;EACN,MAAMC,GAAG,GAAI,GAAEH,MAAM,CAACI,IAAK,IAAGH,MAAO,EAArC;EACAJ,iBAAiB,CAACQ,GAAlB,CAAsBF,GAAtB,EAA2BD,YAA3B;EAEA,MAAMI,gBAAgB,GAAGN,MAAM,CAACO,SAAP,IAAoBP,MAAM,CAACQ,OAApD;;EACA,IAAIF,gBAAJ,EAAsB;IACpB,MAAMH,GAAG,GAAI,GAAEG,gBAAiB,IAAGL,MAAO,EAA1C;IACAJ,iBAAiB,CAACQ,GAAlB,CAAsBF,GAAtB,EAA2BD,YAA3B;EACD;AACF;;AAEM,SAASO,mBAAT,CACLT,MADK,EAOLC,MAPK,EAQA;EACL,MAAME,GAAG,GAAI,GAAEH,MAAM,CAACO,SAAP,IAAoBP,MAAM,CAACQ,OAA3B,IAAsCR,MAAM,CAACI,IAAK,IAAGH,MAAO,EAA3E;EAEA,IAAIS,YAAY,GAAGb,iBAAiB,CAACc,GAAlB,CAAsBR,GAAtB,CAAnB;;EACA,IAAI,CAACO,YAAL,EAAmB;IACjBA,YAAY,GAAGE,OAAO,CAACX,MAAM,KAAM,aAAZ,IACrBD,MAAM,CAACa,0BADc,GAEnBb,MAAM,CAACa,0BAFY,GAGlB,GAAEb,MAAM,CAACQ,OAAQ,IAAGP,MAAO,EAHV,CAAtB;IAIAJ,iBAAiB,CAACQ,GAAlB,CAAsBF,GAAtB,EAA2BO,YAA3B;EACD;;EACD,OAAOA,YAAP;AACD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby",
|
|
3
3
|
"description": "Blazing fast modern site generator for React",
|
|
4
|
-
"version": "4.25.
|
|
4
|
+
"version": "4.25.2",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gatsby": "./cli.js"
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
"webpack-stats-plugin": "^1.0.3",
|
|
175
175
|
"webpack-virtual-modules": "^0.3.2",
|
|
176
176
|
"xstate": "4.32.1",
|
|
177
|
-
"yaml-loader": "^0.
|
|
177
|
+
"yaml-loader": "^0.8.0"
|
|
178
178
|
},
|
|
179
179
|
"devDependencies": {
|
|
180
180
|
"@babel/cli": "^7.15.4",
|
|
@@ -277,5 +277,5 @@
|
|
|
277
277
|
"yargs": {
|
|
278
278
|
"boolean-negation": false
|
|
279
279
|
},
|
|
280
|
-
"gitHead": "
|
|
280
|
+
"gitHead": "13bf518f95eed9373da0ae93a13ce774a4a3fc17"
|
|
281
281
|
}
|