@backstage/plugin-scaffolder-backend-module-workspace-database 0.0.0-nightly-20260822023239

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # @backstage/plugin-scaffolder-backend-module-workspace-database
2
+
3
+ ## 0.0.0-nightly-20260822023239
4
+
5
+ ### Minor Changes
6
+
7
+ - e95b649: Added task recovery feature with new `scaffolder.taskRecovery` config section. When enabled, tasks that crash or timeout are automatically recovered and resume from the last completed step, task secrets are retained until the task reaches a terminal state so recovery can continue, and completed step outputs are persisted. Enabling recovery applies to all scaffolder tasks, so actions used by those tasks should be idempotent or use checkpoints. When recovery is disabled (the default), the previous behavior is unchanged: secrets are cleared as soon as a task is claimed and retries re-run every step. The new config consolidates previous experimental flags (`EXPERIMENTAL_recoverTasks`, `EXPERIMENTAL_workspaceSerialization`, `EXPERIMENTAL_recoverTasksTimeout`) which remain supported as fallbacks. The legacy workspace provider setting continues to select a provider only when `EXPERIMENTAL_workspaceSerialization` is `true`.
8
+
9
+ Workspace serialization for task recovery now requires installing a separate workspace provider module, including when you use the legacy configuration. For development, use `@backstage/plugin-scaffolder-backend-module-workspace-database` (50 MB limit, not recommended for production). On first startup, that module migrates existing database workspace snapshots from the legacy task storage. For production, use `@backstage/plugin-scaffolder-backend-module-gcp` or a similar external storage provider. The scaffolder rejects a configured provider that has not been installed and registered.
10
+
11
+ Enabling crash recovery does not keep completed task event streams open; normal task completion remains terminal for event-stream clients.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+ - @backstage/plugin-scaffolder-node@0.0.0-nightly-20260822023239
17
+ - @backstage/backend-plugin-api@1.10.0
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @backstage/plugin-scaffolder-backend-module-workspace-database
2
+
3
+ This module provides a database-backed workspace provider for the scaffolder backend.
4
+
5
+ **Warning:** This module is intended for development use only. In production, use an external storage provider like GCS (`@backstage/plugin-scaffolder-backend-module-gcp`).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ yarn add @backstage/plugin-scaffolder-backend-module-workspace-database
11
+ ```
12
+
13
+ Add to your backend:
14
+
15
+ ```typescript
16
+ // packages/backend/src/index.ts
17
+ backend.add(
18
+ import('@backstage/plugin-scaffolder-backend-module-workspace-database'),
19
+ );
20
+ ```
21
+
22
+ Configure in your app-config:
23
+
24
+ ```yaml
25
+ scaffolder:
26
+ taskRecovery:
27
+ enabled: true
28
+ workspaceProvider: database
29
+ ```
30
+
31
+ The module does not register the provider in production by default. Although it is not recommended, you can explicitly enable it with the following configuration:
32
+
33
+ ```yaml
34
+ scaffolder:
35
+ taskRecovery:
36
+ database:
37
+ dangerouslyEnableInProduction: true
38
+ ```
39
+
40
+ ## Limitations
41
+
42
+ - 50 MB maximum workspace size.
43
+ - Disabled in production unless you set `dangerouslyEnableInProduction` to `true`.
44
+ - Not recommended for high-volume or large workspace scenarios.
@@ -0,0 +1,32 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "scaffolder": {
6
+ "type": "object",
7
+ "properties": {
8
+ "taskRecovery": {
9
+ "type": "object",
10
+ "properties": {
11
+ "database": {
12
+ "type": "object",
13
+ "properties": {
14
+ "dangerouslyEnableInProduction": {
15
+ "type": "boolean",
16
+ "description": "Dangerously enable the database workspace provider in production.",
17
+ "visibility": "backend"
18
+ }
19
+ },
20
+ "required": [
21
+ "dangerouslyEnableInProduction"
22
+ ],
23
+ "description": "Database workspace provider configuration."
24
+ }
25
+ },
26
+ "description": "Task recovery configuration"
27
+ }
28
+ },
29
+ "description": "Configuration options for the scaffolder plugin"
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var module$1 = require('./module.cjs.js');
6
+
7
+
8
+
9
+ exports.default = module$1.workspaceDatabaseModule;
10
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,12 @@
1
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
+
3
+ /**
4
+ * @public
5
+ * Database workspace provider module for the Scaffolder Backend.
6
+ *
7
+ * This module is intended for development use only. In production,
8
+ * use an external storage provider like GCS.
9
+ */
10
+ declare const workspaceDatabaseModule: _backstage_backend_plugin_api.BackendFeature;
11
+
12
+ export { workspaceDatabaseModule as default };
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var alpha = require('@backstage/plugin-scaffolder-node/alpha');
5
+ var DatabaseWorkspaceProvider = require('./provider/DatabaseWorkspaceProvider.cjs.js');
6
+
7
+ const migrationsDir = backendPluginApi.resolvePackagePath(
8
+ "@backstage/plugin-scaffolder-backend-module-workspace-database",
9
+ "migrations"
10
+ );
11
+ const migrationsTable = "scaffolder_workspace_database_migrations";
12
+ const workspaceDatabaseModule = backendPluginApi.createBackendModule({
13
+ moduleId: "workspace-database",
14
+ pluginId: "scaffolder",
15
+ register({ registerInit }) {
16
+ registerInit({
17
+ deps: {
18
+ scaffolderWorkspaceProviders: alpha.scaffolderWorkspaceProviderExtensionPoint,
19
+ database: backendPluginApi.coreServices.database,
20
+ logger: backendPluginApi.coreServices.logger,
21
+ config: backendPluginApi.coreServices.rootConfig
22
+ },
23
+ async init({ database, logger, scaffolderWorkspaceProviders, config }) {
24
+ if (process.env.NODE_ENV === "production" && !config.getOptionalBoolean(
25
+ "scaffolder.taskRecovery.database.dangerouslyEnableInProduction"
26
+ )) {
27
+ logger.warn(
28
+ "Database workspace provider is not supported in production and will not be enabled"
29
+ );
30
+ return;
31
+ }
32
+ const db = await database.getClient();
33
+ if (!database.migrations?.skip) {
34
+ await db.migrate.latest({
35
+ directory: migrationsDir,
36
+ tableName: migrationsTable
37
+ });
38
+ }
39
+ scaffolderWorkspaceProviders.addProviders({
40
+ database: DatabaseWorkspaceProvider.DatabaseWorkspaceProvider.create({ db })
41
+ });
42
+ }
43
+ });
44
+ }
45
+ });
46
+
47
+ exports.workspaceDatabaseModule = workspaceDatabaseModule;
48
+ //# sourceMappingURL=module.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2026 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { resolvePackagePath } from '@backstage/backend-plugin-api';\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { scaffolderWorkspaceProviderExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport { DatabaseWorkspaceProvider } from './provider';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-scaffolder-backend-module-workspace-database',\n 'migrations',\n);\nconst migrationsTable = 'scaffolder_workspace_database_migrations';\n\n/**\n * @public\n * Database workspace provider module for the Scaffolder Backend.\n *\n * This module is intended for development use only. In production,\n * use an external storage provider like GCS.\n */\nexport const workspaceDatabaseModule = createBackendModule({\n moduleId: 'workspace-database',\n pluginId: 'scaffolder',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolderWorkspaceProviders: scaffolderWorkspaceProviderExtensionPoint,\n database: coreServices.database,\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n },\n async init({ database, logger, scaffolderWorkspaceProviders, config }) {\n if (\n process.env.NODE_ENV === 'production' &&\n !config.getOptionalBoolean(\n 'scaffolder.taskRecovery.database.dangerouslyEnableInProduction',\n )\n ) {\n logger.warn(\n 'Database workspace provider is not supported in production and will not be enabled',\n );\n return;\n }\n\n const db = await database.getClient();\n\n // Run migrations for our table\n if (!database.migrations?.skip) {\n await db.migrate.latest({\n directory: migrationsDir,\n tableName: migrationsTable,\n });\n }\n\n scaffolderWorkspaceProviders.addProviders({\n database: DatabaseWorkspaceProvider.create({ db }),\n });\n },\n });\n },\n});\n"],"names":["resolvePackagePath","createBackendModule","scaffolderWorkspaceProviderExtensionPoint","coreServices","DatabaseWorkspaceProvider"],"mappings":";;;;;;AAwBA,MAAM,aAAA,GAAgBA,mCAAA;AAAA,EACpB,gEAAA;AAAA,EACA;AACF,CAAA;AACA,MAAM,eAAA,GAAkB,0CAAA;AASjB,MAAM,0BAA0BC,oCAAA,CAAoB;AAAA,EACzD,QAAA,EAAU,oBAAA;AAAA,EACV,QAAA,EAAU,YAAA;AAAA,EACV,QAAA,CAAS,EAAE,YAAA,EAAa,EAAG;AACzB,IAAA,YAAA,CAAa;AAAA,MACX,IAAA,EAAM;AAAA,QACJ,4BAAA,EAA8BC,+CAAA;AAAA,QAC9B,UAAUC,6BAAA,CAAa,QAAA;AAAA,QACvB,QAAQA,6BAAA,CAAa,MAAA;AAAA,QACrB,QAAQA,6BAAA,CAAa;AAAA,OACvB;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,UAAU,MAAA,EAAQ,4BAAA,EAA8B,QAAO,EAAG;AACrE,QAAA,IACE,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,IACzB,CAAC,MAAA,CAAO,kBAAA;AAAA,UACN;AAAA,SACF,EACA;AACA,UAAA,MAAA,CAAO,IAAA;AAAA,YACL;AAAA,WACF;AACA,UAAA;AAAA,QACF;AAEA,QAAA,MAAM,EAAA,GAAK,MAAM,QAAA,CAAS,SAAA,EAAU;AAGpC,QAAA,IAAI,CAAC,QAAA,CAAS,UAAA,EAAY,IAAA,EAAM;AAC9B,UAAA,MAAM,EAAA,CAAG,QAAQ,MAAA,CAAO;AAAA,YACtB,SAAA,EAAW,aAAA;AAAA,YACX,SAAA,EAAW;AAAA,WACZ,CAAA;AAAA,QACH;AAEA,QAAA,4BAAA,CAA6B,YAAA,CAAa;AAAA,UACxC,QAAA,EAAUC,mDAAA,CAA0B,MAAA,CAAO,EAAE,IAAI;AAAA,SAClD,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var alpha = require('@backstage/plugin-scaffolder-node/alpha');
4
+
5
+ const MAX_WORKSPACE_SIZE_BYTES = 50 * 1024 * 1024;
6
+ class DatabaseWorkspaceProvider {
7
+ db;
8
+ legacyWorkspaceColumn;
9
+ static create(options) {
10
+ return new DatabaseWorkspaceProvider(options.db);
11
+ }
12
+ constructor(db) {
13
+ this.db = db;
14
+ }
15
+ hasLegacyWorkspaceColumn() {
16
+ this.legacyWorkspaceColumn ??= this.db.schema.hasColumn(
17
+ "tasks",
18
+ "workspace"
19
+ );
20
+ return this.legacyWorkspaceColumn;
21
+ }
22
+ async serializeWorkspace(options) {
23
+ const { contents: workspace } = await alpha.serializeWorkspace({
24
+ path: options.path
25
+ });
26
+ if (workspace.length > MAX_WORKSPACE_SIZE_BYTES) {
27
+ throw new Error(
28
+ `Workspace size (${Math.round(
29
+ workspace.length / 1024 / 1024
30
+ )}MB) exceeds maximum allowed size of 50MB for database storage. Consider using an external storage provider like GCS.`
31
+ );
32
+ }
33
+ const hasLegacyWorkspaceColumn = await this.hasLegacyWorkspaceColumn();
34
+ await this.db.transaction(async (tx) => {
35
+ await tx("scaffolder_task_workspaces").insert({
36
+ task_id: options.taskId,
37
+ workspace
38
+ }).onConflict("task_id").merge(["workspace"]);
39
+ if (hasLegacyWorkspaceColumn) {
40
+ await tx("tasks").where({ id: options.taskId }).whereNotNull("workspace").update({ workspace });
41
+ }
42
+ });
43
+ }
44
+ async rehydrateWorkspace(options) {
45
+ let workspace;
46
+ if (await this.hasLegacyWorkspaceColumn()) {
47
+ const legacyRow = await this.db("tasks").where({ id: options.taskId }).select("workspace").first();
48
+ workspace = legacyRow?.workspace ?? void 0;
49
+ }
50
+ if (workspace) {
51
+ await this.db("scaffolder_task_workspaces").insert({ task_id: options.taskId, workspace }).onConflict("task_id").merge(["workspace"]);
52
+ } else {
53
+ const row = await this.db(
54
+ "scaffolder_task_workspaces"
55
+ ).where({ task_id: options.taskId }).first();
56
+ workspace = row?.workspace;
57
+ }
58
+ if (workspace) {
59
+ await alpha.restoreWorkspace({
60
+ path: options.targetPath,
61
+ buffer: workspace
62
+ });
63
+ }
64
+ }
65
+ async cleanWorkspace(options) {
66
+ const hasLegacyWorkspaceColumn = await this.hasLegacyWorkspaceColumn();
67
+ await this.db.transaction(async (tx) => {
68
+ await tx("scaffolder_task_workspaces").where({ task_id: options.taskId }).delete();
69
+ if (hasLegacyWorkspaceColumn) {
70
+ await tx("tasks").where({ id: options.taskId }).update({ workspace: null });
71
+ }
72
+ });
73
+ }
74
+ }
75
+
76
+ exports.DatabaseWorkspaceProvider = DatabaseWorkspaceProvider;
77
+ //# sourceMappingURL=DatabaseWorkspaceProvider.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabaseWorkspaceProvider.cjs.js","sources":["../../src/provider/DatabaseWorkspaceProvider.ts"],"sourcesContent":["/*\n * Copyright 2026 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Knex } from 'knex';\nimport {\n WorkspaceProvider,\n serializeWorkspace,\n restoreWorkspace,\n} from '@backstage/plugin-scaffolder-node/alpha';\n\nconst MAX_WORKSPACE_SIZE_BYTES = 50 * 1024 * 1024; // 50MB\n\ntype RawDbTaskWorkspaceRow = {\n task_id: string;\n workspace: Buffer;\n created_at: Date;\n};\n\n/**\n * A workspace provider that stores serialized workspaces in the database.\n *\n * @remarks\n * This provider is intended for development use only. It has a 50MB size limit\n * and is disabled in production unless explicitly enabled via config.\n *\n * For production use, consider using an external storage provider like GCS.\n */\nexport class DatabaseWorkspaceProvider implements WorkspaceProvider {\n private readonly db: Knex;\n private legacyWorkspaceColumn?: Promise<boolean>;\n\n static create(options: { db: Knex }) {\n return new DatabaseWorkspaceProvider(options.db);\n }\n\n private constructor(db: Knex) {\n this.db = db;\n }\n\n private hasLegacyWorkspaceColumn(): Promise<boolean> {\n this.legacyWorkspaceColumn ??= this.db.schema.hasColumn(\n 'tasks',\n 'workspace',\n );\n return this.legacyWorkspaceColumn;\n }\n\n public async serializeWorkspace(options: {\n path: string;\n taskId: string;\n }): Promise<void> {\n const { contents: workspace } = await serializeWorkspace({\n path: options.path,\n });\n\n if (workspace.length > MAX_WORKSPACE_SIZE_BYTES) {\n throw new Error(\n `Workspace size (${Math.round(\n workspace.length / 1024 / 1024,\n )}MB) exceeds ` +\n `maximum allowed size of 50MB for database storage. ` +\n `Consider using an external storage provider like GCS.`,\n );\n }\n\n const hasLegacyWorkspaceColumn = await this.hasLegacyWorkspaceColumn();\n await this.db.transaction(async tx => {\n await tx<RawDbTaskWorkspaceRow>('scaffolder_task_workspaces')\n .insert({\n task_id: options.taskId,\n workspace,\n })\n .onConflict('task_id')\n .merge(['workspace']);\n\n if (hasLegacyWorkspaceColumn) {\n await tx('tasks')\n .where({ id: options.taskId })\n .whereNotNull('workspace')\n .update({ workspace });\n }\n });\n }\n\n public async rehydrateWorkspace(options: {\n taskId: string;\n targetPath: string;\n }): Promise<void> {\n let workspace: Buffer | undefined;\n if (await this.hasLegacyWorkspaceColumn()) {\n const legacyRow = await this.db('tasks')\n .where({ id: options.taskId })\n .select('workspace')\n .first();\n workspace = legacyRow?.workspace ?? undefined;\n }\n\n if (workspace) {\n await this.db<RawDbTaskWorkspaceRow>('scaffolder_task_workspaces')\n .insert({ task_id: options.taskId, workspace })\n .onConflict('task_id')\n .merge(['workspace']);\n } else {\n const row = await this.db<RawDbTaskWorkspaceRow>(\n 'scaffolder_task_workspaces',\n )\n .where({ task_id: options.taskId })\n .first();\n workspace = row?.workspace;\n }\n\n if (workspace) {\n await restoreWorkspace({\n path: options.targetPath,\n buffer: workspace,\n });\n }\n }\n\n public async cleanWorkspace(options: { taskId: string }): Promise<void> {\n const hasLegacyWorkspaceColumn = await this.hasLegacyWorkspaceColumn();\n await this.db.transaction(async tx => {\n await tx<RawDbTaskWorkspaceRow>('scaffolder_task_workspaces')\n .where({ task_id: options.taskId })\n .delete();\n if (hasLegacyWorkspaceColumn) {\n await tx('tasks')\n .where({ id: options.taskId })\n .update({ workspace: null });\n }\n });\n }\n}\n"],"names":["serializeWorkspace","restoreWorkspace"],"mappings":"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"}
@@ -0,0 +1,96 @@
1
+ /*
2
+ * Copyright 2026 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // @ts-check
18
+
19
+ /**
20
+ * @param { import("knex").Knex } knex
21
+ */
22
+ exports.up = async function up(knex) {
23
+ await knex.schema.createTable('scaffolder_task_workspaces', table => {
24
+ table
25
+ .string('task_id')
26
+ .primary()
27
+ .notNullable()
28
+ .comment('The task this workspace belongs to');
29
+ const workspace = knex.client.config.client.includes('mysql')
30
+ ? table.specificType('workspace', 'LONGBLOB')
31
+ : table.binary('workspace');
32
+ workspace
33
+ .notNullable()
34
+ .comment('Serialized workspace contents (tar archive)');
35
+ table
36
+ .timestamp('created_at', { useTz: true })
37
+ .notNullable()
38
+ .defaultTo(knex.fn.now())
39
+ .comment('When the workspace was serialized');
40
+ });
41
+
42
+ if (await knex.schema.hasColumn('tasks', 'workspace')) {
43
+ let lastTaskId;
44
+ for (;;) {
45
+ const query = knex('tasks')
46
+ .select('id', 'workspace')
47
+ .whereNotNull('workspace')
48
+ .orderBy('id')
49
+ .limit(100);
50
+ if (lastTaskId) {
51
+ query.andWhere('id', '>', lastTaskId);
52
+ }
53
+ const legacyWorkspaces = await query;
54
+ if (legacyWorkspaces.length === 0) {
55
+ break;
56
+ }
57
+ await knex('scaffolder_task_workspaces').insert(
58
+ legacyWorkspaces.map(({ id, workspace }) => ({
59
+ task_id: id,
60
+ workspace,
61
+ })),
62
+ );
63
+ lastTaskId = legacyWorkspaces[legacyWorkspaces.length - 1].id;
64
+ }
65
+ }
66
+ };
67
+
68
+ /**
69
+ * @param {import('knex').Knex} knex
70
+ */
71
+ exports.down = async function down(knex) {
72
+ if (await knex.schema.hasColumn('tasks', 'workspace')) {
73
+ let lastTaskId;
74
+ for (;;) {
75
+ const query = knex('scaffolder_task_workspaces')
76
+ .select('task_id', 'workspace')
77
+ .orderBy('task_id')
78
+ .limit(100);
79
+ if (lastTaskId) {
80
+ query.andWhere('task_id', '>', lastTaskId);
81
+ }
82
+ const workspaces = await query;
83
+ if (workspaces.length === 0) {
84
+ break;
85
+ }
86
+ for (const { task_id: taskId, workspace } of workspaces) {
87
+ await knex('tasks')
88
+ .where({ id: taskId })
89
+ .whereNull('workspace')
90
+ .update({ workspace });
91
+ }
92
+ lastTaskId = workspaces[workspaces.length - 1].task_id;
93
+ }
94
+ }
95
+ await knex.schema.dropTable('scaffolder_task_workspaces');
96
+ };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@backstage/plugin-scaffolder-backend-module-workspace-database",
3
+ "version": "0.0.0-nightly-20260822023239",
4
+ "description": "Database workspace provider module for @backstage/plugin-scaffolder-backend (development use only)",
5
+ "backstage": {
6
+ "role": "backend-plugin-module",
7
+ "pluginId": "scaffolder",
8
+ "pluginPackage": "@backstage/plugin-scaffolder-backend",
9
+ "features": {
10
+ ".": "@backstage/BackendFeature"
11
+ }
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/backstage/backstage",
19
+ "directory": "plugins/scaffolder-backend-module-workspace-database"
20
+ },
21
+ "license": "Apache-2.0",
22
+ "exports": {
23
+ ".": {
24
+ "backstage": "@backstage/BackendFeature",
25
+ "require": "./dist/index.cjs.js",
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.cjs.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "main": "./dist/index.cjs.js",
32
+ "types": "./dist/index.d.ts",
33
+ "typesVersions": {
34
+ "*": {
35
+ "package.json": [
36
+ "package.json"
37
+ ]
38
+ }
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "migrations",
43
+ "config.schema.json"
44
+ ],
45
+ "scripts": {
46
+ "build": "backstage-cli package build",
47
+ "clean": "backstage-cli package clean",
48
+ "lint": "backstage-cli package lint",
49
+ "prepack": "backstage-cli package prepack",
50
+ "postpack": "backstage-cli package postpack",
51
+ "start": "backstage-cli package start",
52
+ "test": "backstage-cli package test"
53
+ },
54
+ "dependencies": {
55
+ "@backstage/backend-plugin-api": "1.10.0",
56
+ "@backstage/plugin-scaffolder-node": "0.0.0-nightly-20260822023239",
57
+ "knex": "^3.0.0"
58
+ },
59
+ "devDependencies": {
60
+ "@backstage/backend-defaults": "0.17.7",
61
+ "@backstage/backend-test-utils": "1.11.6",
62
+ "@backstage/cli": "0.0.0-nightly-20260822023239",
63
+ "@backstage/config": "1.3.8",
64
+ "fs-extra": "^11.0.0"
65
+ },
66
+ "configSchema": "config.schema.json"
67
+ }