@aligent/nx-appbuilder 0.2.1 → 0.3.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
@@ -97,7 +97,7 @@ The app generator always renders a **base** subtree into `<app-name>/`:
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
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`)
100
+ - `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
101
  - `vitest.config.ts` - Vitest config
102
102
  - `.editorconfig`, `.nvmrc`, `.gitignore`, `README.md`
103
103
 
@@ -179,6 +179,15 @@ npx nx build nx-appbuilder
179
179
 
180
180
  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
181
 
182
+ #### Dependency version pins
183
+
184
+ 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`:
185
+
186
+ - `preset/template-package/package.json` pins the workspace-level devDeps (`nx`, `@nx/*` plugins, `eslint`, `prettier`, `typescript`, `vitest`, `@aligent/ts-code-standards`).
187
+ - `app/template-package/package.json` pins the per-app deps (`@adobe/aio-*`, React + Spectrum, lint/test tooling, etc.).
188
+
189
+ 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.
190
+
182
191
  ### Running tests / lint / type-check
183
192
 
184
193
  ```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.3.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,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,25 @@ 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
33
  '@babel/preset-env',
70
34
  '@babel/preset-typescript',
71
35
  '@types/node',
72
36
  'babel-loader',
37
+ // `eslint` is also pinned at the workspace root; declaring it here keeps
38
+ // the app's `lint` script resolvable independent of npm workspace hoisting.
39
+ 'eslint',
40
+ // `prettier` is required as a peer dep of `eslint-plugin-prettier`, which
41
+ // is wired in via `@aligent/ts-code-standards`. Without an explicit
42
+ // declaration the lint run can hang in the dynamic-import fallback path.
43
+ 'prettier',
73
44
  'ts-loader',
74
45
  'type-fest',
75
46
  'typescript',
76
47
  'vitest',
77
48
  ]);
78
- const ADMIN_UI_DEV_DEPS = pickVersions(TEMPLATE.devDependencies, [
49
+ const ADMIN_UI_DEV_DEPS = (0, template_package_1.pickVersions)(TEMPLATE.devDependencies, [
79
50
  '@types/react',
80
51
  '@types/react-dom',
81
52
  ]);
@@ -23,6 +23,8 @@
23
23
  "@types/react": "^19.1.0",
24
24
  "@types/react-dom": "^19.1.2",
25
25
  "babel-loader": "^10.0.0",
26
+ "eslint": "^9.0.0",
27
+ "prettier": "^3.8.1",
26
28
  "ts-loader": "^9.5.2",
27
29
  "type-fest": "^4.39.1",
28
30
  "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
+ }