Merge pull request #4307 from backstage/rugvip/devres

cli,config-loader,app-backend: fixes for module resolution and config loading
This commit is contained in:
Patrik Oldsberg
2021-01-29 19:24:11 +01:00
committed by GitHub
6 changed files with 67 additions and 7 deletions
+30 -1
View File
@@ -219,7 +219,7 @@ export async function createBackendConfig(
}
: {}),
externals: [
nodeExternals({
nodeExternalsWithResolve({
modulesDir: paths.rootNodeModules,
additionalModuleDirs: moduleDirs,
allowlist: ['webpack/hot/poll?100', ...localPackageNames],
@@ -296,3 +296,32 @@ export async function createBackendConfig(
],
};
}
// This makes the module resolution happen from the context of each non-external module, rather
// than the main entrypoint. This fixes a bug where dependencies would be resolved from the backend
// package rather than each individual backend package and plugin.
//
// TODO(Rugvip): Feature suggestion/contribute this to webpack-externals
function nodeExternalsWithResolve(
options: Parameters<typeof nodeExternals>[0],
) {
let currentContext: string;
const externals = nodeExternals({
...options,
importType(request) {
const resolved = require.resolve(request, {
paths: [currentContext],
});
return `commonjs ${resolved}`;
},
});
return (
context: string,
request: string,
callback: webpack.ExternalsFunctionCallback,
) => {
currentContext = context;
return externals(context, request, callback);
};
}
@@ -69,6 +69,14 @@ export function compileConfigSchemas(
},
});
for (const schema of schemas) {
try {
ajv.compile(schema.value);
} catch (error) {
throw new Error(`Schema at ${schema.path} is invalid, ${error}`);
}
}
const merged = mergeAllOf(
{ allOf: schemas.map(_ => _.value) },
{