@blotch/rsbuild-plugin-angular-lynx 22.2.0 → 22.2.2

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,72 @@
1
+ import type { Budget } from './options.js';
2
+ /**
3
+ * Checks angular.json `budgets` against a Lynx build's output.
4
+ *
5
+ * The size parsing, the thresholds and the messages are ported from
6
+ * `@angular/build`'s bundle calculator (`src/utils/bundle-calculator.js` and
7
+ * `src/utils/format-bytes.js`), so a Lynx app reports budgets exactly as
8
+ * `ng build` does for a web app: the same units (1 kB = 1000 bytes), the
9
+ * same baseline arithmetic and the same wording. It's copied because those
10
+ * modules are internal to `@angular/build`, not in its package `exports`.
11
+ *
12
+ * What each budget type measures differs from the web, because a Lynx app
13
+ * ships as `.bundle` files rather than separate scripts and stylesheets:
14
+ *
15
+ * - `initial`: each entry's bundle, on its own. A Lynx page loads one bundle,
16
+ * so a multi-page app's pages are checked separately rather than summed.
17
+ * - `bundle`: the bundle of the entry named by the budget's `name`.
18
+ * - `all` / `any`: every bundle and script the `lynx` environment emits,
19
+ * together / each. Media and fonts aren't counted, as on the web.
20
+ * - `allScript` / `anyScript`: the same files as `all` / `any`. A Lynx
21
+ * bundle carries the app's scripts (and its styles, encoded together), so
22
+ * there is no script-only file to measure.
23
+ * - `anyComponentStyle`: each component stylesheet, compiled.
24
+ */
25
+ /** Angular's unit for `kB`, `MB` and `GB`: decimal, not 1024. */
26
+ export declare const BYTES_IN_KILOBYTE = 1000;
27
+ export type BudgetSeverity = 'warning' | 'error';
28
+ export type BudgetThreshold = {
29
+ readonly limit: number;
30
+ readonly type: 'maximum' | 'minimum';
31
+ readonly severity: BudgetSeverity;
32
+ };
33
+ export type BudgetFailure = {
34
+ readonly severity: BudgetSeverity;
35
+ readonly label: string;
36
+ readonly message: string;
37
+ };
38
+ /** A file the `lynx` environment emits that budgets count. */
39
+ export type BudgetAsset = {
40
+ readonly name: string;
41
+ readonly size: number;
42
+ /** Set for an entry's own bundle: the entry (page) it was built from. */
43
+ readonly entryName?: string;
44
+ };
45
+ /** The compiled size of one component stylesheet. */
46
+ export type ComponentStyleSize = {
47
+ /** The stylesheet, or for inline styles the component, relative to the workspace. */
48
+ readonly label: string;
49
+ readonly size: number;
50
+ };
51
+ /**
52
+ * Parses a budget size (`'500kB'`, `'1.5mb'`, `'2048'`, `'10%'`) into bytes.
53
+ * A percentage is of `baseline`; with a baseline, the result is the baseline
54
+ * moved by the value, up (`factor` 1) or down (`factor` -1). Input it
55
+ * can't parse gives NaN, which no size crosses, as in Angular.
56
+ */
57
+ export declare const calculateBytes: (input: string, baseline?: string, factor?: 1 | -1) => number;
58
+ /**
59
+ * The limits a budget sets, in the order Angular checks them. `warning` and
60
+ * `error` are relative to the baseline in both directions, so each gives a
61
+ * minimum and a maximum.
62
+ */
63
+ export declare const calculateThresholds: (budget: Budget) => BudgetThreshold[];
64
+ /** Formats a byte count the way `ng build`'s budget messages do: `1.23 kB`. */
65
+ export declare const formatSize: (size: number) => string;
66
+ /** The failures of one measured size against a budget's thresholds. */
67
+ export declare const checkThresholds: (thresholds: readonly BudgetThreshold[], size: number, label: string) => BudgetFailure[];
68
+ /** Checks every budget against a build's output. */
69
+ export declare const checkBudgets: (budgets: readonly Budget[], output: {
70
+ readonly assets: readonly BudgetAsset[];
71
+ readonly componentStyles: readonly ComponentStyleSize[];
72
+ }) => BudgetFailure[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import type * as AngularCompilationModule from '@angular/build/src/tools/angular/compilation';
2
+ import type * as ComponentStylesheetsModule from '@angular/build/src/tools/esbuild/angular/component-stylesheets';
3
+ import type * as JavaScriptTransformerModule from '@angular/build/src/tools/javascript-transformer';
4
+ /** Absolute path of the installed `@angular/build` package root. */
5
+ export declare const angularBuildRoot: string;
6
+ /**
7
+ * Loads a module from inside `@angular/build` by its path relative to the
8
+ * package root, bypassing the `exports` map.
9
+ */
10
+ export declare const loadAngularBuildInternal: <T>(subpath: string) => T;
11
+ export declare const createAngularCompilation: typeof AngularCompilationModule.createAngularCompilation, DiagnosticModes: typeof AngularCompilationModule.DiagnosticModes;
12
+ export declare const JavaScriptTransformer: typeof JavaScriptTransformerModule.JavaScriptTransformer;
13
+ export declare const ComponentStylesheetBundler: typeof ComponentStylesheetsModule.ComponentStylesheetBundler;
14
+ export type ComponentStylesheetBundler = ComponentStylesheetsModule.ComponentStylesheetBundler;
@@ -1,4 +1,4 @@
1
- import { ComponentStylesheetBundler } from '@angular/build/src/tools/esbuild/angular/component-stylesheets';
1
+ import { ComponentStylesheetBundler } from './build-internals.js';
2
2
  import type { NormalizedOptions } from './options.js';
3
3
  /**
4
4
  * Creates an Angular `ComponentStylesheetBundler` configured for the current workspace.
@@ -1,4 +1,3 @@
1
- import type { OutputHashing } from '@angular-devkit/build-angular';
2
1
  import type { workspaces } from '@angular-devkit/core';
3
2
  import type { TargetDefinition } from '@angular-devkit/core/src/workspace/definitions';
4
3
  import { type NormalizedCachedOptions } from './normalize-cache.js';
@@ -40,6 +39,53 @@ export type NormalizedI18nOptions = {
40
39
  sourceLocale: string;
41
40
  hasDefinedSourceLocale: boolean;
42
41
  };
42
+ /**
43
+ * The values of angular.json's `outputHashing` build option: which emitted
44
+ * file names get a content hash.
45
+ *
46
+ * Copied from the `OutputHashing` enum that Angular's builder schemas
47
+ * generate, as a string union because angular.json holds plain strings.
48
+ * Keep it in step with them when Angular adds a value.
49
+ *
50
+ * It used to be imported from `@angular-devkit/build-angular`, which made
51
+ * that package a peer dependency of this plugin. That package is Angular's
52
+ * legacy webpack-based builder: apps from a current `ng new` don't have it,
53
+ * and npm installs missing peer dependencies, so every AngularLynx app got it
54
+ * and its webpack toolchain (about 300 packages) for this one type.
55
+ *
56
+ * @see `OutputHashing` in `@angular/build/src/builders/application/schema.d.ts`
57
+ * @see `OutputHashing` in `@angular-devkit/build-angular/src/builders/browser/schema.d.ts`
58
+ */
59
+ export type OutputHashing = 'all' | 'bundles' | 'media' | 'none';
60
+ /**
61
+ * One entry of angular.json's `budgets` build option: a size limit on part
62
+ * of the build output, which `ng build` reports as a warning or an error
63
+ * when the output crosses it. See budgets.ts for what each `type` measures
64
+ * in a Lynx build.
65
+ *
66
+ * Copied from the `Budget` type (and its `Type` enum, as a string union) that
67
+ * Angular's application builder schema generates, for the same reason as
68
+ * {@link OutputHashing}: importing it would make an Angular builder package a
69
+ * dependency of this plugin for one type. Keep it in step with Angular's
70
+ * schema when Angular adds a field or a budget type.
71
+ *
72
+ * @see `Budget` in `@angular/build/src/builders/application/schema.d.ts`
73
+ */
74
+ export type Budget = {
75
+ readonly type: 'all' | 'allScript' | 'any' | 'anyComponentStyle' | 'anyScript' | 'bundle' | 'initial';
76
+ /** The bundle a `bundle` budget measures: an entry name. */
77
+ readonly name?: string;
78
+ /** The size that the relative thresholds below are relative to. */
79
+ readonly baseline?: string;
80
+ readonly maximumWarning?: string;
81
+ readonly maximumError?: string;
82
+ readonly minimumWarning?: string;
83
+ readonly minimumError?: string;
84
+ /** A threshold in both directions from `baseline`. */
85
+ readonly warning?: string;
86
+ /** A threshold in both directions from `baseline`. */
87
+ readonly error?: string;
88
+ };
43
89
  export type NormalizedOptions = {
44
90
  tsconfig: string;
45
91
  aot: boolean;
@@ -56,7 +102,7 @@ export type NormalizedOptions = {
56
102
  };
57
103
  fileReplacements: Record<string, string> | undefined;
58
104
  polyfills?: string[];
59
- index: string;
105
+ index: string | undefined;
60
106
  browser: string;
61
107
  advancedOptimizations: boolean;
62
108
  outputPath: string | undefined;
@@ -71,9 +117,41 @@ export type NormalizedOptions = {
71
117
  styles: string[];
72
118
  i18n: NormalizedI18nOptions;
73
119
  i18nMissingTranslation: 'error' | 'warning' | 'ignore';
120
+ budgets: readonly Budget[];
74
121
  };
75
122
  export declare const readTarget: (project: workspaces.ProjectDefinition, target?: string) => TargetDefinition | undefined;
123
+ /**
124
+ * Resolves angular.json's `index` option to an absolute path the way
125
+ * `@angular/build`'s application builder does. Projects from recent `ng new`
126
+ * omit it and rely on the builder's default of `<sourceRoot>/index.html`, so
127
+ * assuming a string here crashed on every freshly generated app. It may also be
128
+ * an `{ input, output }` object, or a boolean to build without an index page.
129
+ */
130
+ export declare const resolveIndexPath: (index: unknown, project: workspaces.ProjectDefinition, workspaceRoot: string) => string | undefined;
131
+ /**
132
+ * Resolves angular.json's `outputPath`, which may be a string or a
133
+ * `{ base, browser, ... }` object. Recent `ng new` omits it; returning
134
+ * `undefined` then keeps rspeedy's own `dist` directory (see
135
+ * `applyAngularConfig`) rather than crashing on `path.join(root, undefined)`.
136
+ */
137
+ export declare const resolveOutputPath: (outputPath: unknown, workspaceRoot: string) => string | undefined;
138
+ /**
139
+ * Reads the build target's options from angular.json, merged the way Angular
140
+ * CLI merges them: the selected configuration's keys (by default the
141
+ * target's `defaultConfiguration`) over the base options, leaving the keys it
142
+ * doesn't mention at their base values.
143
+ *
144
+ * Only for plain rspeedy runs. Under `ng build` / `ng serve`, Angular CLI has
145
+ * already merged them, `-c` and command-line overrides included, and the
146
+ * builders pass them in (see angular-cli-context.ts).
147
+ */
148
+ export declare const readBuildTargetOptions: (project: workspaces.ProjectDefinition, configurationName?: string) => Record<string, unknown>;
76
149
  export declare const readBuildOptions: (project: workspaces.ProjectDefinition, basePath: string, configurationName?: string) => Promise<NormalizedOptions>;
150
+ /**
151
+ * Turns a build target's options into the shape the compile pipeline uses:
152
+ * absolute paths, and the expanded forms of Angular's shorthand options.
153
+ */
154
+ export declare const normalizeBuildOptions: (buildOptions: Readonly<Record<string, unknown>>, project: workspaces.ProjectDefinition, basePath: string) => Promise<NormalizedOptions>;
77
155
  /**
78
156
  * Normalizes the `i18n` section from angular.json's project definition.
79
157
  * Angular supports `sourceLocale` as either a string ('en-US') or an object
@@ -3,5 +3,9 @@ export type AngularWorkspace = {
3
3
  workspace: workspaces.WorkspaceDefinition;
4
4
  basePath: string;
5
5
  };
6
- export declare const getAngularWorkspace: () => Promise<AngularWorkspace>;
6
+ /**
7
+ * Reads the angular.json found by searching up from `from`: the workspace
8
+ * root Angular CLI passed in, or the working directory under plain rspeedy.
9
+ */
10
+ export declare const getAngularWorkspace: (from?: string) => Promise<AngularWorkspace>;
7
11
  export declare const getProjectByCwd: (workspace: workspaces.WorkspaceDefinition, basePath: string) => string | null;
@@ -0,0 +1,26 @@
1
+ import type { workspaces } from '@angular-devkit/core';
2
+ import type { AngularCliContext } from '../../angular-cli-context.js';
3
+ import { type NormalizedOptions } from './options.js';
4
+ /**
5
+ * Picks the project whose build target configures the compile (tsconfig,
6
+ * polyfills, global styles, output path), and normalizes its options.
7
+ *
8
+ * The project is the one Angular CLI is building, when there is one: one of
9
+ * the `pages` if the plugin builds several, otherwise any. Without Angular
10
+ * CLI it is the first of the `pages`, or the project the working directory
11
+ * is in.
12
+ *
13
+ * The options are the ones Angular CLI resolved for that project (with `-c`
14
+ * and command-line overrides applied) when it is the one being built, and
15
+ * otherwise the target's options in angular.json under its default
16
+ * configuration.
17
+ */
18
+ export declare const resolvePrimaryBuild: ({ workspace, basePath, pages, cli, }: {
19
+ workspace: workspaces.WorkspaceDefinition;
20
+ basePath: string;
21
+ pages: string[] | "all" | undefined;
22
+ cli: AngularCliContext | undefined;
23
+ }) => Promise<{
24
+ projectName: string;
25
+ buildOptions: NormalizedOptions;
26
+ }>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotch/rsbuild-plugin-angular-lynx",
3
- "version": "22.2.0",
3
+ "version": "22.2.2",
4
4
  "description": "Rsbuild plugin for building AngularLynx applications",
5
5
  "homepage": "https://github.com/Blotch-Smart-Frames/AngularLynx#readme",
6
6
  "bugs": {
@@ -13,8 +13,7 @@
13
13
  "directory": "packages/rsbuild-plugin-angular-lynx"
14
14
  },
15
15
  "files": [
16
- "dist",
17
- "patch"
16
+ "dist"
18
17
  ],
19
18
  "type": "module",
20
19
  "module": "./dist/index.js",
@@ -23,7 +22,8 @@
23
22
  ".": {
24
23
  "types": "./dist/index.d.ts",
25
24
  "import": "./dist/index.js"
26
- }
25
+ },
26
+ "./package.json": "./package.json"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "rslib build",
@@ -37,7 +37,6 @@
37
37
  "format": "oxfmt --write .",
38
38
  "format:check": "oxfmt --check .",
39
39
  "cspell": "cspell .",
40
- "postinstall": "node ./patch/patch-angular-build.cjs",
41
40
  "publish:local": "yalc publish --push"
42
41
  },
43
42
  "dependencies": {
@@ -50,7 +49,6 @@
50
49
  "tiny-invariant": "^1.3.3"
51
50
  },
52
51
  "devDependencies": {
53
- "@angular-devkit/build-angular": "^22.2.2",
54
52
  "@angular-devkit/core": "^22.2.2",
55
53
  "@angular/build": "^22.2.2",
56
54
  "@rsbuild/core": "^2.2.9",
@@ -61,7 +59,6 @@
61
59
  "typescript": "^6.0.3"
62
60
  },
63
61
  "peerDependencies": {
64
- "@angular-devkit/build-angular": "^22.2.0",
65
62
  "@angular-devkit/core": "^22.2.0",
66
63
  "@angular/build": "^22.2.0",
67
64
  "@angular/localize": "^22.2.0",
@@ -71,5 +68,14 @@
71
68
  "@angular/localize": {
72
69
  "optional": true
73
70
  }
71
+ },
72
+ "ng-update": {
73
+ "packageGroup": [
74
+ "@blotch/angular-lynx",
75
+ "@blotch/angular-lynx-build",
76
+ "@blotch/angular-lynx-testing-library",
77
+ "@blotch/rsbuild-plugin-angular-lynx",
78
+ "@blotch/angular-lynx-native"
79
+ ]
74
80
  }
75
81
  }
@@ -1,27 +0,0 @@
1
- const { readFileSync, writeFileSync } = require('node:fs');
2
-
3
- const main = () => {
4
- const angularBuildPackageJson =
5
- require.resolve('@angular/build/package.json');
6
- const fileContentsJson = JSON.parse(
7
- readFileSync(angularBuildPackageJson, 'utf8'),
8
- );
9
- // Angular 22.2 moved the transformer out of `src/tools/esbuild/`.
10
- fileContentsJson.exports['./src/tools/javascript-transformer'] =
11
- './src/tools/javascript-transformer/index.js';
12
- fileContentsJson.exports['./src/tools/angular/compilation'] =
13
- './src/tools/angular/compilation/index.js';
14
- fileContentsJson.exports[
15
- './src/tools/esbuild/angular/file-reference-tracker'
16
- ] = './src/tools/esbuild/angular/file-reference-tracker.js';
17
- fileContentsJson.exports[
18
- './src/tools/esbuild/angular/component-stylesheets'
19
- ] = './src/tools/esbuild/angular/component-stylesheets.js';
20
-
21
- writeFileSync(
22
- angularBuildPackageJson,
23
- JSON.stringify(fileContentsJson, null, 2),
24
- );
25
- };
26
-
27
- main();