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