From 2e7207ae436ee95ed1e2eae59df619fab7454a1b Mon Sep 17 00:00:00 2001 From: Harshil Agrawal Date: Sat, 26 Jan 2019 00:54:16 +0530 Subject: [PATCH 1/6] gatsby-source-mongodb sanitizeName fix --- packages/gatsby-source-mongodb/src/__tests__/utility.js | 7 +++++++ packages/gatsby-source-mongodb/src/gatsby-node.js | 5 +---- packages/gatsby-source-mongodb/src/utility.js | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 packages/gatsby-source-mongodb/src/__tests__/utility.js create mode 100644 packages/gatsby-source-mongodb/src/utility.js diff --git a/packages/gatsby-source-mongodb/src/__tests__/utility.js b/packages/gatsby-source-mongodb/src/__tests__/utility.js new file mode 100644 index 0000000000000..82180ef30b351 --- /dev/null +++ b/packages/gatsby-source-mongodb/src/__tests__/utility.js @@ -0,0 +1,7 @@ +const { sanitizeName } = require(`../utility`) + +it(`removes unsupporterd characters from name`, () => { + const name = `one-two-three` + const output = sanitizeName(name) + expect(output.search(/-/)).toEqual(-1) +}) diff --git a/packages/gatsby-source-mongodb/src/gatsby-node.js b/packages/gatsby-source-mongodb/src/gatsby-node.js index a4ba3535235cc..ec260b96f2153 100644 --- a/packages/gatsby-source-mongodb/src/gatsby-node.js +++ b/packages/gatsby-source-mongodb/src/gatsby-node.js @@ -1,6 +1,7 @@ const MongoClient = require(`mongodb`).MongoClient const crypto = require(`crypto`) const prepareMappingChildNode = require(`./mapping`) +const { sanitizeName } = require(`./utility`) const _ = require(`lodash`) const queryString = require(`query-string`) @@ -131,10 +132,6 @@ function createNodes( }) } -function sanitizeName(s) { - return s.replace(/[^_a-zA-Z0-9]/, ``).replace(/\b\w/g, l => l.toUpperCase()) -} - function getConnectionExtraParams(extraParams) { let connectionSuffix if (extraParams) { diff --git a/packages/gatsby-source-mongodb/src/utility.js b/packages/gatsby-source-mongodb/src/utility.js new file mode 100644 index 0000000000000..b6548eff9d05f --- /dev/null +++ b/packages/gatsby-source-mongodb/src/utility.js @@ -0,0 +1,5 @@ +function sanitizeName(s) { + return s.replace(/[^_a-zA-Z0-9]/g, ``).replace(/\b\w/g, l => l.toUpperCase()) +} + +exports.sanitizeName = sanitizeName From 3b963406c01b58545075a2cc143aead48d26f9b5 Mon Sep 17 00:00:00 2001 From: Harshil Agrawal Date: Sat, 26 Jan 2019 01:58:02 +0530 Subject: [PATCH 2/6] changed name, changed exports to module.exports --- .../gatsby-source-mongodb/src/__tests__/sanitize-name.js | 7 +++++++ packages/gatsby-source-mongodb/src/__tests__/utility.js | 7 ------- packages/gatsby-source-mongodb/src/gatsby-node.js | 2 +- .../src/{utility.js => sanitize-name.js} | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js delete mode 100644 packages/gatsby-source-mongodb/src/__tests__/utility.js rename packages/gatsby-source-mongodb/src/{utility.js => sanitize-name.js} (75%) diff --git a/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js b/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js new file mode 100644 index 0000000000000..67543a9e4ae16 --- /dev/null +++ b/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js @@ -0,0 +1,7 @@ +const { sanitizeName } = require(`../sanitize-name`) + +it(`removes unsupported characters from name`, () => { + const name = `one-two-three` + const output = sanitizeName(name) + expect(output).not.toContain(`-`) +}) diff --git a/packages/gatsby-source-mongodb/src/__tests__/utility.js b/packages/gatsby-source-mongodb/src/__tests__/utility.js deleted file mode 100644 index 82180ef30b351..0000000000000 --- a/packages/gatsby-source-mongodb/src/__tests__/utility.js +++ /dev/null @@ -1,7 +0,0 @@ -const { sanitizeName } = require(`../utility`) - -it(`removes unsupporterd characters from name`, () => { - const name = `one-two-three` - const output = sanitizeName(name) - expect(output.search(/-/)).toEqual(-1) -}) diff --git a/packages/gatsby-source-mongodb/src/gatsby-node.js b/packages/gatsby-source-mongodb/src/gatsby-node.js index ec260b96f2153..29b6575cd739f 100644 --- a/packages/gatsby-source-mongodb/src/gatsby-node.js +++ b/packages/gatsby-source-mongodb/src/gatsby-node.js @@ -1,7 +1,7 @@ const MongoClient = require(`mongodb`).MongoClient const crypto = require(`crypto`) const prepareMappingChildNode = require(`./mapping`) -const { sanitizeName } = require(`./utility`) +const { sanitizeName } = require(`./sanitize-name`) const _ = require(`lodash`) const queryString = require(`query-string`) diff --git a/packages/gatsby-source-mongodb/src/utility.js b/packages/gatsby-source-mongodb/src/sanitize-name.js similarity index 75% rename from packages/gatsby-source-mongodb/src/utility.js rename to packages/gatsby-source-mongodb/src/sanitize-name.js index b6548eff9d05f..dfdd4a23fb5e8 100644 --- a/packages/gatsby-source-mongodb/src/utility.js +++ b/packages/gatsby-source-mongodb/src/sanitize-name.js @@ -2,4 +2,4 @@ function sanitizeName(s) { return s.replace(/[^_a-zA-Z0-9]/g, ``).replace(/\b\w/g, l => l.toUpperCase()) } -exports.sanitizeName = sanitizeName +module.exports = { sanitizeName } From d1f39fb496dbb08940c847cdcd4ad127498a33a6 Mon Sep 17 00:00:00 2001 From: Harshil Agrawal Date: Wed, 6 Feb 2019 20:18:07 +0530 Subject: [PATCH 3/6] changed export and import as per review --- packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js | 2 +- packages/gatsby-source-mongodb/src/sanitize-name.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js b/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js index 67543a9e4ae16..4edbf698d9e19 100644 --- a/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js +++ b/packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js @@ -1,4 +1,4 @@ -const { sanitizeName } = require(`../sanitize-name`) +const sanitizeName = require(`../sanitize-name`) it(`removes unsupported characters from name`, () => { const name = `one-two-three` diff --git a/packages/gatsby-source-mongodb/src/sanitize-name.js b/packages/gatsby-source-mongodb/src/sanitize-name.js index dfdd4a23fb5e8..c5edc847e6d01 100644 --- a/packages/gatsby-source-mongodb/src/sanitize-name.js +++ b/packages/gatsby-source-mongodb/src/sanitize-name.js @@ -1,5 +1,5 @@ -function sanitizeName(s) { +module.exports = function sanitizeName(s) { return s.replace(/[^_a-zA-Z0-9]/g, ``).replace(/\b\w/g, l => l.toUpperCase()) } -module.exports = { sanitizeName } +// module.exports = { sanitizeName } From 4acf60012180c34ecf85081f933971424493f7e8 Mon Sep 17 00:00:00 2001 From: Harshil Agrawal Date: Wed, 6 Feb 2019 20:29:24 +0530 Subject: [PATCH 4/6] fixed conflicting issues --- packages/gatsby-source-mongodb/src/gatsby-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-mongodb/src/gatsby-node.js b/packages/gatsby-source-mongodb/src/gatsby-node.js index 29b6575cd739f..c35965d5a51a1 100644 --- a/packages/gatsby-source-mongodb/src/gatsby-node.js +++ b/packages/gatsby-source-mongodb/src/gatsby-node.js @@ -1,7 +1,7 @@ const MongoClient = require(`mongodb`).MongoClient const crypto = require(`crypto`) const prepareMappingChildNode = require(`./mapping`) -const { sanitizeName } = require(`./sanitize-name`) +const sanitizeName = require(`./sanitize-name`) const _ = require(`lodash`) const queryString = require(`query-string`) From da29aba1348e1204f62b793644e128a418c9e174 Mon Sep 17 00:00:00 2001 From: Dustin Schau Date: Wed, 20 Feb 2019 23:01:34 +0530 Subject: [PATCH 5/6] removed lodash As suggested, since lodash is not being used, it is not required Co-Authored-By: harshil1712 --- packages/gatsby-source-mongodb/src/gatsby-node.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/gatsby-source-mongodb/src/gatsby-node.js b/packages/gatsby-source-mongodb/src/gatsby-node.js index 94289055c3ef5..299c83825aab1 100644 --- a/packages/gatsby-source-mongodb/src/gatsby-node.js +++ b/packages/gatsby-source-mongodb/src/gatsby-node.js @@ -2,7 +2,6 @@ const MongoClient = require(`mongodb`).MongoClient const crypto = require(`crypto`) const prepareMappingChildNode = require(`./mapping`) const sanitizeName = require(`./sanitize-name`) -const _ = require(`lodash`) const queryString = require(`query-string`) exports.sourceNodes = ( From b35a7259e6063d1cd70757a5f7d3cd17d530549a Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Tue, 12 Mar 2019 13:03:46 +0100 Subject: [PATCH 6/6] fix review --- packages/gatsby-source-mongodb/src/sanitize-name.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/gatsby-source-mongodb/src/sanitize-name.js b/packages/gatsby-source-mongodb/src/sanitize-name.js index c5edc847e6d01..2487eb8eb92c3 100644 --- a/packages/gatsby-source-mongodb/src/sanitize-name.js +++ b/packages/gatsby-source-mongodb/src/sanitize-name.js @@ -1,5 +1,3 @@ module.exports = function sanitizeName(s) { return s.replace(/[^_a-zA-Z0-9]/g, ``).replace(/\b\w/g, l => l.toUpperCase()) } - -// module.exports = { sanitizeName }