@analogjs/vite-plugin-angular 3.0.0-beta.47 → 3.0.0-beta.49

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.
@@ -0,0 +1,104 @@
1
+ import * as fs from "node:fs";
2
+ import { basename, dirname, join, posix } from "node:path";
3
+ import { normalizePath } from "vite";
4
+ //#region packages/vite-plugin-angular/src/lib/utils/ngp-host-fs.ts
5
+ var FILE = {
6
+ isFile: true,
7
+ isDir: false,
8
+ isSymlink: false
9
+ };
10
+ var NOT_FOUND_CODES = /* @__PURE__ */ new Set([
11
+ "ENOENT",
12
+ "ENOTDIR",
13
+ "ENAMETOOLONG",
14
+ "EINVAL"
15
+ ]);
16
+ function orNull(read) {
17
+ try {
18
+ return read();
19
+ } catch (error) {
20
+ if (NOT_FOUND_CODES.has(error.code ?? "")) return null;
21
+ throw error;
22
+ }
23
+ }
24
+ var canonicalDirs = /* @__PURE__ */ new Map();
25
+ /**
26
+ * `path`, normalized, with the symlinks of its directory resolved. Lowered
27
+ * modules are keyed by these paths, whichever path a file is reached by.
28
+ */
29
+ function canonicalPath(path) {
30
+ const normalized = normalizePath(path);
31
+ const dir = posix.dirname(normalized);
32
+ let real = canonicalDirs.get(dir);
33
+ if (real === void 0) {
34
+ real = orNull(() => normalizePath(fs.realpathSync(dir))) ?? dir;
35
+ canonicalDirs.set(dir, real);
36
+ }
37
+ return `${real}/${posix.basename(normalized)}`;
38
+ }
39
+ function toStat(stats) {
40
+ return {
41
+ isFile: stats.isFile(),
42
+ isDir: stats.isDirectory(),
43
+ isSymlink: stats.isSymbolicLink()
44
+ };
45
+ }
46
+ /**
47
+ * The disk, with each module of a source format served as a TypeScript file
48
+ * named after it (`x.tsrx` as `x.tsrx.ts`) and the module itself hidden, so an
49
+ * import of `./x.tsrx` resolves to its TypeScript.
50
+ *
51
+ * @param programCode The TypeScript of a module's program file, by the file's
52
+ * normalized, canonical path.
53
+ */
54
+ function createNgpHostFs(programCode) {
55
+ const programFile = (path) => programCode(canonicalPath(path));
56
+ const isHidden = (path) => programCode(`${canonicalPath(path)}.ts`) !== void 0;
57
+ const encoder = new TextEncoder();
58
+ return {
59
+ read(path) {
60
+ const code = programFile(path);
61
+ if (code !== void 0) return encoder.encode(code);
62
+ if (isHidden(path)) return null;
63
+ const buffer = orNull(() => fs.readFileSync(path));
64
+ return buffer && new Uint8Array(buffer);
65
+ },
66
+ metadata(path) {
67
+ if (programFile(path) !== void 0) return FILE;
68
+ if (isHidden(path)) return null;
69
+ const stats = orNull(() => fs.statSync(path));
70
+ return stats && toStat(stats);
71
+ },
72
+ symlinkMetadata(path) {
73
+ if (programFile(path) !== void 0) return FILE;
74
+ if (isHidden(path)) return null;
75
+ const stats = orNull(() => fs.lstatSync(path));
76
+ return stats && toStat(stats);
77
+ },
78
+ readLink(path) {
79
+ return orNull(() => fs.readlinkSync(path, "utf-8"));
80
+ },
81
+ canonicalize(path) {
82
+ if (programFile(path) !== void 0) {
83
+ const dir = orNull(() => fs.realpathSync(dirname(path)));
84
+ return dir && join(dir, basename(path));
85
+ }
86
+ if (isHidden(path)) return null;
87
+ return orNull(() => fs.realpathSync(path));
88
+ },
89
+ readDir(path) {
90
+ const entries = orNull(() => fs.readdirSync(path, { withFileTypes: true }));
91
+ return entries && entries.map((entry) => isHidden(join(path, entry.name)) ? {
92
+ ...FILE,
93
+ name: `${entry.name}.ts`
94
+ } : {
95
+ ...toStat(entry),
96
+ name: entry.name
97
+ });
98
+ }
99
+ };
100
+ }
101
+ //#endregion
102
+ export { canonicalPath, createNgpHostFs };
103
+
104
+ //# sourceMappingURL=ngp-host-fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngp-host-fs.js","names":[],"sources":["../../../../src/lib/utils/ngp-host-fs.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport { basename, dirname, join, posix } from 'node:path';\nimport { normalizePath } from 'vite';\n\ninterface HostStat {\n isFile: boolean;\n isDir: boolean;\n isSymlink: boolean;\n}\n\ninterface HostDirEntry extends HostStat {\n name: string;\n}\n\n/** The file system NGP's WebAssembly backend reads through (`hostFs`). */\nexport interface NgpHostFs {\n read(path: string): Uint8Array | null;\n metadata(path: string): HostStat | null;\n symlinkMetadata(path: string): HostStat | null;\n readLink(path: string): string | null;\n canonicalize(path: string): string | null;\n readDir(path: string): HostDirEntry[] | null;\n}\n\nconst FILE: HostStat = { isFile: true, isDir: false, isSymlink: false };\n\n// The errors NGP's own host treats as a missing file\nconst NOT_FOUND_CODES = new Set([\n 'ENOENT',\n 'ENOTDIR',\n 'ENAMETOOLONG',\n 'EINVAL',\n]);\n\nfunction orNull<T>(read: () => T): T | null {\n try {\n return read();\n } catch (error) {\n if (NOT_FOUND_CODES.has((error as NodeJS.ErrnoException).code ?? '')) {\n return null;\n }\n throw error;\n }\n}\n\nconst canonicalDirs = new Map<string, string>();\n\n/**\n * `path`, normalized, with the symlinks of its directory resolved. Lowered\n * modules are keyed by these paths, whichever path a file is reached by.\n */\nexport function canonicalPath(path: string): string {\n const normalized = normalizePath(path);\n const dir = posix.dirname(normalized);\n let real = canonicalDirs.get(dir);\n if (real === undefined) {\n real = orNull(() => normalizePath(fs.realpathSync(dir))) ?? dir;\n canonicalDirs.set(dir, real);\n }\n return `${real}/${posix.basename(normalized)}`;\n}\n\nfunction toStat(\n stats: Pick<fs.Stats, 'isFile' | 'isDirectory' | 'isSymbolicLink'>,\n): HostStat {\n return {\n isFile: stats.isFile(),\n isDir: stats.isDirectory(),\n isSymlink: stats.isSymbolicLink(),\n };\n}\n\n/**\n * The disk, with each module of a source format served as a TypeScript file\n * named after it (`x.tsrx` as `x.tsrx.ts`) and the module itself hidden, so an\n * import of `./x.tsrx` resolves to its TypeScript.\n *\n * @param programCode The TypeScript of a module's program file, by the file's\n * normalized, canonical path.\n */\nexport function createNgpHostFs(\n programCode: (path: string) => string | undefined,\n): NgpHostFs {\n const programFile = (path: string) => programCode(canonicalPath(path));\n const isHidden = (path: string) =>\n programCode(`${canonicalPath(path)}.ts`) !== undefined;\n const encoder = new TextEncoder();\n\n return {\n read(path) {\n const code = programFile(path);\n if (code !== undefined) return encoder.encode(code);\n if (isHidden(path)) return null;\n const buffer = orNull(() => fs.readFileSync(path));\n return buffer && new Uint8Array(buffer);\n },\n metadata(path) {\n if (programFile(path) !== undefined) return FILE;\n if (isHidden(path)) return null;\n const stats = orNull(() => fs.statSync(path));\n return stats && toStat(stats);\n },\n symlinkMetadata(path) {\n if (programFile(path) !== undefined) return FILE;\n if (isHidden(path)) return null;\n const stats = orNull(() => fs.lstatSync(path));\n return stats && toStat(stats);\n },\n readLink(path) {\n return orNull(() => fs.readlinkSync(path, 'utf-8'));\n },\n canonicalize(path) {\n if (programFile(path) !== undefined) {\n const dir = orNull(() => fs.realpathSync(dirname(path)));\n return dir && join(dir, basename(path));\n }\n if (isHidden(path)) return null;\n return orNull(() => fs.realpathSync(path));\n },\n readDir(path) {\n const entries = orNull(() =>\n fs.readdirSync(path, { withFileTypes: true }),\n );\n return (\n entries &&\n entries.map((entry) =>\n isHidden(join(path, entry.name))\n ? { ...FILE, name: `${entry.name}.ts` }\n : { ...toStat(entry), name: entry.name },\n )\n );\n },\n };\n}\n"],"mappings":";;;;AAwBA,IAAM,OAAiB;CAAE,QAAQ;CAAM,OAAO;CAAO,WAAW;AAAM;AAGtE,IAAM,kCAAkB,IAAI,IAAI;CAC9B;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,OAAU,MAAyB;CAC1C,IAAI;EACF,OAAO,KAAK;CACd,SAAS,OAAO;EACd,IAAI,gBAAgB,IAAK,MAAgC,QAAQ,EAAE,GACjE,OAAO;EAET,MAAM;CACR;AACF;AAEA,IAAM,gCAAgB,IAAI,IAAoB;;;;;AAM9C,SAAgB,cAAc,MAAsB;CAClD,MAAM,aAAa,cAAc,IAAI;CACrC,MAAM,MAAM,MAAM,QAAQ,UAAU;CACpC,IAAI,OAAO,cAAc,IAAI,GAAG;CAChC,IAAI,SAAS,KAAA,GAAW;E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