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

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.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/dist/544.js +21 -0
  3. package/dist/angular-rebuild-coordinator.d.ts +1 -1
  4. package/dist/angular.d.ts +3 -2
  5. package/dist/background-entry.d.ts +96 -0
  6. package/dist/client/background-hot-updates.d.ts +50 -0
  7. package/dist/client/background-hot-updates.js +77 -0
  8. package/dist/client/background-hot-updates.test.d.ts +1 -0
  9. package/dist/client/css-hot-update.cjs +9 -0
  10. package/dist/client/css-hot-update.d.ts +44 -0
  11. package/dist/client/css-hot-update.js +42 -0
  12. package/dist/client/css-hot-update.test.d.ts +1 -0
  13. package/dist/client/hmr-background.js +16 -0
  14. package/dist/client/hmr-main-thread.js +9 -0
  15. package/dist/client/hmr-protocol.d.ts +74 -0
  16. package/dist/client/main-thread-hot-updates.d.ts +40 -0
  17. package/dist/client/main-thread-hot-updates.js +78 -0
  18. package/dist/client/main-thread-hot-updates.test.d.ts +1 -0
  19. package/dist/client/testing/test-context.d.ts +16 -0
  20. package/dist/component-styles-cache.d.ts +5 -35
  21. package/dist/component-styles.d.ts +73 -0
  22. package/dist/component-styles.test.d.ts +1 -0
  23. package/dist/cross-thread-transform.d.ts +38 -0
  24. package/dist/cross-thread-transform.test.d.ts +1 -0
  25. package/dist/css.d.ts +2 -2
  26. package/dist/entry.d.ts +23 -2
  27. package/dist/hot-updates.d.ts +67 -0
  28. package/dist/hot-updates.test.d.ts +1 -0
  29. package/dist/index.js +718 -168
  30. package/dist/layers.d.ts +6 -4
  31. package/dist/logger/dev-logger-middleware.d.ts +13 -7
  32. package/dist/logger/dev-logger.d.ts +13 -0
  33. package/dist/polyfills.js +56 -0
  34. package/dist/polyfills.test.d.ts +1 -0
  35. package/dist/pure-classes.d.ts +27 -0
  36. package/dist/pure-classes.test.d.ts +1 -0
  37. package/dist/resolve.d.ts +19 -0
  38. package/dist/resolve.test.d.ts +1 -0
  39. package/dist/split-chunks.d.ts +2 -2
  40. package/dist/styles/blur-view.css +16 -0
  41. package/dist/transform-module.d.ts +43 -17
  42. package/dist/utils/angular/component-scope-id.d.ts +5 -3
  43. package/dist/utils/options.d.ts +40 -1
  44. package/package.json +1 -2
  45. package/dist/loaders/thread-globals-loader.d.ts +0 -8
  46. package/dist/loaders/thread-globals-loader.js +0 -6
  47. /package/dist/{loaders/thread-globals-loader.test.d.ts → background-entry.test.d.ts} +0 -0
@@ -1,20 +1,4 @@
1
1
  import type { ComponentStyleSize } from './utils/angular/budgets.js';
2
- /**
3
- * Per-component stylesheet bookkeeping. `imports` lists the on-disk scoped CSS
4
- * paths the loader will prepend as `import` statements; `inlineStyles` mirrors
5
- * Angular's inline-style handling surface; `processedFiles` deduplicates calls
6
- * that Angular's AOT compiler makes multiple times for the same stylesheet.
7
- */
8
- export type ComponentStylesEntry = {
9
- imports: string[];
10
- inlineStyles: string[];
11
- scopeId: string;
12
- processedFiles: Map<string, string>;
13
- };
14
- export type ComponentScopeInfo = {
15
- className: string;
16
- scopeId: string;
17
- };
18
2
  /**
19
3
  * Drops the recorded stylesheet sizes of a component whose file was deleted,
20
4
  * so `anyComponentStyle` budgets stop reporting styles that no longer ship.
@@ -24,28 +8,14 @@ export declare const forgetComponentStyleSizes: (componentStyleSizes: Map<string
24
8
  * Builds the `transformStylesheet` callback that Angular's AOT compiler invokes
25
9
  * for every component stylesheet (inline `styles: []` and external `styleUrls`).
26
10
  *
27
- * The callback is a closure over the two shared caches the loader
28
- * (`api.transform` in angular.ts) later reads from:
29
- * - `componentStylesCache` — maps component source file → its scoped CSS imports
30
- * - `componentScopeIds` — maps component source file → { className, scopeId }
31
- *
32
- * Extracted from angular.ts so the dedup / scoped-path / write-if-changed logic
33
- * can be unit-tested directly by driving the returned callback, without standing
34
- * up a full Angular compilation.
11
+ * It returns the CSS unchanged, so the compiler embeds it in the component's
12
+ * definition and scopes it for the component's `encapsulation`, as on the web.
13
+ * extractComponentStyles() (component-styles.ts) then lifts it back out of the
14
+ * compiled code as Lynx CSS. The callback only records each stylesheet's size,
15
+ * for `anyComponentStyle` budgets.
35
16
  */
36
17
  export declare const createTransformStylesheet: (params: {
37
18
  basePath: string;
38
- scopedCssCacheDir: string;
39
- componentStylesCache: Map<string, ComponentStylesEntry>;
40
- componentScopeIds: Map<string, ComponentScopeInfo>;
41
- /**
42
- * Called with the path of each scoped CSS file whose contents were
43
- * (re)written. On watch rebuilds the scoped files change after rspack's
44
- * watcher has already collected the edit, so angular.ts passes them to
45
- * rspack as modified. Otherwise the CSS change would only ship on the
46
- * following rebuild.
47
- */
48
- onStylesheetWritten?: (filePath: string) => void;
49
19
  /**
50
20
  * The compiled size of every component stylesheet, for `anyComponentStyle`
51
21
  * budgets. Overwritten each time Angular compiles a stylesheet, so watch
@@ -0,0 +1,73 @@
1
+ import type { ModuleStylesheets } from './transform-module.js';
2
+ /**
3
+ * One component's styles, lifted out of its compiled definition.
4
+ */
5
+ export type ExtractedComponentStyles = {
6
+ className: string;
7
+ /**
8
+ * The ID the runtime builds the scope classes from. Only Emulated components
9
+ * need one, so it's `undefined` for the others.
10
+ */
11
+ scopeId: string | undefined;
12
+ /** The stylesheets, ready to be written as CSS files. */
13
+ stylesheets: string[];
14
+ };
15
+ export type ExtractComponentStylesResult = {
16
+ /** The module's code, without the `styles` the stylesheets came from. */
17
+ code: string;
18
+ components: ExtractedComponentStyles[];
19
+ };
20
+ /**
21
+ * Turns Angular's emulated-encapsulation CSS into CSS that Lynx can match.
22
+ *
23
+ * Angular's compiler scopes an Emulated component's styles with attribute
24
+ * selectors: `.title` becomes `.title[_ngcontent-%COMP%]`, `:host` becomes
25
+ * `[_nghost-%COMP%]`, and keyframe names gain a `_ngcontent-%COMP%_` prefix. On
26
+ * the web, the renderer puts those attributes on the elements. Lynx's selector
27
+ * matcher has no attribute selectors (`SelectorMatcher::MatchSimple` in Lynx
28
+ * core's css/ng/matcher only handles tag, class, id and pseudo-classes), so the
29
+ * attributes become classes here, and EmulatedLynxRenderer adds the same
30
+ * classes to the elements.
31
+ */
32
+ export declare const toLynxScopedCss: (css: string, scopeId: string) => string;
33
+ /**
34
+ * Fills the CSS variable namespace placeholder Angular's compiler puts in every
35
+ * component's styles: `var(--muted)` compiles to `var(--%NS%muted)`. Angular's
36
+ * renderer fills it with `CSS_VAR_NAMESPACE`, which is empty unless an app
37
+ * opts in with `provideCssVarNamespacing()`. Lynx CSS is compiled ahead of
38
+ * time, so it gets the default here, and the variables keep their own names,
39
+ * which global stylesheets such as the theme define.
40
+ */
41
+ export declare const fillCssVarNamespace: (css: string) => string;
42
+ /**
43
+ * Lifts each component's `styles` out of Angular's compiled output, so they
44
+ * can ship as Lynx CSS.
45
+ *
46
+ * Lynx can't add styles at runtime: CSS has to be compiled into the bundle.
47
+ * So the plugin lets Angular's compiler embed every component's styles in its
48
+ * definition, exactly as on the web (scoped for `ViewEncapsulation.Emulated`,
49
+ * left global for `None` and `ShadowDom`), then takes them back out here. That
50
+ * keeps each component's styles with its own encapsulation, even when two
51
+ * components share a stylesheet file, and removes the CSS strings from the
52
+ * JavaScript.
53
+ *
54
+ * Only `styles` arrays made of string literals are taken, which is what the
55
+ * compiler emits. Anything else is left in place.
56
+ */
57
+ export declare const extractComponentStyles: (code: string, fileName: string) => ExtractComponentStylesResult;
58
+ /**
59
+ * Writes the stylesheets extracted from one module as CSS files, so the
60
+ * module can import them and css-extract compiles them into the bundle.
61
+ *
62
+ * A file is only rewritten when its content changed, and each rewrite is
63
+ * reported through `onWritten`: on a watch rebuild the files change after
64
+ * rspack's watcher collected the edit, so the plugin reports them to rspack as
65
+ * changed, or the new CSS would only ship on the following rebuild.
66
+ */
67
+ export declare const writeModuleStylesheets: (params: {
68
+ basePath: string;
69
+ cacheDir: string;
70
+ fileName: string;
71
+ components: readonly ExtractedComponentStyles[];
72
+ onWritten?: (filePath: string) => void;
73
+ }) => ModuleStylesheets | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ export type CrossThreadTransformOptions = {
2
+ /** The directory the file keys are relative to, the same for both bundles. */
3
+ root: string;
4
+ };
5
+ /**
6
+ * Gives each module-level `backgroundFn(fn)`, `createMainThreadRef(value)` and
7
+ * `new MainThreadRef(value)` one more argument: an ID from the file and the
8
+ * call's position, such as `'3f9a1c2b7d:0'`.
9
+ *
10
+ * Angular runs on the main thread only, but the background thread runs the
11
+ * modules that make these calls too (see background-entry.ts), for the
12
+ * functions that main-thread code calls there. The main thread sends a handle
13
+ * or ref across by this ID, and the other thread finds its own copy by it.
14
+ * The runtime's fallback is a counter, which only matches if both threads run
15
+ * the same calls in the same order. They don't: the background thread runs
16
+ * only some of the app's modules, and in a different order, and Angular code
17
+ * (which also creates refs) runs on the main thread only.
18
+ *
19
+ * Calls inside a function or class are left alone, since one call site can run
20
+ * any number of times there.
21
+ *
22
+ * @param code - The module's JavaScript.
23
+ * @param filename - The module's path.
24
+ * @param options - See {@link CrossThreadTransformOptions}.
25
+ * @returns The transformed code, or `code` itself when nothing applies.
26
+ */
27
+ export declare const transformCrossThread: (code: string, filename: string, options: CrossThreadTransformOptions) => string;
28
+ /**
29
+ * Whether the module calls `backgroundFn()`, `createMainThreadRef()` or
30
+ * `new MainThreadRef()` at module level, so the background thread has to run
31
+ * it too. These are the calls {@link transformCrossThread} tags.
32
+ *
33
+ * @param code - The module's JavaScript.
34
+ * @param filename - The module's path.
35
+ * @returns `true` when the module defines a value the main thread can send
36
+ * across by ID.
37
+ */
38
+ export declare const definesCrossThreadValues: (code: string, filename: string) => boolean;
@@ -0,0 +1 @@
1
+ export {};
package/dist/css.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { RsbuildPluginAPI } from '@lynx-js/rspeedy';
2
2
  import type { CSSLoaderOptions } from '@rsbuild/core';
3
- import type { PluginAngularLynxOptions } from './utils/options.js';
4
- export declare const applyCSS: (api: RsbuildPluginAPI, options: Required<PluginAngularLynxOptions>) => void;
3
+ import type { NormalizedPluginAngularLynxOptions } from './utils/options.js';
4
+ export declare const applyCSS: (api: RsbuildPluginAPI, options: NormalizedPluginAngularLynxOptions) => void;
5
5
  /**
6
6
  * This is copied from https://github.com/web-infra-dev/rsbuild/blob/9f8be2d71ffeb7da969cda36fd9755db2cadaff5/packages/core/src/plugins/css.ts#L42
7
7
  *
package/dist/entry.d.ts CHANGED
@@ -1,12 +1,33 @@
1
1
  import type { RsbuildPluginAPI, Rspack } from '@lynx-js/rspeedy';
2
2
  import type { UndefinedOnPartialDeep } from 'type-fest';
3
- import type { PluginAngularLynxOptions } from './utils/options.js';
3
+ import type { BackgroundEntries } from './background-entry.js';
4
+ import type { NormalizedPluginAngularLynxOptions } from './utils/options.js';
4
5
  /**
5
6
  * The key `pluginLynx` (the Lynx build engine, which Rspeedy registers) exposes
6
7
  * its resolved config under. Mirrors `S_LYNX_CONFIG` in React Lynx's plugin.
7
8
  */
8
9
  export declare const S_LYNX_CONFIG: unique symbol;
9
- export declare const applyEntry: (api: RsbuildPluginAPI, options: Required<PluginAngularLynxOptions>) => void;
10
+ /**
11
+ * The `blur-view` rule that approximates iOS's blur materials on Android,
12
+ * from variables the runtime sets (see the file). Only the native bundle gets
13
+ * it: web draws the materials itself, in the element's shadow root, and an
14
+ * app-level rule there would beat them. It goes before every other import, so
15
+ * the app's own stylesheets come later and win a tie.
16
+ */
17
+ export declare const BLUR_VIEW_STYLESHEET: string;
18
+ /**
19
+ * The hot update clients (see client/). The background one stands in for
20
+ * `@rspack/core/hot/dev-server`; the main-thread one gives the main thread its
21
+ * own hot updates. Together they apply each update on both threads, or reload.
22
+ */
23
+ export declare const HMR_BACKGROUND_CLIENT: string;
24
+ export declare const HMR_MAIN_THREAD_CLIENT: string;
25
+ /**
26
+ * Applies stylesheet edits on the main thread, in place of css-extract's
27
+ * `runtime/hotModuleReplacement.cjs` (see client/css-hot-update.ts).
28
+ */
29
+ export declare const CSS_HOT_UPDATE: string;
30
+ export declare const applyEntry: (api: RsbuildPluginAPI, options: NormalizedPluginAngularLynxOptions, backgroundEntries: BackgroundEntries, appEntries: Set<string>) => void;
10
31
  /**
11
32
  * This is copied from https://github.com/web-infra-dev/rsbuild/blob/037da7b9d92e20c7136c8b2efa21eef539fa2f88/packages/core/src/plugins/html.ts#L168
12
33
  */
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Whether a build environment takes hot updates, under the same conditions
3
+ * entry.ts adds the hot update clients: a development build of a Lynx
4
+ * environment (the web preview has none) without `dev.hmr: false`.
5
+ *
6
+ * @param environment - The environment, as Rsbuild passes it to a transform.
7
+ * @returns Whether modules should take hot updates.
8
+ */
9
+ export declare const hotUpdatesEnabled: (environment: {
10
+ name: string;
11
+ config: {
12
+ mode?: string;
13
+ dev?: {
14
+ hmr?: boolean;
15
+ };
16
+ };
17
+ }) => boolean;
18
+ /**
19
+ * Hashes a component file's source without its components' templates and
20
+ * styles. Two versions of a file with the same signature differ only in what
21
+ * a hot update can apply in place (see `ɵhmrAccept` in the runtime). An
22
+ * external template or stylesheet isn't in the source at all, so editing one
23
+ * leaves the signature as it was.
24
+ *
25
+ * @param source - The file's TypeScript source.
26
+ * @param fileName - The file's path, for the parser.
27
+ * @returns The signature.
28
+ */
29
+ export declare const hotUpdateSignature: (source: string, fileName: string) => string;
30
+ /**
31
+ * Finds the components a module's compiled code defines, as the names of
32
+ * their classes. Only classes declared at the top of the module are listed,
33
+ * because the code {@link addHotAccept} appends assigns to them there.
34
+ *
35
+ * @param code - The module's code, as Angular's compiler emitted it.
36
+ * @param fileName - The module's path, for the parser.
37
+ * @returns The class names, in the order the module defines them.
38
+ */
39
+ export declare const componentClassNames: (code: string, fileName: string) => string[];
40
+ /**
41
+ * Makes a module that defines components take its own hot updates, through
42
+ * the runtime's `ɵhmrAccept`. The call reassigns the module's component
43
+ * classes to what it returns, so after an in-place update the module's
44
+ * exports are the classes the running app already uses.
45
+ *
46
+ * @param code - The module's code.
47
+ * @param options.components - The names of the module's component classes.
48
+ * @param options.signature - The source's {@link hotUpdateSignature}.
49
+ * @param options.compiled - The code Angular's compiler emitted for the
50
+ * module, before the plugin's other transforms.
51
+ * @returns The code with the call appended.
52
+ */
53
+ export declare const addHotAccept: (code: string, { components, signature, compiled, }: {
54
+ components: string[];
55
+ signature: string;
56
+ compiled: string;
57
+ }) => string;
58
+ /**
59
+ * Makes the app's entry module take every hot update its imports pass on.
60
+ * Re-running the entry calls `bootstrapApplication()` again, which replaces
61
+ * the running app with one built from the updated modules (on the main
62
+ * thread; the background thread runs no app).
63
+ *
64
+ * @param code - The entry module's code.
65
+ * @returns The code with the self-accept appended.
66
+ */
67
+ export declare const addEntryHotAccept: (code: string) => string;
@@ -0,0 +1 @@
1
+ export {};