@analogjs/vite-plugin-angular 3.0.0-beta.5 → 3.0.0-beta.50
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/migrations/migrate-setup-vitest/migrate-setup-vitest.js +2 -1
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
- package/ngp/LICENSE +21 -0
- package/ngp/api.mjs +46806 -0
- package/ngp/build.json +4 -0
- package/ngp/ng_analyze.cjs +601 -0
- package/ngp/ng_analyze_bg.wasm +0 -0
- package/package.json +4 -1
- package/src/index.d.ts +2 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
- package/src/lib/analog-plugin-interop.js +1 -1
- package/src/lib/angular-build-context.d.ts +215 -0
- package/src/lib/angular-build-context.js +361 -0
- package/src/lib/angular-build-context.js.map +1 -0
- package/src/lib/angular-build-optimizer-plugin.d.ts +6 -4
- package/src/lib/angular-build-optimizer-plugin.js +24 -9
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.d.ts +5 -3
- package/src/lib/angular-jit-plugin.js +14 -6
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +6 -109
- package/src/lib/angular-vite-plugin.js +8 -1249
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +3 -2
- package/src/lib/angular-vitest-plugin.js +6 -3
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/companion-plugins.d.ts +7 -0
- package/src/lib/companion-plugins.js +38 -0
- package/src/lib/companion-plugins.js.map +1 -0
- package/src/lib/compilation-api/compilation-api-plugin.d.ts +11 -2
- package/src/lib/compilation-api/compilation-api-plugin.js +154 -282
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
- package/src/lib/compiler/compile.d.ts +1 -1
- package/src/lib/compiler/compile.js +190 -145
- package/src/lib/compiler/compile.js.map +1 -1
- package/src/lib/compiler/defer.d.ts +2 -3
- package/src/lib/compiler/defer.js +12 -14
- package/src/lib/compiler/defer.js.map +1 -1
- package/src/lib/compiler/dts-reader.d.ts +6 -1
- package/src/lib/compiler/dts-reader.js +19 -10
- package/src/lib/compiler/dts-reader.js.map +1 -1
- package/src/lib/compiler/hmr.d.ts +4 -0
- package/src/lib/compiler/hmr.js +7 -2
- package/src/lib/compiler/hmr.js.map +1 -1
- package/src/lib/compiler/index.d.ts +2 -2
- package/src/lib/compiler/index.js +4 -4
- package/src/lib/compiler/jit-metadata.d.ts +3 -1
- package/src/lib/compiler/jit-metadata.js +10 -8
- package/src/lib/compiler/jit-metadata.js.map +1 -1
- package/src/lib/compiler/jit-transform.js +2 -2
- package/src/lib/compiler/jit-transform.js.map +1 -1
- package/src/lib/compiler/js-emitter.d.ts +0 -3
- package/src/lib/compiler/js-emitter.js +3 -21
- package/src/lib/compiler/js-emitter.js.map +1 -1
- package/src/lib/compiler/registry.d.ts +7 -1
- package/src/lib/compiler/registry.js +23 -3
- package/src/lib/compiler/registry.js.map +1 -1
- package/src/lib/compiler/resource-inliner.d.ts +8 -9
- package/src/lib/compiler/resource-inliner.js +10 -18
- package/src/lib/compiler/resource-inliner.js.map +1 -1
- package/src/lib/compiler/style-ast.d.ts +9 -1
- package/src/lib/compiler/style-ast.js +26 -5
- package/src/lib/compiler/style-ast.js.map +1 -1
- package/src/lib/compiler/type-elision.d.ts +4 -3
- package/src/lib/compiler/type-elision.js +10 -11
- package/src/lib/compiler/type-elision.js.map +1 -1
- package/src/lib/compiler/utils.d.ts +9 -7
- package/src/lib/compiler/utils.js +49 -9
- package/src/lib/compiler/utils.js.map +1 -1
- package/src/lib/component-scanner.d.ts +74 -0
- package/src/lib/component-scanner.js +178 -0
- package/src/lib/component-scanner.js.map +1 -0
- package/src/lib/component-styles-plugin.d.ts +52 -0
- package/src/lib/component-styles-plugin.js +353 -0
- package/src/lib/component-styles-plugin.js.map +1 -0
- package/src/lib/compose-angular-plugins.d.ts +12 -0
- package/src/lib/compose-angular-plugins.js +31 -0
- package/src/lib/compose-angular-plugins.js.map +1 -0
- package/src/lib/dev-server-mode-plugin.d.ts +7 -0
- package/src/lib/dev-server-mode-plugin.js +23 -0
- package/src/lib/dev-server-mode-plugin.js.map +1 -0
- package/src/lib/fast-compile-api.d.ts +62 -0
- package/src/lib/fast-compile-api.js +12 -0
- package/src/lib/fast-compile-api.js.map +1 -0
- package/src/lib/fast-compile-plugin.d.ts +6 -1
- package/src/lib/fast-compile-plugin.js +167 -107
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/host.d.ts +3 -0
- package/src/lib/host.js +4 -2
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.d.ts +6 -3
- package/src/lib/live-reload-plugin.js +13 -6
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/ngp-compile-api.d.ts +55 -0
- package/src/lib/ngp-compile-api.js +12 -0
- package/src/lib/ngp-compile-api.js.map +1 -0
- package/src/lib/ngp-compile-plugin.d.ts +4 -0
- package/src/lib/ngp-compile-plugin.js +662 -0
- package/src/lib/ngp-compile-plugin.js.map +1 -0
- package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
- package/src/lib/ngtsc-compile-plugin.js +778 -0
- package/src/lib/ngtsc-compile-plugin.js.map +1 -0
- package/src/lib/nx-folder-plugin.d.ts +6 -5
- package/src/lib/nx-folder-plugin.js +12 -7
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
- package/src/lib/plugins/file-replacements.plugin.js +1 -0
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +5 -1
- package/src/lib/router-plugin.js +13 -4
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/utils/compilation-shared.js +1 -1
- package/src/lib/utils/devkit.js +1 -1
- package/src/lib/utils/hmr-component-updates.d.ts +7 -0
- package/src/lib/utils/hmr-component-updates.js +87 -0
- package/src/lib/utils/hmr-component-updates.js.map +1 -0
- package/src/lib/utils/lsp-type-checker.d.ts +75 -0
- package/src/lib/utils/lsp-type-checker.js +531 -0
- package/src/lib/utils/lsp-type-checker.js.map +1 -0
- package/src/lib/utils/ngp-host-fs.d.ts +32 -0
- package/src/lib/utils/ngp-host-fs.js +104 -0
- package/src/lib/utils/ngp-host-fs.js.map +1 -0
- package/src/lib/utils/plugin-config.d.ts +15 -8
- package/src/lib/utils/plugin-config.js +18 -5
- package/src/lib/utils/plugin-config.js.map +1 -1
- package/src/lib/utils/stylesheet-warning.d.ts +2 -0
- package/src/lib/utils/stylesheet-warning.js +11 -0
- package/src/lib/utils/stylesheet-warning.js.map +1 -0
- package/src/lib/utils/tsconfig-resolver.js +1 -1
- package/src/lib/virtual-modules-plugin.d.ts +11 -3
- package/src/lib/virtual-modules-plugin.js +43 -12
- package/src/lib/virtual-modules-plugin.js.map +1 -1
|
@@ -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;EACtB,OAAO,aAAa,cAAc,G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,CAAC,CAAC;IACvD,OAAO,OAAO,KAAK,KAAK,SAAS,IAAI,CAAC;GACxC;GACA,IAAI,SAAS,IAAI,GAAG,OAAO;GAC3B,OAAO,aAAa,GAAG,aAAa,IAAI,CAAC;EAC3C;EACA,QAAQ,MAAM;GACZ,MAAM,UAAU,aACd,GAAG,YAAY,MAAM,EAAE,eAAe,KAAK,CAAC,CAC9C;GACA,OACE,WACA,QAAQ,KAAK,UACX,SAAS,KAAK,MAAM,MAAM,IAAI,CAAC,IAC3B;IAAE,GAAG;IAAM,MAAM,GAAG,MAAM,KAAK;GAAK,IACpC;IAAE,GAAG,OAAO,KAAK;IAAG,MAAM,MAAM;GAAK,CAC3C;EAEJ;CACF;AACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as vite from "vite";
|
|
1
2
|
/**
|
|
2
3
|
* TypeScript file extension regex
|
|
3
4
|
* Match .ts / .cts / .mts extensions with an optional ?query suffix.
|
|
@@ -10,8 +11,8 @@
|
|
|
10
11
|
* zero characters, and any non-`x` letter was admitted — so `.tsrx`
|
|
11
12
|
* and similar extensions matched by accident.
|
|
12
13
|
*/
|
|
13
|
-
export declare const TS_EXT_REGEX:
|
|
14
|
-
export declare const EXCLUDED_TS_EXT_REGEX:
|
|
14
|
+
export declare const TS_EXT_REGEX: RegExp;
|
|
15
|
+
export declare const EXCLUDED_TS_EXT_REGEX: RegExp;
|
|
15
16
|
/**
|
|
16
17
|
* Resolves whether Angular should be compiled for production. An explicit
|
|
17
18
|
* `development` mode wins over an ambient production `NODE_ENV` (e.g. set by
|
|
@@ -19,13 +20,22 @@ export declare const EXCLUDED_TS_EXT_REGEX: unknown;
|
|
|
19
20
|
* development compilation. See #2458 and #2462.
|
|
20
21
|
*/
|
|
21
22
|
export declare function isProdMode(mode: string | undefined): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether a Vite environment runs on the server. `configEnvironment` sees the
|
|
25
|
+
* environment's options before Vite resolves them, so an unset `consumer`
|
|
26
|
+
* falls back to Vite's own default: every environment except `client` is a
|
|
27
|
+
* server environment.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isServerEnvironment(name: string, config: {
|
|
30
|
+
consumer?: string;
|
|
31
|
+
}): boolean;
|
|
22
32
|
export interface TsConfigResolutionContext {
|
|
23
33
|
root: string;
|
|
24
34
|
isProd: boolean;
|
|
25
35
|
isLib: boolean;
|
|
26
36
|
}
|
|
27
|
-
export declare function getTsConfigPath(root: string, tsconfig: string, isProd: boolean, isTest: boolean, isLib: boolean, workspaceRoot?: string);
|
|
28
|
-
export declare function createTsConfigGetter(tsconfigOrGetter?: string | (() => string));
|
|
37
|
+
export declare function getTsConfigPath(root: string, tsconfig: string, isProd: boolean, isTest: boolean, isLib: boolean, workspaceRoot?: string): string;
|
|
38
|
+
export declare function createTsConfigGetter(tsconfigOrGetter?: string | (() => string)): () => string;
|
|
29
39
|
export interface DepOptimizerOptions {
|
|
30
40
|
tsconfig: string;
|
|
31
41
|
isProd: boolean;
|
|
@@ -35,8 +45,5 @@ export interface DepOptimizerOptions {
|
|
|
35
45
|
isAstroIntegration: boolean;
|
|
36
46
|
}
|
|
37
47
|
export declare function createDepOptimizerConfig(opts: DepOptimizerOptions): {
|
|
38
|
-
optimizeDeps:
|
|
39
|
-
include: unknown;
|
|
40
|
-
exclude: unknown;
|
|
41
|
-
};
|
|
48
|
+
optimizeDeps: vite.DepOptimizationOptions;
|
|
42
49
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createCompilerPlugin, createRolldownCompilerPlugin } from "../compiler-plugin.js";
|
|
2
|
+
import { isRolldown } from "./rolldown.js";
|
|
2
3
|
import { createPersistentTransformCache, resolveTransformCacheDir } from "./transform-cache.js";
|
|
3
4
|
import { existsSync } from "node:fs";
|
|
4
5
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
5
|
-
import * as vite from "vite";
|
|
6
6
|
//#region packages/vite-plugin-angular/src/lib/utils/plugin-config.ts
|
|
7
7
|
/**
|
|
8
8
|
* TypeScript file extension regex
|
|
@@ -28,6 +28,15 @@ function isProdMode(mode) {
|
|
|
28
28
|
if (mode === "development") return false;
|
|
29
29
|
return mode === "production" || process.env.NODE_ENV === "production";
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether a Vite environment runs on the server. `configEnvironment` sees the
|
|
33
|
+
* environment's options before Vite resolves them, so an unset `consumer`
|
|
34
|
+
* falls back to Vite's own default: every environment except `client` is a
|
|
35
|
+
* server environment.
|
|
36
|
+
*/
|
|
37
|
+
function isServerEnvironment(name, config) {
|
|
38
|
+
return (config.consumer ?? (name === "client" ? "client" : "server")) === "server";
|
|
39
|
+
}
|
|
31
40
|
function getTsConfigPath(root, tsconfig, isProd, isTest, isLib, workspaceRoot) {
|
|
32
41
|
if (tsconfig && isAbsolute(tsconfig)) {
|
|
33
42
|
if (!existsSync(tsconfig)) console.error(`[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${tsconfig}. This causes compilation issues. Check the path or set the "tsconfig" property with an absolute path.`);
|
|
@@ -51,7 +60,7 @@ function createTsConfigGetter(tsconfigOrGetter) {
|
|
|
51
60
|
}
|
|
52
61
|
function createDepOptimizerConfig(opts) {
|
|
53
62
|
const defineOptions = {
|
|
54
|
-
ngJitMode: "false",
|
|
63
|
+
...opts.jit ? {} : { ngJitMode: "false" },
|
|
55
64
|
ngI18nClosureMode: "false",
|
|
56
65
|
...opts.watchMode ? {} : { ngDevMode: "false" }
|
|
57
66
|
};
|
|
@@ -75,12 +84,16 @@ function createDepOptimizerConfig(opts) {
|
|
|
75
84
|
define: defineOptions
|
|
76
85
|
};
|
|
77
86
|
return { optimizeDeps: {
|
|
78
|
-
include: [
|
|
87
|
+
include: [
|
|
88
|
+
"rxjs/operators",
|
|
89
|
+
"rxjs",
|
|
90
|
+
"tslib"
|
|
91
|
+
],
|
|
79
92
|
exclude: ["@angular/platform-server"],
|
|
80
|
-
...
|
|
93
|
+
...isRolldown() ? { rolldownOptions } : { esbuildOptions }
|
|
81
94
|
} };
|
|
82
95
|
}
|
|
83
96
|
//#endregion
|
|
84
|
-
export { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX, createDepOptimizerConfig, createTsConfigGetter, getTsConfigPath, isProdMode };
|
|
97
|
+
export { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX, createDepOptimizerConfig, createTsConfigGetter, getTsConfigPath, isProdMode, isServerEnvironment };
|
|
85
98
|
|
|
86
99
|
//# sourceMappingURL=plugin-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-config.js","names":[],"sources":["../../../../src/lib/utils/plugin-config.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, isAbsolute, resolve } from 'node:path';\nimport * as vite from 'vite';\n\nimport {\n createCompilerPlugin,\n createRolldownCompilerPlugin,\n} from '../compiler-plugin.js';\nimport {\n createPersistentTransformCache,\n resolveTransformCacheDir,\n} from './transform-cache.js';\n\n/**\n * TypeScript file extension regex\n * Match .ts / .cts / .mts extensions with an optional ?query suffix.\n * Reject .tsx — and any other `.ts<letter>…` extension like .tsrx — via\n * a negative-lookahead on a following ASCII letter, so only genuine TS\n * files pass.\n *\n * Previous form `/\\.[cm]?(ts)[^x]?\\??/` was intended to exclude `.tsx`\n * specifically (`[^x]?` = not-an-x), but the `?` quantifier also allows\n * zero characters, and any non-`x` letter was admitted — so `.tsrx`\n * and similar extensions matched by accident.\n */\nexport const TS_EXT_REGEX = /\\.[cm]?ts(?![a-z])/;\n\n// Spec files stay included — a newly added spec must join the program's\n// root names in Vitest watch mode.\nexport const EXCLUDED_TS_EXT_REGEX = /\\.d\\.[cm]?ts$/;\n\n/**\n * Resolves whether Angular should be compiled for production. An explicit\n * `development` mode wins over an ambient production `NODE_ENV` (e.g. set by\n * `storybook build` at CLI entry), so a build can opt into Angular's\n * development compilation. See #2458 and #2462.\n */\nexport function isProdMode(mode: string | undefined): boolean {\n if (mode === 'development') {\n return false;\n }\n\n return mode === 'production' || process.env['NODE_ENV'] === 'production';\n}\n\nexport interface TsConfigResolutionContext {\n root: string;\n isProd: boolean;\n isLib: boolean;\n}\n\nexport function getTsConfigPath(\n root: string,\n tsconfig: string,\n isProd: boolean,\n isTest: boolean,\n isLib: boolean,\n workspaceRoot?: string,\n) {\n if (tsconfig && isAbsolute(tsconfig)) {\n if (!existsSync(tsconfig)) {\n console.error(\n `[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${tsconfig}. This causes compilation issues. Check the path or set the \"tsconfig\" property with an absolute path.`,\n );\n }\n\n return tsconfig;\n }\n\n let tsconfigFilePath = './tsconfig.app.json';\n\n if (isLib) {\n tsconfigFilePath = isProd\n ? './tsconfig.lib.prod.json'\n : './tsconfig.lib.json';\n }\n\n if (isTest) {\n tsconfigFilePath = './tsconfig.spec.json';\n }\n\n if (tsconfig) {\n tsconfigFilePath = tsconfig;\n }\n\n const resolvedPath = resolve(root, tsconfigFilePath);\n\n if (existsSync(resolvedPath)) {\n return resolvedPath;\n }\n\n // Callers such as Storybook's Angular builder document their `tsConfig` as\n // workspace-relative while setting the Vite root to the project directory,\n // so the path joins onto the project root twice. Fall back to the workspace\n // root before failing.\n const workspacePath = workspaceRoot\n ? resolve(workspaceRoot, tsconfigFilePath)\n : undefined;\n\n if (workspacePath && existsSync(workspacePath)) {\n return workspacePath;\n }\n\n const attemptedPaths =\n workspacePath && workspacePath !== resolvedPath\n ? `${resolvedPath} or ${workspacePath}`\n : resolvedPath;\n\n console.error(\n `[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${attemptedPaths}. This causes compilation issues. Check the path or set the \"tsconfig\" property with an absolute path.`,\n );\n\n return resolvedPath;\n}\n\nexport function createTsConfigGetter(\n tsconfigOrGetter?: string | (() => string),\n) {\n if (typeof tsconfigOrGetter === 'function') {\n return tsconfigOrGetter;\n }\n\n return () => tsconfigOrGetter || '';\n}\n\nexport interface DepOptimizerOptions {\n tsconfig: string;\n isProd: boolean;\n jit: boolean;\n watchMode: boolean;\n isTest: boolean;\n isAstroIntegration: boolean;\n}\n\nexport function createDepOptimizerConfig(opts: DepOptimizerOptions) {\n const defineOptions = {\n ngJitMode: 'false',\n ngI18nClosureMode: 'false',\n ...(opts.watchMode ? {} : { ngDevMode: 'false' }),\n };\n\n // Persist linked dependency output across dep-optimizer runs. The\n // transformer's own key covers file bytes + options, and the directory\n // is namespaced by Angular version, so entries never go stale.\n const transformCacheDir = resolveTransformCacheDir(dirname(opts.tsconfig));\n const transformCache = transformCacheDir\n ? createPersistentTransformCache(transformCacheDir)\n : undefined;\n\n const rolldownOptions: vite.DepOptimizationOptions['rolldownOptions'] = {\n plugins: [\n createRolldownCompilerPlugin(\n {\n tsconfig: opts.tsconfig,\n sourcemap: !opts.isProd,\n advancedOptimizations: opts.isProd,\n jit: opts.jit,\n incremental: opts.watchMode,\n },\n opts.isTest,\n !opts.isAstroIntegration,\n transformCache,\n ),\n ],\n };\n\n const esbuildOptions: vite.DepOptimizationOptions['esbuildOptions'] = {\n plugins: [\n createCompilerPlugin(\n {\n tsconfig: opts.tsconfig,\n sourcemap: !opts.isProd,\n advancedOptimizations: opts.isProd,\n jit: opts.jit,\n incremental: opts.watchMode,\n },\n opts.isTest,\n !opts.isAstroIntegration,\n transformCache,\n ),\n ],\n define: defineOptions,\n };\n\n // No top-level `resolve` block: the `style` package-export condition\n // is now scoped to `.css`-extension requests via\n // `cssExtensionStyleResolverPlugin`, so this dep optimizer config no\n // longer needs to leak it into Vite's global `resolve.conditions`.\n return {\n optimizeDeps: {\n include: ['rxjs/operators', 'rxjs'],\n exclude: ['@angular/platform-server'],\n ...(
|
|
1
|
+
{"version":3,"file":"plugin-config.js","names":[],"sources":["../../../../src/lib/utils/plugin-config.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, isAbsolute, resolve } from 'node:path';\nimport * as vite from 'vite';\n\nimport {\n createCompilerPlugin,\n createRolldownCompilerPlugin,\n} from '../compiler-plugin.js';\nimport { isRolldown } from './rolldown.js';\nimport {\n createPersistentTransformCache,\n resolveTransformCacheDir,\n} from './transform-cache.js';\n\n/**\n * TypeScript file extension regex\n * Match .ts / .cts / .mts extensions with an optional ?query suffix.\n * Reject .tsx — and any other `.ts<letter>…` extension like .tsrx — via\n * a negative-lookahead on a following ASCII letter, so only genuine TS\n * files pass.\n *\n * Previous form `/\\.[cm]?(ts)[^x]?\\??/` was intended to exclude `.tsx`\n * specifically (`[^x]?` = not-an-x), but the `?` quantifier also allows\n * zero characters, and any non-`x` letter was admitted — so `.tsrx`\n * and similar extensions matched by accident.\n */\nexport const TS_EXT_REGEX: RegExp = /\\.[cm]?ts(?![a-z])/;\n\n// Spec files stay included — a newly added spec must join the program's\n// root names in Vitest watch mode.\nexport const EXCLUDED_TS_EXT_REGEX: RegExp = /\\.d\\.[cm]?ts$/;\n\n/**\n * Resolves whether Angular should be compiled for production. An explicit\n * `development` mode wins over an ambient production `NODE_ENV` (e.g. set by\n * `storybook build` at CLI entry), so a build can opt into Angular's\n * development compilation. See #2458 and #2462.\n */\nexport function isProdMode(mode: string | undefined): boolean {\n if (mode === 'development') {\n return false;\n }\n\n return mode === 'production' || process.env['NODE_ENV'] === 'production';\n}\n\n/**\n * Whether a Vite environment runs on the server. `configEnvironment` sees the\n * environment's options before Vite resolves them, so an unset `consumer`\n * falls back to Vite's own default: every environment except `client` is a\n * server environment.\n */\nexport function isServerEnvironment(\n name: string,\n config: { consumer?: string },\n): boolean {\n return (\n (config.consumer ?? (name === 'client' ? 'client' : 'server')) === 'server'\n );\n}\n\nexport interface TsConfigResolutionContext {\n root: string;\n isProd: boolean;\n isLib: boolean;\n}\n\nexport function getTsConfigPath(\n root: string,\n tsconfig: string,\n isProd: boolean,\n isTest: boolean,\n isLib: boolean,\n workspaceRoot?: string,\n): string {\n if (tsconfig && isAbsolute(tsconfig)) {\n if (!existsSync(tsconfig)) {\n console.error(\n `[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${tsconfig}. This causes compilation issues. Check the path or set the \"tsconfig\" property with an absolute path.`,\n );\n }\n\n return tsconfig;\n }\n\n let tsconfigFilePath = './tsconfig.app.json';\n\n if (isLib) {\n tsconfigFilePath = isProd\n ? './tsconfig.lib.prod.json'\n : './tsconfig.lib.json';\n }\n\n if (isTest) {\n tsconfigFilePath = './tsconfig.spec.json';\n }\n\n if (tsconfig) {\n tsconfigFilePath = tsconfig;\n }\n\n const resolvedPath = resolve(root, tsconfigFilePath);\n\n if (existsSync(resolvedPath)) {\n return resolvedPath;\n }\n\n // Callers such as Storybook's Angular builder document their `tsConfig` as\n // workspace-relative while setting the Vite root to the project directory,\n // so the path joins onto the project root twice. Fall back to the workspace\n // root before failing.\n const workspacePath = workspaceRoot\n ? resolve(workspaceRoot, tsconfigFilePath)\n : undefined;\n\n if (workspacePath && existsSync(workspacePath)) {\n return workspacePath;\n }\n\n const attemptedPaths =\n workspacePath && workspacePath !== resolvedPath\n ? `${resolvedPath} or ${workspacePath}`\n : resolvedPath;\n\n console.error(\n `[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${attemptedPaths}. This causes compilation issues. Check the path or set the \"tsconfig\" property with an absolute path.`,\n );\n\n return resolvedPath;\n}\n\nexport function createTsConfigGetter(\n tsconfigOrGetter?: string | (() => string),\n): () => string {\n if (typeof tsconfigOrGetter === 'function') {\n return tsconfigOrGetter;\n }\n\n return () => tsconfigOrGetter || '';\n}\n\nexport interface DepOptimizerOptions {\n tsconfig: string;\n isProd: boolean;\n jit: boolean;\n watchMode: boolean;\n isTest: boolean;\n isAstroIntegration: boolean;\n}\n\nexport function createDepOptimizerConfig(opts: DepOptimizerOptions): {\n optimizeDeps: vite.DepOptimizationOptions;\n} {\n const defineOptions = {\n ...(opts.jit ? {} : { ngJitMode: 'false' }),\n ngI18nClosureMode: 'false',\n ...(opts.watchMode ? {} : { ngDevMode: 'false' }),\n };\n\n // Persist linked dependency output across dep-optimizer runs. The\n // transformer's own key covers file bytes + options, and the directory\n // is namespaced by Angular version, so entries never go stale.\n const transformCacheDir = resolveTransformCacheDir(dirname(opts.tsconfig));\n const transformCache = transformCacheDir\n ? createPersistentTransformCache(transformCacheDir)\n : undefined;\n\n const rolldownOptions: vite.DepOptimizationOptions['rolldownOptions'] = {\n plugins: [\n createRolldownCompilerPlugin(\n {\n tsconfig: opts.tsconfig,\n sourcemap: !opts.isProd,\n advancedOptimizations: opts.isProd,\n jit: opts.jit,\n incremental: opts.watchMode,\n },\n opts.isTest,\n !opts.isAstroIntegration,\n transformCache,\n ),\n ],\n };\n\n const esbuildOptions: vite.DepOptimizationOptions['esbuildOptions'] = {\n plugins: [\n createCompilerPlugin(\n {\n tsconfig: opts.tsconfig,\n sourcemap: !opts.isProd,\n advancedOptimizations: opts.isProd,\n jit: opts.jit,\n incremental: opts.watchMode,\n },\n opts.isTest,\n !opts.isAstroIntegration,\n transformCache,\n ),\n ],\n define: defineOptions,\n };\n\n // No top-level `resolve` block: the `style` package-export condition\n // is now scoped to `.css`-extension requests via\n // `cssExtensionStyleResolverPlugin`, so this dep optimizer config no\n // longer needs to leak it into Vite's global `resolve.conditions`.\n return {\n optimizeDeps: {\n include: ['rxjs/operators', 'rxjs', 'tslib'],\n exclude: ['@angular/platform-server'],\n ...(isRolldown() ? { rolldownOptions } : { esbuildOptions }),\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0BA,IAAa,eAAuB;AAIpC,IAAa,wBAAgC;;;;;;;AAQ7C,SAAgB,WAAW,MAAmC;CAC5D,IAAI,SAAS,eACX,OAAO;CAGT,OAAO,SAAS,gBAAA,QAAA,IAAA,aAA4C;AAC9D;;;;;;;AAQA,SAAgB,oBACd,MACA,QACS;CACT,QACG,OAAO,aAAa,SAAS,WAAW,WAAW,eAAe;AAEvE;AAQA,SAAgB,gBACd,MACA,UACA,QACA,QACA,OACA,eACQ;CACR,IAAI,YAAY,WAAW,QAAQ,GAAG;EACpC,IAAI,CAAC,WAAW,QAAQ,GACtB,QAAQ,MACN,kEAAkE,S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;CAMA,OAAO,EACL,cAAc;EACZ,SAAS;GAAC;GAAkB;GAAQ;EAAO;EAC3C,SAAS,CAAC,0BAA0B;EACpC,GAAI,WAAW,IAAI,EAAE,gBAAgB,IAAI,EAAE,eAAe;CAC5D,EACF;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region packages/vite-plugin-angular/src/lib/utils/stylesheet-warning.ts
|
|
2
|
+
function reportStylesheetError(logger, filename, error, isBuild) {
|
|
3
|
+
const message = `[@analogjs/vite-plugin-angular] Failed to process stylesheet ${filename}`;
|
|
4
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
5
|
+
if (isBuild) throw new Error(`${message}. ${detail}`, { cause: error });
|
|
6
|
+
logger?.warn(`${message}; it was left unprocessed. ${detail}`, { timestamp: true });
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { reportStylesheetError };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=stylesheet-warning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stylesheet-warning.js","names":[],"sources":["../../../../src/lib/utils/stylesheet-warning.ts"],"sourcesContent":["import type { Logger } from 'vite';\n\nexport function reportStylesheetError(\n logger: Logger | undefined,\n filename: string,\n error: unknown,\n isBuild: boolean,\n): void {\n const message = `[@analogjs/vite-plugin-angular] Failed to process stylesheet ${filename}`;\n const detail = error instanceof Error ? error.message : String(error);\n if (isBuild) {\n throw new Error(`${message}. ${detail}`, { cause: error });\n }\n logger?.warn(`${message}; it was left unprocessed. ${detail}`, {\n timestamp: true,\n });\n}\n"],"mappings":";AAEA,SAAgB,sBACd,QACA,UACA,OACA,SACM;CACN,MAAM,UAAU,gEAAgE;CAChF,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CACpE,IAAI,SACF,MAAM,IAAI,MAAM,GAAG,QAAQ,IAAI,UAAU,EAAE,OAAO,MAAM,CAAC;CAE3D,QAAQ,KAAK,GAAG,QAAQ,6BAA6B,UAAU,EAC7D,WAAW,KACb,CAAC;AACH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { debugEmit, debugEmitV } from "./debug.js";
|
|
2
2
|
import { existsSync, statSync } from "node:fs";
|
|
3
|
-
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
3
|
import { createRequire } from "node:module";
|
|
4
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
6
|
import * as compilerCli from "@angular/compiler-cli";
|
|
7
7
|
import { globSync } from "tinyglobby";
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { Plugin } from "vite";
|
|
1
|
+
import { type Plugin, type ResolvedConfig } from "vite";
|
|
2
|
+
import { type AngularBuildContext } from "./angular-build-context.js";
|
|
2
3
|
export interface VirtualModulesPluginOptions {
|
|
3
|
-
jit
|
|
4
|
+
jit?: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare function
|
|
6
|
+
export declare function resolveAngularVirtualId(id: string, importer: string | undefined, options: {
|
|
7
|
+
jit: boolean;
|
|
8
|
+
resolvedConfig?: ResolvedConfig;
|
|
9
|
+
}): string | undefined;
|
|
10
|
+
export declare function loadAngularVirtualModule(pluginCtx: {
|
|
11
|
+
addWatchFile(path: string): void;
|
|
12
|
+
}, id: string, resolvedConfig?: ResolvedConfig): Promise<string | undefined>;
|
|
13
|
+
export declare function virtualModulesPlugin(ctxOrOptions?: AngularBuildContext | VirtualModulesPluginOptions): Plugin;
|
|
@@ -1,26 +1,57 @@
|
|
|
1
|
+
import { isAngularBuildContext } from "./angular-build-context.js";
|
|
2
|
+
import { markStylePathSafe } from "./utils/safe-module-paths.js";
|
|
1
3
|
import { toVirtualRawId } from "./utils/virtual-ids.js";
|
|
4
|
+
import { loadVirtualRawModule, rewriteHtmlRawImport } from "./utils/virtual-resources.js";
|
|
2
5
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
3
6
|
import { normalizePath } from "vite";
|
|
4
7
|
//#region packages/vite-plugin-angular/src/lib/virtual-modules-plugin.ts
|
|
5
|
-
function
|
|
8
|
+
function resolveAngularVirtualId(id, importer, options) {
|
|
9
|
+
if (id.startsWith("virtual:@analogjs/vite-plugin-angular:raw:")) return `\0${id}`;
|
|
10
|
+
if (options.jit && id.startsWith("angular:jit:")) {
|
|
11
|
+
const filePath = normalizePath(resolve(dirname(importer), id.split(";")[1]));
|
|
12
|
+
if (id.includes(":style")) {
|
|
13
|
+
markStylePathSafe(options.resolvedConfig, filePath);
|
|
14
|
+
return filePath + "?inline";
|
|
15
|
+
}
|
|
16
|
+
return toVirtualRawId(filePath);
|
|
17
|
+
}
|
|
18
|
+
const rawRewrite = rewriteHtmlRawImport(id, importer);
|
|
19
|
+
if (rawRewrite) return rawRewrite;
|
|
20
|
+
if (/\.(css|scss|sass|less)\?inline$/.test(id) && importer) {
|
|
21
|
+
const filePath = id.split("?")[0];
|
|
22
|
+
const resolved = isAbsolute(filePath) ? normalizePath(filePath) : normalizePath(resolve(dirname(importer), filePath));
|
|
23
|
+
markStylePathSafe(options.resolvedConfig, resolved);
|
|
24
|
+
return resolved + "?inline";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function loadAngularVirtualModule(pluginCtx, id, resolvedConfig) {
|
|
28
|
+
const rawModule = await loadVirtualRawModule(pluginCtx, id);
|
|
29
|
+
if (rawModule !== void 0) return rawModule;
|
|
30
|
+
if (/\.(css|scss|sass|less)\?inline$/.test(id)) markStylePathSafe(resolvedConfig, id.split("?")[0]);
|
|
31
|
+
}
|
|
32
|
+
function virtualModulesPlugin(ctxOrOptions) {
|
|
33
|
+
const sharedCtx = isAngularBuildContext(ctxOrOptions) ? ctxOrOptions : void 0;
|
|
34
|
+
const standaloneJit = isAngularBuildContext(ctxOrOptions) ? ctxOrOptions.options.jit : ctxOrOptions?.jit ?? false;
|
|
35
|
+
let localConfig;
|
|
6
36
|
return {
|
|
7
37
|
name: "@analogjs/vite-plugin-angular:virtual-modules",
|
|
8
38
|
enforce: "pre",
|
|
39
|
+
configResolved(config) {
|
|
40
|
+
localConfig = config;
|
|
41
|
+
sharedCtx?.setResolvedConfig(config);
|
|
42
|
+
},
|
|
9
43
|
resolveId(id, importer) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const resolved = isAbsolute(filePath) ? normalizePath(filePath) : importer ? normalizePath(resolve(dirname(importer), filePath)) : void 0;
|
|
18
|
-
if (resolved) return toVirtualRawId(resolved);
|
|
19
|
-
}
|
|
44
|
+
return resolveAngularVirtualId(id, importer, {
|
|
45
|
+
jit: sharedCtx ? sharedCtx.options.jit : standaloneJit,
|
|
46
|
+
resolvedConfig: sharedCtx?.resolvedConfig ?? localConfig
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
async load(id) {
|
|
50
|
+
return loadAngularVirtualModule(this, id, sharedCtx?.resolvedConfig ?? localConfig);
|
|
20
51
|
}
|
|
21
52
|
};
|
|
22
53
|
}
|
|
23
54
|
//#endregion
|
|
24
|
-
export { virtualModulesPlugin };
|
|
55
|
+
export { loadAngularVirtualModule, resolveAngularVirtualId, virtualModulesPlugin };
|
|
25
56
|
|
|
26
57
|
//# sourceMappingURL=virtual-modules-plugin.js.map
|
|
@@ -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, Plugin } from 'vite';\nimport { VIRTUAL_RAW_PREFIX, toVirtualRawId } from './utils/virtual-ids.js';\n\nexport interface VirtualModulesPluginOptions {\n jit
|
|
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 ?? localConfig,\n });\n },\n async load(id) {\n return loadAngularVirtualModule(\n this,\n id,\n sharedCtx?.resolvedConfig ?? localConfig,\n );\n },\n };\n}\n"],"mappings":";;;;;;;AAiBA,SAAgB,wBACd,IACA,UACA,SAIoB;CACpB,IAAI,GAAG,WAAA,4CAA6B,GAClC,OAAO,KAAK;CAGd,IAAI,QAAQ,OAAO,GAAG,WAAW,cAAc,GAAG;EAChD,MAAM,WAAW,cACf,QAAQ,QAAQ,QAAkB,GAAG,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,CACvD;EACA,IAAI,GAAG,SAAS,QAAQ,GAAG;GACzB,kBAAkB,QAAQ,gBAAgB,QAAQ;GAClD,OAAO,WAAW;EACpB;EACA,OAAO,eAAe,QAAQ;CAChC;CAGA,MAAM,aAAa,qBAAqB,IAAI,QAAQ;CACpD,IAAI,YACF,OAAO;CAKT,IAAI,kCAAkC,KAAK,EAAE,KAAK,UAAU;EAC1D,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,CAAC;EAC/B,MAAM,WAAW,WAAW,QAAQ,IAChC,cAAc,QAAQ,IACtB,cAAc,QAAQ,QAAQ,QAAQ,GAAG,QAAQ,CAAC;EACtD,kBAAkB,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