Skip to content

Commit

Permalink
Merge pull request #34 from highcharts/v1.5.2
Browse files Browse the repository at this point in the history
v1.5.2: Added support for @moduleSpace to product namespace replacement.
  • Loading branch information
bre1470 authored Jun 29, 2023
2 parents f5a53a0 + 8e9d791 commit c27c0e2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const getIndividualOptions = ({
exclude,
files,
fileOptions = {},
namespace,
output,
palette,
product,
Expand All @@ -117,6 +118,7 @@ const getIndividualOptions = ({
date,
entry: resolve(join(base, filename)),
exclude,
namespace,
product,
umd,
version
Expand All @@ -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) => {
Expand All @@ -145,6 +147,7 @@ const getESModuleOptions = (
date,
process: process[type],
entry,
namespace,
outputPath: resolve(join(
output,
(type === 'classic' ? '' : 'js/'),
Expand Down
20 changes: 11 additions & 9 deletions src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -536,17 +535,19 @@ 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, namespace, printPath, requires, umd } = options
let result = umd ? applyUMD(content, printPath) : applyModule(content)
result = addLicenseHeader(result, { entry })
return result
.replace('@moduleEvent', `'${namespace}ModuleLoaded'`)
.replace('@moduleName', moduleName ? `'${moduleName}', ` : '')
.replace('@AMDParams', requires.length ? 'Highcharts' : '')
.replace('@AMDParams', requires.length ? namespace : '')
.replace('@AMDFactory', requires.length
? '\n' + indent('factory(Highcharts);\nfactory.Highcharts = Highcharts;', IND.repeat(3))
? '\n' + indent(`factory(${namespace});\nfactory.${namespace} = ${namespace};`, IND.repeat(3))
: ''
)
.replace(/@dependencies/g, safeReplace(requires.join('\', \'')))
.replace(/@moduleSpace/g, namespace)
}

const compileFile = options => {
Expand All @@ -561,8 +562,9 @@ const compileFile = options => {
const {
requires = getRequires(contentEntry),
exclude = getExcludedFilenames(requires, base),
umd = requires.length === 0,
moduleName = getModuleName(contentEntry)
moduleName = getModuleName(contentEntry),
namespace = 'Highcharts',
umd = requires.length === 0
} = options

// Transform modules
Expand All @@ -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, namespace, printPath, requires, umd }
)
}

Expand Down
16 changes: 7 additions & 9 deletions src/templates/umd-module.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
return factory;
});
} else {
factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
factory(typeof @moduleSpace !== 'undefined' ? @moduleSpace : undefined);
}
}(function (Highcharts) {
}(function (@moduleSpace) {
'use strict';
var _modules = Highcharts ? Highcharts._modules : {};
var _modules = @moduleSpace ? @moduleSpace._modules : {};
function _registerModule(obj, path, args, fn) {
if (!obj.hasOwnProperty(path)) {
obj[path] = fn.apply(null, args);

if (typeof CustomEvent === 'function') {
window.dispatchEvent(
new CustomEvent(
'HighchartsModuleLoaded',
{ detail: { path: path, module: obj[path] }
})
);
window.dispatchEvent(new CustomEvent(
@moduleEvent,
{ detail: { path: path, module: obj[path] } }
));
}
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/templates/umd-standalone.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -22,12 +22,10 @@
obj[path] = fn.apply(null, args);

if (typeof CustomEvent === 'function') {
window.dispatchEvent(
new CustomEvent(
'HighchartsModuleLoaded',
{ detail: { path: path, module: obj[path] }
})
);
window.dispatchEvent(new CustomEvent(
@moduleEvent,
{ detail: { path: path, module: obj[path] } }
));
}
}
}
Expand Down

0 comments on commit c27c0e2

Please sign in to comment.