gatsby 5.3.0-next.3 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cache-dir/commonjs/develop-static-entry.js +0 -4
- package/cache-dir/commonjs/loader.js +1 -1
- package/cache-dir/commonjs/ssr-develop-static-entry.js +1 -5
- package/cache-dir/commonjs/static-entry.js +1 -4
- package/cache-dir/develop-static-entry.js +0 -4
- package/cache-dir/loader.js +1 -1
- package/cache-dir/ssr-develop-static-entry.js +0 -4
- package/cache-dir/static-entry.js +0 -4
- package/dist/bootstrap/__mocks__/get-config/{ts-dir → ts}/gatsby-config.d.ts +0 -0
- package/dist/bootstrap/get-config-file.js +143 -99
- package/dist/bootstrap/get-config-file.js.map +1 -1
- package/dist/bootstrap/load-plugins/index.js +7 -6
- package/dist/bootstrap/load-plugins/index.js.map +1 -1
- package/dist/bootstrap/load-plugins/validate.d.ts +4 -3
- package/dist/bootstrap/load-plugins/validate.js +16 -8
- package/dist/bootstrap/load-plugins/validate.js.map +1 -1
- package/dist/bootstrap/resolve-js-file-path.d.ts +8 -0
- package/dist/bootstrap/resolve-js-file-path.js +51 -0
- package/dist/bootstrap/resolve-js-file-path.js.map +1 -0
- package/dist/bootstrap/resolve-module-exports.d.ts +16 -10
- package/dist/bootstrap/resolve-module-exports.js +36 -23
- package/dist/bootstrap/resolve-module-exports.js.map +1 -1
- package/dist/commands/build-html.js +6 -22
- package/dist/commands/build-html.js.map +1 -1
- package/dist/query/query-runner.js +3 -13
- package/dist/query/query-runner.js.map +1 -1
- package/dist/schema/graphql-engine/entry.js +3 -3
- package/dist/schema/graphql-engine/entry.js.map +1 -1
- package/dist/schema/graphql-engine/print-plugins.js +21 -12
- package/dist/schema/graphql-engine/print-plugins.js.map +1 -1
- package/dist/services/initialize.js +6 -2
- package/dist/services/initialize.js.map +1 -1
- package/dist/utils/api-runner-node.js +66 -65
- package/dist/utils/api-runner-node.js.map +1 -1
- package/dist/utils/{require-gatsby-plugin.d.ts → import-gatsby-plugin.d.ts} +2 -2
- package/dist/utils/import-gatsby-plugin.js +43 -0
- package/dist/utils/import-gatsby-plugin.js.map +1 -0
- package/dist/utils/jobs/manager.js +20 -20
- package/dist/utils/jobs/manager.js.map +1 -1
- package/dist/utils/jobs/types.js +7 -1
- package/dist/utils/jobs/types.js.map +1 -1
- package/dist/utils/jobs/worker-messaging.js +11 -3
- package/dist/utils/jobs/worker-messaging.js.map +1 -1
- package/dist/utils/module-resolver.d.ts +1 -2
- package/dist/utils/module-resolver.js.map +1 -1
- package/dist/utils/page-data.d.ts +12 -0
- package/dist/utils/page-data.js +28 -0
- package/dist/utils/page-data.js.map +1 -1
- package/dist/utils/parcel/compile-gatsby-files.js +1 -1
- package/dist/utils/parcel/compile-gatsby-files.js.map +1 -1
- package/dist/utils/test-import-error.d.ts +1 -0
- package/dist/utils/test-import-error.js +20 -0
- package/dist/utils/test-import-error.js.map +1 -0
- package/dist/utils/worker/child/render-html.js +3 -21
- package/dist/utils/worker/child/render-html.js.map +1 -1
- package/dist/utils/worker/messaging.d.ts +10 -2
- package/dist/utils/worker/messaging.js.map +1 -1
- package/package.json +22 -22
- package/dist/utils/require-gatsby-plugin.js +0 -24
- package/dist/utils/require-gatsby-plugin.js.map +0 -1
- package/dist/utils/test-require-error.d.ts +0 -1
- package/dist/utils/test-require-error.js +0 -21
- package/dist/utils/test-require-error.js.map +0 -1
|
@@ -17,10 +17,6 @@ var _apiRunnerSsr = require("./api-runner-ssr");
|
|
|
17
17
|
var _asyncRequires = _interopRequireDefault(require("$virtual/async-requires"));
|
|
18
18
|
|
|
19
19
|
/* global BROWSER_ESM_ONLY */
|
|
20
|
-
// import testRequireError from "./test-require-error"
|
|
21
|
-
// For some extremely mysterious reason, webpack adds the above module *after*
|
|
22
|
-
// this module so that when this code runs, testRequireError is undefined.
|
|
23
|
-
// So in the meantime, we'll just inline it.
|
|
24
20
|
const testRequireError = (moduleName, err) => {
|
|
25
21
|
const regex = new RegExp(`Error: Cannot find module\\s.${moduleName}`);
|
|
26
22
|
const firstLine = err.toString().split(`\n`)[0];
|
|
@@ -354,7 +354,7 @@ class BaseLoader {
|
|
|
354
354
|
});
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
const url =
|
|
357
|
+
const url = `${__PATH_PREFIX__}/slice-data/${sliceName}.json`;
|
|
358
358
|
return doFetch(url, `GET`).then(res => {
|
|
359
359
|
const jsonPayload = JSON.parse(res.responseText);
|
|
360
360
|
this.slicesDataDb.set(sliceName, jsonPayload);
|
|
@@ -42,11 +42,7 @@ var _loader = require("./loader");
|
|
|
42
42
|
|
|
43
43
|
/* global BROWSER_ESM_ONLY */
|
|
44
44
|
// prefer default export if available
|
|
45
|
-
const preferDefault = m => m && m.default || m;
|
|
46
|
-
// For some extremely mysterious reason, webpack adds the above module *after*
|
|
47
|
-
// this module so that when this code runs, testRequireError is undefined.
|
|
48
|
-
// So in the meantime, we'll just inline it.
|
|
49
|
-
|
|
45
|
+
const preferDefault = m => m && m.default || m;
|
|
50
46
|
|
|
51
47
|
const testRequireError = (moduleName, err) => {
|
|
52
48
|
const regex = new RegExp(`Error: Cannot find module\\s.${moduleName}`);
|
|
@@ -86,10 +86,7 @@ const {
|
|
|
86
86
|
|
|
87
87
|
const {
|
|
88
88
|
join
|
|
89
|
-
} = path.posix;
|
|
90
|
-
// For some extremely mysterious reason, webpack adds the above module *after*
|
|
91
|
-
// this module so that when this code runs, testRequireError is undefined.
|
|
92
|
-
// So in the meantime, we'll just inline it.
|
|
89
|
+
} = path.posix;
|
|
93
90
|
|
|
94
91
|
const testRequireError = (moduleName, err) => {
|
|
95
92
|
const regex = new RegExp(`Error: Cannot find module\\s.${moduleName}`);
|
|
@@ -5,10 +5,6 @@ import { merge } from "lodash"
|
|
|
5
5
|
import { apiRunner } from "./api-runner-ssr"
|
|
6
6
|
import asyncRequires from "$virtual/async-requires"
|
|
7
7
|
|
|
8
|
-
// import testRequireError from "./test-require-error"
|
|
9
|
-
// For some extremely mysterious reason, webpack adds the above module *after*
|
|
10
|
-
// this module so that when this code runs, testRequireError is undefined.
|
|
11
|
-
// So in the meantime, we'll just inline it.
|
|
12
8
|
const testRequireError = (moduleName, err) => {
|
|
13
9
|
const regex = new RegExp(`Error: Cannot find module\\s.${moduleName}`)
|
|
14
10
|
const firstLine = err.toString().split(`\n`)[0]
|
package/cache-dir/loader.js
CHANGED
|
@@ -327,7 +327,7 @@ export class BaseLoader {
|
|
|
327
327
|
return Promise.resolve({ sliceName, jsonPayload })
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
const url =
|
|
330
|
+
const url = `${__PATH_PREFIX__}/slice-data/${sliceName}.json`
|
|
331
331
|
return doFetch(url, `GET`).then(res => {
|
|
332
332
|
const jsonPayload = JSON.parse(res.responseText)
|
|
333
333
|
|
|
@@ -16,10 +16,6 @@ import { getStaticQueryResults } from "./loader"
|
|
|
16
16
|
// prefer default export if available
|
|
17
17
|
const preferDefault = m => (m && m.default) || m
|
|
18
18
|
|
|
19
|
-
// import testRequireError from "./test-require-error"
|
|
20
|
-
// For some extremely mysterious reason, webpack adds the above module *after*
|
|
21
|
-
// this module so that when this code runs, testRequireError is undefined.
|
|
22
|
-
// So in the meantime, we'll just inline it.
|
|
23
19
|
const testRequireError = (moduleName, err) => {
|
|
24
20
|
const regex = new RegExp(`Error: Cannot find module\\s.${moduleName}`)
|
|
25
21
|
const firstLine = err.toString().split(`\n`)[0]
|
|
@@ -28,10 +28,6 @@ const { ServerSliceRenderer } = require(`./slice/server-slice-renderer`)
|
|
|
28
28
|
// we want to force posix-style joins, so Windows doesn't produce backslashes for urls
|
|
29
29
|
const { join } = path.posix
|
|
30
30
|
|
|
31
|
-
// const testRequireError = require("./test-require-error")
|
|
32
|
-
// For some extremely mysterious reason, webpack adds the above module *after*
|
|
33
|
-
// this module so that when this code runs, testRequireError is undefined.
|
|
34
|
-
// So in the meantime, we'll just inline it.
|
|
35
31
|
const testRequireError = (moduleName, err) => {
|
|
36
32
|
const regex = new RegExp(`Error: Cannot find module\\s.${moduleName}`)
|
|
37
33
|
const firstLine = err.toString().split(`\n`)[0]
|
|
File without changes
|
|
@@ -7,133 +7,177 @@ exports.getConfigFile = getConfigFile;
|
|
|
7
7
|
|
|
8
8
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _testImportError = require("../utils/test-import-error");
|
|
11
11
|
|
|
12
12
|
var _reporter = _interopRequireDefault(require("gatsby-cli/lib/reporter"));
|
|
13
13
|
|
|
14
14
|
var _path = _interopRequireDefault(require("path"));
|
|
15
15
|
|
|
16
|
-
var _fsExistsCached = require("fs-exists-cached");
|
|
17
|
-
|
|
18
16
|
var _compileGatsbyFiles = require("../utils/parcel/compile-gatsby-files");
|
|
19
17
|
|
|
20
18
|
var _isNearMatch = require("../utils/is-near-match");
|
|
21
19
|
|
|
20
|
+
var _resolveJsFilePath = require("./resolve-js-file-path");
|
|
21
|
+
|
|
22
|
+
var _preferDefault = require("./prefer-default");
|
|
23
|
+
|
|
22
24
|
async function getConfigFile(siteDirectory, configName, distance = 3) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
const compiledResult = await attemptImportCompiled(siteDirectory, configName);
|
|
26
|
+
|
|
27
|
+
if (compiledResult !== null && compiledResult !== void 0 && compiledResult.configModule && compiledResult !== null && compiledResult !== void 0 && compiledResult.configFilePath) {
|
|
28
|
+
return compiledResult;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const uncompiledResult = await attemptImportUncompiled(siteDirectory, configName, distance);
|
|
32
|
+
return uncompiledResult || {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function attemptImport(siteDirectory, configPath) {
|
|
36
|
+
const configFilePath = await (0, _resolveJsFilePath.resolveJSFilepath)({
|
|
37
|
+
rootDir: siteDirectory,
|
|
38
|
+
filePath: configPath
|
|
39
|
+
}); // The file does not exist, no sense trying to import it
|
|
40
|
+
|
|
41
|
+
if (!configFilePath) {
|
|
42
|
+
return {
|
|
43
|
+
configFilePath: ``,
|
|
44
|
+
configModule: undefined
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const importedModule = await import(configFilePath);
|
|
49
|
+
const configModule = (0, _preferDefault.preferDefault)(importedModule);
|
|
50
|
+
return {
|
|
51
|
+
configFilePath,
|
|
52
|
+
configModule
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function attemptImportCompiled(siteDirectory, configName) {
|
|
57
|
+
let compiledResult;
|
|
26
58
|
|
|
27
59
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} catch (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
const compiledConfigPath = _path.default.join(`${siteDirectory}/${_compileGatsbyFiles.COMPILED_CACHE_DIR}`, configName);
|
|
61
|
+
|
|
62
|
+
compiledResult = await attemptImport(siteDirectory, compiledConfigPath);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
_reporter.default.panic({
|
|
65
|
+
id: `11902`,
|
|
66
|
+
error: error,
|
|
67
|
+
context: {
|
|
68
|
+
configName,
|
|
69
|
+
message: error.message
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return compiledResult;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function attemptImportUncompiled(siteDirectory, configName, distance) {
|
|
78
|
+
var _uncompiledResult;
|
|
79
|
+
|
|
80
|
+
let uncompiledResult;
|
|
81
|
+
|
|
82
|
+
const uncompiledConfigPath = _path.default.join(siteDirectory, configName);
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
uncompiledResult = await attemptImport(siteDirectory, uncompiledConfigPath);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (!(0, _testImportError.testImportError)(uncompiledConfigPath, error)) {
|
|
43
88
|
_reporter.default.panic({
|
|
44
|
-
id: `
|
|
45
|
-
error
|
|
89
|
+
id: `10123`,
|
|
90
|
+
error,
|
|
46
91
|
context: {
|
|
47
92
|
configName,
|
|
48
|
-
message:
|
|
93
|
+
message: error.message
|
|
49
94
|
}
|
|
50
95
|
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if ((_uncompiledResult = uncompiledResult) !== null && _uncompiledResult !== void 0 && _uncompiledResult.configFilePath) {
|
|
100
|
+
return uncompiledResult;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const error = new Error(`Cannot find package '${uncompiledConfigPath}'`);
|
|
104
|
+
const {
|
|
105
|
+
tsConfig,
|
|
106
|
+
nearMatch
|
|
107
|
+
} = await checkTsAndNearMatch(siteDirectory, configName, distance); // gatsby-config.ts exists but compiled gatsby-config.js does not
|
|
108
|
+
|
|
109
|
+
if (tsConfig) {
|
|
110
|
+
_reporter.default.panic({
|
|
111
|
+
id: `10127`,
|
|
112
|
+
error,
|
|
113
|
+
context: {
|
|
114
|
+
configName
|
|
70
115
|
}
|
|
116
|
+
});
|
|
117
|
+
} // gatsby-config is misnamed
|
|
71
118
|
|
|
72
|
-
const files = await _fsExtra.default.readdir(siteDirectory);
|
|
73
|
-
let tsConfig = false;
|
|
74
|
-
let nearMatch = ``;
|
|
75
119
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
120
|
+
if (nearMatch) {
|
|
121
|
+
const isTSX = nearMatch.endsWith(`.tsx`);
|
|
80
122
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
123
|
+
_reporter.default.panic({
|
|
124
|
+
id: `10124`,
|
|
125
|
+
error,
|
|
126
|
+
context: {
|
|
127
|
+
configName,
|
|
128
|
+
nearMatch,
|
|
129
|
+
isTSX
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
} // gatsby-config is incorrectly located in src directory
|
|
85
133
|
|
|
86
|
-
if (name === configName && ext === `.ts`) {
|
|
87
|
-
tsConfig = true;
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
134
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
configName
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
} // gatsby-config is misnamed
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (nearMatch) {
|
|
109
|
-
const isTSX = nearMatch.endsWith(`.tsx`);
|
|
110
|
-
|
|
111
|
-
_reporter.default.panic({
|
|
112
|
-
id: `10124`,
|
|
113
|
-
error: innerError,
|
|
114
|
-
context: {
|
|
115
|
-
configName,
|
|
116
|
-
nearMatch,
|
|
117
|
-
isTSX
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
} // gatsby-config.js is incorrectly located in src/gatsby-config.js
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if ((0, _fsExistsCached.sync)(_path.default.join(siteDirectory, `src`, configName + `.js`))) {
|
|
124
|
-
_reporter.default.panic({
|
|
125
|
-
id: `10125`,
|
|
126
|
-
context: {
|
|
127
|
-
configName
|
|
128
|
-
}
|
|
129
|
-
});
|
|
135
|
+
const isInSrcDir = await (0, _resolveJsFilePath.resolveJSFilepath)({
|
|
136
|
+
rootDir: siteDirectory,
|
|
137
|
+
filePath: _path.default.join(siteDirectory, `src`, configName),
|
|
138
|
+
warn: false
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (isInSrcDir) {
|
|
142
|
+
_reporter.default.panic({
|
|
143
|
+
id: `10125`,
|
|
144
|
+
context: {
|
|
145
|
+
configName
|
|
130
146
|
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return uncompiledResult;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function checkTsAndNearMatch(siteDirectory, configName, distance) {
|
|
154
|
+
const files = await _fsExtra.default.readdir(siteDirectory);
|
|
155
|
+
let tsConfig = false;
|
|
156
|
+
let nearMatch = ``;
|
|
157
|
+
|
|
158
|
+
for (const file of files) {
|
|
159
|
+
if (tsConfig || nearMatch) {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const {
|
|
164
|
+
name,
|
|
165
|
+
ext
|
|
166
|
+
} = _path.default.parse(file);
|
|
167
|
+
|
|
168
|
+
if (name === configName && ext === `.ts`) {
|
|
169
|
+
tsConfig = true;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if ((0, _isNearMatch.isNearMatch)(name, configName, distance)) {
|
|
174
|
+
nearMatch = file;
|
|
131
175
|
}
|
|
132
176
|
}
|
|
133
177
|
|
|
134
178
|
return {
|
|
135
|
-
|
|
136
|
-
|
|
179
|
+
tsConfig,
|
|
180
|
+
nearMatch
|
|
137
181
|
};
|
|
138
182
|
}
|
|
139
183
|
//# sourceMappingURL=get-config-file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-config-file.js","names":["getConfigFile","siteDirectory","configName","distance","
|
|
1
|
+
{"version":3,"file":"get-config-file.js","names":["getConfigFile","siteDirectory","configName","distance","compiledResult","attemptImportCompiled","configModule","configFilePath","uncompiledResult","attemptImportUncompiled","attemptImport","configPath","resolveJSFilepath","rootDir","filePath","undefined","importedModule","preferDefault","compiledConfigPath","path","join","COMPILED_CACHE_DIR","error","report","panic","id","context","message","uncompiledConfigPath","testImportError","Error","tsConfig","nearMatch","checkTsAndNearMatch","isTSX","endsWith","isInSrcDir","warn","files","fs","readdir","file","name","ext","parse","isNearMatch"],"sources":["../../src/bootstrap/get-config-file.ts"],"sourcesContent":["import fs from \"fs-extra\"\nimport { testImportError } from \"../utils/test-import-error\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport path from \"path\"\nimport { COMPILED_CACHE_DIR } from \"../utils/parcel/compile-gatsby-files\"\nimport { isNearMatch } from \"../utils/is-near-match\"\nimport { resolveJSFilepath } from \"./resolve-js-file-path\"\nimport { preferDefault } from \"./prefer-default\"\n\nexport async function getConfigFile(\n siteDirectory: string,\n configName: string,\n distance: number = 3\n): Promise<{\n configModule: any\n configFilePath: string\n}> {\n const compiledResult = await attemptImportCompiled(siteDirectory, configName)\n\n if (compiledResult?.configModule && compiledResult?.configFilePath) {\n return compiledResult\n }\n\n const uncompiledResult = await attemptImportUncompiled(\n siteDirectory,\n configName,\n distance\n )\n\n return uncompiledResult || {}\n}\n\nasync function attemptImport(\n siteDirectory: string,\n configPath: string\n): Promise<{\n configModule: unknown\n configFilePath: string\n}> {\n const configFilePath = await resolveJSFilepath({\n rootDir: siteDirectory,\n filePath: configPath,\n })\n\n // The file does not exist, no sense trying to import it\n if (!configFilePath) {\n return { configFilePath: ``, configModule: undefined }\n }\n\n const importedModule = await import(configFilePath)\n const configModule = preferDefault(importedModule)\n\n return { configFilePath, configModule }\n}\n\nasync function attemptImportCompiled(\n siteDirectory: string,\n configName: string\n): Promise<{\n configModule: unknown\n configFilePath: string\n}> {\n let compiledResult\n\n try {\n const compiledConfigPath = path.join(\n `${siteDirectory}/${COMPILED_CACHE_DIR}`,\n configName\n )\n compiledResult = await attemptImport(siteDirectory, compiledConfigPath)\n } catch (error) {\n report.panic({\n id: `11902`,\n error: error,\n context: {\n configName,\n message: error.message,\n },\n })\n }\n\n return compiledResult\n}\n\nasync function attemptImportUncompiled(\n siteDirectory: string,\n configName: string,\n distance: number\n): Promise<{\n configModule: unknown\n configFilePath: string\n}> {\n let uncompiledResult\n\n const uncompiledConfigPath = path.join(siteDirectory, configName)\n\n try {\n uncompiledResult = await attemptImport(siteDirectory, uncompiledConfigPath)\n } catch (error) {\n if (!testImportError(uncompiledConfigPath, error)) {\n report.panic({\n id: `10123`,\n error,\n context: {\n configName,\n message: error.message,\n },\n })\n }\n }\n\n if (uncompiledResult?.configFilePath) {\n return uncompiledResult\n }\n\n const error = new Error(`Cannot find package '${uncompiledConfigPath}'`)\n\n const { tsConfig, nearMatch } = await checkTsAndNearMatch(\n siteDirectory,\n configName,\n distance\n )\n\n // gatsby-config.ts exists but compiled gatsby-config.js does not\n if (tsConfig) {\n report.panic({\n id: `10127`,\n error,\n context: {\n configName,\n },\n })\n }\n\n // gatsby-config is misnamed\n if (nearMatch) {\n const isTSX = nearMatch.endsWith(`.tsx`)\n report.panic({\n id: `10124`,\n error,\n context: {\n configName,\n nearMatch,\n isTSX,\n },\n })\n }\n\n // gatsby-config is incorrectly located in src directory\n const isInSrcDir = await resolveJSFilepath({\n rootDir: siteDirectory,\n filePath: path.join(siteDirectory, `src`, configName),\n warn: false,\n })\n\n if (isInSrcDir) {\n report.panic({\n id: `10125`,\n context: {\n configName,\n },\n })\n }\n\n return uncompiledResult\n}\n\nasync function checkTsAndNearMatch(\n siteDirectory: string,\n configName: string,\n distance: number\n): Promise<{\n tsConfig: boolean\n nearMatch: string\n}> {\n const files = await fs.readdir(siteDirectory)\n\n let tsConfig = false\n let nearMatch = ``\n\n for (const file of files) {\n if (tsConfig || nearMatch) {\n break\n }\n\n const { name, ext } = path.parse(file)\n\n if (name === configName && ext === `.ts`) {\n tsConfig = true\n break\n }\n\n if (isNearMatch(name, configName, distance)) {\n nearMatch = file\n }\n }\n\n return {\n tsConfig,\n nearMatch,\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,eAAeA,a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 @@ async function loadPlugins(rawConfig, rootDir) {
|
|
|
43
43
|
const pluginArray = (0, _flattenPlugins.flattenPlugins)(pluginInfos); // Work out which plugins use which APIs, including those which are not
|
|
44
44
|
// valid Gatsby APIs, aka 'badExports'
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
let {
|
|
47
|
+
flattenedPlugins,
|
|
48
|
+
badExports
|
|
49
|
+
} = await (0, _validate.collatePluginAPIs)({
|
|
47
50
|
currentAPIs,
|
|
48
|
-
flattenedPlugins: pluginArray
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
let flattenedPlugins = x.flattenedPlugins;
|
|
52
|
-
const badExports = x.badExports; // Show errors for any non-Gatsby APIs exported from plugins
|
|
51
|
+
flattenedPlugins: pluginArray,
|
|
52
|
+
rootDir
|
|
53
|
+
}); // Show errors for any non-Gatsby APIs exported from plugins
|
|
53
54
|
|
|
54
55
|
await (0, _validate.handleBadExports)({
|
|
55
56
|
currentAPIs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["loadPlugins","rawConfig","rootDir","config","normalizeConfig","validateConfigPluginsOptions","currentAPIs","getAPI","browser","browserAPIs","node","nodeAPIs","ssr","ssrAPIs","pluginInfos","loadInternalPlugins","pluginArray","flattenPlugins","
|
|
1
|
+
{"version":3,"file":"index.js","names":["loadPlugins","rawConfig","rootDir","config","normalizeConfig","validateConfigPluginsOptions","currentAPIs","getAPI","browser","browserAPIs","node","nodeAPIs","ssr","ssrAPIs","pluginInfos","loadInternalPlugins","pluginArray","flattenPlugins","flattenedPlugins","badExports","collatePluginAPIs","handleBadExports","handleMultipleReplaceRenderers","store","dispatch","type","payload"],"sources":["../../../src/bootstrap/load-plugins/index.ts"],"sourcesContent":["import { store } from \"../../redux\"\nimport { IGatsbyState } from \"../../redux/types\"\nimport * as nodeAPIs from \"../../utils/api-node-docs\"\nimport * as browserAPIs from \"../../utils/api-browser-docs\"\nimport ssrAPIs from \"../../../cache-dir/api-ssr-docs\"\nimport { loadInternalPlugins } from \"./load-internal-plugins\"\nimport {\n collatePluginAPIs,\n handleBadExports,\n handleMultipleReplaceRenderers,\n validateConfigPluginsOptions,\n} from \"./validate\"\nimport { IFlattenedPlugin } from \"./types\"\nimport { normalizeConfig } from \"./utils/normalize\"\nimport { getAPI } from \"./utils/get-api\"\nimport { flattenPlugins } from \"./utils/flatten-plugins\"\nimport { IGatsbyConfig } from \"../../internal\"\n\nexport async function loadPlugins(\n rawConfig: IGatsbyConfig,\n rootDir: string\n): Promise<Array<IFlattenedPlugin>> {\n // Turn all strings in plugins: [`...`] into the { resolve: ``, options: {} } form\n const config = normalizeConfig(rawConfig)\n\n // Show errors for invalid plugin configuration\n await validateConfigPluginsOptions(config, rootDir)\n\n const currentAPIs = getAPI({\n browser: browserAPIs,\n node: nodeAPIs,\n ssr: ssrAPIs,\n })\n\n // Collate internal plugins, site config plugins, site default plugins\n const pluginInfos = loadInternalPlugins(config, rootDir)\n\n // Create a flattened array of the plugins\n const pluginArray = flattenPlugins(pluginInfos)\n\n // Work out which plugins use which APIs, including those which are not\n // valid Gatsby APIs, aka 'badExports'\n let { flattenedPlugins, badExports } = await collatePluginAPIs({\n currentAPIs,\n flattenedPlugins: pluginArray,\n rootDir,\n })\n\n // Show errors for any non-Gatsby APIs exported from plugins\n await handleBadExports({ currentAPIs, badExports })\n\n // Show errors when ReplaceRenderer has been implemented multiple times\n flattenedPlugins = handleMultipleReplaceRenderers({\n flattenedPlugins,\n })\n\n // If we get this far, everything looks good. Update the store\n store.dispatch({\n type: `SET_SITE_FLATTENED_PLUGINS`,\n payload: flattenedPlugins as IGatsbyState[\"flattenedPlugins\"],\n })\n\n return flattenedPlugins\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AACA;;AACA;;;;;;AAGO,eAAeA,WAAf,CACLC,SADK,EAELC,OAFK,EAG6B;EAClC;EACA,MAAMC,MAAM,GAAG,IAAAC,0BAAA,EAAgBH,SAAhB,CAAf,CAFkC,CAIlC;;EACA,MAAM,IAAAI,sCAAA,EAA6BF,MAA7B,EAAqCD,OAArC,CAAN;EAEA,MAAMI,WAAW,GAAG,IAAAC,cAAA,EAAO;IACzBC,OAAO,EAAEC,WADgB;IAEzBC,IAAI,EAAEC,QAFmB;IAGzBC,GAAG,EAAEC;EAHoB,CAAP,CAApB,CAPkC,CAalC;;EACA,MAAMC,WAAW,GAAG,IAAAC,wCAAA,EAAoBZ,MAApB,EAA4BD,OAA5B,CAApB,CAdkC,CAgBlC;;EACA,MAAMc,WAAW,GAAG,IAAAC,8BAAA,EAAeH,WAAf,CAApB,CAjBkC,CAmBlC;EACA;;EACA,IAAI;IAAEI,gBAAF;IAAoBC;EAApB,IAAmC,MAAM,IAAAC,2BAAA,EAAkB;IAC7Dd,WAD6D;IAE7DY,gBAAgB,EAAEF,WAF2C;IAG7Dd;EAH6D,CAAlB,CAA7C,CArBkC,CA2BlC;;EACA,MAAM,IAAAmB,0BAAA,EAAiB;IAAEf,WAAF;IAAea;EAAf,CAAjB,CAAN,CA5BkC,CA8BlC;;EACAD,gBAAgB,GAAG,IAAAI,wCAAA,EAA+B;IAChDJ;EADgD,CAA/B,CAAnB,CA/BkC,CAmClC;;EACAK,YAAA,CAAMC,QAAN,CAAe;IACbC,IAAI,EAAG,4BADM;IAEbC,OAAO,EAAER;EAFI,CAAf;;EAKA,OAAOA,gBAAP;AACD"}
|
|
@@ -26,13 +26,14 @@ export declare function validateConfigPluginsOptions(config: ISiteConfig | undef
|
|
|
26
26
|
/**
|
|
27
27
|
* Identify which APIs each plugin exports
|
|
28
28
|
*/
|
|
29
|
-
export declare function collatePluginAPIs({ currentAPIs, flattenedPlugins, }: {
|
|
29
|
+
export declare function collatePluginAPIs({ currentAPIs, flattenedPlugins, rootDir, }: {
|
|
30
30
|
currentAPIs: ICurrentAPIs;
|
|
31
31
|
flattenedPlugins: Array<IPluginInfo & Partial<IFlattenedPlugin>>;
|
|
32
|
-
|
|
32
|
+
rootDir: string;
|
|
33
|
+
}): Promise<{
|
|
33
34
|
flattenedPlugins: Array<IFlattenedPlugin>;
|
|
34
35
|
badExports: IEntryMap;
|
|
35
|
-
}
|
|
36
|
+
}>;
|
|
36
37
|
export declare const handleMultipleReplaceRenderers: ({ flattenedPlugins, }: {
|
|
37
38
|
flattenedPlugins: Array<IFlattenedPlugin>;
|
|
38
39
|
}) => Array<IFlattenedPlugin>;
|
|
@@ -304,9 +304,10 @@ async function validateConfigPluginsOptions(config = {}, rootDir) {
|
|
|
304
304
|
*/
|
|
305
305
|
|
|
306
306
|
|
|
307
|
-
function collatePluginAPIs({
|
|
307
|
+
async function collatePluginAPIs({
|
|
308
308
|
currentAPIs,
|
|
309
|
-
flattenedPlugins
|
|
309
|
+
flattenedPlugins,
|
|
310
|
+
rootDir
|
|
310
311
|
}) {
|
|
311
312
|
// Get a list of bad exports
|
|
312
313
|
const badExports = {
|
|
@@ -314,7 +315,8 @@ function collatePluginAPIs({
|
|
|
314
315
|
browser: [],
|
|
315
316
|
ssr: []
|
|
316
317
|
};
|
|
317
|
-
|
|
318
|
+
|
|
319
|
+
for (const plugin of flattenedPlugins) {
|
|
318
320
|
var _plugin$resolvedCompi;
|
|
319
321
|
|
|
320
322
|
plugin.nodeAPIs = [];
|
|
@@ -323,11 +325,16 @@ function collatePluginAPIs({
|
|
|
323
325
|
// the plugin node itself *and* in an API to plugins map for faster lookups
|
|
324
326
|
// later.
|
|
325
327
|
|
|
326
|
-
const pluginNodeExports = (0, _resolveModuleExports.resolveModuleExports)((_plugin$resolvedCompi = plugin.resolvedCompiledGatsbyNode) !== null && _plugin$resolvedCompi !== void 0 ? _plugin$resolvedCompi : `${plugin.resolve}/gatsby-node`, {
|
|
327
|
-
mode: `
|
|
328
|
+
const pluginNodeExports = await (0, _resolveModuleExports.resolveModuleExports)((_plugin$resolvedCompi = plugin.resolvedCompiledGatsbyNode) !== null && _plugin$resolvedCompi !== void 0 ? _plugin$resolvedCompi : `${plugin.resolve}/gatsby-node`, {
|
|
329
|
+
mode: `import`,
|
|
330
|
+
rootDir
|
|
331
|
+
});
|
|
332
|
+
const pluginBrowserExports = await (0, _resolveModuleExports.resolveModuleExports)(`${plugin.resolve}/gatsby-browser`, {
|
|
333
|
+
rootDir
|
|
334
|
+
});
|
|
335
|
+
const pluginSSRExports = await (0, _resolveModuleExports.resolveModuleExports)(`${plugin.resolve}/gatsby-ssr`, {
|
|
336
|
+
rootDir
|
|
328
337
|
});
|
|
329
|
-
const pluginBrowserExports = (0, _resolveModuleExports.resolveModuleExports)(`${plugin.resolve}/gatsby-browser`);
|
|
330
|
-
const pluginSSRExports = (0, _resolveModuleExports.resolveModuleExports)(`${plugin.resolve}/gatsby-ssr`);
|
|
331
338
|
|
|
332
339
|
if (pluginNodeExports.length > 0) {
|
|
333
340
|
plugin.nodeAPIs = (0, _intersection2.default)(pluginNodeExports, currentAPIs.node);
|
|
@@ -343,7 +350,8 @@ function collatePluginAPIs({
|
|
|
343
350
|
plugin.ssrAPIs = (0, _intersection2.default)(pluginSSRExports, currentAPIs.ssr);
|
|
344
351
|
badExports.ssr = badExports.ssr.concat(getBadExports(plugin, pluginSSRExports, currentAPIs.ssr)); // Collate any bad exports
|
|
345
352
|
}
|
|
346
|
-
}
|
|
353
|
+
}
|
|
354
|
+
|
|
347
355
|
return {
|
|
348
356
|
flattenedPlugins: flattenedPlugins,
|
|
349
357
|
badExports
|