diff --git a/NEWS b/NEWS index 69b2d217..4bbaca1b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +# 1.7.2 + +* Remove the use of the path module from common code used by browser builds. + This should remove the need to polyfill path in the browser. + # 1.7.1 * Handle numbering level definitions without an explicit format. diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js index 5f0fd054..0d72cd76 100644 --- a/lib/docx/docx-reader.js +++ b/lib/docx/docx-reader.js @@ -1,8 +1,6 @@ exports.read = read; exports._findPartPaths = findPartPaths; -var path = require("path"); - var promises = require("../promises"); var documents = require("../documents"); var Result = require("../results").Result; @@ -27,7 +25,7 @@ function read(docxFile, input) { contentTypes: readContentTypesFromZipFile(docxFile), partPaths: findPartPaths(docxFile), docxFile: docxFile, - files: new Files(input.path ? path.dirname(input.path) : null) + files: input.path ? Files.relativeToFile(input.path) : new Files(null) }).also(function(result) { return { styles: readStylesFromZipFile(docxFile, result.partPaths.styles) diff --git a/lib/docx/files.js b/lib/docx/files.js index 6380ea46..502db086 100644 --- a/lib/docx/files.js +++ b/lib/docx/files.js @@ -1,6 +1,7 @@ var fs = require("fs"); var url = require("url"); var os = require("os"); +var dirname = require("path").dirname; var resolvePath = require("path").resolve; var isAbsolutePath = require('path-is-absolute'); @@ -20,7 +21,7 @@ function Files(base) { }); }); } - + function resolveUri(uri) { var path = uriToPath(uri); if (isAbsolutePath(path)) { @@ -31,12 +32,20 @@ function Files(base) { return promises.reject(new Error("could not find external image '" + uri + "', path of input document is unknown")); } } - + return { read: read }; } + +function relativeToFile(filePath) { + return new Files(dirname(filePath)); +} + +Files.relativeToFile = relativeToFile; + + var readFile = promises.promisify(fs.readFile.bind(fs)); @@ -44,7 +53,7 @@ function uriToPath(uriString, platform) { if (!platform) { platform = os.platform(); } - + var uri = url.parse(uriString); if (isLocalFileUri(uri) || isRelativeUri(uri)) { var path = decodeURIComponent(uri.path);