@analogjs/vite-plugin-angular 3.0.0-alpha.44 → 3.0.0-alpha.45
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 -81
- 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.js +29 -6
- package/src/lib/fast-compile-plugin.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 +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"}
|