gatsby-transformer-javascript-frontmatter
Advanced tools
Comparing version 1.1.0-alpha.9d4de2a6 to 1.1.0-alpha.9fe50b00
@@ -19,9 +19,9 @@ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator"); | ||
getNode, | ||
boundActionCreators, | ||
actions, | ||
loadNodeContent | ||
}) { | ||
const createNode = boundActionCreators.createNode, | ||
createParentChildLink = boundActionCreators.createParentChildLink; // This only processes javascript files. | ||
const createNode = actions.createNode, | ||
createParentChildLink = actions.createParentChildLink; // This only processes javascript & jsx files. | ||
if (node.internal.mediaType !== `application/javascript`) { | ||
if (node.internal.mediaType !== `application/javascript` && node.internal.mediaType !== `text/jsx`) { | ||
return; | ||
@@ -36,3 +36,3 @@ } | ||
}; | ||
let exportsData, frontmatter; | ||
let exportsData, frontmatter, error; | ||
@@ -64,2 +64,3 @@ try { | ||
frontmatter = {}; | ||
error = false; | ||
traverse(ast, { | ||
@@ -87,40 +88,41 @@ AssignmentExpression: function AssignmentExpression(astPath) { | ||
}); | ||
exportsData = Object.assign({}, frontmatter, { | ||
error: false | ||
}); | ||
} catch (e) { | ||
// stick the error on the query so the user can | ||
// react to an error as they see fit | ||
exportsData = Object.assign({}, frontmatter, { | ||
error: { | ||
err: true, | ||
code: e.code, | ||
message: e.message, | ||
stack: e.stack | ||
} | ||
}); | ||
error = { | ||
err: true, | ||
code: e.code, | ||
message: e.message, | ||
stack: e.stack | ||
}; | ||
} finally { | ||
const objStr = JSON.stringify(node); | ||
const contentDigest = crypto.createHash(`md5`).update(objStr).digest(`hex`); | ||
const nodeData = { | ||
id: `${node.id} >>> JavascriptFrontmatter`, | ||
children: [], | ||
parent: node.id, | ||
node: Object.assign({}, node), | ||
internal: { | ||
contentDigest, | ||
type: `JavascriptFrontmatter` | ||
// only create node if frontmatter is not empty | ||
if (!_.isEmpty(frontmatter)) { | ||
exportsData = Object.assign({}, frontmatter, { | ||
error: error | ||
}); | ||
const objStr = JSON.stringify(node); | ||
const contentDigest = crypto.createHash(`md5`).update(objStr).digest(`hex`); | ||
const nodeData = { | ||
id: `${node.id} >>> JavascriptFrontmatter`, | ||
children: [], | ||
parent: node.id, | ||
node: Object.assign({}, node), | ||
internal: { | ||
contentDigest, | ||
type: `JavascriptFrontmatter` | ||
} | ||
}; | ||
nodeData.frontmatter = Object.assign({}, exportsData); | ||
if (node.internal.type === `File`) { | ||
nodeData.fileAbsolutePath = node.absolutePath; | ||
} | ||
}; | ||
nodeData.frontmatter = Object.assign({}, exportsData); | ||
if (node.internal.type === `File`) { | ||
nodeData.fileAbsolutePath = node.absolutePath; | ||
createNode(nodeData); | ||
createParentChildLink({ | ||
parent: node, | ||
child: nodeData | ||
}); | ||
} | ||
createNode(nodeData); | ||
createParentChildLink({ | ||
parent: node, | ||
child: nodeData | ||
}); | ||
} | ||
@@ -127,0 +129,0 @@ }); |
{ | ||
"name": "gatsby-transformer-javascript-frontmatter", | ||
"version": "1.1.0-alpha.9d4de2a6", | ||
"description": "Gatsby transformer plugin for JavaScript to extract exports.frontmatter statically.", | ||
"scripts": { | ||
"build": "babel src --out-dir . --ignore __tests__", | ||
"watch": "babel -w src --out-dir . --ignore __tests__", | ||
"prepublish": "cross-env NODE_ENV=production npm run build" | ||
}, | ||
"keywords": [ | ||
"gatsby", | ||
"gatsby-plugin", | ||
"js" | ||
], | ||
"version": "1.1.0-alpha.9fe50b00", | ||
"author": "Jacob Bolda <me@jacobbolda.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
@@ -24,4 +13,18 @@ "babel-runtime": "^6.26.0", | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.38", | ||
"@babel/core": "^7.0.0-beta.38", | ||
"cross-env": "^5.0.5" | ||
}, | ||
"keywords": [ | ||
"gatsby", | ||
"gatsby-plugin", | ||
"js" | ||
], | ||
"license": "MIT", | ||
"repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-javascript-frontmatter", | ||
"scripts": { | ||
"build": "babel src --out-dir . --ignore __tests__", | ||
"prepublish": "cross-env NODE_ENV=production npm run build", | ||
"watch": "babel -w src --out-dir . --ignore __tests__" | ||
} | ||
} |
@@ -7,3 +7,3 @@ # gatsby-transformer-javascript-frontmatter | ||
`npm install --save gatsby-transformer-frontmatter` | ||
`npm install --save gatsby-transformer-javascript-frontmatter` | ||
@@ -10,0 +10,0 @@ ## How to use |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
7415
111
3