Skip to content

Add amd wrapper to fix esbuild #7122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions tasks/bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import prependFile from 'prepend-file';
import constants from './util/constants.js';
import common from './util/common.js';
import _bundle from './util/bundle_wrapper.mjs';
import fsExtra from 'fs-extra';

var header = constants.licenseDist + '\n';
var pathToPlotlyDist = constants.pathToPlotlyDist;
Expand All @@ -27,6 +28,11 @@ if(!doesFileExist(constants.pathToCSSBuild)) {
].join('\n'));
}

function amdWrapper(path){
prependFile.sync(path, "define(function (require, exports, module) {", common.throwOnError)
fsExtra.appendFile(path, "})", common.throwOnError)
}

// list of tasks to pass to run-series to not blow up
// memory consumption.
var tasks = [];
Expand All @@ -36,7 +42,7 @@ tasks.push(function(done) {
_bundle(pathToPlotlyIndex, pathToPlotlyDist, {
}, function() {
prependFile.sync(pathToPlotlyDist, header, common.throwOnError);

amdWrapper(pathToPlotlyDist)
done();
});
});
Expand All @@ -47,7 +53,7 @@ tasks.push(function(done) {
minify: true,
}, function() {
prependFile.sync(pathToPlotlyDistMin, header, common.throwOnError);

amdWrapper(pathToPlotlyDistMin)
done();
});
});
Expand All @@ -57,7 +63,7 @@ tasks.push(function(done) {
_bundle(pathToPlotlyStrict, pathToPlotlyStrictDist, {
}, function() {
prependFile.sync(pathToPlotlyStrictDist, header.replace('plotly.js', 'plotly.js (strict)'), common.throwOnError);

amdWrapper(pathToPlotlyStrictDist)
done();
});
});
Expand All @@ -68,7 +74,7 @@ tasks.push(function(done) {
minify: true,
}, function() {
prependFile.sync(pathToPlotlyStrictDistMin, header.replace('plotly.js', 'plotly.js (strict - minified)'), common.throwOnError);

amdWrapper(pathToPlotlyStrictDistMin)
done();
});
});
Expand All @@ -80,7 +86,7 @@ tasks.push(function(done) {
standalone: 'PlotlyGeoAssets'
}, function() {
prependFile.sync(pathToPlotlyGeoAssetsDist, header, common.throwOnError);

amdWrapper(pathToPlotlyGeoAssetsDist)
done();
});
});
Expand All @@ -91,7 +97,6 @@ tasks.push(function(done) {
noCompressAttributes: true
}, function() {
prependFile.sync(pathToPlotlyDistWithMeta, header, common.throwOnError);

done();
});
});
Expand Down