@analogjs/vite-plugin-angular 3.0.0-beta.1 → 3.0.0-beta.10

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 (30) hide show
  1. package/README.md +40 -0
  2. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +13 -2
  3. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
  4. package/package.json +1 -14
  5. package/src/lib/angular-vite-plugin.js +14 -1
  6. package/src/lib/angular-vite-plugin.js.map +1 -1
  7. package/src/lib/compiler/compile.js +5 -2
  8. package/src/lib/compiler/compile.js.map +1 -1
  9. package/src/lib/compiler/dts-reader.d.ts +5 -0
  10. package/src/lib/compiler/dts-reader.js +9 -3
  11. package/src/lib/compiler/dts-reader.js.map +1 -1
  12. package/src/lib/compiler/hmr.d.ts +4 -0
  13. package/src/lib/compiler/hmr.js +7 -2
  14. package/src/lib/compiler/hmr.js.map +1 -1
  15. package/src/lib/compiler/index.d.ts +2 -2
  16. package/src/lib/compiler/index.js +3 -3
  17. package/src/lib/compiler/jit-metadata.d.ts +3 -1
  18. package/src/lib/compiler/jit-metadata.js +10 -8
  19. package/src/lib/compiler/jit-metadata.js.map +1 -1
  20. package/src/lib/compiler/registry.d.ts +6 -0
  21. package/src/lib/compiler/registry.js +21 -1
  22. package/src/lib/compiler/registry.js.map +1 -1
  23. package/src/lib/fast-compile-plugin.js +97 -15
  24. package/src/lib/fast-compile-plugin.js.map +1 -1
  25. package/src/lib/tools/src/builders/vite/vite-build.impl.js +2 -1
  26. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  27. package/migrations/migrations.json +0 -9
  28. package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +0 -2
  29. package/migrations/update-3-0-0/migrate-setup-vitest.js +0 -37
  30. package/migrations/update-3-0-0/migrate-setup-vitest.js.map +0 -1
package/README.md CHANGED
@@ -50,6 +50,46 @@ export default defineConfig({
50
50
 
51
51
  > The `angular` plugin should be listed **first** in the plugins array.
52
52
 
53
+ ## Plugin Options
54
+
55
+ All options are optional.
56
+
57
+ | Option | Default | Description |
58
+ | ----------------------- | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
59
+ | `tsconfig` | `tsconfig.app.json` | Path to the tsconfig used for compilation, or a function returning it. Libraries default to `tsconfig.lib.json` and tests to `tsconfig.spec.json`. |
60
+ | `workspaceRoot` | `NX_WORKSPACE_ROOT`, then `process.cwd()` | Absolute path to the workspace root. Set it in monorepos where the app is not the working directory. |
61
+ | `inlineStylesExtension` | `'css'` | Stylesheet language for inline component `styles`, such as `'scss'`. See [CSS Pre-processors](https://analogjs.org/docs/packages/vite-plugin-angular/css-preprocessors). |
62
+ | `jit` | `true` in tests, `false` otherwise | Compile components in JIT mode instead of AOT. |
63
+ | `include` | `[]` | Additional globs, relative to the workspace root, to add to compilation, such as components from a library outside the tsconfig `include`. |
64
+ | `liveReload` | `true` | Enables Angular component HMR during development. This is separate from Vite's `server.hmr` transport option. |
65
+ | `disableTypeChecking` | `true` | Skips semantic and template diagnostics during compilation. Set to `false` to report type errors from the Vite build. |
66
+ | `fileReplacements` | `[]` | Replaces source files at build time, like `fileReplacements` in `angular.json`. Use `{ replace, with }`, or `{ replace, ssr }` for the SSR build. `with` and `ssr` paths resolve against `workspaceRoot`. |
67
+ | `fastCompile` | `false` | Opts into the [fast compile path](#fast-compile-mode). |
68
+ | `fastCompileMode` | `'full'` | Output mode for `fastCompile`: `'full'` for apps, `'partial'` for publishing libraries. |
69
+ | `debug` | `false` | Enables `analog:angular:*` debug logging. |
70
+
71
+ ```ts
72
+ import { defineConfig } from 'vite';
73
+ import angular from '@analogjs/vite-plugin-angular';
74
+
75
+ export default defineConfig(({ mode }) => ({
76
+ plugins: [
77
+ angular({
78
+ inlineStylesExtension: 'scss',
79
+ fileReplacements:
80
+ mode === 'production'
81
+ ? [
82
+ {
83
+ replace: 'src/environments/environment.ts',
84
+ with: 'src/environments/environment.prod.ts',
85
+ },
86
+ ]
87
+ : [],
88
+ }),
89
+ ],
90
+ }));
91
+ ```
92
+
53
93
  ## Fast Compile Mode
54
94
 
55
95
  `fastCompile` opts the plugin into a single-pass compilation path that emits Ivy instructions directly and skips Angular's template type-checking. It's intended for content-focused apps and faster dev iteration where build throughput matters more than inline type-safety feedback.
@@ -1,7 +1,17 @@
1
- import { NodePackageInstallTask } from "@angular-devkit/schematics/tasks";
1
+ import { NodePackageInstallTask } from "@angular-devkit/schematics/tasks/index.js";
2
2
  //#region packages/vite-plugin-angular/migrations/migrate-setup-vitest/migrate-setup-vitest.ts
3
3
  var OLD_IMPORT = "@analogjs/vite-plugin-angular/setup-vitest";
4
4
  var NEW_IMPORT = "@analogjs/vitest-angular/setup-zone";
5
+ var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
6
+ ".cjs",
7
+ ".cts",
8
+ ".js",
9
+ ".jsx",
10
+ ".mjs",
11
+ ".mts",
12
+ ".ts",
13
+ ".tsx"
14
+ ]);
5
15
  function addVitestAngularDependency(tree, context) {
6
16
  const pkgPath = "/package.json";
7
17
  const content = tree.read(pkgPath);
@@ -24,7 +34,8 @@ function migrateSetupVitest() {
24
34
  return (tree, context) => {
25
35
  const filesToUpdate = [];
26
36
  tree.visit((filePath) => {
27
- if (!filePath.endsWith(".ts") && !filePath.endsWith(".mts") && !filePath.endsWith(".js") && !filePath.endsWith(".mjs")) return;
37
+ const extension = filePath.slice(filePath.lastIndexOf("."));
38
+ if (!SUPPORTED_EXTENSIONS.has(extension)) return;
28
39
  if (filePath.includes("/node_modules/")) return;
29
40
  const content = tree.read(filePath);
30
41
  if (!content) return;
@@ -1 +1 @@
1
- {"version":3,"file":"migrate-setup-vitest.js","names":[],"sources":["../../../migrations/migrate-setup-vitest/migrate-setup-vitest.ts"],"sourcesContent":["import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';\n\nconst OLD_IMPORT = '@analogjs/vite-plugin-angular/setup-vitest';\nconst NEW_IMPORT = '@analogjs/vitest-angular/setup-zone';\n\nfunction addVitestAngularDependency(\n tree: Tree,\n context: SchematicContext,\n): void {\n const pkgPath = '/package.json';\n const content = tree.read(pkgPath);\n if (!content) {\n return;\n }\n\n const pkg = JSON.parse(content.toString('utf-8'));\n const devDeps = pkg['devDependencies'] || {};\n const deps = pkg['dependencies'] || {};\n\n if (\n !devDeps['@analogjs/vitest-angular'] &&\n !deps['@analogjs/vitest-angular']\n ) {\n const analogVersion =\n devDeps['@analogjs/vite-plugin-angular'] ||\n deps['@analogjs/vite-plugin-angular'] ||\n '*';\n\n pkg['devDependencies'] = {\n ...devDeps,\n '@analogjs/vitest-angular': analogVersion,\n };\n\n tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2) + '\\n');\n context.addTask(new NodePackageInstallTask());\n context.logger.info(\n `Added '@analogjs/vitest-angular': '${analogVersion}' to devDependencies.`,\n );\n }\n}\n\nexport default function migrateSetupVitest(): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const filesToUpdate: string[] = [];\n\n tree.visit((filePath) => {\n if (\n !filePath.endsWith('.ts') &&\n !filePath.endsWith('.mts') &&\n !filePath.endsWith('.js') &&\n !filePath.endsWith('.mjs')\n ) {\n return;\n }\n if (filePath.includes('/node_modules/')) {\n return;\n }\n\n const content = tree.read(filePath);\n if (!content) {\n return;\n }\n\n const text = content.toString('utf-8');\n if (text.includes(OLD_IMPORT)) {\n const updated = text.replace(\n new RegExp(OLD_IMPORT.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'g'),\n NEW_IMPORT,\n );\n tree.overwrite(filePath, updated);\n filesToUpdate.push(filePath);\n }\n });\n\n if (filesToUpdate.length > 0) {\n context.logger.info(\n `Migrated ${filesToUpdate.length} file(s) from '${OLD_IMPORT}' to '${NEW_IMPORT}':`,\n );\n for (const file of filesToUpdate) {\n context.logger.info(` - ${file}`);\n }\n }\n\n if (filesToUpdate.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,SAAS,GAAG;GAC5B,QAAQ,OAAO,KACb,YAAY,cAAc,OAAO,iBAAiB,WAAW,QAAQ,WAAW,GAClF;GACA,KAAK,MAAM,QAAQ,eACjB,QAAQ,OAAO,KAAK,OAAO,MAAM;EAErC;EAEA,IAAI,cAAc,SAAS,GACzB,2BAA2B,MAAM,OAAO;EAG1C,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"migrate-setup-vitest.js","names":[],"sources":["../../../migrations/migrate-setup-vitest/migrate-setup-vitest.ts"],"sourcesContent":["import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport { NodePackageInstallTask } from '@angular-devkit/schematics/tasks/index.js';\n\nconst OLD_IMPORT = '@analogjs/vite-plugin-angular/setup-vitest';\nconst NEW_IMPORT = '@analogjs/vitest-angular/setup-zone';\nconst SUPPORTED_EXTENSIONS = new Set([\n '.cjs',\n '.cts',\n '.js',\n '.jsx',\n '.mjs',\n '.mts',\n '.ts',\n '.tsx',\n]);\n\nfunction addVitestAngularDependency(\n tree: Tree,\n context: SchematicContext,\n): void {\n const pkgPath = '/package.json';\n const content = tree.read(pkgPath);\n if (!content) {\n return;\n }\n\n const pkg = JSON.parse(content.toString('utf-8'));\n const devDeps = pkg['devDependencies'] || {};\n const deps = pkg['dependencies'] || {};\n\n if (\n !devDeps['@analogjs/vitest-angular'] &&\n !deps['@analogjs/vitest-angular']\n ) {\n const analogVersion =\n devDeps['@analogjs/vite-plugin-angular'] ||\n deps['@analogjs/vite-plugin-angular'] ||\n '*';\n\n pkg['devDependencies'] = {\n ...devDeps,\n '@analogjs/vitest-angular': analogVersion,\n };\n\n tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2) + '\\n');\n context.addTask(new NodePackageInstallTask());\n context.logger.info(\n `Added '@analogjs/vitest-angular': '${analogVersion}' to devDependencies.`,\n );\n }\n}\n\nexport default function migrateSetupVitest(): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const filesToUpdate: string[] = [];\n\n tree.visit((filePath) => {\n const extension = filePath.slice(filePath.lastIndexOf('.'));\n if (!SUPPORTED_EXTENSIONS.has(extension)) {\n return;\n }\n if (filePath.includes('/node_modules/')) {\n return;\n }\n\n const content = tree.read(filePath);\n if (!content) {\n return;\n }\n\n const text = content.toString('utf-8');\n if (text.includes(OLD_IMPORT)) {\n const updated = text.replace(\n new RegExp(OLD_IMPORT.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'g'),\n NEW_IMPORT,\n );\n tree.overwrite(filePath, updated);\n filesToUpdate.push(filePath);\n }\n });\n\n if (filesToUpdate.length > 0) {\n context.logger.info(\n `Migrated ${filesToUpdate.length} file(s) from '${OLD_IMPORT}' to '${NEW_IMPORT}':`,\n );\n for (const file of filesToUpdate) {\n context.logger.info(` - ${file}`);\n }\n }\n\n if (filesToUpdate.length > 0) {\n addVitestAngularDependency(tree, context);\n }\n\n return tree;\n };\n}\n"],"mappings":";;AAGA,IAAM,aAAa;AACnB,IAAM,aAAa;AACnB,IAAM,uCAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,2BACP,MACA,SACM;CACN,MAAM,UAAU;CAChB,MAAM,UAAU,KAAK,KAAK,OAAO;CACjC,IAAI,CAAC,SACH;CAGF,MAAM,MAAM,KAAK,MAAM,QAAQ,SAAS,OAAO,CAAC;CAChD,MAAM,UAAU,IAAI,sBAAsB,CAAC;CAC3C,MAAM,OAAO,IAAI,mBAAmB,CAAC;CAErC,IACE,CAAC,QAAQ,+BACT,CAAC,KAAK,6BACN;EACA,MAAM,gBACJ,QAAQ,oCACR,KAAK,oCACL;EAEF,IAAI,qBAAqB;GACvB,GAAG;GACH,4BAA4B;EAC9B;EAEA,KAAK,UAAU,SAAS,KAAK,UAAU,KAAK,MAAM,CAAC,IAAI,IAAI;EAC3D,QAAQ,QAAQ,IAAI,uBAAuB,CAAC;EAC5C,QAAQ,OAAO,KACb,sCAAsC,cAAc,sBACtD;CACF;AACF;AAEA,SAAwB,qBAA2B;CACjD,QAAQ,MAAY,YAA8B;EAChD,MAAM,gBAA0B,CAAC;EAEjC,KAAK,OAAO,aAAa;GACvB,MAAM,YAAY,SAAS,MAAM,SAAS,YAAY,GAAG,CAAC;GAC1D,IAAI,CAAC,qBAAqB,IAAI,SAAS,GACrC;GAEF,IAAI,SAAS,SAAS,gBAAgB,GACpC;GAGF,MAAM,UAAU,KAAK,KAAK,QAAQ;GAClC,IAAI,CAAC,SACH;GAGF,MAAM,OAAO,QAAQ,SAAS,OAAO;GACrC,IAAI,KAAK,SAAS,UAAU,GAAG;IAC7B,MAAM,UAAU,KAAK,QACnB,IAAI,OAAO,WAAW,QAAQ,uBAAuB,MAAM,GAAG,GAAG,GACjE,UACF;IACA,KAAK,UAAU,UAAU,OAAO;IAChC,cAAc,KAAK,QAAQ;GAC7B;EACF,CAAC;EAED,IAAI,cAAc,SAAS,GAAG;GAC5B,QAAQ,OAAO,KACb,YAAY,cAAc,OAAO,iBAAiB,WAAW,QAAQ,WAAW,GAClF;GACA,KAAK,MAAM,QAAQ,eACjB,QAAQ,OAAO,KAAK,OAAO,MAAM;EAErC;EAEA,IAAI,cAAc,SAAS,GACzB,2BAA2B,MAAM,OAAO;EAG1C,OAAO;CACT;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/vite-plugin-angular",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.10",
4
4
  "description": "Vite Plugin for Angular",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -57,18 +57,6 @@
57
57
  "tinyglobby": "^0.2.15"
58
58
  },
59
59
  "builders": "./src/lib/tools/builders.json",
60
- "nx-migrations": {
61
- "packageGroup": [
62
- "@analogjs/platform",
63
- "@analogjs/content",
64
- "@analogjs/router",
65
- "@analogjs/storybook-angular",
66
- "@analogjs/vite-plugin-angular",
67
- "@analogjs/vite-plugin-nitro",
68
- "@analogjs/vitest-angular"
69
- ],
70
- "migrations": "./migrations/migrations.json"
71
- },
72
60
  "ng-update": {
73
61
  "packageGroup": [
74
62
  "@analogjs/platform",
@@ -83,7 +71,6 @@
83
71
  },
84
72
  "exports": {
85
73
  "./package.json": "./package.json",
86
- "./migrations.json": "./migrations/migrations.json",
87
74
  ".": {
88
75
  "types": "./src/index.d.ts",
89
76
  "import": "./src/index.js",
@@ -163,6 +163,7 @@ function angular(options) {
163
163
  return emittedResult;
164
164
  };
165
165
  let initialCompilation = false;
166
+ let activeBuilds = 0;
166
167
  const declarationFiles = [];
167
168
  const fileTransformMap = /* @__PURE__ */ new Map();
168
169
  let styleTransform;
@@ -271,6 +272,7 @@ function angular(options) {
271
272
  });
272
273
  },
273
274
  async buildStart() {
275
+ activeBuilds++;
274
276
  if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, resolvedConfig);
275
277
  if (!deferInitialCompilation) {
276
278
  pendingCompilation = performCompilation(this.environment?.config ?? resolvedConfig);
@@ -280,7 +282,8 @@ function angular(options) {
280
282
  }
281
283
  },
282
284
  buildEnd() {
283
- if (watchMode) return;
285
+ activeBuilds = Math.max(0, activeBuilds - 1);
286
+ if (watchMode || activeBuilds > 0) return;
284
287
  nextProgram = void 0;
285
288
  cachedHost = void 0;
286
289
  cachedHostKey = void 0;
@@ -757,6 +760,7 @@ function angular(options) {
757
760
  ...isTest && !isStackBlitz ? angularVitestPlugins((id) => outputFiles.get(normalizePath(id))?.map) : [],
758
761
  jit && jitPlugin({ inlineStylesExtension: pluginOptions.inlineStylesExtension }),
759
762
  buildOptimizerPlugin({ jit }),
763
+ !isTest && devServerModePlugin(),
760
764
  routerPlugin(),
761
765
  nxFolderPlugin(),
762
766
  encapsulationPlugin()
@@ -1003,6 +1007,15 @@ function isModuleForChangedResource(mod, changedFile, stylesheetRegistry) {
1003
1007
  const sourcePath = stylesheetRegistry?.resolveExternalSource(requestPath) ?? stylesheetRegistry?.resolveExternalSource(requestPath.replace(/^\//, "")) ?? stylesheetRegistry?.getServedSourcePath(requestPath) ?? stylesheetRegistry?.getServedSourcePath(requestPath.replace(/^\//, ""));
1004
1008
  return normalizePath((sourcePath ?? "").split("?")[0]) === normalizedChangedFile;
1005
1009
  }
1010
+ function devServerModePlugin() {
1011
+ return {
1012
+ name: "@analogjs/vite-plugin-angular-dev-server-mode",
1013
+ apply: "serve",
1014
+ configEnvironment(_name, config) {
1015
+ if (config.consumer === "server") return { define: { ngServerMode: "true" } };
1016
+ }
1017
+ };
1018
+ }
1006
1019
  function diagnoseComponentStylesheetPipeline(changedFile, directModule, stylesheetRegistry, wrapperModules, stylePreprocessor) {
1007
1020
  const normalizedFile = normalizePath(changedFile.split("?")[0]);
1008
1021
  const sourceExists = existsSync(normalizedFile);