gatsby-source-filesystem 5.5.0-next.0 → 5.5.0-next.1

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 CHANGED
@@ -3,6 +3,14 @@
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.4.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-source-filesystem@5.4.0/packages/gatsby-source-filesystem) (2023-01-10)
7
+
8
+ [🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v5.4)
9
+
10
+ #### Chores
11
+
12
+ - update babel monorepo [#37386](https://github.com/gatsbyjs/gatsby/issues/37386) ([b941876](https://github.com/gatsbyjs/gatsby/commit/b94187633d94d0f0071b38ffe93380dd802ec70f))
13
+
6
14
  ### [5.3.1](https://github.com/gatsbyjs/gatsby/commits/gatsby-source-filesystem@5.3.1/packages/gatsby-source-filesystem) (2022-12-14)
7
15
 
8
16
  **Note:** Version bump only for package gatsby-source-filesystem
package/README.md CHANGED
@@ -1,35 +1,28 @@
1
1
  # gatsby-source-filesystem
2
2
 
3
- A Gatsby source plugin for sourcing data into your Gatsby application
4
- from your local filesystem.
3
+ A Gatsby source plugin for sourcing data into your Gatsby application from your local filesystem.
5
4
 
6
- The plugin creates `File` nodes from files. The various "transformer"
7
- plugins can transform `File` nodes into various other types of data e.g.
8
- `gatsby-transformer-json` transforms JSON files into JSON data nodes and
9
- `gatsby-transformer-remark` transforms markdown files into `MarkdownRemark`
10
- nodes from which you can query an HTML representation of the markdown.
5
+ The plugin creates `File` nodes from files. The various "transformer" plugins can transform `File` nodes into various other types of data e.g. [`gatsby-transformer-json`](https://www.gatsbyjs.com/plugins/gatsby-transformer-json/) transforms JSON files into JSON data nodes and [`gatsby-transformer-remark`](https://www.gatsbyjs.com/plugins/gatsby-transformer-remark/) transforms markdown files into `MarkdownRemark` nodes from which you can query an HTML representation of the markdown.
11
6
 
12
7
  ## Install
13
8
 
14
- `npm install gatsby-source-filesystem`
9
+ ```shell
10
+ npm install gatsby-source-filesystem
11
+ ```
15
12
 
16
13
  ## How to use
17
14
 
18
- ```javascript
19
- // In your gatsby-config.js
15
+ You can have multiple instances of this plugin to read source nodes from different locations on your filesystem. Be sure to give each instance a unique `name`.
16
+
17
+ ```js:title=gatsby-config.js
20
18
  module.exports = {
21
19
  plugins: [
22
- // You can have multiple instances of this plugin
23
- // to read source nodes from different locations on your
24
- // filesystem.
25
- //
26
- // The following sets up the Jekyll pattern of having a
27
- // "pages" directory for Markdown files and a "data" directory
28
- // for `.json`, `.yaml`, `.csv`.
29
20
  {
30
21
  resolve: `gatsby-source-filesystem`,
31
22
  options: {
23
+ // The unique name for each instance
32
24
  name: `pages`,
25
+ // Path to the directory
33
26
  path: `${__dirname}/src/pages/`,
34
27
  },
35
28
  },
@@ -38,7 +31,10 @@ module.exports = {
38
31
  options: {
39
32
  name: `data`,
40
33
  path: `${__dirname}/src/data/`,
41
- ignore: [`**/\.*`], // ignore files starting with a dot
34
+ // Ignore files starting with a dot
35
+ ignore: [`**/\.*`],
36
+ // Use "mtime" and "inode" to fingerprint files (to check if file has changed)
37
+ fastHash: true,
42
38
  },
43
39
  },
44
40
  ],
@@ -47,9 +43,23 @@ module.exports = {
47
43
 
48
44
  ## Options
49
45
 
50
- In addition to the name and path parameters you may pass an optional `ignore` array of file globs to ignore.
46
+ ### name
47
+
48
+ **Required**
49
+
50
+ A unique name for the `gatsby-source-filesytem` instance. This name will also be a key on the `File` node called `sourceInstanceName`. You can use this e.g. for filtering.
51
+
52
+ ### path
53
+
54
+ **Required**
55
+
56
+ Path to the folder that should be sourced. Ideally an absolute path.
51
57
 
52
- They will be added to the following default list:
58
+ ### ignore
59
+
60
+ **Optional**
61
+
62
+ Array of file globs to ignore. They will be added to the following default list:
53
63
 
54
64
  ```text
55
65
  **/*.un~
@@ -62,8 +72,24 @@ They will be added to the following default list:
62
72
  ../**/dist/**
63
73
  ```
64
74
 
75
+ ### fastHash
76
+
77
+ **Optional**
78
+
79
+ By default, `gatsby-source-filesystem` creates an MD5 hash of each file to determine if it has changed between sourcing. However, on sites with many large files this can lead to a significant slowdown. Thus you can enable the `fastHash` setting to use an alternative hashing mechanism.
80
+
81
+ `fastHash` uses the `mtime` and `inode` to fingerprint the files. On a modern OS this can be considered a robust solution to determine if a file has changed, however on older systems it can be unreliable. Therefore it's not enabled by default.
82
+
83
+ ### Environment variables
84
+
65
85
  To prevent concurrent requests overload of `processRemoteNode`, you can adjust the `200` default concurrent downloads, with `GATSBY_CONCURRENT_DOWNLOAD` environment variable.
66
86
 
87
+ In case that due to spotty network, or slow connection, some remote files fail to download. Even after multiple retries and adjusting concurrent downloads, you can adjust timeout and retry settings with these environment variables:
88
+
89
+ - `GATSBY_STALL_RETRY_LIMIT`, default: `3`
90
+ - `GATSBY_STALL_TIMEOUT`, default: `30000`
91
+ - `GATSBY_CONNECTION_TIMEOUT`, default: `30000`
92
+
67
93
  ## How to query
68
94
 
69
95
  You can query file nodes like the following:
@@ -263,7 +289,7 @@ The `createFileNodeFromBuffer` helper accepts a `Buffer`, caches its contents to
263
289
 
264
290
  The name of the file can be passed to the `createFileNodeFromBuffer` helper. If no name is given, the content hash will be used to determine the name.
265
291
 
266
- ## Example usage
292
+ #### Example usage
267
293
 
268
294
  The following example is adapted from the source of [`gatsby-source-mysql`](https://github.com/malcolm-kee/gatsby-source-mysql):
269
295
 
@@ -338,11 +364,3 @@ function createMySqlNodes({ name, __sql, idField, keys }, results, ctx) {
338
364
 
339
365
  module.exports = createMySqlNodes
340
366
  ```
341
-
342
- ## Troubleshooting
343
-
344
- In case that due to spotty network, or slow connection, some remote files fail to download. Even after multiple retries and adjusting concurrent downloads, you can adjust timeout and retry settings with these environment variables:
345
-
346
- - `GATSBY_STALL_RETRY_LIMIT`, default: `3`
347
- - `GATSBY_STALL_TIMEOUT`, default: `30000`
348
- - `GATSBY_CONNECTION_TIMEOUT`, default: `30000`
@@ -4,12 +4,12 @@ const path = require(`path`);
4
4
  const fs = require(`fs-extra`);
5
5
  const mime = require(`mime`);
6
6
  const prettyBytes = require(`pretty-bytes`);
7
- const md5File = require(`md5-file`);
8
7
  const {
9
8
  createContentDigest,
10
- slash
9
+ slash,
10
+ md5File
11
11
  } = require(`gatsby-core-utils`);
12
- exports.createFileNode = async (pathToFile, createNodeId, pluginOptions = {}) => {
12
+ exports.createFileNode = async (pathToFile, createNodeId, pluginOptions = {}, cache = null) => {
13
13
  const slashed = slash(pathToFile);
14
14
  const parsedSlashed = path.parse(slashed);
15
15
  const slashedFile = {
@@ -31,7 +31,19 @@ exports.createFileNode = async (pathToFile, createNodeId, pluginOptions = {}) =>
31
31
  description: `Directory "${path.relative(process.cwd(), slashed)}"`
32
32
  };
33
33
  } else {
34
- const contentDigest = await md5File(slashedFile.absolutePath);
34
+ const key = stats.mtimeMs.toString() + stats.ino.toString();
35
+ let contentDigest;
36
+ if (pluginOptions.fastHash) {
37
+ // Skip hashing.
38
+ contentDigest = key;
39
+ } else {
40
+ // Generate a hash, but only if the file has changed.
41
+ contentDigest = cache && (await cache.get(key));
42
+ if (!contentDigest) {
43
+ contentDigest = await md5File(slashedFile.absolutePath);
44
+ if (cache) await cache.set(key, contentDigest);
45
+ }
46
+ }
35
47
  const mediaType = mime.getType(slashedFile.ext);
36
48
  internal = {
37
49
  contentDigest,
package/gatsby-node.js CHANGED
@@ -32,10 +32,11 @@ const createFSMachine = ({
32
32
  },
33
33
  getNode,
34
34
  createNodeId,
35
- reporter
35
+ reporter,
36
+ cache
36
37
  }, pluginOptions) => {
37
38
  const createAndProcessNode = path => {
38
- const fileNodePromise = createFileNode(path, createNodeId, pluginOptions).then(fileNode => {
39
+ const fileNodePromise = createFileNode(path, createNodeId, pluginOptions, cache).then(fileNode => {
39
40
  createNode(fileNode);
40
41
  return null;
41
42
  });
@@ -190,6 +191,7 @@ exports.pluginOptionsSchema = ({
190
191
  }) => Joi.object({
191
192
  name: Joi.string(),
192
193
  path: Joi.string(),
194
+ fastHash: Joi.boolean().default(false),
193
195
  ignore: Joi.array().items(Joi.string(), Joi.object().regex(), Joi.function())
194
196
  });
195
197
  exports.sourceNodes = (api, pluginOptions) => {
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": "5.5.0-next.0",
4
+ "version": "5.5.0-next.1",
5
5
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
6
6
  "bugs": {
7
7
  "url": "https://github.com/gatsbyjs/gatsby/issues"
@@ -10,10 +10,9 @@
10
10
  "@babel/runtime": "^7.20.7",
11
11
  "chokidar": "^3.5.3",
12
12
  "file-type": "^16.5.4",
13
- "fs-extra": "^10.1.0",
14
- "gatsby-core-utils": "^4.5.0-next.0",
15
- "md5-file": "^5.0.0",
16
- "mime": "^2.6.0",
13
+ "fs-extra": "^11.1.0",
14
+ "gatsby-core-utils": "^4.5.0-next.1",
15
+ "mime": "^3.0.0",
17
16
  "pretty-bytes": "^5.6.0",
18
17
  "valid-url": "^1.0.9",
19
18
  "xstate": "^4.34.0"
@@ -47,5 +46,5 @@
47
46
  "engines": {
48
47
  "node": ">=18.0.0"
49
48
  },
50
- "gitHead": "4ef5d775d18329abc5d4e78d1e0a99e904f00cd1"
49
+ "gitHead": "f8f084ae96bd105509903216daa766325ec65b9e"
51
50
  }