@analogjs/vite-plugin-angular 3.0.0-alpha.99 → 3.0.0-beta.10
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 +40 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +13 -2
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
- package/package.json +1 -14
- package/src/lib/analog-plugin-interop.js +1 -1
- package/src/lib/analog-plugin-interop.js.map +1 -1
- package/src/lib/angular-build-optimizer-plugin.js +1 -1
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.js +24 -8
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.js +1 -1
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compilation-api/compilation-api-plugin.js +6 -5
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
- package/src/lib/compilation-api/index.js +2 -1
- package/src/lib/compiler/angular-version.js +1 -1
- package/src/lib/compiler/angular-version.js.map +1 -1
- package/src/lib/compiler/class-field-lowering.js.map +1 -1
- package/src/lib/compiler/compile.js +27 -21
- package/src/lib/compiler/compile.js.map +1 -1
- package/src/lib/compiler/constants.js +4 -4
- package/src/lib/compiler/constants.js.map +1 -1
- package/src/lib/compiler/debug.js.map +1 -1
- package/src/lib/compiler/defer.js +1 -1
- package/src/lib/compiler/defer.js.map +1 -1
- package/src/lib/compiler/dts-reader.d.ts +5 -0
- package/src/lib/compiler/dts-reader.js +10 -4
- package/src/lib/compiler/dts-reader.js.map +1 -1
- package/src/lib/compiler/hmr.d.ts +4 -0
- package/src/lib/compiler/hmr.js +7 -2
- package/src/lib/compiler/hmr.js.map +1 -1
- package/src/lib/compiler/index.d.ts +2 -2
- package/src/lib/compiler/index.js +9 -8
- package/src/lib/compiler/jit-metadata.d.ts +3 -1
- package/src/lib/compiler/jit-metadata.js +10 -8
- package/src/lib/compiler/jit-metadata.js.map +1 -1
- package/src/lib/compiler/jit-transform.js +3 -5
- package/src/lib/compiler/jit-transform.js.map +1 -1
- package/src/lib/compiler/js-emitter.js +2 -4
- package/src/lib/compiler/js-emitter.js.map +1 -1
- package/src/lib/compiler/metadata.js +10 -12
- package/src/lib/compiler/metadata.js.map +1 -1
- package/src/lib/compiler/registry.d.ts +6 -0
- package/src/lib/compiler/registry.js +21 -1
- package/src/lib/compiler/registry.js.map +1 -1
- package/src/lib/compiler/resource-inliner.js.map +1 -1
- package/src/lib/compiler/style-ast.js.map +1 -1
- package/src/lib/compiler/type-elision.js +2 -2
- package/src/lib/compiler/type-elision.js.map +1 -1
- package/src/lib/compiler/utils.js +7 -5
- package/src/lib/compiler/utils.js.map +1 -1
- package/src/lib/compiler-plugin.js +7 -0
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/component-resolvers.js +1 -1
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/encapsulation-plugin.js +3 -2
- package/src/lib/encapsulation-plugin.js.map +1 -1
- package/src/lib/fast-compile-plugin.js +100 -17
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/host.js.map +1 -1
- package/src/lib/hot-update-batch.js +1 -1
- package/src/lib/hot-update-batch.js.map +1 -1
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-preprocessor.js.map +1 -1
- package/src/lib/stylesheet-registry.js.map +1 -1
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +4 -2
- 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 +2 -1
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/utils/compilation-shared.js.map +1 -1
- package/src/lib/utils/css-extension-resolver.js.map +1 -1
- package/src/lib/utils/css-preprocessor-workers.js.map +1 -1
- package/src/lib/utils/debug-harness.js.map +1 -1
- package/src/lib/utils/debug-log-file.js +2 -1
- package/src/lib/utils/debug-log-file.js.map +1 -1
- package/src/lib/utils/debug.js.map +1 -1
- package/src/lib/utils/devkit.js +1 -1
- package/src/lib/utils/devkit.js.map +1 -1
- package/src/lib/utils/jit-inline-styles.js.map +1 -1
- package/src/lib/utils/plugin-config.js.map +1 -1
- package/src/lib/utils/rolldown.js.map +1 -1
- package/src/lib/utils/safe-module-paths.js.map +1 -1
- package/src/lib/utils/transform-cache.js.map +1 -1
- package/src/lib/utils/tsconfig-resolver.js +2 -1
- package/src/lib/utils/tsconfig-resolver.js.map +1 -1
- package/src/lib/utils/virtual-ids.js.map +1 -1
- package/src/lib/utils/virtual-resources.js.map +1 -1
- package/src/lib/virtual-modules-plugin.js +4 -1
- package/src/lib/virtual-modules-plugin.js.map +1 -1
- package/migrations/migrations.json +0 -9
- package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +0 -2
- package/migrations/update-3-0-0/migrate-setup-vitest.js +0 -36
- package/migrations/update-3-0-0/migrate-setup-vitest.js.map +0 -1
package/README.md
CHANGED
|
@@ -50,6 +50,46 @@ export default defineConfig({
|
|
|
50
50
|
|
|
51
51
|
> The `angular` plugin should be listed **first** in the plugins array.
|
|
52
52
|
|
|
53
|
+
## Plugin Options
|
|
54
|
+
|
|
55
|
+
All options are optional.
|
|
56
|
+
|
|
57
|
+
| Option | Default | Description |
|
|
58
|
+
| ----------------------- | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
59
|
+
| `tsconfig` | `tsconfig.app.json` | Path to the tsconfig used for compilation, or a function returning it. Libraries default to `tsconfig.lib.json` and tests to `tsconfig.spec.json`. |
|
|
60
|
+
| `workspaceRoot` | `NX_WORKSPACE_ROOT`, then `process.cwd()` | Absolute path to the workspace root. Set it in monorepos where the app is not the working directory. |
|
|
61
|
+
| `inlineStylesExtension` | `'css'` | Stylesheet language for inline component `styles`, such as `'scss'`. See [CSS Pre-processors](https://analogjs.org/docs/packages/vite-plugin-angular/css-preprocessors). |
|
|
62
|
+
| `jit` | `true` in tests, `false` otherwise | Compile components in JIT mode instead of AOT. |
|
|
63
|
+
| `include` | `[]` | Additional globs, relative to the workspace root, to add to compilation, such as components from a library outside the tsconfig `include`. |
|
|
64
|
+
| `liveReload` | `true` | Enables Angular component HMR during development. This is separate from Vite's `server.hmr` transport option. |
|
|
65
|
+
| `disableTypeChecking` | `true` | Skips semantic and template diagnostics during compilation. Set to `false` to report type errors from the Vite build. |
|
|
66
|
+
| `fileReplacements` | `[]` | Replaces source files at build time, like `fileReplacements` in `angular.json`. Use `{ replace, with }`, or `{ replace, ssr }` for the SSR build. `with` and `ssr` paths resolve against `workspaceRoot`. |
|
|
67
|
+
| `fastCompile` | `false` | Opts into the [fast compile path](#fast-compile-mode). |
|
|
68
|
+
| `fastCompileMode` | `'full'` | Output mode for `fastCompile`: `'full'` for apps, `'partial'` for publishing libraries. |
|
|
69
|
+
| `debug` | `false` | Enables `analog:angular:*` debug logging. |
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { defineConfig } from 'vite';
|
|
73
|
+
import angular from '@analogjs/vite-plugin-angular';
|
|
74
|
+
|
|
75
|
+
export default defineConfig(({ mode }) => ({
|
|
76
|
+
plugins: [
|
|
77
|
+
angular({
|
|
78
|
+
inlineStylesExtension: 'scss',
|
|
79
|
+
fileReplacements:
|
|
80
|
+
mode === 'production'
|
|
81
|
+
? [
|
|
82
|
+
{
|
|
83
|
+
replace: 'src/environments/environment.ts',
|
|
84
|
+
with: 'src/environments/environment.prod.ts',
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
: [],
|
|
88
|
+
}),
|
|
89
|
+
],
|
|
90
|
+
}));
|
|
91
|
+
```
|
|
92
|
+
|
|
53
93
|
## Fast Compile Mode
|
|
54
94
|
|
|
55
95
|
`fastCompile` opts the plugin into a single-pass compilation path that emits Ivy instructions directly and skips Angular's template type-checking. It's intended for content-focused apps and faster dev iteration where build throughput matters more than inline type-safety feedback.
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import { NodePackageInstallTask } from "@angular-devkit/schematics/tasks";
|
|
1
|
+
import { NodePackageInstallTask } from "@angular-devkit/schematics/tasks/index.js";
|
|
2
2
|
//#region packages/vite-plugin-angular/migrations/migrate-setup-vitest/migrate-setup-vitest.ts
|
|
3
3
|
var OLD_IMPORT = "@analogjs/vite-plugin-angular/setup-vitest";
|
|
4
4
|
var NEW_IMPORT = "@analogjs/vitest-angular/setup-zone";
|
|
5
|
+
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
6
|
+
".cjs",
|
|
7
|
+
".cts",
|
|
8
|
+
".js",
|
|
9
|
+
".jsx",
|
|
10
|
+
".mjs",
|
|
11
|
+
".mts",
|
|
12
|
+
".ts",
|
|
13
|
+
".tsx"
|
|
14
|
+
]);
|
|
5
15
|
function addVitestAngularDependency(tree, context) {
|
|
6
16
|
const pkgPath = "/package.json";
|
|
7
17
|
const content = tree.read(pkgPath);
|
|
@@ -24,7 +34,8 @@ function migrateSetupVitest() {
|
|
|
24
34
|
return (tree, context) => {
|
|
25
35
|
const filesToUpdate = [];
|
|
26
36
|
tree.visit((filePath) => {
|
|
27
|
-
|
|
37
|
+
const extension = filePath.slice(filePath.lastIndexOf("."));
|
|
38
|
+
if (!SUPPORTED_EXTENSIONS.has(extension)) return;
|
|
28
39
|
if (filePath.includes("/node_modules/")) return;
|
|
29
40
|
const content = tree.read(filePath);
|
|
30
41
|
if (!content) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-setup-vitest.js","names":[],"sources":["../../../migrations/migrate-setup-vitest/migrate-setup-vitest.ts"],"sourcesContent":["import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';\n\nconst OLD_IMPORT = '@analogjs/vite-plugin-angular/setup-vitest';\nconst NEW_IMPORT = '@analogjs/vitest-angular/setup-zone';\n\nfunction addVitestAngularDependency(\n tree: Tree,\n context: SchematicContext,\n): void {\n const pkgPath = '/package.json';\n const content = tree.read(pkgPath);\n if (!content) {\n return;\n }\n\n const pkg = JSON.parse(content.toString('utf-8'));\n const devDeps = pkg['devDependencies'] || {};\n const deps = pkg['dependencies'] || {};\n\n if (\n !devDeps['@analogjs/vitest-angular'] &&\n !deps['@analogjs/vitest-angular']\n ) {\n const analogVersion =\n devDeps['@analogjs/vite-plugin-angular'] ||\n deps['@analogjs/vite-plugin-angular'] ||\n '*';\n\n pkg['devDependencies'] = {\n ...devDeps,\n '@analogjs/vitest-angular': analogVersion,\n };\n\n tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2) + '\\n');\n context.addTask(new NodePackageInstallTask());\n context.logger.info(\n `Added '@analogjs/vitest-angular': '${analogVersion}' to devDependencies.`,\n );\n }\n}\n\nexport default function migrateSetupVitest(): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const filesToUpdate: string[] = [];\n\n tree.visit((filePath) => {\n
|
|
1
|
+
{"version":3,"file":"migrate-setup-vitest.js","names":[],"sources":["../../../migrations/migrate-setup-vitest/migrate-setup-vitest.ts"],"sourcesContent":["import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport { NodePackageInstallTask } from '@angular-devkit/schematics/tasks/index.js';\n\nconst OLD_IMPORT = '@analogjs/vite-plugin-angular/setup-vitest';\nconst NEW_IMPORT = '@analogjs/vitest-angular/setup-zone';\nconst SUPPORTED_EXTENSIONS = new Set([\n '.cjs',\n '.cts',\n '.js',\n '.jsx',\n '.mjs',\n '.mts',\n '.ts',\n '.tsx',\n]);\n\nfunction addVitestAngularDependency(\n tree: Tree,\n context: SchematicContext,\n): void {\n const pkgPath = '/package.json';\n const content = tree.read(pkgPath);\n if (!content) {\n return;\n }\n\n const pkg = JSON.parse(content.toString('utf-8'));\n const devDeps = pkg['devDependencies'] || {};\n const deps = pkg['dependencies'] || {};\n\n if (\n !devDeps['@analogjs/vitest-angular'] &&\n !deps['@analogjs/vitest-angular']\n ) {\n const analogVersion =\n devDeps['@analogjs/vite-plugin-angular'] ||\n deps['@analogjs/vite-plugin-angular'] ||\n '*';\n\n pkg['devDependencies'] = {\n ...devDeps,\n '@analogjs/vitest-angular': analogVersion,\n };\n\n tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2) + '\\n');\n context.addTask(new NodePackageInstallTask());\n context.logger.info(\n `Added '@analogjs/vitest-angular': '${analogVersion}' to devDependencies.`,\n );\n }\n}\n\nexport default function migrateSetupVitest(): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const filesToUpdate: string[] = [];\n\n tree.visit((filePath) => {\n const extension = filePath.slice(filePath.lastIndexOf('.'));\n if (!SUPPORTED_EXTENSIONS.has(extension)) {\n return;\n }\n if (filePath.includes('/node_modules/')) {\n return;\n }\n\n const content = tree.read(filePath);\n if (!content) {\n return;\n }\n\n const text = content.toString('utf-8');\n if (text.includes(OLD_IMPORT)) {\n const updated = text.replace(\n new RegExp(OLD_IMPORT.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'g'),\n NEW_IMPORT,\n );\n tree.overwrite(filePath, updated);\n filesToUpdate.push(filePath);\n }\n });\n\n if (filesToUpdate.length > 0) {\n context.logger.info(\n `Migrated ${filesToUpdate.length} file(s) from '${OLD_IMPORT}' to '${NEW_IMPORT}':`,\n );\n for (const file of filesToUpdate) {\n context.logger.info(` - ${file}`);\n }\n }\n\n if (filesToUpdate.length > 0) {\n addVitestAngularDependency(tree, context);\n }\n\n return tree;\n };\n}\n"],"mappings":";;AAGA,IAAM,aAAa;AACnB,IAAM,aAAa;AACnB,IAAM,uCAAuB,IAAI,IAAI;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,2BACP,MACA,SACM;CACN,MAAM,UAAU;CAChB,MAAM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2BAA2B,MAAM,OAAO;EAG1C,OAAO;CACT;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@analogjs/vite-plugin-angular",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.10",
|
|
4
4
|
"description": "Vite Plugin for Angular",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -57,18 +57,6 @@
|
|
|
57
57
|
"tinyglobby": "^0.2.15"
|
|
58
58
|
},
|
|
59
59
|
"builders": "./src/lib/tools/builders.json",
|
|
60
|
-
"nx-migrations": {
|
|
61
|
-
"packageGroup": [
|
|
62
|
-
"@analogjs/platform",
|
|
63
|
-
"@analogjs/content",
|
|
64
|
-
"@analogjs/router",
|
|
65
|
-
"@analogjs/storybook-angular",
|
|
66
|
-
"@analogjs/vite-plugin-angular",
|
|
67
|
-
"@analogjs/vite-plugin-nitro",
|
|
68
|
-
"@analogjs/vitest-angular"
|
|
69
|
-
],
|
|
70
|
-
"migrations": "./migrations/migrations.json"
|
|
71
|
-
},
|
|
72
60
|
"ng-update": {
|
|
73
61
|
"packageGroup": [
|
|
74
62
|
"@analogjs/platform",
|
|
@@ -83,7 +71,6 @@
|
|
|
83
71
|
},
|
|
84
72
|
"exports": {
|
|
85
73
|
"./package.json": "./package.json",
|
|
86
|
-
"./migrations.json": "./migrations/migrations.json",
|
|
87
74
|
".": {
|
|
88
75
|
"types": "./src/index.d.ts",
|
|
89
76
|
"import": "./src/index.js",
|
|
@@ -92,6 +92,6 @@ function describeError(error) {
|
|
|
92
92
|
return error instanceof Error ? error.message : String(error);
|
|
93
93
|
}
|
|
94
94
|
//#endregion
|
|
95
|
-
export { discoverAnalogIntegrations };
|
|
95
|
+
export { discoverAnalogIntegrations, runAnalogSetupHooks };
|
|
96
96
|
|
|
97
97
|
//# sourceMappingURL=analog-plugin-interop.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analog-plugin-interop.js","names":[],"sources":["../../../src/lib/analog-plugin-interop.ts"],"sourcesContent":["import type { Plugin, ResolvedConfig } from 'vite';\nimport {\n composeStylePreprocessors,\n type StylePreprocessor,\n type StylesheetRegistryReader,\n} from './style-preprocessor.js';\nimport type { RegistryEntry } from './compiler/registry.js';\nimport { debugStylePipeline } from './utils/debug.js';\n\nexport type TransformFilter = (code: string, id: string) => boolean;\n\nexport type ComponentRegistryEntries = ReadonlyMap<string, RegistryEntry>;\n\nexport interface StylesheetRegistryContext {\n workspaceRoot: string;\n}\n\nexport type StylesheetRegistryConfigurator = (\n registry: StylesheetRegistryReader,\n context: StylesheetRegistryContext,\n) => void;\n\n/**\n * Narrow framework context handed to a Vite plugin's `analog.setup()` hook.\n * Only grows when a concrete integration needs another seam.\n */\nexport interface AnalogPluginContext {\n /**\n * Registers a pre-transform that runs on every Angular component stylesheet\n * before it enters Vite's `preprocessCSS` pipeline.\n */\n registerStylePreprocessor(preprocessor: StylePreprocessor): void;\n /**\n * Requests that component styles are externalized in dev and watch mode so\n * they run through Vite's CSS plugin pipeline (for example\n * `@tailwindcss/vite`) instead of being inlined through `preprocessCSS`,\n * which only runs PostCSS and CSS preprocessors. Production builds keep\n * inlining component styles.\n */\n externalizeComponentStyles(): void;\n /**\n * Receives the live stylesheet registry for externalized component styles\n * each time a compilation creates one, so the plugin can map component\n * stylesheet sources to their served ids, dependencies, and diagnostics.\n */\n configureStylesheetRegistry(configure: StylesheetRegistryConfigurator): void;\n /**\n * Restricts which modules Angular compiles. A module is transformed only\n * when every registered filter returns `true` for it.\n */\n registerTransformFilter(filter: TransformFilter): void;\n /**\n * Contributes directive, component, pipe, and NgModule metadata keyed by\n * class name for classes the fast compiler cannot reach through its own\n * tsconfig-driven scan (for example components compiled from another\n * source format). The map is read on every compile, so a plugin may keep\n * filling it after setup.\n */\n registerComponentRegistry(entries: ComponentRegistryEntries): void;\n /**\n * Adds TypeScript include globs to the Angular compilation. Globs resolve\n * against the same workspace root as `angular({ include })`, so a leading\n * `/` means workspace-relative.\n */\n addInclude(globs: string[]): void;\n}\n\nexport interface AnalogPluginHooks {\n setup?(context: AnalogPluginContext): void | Promise<void>;\n}\n\n/**\n * A normal Vite plugin that optionally exposes an `analog` setup hook.\n * Discovery is structural (`plugin.analog?.setup`), so this type is a DX aid\n * rather than a requirement.\n */\nexport type AnalogIntegrationPlugin = Plugin & { analog?: AnalogPluginHooks };\n\nexport interface AnalogIntegrations {\n stylePreprocessor?: StylePreprocessor;\n configureStylesheetRegistry?: StylesheetRegistryConfigurator;\n transformFilter?: TransformFilter;\n componentRegistries: ComponentRegistryEntries[];\n include: string[];\n externalizeStyles: boolean;\n}\n\nconst integrationsByConfig = new WeakMap<\n ResolvedConfig,\n Promise<AnalogIntegrations>\n>();\n\n/**\n * Runs every `analog.setup()` hook found in the resolved Vite plugin list,\n * once per resolved config, and composes the registrations in plugin order.\n */\nexport function discoverAnalogIntegrations(\n config: ResolvedConfig,\n): Promise<AnalogIntegrations> {\n let pending = integrationsByConfig.get(config);\n if (!pending) {\n pending = runAnalogSetupHooks(config.plugins ?? []);\n integrationsByConfig.set(config, pending);\n }\n return pending;\n}\n\nexport async function runAnalogSetupHooks(\n plugins: readonly Plugin[],\n): Promise<AnalogIntegrations> {\n const preprocessors: StylePreprocessor[] = [];\n const registryConfigurators: StylesheetRegistryConfigurator[] = [];\n const transformFilters: TransformFilter[] = [];\n const componentRegistries: ComponentRegistryEntries[] = [];\n const include: string[] = [];\n let externalizeStyles = false;\n\n for (const plugin of plugins as readonly AnalogIntegrationPlugin[]) {\n if (typeof plugin.analog?.setup !== 'function') {\n continue;\n }\n\n const registeredBefore = preprocessors.length;\n const context: AnalogPluginContext = {\n registerStylePreprocessor(preprocessor) {\n preprocessors.push(wrapStylePreprocessor(plugin.name, preprocessor));\n },\n externalizeComponentStyles() {\n externalizeStyles = true;\n },\n configureStylesheetRegistry(configure) {\n registryConfigurators.push(\n wrapRegistryConfigurator(plugin.name, configure),\n );\n },\n registerTransformFilter(filter) {\n transformFilters.push(filter);\n },\n registerComponentRegistry(entries) {\n componentRegistries.push(entries);\n },\n addInclude(globs) {\n include.push(...globs);\n },\n };\n\n try {\n await plugin.analog.setup(context);\n } catch (error) {\n throw new Error(\n `[analog] analog.setup() from plugin \"${plugin.name}\" failed: ${describeError(error)}`,\n );\n }\n\n debugStylePipeline('analog.setup() completed', {\n plugin: plugin.name,\n stylePreprocessors: preprocessors.length - registeredBefore,\n registryConfigurators: registryConfigurators.length,\n transformFilters: transformFilters.length,\n componentRegistries: componentRegistries.length,\n include: include.length,\n externalizeStyles,\n });\n }\n\n return {\n stylePreprocessor: composeStylePreprocessors(preprocessors),\n configureStylesheetRegistry: registryConfigurators.length\n ? (registry, context) => {\n for (const configure of registryConfigurators) {\n configure(registry, context);\n }\n }\n : undefined,\n transformFilter: transformFilters.length\n ? (code, id) => transformFilters.every((filter) => filter(code, id))\n : undefined,\n componentRegistries,\n include,\n externalizeStyles,\n };\n}\n\nfunction wrapStylePreprocessor(\n pluginName: string,\n preprocessor: StylePreprocessor,\n): StylePreprocessor {\n return (code, filename, context) => {\n try {\n return preprocessor(code, filename, context);\n } catch (error) {\n throw new Error(\n `[analog] Style preprocessor from plugin \"${pluginName}\" failed for \"${filename}\": ${describeError(error)}`,\n );\n }\n };\n}\n\nfunction wrapRegistryConfigurator(\n pluginName: string,\n configure: StylesheetRegistryConfigurator,\n): StylesheetRegistryConfigurator {\n return (registry, context) => {\n try {\n configure(registry, context);\n } catch (error) {\n throw new Error(\n `[analog] Stylesheet registry configurator from plugin \"${pluginName}\" failed: ${describeError(error)}`,\n );\n }\n };\n}\n\nfunction describeError(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";;;AAuFA,IAAM,uCAAuB,IAAI,
|
|
1
|
+
{"version":3,"file":"analog-plugin-interop.js","names":[],"sources":["../../../src/lib/analog-plugin-interop.ts"],"sourcesContent":["import type { Plugin, ResolvedConfig } from 'vite';\nimport {\n composeStylePreprocessors,\n type StylePreprocessor,\n type StylesheetRegistryReader,\n} from './style-preprocessor.js';\nimport type { RegistryEntry } from './compiler/registry.js';\nimport { debugStylePipeline } from './utils/debug.js';\n\nexport type TransformFilter = (code: string, id: string) => boolean;\n\nexport type ComponentRegistryEntries = ReadonlyMap<string, RegistryEntry>;\n\nexport interface StylesheetRegistryContext {\n workspaceRoot: string;\n}\n\nexport type StylesheetRegistryConfigurator = (\n registry: StylesheetRegistryReader,\n context: StylesheetRegistryContext,\n) => void;\n\n/**\n * Narrow framework context handed to a Vite plugin's `analog.setup()` hook.\n * Only grows when a concrete integration needs another seam.\n */\nexport interface AnalogPluginContext {\n /**\n * Registers a pre-transform that runs on every Angular component stylesheet\n * before it enters Vite's `preprocessCSS` pipeline.\n */\n registerStylePreprocessor(preprocessor: StylePreprocessor): void;\n /**\n * Requests that component styles are externalized in dev and watch mode so\n * they run through Vite's CSS plugin pipeline (for example\n * `@tailwindcss/vite`) instead of being inlined through `preprocessCSS`,\n * which only runs PostCSS and CSS preprocessors. Production builds keep\n * inlining component styles.\n */\n externalizeComponentStyles(): void;\n /**\n * Receives the live stylesheet registry for externalized component styles\n * each time a compilation creates one, so the plugin can map component\n * stylesheet sources to their served ids, dependencies, and diagnostics.\n */\n configureStylesheetRegistry(configure: StylesheetRegistryConfigurator): void;\n /**\n * Restricts which modules Angular compiles. A module is transformed only\n * when every registered filter returns `true` for it.\n */\n registerTransformFilter(filter: TransformFilter): void;\n /**\n * Contributes directive, component, pipe, and NgModule metadata keyed by\n * class name for classes the fast compiler cannot reach through its own\n * tsconfig-driven scan (for example components compiled from another\n * source format). The map is read on every compile, so a plugin may keep\n * filling it after setup.\n */\n registerComponentRegistry(entries: ComponentRegistryEntries): void;\n /**\n * Adds TypeScript include globs to the Angular compilation. Globs resolve\n * against the same workspace root as `angular({ include })`, so a leading\n * `/` means workspace-relative.\n */\n addInclude(globs: string[]): void;\n}\n\nexport interface AnalogPluginHooks {\n setup?(context: AnalogPluginContext): void | Promise<void>;\n}\n\n/**\n * A normal Vite plugin that optionally exposes an `analog` setup hook.\n * Discovery is structural (`plugin.analog?.setup`), so this type is a DX aid\n * rather than a requirement.\n */\nexport type AnalogIntegrationPlugin = Plugin & { analog?: AnalogPluginHooks };\n\nexport interface AnalogIntegrations {\n stylePreprocessor?: StylePreprocessor;\n configureStylesheetRegistry?: StylesheetRegistryConfigurator;\n transformFilter?: TransformFilter;\n componentRegistries: ComponentRegistryEntries[];\n include: string[];\n externalizeStyles: boolean;\n}\n\nconst integrationsByConfig = new WeakMap<\n ResolvedConfig,\n Promise<AnalogIntegrations>\n>();\n\n/**\n * Runs every `analog.setup()` hook found in the resolved Vite plugin list,\n * once per resolved config, and composes the registrations in plugin order.\n */\nexport function discoverAnalogIntegrations(\n config: ResolvedConfig,\n): Promise<AnalogIntegrations> {\n let pending = integrationsByConfig.get(config);\n if (!pending) {\n pending = runAnalogSetupHooks(config.plugins ?? []);\n integrationsByConfig.set(config, pending);\n }\n return pending;\n}\n\nexport async function runAnalogSetupHooks(\n plugins: readonly Plugin[],\n): Promise<AnalogIntegrations> {\n const preprocessors: StylePreprocessor[] = [];\n const registryConfigurators: StylesheetRegistryConfigurator[] = [];\n const transformFilters: TransformFilter[] = [];\n const componentRegistries: ComponentRegistryEntries[] = [];\n const include: string[] = [];\n let externalizeStyles = false;\n\n for (const plugin of plugins as readonly AnalogIntegrationPlugin[]) {\n if (typeof plugin.analog?.setup !== 'function') {\n continue;\n }\n\n const registeredBefore = preprocessors.length;\n const context: AnalogPluginContext = {\n registerStylePreprocessor(preprocessor) {\n preprocessors.push(wrapStylePreprocessor(plugin.name, preprocessor));\n },\n externalizeComponentStyles() {\n externalizeStyles = true;\n },\n configureStylesheetRegistry(configure) {\n registryConfigurators.push(\n wrapRegistryConfigurator(plugin.name, configure),\n );\n },\n registerTransformFilter(filter) {\n transformFilters.push(filter);\n },\n registerComponentRegistry(entries) {\n componentRegistries.push(entries);\n },\n addInclude(globs) {\n include.push(...globs);\n },\n };\n\n try {\n await plugin.analog.setup(context);\n } catch (error) {\n throw new Error(\n `[analog] analog.setup() from plugin \"${plugin.name}\" failed: ${describeError(error)}`,\n );\n }\n\n debugStylePipeline('analog.setup() completed', {\n plugin: plugin.name,\n stylePreprocessors: preprocessors.length - registeredBefore,\n registryConfigurators: registryConfigurators.length,\n transformFilters: transformFilters.length,\n componentRegistries: componentRegistries.length,\n include: include.length,\n externalizeStyles,\n });\n }\n\n return {\n stylePreprocessor: composeStylePreprocessors(preprocessors),\n configureStylesheetRegistry: registryConfigurators.length\n ? (registry, context) => {\n for (const configure of registryConfigurators) {\n configure(registry, context);\n }\n }\n : undefined,\n transformFilter: transformFilters.length\n ? (code, id) => transformFilters.every((filter) => filter(code, id))\n : undefined,\n componentRegistries,\n include,\n externalizeStyles,\n };\n}\n\nfunction wrapStylePreprocessor(\n pluginName: string,\n preprocessor: StylePreprocessor,\n): StylePreprocessor {\n return (code, filename, context) => {\n try {\n return preprocessor(code, filename, context);\n } catch (error) {\n throw new Error(\n `[analog] Style preprocessor from plugin \"${pluginName}\" failed for \"${filename}\": ${describeError(error)}`,\n );\n }\n };\n}\n\nfunction wrapRegistryConfigurator(\n pluginName: string,\n configure: StylesheetRegistryConfigurator,\n): StylesheetRegistryConfigurator {\n return (registry, context) => {\n try {\n configure(registry, context);\n } catch (error) {\n throw new Error(\n `[analog] Stylesheet registry configurator from plugin \"${pluginName}\" failed: ${describeError(error)}`,\n );\n }\n };\n}\n\nfunction describeError(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";;;AAuFA,IAAM,uCAAuB,IAAI,QAG/B;;;;;AAMF,SAAgB,2BACd,QAC6B;CAC7B,IAAI,UAAU,qBAAqB,IAAI,MAAM;CAC7C,IAAI,CAAC,SAAS;EACZ,UAAU,oBAAoB,OAAO,WAAW,CAAC,CAAC;EAClD,qBAAqB,IAAI,QAAQ,OAAO;CAC1C;CACA,OAAO;AACT;AAEA,eAAsB,oBACpB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AEA,SAAS,sBACP,YACA,cACmB;CACnB,QAAQ,MAAM,UAAU,YAAY;EAClC,IAAI;GACF,OAAO,aAAa,MAAM,UAAU,OAAO;EAC7C,SAAS,OAAO;GACd,MAAM,IAAI,MACR,4CAA4C,WAAW,gBAAgB,SAAS,KAAK,cAAc,KAAK,GAC1G;EACF;CACF;AACF;AAEA,SAAS,yBACP,YACA,WACgC;CAChC,QAAQ,UAAU,YAAY;EAC5B,IAAI;GACF,UAAU,UAAU,OAAO;EAC7B,SAAS,OAAO;GACd,MAAM,IAAI,MACR,0DAA0D,WAAW,YAAY,cAAc,KAAK,GACtG;EACF;CACF;AACF;AAEA,SAAS,cAAc,OAAwB;CAC7C,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D"}
|
|
@@ -1 +1 @@
|
|
|
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({ jit }: { jit: boolean }): 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,EAAE,OAAiC;CACtE,MAAM,+BAAe,IAAI,
|
|
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({ jit }: { jit: boolean }): 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,EAAE,OAAiC;CACtE,MAAM,+BAAe,IAAI,IAGvB;CACF,IAAI,SAAS;CACb,IAAI,UAAU;CACd,IAAI,qBAAqB;CAEzB,SAAS,eAAe,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BACH,uBAAuB,aAAa,OAAO,IAC3C;KAAE,MAAM;KAAa,KAAK,EAAE,UAAU,GAAG;IAAE;GACjD;EACF;EACA,MAAM,cAAc;GAClB,IAAI,SACF;GAEF,MAAM,UAAU,KAAK,aAAa,QAAQ;GAC1C,MAAM,cAAc,aAAa,IAAI,OAAO;GAC5C,IAAI,aAAa;IACf,aAAa,OAAO,OAAO;IAC3B,MAAM,YAAY,MAAM;GAC1B;EACF;CACF;AACF;AAEA,SAAgB,uBACd,MACA,IACsC;CACtC,MAAM,iBAAiB,KAAK,MAC1B,mGACF;CACA,IAAI,CAAC,kBAAkB,eAAe,UAAU,KAAA,GAC9C,OAAO;EACL;EACA,KAAK;CACP;CAEF,OAAO;EACL,MAAM,KAAK,MAAM,GAAG,eAAe,KAAK;EACxC,KAAK,OAAO,KAAK,eAAe,IAAK,QAAQ,CAAC,CAAC,SAAS;CAC1D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
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 hashJitInlineStyles,\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 encodedStyles = getJitInlineStyles(id.split('style:inline;')[1]);\n const styleIdHash = hashJitInlineStyles(encodedStyles);\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":";;;;;;;AAYA,SAAgB,UAAU,EACxB,yBAGS;CACT,IAAI;CACJ,IAAI;
|
|
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 hashJitInlineStyles,\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 encodedStyles = getJitInlineStyles(id.split('style:inline;')[1]);\n const styleIdHash = hashJitInlineStyles(encodedStyles);\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":";;;;;;;AAYA,SAAgB,UAAU,EACxB,yBAGS;CACT,IAAI;CACJ,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,eAAe,SAAS;GACtB,SAAS;EACX;EACA,MAAM,aAAa;GACjB,qBAAqB,MAAM,2BAA2B,MAAM,EAAA,CACzD;EACL;EACA,UAAU,IAAY;GACpB,IAAI,GAAG,WAAW,iBAAiB,GACjC,OAAO,KAAK;EAIhB;EACA,MAAM,KAAK,IAAY;GACrB,IAAI,GAAG,SAAA,mCAAgC,GAAG;IACxC,MAAM,gBAAgB,mBAAmB,GAAG,MAAM,eAAe,CAAC,CAAC,EAAE;IACrE,MAAM,cAAc,oBAAoB,aAAa;IACrD,MAAM,gBAAgB,OAAO,KAC3B,mBAAmB,aAAa,GAChC,QACF,CAAC,CAAC,SAAS;IACX,MAAM,WAAW,GAAG,YAAY,GAAG;IACnC,MAAM,eAAe,qBACnB,eACA,UACA,mBACA;KAAE;KAAU,QAAQ;IAAK,CAC3B;IAEA,IAAI,SAA6B;IAEjC,IAAI;KAMF,UAAS,MALc,cACrB,cACA,GAAG,SAAS,UACZ,MACF,EAAA,EACmB;IACrB,SAAS,GAAG;KACV,MAAM,eAAe,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;KAC9D,YAAY,6BAA6B;MACvC;MACA,OAAO;KACT,CAAC;KACD,QAAQ,KACN,6HACA,aACA,YACF;IACF;IAEA,OAAO,oBAAoB,OAAO;GACpC;EAGF;EACA,cAAc;GACZ,IAAI,CAAC,KAAK,MAAM,WACd,8BAA8B;EAElC;CACF;AACF"}
|
|
@@ -133,7 +133,8 @@ function angular(options) {
|
|
|
133
133
|
const normalizeEmitterLookupId = (file) => {
|
|
134
134
|
const normalizedFile = normalizePath(file);
|
|
135
135
|
if (!normalizedFile.startsWith("/@fs/")) return normalizedFile;
|
|
136
|
-
|
|
136
|
+
const fsPath = normalizedFile.slice(4).replace(/^\/([A-Za-z]:\/)/, "$1");
|
|
137
|
+
return normalizePath(fsPath);
|
|
137
138
|
};
|
|
138
139
|
const describeEmitMarkers = (content) => ({
|
|
139
140
|
contentLength: content.length,
|
|
@@ -162,6 +163,7 @@ function angular(options) {
|
|
|
162
163
|
return emittedResult;
|
|
163
164
|
};
|
|
164
165
|
let initialCompilation = false;
|
|
166
|
+
let activeBuilds = 0;
|
|
165
167
|
const declarationFiles = [];
|
|
166
168
|
const fileTransformMap = /* @__PURE__ */ new Map();
|
|
167
169
|
let styleTransform;
|
|
@@ -251,14 +253,14 @@ function angular(options) {
|
|
|
251
253
|
hotUpdates.configureServer(server);
|
|
252
254
|
const invalidateCompilationOnFsChange = createFsWatcherCacheInvalidator(invalidateFsCaches, invalidateTsconfigCaches, () => performCompilation(resolvedConfig));
|
|
253
255
|
server.watcher.on("add", (file) => {
|
|
254
|
-
if (EXCLUDED_TS_EXT_REGEX.test(file)) invalidateSourceFiles(new Set([normalizePath(file)]));
|
|
256
|
+
if (EXCLUDED_TS_EXT_REGEX.test(file)) invalidateSourceFiles(/* @__PURE__ */ new Set([normalizePath(file)]));
|
|
255
257
|
return invalidateCompilationOnFsChange();
|
|
256
258
|
});
|
|
257
259
|
server.watcher.on("unlink", (file) => {
|
|
258
260
|
const id = normalizePath(file);
|
|
259
261
|
outputFiles.delete(id);
|
|
260
262
|
tsSourceFileCache.delete(id);
|
|
261
|
-
sourceFileCache.invalidate(new Set([id]));
|
|
263
|
+
sourceFileCache.invalidate(/* @__PURE__ */ new Set([id]));
|
|
262
264
|
evictDeletedFileMetadata(file, {
|
|
263
265
|
classNamesMap: classNames,
|
|
264
266
|
fileTransformMap
|
|
@@ -270,6 +272,7 @@ function angular(options) {
|
|
|
270
272
|
});
|
|
271
273
|
},
|
|
272
274
|
async buildStart() {
|
|
275
|
+
activeBuilds++;
|
|
273
276
|
if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, resolvedConfig);
|
|
274
277
|
if (!deferInitialCompilation) {
|
|
275
278
|
pendingCompilation = performCompilation(this.environment?.config ?? resolvedConfig);
|
|
@@ -279,7 +282,8 @@ function angular(options) {
|
|
|
279
282
|
}
|
|
280
283
|
},
|
|
281
284
|
buildEnd() {
|
|
282
|
-
|
|
285
|
+
activeBuilds = Math.max(0, activeBuilds - 1);
|
|
286
|
+
if (watchMode || activeBuilds > 0) return;
|
|
283
287
|
nextProgram = void 0;
|
|
284
288
|
cachedHost = void 0;
|
|
285
289
|
cachedHostKey = void 0;
|
|
@@ -756,6 +760,7 @@ function angular(options) {
|
|
|
756
760
|
...isTest && !isStackBlitz ? angularVitestPlugins((id) => outputFiles.get(normalizePath(id))?.map) : [],
|
|
757
761
|
jit && jitPlugin({ inlineStylesExtension: pluginOptions.inlineStylesExtension }),
|
|
758
762
|
buildOptimizerPlugin({ jit }),
|
|
763
|
+
!isTest && devServerModePlugin(),
|
|
759
764
|
routerPlugin(),
|
|
760
765
|
nxFolderPlugin(),
|
|
761
766
|
encapsulationPlugin()
|
|
@@ -872,7 +877,8 @@ function angular(options) {
|
|
|
872
877
|
}
|
|
873
878
|
if (!watchMode) builder = ts.createAbstractBuilder(typeScriptProgram, host, oldBuilder);
|
|
874
879
|
if (angularCompiler) await angularCompiler.analyzeAsync();
|
|
875
|
-
const
|
|
880
|
+
const beforeTransformers = jit ? [compilerCli.constructorParametersDownlevelTransform(builder.getProgram()), createJitResourceTransformer(() => builder.getProgram().getTypeChecker())] : [];
|
|
881
|
+
const transformers = mergeTransformers({ before: beforeTransformers }, jit ? {} : angularCompiler.prepareEmit().transformers);
|
|
876
882
|
const fileMetadata = getFileMetadata(builder, angularCompiler, pluginOptions.liveReload, pluginOptions.disableTypeChecking);
|
|
877
883
|
const writeFileCallback = (_filename, content, _a, _b, sourceFiles) => {
|
|
878
884
|
if (!sourceFiles?.length) return;
|
|
@@ -998,7 +1004,17 @@ function isModuleForChangedResource(mod, changedFile, stylesheetRegistry) {
|
|
|
998
1004
|
if (normalizePath((mod.file ?? "").split("?")[0]) === normalizedChangedFile) return true;
|
|
999
1005
|
if (!mod.id) return false;
|
|
1000
1006
|
const requestPath = getFilenameFromPath(mod.id);
|
|
1001
|
-
|
|
1007
|
+
const sourcePath = stylesheetRegistry?.resolveExternalSource(requestPath) ?? stylesheetRegistry?.resolveExternalSource(requestPath.replace(/^\//, "")) ?? stylesheetRegistry?.getServedSourcePath(requestPath) ?? stylesheetRegistry?.getServedSourcePath(requestPath.replace(/^\//, ""));
|
|
1008
|
+
return normalizePath((sourcePath ?? "").split("?")[0]) === normalizedChangedFile;
|
|
1009
|
+
}
|
|
1010
|
+
function devServerModePlugin() {
|
|
1011
|
+
return {
|
|
1012
|
+
name: "@analogjs/vite-plugin-angular-dev-server-mode",
|
|
1013
|
+
apply: "serve",
|
|
1014
|
+
configEnvironment(_name, config) {
|
|
1015
|
+
if (config.consumer === "server") return { define: { ngServerMode: "true" } };
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1002
1018
|
}
|
|
1003
1019
|
function diagnoseComponentStylesheetPipeline(changedFile, directModule, stylesheetRegistry, wrapperModules, stylePreprocessor) {
|
|
1004
1020
|
const normalizedFile = normalizePath(changedFile.split("?")[0]);
|
|
@@ -1156,7 +1172,7 @@ function logComponentStylesheetHmrOutcome(details) {
|
|
|
1156
1172
|
rejectedPreferredPaths: [...new Set(rejectedPreferredPaths)],
|
|
1157
1173
|
pitfalls: [...new Set(pitfalls)],
|
|
1158
1174
|
anomalies: details.diagnosis.anomalies,
|
|
1159
|
-
hints: [
|
|
1175
|
+
hints: [.../* @__PURE__ */ new Set([...details.diagnosis.hints, ...hints])]
|
|
1160
1176
|
});
|
|
1161
1177
|
}
|
|
1162
1178
|
function findTemplateOwnerModules(server, resourceFile) {
|
|
@@ -1234,6 +1250,6 @@ function getFilenameFromPath(id) {
|
|
|
1234
1250
|
}
|
|
1235
1251
|
}
|
|
1236
1252
|
//#endregion
|
|
1237
|
-
export { angular };
|
|
1253
|
+
export { angular, createFsWatcherCacheInvalidator, evictDeletedFileMetadata, findComponentStylesheetWrapperModules, findTemplateOwnerModules, getFileMetadata, getModulesForChangedFile, isModuleForChangedResource };
|
|
1238
1254
|
|
|
1239
1255
|
//# sourceMappingURL=angular-vite-plugin.js.map
|