Skip to content

Commit

Permalink
Merge pull request #20724 from backstage/rugvip/patch-backend-import
Browse files Browse the repository at this point in the history
patch broken dynamic imports calls in new backend system
  • Loading branch information
Rugvip committed Oct 22, 2023
2 parents d826f51 + 932eee8 commit d20a7af
Show file tree
Hide file tree
Showing 52 changed files with 358 additions and 136 deletions.
Expand Up @@ -349,7 +349,7 @@ import { createRouter } from './service/router';
/**
* The example TODO list backend plugin.
*
* @alpha
* @public
*/
export const exampleTodoListPlugin = createBackendPlugin({
pluginId: 'exampleTodoList',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -52,7 +52,7 @@
"jest-haste-map@^29.4.3": "patch:jest-haste-map@npm%3A29.4.3#./.yarn/patches/jest-haste-map-npm-29.4.3-19b03fcef3.patch",
"mock-fs@^5.2.0": "patch:mock-fs@npm%3A5.2.0#./.yarn/patches/mock-fs-npm-5.2.0-5103a7b507.patch"
},
"version": "1.19.1",
"version": "1.19.2",
"dependencies": {
"@backstage/errors": "workspace:^",
"@manypkg/get-packages": "^1.1.3"
Expand Down
13 changes: 13 additions & 0 deletions packages/backend-app-api/CHANGELOG.md
@@ -1,5 +1,18 @@
# @backstage/backend-app-api

## 0.5.7

### Patch Changes

- 9a0bf5fbb178: Added a workaround for double `default` wrapping when dynamically importing CommonJS modules with default exports.
- Updated dependencies
- @backstage/backend-common@0.19.9
- @backstage/backend-tasks@0.5.12
- @backstage/plugin-auth-node@0.4.1
- @backstage/plugin-permission-node@0.7.18
- @backstage/config-loader@1.5.1
- @backstage/backend-plugin-api@0.6.7

## 0.5.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-app-api/package.json
@@ -1,7 +1,7 @@
{
"name": "@backstage/backend-app-api",
"description": "Core API used by Backstage backend apps",
"version": "0.5.6",
"version": "0.5.7",
"main": "src/index.ts",
"types": "src/index.ts",
"publishConfig": {
Expand Down
23 changes: 21 additions & 2 deletions packages/backend-app-api/src/wiring/BackstageBackend.ts
Expand Up @@ -57,7 +57,26 @@ function isPromise<T>(value: unknown | Promise<T>): value is Promise<T> {
}

function unwrapFeature(
feature: BackendFeature | (() => BackendFeature),
feature:
| BackendFeature
| (() => BackendFeature)
| { default: BackendFeature | (() => BackendFeature) },
): BackendFeature {
return typeof feature === 'function' ? feature() : feature;
if (typeof feature === 'function') {
return feature();
}
if ('$$type' in feature) {
return feature;
}
// This is a workaround where default exports get transpiled to `exports['default'] = ...`
// in CommonJS modules, which in turn results in a double `{ default: { default: ... } }` nesting
// when importing using a dynamic import.
// TODO: This is a broader issue than just this piece of code, and should move away from CommonJS.
if ('default' in feature) {
const defaultFeature = feature.default;
return typeof defaultFeature === 'function'
? defaultFeature()
: defaultFeature;
}
return feature;
}
2 changes: 1 addition & 1 deletion packages/backend-next/src/index.ts
Expand Up @@ -39,7 +39,7 @@ backend.add(
import('@backstage/plugin-permission-backend-module-allow-all-policy'),
);
backend.add(import('@backstage/plugin-permission-backend/alpha'));
backend.add(import('@backstage/plugin-proxy-backend'));
backend.add(import('@backstage/plugin-proxy-backend/alpha'));
backend.add(import('@backstage/plugin-scaffolder-backend/alpha'));
backend.add(import('@backstage/plugin-search-backend-module-catalog/alpha'));
backend.add(import('@backstage/plugin-search-backend-module-explore/alpha'));
Expand Down
10 changes: 10 additions & 0 deletions plugins/bazaar-backend/CHANGELOG.md
@@ -1,5 +1,15 @@
# @backstage/plugin-bazaar-backend

## 0.3.4

### Patch Changes

- f6c651fe3c6c: Switched to using `"exports"` field for `/alpha` subpath export.
- Updated dependencies
- @backstage/backend-common@0.19.9
- @backstage/plugin-auth-node@0.4.1
- @backstage/backend-plugin-api@0.6.7

## 0.3.3

### Patch Changes
Expand Down
13 changes: 13 additions & 0 deletions plugins/bazaar-backend/alpha-api-report.md
@@ -0,0 +1,13 @@
## API Report File for "@backstage/plugin-bazaar-backend"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';

// @alpha
const _default: () => BackendFeature;
export default _default;

// (No @packageDocumentation comment for this package)
```
5 changes: 0 additions & 5 deletions plugins/bazaar-backend/api-report.md
Expand Up @@ -3,17 +3,12 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import express from 'express';
import { IdentityApi } from '@backstage/plugin-auth-node';
import { Logger } from 'winston';
import { PluginDatabaseManager } from '@backstage/backend-common';

// @alpha
const bazaarPlugin: () => BackendFeature;
export default bazaarPlugin;

// @public (undocumented)
export function createRouter(options: RouterOptions): Promise<express.Router>;

Expand Down
24 changes: 18 additions & 6 deletions plugins/bazaar-backend/package.json
@@ -1,14 +1,26 @@
{
"name": "@backstage/plugin-bazaar-backend",
"version": "0.3.3",
"version": "0.3.4",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts",
"alphaTypes": "dist/index.alpha.d.ts"
"access": "public"
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
}
},
"backstage": {
"role": "backend-plugin"
Expand All @@ -21,7 +33,7 @@
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build --experimental-type-build",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"prepack": "backstage-cli package prepack",
Expand Down
Expand Up @@ -26,7 +26,7 @@ import { createRouter } from './service/router';
*
* @alpha
*/
export const bazaarPlugin = createBackendPlugin({
export default createBackendPlugin({
pluginId: 'bazaar',
register(env) {
env.registerInit({
Expand Down
1 change: 0 additions & 1 deletion plugins/bazaar-backend/src/index.ts
Expand Up @@ -15,4 +15,3 @@
*/

export * from './service/router';
export { bazaarPlugin as default } from './plugin';
2 changes: 1 addition & 1 deletion plugins/example-todo-list-backend/api-report.md
Expand Up @@ -11,7 +11,7 @@ import { Logger } from 'winston';
// @public
export function createRouter(options: RouterOptions): Promise<express.Router>;

// @alpha
// @public
const exampleTodoListPlugin: () => BackendFeature;
export default exampleTodoListPlugin;

Expand Down
5 changes: 2 additions & 3 deletions plugins/example-todo-list-backend/package.json
Expand Up @@ -17,12 +17,11 @@
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts",
"alphaTypes": "dist/index.alpha.d.ts"
"types": "dist/index.d.ts"
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build --experimental-type-build",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"prepack": "backstage-cli package prepack",
Expand Down
2 changes: 1 addition & 1 deletion plugins/example-todo-list-backend/src/plugin.ts
Expand Up @@ -24,7 +24,7 @@ import { createRouter } from './service/router';
/**
* The example TODO list backend plugin.
*
* @alpha
* @public
*/
export const exampleTodoListPlugin = createBackendPlugin({
pluginId: 'exampleTodoList',
Expand Down
9 changes: 9 additions & 0 deletions plugins/kafka-backend/CHANGELOG.md
@@ -1,5 +1,14 @@
# @backstage/plugin-kafka-backend

## 0.3.4

### Patch Changes

- f6c651fe3c6c: Switched to using `"exports"` field for `/alpha` subpath export.
- Updated dependencies
- @backstage/backend-common@0.19.9
- @backstage/backend-plugin-api@0.6.7

## 0.3.3

### Patch Changes
Expand Down
13 changes: 13 additions & 0 deletions plugins/kafka-backend/alpha-api-report.md
@@ -0,0 +1,13 @@
## API Report File for "@backstage/plugin-kafka-backend"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';

// @alpha
const _default: () => BackendFeature;
export default _default;

// (No @packageDocumentation comment for this package)
```
5 changes: 0 additions & 5 deletions plugins/kafka-backend/api-report.md
Expand Up @@ -3,18 +3,13 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import express from 'express';
import { Logger } from 'winston';

// @public (undocumented)
export function createRouter(options: RouterOptions): Promise<express.Router>;

// @alpha
const kafkaPlugin: () => BackendFeature;
export default kafkaPlugin;

// @public (undocumented)
export interface RouterOptions {
// (undocumented)
Expand Down
24 changes: 18 additions & 6 deletions plugins/kafka-backend/package.json
@@ -1,15 +1,27 @@
{
"name": "@backstage/plugin-kafka-backend",
"description": "A Backstage backend plugin that integrates towards Kafka",
"version": "0.3.3",
"version": "0.3.4",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts",
"alphaTypes": "dist/index.alpha.d.ts"
"access": "public"
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
}
},
"backstage": {
"role": "backend-plugin"
Expand All @@ -27,7 +39,7 @@
"configSchema": "config.d.ts",
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build --experimental-type-build",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"prepack": "backstage-cli package prepack",
Expand Down
Expand Up @@ -26,7 +26,7 @@ import { createRouter } from './service/router';
*
* @alpha
*/
export const kafkaPlugin = createBackendPlugin({
export default createBackendPlugin({
pluginId: 'kafka',
register(env) {
env.registerInit({
Expand Down
1 change: 0 additions & 1 deletion plugins/kafka-backend/src/index.ts
Expand Up @@ -22,4 +22,3 @@

export type { RouterOptions } from './service/router';
export { createRouter } from './service/router';
export { kafkaPlugin as default } from './plugin';
9 changes: 9 additions & 0 deletions plugins/periskop-backend/CHANGELOG.md
@@ -1,5 +1,14 @@
# @backstage/plugin-periskop-backend

## 0.2.4

### Patch Changes

- f6c651fe3c6c: Switched to using `"exports"` field for `/alpha` subpath export.
- Updated dependencies
- @backstage/backend-common@0.19.9
- @backstage/backend-plugin-api@0.6.7

## 0.2.3

### Patch Changes
Expand Down
13 changes: 13 additions & 0 deletions plugins/periskop-backend/alpha-api-report.md
@@ -0,0 +1,13 @@
## API Report File for "@backstage/plugin-periskop-backend"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';

// @alpha
const _default: () => BackendFeature;
export default _default;

// (No @packageDocumentation comment for this package)
```
5 changes: 0 additions & 5 deletions plugins/periskop-backend/api-report.md
Expand Up @@ -3,18 +3,13 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import express from 'express';
import { Logger } from 'winston';

// @public (undocumented)
export function createRouter(options: RouterOptions): Promise<express.Router>;

// @alpha
const periskopPlugin: () => BackendFeature;
export default periskopPlugin;

// @public (undocumented)
export interface RouterOptions {
// (undocumented)
Expand Down

0 comments on commit d20a7af

Please sign in to comment.