@analogjs/vite-plugin-angular 3.0.0-alpha.7 → 3.0.0-alpha.9

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 (54) hide show
  1. package/package.json +7 -9
  2. package/setup-vitest.js +154 -193
  3. package/setup-vitest.js.map +1 -1
  4. package/src/index.d.ts +1 -1
  5. package/src/index.js +6 -2
  6. package/src/index.js.map +1 -1
  7. package/src/lib/angular-build-optimizer-plugin.js +48 -62
  8. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  9. package/src/lib/angular-jit-plugin.js +31 -37
  10. package/src/lib/angular-jit-plugin.js.map +1 -1
  11. package/src/lib/angular-pending-tasks.plugin.js +17 -18
  12. package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
  13. package/src/lib/angular-vite-plugin.js +790 -1076
  14. package/src/lib/angular-vite-plugin.js.map +1 -1
  15. package/src/lib/angular-vitest-plugin.d.ts +16 -12
  16. package/src/lib/angular-vitest-plugin.js +97 -114
  17. package/src/lib/angular-vitest-plugin.js.map +1 -1
  18. package/src/lib/compiler-plugin.js +40 -44
  19. package/src/lib/compiler-plugin.js.map +1 -1
  20. package/src/lib/component-resolvers.d.ts +4 -2
  21. package/src/lib/component-resolvers.js +93 -64
  22. package/src/lib/component-resolvers.js.map +1 -1
  23. package/src/lib/host.js +69 -101
  24. package/src/lib/host.js.map +1 -1
  25. package/src/lib/live-reload-plugin.js +51 -63
  26. package/src/lib/live-reload-plugin.js.map +1 -1
  27. package/src/lib/nx-folder-plugin.js +18 -16
  28. package/src/lib/nx-folder-plugin.js.map +1 -1
  29. package/src/lib/plugins/file-replacements.plugin.js +35 -62
  30. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  31. package/src/lib/router-plugin.js +23 -23
  32. package/src/lib/router-plugin.js.map +1 -1
  33. package/src/lib/tools/package.json +2 -5
  34. package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -38
  35. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  36. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +52 -60
  37. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  38. package/src/lib/tools/src/index.js +0 -2
  39. package/src/lib/utils/devkit.js +34 -38
  40. package/src/lib/utils/devkit.js.map +1 -1
  41. package/src/lib/utils/rolldown.d.ts +2 -0
  42. package/src/lib/utils/rolldown.js +12 -0
  43. package/src/lib/utils/rolldown.js.map +1 -0
  44. package/src/lib/utils/source-file-cache.js +35 -37
  45. package/src/lib/utils/source-file-cache.js.map +1 -1
  46. package/README.md +0 -91
  47. package/src/lib/models.js +0 -1
  48. package/src/lib/models.js.map +0 -1
  49. package/src/lib/tools/README.md +0 -3
  50. package/src/lib/tools/src/index.js.map +0 -1
  51. package/src/lib/utils/compiler-plugin-options.js +0 -1
  52. package/src/lib/utils/compiler-plugin-options.js.map +0 -1
  53. package/src/lib/utils/hmr-candidates.js +0 -272
  54. package/src/lib/utils/hmr-candidates.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"dev-server.impl.js","sourceRoot":"","sources":["../../../../../../../../../packages/vite-plugin-angular-tools/src/builders/vite-dev-server/dev-server.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AAInC,KAAK,UAAU,oBAAoB,CACjC,OAA4B,EAC5B,OAAuB;IAEvB,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC;IACnE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,C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ACzC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,EAAE;SAC/B,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,EAAE;SACZ,CAAC;IACJ,CAAC;AACH,CAAC;AAED,qBAAqB;AACrB,KAAK,UAAU,gBAAgB,CAAC,MAA2B;IACzD,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;IAEtB,MAAM,CAAC,SAAS,EAAE,CAAC;IAEnB,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE;QAC/B,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC,CAAC;IAEF,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AACtC,CAAC;AAED,eAAe,aAAa,CAAC,oBAAoB,CAAQ,CAAC"}
1
+ {"version":3,"file":"dev-server.impl.js","names":[],"sources":["../../../../../../../../../packages/vite-plugin-angular-tools/src/builders/vite-dev-server/dev-server.impl.ts"],"sourcesContent":["import {\n BuilderContext,\n BuilderOutput,\n createBuilder,\n targetFromTargetString,\n} from '@angular-devkit/architect';\nimport type { InlineConfig } from 'vite';\nimport { ViteDevServerSchema } from './schema';\n\nasync function viteDevServerBuilder(\n options: ViteDevServerSchema,\n context: BuilderContext,\n): Promise<BuilderOutput> {\n const { createServer } = await Function('return import(\"vite\")')();\n if (!context.target) {\n throw new Error('Builder must be executed with a target');\n }\n const projectConfig = await context.getProjectMetadata(context.target);\n const projectName = context.target.project;\n const buildTargetSpecifier = options.buildTarget ?? `::development`;\n const buildTarget = targetFromTargetString(\n buildTargetSpecifier,\n projectName,\n 'build',\n );\n\n const browserBuilderName = await context.getBuilderNameForTarget(buildTarget);\n const rawBuildOptions = await context.getTargetOptions(buildTarget);\n const buildOptions = await context.validateOptions(\n rawBuildOptions,\n browserBuilderName,\n );\n\n const serverConfig: InlineConfig = {\n configFile: buildOptions.configFile as string,\n root: projectConfig.root as string,\n mode: (process.env.NODE_ENV ??\n buildOptions.mode ??\n 'development') as string,\n build: {\n sourcemap: !!buildOptions.sourcemap,\n },\n server: {\n hmr: options?.hmr,\n port: options?.port,\n },\n };\n\n try {\n const server = await createServer(serverConfig);\n await runViteDevServer(server);\n const resolvedUrls = [\n ...server.resolvedUrls.local,\n ...server.resolvedUrls.network,\n ];\n\n await new Promise<void>((resolve) => {\n process.once('SIGINT', () => resolve());\n process.once('SIGTERM', () => resolve());\n process.once('exit', () => resolve());\n });\n\n return {\n success: true,\n baseUrl: resolvedUrls[0] ?? '',\n };\n } catch (e) {\n console.error(e);\n return {\n success: false,\n baseUrl: '',\n };\n }\n}\n\n// vite ViteDevServer\nasync function runViteDevServer(server: Record<string, any>): Promise<void> {\n await server.listen();\n\n server.printUrls();\n\n const processOnExit = async () => {\n await server.close();\n };\n\n process.once('SIGINT', processOnExit);\n process.once('SIGTERM', processOnExit);\n process.once('exit', processOnExit);\n}\n\nexport default createBuilder(viteDevServerBuilder) as any;\n"],"mappings":";;AASA,eAAe,qBACb,SACA,SACwB;CACxB,MAAM,EAAE,iBAAiB,MAAM,SAAS,0BAAwB,EAAE;AAClE,KAAI,CAAC,QAAQ,OACX,OAAM,IAAI,MAAM,yCAAyC;CAE3D,MAAM,gBAAgB,MAAM,QAAQ,mBAAmB,QAAQ,OAAO;CACtE,MAAM,cAAc,QAAQ,OAAO;CAEnC,MAAM,cAAc,uBADS,QAAQ,eAAe,iBAGlD,aACA,QACD;CAED,MAAM,qBAAqB,MAAM,QAAQ,wBAAwB,YAAY;CAC7E,MAAM,kBAAkB,MAAM,QAAQ,iBAAiB,YAAY;CACnE,MAAM,eAAe,MAAM,QAAQ,gBACjC,iBACA,mBACD;CAED,MAAM,eAA6B;EACjC,YAAY,aAAa;EACzB,MAAM,cAAc;EACpB,MAAA,QAAA,IAAA,YACE,aAAa,QACb;EACF,OAAO,EACL,WAAW,CAAC,CAAC,aAAa,WAC3B;EACD,QAAQ;GACN,KAAK,SAAS;GACd,MAAM,SAAS;GAChB;EACF;AAED,KAAI;EACF,MAAM,SAAS,MAAM,aAAa,aAAa;AAC/C,QAAM,iBAAiB,OAAO;EAC9B,MAAM,eAAe,CACnB,GAAG,OAAO,aAAa,OACvB,GAAG,OAAO,aAAa,QACxB;AAED,QAAM,IAAI,SAAe,YAAY;AACnC,WAAQ,KAAK,gBAAgB,SAAS,CAAC;AACvC,WAAQ,KAAK,iBAAiB,SAAS,CAAC;AACxC,WAAQ,KAAK,cAAc,SAAS,CAAC;IACrC;AAEF,SAAO;GACL,SAAS;GACT,SAAS,aAAa,MAAM;GAC7B;UACM,GAAG;AACV,UAAQ,MAAM,EAAE;AAChB,SAAO;GACL,SAAS;GACT,SAAS;GACV;;;AAKL,eAAe,iBAAiB,QAA4C;AAC1E,OAAM,OAAO,QAAQ;AAErB,QAAO,WAAW;CAElB,MAAM,gBAAgB,YAAY;AAChC,QAAM,OAAO,OAAO;;AAGtB,SAAQ,KAAK,UAAU,cAAc;AACrC,SAAQ,KAAK,WAAW,cAAc;AACtC,SAAQ,KAAK,QAAQ,cAAc;;AAGrC,IAAA,0BAAe,cAAc,qBAAqB"}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=index.js.map
@@ -1,41 +1,37 @@
1
- import { VERSION } from '@angular/compiler-cli';
2
- import { createRequire } from 'node:module';
3
- import * as sfc from './source-file-cache.js';
4
- const require = createRequire(import.meta.url);
5
- const angularMajor = Number(VERSION.major);
6
- const angularMinor = Number(VERSION.minor);
7
- const angularPatch = Number(VERSION.patch);
8
- const padVersion = (version) => String(version).padStart(2, '0');
9
- const angularFullVersion = Number(`${angularMajor}${padVersion(angularMinor)}${padVersion(angularPatch)}`);
10
- let sourceFileCache;
11
- let cjt;
12
- let jt;
13
- let createAngularCompilation;
14
- if (angularMajor < 17) {
15
- throw new Error('AnalogJS is not compatible with Angular v16 and lower');
16
- }
1
+ import { SourceFileCache } from "./source-file-cache.js";
2
+ import { VERSION } from "@angular/compiler-cli";
3
+ import { createRequire } from "node:module";
4
+ //#region packages/vite-plugin-angular/src/lib/utils/devkit.ts
5
+ var require = createRequire(import.meta.url);
6
+ var angularMajor = Number(VERSION.major);
7
+ var angularMinor = Number(VERSION.minor);
8
+ var angularPatch = Number(VERSION.patch);
9
+ var padVersion = (version) => String(version).padStart(2, "0");
10
+ var angularFullVersion = Number(`${angularMajor}${padVersion(angularMinor)}${padVersion(angularPatch)}`);
11
+ var sourceFileCache;
12
+ var cjt;
13
+ var jt;
14
+ var createAngularCompilation;
15
+ if (angularMajor < 17) throw new Error("AnalogJS is not compatible with Angular v16 and lower");
17
16
  else if (angularMajor >= 17 && angularMajor < 18) {
18
- const cp = require('@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin.js');
19
- const { createJitResourceTransformer, } = require('@angular-devkit/build-angular/src/tools/esbuild/angular/jit-resource-transformer.js');
20
- const { JavaScriptTransformer, } = require('@angular-devkit/build-angular/src/tools/esbuild/javascript-transformer.js');
21
- /**
22
- * Workaround for compatibility with Angular 17.0+
23
- */
24
- if (typeof cp['SourceFileCache'] !== 'undefined') {
25
- sourceFileCache = cp.SourceFileCache;
26
- }
27
- else {
28
- sourceFileCache = sfc.SourceFileCache;
29
- }
30
- cjt = createJitResourceTransformer;
31
- jt = JavaScriptTransformer;
32
- }
33
- else {
34
- const { createJitResourceTransformer, JavaScriptTransformer, SourceFileCache, createAngularCompilation: createAngularCompilationFn, } = require('@angular/build/private');
35
- sourceFileCache = SourceFileCache;
36
- cjt = createJitResourceTransformer;
37
- jt = JavaScriptTransformer;
38
- createAngularCompilation = createAngularCompilationFn;
17
+ const cp = require("@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin.js");
18
+ const { createJitResourceTransformer } = require("@angular-devkit/build-angular/src/tools/esbuild/angular/jit-resource-transformer.js");
19
+ const { JavaScriptTransformer } = require("@angular-devkit/build-angular/src/tools/esbuild/javascript-transformer.js");
20
+ /**
21
+ * Workaround for compatibility with Angular 17.0+
22
+ */
23
+ if (typeof cp["SourceFileCache"] !== "undefined") sourceFileCache = cp.SourceFileCache;
24
+ else sourceFileCache = SourceFileCache;
25
+ cjt = createJitResourceTransformer;
26
+ jt = JavaScriptTransformer;
27
+ } else {
28
+ const { createJitResourceTransformer, JavaScriptTransformer, SourceFileCache, createAngularCompilation: createAngularCompilationFn } = require("@angular/build/private");
29
+ sourceFileCache = SourceFileCache;
30
+ cjt = createJitResourceTransformer;
31
+ jt = JavaScriptTransformer;
32
+ createAngularCompilation = createAngularCompilationFn;
39
33
  }
40
- export { cjt as createJitResourceTransformer, jt as JavaScriptTransformer, sourceFileCache as SourceFileCache, angularMajor, angularMinor, angularPatch, createAngularCompilation, angularFullVersion, };
34
+ //#endregion
35
+ export { angularFullVersion, cjt, createAngularCompilation, jt, sourceFileCache };
36
+
41
37
  //# sourceMappingURL=devkit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"devkit.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/devkit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,GAAG,MAAM,wBAAwB,CAAC;AAE9C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,YAAY,GAAW,MAAM,CAAC,O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,EACf,wBAAwB,EAAE,0BAA0B,GACrD,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAEtC,eAAe,GAAG,eAAe,CAAC;IAClC,GAAG,GAAG,4BAA4B,CAAC;IACnC,EAAE,GAAG,qBAAqB,CAAC;IAC3B,wBAAwB,GAAG,0BAA0B,CAAC;AACxD,CAAC;AAED,OAAO,EACL,GAAG,IAAI,4BAA4B,EACnC,EAAE,IAAI,qBAAqB,EAC3B,eAAe,IAAI,eAAe,EAElC,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,wBAAwB,EACxB,kBAAkB,GACnB,CAAC"}
1
+ {"version":3,"file":"devkit.js","names":[],"sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/devkit.ts"],"sourcesContent":["import { VERSION } from '@angular/compiler-cli';\nimport { createRequire } from 'node:module';\nimport type { CompilerPluginOptions } from './compiler-plugin-options.js';\nimport * as sfc from './source-file-cache.js';\n\nconst require = createRequire(import.meta.url);\n\nconst angularMajor: number = Number(VERSION.major);\nconst angularMinor: number = Number(VERSION.minor);\nconst angularPatch: number = Number(VERSION.patch);\nconst padVersion = (version: number) => String(version).padStart(2, '0');\nconst angularFullVersion: number = Number(\n `${angularMajor}${padVersion(angularMinor)}${padVersion(angularPatch)}`,\n);\nlet sourceFileCache: any;\nlet cjt: (...args: any[]) => any;\nlet jt: any;\nlet createAngularCompilation: (...args: any[]) => any;\n\nif (angularMajor < 17) {\n throw new Error('AnalogJS is not compatible with Angular v16 and lower');\n} else if (angularMajor >= 17 && angularMajor < 18) {\n const cp = require('@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin.js');\n const {\n createJitResourceTransformer,\n } = require('@angular-devkit/build-angular/src/tools/esbuild/angular/jit-resource-transformer.js');\n const {\n JavaScriptTransformer,\n } = require('@angular-devkit/build-angular/src/tools/esbuild/javascript-transformer.js');\n\n /**\n * Workaround for compatibility with Angular 17.0+\n */\n if (typeof cp['SourceFileCache'] !== 'undefined') {\n sourceFileCache = cp.SourceFileCache;\n } else {\n sourceFileCache = sfc.SourceFileCache;\n }\n\n cjt = createJitResourceTransformer;\n jt = JavaScriptTransformer;\n} else {\n const {\n createJitResourceTransformer,\n JavaScriptTransformer,\n SourceFileCache,\n createAngularCompilation: createAngularCompilationFn,\n } = require('@angular/build/private');\n\n sourceFileCache = SourceFileCache;\n cjt = createJitResourceTransformer;\n jt = JavaScriptTransformer;\n createAngularCompilation = createAngularCompilationFn;\n}\n\nexport {\n cjt as createJitResourceTransformer,\n jt as JavaScriptTransformer,\n sourceFileCache as SourceFileCache,\n CompilerPluginOptions,\n angularMajor,\n angularMinor,\n angularPatch,\n createAngularCompilation,\n angularFullVersion,\n};\n"],"mappings":";;;;AAKA,IAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAE9C,IAAM,eAAuB,OAAO,QAAQ,MAAM;AAClD,IAAM,eAAuB,OAAO,QAAQ,MAAM;AAClD,IAAM,eAAuB,OAAO,QAAQ,MAAM;AAClD,IAAM,cAAc,YAAoB,OAAO,QAAQ,CAAC,SAAS,GAAG,IAAI;AACxE,IAAM,qBAA6B,OACjC,GAAG,eAAe,WAAW,aAAa,GAAG,WAAW,aAAa,GACtE;AACD,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAI;AAEJ,IAAI,eAAe,GACjB,OAAM,IAAI,MAAM,wDAAwD;SAC/D,gBAAgB,MAAM,eAAe,IAAI;CAClD,MAAM,KAAK,QAAQ,6EAA6E;CAChG,MAAM,EACJ,iCACE,QAAQ,sFAAsF;CAClG,MAAM,EACJ,0BACE,QAAQ,4EAA4E;;;;AAKxF,KAAI,OAAO,GAAG,uBAAuB,YACnC,mBAAkB,GAAG;KAErB,mBAAkB;AAGpB,OAAM;AACN,MAAK;OACA;CACL,MAAM,EACJ,8BACA,uBACA,iBACA,0BAA0B,+BACxB,QAAQ,yBAAyB;AAErC,mBAAkB;AAClB,OAAM;AACN,MAAK;AACL,4BAA2B"}
@@ -0,0 +1,2 @@
1
+ export declare function isRolldown(): boolean;
2
+ export declare function getJsTransformConfigKey(): 'oxc' | 'esbuild';
@@ -0,0 +1,12 @@
1
+ import * as vite from "vite";
2
+ //#region packages/vite-plugin-angular/src/lib/utils/rolldown.ts
3
+ function isRolldown() {
4
+ return !!vite.rolldownVersion;
5
+ }
6
+ function getJsTransformConfigKey() {
7
+ return isRolldown() ? "oxc" : "esbuild";
8
+ }
9
+ //#endregion
10
+ export { getJsTransformConfigKey, isRolldown };
11
+
12
+ //# sourceMappingURL=rolldown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rolldown.js","names":[],"sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/rolldown.ts"],"sourcesContent":["import * as vite from 'vite';\n\nexport function isRolldown(): boolean {\n return !!vite.rolldownVersion;\n}\n\nexport function getJsTransformConfigKey(): 'oxc' | 'esbuild' {\n return isRolldown() ? 'oxc' : 'esbuild';\n}\n"],"mappings":";;AAEA,SAAgB,aAAsB;AACpC,QAAO,CAAC,CAAC,KAAK;;AAGhB,SAAgB,0BAA6C;AAC3D,QAAO,YAAY,GAAG,QAAQ"}
@@ -1,39 +1,37 @@
1
+ import * as path$1 from "node:path";
2
+ import { platform } from "node:os";
3
+ import { pathToFileURL } from "node:url";
4
+ //#region packages/vite-plugin-angular/src/lib/utils/source-file-cache.ts
1
5
  /**
2
- * @license
3
- * Copyright Google LLC All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
- import { platform } from 'node:os';
9
- import * as path from 'node:path';
10
- import { pathToFileURL } from 'node:url';
11
- const USING_WINDOWS = platform() === 'win32';
12
- const WINDOWS_SEP_REGEXP = new RegExp(`\\${path.win32.sep}`, 'g');
13
- export class SourceFileCache extends Map {
14
- persistentCachePath;
15
- modifiedFiles = new Set();
16
- babelFileCache = new Map();
17
- typeScriptFileCache = new Map();
18
- referencedFiles;
19
- constructor(persistentCachePath) {
20
- super();
21
- this.persistentCachePath = persistentCachePath;
22
- }
23
- invalidate(files) {
24
- if (files !== this.modifiedFiles) {
25
- this.modifiedFiles.clear();
26
- }
27
- for (let file of files) {
28
- this.babelFileCache.delete(file);
29
- this.typeScriptFileCache.delete(pathToFileURL(file).href);
30
- // Normalize separators to allow matching TypeScript Host paths
31
- if (USING_WINDOWS) {
32
- file = file.replace(WINDOWS_SEP_REGEXP, path.posix.sep);
33
- }
34
- this.delete(file);
35
- this.modifiedFiles.add(file);
36
- }
37
- }
38
- }
6
+ * @license
7
+ * Copyright Google LLC All Rights Reserved.
8
+ *
9
+ * Use of this source code is governed by an MIT-style license that can be
10
+ * found in the LICENSE file at https://angular.io/license
11
+ */
12
+ var USING_WINDOWS = platform() === "win32";
13
+ var WINDOWS_SEP_REGEXP = new RegExp(`\\${path$1.win32.sep}`, "g");
14
+ var SourceFileCache = class extends Map {
15
+ modifiedFiles = /* @__PURE__ */ new Set();
16
+ babelFileCache = /* @__PURE__ */ new Map();
17
+ typeScriptFileCache = /* @__PURE__ */ new Map();
18
+ referencedFiles;
19
+ constructor(persistentCachePath) {
20
+ super();
21
+ this.persistentCachePath = persistentCachePath;
22
+ }
23
+ invalidate(files) {
24
+ if (files !== this.modifiedFiles) this.modifiedFiles.clear();
25
+ for (let file of files) {
26
+ this.babelFileCache.delete(file);
27
+ this.typeScriptFileCache.delete(pathToFileURL(file).href);
28
+ if (USING_WINDOWS) file = file.replace(WINDOWS_SEP_REGEXP, path$1.posix.sep);
29
+ this.delete(file);
30
+ this.modifiedFiles.add(file);
31
+ }
32
+ }
33
+ };
34
+ //#endregion
35
+ export { SourceFileCache };
36
+
39
37
  //# sourceMappingURL=source-file-cache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"source-file-cache.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/source-file-cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK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plugin-angular/src/lib/utils/source-file-cache.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport { platform } from 'node:os';\nimport * as path from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type ts from 'typescript';\n\nconst USING_WINDOWS = platform() === 'win32';\nconst WINDOWS_SEP_REGEXP = new RegExp(`\\\\${path.win32.sep}`, 'g');\n\nexport class SourceFileCache extends Map<string, ts.SourceFile> {\n readonly modifiedFiles: Set<string> = new Set<string>();\n readonly babelFileCache: Map<string, Uint8Array> = new Map<\n string,\n Uint8Array\n >();\n readonly typeScriptFileCache: Map<string, string | Uint8Array> = new Map<\n string,\n string | Uint8Array\n >();\n\n referencedFiles?: readonly string[];\n\n constructor(readonly persistentCachePath?: string) {\n super();\n }\n\n invalidate(files: Iterable<string>): void {\n if (files !== this.modifiedFiles) {\n this.modifiedFiles.clear();\n }\n for (let file of files) {\n this.babelFileCache.delete(file);\n this.typeScriptFileCache.delete(pathToFileURL(file).href);\n\n // Normalize separators to allow matching TypeScript Host paths\n if (USING_WINDOWS) {\n file = file.replace(WINDOWS_SEP_REGEXP, path.posix.sep);\n }\n\n this.delete(file);\n this.modifiedFiles.add(file);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAaA,IAAM,gBAAgB,UAAU,KAAK;AACrC,IAAM,qBAAqB,IAAI,OAAO,KAAK,OAAK,MAAM,OAAO,IAAI;AAEjE,IAAa,kBAAb,cAAqC,IAA2B;CAC9D,gCAAsC,IAAI,KAAa;CACvD,iCAAmD,IAAI,KAGpD;CACH,sCAAiE,IAAI,KAGlE;CAEH;CAEA,YAAY,qBAAuC;AACjD,SAAO;AADY,OAAA,sBAAA;;CAIrB,WAAW,OAA+B;AACxC,MAAI,UAAU,KAAK,cACjB,MAAK,cAAc,OAAO;AAE5B,OAAK,IAAI,QAAQ,OAAO;AACtB,QAAK,eAAe,OAAO,KAAK;AAChC,QAAK,oBAAoB,OAAO,cAAc,KAAK,CAAC,KAAK;AAGzD,OAAI,cACF,QAAO,KAAK,QAAQ,oBAAoB,OAAK,MAAM,IAAI;AAGzD,QAAK,OAAO,KAAK;AACjB,QAAK,cAAc,IAAI,KAAK"}
package/README.md DELETED
@@ -1,91 +0,0 @@
1
- # @analogjs/vite-plugin-angular
2
-
3
- A Vite plugin for building Angular applications
4
-
5
- ## Install
6
-
7
- With npm:
8
-
9
- ```sh
10
- npm install @analogjs/vite-plugin-angular --save-dev
11
- ```
12
-
13
- With pnpm:
14
-
15
- ```sh
16
- pnpm install @analogjs/vite-plugin-angular --save-dev
17
- ```
18
-
19
- With yarn:
20
-
21
- ```sh
22
- yarn install @analogjs/vite-plugin-angular --dev
23
- ```
24
-
25
- With bun:
26
-
27
- ```sh
28
- bun install @analogjs/vite-plugin-angular --dev
29
- ```
30
-
31
- ## Setup
32
-
33
- Add the plugin to the `plugins` array in your Vite config
34
-
35
- ```ts
36
- import { defineConfig } from 'vite';
37
- import angular from '@analogjs/vite-plugin-angular';
38
-
39
- // https://vitejs.dev/config/
40
- export default defineConfig({
41
- resolve: {
42
- mainFields: ['module'],
43
- },
44
-
45
- plugins: [angular()],
46
- });
47
- ```
48
-
49
- > The `angular` plugin should be listed **first** in the plugins array.
50
-
51
- ## Setting up the TypeScript config
52
-
53
- The integration needs a `tsconfig.app.json` at the root of the project for compilation.
54
-
55
- Create a `tsconfig.app.json` in the root of the project.
56
-
57
- ```json
58
- {
59
- "extends": "./tsconfig.json",
60
- "compileOnSave": false,
61
- "compilerOptions": {
62
- "baseUrl": "./",
63
- "outDir": "./dist/out-tsc",
64
- "forceConsistentCasingInFileNames": true,
65
- "strict": true,
66
- "noImplicitOverride": true,
67
- "noPropertyAccessFromIndexSignature": true,
68
- "noImplicitReturns": true,
69
- "noFallthroughCasesInSwitch": true,
70
- "sourceMap": true,
71
- "declaration": false,
72
- "downlevelIteration": true,
73
- "experimentalDecorators": true,
74
- "moduleResolution": "node",
75
- "importHelpers": true,
76
- "noEmit": false,
77
- "target": "es2020",
78
- "module": "es2020",
79
- "lib": ["es2020", "dom"],
80
- "skipLibCheck": true
81
- },
82
- "angularCompilerOptions": {
83
- "enableI18nLegacyMessageIdFormat": false,
84
- "strictInjectionParameters": true,
85
- "strictInputAccessModifiers": true,
86
- "strictTemplates": true
87
- },
88
- "files": [],
89
- "include": ["src/**/*.ts"]
90
- }
91
- ```
package/src/lib/models.js DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=models.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/models.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- # @analogjs/vite-plugin-angular-tools
2
-
3
- Builders & Schematics for the `@analogjs/vite-plugin-angular` package.
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/vite-plugin-angular-tools/src/index.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=compiler-plugin-options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compiler-plugin-options.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/compiler-plugin-options.ts"],"names":[],"mappings":""}
@@ -1,272 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Google LLC All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.dev/license
7
- */
8
- import assert from 'node:assert';
9
- import ts from 'typescript';
10
- /**
11
- * Analyzes one or more modified files for changes to determine if any
12
- * class declarations for Angular components are candidates for hot
13
- * module replacement (HMR). If any source files are also modified but
14
- * are not candidates then all candidates become invalid. This invalidation
15
- * ensures that a full rebuild occurs and the running application stays
16
- * synchronized with the code.
17
- * @param modifiedFiles A set of modified files to analyze.
18
- * @param param1 An Angular compiler instance
19
- * @param staleSourceFiles A map of paths to previous source file instances.
20
- * @returns A set of HMR candidate component class declarations.
21
- */
22
- export function collectHmrCandidates(modifiedFiles, { compiler }, staleSourceFiles) {
23
- const candidates = new Set();
24
- for (const file of modifiedFiles) {
25
- // If the file is a template for component(s), add component classes as candidates
26
- const templateFileNodes = compiler.getComponentsWithTemplateFile(file);
27
- if (templateFileNodes.size) {
28
- templateFileNodes.forEach((node) => candidates.add(node));
29
- continue;
30
- }
31
- // If the file is a style for component(s), add component classes as candidates
32
- const styleFileNodes = compiler.getComponentsWithStyleFile(file);
33
- if (styleFileNodes.size) {
34
- styleFileNodes.forEach((node) => candidates.add(node));
35
- continue;
36
- }
37
- const staleSource = staleSourceFiles?.get(file);
38
- if (staleSource === undefined) {
39
- // Unknown file requires a rebuild so clear out the candidates and stop collecting
40
- candidates.clear();
41
- break;
42
- }
43
- const updatedSource = compiler.getCurrentProgram().getSourceFile(file);
44
- if (updatedSource === undefined) {
45
- // No longer existing program file requires a rebuild so clear out the candidates and stop collecting
46
- candidates.clear();
47
- break;
48
- }
49
- // Analyze the stale and updated file for changes
50
- const fileCandidates = analyzeFileUpdates(staleSource, updatedSource, compiler);
51
- if (fileCandidates) {
52
- fileCandidates.forEach((node) => candidates.add(node));
53
- }
54
- else {
55
- // Unsupported HMR changes present
56
- // Only template and style literal changes are allowed.
57
- candidates.clear();
58
- break;
59
- }
60
- }
61
- return candidates;
62
- }
63
- /**
64
- * Analyzes the updates of a source file for potential HMR component class candidates.
65
- * A source file can contain candidates if only the Angular component metadata of a class
66
- * has been changed and the metadata changes are only of supported fields.
67
- * @param stale The stale (previous) source file instance.
68
- * @param updated The updated source file instance.
69
- * @param compiler An Angular compiler instance.
70
- * @returns An array of candidate class declarations; or `null` if unsupported changes are present.
71
- */
72
- export function analyzeFileUpdates(stale, updated, compiler) {
73
- if (stale.statements.length !== updated.statements.length) {
74
- return null;
75
- }
76
- const candidates = [];
77
- for (let i = 0; i < updated.statements.length; ++i) {
78
- const updatedNode = updated.statements[i];
79
- const staleNode = stale.statements[i];
80
- if (ts.isClassDeclaration(updatedNode)) {
81
- if (!ts.isClassDeclaration(staleNode)) {
82
- return null;
83
- }
84
- // Check class declaration differences (name/heritage/modifiers)
85
- if (updatedNode.name?.text !== staleNode.name?.text) {
86
- return null;
87
- }
88
- if (!equalRangeText(updatedNode.heritageClauses, updated, staleNode.heritageClauses, stale)) {
89
- return null;
90
- }
91
- const updatedModifiers = ts.getModifiers(updatedNode);
92
- const staleModifiers = ts.getModifiers(staleNode);
93
- if (updatedModifiers?.length !== staleModifiers?.length ||
94
- !updatedModifiers?.every((updatedModifier) => staleModifiers?.some((staleModifier) => updatedModifier.kind === staleModifier.kind))) {
95
- return null;
96
- }
97
- // Check for component class nodes
98
- const meta = compiler?.getMeta(updatedNode);
99
- console.log('meta', stale.fileName, meta);
100
- if (meta?.decorator &&
101
- meta.isComponent === true) {
102
- const updatedDecorators = ts.getDecorators(updatedNode);
103
- const staleDecorators = ts.getDecorators(staleNode);
104
- if (!staleDecorators ||
105
- staleDecorators.length !== updatedDecorators?.length) {
106
- return null;
107
- }
108
- // TODO: Check other decorators instead of assuming all multi-decorator components are unsupported
109
- if (staleDecorators.length > 1) {
110
- return null;
111
- }
112
- // Find index of component metadata decorator
113
- const metaDecoratorIndex = updatedDecorators?.indexOf(meta.decorator);
114
- assert(metaDecoratorIndex !== undefined, 'Component metadata decorator should always be present on component class.');
115
- const updatedDecoratorExpression = meta.decorator.expression;
116
- assert(ts.isCallExpression(updatedDecoratorExpression) &&
117
- updatedDecoratorExpression.arguments.length === 1, 'Component metadata decorator should contain a call expression with a single argument.');
118
- // Check the matching stale index for the component decorator
119
- const staleDecoratorExpression = staleDecorators[metaDecoratorIndex]?.expression;
120
- if (!staleDecoratorExpression ||
121
- !ts.isCallExpression(staleDecoratorExpression) ||
122
- staleDecoratorExpression.arguments.length !== 1) {
123
- return null;
124
- }
125
- // Check decorator name/expression
126
- // NOTE: This would typically be `Component` but can also be a property expression or some other alias.
127
- // To avoid complex checks, this ensures the textual representation does not change. This has a low chance
128
- // of a false positive if the expression is changed to still reference the `Component` type but has different
129
- // text. However, it is rare for `Component` to not be used directly and additionally unlikely that it would
130
- // be changed between edits. A false positive would also only lead to a difference of a full page reload versus
131
- // an HMR update.
132
- if (!equalRangeText(updatedDecoratorExpression.expression, updated, staleDecoratorExpression.expression, stale)) {
133
- return null;
134
- }
135
- // Compare component meta decorator object literals
136
- const analysis = analyzeMetaUpdates(staleDecoratorExpression, stale, updatedDecoratorExpression, updated);
137
- if (analysis === MetaUpdateAnalysis.Unsupported) {
138
- return null;
139
- }
140
- // Compare text of the member nodes to determine if any changes have occurred
141
- if (!equalRangeText(updatedNode.members, updated, staleNode.members, stale)) {
142
- // A change to a member outside a component's metadata is unsupported
143
- return null;
144
- }
145
- // If all previous class checks passed, this class is supported for HMR updates
146
- if (analysis === MetaUpdateAnalysis.Supported) {
147
- candidates.push(updatedNode);
148
- }
149
- continue;
150
- }
151
- }
152
- // Compare text of the statement nodes to determine if any changes have occurred
153
- // TODO: Consider expanding this to check semantic updates for each node kind
154
- if (!equalRangeText(updatedNode, updated, staleNode, stale)) {
155
- // A change to a statement outside a component's metadata is unsupported
156
- return null;
157
- }
158
- }
159
- return candidates;
160
- }
161
- /**
162
- * The set of Angular component metadata fields that are supported by HMR updates.
163
- */
164
- const SUPPORTED_FIELD_NAMES = new Set([
165
- 'template',
166
- 'templateUrl',
167
- 'styles',
168
- 'styleUrl',
169
- 'stylesUrl',
170
- ]);
171
- var MetaUpdateAnalysis;
172
- (function (MetaUpdateAnalysis) {
173
- MetaUpdateAnalysis[MetaUpdateAnalysis["Supported"] = 0] = "Supported";
174
- MetaUpdateAnalysis[MetaUpdateAnalysis["Unsupported"] = 1] = "Unsupported";
175
- MetaUpdateAnalysis[MetaUpdateAnalysis["None"] = 2] = "None";
176
- })(MetaUpdateAnalysis || (MetaUpdateAnalysis = {}));
177
- /**
178
- * Analyzes the metadata fields of a decorator call expression for unsupported HMR updates.
179
- * Only updates to supported fields can be present for HMR to be viable.
180
- * @param staleCall A call expression instance.
181
- * @param staleSource The source file instance containing the stale call instance.
182
- * @param updatedCall A call expression instance.
183
- * @param updatedSource The source file instance containing the updated call instance.
184
- * @returns A MetaUpdateAnalysis enum value.
185
- */
186
- function analyzeMetaUpdates(staleCall, staleSource, updatedCall, updatedSource) {
187
- const staleObject = staleCall.arguments[0];
188
- const updatedObject = updatedCall.arguments[0];
189
- let hasSupportedUpdate = false;
190
- if (!ts.isObjectLiteralExpression(staleObject) ||
191
- !ts.isObjectLiteralExpression(updatedObject)) {
192
- return MetaUpdateAnalysis.Unsupported;
193
- }
194
- const supportedFields = new Map();
195
- const unsupportedFields = [];
196
- for (const property of staleObject.properties) {
197
- if (!ts.isPropertyAssignment(property) ||
198
- ts.isComputedPropertyName(property.name)) {
199
- // Unsupported object literal property
200
- return MetaUpdateAnalysis.Unsupported;
201
- }
202
- const name = property.name.text;
203
- if (SUPPORTED_FIELD_NAMES.has(name)) {
204
- supportedFields.set(name, property.initializer);
205
- continue;
206
- }
207
- unsupportedFields.push(property.initializer);
208
- }
209
- let i = 0;
210
- for (const property of updatedObject.properties) {
211
- if (!ts.isPropertyAssignment(property) ||
212
- ts.isComputedPropertyName(property.name)) {
213
- // Unsupported object literal property
214
- return MetaUpdateAnalysis.Unsupported;
215
- }
216
- const name = property.name.text;
217
- if (SUPPORTED_FIELD_NAMES.has(name)) {
218
- const staleInitializer = supportedFields.get(name);
219
- // If the supported field was added or has its content changed, there has been a supported update
220
- if (!staleInitializer ||
221
- !equalRangeText(property.initializer, updatedSource, staleInitializer, staleSource)) {
222
- hasSupportedUpdate = true;
223
- }
224
- // Remove the field entry to allow tracking removed fields
225
- supportedFields.delete(name);
226
- continue;
227
- }
228
- // Compare in order
229
- if (!equalRangeText(property.initializer, updatedSource, unsupportedFields[i++], staleSource)) {
230
- return MetaUpdateAnalysis.Unsupported;
231
- }
232
- }
233
- if (i !== unsupportedFields.length) {
234
- return MetaUpdateAnalysis.Unsupported;
235
- }
236
- // Any remaining supported field indicates a field removal. This is also considered a supported update.
237
- hasSupportedUpdate ||= supportedFields.size > 0;
238
- return hasSupportedUpdate
239
- ? MetaUpdateAnalysis.Supported
240
- : MetaUpdateAnalysis.None;
241
- }
242
- /**
243
- * Compares the text from a provided range in a source file to the text of a range in a second source file.
244
- * The comparison avoids making any intermediate string copies.
245
- * @param firstRange A text range within the first source file.
246
- * @param firstSource A source file instance.
247
- * @param secondRange A text range within the second source file.
248
- * @param secondSource A source file instance.
249
- * @returns true, if the text from both ranges is equal; false, otherwise.
250
- */
251
- function equalRangeText(firstRange, firstSource, secondRange, secondSource) {
252
- // Check matching undefined values
253
- if (!firstRange || !secondRange) {
254
- return firstRange === secondRange;
255
- }
256
- // Ensure lengths are equal
257
- const firstLength = firstRange.end - firstRange.pos;
258
- const secondLength = secondRange.end - secondRange.pos;
259
- if (firstLength !== secondLength) {
260
- return false;
261
- }
262
- // Check each character
263
- for (let i = 0; i < firstLength; ++i) {
264
- const firstChar = firstSource.text.charCodeAt(i + firstRange.pos);
265
- const secondChar = secondSource.text.charCodeAt(i + secondRange.pos);
266
- if (firstChar !== secondChar) {
267
- return false;
268
- }
269
- }
270
- return true;
271
- }
272
- //# sourceMappingURL=hmr-candidates.js.map