@analogjs/vite-plugin-angular 3.0.0-beta.57 → 3.0.0-beta.58

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/vite-plugin-angular",
3
- "version": "3.0.0-beta.57",
3
+ "version": "3.0.0-beta.58",
4
4
  "description": "Vite Plugin for Angular",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -2,9 +2,34 @@ import { isAngularBuildContext } from "./angular-build-context.js";
2
2
  import { markStylePathSafe } from "./utils/safe-module-paths.js";
3
3
  import { toVirtualRawId } from "./utils/virtual-ids.js";
4
4
  import { loadVirtualRawModule, rewriteHtmlRawImport } from "./utils/virtual-resources.js";
5
- import { dirname, isAbsolute, resolve } from "node:path";
5
+ import { statSync } from "node:fs";
6
+ import { dirname, isAbsolute, join, resolve } from "node:path";
6
7
  import { normalizePath } from "vite";
7
8
  //#region packages/vite-plugin-angular/src/lib/virtual-modules-plugin.ts
9
+ var FS_PREFIX = "/@fs/";
10
+ function isDirectory(path) {
11
+ return statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
12
+ }
13
+ /**
14
+ * The file a URL that Vite wrote into a module's code points at. Vitest
15
+ * resolves the imports of a module restored from `fsModuleCache` by these
16
+ * URLs, so they must resolve to the same file as the original import.
17
+ * `/@fs/<path>` is that path. A root-relative URL (`/src/app/a.css`) is the
18
+ * file under the Vite root when there is one; otherwise the caller reads it
19
+ * as the path given, which is the order Vite tries the two in. A URL that
20
+ * already starts with the root's path is root-relative only when the root
21
+ * holds a directory at its own path (`/app/app`), as in Vite's resolver.
22
+ */
23
+ function resolveViteUrl(url, root) {
24
+ if (url.startsWith(FS_PREFIX)) {
25
+ const fsPath = url.slice(5);
26
+ return /^[A-Z]:/i.test(fsPath) ? fsPath : `/${fsPath}`;
27
+ }
28
+ if (!root || !url.startsWith("/")) return;
29
+ if (url.startsWith(`${root}/`) && !isDirectory(join(root, root))) return;
30
+ const filePath = join(root, url);
31
+ return statSync(filePath, { throwIfNoEntry: false })?.isFile() ? filePath : void 0;
32
+ }
8
33
  function resolveAngularVirtualId(id, importer, options) {
9
34
  if (id.startsWith("virtual:@analogjs/vite-plugin-angular:raw:")) return `\0${id}`;
10
35
  if (options.jit && id.startsWith("angular:jit:")) {
@@ -19,7 +44,7 @@ function resolveAngularVirtualId(id, importer, options) {
19
44
  if (rawRewrite) return rawRewrite;
20
45
  if (/\.(css|scss|sass|less)\?inline$/.test(id) && importer) {
21
46
  const filePath = id.split("?")[0];
22
- const resolved = isAbsolute(filePath) ? normalizePath(filePath) : normalizePath(resolve(dirname(importer), filePath));
47
+ const resolved = normalizePath(resolveViteUrl(filePath, options.resolvedConfig?.root) ?? (isAbsolute(filePath) ? filePath : resolve(dirname(importer), filePath)));
23
48
  markStylePathSafe(options.resolvedConfig, resolved);
24
49
  return resolved + "?inline";
25
50
  }
@@ -1 +1 @@
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, type Plugin, type ResolvedConfig } from 'vite';\nimport {\n isAngularBuildContext,\n type AngularBuildContext,\n} from './angular-build-context.js';\nimport { markStylePathSafe } from './utils/safe-module-paths.js';\nimport { VIRTUAL_RAW_PREFIX, toVirtualRawId } from './utils/virtual-ids.js';\nimport {\n loadVirtualRawModule,\n rewriteHtmlRawImport,\n} from './utils/virtual-resources.js';\n\nexport interface VirtualModulesPluginOptions {\n jit?: boolean;\n}\n\nexport function resolveAngularVirtualId(\n id: string,\n importer: string | undefined,\n options: {\n jit: boolean;\n resolvedConfig?: ResolvedConfig;\n },\n): string | undefined {\n if (id.startsWith(VIRTUAL_RAW_PREFIX)) {\n return `\\0${id}`;\n }\n\n if (options.jit && id.startsWith('angular:jit:')) {\n const filePath = normalizePath(\n resolve(dirname(importer as string), id.split(';')[1]),\n );\n if (id.includes(':style')) {\n markStylePathSafe(options.resolvedConfig, filePath);\n return filePath + '?inline';\n }\n return toVirtualRawId(filePath);\n }\n\n // Intercept .html?raw imports to bypass Vite server.fs restrictions\n const rawRewrite = rewriteHtmlRawImport(id, importer);\n if (rawRewrite) {\n return rawRewrite;\n }\n\n // User `.scss?inline` / `.css?inline` imports: resolve and mark\n // safe so Vite's native CSS pipeline handles them.\n if (/\\.(css|scss|sass|less)\\?inline$/.test(id) && importer) {\n const filePath = id.split('?')[0];\n const resolved = isAbsolute(filePath)\n ? normalizePath(filePath)\n : normalizePath(resolve(dirname(importer), filePath));\n markStylePathSafe(options.resolvedConfig, resolved);\n return resolved + '?inline';\n }\n\n return undefined;\n}\n\nexport async function loadAngularVirtualModule(\n pluginCtx: { addWatchFile(path: string): void },\n id: string,\n resolvedConfig?: ResolvedConfig,\n): Promise<string | undefined> {\n const rawModule = await loadVirtualRawModule(pluginCtx, id);\n if (rawModule !== undefined) {\n return rawModule;\n }\n\n // Vitest fallback: the module-runner can skip resolveId, so the bare\n // ?inline query reaches load. Mark safe and let Vite handle it.\n if (/\\.(css|scss|sass|less)\\?inline$/.test(id)) {\n markStylePathSafe(resolvedConfig, id.split('?')[0]);\n }\n\n return undefined;\n}\n\nexport function virtualModulesPlugin(\n ctxOrOptions?: AngularBuildContext | VirtualModulesPluginOptions,\n): Plugin {\n const sharedCtx = isAngularBuildContext(ctxOrOptions)\n ? ctxOrOptions\n : undefined;\n const standaloneJit = isAngularBuildContext(ctxOrOptions)\n ? ctxOrOptions.options.jit\n : (ctxOrOptions?.jit ?? false);\n let localConfig: ResolvedConfig | undefined;\n\n return {\n name: '@analogjs/vite-plugin-angular:virtual-modules',\n enforce: 'pre',\n configResolved(config) {\n localConfig = config;\n sharedCtx?.setResolvedConfig(config);\n },\n resolveId(id, importer) {\n return resolveAngularVirtualId(id, importer, {\n jit: sharedCtx ? sharedCtx.options.jit : standaloneJit,\n resolvedConfig: sharedCtx?.resolvedConfig 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;GACrB,cAAc;GACd,WAAW,kBAAkB,MAAM;EACrC;EACA,UAAU,IAAI,UAAU;GACtB,OAAO,wBAAwB,IAAI,UAAU;IAC3C,KAAK,YAAY,UAAU,QAAQ,MAAM;IACzC,gBAAgB,WAAW,kBAAkB;GAC/C,CAAC;EACH;EACA,MAAM,KAAK,IAAI;GACb,OAAO,yBACL,MACA,IACA,WAAW,kBAAkB,WAC/B;EACF;CACF;AACF"}
1
+ {"version":3,"file":"virtual-modules-plugin.js","names":[],"sources":["../../../src/lib/virtual-modules-plugin.ts"],"sourcesContent":["import { statSync } from 'node:fs';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\nimport { normalizePath, type Plugin, type ResolvedConfig } from 'vite';\nimport {\n isAngularBuildContext,\n type AngularBuildContext,\n} from './angular-build-context.js';\nimport { markStylePathSafe } from './utils/safe-module-paths.js';\nimport { VIRTUAL_RAW_PREFIX, toVirtualRawId } from './utils/virtual-ids.js';\nimport {\n loadVirtualRawModule,\n rewriteHtmlRawImport,\n} from './utils/virtual-resources.js';\n\nexport interface VirtualModulesPluginOptions {\n jit?: boolean;\n}\n\nconst FS_PREFIX = '/@fs/';\n\nfunction isDirectory(path: string): boolean {\n return statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;\n}\n\n/**\n * The file a URL that Vite wrote into a module's code points at. Vitest\n * resolves the imports of a module restored from `fsModuleCache` by these\n * URLs, so they must resolve to the same file as the original import.\n * `/@fs/<path>` is that path. A root-relative URL (`/src/app/a.css`) is the\n * file under the Vite root when there is one; otherwise the caller reads it\n * as the path given, which is the order Vite tries the two in. A URL that\n * already starts with the root's path is root-relative only when the root\n * holds a directory at its own path (`/app/app`), as in Vite's resolver.\n */\nfunction resolveViteUrl(\n url: string,\n root: string | undefined,\n): string | undefined {\n if (url.startsWith(FS_PREFIX)) {\n const fsPath = url.slice(FS_PREFIX.length);\n // `/@fs/C:/a.css` on Windows, `/@fs/home/a.css` elsewhere.\n return /^[A-Z]:/i.test(fsPath) ? fsPath : `/${fsPath}`;\n }\n if (!root || !url.startsWith('/')) {\n return undefined;\n }\n if (url.startsWith(`${root}/`) && !isDirectory(join(root, root))) {\n return undefined;\n }\n const filePath = join(root, url);\n return statSync(filePath, { throwIfNoEntry: false })?.isFile()\n ? filePath\n : undefined;\n}\n\nexport function resolveAngularVirtualId(\n id: string,\n importer: string | undefined,\n options: {\n jit: boolean;\n resolvedConfig?: ResolvedConfig;\n },\n): string | undefined {\n if (id.startsWith(VIRTUAL_RAW_PREFIX)) {\n return `\\0${id}`;\n }\n\n if (options.jit && id.startsWith('angular:jit:')) {\n const filePath = normalizePath(\n resolve(dirname(importer as string), id.split(';')[1]),\n );\n if (id.includes(':style')) {\n markStylePathSafe(options.resolvedConfig, filePath);\n return filePath + '?inline';\n }\n return toVirtualRawId(filePath);\n }\n\n // Intercept .html?raw imports to bypass Vite server.fs restrictions\n const rawRewrite = rewriteHtmlRawImport(id, importer);\n if (rawRewrite) {\n return rawRewrite;\n }\n\n // User `.scss?inline` / `.css?inline` imports: resolve and mark\n // safe so Vite's native CSS pipeline handles them.\n if (/\\.(css|scss|sass|less)\\?inline$/.test(id) && importer) {\n const filePath = id.split('?')[0];\n const resolved = normalizePath(\n resolveViteUrl(filePath, options.resolvedConfig?.root) ??\n (isAbsolute(filePath)\n ? filePath\n : resolve(dirname(importer), filePath)),\n );\n markStylePathSafe(options.resolvedConfig, resolved);\n return resolved + '?inline';\n }\n\n return undefined;\n}\n\nexport async function loadAngularVirtualModule(\n pluginCtx: { addWatchFile(path: string): void },\n id: string,\n resolvedConfig?: ResolvedConfig,\n): Promise<string | undefined> {\n const rawModule = await loadVirtualRawModule(pluginCtx, id);\n if (rawModule !== undefined) {\n return rawModule;\n }\n\n // Vitest fallback: the module-runner can skip resolveId, so the bare\n // ?inline query reaches load. Mark safe and let Vite handle it.\n if (/\\.(css|scss|sass|less)\\?inline$/.test(id)) {\n markStylePathSafe(resolvedConfig, id.split('?')[0]);\n }\n\n return undefined;\n}\n\nexport function virtualModulesPlugin(\n ctxOrOptions?: AngularBuildContext | VirtualModulesPluginOptions,\n): Plugin {\n const sharedCtx = isAngularBuildContext(ctxOrOptions)\n ? ctxOrOptions\n : undefined;\n const standaloneJit = isAngularBuildContext(ctxOrOptions)\n ? ctxOrOptions.options.jit\n : (ctxOrOptions?.jit ?? false);\n let localConfig: ResolvedConfig | undefined;\n\n return {\n name: '@analogjs/vite-plugin-angular:virtual-modules',\n enforce: 'pre',\n configResolved(config) {\n localConfig = config;\n sharedCtx?.setResolvedConfig(config);\n },\n resolveId(id, importer) {\n return resolveAngularVirtualId(id, importer, {\n jit: sharedCtx ? sharedCtx.options.jit : standaloneJit,\n resolvedConfig: sharedCtx?.resolvedConfig ?? localConfig,\n });\n },\n async load(id) {\n return loadAngularVirtualModule(\n this,\n id,\n sharedCtx?.resolvedConfig ?? localConfig,\n );\n },\n };\n}\n"],"mappings":";;;;;;;;AAkBA,IAAM,YAAY;AAElB,SAAS,YAAY,MAAuB;CAC1C,OAAO,SAAS,MAAM,EAAE,gBAAgB,MAAM,CAAC,CAAC,EAAE,YAAY,KAAK;AACrE;;;;;;;;;;;AAYA,SAAS,eACP,KACA,MACoB;CACpB,IAAI,IAAI,WAAW,SAAS,GAAG;EAC7B,MAAM,SAAS,IAAI,MAAM,CAAgB;EAEzC,OAAO,WAAW,KAAK,MAAM,IAAI,SAAS,IAAI;CAChD;CACA,IAAI,CAAC,QAAQ,CAAC,IAAI,WAAW,GAAG,GAC9B;CAEF,IAAI,IAAI,WAAW,GAAG,KAAK,EAAE,KAAK,CAAC,YAAY,KAAK,MAAM,IAAI,CAAC,GAC7D;CAEF,MAAM,WAAW,KAAK,MAAM,GAAG;CAC/B,OAAO,SAAS,UAAU,EAAE,gBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,IACzD,WACA,KAAA;AACN;AAEA,SAAgB,wBACd,IACA,UACA,SAIoB;CACpB,IAAI,GAAG,WAAA,4CAA6B,GAClC,OAAO,KAAK;CAGd,I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