@analogjs/vite-plugin-angular 3.0.0-alpha.44 → 3.0.0-alpha.46
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 +2 -0
- package/package.json +17 -1
- package/src/lib/angular-jit-plugin.js +0 -3
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.js +29 -82
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/compilation-api/compilation-api-plugin.js +0 -2
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
- package/src/lib/fast-compile-plugin.d.ts +14 -0
- package/src/lib/fast-compile-plugin.js +36 -7
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/utils/plugin-config.d.ts +9 -2
- package/src/lib/utils/plugin-config.js +10 -3
- package/src/lib/utils/plugin-config.js.map +1 -1
- package/src/lib/utils/safe-module-paths.d.ts +16 -0
- package/src/lib/utils/safe-module-paths.js +29 -0
- package/src/lib/utils/safe-module-paths.js.map +1 -0
- package/src/lib/utils/virtual-ids.d.ts +0 -4
- package/src/lib/utils/virtual-ids.js +1 -13
- package/src/lib/utils/virtual-ids.js.map +1 -1
- package/src/lib/utils/virtual-resources.d.ts +0 -28
- package/src/lib/utils/virtual-resources.js +17 -41
- package/src/lib/utils/virtual-resources.js.map +1 -1
- package/src/lib/virtual-modules-plugin.js +4 -31
- package/src/lib/virtual-modules-plugin.js.map +1 -1
|
@@ -1,24 +1,7 @@
|
|
|
1
|
-
import { type ResolvedConfig } from "vite";
|
|
2
1
|
interface PluginContextLike {
|
|
3
2
|
addWatchFile(path: string): void;
|
|
4
3
|
}
|
|
5
4
|
/**
|
|
6
|
-
* True when the given stylesheet should be run through Vite's `preprocessCSS`,
|
|
7
|
-
* given Vitest's `test.css` semantics:
|
|
8
|
-
*
|
|
9
|
-
* - non-test contexts → always preprocess
|
|
10
|
-
* - `test.css: true` → always preprocess
|
|
11
|
-
* - `test.css: false` → never preprocess
|
|
12
|
-
* - `test.css: { include }` → preprocess only when `filePath` matches an
|
|
13
|
-
* include pattern and isn't excluded
|
|
14
|
-
* - `test.css` unset → Vitest defaults to `include: []`, so nothing
|
|
15
|
-
* matches and we don't preprocess
|
|
16
|
-
*
|
|
17
|
-
* Used to gate `preprocessCSS` calls in test mode so we don't surface SCSS
|
|
18
|
-
* deprecation noise or pay preprocessing cost the user didn't ask for. (#2297)
|
|
19
|
-
*/
|
|
20
|
-
export declare function shouldPreprocessTestCss(config: ResolvedConfig | undefined, filePath?: string): boolean;
|
|
21
|
-
/**
|
|
22
5
|
* Rewrite a user `.html?raw` import to a virtual raw id. Returns undefined
|
|
23
6
|
* when the id doesn't match, so callers can fall through to the next check.
|
|
24
7
|
*
|
|
@@ -28,20 +11,9 @@ export declare function shouldPreprocessTestCss(config: ResolvedConfig | undefin
|
|
|
28
11
|
*/
|
|
29
12
|
export declare function rewriteHtmlRawImport(id: string, importer: string | undefined): string | undefined;
|
|
30
13
|
/**
|
|
31
|
-
* Rewrite a user `.scss?inline` / `.css?inline` / … import to a virtual
|
|
32
|
-
* style id. Returns undefined when the id doesn't match.
|
|
33
|
-
*/
|
|
34
|
-
export declare function rewriteInlineStyleImport(id: string, importer: string | undefined): string | undefined;
|
|
35
|
-
/**
|
|
36
14
|
* Load a virtual raw module: reads the backing file, registers it for HMR
|
|
37
15
|
* watching, and returns its content as a default-exported string. Returns
|
|
38
16
|
* undefined when the id is not a virtual raw id.
|
|
39
17
|
*/
|
|
40
18
|
export declare function loadVirtualRawModule(ctx: PluginContextLike, id: string): Promise<string | undefined>;
|
|
41
|
-
/**
|
|
42
|
-
* Load a virtual style module: reads the backing stylesheet, runs it through
|
|
43
|
-
* Vite's CSS preprocessor, and returns the result as a default-exported
|
|
44
|
-
* string. Returns undefined when the id is not a virtual style id.
|
|
45
|
-
*/
|
|
46
|
-
export declare function loadVirtualStyleModule(ctx: PluginContextLike, id: string, resolvedConfig: ResolvedConfig): Promise<string | undefined>;
|
|
47
19
|
export {};
|
|
@@ -1,34 +1,24 @@
|
|
|
1
|
-
import { fromVirtualRawId,
|
|
1
|
+
import { fromVirtualRawId, isVirtualRawId, toVirtualRawId } from "./virtual-ids.js";
|
|
2
2
|
import { promises } from "node:fs";
|
|
3
|
-
import "node:path";
|
|
4
|
-
import {
|
|
3
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
4
|
+
import { normalizePath } from "vite";
|
|
5
5
|
//#region packages/vite-plugin-angular/src/lib/utils/virtual-resources.ts
|
|
6
|
+
function resolveImportPath(id, importer) {
|
|
7
|
+
const filePath = id.split("?")[0];
|
|
8
|
+
return isAbsolute(filePath) ? normalizePath(filePath) : importer ? normalizePath(resolve(dirname(importer), filePath)) : void 0;
|
|
9
|
+
}
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - non-test contexts → always preprocess
|
|
11
|
-
* - `test.css: true` → always preprocess
|
|
12
|
-
* - `test.css: false` → never preprocess
|
|
13
|
-
* - `test.css: { include }` → preprocess only when `filePath` matches an
|
|
14
|
-
* include pattern and isn't excluded
|
|
15
|
-
* - `test.css` unset → Vitest defaults to `include: []`, so nothing
|
|
16
|
-
* matches and we don't preprocess
|
|
11
|
+
* Rewrite a user `.html?raw` import to a virtual raw id. Returns undefined
|
|
12
|
+
* when the id doesn't match, so callers can fall through to the next check.
|
|
17
13
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
* Routed through a virtual id (rather than `?analog-raw`) so the path Vite
|
|
15
|
+
* sees has no file extension — keeps vite:asset / vite:css from re-tagging
|
|
16
|
+
* the id before our load hook runs.
|
|
20
17
|
*/
|
|
21
|
-
function
|
|
22
|
-
if (!(
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
if (cssOpt === false || cssOpt == null) return false;
|
|
26
|
-
const toArray = (value) => value == null ? [] : Array.isArray(value) ? value : [value];
|
|
27
|
-
const include = toArray(cssOpt.include);
|
|
28
|
-
const exclude = toArray(cssOpt.exclude);
|
|
29
|
-
if (!filePath || include.length === 0) return false;
|
|
30
|
-
const matches = (patterns) => patterns.some((p) => typeof p === "string" ? filePath.includes(p) : p.test(filePath));
|
|
31
|
-
return matches(include) && !matches(exclude);
|
|
18
|
+
function rewriteHtmlRawImport(id, importer) {
|
|
19
|
+
if (!id.includes(".html?raw")) return void 0;
|
|
20
|
+
const resolved = resolveImportPath(id, importer);
|
|
21
|
+
return resolved ? toVirtualRawId(resolved) : void 0;
|
|
32
22
|
}
|
|
33
23
|
/**
|
|
34
24
|
* Load a virtual raw module: reads the backing file, registers it for HMR
|
|
@@ -42,21 +32,7 @@ async function loadVirtualRawModule(ctx, id) {
|
|
|
42
32
|
const content = await promises.readFile(filePath, "utf-8");
|
|
43
33
|
return `export default ${JSON.stringify(content)}`;
|
|
44
34
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Load a virtual style module: reads the backing stylesheet, runs it through
|
|
47
|
-
* Vite's CSS preprocessor, and returns the result as a default-exported
|
|
48
|
-
* string. Returns undefined when the id is not a virtual style id.
|
|
49
|
-
*/
|
|
50
|
-
async function loadVirtualStyleModule(ctx, id, resolvedConfig) {
|
|
51
|
-
if (!isVirtualStyleId(id)) return void 0;
|
|
52
|
-
const filePath = fromVirtualStyleId(id);
|
|
53
|
-
ctx.addWatchFile(filePath);
|
|
54
|
-
const code = await promises.readFile(filePath, "utf-8");
|
|
55
|
-
if (!shouldPreprocessTestCss(resolvedConfig, filePath)) return `export default ${JSON.stringify(code)}`;
|
|
56
|
-
const result = await preprocessCSS(code, filePath, resolvedConfig);
|
|
57
|
-
return `export default ${JSON.stringify(result.code)}`;
|
|
58
|
-
}
|
|
59
35
|
//#endregion
|
|
60
|
-
export { loadVirtualRawModule,
|
|
36
|
+
export { loadVirtualRawModule, rewriteHtmlRawImport };
|
|
61
37
|
|
|
62
38
|
//# sourceMappingURL=virtual-resources.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-resources.js","names":[],"sources":["../../../../src/lib/utils/virtual-resources.ts"],"sourcesContent":["// Shared Vite plugin helpers for routing component resources (templates
|
|
1
|
+
{"version":3,"file":"virtual-resources.js","names":[],"sources":["../../../../src/lib/utils/virtual-resources.ts"],"sourcesContent":["// Shared Vite plugin helpers for routing component resources (templates)\n// through virtual module ids. Both angular-vite-plugin and fast-compile-plugin\n// use these so the rewriting + loading behavior stays in sync between them.\n//\n// Style ?inline imports now flow through Vite's native CSS pipeline via\n// safeModulePaths (see safe-module-paths.ts). Only template ?raw imports\n// still use virtual ids.\n\nimport { promises as fsPromises } from 'node:fs';\nimport { dirname, isAbsolute, resolve } from 'node:path';\nimport { normalizePath } from 'vite';\n\nimport {\n fromVirtualRawId,\n isVirtualRawId,\n toVirtualRawId,\n} from './virtual-ids.js';\n\ninterface PluginContextLike {\n addWatchFile(path: string): void;\n}\n\nfunction resolveImportPath(\n id: string,\n importer: string | undefined,\n): string | undefined {\n const filePath = id.split('?')[0];\n return isAbsolute(filePath)\n ? normalizePath(filePath)\n : importer\n ? normalizePath(resolve(dirname(importer), filePath))\n : undefined;\n}\n\n/**\n * Rewrite a user `.html?raw` import to a virtual raw id. Returns undefined\n * when the id doesn't match, so callers can fall through to the next check.\n *\n * Routed through a virtual id (rather than `?analog-raw`) so the path Vite\n * sees has no file extension — keeps vite:asset / vite:css from re-tagging\n * the id before our load hook runs.\n */\nexport function rewriteHtmlRawImport(\n id: string,\n importer: string | undefined,\n): string | undefined {\n if (!id.includes('.html?raw')) return undefined;\n const resolved = resolveImportPath(id, importer);\n return resolved ? toVirtualRawId(resolved) : undefined;\n}\n\n/**\n * Load a virtual raw module: reads the backing file, registers it for HMR\n * watching, and returns its content as a default-exported string. Returns\n * undefined when the id is not a virtual raw id.\n */\nexport async function loadVirtualRawModule(\n ctx: PluginContextLike,\n id: string,\n): Promise<string | undefined> {\n if (!isVirtualRawId(id)) return undefined;\n const filePath = fromVirtualRawId(id);\n ctx.addWatchFile(filePath);\n const content = await fsPromises.readFile(filePath, 'utf-8');\n return `export default ${JSON.stringify(content)}`;\n}\n"],"mappings":";;;;;AAsBA,SAAS,kBACP,IACA,UACoB;CACpB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAC/B,QAAO,WAAW,SAAS,GACvB,cAAc,SAAS,GACvB,WACE,cAAc,QAAQ,QAAQ,SAAS,EAAE,SAAS,CAAC,GACnD,KAAA;;;;;;;;;;AAWR,SAAgB,qBACd,IACA,UACoB;AACpB,KAAI,CAAC,GAAG,SAAS,YAAY,CAAE,QAAO,KAAA;CACtC,MAAM,WAAW,kBAAkB,IAAI,SAAS;AAChD,QAAO,WAAW,eAAe,SAAS,GAAG,KAAA;;;;;;;AAQ/C,eAAsB,qBACpB,KACA,IAC6B;AAC7B,KAAI,CAAC,eAAe,GAAG,CAAE,QAAO,KAAA;CAChC,MAAM,WAAW,iBAAiB,GAAG;AACrC,KAAI,aAAa,SAAS;CAC1B,MAAM,UAAU,MAAM,SAAW,SAAS,UAAU,QAAQ;AAC5D,QAAO,kBAAkB,KAAK,UAAU,QAAQ"}
|
|
@@ -1,46 +1,19 @@
|
|
|
1
|
-
import { toVirtualRawId
|
|
2
|
-
import { loadVirtualRawModule, loadVirtualStyleModule, shouldPreprocessTestCss } from "./utils/virtual-resources.js";
|
|
3
|
-
import { promises } from "node:fs";
|
|
1
|
+
import { toVirtualRawId } from "./utils/virtual-ids.js";
|
|
4
2
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
5
|
-
import { normalizePath
|
|
3
|
+
import { normalizePath } from "vite";
|
|
6
4
|
//#region packages/vite-plugin-angular/src/lib/virtual-modules-plugin.ts
|
|
7
5
|
function virtualModulesPlugin(pluginOptions) {
|
|
8
|
-
let resolvedConfig;
|
|
9
6
|
return {
|
|
10
7
|
name: "@analogjs/vite-plugin-angular:virtual-modules",
|
|
11
8
|
enforce: "pre",
|
|
12
|
-
configResolved(config) {
|
|
13
|
-
resolvedConfig = config;
|
|
14
|
-
},
|
|
15
9
|
resolveId(id, importer) {
|
|
16
|
-
if (id.startsWith("virtual:@analogjs/vite-plugin-angular:
|
|
17
|
-
if (pluginOptions.jit && id.startsWith("angular:jit:"))
|
|
18
|
-
const filePath = normalizePath(resolve(dirname(importer), id.split(";")[1]));
|
|
19
|
-
return id.includes(":style") ? toVirtualStyleId(filePath) : toVirtualRawId(filePath);
|
|
20
|
-
}
|
|
10
|
+
if (id.startsWith("virtual:@analogjs/vite-plugin-angular:raw:")) return `\0${id}`;
|
|
11
|
+
if (pluginOptions.jit && id.startsWith("angular:jit:")) return toVirtualRawId(normalizePath(resolve(dirname(importer), id.split(";")[1])));
|
|
21
12
|
if (id.includes(".html?raw")) {
|
|
22
13
|
const filePath = id.split("?")[0];
|
|
23
14
|
const resolved = isAbsolute(filePath) ? normalizePath(filePath) : importer ? normalizePath(resolve(dirname(importer), filePath)) : void 0;
|
|
24
15
|
if (resolved) return toVirtualRawId(resolved);
|
|
25
16
|
}
|
|
26
|
-
if (/\.(css|scss|sass|less)\?inline$/.test(id)) {
|
|
27
|
-
const filePath = id.split("?")[0];
|
|
28
|
-
const resolved = isAbsolute(filePath) ? normalizePath(filePath) : importer ? normalizePath(resolve(dirname(importer), filePath)) : void 0;
|
|
29
|
-
if (resolved) return toVirtualStyleId(resolved);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
async load(id) {
|
|
33
|
-
const styleModule = await loadVirtualStyleModule(this, id, resolvedConfig);
|
|
34
|
-
if (styleModule !== void 0) return styleModule;
|
|
35
|
-
const rawModule = await loadVirtualRawModule(this, id);
|
|
36
|
-
if (rawModule !== void 0) return rawModule;
|
|
37
|
-
if (/\.(css|scss|sass|less)\?inline$/.test(id)) {
|
|
38
|
-
const filePath = id.split("?")[0];
|
|
39
|
-
const code = await promises.readFile(filePath, "utf-8");
|
|
40
|
-
if (!shouldPreprocessTestCss(resolvedConfig, filePath)) return `export default ${JSON.stringify(code)}`;
|
|
41
|
-
const result = await preprocessCSS(code, filePath, resolvedConfig);
|
|
42
|
-
return `export default ${JSON.stringify(result.code)}`;
|
|
43
|
-
}
|
|
44
17
|
}
|
|
45
18
|
};
|
|
46
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-modules-plugin.js","names":[],"sources":["../../../src/lib/virtual-modules-plugin.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"virtual-modules-plugin.js","names":[],"sources":["../../../src/lib/virtual-modules-plugin.ts"],"sourcesContent":["import { dirname, isAbsolute, resolve } from 'node:path';\nimport { normalizePath, Plugin } from 'vite';\nimport { VIRTUAL_RAW_PREFIX, toVirtualRawId } from './utils/virtual-ids.js';\n\nexport interface VirtualModulesPluginOptions {\n jit: boolean;\n}\n\nexport function virtualModulesPlugin(\n pluginOptions: VirtualModulesPluginOptions,\n): Plugin {\n return {\n name: '@analogjs/vite-plugin-angular:virtual-modules',\n enforce: 'pre',\n resolveId(id, importer) {\n if (id.startsWith(VIRTUAL_RAW_PREFIX)) {\n return `\\0${id}`;\n }\n\n if (pluginOptions.jit && id.startsWith('angular:jit:')) {\n const filePath = normalizePath(\n resolve(dirname(importer as string), id.split(';')[1]),\n );\n return toVirtualRawId(filePath);\n }\n\n // Intercept .html?raw imports to bypass Vite server.fs restrictions\n if (id.includes('.html?raw')) {\n const filePath = id.split('?')[0];\n const resolved = isAbsolute(filePath)\n ? normalizePath(filePath)\n : importer\n ? normalizePath(resolve(dirname(importer), filePath))\n : undefined;\n if (resolved) {\n return toVirtualRawId(resolved);\n }\n }\n\n return undefined;\n },\n };\n}\n"],"mappings":";;;;AAQA,SAAgB,qBACd,eACQ;AACR,QAAO;EACL,MAAM;EACN,SAAS;EACT,UAAU,IAAI,UAAU;AACtB,OAAI,GAAG,WAAA,6CAA8B,CACnC,QAAO,KAAK;AAGd,OAAI,cAAc,OAAO,GAAG,WAAW,eAAe,CAIpD,QAAO,eAHU,cACf,QAAQ,QAAQ,SAAmB,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CACvD,CAC8B;AAIjC,OAAI,GAAG,SAAS,YAAY,EAAE;IAC5B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;IAC/B,MAAM,WAAW,WAAW,SAAS,GACjC,cAAc,SAAS,GACvB,WACE,cAAc,QAAQ,QAAQ,SAAS,EAAE,SAAS,CAAC,GACnD,KAAA;AACN,QAAI,SACF,QAAO,eAAe,SAAS;;;EAMtC"}
|