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