@angular/build 18.0.0-next.3

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 (253) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/builders.json +14 -0
  4. package/package.json +87 -0
  5. package/src/builders/application/build-action.d.ts +33 -0
  6. package/src/builders/application/build-action.js +183 -0
  7. package/src/builders/application/execute-build.d.ts +11 -0
  8. package/src/builders/application/execute-build.js +125 -0
  9. package/src/builders/application/execute-post-bundle.d.ts +25 -0
  10. package/src/builders/application/execute-post-bundle.js +93 -0
  11. package/src/builders/application/i18n.d.ts +29 -0
  12. package/src/builders/application/i18n.js +128 -0
  13. package/src/builders/application/index.d.ts +57 -0
  14. package/src/builders/application/index.js +121 -0
  15. package/src/builders/application/options.d.ts +149 -0
  16. package/src/builders/application/options.js +369 -0
  17. package/src/builders/application/schema.d.ts +512 -0
  18. package/src/builders/application/schema.js +58 -0
  19. package/src/builders/application/schema.json +635 -0
  20. package/src/builders/application/setup-bundling.d.ts +19 -0
  21. package/src/builders/application/setup-bundling.js +71 -0
  22. package/src/builders/dev-server/builder.d.ts +32 -0
  23. package/src/builders/dev-server/builder.js +70 -0
  24. package/src/builders/dev-server/index.d.ts +14 -0
  25. package/src/builders/dev-server/index.js +15 -0
  26. package/src/builders/dev-server/internal.d.ts +19 -0
  27. package/src/builders/dev-server/internal.js +29 -0
  28. package/src/builders/dev-server/options.d.ts +47 -0
  29. package/src/builders/dev-server/options.js +65 -0
  30. package/src/builders/dev-server/output.d.ts +16 -0
  31. package/src/builders/dev-server/output.js +9 -0
  32. package/src/builders/dev-server/schema.d.ts +118 -0
  33. package/src/builders/dev-server/schema.js +4 -0
  34. package/src/builders/dev-server/schema.json +131 -0
  35. package/src/builders/dev-server/vite-server.d.ts +31 -0
  36. package/src/builders/dev-server/vite-server.js +504 -0
  37. package/src/index.d.ts +11 -0
  38. package/src/index.js +16 -0
  39. package/src/private.d.ts +35 -0
  40. package/src/private.js +70 -0
  41. package/src/tools/babel/plugins/adjust-static-class-members.d.ts +26 -0
  42. package/src/tools/babel/plugins/adjust-static-class-members.js +351 -0
  43. package/src/tools/babel/plugins/adjust-typescript-enums.d.ts +22 -0
  44. package/src/tools/babel/plugins/adjust-typescript-enums.js +113 -0
  45. package/src/tools/babel/plugins/elide-angular-metadata.d.ts +22 -0
  46. package/src/tools/babel/plugins/elide-angular-metadata.js +110 -0
  47. package/src/tools/babel/plugins/index.d.ts +11 -0
  48. package/src/tools/babel/plugins/index.js +21 -0
  49. package/src/tools/babel/plugins/pure-toplevel-functions.d.ts +15 -0
  50. package/src/tools/babel/plugins/pure-toplevel-functions.js +90 -0
  51. package/src/tools/babel/typings.d.ts +21 -0
  52. package/src/tools/esbuild/angular/angular-host.d.ts +26 -0
  53. package/src/tools/esbuild/angular/angular-host.js +134 -0
  54. package/src/tools/esbuild/angular/compilation/angular-compilation.d.ts +42 -0
  55. package/src/tools/esbuild/angular/compilation/angular-compilation.js +94 -0
  56. package/src/tools/esbuild/angular/compilation/aot-compilation.d.ts +21 -0
  57. package/src/tools/esbuild/angular/compilation/aot-compilation.js +224 -0
  58. package/src/tools/esbuild/angular/compilation/factory.d.ts +16 -0
  59. package/src/tools/esbuild/angular/compilation/factory.js +56 -0
  60. package/src/tools/esbuild/angular/compilation/index.d.ts +10 -0
  61. package/src/tools/esbuild/angular/compilation/index.js +17 -0
  62. package/src/tools/esbuild/angular/compilation/jit-bootstrap-transformer.d.ts +10 -0
  63. package/src/tools/esbuild/angular/compilation/jit-bootstrap-transformer.js +182 -0
  64. package/src/tools/esbuild/angular/compilation/jit-compilation.d.ts +21 -0
  65. package/src/tools/esbuild/angular/compilation/jit-compilation.js +106 -0
  66. package/src/tools/esbuild/angular/compilation/noop-compilation.d.ts +20 -0
  67. package/src/tools/esbuild/angular/compilation/noop-compilation.js +26 -0
  68. package/src/tools/esbuild/angular/compilation/parallel-compilation.d.ts +42 -0
  69. package/src/tools/esbuild/angular/compilation/parallel-compilation.js +123 -0
  70. package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +33 -0
  71. package/src/tools/esbuild/angular/compilation/parallel-worker.js +90 -0
  72. package/src/tools/esbuild/angular/compilation-state.d.ts +15 -0
  73. package/src/tools/esbuild/angular/compilation-state.js +44 -0
  74. package/src/tools/esbuild/angular/compiler-plugin.d.ts +27 -0
  75. package/src/tools/esbuild/angular/compiler-plugin.js +441 -0
  76. package/src/tools/esbuild/angular/component-stylesheets.d.ts +44 -0
  77. package/src/tools/esbuild/angular/component-stylesheets.js +150 -0
  78. package/src/tools/esbuild/angular/diagnostics.d.ts +15 -0
  79. package/src/tools/esbuild/angular/diagnostics.js +69 -0
  80. package/src/tools/esbuild/angular/file-reference-tracker.d.ts +17 -0
  81. package/src/tools/esbuild/angular/file-reference-tracker.js +57 -0
  82. package/src/tools/esbuild/angular/jit-plugin-callbacks.d.ts +23 -0
  83. package/src/tools/esbuild/angular/jit-plugin-callbacks.js +117 -0
  84. package/src/tools/esbuild/angular/jit-resource-transformer.d.ts +17 -0
  85. package/src/tools/esbuild/angular/jit-resource-transformer.js +186 -0
  86. package/src/tools/esbuild/angular/source-file-cache.d.ts +18 -0
  87. package/src/tools/esbuild/angular/source-file-cache.js +65 -0
  88. package/src/tools/esbuild/angular/uri.d.ts +54 -0
  89. package/src/tools/esbuild/angular/uri.js +74 -0
  90. package/src/tools/esbuild/angular/web-worker-transformer.d.ts +17 -0
  91. package/src/tools/esbuild/angular/web-worker-transformer.js +94 -0
  92. package/src/tools/esbuild/application-code-bundle.d.ts +20 -0
  93. package/src/tools/esbuild/application-code-bundle.js +368 -0
  94. package/src/tools/esbuild/budget-stats.d.ts +19 -0
  95. package/src/tools/esbuild/budget-stats.js +59 -0
  96. package/src/tools/esbuild/bundler-context.d.ts +75 -0
  97. package/src/tools/esbuild/bundler-context.js +366 -0
  98. package/src/tools/esbuild/bundler-execution-result.d.ts +71 -0
  99. package/src/tools/esbuild/bundler-execution-result.js +131 -0
  100. package/src/tools/esbuild/cache.d.ts +88 -0
  101. package/src/tools/esbuild/cache.js +92 -0
  102. package/src/tools/esbuild/commonjs-checker.d.ts +28 -0
  103. package/src/tools/esbuild/commonjs-checker.js +151 -0
  104. package/src/tools/esbuild/compiler-plugin-options.d.ts +16 -0
  105. package/src/tools/esbuild/compiler-plugin-options.js +49 -0
  106. package/src/tools/esbuild/external-packages-plugin.d.ts +18 -0
  107. package/src/tools/esbuild/external-packages-plugin.js +70 -0
  108. package/src/tools/esbuild/global-scripts.d.ts +16 -0
  109. package/src/tools/esbuild/global-scripts.js +142 -0
  110. package/src/tools/esbuild/global-styles.d.ts +10 -0
  111. package/src/tools/esbuild/global-styles.js +74 -0
  112. package/src/tools/esbuild/i18n-inliner-worker.d.ts +42 -0
  113. package/src/tools/esbuild/i18n-inliner-worker.js +136 -0
  114. package/src/tools/esbuild/i18n-inliner.d.ts +44 -0
  115. package/src/tools/esbuild/i18n-inliner.js +150 -0
  116. package/src/tools/esbuild/i18n-locale-plugin.d.ts +22 -0
  117. package/src/tools/esbuild/i18n-locale-plugin.js +120 -0
  118. package/src/tools/esbuild/index-html-generator.d.ts +15 -0
  119. package/src/tools/esbuild/index-html-generator.js +81 -0
  120. package/src/tools/esbuild/javascript-transformer-worker.d.ts +19 -0
  121. package/src/tools/esbuild/javascript-transformer-worker.js +154 -0
  122. package/src/tools/esbuild/javascript-transformer.d.ts +54 -0
  123. package/src/tools/esbuild/javascript-transformer.js +147 -0
  124. package/src/tools/esbuild/license-extractor.d.ts +25 -0
  125. package/src/tools/esbuild/license-extractor.js +158 -0
  126. package/src/tools/esbuild/load-result-cache.d.ts +21 -0
  127. package/src/tools/esbuild/load-result-cache.js +75 -0
  128. package/src/tools/esbuild/profiling.d.ts +11 -0
  129. package/src/tools/esbuild/profiling.js +78 -0
  130. package/src/tools/esbuild/rxjs-esm-resolution-plugin.d.ts +18 -0
  131. package/src/tools/esbuild/rxjs-esm-resolution-plugin.js +44 -0
  132. package/src/tools/esbuild/sourcemap-ignorelist-plugin.d.ts +17 -0
  133. package/src/tools/esbuild/sourcemap-ignorelist-plugin.js +73 -0
  134. package/src/tools/esbuild/stylesheets/bundle-options.d.ts +35 -0
  135. package/src/tools/esbuild/stylesheets/bundle-options.js +64 -0
  136. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.d.ts +25 -0
  137. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.js +57 -0
  138. package/src/tools/esbuild/stylesheets/css-language.d.ts +9 -0
  139. package/src/tools/esbuild/stylesheets/css-language.js +15 -0
  140. package/src/tools/esbuild/stylesheets/css-resource-plugin.d.ts +18 -0
  141. package/src/tools/esbuild/stylesheets/css-resource-plugin.js +114 -0
  142. package/src/tools/esbuild/stylesheets/less-language.d.ts +9 -0
  143. package/src/tools/esbuild/stylesheets/less-language.js +155 -0
  144. package/src/tools/esbuild/stylesheets/sass-language.d.ts +10 -0
  145. package/src/tools/esbuild/stylesheets/sass-language.js +185 -0
  146. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.d.ts +58 -0
  147. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js +282 -0
  148. package/src/tools/esbuild/utils.d.ts +49 -0
  149. package/src/tools/esbuild/utils.js +392 -0
  150. package/src/tools/esbuild/virtual-module-plugin.d.ts +33 -0
  151. package/src/tools/esbuild/virtual-module-plugin.js +43 -0
  152. package/src/tools/esbuild/watcher.d.ts +25 -0
  153. package/src/tools/esbuild/watcher.js +118 -0
  154. package/src/tools/sass/lexer.d.ts +18 -0
  155. package/src/tools/sass/lexer.js +161 -0
  156. package/src/tools/sass/rebasing-importer.d.ts +101 -0
  157. package/src/tools/sass/rebasing-importer.js +334 -0
  158. package/src/tools/sass/sass-service.d.ts +72 -0
  159. package/src/tools/sass/sass-service.js +213 -0
  160. package/src/tools/sass/worker.d.ts +8 -0
  161. package/src/tools/sass/worker.js +192 -0
  162. package/src/tools/vite/angular-memory-plugin.d.ts +24 -0
  163. package/src/tools/vite/angular-memory-plugin.js +268 -0
  164. package/src/tools/vite/i18n-locale-plugin.d.ts +18 -0
  165. package/src/tools/vite/i18n-locale-plugin.js +55 -0
  166. package/src/utils/bundle-calculator.d.ts +44 -0
  167. package/src/utils/bundle-calculator.js +303 -0
  168. package/src/utils/check-port.d.ts +8 -0
  169. package/src/utils/check-port.js +58 -0
  170. package/src/utils/color.d.ts +10 -0
  171. package/src/utils/color.js +63 -0
  172. package/src/utils/delete-output-dir.d.ts +11 -0
  173. package/src/utils/delete-output-dir.js +46 -0
  174. package/src/utils/environment-options.d.ts +16 -0
  175. package/src/utils/environment-options.js +79 -0
  176. package/src/utils/error.d.ts +10 -0
  177. package/src/utils/error.js +21 -0
  178. package/src/utils/format-bytes.d.ts +8 -0
  179. package/src/utils/format-bytes.js +22 -0
  180. package/src/utils/i18n-options.d.ts +33 -0
  181. package/src/utils/i18n-options.js +161 -0
  182. package/src/utils/index-file/add-event-dispatch-contract.d.ts +8 -0
  183. package/src/utils/index-file/add-event-dispatch-contract.js +28 -0
  184. package/src/utils/index-file/augment-index-html.d.ts +40 -0
  185. package/src/utils/index-file/augment-index-html.js +239 -0
  186. package/src/utils/index-file/html-rewriting-stream.d.ts +11 -0
  187. package/src/utils/index-file/html-rewriting-stream.js +28 -0
  188. package/src/utils/index-file/index-html-generator.d.ts +57 -0
  189. package/src/utils/index-file/index-html-generator.js +135 -0
  190. package/src/utils/index-file/inline-critical-css.d.ts +24 -0
  191. package/src/utils/index-file/inline-critical-css.js +179 -0
  192. package/src/utils/index-file/inline-fonts.d.ts +23 -0
  193. package/src/utils/index-file/inline-fonts.js +267 -0
  194. package/src/utils/index-file/nonce.d.ts +12 -0
  195. package/src/utils/index-file/nonce.js +55 -0
  196. package/src/utils/index-file/style-nonce.d.ts +12 -0
  197. package/src/utils/index-file/style-nonce.js +55 -0
  198. package/src/utils/index.d.ts +11 -0
  199. package/src/utils/index.js +27 -0
  200. package/src/utils/load-esm.d.ts +20 -0
  201. package/src/utils/load-esm.js +31 -0
  202. package/src/utils/load-proxy-config.d.ts +8 -0
  203. package/src/utils/load-proxy-config.js +189 -0
  204. package/src/utils/load-translations.d.ts +16 -0
  205. package/src/utils/load-translations.js +84 -0
  206. package/src/utils/normalize-asset-patterns.d.ts +14 -0
  207. package/src/utils/normalize-asset-patterns.js +96 -0
  208. package/src/utils/normalize-cache.d.ts +16 -0
  209. package/src/utils/normalize-cache.js +44 -0
  210. package/src/utils/normalize-optimization.d.ts +13 -0
  211. package/src/utils/normalize-optimization.js +42 -0
  212. package/src/utils/normalize-source-maps.d.ts +9 -0
  213. package/src/utils/normalize-source-maps.js +23 -0
  214. package/src/utils/postcss-configuration.d.ts +17 -0
  215. package/src/utils/postcss-configuration.js +86 -0
  216. package/src/utils/purge-cache.d.ts +10 -0
  217. package/src/utils/purge-cache.js +40 -0
  218. package/src/utils/resolve-assets.d.ts +18 -0
  219. package/src/utils/resolve-assets.js +35 -0
  220. package/src/utils/routes-extractor/extractor.d.ts +15 -0
  221. package/src/utils/routes-extractor/extractor.js +97 -0
  222. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +18 -0
  223. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +129 -0
  224. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.d.ts +8 -0
  225. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.js +13 -0
  226. package/src/utils/server-rendering/fetch-patch.d.ts +8 -0
  227. package/src/utils/server-rendering/fetch-patch.js +66 -0
  228. package/src/utils/server-rendering/load-esm-from-memory.d.ts +10 -0
  229. package/src/utils/server-rendering/load-esm-from-memory.js +26 -0
  230. package/src/utils/server-rendering/main-bundle-exports.d.ts +27 -0
  231. package/src/utils/server-rendering/main-bundle-exports.js +9 -0
  232. package/src/utils/server-rendering/prerender.d.ts +23 -0
  233. package/src/utils/server-rendering/prerender.js +192 -0
  234. package/src/utils/server-rendering/render-page.d.ts +26 -0
  235. package/src/utils/server-rendering/render-page.js +110 -0
  236. package/src/utils/server-rendering/render-worker.d.ts +22 -0
  237. package/src/utils/server-rendering/render-worker.js +30 -0
  238. package/src/utils/server-rendering/routes-extractor-worker.d.ts +21 -0
  239. package/src/utils/server-rendering/routes-extractor-worker.js +53 -0
  240. package/src/utils/service-worker.d.ts +25 -0
  241. package/src/utils/service-worker.js +211 -0
  242. package/src/utils/spinner.d.ts +20 -0
  243. package/src/utils/spinner.js +55 -0
  244. package/src/utils/stats-table.d.ts +20 -0
  245. package/src/utils/stats-table.js +205 -0
  246. package/src/utils/supported-browsers.d.ts +10 -0
  247. package/src/utils/supported-browsers.js +42 -0
  248. package/src/utils/tty.d.ts +8 -0
  249. package/src/utils/tty.js +23 -0
  250. package/src/utils/url.d.ts +8 -0
  251. package/src/utils/url.js +18 -0
  252. package/src/utils/version.d.ts +8 -0
  253. package/src/utils/version.js +59 -0
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.findUrls = void 0;
11
+ // TODO: Combine everything into a single pass lexer
12
+ /**
13
+ * Determines if a unicode code point is a CSS whitespace character.
14
+ * @param code The unicode code point to test.
15
+ * @returns true, if the code point is CSS whitespace; false, otherwise.
16
+ */
17
+ function isWhitespace(code) {
18
+ // Based on https://www.w3.org/TR/css-syntax-3/#whitespace
19
+ switch (code) {
20
+ case 0x0009: // tab
21
+ case 0x0020: // space
22
+ case 0x000a: // line feed
23
+ case 0x000c: // form feed
24
+ case 0x000d: // carriage return
25
+ return true;
26
+ default:
27
+ return false;
28
+ }
29
+ }
30
+ /**
31
+ * Scans a CSS or Sass file and locates all valid url function values as defined by the
32
+ * syntax specification.
33
+ * @param contents A string containing a CSS or Sass file to scan.
34
+ * @returns An iterable that yields each CSS url function value found.
35
+ */
36
+ function* findUrls(contents) {
37
+ let pos = 0;
38
+ let width = 1;
39
+ let current = -1;
40
+ const next = () => {
41
+ pos += width;
42
+ current = contents.codePointAt(pos) ?? -1;
43
+ width = current > 0xffff ? 2 : 1;
44
+ return current;
45
+ };
46
+ // Based on https://www.w3.org/TR/css-syntax-3/#consume-ident-like-token
47
+ while ((pos = contents.indexOf('url(', pos)) !== -1) {
48
+ // Set to position of the (
49
+ pos += 3;
50
+ width = 1;
51
+ // Consume all leading whitespace
52
+ while (isWhitespace(next())) {
53
+ /* empty */
54
+ }
55
+ // Initialize URL state
56
+ const url = { start: pos, end: -1, value: '' };
57
+ let complete = false;
58
+ // If " or ', then consume the value as a string
59
+ if (current === 0x0022 || current === 0x0027) {
60
+ const ending = current;
61
+ // Based on https://www.w3.org/TR/css-syntax-3/#consume-string-token
62
+ while (!complete) {
63
+ switch (next()) {
64
+ case -1: // EOF
65
+ return;
66
+ case 0x000a: // line feed
67
+ case 0x000c: // form feed
68
+ case 0x000d: // carriage return
69
+ // Invalid
70
+ complete = true;
71
+ break;
72
+ case 0x005c: // \ -- character escape
73
+ // If not EOF or newline, add the character after the escape
74
+ switch (next()) {
75
+ case -1:
76
+ return;
77
+ case 0x000a: // line feed
78
+ case 0x000c: // form feed
79
+ case 0x000d: // carriage return
80
+ // Skip when inside a string
81
+ break;
82
+ default:
83
+ // TODO: Handle hex escape codes
84
+ url.value += String.fromCodePoint(current);
85
+ break;
86
+ }
87
+ break;
88
+ case ending:
89
+ // Full string position should include the quotes for replacement
90
+ url.end = pos + 1;
91
+ complete = true;
92
+ yield url;
93
+ break;
94
+ default:
95
+ url.value += String.fromCodePoint(current);
96
+ break;
97
+ }
98
+ }
99
+ next();
100
+ continue;
101
+ }
102
+ // Based on https://www.w3.org/TR/css-syntax-3/#consume-url-token
103
+ while (!complete) {
104
+ switch (current) {
105
+ case -1: // EOF
106
+ return;
107
+ case 0x0022: // "
108
+ case 0x0027: // '
109
+ case 0x0028: // (
110
+ // Invalid
111
+ complete = true;
112
+ break;
113
+ case 0x0029: // )
114
+ // URL is valid and complete
115
+ url.end = pos;
116
+ complete = true;
117
+ break;
118
+ case 0x005c: // \ -- character escape
119
+ // If not EOF or newline, add the character after the escape
120
+ switch (next()) {
121
+ case -1: // EOF
122
+ return;
123
+ case 0x000a: // line feed
124
+ case 0x000c: // form feed
125
+ case 0x000d: // carriage return
126
+ // Invalid
127
+ complete = true;
128
+ break;
129
+ default:
130
+ // TODO: Handle hex escape codes
131
+ url.value += String.fromCodePoint(current);
132
+ break;
133
+ }
134
+ break;
135
+ default:
136
+ if (isWhitespace(current)) {
137
+ while (isWhitespace(next())) {
138
+ /* empty */
139
+ }
140
+ // Unescaped whitespace is only valid before the closing )
141
+ if (current === 0x0029) {
142
+ // URL is valid
143
+ url.end = pos;
144
+ }
145
+ complete = true;
146
+ }
147
+ else {
148
+ // Add the character to the url value
149
+ url.value += String.fromCodePoint(current);
150
+ }
151
+ break;
152
+ }
153
+ next();
154
+ }
155
+ // An end position indicates a URL was found
156
+ if (url.end !== -1) {
157
+ yield url;
158
+ }
159
+ }
160
+ }
161
+ exports.findUrls = findUrls;
@@ -0,0 +1,101 @@
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.io/license
7
+ */
8
+ import { RawSourceMap } from '@ampproject/remapping';
9
+ import type { CanonicalizeContext, Importer, ImporterResult } from 'sass';
10
+ /**
11
+ * A preprocessed cache entry for the files and directories within a previously searched
12
+ * directory when performing Sass import resolution.
13
+ */
14
+ export interface DirectoryEntry {
15
+ files: Set<string>;
16
+ directories: Set<string>;
17
+ }
18
+ /**
19
+ * A Sass Importer base class that provides the load logic to rebase all `url()` functions
20
+ * within a stylesheet. The rebasing will ensure that the URLs in the output of the Sass compiler
21
+ * reflect the final filesystem location of the output CSS file.
22
+ *
23
+ * This class provides the core of the rebasing functionality. To ensure that each file is processed
24
+ * by this importer's load implementation, the Sass compiler requires the importer's canonicalize
25
+ * function to return a non-null value with the resolved location of the requested stylesheet.
26
+ * Concrete implementations of this class must provide this canonicalize functionality for rebasing
27
+ * to be effective.
28
+ */
29
+ declare abstract class UrlRebasingImporter implements Importer<'sync'> {
30
+ private entryDirectory;
31
+ private rebaseSourceMaps?;
32
+ /**
33
+ * @param entryDirectory The directory of the entry stylesheet that was passed to the Sass compiler.
34
+ * @param rebaseSourceMaps When provided, rebased files will have an intermediate sourcemap added to the Map
35
+ * which can be used to generate a final sourcemap that contains original sources.
36
+ */
37
+ constructor(entryDirectory: string, rebaseSourceMaps?: Map<string, RawSourceMap> | undefined);
38
+ abstract canonicalize(url: string, options: {
39
+ fromImport: boolean;
40
+ }): URL | null;
41
+ load(canonicalUrl: URL): ImporterResult | null;
42
+ }
43
+ /**
44
+ * Provides the Sass importer logic to resolve relative stylesheet imports via both import and use rules
45
+ * and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that
46
+ * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.
47
+ */
48
+ export declare class RelativeUrlRebasingImporter extends UrlRebasingImporter {
49
+ private directoryCache;
50
+ constructor(entryDirectory: string, directoryCache?: Map<string, DirectoryEntry>, rebaseSourceMaps?: Map<string, RawSourceMap>);
51
+ canonicalize(url: string, options: {
52
+ fromImport: boolean;
53
+ }): URL | null;
54
+ /**
55
+ * Attempts to resolve a provided URL to a stylesheet file using the Sass compiler's resolution algorithm.
56
+ * Based on https://github.com/sass/dart-sass/blob/44d6bb6ac72fe6b93f5bfec371a1fffb18e6b76d/lib/src/importer/utils.dart
57
+ * @param url The file protocol URL to resolve.
58
+ * @param fromImport If true, URL was from an import rule; otherwise from a use rule.
59
+ * @param checkDirectory If true, try checking for a directory with the base name containing an index file.
60
+ * @returns A full resolved URL of the stylesheet file or `null` if not found.
61
+ */
62
+ private resolveImport;
63
+ /**
64
+ * Checks an array of potential stylesheet files to determine if there is a valid
65
+ * stylesheet file. More than one discovered file may indicate an error.
66
+ * @param found An array of discovered stylesheet files.
67
+ * @returns A fully resolved path for a stylesheet file or `null` if not found.
68
+ * @throws If there are ambiguous files discovered.
69
+ */
70
+ private checkFound;
71
+ }
72
+ /**
73
+ * Provides the Sass importer logic to resolve module (npm package) stylesheet imports via both import and
74
+ * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that
75
+ * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.
76
+ */
77
+ export declare class ModuleUrlRebasingImporter extends RelativeUrlRebasingImporter {
78
+ private finder;
79
+ constructor(entryDirectory: string, directoryCache: Map<string, DirectoryEntry>, rebaseSourceMaps: Map<string, RawSourceMap> | undefined, finder: (specifier: string, options: CanonicalizeContext) => URL | null);
80
+ canonicalize(url: string, options: CanonicalizeContext): URL | null;
81
+ }
82
+ /**
83
+ * Provides the Sass importer logic to resolve load paths located stylesheet imports via both import and
84
+ * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that
85
+ * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.
86
+ */
87
+ export declare class LoadPathsUrlRebasingImporter extends RelativeUrlRebasingImporter {
88
+ private loadPaths;
89
+ constructor(entryDirectory: string, directoryCache: Map<string, DirectoryEntry>, rebaseSourceMaps: Map<string, RawSourceMap> | undefined, loadPaths: Iterable<string>);
90
+ canonicalize(url: string, options: {
91
+ fromImport: boolean;
92
+ }): URL | null;
93
+ }
94
+ /**
95
+ * Workaround for Sass not calling instance methods with `this`.
96
+ * The `canonicalize` and `load` methods will be bound to the class instance.
97
+ * @param importer A Sass importer to bind.
98
+ * @returns The bound Sass importer.
99
+ */
100
+ export declare function sassBindWorkaround<T extends Importer>(importer: T): T;
101
+ export {};
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.sassBindWorkaround = exports.LoadPathsUrlRebasingImporter = exports.ModuleUrlRebasingImporter = exports.RelativeUrlRebasingImporter = void 0;
14
+ const magic_string_1 = __importDefault(require("magic-string"));
15
+ const node_fs_1 = require("node:fs");
16
+ const node_path_1 = require("node:path");
17
+ const node_url_1 = require("node:url");
18
+ const lexer_1 = require("./lexer");
19
+ /**
20
+ * Ensures that a bare specifier URL path that is intended to be treated as
21
+ * a relative path has a leading `./` or `../` prefix.
22
+ *
23
+ * @param url A bare specifier URL path that should be considered relative.
24
+ * @returns
25
+ */
26
+ function ensureRelative(url) {
27
+ // Empty
28
+ if (!url) {
29
+ return url;
30
+ }
31
+ // Already relative
32
+ if (url[0] === '.' && (url[1] === '/' || (url[1] === '.' && url[2] === '/'))) {
33
+ return url;
34
+ }
35
+ // Needs prefix
36
+ return './' + url;
37
+ }
38
+ /**
39
+ * A Sass Importer base class that provides the load logic to rebase all `url()` functions
40
+ * within a stylesheet. The rebasing will ensure that the URLs in the output of the Sass compiler
41
+ * reflect the final filesystem location of the output CSS file.
42
+ *
43
+ * This class provides the core of the rebasing functionality. To ensure that each file is processed
44
+ * by this importer's load implementation, the Sass compiler requires the importer's canonicalize
45
+ * function to return a non-null value with the resolved location of the requested stylesheet.
46
+ * Concrete implementations of this class must provide this canonicalize functionality for rebasing
47
+ * to be effective.
48
+ */
49
+ class UrlRebasingImporter {
50
+ entryDirectory;
51
+ rebaseSourceMaps;
52
+ /**
53
+ * @param entryDirectory The directory of the entry stylesheet that was passed to the Sass compiler.
54
+ * @param rebaseSourceMaps When provided, rebased files will have an intermediate sourcemap added to the Map
55
+ * which can be used to generate a final sourcemap that contains original sources.
56
+ */
57
+ constructor(entryDirectory, rebaseSourceMaps) {
58
+ this.entryDirectory = entryDirectory;
59
+ this.rebaseSourceMaps = rebaseSourceMaps;
60
+ }
61
+ load(canonicalUrl) {
62
+ const stylesheetPath = (0, node_url_1.fileURLToPath)(canonicalUrl);
63
+ const stylesheetDirectory = (0, node_path_1.dirname)(stylesheetPath);
64
+ let contents = (0, node_fs_1.readFileSync)(stylesheetPath, 'utf-8');
65
+ // Rebase any URLs that are found
66
+ let updatedContents;
67
+ for (const { start, end, value } of (0, lexer_1.findUrls)(contents)) {
68
+ // Skip if value is empty or Webpack-specific prefix
69
+ if (value.length === 0 || value[0] === '~' || value[0] === '^') {
70
+ continue;
71
+ }
72
+ // Skip if root-relative, absolute or protocol relative url
73
+ if (/^((?:\w+:)?\/\/|data:|chrome:|#|\/)/.test(value)) {
74
+ continue;
75
+ }
76
+ // Sass variable usage either starts with a `$` or contains a namespace and a `.$`
77
+ const valueNormalized = value[0] === '$' || /^\w+\.\$/.test(value) ? `#{${value}}` : value;
78
+ const rebasedPath = (0, node_path_1.relative)(this.entryDirectory, stylesheetDirectory) + '||file:' + valueNormalized;
79
+ // Normalize path separators and escape characters
80
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/url#syntax
81
+ const rebasedUrl = ensureRelative(rebasedPath.replace(/\\/g, '/').replace(/[()\s'"]/g, '\\$&'));
82
+ updatedContents ??= new magic_string_1.default(contents);
83
+ // Always quote the URL to avoid potential downstream parsing problems
84
+ updatedContents.update(start, end, `"${rebasedUrl}"`);
85
+ }
86
+ if (updatedContents) {
87
+ contents = updatedContents.toString();
88
+ if (this.rebaseSourceMaps) {
89
+ // Generate an intermediate source map for the rebasing changes
90
+ const map = updatedContents.generateMap({
91
+ hires: 'boundary',
92
+ includeContent: true,
93
+ source: canonicalUrl.href,
94
+ });
95
+ this.rebaseSourceMaps.set(canonicalUrl.href, map);
96
+ }
97
+ }
98
+ let syntax;
99
+ switch ((0, node_path_1.extname)(stylesheetPath).toLowerCase()) {
100
+ case '.css':
101
+ syntax = 'css';
102
+ break;
103
+ case '.sass':
104
+ syntax = 'indented';
105
+ break;
106
+ default:
107
+ syntax = 'scss';
108
+ break;
109
+ }
110
+ return {
111
+ contents,
112
+ syntax,
113
+ sourceMapUrl: canonicalUrl,
114
+ };
115
+ }
116
+ }
117
+ /**
118
+ * Provides the Sass importer logic to resolve relative stylesheet imports via both import and use rules
119
+ * and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that
120
+ * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.
121
+ */
122
+ class RelativeUrlRebasingImporter extends UrlRebasingImporter {
123
+ directoryCache;
124
+ constructor(entryDirectory, directoryCache = new Map(), rebaseSourceMaps) {
125
+ super(entryDirectory, rebaseSourceMaps);
126
+ this.directoryCache = directoryCache;
127
+ }
128
+ canonicalize(url, options) {
129
+ return this.resolveImport(url, options.fromImport, true);
130
+ }
131
+ /**
132
+ * Attempts to resolve a provided URL to a stylesheet file using the Sass compiler's resolution algorithm.
133
+ * Based on https://github.com/sass/dart-sass/blob/44d6bb6ac72fe6b93f5bfec371a1fffb18e6b76d/lib/src/importer/utils.dart
134
+ * @param url The file protocol URL to resolve.
135
+ * @param fromImport If true, URL was from an import rule; otherwise from a use rule.
136
+ * @param checkDirectory If true, try checking for a directory with the base name containing an index file.
137
+ * @returns A full resolved URL of the stylesheet file or `null` if not found.
138
+ */
139
+ resolveImport(url, fromImport, checkDirectory) {
140
+ let stylesheetPath;
141
+ try {
142
+ stylesheetPath = (0, node_url_1.fileURLToPath)(url);
143
+ }
144
+ catch {
145
+ // Only file protocol URLs are supported by this importer
146
+ return null;
147
+ }
148
+ const directory = (0, node_path_1.dirname)(stylesheetPath);
149
+ const extension = (0, node_path_1.extname)(stylesheetPath);
150
+ const hasStyleExtension = extension === '.scss' || extension === '.sass' || extension === '.css';
151
+ // Remove the style extension if present to allow adding the `.import` suffix
152
+ const filename = (0, node_path_1.basename)(stylesheetPath, hasStyleExtension ? extension : undefined);
153
+ const importPotentials = new Set();
154
+ const defaultPotentials = new Set();
155
+ if (hasStyleExtension) {
156
+ if (fromImport) {
157
+ importPotentials.add(filename + '.import' + extension);
158
+ importPotentials.add('_' + filename + '.import' + extension);
159
+ }
160
+ defaultPotentials.add(filename + extension);
161
+ defaultPotentials.add('_' + filename + extension);
162
+ }
163
+ else {
164
+ if (fromImport) {
165
+ importPotentials.add(filename + '.import.scss');
166
+ importPotentials.add(filename + '.import.sass');
167
+ importPotentials.add(filename + '.import.css');
168
+ importPotentials.add('_' + filename + '.import.scss');
169
+ importPotentials.add('_' + filename + '.import.sass');
170
+ importPotentials.add('_' + filename + '.import.css');
171
+ }
172
+ defaultPotentials.add(filename + '.scss');
173
+ defaultPotentials.add(filename + '.sass');
174
+ defaultPotentials.add(filename + '.css');
175
+ defaultPotentials.add('_' + filename + '.scss');
176
+ defaultPotentials.add('_' + filename + '.sass');
177
+ defaultPotentials.add('_' + filename + '.css');
178
+ }
179
+ let foundDefaults;
180
+ let foundImports;
181
+ let hasPotentialIndex = false;
182
+ let cachedEntries = this.directoryCache.get(directory);
183
+ if (cachedEntries) {
184
+ // If there is a preprocessed cache of the directory, perform an intersection of the potentials
185
+ // and the directory files.
186
+ const { files, directories } = cachedEntries;
187
+ foundDefaults = [...defaultPotentials].filter((potential) => files.has(potential));
188
+ foundImports = [...importPotentials].filter((potential) => files.has(potential));
189
+ hasPotentialIndex = checkDirectory && !hasStyleExtension && directories.has(filename);
190
+ }
191
+ else {
192
+ // If no preprocessed cache exists, get the entries from the file system and, while searching,
193
+ // generate the cache for later requests.
194
+ let entries;
195
+ try {
196
+ entries = (0, node_fs_1.readdirSync)(directory, { withFileTypes: true });
197
+ }
198
+ catch {
199
+ return null;
200
+ }
201
+ foundDefaults = [];
202
+ foundImports = [];
203
+ cachedEntries = { files: new Set(), directories: new Set() };
204
+ for (const entry of entries) {
205
+ let isDirectory;
206
+ let isFile;
207
+ if (entry.isSymbolicLink()) {
208
+ const stats = (0, node_fs_1.statSync)((0, node_path_1.join)(entry.path, entry.name));
209
+ isDirectory = stats.isDirectory();
210
+ isFile = stats.isFile();
211
+ }
212
+ else {
213
+ isDirectory = entry.isDirectory();
214
+ isFile = entry.isFile();
215
+ }
216
+ if (isDirectory) {
217
+ cachedEntries.directories.add(entry.name);
218
+ // Record if the name should be checked as a directory with an index file
219
+ if (checkDirectory && !hasStyleExtension && entry.name === filename) {
220
+ hasPotentialIndex = true;
221
+ }
222
+ }
223
+ if (!isFile) {
224
+ continue;
225
+ }
226
+ cachedEntries.files.add(entry.name);
227
+ if (importPotentials.has(entry.name)) {
228
+ foundImports.push(entry.name);
229
+ }
230
+ if (defaultPotentials.has(entry.name)) {
231
+ foundDefaults.push(entry.name);
232
+ }
233
+ }
234
+ this.directoryCache.set(directory, cachedEntries);
235
+ }
236
+ // `foundImports` will only contain elements if `options.fromImport` is true
237
+ const result = this.checkFound(foundImports) ?? this.checkFound(foundDefaults);
238
+ if (result !== null) {
239
+ return (0, node_url_1.pathToFileURL)((0, node_path_1.join)(directory, result));
240
+ }
241
+ if (hasPotentialIndex) {
242
+ // Check for index files using filename as a directory
243
+ return this.resolveImport(url + '/index', fromImport, false);
244
+ }
245
+ return null;
246
+ }
247
+ /**
248
+ * Checks an array of potential stylesheet files to determine if there is a valid
249
+ * stylesheet file. More than one discovered file may indicate an error.
250
+ * @param found An array of discovered stylesheet files.
251
+ * @returns A fully resolved path for a stylesheet file or `null` if not found.
252
+ * @throws If there are ambiguous files discovered.
253
+ */
254
+ checkFound(found) {
255
+ if (found.length === 0) {
256
+ // Not found
257
+ return null;
258
+ }
259
+ // More than one found file may be an error
260
+ if (found.length > 1) {
261
+ // Presence of CSS files alongside a Sass file does not cause an error
262
+ const foundWithoutCss = found.filter((element) => (0, node_path_1.extname)(element) !== '.css');
263
+ // If the length is zero then there are two or more css files
264
+ // If the length is more than one than there are two or more sass/scss files
265
+ if (foundWithoutCss.length !== 1) {
266
+ throw new Error('Ambiguous import detected.');
267
+ }
268
+ // Return the non-CSS file (sass/scss files have priority)
269
+ // https://github.com/sass/dart-sass/blob/44d6bb6ac72fe6b93f5bfec371a1fffb18e6b76d/lib/src/importer/utils.dart#L44-L47
270
+ return foundWithoutCss[0];
271
+ }
272
+ return found[0];
273
+ }
274
+ }
275
+ exports.RelativeUrlRebasingImporter = RelativeUrlRebasingImporter;
276
+ /**
277
+ * Provides the Sass importer logic to resolve module (npm package) stylesheet imports via both import and
278
+ * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that
279
+ * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.
280
+ */
281
+ class ModuleUrlRebasingImporter extends RelativeUrlRebasingImporter {
282
+ finder;
283
+ constructor(entryDirectory, directoryCache, rebaseSourceMaps, finder) {
284
+ super(entryDirectory, directoryCache, rebaseSourceMaps);
285
+ this.finder = finder;
286
+ }
287
+ canonicalize(url, options) {
288
+ if (url.startsWith('file://')) {
289
+ return super.canonicalize(url, options);
290
+ }
291
+ let result = this.finder(url, options);
292
+ result &&= super.canonicalize(result.href, options);
293
+ return result;
294
+ }
295
+ }
296
+ exports.ModuleUrlRebasingImporter = ModuleUrlRebasingImporter;
297
+ /**
298
+ * Provides the Sass importer logic to resolve load paths located stylesheet imports via both import and
299
+ * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that
300
+ * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.
301
+ */
302
+ class LoadPathsUrlRebasingImporter extends RelativeUrlRebasingImporter {
303
+ loadPaths;
304
+ constructor(entryDirectory, directoryCache, rebaseSourceMaps, loadPaths) {
305
+ super(entryDirectory, directoryCache, rebaseSourceMaps);
306
+ this.loadPaths = loadPaths;
307
+ }
308
+ canonicalize(url, options) {
309
+ if (url.startsWith('file://')) {
310
+ return super.canonicalize(url, options);
311
+ }
312
+ let result = null;
313
+ for (const loadPath of this.loadPaths) {
314
+ result = super.canonicalize((0, node_url_1.pathToFileURL)((0, node_path_1.join)(loadPath, url)).href, options);
315
+ if (result !== null) {
316
+ break;
317
+ }
318
+ }
319
+ return result;
320
+ }
321
+ }
322
+ exports.LoadPathsUrlRebasingImporter = LoadPathsUrlRebasingImporter;
323
+ /**
324
+ * Workaround for Sass not calling instance methods with `this`.
325
+ * The `canonicalize` and `load` methods will be bound to the class instance.
326
+ * @param importer A Sass importer to bind.
327
+ * @returns The bound Sass importer.
328
+ */
329
+ function sassBindWorkaround(importer) {
330
+ importer.canonicalize = importer.canonicalize.bind(importer);
331
+ importer.load = importer.load.bind(importer);
332
+ return importer;
333
+ }
334
+ exports.sassBindWorkaround = sassBindWorkaround;
@@ -0,0 +1,72 @@
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.io/license
7
+ */
8
+ import { CompileResult, Deprecation, SourceSpan, StringOptions } from 'sass';
9
+ export interface SerializableVersion {
10
+ major: number;
11
+ minor: number;
12
+ patch: number;
13
+ }
14
+ export interface SerializableDeprecation extends Omit<Deprecation, 'obsoleteIn' | 'deprecatedIn'> {
15
+ /** The version this deprecation first became active in. */
16
+ deprecatedIn: SerializableVersion | null;
17
+ /** The version this deprecation became obsolete in. */
18
+ obsoleteIn: SerializableVersion | null;
19
+ }
20
+ export type SerializableWarningMessage = ({
21
+ deprecation: true;
22
+ deprecationType: SerializableDeprecation;
23
+ } | {
24
+ deprecation: false;
25
+ }) & {
26
+ message: string;
27
+ span?: Omit<SourceSpan, 'url'> & {
28
+ url?: string;
29
+ };
30
+ stack?: string;
31
+ };
32
+ /**
33
+ * A Sass renderer implementation that provides an interface that can be used by Webpack's
34
+ * `sass-loader`. The implementation uses a Worker thread to perform the Sass rendering
35
+ * with the `dart-sass` package. The `dart-sass` synchronous render function is used within
36
+ * the worker which can be up to two times faster than the asynchronous variant.
37
+ */
38
+ export declare class SassWorkerImplementation {
39
+ private rebase;
40
+ private readonly workers;
41
+ private readonly availableWorkers;
42
+ private readonly requests;
43
+ private readonly workerPath;
44
+ private idCounter;
45
+ private nextWorkerIndex;
46
+ constructor(rebase?: boolean);
47
+ /**
48
+ * Provides information about the Sass implementation.
49
+ * This mimics enough of the `dart-sass` value to be used with the `sass-loader`.
50
+ */
51
+ get info(): string;
52
+ /**
53
+ * The synchronous render function is not used by the `sass-loader`.
54
+ */
55
+ compileString(): never;
56
+ /**
57
+ * Asynchronously request a Sass stylesheet to be renderered.
58
+ *
59
+ * @param source The contents to compile.
60
+ * @param options The `dart-sass` options to use when rendering the stylesheet.
61
+ */
62
+ compileStringAsync(source: string, options: StringOptions<'async'>): Promise<CompileResult>;
63
+ /**
64
+ * Shutdown the Sass render worker.
65
+ * Executing this method will stop any pending render requests.
66
+ */
67
+ close(): void;
68
+ private createWorker;
69
+ private processImporters;
70
+ private createRequest;
71
+ private isFileImporter;
72
+ }