@analogjs/vite-plugin-angular 3.0.0-beta.46 → 3.0.0-beta.48

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.46",
3
+ "version": "3.0.0-beta.48",
4
4
  "description": "Vite Plugin for Angular",
5
5
  "type": "module",
6
6
  "keywords": [
package/src/index.d.ts CHANGED
@@ -3,6 +3,8 @@ 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";
7
+ export { findNgpCompileApi, type NgpCompileApi, type NgpLowerContext, type NgpLoweredModule, type NgpSourceFormat } from "./lib/ngp-compile-api.js";
6
8
  export type { RegistryEntry as ComponentRegistryEntry, RegistryInput as ComponentRegistryInput } from "./lib/compiler/registry.js";
7
9
  export type { StylePreprocessor, StylesheetDependency, StylesheetDiagnostic, StylesheetRegistryReader, StylesheetTransformContext, StylesheetTransformResult } from "./lib/style-preprocessor.js";
8
10
  export default angular;
package/src/index.js CHANGED
@@ -1,9 +1,11 @@
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";
5
+ import { findNgpCompileApi } from "./lib/ngp-compile-api.js";
4
6
  //#region packages/vite-plugin-angular/src/index.ts
5
7
  var src_default = angular;
6
8
  //#endregion
7
- export { angular, angularCompilationPlugin, src_default as default };
9
+ export { angular, angularCompilationPlugin, src_default as default, findFastCompileApi, findNgpCompileApi };
8
10
 
9
11
  //# 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 {\n findNgpCompileApi,\n type NgpCompileApi,\n type NgpLowerContext,\n type NgpLoweredModule,\n type NgpSourceFormat,\n} from './lib/ngp-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":";;;;;;AA4CA,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;;;;;;AAO1C,SAAgB,SAAS,UAAkB,MAA2B;CACpE,IAAI,gBACF,IAAI;EACF,OAAO,UAAU,UAAU,MAAM,kBAAkB;CACrD,QAAQ;EACN,iBAAiB;CACnB;CAEF,OAAO,UAAU,UAAU,IAAI;AACjC;;AAGA,SAAgB,eAAe,SAAqB;CAClD,MAAM,SAAgB,CAAC;CACvB,QAAQ,UAAU,SAAS;EACzB,IAAI,KAAK,SAAS,oBAAoB,OAAO,KAAK,IAAI;EACtD,OAAO;CACT,CAAC;CACD,OAAO;AACT;;;;;AAMA,SAAgB,QAAQ,MAAW,OAAqC;CACtE,IAAI,MAAM,QAAQ,IAAI,GAAG;EACvB,KAAK,MAAM,SAAS,MAAM,QAAQ,OAAO,KAAK;EAC9C;CACF;CACA,IAAI,CAAC,QAAQ,OAAO,KAAK,SAAS,YAAY,CAAC,MAAM,IAAI,GAAG;CAC5D,KAAK,MAAM,OAAO,MAAM;EACtB,MAAM,QAAQ,KAAK;EACnB,IAAI,SAAS,OAAO,UAAU,UAAU,QAAQ,OAAO,KAAK;CAC9D;AACF;;AAGA,SAAgB,oBAAoB,MAAgB;CAClD,IACE,MAAM,SAAS,oBACf,KAAK,QAAQ,SAAS,gBACtB,KAAK,OAAO,SAAS,cACrB;EACA,MAAM,MAAM,KAAK,YAAY;EAC7B,IAAI,KAAK,SAAS,2BAA2B;GAC3C,IACE,IAAI,MAAM,SAAS,kBACnB,IAAI,MAAM,SAAS,kBACnB;IAEA,MAAM,QADQ,IAAI,KAAK,cAAc,IAAI,KAAK,QAAQ,CAAC,EAAA,CACpC;IACnB,IAAI,MAAM,SAAS,qBAAqB,KAAK,UAC3C,OAAO,KAAK;GAChB,OAEE,OAAO,IAAI;EAEf;EACA,IAAI,KAAK,SAAS,sBAAsB;GACtC,MAAM,QAAQ,IAAI,MAAM,cAAc,IAAI,MAAM,QAAQ,CAAC;GACzD,IAAI,MAAM,WAAW,GAAG;IACtB,MAAM,OAAO,MAAM;IACnB,IAAI,MAAM,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,y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E,OAAO,IAAI;EAEf;EACA,IAAI,KAAK,SAAS,sBAAsB;GACtC,MAAM,QAAQ,IAAI,MAAM,cAAc,IAAI,MAAM,QAAQ,CAAC;GACzD,IAAI,MAAM,WAAW,GAAG;IACtB,MAAM,OAAO,MAAM;IACnB,IAAI,MAAM,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"}
@@ -0,0 +1,74 @@
1
+ import type { parseSync } from "oxc-parser";
2
+ import type { ComponentRegistryEntries } from "./analog-plugin-interop.js";
3
+ import { type ComponentRegistry, type RegistryEntry } from "./compiler/index.js";
4
+ import type { FastCompileResolve, FastCompileSourceFormat } from "./fast-compile-api.js";
5
+ type OxcProgram = ReturnType<typeof parseSync>["program"];
6
+ /** Resolves an import to a source file to scan, or `null` to skip it. */
7
+ export type ResolveImport = (spec: string, importer: string) => Promise<string | null>;
8
+ /**
9
+ * Angular classes scanned from source files and package `.d.ts` declarations,
10
+ * so source formats can look up the selectors of the components they import
11
+ * before any compiler sees their modules. Shared by the fast compile and NGP
12
+ * plugins.
13
+ */
14
+ export declare class ComponentScanner {
15
+ readonly registry: ComponentRegistry;
16
+ readonly scannedDtsPackages: Set<string>;
17
+ /** Files scanned on demand, mapped to the barrel chain each pulled in. */
18
+ readonly lazyScans: Map<string, Promise<Set<string>>>;
19
+ /** Modules compiled against each scanned file. */
20
+ readonly importersByFile: Map<string, Set<string>>;
21
+ private readonly sourceFormats;
22
+ private root;
23
+ /** Where package declarations are looked up from. */
24
+ get projectRoot(): string;
25
+ reset(projectRoot: string): void;
26
+ registerSourceFormat(format: FastCompileSourceFormat): void;
27
+ sourceFormatOf(file: string): FastCompileSourceFormat | undefined;
28
+ /** Whether `file` is TypeScript or a module of a registered source format. */
29
+ isCompiledSource(file: string): boolean;
30
+ /**
31
+ * Reads a source file for scanning. Modules of a registered source format
32
+ * are converted to TypeScript first so the scanner sees their classes.
33
+ */
34
+ readScanSource(file: string): Promise<string>;
35
+ /**
36
+ * Adapts a Vite-style resolver to the scanner's: only source files this
37
+ * scanner reads, outside `node_modules` (package declarations come from the
38
+ * `.d.ts` scanner instead).
39
+ */
40
+ toResolveImport(resolve: FastCompileResolve): ResolveImport;
41
+ /** Scans the `.d.ts` declarations of `packages` into the registry, once each. */
42
+ ensureDtsRegistryForPackages(packages: Iterable<string>): void;
43
+ ensureDtsRegistryForSource(code: string, id: string, program?: OxcProgram): void;
44
+ /**
45
+ * Scans the modules behind `specifiers`, imported by `importer`: packages
46
+ * from their `.d.ts` declarations, everything else from source.
47
+ */
48
+ scanImports(specifiers: string[], importer: string, resolve: FastCompileResolve): Promise<void>;
49
+ /**
50
+ * Scans the files behind `specs`, imported by `id`, into the registry and
51
+ * records `id` as their importer.
52
+ */
53
+ resolveImportSpecifiers(specs: string[], id: string, resolveImport: ResolveImport): Promise<void>;
54
+ /**
55
+ * The element selector of a component or directive class. `external` are
56
+ * registries contributed through `analog.setup()`.
57
+ */
58
+ lookupSelector(className: string, external?: readonly ComponentRegistryEntries[]): string | null;
59
+ /** The files scanned for `importer`. */
60
+ dependenciesOf(importer: string): string[];
61
+ entriesOf(file: string): RegistryEntry[];
62
+ /** Drops what was scanned from `file`, so the next scan reads it again. */
63
+ invalidate(file: string): void;
64
+ private addEntry;
65
+ private scanOnDemand;
66
+ /**
67
+ * Scan a file and everything it re-exports, resolving specifiers through
68
+ * Vite so path aliases work. Tuple barrels and NgModules can list classes
69
+ * their file imports without re-exporting, so their imports are followed
70
+ * too. Returns every file scanned.
71
+ */
72
+ private scanWithReExports;
73
+ }
74
+ export {};
@@ -0,0 +1,178 @@
1
+ import { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX } from "./utils/plugin-config.js";
2
+ import { parseOxc } from "./compiler/utils.js";
3
+ import { scanFile } from "./compiler/registry.js";
4
+ import { collectAllImports, collectImportedPackages, collectReExports, scanPackageDts } from "./compiler/dts-reader.js";
5
+ import "./compiler/index.js";
6
+ import { promises } from "node:fs";
7
+ import { normalizePath } from "vite";
8
+ //#region packages/vite-plugin-angular/src/lib/component-scanner.ts
9
+ /**
10
+ * Angular classes scanned from source files and package `.d.ts` declarations,
11
+ * so source formats can look up the selectors of the components they import
12
+ * before any compiler sees their modules. Shared by the fast compile and NGP
13
+ * plugins.
14
+ */
15
+ var ComponentScanner = class {
16
+ registry = /* @__PURE__ */ new Map();
17
+ scannedDtsPackages = /* @__PURE__ */ new Set();
18
+ /** Files scanned on demand, mapped to the barrel chain each pulled in. */
19
+ lazyScans = /* @__PURE__ */ new Map();
20
+ /** Modules compiled against each scanned file. */
21
+ importersByFile = /* @__PURE__ */ new Map();
22
+ sourceFormats = [];
23
+ root = "";
24
+ /** Where package declarations are looked up from. */
25
+ get projectRoot() {
26
+ return this.root;
27
+ }
28
+ reset(projectRoot) {
29
+ this.root = projectRoot;
30
+ this.registry.clear();
31
+ this.scannedDtsPackages.clear();
32
+ this.lazyScans.clear();
33
+ this.importersByFile.clear();
34
+ }
35
+ registerSourceFormat(format) {
36
+ if (!this.sourceFormats.includes(format)) this.sourceFormats.push(format);
37
+ }
38
+ sourceFormatOf(file) {
39
+ const path = file.split("?")[0];
40
+ return this.sourceFormats.find((format) => format.test(path));
41
+ }
42
+ /** Whether `file` is TypeScript or a module of a registered source format. */
43
+ isCompiledSource(file) {
44
+ return TS_EXT_REGEX.test(file) || this.sourceFormatOf(file) !== void 0;
45
+ }
46
+ /**
47
+ * Reads a source file for scanning. Modules of a registered source format
48
+ * are converted to TypeScript first so the scanner sees their classes.
49
+ */
50
+ async readScanSource(file) {
51
+ const code = await promises.readFile(file, "utf-8");
52
+ const format = this.sourceFormatOf(file);
53
+ return format ? format.toScanSource(code, file) : code;
54
+ }
55
+ /**
56
+ * Adapts a Vite-style resolver to the scanner's: only source files this
57
+ * scanner reads, outside `node_modules` (package declarations come from the
58
+ * `.d.ts` scanner instead).
59
+ */
60
+ toResolveImport(resolve) {
61
+ return async (spec, importer) => {
62
+ const resolved = await resolve(spec, importer);
63
+ if (!resolved || resolved.external) return null;
64
+ const file = normalizePath(resolved.id.split("?")[0]);
65
+ return this.isCompiledSource(file) && !EXCLUDED_TS_EXT_REGEX.test(file) && !file.includes("/node_modules/") ? file : null;
66
+ };
67
+ }
68
+ /** Scans the `.d.ts` declarations of `packages` into the registry, once each. */
69
+ ensureDtsRegistryForPackages(packages) {
70
+ for (const pkg of packages) {
71
+ if (this.scannedDtsPackages.has(pkg)) continue;
72
+ this.scannedDtsPackages.add(pkg);
73
+ try {
74
+ const dtsEntries = scanPackageDts(pkg, this.root || process.cwd(), this.scannedDtsPackages);
75
+ for (const entry of dtsEntries) this.addEntry(entry);
76
+ } catch {}
77
+ }
78
+ }
79
+ ensureDtsRegistryForSource(code, id, program) {
80
+ this.ensureDtsRegistryForPackages(collectImportedPackages(code, id, program));
81
+ }
82
+ /**
83
+ * Scans the modules behind `specifiers`, imported by `importer`: packages
84
+ * from their `.d.ts` declarations, everything else from source.
85
+ */
86
+ scanImports(specifiers, importer, resolve) {
87
+ this.ensureDtsRegistryForPackages(specifiers.filter((spec) => !spec.startsWith(".") && !spec.startsWith("/")).map((spec) => {
88
+ const parts = spec.split("/");
89
+ return spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
90
+ }));
91
+ return this.resolveImportSpecifiers(specifiers, importer, this.toResolveImport(resolve));
92
+ }
93
+ /**
94
+ * Scans the files behind `specs`, imported by `id`, into the registry and
95
+ * records `id` as their importer.
96
+ */
97
+ async resolveImportSpecifiers(specs, id, resolveImport) {
98
+ await Promise.all(specs.map(async (spec) => {
99
+ const file = await resolveImport(spec, id);
100
+ if (!file) return;
101
+ for (const scanned of await this.scanOnDemand(file, resolveImport)) {
102
+ let importers = this.importersByFile.get(scanned);
103
+ if (!importers) {
104
+ importers = /* @__PURE__ */ new Set();
105
+ this.importersByFile.set(scanned, importers);
106
+ }
107
+ importers.add(id);
108
+ }
109
+ }));
110
+ }
111
+ /**
112
+ * The element selector of a component or directive class. `external` are
113
+ * registries contributed through `analog.setup()`.
114
+ */
115
+ lookupSelector(className, external = []) {
116
+ const entry = this.registry.get(className) ?? external.map((r) => r.get(className)).find((e) => e !== void 0);
117
+ if (!entry || entry.kind !== "component" && entry.kind !== "directive") return null;
118
+ return entry.selector;
119
+ }
120
+ /** The files scanned for `importer`. */
121
+ dependenciesOf(importer) {
122
+ return [...this.importersByFile].filter(([, importers]) => importers.has(importer)).map(([file]) => file);
123
+ }
124
+ entriesOf(file) {
125
+ return [...this.registry.values()].filter((e) => e.fileName === file);
126
+ }
127
+ /** Drops what was scanned from `file`, so the next scan reads it again. */
128
+ invalidate(file) {
129
+ for (const entry of this.entriesOf(file)) this.registry.delete(entry.className);
130
+ this.lazyScans.clear();
131
+ }
132
+ addEntry(entry) {
133
+ if (!this.registry.has(entry.className)) this.registry.set(entry.className, entry);
134
+ }
135
+ scanOnDemand(file, resolveImport) {
136
+ let scan = this.lazyScans.get(file);
137
+ if (!scan) {
138
+ scan = this.scanWithReExports(file, resolveImport);
139
+ this.lazyScans.set(file, scan);
140
+ }
141
+ return scan;
142
+ }
143
+ /**
144
+ * Scan a file and everything it re-exports, resolving specifiers through
145
+ * Vite so path aliases work. Tuple barrels and NgModules can list classes
146
+ * their file imports without re-exporting, so their imports are followed
147
+ * too. Returns every file scanned.
148
+ */
149
+ async scanWithReExports(file, resolveImport) {
150
+ const visited = /* @__PURE__ */ new Set();
151
+ const visit = async (current) => {
152
+ if (visited.has(current)) return;
153
+ visited.add(current);
154
+ let code;
155
+ let program;
156
+ try {
157
+ code = await this.readScanSource(current);
158
+ program = parseOxc(current, code).program;
159
+ } catch {
160
+ return;
161
+ }
162
+ const entries = scanFile(code, current, program);
163
+ for (const entry of entries) this.addEntry(entry);
164
+ this.ensureDtsRegistryForSource(code, current, program);
165
+ const specifiers = entries.some((e) => e.kind === "tuple" || e.kind === "ngmodule") ? collectAllImports(code, current, program) : collectReExports(code, current, program);
166
+ for (const spec of specifiers) {
167
+ const dep = await resolveImport(spec, current);
168
+ if (dep) await visit(dep);
169
+ }
170
+ };
171
+ await visit(file);
172
+ return visited;
173
+ }
174
+ };
175
+ //#endregion
176
+ export { ComponentScanner };
177
+
178
+ //# sourceMappingURL=component-scanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-scanner.js","names":[],"sources":["../../../src/lib/component-scanner.ts"],"sourcesContent":["import { promises as fsPromises } from 'node:fs';\nimport type { parseSync } from 'oxc-parser';\nimport { normalizePath } from 'vite';\n\nimport type { ComponentRegistryEntries } from './analog-plugin-interop.js';\nimport {\n collectAllImports,\n collectImportedPackages,\n collectReExports,\n scanFile,\n scanPackageDts,\n type ComponentRegistry,\n type RegistryEntry,\n} from './compiler/index.js';\nimport { parseOxc } from './compiler/utils.js';\nimport type {\n FastCompileResolve,\n FastCompileSourceFormat,\n} from './fast-compile-api.js';\nimport { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX } from './utils/plugin-config.js';\n\ntype OxcProgram = ReturnType<typeof parseSync>['program'];\n\n/** Resolves an import to a source file to scan, or `null` to skip it. */\nexport type ResolveImport = (\n spec: string,\n importer: string,\n) => Promise<string | null>;\n\n/**\n * Angular classes scanned from source files and package `.d.ts` declarations,\n * so source formats can look up the selectors of the components they import\n * before any compiler sees their modules. Shared by the fast compile and NGP\n * plugins.\n */\nexport class ComponentScanner {\n readonly registry: ComponentRegistry = new Map();\n readonly scannedDtsPackages: Set<string> = new Set();\n /** Files scanned on demand, mapped to the barrel chain each pulled in. */\n readonly lazyScans: Map<string, Promise<Set<string>>> = new Map();\n /** Modules compiled against each scanned file. */\n readonly importersByFile: Map<string, Set<string>> = new Map();\n private readonly sourceFormats: FastCompileSourceFormat[] = [];\n private root = '';\n\n /** Where package declarations are looked up from. */\n get projectRoot(): string {\n return this.root;\n }\n\n reset(projectRoot: string): void {\n this.root = projectRoot;\n this.registry.clear();\n this.scannedDtsPackages.clear();\n this.lazyScans.clear();\n this.importersByFile.clear();\n }\n\n registerSourceFormat(format: FastCompileSourceFormat): void {\n if (!this.sourceFormats.includes(format)) {\n this.sourceFormats.push(format);\n }\n }\n\n sourceFormatOf(file: string): FastCompileSourceFormat | undefined {\n const path = file.split('?')[0];\n return this.sourceFormats.find((format) => format.test(path));\n }\n\n /** Whether `file` is TypeScript or a module of a registered source format. */\n isCompiledSource(file: string): boolean {\n return TS_EXT_REGEX.test(file) || this.sourceFormatOf(file) !== undefined;\n }\n\n /**\n * Reads a source file for scanning. Modules of a registered source format\n * are converted to TypeScript first so the scanner sees their classes.\n */\n async readScanSource(file: string): Promise<string> {\n const code = await fsPromises.readFile(file, 'utf-8');\n const format = this.sourceFormatOf(file);\n return format ? format.toScanSource(code, file) : code;\n }\n\n /**\n * Adapts a Vite-style resolver to the scanner's: only source files this\n * scanner reads, outside `node_modules` (package declarations come from the\n * `.d.ts` scanner instead).\n */\n toResolveImport(resolve: FastCompileResolve): ResolveImport {\n return async (spec, importer) => {\n const resolved = await resolve(spec, importer);\n if (!resolved || resolved.external) return null;\n const file = normalizePath(resolved.id.split('?')[0]);\n return this.isCompiledSource(file) &&\n !EXCLUDED_TS_EXT_REGEX.test(file) &&\n !file.includes('/node_modules/')\n ? file\n : null;\n };\n }\n\n /** Scans the `.d.ts` declarations of `packages` into the registry, once each. */\n ensureDtsRegistryForPackages(packages: Iterable<string>): void {\n for (const pkg of packages) {\n if (this.scannedDtsPackages.has(pkg)) continue;\n this.scannedDtsPackages.add(pkg);\n try {\n const dtsEntries = scanPackageDts(\n pkg,\n // Before a tsconfig resolves, look up packages from the working directory.\n this.root || process.cwd(),\n this.scannedDtsPackages,\n );\n for (const entry of dtsEntries) {\n this.addEntry(entry);\n }\n } catch {\n // Package may not have .d.ts files or may not be Angular\n }\n }\n }\n\n ensureDtsRegistryForSource(\n code: string,\n id: string,\n program?: OxcProgram,\n ): void {\n this.ensureDtsRegistryForPackages(\n collectImportedPackages(code, id, program),\n );\n }\n\n /**\n * Scans the modules behind `specifiers`, imported by `importer`: packages\n * from their `.d.ts` declarations, everything else from source.\n */\n scanImports(\n specifiers: string[],\n importer: string,\n resolve: FastCompileResolve,\n ): Promise<void> {\n this.ensureDtsRegistryForPackages(\n specifiers\n .filter((spec) => !spec.startsWith('.') && !spec.startsWith('/'))\n .map((spec) => {\n const parts = spec.split('/');\n return spec.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];\n }),\n );\n return this.resolveImportSpecifiers(\n specifiers,\n importer,\n this.toResolveImport(resolve),\n );\n }\n\n /**\n * Scans the files behind `specs`, imported by `id`, into the registry and\n * records `id` as their importer.\n */\n async resolveImportSpecifiers(\n specs: string[],\n id: string,\n resolveImport: ResolveImport,\n ): Promise<void> {\n await Promise.all(\n specs.map(async (spec) => {\n const file = await resolveImport(spec, id);\n if (!file) return;\n for (const scanned of await this.scanOnDemand(file, resolveImport)) {\n let importers = this.importersByFile.get(scanned);\n if (!importers) {\n importers = new Set();\n this.importersByFile.set(scanned, importers);\n }\n importers.add(id);\n }\n }),\n );\n }\n\n /**\n * The element selector of a component or directive class. `external` are\n * registries contributed through `analog.setup()`.\n */\n lookupSelector(\n className: string,\n external: readonly ComponentRegistryEntries[] = [],\n ): string | null {\n const entry =\n this.registry.get(className) ??\n external.map((r) => r.get(className)).find((e) => e !== undefined);\n if (!entry || (entry.kind !== 'component' && entry.kind !== 'directive')) {\n return null;\n }\n return entry.selector;\n }\n\n /** The files scanned for `importer`. */\n dependenciesOf(importer: string): string[] {\n return [...this.importersByFile]\n .filter(([, importers]) => importers.has(importer))\n .map(([file]) => file);\n }\n\n entriesOf(file: string): RegistryEntry[] {\n return [...this.registry.values()].filter((e) => e.fileName === file);\n }\n\n /** Drops what was scanned from `file`, so the next scan reads it again. */\n invalidate(file: string): void {\n for (const entry of this.entriesOf(file)) {\n this.registry.delete(entry.className);\n }\n this.lazyScans.clear();\n }\n\n private addEntry(entry: RegistryEntry): void {\n if (!this.registry.has(entry.className)) {\n this.registry.set(entry.className, entry);\n }\n }\n\n private scanOnDemand(\n file: string,\n resolveImport: ResolveImport,\n ): Promise<Set<string>> {\n let scan = this.lazyScans.get(file);\n if (!scan) {\n scan = this.scanWithReExports(file, resolveImport);\n this.lazyScans.set(file, scan);\n }\n return scan;\n }\n\n /**\n * Scan a file and everything it re-exports, resolving specifiers through\n * Vite so path aliases work. Tuple barrels and NgModules can list classes\n * their file imports without re-exporting, so their imports are followed\n * too. Returns every file scanned.\n */\n private async scanWithReExports(\n file: string,\n resolveImport: ResolveImport,\n ): Promise<Set<string>> {\n const visited = new Set<string>();\n const visit = async (current: string): Promise<void> => {\n if (visited.has(current)) return;\n visited.add(current);\n let code: string;\n let program: OxcProgram;\n try {\n code = await this.readScanSource(current);\n program = parseOxc(current, code).program;\n } catch {\n return;\n }\n const entries = scanFile(code, current, program);\n for (const entry of entries) {\n this.addEntry(entry);\n }\n this.ensureDtsRegistryForSource(code, current, program);\n const followsImports = entries.some(\n (e) => e.kind === 'tuple' || e.kind === 'ngmodule',\n );\n const specifiers = followsImports\n ? collectAllImports(code, current, program)\n : collectReExports(code, current, program);\n for (const spec of specifiers) {\n const dep = await resolveImport(spec, current);\n if (dep) await visit(dep);\n }\n };\n await visit(file);\n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C/C,KAAK,MAAM,SAAS,SAClB,KAAK,SAAS,KAAK;GAErB,KAAK,2BAA2B,MAAM,SAAS,OAAO;GAItD,MAAM,aAHiB,QAAQ,MAC5B,MAAM,EAAE,SAAS,WAAW,EAAE,SAAS,UAEvB,IACf,kBAAkB,MAAM,SAAS,OAAO,IACxC,iBAAiB,MAAM,SAAS,OAAO;GAC3C,KAAK,MAAM,QAAQ,YAAY;IAC7B,MAAM,MAAM,MAAM,cAAc,MAAM,OAAO;IAC7C,IAAI,KAAK,MAAM,MAAM,GAAG;GAC1B;EACF;EACA,MAAM,MAAM,IAAI;EAChB,OAAO;CACT;AACF"}
@@ -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"}