Skip to content

Commit

Permalink
update to get-workspaces plugin (#32)
Browse files Browse the repository at this point in the history
* update to get-workspaces plugin

* fix build to include index so this is isntallable
  • Loading branch information
Noviny authored and emmatown committed Nov 11, 2019
1 parent 3153eb3 commit 4fbc692
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-windows-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@manypkg/gatsby-source-workspace": minor
---

Add new config option, which allows the user to specify the package.json fields they want to include
5 changes: 5 additions & 0 deletions .changeset/old-knives-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@manypkg/gatsby-source-workspace": patch
---

Include `version` field by default
19 changes: 15 additions & 4 deletions packages/gatsby-source-workspace/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,36 @@ to 'meta' - this might still be the wrong name but I want to try it out.
(meta represents the full contents of the package.json)
*/

exports.createSchemaCustomization = ({ actions }) => {
exports.createSchemaCustomization = ({ actions }, { extraFields }) => {
let { createTypes } = actions;

let typeDefs = `
type workspaceInfo implements Node {
name: String
version: String
dir: String
relativeDir: String
manifest: JSON!
${extraFields
.map(({ name, definition }) => `${name}: ${definition}`)
.join("\n ")}
}
`;
createTypes(typeDefs);
};

exports.sourceNodes = async ({ actions }, pluginOptions) => {
exports.sourceNodes = async ({ actions }, { cwd, extraFields }) => {
let { createNode } = actions;
let cwd = pluginOptions.cwd || process.cwd();
cwd = cwd || process.cwd();
let repoRoot = await findWorkspacesRoot(cwd);
let workspaces = await getWorkspaces({ cwd: repoRoot });

for (let { name, dir, config: manifest } of workspaces) {
createNode({
let newNode = {
name,
dir,
relativeDir: path.relative(cwd, dir),
version: manifest.version,
manifest,
id: name,
internal: {
Expand All @@ -43,6 +48,12 @@ exports.sourceNodes = async ({ actions }, pluginOptions) => {
}),
type: "workspaceInfo"
}
};

extraFields.forEach(({ name }) => {
newNode[name] = manifest[name];
});

createNode(newNode);
}
};
3 changes: 2 additions & 1 deletion packages/gatsby-source-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"get-workspaces": "^0.5.0"
},
"files": [
"gatsby-node.js"
"gatsby-node.js",
"index.js"
]
}
12 changes: 11 additions & 1 deletion test-gatsby/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ async function getGatsbyConfig() {
path: `${__dirname}/src/pages`
}
},
"@manypkg/gatsby-source-workspace",
{
resolve: "@manypkg/gatsby-source-workspace",
options: {
extraFields: [
{
name: "license",
definition: `String`
}
]
}
},
{
resolve: `gatsby-source-filesystem`,
options: {
Expand Down

0 comments on commit 4fbc692

Please sign in to comment.