From 44bbcfe3b149b868e061b1e3cacb177b8760d4fe Mon Sep 17 00:00:00 2001 From: Mark Davis Date: Wed, 24 Apr 2019 19:34:38 -0400 Subject: [PATCH 1/2] fix(runtime-generator): fix module not found errors for custom spriteModule or symbolModule This change fixes module not found errors that could occur when specifying a custom spriteModule or symbolModule. Previously the import statements this loader generated would only work for svg imports made from certain directories. --- lib/runtime-generator.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/runtime-generator.js b/lib/runtime-generator.js index 361b310..4dd37c8 100644 --- a/lib/runtime-generator.js +++ b/lib/runtime-generator.js @@ -1,3 +1,4 @@ +const { isAbsolute, join } = require('path'); const { stringifyRequest } = require('loader-utils'); const { stringify, @@ -16,7 +17,7 @@ const { * @return {string} */ function runtimeGenerator(params) { - const { symbol, config, context } = params; + const { symbol, config, context, loaderContext } = params; const { extract, esModule, spriteModule, symbolModule, runtimeCompat, publicPath } = config; let runtime; @@ -33,8 +34,11 @@ function runtimeGenerator(params) { }`; runtime = generateExport(data, esModule); } else { - const spriteModuleImport = stringifyRequest({ context }, spriteModule); - const symbolModuleImport = stringifyRequest({ context }, symbolModule); + const spriteModuleAbsPath = isAbsolute(spriteModule) ? spriteModule : join(context, spriteModule); + const symbolModuleAbsPath = isAbsolute(symbolModule) ? symbolModule : join(context, symbolModule); + + const spriteModuleImport = stringifyRequest(loaderContext, spriteModuleAbsPath); + const symbolModuleImport = stringifyRequest(loaderContext, symbolModuleAbsPath); runtime = [ generateImport('SpriteSymbol', symbolModuleImport, esModule), From dc931e260a3d6dc3c7fb39d5706aee29276b0768 Mon Sep 17 00:00:00 2001 From: Mark Davis Date: Thu, 25 Apr 2019 09:32:31 -0400 Subject: [PATCH 2/2] fix(configuration): make default config work with yarn PnP This change makes the default values for spriteModule and symbolModule use absolute paths so that they work with yarn plug n play ISSUES CLOSED: 344 --- lib/config.js | 4 ++-- lib/configurator.js | 4 ++-- test/configurator.test.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/config.js b/lib/config.js index 5ef89b5..7f44bc0 100644 --- a/lib/config.js +++ b/lib/config.js @@ -55,7 +55,7 @@ module.exports = { * @type {string} * @autoconfigured */ - spriteModule: 'svg-sprite-loader/runtime/browser-sprite.build', + spriteModule: require.resolve('../runtime/browser-sprite.build'), /** * Path to symbol module. @@ -65,7 +65,7 @@ module.exports = { * @type {string} * @autoconfigured */ - symbolModule: 'svg-baker-runtime/browser-symbol', + symbolModule: require.resolve('svg-baker-runtime/browser-symbol'), /** * Generated export format: diff --git a/lib/configurator.js b/lib/configurator.js index bb41b81..4428805 100644 --- a/lib/configurator.js +++ b/lib/configurator.js @@ -3,8 +3,8 @@ const defaults = require('./config'); const utils = require('./utils'); const loaderDefaults = defaults.loader; -const isomorphicSpriteModule = 'svg-sprite-loader/runtime/sprite.build'; -const isomorphicSymbolModule = 'svg-baker-runtime/symbol'; +const isomorphicSpriteModule = require.resolve('../runtime/sprite.build'); +const isomorphicSymbolModule = require.resolve('svg-baker-runtime/symbol'); const isTargetBrowser = target => target === 'web' || target === 'electron-renderer'; diff --git a/test/configurator.test.js b/test/configurator.test.js index ca876f8..219391f 100644 --- a/test/configurator.test.js +++ b/test/configurator.test.js @@ -38,8 +38,8 @@ describe('configurator', () => { strictEqual(config.symbolModule, loaderDefaults.symbolModule); config = configure({ context, target: 'node' }); - strictEqual(config.spriteModule, 'svg-sprite-loader/runtime/sprite.build'); - strictEqual(config.symbolModule, 'svg-baker-runtime/symbol'); + strictEqual(config.spriteModule, require.resolve('../runtime/sprite.build')); + strictEqual(config.symbolModule, require.resolve('svg-baker-runtime/symbol')); }); it('should properly autodetect extract mode', () => {