mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
build(esbuild-config): add refractor compatibility plugin to resolve refractor imports
Add createRefractorCompatibilityPlugin that maps imports from refractor/lib and refractor/lang to the local refractor package (searching candidate node_modules paths), and include it in the plugins list so esbuild can correctly resolve refractor modules.
This commit is contained in:
@@ -8,6 +8,37 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const dotenv = require('dotenv');
|
||||
|
||||
function createRefractorCompatibilityPlugin() {
|
||||
const candidateRoots = [
|
||||
path.resolve(__dirname, '../node_modules/refractor'),
|
||||
path.resolve(__dirname, '../../node_modules/refractor'),
|
||||
];
|
||||
|
||||
const refractorRoot = candidateRoots.find((packagePath) => fs.existsSync(packagePath));
|
||||
|
||||
if (!refractorRoot) {
|
||||
throw new Error('Unable to locate refractor package for esbuild compatibility plugin.');
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'refractor-compatibility',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^refractor\/lib\// }, (args) => {
|
||||
const relativePath = args.path.replace(/^refractor\/lib\//, '');
|
||||
const candidatePath = path.join(refractorRoot, 'lib', `${relativePath}.js`);
|
||||
return { path: candidatePath };
|
||||
});
|
||||
|
||||
build.onResolve({ filter: /^refractor\/lang\// }, (args) => {
|
||||
const relativePath = args.path.replace(/^refractor\/lang\//, '');
|
||||
const filename = relativePath.endsWith('.js') ? relativePath : `${relativePath}.js`;
|
||||
const candidatePath = path.join(refractorRoot, 'lang', filename);
|
||||
return { path: candidatePath };
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// CSS Plugin to handle CSS/SCSS files
|
||||
function createCSSPlugin() {
|
||||
return {
|
||||
@@ -146,7 +177,7 @@ function createConfig(options) {
|
||||
'react': path.resolve('./node_modules/react'),
|
||||
...additionalAlias,
|
||||
},
|
||||
plugins: [createCSSPlugin(), createFileLoaderPlugin()],
|
||||
plugins: [createRefractorCompatibilityPlugin(), createCSSPlugin(), createFileLoaderPlugin()],
|
||||
loader: {
|
||||
'.tsx': 'tsx',
|
||||
'.ts': 'ts',
|
||||
|
||||
Reference in New Issue
Block a user