@staticbolt/wcp-staticbolt-plugin 1.0.0-beta.5
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/LICENSE +22 -0
- package/lib/index.d.mts +20 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +69 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +30 -0
- package/src/index.ts +101 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ahmed Alabsi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MetadataBase, Plugin } from "@staticbolt/core";
|
|
2
|
+
import { AcceptedPlugin } from "@staticbolt/wcp-core";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
interface WcpStaticBoltPluginOptions {
|
|
6
|
+
include?: string[];
|
|
7
|
+
exclude?: string[];
|
|
8
|
+
forceProduction?: boolean;
|
|
9
|
+
loadPostcssConfig?: boolean;
|
|
10
|
+
postcssPlugins?: AcceptedPlugin[];
|
|
11
|
+
}
|
|
12
|
+
interface WcpMetadata extends MetadataBase {
|
|
13
|
+
type: "WcpMetadata";
|
|
14
|
+
code: string;
|
|
15
|
+
}
|
|
16
|
+
declare function isWcpMetadata(metadata?: MetadataBase): metadata is WcpMetadata;
|
|
17
|
+
declare function wcpStaticBoltPlugin(options?: WcpStaticBoltPluginOptions): Plugin;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { WcpMetadata, WcpStaticBoltPluginOptions, isWcpMetadata, wcpStaticBoltPlugin };
|
|
20
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;UAMiB,0BAAA;EACf,OAAA;EACA,OAAA;EACA,eAAA;EACA,iBAAA;EACA,cAAA,GAAiB,cAAA;AAAA;AAAA,UAGF,WAAA,SAAoB,YAAA;EACnC,IAAA;EACA,IAAA;AAAA;AAAA,iBAGc,aAAA,CAAc,QAAA,GAAW,YAAA,GAAe,QAAA,IAAY,WAAA;AAAA,iBAIpD,mBAAA,CAAoB,OAAA,GAAS,0BAAA,GAAkC,MAAA"}
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DependencyTracker, isScriptMetadata, path } from "@staticbolt/core";
|
|
2
|
+
import { buildWebComponent } from "@staticbolt/wcp-core";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
function isWcpMetadata(metadata) {
|
|
6
|
+
return metadata?.type === "WcpMetadata";
|
|
7
|
+
}
|
|
8
|
+
function wcpStaticBoltPlugin(options = {}) {
|
|
9
|
+
const include = options.include ??= ["sources/components/**/*.ts"];
|
|
10
|
+
const ignore = options.exclude ??= ["**/*.d.ts"];
|
|
11
|
+
const deps = new DependencyTracker();
|
|
12
|
+
return {
|
|
13
|
+
name: "wcp-staticbolt-plugin",
|
|
14
|
+
async transform(metadata) {
|
|
15
|
+
if (!isScriptMetadata(metadata)) return;
|
|
16
|
+
if (!path.matchPath(metadata.id, {
|
|
17
|
+
include,
|
|
18
|
+
ignore,
|
|
19
|
+
root: this.root
|
|
20
|
+
})) return;
|
|
21
|
+
const filePath = metadata.id;
|
|
22
|
+
const production = options.forceProduction ?? this.production;
|
|
23
|
+
const [buildResult, buildError] = await buildWebComponent({
|
|
24
|
+
production,
|
|
25
|
+
filePath,
|
|
26
|
+
loadPostcssConfig: options.loadPostcssConfig,
|
|
27
|
+
postcssPlugins: options.postcssPlugins,
|
|
28
|
+
minifyCss: production,
|
|
29
|
+
minifyHtml: production,
|
|
30
|
+
minifyCssClasses: production,
|
|
31
|
+
minifyJs: false,
|
|
32
|
+
iife: false
|
|
33
|
+
});
|
|
34
|
+
if (buildError) {
|
|
35
|
+
this.log.error(buildError.message);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
metadata.ast = buildResult.ast;
|
|
39
|
+
const currentSources = /* @__PURE__ */ new Set();
|
|
40
|
+
for (const dependency of buildResult.embedded.html) {
|
|
41
|
+
const dep = path.normalize(dependency.filePath);
|
|
42
|
+
currentSources.add(dep);
|
|
43
|
+
metadata.directDependencies.add(dep);
|
|
44
|
+
this.watcher?.add(dep);
|
|
45
|
+
}
|
|
46
|
+
for (const dependency of buildResult.embedded.css) {
|
|
47
|
+
const dep = path.normalize(dependency.filePath);
|
|
48
|
+
currentSources.add(dep);
|
|
49
|
+
metadata.directDependencies.add(dep);
|
|
50
|
+
this.watcher?.add(dep);
|
|
51
|
+
}
|
|
52
|
+
deps.update(metadata.id, currentSources);
|
|
53
|
+
},
|
|
54
|
+
onFileEvent(event, id) {
|
|
55
|
+
if (event === "unlink") deps.delete(id);
|
|
56
|
+
},
|
|
57
|
+
resolveCompileList(compileSet, event) {
|
|
58
|
+
if (event !== "change") return;
|
|
59
|
+
for (const id of Array.from(compileSet)) {
|
|
60
|
+
const importers = deps.getImporters(id);
|
|
61
|
+
for (const importer of importers) compileSet.add(importer);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { isWcpMetadata, wcpStaticBoltPlugin };
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { DependencyTracker, isScriptMetadata, path } from \"@staticbolt/core\";\nimport { buildWebComponent } from \"@staticbolt/wcp-core\";\n\nimport type { MetadataBase, Plugin } from \"@staticbolt/core\";\nimport type { AcceptedPlugin } from \"@staticbolt/wcp-core\";\n\nexport interface WcpStaticBoltPluginOptions {\n include?: string[];\n exclude?: string[];\n forceProduction?: boolean;\n loadPostcssConfig?: boolean;\n postcssPlugins?: AcceptedPlugin[];\n}\n\nexport interface WcpMetadata extends MetadataBase {\n type: \"WcpMetadata\";\n code: string;\n}\n\nexport function isWcpMetadata(metadata?: MetadataBase): metadata is WcpMetadata {\n return metadata?.type === \"WcpMetadata\";\n}\n\nexport function wcpStaticBoltPlugin(options: WcpStaticBoltPluginOptions = {}): Plugin {\n const include = (options.include ??= [\"sources/components/**/*.ts\"]);\n const ignore = (options.exclude ??= [\"**/*.d.ts\"]);\n\n const deps = new DependencyTracker();\n\n return {\n name: \"wcp-staticbolt-plugin\",\n\n async transform(metadata) {\n if (!isScriptMetadata(metadata)) return;\n\n const isIncluded = path.matchPath(metadata.id, { include, ignore, root: this.root });\n if (!isIncluded) return;\n\n const filePath = metadata.id;\n\n const production = options.forceProduction ?? this.production;\n\n const [buildResult, buildError] = await buildWebComponent({\n production,\n filePath,\n loadPostcssConfig: options.loadPostcssConfig,\n postcssPlugins: options.postcssPlugins,\n minifyCss: production,\n minifyHtml: production,\n minifyCssClasses: production,\n minifyJs: false,\n iife: false,\n });\n\n if (buildError) {\n this.log.error(buildError.message);\n return;\n }\n\n metadata.ast = buildResult.ast;\n\n const currentSources = new Set<string>();\n\n for (const dependency of buildResult.embedded.html) {\n const dep = path.normalize(dependency.filePath);\n currentSources.add(dep);\n\n metadata.directDependencies.add(dep);\n this.watcher?.add(dep);\n }\n\n for (const dependency of buildResult.embedded.css) {\n const dep = path.normalize(dependency.filePath);\n currentSources.add(dep);\n\n metadata.directDependencies.add(dep);\n this.watcher?.add(dep);\n }\n\n deps.update(metadata.id, currentSources);\n },\n\n onFileEvent(event, id) {\n if (event === \"unlink\") {\n deps.delete(id);\n }\n },\n\n resolveCompileList(compileSet, event) {\n if (event !== \"change\") return;\n\n for (const id of Array.from(compileSet)) {\n const importers = deps.getImporters(id);\n\n for (const importer of importers) {\n compileSet.add(importer);\n }\n }\n },\n };\n}\n"],"mappings":";;;;AAmBA,SAAgB,cAAc,UAAkD;CAC9E,OAAO,UAAU,SAAS;;AAG5B,SAAgB,oBAAoB,UAAsC,EAAE,EAAU;CACpF,MAAM,UAAW,QAAQ,YAAY,CAAC,6BAA6B;CACnE,MAAM,SAAU,QAAQ,YAAY,CAAC,YAAY;CAEjD,MAAM,OAAO,IAAI,mBAAmB;CAEpC,OAAO;EACL,MAAM;EAEN,MAAM,UAAU,UAAU;GACxB,IAAI,CAAC,iBAAiB,SAAS,EAAE;GAGjC,IAAI,CADe,KAAK,UAAU,SAAS,IAAI;IAAE;IAAS;IAAQ,MAAM,KAAK;IAAM,CACpE,EAAE;GAEjB,MAAM,WAAW,SAAS;GAE1B,MAAM,aAAa,QAAQ,mBAAmB,KAAK;GAEnD,MAAM,CAAC,aAAa,cAAc,MAAM,kBAAkB;IACxD;IACA;IACA,mBAAmB,QAAQ;IAC3B,gBAAgB,QAAQ;IACxB,WAAW;IACX,YAAY;IACZ,kBAAkB;IAClB,UAAU;IACV,MAAM;IACP,CAAC;GAEF,IAAI,YAAY;IACd,KAAK,IAAI,MAAM,WAAW,QAAQ;IAClC;;GAGF,SAAS,MAAM,YAAY;GAE3B,MAAM,iCAAiB,IAAI,KAAa;GAExC,KAAK,MAAM,cAAc,YAAY,SAAS,MAAM;IAClD,MAAM,MAAM,KAAK,UAAU,WAAW,SAAS;IAC/C,eAAe,IAAI,IAAI;IAEvB,SAAS,mBAAmB,IAAI,IAAI;IACpC,KAAK,SAAS,IAAI,IAAI;;GAGxB,KAAK,MAAM,cAAc,YAAY,SAAS,KAAK;IACjD,MAAM,MAAM,KAAK,UAAU,WAAW,SAAS;IAC/C,eAAe,IAAI,IAAI;IAEvB,SAAS,mBAAmB,IAAI,IAAI;IACpC,KAAK,SAAS,IAAI,IAAI;;GAGxB,KAAK,OAAO,SAAS,IAAI,eAAe;;EAG1C,YAAY,OAAO,IAAI;GACrB,IAAI,UAAU,UACZ,KAAK,OAAO,GAAG;;EAInB,mBAAmB,YAAY,OAAO;GACpC,IAAI,UAAU,UAAU;GAExB,KAAK,MAAM,MAAM,MAAM,KAAK,WAAW,EAAE;IACvC,MAAM,YAAY,KAAK,aAAa,GAAG;IAEvC,KAAK,MAAM,YAAY,WACrB,WAAW,IAAI,SAAS;;;EAI/B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@staticbolt/wcp-staticbolt-plugin",
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Ahmed ALABSI",
|
|
7
|
+
"description": "staticbolt plugin for WCP web components",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"prepack": "npm run build",
|
|
10
|
+
"watch": "tsdown -w 'src/**/*.ts'",
|
|
11
|
+
"build": "tsdown"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./lib/index.d.mts",
|
|
17
|
+
"node": "./lib/index.mjs",
|
|
18
|
+
"default": "./lib/index.mjs"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"src"
|
|
25
|
+
],
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@staticbolt/core": "*",
|
|
28
|
+
"@staticbolt/wcp-core": "*"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { DependencyTracker, isScriptMetadata, path } from "@staticbolt/core";
|
|
2
|
+
import { buildWebComponent } from "@staticbolt/wcp-core";
|
|
3
|
+
|
|
4
|
+
import type { MetadataBase, Plugin } from "@staticbolt/core";
|
|
5
|
+
import type { AcceptedPlugin } from "@staticbolt/wcp-core";
|
|
6
|
+
|
|
7
|
+
export interface WcpStaticBoltPluginOptions {
|
|
8
|
+
include?: string[];
|
|
9
|
+
exclude?: string[];
|
|
10
|
+
forceProduction?: boolean;
|
|
11
|
+
loadPostcssConfig?: boolean;
|
|
12
|
+
postcssPlugins?: AcceptedPlugin[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface WcpMetadata extends MetadataBase {
|
|
16
|
+
type: "WcpMetadata";
|
|
17
|
+
code: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isWcpMetadata(metadata?: MetadataBase): metadata is WcpMetadata {
|
|
21
|
+
return metadata?.type === "WcpMetadata";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function wcpStaticBoltPlugin(options: WcpStaticBoltPluginOptions = {}): Plugin {
|
|
25
|
+
const include = (options.include ??= ["sources/components/**/*.ts"]);
|
|
26
|
+
const ignore = (options.exclude ??= ["**/*.d.ts"]);
|
|
27
|
+
|
|
28
|
+
const deps = new DependencyTracker();
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
name: "wcp-staticbolt-plugin",
|
|
32
|
+
|
|
33
|
+
async transform(metadata) {
|
|
34
|
+
if (!isScriptMetadata(metadata)) return;
|
|
35
|
+
|
|
36
|
+
const isIncluded = path.matchPath(metadata.id, { include, ignore, root: this.root });
|
|
37
|
+
if (!isIncluded) return;
|
|
38
|
+
|
|
39
|
+
const filePath = metadata.id;
|
|
40
|
+
|
|
41
|
+
const production = options.forceProduction ?? this.production;
|
|
42
|
+
|
|
43
|
+
const [buildResult, buildError] = await buildWebComponent({
|
|
44
|
+
production,
|
|
45
|
+
filePath,
|
|
46
|
+
loadPostcssConfig: options.loadPostcssConfig,
|
|
47
|
+
postcssPlugins: options.postcssPlugins,
|
|
48
|
+
minifyCss: production,
|
|
49
|
+
minifyHtml: production,
|
|
50
|
+
minifyCssClasses: production,
|
|
51
|
+
minifyJs: false,
|
|
52
|
+
iife: false,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (buildError) {
|
|
56
|
+
this.log.error(buildError.message);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
metadata.ast = buildResult.ast;
|
|
61
|
+
|
|
62
|
+
const currentSources = new Set<string>();
|
|
63
|
+
|
|
64
|
+
for (const dependency of buildResult.embedded.html) {
|
|
65
|
+
const dep = path.normalize(dependency.filePath);
|
|
66
|
+
currentSources.add(dep);
|
|
67
|
+
|
|
68
|
+
metadata.directDependencies.add(dep);
|
|
69
|
+
this.watcher?.add(dep);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const dependency of buildResult.embedded.css) {
|
|
73
|
+
const dep = path.normalize(dependency.filePath);
|
|
74
|
+
currentSources.add(dep);
|
|
75
|
+
|
|
76
|
+
metadata.directDependencies.add(dep);
|
|
77
|
+
this.watcher?.add(dep);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
deps.update(metadata.id, currentSources);
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
onFileEvent(event, id) {
|
|
84
|
+
if (event === "unlink") {
|
|
85
|
+
deps.delete(id);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
resolveCompileList(compileSet, event) {
|
|
90
|
+
if (event !== "change") return;
|
|
91
|
+
|
|
92
|
+
for (const id of Array.from(compileSet)) {
|
|
93
|
+
const importers = deps.getImporters(id);
|
|
94
|
+
|
|
95
|
+
for (const importer of importers) {
|
|
96
|
+
compileSet.add(importer);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|