@ngrs/build 0.0.0-stage → 0.1.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.
@@ -0,0 +1,108 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "title": "ngrs Dev Server Target Schema",
4
+ "description": "Dev Server target options (1:1 compatible with @angular/build:dev-server and @angular-devkit/build-angular:dev-server).",
5
+ "type": "object",
6
+ "properties": {
7
+ "buildTarget": {
8
+ "type": "string",
9
+ "description": "A build builder target to serve in the format of 'project:target[:configuration]'."
10
+ },
11
+ "browserTarget": {
12
+ "type": "string",
13
+ "description": "Legacy alias for 'buildTarget' in 'project:target[:configuration]' format."
14
+ },
15
+ "port": {
16
+ "type": "number",
17
+ "default": 4200
18
+ },
19
+ "host": {
20
+ "type": "string",
21
+ "default": "localhost"
22
+ },
23
+ "proxyConfig": {
24
+ "type": "string"
25
+ },
26
+ "ssl": {
27
+ "type": "boolean",
28
+ "default": false
29
+ },
30
+ "sslKey": {
31
+ "type": "string"
32
+ },
33
+ "sslCert": {
34
+ "type": "string"
35
+ },
36
+ "allowedHosts": {
37
+ "default": [],
38
+ "oneOf": [
39
+ {
40
+ "type": "array",
41
+ "items": { "type": "string" }
42
+ },
43
+ { "type": "boolean" }
44
+ ]
45
+ },
46
+ "define": {
47
+ "type": "object",
48
+ "additionalProperties": { "type": "string" }
49
+ },
50
+ "headers": {
51
+ "type": "object",
52
+ "additionalProperties": { "type": "string" }
53
+ },
54
+ "open": {
55
+ "type": "boolean",
56
+ "default": false
57
+ },
58
+ "verbose": {
59
+ "type": "boolean"
60
+ },
61
+ "progress": {
62
+ "type": "boolean",
63
+ "default": true
64
+ },
65
+ "colors": {
66
+ "type": "boolean"
67
+ },
68
+ "liveReload": {
69
+ "type": "boolean",
70
+ "default": true
71
+ },
72
+ "servePath": {
73
+ "type": "string"
74
+ },
75
+ "hmr": {
76
+ "type": "boolean"
77
+ },
78
+ "watch": {
79
+ "type": "boolean",
80
+ "default": true
81
+ },
82
+ "poll": {
83
+ "type": "number"
84
+ },
85
+ "inspect": {
86
+ "default": false,
87
+ "oneOf": [{ "type": "string" }, { "type": "boolean" }]
88
+ },
89
+ "prebundle": {
90
+ "default": true,
91
+ "oneOf": [
92
+ { "type": "boolean" },
93
+ {
94
+ "type": "object",
95
+ "properties": {
96
+ "exclude": {
97
+ "type": "array",
98
+ "items": { "type": "string" }
99
+ }
100
+ },
101
+ "required": ["exclude"],
102
+ "additionalProperties": false
103
+ }
104
+ ]
105
+ }
106
+ },
107
+ "additionalProperties": true
108
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "title": "ngrs Extract i18n Target Schema",
4
+ "description": "Extract i18n target options compatible with @angular/build:extract-i18n.",
5
+ "type": "object",
6
+ "properties": {
7
+ "buildTarget": {
8
+ "type": "string"
9
+ },
10
+ "browserTarget": {
11
+ "type": "string"
12
+ },
13
+ "format": {
14
+ "type": "string",
15
+ "default": "xlf",
16
+ "enum": ["xmb", "xlf", "xlif", "xliff", "xlf2", "xliff2"]
17
+ },
18
+ "progress": {
19
+ "type": "boolean",
20
+ "default": true
21
+ },
22
+ "outputPath": {
23
+ "type": "string"
24
+ },
25
+ "outFile": {
26
+ "type": "string"
27
+ },
28
+ "i18nDuplicateTranslation": {
29
+ "type": "string",
30
+ "enum": ["error", "warning", "ignore"],
31
+ "default": "warning"
32
+ }
33
+ },
34
+ "additionalProperties": true
35
+ }
@@ -0,0 +1,118 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "title": "ngrs Unit Test Builder Schema",
4
+ "description": "Unit test target options (1:1 compatible with @angular/build:unit-test powered by Vitest & @ngrs/vite).",
5
+ "type": "object",
6
+ "properties": {
7
+ "tsConfig": {
8
+ "type": "string",
9
+ "description": "The name of the TypeScript configuration file (defaults to tsconfig.spec.json if present)."
10
+ },
11
+ "buildTarget": {
12
+ "type": "string",
13
+ "description": "A build builder target to inherit options from in 'project:target[:configuration]' format (defaults to '::development')."
14
+ },
15
+ "runner": {
16
+ "type": "string",
17
+ "default": "vitest",
18
+ "enum": ["vitest", "karma"]
19
+ },
20
+ "runnerConfig": {
21
+ "oneOf": [{ "type": "boolean" }, { "type": "string" }],
22
+ "default": false
23
+ },
24
+ "environment": {
25
+ "type": "string",
26
+ "enum": ["happy-dom", "node"],
27
+ "default": "happy-dom",
28
+ "description": "Vitest execution environment (defaults to 'happy-dom')."
29
+ },
30
+ "polyfills": {
31
+ "type": "array",
32
+ "items": { "type": "string" }
33
+ },
34
+ "include": {
35
+ "type": "array",
36
+ "items": { "type": "string" },
37
+ "default": ["**/*.spec.ts"]
38
+ },
39
+ "exclude": {
40
+ "type": "array",
41
+ "items": { "type": "string" }
42
+ },
43
+ "filter": {
44
+ "type": "string",
45
+ "description": "Filter executed tests by test name regex pattern."
46
+ },
47
+ "watch": {
48
+ "type": "boolean"
49
+ },
50
+ "coverage": {
51
+ "type": "boolean",
52
+ "default": false
53
+ },
54
+ "coverageReporters": {
55
+ "type": "array",
56
+ "items": {
57
+ "oneOf": [{ "type": "string" }, { "type": "array" }]
58
+ }
59
+ },
60
+ "coverageInclude": {
61
+ "type": "array",
62
+ "items": { "type": "string" }
63
+ },
64
+ "coverageExclude": {
65
+ "type": "array",
66
+ "items": { "type": "string" }
67
+ },
68
+ "coverageThresholds": {
69
+ "type": "object"
70
+ },
71
+ "reporters": {
72
+ "type": "array",
73
+ "items": {
74
+ "oneOf": [{ "type": "string" }, { "type": "array" }]
75
+ }
76
+ },
77
+ "outputFile": {
78
+ "type": "string"
79
+ },
80
+ "browsers": {
81
+ "type": "array",
82
+ "items": { "type": "string" }
83
+ },
84
+ "headless": {
85
+ "type": "boolean",
86
+ "default": true
87
+ },
88
+ "browserViewport": {
89
+ "type": "string"
90
+ },
91
+ "ui": {
92
+ "type": "boolean"
93
+ },
94
+ "isolate": {
95
+ "type": "boolean"
96
+ },
97
+ "providersFile": {
98
+ "type": "string"
99
+ },
100
+ "setupFiles": {
101
+ "type": "array",
102
+ "items": { "type": "string" }
103
+ },
104
+ "listTests": {
105
+ "type": "boolean",
106
+ "default": false
107
+ },
108
+ "progress": {
109
+ "type": "boolean",
110
+ "default": true
111
+ },
112
+ "debug": {
113
+ "type": "boolean",
114
+ "default": false
115
+ }
116
+ },
117
+ "additionalProperties": true
118
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "schematics": {
3
+ "ng-add": {
4
+ "description": "Configures an Angular CLI workspace (angular.json) to build and serve using @ngrs/build.",
5
+ "factory": "./ng-add/index.cjs",
6
+ "schema": "./ng-add/schema.json",
7
+ "aliases": ["install", "init"]
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,231 @@
1
+ 'use strict';
2
+
3
+ const { applyEdits, modify, parse, printParseErrorCode } = require('jsonc-parser');
4
+
5
+ const WORKSPACE_CANDIDATES = ['/angular.json', '/workspace.json'];
6
+ const PACKAGE_JSON_CANDIDATES = ['/package.json', 'package.json'];
7
+ const HAPPY_DOM_VERSION = '^20.0.0';
8
+
9
+ const BUILDER_MIGRATIONS = Object.freeze({
10
+ '@angular/build:application': '@ngrs/build:application',
11
+ '@angular-devkit/build-angular:application': '@ngrs/build:application',
12
+ '@angular-devkit/build-angular:browser-esbuild': '@ngrs/build:browser-esbuild',
13
+ '@angular-devkit/build-angular:browser': '@ngrs/build:browser',
14
+ '@angular/build:dev-server': '@ngrs/build:dev-server',
15
+ '@angular-devkit/build-angular:dev-server': '@ngrs/build:dev-server',
16
+ '@angular/build:extract-i18n': '@ngrs/build:extract-i18n',
17
+ '@angular-devkit/build-angular:extract-i18n': '@ngrs/build:extract-i18n',
18
+ '@angular/build:unit-test': '@ngrs/build:unit-test',
19
+ });
20
+
21
+ /**
22
+ * Surgically updates builder strings in an `angular.json` / `workspace.json` JSONC document while
23
+ * preserving comments, formatting, and untouched keys.
24
+ *
25
+ * @param {string} rawText
26
+ * @param {{ project?: string }} [options]
27
+ * @returns {{ updatedText: string, changed: boolean, updates: Array<{ project: string, target: string, from: string, to: string }>, alreadyConfiguredCount: number }}
28
+ */
29
+ function migrateWorkspaceJsoncText(rawText, options = {}) {
30
+ const parseErrors = [];
31
+ const workspace = parse(rawText, parseErrors, { allowTrailingComma: true });
32
+ if (parseErrors.length > 0) {
33
+ const first = parseErrors[0];
34
+ throw new Error(
35
+ `Failed to parse Angular workspace configuration: ${printParseErrorCode(first.error)} at offset ${first.offset}.`,
36
+ );
37
+ }
38
+
39
+ const projects = workspace && typeof workspace === 'object' ? workspace.projects || {} : {};
40
+ const allProjectNames = Object.keys(projects);
41
+ if (allProjectNames.length === 0) {
42
+ throw new Error('No projects found in angular.json.');
43
+ }
44
+
45
+ let targetProjectNames = allProjectNames;
46
+ if (options.project) {
47
+ if (!projects[options.project]) {
48
+ throw new Error(
49
+ `Project "${options.project}" does not exist in angular.json. Available projects: ${allProjectNames.join(', ')}.`,
50
+ );
51
+ }
52
+ targetProjectNames = [options.project];
53
+ }
54
+
55
+ let updatedText = rawText;
56
+ const updates = [];
57
+ let alreadyConfiguredCount = 0;
58
+
59
+ for (const projName of targetProjectNames) {
60
+ const proj = projects[projName];
61
+ if (!proj || typeof proj !== 'object') {
62
+ continue;
63
+ }
64
+
65
+ for (const sectionKey of ['architect', 'targets']) {
66
+ const targetsObj = proj[sectionKey];
67
+ if (!targetsObj || typeof targetsObj !== 'object') {
68
+ continue;
69
+ }
70
+
71
+ for (const [targetName, targetDef] of Object.entries(targetsObj)) {
72
+ const currentBuilder = targetDef && targetDef.builder;
73
+ if (typeof currentBuilder !== 'string') {
74
+ continue;
75
+ }
76
+ if (currentBuilder.startsWith('@ngrs/build:')) {
77
+ alreadyConfiguredCount += 1;
78
+ continue;
79
+ }
80
+ const nextBuilder = BUILDER_MIGRATIONS[currentBuilder];
81
+ if (!nextBuilder) {
82
+ continue;
83
+ }
84
+
85
+ const edits = modify(
86
+ updatedText,
87
+ ['projects', projName, sectionKey, targetName, 'builder'],
88
+ nextBuilder,
89
+ { formattingOptions: { tabSize: 2, insertSpaces: true } },
90
+ );
91
+ updatedText = applyEdits(updatedText, edits);
92
+ updates.push({
93
+ project: projName,
94
+ target: targetName,
95
+ from: currentBuilder,
96
+ to: nextBuilder,
97
+ });
98
+ }
99
+ }
100
+ }
101
+
102
+ return {
103
+ updatedText,
104
+ changed: updates.length > 0 && updatedText !== rawText,
105
+ updates,
106
+ alreadyConfiguredCount,
107
+ };
108
+ }
109
+
110
+ /**
111
+ * Updates `package.json` to standardize unit test DOM environment on `happy-dom` (adding
112
+ * `"happy-dom"` to `devDependencies` if absent and removing legacy `"jsdom"` / `"@types/jsdom"`).
113
+ *
114
+ * @param {string} rawPkgText
115
+ * @returns {{ updatedText: string, changed: boolean, addedHappyDom: boolean, removedJsdom: boolean }}
116
+ */
117
+ function migratePackageJsonForHappyDom(rawPkgText) {
118
+ const parseErrors = [];
119
+ const pkg = parse(rawPkgText, parseErrors, { allowTrailingComma: true });
120
+ if (parseErrors.length > 0 || !pkg || typeof pkg !== 'object') {
121
+ return {
122
+ updatedText: rawPkgText,
123
+ changed: false,
124
+ addedHappyDom: false,
125
+ removedJsdom: false,
126
+ };
127
+ }
128
+
129
+ let updatedText = rawPkgText;
130
+ let removedJsdom = false;
131
+ let addedHappyDom = false;
132
+
133
+ for (const section of ['devDependencies', 'dependencies']) {
134
+ if (pkg[section] && typeof pkg[section] === 'object') {
135
+ for (const legacyPkg of ['jsdom', '@types/jsdom']) {
136
+ if (legacyPkg in pkg[section]) {
137
+ const edits = modify(updatedText, [section, legacyPkg], undefined, {
138
+ formattingOptions: { tabSize: 2, insertSpaces: true },
139
+ });
140
+ updatedText = applyEdits(updatedText, edits);
141
+ removedJsdom = true;
142
+ }
143
+ }
144
+ }
145
+ }
146
+
147
+ const hasHappyDom =
148
+ (pkg.devDependencies && 'happy-dom' in pkg.devDependencies) ||
149
+ (pkg.dependencies && 'happy-dom' in pkg.dependencies);
150
+
151
+ if (!hasHappyDom) {
152
+ const edits = modify(updatedText, ['devDependencies', 'happy-dom'], HAPPY_DOM_VERSION, {
153
+ formattingOptions: { tabSize: 2, insertSpaces: true },
154
+ });
155
+ updatedText = applyEdits(updatedText, edits);
156
+ addedHappyDom = true;
157
+ }
158
+
159
+ return {
160
+ updatedText,
161
+ changed: updatedText !== rawPkgText,
162
+ addedHappyDom,
163
+ removedJsdom,
164
+ };
165
+ }
166
+
167
+ /**
168
+ * Official Angular CLI `ng add @ngrs/build` Schematic Rule factory.
169
+ *
170
+ * @param {{ project?: string }} [options]
171
+ */
172
+ function ngAdd(options = {}) {
173
+ return (tree, context) => {
174
+ const workspacePath = WORKSPACE_CANDIDATES.find((candidate) => tree.exists(candidate));
175
+ if (!workspacePath) {
176
+ throw new Error(
177
+ 'Could not find an Angular workspace configuration file (angular.json or workspace.json).',
178
+ );
179
+ }
180
+
181
+ const buffer = tree.read(workspacePath);
182
+ if (!buffer) {
183
+ throw new Error(`Unable to read "${workspacePath}".`);
184
+ }
185
+
186
+ const rawText = buffer.toString('utf8');
187
+ const result = migrateWorkspaceJsoncText(rawText, options);
188
+
189
+ if (result.changed) {
190
+ tree.overwrite(workspacePath, result.updatedText);
191
+ for (const item of result.updates) {
192
+ context?.logger?.info?.(
193
+ `Configured ${item.project}:${item.target} builder (${item.from} -> ${item.to})`,
194
+ );
195
+ }
196
+ } else if (result.alreadyConfiguredCount > 0) {
197
+ context?.logger?.info?.('Workspace targets are already configured to use @ngrs/build.');
198
+ } else {
199
+ context?.logger?.warn?.(
200
+ 'No compatible Angular application build/serve targets were found to update.',
201
+ );
202
+ }
203
+
204
+ const pkgPath = PACKAGE_JSON_CANDIDATES.find((candidate) => tree.exists(candidate));
205
+ if (pkgPath) {
206
+ const pkgBuf = tree.read(pkgPath);
207
+ if (pkgBuf) {
208
+ const pkgRes = migratePackageJsonForHappyDom(pkgBuf.toString('utf8'));
209
+ if (pkgRes.changed) {
210
+ tree.overwrite(pkgPath, pkgRes.updatedText);
211
+ if (pkgRes.removedJsdom) {
212
+ context?.logger?.info?.('Removed legacy jsdom dependency from package.json');
213
+ }
214
+ if (pkgRes.addedHappyDom) {
215
+ context?.logger?.info?.(`Added happy-dom (${HAPPY_DOM_VERSION}) to devDependencies`);
216
+ }
217
+ }
218
+ }
219
+ }
220
+
221
+ return tree;
222
+ };
223
+ }
224
+
225
+ module.exports = ngAdd;
226
+ module.exports.default = ngAdd;
227
+ module.exports.ngAdd = ngAdd;
228
+ module.exports.BUILDER_MIGRATIONS = BUILDER_MIGRATIONS;
229
+ module.exports.HAPPY_DOM_VERSION = HAPPY_DOM_VERSION;
230
+ module.exports.migrateWorkspaceJsoncText = migrateWorkspaceJsoncText;
231
+ module.exports.migratePackageJsonForHappyDom = migratePackageJsonForHappyDom;
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "SchematicsNgrsBuildNgAdd",
4
+ "title": "@ngrs/build ng-add Options Schema",
5
+ "type": "object",
6
+ "description": "Configures an Angular workspace (angular.json) to use @ngrs/build for build, serve, and extract-i18n targets.",
7
+ "properties": {
8
+ "project": {
9
+ "type": "string",
10
+ "description": "Name of a specific project in angular.json to configure. Defaults to all compatible projects in the workspace."
11
+ }
12
+ },
13
+ "additionalProperties": false
14
+ }
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ const path = require('node:path');
4
+
5
+ const BuilderSymbol = Symbol.for('@angular-devkit/architect:builder');
6
+ const BuilderVersionSymbol = Symbol.for('@angular-devkit/architect:version');
7
+
8
+ function tryLoadRealArchitect() {
9
+ const candidates = [
10
+ () => {
11
+ const cwdReq = require('node:module').createRequire(
12
+ path.join(process.cwd(), 'package.json'),
13
+ );
14
+ return cwdReq('@angular-devkit/architect');
15
+ },
16
+ () => require('@angular-devkit/architect'),
17
+ ];
18
+ for (const load of candidates) {
19
+ try {
20
+ const mod = load();
21
+ if (mod && typeof mod.createBuilder === 'function') {
22
+ return mod;
23
+ }
24
+ } catch {
25
+ // Fallback to lightweight compat descriptor
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+
31
+ function createCjsBuilder(handlerFn) {
32
+ const realArchitect = tryLoadRealArchitect();
33
+ if (realArchitect) {
34
+ const wrapped = realArchitect.createBuilder(handlerFn);
35
+ wrapped.execute = handlerFn;
36
+ wrapped.default = wrapped;
37
+ return wrapped;
38
+ }
39
+
40
+ const compat = {
41
+ handler: handlerFn,
42
+ execute: handlerFn,
43
+ [BuilderSymbol]: true,
44
+ [BuilderVersionSymbol]: '0.1900.0',
45
+ };
46
+ compat.default = compat;
47
+ return compat;
48
+ }
49
+
50
+ module.exports = {
51
+ BuilderSymbol,
52
+ BuilderVersionSymbol,
53
+ createCjsBuilder,
54
+ };