From b32e8acd7c9234e5c1c96a00a6a69d207e7fdeef Mon Sep 17 00:00:00 2001 From: Jacob Page <85361835+jpage-godaddy@users.noreply.github.com> Date: Thu, 21 Dec 2023 10:57:17 -0800 Subject: [PATCH] Docsify bug workaround (#643) Ensure that `strip-indent@3` is floated to the top of `node_modules` to fix a bug where `docsify-server-renderer` can require that package (which it doesn't have as a declared dependency) and receive version 4 instead, which is an ESM module. --- packages/gasket-plugin-docsify/CHANGELOG.md | 2 ++ packages/gasket-plugin-docsify/lib/create.js | 6 ++++++ packages/gasket-plugin-docsify/lib/index.js | 2 ++ .../gasket-plugin-docsify/test/create.test.js | 15 +++++++++++++++ packages/gasket-plugin-docsify/test/index.test.js | 1 + 5 files changed, 26 insertions(+) create mode 100644 packages/gasket-plugin-docsify/lib/create.js create mode 100644 packages/gasket-plugin-docsify/test/create.test.js diff --git a/packages/gasket-plugin-docsify/CHANGELOG.md b/packages/gasket-plugin-docsify/CHANGELOG.md index 4af2b017a..ef1ec08d0 100644 --- a/packages/gasket-plugin-docsify/CHANGELOG.md +++ b/packages/gasket-plugin-docsify/CHANGELOG.md @@ -1,5 +1,7 @@ # `@gasket/plugin-docsify` +- Workaround to fix `gasket docs` command caused by a [docsify bug](https://github.com/docsifyjs/docsify/issues/2345) + ### 6.34.4 - Upgrade eslint-plugin-unicorn v43 ([#436]) diff --git a/packages/gasket-plugin-docsify/lib/create.js b/packages/gasket-plugin-docsify/lib/create.js new file mode 100644 index 000000000..1a22f9657 --- /dev/null +++ b/packages/gasket-plugin-docsify/lib/create.js @@ -0,0 +1,6 @@ +module.exports = function create(_gasket, { pkg }) { + // Workaround for https://github.com/docsifyjs/docsify/issues/2345 + pkg.add('dependencies', { + 'strip-indent': require('docsify/package.json').dependencies['strip-indent'] + }); +}; diff --git a/packages/gasket-plugin-docsify/lib/index.js b/packages/gasket-plugin-docsify/lib/index.js index 78fb20162..8c2ebb381 100644 --- a/packages/gasket-plugin-docsify/lib/index.js +++ b/packages/gasket-plugin-docsify/lib/index.js @@ -1,8 +1,10 @@ +const create = require('./create'); const docsView = require('./docs-view'); module.exports = { name: require('../package').name, hooks: { + create, docsView, metadata(gasket, meta) { return { diff --git a/packages/gasket-plugin-docsify/test/create.test.js b/packages/gasket-plugin-docsify/test/create.test.js new file mode 100644 index 000000000..85d3cc9b1 --- /dev/null +++ b/packages/gasket-plugin-docsify/test/create.test.js @@ -0,0 +1,15 @@ +const { hooks: { create } } = require('../lib'); +const docsifyPackage = require('docsify/package.json'); + +describe('The create hook', () => { + it('adds a strip-indent dependency to work around a docsify bug', function () { + const context = { pkg: { add: jest.fn() } }; + + create({}, context); + + expect(context.pkg.add).toHaveBeenCalledWith( + 'dependencies', + { 'strip-indent': docsifyPackage.dependencies['strip-indent'] } + ); + }); +}); diff --git a/packages/gasket-plugin-docsify/test/index.test.js b/packages/gasket-plugin-docsify/test/index.test.js index 92c510b01..bab900c81 100644 --- a/packages/gasket-plugin-docsify/test/index.test.js +++ b/packages/gasket-plugin-docsify/test/index.test.js @@ -12,6 +12,7 @@ describe('Plugin', function () { it('has expected hooks', () => { const expected = [ + 'create', 'docsView', 'metadata' ];