gatsby-source-filesystem 4.6.0 → 4.8.0-next.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/CHANGELOG.md +6 -0
- package/create-remote-file-node.js +12 -119
- package/package.json +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.6.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-source-filesystem@4.6.0/packages/gatsby-source-filesystem) (2022-01-25)
|
|
7
|
+
|
|
8
|
+
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v4.6)
|
|
9
|
+
|
|
10
|
+
**Note:** Version bump only for package gatsby-source-filesystem
|
|
11
|
+
|
|
6
12
|
### [4.5.2](https://github.com/gatsbyjs/gatsby/commits/gatsby-source-filesystem@4.5.2/packages/gatsby-source-filesystem) (2022-01-17)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package gatsby-source-filesystem
|
|
@@ -1,30 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const fs = require(`fs-extra`);
|
|
4
|
-
|
|
5
3
|
const {
|
|
6
|
-
|
|
7
|
-
fetchRemoteFile,
|
|
8
|
-
createFilePath
|
|
4
|
+
fetchRemoteFile
|
|
9
5
|
} = require(`gatsby-core-utils`);
|
|
10
6
|
|
|
11
|
-
const path = require(`path`);
|
|
12
|
-
|
|
13
7
|
const {
|
|
14
8
|
isWebUri
|
|
15
9
|
} = require(`valid-url`);
|
|
16
10
|
|
|
17
|
-
const Queue = require(`fastq`);
|
|
18
|
-
|
|
19
11
|
const {
|
|
20
12
|
createFileNode
|
|
21
13
|
} = require(`./create-file-node`);
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
getRemoteFileExtension
|
|
25
|
-
} = require(`./utils`);
|
|
26
|
-
|
|
27
|
-
let showFlagWarning = !!process.env.GATSBY_EXPERIMENTAL_REMOTE_FILE_PLACEHOLDER;
|
|
28
14
|
/********************
|
|
29
15
|
* Type Definitions *
|
|
30
16
|
********************/
|
|
@@ -59,37 +45,6 @@ let showFlagWarning = !!process.env.GATSBY_EXPERIMENTAL_REMOTE_FILE_PLACEHOLDER;
|
|
|
59
45
|
* @param {Reporter} [options.reporter]
|
|
60
46
|
*/
|
|
61
47
|
|
|
62
|
-
/********************
|
|
63
|
-
* Queue Management *
|
|
64
|
-
********************/
|
|
65
|
-
|
|
66
|
-
const GATSBY_CONCURRENT_DOWNLOAD = process.env.GATSBY_CONCURRENT_DOWNLOAD ? parseInt(process.env.GATSBY_CONCURRENT_DOWNLOAD, 10) || 0 : 200;
|
|
67
|
-
const queue = Queue(pushToQueue, GATSBY_CONCURRENT_DOWNLOAD);
|
|
68
|
-
/**
|
|
69
|
-
* @callback {Queue~queueCallback}
|
|
70
|
-
* @param {*} error
|
|
71
|
-
* @param {*} result
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* pushToQueue
|
|
76
|
-
* --
|
|
77
|
-
* Handle tasks that are pushed in to the Queue
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @param {CreateRemoteFileNodePayload} task
|
|
81
|
-
* @param {Queue~queueCallback} cb
|
|
82
|
-
* @return {Promise<null>}
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
async function pushToQueue(task, cb) {
|
|
86
|
-
try {
|
|
87
|
-
const node = await processRemoteNode(task);
|
|
88
|
-
return cb(null, node);
|
|
89
|
-
} catch (e) {
|
|
90
|
-
return cb(e);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
48
|
/******************
|
|
94
49
|
* Core Functions *
|
|
95
50
|
******************/
|
|
@@ -115,27 +70,14 @@ async function processRemoteNode({
|
|
|
115
70
|
ext,
|
|
116
71
|
name
|
|
117
72
|
}) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
name
|
|
127
|
-
});
|
|
128
|
-
} else {
|
|
129
|
-
filename = await fetchRemoteFile({
|
|
130
|
-
url,
|
|
131
|
-
cache,
|
|
132
|
-
auth,
|
|
133
|
-
httpHeaders,
|
|
134
|
-
ext,
|
|
135
|
-
name
|
|
136
|
-
});
|
|
137
|
-
} // Create the file node.
|
|
138
|
-
|
|
73
|
+
const filename = await fetchRemoteFile({
|
|
74
|
+
url,
|
|
75
|
+
cache,
|
|
76
|
+
auth,
|
|
77
|
+
httpHeaders,
|
|
78
|
+
ext,
|
|
79
|
+
name
|
|
80
|
+
}); // Create the file node.
|
|
139
81
|
|
|
140
82
|
const fileNode = await createFileNode(filename, createNodeId, {});
|
|
141
83
|
fileNode.internal.description = `File "${url}"`;
|
|
@@ -150,50 +92,12 @@ async function processRemoteNode({
|
|
|
150
92
|
});
|
|
151
93
|
return fileNode;
|
|
152
94
|
}
|
|
153
|
-
|
|
154
|
-
async function fetchPlaceholder({
|
|
155
|
-
fromPath,
|
|
156
|
-
url,
|
|
157
|
-
cache,
|
|
158
|
-
ext,
|
|
159
|
-
name
|
|
160
|
-
}) {
|
|
161
|
-
const pluginCacheDir = cache.directory;
|
|
162
|
-
const digest = createContentDigest(url);
|
|
163
|
-
|
|
164
|
-
if (!ext) {
|
|
165
|
-
ext = getRemoteFileExtension(url);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const filename = createFilePath(path.join(pluginCacheDir, digest), name, ext);
|
|
169
|
-
fs.copySync(fromPath, filename);
|
|
170
|
-
return filename;
|
|
171
|
-
}
|
|
172
95
|
/**
|
|
173
96
|
* Index of promises resolving to File node from remote url
|
|
174
97
|
*/
|
|
175
98
|
|
|
176
99
|
|
|
177
100
|
const processingCache = {};
|
|
178
|
-
/**
|
|
179
|
-
* pushTask
|
|
180
|
-
* --
|
|
181
|
-
* pushes a task in to the Queue and the processing cache
|
|
182
|
-
*
|
|
183
|
-
* Promisfy a task in queue
|
|
184
|
-
* @param {CreateRemoteFileNodePayload} task
|
|
185
|
-
* @return {Promise<Object>}
|
|
186
|
-
*/
|
|
187
|
-
|
|
188
|
-
const pushTask = task => new Promise((resolve, reject) => {
|
|
189
|
-
queue.push(task, (err, node) => {
|
|
190
|
-
if (!err) {
|
|
191
|
-
resolve(node);
|
|
192
|
-
} else {
|
|
193
|
-
reject(`failed to process ${task.url}\n${err}`);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
101
|
/***************
|
|
198
102
|
* Entry Point *
|
|
199
103
|
***************/
|
|
@@ -210,7 +114,6 @@ const pushTask = task => new Promise((resolve, reject) => {
|
|
|
210
114
|
* @return {Promise<Object>} Returns the created node
|
|
211
115
|
*/
|
|
212
116
|
|
|
213
|
-
|
|
214
117
|
module.exports = function createRemoteFileNode({
|
|
215
118
|
url,
|
|
216
119
|
cache,
|
|
@@ -223,19 +126,9 @@ module.exports = function createRemoteFileNode({
|
|
|
223
126
|
ext = null,
|
|
224
127
|
name = null
|
|
225
128
|
}) {
|
|
226
|
-
|
|
227
|
-
showFlagWarning = false; // Note: This will use a placeholder image as the default for every file that is downloaded through this API.
|
|
228
|
-
// That may break certain cases, in particular when the file is not meant to be an image or when the image
|
|
229
|
-
// is expected to be of a particular type that is other than the placeholder. This API is meant to bypass
|
|
230
|
-
// the remote download for local testing only.
|
|
231
|
-
|
|
232
|
-
console.info(`GATSBY_EXPERIMENTAL_REMOTE_FILE_PLACEHOLDER: Any file downloaded by \`createRemoteFileNode\` will use the same placeholder image and skip the remote fetch. Note: This is an experimental flag that can change/disappear at any point.`);
|
|
233
|
-
console.info(`GATSBY_EXPERIMENTAL_REMOTE_FILE_PLACEHOLDER: File to use: \`${process.env.GATSBY_EXPERIMENTAL_REMOTE_FILE_PLACEHOLDER}\``);
|
|
234
|
-
} // validation of the input
|
|
129
|
+
// validation of the input
|
|
235
130
|
// without this it's notoriously easy to pass in the wrong `createNodeId`
|
|
236
131
|
// see gatsbyjs/gatsby#6643
|
|
237
|
-
|
|
238
|
-
|
|
239
132
|
if (typeof createNodeId !== `function`) {
|
|
240
133
|
throw new Error(`createNodeId must be a function, was ${typeof createNodeId}`);
|
|
241
134
|
}
|
|
@@ -260,10 +153,10 @@ module.exports = function createRemoteFileNode({
|
|
|
260
153
|
}
|
|
261
154
|
|
|
262
155
|
if (!url || isWebUri(url) === undefined) {
|
|
263
|
-
return Promise.reject(`url passed to createRemoteFileNode is either missing or not a proper web uri: ${url}`);
|
|
156
|
+
return Promise.reject(new Error(`url passed to createRemoteFileNode is either missing or not a proper web uri: ${url}`));
|
|
264
157
|
}
|
|
265
158
|
|
|
266
|
-
const fileDownloadPromise =
|
|
159
|
+
const fileDownloadPromise = processRemoteNode({
|
|
267
160
|
url,
|
|
268
161
|
cache,
|
|
269
162
|
createNode,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby-source-filesystem",
|
|
3
3
|
"description": "Gatsby source plugin for building websites from local data. Markdown, JSON, images, YAML, CSV, and dozens of other data types supported.",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.8.0-next.0",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/gatsbyjs/gatsby/issues"
|
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@babel/runtime": "^7.15.4",
|
|
11
11
|
"chokidar": "^3.5.2",
|
|
12
|
-
"fastq": "^1.13.0",
|
|
13
12
|
"file-type": "^16.5.3",
|
|
14
13
|
"fs-extra": "^10.0.0",
|
|
15
|
-
"gatsby-core-utils": "^3.
|
|
14
|
+
"gatsby-core-utils": "^3.8.0-next.0",
|
|
16
15
|
"got": "^9.6.0",
|
|
17
16
|
"md5-file": "^5.0.0",
|
|
18
17
|
"mime": "^2.5.2",
|
|
@@ -24,7 +23,7 @@
|
|
|
24
23
|
"devDependencies": {
|
|
25
24
|
"@babel/cli": "^7.15.4",
|
|
26
25
|
"@babel/core": "^7.15.5",
|
|
27
|
-
"babel-preset-gatsby-package": "^2.
|
|
26
|
+
"babel-preset-gatsby-package": "^2.8.0-next.0",
|
|
28
27
|
"cross-env": "^7.0.3"
|
|
29
28
|
},
|
|
30
29
|
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-filesystem#readme",
|
|
@@ -50,5 +49,5 @@
|
|
|
50
49
|
"engines": {
|
|
51
50
|
"node": ">=14.15.0"
|
|
52
51
|
},
|
|
53
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "459d61e672d081ce6968ef07fe1b39c2e6e2a001"
|
|
54
53
|
}
|