@analogjs/vite-plugin-angular 3.0.0-alpha.7 → 3.0.0-alpha.71
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 +30 -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 +51 -12
- package/src/index.d.ts +5 -2
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/lib/analog-plugin-interop.d.ts +40 -0
- package/src/lib/analog-plugin-interop.js +61 -0
- package/src/lib/analog-plugin-interop.js.map +1 -0
- package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
- package/src/lib/angular-build-optimizer-plugin.js +57 -62
- 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 +51 -37
- 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 +17 -18
- package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +177 -69
- package/src/lib/angular-vite-plugin.js +1227 -1084
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +26 -17
- package/src/lib/angular-vitest-plugin.js +106 -114
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compilation-api/compilation-api-plugin.d.ts +29 -0
- package/src/lib/compilation-api/compilation-api-plugin.js +491 -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 +40 -44
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/component-resolvers.d.ts +23 -5
- package/src/lib/component-resolvers.js +107 -64
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/encapsulation-plugin.d.ts +13 -0
- package/src/lib/encapsulation-plugin.js +48 -0
- package/src/lib/encapsulation-plugin.js.map +1 -0
- package/src/lib/fast-compile-plugin.d.ts +28 -0
- package/src/lib/fast-compile-plugin.js +414 -0
- package/src/lib/fast-compile-plugin.js.map +1 -0
- package/src/lib/host.d.ts +10 -8
- package/src/lib/host.js +113 -101
- 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 +61 -63
- 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 +18 -16
- 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 +40 -62
- 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 +35 -23
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-pipeline.d.ts +15 -0
- package/src/lib/style-pipeline.js +31 -0
- package/src/lib/style-pipeline.js.map +1 -0
- 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/tailwind-plugin.d.ts +34 -0
- package/src/lib/tailwind-plugin.js +116 -0
- package/src/lib/tailwind-plugin.js.map +1 -0
- package/src/lib/tools/package.json +2 -7
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +33 -38
- 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 +51 -62
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/tools/src/index.js +0 -2
- 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/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 +28 -0
- package/src/lib/utils/debug.js +39 -0
- package/src/lib/utils/debug.js.map +1 -0
- package/src/lib/utils/devkit.d.ts +6 -6
- package/src/lib/utils/devkit.js +34 -38
- 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 +2 -0
- package/src/lib/utils/rolldown.js +12 -0
- package/src/lib/utils/rolldown.js.map +1 -0
- 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 +35 -37
- package/src/lib/utils/source-file-cache.js.map +1 -1
- package/src/lib/utils/tailwind-reference.d.ts +12 -0
- package/src/lib/utils/tailwind-reference.js +99 -0
- package/src/lib/utils/tailwind-reference.js.map +1 -0
- 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 +28 -0
- package/src/lib/utils/tsconfig-resolver.js +191 -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 -215
- package/setup-vitest.js.map +0 -1
- package/src/lib/models.js +0 -1
- package/src/lib/models.js.map +0 -1
- package/src/lib/tools/README.md +0 -3
- package/src/lib/tools/src/index.d.ts +0 -0
- package/src/lib/tools/src/index.js.map +0 -1
- package/src/lib/utils/compiler-plugin-options.js +0 -1
- package/src/lib/utils/compiler-plugin-options.js.map +0 -1
- package/src/lib/utils/hmr-candidates.js +0 -272
- package/src/lib/utils/hmr-candidates.js.map +0 -1
|
@@ -1,122 +1,114 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getJsTransformConfigKey, isRolldown } from "./utils/rolldown.js";
|
|
2
|
+
import * as vite from "vite";
|
|
3
|
+
//#region packages/vite-plugin-angular/src/lib/angular-vitest-plugin.ts
|
|
4
|
+
var vitestAngularSetupEntries = [
|
|
5
|
+
"@analogjs/vitest-angular/setup-testbed",
|
|
6
|
+
"@analogjs/vitest-angular/setup-zone",
|
|
7
|
+
"@analogjs/vitest-angular/setup-snapshots",
|
|
8
|
+
"@analogjs/vitest-angular/setup-serializers"
|
|
9
|
+
];
|
|
2
10
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
code,
|
|
54
|
-
map,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
},
|
|
60
|
-
};
|
|
11
|
+
* Sets up test config for Vitest and downlevels Angular FESM bundles and
|
|
12
|
+
* `@angular/cdk` from modern async/await to ES2016 so that Zone.js can
|
|
13
|
+
* intercept promises during `fakeAsync` tests.
|
|
14
|
+
*
|
|
15
|
+
* Under Vite 8+ (Rolldown) downleveling is not needed.
|
|
16
|
+
* Under Vite ≤7, esbuild handles the downlevel.
|
|
17
|
+
*/
|
|
18
|
+
function angularVitestPlugin() {
|
|
19
|
+
return {
|
|
20
|
+
name: "@analogjs/vitest-angular-esm-plugin",
|
|
21
|
+
apply: "serve",
|
|
22
|
+
enforce: "post",
|
|
23
|
+
config(userConfig) {
|
|
24
|
+
const browserEnabled = userConfig.test?.browser?.enabled;
|
|
25
|
+
return {
|
|
26
|
+
optimizeDeps: { include: [
|
|
27
|
+
"tslib",
|
|
28
|
+
"@angular/core",
|
|
29
|
+
"@angular/core/testing",
|
|
30
|
+
"@angular/platform-browser/testing"
|
|
31
|
+
] },
|
|
32
|
+
ssr: { noExternal: [
|
|
33
|
+
...vitestAngularSetupEntries,
|
|
34
|
+
/fesm2022(.*?)testing/,
|
|
35
|
+
/fesm2015/
|
|
36
|
+
] },
|
|
37
|
+
...browserEnabled ? {} : { test: { pool: userConfig.test?.pool ?? "vmThreads" } }
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
transform: {
|
|
41
|
+
filter: { id: /fesm2022|@angular\/cdk/ },
|
|
42
|
+
async handler(_code, id) {
|
|
43
|
+
if (/fesm2022/.test(id) && _code.includes("async ") || _code.includes("@angular/cdk")) {
|
|
44
|
+
if (isRolldown()) return;
|
|
45
|
+
const { code, map } = await vite.transformWithEsbuild(_code, id, {
|
|
46
|
+
loader: "js",
|
|
47
|
+
format: "esm",
|
|
48
|
+
target: "es2016",
|
|
49
|
+
sourcemap: true,
|
|
50
|
+
sourcefile: id
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
code,
|
|
54
|
+
map
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
61
60
|
}
|
|
62
61
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
esbuild: userConfig.esbuild ?? false,
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
};
|
|
62
|
+
* Eagerly disables the built-in JS transformer (esbuild on Vite ≤7, OXC on
|
|
63
|
+
* Vite 8+) so Vitest's internal plugin doesn't race with the Angular
|
|
64
|
+
* compiler. Must run at `enforce: 'pre'` to take effect before Vitest
|
|
65
|
+
* reads the resolved config.
|
|
66
|
+
*/
|
|
67
|
+
function angularVitestEsbuildPlugin() {
|
|
68
|
+
return {
|
|
69
|
+
name: "@analogjs/vitest-angular-esbuild-oxc-plugin",
|
|
70
|
+
enforce: "pre",
|
|
71
|
+
config(userConfig) {
|
|
72
|
+
const jsTransformConfigKey = getJsTransformConfigKey();
|
|
73
|
+
return { [jsTransformConfigKey]: jsTransformConfigKey === "oxc" ? userConfig.oxc ?? false : userConfig.esbuild ?? false };
|
|
74
|
+
}
|
|
75
|
+
};
|
|
82
76
|
}
|
|
83
77
|
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
};
|
|
78
|
+
* Post-processing pass that converts any `.ts` files Angular's compilation
|
|
79
|
+
* skipped (e.g. files without Angular decorators when
|
|
80
|
+
* `useAngularCompilationAPI` is on) into runnable JS via esbuild/OXC.
|
|
81
|
+
*
|
|
82
|
+
* Files Angular already compiled have a sourcemap available via
|
|
83
|
+
* `getInMap` — we skip those here to avoid breaking the chain Vite is
|
|
84
|
+
* already wiring up. Re-running OXC over already-compiled JS produces a
|
|
85
|
+
* map relative to the TS-emitted JS, not the original .ts source, and
|
|
86
|
+
* OXC's `inMap` parameter does not chain through the way esbuild's inline
|
|
87
|
+
* `//# sourceMappingURL=` auto-detection does.
|
|
88
|
+
*/
|
|
89
|
+
function angularVitestSourcemapPlugin(getInMap) {
|
|
90
|
+
return {
|
|
91
|
+
name: "@analogjs/vitest-angular-sourcemap-plugin",
|
|
92
|
+
transform: {
|
|
93
|
+
filter: { id: /\.ts(?:\?|$)/ },
|
|
94
|
+
async handler(code, id) {
|
|
95
|
+
const [bareId, query] = id.split("?");
|
|
96
|
+
if (query && query.includes("inline")) return;
|
|
97
|
+
if (getInMap?.(bareId)) return;
|
|
98
|
+
if (isRolldown() && vite.transformWithOxc) return await vite.transformWithOxc(code, id, { lang: /\.tsx(\?|$)/.test(bareId) ? "tsx" : "ts" });
|
|
99
|
+
else return await vite.transformWithEsbuild(code, id, { loader: "ts" });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
114
103
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
104
|
+
function angularVitestPlugins(getInMap) {
|
|
105
|
+
return [
|
|
106
|
+
angularVitestPlugin(),
|
|
107
|
+
angularVitestEsbuildPlugin(),
|
|
108
|
+
angularVitestSourcemapPlugin(getInMap)
|
|
109
|
+
];
|
|
121
110
|
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { angularVitestPlugins };
|
|
113
|
+
|
|
122
114
|
//# sourceMappingURL=angular-vitest-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-vitest-plugin.js","
|
|
1
|
+
{"version":3,"file":"angular-vitest-plugin.js","names":[],"sources":["../../../src/lib/angular-vitest-plugin.ts"],"sourcesContent":["import type { Plugin, TransformResult, UserConfig } from 'vite';\n// Use the namespace import so these runtime helpers still resolve on Vite 6,\n// which does not expose them as named exports.\nimport * as vite from 'vite';\nimport { getJsTransformConfigKey, isRolldown } from './utils/rolldown.js';\n\nconst vitestAngularSetupEntries = [\n '@analogjs/vitest-angular/setup-testbed',\n '@analogjs/vitest-angular/setup-zone',\n '@analogjs/vitest-angular/setup-snapshots',\n '@analogjs/vitest-angular/setup-serializers',\n];\n\n/**\n * Sets up test config for Vitest and downlevels Angular FESM bundles and\n * `@angular/cdk` from modern async/await to ES2016 so that Zone.js can\n * intercept promises during `fakeAsync` tests.\n *\n * Under Vite 8+ (Rolldown) downleveling is not needed.\n * Under Vite ≤7, esbuild handles the downlevel.\n */\nexport function angularVitestPlugin(): Plugin {\n return {\n name: '@analogjs/vitest-angular-esm-plugin',\n apply: 'serve',\n enforce: 'post',\n config(userConfig) {\n // The `vmThreads` pool default only applies to the Node/JSDOM runner.\n // In Vitest browser mode a Node pool is a no-op for execution, but it\n // still poisons isolation: `isolate` has no effect under VM pools\n // (https://vitest.dev/config/isolate), and since Vitest 4.0.7 browser\n // isolation inherits that resolution — so forcing `vmThreads` disables\n // per-file isolation and leaks global state (e.g. fake timers) between\n // spec files. Leave the pool untouched when browser mode is enabled.\n const browserEnabled = (userConfig as any).test?.browser?.enabled;\n\n return {\n optimizeDeps: {\n include: [\n 'tslib',\n '@angular/core',\n '@angular/core/testing',\n '@angular/platform-browser/testing',\n ],\n },\n ssr: {\n noExternal: [\n ...vitestAngularSetupEntries,\n /fesm2022(.*?)testing/,\n /fesm2015/,\n ],\n },\n ...(browserEnabled\n ? {}\n : {\n test: {\n pool: (userConfig as any).test?.pool ?? 'vmThreads',\n },\n }),\n };\n },\n // Filter by module ID so only Angular FESM2022 bundles and CDK enter\n // the handler. The inner guards add a secondary code-content check\n // (`async` keyword) for fesm2022 to avoid needless transforms.\n transform: {\n filter: {\n id: /fesm2022|@angular\\/cdk/,\n },\n async handler(_code, id) {\n if (\n (/fesm2022/.test(id) && _code.includes('async ')) ||\n _code.includes('@angular/cdk')\n ) {\n if (isRolldown()) {\n return undefined;\n }\n\n const { code, map } = await vite.transformWithEsbuild(_code, id, {\n loader: 'js',\n format: 'esm',\n target: 'es2016',\n sourcemap: true,\n sourcefile: id,\n });\n\n return {\n code,\n map,\n };\n }\n\n return undefined;\n },\n },\n };\n}\n\n/**\n * Eagerly disables the built-in JS transformer (esbuild on Vite ≤7, OXC on\n * Vite 8+) so Vitest's internal plugin doesn't race with the Angular\n * compiler. Must run at `enforce: 'pre'` to take effect before Vitest\n * reads the resolved config.\n */\nexport function angularVitestEsbuildPlugin(): Plugin {\n return {\n name: '@analogjs/vitest-angular-esbuild-oxc-plugin',\n enforce: 'pre',\n config(userConfig: UserConfig) {\n const jsTransformConfigKey = getJsTransformConfigKey();\n\n return {\n [jsTransformConfigKey]:\n jsTransformConfigKey === 'oxc'\n ? (userConfig.oxc ?? false)\n : (userConfig.esbuild ?? false),\n };\n },\n };\n}\n\n/**\n * Post-processing pass that converts any `.ts` files Angular's compilation\n * skipped (e.g. files without Angular decorators when\n * `useAngularCompilationAPI` is on) into runnable JS via esbuild/OXC.\n *\n * Files Angular already compiled have a sourcemap available via\n * `getInMap` — we skip those here to avoid breaking the chain Vite is\n * already wiring up. Re-running OXC over already-compiled JS produces a\n * map relative to the TS-emitted JS, not the original .ts source, and\n * OXC's `inMap` parameter does not chain through the way esbuild's inline\n * `//# sourceMappingURL=` auto-detection does.\n */\nexport function angularVitestSourcemapPlugin(\n getInMap?: (id: string) => string | undefined,\n): Plugin {\n return {\n name: '@analogjs/vitest-angular-sourcemap-plugin',\n transform: {\n filter: {\n // Match `.ts` at the end of the path OR before a `?` query string.\n // Vite/Vitest appends query params for virtual modules (e.g.\n // `component.ts?inline`), so a plain `$` anchor would reject them\n // and leave sourcemaps misaligned — causing Angular TestBed teardown\n // crashes (`_doc` undefined in `removeAllRootElements`).\n // The negative lookahead `(?!x)` prevents matching `.tsx` or `.d.ts`.\n id: /\\.ts(?:\\?|$)/,\n },\n async handler(code: string, id: string) {\n const [bareId, query] = id.split('?');\n\n if (query && query.includes('inline')) {\n return;\n }\n\n if (getInMap?.(bareId)) {\n return;\n }\n\n // Keep this in step with `getJsTransformConfigKey()`, which picks the\n // `oxc`/`esbuild` config key off the same signal. Vite 8 ships\n // `transformWithOxc` even on the esbuild path, so feature detection\n // alone would transform with OXC under an `esbuild` config key.\n if (isRolldown() && vite.transformWithOxc) {\n const result = await vite.transformWithOxc(code, id, {\n lang: /\\.tsx(\\?|$)/.test(bareId) ? 'tsx' : 'ts',\n });\n return result as unknown as vite.TransformResult;\n } else {\n const result = await vite.transformWithEsbuild(code, id, {\n loader: 'ts',\n });\n return result;\n }\n },\n },\n };\n}\n\nexport function angularVitestPlugins(\n getInMap?: (id: string) => string | undefined,\n): Plugin[] {\n return [\n angularVitestPlugin(),\n angularVitestEsbuildPlugin(),\n angularVitestSourcemapPlugin(getInMap),\n ];\n}\n"],"mappings":";;;AAMA,IAAM,4BAA4B;CAChC;CACA;CACA;CACA;CACD;;;;;;;;;AAUD,SAAgB,sBAA8B;AAC5C,QAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;EACT,OAAO,YAAY;GAQjB,MAAM,iBAAkB,WAAmB,MAAM,SAAS;AAE1D,UAAO;IACL,cAAc,EACZ,SAAS;KACP;KACA;KACA;KACA;KACD,EACF;IACD,KAAK,EACH,YAAY;KACV,GAAG;KACH;KACA;KACD,EACF;IACD,GAAI,iBACA,EAAE,GACF,EACE,MAAM,EACJ,MAAO,WAAmB,MAAM,QAAQ,aACzC,EACF;IACN;;EAKH,WAAW;GACT,QAAQ,EACN,IAAI,0BACL;GACD,MAAM,QAAQ,OAAO,IAAI;AACvB,QACG,WAAW,KAAK,GAAG,IAAI,MAAM,SAAS,SAAS,IAChD,MAAM,SAAS,eAAe,EAC9B;AACA,SAAI,YAAY,CACd;KAGF,MAAM,EAAE,MAAM,QAAQ,MAAM,KAAK,qBAAqB,OAAO,IAAI;MAC/D,QAAQ;MACR,QAAQ;MACR,QAAQ;MACR,WAAW;MACX,YAAY;MACb,CAAC;AAEF,YAAO;MACL;MACA;MACD;;;GAKN;EACF;;;;;;;;AASH,SAAgB,6BAAqC;AACnD,QAAO;EACL,MAAM;EACN,SAAS;EACT,OAAO,YAAwB;GAC7B,MAAM,uBAAuB,yBAAyB;AAEtD,UAAO,GACJ,uBACC,yBAAyB,QACpB,WAAW,OAAO,QAClB,WAAW,WAAW,OAC9B;;EAEJ;;;;;;;;;;;;;;AAeH,SAAgB,6BACd,UACQ;AACR,QAAO;EACL,MAAM;EACN,WAAW;GACT,QAAQ,EAON,IAAI,gBACL;GACD,MAAM,QAAQ,MAAc,IAAY;IACtC,MAAM,CAAC,QAAQ,SAAS,GAAG,MAAM,IAAI;AAErC,QAAI,SAAS,MAAM,SAAS,SAAS,CACnC;AAGF,QAAI,WAAW,OAAO,CACpB;AAOF,QAAI,YAAY,IAAI,KAAK,iBAIvB,QAHe,MAAM,KAAK,iBAAiB,MAAM,IAAI,EACnD,MAAM,cAAc,KAAK,OAAO,GAAG,QAAQ,MAC5C,CAAC;QAMF,QAHe,MAAM,KAAK,qBAAqB,MAAM,IAAI,EACvD,QAAQ,MACT,CAAC;;GAIP;EACF;;AAGH,SAAgB,qBACd,UACU;AACV,QAAO;EACL,qBAAqB;EACrB,4BAA4B;EAC5B,6BAA6B,SAAS;EACvC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
import { type DebugOption } from "../utils/debug.js";
|
|
3
|
+
import type { StylePreprocessor } from "../style-preprocessor.js";
|
|
4
|
+
import { AngularStylePipelineOptions } from "../style-pipeline.js";
|
|
5
|
+
import { type FileReplacement } from "../plugins/file-replacements.plugin.js";
|
|
6
|
+
export interface CompilationAPIPluginOptions {
|
|
7
|
+
tsconfigGetter: () => string;
|
|
8
|
+
workspaceRoot: string;
|
|
9
|
+
inlineStylesExtension: string;
|
|
10
|
+
jit: boolean;
|
|
11
|
+
liveReload: boolean;
|
|
12
|
+
disableTypeChecking: boolean;
|
|
13
|
+
supportedBrowsers: string[];
|
|
14
|
+
transformFilter?: (code: string, id: string) => boolean;
|
|
15
|
+
fileReplacements: FileReplacement[];
|
|
16
|
+
stylePreprocessor?: StylePreprocessor;
|
|
17
|
+
stylePipeline?: AngularStylePipelineOptions;
|
|
18
|
+
hasTailwindCss: boolean;
|
|
19
|
+
tailwindCss?: {
|
|
20
|
+
rootStylesheet: string;
|
|
21
|
+
prefixes?: string[];
|
|
22
|
+
};
|
|
23
|
+
isTest: boolean;
|
|
24
|
+
isAstroIntegration: boolean;
|
|
25
|
+
include: string[];
|
|
26
|
+
additionalContentDirs: string[];
|
|
27
|
+
debug?: DebugOption;
|
|
28
|
+
}
|
|
29
|
+
export declare function compilationAPIPlugin(pluginOptions: CompilationAPIPluginOptions): Plugin;
|