Skip to content

Commit

Permalink
fix: framework demos fail when system.js faces some auto re-exports (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
VasilyStrelyaev authored Dec 6, 2024
1 parent 2ac1f5d commit c2f2b0b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/demos/utils/bundle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Builder = require('systemjs-builder');
const babel = require('@babel/core');
const url = require('url');

const GRID_COMMON_STAR_IMPORT = 'exports.Grids = __importStar(require("./grids"));';

// https://stackoverflow.com/questions/42412965/how-to-load-named-exports-with-systemjs/47108328
const prepareModulesToNamedImport = () => {
Expand Down Expand Up @@ -216,13 +217,22 @@ const prepareConfigs = (framework)=> {
]
};

// This auto-generated runtime import is useless because grid.js exports only types,
// but System.js transpiles this import into code that crashes when triggered in a Demo.
const removeImportTranspiledToCrashingCode = (result) => {
if(result.code.includes(GRID_COMMON_STAR_IMPORT)) {
result.code = result.code.replace(GRID_COMMON_STAR_IMPORT, '');
}
}

const result = new Promise((resolve) => {
// systemjs-builder uses babel 6, so we use babel 7 here for transpiling ES2020
babel.transformFile(url.fileURLToPath(load.name), babelOptions, (err, result) => {
if(err) {
fetch(load).then(r => resolve(r));
console.log('Unexpected transipling error (babel 7): ' + err);
} else {
removeImportTranspiledToCrashingCode(result);
resolve(result.code);
}
});
Expand Down

0 comments on commit c2f2b0b

Please sign in to comment.