Skip to content

Commit

Permalink
fix(cli): fix entrypoint validation on backstage 1.24.0 and above. (j…
Browse files Browse the repository at this point in the history
…anus-idp#1741)

Signed-off-by: David Festal <dfestal@redhat.com>
  • Loading branch information
davidfestal committed May 29, 2024
1 parent 8b732ec commit 6ed4171
Showing 1 changed file with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -796,21 +796,41 @@ function validatePluginEntryPoints(target: string): string {
Task.log(
` adding typescript extension support to enable entry point validation`,
);
let tsNode: string | undefined;

let nodeTransform: string | undefined;
try {
tsNode = dynamicPluginRequire.resolve('ts-node');
nodeTransform = dynamicPluginRequire.resolve(
'@backstage/cli/config/nodeTransform.cjs',
);
} catch (e) {
Task.log(` => unable to find 'ts-node' in the plugin context`);
Task.log(
` => unable to find '@backstage/cli/config/nodeTransform.cjs' in the plugin context`,
);
}

if (tsNode) {
dynamicPluginRequire(tsNode).register({
transpileOnly: true,
project: path.resolve(paths.targetRoot, 'tsconfig.json'),
compilerOptions: {
module: 'CommonJS',
},
});
if (nodeTransform) {
dynamicPluginRequire(nodeTransform);
} else {
Task.log(
` => searching for 'ts-node' (legacy mode before backage 1.24.0)`,
);

let tsNode: string | undefined;
try {
tsNode = dynamicPluginRequire.resolve('ts-node');
} catch (e) {
Task.log(` => unable to find 'ts-node' in the plugin context`);
}

if (tsNode) {
dynamicPluginRequire(tsNode).register({
transpileOnly: true,
project: path.resolve(paths.targetRoot, 'tsconfig.json'),
compilerOptions: {
module: 'CommonJS',
},
});
}
}

// Retry requiring the plugin main module after adding typescript extensions
Expand Down

0 comments on commit 6ed4171

Please sign in to comment.