diff --git a/lib/server/versionFallback.js b/lib/server/versionFallback.js index 7abf1a3317..c938726e8a 100644 --- a/lib/server/versionFallback.js +++ b/lib/server/versionFallback.js @@ -9,7 +9,6 @@ const CWD = process.cwd(); const glob = require("glob"); const fs = require("fs"); const path = require("path"); -const diff = require("diff"); const assert = require("assert"); const siteConfig = require(CWD + "/siteConfig.js"); @@ -66,7 +65,10 @@ function extractMetadata(content) { for (let i = 0; i < lines.length - 1; ++i) { const keyvalue = lines[i].split(":"); const key = keyvalue[0].trim(); - let value = keyvalue.slice(1).join(":").trim(); + let value = keyvalue + .slice(1) + .join(":") + .trim(); try { value = JSON.parse(value); } catch (e) {} @@ -95,18 +97,20 @@ files.forEach(file => { const metadata = res.metadata; if (!metadata.original_id) { - console.error(`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`); + console.error( + `No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?` + ); throw new Error( `No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?` ); } if (!metadata.id) { console.error(`No 'id' field found in ${file}.`); - throw new Error( - `No 'id' field found in ${file}.` + throw new Error(`No 'id' field found in ${file}.`); + } else if (metadata.id.indexOf("version-") === -1) { + console.error( + `The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?` ); - } else if (metadata.id.indexOf('version-') === -1) { - console.error(`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`); throw new Error( `The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?` ); @@ -174,16 +178,10 @@ function diffLatestDoc(file, id) { return true; } - const diffs = diff.diffChars( - extractMetadata(fs.readFileSync(latestFile, "utf8")).rawContent, - extractMetadata(fs.readFileSync(file, "utf8")).rawContent + return ( + extractMetadata(fs.readFileSync(latestFile, "utf8")).rawContent.trim() !== + extractMetadata(fs.readFileSync(file, "utf8")).rawContent.trim() ); - diffs.forEach(part => { - if (part.added || part.removed) { - return true; - } - }); - return false; } // return metadata for a versioned file given the file, its version (requested), diff --git a/package.json b/package.json index bbab1b50db..2deb443c53 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "classnames": "^2.2.5", "commander": "^2.11.0", "crowdin-cli": "^0.3.0", - "diff": "^3.3.0", "escape-string-regexp": "^1.0.5", "express": "^4.15.3", "feed": "^1.1.0", diff --git a/yarn.lock b/yarn.lock index 293100e690..29a75fc17e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -808,10 +808,6 @@ detect-indent@^4.0.0: dependencies: repeating "^2.0.0" -diff@^3.3.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c" - ecc-jsbn@~0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505"