Skip to content

Commit

Permalink
Don't use path module in browser builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Apr 27, 2024
1 parent 5ac58a1 commit 4bd14e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 1 addition & 3 deletions lib/docx/docx-reader.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions lib/docx/files.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -20,7 +21,7 @@ function Files(base) {
});
});
}

function resolveUri(uri) {
var path = uriToPath(uri);
if (isAbsolutePath(path)) {
Expand All @@ -31,20 +32,28 @@ 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));


function uriToPath(uriString, platform) {
if (!platform) {
platform = os.platform();
}

var uri = url.parse(uriString);
if (isLocalFileUri(uri) || isRelativeUri(uri)) {
var path = decodeURIComponent(uri.path);
Expand Down

0 comments on commit 4bd14e9

Please sign in to comment.