@staticbolt/wcp-staticbolt-plugin 1.0.0-beta.5 → 1.0.0-beta.7

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/lib/index.d.mts CHANGED
@@ -1,20 +1,50 @@
1
- import { MetadataBase, Plugin } from "@staticbolt/core";
1
+ import { Plugin } from "@staticbolt/core";
2
2
  import { AcceptedPlugin } from "@staticbolt/wcp-core";
3
3
 
4
4
  //#region src/index.d.ts
5
5
  interface WcpStaticBoltPluginOptions {
6
- include?: string[];
6
+ /** Glob patterns for web component `.ts` files to process. */
7
+ include: string[];
8
+ /** Glob patterns for files to exclude from processing. */
7
9
  exclude?: string[];
10
+ /** Forces the plugin to run in production mode regardless of environment. */
8
11
  forceProduction?: boolean;
12
+ /** Loads the local PostCSS config file and applies its plugins. */
9
13
  loadPostcssConfig?: boolean;
10
- postcssPlugins?: AcceptedPlugin[];
14
+ /** Additional PostCSS plugins to apply during processing. */
15
+ postcssPlugins?: readonly AcceptedPlugin[];
16
+ /**
17
+ * Wraps the generated component bundle in an IIFE.
18
+ *
19
+ * @default false
20
+ */
21
+ iife?: boolean;
22
+ /**
23
+ * Minifies component CSS output.
24
+ *
25
+ * Defaults to `true` in production mode.
26
+ */
27
+ minifyCSS?: boolean;
28
+ /**
29
+ * Minifies component HTML output.
30
+ *
31
+ * Defaults to `true` in production mode.
32
+ */
33
+ minifyHTML?: boolean;
34
+ /**
35
+ * Minifies generated CSS class names.
36
+ *
37
+ * Defaults to `true` in production mode.
38
+ */
39
+ minifyCssClasses?: boolean;
40
+ /**
41
+ * Minifies generated CSS variable names.
42
+ *
43
+ * Defaults to `true` in production mode.
44
+ */
45
+ minifyCssVariables?: boolean;
11
46
  }
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;
47
+ declare function wcpStaticBoltPlugin(options: WcpStaticBoltPluginOptions): Plugin;
18
48
  //#endregion
19
- export { WcpMetadata, WcpStaticBoltPluginOptions, isWcpMetadata, wcpStaticBoltPlugin };
49
+ export { WcpStaticBoltPluginOptions, wcpStaticBoltPlugin };
20
50
  //# sourceMappingURL=index.d.mts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;UAMiB,0BAAA;;EAEf,OAAA;EAFyC;EAKzC,OAAA;EASwC;EANxC,eAAA;EAHA;EAMA,iBAAA;EAAA;EAGA,cAAA,YAA0B,cAAA;EAAA;;;;;EAO1B,IAAA;EA4BkB;;AAGpB;;;EAxBE,SAAA;EAwB2C;;;;;EAjB3C,UAAA;;;;;;EAOA,gBAAA;;;;;;EAOA,kBAAA;AAAA;AAAA,iBAGc,mBAAA,CAAoB,OAAA,EAAS,0BAAA,GAA6B,MAAA"}
package/lib/index.mjs CHANGED
@@ -2,11 +2,8 @@ import { DependencyTracker, isScriptMetadata, path } from "@staticbolt/core";
2
2
  import { buildWebComponent } from "@staticbolt/wcp-core";
3
3
 
4
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"];
5
+ function wcpStaticBoltPlugin(options) {
6
+ const include = options.include;
10
7
  const ignore = options.exclude ??= ["**/*.d.ts"];
11
8
  const deps = new DependencyTracker();
12
9
  return {
@@ -25,11 +22,12 @@ function wcpStaticBoltPlugin(options = {}) {
25
22
  filePath,
26
23
  loadPostcssConfig: options.loadPostcssConfig,
27
24
  postcssPlugins: options.postcssPlugins,
28
- minifyCss: production,
29
- minifyHtml: production,
30
- minifyCssClasses: production,
25
+ minifyCss: options.minifyCSS ?? production,
26
+ minifyHtml: options.minifyHTML ?? production,
27
+ minifyCssClasses: options.minifyCssClasses ?? production,
28
+ minifyCssVariables: options.minifyCssVariables ?? production,
31
29
  minifyJs: false,
32
- iife: false
30
+ iife: options.iife ?? false
33
31
  });
34
32
  if (buildError) {
35
33
  this.log.error(buildError.message);
@@ -65,5 +63,5 @@ function wcpStaticBoltPlugin(options = {}) {
65
63
  }
66
64
 
67
65
  //#endregion
68
- export { isWcpMetadata, wcpStaticBoltPlugin };
66
+ export { wcpStaticBoltPlugin };
69
67
  //# sourceMappingURL=index.mjs.map
package/lib/index.mjs.map CHANGED
@@ -1 +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"}
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 { Plugin } from \"@staticbolt/core\";\nimport type { AcceptedPlugin } from \"@staticbolt/wcp-core\";\n\nexport interface WcpStaticBoltPluginOptions {\n /** Glob patterns for web component `.ts` files to process. */\n include: string[];\n\n /** Glob patterns for files to exclude from processing. */\n exclude?: string[];\n\n /** Forces the plugin to run in production mode regardless of environment. */\n forceProduction?: boolean;\n\n /** Loads the local PostCSS config file and applies its plugins. */\n loadPostcssConfig?: boolean;\n\n /** Additional PostCSS plugins to apply during processing. */\n postcssPlugins?: readonly AcceptedPlugin[];\n\n /**\n * Wraps the generated component bundle in an IIFE.\n *\n * @default false\n */\n iife?: boolean;\n\n /**\n * Minifies component CSS output.\n *\n * Defaults to `true` in production mode.\n */\n minifyCSS?: boolean;\n\n /**\n * Minifies component HTML output.\n *\n * Defaults to `true` in production mode.\n */\n minifyHTML?: boolean;\n\n /**\n * Minifies generated CSS class names.\n *\n * Defaults to `true` in production mode.\n */\n minifyCssClasses?: boolean;\n\n /**\n * Minifies generated CSS variable names.\n *\n * Defaults to `true` in production mode.\n */\n minifyCssVariables?: boolean;\n}\n\nexport function wcpStaticBoltPlugin(options: WcpStaticBoltPluginOptions): Plugin {\n const include = options.include;\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: options.minifyCSS ?? production,\n minifyHtml: options.minifyHTML ?? production,\n minifyCssClasses: options.minifyCssClasses ?? production,\n minifyCssVariables: options.minifyCssVariables ?? production,\n minifyJs: false, // left for staticbolt to handle\n iife: options.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":";;;;AA0DA,SAAgB,oBAAoB,SAA6C;CAC/E,MAAM,UAAU,QAAQ;CACxB,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,QAAQ,aAAa;IAChC,YAAY,QAAQ,cAAc;IAClC,kBAAkB,QAAQ,oBAAoB;IAC9C,oBAAoB,QAAQ,sBAAsB;IAClD,UAAU;IACV,MAAM,QAAQ,QAAQ;IACvB,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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staticbolt/wcp-staticbolt-plugin",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.7",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Ahmed ALABSI",
package/src/index.ts CHANGED
@@ -1,28 +1,63 @@
1
1
  import { DependencyTracker, isScriptMetadata, path } from "@staticbolt/core";
2
2
  import { buildWebComponent } from "@staticbolt/wcp-core";
3
3
 
4
- import type { MetadataBase, Plugin } from "@staticbolt/core";
4
+ import type { Plugin } from "@staticbolt/core";
5
5
  import type { AcceptedPlugin } from "@staticbolt/wcp-core";
6
6
 
7
7
  export interface WcpStaticBoltPluginOptions {
8
- include?: string[];
8
+ /** Glob patterns for web component `.ts` files to process. */
9
+ include: string[];
10
+
11
+ /** Glob patterns for files to exclude from processing. */
9
12
  exclude?: string[];
13
+
14
+ /** Forces the plugin to run in production mode regardless of environment. */
10
15
  forceProduction?: boolean;
11
- loadPostcssConfig?: boolean;
12
- postcssPlugins?: AcceptedPlugin[];
13
- }
14
16
 
15
- export interface WcpMetadata extends MetadataBase {
16
- type: "WcpMetadata";
17
- code: string;
18
- }
17
+ /** Loads the local PostCSS config file and applies its plugins. */
18
+ loadPostcssConfig?: boolean;
19
19
 
20
- export function isWcpMetadata(metadata?: MetadataBase): metadata is WcpMetadata {
21
- return metadata?.type === "WcpMetadata";
20
+ /** Additional PostCSS plugins to apply during processing. */
21
+ postcssPlugins?: readonly AcceptedPlugin[];
22
+
23
+ /**
24
+ * Wraps the generated component bundle in an IIFE.
25
+ *
26
+ * @default false
27
+ */
28
+ iife?: boolean;
29
+
30
+ /**
31
+ * Minifies component CSS output.
32
+ *
33
+ * Defaults to `true` in production mode.
34
+ */
35
+ minifyCSS?: boolean;
36
+
37
+ /**
38
+ * Minifies component HTML output.
39
+ *
40
+ * Defaults to `true` in production mode.
41
+ */
42
+ minifyHTML?: boolean;
43
+
44
+ /**
45
+ * Minifies generated CSS class names.
46
+ *
47
+ * Defaults to `true` in production mode.
48
+ */
49
+ minifyCssClasses?: boolean;
50
+
51
+ /**
52
+ * Minifies generated CSS variable names.
53
+ *
54
+ * Defaults to `true` in production mode.
55
+ */
56
+ minifyCssVariables?: boolean;
22
57
  }
23
58
 
24
- export function wcpStaticBoltPlugin(options: WcpStaticBoltPluginOptions = {}): Plugin {
25
- const include = (options.include ??= ["sources/components/**/*.ts"]);
59
+ export function wcpStaticBoltPlugin(options: WcpStaticBoltPluginOptions): Plugin {
60
+ const include = options.include;
26
61
  const ignore = (options.exclude ??= ["**/*.d.ts"]);
27
62
 
28
63
  const deps = new DependencyTracker();
@@ -45,11 +80,12 @@ export function wcpStaticBoltPlugin(options: WcpStaticBoltPluginOptions = {}): P
45
80
  filePath,
46
81
  loadPostcssConfig: options.loadPostcssConfig,
47
82
  postcssPlugins: options.postcssPlugins,
48
- minifyCss: production,
49
- minifyHtml: production,
50
- minifyCssClasses: production,
51
- minifyJs: false,
52
- iife: false,
83
+ minifyCss: options.minifyCSS ?? production,
84
+ minifyHtml: options.minifyHTML ?? production,
85
+ minifyCssClasses: options.minifyCssClasses ?? production,
86
+ minifyCssVariables: options.minifyCssVariables ?? production,
87
+ minifyJs: false, // left for staticbolt to handle
88
+ iife: options.iife ?? false,
53
89
  });
54
90
 
55
91
  if (buildError) {