@analogjs/vite-plugin-angular 3.0.0-alpha.7 → 3.0.0-alpha.9
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 +7 -9
- package/setup-vitest.js +154 -193
- package/setup-vitest.js.map +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/lib/angular-build-optimizer-plugin.js +48 -62
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.js +31 -37
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-pending-tasks.plugin.js +17 -18
- package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.js +790 -1076
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +16 -12
- package/src/lib/angular-vitest-plugin.js +97 -114
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compiler-plugin.js +40 -44
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/component-resolvers.d.ts +4 -2
- package/src/lib/component-resolvers.js +93 -64
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/host.js +69 -101
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.js +51 -63
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/nx-folder-plugin.js +18 -16
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.js +35 -62
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.js +23 -23
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/tools/package.json +2 -5
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -38
- package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +52 -60
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/tools/src/index.js +0 -2
- package/src/lib/utils/devkit.js +34 -38
- package/src/lib/utils/devkit.js.map +1 -1
- package/src/lib/utils/rolldown.d.ts +2 -0
- package/src/lib/utils/rolldown.js +12 -0
- package/src/lib/utils/rolldown.js.map +1 -0
- package/src/lib/utils/source-file-cache.js +35 -37
- package/src/lib/utils/source-file-cache.js.map +1 -1
- package/README.md +0 -91
- package/src/lib/models.js +0 -1
- package/src/lib/models.js.map +0 -1
- package/src/lib/tools/README.md +0 -3
- package/src/lib/tools/src/index.js.map +0 -1
- package/src/lib/utils/compiler-plugin-options.js +0 -1
- package/src/lib/utils/compiler-plugin-options.js.map +0 -1
- package/src/lib/utils/hmr-candidates.js +0 -272
- package/src/lib/utils/hmr-candidates.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-server.impl.js","
|
|
1
|
+
{"version":3,"file":"dev-server.impl.js","names":[],"sources":["../../../../../../../../../packages/vite-plugin-angular-tools/src/builders/vite-dev-server/dev-server.impl.ts"],"sourcesContent":["import {\n BuilderContext,\n BuilderOutput,\n createBuilder,\n targetFromTargetString,\n} from '@angular-devkit/architect';\nimport type { InlineConfig } from 'vite';\nimport { ViteDevServerSchema } from './schema';\n\nasync function viteDevServerBuilder(\n options: ViteDevServerSchema,\n context: BuilderContext,\n): Promise<BuilderOutput> {\n const { createServer } = await Function('return import(\"vite\")')();\n if (!context.target) {\n throw new Error('Builder must be executed with a target');\n }\n const projectConfig = await context.getProjectMetadata(context.target);\n const projectName = context.target.project;\n const buildTargetSpecifier = options.buildTarget ?? `::development`;\n const buildTarget = targetFromTargetString(\n buildTargetSpecifier,\n projectName,\n 'build',\n );\n\n const browserBuilderName = await context.getBuilderNameForTarget(buildTarget);\n const rawBuildOptions = await context.getTargetOptions(buildTarget);\n const buildOptions = await context.validateOptions(\n rawBuildOptions,\n browserBuilderName,\n );\n\n const serverConfig: InlineConfig = {\n configFile: buildOptions.configFile as string,\n root: projectConfig.root as string,\n mode: (process.env.NODE_ENV ??\n buildOptions.mode ??\n 'development') as string,\n build: {\n sourcemap: !!buildOptions.sourcemap,\n },\n server: {\n hmr: options?.hmr,\n port: options?.port,\n },\n };\n\n try {\n const server = await createServer(serverConfig);\n await runViteDevServer(server);\n const resolvedUrls = [\n ...server.resolvedUrls.local,\n ...server.resolvedUrls.network,\n ];\n\n await new Promise<void>((resolve) => {\n process.once('SIGINT', () => resolve());\n process.once('SIGTERM', () => resolve());\n process.once('exit', () => resolve());\n });\n\n return {\n success: true,\n baseUrl: resolvedUrls[0] ?? '',\n };\n } catch (e) {\n console.error(e);\n return {\n success: false,\n baseUrl: '',\n };\n }\n}\n\n// vite ViteDevServer\nasync function runViteDevServer(server: Record<string, any>): Promise<void> {\n await server.listen();\n\n server.printUrls();\n\n const processOnExit = async () => {\n await server.close();\n };\n\n process.once('SIGINT', processOnExit);\n process.once('SIGTERM', processOnExit);\n process.once('exit', processOnExit);\n}\n\nexport default createBuilder(viteDevServerBuilder) as any;\n"],"mappings":";;AASA,eAAe,qBACb,SACA,SACwB;CACxB,MAAM,EAAE,iBAAiB,MAAM,SAAS,0BAAwB,EAAE;AAClE,KAAI,CAAC,QAAQ,OACX,OAAM,IAAI,MAAM,yCAAyC;CAE3D,MAAM,gBAAgB,MAAM,QAAQ,mBAAmB,QAAQ,OAAO;CACtE,MAAM,cAAc,QAAQ,OAAO;CAEnC,MAAM,cAAc,uBADS,QAAQ,eAAe,iBAGlD,aACA,QACD;CAED,MAAM,qBAAqB,MAAM,QAAQ,wBAAwB,YAAY;CAC7E,MAAM,kBAAkB,MAAM,QAAQ,iBAAiB,YAAY;CACnE,MAAM,eAAe,MAAM,QAAQ,gBACjC,iBACA,mBACD;CAED,MAAM,eAA6B;EACjC,YAAY,aAAa;EACzB,MAAM,cAAc;EACpB,MAAA,QAAA,IAAA,YACE,aAAa,QACb;EACF,OAAO,EACL,WAAW,CAAC,CAAC,aAAa,WAC3B;EACD,QAAQ;GACN,KAAK,SAAS;GACd,MAAM,SAAS;GAChB;EACF;AAED,KAAI;EACF,MAAM,SAAS,MAAM,aAAa,aAAa;AAC/C,QAAM,iBAAiB,OAAO;EAC9B,MAAM,eAAe,CACnB,GAAG,OAAO,aAAa,OACvB,GAAG,OAAO,aAAa,QACxB;AAED,QAAM,IAAI,SAAe,YAAY;AACnC,WAAQ,KAAK,gBAAgB,SAAS,CAAC;AACvC,WAAQ,KAAK,iBAAiB,SAAS,CAAC;AACxC,WAAQ,KAAK,cAAc,SAAS,CAAC;IACrC;AAEF,SAAO;GACL,SAAS;GACT,SAAS,aAAa,MAAM;GAC7B;UACM,GAAG;AACV,UAAQ,MAAM,EAAE;AAChB,SAAO;GACL,SAAS;GACT,SAAS;GACV;;;AAKL,eAAe,iBAAiB,QAA4C;AAC1E,OAAM,OAAO,QAAQ;AAErB,QAAO,WAAW;CAElB,MAAM,gBAAgB,YAAY;AAChC,QAAM,OAAO,OAAO;;AAGtB,SAAQ,KAAK,UAAU,cAAc;AACrC,SAAQ,KAAK,WAAW,cAAc;AACtC,SAAQ,KAAK,QAAQ,cAAc;;AAGrC,IAAA,0BAAe,cAAc,qBAAqB"}
|
package/src/lib/utils/devkit.js
CHANGED
|
@@ -1,41 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
1
|
+
import { SourceFileCache } from "./source-file-cache.js";
|
|
2
|
+
import { VERSION } from "@angular/compiler-cli";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
//#region packages/vite-plugin-angular/src/lib/utils/devkit.ts
|
|
5
|
+
var require = createRequire(import.meta.url);
|
|
6
|
+
var angularMajor = Number(VERSION.major);
|
|
7
|
+
var angularMinor = Number(VERSION.minor);
|
|
8
|
+
var angularPatch = Number(VERSION.patch);
|
|
9
|
+
var padVersion = (version) => String(version).padStart(2, "0");
|
|
10
|
+
var angularFullVersion = Number(`${angularMajor}${padVersion(angularMinor)}${padVersion(angularPatch)}`);
|
|
11
|
+
var sourceFileCache;
|
|
12
|
+
var cjt;
|
|
13
|
+
var jt;
|
|
14
|
+
var createAngularCompilation;
|
|
15
|
+
if (angularMajor < 17) throw new Error("AnalogJS is not compatible with Angular v16 and lower");
|
|
17
16
|
else if (angularMajor >= 17 && angularMajor < 18) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { createJitResourceTransformer, JavaScriptTransformer, SourceFileCache, createAngularCompilation: createAngularCompilationFn, } = require('@angular/build/private');
|
|
35
|
-
sourceFileCache = SourceFileCache;
|
|
36
|
-
cjt = createJitResourceTransformer;
|
|
37
|
-
jt = JavaScriptTransformer;
|
|
38
|
-
createAngularCompilation = createAngularCompilationFn;
|
|
17
|
+
const cp = require("@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin.js");
|
|
18
|
+
const { createJitResourceTransformer } = require("@angular-devkit/build-angular/src/tools/esbuild/angular/jit-resource-transformer.js");
|
|
19
|
+
const { JavaScriptTransformer } = require("@angular-devkit/build-angular/src/tools/esbuild/javascript-transformer.js");
|
|
20
|
+
/**
|
|
21
|
+
* Workaround for compatibility with Angular 17.0+
|
|
22
|
+
*/
|
|
23
|
+
if (typeof cp["SourceFileCache"] !== "undefined") sourceFileCache = cp.SourceFileCache;
|
|
24
|
+
else sourceFileCache = SourceFileCache;
|
|
25
|
+
cjt = createJitResourceTransformer;
|
|
26
|
+
jt = JavaScriptTransformer;
|
|
27
|
+
} else {
|
|
28
|
+
const { createJitResourceTransformer, JavaScriptTransformer, SourceFileCache, createAngularCompilation: createAngularCompilationFn } = require("@angular/build/private");
|
|
29
|
+
sourceFileCache = SourceFileCache;
|
|
30
|
+
cjt = createJitResourceTransformer;
|
|
31
|
+
jt = JavaScriptTransformer;
|
|
32
|
+
createAngularCompilation = createAngularCompilationFn;
|
|
39
33
|
}
|
|
40
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
export { angularFullVersion, cjt, createAngularCompilation, jt, sourceFileCache };
|
|
36
|
+
|
|
41
37
|
//# sourceMappingURL=devkit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devkit.js","
|
|
1
|
+
{"version":3,"file":"devkit.js","names":[],"sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/devkit.ts"],"sourcesContent":["import { VERSION } from '@angular/compiler-cli';\nimport { createRequire } from 'node:module';\nimport type { CompilerPluginOptions } from './compiler-plugin-options.js';\nimport * as sfc from './source-file-cache.js';\n\nconst require = createRequire(import.meta.url);\n\nconst angularMajor: number = Number(VERSION.major);\nconst angularMinor: number = Number(VERSION.minor);\nconst angularPatch: number = Number(VERSION.patch);\nconst padVersion = (version: number) => String(version).padStart(2, '0');\nconst angularFullVersion: number = Number(\n `${angularMajor}${padVersion(angularMinor)}${padVersion(angularPatch)}`,\n);\nlet sourceFileCache: any;\nlet cjt: (...args: any[]) => any;\nlet jt: any;\nlet createAngularCompilation: (...args: any[]) => any;\n\nif (angularMajor < 17) {\n throw new Error('AnalogJS is not compatible with Angular v16 and lower');\n} else if (angularMajor >= 17 && angularMajor < 18) {\n const cp = require('@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin.js');\n const {\n createJitResourceTransformer,\n } = require('@angular-devkit/build-angular/src/tools/esbuild/angular/jit-resource-transformer.js');\n const {\n JavaScriptTransformer,\n } = require('@angular-devkit/build-angular/src/tools/esbuild/javascript-transformer.js');\n\n /**\n * Workaround for compatibility with Angular 17.0+\n */\n if (typeof cp['SourceFileCache'] !== 'undefined') {\n sourceFileCache = cp.SourceFileCache;\n } else {\n sourceFileCache = sfc.SourceFileCache;\n }\n\n cjt = createJitResourceTransformer;\n jt = JavaScriptTransformer;\n} else {\n const {\n createJitResourceTransformer,\n JavaScriptTransformer,\n SourceFileCache,\n createAngularCompilation: createAngularCompilationFn,\n } = require('@angular/build/private');\n\n sourceFileCache = SourceFileCache;\n cjt = createJitResourceTransformer;\n jt = JavaScriptTransformer;\n createAngularCompilation = createAngularCompilationFn;\n}\n\nexport {\n cjt as createJitResourceTransformer,\n jt as JavaScriptTransformer,\n sourceFileCache as SourceFileCache,\n CompilerPluginOptions,\n angularMajor,\n angularMinor,\n angularPatch,\n createAngularCompilation,\n angularFullVersion,\n};\n"],"mappings":";;;;AAKA,IAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAE9C,IAAM,eAAuB,OAAO,QAAQ,MAAM;AAClD,IAAM,eAAuB,OAAO,QAAQ,MAAM;AAClD,IAAM,eAAuB,OAAO,QAAQ,MAAM;AAClD,IAAM,cAAc,YAAoB,OAAO,QAAQ,CAAC,SAAS,GAAG,IAAI;AACxE,IAAM,qBAA6B,OACjC,GAAG,eAAe,WAAW,aAAa,GAAG,WAAW,aAAa,GACtE;AACD,IAAI;AACJ,IAAI;AACJ,IAAI;AACJ,IAAI;AAEJ,IAAI,eAAe,GACjB,OAAM,IAAI,MAAM,wDAAwD;SAC/D,gBAAgB,MAAM,eAAe,IAAI;CAClD,MAAM,KAAK,QAAQ,6EAA6E;CAChG,MAAM,EACJ,iCACE,QAAQ,sFAAsF;CAClG,MAAM,EACJ,0BACE,QAAQ,4EAA4E;;;;AAKxF,KAAI,OAAO,GAAG,uBAAuB,YACnC,mBAAkB,GAAG;KAErB,mBAAkB;AAGpB,OAAM;AACN,MAAK;OACA;CACL,MAAM,EACJ,8BACA,uBACA,iBACA,0BAA0B,+BACxB,QAAQ,yBAAyB;AAErC,mBAAkB;AAClB,OAAM;AACN,MAAK;AACL,4BAA2B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as vite from "vite";
|
|
2
|
+
//#region packages/vite-plugin-angular/src/lib/utils/rolldown.ts
|
|
3
|
+
function isRolldown() {
|
|
4
|
+
return !!vite.rolldownVersion;
|
|
5
|
+
}
|
|
6
|
+
function getJsTransformConfigKey() {
|
|
7
|
+
return isRolldown() ? "oxc" : "esbuild";
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getJsTransformConfigKey, isRolldown };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=rolldown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rolldown.js","names":[],"sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/rolldown.ts"],"sourcesContent":["import * as vite from 'vite';\n\nexport function isRolldown(): boolean {\n return !!vite.rolldownVersion;\n}\n\nexport function getJsTransformConfigKey(): 'oxc' | 'esbuild' {\n return isRolldown() ? 'oxc' : 'esbuild';\n}\n"],"mappings":";;AAEA,SAAgB,aAAsB;AACpC,QAAO,CAAC,CAAC,KAAK;;AAGhB,SAAgB,0BAA6C;AAC3D,QAAO,YAAY,GAAG,QAAQ"}
|
|
@@ -1,39 +1,37 @@
|
|
|
1
|
+
import * as path$1 from "node:path";
|
|
2
|
+
import { platform } from "node:os";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
//#region packages/vite-plugin-angular/src/lib/utils/source-file-cache.ts
|
|
1
5
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
this.delete(file);
|
|
35
|
-
this.modifiedFiles.add(file);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright Google LLC All Rights Reserved.
|
|
8
|
+
*
|
|
9
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
10
|
+
* found in the LICENSE file at https://angular.io/license
|
|
11
|
+
*/
|
|
12
|
+
var USING_WINDOWS = platform() === "win32";
|
|
13
|
+
var WINDOWS_SEP_REGEXP = new RegExp(`\\${path$1.win32.sep}`, "g");
|
|
14
|
+
var SourceFileCache = class extends Map {
|
|
15
|
+
modifiedFiles = /* @__PURE__ */ new Set();
|
|
16
|
+
babelFileCache = /* @__PURE__ */ new Map();
|
|
17
|
+
typeScriptFileCache = /* @__PURE__ */ new Map();
|
|
18
|
+
referencedFiles;
|
|
19
|
+
constructor(persistentCachePath) {
|
|
20
|
+
super();
|
|
21
|
+
this.persistentCachePath = persistentCachePath;
|
|
22
|
+
}
|
|
23
|
+
invalidate(files) {
|
|
24
|
+
if (files !== this.modifiedFiles) this.modifiedFiles.clear();
|
|
25
|
+
for (let file of files) {
|
|
26
|
+
this.babelFileCache.delete(file);
|
|
27
|
+
this.typeScriptFileCache.delete(pathToFileURL(file).href);
|
|
28
|
+
if (USING_WINDOWS) file = file.replace(WINDOWS_SEP_REGEXP, path$1.posix.sep);
|
|
29
|
+
this.delete(file);
|
|
30
|
+
this.modifiedFiles.add(file);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { SourceFileCache };
|
|
36
|
+
|
|
39
37
|
//# sourceMappingURL=source-file-cache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-file-cache.js","
|
|
1
|
+
{"version":3,"file":"source-file-cache.js","names":[],"sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/source-file-cache.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport { platform } from 'node:os';\nimport * as path from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type ts from 'typescript';\n\nconst USING_WINDOWS = platform() === 'win32';\nconst WINDOWS_SEP_REGEXP = new RegExp(`\\\\${path.win32.sep}`, 'g');\n\nexport class SourceFileCache extends Map<string, ts.SourceFile> {\n readonly modifiedFiles: Set<string> = new Set<string>();\n readonly babelFileCache: Map<string, Uint8Array> = new Map<\n string,\n Uint8Array\n >();\n readonly typeScriptFileCache: Map<string, string | Uint8Array> = new Map<\n string,\n string | Uint8Array\n >();\n\n referencedFiles?: readonly string[];\n\n constructor(readonly persistentCachePath?: string) {\n super();\n }\n\n invalidate(files: Iterable<string>): void {\n if (files !== this.modifiedFiles) {\n this.modifiedFiles.clear();\n }\n for (let file of files) {\n this.babelFileCache.delete(file);\n this.typeScriptFileCache.delete(pathToFileURL(file).href);\n\n // Normalize separators to allow matching TypeScript Host paths\n if (USING_WINDOWS) {\n file = file.replace(WINDOWS_SEP_REGEXP, path.posix.sep);\n }\n\n this.delete(file);\n this.modifiedFiles.add(file);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAaA,IAAM,gBAAgB,UAAU,KAAK;AACrC,IAAM,qBAAqB,IAAI,OAAO,KAAK,OAAK,MAAM,OAAO,IAAI;AAEjE,IAAa,kBAAb,cAAqC,IAA2B;CAC9D,gCAAsC,IAAI,KAAa;CACvD,iCAAmD,IAAI,KAGpD;CACH,sCAAiE,IAAI,KAGlE;CAEH;CAEA,YAAY,qBAAuC;AACjD,SAAO;AADY,OAAA,sBAAA;;CAIrB,WAAW,OAA+B;AACxC,MAAI,UAAU,KAAK,cACjB,MAAK,cAAc,OAAO;AAE5B,OAAK,IAAI,QAAQ,OAAO;AACtB,QAAK,eAAe,OAAO,KAAK;AAChC,QAAK,oBAAoB,OAAO,cAAc,KAAK,CAAC,KAAK;AAGzD,OAAI,cACF,QAAO,KAAK,QAAQ,oBAAoB,OAAK,MAAM,IAAI;AAGzD,QAAK,OAAO,KAAK;AACjB,QAAK,cAAc,IAAI,KAAK"}
|
package/README.md
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
# @analogjs/vite-plugin-angular
|
|
2
|
-
|
|
3
|
-
A Vite plugin for building Angular applications
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
With npm:
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
npm install @analogjs/vite-plugin-angular --save-dev
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
With pnpm:
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
pnpm install @analogjs/vite-plugin-angular --save-dev
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
With yarn:
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
yarn install @analogjs/vite-plugin-angular --dev
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
With bun:
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
bun install @analogjs/vite-plugin-angular --dev
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Setup
|
|
32
|
-
|
|
33
|
-
Add the plugin to the `plugins` array in your Vite config
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
import { defineConfig } from 'vite';
|
|
37
|
-
import angular from '@analogjs/vite-plugin-angular';
|
|
38
|
-
|
|
39
|
-
// https://vitejs.dev/config/
|
|
40
|
-
export default defineConfig({
|
|
41
|
-
resolve: {
|
|
42
|
-
mainFields: ['module'],
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
plugins: [angular()],
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
> The `angular` plugin should be listed **first** in the plugins array.
|
|
50
|
-
|
|
51
|
-
## Setting up the TypeScript config
|
|
52
|
-
|
|
53
|
-
The integration needs a `tsconfig.app.json` at the root of the project for compilation.
|
|
54
|
-
|
|
55
|
-
Create a `tsconfig.app.json` in the root of the project.
|
|
56
|
-
|
|
57
|
-
```json
|
|
58
|
-
{
|
|
59
|
-
"extends": "./tsconfig.json",
|
|
60
|
-
"compileOnSave": false,
|
|
61
|
-
"compilerOptions": {
|
|
62
|
-
"baseUrl": "./",
|
|
63
|
-
"outDir": "./dist/out-tsc",
|
|
64
|
-
"forceConsistentCasingInFileNames": true,
|
|
65
|
-
"strict": true,
|
|
66
|
-
"noImplicitOverride": true,
|
|
67
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
68
|
-
"noImplicitReturns": true,
|
|
69
|
-
"noFallthroughCasesInSwitch": true,
|
|
70
|
-
"sourceMap": true,
|
|
71
|
-
"declaration": false,
|
|
72
|
-
"downlevelIteration": true,
|
|
73
|
-
"experimentalDecorators": true,
|
|
74
|
-
"moduleResolution": "node",
|
|
75
|
-
"importHelpers": true,
|
|
76
|
-
"noEmit": false,
|
|
77
|
-
"target": "es2020",
|
|
78
|
-
"module": "es2020",
|
|
79
|
-
"lib": ["es2020", "dom"],
|
|
80
|
-
"skipLibCheck": true
|
|
81
|
-
},
|
|
82
|
-
"angularCompilerOptions": {
|
|
83
|
-
"enableI18nLegacyMessageIdFormat": false,
|
|
84
|
-
"strictInjectionParameters": true,
|
|
85
|
-
"strictInputAccessModifiers": true,
|
|
86
|
-
"strictTemplates": true
|
|
87
|
-
},
|
|
88
|
-
"files": [],
|
|
89
|
-
"include": ["src/**/*.ts"]
|
|
90
|
-
}
|
|
91
|
-
```
|
package/src/lib/models.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=models.js.map
|
package/src/lib/models.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/models.ts"],"names":[],"mappings":""}
|
package/src/lib/tools/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/vite-plugin-angular-tools/src/index.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=compiler-plugin-options.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compiler-plugin-options.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/compiler-plugin-options.ts"],"names":[],"mappings":""}
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
-
*/
|
|
8
|
-
import assert from 'node:assert';
|
|
9
|
-
import ts from 'typescript';
|
|
10
|
-
/**
|
|
11
|
-
* Analyzes one or more modified files for changes to determine if any
|
|
12
|
-
* class declarations for Angular components are candidates for hot
|
|
13
|
-
* module replacement (HMR). If any source files are also modified but
|
|
14
|
-
* are not candidates then all candidates become invalid. This invalidation
|
|
15
|
-
* ensures that a full rebuild occurs and the running application stays
|
|
16
|
-
* synchronized with the code.
|
|
17
|
-
* @param modifiedFiles A set of modified files to analyze.
|
|
18
|
-
* @param param1 An Angular compiler instance
|
|
19
|
-
* @param staleSourceFiles A map of paths to previous source file instances.
|
|
20
|
-
* @returns A set of HMR candidate component class declarations.
|
|
21
|
-
*/
|
|
22
|
-
export function collectHmrCandidates(modifiedFiles, { compiler }, staleSourceFiles) {
|
|
23
|
-
const candidates = new Set();
|
|
24
|
-
for (const file of modifiedFiles) {
|
|
25
|
-
// If the file is a template for component(s), add component classes as candidates
|
|
26
|
-
const templateFileNodes = compiler.getComponentsWithTemplateFile(file);
|
|
27
|
-
if (templateFileNodes.size) {
|
|
28
|
-
templateFileNodes.forEach((node) => candidates.add(node));
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
// If the file is a style for component(s), add component classes as candidates
|
|
32
|
-
const styleFileNodes = compiler.getComponentsWithStyleFile(file);
|
|
33
|
-
if (styleFileNodes.size) {
|
|
34
|
-
styleFileNodes.forEach((node) => candidates.add(node));
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
const staleSource = staleSourceFiles?.get(file);
|
|
38
|
-
if (staleSource === undefined) {
|
|
39
|
-
// Unknown file requires a rebuild so clear out the candidates and stop collecting
|
|
40
|
-
candidates.clear();
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
const updatedSource = compiler.getCurrentProgram().getSourceFile(file);
|
|
44
|
-
if (updatedSource === undefined) {
|
|
45
|
-
// No longer existing program file requires a rebuild so clear out the candidates and stop collecting
|
|
46
|
-
candidates.clear();
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
// Analyze the stale and updated file for changes
|
|
50
|
-
const fileCandidates = analyzeFileUpdates(staleSource, updatedSource, compiler);
|
|
51
|
-
if (fileCandidates) {
|
|
52
|
-
fileCandidates.forEach((node) => candidates.add(node));
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// Unsupported HMR changes present
|
|
56
|
-
// Only template and style literal changes are allowed.
|
|
57
|
-
candidates.clear();
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return candidates;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Analyzes the updates of a source file for potential HMR component class candidates.
|
|
65
|
-
* A source file can contain candidates if only the Angular component metadata of a class
|
|
66
|
-
* has been changed and the metadata changes are only of supported fields.
|
|
67
|
-
* @param stale The stale (previous) source file instance.
|
|
68
|
-
* @param updated The updated source file instance.
|
|
69
|
-
* @param compiler An Angular compiler instance.
|
|
70
|
-
* @returns An array of candidate class declarations; or `null` if unsupported changes are present.
|
|
71
|
-
*/
|
|
72
|
-
export function analyzeFileUpdates(stale, updated, compiler) {
|
|
73
|
-
if (stale.statements.length !== updated.statements.length) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
const candidates = [];
|
|
77
|
-
for (let i = 0; i < updated.statements.length; ++i) {
|
|
78
|
-
const updatedNode = updated.statements[i];
|
|
79
|
-
const staleNode = stale.statements[i];
|
|
80
|
-
if (ts.isClassDeclaration(updatedNode)) {
|
|
81
|
-
if (!ts.isClassDeclaration(staleNode)) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
// Check class declaration differences (name/heritage/modifiers)
|
|
85
|
-
if (updatedNode.name?.text !== staleNode.name?.text) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
if (!equalRangeText(updatedNode.heritageClauses, updated, staleNode.heritageClauses, stale)) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
const updatedModifiers = ts.getModifiers(updatedNode);
|
|
92
|
-
const staleModifiers = ts.getModifiers(staleNode);
|
|
93
|
-
if (updatedModifiers?.length !== staleModifiers?.length ||
|
|
94
|
-
!updatedModifiers?.every((updatedModifier) => staleModifiers?.some((staleModifier) => updatedModifier.kind === staleModifier.kind))) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
// Check for component class nodes
|
|
98
|
-
const meta = compiler?.getMeta(updatedNode);
|
|
99
|
-
console.log('meta', stale.fileName, meta);
|
|
100
|
-
if (meta?.decorator &&
|
|
101
|
-
meta.isComponent === true) {
|
|
102
|
-
const updatedDecorators = ts.getDecorators(updatedNode);
|
|
103
|
-
const staleDecorators = ts.getDecorators(staleNode);
|
|
104
|
-
if (!staleDecorators ||
|
|
105
|
-
staleDecorators.length !== updatedDecorators?.length) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
// TODO: Check other decorators instead of assuming all multi-decorator components are unsupported
|
|
109
|
-
if (staleDecorators.length > 1) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
// Find index of component metadata decorator
|
|
113
|
-
const metaDecoratorIndex = updatedDecorators?.indexOf(meta.decorator);
|
|
114
|
-
assert(metaDecoratorIndex !== undefined, 'Component metadata decorator should always be present on component class.');
|
|
115
|
-
const updatedDecoratorExpression = meta.decorator.expression;
|
|
116
|
-
assert(ts.isCallExpression(updatedDecoratorExpression) &&
|
|
117
|
-
updatedDecoratorExpression.arguments.length === 1, 'Component metadata decorator should contain a call expression with a single argument.');
|
|
118
|
-
// Check the matching stale index for the component decorator
|
|
119
|
-
const staleDecoratorExpression = staleDecorators[metaDecoratorIndex]?.expression;
|
|
120
|
-
if (!staleDecoratorExpression ||
|
|
121
|
-
!ts.isCallExpression(staleDecoratorExpression) ||
|
|
122
|
-
staleDecoratorExpression.arguments.length !== 1) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
// Check decorator name/expression
|
|
126
|
-
// NOTE: This would typically be `Component` but can also be a property expression or some other alias.
|
|
127
|
-
// To avoid complex checks, this ensures the textual representation does not change. This has a low chance
|
|
128
|
-
// of a false positive if the expression is changed to still reference the `Component` type but has different
|
|
129
|
-
// text. However, it is rare for `Component` to not be used directly and additionally unlikely that it would
|
|
130
|
-
// be changed between edits. A false positive would also only lead to a difference of a full page reload versus
|
|
131
|
-
// an HMR update.
|
|
132
|
-
if (!equalRangeText(updatedDecoratorExpression.expression, updated, staleDecoratorExpression.expression, stale)) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
// Compare component meta decorator object literals
|
|
136
|
-
const analysis = analyzeMetaUpdates(staleDecoratorExpression, stale, updatedDecoratorExpression, updated);
|
|
137
|
-
if (analysis === MetaUpdateAnalysis.Unsupported) {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
// Compare text of the member nodes to determine if any changes have occurred
|
|
141
|
-
if (!equalRangeText(updatedNode.members, updated, staleNode.members, stale)) {
|
|
142
|
-
// A change to a member outside a component's metadata is unsupported
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
// If all previous class checks passed, this class is supported for HMR updates
|
|
146
|
-
if (analysis === MetaUpdateAnalysis.Supported) {
|
|
147
|
-
candidates.push(updatedNode);
|
|
148
|
-
}
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// Compare text of the statement nodes to determine if any changes have occurred
|
|
153
|
-
// TODO: Consider expanding this to check semantic updates for each node kind
|
|
154
|
-
if (!equalRangeText(updatedNode, updated, staleNode, stale)) {
|
|
155
|
-
// A change to a statement outside a component's metadata is unsupported
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return candidates;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* The set of Angular component metadata fields that are supported by HMR updates.
|
|
163
|
-
*/
|
|
164
|
-
const SUPPORTED_FIELD_NAMES = new Set([
|
|
165
|
-
'template',
|
|
166
|
-
'templateUrl',
|
|
167
|
-
'styles',
|
|
168
|
-
'styleUrl',
|
|
169
|
-
'stylesUrl',
|
|
170
|
-
]);
|
|
171
|
-
var MetaUpdateAnalysis;
|
|
172
|
-
(function (MetaUpdateAnalysis) {
|
|
173
|
-
MetaUpdateAnalysis[MetaUpdateAnalysis["Supported"] = 0] = "Supported";
|
|
174
|
-
MetaUpdateAnalysis[MetaUpdateAnalysis["Unsupported"] = 1] = "Unsupported";
|
|
175
|
-
MetaUpdateAnalysis[MetaUpdateAnalysis["None"] = 2] = "None";
|
|
176
|
-
})(MetaUpdateAnalysis || (MetaUpdateAnalysis = {}));
|
|
177
|
-
/**
|
|
178
|
-
* Analyzes the metadata fields of a decorator call expression for unsupported HMR updates.
|
|
179
|
-
* Only updates to supported fields can be present for HMR to be viable.
|
|
180
|
-
* @param staleCall A call expression instance.
|
|
181
|
-
* @param staleSource The source file instance containing the stale call instance.
|
|
182
|
-
* @param updatedCall A call expression instance.
|
|
183
|
-
* @param updatedSource The source file instance containing the updated call instance.
|
|
184
|
-
* @returns A MetaUpdateAnalysis enum value.
|
|
185
|
-
*/
|
|
186
|
-
function analyzeMetaUpdates(staleCall, staleSource, updatedCall, updatedSource) {
|
|
187
|
-
const staleObject = staleCall.arguments[0];
|
|
188
|
-
const updatedObject = updatedCall.arguments[0];
|
|
189
|
-
let hasSupportedUpdate = false;
|
|
190
|
-
if (!ts.isObjectLiteralExpression(staleObject) ||
|
|
191
|
-
!ts.isObjectLiteralExpression(updatedObject)) {
|
|
192
|
-
return MetaUpdateAnalysis.Unsupported;
|
|
193
|
-
}
|
|
194
|
-
const supportedFields = new Map();
|
|
195
|
-
const unsupportedFields = [];
|
|
196
|
-
for (const property of staleObject.properties) {
|
|
197
|
-
if (!ts.isPropertyAssignment(property) ||
|
|
198
|
-
ts.isComputedPropertyName(property.name)) {
|
|
199
|
-
// Unsupported object literal property
|
|
200
|
-
return MetaUpdateAnalysis.Unsupported;
|
|
201
|
-
}
|
|
202
|
-
const name = property.name.text;
|
|
203
|
-
if (SUPPORTED_FIELD_NAMES.has(name)) {
|
|
204
|
-
supportedFields.set(name, property.initializer);
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
unsupportedFields.push(property.initializer);
|
|
208
|
-
}
|
|
209
|
-
let i = 0;
|
|
210
|
-
for (const property of updatedObject.properties) {
|
|
211
|
-
if (!ts.isPropertyAssignment(property) ||
|
|
212
|
-
ts.isComputedPropertyName(property.name)) {
|
|
213
|
-
// Unsupported object literal property
|
|
214
|
-
return MetaUpdateAnalysis.Unsupported;
|
|
215
|
-
}
|
|
216
|
-
const name = property.name.text;
|
|
217
|
-
if (SUPPORTED_FIELD_NAMES.has(name)) {
|
|
218
|
-
const staleInitializer = supportedFields.get(name);
|
|
219
|
-
// If the supported field was added or has its content changed, there has been a supported update
|
|
220
|
-
if (!staleInitializer ||
|
|
221
|
-
!equalRangeText(property.initializer, updatedSource, staleInitializer, staleSource)) {
|
|
222
|
-
hasSupportedUpdate = true;
|
|
223
|
-
}
|
|
224
|
-
// Remove the field entry to allow tracking removed fields
|
|
225
|
-
supportedFields.delete(name);
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
// Compare in order
|
|
229
|
-
if (!equalRangeText(property.initializer, updatedSource, unsupportedFields[i++], staleSource)) {
|
|
230
|
-
return MetaUpdateAnalysis.Unsupported;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (i !== unsupportedFields.length) {
|
|
234
|
-
return MetaUpdateAnalysis.Unsupported;
|
|
235
|
-
}
|
|
236
|
-
// Any remaining supported field indicates a field removal. This is also considered a supported update.
|
|
237
|
-
hasSupportedUpdate ||= supportedFields.size > 0;
|
|
238
|
-
return hasSupportedUpdate
|
|
239
|
-
? MetaUpdateAnalysis.Supported
|
|
240
|
-
: MetaUpdateAnalysis.None;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Compares the text from a provided range in a source file to the text of a range in a second source file.
|
|
244
|
-
* The comparison avoids making any intermediate string copies.
|
|
245
|
-
* @param firstRange A text range within the first source file.
|
|
246
|
-
* @param firstSource A source file instance.
|
|
247
|
-
* @param secondRange A text range within the second source file.
|
|
248
|
-
* @param secondSource A source file instance.
|
|
249
|
-
* @returns true, if the text from both ranges is equal; false, otherwise.
|
|
250
|
-
*/
|
|
251
|
-
function equalRangeText(firstRange, firstSource, secondRange, secondSource) {
|
|
252
|
-
// Check matching undefined values
|
|
253
|
-
if (!firstRange || !secondRange) {
|
|
254
|
-
return firstRange === secondRange;
|
|
255
|
-
}
|
|
256
|
-
// Ensure lengths are equal
|
|
257
|
-
const firstLength = firstRange.end - firstRange.pos;
|
|
258
|
-
const secondLength = secondRange.end - secondRange.pos;
|
|
259
|
-
if (firstLength !== secondLength) {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
// Check each character
|
|
263
|
-
for (let i = 0; i < firstLength; ++i) {
|
|
264
|
-
const firstChar = firstSource.text.charCodeAt(i + firstRange.pos);
|
|
265
|
-
const secondChar = secondSource.text.charCodeAt(i + secondRange.pos);
|
|
266
|
-
if (firstChar !== secondChar) {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
//# sourceMappingURL=hmr-candidates.js.map
|