@analogjs/vite-plugin-angular 3.0.0-alpha.4 → 3.0.0-alpha.41

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 (168) hide show
  1. package/README.md +28 -0
  2. package/migrations/migrate-setup-vitest/migrate-setup-vitest.d.ts +2 -0
  3. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
  4. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
  5. package/migrations/migration.json +7 -1
  6. package/migrations/migrations.json +9 -0
  7. package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +2 -0
  8. package/migrations/update-3-0-0/migrate-setup-vitest.js +36 -0
  9. package/migrations/update-3-0-0/migrate-setup-vitest.js.map +1 -0
  10. package/package.json +25 -12
  11. package/src/index.d.ts +3 -2
  12. package/src/index.js +6 -2
  13. package/src/index.js.map +1 -1
  14. package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
  15. package/src/lib/angular-build-optimizer-plugin.js +48 -62
  16. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  17. package/src/lib/angular-jit-plugin.d.ts +3 -3
  18. package/src/lib/angular-jit-plugin.js +42 -37
  19. package/src/lib/angular-jit-plugin.js.map +1 -1
  20. package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
  21. package/src/lib/angular-pending-tasks.plugin.js +17 -18
  22. package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
  23. package/src/lib/angular-vite-plugin.d.ts +250 -40
  24. package/src/lib/angular-vite-plugin.js +2216 -964
  25. package/src/lib/angular-vite-plugin.js.map +1 -1
  26. package/src/lib/angular-vitest-plugin.d.ts +19 -15
  27. package/src/lib/angular-vitest-plugin.js +99 -114
  28. package/src/lib/angular-vitest-plugin.js.map +1 -1
  29. package/src/lib/compiler/angular-version.d.ts +19 -0
  30. package/src/lib/compiler/angular-version.js +16 -0
  31. package/src/lib/compiler/angular-version.js.map +1 -0
  32. package/src/lib/compiler/class-field-lowering.d.ts +23 -0
  33. package/src/lib/compiler/class-field-lowering.js +131 -0
  34. package/src/lib/compiler/class-field-lowering.js.map +1 -0
  35. package/src/lib/compiler/compile.d.ts +44 -0
  36. package/src/lib/compiler/compile.js +731 -0
  37. package/src/lib/compiler/compile.js.map +1 -0
  38. package/src/lib/compiler/constants.d.ts +18 -0
  39. package/src/lib/compiler/constants.js +52 -0
  40. package/src/lib/compiler/constants.js.map +1 -0
  41. package/src/lib/compiler/debug.d.ts +22 -0
  42. package/src/lib/compiler/debug.js +20 -0
  43. package/src/lib/compiler/debug.js.map +1 -0
  44. package/src/lib/compiler/defer.d.ts +47 -0
  45. package/src/lib/compiler/defer.js +138 -0
  46. package/src/lib/compiler/defer.js.map +1 -0
  47. package/src/lib/compiler/dts-reader.d.ts +35 -0
  48. package/src/lib/compiler/dts-reader.js +365 -0
  49. package/src/lib/compiler/dts-reader.js.map +1 -0
  50. package/src/lib/compiler/hmr.d.ts +16 -0
  51. package/src/lib/compiler/hmr.js +69 -0
  52. package/src/lib/compiler/hmr.js.map +1 -0
  53. package/src/lib/compiler/index.d.ts +7 -0
  54. package/src/lib/compiler/index.js +7 -0
  55. package/src/lib/compiler/jit-metadata.d.ts +14 -0
  56. package/src/lib/compiler/jit-metadata.js +146 -0
  57. package/src/lib/compiler/jit-metadata.js.map +1 -0
  58. package/src/lib/compiler/jit-transform.d.ts +24 -0
  59. package/src/lib/compiler/jit-transform.js +200 -0
  60. package/src/lib/compiler/jit-transform.js.map +1 -0
  61. package/src/lib/compiler/js-emitter.d.ts +10 -0
  62. package/src/lib/compiler/js-emitter.js +420 -0
  63. package/src/lib/compiler/js-emitter.js.map +1 -0
  64. package/src/lib/compiler/metadata.d.ts +45 -0
  65. package/src/lib/compiler/metadata.js +633 -0
  66. package/src/lib/compiler/metadata.js.map +1 -0
  67. package/src/lib/compiler/registry.d.ts +49 -0
  68. package/src/lib/compiler/registry.js +164 -0
  69. package/src/lib/compiler/registry.js.map +1 -0
  70. package/src/lib/compiler/resource-inliner.d.ts +21 -0
  71. package/src/lib/compiler/resource-inliner.js +152 -0
  72. package/src/lib/compiler/resource-inliner.js.map +1 -0
  73. package/src/lib/compiler/style-ast.d.ts +8 -0
  74. package/src/lib/compiler/style-ast.js +54 -0
  75. package/src/lib/compiler/style-ast.js.map +1 -0
  76. package/src/lib/compiler/styles.d.ts +13 -0
  77. package/src/lib/compiler/test-helpers.d.ts +7 -0
  78. package/src/lib/compiler/type-elision.d.ts +26 -0
  79. package/src/lib/compiler/type-elision.js +211 -0
  80. package/src/lib/compiler/type-elision.js.map +1 -0
  81. package/src/lib/compiler/utils.d.ts +10 -0
  82. package/src/lib/compiler/utils.js +35 -0
  83. package/src/lib/compiler/utils.js.map +1 -0
  84. package/src/lib/compiler-plugin.d.ts +11 -11
  85. package/src/lib/compiler-plugin.js +43 -44
  86. package/src/lib/compiler-plugin.js.map +1 -1
  87. package/src/lib/component-resolvers.d.ts +23 -5
  88. package/src/lib/component-resolvers.js +153 -63
  89. package/src/lib/component-resolvers.js.map +1 -1
  90. package/src/lib/fast-compile-plugin.d.ts +14 -0
  91. package/src/lib/fast-compile-plugin.js +270 -0
  92. package/src/lib/fast-compile-plugin.js.map +1 -0
  93. package/src/lib/host.d.ts +10 -8
  94. package/src/lib/host.js +113 -101
  95. package/src/lib/host.js.map +1 -1
  96. package/src/lib/live-reload-plugin.d.ts +5 -5
  97. package/src/lib/live-reload-plugin.js +61 -62
  98. package/src/lib/live-reload-plugin.js.map +1 -1
  99. package/src/lib/models.d.ts +9 -9
  100. package/src/lib/nx-folder-plugin.d.ts +5 -5
  101. package/src/lib/nx-folder-plugin.js +18 -16
  102. package/src/lib/nx-folder-plugin.js.map +1 -1
  103. package/src/lib/plugins/file-replacements.plugin.d.ts +4 -4
  104. package/src/lib/plugins/file-replacements.plugin.js +40 -62
  105. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  106. package/src/lib/router-plugin.d.ts +1 -1
  107. package/src/lib/router-plugin.js +23 -23
  108. package/src/lib/router-plugin.js.map +1 -1
  109. package/src/lib/style-pipeline.d.ts +15 -0
  110. package/src/lib/style-pipeline.js +31 -0
  111. package/src/lib/style-pipeline.js.map +1 -0
  112. package/src/lib/style-preprocessor.d.ts +35 -0
  113. package/src/lib/style-preprocessor.js +35 -0
  114. package/src/lib/style-preprocessor.js.map +1 -0
  115. package/src/lib/stylesheet-registry.d.ts +73 -0
  116. package/src/lib/stylesheet-registry.js +168 -0
  117. package/src/lib/stylesheet-registry.js.map +1 -0
  118. package/src/lib/tools/package.json +2 -7
  119. package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -38
  120. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  121. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +51 -62
  122. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  123. package/src/lib/tools/src/index.js +0 -2
  124. package/src/lib/utils/compiler-plugin-options.d.ts +11 -11
  125. package/src/lib/utils/debug-harness.d.ts +23 -0
  126. package/src/lib/utils/debug-harness.js +88 -0
  127. package/src/lib/utils/debug-harness.js.map +1 -0
  128. package/src/lib/utils/debug-log-file.d.ts +5 -0
  129. package/src/lib/utils/debug-log-file.js +56 -0
  130. package/src/lib/utils/debug-log-file.js.map +1 -0
  131. package/src/lib/utils/debug.d.ts +28 -0
  132. package/src/lib/utils/debug.js +39 -0
  133. package/src/lib/utils/debug.js.map +1 -0
  134. package/src/lib/utils/devkit.d.ts +6 -6
  135. package/src/lib/utils/devkit.js +34 -38
  136. package/src/lib/utils/devkit.js.map +1 -1
  137. package/src/lib/utils/hmr-candidates.d.ts +28 -28
  138. package/src/lib/utils/plugin-config.d.ts +30 -0
  139. package/src/lib/utils/plugin-config.js +64 -0
  140. package/src/lib/utils/plugin-config.js.map +1 -0
  141. package/src/lib/utils/rolldown.d.ts +2 -0
  142. package/src/lib/utils/rolldown.js +12 -0
  143. package/src/lib/utils/rolldown.js.map +1 -0
  144. package/src/lib/utils/source-file-cache.d.ts +8 -15
  145. package/src/lib/utils/source-file-cache.js +35 -37
  146. package/src/lib/utils/source-file-cache.js.map +1 -1
  147. package/src/lib/utils/tailwind-reference.d.ts +12 -0
  148. package/src/lib/utils/tailwind-reference.js +99 -0
  149. package/src/lib/utils/tailwind-reference.js.map +1 -0
  150. package/src/lib/utils/virtual-ids.d.ts +8 -0
  151. package/src/lib/utils/virtual-ids.js +35 -0
  152. package/src/lib/utils/virtual-ids.js.map +1 -0
  153. package/src/lib/utils/virtual-resources.d.ts +47 -0
  154. package/src/lib/utils/virtual-resources.js +89 -0
  155. package/src/lib/utils/virtual-resources.js.map +1 -0
  156. package/src/test-setup.d.ts +2 -0
  157. package/setup-vitest.d.ts +0 -4
  158. package/setup-vitest.js +0 -215
  159. package/setup-vitest.js.map +0 -1
  160. package/src/lib/models.js +0 -1
  161. package/src/lib/models.js.map +0 -1
  162. package/src/lib/tools/README.md +0 -3
  163. package/src/lib/tools/src/index.d.ts +0 -0
  164. package/src/lib/tools/src/index.js.map +0 -1
  165. package/src/lib/utils/compiler-plugin-options.js +0 -1
  166. package/src/lib/utils/compiler-plugin-options.js.map +0 -1
  167. package/src/lib/utils/hmr-candidates.js +0 -272
  168. package/src/lib/utils/hmr-candidates.js.map +0 -1
package/src/lib/host.js CHANGED
@@ -1,108 +1,120 @@
1
- import { normalizePath } from 'vite';
2
- import { createHash } from 'node:crypto';
3
- import path from 'node:path';
4
- export function augmentHostWithResources(host, transform, options) {
5
- const resourceHost = host;
6
- resourceHost.readResource = async function (fileName) {
7
- const filePath = normalizePath(fileName);
8
- const content = this.readFile(filePath);
9
- if (content === undefined) {
10
- throw new Error('Unable to locate component resource: ' + fileName);
11
- }
12
- return content;
13
- };
14
- resourceHost.getModifiedResourceFiles = function () {
15
- return options?.sourceFileCache?.modifiedFiles;
16
- };
17
- resourceHost.transformResource = async function (data, context) {
18
- // Only style resources are supported currently
19
- if (context.type !== 'style') {
20
- return null;
21
- }
22
- if (options.inlineComponentStyles) {
23
- const id = createHash('sha256')
24
- .update(context.containingFile)
25
- .update(context.className)
26
- .update(String(context.order))
27
- .update(data)
28
- .digest('hex');
29
- const filename = id + '.' + options.inlineStylesExtension;
30
- options.inlineComponentStyles.set(filename, data);
31
- return { content: filename };
32
- }
33
- // Resource file only exists for external stylesheets
34
- const filename = context.resourceFile ??
35
- context.containingFile.replace('.ts', `.${options?.inlineStylesExtension}`);
36
- let stylesheetResult;
37
- try {
38
- stylesheetResult = await transform(data, `${filename}?direct`);
39
- }
40
- catch (e) {
41
- console.error(`${e}`);
42
- }
43
- return { content: stylesheetResult?.code || '' };
44
- };
45
- resourceHost.resourceNameToFileName = function (resourceName, containingFile) {
46
- const resolvedPath = path.join(path.dirname(containingFile), resourceName);
47
- // All resource names that have template file extensions are assumed to be templates
48
- if (!options.externalComponentStyles || !hasStyleExtension(resolvedPath)) {
49
- return resolvedPath;
50
- }
51
- // For external stylesheets, create a unique identifier and store the mapping
52
- let externalId = options.externalComponentStyles.get(resolvedPath);
53
- externalId ??= createHash('sha256').update(resolvedPath).digest('hex');
54
- const filename = externalId + path.extname(resolvedPath);
55
- options.externalComponentStyles.set(filename, resolvedPath);
56
- return filename;
57
- };
1
+ import { debugStyles } from "./utils/debug.js";
2
+ import { isTailwindReferenceError } from "./utils/tailwind-reference.js";
3
+ import { normalizeStylesheetDependencies } from "./style-preprocessor.js";
4
+ import { preprocessStylesheetResult, registerStylesheetContent } from "./stylesheet-registry.js";
5
+ import { createHash } from "node:crypto";
6
+ import path from "node:path";
7
+ import { normalizePath } from "vite";
8
+ //#region packages/vite-plugin-angular/src/lib/host.ts
9
+ function augmentHostWithResources(host, transform, options) {
10
+ const resourceHost = host;
11
+ resourceHost.readResource = async function(fileName) {
12
+ const filePath = normalizePath(fileName);
13
+ const content = this.readFile(filePath);
14
+ if (content === void 0) throw new Error("Unable to locate component resource: " + fileName);
15
+ return content;
16
+ };
17
+ resourceHost.getModifiedResourceFiles = function() {
18
+ return options?.sourceFileCache?.modifiedFiles;
19
+ };
20
+ resourceHost.transformResource = async function(data, context) {
21
+ if (context.type !== "style") return null;
22
+ const filename = context.resourceFile ?? context.containingFile.replace(".ts", `.${options?.inlineStylesExtension}`);
23
+ const preprocessed = preprocessStylesheetResult(data, filename, options.stylePreprocessor, {
24
+ filename,
25
+ containingFile: context.containingFile,
26
+ resourceFile: context.resourceFile ?? void 0,
27
+ className: context.className,
28
+ order: context.order,
29
+ inline: !context.resourceFile
30
+ });
31
+ if (options.stylesheetRegistry) {
32
+ const stylesheetId = registerStylesheetContent(options.stylesheetRegistry, {
33
+ code: preprocessed.code,
34
+ dependencies: normalizeStylesheetDependencies(preprocessed.dependencies),
35
+ diagnostics: preprocessed.diagnostics,
36
+ tags: preprocessed.tags,
37
+ containingFile: context.containingFile,
38
+ className: context.className,
39
+ order: context.order,
40
+ inlineStylesExtension: options.inlineStylesExtension,
41
+ resourceFile: context.resourceFile ?? void 0
42
+ });
43
+ debugStyles("NgtscProgram: stylesheet deferred to Vite pipeline", {
44
+ stylesheetId,
45
+ resourceFile: context.resourceFile ?? "(inline)",
46
+ dependencies: preprocessed.dependencies,
47
+ diagnostics: preprocessed.diagnostics,
48
+ tags: preprocessed.tags
49
+ });
50
+ return { content: stylesheetId };
51
+ }
52
+ debugStyles("NgtscProgram: stylesheet processed inline via transform", {
53
+ filename,
54
+ resourceFile: context.resourceFile ?? "(inline)",
55
+ dataLength: preprocessed.code.length
56
+ });
57
+ let stylesheetResult;
58
+ try {
59
+ stylesheetResult = await transform(preprocessed.code, `${filename}?direct`);
60
+ } catch (e) {
61
+ if (isTailwindReferenceError(e)) throw e;
62
+ debugStyles("NgtscProgram: stylesheet transform error", {
63
+ filename,
64
+ resourceFile: context.resourceFile ?? "(inline)",
65
+ error: String(e)
66
+ });
67
+ }
68
+ if (!stylesheetResult?.code) return null;
69
+ return { content: stylesheetResult.code };
70
+ };
71
+ resourceHost.resourceNameToFileName = function(resourceName, containingFile, fallbackResolve) {
72
+ let resolved = null;
73
+ if (fallbackResolve) resolved = fallbackResolve(path.dirname(containingFile), resourceName);
74
+ const resolvedPath = normalizePath(resolved ?? path.join(path.dirname(containingFile), resourceName));
75
+ if (!options.stylesheetRegistry || !hasStyleExtension(resolvedPath)) return resolvedPath;
76
+ const filename = createHash("sha256").update(resolvedPath).digest("hex") + path.extname(resolvedPath);
77
+ options.stylesheetRegistry.registerExternalRequest(filename, resolvedPath);
78
+ debugStyles("NgtscProgram: external stylesheet ID mapped for resolveId", {
79
+ resourceName,
80
+ resolvedPath,
81
+ filename
82
+ });
83
+ return resolvedPath;
84
+ };
58
85
  }
59
- export function augmentProgramWithVersioning(program) {
60
- const baseGetSourceFiles = program.getSourceFiles;
61
- program.getSourceFiles = function (...parameters) {
62
- const files = baseGetSourceFiles(...parameters);
63
- for (const file of files) {
64
- file.version ??= createHash('sha256').update(file.text).digest('hex');
65
- }
66
- return files;
67
- };
86
+ function augmentProgramWithVersioning(program) {
87
+ const baseGetSourceFiles = program.getSourceFiles;
88
+ program.getSourceFiles = function(...parameters) {
89
+ const files = baseGetSourceFiles(...parameters);
90
+ for (const file of files) file.version ??= createHash("sha256").update(file.text).digest("hex");
91
+ return files;
92
+ };
68
93
  }
69
- export function augmentHostWithCaching(host, cache) {
70
- const baseGetSourceFile = host.getSourceFile;
71
- host.getSourceFile = function (fileName, languageVersion, onError, shouldCreateNewSourceFile, ...parameters) {
72
- if (!shouldCreateNewSourceFile && cache.has(fileName)) {
73
- return cache.get(fileName);
74
- }
75
- const file = baseGetSourceFile.call(host, fileName, languageVersion, onError, true, ...parameters);
76
- if (file) {
77
- cache.set(fileName, file);
78
- }
79
- return file;
80
- };
94
+ function augmentHostWithCaching(host, cache) {
95
+ const baseGetSourceFile = host.getSourceFile;
96
+ host.getSourceFile = function(fileName, languageVersion, onError, shouldCreateNewSourceFile, ...parameters) {
97
+ if (!shouldCreateNewSourceFile && cache.has(fileName)) return cache.get(fileName);
98
+ const file = baseGetSourceFile.call(host, fileName, languageVersion, onError, true, ...parameters);
99
+ if (file) cache.set(fileName, file);
100
+ return file;
101
+ };
81
102
  }
82
- export function mergeTransformers(first, second) {
83
- const result = {};
84
- if (first.before || second.before) {
85
- result.before = [...(first.before || []), ...(second.before || [])];
86
- }
87
- if (first.after || second.after) {
88
- result.after = [...(first.after || []), ...(second.after || [])];
89
- }
90
- if (first.afterDeclarations || second.afterDeclarations) {
91
- result.afterDeclarations = [
92
- ...(first.afterDeclarations || []),
93
- ...(second.afterDeclarations || []),
94
- ];
95
- }
96
- return result;
103
+ function mergeTransformers(first, second) {
104
+ const result = {};
105
+ if (first.before || second.before) result.before = [...first.before || [], ...second.before || []];
106
+ if (first.after || second.after) result.after = [...first.after || [], ...second.after || []];
107
+ if (first.afterDeclarations || second.afterDeclarations) result.afterDeclarations = [...first.afterDeclarations || [], ...second.afterDeclarations || []];
108
+ return result;
97
109
  }
98
110
  function hasStyleExtension(file) {
99
- const extension = path.extname(file).toLowerCase();
100
- switch (extension) {
101
- case '.css':
102
- case '.scss':
103
- return true;
104
- default:
105
- return false;
106
- }
111
+ switch (path.extname(file).toLowerCase()) {
112
+ case ".css":
113
+ case ".scss": return true;
114
+ default: return false;
115
+ }
107
116
  }
117
+ //#endregion
118
+ export { augmentHostWithCaching, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers };
119
+
108
120
  //# sourceMappingURL=host.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"host.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/host.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAIrC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,UAAU,wBAAwB,CACtC,IAAqB,EACrB,SAI2B,EAC3B,OAMC;IAED,MAAM,YAAY,GAAG,IAAoB,CAAC;IAE1C,YAAY,CAAC,YAAY,GAAG,KAAK,WAAW,QA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ACtE,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,MAAM,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,KAAK,CAAC,iBAAiB,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;QACxD,MAAM,CAAC,iBAAiB,GAAG;YACzB,GAAG,CAAC,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC;YAClC,GAAG,CAAC,MAAM,CAAC,iBAAiB,IAAI,EAAE,CAAC;SACpC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY;IACrC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAEnD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO;YACV,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"host.js","names":[],"sources":["../../../src/lib/host.ts"],"sourcesContent":["import type { CompilerHost } from '@angular/compiler-cli';\nimport { normalizePath } from 'vite';\n\nimport * as ts from 'typescript';\n\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport {\n normalizeStylesheetDependencies,\n type StylePreprocessor,\n} from './style-preprocessor.js';\nimport {\n AnalogStylesheetRegistry,\n preprocessStylesheetResult,\n registerStylesheetContent,\n} from './stylesheet-registry.js';\nimport { debugStyles } from './utils/debug.js';\nimport type { SourceFileCache } from './utils/source-file-cache.js';\nimport { isTailwindReferenceError } from './utils/tailwind-reference.js';\n\nexport function augmentHostWithResources(\n host: ts.CompilerHost,\n transform: (\n code: string,\n id: string,\n options?: { ssr?: boolean },\n ) => ReturnType<any> | null,\n options: {\n inlineStylesExtension: string;\n isProd?: boolean;\n stylesheetRegistry?: AnalogStylesheetRegistry;\n sourceFileCache?: SourceFileCache;\n stylePreprocessor?: StylePreprocessor;\n },\n): void {\n const resourceHost = host as CompilerHost;\n\n resourceHost.readResource = async function (fileName: string) {\n const filePath = normalizePath(fileName);\n\n const content = (this as any).readFile(filePath);\n\n if (content === undefined) {\n throw new Error('Unable to locate component resource: ' + fileName);\n }\n\n return content;\n };\n\n resourceHost.getModifiedResourceFiles = function () {\n return options?.sourceFileCache?.modifiedFiles;\n };\n\n resourceHost.transformResource = async function (data, context) {\n // Only style resources are supported currently\n if (context.type !== 'style') {\n return null;\n }\n\n const filename =\n context.resourceFile ??\n context.containingFile.replace(\n '.ts',\n `.${options?.inlineStylesExtension}`,\n );\n const preprocessed = preprocessStylesheetResult(\n data,\n filename,\n options.stylePreprocessor,\n {\n filename,\n containingFile: context.containingFile,\n resourceFile: context.resourceFile ?? undefined,\n className: context.className,\n order: context.order,\n inline: !context.resourceFile,\n },\n );\n\n // Externalized path: store preprocessed CSS for Vite's serve-time pipeline.\n // CSS must NOT be transformed here — the load hook returns it into\n // Vite's transform pipeline where PostCSS / Tailwind process it once.\n if (options.stylesheetRegistry) {\n const stylesheetId = registerStylesheetContent(\n options.stylesheetRegistry,\n {\n code: preprocessed.code,\n dependencies: normalizeStylesheetDependencies(\n preprocessed.dependencies,\n ),\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n containingFile: context.containingFile,\n className: context.className,\n order: context.order,\n inlineStylesExtension: options.inlineStylesExtension,\n resourceFile: context.resourceFile ?? undefined,\n },\n );\n debugStyles('NgtscProgram: stylesheet deferred to Vite pipeline', {\n stylesheetId,\n resourceFile: context.resourceFile ?? '(inline)',\n dependencies: preprocessed.dependencies,\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n });\n return { content: stylesheetId };\n }\n\n // Non-externalized: CSS is returned directly to the Angular compiler\n // and never re-enters Vite's pipeline, so transform eagerly.\n debugStyles('NgtscProgram: stylesheet processed inline via transform', {\n filename,\n resourceFile: context.resourceFile ?? '(inline)',\n dataLength: preprocessed.code.length,\n });\n let stylesheetResult;\n\n try {\n stylesheetResult = await transform(\n preprocessed.code,\n `${filename}?direct`,\n );\n } catch (e) {\n if (isTailwindReferenceError(e)) {\n throw e;\n }\n debugStyles('NgtscProgram: stylesheet transform error', {\n filename,\n resourceFile: context.resourceFile ?? '(inline)',\n error: String(e),\n });\n }\n\n if (!stylesheetResult?.code) {\n return null;\n }\n\n return { content: stylesheetResult.code };\n };\n\n resourceHost.resourceNameToFileName = function (\n resourceName,\n containingFile,\n fallbackResolve,\n ) {\n // Angular's fallbackResolve callback expects (resourceUrl, containingFile),\n // NOT (directory, resourceName). Use it correctly or fall back to\n // path.join for simple relative paths.\n let resolved: string | null = null;\n if (fallbackResolve) {\n resolved = fallbackResolve(path.dirname(containingFile), resourceName);\n }\n const resolvedPath = normalizePath(\n resolved ?? path.join(path.dirname(containingFile), resourceName),\n );\n\n // All resource names that have template file extensions are assumed to be templates\n if (!options.stylesheetRegistry || !hasStyleExtension(resolvedPath)) {\n return resolvedPath;\n }\n\n // Register the hash-based external mapping so the resolveId hook can\n // resolve Angular's compiled stylesheet references back to the source.\n const externalId = createHash('sha256').update(resolvedPath).digest('hex');\n const filename = externalId + path.extname(resolvedPath);\n\n options.stylesheetRegistry.registerExternalRequest(filename, resolvedPath);\n debugStyles('NgtscProgram: external stylesheet ID mapped for resolveId', {\n resourceName,\n resolvedPath,\n filename,\n });\n\n // Return the real path so Angular can read the file during analysis.\n // Previously, returning the hash-based filename caused \"Could not find\n // stylesheet file\" errors because the hash doesn't exist on disk,\n // preventing AOT compilation for any component with styleUrls. (#2293)\n return resolvedPath;\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] =\n baseGetSourceFiles(...parameters);\n\n for (const file of files) {\n file.version ??= createHash('sha256').update(file.text).digest('hex');\n }\n\n return files;\n };\n}\n\nexport function augmentHostWithCaching(\n host: ts.CompilerHost,\n cache: Map<string, ts.SourceFile>,\n): void {\n const baseGetSourceFile = host.getSourceFile;\n host.getSourceFile = function (\n fileName,\n languageVersion,\n onError,\n shouldCreateNewSourceFile,\n ...parameters\n ) {\n if (!shouldCreateNewSourceFile && cache.has(fileName)) {\n return cache.get(fileName);\n }\n\n const file = baseGetSourceFile.call(\n host,\n fileName,\n languageVersion,\n onError,\n true,\n ...parameters,\n );\n\n if (file) {\n cache.set(fileName, file);\n }\n\n return file;\n };\n}\n\nexport function mergeTransformers(\n first: ts.CustomTransformers,\n second: ts.CustomTransformers,\n): ts.CustomTransformers {\n const result: ts.CustomTransformers = {};\n\n if (first.before || second.before) {\n result.before = [...(first.before || []), ...(second.before || [])];\n }\n\n if (first.after || second.after) {\n result.after = [...(first.after || []), ...(second.after || [])];\n }\n\n if (first.afterDeclarations || second.afterDeclarations) {\n result.afterDeclarations = [\n ...(first.afterDeclarations || []),\n ...(second.afterDeclarations || []),\n ];\n }\n\n return result;\n}\n\nfunction hasStyleExtension(file: string): boolean {\n const extension = path.extname(file).toLowerCase();\n\n switch (extension) {\n case '.css':\n case '.scss':\n return true;\n default:\n return false;\n }\n}\n"],"mappings":";;;;;;;;AAoBA,SAAgB,yBACd,MACA,WAKA,SAOM;CACN,MAAM,eAAe;AAErB,cAAa,eAAe,eAAgB,UAAkB;EAC5D,MAAM,WAAW,cAAc,SAAS;EAExC,MAAM,UAAW,KAAa,SAAS,SAAS;AAEhD,MAAI,YAAY,KAAA,EACd,OAAM,IAAI,MAAM,0CAA0C,SAAS;AAGrE,SAAO;;AAGT,cAAa,2BAA2B,WAAY;AAClD,SAAO,SAAS,iBAAiB;;AAGnC,cAAa,oBAAoB,eAAgB,MAAM,SAAS;AAE9D,MAAI,QAAQ,SAAS,QACn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MAAM,qBAAqB,EAAE,EACjC,GAAI,OAAO,qBAAqB,EAAE,CACnC;AAGH,QAAO;;AAGT,SAAS,kBAAkB,MAAuB;AAGhD,SAFkB,KAAK,QAAQ,KAAK,CAAC,aAAa,EAElD;EACE,KAAK;EACL,KAAK,QACH,QAAO;EACT,QACE,QAAO"}
@@ -1,6 +1,6 @@
1
- import { Plugin } from 'vite';
2
- import { EmitFileResult } from './models.js';
3
- export declare function liveReloadPlugin({ classNames, fileEmitter, }: {
4
- classNames: Map<string, string>;
5
- fileEmitter: (file: string) => EmitFileResult | undefined;
1
+ import { Plugin } from "vite";
2
+ import { EmitFileResult } from "./models.js";
3
+ export declare function liveReloadPlugin({ classNames, fileEmitter }: {
4
+ classNames: Map<string, string>;
5
+ fileEmitter: (file: string) => EmitFileResult | undefined;
6
6
  }): Plugin;
@@ -1,64 +1,63 @@
1
- import { resolve } from 'node:path';
2
- const ANGULAR_COMPONENT_PREFIX = '/@ng/component';
3
- const FILE_PREFIX = 'file:';
4
- export function liveReloadPlugin({ classNames, fileEmitter, }) {
5
- return {
6
- name: 'analogjs-live-reload-plugin',
7
- apply: 'serve',
8
- configureServer(server) {
9
- const angularComponentMiddleware = async (req, res, next) => {
10
- if (req.url === undefined || res.writableEnded) {
11
- return;
12
- }
13
- if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {
14
- next();
15
- return;
16
- }
17
- const requestUrl = new URL(req.url, 'http://localhost');
18
- const componentId = requestUrl.searchParams.get('c');
19
- if (!componentId) {
20
- res.statusCode = 400;
21
- res.end();
22
- return;
23
- }
24
- const [fileId] = decodeURIComponent(componentId).split('@');
25
- const resolvedId = resolve(process.cwd(), fileId);
26
- const invalidated = !!server.moduleGraph.getModuleById(resolvedId)
27
- ?.lastInvalidationTimestamp && classNames.get(resolvedId);
28
- // don't send an HMR update until the file has been invalidated
29
- if (!invalidated) {
30
- res.setHeader('Content-Type', 'text/javascript');
31
- res.setHeader('Cache-Control', 'no-cache');
32
- res.end('');
33
- return;
34
- }
35
- const result = fileEmitter(resolvedId);
36
- res.setHeader('Content-Type', 'text/javascript');
37
- res.setHeader('Cache-Control', 'no-cache');
38
- res.end(`${result?.hmrUpdateCode || ''}`);
39
- };
40
- server.middlewares.use(angularComponentMiddleware);
41
- },
42
- resolveId(id, _importer, options) {
43
- if (options?.ssr &&
44
- id.startsWith(FILE_PREFIX) &&
45
- id.includes(ANGULAR_COMPONENT_PREFIX)) {
46
- return `\0${id}`;
47
- }
48
- return undefined;
49
- },
50
- load(id, options) {
51
- if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {
52
- const requestUrl = new URL(id.slice(1), 'http://localhost');
53
- const componentId = requestUrl.searchParams.get('c');
54
- if (!componentId) {
55
- return;
56
- }
57
- const result = fileEmitter(resolve(process.cwd(), decodeURIComponent(componentId).split('@')[0]));
58
- return result?.hmrUpdateCode || '';
59
- }
60
- return;
61
- },
62
- };
1
+ import { debugHmr } from "./utils/debug.js";
2
+ import { resolve } from "node:path";
3
+ import { normalizePath } from "vite";
4
+ //#region packages/vite-plugin-angular/src/lib/live-reload-plugin.ts
5
+ var ANGULAR_COMPONENT_PREFIX = "/@ng/component";
6
+ var FILE_PREFIX = "file:";
7
+ function liveReloadPlugin({ classNames, fileEmitter }) {
8
+ return {
9
+ name: "analogjs-live-reload-plugin",
10
+ apply: "serve",
11
+ configureServer(server) {
12
+ if (server.config.server.hmr === false) {
13
+ debugHmr("middleware disabled: vite server.hmr is false");
14
+ return;
15
+ }
16
+ const angularComponentMiddleware = async (req, res, next) => {
17
+ if (req.url === void 0 || res.writableEnded) return;
18
+ if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {
19
+ next();
20
+ return;
21
+ }
22
+ const componentId = new URL(req.url, "http://localhost").searchParams.get("c");
23
+ if (!componentId) {
24
+ res.statusCode = 400;
25
+ res.end();
26
+ return;
27
+ }
28
+ const [fileId] = decodeURIComponent(componentId).split("@");
29
+ const resolvedId = normalizePath(resolve(process.cwd(), fileId));
30
+ if (!(!!server.moduleGraph.getModuleById(resolvedId)?.lastInvalidationTimestamp && classNames.get(resolvedId))) {
31
+ debugHmr("middleware: skipped (not invalidated)", { resolvedId });
32
+ res.setHeader("Content-Type", "text/javascript");
33
+ res.setHeader("Cache-Control", "no-cache");
34
+ res.end("");
35
+ return;
36
+ }
37
+ const result = fileEmitter(resolvedId);
38
+ debugHmr("middleware: served component update", {
39
+ resolvedId,
40
+ hasCode: !!result?.hmrUpdateCode
41
+ });
42
+ res.setHeader("Content-Type", "text/javascript");
43
+ res.setHeader("Cache-Control", "no-cache");
44
+ res.end(`${result?.hmrUpdateCode || ""}`);
45
+ };
46
+ server.middlewares.use(angularComponentMiddleware);
47
+ },
48
+ resolveId(id, _importer, options) {
49
+ if (options?.ssr && id.startsWith(FILE_PREFIX) && id.includes(ANGULAR_COMPONENT_PREFIX)) return `\0${id}`;
50
+ },
51
+ load(id, options) {
52
+ if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {
53
+ const componentId = new URL(id.slice(1), "http://localhost").searchParams.get("c");
54
+ if (!componentId) return;
55
+ return fileEmitter(normalizePath(resolve(process.cwd(), decodeURIComponent(componentId).split("@")[0])))?.hmrUpdateCode || "";
56
+ }
57
+ }
58
+ };
63
59
  }
60
+ //#endregion
61
+ export { liveReloadPlugin };
62
+
64
63
  //# sourceMappingURL=live-reload-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"live-reload-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/live-reload-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,MAAM,wBAAwB,GAAG,gBAAgB,CAAC;AAClD,MAAM,WAAW,GAAG,OAAO,CAAC;AAE5B,MAAM,UAAU,gBAAgB,CAAC,EAC/B,UAAU,EACV,WAAW,GAIZ;IACC,OAAO;QACL,IAAI,EAAE,6BAA6B;QACnC,KAAK,EAAE,OAAO;QACd,eAA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YACrC,CAAC;YAED,OAAO;QACT,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"live-reload-plugin.js","names":[],"sources":["../../../src/lib/live-reload-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { ServerResponse } from 'node:http';\nimport { Connect, normalizePath, Plugin, ViteDevServer } from 'vite';\n\nimport { EmitFileResult } from './models.js';\nimport { debugHmr } from './utils/debug.js';\n\nconst ANGULAR_COMPONENT_PREFIX = '/@ng/component';\nconst FILE_PREFIX = 'file:';\n\nexport function liveReloadPlugin({\n classNames,\n fileEmitter,\n}: {\n classNames: Map<string, string>;\n fileEmitter: (file: string) => EmitFileResult | undefined;\n}): Plugin {\n return {\n name: 'analogjs-live-reload-plugin',\n apply: 'serve',\n configureServer(server: ViteDevServer) {\n if (server.config.server.hmr === false) {\n debugHmr('middleware disabled: vite server.hmr is false');\n return;\n }\n\n const angularComponentMiddleware: Connect.HandleFunction = async (\n req: Connect.IncomingMessage,\n res: ServerResponse<Connect.IncomingMessage>,\n next: Connect.NextFunction,\n ) => {\n if (req.url === undefined || res.writableEnded) {\n return;\n }\n\n if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {\n next();\n\n return;\n }\n\n const requestUrl = new URL(req.url, 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n res.statusCode = 400;\n res.end();\n\n return;\n }\n\n const [fileId] = decodeURIComponent(componentId).split('@');\n const resolvedId = normalizePath(resolve(process.cwd(), fileId));\n const invalidated =\n !!server.moduleGraph.getModuleById(resolvedId)\n ?.lastInvalidationTimestamp && classNames.get(resolvedId);\n\n // don't send an HMR update until the file has been invalidated\n if (!invalidated) {\n debugHmr('middleware: skipped (not invalidated)', { resolvedId });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end('');\n return;\n }\n\n const result = fileEmitter(resolvedId);\n debugHmr('middleware: served component update', {\n resolvedId,\n hasCode: !!result?.hmrUpdateCode,\n });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end(`${result?.hmrUpdateCode || ''}`);\n };\n\n server.middlewares.use(angularComponentMiddleware);\n },\n resolveId(id, _importer, options) {\n if (\n options?.ssr &&\n id.startsWith(FILE_PREFIX) &&\n id.includes(ANGULAR_COMPONENT_PREFIX)\n ) {\n return `\\0${id}`;\n }\n\n return undefined;\n },\n load(id, options) {\n if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {\n const requestUrl = new URL(id.slice(1), 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n return;\n }\n\n const result = fileEmitter(\n normalizePath(\n resolve(\n process.cwd(),\n decodeURIComponent(componentId).split('@')[0],\n ),\n ),\n );\n\n return result?.hmrUpdateCode || '';\n }\n\n return;\n },\n };\n}\n"],"mappings":";;;;AAOA,IAAM,2BAA2B;AACjC,IAAM,cAAc;AAEpB,SAAgB,iBAAiB,EAC/B,YACA,eAIS;AACT,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,QAAuB;AACrC,OAAI,OAAO,OAAO,OAAO,QAAQ,OAAO;AACtC,aAAS,gDAAgD;AACzD;;GAGF,MAAM,6BAAqD,OACzD,KACA,KACA,SACG;AACH,QAAI,IAAI,QAAQ,KAAA,KAAa,IAAI,cAC/B;AAGF,QAAI,CAAC,IAAI,IAAI,SAAS,yBAAyB,EAAE;AAC/C,WAAM;AAEN;;IAIF,MAAM,cADa,IAAI,IAAI,IAAI,KAAK,mBAAmB,CACxB,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,aAAa;AAChB,SAAI,aAAa;AACjB,SAAI,KAAK;AAET;;IAGF,MAAM,CAAC,UAAU,mBAAmB,YAAY,CAAC,MAAM,IAAI;IAC3D,MAAM,aAAa,cAAc,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC;AAMhE,QAAI,EAJF,CAAC,CAAC,OAAO,YAAY,cAAc,WAAW,EAC1C,6BAA6B,WAAW,IAAI,WAAW,GAG3C;AAChB,cAAS,yCAAyC,EAAE,YAAY,CAAC;AACjE,SAAI,UAAU,gBAAgB,kBAAkB;AAChD,SAAI,UAAU,iBAAiB,WAAW;AAC1C,SAAI,IAAI,GAAG;AACX;;IAGF,MAAM,SAAS,YAAY,WAAW;AACtC,aAAS,uCAAuC;KAC9C;KACA,SAAS,CAAC,CAAC,QAAQ;KACpB,CAAC;AACF,QAAI,UAAU,gBAAgB,kBAAkB;AAChD,QAAI,UAAU,iBAAiB,WAAW;AAC1C,QAAI,IAAI,GAAG,QAAQ,iBAAiB,KAAK;;AAG3C,UAAO,YAAY,IAAI,2BAA2B;;EAEpD,UAAU,IAAI,WAAW,SAAS;AAChC,OACE,SAAS,OACT,GAAG,WAAW,YAAY,IAC1B,GAAG,SAAS,yBAAyB,CAErC,QAAO,KAAK;;EAKhB,KAAK,IAAI,SAAS;AAChB,OAAI,SAAS,OAAO,GAAG,SAAS,yBAAyB,EAAE;IAEzD,MAAM,cADa,IAAI,IAAI,GAAG,MAAM,EAAE,EAAE,mBAAmB,CAC5B,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,YACH;AAYF,WATe,YACb,cACE,QACE,QAAQ,KAAK,EACb,mBAAmB,YAAY,CAAC,MAAM,IAAI,CAAC,GAC5C,CACF,CACF,EAEc,iBAAiB;;;EAKrC"}
@@ -1,11 +1,11 @@
1
- import type ts from 'typescript';
1
+ import type ts from "typescript";
2
2
  export interface EmitFileResult {
3
- content?: string;
4
- map?: string;
5
- dependencies: readonly string[];
6
- hash?: Uint8Array;
7
- errors?: (string | ts.DiagnosticMessageChain)[];
8
- warnings?: (string | ts.DiagnosticMessageChain)[];
9
- hmrUpdateCode?: string | null;
10
- hmrEligible?: boolean | null;
3
+ content?: string;
4
+ map?: string;
5
+ dependencies: readonly string[];
6
+ hash?: Uint8Array;
7
+ errors?: (string | ts.DiagnosticMessageChain)[];
8
+ warnings?: (string | ts.DiagnosticMessageChain)[];
9
+ hmrUpdateCode?: string | null;
10
+ hmrEligible?: boolean | null;
11
11
  }
@@ -1,7 +1,7 @@
1
- import { Plugin } from 'vite';
1
+ import { Plugin } from "vite";
2
2
  /**
3
- * Ignores anything in the .nx folder from triggering HMR
4
- *
5
- * @returns
6
- */
3
+ * Ignores anything in the .nx folder from triggering HMR
4
+ *
5
+ * @returns
6
+ */
7
7
  export declare function nxFolderPlugin(): Plugin;
@@ -1,19 +1,21 @@
1
- import { normalizePath } from 'vite';
1
+ import { normalizePath } from "vite";
2
+ //#region packages/vite-plugin-angular/src/lib/nx-folder-plugin.ts
2
3
  /**
3
- * Ignores anything in the .nx folder from triggering HMR
4
- *
5
- * @returns
6
- */
7
- export function nxFolderPlugin() {
8
- return {
9
- name: 'analogjs-nx-folder-plugin',
10
- apply: 'serve',
11
- handleHotUpdate(ctx) {
12
- if (ctx.file.includes(normalizePath('/.nx/'))) {
13
- return [];
14
- }
15
- return ctx.modules;
16
- },
17
- };
4
+ * Ignores anything in the .nx folder from triggering HMR
5
+ *
6
+ * @returns
7
+ */
8
+ function nxFolderPlugin() {
9
+ return {
10
+ name: "analogjs-nx-folder-plugin",
11
+ apply: "serve",
12
+ handleHotUpdate(ctx) {
13
+ if (ctx.file.includes(normalizePath("/.nx/"))) return [];
14
+ return ctx.modules;
15
+ }
16
+ };
18
17
  }
18
+ //#endregion
19
+ export { nxFolderPlugin };
20
+
19
21
  //# sourceMappingURL=nx-folder-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nx-folder-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/nx-folder-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,MAAM,CAAC;AAE7C;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,KAAK,EAAE,OAAO;QACd,eAAe,CAAC,GAAG;YACjB,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;gBAC9C,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,OAAO,GAAG,CAAC,OAAO,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"nx-folder-plugin.js","names":[],"sources":["../../../src/lib/nx-folder-plugin.ts"],"sourcesContent":["import { normalizePath, Plugin } from 'vite';\n\n/**\n * Ignores anything in the .nx folder from triggering HMR\n *\n * @returns\n */\nexport function nxFolderPlugin(): Plugin {\n return {\n name: 'analogjs-nx-folder-plugin',\n apply: 'serve',\n handleHotUpdate(ctx) {\n if (ctx.file.includes(normalizePath('/.nx/'))) {\n return [];\n }\n\n return ctx.modules;\n },\n };\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,iBAAyB;AACvC,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,KAAK;AACnB,OAAI,IAAI,KAAK,SAAS,cAAc,QAAQ,CAAC,CAC3C,QAAO,EAAE;AAGX,UAAO,IAAI;;EAEd"}
@@ -1,12 +1,12 @@
1
- import { Plugin } from 'vite';
1
+ import { Plugin } from "vite";
2
2
  export declare function replaceFiles(replacements: FileReplacement[], workspaceRoot: string): Plugin | false;
3
3
  export type FileReplacement = FileReplacementWith | FileReplacementSSR;
4
4
  export interface FileReplacementBase {
5
- replace: string;
5
+ replace: string;
6
6
  }
7
7
  export interface FileReplacementWith extends FileReplacementBase {
8
- with: string;
8
+ with: string;
9
9
  }
10
10
  export interface FileReplacementSSR extends FileReplacementBase {
11
- ssr: string;
11
+ ssr: string;
12
12
  }