@analogjs/vite-plugin-angular 3.0.0-beta.45 → 3.0.0-beta.47

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/ngp/build.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "revision": "457071571225970890bd5a6baee21373d3960c37",
2
+ "revision": "943ec3bd8d609212d200158eedc8a513466a8368",
3
3
  "wasmBindgen": "0.2.121"
4
4
  }
@@ -50,7 +50,52 @@ class WasmAnalyzer {
50
50
  return ret[0] >>> 0;
51
51
  }
52
52
  /**
53
- * Releases the stream `id` when its consumer stops reading before it ends.
53
+ * @param {string} paths_json
54
+ * @returns {string}
55
+ */
56
+ canonical_paths(paths_json) {
57
+ let deferred3_0;
58
+ let deferred3_1;
59
+ try {
60
+ const ptr0 = passStringToWasm0(paths_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
61
+ const len0 = WASM_VECTOR_LEN;
62
+ const ret = wasm.wasmanalyzer_canonical_paths(this.__wbg_ptr, ptr0, len0);
63
+ var ptr2 = ret[0];
64
+ var len2 = ret[1];
65
+ if (ret[3]) {
66
+ ptr2 = 0; len2 = 0;
67
+ throw takeFromExternrefTable0(ret[2]);
68
+ }
69
+ deferred3_0 = ptr2;
70
+ deferred3_1 = len2;
71
+ return getStringFromWasm0(ptr2, len2);
72
+ } finally {
73
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
74
+ }
75
+ }
76
+ /**
77
+ * @returns {string}
78
+ */
79
+ clear_resolution_cache() {
80
+ let deferred2_0;
81
+ let deferred2_1;
82
+ try {
83
+ const ret = wasm.wasmanalyzer_clear_resolution_cache(this.__wbg_ptr);
84
+ var ptr1 = ret[0];
85
+ var len1 = ret[1];
86
+ if (ret[3]) {
87
+ ptr1 = 0; len1 = 0;
88
+ throw takeFromExternrefTable0(ret[2]);
89
+ }
90
+ deferred2_0 = ptr1;
91
+ deferred2_1 = len1;
92
+ return getStringFromWasm0(ptr1, len1);
93
+ } finally {
94
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
95
+ }
96
+ }
97
+ /**
98
+ * Releases the stream or metadata request `id` when its consumer stops reading before it ends.
54
99
  *
55
100
  * Dropping the receiver closes the channel. The engine's sends to a closed channel
56
101
  * are ignored, so the analysis is no longer observed but is not cancelled. The NAPI
@@ -61,6 +106,21 @@ class WasmAnalyzer {
61
106
  close_stream(id) {
62
107
  wasm.wasmanalyzer_close_stream(this.__wbg_ptr, id);
63
108
  }
109
+ /**
110
+ * @returns {string}
111
+ */
112
+ get_compiler_options() {
113
+ let deferred1_0;
114
+ let deferred1_1;
115
+ try {
116
+ const ret = wasm.wasmanalyzer_get_compiler_options(this.__wbg_ptr);
117
+ deferred1_0 = ret[0];
118
+ deferred1_1 = ret[1];
119
+ return getStringFromWasm0(ret[0], ret[1]);
120
+ } finally {
121
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
122
+ }
123
+ }
64
124
  /**
65
125
  * @param {string} file_path
66
126
  * @returns {string}
@@ -186,6 +246,43 @@ class WasmAnalyzer {
186
246
  }
187
247
  return v3;
188
248
  }
249
+ /**
250
+ * @param {string} module_ref_json
251
+ * @returns {number}
252
+ */
253
+ request_metadata(module_ref_json) {
254
+ const ptr0 = passStringToWasm0(module_ref_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
255
+ const len0 = WASM_VECTOR_LEN;
256
+ const ret = wasm.wasmanalyzer_request_metadata(this.__wbg_ptr, ptr0, len0);
257
+ if (ret[2]) {
258
+ throw takeFromExternrefTable0(ret[1]);
259
+ }
260
+ return ret[0] >>> 0;
261
+ }
262
+ /**
263
+ * @param {string} entry_points_json
264
+ * @returns {string}
265
+ */
266
+ set_entry_points(entry_points_json) {
267
+ let deferred3_0;
268
+ let deferred3_1;
269
+ try {
270
+ const ptr0 = passStringToWasm0(entry_points_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
271
+ const len0 = WASM_VECTOR_LEN;
272
+ const ret = wasm.wasmanalyzer_set_entry_points(this.__wbg_ptr, ptr0, len0);
273
+ var ptr2 = ret[0];
274
+ var len2 = ret[1];
275
+ if (ret[3]) {
276
+ ptr2 = 0; len2 = 0;
277
+ throw takeFromExternrefTable0(ret[2]);
278
+ }
279
+ deferred3_0 = ptr2;
280
+ deferred3_1 = len2;
281
+ return getStringFromWasm0(ptr2, len2);
282
+ } finally {
283
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
284
+ }
285
+ }
189
286
  /**
190
287
  * @param {string} updates_json
191
288
  * @returns {string}
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/vite-plugin-angular",
3
- "version": "3.0.0-beta.45",
3
+ "version": "3.0.0-beta.47",
4
4
  "description": "Vite Plugin for Angular",
5
5
  "type": "module",
6
6
  "keywords": [
package/src/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { angular } from "./lib/angular-vite-plugin.js";
3
3
  export { angular } from "./lib/angular-vite-plugin.js";
4
4
  export type { PluginOptions } from "./lib/angular-vite-plugin.js";
5
5
  export type { AnalogIntegrationPlugin, AnalogPluginContext, AnalogPluginHooks, ComponentRegistryEntries, StylesheetRegistryConfigurator, StylesheetRegistryContext, TransformFilter } from "./lib/analog-plugin-interop.js";
6
+ export { findFastCompileApi, type FastCompileApi, type FastCompileOptions, type FastCompileResolve, type FastCompileSourceFormat, type SourceMapInput } from "./lib/fast-compile-api.js";
6
7
  export type { RegistryEntry as ComponentRegistryEntry, RegistryInput as ComponentRegistryInput } from "./lib/compiler/registry.js";
7
8
  export type { StylePreprocessor, StylesheetDependency, StylesheetDiagnostic, StylesheetRegistryReader, StylesheetTransformContext, StylesheetTransformResult } from "./lib/style-preprocessor.js";
8
9
  export default angular;
package/src/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { angularCompilationPlugin } from "./lib/compilation-api/compilation-api-plugin.js";
2
2
  import "./lib/compilation-api/index.js";
3
3
  import { angular } from "./lib/angular-vite-plugin.js";
4
+ import { findFastCompileApi } from "./lib/fast-compile-api.js";
4
5
  //#region packages/vite-plugin-angular/src/index.ts
5
6
  var src_default = angular;
6
7
  //#endregion
7
- export { angular, angularCompilationPlugin, src_default as default };
8
+ export { angular, angularCompilationPlugin, src_default as default, findFastCompileApi };
8
9
 
9
10
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export {\n angularCompilationPlugin,\n type AngularCompilationPluginOptions,\n} from './lib/compilation-api/index.js';\nimport { angular } from './lib/angular-vite-plugin.js';\nexport { angular } from './lib/angular-vite-plugin.js';\nexport type { PluginOptions } from './lib/angular-vite-plugin.js';\nexport type {\n AnalogIntegrationPlugin,\n AnalogPluginContext,\n AnalogPluginHooks,\n ComponentRegistryEntries,\n StylesheetRegistryConfigurator,\n StylesheetRegistryContext,\n TransformFilter,\n} from './lib/analog-plugin-interop.js';\nexport type {\n RegistryEntry as ComponentRegistryEntry,\n RegistryInput as ComponentRegistryInput,\n} from './lib/compiler/registry.js';\nexport type {\n StylePreprocessor,\n StylesheetDependency,\n StylesheetDiagnostic,\n StylesheetRegistryReader,\n StylesheetTransformContext,\n StylesheetTransformResult,\n} from './lib/style-preprocessor.js';\n\nexport default angular;\n"],"mappings":";;;;AA6BA,IAAA,cAAe"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export {\n angularCompilationPlugin,\n type AngularCompilationPluginOptions,\n} from './lib/compilation-api/index.js';\nimport { angular } from './lib/angular-vite-plugin.js';\nexport { angular } from './lib/angular-vite-plugin.js';\nexport type { PluginOptions } from './lib/angular-vite-plugin.js';\nexport type {\n AnalogIntegrationPlugin,\n AnalogPluginContext,\n AnalogPluginHooks,\n ComponentRegistryEntries,\n StylesheetRegistryConfigurator,\n StylesheetRegistryContext,\n TransformFilter,\n} from './lib/analog-plugin-interop.js';\nexport {\n findFastCompileApi,\n type FastCompileApi,\n type FastCompileOptions,\n type FastCompileResolve,\n type FastCompileSourceFormat,\n type SourceMapInput,\n} from './lib/fast-compile-api.js';\nexport type {\n RegistryEntry as ComponentRegistryEntry,\n RegistryInput as ComponentRegistryInput,\n} from './lib/compiler/registry.js';\nexport type {\n StylePreprocessor,\n StylesheetDependency,\n StylesheetDiagnostic,\n StylesheetRegistryReader,\n StylesheetTransformContext,\n StylesheetTransformResult,\n} from './lib/style-preprocessor.js';\n\nexport default angular;\n"],"mappings":";;;;;AAqCA,IAAA,cAAe"}
@@ -1,9 +1,4 @@
1
1
  import { type ParseResult } from "oxc-parser";
2
- /**
3
- * Parse with oxc-parser, using raw transfer when the platform supports it.
4
- * Falls back to the default transfer for this and later calls if raw
5
- * transfer throws (e.g. its large buffer cannot be allocated).
6
- */
7
2
  export declare function parseOxc(fileName: string, code: string): ParseResult;
8
3
  /** Recursively find all class declarations in an OXC AST, including nested scopes. */
9
4
  export declare function findAllClasses(program: any): any[];
@@ -9,7 +9,18 @@ var useRawTransfer = rawTransferSupported();
9
9
  * Falls back to the default transfer for this and later calls if raw
10
10
  * transfer throws (e.g. its large buffer cannot be allocated).
11
11
  */
12
+ var JS_TS_EXTENSIONS = [
13
+ ".ts",
14
+ ".tsx",
15
+ ".mts",
16
+ ".cts",
17
+ ".js",
18
+ ".jsx",
19
+ ".mjs",
20
+ ".cjs"
21
+ ];
12
22
  function parseOxc(fileName, code) {
23
+ if (!JS_TS_EXTENSIONS.some((ext) => fileName.endsWith(ext))) fileName += ".ts";
13
24
  if (useRawTransfer) try {
14
25
  return parseSync(fileName, code, rawTransferOptions);
15
26
  } catch {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/lib/compiler/utils.ts"],"sourcesContent":["import * as path from 'node:path';\nimport {\n parseSync,\n rawTransferSupported,\n type ParseResult,\n type ParserOptions,\n} from 'oxc-parser';\n\n// Raw transfer reads the AST straight from Rust memory instead of going\n// through JSON (~3x faster). Not yet in oxc-parser's published types.\nconst rawTransferOptions = { experimentalRawTransfer: true } as ParserOptions;\nlet useRawTransfer = rawTransferSupported();\n\n/**\n * Parse with oxc-parser, using raw transfer when the platform supports it.\n * Falls back to the default transfer for this and later calls if raw\n * transfer throws (e.g. its large buffer cannot be allocated).\n */\nexport function parseOxc(fileName: string, code: string): ParseResult {\n if (useRawTransfer) {\n try {\n return parseSync(fileName, code, rawTransferOptions);\n } catch {\n useRawTransfer = false;\n }\n }\n return parseSync(fileName, code);\n}\n\n/** Recursively find all class declarations in an OXC AST, including nested scopes. */\nexport function findAllClasses(program: any): any[] {\n const result: any[] = [];\n walkOxc(program, (node) => {\n if (node.type === 'ClassDeclaration') result.push(node);\n return true;\n });\n return result;\n}\n\n/**\n * Depth-first walk over OXC AST nodes. `visit` returns `false` to skip a\n * node's children.\n */\nexport function walkOxc(node: any, visit: (node: any) => boolean): void {\n if (Array.isArray(node)) {\n for (const child of node) walkOxc(child, visit);\n return;\n }\n if (!node || typeof node.type !== 'string' || !visit(node)) return;\n for (const key in node) {\n const value = node[key];\n if (value && typeof value === 'object') walkOxc(value, visit);\n }\n}\n\n/** Unwrap forwardRef(() => X) to X for OXC AST nodes. Returns the original node if not a forwardRef call. */\nexport function unwrapForwardRefOxc(node: any): any {\n if (\n node?.type === 'CallExpression' &&\n node.callee?.type === 'Identifier' &&\n node.callee.name === 'forwardRef'\n ) {\n const arg = node.arguments?.[0];\n if (arg?.type === 'ArrowFunctionExpression') {\n if (\n arg.body?.type === 'FunctionBody' ||\n arg.body?.type === 'BlockStatement'\n ) {\n const stmts = arg.body.statements || arg.body.body || [];\n const stmt = stmts[0];\n if (stmt?.type === 'ReturnStatement' && stmt.argument)\n return stmt.argument;\n } else {\n // Expression body: forwardRef(() => X)\n return arg.body;\n }\n }\n if (arg?.type === 'FunctionExpression') {\n const stmts = arg.body?.statements || arg.body?.body || [];\n if (stmts.length === 1) {\n const stmt = stmts[0];\n if (stmt?.type === 'ReturnStatement' && stmt.argument)\n return stmt.argument;\n }\n }\n }\n return node;\n}\n\n/**\n * Resolve the module specifier to use for a synthetic import of a registry\n * declaration referenced from `currentFileName`.\n *\n * Order of preference:\n * 1. `entry.sourcePackage` — external packages scanned from `.d.ts` resolve\n * via their package name (proper barrel exports).\n * 2. A relative path derived from `currentFileName` to `entry.fileName` — for\n * local workspace classes scanned from real source files. This is what\n * NgModule/tuple export expansion must use: the class lives in its own\n * file, not the module/barrel file that re-exports it, so importing from\n * the module specifier fails with\n * `\"X\" is not exported by \".../the.module.ts\"`.\n * 3. `fallbackSpecifier` — the import path of the module/tuple itself, used\n * for `.d.ts` entries (whose file path is not a usable import target) and\n * when the registry has no file location for the class.\n *\n * Returns `undefined` when the class is declared in `currentFileName` itself\n * (already in scope — no synthetic import needed).\n */\nexport function resolveSyntheticImportSpecifier(\n currentFileName: string,\n entry: { sourcePackage?: string; fileName?: string },\n fallbackSpecifier: string | undefined,\n): string | undefined {\n if (entry.sourcePackage) return entry.sourcePackage;\n // `.d.ts` entries come from scanning external package type declarations;\n // their file path is not a usable relative import target, so defer to the\n // module/tuple specifier the consumer already imports from.\n if (entry.fileName && !entry.fileName.endsWith('.d.ts')) {\n if (entry.fileName === currentFileName) return undefined;\n return deriveRelativeImportPath(currentFileName, entry.fileName);\n }\n return fallbackSpecifier;\n}\n\n/**\n * Derive a relative module specifier from `fromFile` to `toFile`, suitable for\n * a synthetic `import { … } from '…'` statement: strips the file extension,\n * normalizes to POSIX separators, and ensures an explicit `./` prefix.\n */\nexport function deriveRelativeImportPath(\n fromFile: string,\n toFile: string,\n): string {\n let rel = path.relative(path.dirname(fromFile), toFile);\n rel = rel.replace(/\\.[cm]?[jt]sx?$/, '');\n rel = rel.split(path.sep).join('/');\n if (!rel.startsWith('.')) rel = './' + rel;\n return rel;\n}\n\nexport { ANGULAR_DECORATORS } from './constants.js';\n"],"mappings":";;;;AAUA,IAAM,qBAAqB,EAAE,yBAAyB,KAAK;AAC3D,IAAI,iBAAiB,qBAAqB;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,SAAS,qBAAqB,KAAK,UAC3C,OAAO,KAAK;GAChB;EACF;CACF;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,gCACd,iBACA,OACA,mBACoB;CACpB,IAAI,MAAM,eAAe,OAAO,MAAM;CAItC,IAAI,MAAM,YAAY,CAAC,MAAM,SAAS,SAAS,OAAO,GAAG;EACvD,IAAI,MAAM,aAAa,iBAAiB,OAAO,KAAA;EAC/C,OAAO,yBAAyB,iBAAiB,MAAM,QAAQ;CACjE;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,yBACd,UACA,QACQ;CACR,IAAI,MAAM,OAAK,SAAS,OAAK,QAAQ,QAAQ,GAAG,MAAM;CACtD,MAAM,IAAI,QAAQ,mBAAmB,EAAE;CACvC,MAAM,IAAI,MAAM,OAAK,GAAG,CAAC,CAAC,KAAK,GAAG;CAClC,IAAI,CAAC,IAAI,WAAW,GAAG,GAAG,MAAM,OAAO;CACvC,OAAO;AACT"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../../src/lib/compiler/utils.ts"],"sourcesContent":["import * as path from 'node:path';\nimport {\n parseSync,\n rawTransferSupported,\n type ParseResult,\n type ParserOptions,\n} from 'oxc-parser';\n\n// Raw transfer reads the AST straight from Rust memory instead of going\n// through JSON (~3x faster). Not yet in oxc-parser's published types.\nconst rawTransferOptions = { experimentalRawTransfer: true } as ParserOptions;\nlet useRawTransfer = rawTransferSupported();\n\n/**\n * Parse with oxc-parser, using raw transfer when the platform supports it.\n * Falls back to the default transfer for this and later calls if raw\n * transfer throws (e.g. its large buffer cannot be allocated).\n */\nconst JS_TS_EXTENSIONS = [\n '.ts',\n '.tsx',\n '.mts',\n '.cts',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n];\n\nexport function parseOxc(fileName: string, code: string): ParseResult {\n // OXC picks the language from the extension. Modules of other source\n // formats reach the compiler already converted to TypeScript.\n if (!JS_TS_EXTENSIONS.some((ext) => fileName.endsWith(ext))) {\n fileName += '.ts';\n }\n if (useRawTransfer) {\n try {\n return parseSync(fileName, code, rawTransferOptions);\n } catch {\n useRawTransfer = false;\n }\n }\n return parseSync(fileName, code);\n}\n\n/** Recursively find all class declarations in an OXC AST, including nested scopes. */\nexport function findAllClasses(program: any): any[] {\n const result: any[] = [];\n walkOxc(program, (node) => {\n if (node.type === 'ClassDeclaration') result.push(node);\n return true;\n });\n return result;\n}\n\n/**\n * Depth-first walk over OXC AST nodes. `visit` returns `false` to skip a\n * node's children.\n */\nexport function walkOxc(node: any, visit: (node: any) => boolean): void {\n if (Array.isArray(node)) {\n for (const child of node) walkOxc(child, visit);\n return;\n }\n if (!node || typeof node.type !== 'string' || !visit(node)) return;\n for (const key in node) {\n const value = node[key];\n if (value && typeof value === 'object') walkOxc(value, visit);\n }\n}\n\n/** Unwrap forwardRef(() => X) to X for OXC AST nodes. Returns the original node if not a forwardRef call. */\nexport function unwrapForwardRefOxc(node: any): any {\n if (\n node?.type === 'CallExpression' &&\n node.callee?.type === 'Identifier' &&\n node.callee.name === 'forwardRef'\n ) {\n const arg = node.arguments?.[0];\n if (arg?.type === 'ArrowFunctionExpression') {\n if (\n arg.body?.type === 'FunctionBody' ||\n arg.body?.type === 'BlockStatement'\n ) {\n const stmts = arg.body.statements || arg.body.body || [];\n const stmt = stmts[0];\n if (stmt?.type === 'ReturnStatement' && stmt.argument)\n return stmt.argument;\n } else {\n // Expression body: forwardRef(() => X)\n return arg.body;\n }\n }\n if (arg?.type === 'FunctionExpression') {\n const stmts = arg.body?.statements || arg.body?.body || [];\n if (stmts.length === 1) {\n const stmt = stmts[0];\n if (stmt?.type === 'ReturnStatement' && stmt.argument)\n return stmt.argument;\n }\n }\n }\n return node;\n}\n\n/**\n * Resolve the module specifier to use for a synthetic import of a registry\n * declaration referenced from `currentFileName`.\n *\n * Order of preference:\n * 1. `entry.sourcePackage` — external packages scanned from `.d.ts` resolve\n * via their package name (proper barrel exports).\n * 2. A relative path derived from `currentFileName` to `entry.fileName` — for\n * local workspace classes scanned from real source files. This is what\n * NgModule/tuple export expansion must use: the class lives in its own\n * file, not the module/barrel file that re-exports it, so importing from\n * the module specifier fails with\n * `\"X\" is not exported by \".../the.module.ts\"`.\n * 3. `fallbackSpecifier` — the import path of the module/tuple itself, used\n * for `.d.ts` entries (whose file path is not a usable import target) and\n * when the registry has no file location for the class.\n *\n * Returns `undefined` when the class is declared in `currentFileName` itself\n * (already in scope — no synthetic import needed).\n */\nexport function resolveSyntheticImportSpecifier(\n currentFileName: string,\n entry: { sourcePackage?: string; fileName?: string },\n fallbackSpecifier: string | undefined,\n): string | undefined {\n if (entry.sourcePackage) return entry.sourcePackage;\n // `.d.ts` entries come from scanning external package type declarations;\n // their file path is not a usable relative import target, so defer to the\n // module/tuple specifier the consumer already imports from.\n if (entry.fileName && !entry.fileName.endsWith('.d.ts')) {\n if (entry.fileName === currentFileName) return undefined;\n return deriveRelativeImportPath(currentFileName, entry.fileName);\n }\n return fallbackSpecifier;\n}\n\n/**\n * Derive a relative module specifier from `fromFile` to `toFile`, suitable for\n * a synthetic `import { … } from '…'` statement: strips the file extension,\n * normalizes to POSIX separators, and ensures an explicit `./` prefix.\n */\nexport function deriveRelativeImportPath(\n fromFile: string,\n toFile: string,\n): string {\n let rel = path.relative(path.dirname(fromFile), toFile);\n rel = rel.replace(/\\.[cm]?[jt]sx?$/, '');\n rel = rel.split(path.sep).join('/');\n if (!rel.startsWith('.')) rel = './' + rel;\n return rel;\n}\n\nexport { ANGULAR_DECORATORS } from './constants.js';\n"],"mappings":";;;;AAUA,IAAM,qBAAqB,EAAE,yBAAyB,KAAK;AAC3D,IAAI,iBAAiB,qBAAqB;;;;;;AAO1C,IAAM,mBAAmB;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAgB,SAAS,UAAkB,MAA2B;CAGpE,IAAI,CAAC,iBAAiB,MAAM,QAAQ,SAAS,SAAS,GAAG,CAAC,GACxD,YAAY;CAEd,IAAI,gBACF,IAAI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AO;AACT;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,gCACd,iBACA,OACA,mBACoB;CACpB,IAAI,MAAM,eAAe,OAAO,MAAM;CAItC,IAAI,MAAM,YAAY,CAAC,MAAM,SAAS,SAAS,OAAO,GAAG;EACvD,IAAI,MAAM,aAAa,iBAAiB,OAAO,KAAA;EAC/C,OAAO,yBAAyB,iBAAiB,MAAM,QAAQ;CACjE;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,yBACd,UACA,QACQ;CACR,IAAI,MAAM,OAAK,SAAS,OAAK,QAAQ,QAAQ,GAAG,MAAM;CACtD,MAAM,IAAI,QAAQ,mBAAmB,EAAE;CACvC,MAAM,IAAI,MAAM,OAAK,GAAG,CAAC,CAAC,KAAK,GAAG;CAClC,IAAI,CAAC,IAAI,WAAW,GAAG,GAAG,MAAM,OAAO;CACvC,OAAO;AACT"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The fast compile path's plugin API, for Vite plugins that compile other
3
+ * source formats into Angular components (for example `.tsrx` modules).
4
+ *
5
+ * Such a plugin finds the fast compile plugin by its `api.fastCompile`
6
+ * property, lowers its modules to TypeScript, and hands the result to
7
+ * `compile()`.
8
+ */
9
+ /** Resolves an import the way Vite's `this.resolve` does. */
10
+ export type FastCompileResolve = (specifier: string, importer: string) => Promise<{
11
+ id: string;
12
+ external?: boolean | "absolute" | "relative";
13
+ } | null>;
14
+ /** A source format whose modules compile to Angular components. */
15
+ export interface FastCompileSourceFormat {
16
+ /** Short name used in diagnostics, for example `'tsrx'`. */
17
+ name: string;
18
+ /** Whether a module path (without query) belongs to this format. */
19
+ test(path: string): boolean;
20
+ /**
21
+ * TypeScript for registry scanning. It must declare the same Angular
22
+ * classes, selectors, inputs and outputs as the compiled module; template
23
+ * details may be placeholders.
24
+ */
25
+ toScanSource(code: string, path: string): Promise<string> | string;
26
+ }
27
+ /** A source map, as a JSON string or an object. */
28
+ export type SourceMapInput = string | {
29
+ [key: string]: unknown;
30
+ };
31
+ export interface FastCompileOptions {
32
+ /** Resolves the module's imports, usually the calling plugin's `this.resolve`. */
33
+ resolve: FastCompileResolve;
34
+ /**
35
+ * Maps the compiled output's source map (which points at `code`) back to
36
+ * the module's original source.
37
+ */
38
+ mapToSource?(map: SourceMapInput): {
39
+ [key: string]: unknown;
40
+ };
41
+ }
42
+ export interface FastCompileApi {
43
+ /** Registers a source format so registry scans and HMR understand its modules. */
44
+ registerSourceFormat(format: FastCompileSourceFormat): void;
45
+ /**
46
+ * Scans the modules behind `specifiers`, imported by `importer`, into the
47
+ * component registry so `resolveSelector` knows their selectors. Relative
48
+ * imports are scanned from source; packages from their `.d.ts` declarations.
49
+ */
50
+ scanImports(specifiers: string[], importer: string, resolve: FastCompileResolve): Promise<void>;
51
+ /** The element selector of a component or directive class, if known. */
52
+ resolveSelector(className: string): string | null;
53
+ /** Compiles TypeScript produced for module `id`. */
54
+ compile(code: string, id: string, options: FastCompileOptions): Promise<{
55
+ code: string;
56
+ map: SourceMapInput | null;
57
+ } | undefined>;
58
+ }
59
+ /** Finds the fast compile plugin's API among resolved Vite plugins. */
60
+ export declare function findFastCompileApi(plugins: readonly {
61
+ api?: unknown;
62
+ }[]): FastCompileApi | undefined;
@@ -0,0 +1,12 @@
1
+ //#region packages/vite-plugin-angular/src/lib/fast-compile-api.ts
2
+ /** Finds the fast compile plugin's API among resolved Vite plugins. */
3
+ function findFastCompileApi(plugins) {
4
+ for (const plugin of plugins) {
5
+ const api = plugin.api;
6
+ if (api?.fastCompile) return api.fastCompile;
7
+ }
8
+ }
9
+ //#endregion
10
+ export { findFastCompileApi };
11
+
12
+ //# sourceMappingURL=fast-compile-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fast-compile-api.js","names":[],"sources":["../../../src/lib/fast-compile-api.ts"],"sourcesContent":["/**\n * The fast compile path's plugin API, for Vite plugins that compile other\n * source formats into Angular components (for example `.tsrx` modules).\n *\n * Such a plugin finds the fast compile plugin by its `api.fastCompile`\n * property, lowers its modules to TypeScript, and hands the result to\n * `compile()`.\n */\n\n/** Resolves an import the way Vite's `this.resolve` does. */\nexport type FastCompileResolve = (\n specifier: string,\n importer: string,\n) => Promise<{\n id: string;\n external?: boolean | 'absolute' | 'relative';\n} | null>;\n\n/** A source format whose modules compile to Angular components. */\nexport interface FastCompileSourceFormat {\n /** Short name used in diagnostics, for example `'tsrx'`. */\n name: string;\n /** Whether a module path (without query) belongs to this format. */\n test(path: string): boolean;\n /**\n * TypeScript for registry scanning. It must declare the same Angular\n * classes, selectors, inputs and outputs as the compiled module; template\n * details may be placeholders.\n */\n toScanSource(code: string, path: string): Promise<string> | string;\n}\n\n/** A source map, as a JSON string or an object. */\nexport type SourceMapInput = string | { [key: string]: unknown };\n\nexport interface FastCompileOptions {\n /** Resolves the module's imports, usually the calling plugin's `this.resolve`. */\n resolve: FastCompileResolve;\n /**\n * Maps the compiled output's source map (which points at `code`) back to\n * the module's original source.\n */\n mapToSource?(map: SourceMapInput): { [key: string]: unknown };\n}\n\nexport interface FastCompileApi {\n /** Registers a source format so registry scans and HMR understand its modules. */\n registerSourceFormat(format: FastCompileSourceFormat): void;\n /**\n * Scans the modules behind `specifiers`, imported by `importer`, into the\n * component registry so `resolveSelector` knows their selectors. Relative\n * imports are scanned from source; packages from their `.d.ts` declarations.\n */\n scanImports(\n specifiers: string[],\n importer: string,\n resolve: FastCompileResolve,\n ): Promise<void>;\n /** The element selector of a component or directive class, if known. */\n resolveSelector(className: string): string | null;\n /** Compiles TypeScript produced for module `id`. */\n compile(\n code: string,\n id: string,\n options: FastCompileOptions,\n ): Promise<{ code: string; map: SourceMapInput | null } | undefined>;\n}\n\n/** Finds the fast compile plugin's API among resolved Vite plugins. */\nexport function findFastCompileApi(\n plugins: readonly { api?: unknown }[],\n): FastCompileApi | undefined {\n for (const plugin of plugins) {\n const api = plugin.api as { fastCompile?: FastCompileApi } | undefined;\n if (api?.fastCompile) {\n return api.fastCompile;\n }\n }\n return undefined;\n}\n"],"mappings":";;AAqEA,SAAgB,mBACd,SAC4B;CAC5B,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,MAAM,OAAO;EACnB,IAAI,KAAK,aACP,OAAO,IAAI;CAEf;AAEF"}
@@ -42,6 +42,34 @@ function fastCompilePlugin(optionsOrCtx) {
42
42
  compilationBackend: "fast"
43
43
  });
44
44
  const pluginOptions = sharedCtx ? sharedCtx.options : optionsOrCtx;
45
+ /** Source formats registered through `api.fastCompile.registerSourceFormat`. */
46
+ const sourceFormats = [];
47
+ const sourceFormatOf = (file) => {
48
+ const path = file.split("?")[0];
49
+ return sourceFormats.find((format) => format.test(path));
50
+ };
51
+ /** Whether `file` is a module compiled through this plugin. */
52
+ const isCompiledSource = (file) => TS_EXT_REGEX.test(file) || sourceFormatOf(file) !== void 0;
53
+ /**
54
+ * Reads a source file for registry scanning. Modules of a registered source
55
+ * format are converted to TypeScript first so the scanner sees their classes.
56
+ */
57
+ const readScanSource = async (file) => {
58
+ const code = await promises.readFile(file, "utf-8");
59
+ const format = sourceFormatOf(file);
60
+ return format ? format.toScanSource(code, file) : code;
61
+ };
62
+ /**
63
+ * Adapts a Vite-style resolver to the scanner's: only source files this
64
+ * plugin compiles, outside `node_modules` (package declarations come from
65
+ * the lazy `.d.ts` scanner instead).
66
+ */
67
+ const toResolveImport = (resolve) => async (spec, importer) => {
68
+ const resolved = await resolve(spec, importer);
69
+ if (!resolved || resolved.external) return null;
70
+ const file = normalizePath(resolved.id.split("?")[0]);
71
+ return isCompiledSource(file) && !EXCLUDED_TS_EXT_REGEX.test(file) && !file.includes("/node_modules/") ? file : null;
72
+ };
45
73
  const tsconfigResolver = sharedCtx?.tsconfigResolver ?? new TsconfigResolver({
46
74
  workspaceRoot: pluginOptions.workspaceRoot,
47
75
  include: pluginOptions.include ?? [],
@@ -85,7 +113,7 @@ function fastCompilePlugin(optionsOrCtx) {
85
113
  visited.add(file);
86
114
  let code;
87
115
  try {
88
- code = fileContents?.get(file) ?? await promises.readFile(file, "utf-8");
116
+ code = fileContents?.get(file) ?? await readScanSource(file);
89
117
  fileContents?.set(file, code);
90
118
  } catch (e) {
91
119
  if (debugRegistry.enabled) debugRegistry("scanBarrelExports: failed to read %s: %s", file, e?.message);
@@ -145,7 +173,7 @@ function fastCompilePlugin(optionsOrCtx) {
145
173
  }
146
174
  const results = await Promise.all(Array.from(candidates).map(async (file) => {
147
175
  try {
148
- const code = await promises.readFile(file, "utf-8");
176
+ const code = await readScanSource(file);
149
177
  fileContents.set(file, code);
150
178
  const entries = scanFile(code, file);
151
179
  scanResults.set(file, entries);
@@ -198,7 +226,7 @@ function fastCompilePlugin(optionsOrCtx) {
198
226
  importWalkVisited.add(file);
199
227
  let code;
200
228
  try {
201
- code = fileContents.get(file) ?? await promises.readFile(file, "utf-8");
229
+ code = fileContents.get(file) ?? await readScanSource(file);
202
230
  fileContents.set(file, code);
203
231
  } catch {
204
232
  return;
@@ -248,11 +276,15 @@ function fastCompilePlugin(optionsOrCtx) {
248
276
  debugRegistry("initFastCompile done: %d entries from %d candidate files", registry.size, candidates.size);
249
277
  }
250
278
  function ensureDtsRegistryForSource(code, id, program) {
251
- for (const pkg of collectImportedPackages(code, id, program)) {
279
+ ensureDtsRegistryForPackages(collectImportedPackages(code, id, program));
280
+ }
281
+ /** Scan the `.d.ts` declarations of `packages` into the registry, once each. */
282
+ function ensureDtsRegistryForPackages(packages) {
283
+ for (const pkg of packages) {
252
284
  if (scannedDtsPackages.has(pkg)) continue;
253
285
  scannedDtsPackages.add(pkg);
254
286
  try {
255
- const dtsEntries = scanPackageDts(pkg, projectRoot, scannedDtsPackages);
287
+ const dtsEntries = scanPackageDts(pkg, projectRoot || process.cwd(), scannedDtsPackages);
256
288
  for (const entry of dtsEntries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
257
289
  } catch {}
258
290
  }
@@ -262,7 +294,14 @@ function fastCompilePlugin(optionsOrCtx) {
262
294
  * `id` as their importer, so a metadata change in any of them recompiles it.
263
295
  */
264
296
  async function resolveImportedDeclarations(code, id, program, resolveImport) {
265
- await Promise.all(collectAllImports(code, id, program).map(async (spec) => {
297
+ await resolveImportSpecifiers(collectAllImports(code, id, program), id, resolveImport);
298
+ }
299
+ /**
300
+ * Scan the files behind `specs`, imported by `id`, into the registry and
301
+ * record `id` as their importer.
302
+ */
303
+ async function resolveImportSpecifiers(specs, id, resolveImport) {
304
+ await Promise.all(specs.map(async (spec) => {
266
305
  const file = await resolveImport(spec, id);
267
306
  if (!file) return;
268
307
  for (const scanned of await scanOnDemand(file, resolveImport)) {
@@ -297,7 +336,7 @@ function fastCompilePlugin(optionsOrCtx) {
297
336
  let code;
298
337
  let program;
299
338
  try {
300
- code = await promises.readFile(current, "utf-8");
339
+ code = await readScanSource(current);
301
340
  program = parseOxc(current, code).program;
302
341
  } catch {
303
342
  return;
@@ -314,6 +353,17 @@ function fastCompilePlugin(optionsOrCtx) {
314
353
  await visit(file);
315
354
  return visited;
316
355
  }
356
+ /**
357
+ * The element selector of a component or directive class, for source formats
358
+ * that reference components by class. Includes registries contributed
359
+ * through `analog.setup()`.
360
+ */
361
+ function lookupSelector(className) {
362
+ const registries = sharedCtx ? sharedCtx.componentRegistries : componentRegistries;
363
+ const entry = registry.get(className) ?? registries.map((r) => r.get(className)).find((e) => e !== void 0);
364
+ if (!entry || entry.kind !== "component" && entry.kind !== "directive") return null;
365
+ return entry.selector;
366
+ }
317
367
  function registryEntriesOf(file) {
318
368
  return [...registry.values()].filter((e) => e.fileName === file);
319
369
  }
@@ -366,7 +416,7 @@ function fastCompilePlugin(optionsOrCtx) {
366
416
  const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;
367
417
  const activeStylePreprocessor = sharedCtx?.stylePreprocessor ?? stylePreprocessor;
368
418
  for (let i = 0; i < styleStrings.length; i++) {
369
- const stylePath = stylePaths.get(i) ?? id.replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
419
+ const stylePath = stylePaths.get(i) ?? (sourceFormatOf(id) ? id + ".ts" : id).replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
370
420
  try {
371
421
  const preprocessed = preprocessStylesheet(styleStrings[i], stylePath, activeStylePreprocessor, {
372
422
  filename: stylePath,
@@ -440,7 +490,30 @@ function fastCompilePlugin(optionsOrCtx) {
440
490
  angularCompiler: true,
441
491
  getTsConfigPath: resolveTsConfigPath,
442
492
  getSourceMap: (id) => emittedMaps.get(normalizePath(id)),
443
- hasEmitted: (id) => emittedMaps.has(normalizePath(id))
493
+ hasEmitted: (id) => emittedMaps.has(normalizePath(id)),
494
+ fastCompile: {
495
+ registerSourceFormat(format) {
496
+ if (!sourceFormats.includes(format)) sourceFormats.push(format);
497
+ },
498
+ scanImports(specifiers, importer, resolve) {
499
+ ensureDtsRegistryForPackages(specifiers.filter((spec) => !spec.startsWith(".") && !spec.startsWith("/")).map((spec) => {
500
+ const parts = spec.split("/");
501
+ return spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
502
+ }));
503
+ return resolveImportSpecifiers(specifiers, importer, toResolveImport(resolve));
504
+ },
505
+ resolveSelector: lookupSelector,
506
+ async compile(code, id, { resolve, mapToSource }) {
507
+ const transformed = await handleFastCompileTransform(code, id, toResolveImport(resolve));
508
+ if (!transformed) return;
509
+ const map = transformed.map && mapToSource ? mapToSource(transformed.map) : transformed.map ?? null;
510
+ if (map) emittedMaps.set(normalizePath(id), typeof map === "string" ? map : JSON.stringify(map));
511
+ return {
512
+ code: transformed.code,
513
+ map
514
+ };
515
+ }
516
+ }
444
517
  };
445
518
  sharedCtx?.registerCompiler({
446
519
  name: "@analogjs/vite-plugin-angular-fast-compile",
@@ -509,7 +582,7 @@ function fastCompilePlugin(optionsOrCtx) {
509
582
  const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);
510
583
  if (parentModule) return [parentModule];
511
584
  }
512
- if (TS_EXT_REGEX.test(ctx.file)) {
585
+ if (isCompiledSource(ctx.file)) {
513
586
  const [fileId] = ctx.file.split("?");
514
587
  const oldEntries = registryEntriesOf(fileId);
515
588
  for (const entry of oldEntries) registry.delete(entry.className);
@@ -545,12 +618,8 @@ function fastCompilePlugin(optionsOrCtx) {
545
618
  const activeTransformFilter = sharedCtx?.transformFilter ?? transformFilter;
546
619
  if (activeTransformFilter && !activeTransformFilter(code, id)) return;
547
620
  if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
548
- const transformed = await handleFastCompileTransform(code, id, async (spec, importer) => {
549
- const resolved = await this.resolve(spec, importer, { skipSelf: true });
550
- if (!resolved || resolved.external) return null;
551
- const file = normalizePath(resolved.id.split("?")[0]);
552
- return TS_EXT_REGEX.test(file) && !EXCLUDED_TS_EXT_REGEX.test(file) && !file.includes("/node_modules/") ? file : null;
553
- });
621
+ const resolveImport = toResolveImport((spec, importer) => this.resolve(spec, importer, { skipSelf: true }));
622
+ const transformed = await handleFastCompileTransform(code, id, resolveImport);
554
623
  if (transformed?.map) emittedMaps.set(normalizePath(id), typeof transformed.map === "string" ? transformed.map : JSON.stringify(transformed.map));
555
624
  return transformed;
556
625
  }