From 4d686a068ee7c8b659134cf5754d6181df386d89 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Mon, 7 Sep 2026 13:57:43 +0200 Subject: [PATCH] Fix grunt build rebundling existing dist via browser field The package.json browser mapping for ./lib/index points browserify at dist/jszip.min.js, so grunt build inlined the existing bundle instead of walking lib/. Temporarily remove that mapping during the build and restore package.json afterward. Signed-off-by: Jon Koops --- Gruntfile.js | 36 ++++++++++++++++++++++++++++++++++- documentation/contributing.md | 19 ++++++++---------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9f1b1b88..633f1c93 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -41,6 +41,40 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-browserify"); grunt.loadNpmTasks("grunt-contrib-uglify"); - grunt.registerTask("build", ["browserify", "uglify"]); + var packagePath = "package.json"; + var browserIndexKey = "./lib/index"; + + grunt.registerTask("unmap-browser-entry", function() { + var original = grunt.file.read(packagePath); + var pkg = JSON.parse(original); + + if (!pkg.browser || !pkg.browser[browserIndexKey]) { + return; + } + + grunt.config.set("packageJsonBackup", original); + var browser = Object.assign({}, pkg.browser); + delete browser[browserIndexKey]; + pkg.browser = browser; + grunt.file.write(packagePath, JSON.stringify(pkg, null, 2)); + }); + + grunt.registerTask("restore-browser-entry", function() { + var original = grunt.config.get("packageJsonBackup"); + + if (!original) { + return; + } + + grunt.file.write(packagePath, original); + grunt.config.set("packageJsonBackup", null); + }); + + grunt.registerTask("build", [ + "unmap-browser-entry", + "browserify", + "uglify", + "restore-browser-entry" + ]); grunt.registerTask("default", ["build"]); }; diff --git a/documentation/contributing.md b/documentation/contributing.md index 05150497..879f247e 100644 --- a/documentation/contributing.md +++ b/documentation/contributing.md @@ -63,16 +63,13 @@ If you have tested bug fixes or new features, you can open a ## Releasing a new version -1. In `package.json` temporarily remove `browser["./lib/index"]`. -2. Run `npm test` +1. Run `npm test` * Locally open http://localhost:8080/test/ * Or use the SauceLabs configuration above -3. Update `JSZip.version` in `index.js`, `index.html` and in `package.json` -4. Run `grunt` to generate the new dist files - * undo the package.json change, it was just needed to replace the `__VERSION__` in the header -5. Undo step 1. -6. Change version back in `package.json` (it will get update by the npm command below) -7. Update CHANGES.md -8. Commit the appropriate changes -9. Run `npm version ...` where `...` is `major`, `minor`, or `patch` -10. Run npm publish +2. Update `JSZip.version` in `index.js`, `index.html` and in `package.json` +3. Run `grunt` to generate the new dist files +4. Change version back in `package.json` (it will get update by the npm command below) +5. Update CHANGES.md +6. Commit the appropriate changes +7. Run `npm version ...` where `...` is `major`, `minor`, or `patch` +8. Run npm publish