summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-04-27 13:24:51 +0100
committerMichael Williamson <mike@zwobble.org>2024-04-27 13:24:51 +0100
commit4bd14e9b3de8e7077e013f652712058e37f3e261 (patch)
tree7d87fc8f805093d3c05d4c9aace07d6472b00ba7
parent5ac58a1269b3d5e55adb17730cd965ace7970b11 (diff)
Don't use path module in browser builds
-rw-r--r--NEWS5
-rw-r--r--lib/docx/docx-reader.js4
-rw-r--r--lib/docx/files.js15
3 files changed, 18 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 69b2d21..4bbaca1 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 5f0fd05..0d72cd7 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 6380ea4..502db08 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);