@analogjs/vite-plugin-angular 3.0.0-alpha.3 → 3.0.0-alpha.31
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.d.ts +2 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
- package/migrations/migration.json +7 -1
- package/migrations/migrations.json +9 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +2 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js +36 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js.map +1 -0
- package/package.json +27 -13
- package/src/index.d.ts +3 -2
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/lib/analog-compiler-plugin.d.ts +14 -0
- package/src/lib/analog-compiler-plugin.js +257 -0
- package/src/lib/analog-compiler-plugin.js.map +1 -0
- package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
- 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.d.ts +3 -3
- package/src/lib/angular-jit-plugin.js +37 -37
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
- 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.d.ts +231 -40
- package/src/lib/angular-vite-plugin.js +1948 -964
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +19 -15
- package/src/lib/angular-vitest-plugin.js +99 -114
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compiler-plugin.d.ts +11 -11
- package/src/lib/compiler-plugin.js +43 -44
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/component-resolvers.d.ts +23 -5
- package/src/lib/component-resolvers.js +153 -63
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/host.d.ts +10 -8
- package/src/lib/host.js +109 -101
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.d.ts +5 -5
- package/src/lib/live-reload-plugin.js +57 -62
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/models.d.ts +9 -9
- package/src/lib/nx-folder-plugin.d.ts +5 -5
- 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.d.ts +4 -4
- package/src/lib/plugins/file-replacements.plugin.js +40 -62
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +1 -1
- package/src/lib/router-plugin.js +23 -23
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-pipeline.d.ts +15 -0
- package/src/lib/style-pipeline.js +31 -0
- package/src/lib/style-pipeline.js.map +1 -0
- package/src/lib/style-preprocessor.d.ts +35 -0
- package/src/lib/style-preprocessor.js +35 -0
- package/src/lib/style-preprocessor.js.map +1 -0
- package/src/lib/stylesheet-registry.d.ts +73 -0
- package/src/lib/stylesheet-registry.js +168 -0
- package/src/lib/stylesheet-registry.js.map +1 -0
- package/src/lib/tools/package.json +2 -7
- 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 +51 -62
- 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/compiler-plugin-options.d.ts +11 -11
- package/src/lib/utils/debug-harness.d.ts +23 -0
- package/src/lib/utils/debug-harness.js +88 -0
- package/src/lib/utils/debug-harness.js.map +1 -0
- package/src/lib/utils/debug-log-file.d.ts +5 -0
- package/src/lib/utils/debug-log-file.js +56 -0
- package/src/lib/utils/debug-log-file.js.map +1 -0
- package/src/lib/utils/debug.d.ts +26 -0
- package/src/lib/utils/debug.js +35 -0
- package/src/lib/utils/debug.js.map +1 -0
- package/src/lib/utils/devkit.d.ts +6 -6
- package/src/lib/utils/devkit.js +34 -38
- package/src/lib/utils/devkit.js.map +1 -1
- package/src/lib/utils/hmr-candidates.d.ts +28 -28
- package/src/lib/utils/plugin-config.d.ts +30 -0
- package/src/lib/utils/plugin-config.js +64 -0
- package/src/lib/utils/plugin-config.js.map +1 -0
- 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.d.ts +8 -15
- package/src/lib/utils/source-file-cache.js +35 -37
- package/src/lib/utils/source-file-cache.js.map +1 -1
- package/src/lib/utils/virtual-ids.d.ts +8 -0
- package/src/lib/utils/virtual-ids.js +35 -0
- package/src/lib/utils/virtual-ids.js.map +1 -0
- package/src/lib/utils/virtual-resources.d.ts +31 -0
- package/src/lib/utils/virtual-resources.js +60 -0
- package/src/lib/utils/virtual-resources.js.map +1 -0
- package/src/test-setup.d.ts +2 -0
- package/setup-vitest.d.ts +0 -4
- package/setup-vitest.js +0 -215
- package/setup-vitest.js.map +0 -1
- 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.d.ts +0 -0
- 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,64 +1,59 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const result = fileEmitter(resolve(process.cwd(), decodeURIComponent(componentId).split('@')[0]));
|
|
58
|
-
return result?.hmrUpdateCode || '';
|
|
59
|
-
}
|
|
60
|
-
return;
|
|
61
|
-
},
|
|
62
|
-
};
|
|
1
|
+
import { debugHmr } from "./utils/debug.js";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { normalizePath } from "vite";
|
|
4
|
+
//#region packages/vite-plugin-angular/src/lib/live-reload-plugin.ts
|
|
5
|
+
var ANGULAR_COMPONENT_PREFIX = "/@ng/component";
|
|
6
|
+
var FILE_PREFIX = "file:";
|
|
7
|
+
function liveReloadPlugin({ classNames, fileEmitter }) {
|
|
8
|
+
return {
|
|
9
|
+
name: "analogjs-live-reload-plugin",
|
|
10
|
+
apply: "serve",
|
|
11
|
+
configureServer(server) {
|
|
12
|
+
const angularComponentMiddleware = async (req, res, next) => {
|
|
13
|
+
if (req.url === void 0 || res.writableEnded) return;
|
|
14
|
+
if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {
|
|
15
|
+
next();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const componentId = new URL(req.url, "http://localhost").searchParams.get("c");
|
|
19
|
+
if (!componentId) {
|
|
20
|
+
res.statusCode = 400;
|
|
21
|
+
res.end();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const [fileId] = decodeURIComponent(componentId).split("@");
|
|
25
|
+
const resolvedId = normalizePath(resolve(process.cwd(), fileId));
|
|
26
|
+
if (!(!!server.moduleGraph.getModuleById(resolvedId)?.lastInvalidationTimestamp && classNames.get(resolvedId))) {
|
|
27
|
+
debugHmr("middleware: skipped (not invalidated)", { resolvedId });
|
|
28
|
+
res.setHeader("Content-Type", "text/javascript");
|
|
29
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
30
|
+
res.end("");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const result = fileEmitter(resolvedId);
|
|
34
|
+
debugHmr("middleware: served component update", {
|
|
35
|
+
resolvedId,
|
|
36
|
+
hasCode: !!result?.hmrUpdateCode
|
|
37
|
+
});
|
|
38
|
+
res.setHeader("Content-Type", "text/javascript");
|
|
39
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
40
|
+
res.end(`${result?.hmrUpdateCode || ""}`);
|
|
41
|
+
};
|
|
42
|
+
server.middlewares.use(angularComponentMiddleware);
|
|
43
|
+
},
|
|
44
|
+
resolveId(id, _importer, options) {
|
|
45
|
+
if (options?.ssr && id.startsWith(FILE_PREFIX) && id.includes(ANGULAR_COMPONENT_PREFIX)) return `\0${id}`;
|
|
46
|
+
},
|
|
47
|
+
load(id, options) {
|
|
48
|
+
if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {
|
|
49
|
+
const componentId = new URL(id.slice(1), "http://localhost").searchParams.get("c");
|
|
50
|
+
if (!componentId) return;
|
|
51
|
+
return fileEmitter(normalizePath(resolve(process.cwd(), decodeURIComponent(componentId).split("@")[0])))?.hmrUpdateCode || "";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
63
55
|
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { liveReloadPlugin };
|
|
58
|
+
|
|
64
59
|
//# sourceMappingURL=live-reload-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-reload-plugin.js","
|
|
1
|
+
{"version":3,"file":"live-reload-plugin.js","names":[],"sources":["../../../src/lib/live-reload-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { ServerResponse } from 'node:http';\nimport { Connect, normalizePath, Plugin, ViteDevServer } from 'vite';\n\nimport { EmitFileResult } from './models.js';\nimport { debugHmr } from './utils/debug.js';\n\nconst ANGULAR_COMPONENT_PREFIX = '/@ng/component';\nconst FILE_PREFIX = 'file:';\n\nexport function liveReloadPlugin({\n classNames,\n fileEmitter,\n}: {\n classNames: Map<string, string>;\n fileEmitter: (file: string) => EmitFileResult | undefined;\n}): Plugin {\n return {\n name: 'analogjs-live-reload-plugin',\n apply: 'serve',\n configureServer(server: ViteDevServer) {\n const angularComponentMiddleware: Connect.HandleFunction = async (\n req: Connect.IncomingMessage,\n res: ServerResponse<Connect.IncomingMessage>,\n next: Connect.NextFunction,\n ) => {\n if (req.url === undefined || res.writableEnded) {\n return;\n }\n\n if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {\n next();\n\n return;\n }\n\n const requestUrl = new URL(req.url, 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n res.statusCode = 400;\n res.end();\n\n return;\n }\n\n const [fileId] = decodeURIComponent(componentId).split('@');\n const resolvedId = normalizePath(resolve(process.cwd(), fileId));\n const invalidated =\n !!server.moduleGraph.getModuleById(resolvedId)\n ?.lastInvalidationTimestamp && classNames.get(resolvedId);\n\n // don't send an HMR update until the file has been invalidated\n if (!invalidated) {\n debugHmr('middleware: skipped (not invalidated)', { resolvedId });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end('');\n return;\n }\n\n const result = fileEmitter(resolvedId);\n debugHmr('middleware: served component update', {\n resolvedId,\n hasCode: !!result?.hmrUpdateCode,\n });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end(`${result?.hmrUpdateCode || ''}`);\n };\n\n server.middlewares.use(angularComponentMiddleware);\n },\n resolveId(id, _importer, options) {\n if (\n options?.ssr &&\n id.startsWith(FILE_PREFIX) &&\n id.includes(ANGULAR_COMPONENT_PREFIX)\n ) {\n return `\\0${id}`;\n }\n\n return undefined;\n },\n load(id, options) {\n if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {\n const requestUrl = new URL(id.slice(1), 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n return;\n }\n\n const result = fileEmitter(\n normalizePath(\n resolve(\n process.cwd(),\n decodeURIComponent(componentId).split('@')[0],\n ),\n ),\n );\n\n return result?.hmrUpdateCode || '';\n }\n\n return;\n },\n };\n}\n"],"mappings":";;;;AAOA,IAAM,2BAA2B;AACjC,IAAM,cAAc;AAEpB,SAAgB,iBAAiB,EAC/B,YACA,eAIS;AACT,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,QAAuB;GACrC,MAAM,6BAAqD,OACzD,KACA,KACA,SACG;AACH,QAAI,IAAI,QAAQ,KAAA,KAAa,IAAI,cAC/B;AAGF,QAAI,CAAC,IAAI,IAAI,SAAS,yBAAyB,EAAE;AAC/C,WAAM;AAEN;;IAIF,MAAM,cADa,IAAI,IAAI,IAAI,KAAK,mBAAmB,CACxB,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,aAAa;AAChB,SAAI,aAAa;AACjB,SAAI,KAAK;AAET;;IAGF,MAAM,CAAC,UAAU,mBAAmB,YAAY,CAAC,MAAM,IAAI;IAC3D,MAAM,aAAa,cAAc,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC;AAMhE,QAAI,EAJF,CAAC,CAAC,OAAO,YAAY,cAAc,WAAW,EAC1C,6BAA6B,WAAW,IAAI,WAAW,GAG3C;AAChB,cAAS,yCAAyC,EAAE,YAAY,CAAC;AACjE,SAAI,UAAU,gBAAgB,kBAAkB;AAChD,SAAI,UAAU,iBAAiB,WAAW;AAC1C,SAAI,IAAI,GAAG;AACX;;IAGF,MAAM,SAAS,YAAY,WAAW;AACtC,aAAS,uCAAuC;KAC9C;KACA,SAAS,CAAC,CAAC,QAAQ;KACpB,CAAC;AACF,QAAI,UAAU,gBAAgB,kBAAkB;AAChD,QAAI,UAAU,iBAAiB,WAAW;AAC1C,QAAI,IAAI,GAAG,QAAQ,iBAAiB,KAAK;;AAG3C,UAAO,YAAY,IAAI,2BAA2B;;EAEpD,UAAU,IAAI,WAAW,SAAS;AAChC,OACE,SAAS,OACT,GAAG,WAAW,YAAY,IAC1B,GAAG,SAAS,yBAAyB,CAErC,QAAO,KAAK;;EAKhB,KAAK,IAAI,SAAS;AAChB,OAAI,SAAS,OAAO,GAAG,SAAS,yBAAyB,EAAE;IAEzD,MAAM,cADa,IAAI,IAAI,GAAG,MAAM,EAAE,EAAE,mBAAmB,CAC5B,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,YACH;AAYF,WATe,YACb,cACE,QACE,QAAQ,KAAK,EACb,mBAAmB,YAAY,CAAC,MAAM,IAAI,CAAC,GAC5C,CACF,CACF,EAEc,iBAAiB;;;EAKrC"}
|
package/src/lib/models.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type ts from
|
|
1
|
+
import type ts from "typescript";
|
|
2
2
|
export interface EmitFileResult {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
content?: string;
|
|
4
|
+
map?: string;
|
|
5
|
+
dependencies: readonly string[];
|
|
6
|
+
hash?: Uint8Array;
|
|
7
|
+
errors?: (string | ts.DiagnosticMessageChain)[];
|
|
8
|
+
warnings?: (string | ts.DiagnosticMessageChain)[];
|
|
9
|
+
hmrUpdateCode?: string | null;
|
|
10
|
+
hmrEligible?: boolean | null;
|
|
11
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
* Ignores anything in the .nx folder from triggering HMR
|
|
4
|
+
*
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
7
|
export declare function nxFolderPlugin(): Plugin;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { normalizePath } from
|
|
1
|
+
import { normalizePath } from "vite";
|
|
2
|
+
//#region packages/vite-plugin-angular/src/lib/nx-folder-plugin.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
};
|
|
4
|
+
* Ignores anything in the .nx folder from triggering HMR
|
|
5
|
+
*
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
function nxFolderPlugin() {
|
|
9
|
+
return {
|
|
10
|
+
name: "analogjs-nx-folder-plugin",
|
|
11
|
+
apply: "serve",
|
|
12
|
+
handleHotUpdate(ctx) {
|
|
13
|
+
if (ctx.file.includes(normalizePath("/.nx/"))) return [];
|
|
14
|
+
return ctx.modules;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
18
17
|
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { nxFolderPlugin };
|
|
20
|
+
|
|
19
21
|
//# sourceMappingURL=nx-folder-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-folder-plugin.js","
|
|
1
|
+
{"version":3,"file":"nx-folder-plugin.js","names":[],"sources":["../../../src/lib/nx-folder-plugin.ts"],"sourcesContent":["import { normalizePath, Plugin } from 'vite';\n\n/**\n * Ignores anything in the .nx folder from triggering HMR\n *\n * @returns\n */\nexport function nxFolderPlugin(): Plugin {\n return {\n name: 'analogjs-nx-folder-plugin',\n apply: 'serve',\n handleHotUpdate(ctx) {\n if (ctx.file.includes(normalizePath('/.nx/'))) {\n return [];\n }\n\n return ctx.modules;\n },\n };\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,iBAAyB;AACvC,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,KAAK;AACnB,OAAI,IAAI,KAAK,SAAS,cAAc,QAAQ,CAAC,CAC3C,QAAO,EAAE;AAGX,UAAO,IAAI;;EAEd"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
2
|
export declare function replaceFiles(replacements: FileReplacement[], workspaceRoot: string): Plugin | false;
|
|
3
3
|
export type FileReplacement = FileReplacementWith | FileReplacementSSR;
|
|
4
4
|
export interface FileReplacementBase {
|
|
5
|
-
|
|
5
|
+
replace: string;
|
|
6
6
|
}
|
|
7
7
|
export interface FileReplacementWith extends FileReplacementBase {
|
|
8
|
-
|
|
8
|
+
with: string;
|
|
9
9
|
}
|
|
10
10
|
export interface FileReplacementSSR extends FileReplacementBase {
|
|
11
|
-
|
|
11
|
+
ssr: string;
|
|
12
12
|
}
|
|
@@ -1,64 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
import { isAbsolute, resolve } from
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const foundReplace = mappedReplacements.find((replacement) => resolved?.id?.endsWith(replacement.replace));
|
|
39
|
-
if (foundReplace) {
|
|
40
|
-
try {
|
|
41
|
-
if (this.environment.name === 'ssr' && foundReplace.ssr) {
|
|
42
|
-
// return new file id for ssr
|
|
43
|
-
return {
|
|
44
|
-
id: foundReplace.ssr,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
else if (foundReplace.ssr) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
// return new file id
|
|
51
|
-
return {
|
|
52
|
-
id: foundReplace.with,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
console.error(err);
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return null;
|
|
61
|
-
},
|
|
62
|
-
};
|
|
1
|
+
import { debugCompiler } from "../utils/debug.js";
|
|
2
|
+
import { isAbsolute, resolve } from "node:path";
|
|
3
|
+
//#region packages/vite-plugin-angular/src/lib/plugins/file-replacements.plugin.ts
|
|
4
|
+
function replaceFiles(replacements, workspaceRoot) {
|
|
5
|
+
if (!replacements?.length) return false;
|
|
6
|
+
return {
|
|
7
|
+
name: "rollup-plugin-replace-files",
|
|
8
|
+
enforce: "pre",
|
|
9
|
+
async resolveId(source, importer, options) {
|
|
10
|
+
const resolved = await this.resolve(source, importer, {
|
|
11
|
+
...options,
|
|
12
|
+
skipSelf: true
|
|
13
|
+
});
|
|
14
|
+
const foundReplace = replacements.map((fr) => {
|
|
15
|
+
const frSSR = fr;
|
|
16
|
+
const frWith = fr;
|
|
17
|
+
return {
|
|
18
|
+
...fr,
|
|
19
|
+
ssr: frSSR.ssr ? isAbsolute(frSSR.ssr) ? frSSR.ssr : resolve(workspaceRoot, frSSR.ssr) : "",
|
|
20
|
+
with: frWith.with ? isAbsolute(frWith.with) ? frWith.with : resolve(workspaceRoot, frWith.with) : ""
|
|
21
|
+
};
|
|
22
|
+
}).find((replacement) => resolved?.id?.endsWith(replacement.replace));
|
|
23
|
+
if (foundReplace) try {
|
|
24
|
+
if (this.environment.name === "ssr" && foundReplace.ssr) return { id: foundReplace.ssr };
|
|
25
|
+
else if (foundReplace.ssr) return null;
|
|
26
|
+
return { id: foundReplace.with };
|
|
27
|
+
} catch (err) {
|
|
28
|
+
debugCompiler("file replacement error", {
|
|
29
|
+
error: String(err),
|
|
30
|
+
source,
|
|
31
|
+
importer
|
|
32
|
+
});
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
63
38
|
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { replaceFiles };
|
|
41
|
+
|
|
64
42
|
//# sourceMappingURL=file-replacements.plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-replacements.plugin.js","
|
|
1
|
+
{"version":3,"file":"file-replacements.plugin.js","names":[],"sources":["../../../../src/lib/plugins/file-replacements.plugin.ts"],"sourcesContent":["// source: https://github.com/Myrmod/vitejs-theming/blob/master/build-plugins/rollup/replace-files.js\nimport { isAbsolute, resolve } from 'node:path';\nimport { Plugin } from 'vite';\nimport { debugCompiler } from '../utils/debug.js';\n\nexport function replaceFiles(\n replacements: FileReplacement[],\n workspaceRoot: string,\n): Plugin | false {\n if (!replacements?.length) {\n return false;\n }\n\n return {\n name: 'rollup-plugin-replace-files',\n enforce: 'pre',\n async resolveId(source, importer, options) {\n const resolved = await this.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n /**\n * The reason we're using endsWith here is because the resolved id\n * will be the absolute path to the file. We want to check if the\n * file ends with the file we're trying to replace, which will be essentially\n * the path from the root of our workspace.\n */\n const mappedReplacements = replacements.map((fr: FileReplacement) => {\n const frSSR = fr as FileReplacementSSR;\n const frWith = fr as FileReplacementWith;\n\n return {\n ...fr,\n ssr: frSSR.ssr\n ? isAbsolute(frSSR.ssr)\n ? frSSR.ssr\n : resolve(workspaceRoot, frSSR.ssr)\n : '',\n with: frWith.with\n ? isAbsolute(frWith.with)\n ? frWith.with\n : resolve(workspaceRoot, frWith.with)\n : '',\n };\n });\n const foundReplace = mappedReplacements.find((replacement) =>\n resolved?.id?.endsWith(replacement.replace),\n );\n if (foundReplace) {\n try {\n if (this.environment.name === 'ssr' && foundReplace.ssr) {\n // return new file id for ssr\n return {\n id: foundReplace.ssr,\n };\n } else if (foundReplace.ssr) {\n return null;\n }\n\n // return new file id\n return {\n id: foundReplace.with,\n };\n } catch (err) {\n debugCompiler('file replacement error', {\n error: String(err),\n source,\n importer,\n });\n return null;\n }\n }\n return null;\n },\n };\n}\n\nexport type FileReplacement = FileReplacementWith | FileReplacementSSR;\n\nexport interface FileReplacementBase {\n replace: string;\n}\nexport interface FileReplacementWith extends FileReplacementBase {\n with: string;\n}\n\nexport interface FileReplacementSSR extends FileReplacementBase {\n ssr: string;\n}\n"],"mappings":";;;AAKA,SAAgB,aACd,cACA,eACgB;AAChB,KAAI,CAAC,cAAc,OACjB,QAAO;AAGT,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,UAAU,QAAQ,UAAU,SAAS;GACzC,MAAM,WAAW,MAAM,KAAK,QAAQ,QAAQ,UAAU;IACpD,GAAG;IACH,UAAU;IACX,CAAC;GAyBF,MAAM,eAlBqB,aAAa,KAAK,OAAwB;IACnE,MAAM,QAAQ;IACd,MAAM,SAAS;AAEf,WAAO;KACL,GAAG;KACH,KAAK,MAAM,MACP,WAAW,MAAM,IAAI,GACnB,MAAM,MACN,QAAQ,eAAe,MAAM,IAAI,GACnC;KACJ,MAAM,OAAO,OACT,WAAW,OAAO,KAAK,GACrB,OAAO,OACP,QAAQ,eAAe,OAAO,KAAK,GACrC;KACL;KACD,CACsC,MAAM,gBAC5C,UAAU,IAAI,SAAS,YAAY,QAAQ,CAC5C;AACD,OAAI,aACF,KAAI;AACF,QAAI,KAAK,YAAY,SAAS,SAAS,aAAa,IAElD,QAAO,EACL,IAAI,aAAa,KAClB;aACQ,aAAa,IACtB,QAAO;AAIT,WAAO,EACL,IAAI,aAAa,MAClB;YACM,KAAK;AACZ,kBAAc,0BAA0B;KACtC,OAAO,OAAO,IAAI;KAClB;KACA;KACD,CAAC;AACF,WAAO;;AAGX,UAAO;;EAEV"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Plugin } from
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
2
|
export declare function routerPlugin(): Plugin;
|
package/src/lib/router-plugin.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
};
|
|
1
|
+
import { jt } from "./utils/devkit.js";
|
|
2
|
+
//#region packages/vite-plugin-angular/src/lib/router-plugin.ts
|
|
3
|
+
function routerPlugin() {
|
|
4
|
+
const javascriptTransformer = new jt({ jit: true }, 1);
|
|
5
|
+
/**
|
|
6
|
+
* Transforms Angular packages the didn't get picked up by Vite's pre-optimization.
|
|
7
|
+
*/
|
|
8
|
+
return {
|
|
9
|
+
name: "analogjs-router-optimization",
|
|
10
|
+
enforce: "pre",
|
|
11
|
+
apply: "serve",
|
|
12
|
+
transform: {
|
|
13
|
+
filter: { id: /fesm(.*?)\.mjs/ },
|
|
14
|
+
async handler(_code, id) {
|
|
15
|
+
const path = id.split("?")[0];
|
|
16
|
+
const contents = await javascriptTransformer.transformFile(path);
|
|
17
|
+
return { code: Buffer.from(contents).toString("utf-8") };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
24
21
|
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { routerPlugin };
|
|
24
|
+
|
|
25
25
|
//# sourceMappingURL=router-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-plugin.js","
|
|
1
|
+
{"version":3,"file":"router-plugin.js","names":[],"sources":["../../../src/lib/router-plugin.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport { JavaScriptTransformer } from './utils/devkit.js';\n\nexport function routerPlugin(): Plugin {\n const javascriptTransformer = new JavaScriptTransformer({ jit: true }, 1);\n\n /**\n * Transforms Angular packages the didn't get picked up by Vite's pre-optimization.\n */\n return {\n name: 'analogjs-router-optimization',\n enforce: 'pre',\n apply: 'serve',\n transform: {\n filter: {\n id: /fesm(.*?)\\.mjs/,\n },\n async handler(_code: string, id: string) {\n const path = id.split('?')[0];\n const contents = await javascriptTransformer.transformFile(path);\n\n return {\n code: Buffer.from(contents).toString('utf-8'),\n };\n },\n },\n };\n}\n"],"mappings":";;AAGA,SAAgB,eAAuB;CACrC,MAAM,wBAAwB,IAAI,GAAsB,EAAE,KAAK,MAAM,EAAE,EAAE;;;;AAKzE,QAAO;EACL,MAAM;EACN,SAAS;EACT,OAAO;EACP,WAAW;GACT,QAAQ,EACN,IAAI,kBACL;GACD,MAAM,QAAQ,OAAe,IAAY;IACvC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;IAC3B,MAAM,WAAW,MAAM,sBAAsB,cAAc,KAAK;AAEhE,WAAO,EACL,MAAM,OAAO,KAAK,SAAS,CAAC,SAAS,QAAQ,EAC9C;;GAEJ;EACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnalogStylesheetRegistry } from "./stylesheet-registry.js";
|
|
2
|
+
import type { StylePipelineStylesheetRegistry, StylePreprocessor, StylesheetTransformContext, StylesheetTransformResult } from "./style-preprocessor.js";
|
|
3
|
+
export interface AngularStylePipelineContext {
|
|
4
|
+
workspaceRoot: string;
|
|
5
|
+
}
|
|
6
|
+
export interface AngularStylePipelinePlugin {
|
|
7
|
+
name: string;
|
|
8
|
+
preprocessStylesheet?: (code: string, context: StylesheetTransformContext) => string | StylesheetTransformResult | undefined;
|
|
9
|
+
configureStylesheetRegistry?: (registry: StylePipelineStylesheetRegistry, context: AngularStylePipelineContext) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface AngularStylePipelineOptions {
|
|
12
|
+
plugins: AngularStylePipelinePlugin[];
|
|
13
|
+
}
|
|
14
|
+
export declare function stylePipelinePreprocessorFromPlugins(options: AngularStylePipelineOptions | undefined): StylePreprocessor | undefined;
|
|
15
|
+
export declare function configureStylePipelineRegistry(options: AngularStylePipelineOptions | undefined, registry: AnalogStylesheetRegistry, context: AngularStylePipelineContext): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { debugStylePipeline } from "./utils/debug.js";
|
|
2
|
+
import { normalizeStylesheetTransformResult } from "./style-preprocessor.js";
|
|
3
|
+
//#region packages/vite-plugin-angular/src/lib/style-pipeline.ts
|
|
4
|
+
function stylePipelinePreprocessorFromPlugins(options) {
|
|
5
|
+
const preprocessors = options?.plugins.map((plugin) => plugin.preprocessStylesheet).filter((preprocessor) => !!preprocessor) ?? [];
|
|
6
|
+
if (!preprocessors.length) return;
|
|
7
|
+
return (code, filename, context) => {
|
|
8
|
+
if (!context) {
|
|
9
|
+
debugStylePipeline("skipping community stylesheet preprocessors because Angular did not provide a stylesheet context", { filename });
|
|
10
|
+
return code;
|
|
11
|
+
}
|
|
12
|
+
let current = normalizeStylesheetTransformResult(void 0, code);
|
|
13
|
+
for (const preprocess of preprocessors) {
|
|
14
|
+
const next = normalizeStylesheetTransformResult(preprocess(current.code, context), current.code);
|
|
15
|
+
current = {
|
|
16
|
+
code: next.code,
|
|
17
|
+
dependencies: [...current.dependencies ?? [], ...next.dependencies ?? []],
|
|
18
|
+
diagnostics: [...current.diagnostics ?? [], ...next.diagnostics ?? []],
|
|
19
|
+
tags: [...current.tags ?? [], ...next.tags ?? []]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return current;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function configureStylePipelineRegistry(options, registry, context) {
|
|
26
|
+
for (const plugin of options?.plugins ?? []) plugin.configureStylesheetRegistry?.(registry, context);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { configureStylePipelineRegistry, stylePipelinePreprocessorFromPlugins };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=style-pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-pipeline.js","names":[],"sources":["../../../src/lib/style-pipeline.ts"],"sourcesContent":["import type { AnalogStylesheetRegistry } from './stylesheet-registry.js';\nimport type {\n StylePipelineStylesheetRegistry,\n StylePreprocessor,\n StylesheetTransformContext,\n StylesheetTransformResult,\n} from './style-preprocessor.js';\nimport { normalizeStylesheetTransformResult } from './style-preprocessor.js';\nimport { debugStylePipeline } from './utils/debug.js';\n\nexport interface AngularStylePipelineContext {\n workspaceRoot: string;\n}\n\nexport interface AngularStylePipelinePlugin {\n name: string;\n preprocessStylesheet?: (\n code: string,\n context: StylesheetTransformContext,\n ) => string | StylesheetTransformResult | undefined;\n configureStylesheetRegistry?: (\n registry: StylePipelineStylesheetRegistry,\n context: AngularStylePipelineContext,\n ) => void;\n}\n\nexport interface AngularStylePipelineOptions {\n plugins: AngularStylePipelinePlugin[];\n}\n\nexport function stylePipelinePreprocessorFromPlugins(\n options: AngularStylePipelineOptions | undefined,\n): StylePreprocessor | undefined {\n const preprocessors =\n options?.plugins\n .map((plugin) => plugin.preprocessStylesheet)\n .filter((preprocessor) => !!preprocessor) ?? [];\n\n if (!preprocessors.length) {\n return undefined;\n }\n\n return (code, filename, context) => {\n if (!context) {\n debugStylePipeline(\n 'skipping community stylesheet preprocessors because Angular did not provide a stylesheet context',\n {\n filename,\n },\n );\n return code;\n }\n\n let current = normalizeStylesheetTransformResult(undefined, code);\n for (const preprocess of preprocessors) {\n const next = normalizeStylesheetTransformResult(\n preprocess(current.code, context),\n current.code,\n );\n current = {\n code: next.code,\n dependencies: [\n ...(current.dependencies ?? []),\n ...(next.dependencies ?? []),\n ],\n diagnostics: [\n ...(current.diagnostics ?? []),\n ...(next.diagnostics ?? []),\n ],\n tags: [...(current.tags ?? []), ...(next.tags ?? [])],\n };\n }\n\n return current;\n };\n}\n\nexport function configureStylePipelineRegistry(\n options: AngularStylePipelineOptions | undefined,\n registry: AnalogStylesheetRegistry,\n context: AngularStylePipelineContext,\n): void {\n for (const plugin of options?.plugins ?? []) {\n plugin.configureStylesheetRegistry?.(registry, context);\n }\n}\n"],"mappings":";;;AA8BA,SAAgB,qCACd,SAC+B;CAC/B,MAAM,gBACJ,SAAS,QACN,KAAK,WAAW,OAAO,qBAAqB,CAC5C,QAAQ,iBAAiB,CAAC,CAAC,aAAa,IAAI,EAAE;AAEnD,KAAI,CAAC,cAAc,OACjB;AAGF,SAAQ,MAAM,UAAU,YAAY;AAClC,MAAI,CAAC,SAAS;AACZ,sBACE,oGACA,EACE,UACD,CACF;AACD,UAAO;;EAGT,IAAI,UAAU,mCAAmC,KAAA,GAAW,KAAK;AACjE,OAAK,MAAM,cAAc,eAAe;GACtC,MAAM,OAAO,mCACX,WAAW,QAAQ,MAAM,QAAQ,EACjC,QAAQ,KACT;AACD,aAAU;IACR,MAAM,KAAK;IACX,cAAc,CACZ,GAAI,QAAQ,gBAAgB,EAAE,EAC9B,GAAI,KAAK,gBAAgB,EAAE,CAC5B;IACD,aAAa,CACX,GAAI,QAAQ,eAAe,EAAE,EAC7B,GAAI,KAAK,eAAe,EAAE,CAC3B;IACD,MAAM,CAAC,GAAI,QAAQ,QAAQ,EAAE,EAAG,GAAI,KAAK,QAAQ,EAAE,CAAE;IACtD;;AAGH,SAAO;;;AAIX,SAAgB,+BACd,SACA,UACA,SACM;AACN,MAAK,MAAM,UAAU,SAAS,WAAW,EAAE,CACzC,QAAO,8BAA8B,UAAU,QAAQ"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface StylesheetTransformContext {
|
|
2
|
+
filename: string;
|
|
3
|
+
containingFile?: string;
|
|
4
|
+
resourceFile?: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
order?: number;
|
|
7
|
+
inline: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface StylesheetDependency {
|
|
10
|
+
id: string;
|
|
11
|
+
kind?: "file" | "virtual" | "token" | "bridge" | "manifest" | "runtime";
|
|
12
|
+
owner?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface StylesheetDiagnostic {
|
|
15
|
+
severity: "warning" | "error";
|
|
16
|
+
code: string;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
export interface StylesheetTransformResult {
|
|
20
|
+
code: string;
|
|
21
|
+
dependencies?: Array<string | StylesheetDependency>;
|
|
22
|
+
diagnostics?: StylesheetDiagnostic[];
|
|
23
|
+
tags?: string[];
|
|
24
|
+
}
|
|
25
|
+
export interface StylePipelineStylesheetRegistry {
|
|
26
|
+
getPublicIdsForSource(sourcePath: string): string[];
|
|
27
|
+
getRequestIdsForSource(sourcePath: string): string[];
|
|
28
|
+
getDependenciesForSource(sourcePath: string): StylesheetDependency[];
|
|
29
|
+
getDiagnosticsForSource(sourcePath: string): StylesheetDiagnostic[];
|
|
30
|
+
getTagsForSource(sourcePath: string): string[];
|
|
31
|
+
}
|
|
32
|
+
export type StylePreprocessor = (code: string, filename: string, context?: StylesheetTransformContext) => string | StylesheetTransformResult;
|
|
33
|
+
export declare function normalizeStylesheetTransformResult(value: string | StylesheetTransformResult | undefined, fallbackCode: string): StylesheetTransformResult;
|
|
34
|
+
export declare function normalizeStylesheetDependencies(dependencies: Array<string | StylesheetDependency> | undefined): StylesheetDependency[];
|
|
35
|
+
export declare function composeStylePreprocessors(preprocessors: Array<StylePreprocessor | false | null | undefined>): StylePreprocessor | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region packages/vite-plugin-angular/src/lib/style-preprocessor.ts
|
|
2
|
+
function normalizeStylesheetTransformResult(value, fallbackCode) {
|
|
3
|
+
if (value == null) return { code: fallbackCode };
|
|
4
|
+
if (typeof value === "string") return { code: value };
|
|
5
|
+
return {
|
|
6
|
+
code: value.code ?? fallbackCode,
|
|
7
|
+
dependencies: normalizeStylesheetDependencies(value.dependencies),
|
|
8
|
+
diagnostics: value.diagnostics ?? [],
|
|
9
|
+
tags: value.tags ?? []
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function normalizeStylesheetDependencies(dependencies) {
|
|
13
|
+
return (dependencies ?? []).map((dependency) => typeof dependency === "string" ? { id: dependency } : dependency);
|
|
14
|
+
}
|
|
15
|
+
function composeStylePreprocessors(preprocessors) {
|
|
16
|
+
const active = preprocessors.filter((preprocessor) => !!preprocessor);
|
|
17
|
+
if (!active.length) return;
|
|
18
|
+
return (code, filename, context) => {
|
|
19
|
+
let current = normalizeStylesheetTransformResult(void 0, code);
|
|
20
|
+
for (const preprocessor of active) {
|
|
21
|
+
const next = normalizeStylesheetTransformResult(preprocessor(current.code, filename, context), current.code);
|
|
22
|
+
current = {
|
|
23
|
+
code: next.code,
|
|
24
|
+
dependencies: [...current.dependencies ?? [], ...next.dependencies ?? []],
|
|
25
|
+
diagnostics: [...current.diagnostics ?? [], ...next.diagnostics ?? []],
|
|
26
|
+
tags: [...current.tags ?? [], ...next.tags ?? []]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return current;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { composeStylePreprocessors, normalizeStylesheetDependencies, normalizeStylesheetTransformResult };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=style-preprocessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-preprocessor.js","names":[],"sources":["../../../src/lib/style-preprocessor.ts"],"sourcesContent":["export interface StylesheetTransformContext {\n filename: string;\n containingFile?: string;\n resourceFile?: string;\n className?: string;\n order?: number;\n inline: boolean;\n}\n\nexport interface StylesheetDependency {\n id: string;\n kind?: 'file' | 'virtual' | 'token' | 'bridge' | 'manifest' | 'runtime';\n owner?: string;\n}\n\nexport interface StylesheetDiagnostic {\n severity: 'warning' | 'error';\n code: string;\n message: string;\n}\n\nexport interface StylesheetTransformResult {\n code: string;\n dependencies?: Array<string | StylesheetDependency>;\n diagnostics?: StylesheetDiagnostic[];\n tags?: string[];\n}\n\nexport interface StylePipelineStylesheetRegistry {\n getPublicIdsForSource(sourcePath: string): string[];\n getRequestIdsForSource(sourcePath: string): string[];\n getDependenciesForSource(sourcePath: string): StylesheetDependency[];\n getDiagnosticsForSource(sourcePath: string): StylesheetDiagnostic[];\n getTagsForSource(sourcePath: string): string[];\n}\n\nexport type StylePreprocessor = (\n code: string,\n filename: string,\n context?: StylesheetTransformContext,\n) => string | StylesheetTransformResult;\n\nexport function normalizeStylesheetTransformResult(\n value: string | StylesheetTransformResult | undefined,\n fallbackCode: string,\n): StylesheetTransformResult {\n if (value == null) {\n return { code: fallbackCode };\n }\n\n if (typeof value === 'string') {\n return { code: value };\n }\n\n return {\n code: value.code ?? fallbackCode,\n dependencies: normalizeStylesheetDependencies(value.dependencies),\n diagnostics: value.diagnostics ?? [],\n tags: value.tags ?? [],\n };\n}\n\nexport function normalizeStylesheetDependencies(\n dependencies: Array<string | StylesheetDependency> | undefined,\n): StylesheetDependency[] {\n return (dependencies ?? []).map((dependency) =>\n typeof dependency === 'string' ? { id: dependency } : dependency,\n );\n}\n\nexport function composeStylePreprocessors(\n preprocessors: Array<StylePreprocessor | false | null | undefined>,\n): StylePreprocessor | undefined {\n const active = preprocessors.filter(\n (preprocessor): preprocessor is StylePreprocessor => !!preprocessor,\n );\n\n if (!active.length) {\n return undefined;\n }\n\n return (code, filename, context) => {\n let current = normalizeStylesheetTransformResult(undefined, code);\n\n for (const preprocessor of active) {\n const next = normalizeStylesheetTransformResult(\n preprocessor(current.code, filename, context),\n current.code,\n );\n current = {\n code: next.code,\n dependencies: [\n ...(current.dependencies ?? []),\n ...(next.dependencies ?? []),\n ],\n diagnostics: [\n ...(current.diagnostics ?? []),\n ...(next.diagnostics ?? []),\n ],\n tags: [...(current.tags ?? []), ...(next.tags ?? [])],\n };\n }\n\n return current;\n };\n}\n"],"mappings":";AA0CA,SAAgB,mCACd,OACA,cAC2B;AAC3B,KAAI,SAAS,KACX,QAAO,EAAE,MAAM,cAAc;AAG/B,KAAI,OAAO,UAAU,SACnB,QAAO,EAAE,MAAM,OAAO;AAGxB,QAAO;EACL,MAAM,MAAM,QAAQ;EACpB,cAAc,gCAAgC,MAAM,aAAa;EACjE,aAAa,MAAM,eAAe,EAAE;EACpC,MAAM,MAAM,QAAQ,EAAE;EACvB;;AAGH,SAAgB,gCACd,cACwB;AACxB,SAAQ,gBAAgB,EAAE,EAAE,KAAK,eAC/B,OAAO,eAAe,WAAW,EAAE,IAAI,YAAY,GAAG,WACvD;;AAGH,SAAgB,0BACd,eAC+B;CAC/B,MAAM,SAAS,cAAc,QAC1B,iBAAoD,CAAC,CAAC,aACxD;AAED,KAAI,CAAC,OAAO,OACV;AAGF,SAAQ,MAAM,UAAU,YAAY;EAClC,IAAI,UAAU,mCAAmC,KAAA,GAAW,KAAK;AAEjE,OAAK,MAAM,gBAAgB,QAAQ;GACjC,MAAM,OAAO,mCACX,aAAa,QAAQ,MAAM,UAAU,QAAQ,EAC7C,QAAQ,KACT;AACD,aAAU;IACR,MAAM,KAAK;IACX,cAAc,CACZ,GAAI,QAAQ,gBAAgB,EAAE,EAC9B,GAAI,KAAK,gBAAgB,EAAE,CAC5B;IACD,aAAa,CACX,GAAI,QAAQ,eAAe,EAAE,EAC7B,GAAI,KAAK,eAAe,EAAE,CAC3B;IACD,MAAM,CAAC,GAAI,QAAQ,QAAQ,EAAE,EAAG,GAAI,KAAK,QAAQ,EAAE,CAAE;IACtD;;AAGH,SAAO"}
|