@analogjs/vite-plugin-angular 3.0.0-alpha.6 → 3.0.0-alpha.61
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 +3 -2
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
- package/src/lib/angular-build-optimizer-plugin.js +48 -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 +39 -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 +178 -70
- package/src/lib/angular-vite-plugin.js +1261 -1085
- 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 +105 -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 +488 -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 +445 -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 +152 -63
- 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/template-class-binding-guard-plugin.d.ts +30 -0
- package/src/lib/template-class-binding-guard-plugin.js +237 -0
- package/src/lib/template-class-binding-guard-plugin.js.map +1 -0
- package/src/lib/tools/package.json +2 -7
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -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/plugin-config.d.ts +34 -0
- package/src/lib/utils/plugin-config.js +71 -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,113 @@
|
|
|
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
|
+
return {
|
|
25
|
+
optimizeDeps: { include: [
|
|
26
|
+
"tslib",
|
|
27
|
+
"@angular/core",
|
|
28
|
+
"@angular/core/testing",
|
|
29
|
+
"@angular/platform-browser/testing"
|
|
30
|
+
] },
|
|
31
|
+
ssr: { noExternal: [
|
|
32
|
+
...vitestAngularSetupEntries,
|
|
33
|
+
/fesm2022(.*?)testing/,
|
|
34
|
+
/fesm2015/
|
|
35
|
+
] },
|
|
36
|
+
test: { pool: userConfig.test?.pool ?? "vmThreads" }
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
transform: {
|
|
40
|
+
filter: { id: /fesm2022|@angular\/cdk/ },
|
|
41
|
+
async handler(_code, id) {
|
|
42
|
+
if (/fesm2022/.test(id) && _code.includes("async ") || _code.includes("@angular/cdk")) {
|
|
43
|
+
if (isRolldown()) return;
|
|
44
|
+
const { code, map } = await vite.transformWithEsbuild(_code, id, {
|
|
45
|
+
loader: "js",
|
|
46
|
+
format: "esm",
|
|
47
|
+
target: "es2016",
|
|
48
|
+
sourcemap: true,
|
|
49
|
+
sourcefile: id
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
code,
|
|
53
|
+
map
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
61
59
|
}
|
|
62
60
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
esbuild: userConfig.esbuild ?? false,
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
};
|
|
61
|
+
* Eagerly disables the built-in JS transformer (esbuild on Vite ≤7, OXC on
|
|
62
|
+
* Vite 8+) so Vitest's internal plugin doesn't race with the Angular
|
|
63
|
+
* compiler. Must run at `enforce: 'pre'` to take effect before Vitest
|
|
64
|
+
* reads the resolved config.
|
|
65
|
+
*/
|
|
66
|
+
function angularVitestEsbuildPlugin() {
|
|
67
|
+
return {
|
|
68
|
+
name: "@analogjs/vitest-angular-esbuild-oxc-plugin",
|
|
69
|
+
enforce: "pre",
|
|
70
|
+
config(userConfig) {
|
|
71
|
+
const jsTransformConfigKey = getJsTransformConfigKey();
|
|
72
|
+
return { [jsTransformConfigKey]: jsTransformConfigKey === "oxc" ? userConfig.oxc ?? false : userConfig.esbuild ?? false };
|
|
73
|
+
}
|
|
74
|
+
};
|
|
82
75
|
}
|
|
83
76
|
/**
|
|
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
|
-
};
|
|
77
|
+
* Post-processing pass that converts any `.ts` files Angular's compilation
|
|
78
|
+
* skipped (e.g. files without Angular decorators when
|
|
79
|
+
* `useAngularCompilationAPI` is on) into runnable JS via esbuild/OXC.
|
|
80
|
+
*
|
|
81
|
+
* Files Angular already compiled have a sourcemap available via
|
|
82
|
+
* `getInMap` — we skip those here to avoid breaking the chain Vite is
|
|
83
|
+
* already wiring up. Re-running OXC over already-compiled JS produces a
|
|
84
|
+
* map relative to the TS-emitted JS, not the original .ts source, and
|
|
85
|
+
* OXC's `inMap` parameter does not chain through the way esbuild's inline
|
|
86
|
+
* `//# sourceMappingURL=` auto-detection does.
|
|
87
|
+
*/
|
|
88
|
+
function angularVitestSourcemapPlugin(getInMap) {
|
|
89
|
+
return {
|
|
90
|
+
name: "@analogjs/vitest-angular-sourcemap-plugin",
|
|
91
|
+
transform: {
|
|
92
|
+
filter: { id: /\.ts(?:\?|$)/ },
|
|
93
|
+
async handler(code, id) {
|
|
94
|
+
const [bareId, query] = id.split("?");
|
|
95
|
+
if (query && query.includes("inline")) return;
|
|
96
|
+
if (getInMap?.(bareId)) return;
|
|
97
|
+
if (vite.transformWithOxc) return await vite.transformWithOxc(code, id, { lang: /\.tsx(\?|$)/.test(bareId) ? "tsx" : "ts" });
|
|
98
|
+
else return await vite.transformWithEsbuild(code, id, { loader: "ts" });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
114
102
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
103
|
+
function angularVitestPlugins(getInMap) {
|
|
104
|
+
return [
|
|
105
|
+
angularVitestPlugin(),
|
|
106
|
+
angularVitestEsbuildPlugin(),
|
|
107
|
+
angularVitestSourcemapPlugin(getInMap)
|
|
108
|
+
];
|
|
121
109
|
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { angularVitestPlugins };
|
|
112
|
+
|
|
122
113
|
//# 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 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 test: {\n pool: (userConfig as any).test?.pool ?? 'vmThreads',\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 if (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;AACjB,UAAO;IACL,cAAc,EACZ,SAAS;KACP;KACA;KACA;KACA;KACD,EACF;IACD,KAAK,EACH,YAAY;KACV,GAAG;KACH;KACA;KACD,EACF;IACD,MAAM,EACJ,MAAO,WAAmB,MAAM,QAAQ,aACzC;IACF;;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;AAGF,QAAI,KAAK,iBAIP,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;
|