@aligent/nx-appbuilder 0.2.1 → 0.4.0

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/README.md CHANGED
@@ -96,16 +96,15 @@ The app generator always renders a **base** subtree into `<app-name>/`:
96
96
  - `package.json` - Pinned dependencies and `lint` / `lint:fix` / `check-types` / `test` scripts (per-target variants for actions, web and tests)
97
97
  - `package.json` `nx.targets` block - declares the custom `check-types` and `deploy` targets; `lint` and `test` are inferred by the `@nx/eslint/plugin` and `@nx/vitest` plugins from `eslint.config.mjs` and `vitest.config.ts`
98
98
  - `tsconfig.json` / `tsconfig.base.json` - TypeScript project config
99
- - `babel.actions.config.js` - Babel preset for App Builder actions
100
- - `eslint.config.mjs` / `prettier.config.mjs` - Lint and formatter config (`@aligent/ts-code-standards`)
99
+ - `eslint.config.mjs` / `prettier.config.mjs` - Lint and formatter config (`@aligent/ts-code-standards`). The eslint preset is `react` when `hasAdminUI=true` and `base` otherwise, so action-only apps don't load the React/JSX/a11y rules.
101
100
  - `vitest.config.ts` - Vitest config
102
101
  - `.editorconfig`, `.nvmrc`, `.gitignore`, `README.md`
103
102
 
104
103
  - **Action and test scaffolding**:
105
104
  - `src/actions/tsconfig.json` - TypeScript config for the App Builder actions
106
- - `src/actions/webpack-config.cjs` - Webpack config used by the `aio` CLI to compile actions via `babel-loader`
105
+ - `src/actions/webpack-config.cjs` - Webpack config used by the `aio` CLI to compile actions via `esbuild-loader` (targets the workspace's Node major)
107
106
  - `tests/tsconfig.json` - TypeScript config for the test suite
108
- - `hooks/check-action-types.sh` - `pre-app-build` hook that type-checks actions before deploy
107
+ - `hooks/check-action-types.sh` - Wired as the application-level `pre-app-build` hook in `app.config.yaml` so the action TypeScript is type-checked before every deploy. Custom (non-Adobe) actions also live under `application.runtimeManifest` in `app.config.yaml`; the scaffolded `ext.config.yaml` files are left for Adobe-generated content only.
109
108
  - `global-types/@adobe/aio-sdk/*.d.ts` - Local type augmentations for the Adobe AIO SDK
110
109
 
111
110
  - **Root updates**:
@@ -113,16 +112,16 @@ The app generator always renders a **base** subtree into `<app-name>/`:
113
112
 
114
113
  Additional subtrees are layered on top depending on the selected flags:
115
114
 
116
- | Flag | Subtree rendered | Notable additions |
117
- |-----------------------------------------------------------------|-------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
118
- | any of `hasAdminUI`, `hasBusinessConfig`, `hasCommerceWebhooks` | `commerce-extensibility/` | `app.commerce.config.ts`, `install.yaml`, `commerce/extensibility/1` extension config; pulls in `@adobe/aio-commerce-lib-app` / `-config`. |
119
- | `hasAdminUI` | `commerce-backend-ui/` | React 19 + Spectrum admin UI under `src/commerce-backend-ui-1/`, `web-src/` entry point, action utils, registration, `pre-app-build` web type-check hook. |
120
- | `hasBusinessConfig` | `commerce-config/` | `commerce/configuration/1` extension config wired into `app.commerce.config.ts`; adds a `businessConfig.schema` block to `app.commerce.config.ts`. |
121
- | `hasCommerceWebhooks` | none (modifies `commerce-extensibility/`) | Adds a `webhooks` section to `app.commerce.config.ts` for binding Commerce extensibility hooks to runtime actions or external URLs. No new files; relies on the `commerce-extensibility/` subtree being rendered. |
122
- | `hasRestActions` | `rest-actions/` | `src/actions/rest-sample.ts` registered as a web action in `app.config.yaml`. |
123
- | `hasEvents` | `events/` | `src/actions/handle-sample-event.ts`, sample Commerce + external event subscriptions, `aio-lib-events` global types. |
124
- | `hasScheduledActions` | `scheduled/` | `src/actions/cron-sample.ts` plus the `triggers`/`rules` entries that fire it on a cron schedule. |
125
- | `hasCustomInstallSteps` | `install-steps/` | `scripts/install/sample-step.js` and an `installation.customInstallationSteps` entry in `app.commerce.config.ts`. |
115
+ | Flag | Subtree rendered | Notable additions |
116
+ |-----------------------------------------------------------------|-------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
117
+ | any of `hasAdminUI`, `hasBusinessConfig`, `hasCommerceWebhooks` | `commerce-extensibility/` | `app.commerce.config.ts`, `install.yaml`, `commerce/extensibility/1` extension config; pulls in `@adobe/aio-commerce-lib-app` / `-config`. |
118
+ | `hasAdminUI` | `commerce-backend-ui/` | React 19 + Spectrum admin UI under `src/commerce-backend-ui-1/`, `web-src/` entry point (with `module: Preserve` / `moduleResolution: Bundler` so the webpack/esbuild pipeline sees ESM-style imports), action utils, registration, `pre-app-build` web type-check hook. |
119
+ | `hasBusinessConfig` | `commerce-config/` | `commerce/configuration/1` extension config wired into `app.commerce.config.ts`; adds a `businessConfig.schema` block to `app.commerce.config.ts`. |
120
+ | `hasCommerceWebhooks` | none (modifies `commerce-extensibility/`) | Adds a `webhooks` section to `app.commerce.config.ts` for binding Commerce extensibility hooks to runtime actions or external URLs. No new files; relies on the `commerce-extensibility/` subtree being rendered. |
121
+ | `hasRestActions` | `rest-actions/` | `src/actions/rest-sample.ts` registered as a web action in `app.config.yaml`. |
122
+ | `hasEvents` | `events/` | `src/actions/handle-sample-event.ts`, sample Commerce + external event subscriptions, `aio-lib-events` global types. |
123
+ | `hasScheduledActions` | `scheduled/` | `src/actions/cron-sample.ts` plus the `triggers`/`rules` entries that fire it on a cron schedule. |
124
+ | `hasCustomInstallSteps` | `install-steps/` | `scripts/install/sample-step.js` and an `installation.customInstallationSteps` entry in `app.commerce.config.ts`. |
126
125
 
127
126
  #### Example
128
127
 
@@ -179,6 +178,15 @@ npx nx build nx-appbuilder
179
178
 
180
179
  The `@nx/js:tsc` build executor compiles `src/**/*.ts` to `dist/src/` and copies the templates under `src/generators/<gen>/files/` verbatim. Template files use the `.template` suffix (e.g. `app.commerce.config.ts.template`) so they aren't picked up by lint or `tsc`; `@nx/devkit`'s `generateFiles` strips the suffix at generation time.
181
180
 
181
+ #### Dependency version pins
182
+
183
+ Each generator reads the npm version specs it injects into generated files from a real `package.json` at `src/generators/<gen>/template-package/package.json`:
184
+
185
+ - `preset/template-package/package.json` pins the workspace-level devDeps (`nx`, `@nx/*` plugins, `eslint`, `prettier`, `typescript`, `vitest`, `@aligent/ts-code-standards`).
186
+ - `app/template-package/package.json` pins the per-app deps (`@adobe/aio-*`, React + Spectrum, lint/test tooling, etc.).
187
+
188
+ Both files are tracked by Dependabot (see `.github/dependabot.yml`) so version bumps land via PR. To add a new pin, add it to the relevant template-package and reference it from `pickVersions()` in `preset.ts` / `compose-package-json.ts`. The shared helper at `src/generators/helpers/template-package.ts` enforces that every requested key exists in the template file, so missing pins fail loudly at runtime.
189
+
182
190
  ### Running tests / lint / type-check
183
191
 
184
192
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aligent/nx-appbuilder",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "typings": "./src/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  import { eslintConfigs } from '@aligent/ts-code-standards';
2
2
 
3
3
  export default [
4
- ...eslintConfigs.react,
4
+ ...eslintConfigs.<%= hasAdminUI ? 'react' : 'base' %>,
5
5
  {
6
6
  ignores: ['**/*.js', '**/*.cjs', '**/*.mjs', '**/coverage'],
7
7
  },
@@ -1,6 +1,8 @@
1
- // Webpack configuration required to compile typescript action and web source code
2
- // using the Adobe aio CLI. Adapted from https://github.com/adobe/aio-cli-plugin-app-dev, then switched to babel-loader
3
- // Appbuilder documentation: https://developer.adobe.com/app-builder/docs/guides/configuration/webpack-configuration/
1
+ // Webpack config for action source. esbuild-loader strips the TypeScript and
2
+ // targets the same Node version as the OpenWhisk runtime declared in
3
+ // ext.config.yaml. aio's webpack pipeline emits a CommonJS bundle
4
+ // (libraryTarget: 'commonjs2') which OpenWhisk loads via require().
5
+ // Appbuilder docs: https://developer.adobe.com/app-builder/docs/guides/configuration/webpack-configuration/
4
6
 
5
7
  const path = require('path');
6
8
 
@@ -18,15 +20,12 @@ module.exports = {
18
20
  module: {
19
21
  rules: [
20
22
  {
21
- // Test for .ts - in theory actions should never use .tsx
22
23
  test: /\.ts$/,
23
24
  exclude: /node_modules/,
24
- loader: 'babel-loader',
25
+ loader: 'esbuild-loader',
25
26
  options: {
26
- // Point to the babel config for actions
27
- // This is done to avoid Parcel reading the config file
28
- // while building web code
29
- configFile: './babel.actions.config.js',
27
+ loader: 'ts',
28
+ target: 'node<%= nodeMajor %>',
30
29
  },
31
30
  },
32
31
  ],
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "extends": "@aligent/ts-code-standards/tsconfigs-react",
3
3
  "compilerOptions": {
4
+ "module": "Preserve",
5
+ "moduleResolution": "Bundler",
4
6
  "allowImportingTsExtensions": true,
5
7
  "resolveJsonModule": true,
6
8
  "baseUrl": "../../..",
@@ -1,62 +1,26 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.writePackageJson = writePackageJson;
37
- const devkit_1 = require("@nx/devkit");
38
- const path = __importStar(require("path"));
39
- const TEMPLATE = (0, devkit_1.readJsonFile)(path.join(__dirname, 'template-package', 'package.json'));
40
- function pickVersions(source, names) {
41
- const result = {};
42
- for (const name of names) {
43
- const version = source?.[name];
44
- if (version === undefined) {
45
- throw new Error(`Missing "${name}" in template-package.json`);
46
- }
47
- result[name] = version;
48
- }
49
- return result;
50
- }
51
- const BASE_DEPS = pickVersions(TEMPLATE.dependencies, [
4
+ const template_package_1 = require("../../helpers/template-package");
5
+ /**
6
+ * Builds the new app's package.json based on selected flags.
7
+ *
8
+ * Versions are sourced from `template-package/package.json` (a real package.json
9
+ * that Dependabot watches) — bumping a dependency there flows into every app
10
+ * scaffolded thereafter without code changes. The manifest lives in its own
11
+ * directory because Dependabot's npm ecosystem only discovers files named
12
+ * exactly `package.json`.
13
+ */
14
+ const TEMPLATE = (0, template_package_1.loadTemplatePackage)(__dirname);
15
+ const BASE_DEPS = (0, template_package_1.pickVersions)(TEMPLATE.dependencies, [
52
16
  '@adobe/aio-sdk',
53
17
  '@adobe/aio-lib-telemetry',
54
18
  ]);
55
- const COMMERCE_DEPS = pickVersions(TEMPLATE.dependencies, [
19
+ const COMMERCE_DEPS = (0, template_package_1.pickVersions)(TEMPLATE.dependencies, [
56
20
  '@adobe/aio-commerce-lib-app',
57
21
  '@adobe/aio-commerce-lib-config',
58
22
  ]);
59
- const ADMIN_UI_DEPS = pickVersions(TEMPLATE.dependencies, [
23
+ const ADMIN_UI_DEPS = (0, template_package_1.pickVersions)(TEMPLATE.dependencies, [
60
24
  '@adobe/uix-guest',
61
25
  '@adobe/exc-app',
62
26
  '@adobe/react-spectrum',
@@ -64,18 +28,23 @@ const ADMIN_UI_DEPS = pickVersions(TEMPLATE.dependencies, [
64
28
  'react-dom',
65
29
  'react-router',
66
30
  ]);
67
- const BASE_DEV_DEPS = pickVersions(TEMPLATE.devDependencies, [
31
+ const BASE_DEV_DEPS = (0, template_package_1.pickVersions)(TEMPLATE.devDependencies, [
68
32
  '@aligent/ts-code-standards',
69
- '@babel/preset-env',
70
- '@babel/preset-typescript',
71
33
  '@types/node',
72
- 'babel-loader',
34
+ 'esbuild-loader',
35
+ // `eslint` is also pinned at the workspace root; declaring it here keeps
36
+ // the app's `lint` script resolvable independent of npm workspace hoisting.
37
+ 'eslint',
38
+ // `prettier` is required as a peer dep of `eslint-plugin-prettier`, which
39
+ // is wired in via `@aligent/ts-code-standards`. Without an explicit
40
+ // declaration the lint run can hang in the dynamic-import fallback path.
41
+ 'prettier',
73
42
  'ts-loader',
74
43
  'type-fest',
75
44
  'typescript',
76
45
  'vitest',
77
46
  ]);
78
- const ADMIN_UI_DEV_DEPS = pickVersions(TEMPLATE.devDependencies, [
47
+ const ADMIN_UI_DEV_DEPS = (0, template_package_1.pickVersions)(TEMPLATE.devDependencies, [
79
48
  '@types/react',
80
49
  '@types/react-dom',
81
50
  ]);
@@ -17,12 +17,12 @@
17
17
  },
18
18
  "devDependencies": {
19
19
  "@aligent/ts-code-standards": "^4.2.0",
20
- "@babel/preset-env": "^7.26.9",
21
- "@babel/preset-typescript": "^7.27.0",
22
20
  "@types/node": "^22.14.0",
23
21
  "@types/react": "^19.1.0",
24
22
  "@types/react-dom": "^19.1.2",
25
- "babel-loader": "^10.0.0",
23
+ "esbuild-loader": "^4.3.0",
24
+ "eslint": "^9.0.0",
25
+ "prettier": "^3.8.1",
26
26
  "ts-loader": "^9.5.2",
27
27
  "type-fest": "^4.39.1",
28
28
  "typescript": "^5.8.3",
@@ -0,0 +1,20 @@
1
+ export interface TemplatePackageJson {
2
+ dependencies?: Record<string, string>;
3
+ devDependencies?: Record<string, string>;
4
+ }
5
+ /**
6
+ * Read a generator's `template-package/package.json`. Each generator keeps its
7
+ * version pins in a real package.json (rather than hard-coding versions in TS)
8
+ * so Dependabot can track and bump them via PR.
9
+ *
10
+ * `generatorDir` is the directory containing the generator's compiled code —
11
+ * pass `__dirname` from the caller. The template lives at
12
+ * `<generatorDir>/template-package/package.json`.
13
+ */
14
+ export declare function loadTemplatePackage(generatorDir: string): TemplatePackageJson;
15
+ /**
16
+ * Extract the requested entries from a dependency map, preserving the version
17
+ * spec. Throws if any requested name is missing — keeps the template-package
18
+ * file as the single source of truth and surfaces drift loudly.
19
+ */
20
+ export declare function pickVersions(source: Record<string, string> | undefined, names: readonly string[]): Record<string, string>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadTemplatePackage = loadTemplatePackage;
4
+ exports.pickVersions = pickVersions;
5
+ const devkit_1 = require("@nx/devkit");
6
+ /**
7
+ * Read a generator's `template-package/package.json`. Each generator keeps its
8
+ * version pins in a real package.json (rather than hard-coding versions in TS)
9
+ * so Dependabot can track and bump them via PR.
10
+ *
11
+ * `generatorDir` is the directory containing the generator's compiled code —
12
+ * pass `__dirname` from the caller. The template lives at
13
+ * `<generatorDir>/template-package/package.json`.
14
+ */
15
+ function loadTemplatePackage(generatorDir) {
16
+ return (0, devkit_1.readJsonFile)(`${generatorDir}/template-package/package.json`);
17
+ }
18
+ /**
19
+ * Extract the requested entries from a dependency map, preserving the version
20
+ * spec. Throws if any requested name is missing — keeps the template-package
21
+ * file as the single source of truth and surfaces drift loudly.
22
+ */
23
+ function pickVersions(source, names) {
24
+ const result = {};
25
+ for (const name of names) {
26
+ const version = source?.[name];
27
+ if (version === undefined) {
28
+ throw new Error(`Missing "${name}" in template-package.json`);
29
+ }
30
+ result[name] = version;
31
+ }
32
+ return result;
33
+ }
@@ -36,8 +36,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.default = presetGenerator;
37
37
  const devkit_1 = require("@nx/devkit");
38
38
  const path = __importStar(require("path"));
39
+ const template_package_1 = require("../helpers/template-package");
39
40
  const nx_json_1 = require("./nx-json");
40
41
  const DEFAULT_NODE_VERSION = '24.0.1';
42
+ const TEMPLATE = (0, template_package_1.loadTemplatePackage)(__dirname);
43
+ const WORKSPACE_DEV_DEPS = (0, template_package_1.pickVersions)(TEMPLATE.devDependencies, [
44
+ '@aligent/ts-code-standards',
45
+ '@nx/eslint',
46
+ '@nx/js',
47
+ '@nx/vitest',
48
+ 'eslint',
49
+ 'nx',
50
+ 'prettier',
51
+ 'typescript',
52
+ 'vitest',
53
+ ]);
41
54
  /**
42
55
  * Preset generator invoked by `create-nx-workspace --preset=@aligent/nx-appbuilder`.
43
56
  *
@@ -65,6 +78,20 @@ async function presetGenerator(tree, options) {
65
78
  * devDependencies so the lockfile written by create-nx-workspace stays in sync
66
79
  * with what the preset declares — otherwise npm fails the post-preset install
67
80
  * with an arborist "must provide string spec" error.
81
+ *
82
+ * Most devDependency versions are sourced from `template-package/package.json`
83
+ * (a real package.json that Dependabot watches). The self-version of
84
+ * `@aligent/nx-appbuilder` is read from the generator's own package.json since
85
+ * Dependabot can't track that.
86
+ *
87
+ * Notes on why each dep is pinned at the workspace root:
88
+ * - `@aligent/ts-code-standards` is resolved by the workspace tsconfig's
89
+ * `extends` line and by every generated app's tsconfig chain.
90
+ * - The `@nx/*` plugin packages need to be installed at the workspace root so
91
+ * the plugins declared in nx.json can load.
92
+ * - `eslint` and `prettier` are also declared at the app level (so each app is
93
+ * self-sufficient), but pinning here ensures npm workspaces hoists a single
94
+ * shared version.
68
95
  */
69
96
  function buildWorkspacePackageJson(name, nodeVersion) {
70
97
  const major = nodeVersion.split('.')[0];
@@ -85,24 +112,15 @@ function buildWorkspacePackageJson(name, nodeVersion) {
85
112
  'build:all': 'nx run-many -t build',
86
113
  },
87
114
  workspaces: [],
88
- devDependencies: {
115
+ devDependencies: sortObject({
89
116
  '@aligent/nx-appbuilder': getGeneratorVersion(),
90
- // Resolved by the workspace's tsconfig.json's `extends` line and
91
- // by every generated app's tsconfig chain. Pinned at the workspace
92
- // root so all apps share one resolution.
93
- '@aligent/ts-code-standards': '^4.2.0',
94
- // The @nx plugin packages need to be installed at the workspace
95
- // root so the plugins declared in nx.json can actually load.
96
- '@nx/eslint': '^22.4.5',
97
- '@nx/js': '^22.4.5',
98
- '@nx/vitest': '^22.4.5',
99
- eslint: '^9.0.0',
100
- nx: '^22.4.5',
101
- typescript: '^5.8.3',
102
- vitest: '^2.1.8',
103
- },
117
+ ...WORKSPACE_DEV_DEPS,
118
+ }),
104
119
  };
105
120
  }
121
+ function sortObject(obj) {
122
+ return Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
123
+ }
106
124
  function getGeneratorVersion() {
107
125
  const packagePath = path.join(__dirname, '../../../package.json');
108
126
  const packageJson = (0, devkit_1.readJsonFile)(packagePath);
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@aligent/nx-appbuilder-generated-workspace-deps",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "description": "Version pins for the deps that the preset generator injects into a generated workspace's package.json. Tracked by Dependabot so version bumps land via PR; consumed at runtime by preset.ts.",
6
+ "devDependencies": {
7
+ "@aligent/ts-code-standards": "^4.2.0",
8
+ "@nx/eslint": "^22.4.5",
9
+ "@nx/js": "^22.4.5",
10
+ "@nx/vitest": "^22.4.5",
11
+ "eslint": "^9.0.0",
12
+ "nx": "^22.4.5",
13
+ "prettier": "^3.8.1",
14
+ "typescript": "^5.8.3",
15
+ "vitest": "^2.1.8"
16
+ }
17
+ }
@@ -1,6 +0,0 @@
1
- // Babel configuration allowing compilation of typescript files in both
2
- // test and src/action folders
3
- module.exports = {
4
- presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
5
- ignore: ['**/src/web/**', '**/node_modules/**'],
6
- };