@analogjs/vite-plugin-angular 3.0.0-alpha.9 → 3.0.0-alpha.90
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/README.md +121 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.d.ts +2 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
- package/migrations/migration.json +7 -1
- package/migrations/migrations.json +9 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +2 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js +36 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js.map +1 -0
- package/package.json +49 -8
- package/src/index.d.ts +7 -2
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
- package/src/lib/analog-plugin-interop.d.ts +78 -0
- package/src/lib/analog-plugin-interop.js +97 -0
- package/src/lib/analog-plugin-interop.js.map +1 -0
- package/src/lib/angular-build-optimizer-plugin.d.ts +8 -4
- package/src/lib/angular-build-optimizer-plugin.js +66 -31
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.d.ts +3 -3
- package/src/lib/angular-jit-plugin.js +28 -6
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
- package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +79 -69
- package/src/lib/angular-vite-plugin.js +774 -352
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +26 -21
- package/src/lib/angular-vitest-plugin.js +34 -25
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compilation-api/compilation-api-plugin.d.ts +24 -0
- package/src/lib/compilation-api/compilation-api-plugin.js +547 -0
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -0
- package/src/lib/compilation-api/index.d.ts +1 -0
- package/src/lib/compilation-api/index.js +1 -0
- package/src/lib/compiler/angular-version.d.ts +19 -0
- package/src/lib/compiler/angular-version.js +31 -0
- package/src/lib/compiler/angular-version.js.map +1 -0
- package/src/lib/compiler/class-field-lowering.d.ts +23 -0
- package/src/lib/compiler/class-field-lowering.js +131 -0
- package/src/lib/compiler/class-field-lowering.js.map +1 -0
- package/src/lib/compiler/compile.d.ts +50 -0
- package/src/lib/compiler/compile.js +814 -0
- package/src/lib/compiler/compile.js.map +1 -0
- package/src/lib/compiler/constants.d.ts +24 -0
- package/src/lib/compiler/constants.js +59 -0
- package/src/lib/compiler/constants.js.map +1 -0
- package/src/lib/compiler/debug.d.ts +22 -0
- package/src/lib/compiler/debug.js +20 -0
- package/src/lib/compiler/debug.js.map +1 -0
- package/src/lib/compiler/defer.d.ts +57 -0
- package/src/lib/compiler/defer.js +154 -0
- package/src/lib/compiler/defer.js.map +1 -0
- package/src/lib/compiler/dts-reader.d.ts +45 -0
- package/src/lib/compiler/dts-reader.js +395 -0
- package/src/lib/compiler/dts-reader.js.map +1 -0
- package/src/lib/compiler/hmr.d.ts +16 -0
- package/src/lib/compiler/hmr.js +69 -0
- package/src/lib/compiler/hmr.js.map +1 -0
- package/src/lib/compiler/index.d.ts +8 -0
- package/src/lib/compiler/index.js +8 -0
- package/src/lib/compiler/jit-metadata.d.ts +14 -0
- package/src/lib/compiler/jit-metadata.js +168 -0
- package/src/lib/compiler/jit-metadata.js.map +1 -0
- package/src/lib/compiler/jit-transform.d.ts +24 -0
- package/src/lib/compiler/jit-transform.js +204 -0
- package/src/lib/compiler/jit-transform.js.map +1 -0
- package/src/lib/compiler/js-emitter.d.ts +10 -0
- package/src/lib/compiler/js-emitter.js +446 -0
- package/src/lib/compiler/js-emitter.js.map +1 -0
- package/src/lib/compiler/metadata.d.ts +36 -0
- package/src/lib/compiler/metadata.js +710 -0
- package/src/lib/compiler/metadata.js.map +1 -0
- package/src/lib/compiler/registry.d.ts +56 -0
- package/src/lib/compiler/registry.js +176 -0
- package/src/lib/compiler/registry.js.map +1 -0
- package/src/lib/compiler/resource-inliner.d.ts +43 -0
- package/src/lib/compiler/resource-inliner.js +230 -0
- package/src/lib/compiler/resource-inliner.js.map +1 -0
- package/src/lib/compiler/style-ast.d.ts +9 -0
- package/src/lib/compiler/style-ast.js +54 -0
- package/src/lib/compiler/style-ast.js.map +1 -0
- package/src/lib/compiler/styles.d.ts +13 -0
- package/src/lib/compiler/test-helpers.d.ts +7 -0
- package/src/lib/compiler/type-elision.d.ts +28 -0
- package/src/lib/compiler/type-elision.js +211 -0
- package/src/lib/compiler/type-elision.js.map +1 -0
- package/src/lib/compiler/utils.d.ts +40 -0
- package/src/lib/compiler/utils.js +76 -0
- package/src/lib/compiler/utils.js.map +1 -0
- package/src/lib/compiler-plugin.d.ts +13 -12
- package/src/lib/compiler-plugin.js +18 -18
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/component-resolvers.d.ts +20 -4
- package/src/lib/component-resolvers.js +34 -20
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/encapsulation-plugin.d.ts +23 -0
- package/src/lib/encapsulation-plugin.js +68 -0
- package/src/lib/encapsulation-plugin.js.map +1 -0
- package/src/lib/fast-compile-plugin.d.ts +23 -0
- package/src/lib/fast-compile-plugin.js +433 -0
- package/src/lib/fast-compile-plugin.js.map +1 -0
- package/src/lib/host.d.ts +10 -8
- package/src/lib/host.js +59 -17
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.d.ts +5 -5
- package/src/lib/live-reload-plugin.js +10 -0
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/models.d.ts +9 -9
- package/src/lib/nx-folder-plugin.d.ts +5 -5
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.d.ts +4 -4
- package/src/lib/plugins/file-replacements.plugin.js +6 -1
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +1 -1
- package/src/lib/router-plugin.js +14 -2
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-preprocessor.d.ts +35 -0
- package/src/lib/style-preprocessor.js +35 -0
- package/src/lib/style-preprocessor.js.map +1 -0
- package/src/lib/stylesheet-registry.d.ts +74 -0
- package/src/lib/stylesheet-registry.js +174 -0
- package/src/lib/stylesheet-registry.js.map +1 -0
- package/src/lib/tools/package.json +1 -3
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +7 -5
- package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +16 -19
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/utils/compilation-shared.d.ts +62 -0
- package/src/lib/utils/compilation-shared.js +138 -0
- package/src/lib/utils/compilation-shared.js.map +1 -0
- package/src/lib/utils/compiler-plugin-options.d.ts +11 -11
- package/src/lib/utils/css-extension-resolver.d.ts +32 -0
- package/src/lib/utils/css-extension-resolver.js +73 -0
- package/src/lib/utils/css-extension-resolver.js.map +1 -0
- package/src/lib/utils/css-preprocessor-workers.d.ts +6 -0
- package/src/lib/utils/css-preprocessor-workers.js +29 -0
- package/src/lib/utils/css-preprocessor-workers.js.map +1 -0
- package/src/lib/utils/debug-harness.d.ts +23 -0
- package/src/lib/utils/debug-harness.js +88 -0
- package/src/lib/utils/debug-harness.js.map +1 -0
- package/src/lib/utils/debug-log-file.d.ts +5 -0
- package/src/lib/utils/debug-log-file.js +56 -0
- package/src/lib/utils/debug-log-file.js.map +1 -0
- package/src/lib/utils/debug.d.ts +26 -0
- package/src/lib/utils/debug.js +35 -0
- package/src/lib/utils/debug.js.map +1 -0
- package/src/lib/utils/devkit.d.ts +14 -6
- package/src/lib/utils/devkit.js +40 -2
- package/src/lib/utils/devkit.js.map +1 -1
- package/src/lib/utils/hmr-candidates.d.ts +28 -28
- package/src/lib/utils/jit-inline-styles.d.ts +3 -0
- package/src/lib/utils/jit-inline-styles.js +16 -0
- package/src/lib/utils/jit-inline-styles.js.map +1 -0
- package/src/lib/utils/plugin-config.d.ts +41 -0
- package/src/lib/utils/plugin-config.js +85 -0
- package/src/lib/utils/plugin-config.js.map +1 -0
- package/src/lib/utils/rolldown.d.ts +1 -1
- package/src/lib/utils/rolldown.js.map +1 -1
- package/src/lib/utils/safe-module-paths.d.ts +16 -0
- package/src/lib/utils/safe-module-paths.js +29 -0
- package/src/lib/utils/safe-module-paths.js.map +1 -0
- package/src/lib/utils/source-file-cache.d.ts +8 -15
- package/src/lib/utils/source-file-cache.js.map +1 -1
- package/src/lib/utils/transform-cache.d.ts +43 -0
- package/src/lib/utils/transform-cache.js +97 -0
- package/src/lib/utils/transform-cache.js.map +1 -0
- package/src/lib/utils/tsconfig-resolver.d.ts +34 -0
- package/src/lib/utils/tsconfig-resolver.js +205 -0
- package/src/lib/utils/tsconfig-resolver.js.map +1 -0
- package/src/lib/utils/virtual-ids.d.ts +4 -0
- package/src/lib/utils/virtual-ids.js +23 -0
- package/src/lib/utils/virtual-ids.js.map +1 -0
- package/src/lib/utils/virtual-resources.d.ts +19 -0
- package/src/lib/utils/virtual-resources.js +38 -0
- package/src/lib/utils/virtual-resources.js.map +1 -0
- package/src/lib/virtual-modules-plugin.d.ts +5 -0
- package/src/lib/virtual-modules-plugin.js +23 -0
- package/src/lib/virtual-modules-plugin.js.map +1 -0
- package/src/test-setup.d.ts +2 -0
- package/setup-vitest.d.ts +0 -4
- package/setup-vitest.js +0 -176
- package/setup-vitest.js.map +0 -1
- package/src/lib/tools/src/index.d.ts +0 -0
|
@@ -1,49 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { JavaScriptTransformer } from "./utils/devkit.js";
|
|
2
|
+
import { isProdMode } from "./utils/plugin-config.js";
|
|
3
3
|
//#region packages/vite-plugin-angular/src/lib/angular-build-optimizer-plugin.ts
|
|
4
4
|
function buildOptimizerPlugin({ jit }) {
|
|
5
|
-
const
|
|
6
|
-
sourcemap: false,
|
|
7
|
-
thirdPartySourcemaps: false,
|
|
8
|
-
advancedOptimizations: true,
|
|
9
|
-
jit: true
|
|
10
|
-
}, 1);
|
|
5
|
+
const transformers = /* @__PURE__ */ new Map();
|
|
11
6
|
let isProd = false;
|
|
7
|
+
let isWatch = false;
|
|
8
|
+
let preserveVendorMaps = false;
|
|
9
|
+
function getTransformer(envName = "default") {
|
|
10
|
+
let transformer = transformers.get(envName);
|
|
11
|
+
if (!transformer) {
|
|
12
|
+
transformer = new JavaScriptTransformer({
|
|
13
|
+
sourcemap: preserveVendorMaps,
|
|
14
|
+
thirdPartySourcemaps: preserveVendorMaps,
|
|
15
|
+
advancedOptimizations: isProd,
|
|
16
|
+
jit: true
|
|
17
|
+
}, 1);
|
|
18
|
+
transformers.set(envName, transformer);
|
|
19
|
+
}
|
|
20
|
+
return transformer;
|
|
21
|
+
}
|
|
12
22
|
return {
|
|
13
23
|
name: "@analogjs/vite-plugin-angular-optimizer",
|
|
14
|
-
apply
|
|
24
|
+
apply(_config, env) {
|
|
25
|
+
return env.command === "build" || process.env.NODE_ENV === "production";
|
|
26
|
+
},
|
|
15
27
|
config(userConfig) {
|
|
16
|
-
isProd = userConfig.mode
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} : void 0 }
|
|
31
|
-
};
|
|
28
|
+
isProd = isProdMode(userConfig.mode);
|
|
29
|
+
return { define: isProd ? {
|
|
30
|
+
ngJitMode: "false",
|
|
31
|
+
ngI18nClosureMode: "false",
|
|
32
|
+
ngDevMode: "false",
|
|
33
|
+
ngServerMode: `${!!userConfig.build?.ssr}`
|
|
34
|
+
} : {} };
|
|
35
|
+
},
|
|
36
|
+
configEnvironment(_name, config) {
|
|
37
|
+
if (isProd && config.consumer === "server") return { define: { ngServerMode: "true" } };
|
|
38
|
+
},
|
|
39
|
+
configResolved(config) {
|
|
40
|
+
preserveVendorMaps = !!config.build.sourcemap;
|
|
41
|
+
isWatch = config.command === "serve" || !!config.build?.watch;
|
|
32
42
|
},
|
|
33
43
|
transform: {
|
|
34
|
-
filter: { id: /\.[cm]?js
|
|
44
|
+
filter: { id: /\.[cm]?js(?:\?|$)/ },
|
|
35
45
|
async handler(code, id) {
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
const cleanId = id.split("?")[0];
|
|
47
|
+
if (!/fesm20/.test(cleanId)) return {
|
|
48
|
+
code: isProd && !preserveVendorMaps ? code.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, "") : code,
|
|
49
|
+
map: preserveVendorMaps ? null : { mappings: "" }
|
|
50
|
+
};
|
|
51
|
+
const sideEffects = jit && cleanId.includes("@angular/compiler") ? true : false;
|
|
52
|
+
const result = await getTransformer(this.environment?.name ?? "default").transformData(cleanId, code, false, sideEffects);
|
|
53
|
+
const transformed = Buffer.from(result).toString();
|
|
54
|
+
return preserveVendorMaps ? extractInlineSourceMap(transformed, cleanId) : {
|
|
55
|
+
code: transformed,
|
|
38
56
|
map: { mappings: "" }
|
|
39
57
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
async closeBundle() {
|
|
61
|
+
if (isWatch) return;
|
|
62
|
+
const envName = this.environment?.name ?? "default";
|
|
63
|
+
const transformer = transformers.get(envName);
|
|
64
|
+
if (transformer) {
|
|
65
|
+
transformers.delete(envName);
|
|
66
|
+
await transformer.close();
|
|
43
67
|
}
|
|
44
68
|
}
|
|
45
69
|
};
|
|
46
70
|
}
|
|
71
|
+
function extractInlineSourceMap(code, id) {
|
|
72
|
+
const sourceMapMatch = code.match(/\n?\/\/# sourceMappingURL=data:application\/json(?:;charset=[^;,]+)?;base64,([A-Za-z0-9+/=]+)\s*$/);
|
|
73
|
+
if (!sourceMapMatch || sourceMapMatch.index === void 0) return {
|
|
74
|
+
code,
|
|
75
|
+
map: null
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
code: code.slice(0, sourceMapMatch.index),
|
|
79
|
+
map: Buffer.from(sourceMapMatch[1], "base64").toString()
|
|
80
|
+
};
|
|
81
|
+
}
|
|
47
82
|
//#endregion
|
|
48
83
|
export { buildOptimizerPlugin };
|
|
49
84
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-build-optimizer-plugin.js","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"angular-build-optimizer-plugin.js","names":[],"sources":["../../../src/lib/angular-build-optimizer-plugin.ts"],"sourcesContent":["import type { Plugin, UserConfig } from 'vite';\nimport { JavaScriptTransformer } from './utils/devkit.js';\nimport { isProdMode } from './utils/plugin-config.js';\n\nexport function buildOptimizerPlugin({\n jit,\n}: {\n supportedBrowsers: string[];\n jit: boolean;\n}): Plugin {\n const transformers = new Map<\n string,\n InstanceType<typeof JavaScriptTransformer>\n >();\n let isProd = false;\n let isWatch = false;\n let preserveVendorMaps = false;\n\n function getTransformer(envName = 'default') {\n let transformer = transformers.get(envName);\n if (!transformer) {\n transformer = new JavaScriptTransformer(\n {\n sourcemap: preserveVendorMaps,\n thirdPartySourcemaps: preserveVendorMaps,\n advancedOptimizations: isProd,\n jit: true,\n },\n 1,\n );\n transformers.set(envName, transformer);\n }\n return transformer;\n }\n\n return {\n name: '@analogjs/vite-plugin-angular-optimizer',\n // Normally build-only. Astro's Cloudflare integration (`@astrojs/cloudflare`)\n // transforms SSR modules through a serve-style `workerd` runner *during*\n // `astro build`; an `apply: 'build'` plugin is excluded from that pipeline,\n // so the Angular linker never runs on the worker's partially-compiled\n // packages and they fall back to the JIT compiler. Also apply under a\n // production `NODE_ENV` (which `astro build` sets) so the linker runs in\n // that runner too. Regular Analog dev servers run with a development\n // `NODE_ENV`, so their behavior is unchanged.\n apply(_config, env) {\n return (\n env.command === 'build' || process.env['NODE_ENV'] === 'production'\n );\n },\n config(userConfig) {\n isProd = isProdMode(userConfig.mode);\n // Advanced optimizations paired with dev-mode defines would strip\n // dev-only code the debug API needs, so both key off `isProd`.\n return {\n define: isProd\n ? {\n ngJitMode: 'false',\n ngI18nClosureMode: 'false',\n ngDevMode: 'false',\n ngServerMode: `${!!userConfig.build?.ssr}`,\n }\n : {},\n } as UserConfig;\n },\n // The top-level define keys `ngServerMode` off the legacy `build.ssr`\n // flag. Environment API builds run the server through an environment\n // with `consumer: 'server'` while `build.ssr` stays unset, so give that\n // environment its own value; otherwise the guard compiles to `false`\n // and browser-only hydration features run during SSR.\n configEnvironment(_name, config) {\n if (isProd && config.consumer === 'server') {\n return { define: { ngServerMode: 'true' } };\n }\n return undefined;\n },\n configResolved(config) {\n preserveVendorMaps = !!config.build.sourcemap;\n isWatch = config.command === 'serve' || !!config.build?.watch;\n },\n transform: {\n filter: {\n // Allow an optional `?query` after the extension. Some environments\n // (e.g. Cloudflare's `workerd`, used by Astro's Cloudflare integration)\n // reference optimized deps with a `?v=<hash>` suffix, e.g.\n // `.../fesm2022/_platform_location-chunk.mjs?v=a786a9ff`. A `$`-anchored\n // extension match skips those, so the Angular linker never runs and the\n // partially-compiled package falls back to the JIT compiler at runtime.\n id: /\\.[cm]?js(?:\\?|$)/,\n },\n async handler(code, id) {\n // Strip the `?query` so the fesm check and the transformer see a real\n // filename rather than `foo.mjs?v=<hash>`.\n const cleanId = id.split('?')[0];\n const angularPackage = /fesm20/.test(cleanId);\n\n if (!angularPackage) {\n // `{ mappings: '' }` declares zero segments, dropping the module's own\n // map from the chain; `null` keeps it. Removing `sourceMappingURL` is\n // what makes that map unreachable, so it only runs when discarding.\n return {\n code:\n isProd && !preserveVendorMaps\n ? code.replace(/^\\/\\/# sourceMappingURL=[^\\r\\n]*/gm, '')\n : code,\n map: preserveVendorMaps ? null : { mappings: '' },\n };\n }\n\n const sideEffects =\n jit && cleanId.includes('@angular/compiler') ? true : false;\n const envName = this.environment?.name ?? 'default';\n const transformer = getTransformer(envName);\n const result: Uint8Array = await transformer.transformData(\n cleanId,\n code,\n false,\n sideEffects,\n );\n\n const transformed = Buffer.from(result).toString();\n return preserveVendorMaps\n ? extractInlineSourceMap(transformed, cleanId)\n : { code: transformed, map: { mappings: '' } };\n },\n },\n async closeBundle() {\n if (isWatch) {\n return;\n }\n const envName = this.environment?.name ?? 'default';\n const transformer = transformers.get(envName);\n if (transformer) {\n transformers.delete(envName);\n await transformer.close();\n }\n },\n };\n}\n\nexport function extractInlineSourceMap(\n code: string,\n id: string,\n): { code: string; map: string | null } {\n const sourceMapMatch = code.match(\n /\\n?\\/\\/# sourceMappingURL=data:application\\/json(?:;charset=[^;,]+)?;base64,([A-Za-z0-9+/=]+)\\s*$/,\n );\n if (!sourceMapMatch || sourceMapMatch.index === undefined) {\n return {\n code,\n map: null,\n };\n }\n return {\n code: code.slice(0, sourceMapMatch.index),\n map: Buffer.from(sourceMapMatch[1]!, 'base64').toString(),\n };\n}\n"],"mappings":";;;AAIA,SAAgB,qBAAqB,EACnC,OAIS;CACT,MAAM,+BAAe,IAAI,KAGtB;CACH,IAAI,SAAS;CACb,IAAI,UAAU;CACd,IAAI,qBAAqB;CAEzB,SAAS,eAAe,UAAU,WAAW;EAC3C,IAAI,cAAc,aAAa,IAAI,QAAQ;AAC3C,MAAI,CAAC,aAAa;AAChB,iBAAc,IAAI,sBAChB;IACE,WAAW;IACX,sBAAsB;IACtB,uBAAuB;IACvB,KAAK;IACN,EACD,EACD;AACD,gBAAa,IAAI,SAAS,YAAY;;AAExC,SAAO;;AAGT,QAAO;EACL,MAAM;EASN,MAAM,SAAS,KAAK;AAClB,UACE,IAAI,YAAY,WAAA,QAAA,IAAA,aAAuC;;EAG3D,OAAO,YAAY;AACjB,YAAS,WAAW,WAAW,KAAK;AAGpC,UAAO,EACL,QAAQ,SACJ;IACE,WAAW;IACX,mBAAmB;IACnB,WAAW;IACX,cAAc,GAAG,CAAC,CAAC,WAAW,OAAO;IACtC,GACD,EAAE,EACP;;EAOH,kBAAkB,OAAO,QAAQ;AAC/B,OAAI,UAAU,OAAO,aAAa,SAChC,QAAO,EAAE,QAAQ,EAAE,cAAc,QAAQ,EAAE;;EAI/C,eAAe,QAAQ;AACrB,wBAAqB,CAAC,CAAC,OAAO,MAAM;AACpC,aAAU,OAAO,YAAY,WAAW,CAAC,CAAC,OAAO,OAAO;;EAE1D,WAAW;GACT,QAAQ,EAON,IAAI,qBACL;GACD,MAAM,QAAQ,MAAM,IAAI;IAGtB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC;AAG9B,QAAI,CAFmB,SAAS,KAAK,QAAQ,CAM3C,QAAO;KACL,MACE,UAAU,CAAC,qBACP,KAAK,QAAQ,sCAAsC,GAAG,GACtD;KACN,KAAK,qBAAqB,OAAO,EAAE,UAAU,IAAI;KAClD;IAGH,MAAM,cACJ,OAAO,QAAQ,SAAS,oBAAoB,GAAG,OAAO;IAGxD,MAAM,SAAqB,MADP,eADJ,KAAK,aAAa,QAAQ,UACC,CACE,cAC3C,SACA,MACA,OACA,YACD;IAED,MAAM,cAAc,OAAO,KAAK,OAAO,CAAC,UAAU;AAClD,WAAO,qBACH,uBAAuB,aAAa,QAAQ,GAC5C;KAAE,MAAM;KAAa,KAAK,EAAE,UAAU,IAAI;KAAE;;GAEnD;EACD,MAAM,cAAc;AAClB,OAAI,QACF;GAEF,MAAM,UAAU,KAAK,aAAa,QAAQ;GAC1C,MAAM,cAAc,aAAa,IAAI,QAAQ;AAC7C,OAAI,aAAa;AACf,iBAAa,OAAO,QAAQ;AAC5B,UAAM,YAAY,OAAO;;;EAG9B;;AAGH,SAAgB,uBACd,MACA,IACsC;CACtC,MAAM,iBAAiB,KAAK,MAC1B,oGACD;AACD,KAAI,CAAC,kBAAkB,eAAe,UAAU,KAAA,EAC9C,QAAO;EACL;EACA,KAAK;EACN;AAEH,QAAO;EACL,MAAM,KAAK,MAAM,GAAG,eAAe,MAAM;EACzC,KAAK,OAAO,KAAK,eAAe,IAAK,SAAS,CAAC,UAAU;EAC1D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Plugin } from
|
|
2
|
-
export declare function jitPlugin({ inlineStylesExtension
|
|
3
|
-
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
export declare function jitPlugin({ inlineStylesExtension }: {
|
|
3
|
+
inlineStylesExtension: string;
|
|
4
4
|
}): Plugin;
|
|
@@ -1,29 +1,51 @@
|
|
|
1
|
+
import { debugStyles } from "./utils/debug.js";
|
|
2
|
+
import { preprocessStylesheet } from "./stylesheet-registry.js";
|
|
3
|
+
import { discoverAnalogIntegrations } from "./analog-plugin-interop.js";
|
|
4
|
+
import { getJitInlineStyles } from "./utils/jit-inline-styles.js";
|
|
5
|
+
import { releaseCssPreprocessorWorkers } from "./utils/css-preprocessor-workers.js";
|
|
1
6
|
import { preprocessCSS } from "vite";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
7
|
//#region packages/vite-plugin-angular/src/lib/angular-jit-plugin.ts
|
|
4
8
|
function jitPlugin({ inlineStylesExtension }) {
|
|
5
9
|
let config;
|
|
10
|
+
let stylePreprocessor;
|
|
6
11
|
return {
|
|
7
12
|
name: "@analogjs/vite-plugin-angular-jit",
|
|
8
13
|
configResolved(_config) {
|
|
9
14
|
config = _config;
|
|
10
15
|
},
|
|
16
|
+
async buildStart() {
|
|
17
|
+
stylePreprocessor = (await discoverAnalogIntegrations(config)).stylePreprocessor;
|
|
18
|
+
},
|
|
11
19
|
resolveId(id) {
|
|
12
20
|
if (id.startsWith("virtual:angular")) return `\0${id}`;
|
|
13
21
|
},
|
|
14
22
|
async load(id) {
|
|
15
23
|
if (id.includes("virtual:angular:jit:style:inline;")) {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
24
|
+
const styleIdHash = id.split("style:inline;")[1];
|
|
25
|
+
const encodedStyles = getJitInlineStyles(styleIdHash);
|
|
26
|
+
if (encodedStyles === void 0) return;
|
|
27
|
+
const decodedStyles = Buffer.from(decodeURIComponent(encodedStyles), "base64").toString();
|
|
28
|
+
const filename = `${styleIdHash}.${inlineStylesExtension}`;
|
|
29
|
+
const preprocessed = preprocessStylesheet(decodedStyles, filename, stylePreprocessor, {
|
|
30
|
+
filename,
|
|
31
|
+
inline: true
|
|
32
|
+
});
|
|
19
33
|
let styles = "";
|
|
20
34
|
try {
|
|
21
|
-
styles = (await preprocessCSS(
|
|
35
|
+
styles = (await preprocessCSS(preprocessed, `${filename}?direct`, config))?.code;
|
|
22
36
|
} catch (e) {
|
|
23
|
-
|
|
37
|
+
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
38
|
+
debugStyles("jit css compilation error", {
|
|
39
|
+
styleIdHash,
|
|
40
|
+
error: errorMessage
|
|
41
|
+
});
|
|
42
|
+
console.warn("[@analogjs/vite-plugin-angular]: Failed to preprocess inline JIT stylesheet %s. Returning an empty stylesheet instead. %s", styleIdHash, errorMessage);
|
|
24
43
|
}
|
|
25
44
|
return `export default \`${styles}\``;
|
|
26
45
|
}
|
|
46
|
+
},
|
|
47
|
+
closeBundle() {
|
|
48
|
+
if (!this.meta?.watchMode) releaseCssPreprocessorWorkers();
|
|
27
49
|
}
|
|
28
50
|
};
|
|
29
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-jit-plugin.js","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"angular-jit-plugin.js","names":[],"sources":["../../../src/lib/angular-jit-plugin.ts"],"sourcesContent":["import { Plugin, ResolvedConfig, preprocessCSS } from 'vite';\nimport {\n JIT_INLINE_STYLE_PREFIX,\n getJitInlineStyles,\n} from './utils/jit-inline-styles.js';\nimport { debugStyles } from './utils/debug.js';\nimport { discoverAnalogIntegrations } from './analog-plugin-interop.js';\nimport { preprocessStylesheet } from './stylesheet-registry.js';\nimport type { StylePreprocessor } from './style-preprocessor.js';\nimport { releaseCssPreprocessorWorkers } from './utils/css-preprocessor-workers.js';\n\nexport function jitPlugin({\n inlineStylesExtension,\n}: {\n inlineStylesExtension: string;\n}): Plugin {\n let config: ResolvedConfig;\n let stylePreprocessor: StylePreprocessor | undefined;\n\n return {\n name: '@analogjs/vite-plugin-angular-jit',\n configResolved(_config) {\n config = _config;\n },\n async buildStart() {\n stylePreprocessor = (await discoverAnalogIntegrations(config))\n .stylePreprocessor;\n },\n resolveId(id: string) {\n if (id.startsWith('virtual:angular')) {\n return `\\0${id}`;\n }\n\n return;\n },\n async load(id: string) {\n if (id.includes(JIT_INLINE_STYLE_PREFIX)) {\n const styleIdHash = id.split('style:inline;')[1];\n const encodedStyles = getJitInlineStyles(styleIdHash);\n\n if (encodedStyles === undefined) {\n return;\n }\n\n const decodedStyles = Buffer.from(\n decodeURIComponent(encodedStyles),\n 'base64',\n ).toString();\n const filename = `${styleIdHash}.${inlineStylesExtension}`;\n const preprocessed = preprocessStylesheet(\n decodedStyles,\n filename,\n stylePreprocessor,\n { filename, inline: true },\n );\n\n let styles: string | undefined = '';\n\n try {\n const compiled = await preprocessCSS(\n preprocessed,\n `${filename}?direct`,\n config,\n );\n styles = compiled?.code;\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : String(e);\n debugStyles('jit css compilation error', {\n styleIdHash,\n error: errorMessage,\n });\n console.warn(\n '[@analogjs/vite-plugin-angular]: Failed to preprocess inline JIT stylesheet %s. Returning an empty stylesheet instead. %s',\n styleIdHash,\n errorMessage,\n );\n }\n\n return `export default \\`${styles}\\``;\n }\n\n return;\n },\n closeBundle() {\n if (!this.meta?.watchMode) {\n releaseCssPreprocessorWorkers();\n }\n },\n };\n}\n"],"mappings":";;;;;;;AAWA,SAAgB,UAAU,EACxB,yBAGS;CACT,IAAI;CACJ,IAAI;AAEJ,QAAO;EACL,MAAM;EACN,eAAe,SAAS;AACtB,YAAS;;EAEX,MAAM,aAAa;AACjB,wBAAqB,MAAM,2BAA2B,OAAO,EAC1D;;EAEL,UAAU,IAAY;AACpB,OAAI,GAAG,WAAW,kBAAkB,CAClC,QAAO,KAAK;;EAKhB,MAAM,KAAK,IAAY;AACrB,OAAI,GAAG,SAAA,oCAAiC,EAAE;IACxC,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC;IAC9C,MAAM,gBAAgB,mBAAmB,YAAY;AAErD,QAAI,kBAAkB,KAAA,EACpB;IAGF,MAAM,gBAAgB,OAAO,KAC3B,mBAAmB,cAAc,EACjC,SACD,CAAC,UAAU;IACZ,MAAM,WAAW,GAAG,YAAY,GAAG;IACnC,MAAM,eAAe,qBACnB,eACA,UACA,mBACA;KAAE;KAAU,QAAQ;KAAM,CAC3B;IAED,IAAI,SAA6B;AAEjC,QAAI;AAMF,eALiB,MAAM,cACrB,cACA,GAAG,SAAS,UACZ,OACD,GACkB;aACZ,GAAG;KACV,MAAM,eAAe,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE;AAC/D,iBAAY,6BAA6B;MACvC;MACA,OAAO;MACR,CAAC;AACF,aAAQ,KACN,6HACA,aACA,aACD;;AAGH,WAAO,oBAAoB,OAAO;;;EAKtC,cAAc;AACZ,OAAI,CAAC,KAAK,MAAM,UACd,gCAA+B;;EAGpC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
* This plugin is a workaround for the ɵPendingTasks symbol being renamed
|
|
4
|
+
* to ɵPendingTasksInternal in Angular v19.0.4. The symbol is renamed to support previous versions of
|
|
5
|
+
* Angular with Analog that used the ɵPendingTasks symbol.
|
|
6
|
+
*
|
|
7
|
+
* Commmit: https://github.com/angular/angular/commit/24e317cb157bf1ef159ed8554f1b79cb3443edf4
|
|
8
|
+
*/
|
|
9
9
|
export declare function pendingTasksPlugin(): Plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-pending-tasks.plugin.js","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"angular-pending-tasks.plugin.js","names":[],"sources":["../../../src/lib/angular-pending-tasks.plugin.ts"],"sourcesContent":["import { Plugin } from 'vite';\n\nimport { angularFullVersion } from './utils/devkit.js';\n\n/**\n * This plugin is a workaround for the ɵPendingTasks symbol being renamed\n * to ɵPendingTasksInternal in Angular v19.0.4. The symbol is renamed to support previous versions of\n * Angular with Analog that used the ɵPendingTasks symbol.\n *\n * Commmit: https://github.com/angular/angular/commit/24e317cb157bf1ef159ed8554f1b79cb3443edf4\n */\nexport function pendingTasksPlugin(): Plugin {\n return {\n name: 'analogjs-pending-tasks-plugin',\n transform(code, id) {\n if (id.includes('analogjs-content.mjs')) {\n return {\n code: code.replace('ɵPendingTasksInternal', 'ɵPendingTasks'),\n };\n }\n return;\n },\n };\n}\n"],"mappings":";;;;;;;;AAWA,SAAgB,qBAA6B;AAC3C,QAAO;EACL,MAAM;EACN,UAAU,MAAM,IAAI;AAClB,OAAI,GAAG,SAAS,uBAAuB,CACrC,QAAO,EACL,MAAM,KAAK,QAAQ,yBAAyB,gBAAgB,EAC7D;;EAIN"}
|
|
@@ -1,76 +1,86 @@
|
|
|
1
|
-
import { NgtscProgram } from
|
|
2
|
-
import * as ts from
|
|
3
|
-
import { Plugin } from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Syntactic = 2,
|
|
9
|
-
Semantic = 4,
|
|
10
|
-
All = 7
|
|
11
|
-
}
|
|
1
|
+
import { NgtscProgram } from "@angular/compiler-cli";
|
|
2
|
+
import * as ts from "typescript";
|
|
3
|
+
import { ModuleNode, Plugin, ViteDevServer } from "vite";
|
|
4
|
+
import { type DebugOption } from "./utils/debug.js";
|
|
5
|
+
import { FileReplacement } from "./plugins/file-replacements.plugin.js";
|
|
6
|
+
import { AnalogStylesheetRegistry } from "./stylesheet-registry.js";
|
|
7
|
+
export { DiagnosticModes, injectViteIgnoreForHmrMetadata, isIgnoredHmrFile, toAngularCompilationFileReplacements, mapTemplateUpdatesToFiles, refreshStylesheetRegistryForFile, describeStylesheetContent, isTestWatchMode } from "./utils/compilation-shared.js";
|
|
12
8
|
export interface PluginOptions {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
tsconfig?: string | (() => string);
|
|
10
|
+
workspaceRoot?: string;
|
|
11
|
+
inlineStylesExtension?: string;
|
|
12
|
+
jit?: boolean;
|
|
13
|
+
supportedBrowsers?: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Additional files to include in compilation
|
|
16
|
+
*/
|
|
17
|
+
include?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Enables Analog's Angular live-reload/HMR pipeline during development/watch mode.
|
|
20
|
+
*
|
|
21
|
+
* This is separate from Vite's `server.hmr` option, which configures the
|
|
22
|
+
* HMR client transport.
|
|
23
|
+
*
|
|
24
|
+
* Defaults to `true` for watch mode. Set to `false` to disable Angular
|
|
25
|
+
* reload updates while keeping other stylesheet externalization behavior
|
|
26
|
+
* available when needed.
|
|
27
|
+
*/
|
|
28
|
+
liveReload?: boolean;
|
|
29
|
+
disableTypeChecking?: boolean;
|
|
30
|
+
fileReplacements?: FileReplacement[];
|
|
31
|
+
/**
|
|
32
|
+
* Opt into the fast compile path. Skips Angular's template type-checking
|
|
33
|
+
* and routes compilation through an internal single-pass transform.
|
|
34
|
+
* Defaults to `false`.
|
|
35
|
+
*/
|
|
36
|
+
fastCompile?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Compilation output mode used when `fastCompile` is enabled.
|
|
39
|
+
* - `'full'` (default): Emit final Ivy definitions for application builds.
|
|
40
|
+
* - `'partial'`: Emit partial declarations for library publishing.
|
|
41
|
+
*/
|
|
42
|
+
fastCompileMode?: "full" | "partial";
|
|
43
|
+
/**
|
|
44
|
+
* Enable debug logging for specific scopes.
|
|
45
|
+
*
|
|
46
|
+
* - `true` → enables all `analog:angular:*` scopes
|
|
47
|
+
* - `string[]` → enables listed namespaces (e.g. `['analog:angular:hmr']`)
|
|
48
|
+
* - `{ scopes?, mode? }` → object form with optional `mode: 'build' | 'dev'`
|
|
49
|
+
* to restrict output to a specific Vite command (omit for both)
|
|
50
|
+
*
|
|
51
|
+
* Also responds to the `DEBUG` env var (Node.js) or `localStorage.debug`
|
|
52
|
+
* (browser), using the `obug` convention.
|
|
53
|
+
*/
|
|
54
|
+
debug?: DebugOption;
|
|
36
55
|
}
|
|
56
|
+
export declare function evictDeletedFileMetadata(file: string, { classNamesMap, fileTransformMap }: {
|
|
57
|
+
classNamesMap: Map<string, string>;
|
|
58
|
+
fileTransformMap: Map<string, string>;
|
|
59
|
+
}): void;
|
|
37
60
|
export declare function angular(options?: PluginOptions): Plugin[];
|
|
38
61
|
export declare function createFsWatcherCacheInvalidator(invalidateFsCaches: () => void, invalidateTsconfigCaches: () => void, performCompilation: () => Promise<void>): () => Promise<void>;
|
|
39
62
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
export declare function
|
|
63
|
+
* Returns every live Vite module that can legitimately represent a changed
|
|
64
|
+
* Angular resource file.
|
|
65
|
+
*
|
|
66
|
+
* For normal files, `getModulesByFile()` is enough. For Angular component
|
|
67
|
+
* stylesheets, it is not: the browser often holds virtual hashed requests
|
|
68
|
+
* (`/abc123.css?direct&ngcomp=...` and `/abc123.css?ngcomp=...`) that are no
|
|
69
|
+
* longer discoverable from the original source path alone. We therefore merge:
|
|
70
|
+
* - watcher event modules
|
|
71
|
+
* - module-graph modules by source file
|
|
72
|
+
* - registry-tracked live request ids resolved back through the module graph
|
|
73
|
+
*/
|
|
74
|
+
export declare function getModulesForChangedFile(server: ViteDevServer, file: string, eventModules?: readonly ModuleNode[], stylesheetRegistry?: AnalogStylesheetRegistry): Promise<ModuleNode[]>;
|
|
75
|
+
export declare function isModuleForChangedResource(mod: ModuleNode, changedFile: string, stylesheetRegistry?: AnalogStylesheetRegistry): boolean;
|
|
76
|
+
export declare function findComponentStylesheetWrapperModules(server: ViteDevServer, changedFile: string, directModule: ModuleNode, fileModules: ModuleNode[], stylesheetRegistry?: AnalogStylesheetRegistry): Promise<ModuleNode[]>;
|
|
77
|
+
export declare function findTemplateOwnerModules(server: ViteDevServer, resourceFile: string): ModuleNode[];
|
|
52
78
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* used elsewhere in the plugin (`outputFiles`, `classNames`, etc.).
|
|
61
|
-
*/
|
|
62
|
-
export declare function mapTemplateUpdatesToFiles(templateUpdates: ReadonlyMap<string, string> | undefined): Map<string, {
|
|
63
|
-
className: string;
|
|
64
|
-
code: string;
|
|
65
|
-
}>;
|
|
66
|
-
export declare function getFileMetadata(program: ts.BuilderProgram, angularCompiler?: NgtscProgram['compiler'], liveReload?: boolean, disableTypeChecking?: boolean): (file: string) => {
|
|
67
|
-
errors?: string[];
|
|
68
|
-
warnings?: (string | ts.DiagnosticMessageChain)[];
|
|
69
|
-
hmrUpdateCode?: string | null;
|
|
70
|
-
hmrEligible?: boolean;
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
export declare function getFileMetadata(program: ts.BuilderProgram, angularCompiler?: NgtscProgram["compiler"], hmrEnabled?: boolean, disableTypeChecking?: boolean): (file: string) => {
|
|
82
|
+
errors?: string[];
|
|
83
|
+
warnings?: (string | ts.DiagnosticMessageChain)[];
|
|
84
|
+
hmrUpdateCode?: string | null;
|
|
85
|
+
hmrEligible?: boolean;
|
|
71
86
|
};
|
|
72
|
-
/**
|
|
73
|
-
* Checks for vitest run from the command line
|
|
74
|
-
* @returns boolean
|
|
75
|
-
*/
|
|
76
|
-
export declare function isTestWatchMode(args?: string[]): boolean;
|