gatsby-source-filesystem 5.4.0-next.1 → 5.5.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 +12 -0
- package/create-file-node-from-buffer.js +18 -32
- package/create-file-node.js +2 -9
- package/create-file-path.js +0 -6
- package/create-remote-file-node.js +10 -18
- package/error-utils.js +3 -4
- package/extend-file-node.js +0 -7
- package/gatsby-node.js +13 -32
- package/index.js +0 -2
- package/package.json +7 -7
- package/utils.js +6 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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
|
+
### [5.3.1](https://github.com/gatsbyjs/gatsby/commits/gatsby-source-filesystem@5.3.1/packages/gatsby-source-filesystem) (2022-12-14)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package gatsby-source-filesystem
|
|
9
|
+
|
|
10
|
+
## [5.3.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-source-filesystem@5.3.0/packages/gatsby-source-filesystem) (2022-12-13)
|
|
11
|
+
|
|
12
|
+
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v5.3)
|
|
13
|
+
|
|
14
|
+
#### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- update minor and patch dependencies for gatsby-source-filesystem [#37163](https://github.com/gatsbyjs/gatsby/issues/37163) ([21f815f](https://github.com/gatsbyjs/gatsby/commit/21f815f53a76c511e548dd4f1ae0d71078b5e783))
|
|
17
|
+
|
|
6
18
|
## [5.2.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-source-filesystem@5.2.0/packages/gatsby-source-filesystem) (2022-11-25)
|
|
7
19
|
|
|
8
20
|
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v5.2)
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const fs = require(`fs-extra`);
|
|
4
|
-
|
|
5
4
|
const path = require(`path`);
|
|
6
|
-
|
|
7
5
|
const fileType = require(`file-type`);
|
|
8
|
-
|
|
9
6
|
const {
|
|
10
7
|
createFileNode
|
|
11
8
|
} = require(`./create-file-node`);
|
|
12
|
-
|
|
13
9
|
const {
|
|
14
10
|
createContentDigest,
|
|
15
11
|
createFilePath
|
|
16
12
|
} = require(`gatsby-core-utils`);
|
|
17
|
-
|
|
18
13
|
const cacheId = hash => `create-file-node-from-buffer-${hash}`;
|
|
14
|
+
|
|
19
15
|
/********************
|
|
20
16
|
* Type Definitions *
|
|
21
17
|
********************/
|
|
@@ -47,11 +43,10 @@ const cacheId = hash => `create-file-node-from-buffer-${hash}`;
|
|
|
47
43
|
* @param {Buffer} buffer
|
|
48
44
|
* @returns {Promise<void>}
|
|
49
45
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
46
|
const writeBuffer = (filename, buffer) => new Promise((resolve, reject) => {
|
|
53
47
|
fs.writeFile(filename, buffer, err => err ? reject(err) : resolve());
|
|
54
48
|
});
|
|
49
|
+
|
|
55
50
|
/**
|
|
56
51
|
* processBufferNode
|
|
57
52
|
* --
|
|
@@ -60,8 +55,6 @@ const writeBuffer = (filename, buffer) => new Promise((resolve, reject) => {
|
|
|
60
55
|
* @param {CreateFileNodeFromBufferPayload} options
|
|
61
56
|
* @return {Promise<Object>} Resolves with the fileNode
|
|
62
57
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
58
|
async function processBufferNode({
|
|
66
59
|
buffer,
|
|
67
60
|
hash,
|
|
@@ -72,11 +65,11 @@ async function processBufferNode({
|
|
|
72
65
|
ext,
|
|
73
66
|
name
|
|
74
67
|
}) {
|
|
75
|
-
const pluginCacheDir = cache.directory;
|
|
76
|
-
// a previous run
|
|
68
|
+
const pluginCacheDir = cache.directory;
|
|
77
69
|
|
|
70
|
+
// See if there's a cache file for this buffer's contents from
|
|
71
|
+
// a previous run
|
|
78
72
|
let filename = await cache.get(cacheId(hash));
|
|
79
|
-
|
|
80
73
|
if (!filename) {
|
|
81
74
|
// If the user did not provide an extension and we couldn't get
|
|
82
75
|
// one from remote file, try and guess one
|
|
@@ -84,35 +77,36 @@ async function processBufferNode({
|
|
|
84
77
|
const filetype = await fileType.fromBuffer(buffer);
|
|
85
78
|
ext = filetype ? `.${filetype.ext}` : `.bin`;
|
|
86
79
|
}
|
|
87
|
-
|
|
88
80
|
filename = createFilePath(path.join(pluginCacheDir, hash), name, ext);
|
|
89
|
-
await fs.ensureDir(path.dirname(filename));
|
|
81
|
+
await fs.ensureDir(path.dirname(filename));
|
|
90
82
|
|
|
91
|
-
|
|
83
|
+
// Cache the buffer contents
|
|
84
|
+
await writeBuffer(filename, buffer);
|
|
92
85
|
|
|
86
|
+
// Save the cache file path for future use
|
|
93
87
|
await cache.set(cacheId(hash), filename);
|
|
94
|
-
}
|
|
95
|
-
|
|
88
|
+
}
|
|
96
89
|
|
|
90
|
+
// Create the file node.
|
|
97
91
|
const fileNode = await createFileNode(filename, createNodeId, {});
|
|
98
92
|
fileNode.internal.description = `File "Buffer<${hash}>"`;
|
|
99
93
|
fileNode.hash = hash;
|
|
100
|
-
fileNode.parent = parentNodeId;
|
|
94
|
+
fileNode.parent = parentNodeId;
|
|
95
|
+
// Override the default plugin as gatsby-source-filesystem needs to
|
|
101
96
|
// be the owner of File nodes or there'll be conflicts if any other
|
|
102
97
|
// File nodes are created through normal usages of
|
|
103
98
|
// gatsby-source-filesystem.
|
|
104
|
-
|
|
105
99
|
await createNode(fileNode, {
|
|
106
100
|
name: `gatsby-source-filesystem`
|
|
107
101
|
});
|
|
108
102
|
return fileNode;
|
|
109
103
|
}
|
|
104
|
+
|
|
110
105
|
/**
|
|
111
106
|
* Index of promises resolving to File node from buffer cache
|
|
112
107
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
108
|
const processingCache = {};
|
|
109
|
+
|
|
116
110
|
/***************
|
|
117
111
|
* Entry Point *
|
|
118
112
|
***************/
|
|
@@ -127,7 +121,6 @@ const processingCache = {};
|
|
|
127
121
|
* @param {CreateFileNodeFromBufferPayload} options
|
|
128
122
|
* @return {Promise<Object>} Returns the created node
|
|
129
123
|
*/
|
|
130
|
-
|
|
131
124
|
module.exports = ({
|
|
132
125
|
buffer,
|
|
133
126
|
hash,
|
|
@@ -145,38 +138,31 @@ module.exports = ({
|
|
|
145
138
|
if (typeof createNodeId !== `function`) {
|
|
146
139
|
throw new Error(`createNodeId must be a function, was ${typeof createNodeId}`);
|
|
147
140
|
}
|
|
148
|
-
|
|
149
141
|
if (typeof createNode !== `function`) {
|
|
150
142
|
throw new Error(`createNode must be a function, was ${typeof createNode}`);
|
|
151
143
|
}
|
|
152
|
-
|
|
153
144
|
if (typeof getCache === `function`) {
|
|
154
145
|
// use cache of this plugin and not cache of function caller
|
|
155
146
|
cache = getCache(`gatsby-source-filesystem`);
|
|
156
147
|
}
|
|
157
|
-
|
|
158
148
|
if (typeof cache !== `object`) {
|
|
159
149
|
throw new Error(`Neither "cache" or "getCache" was passed. getCache must be function that return Gatsby cache, "cache" must be the Gatsby cache, was ${typeof cache}`);
|
|
160
150
|
}
|
|
161
|
-
|
|
162
151
|
if (!buffer) {
|
|
163
152
|
return Promise.reject(`bad buffer: ${buffer}`);
|
|
164
153
|
}
|
|
165
|
-
|
|
166
154
|
if (!hash) {
|
|
167
155
|
hash = createContentDigest(buffer);
|
|
168
156
|
}
|
|
169
|
-
|
|
170
157
|
if (!name) {
|
|
171
158
|
name = hash;
|
|
172
|
-
}
|
|
173
|
-
// and return stored promise if we did.
|
|
174
|
-
|
|
159
|
+
}
|
|
175
160
|
|
|
161
|
+
// Check if we already requested node for this remote file
|
|
162
|
+
// and return stored promise if we did.
|
|
176
163
|
if (processingCache[hash]) {
|
|
177
164
|
return processingCache[hash];
|
|
178
165
|
}
|
|
179
|
-
|
|
180
166
|
const bufferCachePromise = processBufferNode({
|
|
181
167
|
buffer,
|
|
182
168
|
hash,
|
package/create-file-node.js
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const path = require(`path`);
|
|
4
|
-
|
|
5
4
|
const fs = require(`fs-extra`);
|
|
6
|
-
|
|
7
5
|
const mime = require(`mime`);
|
|
8
|
-
|
|
9
6
|
const prettyBytes = require(`pretty-bytes`);
|
|
10
|
-
|
|
11
7
|
const md5File = require(`md5-file`);
|
|
12
|
-
|
|
13
8
|
const {
|
|
14
9
|
createContentDigest,
|
|
15
10
|
slash
|
|
16
11
|
} = require(`gatsby-core-utils`);
|
|
17
|
-
|
|
18
12
|
exports.createFileNode = async (pathToFile, createNodeId, pluginOptions = {}) => {
|
|
19
13
|
const slashed = slash(pathToFile);
|
|
20
14
|
const parsedSlashed = path.parse(slashed);
|
|
21
|
-
const slashedFile = {
|
|
15
|
+
const slashedFile = {
|
|
16
|
+
...parsedSlashed,
|
|
22
17
|
absolutePath: slashed,
|
|
23
18
|
// Useful for limiting graphql query with certain parent directory
|
|
24
19
|
relativeDirectory: slash(path.relative(pluginOptions.path || process.cwd(), parsedSlashed.dir))
|
|
25
20
|
};
|
|
26
21
|
const stats = await fs.stat(slashedFile.absolutePath);
|
|
27
22
|
let internal;
|
|
28
|
-
|
|
29
23
|
if (stats.isDirectory()) {
|
|
30
24
|
const contentDigest = createContentDigest({
|
|
31
25
|
stats: stats,
|
|
@@ -46,7 +40,6 @@ exports.createFileNode = async (pathToFile, createNodeId, pluginOptions = {}) =>
|
|
|
46
40
|
description: `File "${path.relative(process.cwd(), slashed)}"`
|
|
47
41
|
};
|
|
48
42
|
}
|
|
49
|
-
|
|
50
43
|
return {
|
|
51
44
|
// Don't actually make the File id the absolute path as otherwise
|
|
52
45
|
// people will use the id for that and ids shouldn't be treated as
|
package/create-file-path.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const path = require(`path`);
|
|
4
|
-
|
|
5
4
|
const {
|
|
6
5
|
slash
|
|
7
6
|
} = require(`gatsby-core-utils`);
|
|
8
|
-
|
|
9
7
|
function findFileNode({
|
|
10
8
|
node,
|
|
11
9
|
getNode
|
|
@@ -13,19 +11,15 @@ function findFileNode({
|
|
|
13
11
|
// Find the file node.
|
|
14
12
|
let fileNode = node;
|
|
15
13
|
let whileCount = 0;
|
|
16
|
-
|
|
17
14
|
while (fileNode.internal.type !== `File` && fileNode.parent && getNode(fileNode.parent) !== undefined && whileCount < 101) {
|
|
18
15
|
fileNode = getNode(fileNode.parent);
|
|
19
16
|
whileCount += 1;
|
|
20
|
-
|
|
21
17
|
if (whileCount > 100) {
|
|
22
18
|
console.log(`It looks like you have a node that's set its parent as itself`, fileNode);
|
|
23
19
|
}
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
return fileNode;
|
|
27
22
|
}
|
|
28
|
-
|
|
29
23
|
module.exports = ({
|
|
30
24
|
node,
|
|
31
25
|
getNode,
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
const {
|
|
4
4
|
fetchRemoteFile
|
|
5
5
|
} = require(`gatsby-core-utils/fetch-remote-file`);
|
|
6
|
-
|
|
7
6
|
const {
|
|
8
7
|
isWebUri
|
|
9
8
|
} = require(`valid-url`);
|
|
10
|
-
|
|
11
9
|
const {
|
|
12
10
|
createFileNode
|
|
13
11
|
} = require(`./create-file-node`);
|
|
12
|
+
|
|
14
13
|
/********************
|
|
15
14
|
* Type Definitions *
|
|
16
15
|
********************/
|
|
@@ -51,8 +50,6 @@ const {
|
|
|
51
50
|
* @param {CreateRemoteFileNodePayload} options
|
|
52
51
|
* @return {Promise<Object>} Resolves with the fileNode
|
|
53
52
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
53
|
async function processRemoteNode({
|
|
57
54
|
url,
|
|
58
55
|
cache,
|
|
@@ -71,27 +68,28 @@ async function processRemoteNode({
|
|
|
71
68
|
httpHeaders,
|
|
72
69
|
ext,
|
|
73
70
|
name
|
|
74
|
-
});
|
|
71
|
+
});
|
|
75
72
|
|
|
73
|
+
// Create the file node.
|
|
76
74
|
const fileNode = await createFileNode(filename, createNodeId, {});
|
|
77
75
|
fileNode.internal.description = `File "${url}"`;
|
|
78
76
|
fileNode.url = url;
|
|
79
|
-
fileNode.parent = parentNodeId;
|
|
77
|
+
fileNode.parent = parentNodeId;
|
|
78
|
+
// Override the default plugin as gatsby-source-filesystem needs to
|
|
80
79
|
// be the owner of File nodes or there'll be conflicts if any other
|
|
81
80
|
// File nodes are created through normal usages of
|
|
82
81
|
// gatsby-source-filesystem.
|
|
83
|
-
|
|
84
82
|
await createNode(fileNode, {
|
|
85
83
|
name: `gatsby-source-filesystem`
|
|
86
84
|
});
|
|
87
85
|
return fileNode;
|
|
88
86
|
}
|
|
87
|
+
|
|
89
88
|
/**
|
|
90
89
|
* Index of promises resolving to File node from remote url
|
|
91
90
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
91
|
const processingCache = {};
|
|
92
|
+
|
|
95
93
|
/***************
|
|
96
94
|
* Entry Point *
|
|
97
95
|
***************/
|
|
@@ -107,7 +105,6 @@ const processingCache = {};
|
|
|
107
105
|
* @param {CreateRemoteFileNodePayload} options
|
|
108
106
|
* @return {Promise<Object>} Returns the created node
|
|
109
107
|
*/
|
|
110
|
-
|
|
111
108
|
module.exports = function createRemoteFileNode({
|
|
112
109
|
url,
|
|
113
110
|
cache,
|
|
@@ -126,30 +123,25 @@ module.exports = function createRemoteFileNode({
|
|
|
126
123
|
if (typeof createNodeId !== `function`) {
|
|
127
124
|
throw new Error(`createNodeId must be a function, was ${typeof createNodeId}`);
|
|
128
125
|
}
|
|
129
|
-
|
|
130
126
|
if (typeof createNode !== `function`) {
|
|
131
127
|
throw new Error(`createNode must be a function, was ${typeof createNode}`);
|
|
132
128
|
}
|
|
133
|
-
|
|
134
129
|
if (typeof getCache === `function`) {
|
|
135
130
|
// use cache of this plugin and not cache of function caller
|
|
136
131
|
cache = getCache(`gatsby-source-filesystem`);
|
|
137
132
|
}
|
|
138
|
-
|
|
139
133
|
if (typeof cache !== `object`) {
|
|
140
134
|
throw new Error(`Neither "cache" or "getCache" was passed. getCache must be function that return Gatsby cache, "cache" must be the Gatsby cache, was ${typeof cache}`);
|
|
141
|
-
}
|
|
142
|
-
// and return stored promise if we did.
|
|
143
|
-
|
|
135
|
+
}
|
|
144
136
|
|
|
137
|
+
// Check if we already requested node for this remote file
|
|
138
|
+
// and return stored promise if we did.
|
|
145
139
|
if (processingCache[url]) {
|
|
146
140
|
return processingCache[url];
|
|
147
141
|
}
|
|
148
|
-
|
|
149
142
|
if (!url || isWebUri(url) === undefined) {
|
|
150
143
|
throw new Error(`url passed to createRemoteFileNode is either missing or not a proper web uri: ${url}`);
|
|
151
144
|
}
|
|
152
|
-
|
|
153
145
|
const fileDownloadPromise = processRemoteNode({
|
|
154
146
|
url,
|
|
155
147
|
cache,
|
package/error-utils.js
CHANGED
|
@@ -10,13 +10,12 @@ const CODES = {
|
|
|
10
10
|
exports.CODES = CODES;
|
|
11
11
|
const pluginPrefix = `gatsby-source-filesystem`;
|
|
12
12
|
exports.pluginPrefix = pluginPrefix;
|
|
13
|
-
|
|
14
13
|
function prefixId(id) {
|
|
15
14
|
return `${pluginPrefix}_${id}`;
|
|
16
|
-
}
|
|
17
|
-
// once reporter.setErrorMap is guaranteed to be available
|
|
18
|
-
|
|
15
|
+
}
|
|
19
16
|
|
|
17
|
+
// TODO: Refactor to use contextual data instead of only context.sourceMessage
|
|
18
|
+
// once reporter.setErrorMap is guaranteed to be available
|
|
20
19
|
const ERROR_MAP = {
|
|
21
20
|
[CODES.Generic]: {
|
|
22
21
|
text: context => context.sourceMessage,
|
package/extend-file-node.js
CHANGED
|
@@ -3,16 +3,12 @@
|
|
|
3
3
|
const {
|
|
4
4
|
GraphQLString
|
|
5
5
|
} = require(`gatsby/graphql`);
|
|
6
|
-
|
|
7
6
|
const fs = require(`fs-extra`);
|
|
8
|
-
|
|
9
7
|
const path = require(`path`);
|
|
10
|
-
|
|
11
8
|
const {
|
|
12
9
|
prefixId,
|
|
13
10
|
CODES
|
|
14
11
|
} = require(`./error-utils`);
|
|
15
|
-
|
|
16
12
|
module.exports = ({
|
|
17
13
|
type,
|
|
18
14
|
getNodeAndSavePathDependency,
|
|
@@ -22,7 +18,6 @@ module.exports = ({
|
|
|
22
18
|
if (type.name !== `File`) {
|
|
23
19
|
return {};
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
return {
|
|
27
22
|
publicURL: {
|
|
28
23
|
type: GraphQLString,
|
|
@@ -32,7 +27,6 @@ module.exports = ({
|
|
|
32
27
|
const details = getNodeAndSavePathDependency(file.id, context.path);
|
|
33
28
|
const fileName = `${file.internal.contentDigest}/${details.base}`;
|
|
34
29
|
const publicPath = path.join(process.cwd(), `public`, `static`, fileName);
|
|
35
|
-
|
|
36
30
|
if (!fs.existsSync(publicPath)) {
|
|
37
31
|
fs.copySync(details.absolutePath, publicPath, {
|
|
38
32
|
dereference: true
|
|
@@ -47,7 +41,6 @@ module.exports = ({
|
|
|
47
41
|
}
|
|
48
42
|
});
|
|
49
43
|
}
|
|
50
|
-
|
|
51
44
|
return `${pathPrefix}/static/${fileName}`;
|
|
52
45
|
}
|
|
53
46
|
}
|
package/gatsby-node.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const chokidar = require(`chokidar`);
|
|
4
|
-
|
|
5
4
|
const fs = require(`fs`);
|
|
6
|
-
|
|
7
5
|
const path = require(`path`);
|
|
8
|
-
|
|
9
6
|
const {
|
|
10
7
|
createMachine,
|
|
11
8
|
interpret,
|
|
12
9
|
assign
|
|
13
10
|
} = require(`xstate`);
|
|
14
|
-
|
|
15
11
|
const {
|
|
16
12
|
createFileNode
|
|
17
13
|
} = require(`./create-file-node`);
|
|
18
|
-
|
|
19
14
|
const {
|
|
20
15
|
ERROR_MAP
|
|
21
16
|
} = require(`./error-utils`);
|
|
22
|
-
|
|
23
17
|
exports.onPreInit = ({
|
|
24
18
|
reporter
|
|
25
19
|
}) => {
|
|
@@ -27,11 +21,10 @@ exports.onPreInit = ({
|
|
|
27
21
|
reporter.setErrorMap(ERROR_MAP);
|
|
28
22
|
}
|
|
29
23
|
};
|
|
24
|
+
|
|
30
25
|
/**
|
|
31
26
|
* Create a state machine to manage Chokidar's not-ready/ready states.
|
|
32
27
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
28
|
const createFSMachine = ({
|
|
36
29
|
actions: {
|
|
37
30
|
createNode,
|
|
@@ -48,25 +41,24 @@ const createFSMachine = ({
|
|
|
48
41
|
});
|
|
49
42
|
return fileNodePromise;
|
|
50
43
|
};
|
|
51
|
-
|
|
52
44
|
const deletePathNode = path => {
|
|
53
|
-
const node = getNode(createNodeId(path));
|
|
45
|
+
const node = getNode(createNodeId(path));
|
|
46
|
+
// It's possible the node was never created as sometimes tools will
|
|
54
47
|
// write and then immediately delete temporary files to the file system.
|
|
55
|
-
|
|
56
48
|
if (node) {
|
|
57
49
|
deleteNode(node);
|
|
58
50
|
}
|
|
59
|
-
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// For every path that is reported before the 'ready' event, we throw them
|
|
60
54
|
// into a queue and then flush the queue when 'ready' event arrives.
|
|
61
55
|
// After 'ready', we handle the 'add' event without putting it into a queue.
|
|
62
|
-
|
|
63
|
-
|
|
64
56
|
let pathQueue = [];
|
|
65
|
-
|
|
66
57
|
const flushPathQueue = () => {
|
|
67
58
|
const queue = pathQueue.slice();
|
|
68
59
|
pathQueue = null;
|
|
69
|
-
return Promise.all(
|
|
60
|
+
return Promise.all(
|
|
61
|
+
// eslint-disable-next-line consistent-return
|
|
70
62
|
queue.map(({
|
|
71
63
|
op,
|
|
72
64
|
path
|
|
@@ -74,19 +66,16 @@ const createFSMachine = ({
|
|
|
74
66
|
switch (op) {
|
|
75
67
|
case `delete`:
|
|
76
68
|
return deletePathNode(path);
|
|
77
|
-
|
|
78
69
|
case `upsert`:
|
|
79
70
|
return createAndProcessNode(path);
|
|
80
71
|
}
|
|
81
72
|
}));
|
|
82
73
|
};
|
|
83
|
-
|
|
84
74
|
const log = expr => (ctx, action, meta) => {
|
|
85
75
|
if (ctx.bootstrapped) {
|
|
86
76
|
reporter.info(expr(ctx, action, meta));
|
|
87
77
|
}
|
|
88
78
|
};
|
|
89
|
-
|
|
90
79
|
const fsMachine = createMachine({
|
|
91
80
|
predictableActionArguments: true,
|
|
92
81
|
context: {
|
|
@@ -162,7 +151,6 @@ const createFSMachine = ({
|
|
|
162
151
|
}) {
|
|
163
152
|
createAndProcessNode(path).catch(err => reporter.error(err));
|
|
164
153
|
},
|
|
165
|
-
|
|
166
154
|
deletePathNode(_, {
|
|
167
155
|
pathType,
|
|
168
156
|
path
|
|
@@ -171,14 +159,12 @@ const createFSMachine = ({
|
|
|
171
159
|
}) {
|
|
172
160
|
deletePathNode(path);
|
|
173
161
|
},
|
|
174
|
-
|
|
175
162
|
flushPathQueue(_, {
|
|
176
163
|
resolve,
|
|
177
164
|
reject
|
|
178
165
|
}) {
|
|
179
166
|
flushPathQueue().then(resolve, reject);
|
|
180
167
|
},
|
|
181
|
-
|
|
182
168
|
queueNodeDeleting(_, {
|
|
183
169
|
path
|
|
184
170
|
}) {
|
|
@@ -187,7 +173,6 @@ const createFSMachine = ({
|
|
|
187
173
|
path
|
|
188
174
|
});
|
|
189
175
|
},
|
|
190
|
-
|
|
191
176
|
queueNodeProcessing(_, {
|
|
192
177
|
path
|
|
193
178
|
}) {
|
|
@@ -196,12 +181,10 @@ const createFSMachine = ({
|
|
|
196
181
|
path
|
|
197
182
|
});
|
|
198
183
|
}
|
|
199
|
-
|
|
200
184
|
}
|
|
201
185
|
});
|
|
202
186
|
return interpret(fsMachine).start();
|
|
203
187
|
};
|
|
204
|
-
|
|
205
188
|
exports.pluginOptionsSchema = ({
|
|
206
189
|
Joi
|
|
207
190
|
}) => Joi.object({
|
|
@@ -209,7 +192,6 @@ exports.pluginOptionsSchema = ({
|
|
|
209
192
|
path: Joi.string(),
|
|
210
193
|
ignore: Joi.array().items(Joi.string(), Joi.object().regex(), Joi.function())
|
|
211
194
|
});
|
|
212
|
-
|
|
213
195
|
exports.sourceNodes = (api, pluginOptions) => {
|
|
214
196
|
// Validate that the path exists.
|
|
215
197
|
if (!fs.existsSync(pluginOptions.path)) {
|
|
@@ -219,17 +201,17 @@ ${pluginOptions.path}
|
|
|
219
201
|
Please pick a path to an existing directory.
|
|
220
202
|
See docs here - https://www.gatsbyjs.com/plugins/gatsby-source-filesystem/
|
|
221
203
|
`);
|
|
222
|
-
}
|
|
223
|
-
// Absolute paths are required to resolve images correctly.
|
|
224
|
-
|
|
204
|
+
}
|
|
225
205
|
|
|
206
|
+
// Validate that the path is absolute.
|
|
207
|
+
// Absolute paths are required to resolve images correctly.
|
|
226
208
|
if (!path.isAbsolute(pluginOptions.path)) {
|
|
227
209
|
pluginOptions.path = path.resolve(process.cwd(), pluginOptions.path);
|
|
228
210
|
}
|
|
211
|
+
const fsMachine = createFSMachine(api, pluginOptions);
|
|
229
212
|
|
|
230
|
-
|
|
213
|
+
// Once bootstrap is finished, we only let one File node update go through
|
|
231
214
|
// the system at a time.
|
|
232
|
-
|
|
233
215
|
api.emitter.on(`BOOTSTRAP_FINISHED`, () => {
|
|
234
216
|
fsMachine.send(`BOOTSTRAP_FINISHED`);
|
|
235
217
|
});
|
|
@@ -281,5 +263,4 @@ See docs here - https://www.gatsbyjs.com/plugins/gatsby-source-filesystem/
|
|
|
281
263
|
});
|
|
282
264
|
});
|
|
283
265
|
};
|
|
284
|
-
|
|
285
266
|
exports.setFieldsOnGraphQLNodeType = require(`./extend-file-node`);
|
package/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const fs = require(`fs-extra`);
|
|
4
|
-
|
|
5
4
|
function loadNodeContent(fileNode) {
|
|
6
5
|
return fs.readFile(fileNode.absolutePath, `utf-8`);
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
exports.createFilePath = require(`./create-file-path`);
|
|
10
8
|
exports.createRemoteFileNode = require(`./create-remote-file-node`);
|
|
11
9
|
exports.createFileNodeFromBuffer = require(`./create-file-node-from-buffer`);
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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": "5.
|
|
4
|
+
"version": "5.5.0-next.0",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/gatsbyjs/gatsby/issues"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@babel/runtime": "^7.
|
|
10
|
+
"@babel/runtime": "^7.20.7",
|
|
11
11
|
"chokidar": "^3.5.3",
|
|
12
12
|
"file-type": "^16.5.4",
|
|
13
13
|
"fs-extra": "^10.1.0",
|
|
14
|
-
"gatsby-core-utils": "^4.
|
|
14
|
+
"gatsby-core-utils": "^4.5.0-next.0",
|
|
15
15
|
"md5-file": "^5.0.0",
|
|
16
16
|
"mime": "^2.6.0",
|
|
17
17
|
"pretty-bytes": "^5.6.0",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"xstate": "^4.34.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@babel/cli": "^7.
|
|
23
|
-
"@babel/core": "^7.
|
|
24
|
-
"babel-preset-gatsby-package": "^3.
|
|
22
|
+
"@babel/cli": "^7.20.7",
|
|
23
|
+
"@babel/core": "^7.20.7",
|
|
24
|
+
"babel-preset-gatsby-package": "^3.5.0-next.0",
|
|
25
25
|
"cross-env": "^7.0.3"
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-filesystem#readme",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=18.0.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "4ef5d775d18329abc5d4e78d1e0a99e904f00cd1"
|
|
51
51
|
}
|
package/utils.js
CHANGED
|
@@ -4,14 +4,12 @@ exports.__esModule = true;
|
|
|
4
4
|
exports.createFilePath = void 0;
|
|
5
5
|
exports.getRemoteFileExtension = getRemoteFileExtension;
|
|
6
6
|
exports.getRemoteFileName = getRemoteFileName;
|
|
7
|
-
|
|
8
7
|
const path = require(`path`);
|
|
9
|
-
|
|
10
8
|
const Url = require(`url`);
|
|
11
|
-
|
|
12
9
|
const {
|
|
13
10
|
createFilePath
|
|
14
11
|
} = require(`gatsby-core-utils`);
|
|
12
|
+
|
|
15
13
|
/**
|
|
16
14
|
* getParsedPath
|
|
17
15
|
* --
|
|
@@ -21,13 +19,11 @@ const {
|
|
|
21
19
|
* @param {String} url
|
|
22
20
|
* @return {Object} path
|
|
23
21
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
22
|
exports.createFilePath = createFilePath;
|
|
27
|
-
|
|
28
23
|
function getParsedPath(url) {
|
|
29
24
|
return path.parse(Url.parse(url).pathname);
|
|
30
25
|
}
|
|
26
|
+
|
|
31
27
|
/**
|
|
32
28
|
* getRemoteFileExtension
|
|
33
29
|
* --
|
|
@@ -37,11 +33,10 @@ function getParsedPath(url) {
|
|
|
37
33
|
* @param {String} url
|
|
38
34
|
* @return {String} extension
|
|
39
35
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
36
|
function getRemoteFileExtension(url) {
|
|
43
37
|
return getParsedPath(url).ext;
|
|
44
38
|
}
|
|
39
|
+
|
|
45
40
|
/**
|
|
46
41
|
* getRemoteFileName
|
|
47
42
|
* --
|
|
@@ -51,10 +46,10 @@ function getRemoteFileExtension(url) {
|
|
|
51
46
|
* @param {String} url
|
|
52
47
|
* @return {String} filename
|
|
53
48
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
49
|
function getRemoteFileName(url) {
|
|
57
50
|
return decodeURIComponent(getParsedPath(url).name);
|
|
58
|
-
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// createFilePath should be imported from `gatsby-core-utils`
|
|
59
54
|
// but some plugins already do import it from `gatsby-source-filesystem/utils`
|
|
60
55
|
// so just keeping re-export here for backward compatibility
|