From e6e7d570c08c9ff81fc26a76c9a900201ab25890 Mon Sep 17 00:00:00 2001 From: bre1470 <40056287+bre1470@users.noreply.github.com> Date: Mon, 26 Jun 2023 18:01:00 +0200 Subject: [PATCH 1/5] Added support for @name to product replacement. --- src/dependencies.js | 18 ++++++++++-------- src/templates/umd-module.txt | 8 ++++---- src/templates/umd-standalone.txt | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/dependencies.js b/src/dependencies.js index e877745..63efb9d 100644 --- a/src/dependencies.js +++ b/src/dependencies.js @@ -309,12 +309,11 @@ const getOrderedDependencies = (file, parent, dependencies) => { } const applyUMD = (content, path) => templateUMDStandalone - .replace(/@name/g, safeReplace('Highcharts')) .replace(/@path/g, safeReplace(path)) .replace('@content', safeReplace(indent(content, IND))) -const applyModule = content => - templateUMDModule.replace('@content', safeReplace(indent(content, IND))) +const applyModule = content => templateUMDModule + .replace('@content', safeReplace(indent(content, IND))) /** * Adds a license header to the top of a distribution file. @@ -536,16 +535,18 @@ const moduleTransform = (content, options) => { * @returns {string} Content of file after transformation */ const fileTransform = (content, options) => { - const { entry, moduleName, umd, printPath, requires } = options + const { entry, moduleName, printPath, product, requires, umd } = options let result = umd ? applyUMD(content, printPath) : applyModule(content) result = addLicenseHeader(result, { entry }) return result + .replace('@moduleEvent', `'${product}ModuleLoaded'`) .replace('@moduleName', moduleName ? `'${moduleName}', ` : '') - .replace('@AMDParams', requires.length ? 'Highcharts' : '') + .replace('@AMDParams', requires.length ? product : '') .replace('@AMDFactory', requires.length - ? '\n' + indent('factory(Highcharts);\nfactory.Highcharts = Highcharts;', IND.repeat(3)) + ? '\n' + indent(`factory(${product});\nfactory.${product} = ${product};`, IND.repeat(3)) : '' ) + .replace(/@name/g, product) .replace(/@dependencies/g, safeReplace(requires.join('\', \''))) } @@ -562,7 +563,8 @@ const compileFile = options => { requires = getRequires(contentEntry), exclude = getExcludedFilenames(requires, base), umd = requires.length === 0, - moduleName = getModuleName(contentEntry) + moduleName = getModuleName(contentEntry), + product = 'Highcharts' } = options // Transform modules @@ -586,7 +588,7 @@ const compileFile = options => { const printPath = relative(join(base, '../'), entry).split('\\').join('/') return fileTransform( modules, - { entry, moduleName, umd, printPath, requires } + { entry, moduleName, printPath, product, requires, umd } ) } diff --git a/src/templates/umd-module.txt b/src/templates/umd-module.txt index 76d061a..ee0ffea 100644 --- a/src/templates/umd-module.txt +++ b/src/templates/umd-module.txt @@ -7,11 +7,11 @@ return factory; }); } else { - factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined); + factory(typeof @name !== 'undefined' ? @name : undefined); } -}(function (Highcharts) { +}(function (@name) { 'use strict'; - var _modules = Highcharts ? Highcharts._modules : {}; + var _modules = @name ? @name._modules : {}; function _registerModule(obj, path, args, fn) { if (!obj.hasOwnProperty(path)) { obj[path] = fn.apply(null, args); @@ -19,7 +19,7 @@ if (typeof CustomEvent === 'function') { window.dispatchEvent( new CustomEvent( - 'HighchartsModuleLoaded', + @moduleEvent, { detail: { path: path, module: obj[path] } }) ); diff --git a/src/templates/umd-standalone.txt b/src/templates/umd-standalone.txt index 5006dba..d87442f 100644 --- a/src/templates/umd-standalone.txt +++ b/src/templates/umd-standalone.txt @@ -24,7 +24,7 @@ if (typeof CustomEvent === 'function') { window.dispatchEvent( new CustomEvent( - 'HighchartsModuleLoaded', + @moduleEvent, { detail: { path: path, module: obj[path] } }) ); From 7c97993df92a3ee903e9b0af4825a62443adc0c0 Mon Sep 17 00:00:00 2001 From: bre1470 <40056287+bre1470@users.noreply.github.com> Date: Mon, 26 Jun 2023 18:11:01 +0200 Subject: [PATCH 2/5] Updated package version. --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 32cbdde..06bfae5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@highcharts/highcharts-assembler", - "version": "1.5.1", + "version": "1.5.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@highcharts/highcharts-assembler", - "version": "1.5.1", + "version": "1.5.2", "license": "ISC", "devDependencies": { "chai": "^4.3.7", diff --git a/package.json b/package.json index 967809f..67b8954 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@highcharts/highcharts-assembler", - "version": "1.5.1", + "version": "1.5.2", "description": "The official bundler for Highcharts JS.", "main": "index.js", "directories": { From c4636771c9f18a6148548c51b5089d2d7db45e0c Mon Sep 17 00:00:00 2001 From: bre1470 <40056287+bre1470@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:23:22 +0200 Subject: [PATCH 3/5] Changed variable name to reflect purpose. --- src/dependencies.js | 16 ++++++++-------- src/templates/umd-module.txt | 10 ++++------ src/templates/umd-standalone.txt | 10 ++++------ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/dependencies.js b/src/dependencies.js index 63efb9d..b84a21d 100644 --- a/src/dependencies.js +++ b/src/dependencies.js @@ -535,18 +535,18 @@ const moduleTransform = (content, options) => { * @returns {string} Content of file after transformation */ const fileTransform = (content, options) => { - const { entry, moduleName, printPath, product, requires, umd } = options + const { entry, moduleName, namespace, printPath, requires, umd } = options let result = umd ? applyUMD(content, printPath) : applyModule(content) result = addLicenseHeader(result, { entry }) return result - .replace('@moduleEvent', `'${product}ModuleLoaded'`) + .replace('@moduleEvent', `'${namespace}ModuleLoaded'`) .replace('@moduleName', moduleName ? `'${moduleName}', ` : '') - .replace('@AMDParams', requires.length ? product : '') + .replace('@AMDParams', requires.length ? namespace : '') .replace('@AMDFactory', requires.length - ? '\n' + indent(`factory(${product});\nfactory.${product} = ${product};`, IND.repeat(3)) + ? '\n' + indent(`factory(${namespace});\nfactory.${namespace} = ${namespace};`, IND.repeat(3)) : '' ) - .replace(/@name/g, product) + .replace(/@name/g, namespace) .replace(/@dependencies/g, safeReplace(requires.join('\', \''))) } @@ -562,9 +562,9 @@ const compileFile = options => { const { requires = getRequires(contentEntry), exclude = getExcludedFilenames(requires, base), - umd = requires.length === 0, moduleName = getModuleName(contentEntry), - product = 'Highcharts' + namespace = 'Highcharts', + umd = requires.length === 0 } = options // Transform modules @@ -588,7 +588,7 @@ const compileFile = options => { const printPath = relative(join(base, '../'), entry).split('\\').join('/') return fileTransform( modules, - { entry, moduleName, printPath, product, requires, umd } + { entry, moduleName, namespace, printPath, requires, umd } ) } diff --git a/src/templates/umd-module.txt b/src/templates/umd-module.txt index ee0ffea..1dc44c9 100644 --- a/src/templates/umd-module.txt +++ b/src/templates/umd-module.txt @@ -17,12 +17,10 @@ obj[path] = fn.apply(null, args); if (typeof CustomEvent === 'function') { - window.dispatchEvent( - new CustomEvent( - @moduleEvent, - { detail: { path: path, module: obj[path] } - }) - ); + window.dispatchEvent(new CustomEvent( + @moduleEvent, + { detail: { path: path, module: obj[path] } } + )); } } } diff --git a/src/templates/umd-standalone.txt b/src/templates/umd-standalone.txt index d87442f..850e8ed 100644 --- a/src/templates/umd-standalone.txt +++ b/src/templates/umd-standalone.txt @@ -22,12 +22,10 @@ obj[path] = fn.apply(null, args); if (typeof CustomEvent === 'function') { - window.dispatchEvent( - new CustomEvent( - @moduleEvent, - { detail: { path: path, module: obj[path] } - }) - ); + window.dispatchEvent(new CustomEvent( + @moduleEvent, + { detail: { path: path, module: obj[path] } } + )); } } } From 8a011fdcab5b71267589c809a3635126e5820798 Mon Sep 17 00:00:00 2001 From: bre1470 <40056287+bre1470@users.noreply.github.com> Date: Tue, 27 Jun 2023 18:12:35 +0200 Subject: [PATCH 4/5] Fixed tag name conflicts. --- src/dependencies.js | 2 +- src/templates/umd-module.txt | 6 +++--- src/templates/umd-standalone.txt | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dependencies.js b/src/dependencies.js index b84a21d..fcb91a4 100644 --- a/src/dependencies.js +++ b/src/dependencies.js @@ -546,8 +546,8 @@ const fileTransform = (content, options) => { ? '\n' + indent(`factory(${namespace});\nfactory.${namespace} = ${namespace};`, IND.repeat(3)) : '' ) - .replace(/@name/g, namespace) .replace(/@dependencies/g, safeReplace(requires.join('\', \''))) + .replace(/@moduleSpace/g, namespace) } const compileFile = options => { diff --git a/src/templates/umd-module.txt b/src/templates/umd-module.txt index 1dc44c9..ac2083a 100644 --- a/src/templates/umd-module.txt +++ b/src/templates/umd-module.txt @@ -7,11 +7,11 @@ return factory; }); } else { - factory(typeof @name !== 'undefined' ? @name : undefined); + factory(typeof @moduleSpace !== 'undefined' ? @moduleSpace : undefined); } -}(function (@name) { +}(function (@moduleSpace) { 'use strict'; - var _modules = @name ? @name._modules : {}; + var _modules = @moduleSpace ? @moduleSpace._modules : {}; function _registerModule(obj, path, args, fn) { if (!obj.hasOwnProperty(path)) { obj[path] = fn.apply(null, args); diff --git a/src/templates/umd-standalone.txt b/src/templates/umd-standalone.txt index 850e8ed..fc05e84 100644 --- a/src/templates/umd-standalone.txt +++ b/src/templates/umd-standalone.txt @@ -9,10 +9,10 @@ return factory(root); }); } else { - if (root.@name) { - root.@name.error(16, true); + if (root.@moduleSpace) { + root.@moduleSpace.error(16, true); } - root.@name = factory(root); + root.@moduleSpace = factory(root); } }(typeof window !== 'undefined' ? window : this, function (window) { 'use strict'; From 8e9d79134d52c2cbbef0c9d465b9c97d93966c59 Mon Sep 17 00:00:00 2001 From: bre1470 <40056287+bre1470@users.noreply.github.com> Date: Tue, 27 Jun 2023 19:18:36 +0200 Subject: [PATCH 5/5] Fixed custom namespace. --- src/build.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/build.js b/src/build.js index a22ea54..e8dd9e3 100644 --- a/src/build.js +++ b/src/build.js @@ -96,6 +96,7 @@ const getIndividualOptions = ({ exclude, files, fileOptions = {}, + namespace, output, palette, product, @@ -117,6 +118,7 @@ const getIndividualOptions = ({ date, entry: resolve(join(base, filename)), exclude, + namespace, product, umd, version @@ -136,7 +138,7 @@ const getIndividualOptions = ({ } const getESModuleOptions = ( - { base, date, output, files, palette, product, types, version } + { base, date, output, files, namespace, palette, product, types, version } ) => { const process = getProcess(palette) return files.reduce((arr, filename, i) => { @@ -145,6 +147,7 @@ const getESModuleOptions = ( date, process: process[type], entry, + namespace, outputPath: resolve(join( output, (type === 'classic' ? '' : 'js/'),