@analogjs/vite-plugin-angular 1.0.0-beta.2 → 1.0.0-beta.4

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 (40) hide show
  1. package/package.json +4 -1
  2. package/setup-vitest.js +7 -2
  3. package/setup-vitest.js.map +1 -1
  4. package/src/index.d.ts +1 -0
  5. package/src/index.js +1 -0
  6. package/src/index.js.map +1 -1
  7. package/src/lib/angular-build-optimizer-plugin.js +48 -51
  8. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  9. package/src/lib/angular-jit-plugin.js +14 -17
  10. package/src/lib/angular-jit-plugin.js.map +1 -1
  11. package/src/lib/angular-vite-plugin.d.ts +13 -2
  12. package/src/lib/angular-vite-plugin.js +311 -248
  13. package/src/lib/angular-vite-plugin.js.map +1 -1
  14. package/src/lib/angular-vitest-plugin.js +15 -18
  15. package/src/lib/angular-vitest-plugin.js.map +1 -1
  16. package/src/lib/authoring/analog.d.ts +1 -0
  17. package/src/lib/authoring/analog.js +373 -0
  18. package/src/lib/authoring/analog.js.map +1 -0
  19. package/src/lib/authoring/constants.d.ts +20 -0
  20. package/src/lib/authoring/constants.js +38 -0
  21. package/src/lib/authoring/constants.js.map +1 -0
  22. package/src/lib/authoring/frontmatter.d.ts +1 -0
  23. package/src/lib/authoring/frontmatter.js +10 -0
  24. package/src/lib/authoring/frontmatter.js.map +1 -0
  25. package/src/lib/authoring/marked-setup.service.d.ts +19 -0
  26. package/src/lib/authoring/marked-setup.service.js +91 -0
  27. package/src/lib/authoring/marked-setup.service.js.map +1 -0
  28. package/src/lib/compiler-plugin.js +12 -15
  29. package/src/lib/compiler-plugin.js.map +1 -1
  30. package/src/lib/component-resolvers.d.ts +2 -2
  31. package/src/lib/component-resolvers.js +35 -45
  32. package/src/lib/component-resolvers.js.map +1 -1
  33. package/src/lib/host.d.ts +4 -0
  34. package/src/lib/host.js +70 -21
  35. package/src/lib/host.js.map +1 -1
  36. package/src/lib/utils/devkit.js.map +1 -1
  37. package/src/lib/utils/source-file-cache.js +5 -3
  38. package/src/lib/utils/source-file-cache.js.map +1 -1
  39. package/vite.config.js +3 -1
  40. package/vite.config.js.map +1 -1
@@ -1,43 +1,46 @@
1
- import { __awaiter } from "tslib";
2
1
  import { transformAsync } from '@babel/core';
3
- import * as compilerCli from '@angular/compiler-cli';
4
2
  import * as path from 'node:path';
3
+ import * as compilerCli from '@angular/compiler-cli';
4
+ import * as ts from 'typescript';
5
5
  import { createRequire } from 'node:module';
6
+ import { normalizePath, } from 'vite';
6
7
  import { createCompilerPlugin } from './compiler-plugin.js';
7
- import { hasStyleUrls, hasTemplateUrl, StyleUrlsResolver, TemplateUrlsResolver, } from './component-resolvers.js';
8
+ import { StyleUrlsResolver, TemplateUrlsResolver, } from './component-resolvers.js';
8
9
  import { augmentHostWithResources } from './host.js';
9
10
  import { jitPlugin } from './angular-jit-plugin.js';
10
11
  import { buildOptimizerPlugin } from './angular-build-optimizer-plugin.js';
11
12
  import { angularApplicationPreset, createJitResourceTransformer, SourceFileCache, } from './utils/devkit.js';
12
13
  import { angularVitestPlugin } from './angular-vitest-plugin.js';
13
14
  const require = createRequire(import.meta.url);
15
+ import { getFrontmatterMetadata } from './authoring/frontmatter.js';
14
16
  /**
15
17
  * TypeScript file extension regex
16
18
  * Match .(c or m)ts, .ts extensions with an optional ? for query params
17
19
  * Ignore .tsx extensions
18
20
  */
19
- const TS_EXT_REGEX = /\.[cm]?ts[^x]?\??/;
21
+ const TS_EXT_REGEX = /\.[cm]?(ts|analog|ag)[^x]?\??/;
20
22
  export function angular(options) {
21
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
22
23
  /**
23
24
  * Normalize plugin options so defaults
24
25
  * are used for values not provided.
25
26
  */
26
27
  const pluginOptions = {
27
- tsconfig: (_a = options === null || options === void 0 ? void 0 : options.tsconfig) !== null && _a !== void 0 ? _a : (process.env['NODE_ENV'] === 'test'
28
- ? './tsconfig.spec.json'
29
- : './tsconfig.app.json'),
30
- workspaceRoot: (_b = options === null || options === void 0 ? void 0 : options.workspaceRoot) !== null && _b !== void 0 ? _b : process.cwd(),
31
- inlineStylesExtension: (_c = options === null || options === void 0 ? void 0 : options.inlineStylesExtension) !== null && _c !== void 0 ? _c : 'css',
28
+ tsconfig: options?.tsconfig ??
29
+ (process.env['NODE_ENV'] === 'test'
30
+ ? './tsconfig.spec.json'
31
+ : './tsconfig.app.json'),
32
+ workspaceRoot: options?.workspaceRoot ?? process.cwd(),
33
+ inlineStylesExtension: options?.inlineStylesExtension ?? 'css',
32
34
  advanced: {
33
35
  tsTransformers: {
34
- before: (_f = (_e = (_d = options === null || options === void 0 ? void 0 : options.advanced) === null || _d === void 0 ? void 0 : _d.tsTransformers) === null || _e === void 0 ? void 0 : _e.before) !== null && _f !== void 0 ? _f : [],
35
- after: (_j = (_h = (_g = options === null || options === void 0 ? void 0 : options.advanced) === null || _g === void 0 ? void 0 : _g.tsTransformers) === null || _h === void 0 ? void 0 : _h.after) !== null && _j !== void 0 ? _j : [],
36
- afterDeclarations: (_m = (_l = (_k = options === null || options === void 0 ? void 0 : options.advanced) === null || _k === void 0 ? void 0 : _k.tsTransformers) === null || _l === void 0 ? void 0 : _l.afterDeclarations) !== null && _m !== void 0 ? _m : [],
36
+ before: options?.advanced?.tsTransformers?.before ?? [],
37
+ after: options?.advanced?.tsTransformers?.after ?? [],
38
+ afterDeclarations: options?.advanced?.tsTransformers?.afterDeclarations ?? [],
37
39
  },
38
40
  },
39
- supportedBrowsers: (_o = options === null || options === void 0 ? void 0 : options.supportedBrowsers) !== null && _o !== void 0 ? _o : ['safari 15'],
40
- jit: options === null || options === void 0 ? void 0 : options.jit,
41
+ supportedBrowsers: options?.supportedBrowsers ?? ['safari 15'],
42
+ jit: options?.jit,
43
+ supportAnalogFormat: options?.experimental?.supportAnalogFormat ?? false,
41
44
  };
42
45
  // The file emitter created during `onStart` that will be used during the build in `onLoad` callbacks for TS files
43
46
  let fileEmitter;
@@ -46,6 +49,8 @@ export function angular(options) {
46
49
  const { mergeTransformers, replaceBootstrap, } = require('@ngtools/webpack/src/ivy/transformation');
47
50
  const { augmentProgramWithVersioning, augmentHostWithCaching, } = require('@ngtools/webpack/src/ivy/host');
48
51
  const ts = require('typescript');
52
+ // let compilerCli: typeof import('@angular/compiler-cli');
53
+ let userConfig;
49
54
  let rootNames;
50
55
  let host;
51
56
  let nextProgram;
@@ -54,7 +59,7 @@ export function angular(options) {
54
59
  const sourceFileCache = new SourceFileCache();
55
60
  const isProd = process.env['NODE_ENV'] === 'production';
56
61
  const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];
57
- const jit = typeof (pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.jit) !== 'undefined' ? pluginOptions.jit : isTest;
62
+ const jit = typeof pluginOptions?.jit !== 'undefined' ? pluginOptions.jit : isTest;
58
63
  let viteServer;
59
64
  let cssPlugin;
60
65
  let styleTransform;
@@ -63,212 +68,225 @@ export function angular(options) {
63
68
  function angularPlugin() {
64
69
  return {
65
70
  name: '@analogjs/vite-plugin-angular',
66
- config(config, { command }) {
67
- var _a;
68
- return __awaiter(this, void 0, void 0, function* () {
69
- watchMode = command === 'serve';
70
- pluginOptions.tsconfig =
71
- (_a = options === null || options === void 0 ? void 0 : options.tsconfig) !== null && _a !== void 0 ? _a : path.resolve(config.root || '.', process.env['NODE_ENV'] === 'test'
71
+ async config(config, { command }) {
72
+ watchMode = command === 'serve';
73
+ userConfig = config;
74
+ pluginOptions.tsconfig =
75
+ options?.tsconfig ??
76
+ path.resolve(config.root || '.', process.env['NODE_ENV'] === 'test'
72
77
  ? './tsconfig.spec.json'
73
78
  : './tsconfig.app.json');
74
- return {
75
- optimizeDeps: {
76
- include: ['rxjs/operators', 'rxjs'],
77
- exclude: ['@angular/platform-server'],
78
- esbuildOptions: {
79
- plugins: [
80
- createCompilerPlugin({
81
- tsconfig: pluginOptions.tsconfig,
82
- sourcemap: !isProd,
83
- advancedOptimizations: isProd,
84
- jit,
85
- incremental: watchMode,
86
- }, isTest),
87
- ],
88
- define: Object.assign({ ngJitMode: 'false', ngI18nClosureMode: 'false' }, (watchMode ? {} : { ngDevMode: 'false' })),
79
+ return {
80
+ optimizeDeps: {
81
+ include: ['rxjs/operators', 'rxjs'],
82
+ exclude: ['@angular/platform-server'],
83
+ esbuildOptions: {
84
+ plugins: [
85
+ createCompilerPlugin({
86
+ tsconfig: pluginOptions.tsconfig,
87
+ sourcemap: !isProd,
88
+ advancedOptimizations: isProd,
89
+ jit,
90
+ incremental: watchMode,
91
+ }, isTest),
92
+ ],
93
+ define: {
94
+ ngJitMode: 'false',
95
+ ngI18nClosureMode: 'false',
96
+ ...(watchMode ? {} : { ngDevMode: 'false' }),
89
97
  },
90
98
  },
91
- resolve: {
92
- conditions: ['style'],
93
- },
94
- };
95
- });
99
+ },
100
+ resolve: {
101
+ conditions: ['style'],
102
+ },
103
+ };
96
104
  },
97
105
  configureServer(server) {
98
106
  viteServer = server;
99
107
  server.watcher.on('add', setupCompilation);
100
108
  server.watcher.on('unlink', setupCompilation);
101
109
  },
102
- buildStart({ plugins }) {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- if (Array.isArray(plugins)) {
105
- cssPlugin = plugins.find((plugin) => plugin.name === 'vite:css');
106
- }
107
- setupCompilation();
108
- // Only store cache if in watch mode
109
- if (watchMode) {
110
- augmentHostWithCaching(host, sourceFileCache);
111
- }
112
- yield buildAndAnalyze();
113
- });
110
+ async buildStart({ plugins }) {
111
+ if (Array.isArray(plugins)) {
112
+ cssPlugin = plugins.find((plugin) => plugin.name === 'vite:css');
113
+ }
114
+ setupCompilation(userConfig);
115
+ // Only store cache if in watch mode
116
+ if (watchMode) {
117
+ augmentHostWithCaching(host, sourceFileCache);
118
+ }
119
+ await buildAndAnalyze();
114
120
  },
115
- handleHotUpdate(ctx) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- // The `handleHotUpdate` hook may be called before the `buildStart`,
118
- // which sets the compilation. As a result, the `host` may not be available
119
- // yet for use, leading to build errors such as "cannot read properties of undefined"
120
- // (because `host` is undefined).
121
- if (!host) {
122
- return;
123
- }
124
- if (TS_EXT_REGEX.test(ctx.file)) {
125
- sourceFileCache.invalidate([ctx.file.replace(/\?(.*)/, '')]);
126
- yield buildAndAnalyze();
121
+ async handleHotUpdate(ctx) {
122
+ // The `handleHotUpdate` hook may be called before the `buildStart`,
123
+ // which sets the compilation. As a result, the `host` may not be available
124
+ // yet for use, leading to build errors such as "cannot read properties of undefined"
125
+ // (because `host` is undefined).
126
+ if (!host) {
127
+ return;
128
+ }
129
+ if (TS_EXT_REGEX.test(ctx.file)) {
130
+ sourceFileCache.invalidate([ctx.file.replace(/\?(.*)/, '')]);
131
+ await buildAndAnalyze();
132
+ }
133
+ if (/\.(html|htm|css|less|sass|scss)$/.test(ctx.file)) {
134
+ /**
135
+ * Check to see if this was a direct request
136
+ * for an external resource (styles, html).
137
+ */
138
+ const isDirect = ctx.modules.find((mod) => ctx.file === mod.file && mod.id?.includes('?direct'));
139
+ if (isDirect) {
140
+ return ctx.modules;
127
141
  }
128
- if (/\.(html|htm|css|less|sass|scss)$/.test(ctx.file)) {
129
- /**
130
- * Check to see if this was a direct request
131
- * for an external resource (styles, html).
132
- */
133
- const isDirect = ctx.modules.find((mod) => { var _a; return ctx.file === mod.file && ((_a = mod.id) === null || _a === void 0 ? void 0 : _a.includes('?direct')); });
134
- if (isDirect) {
135
- return ctx.modules;
136
- }
137
- const mods = [];
138
- ctx.modules.forEach((mod) => {
139
- mod.importers.forEach((imp) => {
140
- sourceFileCache.invalidate([imp.id]);
141
- ctx.server.moduleGraph.invalidateModule(imp);
142
- mods.push(imp);
143
- });
142
+ const mods = [];
143
+ ctx.modules.forEach((mod) => {
144
+ mod.importers.forEach((imp) => {
145
+ sourceFileCache.invalidate([imp.id]);
146
+ ctx.server.moduleGraph.invalidateModule(imp);
147
+ mods.push(imp);
144
148
  });
145
- yield buildAndAnalyze();
146
- return mods;
147
- }
148
- return ctx.modules;
149
- });
149
+ });
150
+ await buildAndAnalyze();
151
+ return mods;
152
+ }
153
+ return ctx.modules;
150
154
  },
151
- transform(code, id) {
152
- var _a, _b, _c;
153
- return __awaiter(this, void 0, void 0, function* () {
154
- // Skip transforming node_modules
155
- if (id.includes('node_modules')) {
156
- return;
155
+ async transform(code, id) {
156
+ // Skip transforming node_modules
157
+ if (id.includes('node_modules')) {
158
+ return;
159
+ }
160
+ /**
161
+ * Check for options.transformFilter
162
+ */
163
+ if (options?.transformFilter &&
164
+ !(options?.transformFilter(code, id) ?? true)) {
165
+ return;
166
+ }
167
+ /**
168
+ * Check for .ts extenstions for inline script files being
169
+ * transformed (Astro).
170
+ *
171
+ * Example ID:
172
+ *
173
+ * /src/pages/index.astro?astro&type=script&index=0&lang.ts
174
+ */
175
+ if (id.includes('type=script')) {
176
+ return;
177
+ }
178
+ /**
179
+ * Skip transforming content files
180
+ */
181
+ if (id.includes('analog-content-list=true')) {
182
+ return;
183
+ }
184
+ if (TS_EXT_REGEX.test(id)) {
185
+ if (id.includes('.ts?')) {
186
+ // Strip the query string off the ID
187
+ // in case of a dynamically loaded file
188
+ id = id.replace(/\?(.*)/, '');
157
189
  }
158
190
  /**
159
- * Check for options.transformFilter
191
+ * Re-analyze on each transform
192
+ * for test(Vitest)
160
193
  */
161
- if (options === null || options === void 0 ? void 0 : options.transformFilter) {
162
- if (!((_a = options === null || options === void 0 ? void 0 : options.transformFilter(code, id)) !== null && _a !== void 0 ? _a : true)) {
163
- return;
194
+ if (isTest) {
195
+ const tsMod = viteServer?.moduleGraph.getModuleById(id);
196
+ if (tsMod) {
197
+ sourceFileCache.invalidate([id]);
198
+ await buildAndAnalyze();
164
199
  }
165
200
  }
166
- /**
167
- * Check for .ts extenstions for inline script files being
168
- * transformed (Astro).
169
- *
170
- * Example ID:
171
- *
172
- * /src/pages/index.astro?astro&type=script&index=0&lang.ts
173
- */
174
- if (id.includes('type=script')) {
175
- return;
176
- }
177
- if (TS_EXT_REGEX.test(id)) {
178
- if (id.includes('.ts?')) {
179
- // Strip the query string off the ID
180
- // in case of a dynamically loaded file
181
- id = id.replace(/\?(.*)/, '');
182
- }
183
- /**
184
- * Re-analyze on each transform
185
- * for test(Vitest)
186
- */
187
- if (isTest) {
188
- const tsMod = viteServer === null || viteServer === void 0 ? void 0 : viteServer.moduleGraph.getModuleById(id);
189
- if (tsMod) {
190
- sourceFileCache.invalidate([id]);
191
- yield buildAndAnalyze();
192
- }
193
- }
194
- let templateUrls = [];
195
- let styleUrls = [];
196
- if (hasTemplateUrl(code)) {
197
- templateUrls = templateUrlsResolver.resolve(code, id);
198
- }
199
- if (hasStyleUrls(code)) {
200
- styleUrls = styleUrlsResolver.resolve(code, id);
201
- }
202
- if (watchMode) {
203
- for (const urlSet of [...templateUrls, ...styleUrls]) {
204
- // `urlSet` is a string where a relative path is joined with an
205
- // absolute path using the `|` symbol.
206
- // For example: `./app.component.html|/home/projects/analog/src/app/app.component.html`.
207
- const [, absoluteFileUrl] = urlSet.split('|');
208
- this.addWatchFile(absoluteFileUrl);
209
- }
210
- }
211
- const typescriptResult = yield fileEmitter(id);
212
- // return fileEmitter
213
- let data = (_b = typescriptResult === null || typescriptResult === void 0 ? void 0 : typescriptResult.content) !== null && _b !== void 0 ? _b : '';
214
- if (jit && data.includes('angular:jit:')) {
215
- data = data.replace(/angular:jit:style:inline;/g, 'virtual:angular:jit:style:inline;');
216
- templateUrls.forEach((templateUrlSet) => {
217
- const [templateFile, resolvedTemplateUrl] = templateUrlSet.split('|');
218
- data = data.replace(`angular:jit:template:file;${templateFile}`, `${resolvedTemplateUrl}?raw`);
219
- });
220
- styleUrls.forEach((styleUrlSet) => {
221
- const [styleFile, resolvedStyleUrl] = styleUrlSet.split('|');
222
- data = data.replace(`angular:jit:style:file;${styleFile}`, `${resolvedStyleUrl}?inline`);
223
- });
224
- }
225
- if (jit) {
226
- return {
227
- code: data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''),
228
- map: {
229
- mappings: '',
230
- },
231
- };
232
- }
233
- const forceAsyncTransformation = /for\s+await\s*\(|async\s+function\s*\*/.test(data);
234
- const useInputSourcemap = (!isProd ? undefined : false);
235
- if (!forceAsyncTransformation && !isProd) {
236
- return {
237
- code: data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''),
238
- map: {
239
- mappings: '',
240
- },
241
- };
201
+ const templateUrls = templateUrlsResolver.resolve(code, id);
202
+ const styleUrls = styleUrlsResolver.resolve(code, id);
203
+ if (watchMode) {
204
+ for (const urlSet of [...templateUrls, ...styleUrls]) {
205
+ // `urlSet` is a string where a relative path is joined with an
206
+ // absolute path using the `|` symbol.
207
+ // For example: `./app.component.html|/home/projects/analog/src/app/app.component.html`.
208
+ const [, absoluteFileUrl] = urlSet.split('|');
209
+ this.addWatchFile(absoluteFileUrl);
242
210
  }
243
- const babelResult = yield transformAsync(data, {
244
- filename: id,
245
- inputSourceMap: (useInputSourcemap
246
- ? undefined
247
- : false),
248
- sourceMaps: !isProd ? 'inline' : false,
249
- compact: false,
250
- configFile: false,
251
- babelrc: false,
252
- browserslistConfigFile: false,
253
- plugins: [],
254
- presets: [
255
- [
256
- angularApplicationPreset,
257
- {
258
- supportedBrowsers: pluginOptions.supportedBrowsers,
259
- forceAsyncTransformation,
260
- optimize: isProd && {},
261
- },
262
- ],
263
- ],
211
+ }
212
+ const typescriptResult = await fileEmitter?.(id);
213
+ if (typescriptResult?.warnings &&
214
+ typescriptResult?.warnings.length > 0) {
215
+ this.warn(`${typescriptResult.warnings.join('\n')}`);
216
+ }
217
+ if (typescriptResult?.errors && typescriptResult?.errors.length > 0) {
218
+ this.error(`${typescriptResult.errors.join('\n')}`);
219
+ }
220
+ // return fileEmitter
221
+ let data = typescriptResult?.content ?? '';
222
+ if (jit && data.includes('angular:jit:')) {
223
+ data = data.replace(/angular:jit:style:inline;/g, 'virtual:angular:jit:style:inline;');
224
+ templateUrls.forEach((templateUrlSet) => {
225
+ const [templateFile, resolvedTemplateUrl] = templateUrlSet.split('|');
226
+ data = data.replace(`angular:jit:template:file;${templateFile}`, `${resolvedTemplateUrl}?raw`);
264
227
  });
228
+ styleUrls.forEach((styleUrlSet) => {
229
+ const [styleFile, resolvedStyleUrl] = styleUrlSet.split('|');
230
+ data = data.replace(`angular:jit:style:file;${styleFile}`, `${resolvedStyleUrl}?inline`);
231
+ });
232
+ }
233
+ if (jit) {
265
234
  return {
266
- code: (_c = babelResult === null || babelResult === void 0 ? void 0 : babelResult.code) !== null && _c !== void 0 ? _c : '',
267
- map: babelResult === null || babelResult === void 0 ? void 0 : babelResult.map,
235
+ code: data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''),
236
+ map: {
237
+ mappings: '',
238
+ },
268
239
  };
269
240
  }
270
- return undefined;
271
- });
241
+ const forceAsyncTransformation = /for\s+await\s*\(|async\s+function\s*\*/.test(data);
242
+ const useInputSourcemap = (!isProd ? undefined : false);
243
+ if ((id.includes('.analog') || id.includes('.agx')) &&
244
+ pluginOptions.supportAnalogFormat &&
245
+ fileEmitter) {
246
+ sourceFileCache.invalidate([`${id}.ts`]);
247
+ const ngFileResult = await fileEmitter(`${id}.ts`);
248
+ data = ngFileResult?.content || '';
249
+ if (id.includes('.agx')) {
250
+ const metadata = await getFrontmatterMetadata(code);
251
+ data += metadata;
252
+ }
253
+ }
254
+ if (!forceAsyncTransformation && !isProd) {
255
+ return {
256
+ code: data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, ''),
257
+ map: {
258
+ mappings: '',
259
+ },
260
+ };
261
+ }
262
+ const babelResult = await transformAsync(data, {
263
+ filename: id,
264
+ inputSourceMap: (useInputSourcemap
265
+ ? undefined
266
+ : false),
267
+ sourceMaps: !isProd ? 'inline' : false,
268
+ compact: false,
269
+ configFile: false,
270
+ babelrc: false,
271
+ browserslistConfigFile: false,
272
+ plugins: [],
273
+ presets: [
274
+ [
275
+ angularApplicationPreset,
276
+ {
277
+ supportedBrowsers: pluginOptions.supportedBrowsers,
278
+ forceAsyncTransformation,
279
+ optimize: isProd && {},
280
+ },
281
+ ],
282
+ ],
283
+ });
284
+ return {
285
+ code: babelResult?.code ?? '',
286
+ map: babelResult?.map,
287
+ };
288
+ }
289
+ return undefined;
272
290
  },
273
291
  };
274
292
  }
@@ -284,10 +302,36 @@ export function angular(options) {
284
302
  supportedBrowsers: pluginOptions.supportedBrowsers,
285
303
  }),
286
304
  ].filter(Boolean);
287
- function setupCompilation() {
305
+ function findAnalogFiles(config) {
306
+ const analogConfig = pluginOptions.supportAnalogFormat;
307
+ if (!analogConfig) {
308
+ return [];
309
+ }
310
+ let extraGlobs = [];
311
+ if (typeof analogConfig === 'object') {
312
+ if (analogConfig.include) {
313
+ extraGlobs = analogConfig.include;
314
+ }
315
+ }
316
+ const fg = require('fast-glob');
317
+ const appRoot = normalizePath(path.resolve(pluginOptions.workspaceRoot, config.root || '.'));
318
+ const workspaceRoot = normalizePath(path.resolve(pluginOptions.workspaceRoot));
319
+ const globs = [
320
+ `${appRoot}/**/*.{analog,agx}`,
321
+ ...extraGlobs.map((glob) => `${workspaceRoot}${glob}.{analog,agx}`),
322
+ ];
323
+ return fg
324
+ .sync(globs, {
325
+ dot: true,
326
+ })
327
+ .map((file) => `${file}.ts`);
328
+ }
329
+ function setupCompilation(config) {
330
+ const analogFiles = findAnalogFiles(config);
288
331
  const { options: tsCompilerOptions, rootNames: rn } = compilerCli.readConfiguration(pluginOptions.tsconfig, {
289
332
  suppressOutputPathCheck: true,
290
333
  outDir: undefined,
334
+ sourceMap: false,
291
335
  inlineSourceMap: !isProd,
292
336
  inlineSources: !isProd,
293
337
  declaration: false,
@@ -295,9 +339,19 @@ export function angular(options) {
295
339
  allowEmptyCodegenFiles: false,
296
340
  annotationsAs: 'decorators',
297
341
  enableResourceInlining: false,
342
+ noEmitOnError: false,
343
+ mapRoot: undefined,
344
+ sourceRoot: undefined,
298
345
  supportTestBed: false,
346
+ supportJitMode: false,
299
347
  });
300
- rootNames = rn;
348
+ if (pluginOptions.supportAnalogFormat) {
349
+ // Experimental Local Compilation is necessary
350
+ // for the Angular compiler to work with
351
+ // AOT and virtually compiled .analog files.
352
+ tsCompilerOptions.compilationMode = 'experimental-local';
353
+ }
354
+ rootNames = rn.concat(analogFiles);
301
355
  compilerOptions = tsCompilerOptions;
302
356
  host = ts.createIncrementalCompilerHost(compilerOptions);
303
357
  styleTransform = watchMode
@@ -306,6 +360,8 @@ export function angular(options) {
306
360
  if (!jit) {
307
361
  augmentHostWithResources(host, styleTransform, {
308
362
  inlineStylesExtension: pluginOptions.inlineStylesExtension,
363
+ supportAnalogFormat: pluginOptions.supportAnalogFormat,
364
+ isProd,
309
365
  });
310
366
  }
311
367
  }
@@ -314,65 +370,72 @@ export function angular(options) {
314
370
  * the source files and create a file emitter.
315
371
  * This is shared between an initial build and a hot update.
316
372
  */
317
- function buildAndAnalyze() {
318
- return __awaiter(this, void 0, void 0, function* () {
319
- let builder;
320
- let typeScriptProgram;
321
- let angularCompiler;
322
- if (!jit) {
323
- // Create the Angular specific program that contains the Angular compiler
324
- const angularProgram = new compilerCli.NgtscProgram(rootNames, compilerOptions, host, nextProgram);
325
- angularCompiler = angularProgram.compiler;
326
- typeScriptProgram = angularProgram.getTsProgram();
327
- augmentProgramWithVersioning(typeScriptProgram);
328
- builder = builderProgram =
329
- ts.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, host, builderProgram);
330
- yield angularCompiler.analyzeAsync();
331
- nextProgram = angularProgram;
332
- }
333
- else {
334
- builder = builderProgram =
335
- ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, compilerOptions, host, nextProgram);
336
- typeScriptProgram = builder.getProgram();
337
- nextProgram = builderProgram;
338
- }
339
- if (!watchMode) {
340
- // When not in watch mode, the startup cost of the incremental analysis can be avoided by
341
- // using an abstract builder that only wraps a TypeScript program.
342
- builder = ts.createAbstractBuilder(typeScriptProgram, host);
343
- }
344
- const getTypeChecker = () => builder.getProgram().getTypeChecker();
345
- fileEmitter = createFileEmitter(builder, mergeTransformers({
346
- before: [
347
- replaceBootstrap(getTypeChecker),
348
- ...(jit
349
- ? [
350
- compilerCli.constructorParametersDownlevelTransform(builder.getProgram()),
351
- createJitResourceTransformer(getTypeChecker),
352
- ]
353
- : []),
354
- ...pluginOptions.advanced.tsTransformers.before,
355
- ],
356
- after: pluginOptions.advanced.tsTransformers.after,
357
- afterDeclarations: pluginOptions.advanced.tsTransformers.afterDeclarations,
358
- }, jit ? {} : angularCompiler.prepareEmit().transformers), () => []);
359
- });
373
+ async function buildAndAnalyze() {
374
+ let builder;
375
+ let typeScriptProgram;
376
+ let angularCompiler;
377
+ if (!jit) {
378
+ // Create the Angular specific program that contains the Angular compiler
379
+ const angularProgram = new compilerCli.NgtscProgram(rootNames, compilerOptions, host, nextProgram);
380
+ angularCompiler = angularProgram.compiler;
381
+ typeScriptProgram = angularProgram.getTsProgram();
382
+ augmentProgramWithVersioning(typeScriptProgram);
383
+ builder = builderProgram =
384
+ ts.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, host, builderProgram);
385
+ await angularCompiler.analyzeAsync();
386
+ nextProgram = angularProgram;
387
+ }
388
+ else {
389
+ builder = builderProgram =
390
+ ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, compilerOptions, host, nextProgram);
391
+ typeScriptProgram = builder.getProgram();
392
+ nextProgram = builderProgram;
393
+ }
394
+ if (!watchMode) {
395
+ // When not in watch mode, the startup cost of the incremental analysis can be avoided by
396
+ // using an abstract builder that only wraps a TypeScript program.
397
+ builder = ts.createAbstractBuilder(typeScriptProgram, host);
398
+ }
399
+ const getTypeChecker = () => builder.getProgram().getTypeChecker();
400
+ fileEmitter = createFileEmitter(builder, mergeTransformers({
401
+ before: [
402
+ replaceBootstrap(getTypeChecker),
403
+ ...(jit
404
+ ? [
405
+ compilerCli.constructorParametersDownlevelTransform(builder.getProgram()),
406
+ createJitResourceTransformer(getTypeChecker),
407
+ ]
408
+ : []),
409
+ ...pluginOptions.advanced.tsTransformers.before,
410
+ ],
411
+ after: pluginOptions.advanced.tsTransformers.after,
412
+ afterDeclarations: pluginOptions.advanced.tsTransformers.afterDeclarations,
413
+ }, jit ? {} : angularCompiler.prepareEmit().transformers), () => [], angularCompiler);
360
414
  }
361
415
  }
362
- export function createFileEmitter(program, transformers = {}, onAfterEmit) {
363
- return (file) => __awaiter(this, void 0, void 0, function* () {
416
+ export function createFileEmitter(program, transformers = {}, onAfterEmit, angularCompiler) {
417
+ return async (file) => {
364
418
  const sourceFile = program.getSourceFile(file);
365
419
  if (!sourceFile) {
366
420
  return undefined;
367
421
  }
422
+ const diagnostics = angularCompiler
423
+ ? angularCompiler.getDiagnosticsForFile(sourceFile, 1)
424
+ : [];
425
+ const errors = diagnostics
426
+ .filter((d) => d.category === ts.DiagnosticCategory.Error)
427
+ .map((d) => d.messageText);
428
+ const warnings = diagnostics
429
+ .filter((d) => d.category === ts.DiagnosticCategory.Warning)
430
+ .map((d) => d.messageText);
368
431
  let content;
369
432
  program.emit(sourceFile, (filename, data) => {
370
433
  if (/\.[cm]?js$/.test(filename)) {
371
434
  content = data;
372
435
  }
373
436
  }, undefined /* cancellationToken */, undefined /* emitOnlyDtsFiles */, transformers);
374
- onAfterEmit === null || onAfterEmit === void 0 ? void 0 : onAfterEmit(sourceFile);
375
- return { content, dependencies: [] };
376
- });
437
+ onAfterEmit?.(sourceFile);
438
+ return { content, dependencies: [], errors, warnings };
439
+ };
377
440
  }
378
441
  //# sourceMappingURL=angular-vite-plugin.js.map