{"name":"gatsby-source-filesystem","version":"5.17.0-react19.0","keywords":["gatsby","gatsby-plugin"],"author":{"name":"Kyle Mathews","email":"mathews.kyle@gmail.com"},"license":"MIT","_id":"gatsby-source-filesystem@5.17.0-react19.0","maintainers":[{"name":"pieh","email":"misiek.piechowiak@gmail.com"},{"name":"kathmbeck","email":"katherine.beck@netlify.com"},{"name":"serhalp-netlify","email":"philippe.serhal@netlify.com"},{"name":"mlgualtieri-gatsby","email":"mike.gualtieri@netlify.com"},{"name":"fk","email":"sechskilo@gmail.com"},{"name":"tylerbarnes","email":"tyler@known.design"},{"name":"daniellewgatsby","email":"daniel.lew@gatsbyjs.com"}],"homepage":"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-filesystem#readme","bugs":{"url":"https://github.com/gatsbyjs/gatsby/issues"},"dist":{"shasum":"a19b52c33718fb02cb9a2b9225a64b337ec894ce","tarball":"http://registry-npm.ywwl.com/gatsby-source-filesystem/download/gatsby-source-filesystem-5.17.0-react19.0.tgz","fileCount":15,"integrity":"sha512-nAWHJRuliEUU7FVuOrghhK9r8IWtdCWYIbH1RgSZanAPrBdZm+0M9LsJnOMyYknL8CcJKd0gWZf9FUskbFw6+w==","signatures":[{"sig":"MEQCIEJc4DqAsD6v9HjyriNiFpBEpm8pH9vNQ9mXEkskHGvAAiAKsCrw71rNOaX/3huwhAn2VZQ6rtB+CWU8GYB8WBMCmQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":118734,"size":24089,"noattachment":false,"key":"/gatsby-source-filesystem/-/gatsby-source-filesystem-5.17.0-react19.0.tgz"},"types":"index.d.ts","engines":{"node":">=18.0.0"},"gitHead":"ad34f2199560f6c212ff45c2ebaf33273fc837f0","scripts":{"build":"babel src --out-dir . --ignore \"**/__tests__\"","watch":"babel -w src --out-dir . --ignore \"**/__tests__\"","prepare":"cross-env NODE_ENV=production npm run build"},"_npmUser":{"name":"serhalp-netlify","email":"philippe.serhal@netlify.com"},"deprecated":"This React 19 prerelease version may be selected unexpectedly by npm when resolving version ranges. Please use the latest stable version, or use @next to install React 19 compatible prerelease version.","repository":{"url":"git+https://github.com/gatsbyjs/gatsby.git","type":"git","directory":"packages/gatsby-source-filesystem"},"_npmVersion":"lerna/3.22.1/node@v22.19.0+arm64 (darwin)","description":"Gatsby source plugin for building websites from local data. Markdown, JSON, images, YAML, CSV, and dozens of other data types supported.","directories":{},"_nodeVersion":"22.19.0","dependencies":{"mime":"^3.0.0","xstate":"^4.38.0","chokidar":"^3.6.0","fs-extra":"^11.2.0","file-type":"^16.5.4","valid-url":"^1.0.9","pretty-bytes":"^5.6.0","@babel/runtime":"^7.20.13","gatsby-core-utils":"^4.16.0-next.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"cross-env":"^7.0.3","@babel/cli":"^7.20.7","@babel/core":"^7.20.12","babel-preset-gatsby-package":"^3.16.0-next.0"},"peerDependencies":{"gatsby":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/gatsby-source-filesystem_5.17.0-react19.0_1764189965297_0.5926083429196278","host":"s3://npm-registry-packages-npm-production"},"readme":"# gatsby-source-filesystem\n\nA Gatsby plugin for sourcing data into your Gatsby application from your local filesystem.\n\nThe plugin creates `File` nodes from files. The various [transformer plugins](https://www.gatsbyjs.com/plugins/?=gatsby-transformer) can transform `File` nodes into other types of data e.g. [`gatsby-transformer-json`](https://www.gatsbyjs.com/plugins/gatsby-transformer-json/) transforms JSON files into `JSON` nodes and [`gatsby-transformer-remark`](https://www.gatsbyjs.com/plugins/gatsby-transformer-remark/) transforms markdown files into `MarkdownRemark` nodes.\n\n## Install\n\n```shell\nnpm install gatsby-source-filesystem\n```\n\n## How to use\n\nYou can have multiple instances of this plugin in your `gatsby-config` to read files from different locations on your filesystem. Be sure to give each instance a unique `name`.\n\n```js:title=gatsby-config.js\nmodule.exports = {\n  plugins: [\n    {\n      resolve: `gatsby-source-filesystem`,\n      options: {\n        // The unique name for each instance\n        name: `pages`,\n        // Path to the directory\n        path: `${__dirname}/src/pages/`,\n      },\n    },\n    {\n      resolve: `gatsby-source-filesystem`,\n      options: {\n        name: `data`,\n        path: `${__dirname}/src/data/`,\n        // Ignore files starting with a dot\n        ignore: [`**/\\.*`],\n        // Use \"mtime\" and \"inode\" to fingerprint files (to check if file has changed)\n        fastHash: true,\n      },\n    },\n  ],\n}\n```\n\nIn the above example every file under `src/pages` and `src/data` will be made available as a `File` node inside GraphQL. You don't need to set up another instance of `gatsby-source-filesystem` for e.g. `src/data/images` (since those files are already sourced). However, if you want to be able to filter your files you can set up a new instance and later use the `sourceInstanceName`.\n\n## Options\n\n### name\n\n**Required**\n\nA 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.\n\n### path\n\n**Required**\n\nPath to the folder that should be sourced. Ideally an absolute path.\n\n### ignore\n\n**Optional**\n\nArray of file globs to ignore. They will be added to the following default list:\n\n```text\n**/*.un~\n**/.DS_Store\n**/.gitignore\n**/.npmignore\n**/.babelrc\n**/yarn.lock\n**/node_modules\n../**/dist/**\n```\n\n### fastHash\n\n**Optional**\n\nBy 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.\n\n`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.\n\n### Environment variables\n\n- `GATSBY_CONCURRENT_DOWNLOAD` (default: `200`). To prevent concurrent requests you can configure the concurrency of `processRemoteNode`.\n\nIf you have a spotty network or slow connection, you can adjust the retries and timeouts:\n\n- `GATSBY_STALL_RETRY_LIMIT` (default: `3`)\n- `GATSBY_STALL_TIMEOUT` (default: `30000`)\n- `GATSBY_CONNECTION_TIMEOUT` (default: `30000`)\n\n## How to query\n\nYou can query the `File` nodes as following:\n\n```graphql\n{\n  allFile {\n    nodes {\n      extension\n      dir\n      modifiedTime\n    }\n  }\n}\n```\n\nUse [GraphiQL](https://www.gatsbyjs.com/docs/how-to/querying-data/running-queries-with-graphiql/) to explore all available keys.\n\nTo filter by the `name` you specified in the `gatsby-config`, use `sourceInstanceName`:\n\n```graphql\n{\n  allFile(filter: { sourceInstanceName: { eq: \"data\" } }) {\n    nodes {\n      extension\n      dir\n      modifiedTime\n    }\n  }\n}\n```\n\n## Helper functions\n\n`gatsby-source-filesystem` exports three helper functions:\n\n- [`createFilePath`](#createfilepath)\n- [`createRemoteFileNode`](#createremotefilenode)\n- [`createFileNodeFromBuffer`](#createfilenodefrombuffer)\n\n### `createFilePath`\n\nWhen building pages from files, you often want to create a URL from a file's path on the filesystem. For example, if you have a markdown file at `src/content/2018-01-23-my-blog-post/index.md`, you might want to turn that into a page on your site at `example.com/blog/2018-01-23-my-blog-post/`. `createFilePath` is a helper function to make this task easier.\n\n```javascript\ncreateFilePath({\n  // The node you'd like to convert to a path\n  // e.g. from a markdown, JSON, YAML file, etc.\n  node,\n  // Method used to get a node\n  // The parameter from `onCreateNode` should be passed in here\n  getNode,\n  // The base path for your files.\n  // It is relative to the `options.path` setting in the `gatsby-source-filesystem` entries of your `gatsby-config`.\n  // Defaults to `src/pages`. For the example above, you'd use `src/content`.\n  basePath,\n  // Whether you want your file paths to contain a trailing `/` slash\n  // Defaults to true\n  trailingSlash,\n})\n```\n\n#### Example\n\n```js:title=gatsby-node.js\nconst { createFilePath } = require(`gatsby-source-filesystem`)\n\nexports.onCreateNode = ({ node, getNode, actions }) => {\n  const { createNodeField } = actions\n  // Ensures we are processing only markdown files\n  if (node.internal.type === \"MarkdownRemark\") {\n    // Use `createFilePath` to turn markdown files in our `src/content` directory into `/blog/slug`\n    const relativeFilePath = createFilePath({\n      node,\n      getNode,\n      basePath: \"src/content\",\n    })\n\n    // Creates new query'able field with name of 'slug'\n    createNodeField({\n      node,\n      name: \"slug\",\n      value: `/blog${relativeFilePath}`,\n    })\n  }\n}\n```\n\n### `createRemoteFileNode`\n\nWhen building source plugins for remote data sources (Headless CMSs, APIs, etc.), their data will often link to files stored remotely that are often convenient to download so you can work with them locally.\n\nThe `createRemoteFileNode` helper makes it easy to download remote files and add them to your site's GraphQL schema.\n\nWhile downloading the assets, special characters (regex: `/:|\\/|\\*|\\?|\"|<|>|\\||\\\\/g`) in filenames are replaced with a hyphen \"-\". When special characters are found a file hash is added to keep files unique e.g `a:file.jpg` becomes `a-file-73hd.jpg` (as otherwise `a:file.jpg` and `a*file.jpg` would overwrite themselves).\n\n```javascript\ncreateRemoteFileNode({\n  // The source url of the remote file\n  url: `https://example.com/a-file.jpg`,\n  // The id of the parent node (i.e. the node to which the new remote File node will be linked to)\n  parentNodeId,\n  // Gatsby's cache which the helper uses to check if the file has been downloaded already. It's passed to all Node APIs.\n  getCache,\n  // The action used to create nodes\n  createNode,\n  // A helper function for creating node Ids\n  createNodeId,\n  // OPTIONAL\n  // Adds htaccess authentication to the download request if passed in.\n  auth: { htaccess_user: `USER`, htaccess_pass: `PASSWORD` },\n  // OPTIONAL\n  // Adds extra http headers to download request if passed in.\n  httpHeaders: { Authorization: `Bearer someAccessToken` },\n  // OPTIONAL\n  // Sets the file extension\n  ext: `.jpg`,\n})\n```\n\n#### Example\n\nThe following example is pulled from the [Preprocessing External Images guide](https://www.gatsbyjs.com/docs/how-to/images-and-media/preprocessing-external-images/). Downloaded files are created as `File` nodes and then linked to the `MarkdownRemark` node, so it can be used with e.g. [`gatsby-plugin-image`](https://www.gatsbyjs.com/docs/how-to/images-and-media/using-gatsby-plugin-image/). The file node can then be queried using GraphQL.\n\n```js:title=gatsby-node.js\nconst { createRemoteFileNode } = require(\"gatsby-source-filesystem\")\n\nexports.onCreateNode = async ({\n  node,\n  actions: { createNode, createNodeField },\n  createNodeId,\n  getCache,\n}) => {\n  // For all MarkdownRemark nodes that have a featured image url, call createRemoteFileNode\n  if (\n    node.internal.type === \"MarkdownRemark\" &&\n    node.frontmatter.featuredImgUrl !== null\n  ) {\n    const fileNode = await createRemoteFileNode({\n      url: node.frontmatter.featuredImgUrl, // string that points to the URL of the image\n      parentNodeId: node.id, // id of the parent node of the fileNode you are going to create\n      createNode, // helper function in gatsby-node to generate the node\n      createNodeId, // helper function in gatsby-node to generate the node id\n      getCache,\n    })\n\n    // if the file was created, extend the node with \"localFile\"\n    if (fileNode) {\n      createNodeField({ node, name: \"localFile\", value: fileNode.id })\n    }\n  }\n}\n```\n\n#### Retrieving the remote file name and extension\n\nThe helper first tries to retrieve the file name and extension by parsing the url and the path provided (e.g. if the url is `https://example.com/image.jpg`, the extension will be inferred as `.jpg` and the name as `image`). If the url does not contain an extension, `createRemoteFileNode` use the [`file-type`](https://www.npmjs.com/package/file-type) package to infer the file type. Finally, the name and the extension _can_ be explicitly passed, like so:\n\n```javascript\ncreateRemoteFileNode({\n  // The source url of the remote file\n  url: `https://example.com/a-file-without-an-extension`,\n  parentNodeId: node.id,\n  getCache,\n  createNode,\n  createNodeId,\n  // if necessary!\n  ext: `.jpg`,\n  name: `image`,\n})\n```\n\n### `createFileNodeFromBuffer`\n\nWhen working with data that isn't already stored in a file, such as when querying binary/blob fields from a database, it's helpful to cache that data to the filesystem in order to use it with other transformers that accept files as input.\n\nThe `createFileNodeFromBuffer` helper accepts a `Buffer`, caches its contents to disk, and creates a `File` node that points to it.\n\nThe 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.\n\n#### Example\n\nThe following example is adapted from the source of [`gatsby-source-mysql`](https://github.com/malcolm-kee/gatsby-source-mysql):\n\n```js:title=gatsby-node.js\nconst createMySqlNodes = require(`./create-nodes`)\n\nexports.sourceNodes = async ({ actions, createNodeId, getCache }, config) => {\n  const { createNode } = actions\n  const { conn, queries } = config\n  const { db, results } = await query(conn, queries)\n\n  try {\n    queries\n      .map((query, i) => ({ ...query, ___sql: results[i] }))\n      .forEach(result =>\n        createMySqlNodes(result, results, createNode, {\n          createNode,\n          createNodeId,\n          getCache,\n        })\n      )\n    db.end()\n  } catch (e) {\n    console.error(e)\n    db.end()\n  }\n}\n\n// create-nodes.js\nconst { createFileNodeFromBuffer } = require(`gatsby-source-filesystem`)\nconst createNodeHelpers = require(`gatsby-node-helpers`).default\n\nconst { createNodeFactory } = createNodeHelpers({ typePrefix: `mysql` })\n\nfunction attach(node, key, value, ctx) {\n  if (Buffer.isBuffer(value)) {\n    ctx.linkChildren.push(parentNodeId =>\n      createFileNodeFromBuffer({\n        buffer: value,\n        getCache: ctx.getCache,\n        createNode: ctx.createNode,\n        createNodeId: ctx.createNodeId,\n      })\n    )\n    value = `Buffer`\n  }\n\n  node[key] = value\n}\n\nfunction createMySqlNodes({ name, __sql, idField, keys }, results, ctx) {\n  const MySqlNode = createNodeFactory(name)\n  ctx.linkChildren = []\n\n  return __sql.forEach(row => {\n    if (!keys) keys = Object.keys(row)\n\n    const node = { id: row[idField] }\n\n    for (const key of keys) {\n      attach(node, key, row[key], ctx)\n    }\n\n    node = ctx.createNode(node)\n\n    for (const link of ctx.linkChildren) {\n      link(node.id)\n    }\n  })\n}\n\nmodule.exports = createMySqlNodes\n```\n","publish_time":1764189965502,"_cnpm_publish_time":1764189965502,"dist-tags":{"alpha-9689ff":"4.23.0-alpha-9689ff.25","alpha-a5-peer":"4.23.0-alpha-a5-peer.70","alpha-mdx-v2":"4.18.0-alpha-mdx-v2.68","alpha-qe-sm":"3.14.0-alpha-qe-sm.46","alpha-remote-fetch":"3.14.0-alpha-remote-fetch.79","alpha-remote-file":"3.10.0-alpha-remote-file.48","alpha-trailing-slash":"4.5.0-alpha-trailing-slash.71","alpha-transformer-json":"4.14.0-alpha-transformer-json.26","alpha-ts-jit":"4.6.0-alpha-ts-jit.27","alpha-v5":"5.0.0-alpha-v5.d20221012t101120.57","berry-mdx":"2.1.47-berry-mdx.56","coreutils":"3.12.0-coreutils.29","dev-ssr-2":"2.3.26-dev-ssr-2.60","drupal-next":"3.14.0-drupal-next.94","drupal-proxyurl":"5.0.0-alpha-drupal-proxyurl.14","drupal-self-reference":"4.18.0-alpha-drupal-self-reference.18","functions-next":"3.4.0-functions-next.18","image-cdn":"4.9.0-alpha-image-service2.14","image-service":"4.8.0-alpha-image-service.35","incbuild-collections":"2.3.25-incbuild-collections.159","latest":"5.16.0","latest-v3":"3.15.0","latest-v4":"4.25.0","mdxv4-rc":"4.20.0-mdxv4-rc.124","next":"5.17.0-next.0","otp-test":"2.1.19-otp-test.21","pr-20741":"2.1.48-pr-20741.67","preview-gh-api":"4.23.0-alpha-preview-gh-api.26","prompt-restart":"2.2.3-prompt-restart.146","react19":"5.17.0-react19.1","reporter-npm":"2.0.42-reporter-npm.8","telemetry-test":"2.6.0-telemetry-test.360","unifiedroutes":"2.2.4-unifiedroutes.76","v3rc":"3.0.0-v3rc.0","wp-image-cdn-auth":"4.15.0-alpha-wp-image-cdn-auth.45"}}