@altano/html-cdnify 3.0.5 → 4.0.1

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.
@@ -1,21 +1,25 @@
1
- import * as HtmlAttributeStreamTransformer from "./HtmlAttributeStreamTransformer.js";
2
- export type CDNTransformFunction = (cdnUrl: string, oldUrl: string, bufferPath: string) => string;
3
- export interface CDNTransformerOptions {
4
- cdnUrl: string;
5
- bufferPath?: string;
6
- transformDefinitions?: HtmlAttributeStreamTransformer.TransformDefinition[];
7
- transformFunction?: CDNTransformFunction;
1
+ import { HtmlAttributeStreamTransformer, TransformDefinition } from "./HtmlAttributeStreamTransformer.js";
2
+
3
+ //#region src/CDNTransformer.d.ts
4
+ type CDNTransformFunction = (cdnUrl: string, oldUrl: string, bufferPath: string) => string;
5
+ interface CDNTransformerOptions {
6
+ cdnUrl: string;
7
+ bufferPath?: string;
8
+ transformDefinitions?: TransformDefinition[];
9
+ transformFunction?: CDNTransformFunction;
8
10
  }
9
11
  /**
10
- * Wraps a node-trumpet Transform stream, w/ HTML as input and
11
- * HTML as output. The output will have all non-absolute-URL
12
- * attributes that identify CDN-able resources converted to
13
- * use the given CDN URL.
14
- */
15
- export declare class CDNTransformer extends HtmlAttributeStreamTransformer.HtmlAttributeStreamTransformer {
16
- #private;
17
- cdnOptions: Required<CDNTransformerOptions>;
18
- constructor(cdnOptions: CDNTransformerOptions);
19
- static defaultTransformFunction: (newUrlBase: string, oldUrl: string, pathOldUrlIsRelativeTo?: string) => string;
12
+ * Wraps a node-trumpet Transform stream, w/ HTML as input and
13
+ * HTML as output. The output will have all non-absolute-URL
14
+ * attributes that identify CDN-able resources converted to
15
+ * use the given CDN URL.
16
+ */
17
+ declare class CDNTransformer extends HtmlAttributeStreamTransformer {
18
+ #private;
19
+ cdnOptions: Required<CDNTransformerOptions>;
20
+ constructor(cdnOptions: CDNTransformerOptions);
21
+ static defaultTransformFunction: CDNTransformFunction;
20
22
  }
23
+ //#endregion
24
+ export { CDNTransformFunction, CDNTransformer, CDNTransformerOptions };
21
25
  //# sourceMappingURL=CDNTransformer.d.ts.map
@@ -1,125 +1,102 @@
1
- import { unionBy, merge, mergeWith } from "lodash";
2
- import urlConverter from "./urlConverter.js";
3
- import * as HtmlAttributeStreamTransformer from "./HtmlAttributeStreamTransformer.js";
4
- class OptionsMerger {
5
- static isTransformDefinition(a) {
6
- return a != null && typeof a === "object" && "selector" in a && "attribute" in a && typeof a.selector === "string" && typeof a.selector === "string" && typeof a.attribute === "string";
7
- }
8
- static isTransformDefinitions(a) {
9
- return Array.isArray(a) && a.length > 0 && OptionsMerger.isTransformDefinition(a[0]);
10
- }
11
- static mergeCustomizer = (objValue, srcValue) => {
12
- if (OptionsMerger.isTransformDefinitions(objValue) && OptionsMerger.isTransformDefinitions(srcValue)) {
13
- const result = unionBy(
14
- srcValue,
15
- objValue,
16
- // reverse order to allow srcValue to take precedence
17
- (value) => `${value.selector} / ${value.attribute}`
18
- );
19
- return result;
20
- } else {
21
- return void 0;
22
- }
23
- };
24
- static merge(target, source1, source2, source3) {
25
- return mergeWith(
26
- target,
27
- source1,
28
- source2,
29
- source3,
30
- OptionsMerger.mergeCustomizer
31
- );
32
- }
33
- }
34
- class CDNTransformer extends HtmlAttributeStreamTransformer.HtmlAttributeStreamTransformer {
35
- cdnOptions;
36
- constructor(cdnOptions) {
37
- super(
38
- OptionsMerger.merge(
39
- {},
40
- CDNTransformer.#defaultHtmlAttributeStreamTransformerOptions,
41
- {
42
- transformDefinitions: [],
43
- transformFunction: (attribute) => this.#cdnifyAttribute(attribute)
44
- },
45
- {
46
- transformDefinitions: cdnOptions.transformDefinitions
47
- }
48
- )
49
- );
50
- this.cdnOptions = merge(
51
- {
52
- transformDefinitions: []
53
- },
54
- CDNTransformer.#defaultCdnOptions,
55
- cdnOptions
56
- );
57
- if (typeof this.cdnOptions.cdnUrl !== "string") {
58
- throw new Error(`Invalid cdnUrl specified.`);
59
- }
60
- }
61
- #cdnifyAttribute(oldUrl) {
62
- return this.cdnOptions.transformFunction(
63
- this.cdnOptions.cdnUrl,
64
- oldUrl,
65
- this.cdnOptions.bufferPath
66
- );
67
- }
68
- static #defaultCdnOptions = {
69
- bufferPath: ".",
70
- transformFunction: urlConverter
71
- };
72
- static defaultTransformFunction = CDNTransformer.#defaultCdnOptions.transformFunction;
73
- static #defaultHtmlAttributeStreamTransformerOptions = {
74
- attributeToMarkElementToBeIgnored: "data-cdn-ignore",
75
- // inspired by https://github.com/callumlocke/grunt-cdnify/blob/master/tasks/cdnify.js#L31
76
- transformDefinitions: [
77
- {
78
- selector: `video[poster]:not([data-cdn-ignore])`,
79
- attribute: "poster"
80
- },
81
- {
82
- selector: `img[data-src]:not([data-cdn-ignore])`,
83
- attribute: "data-src"
84
- },
85
- {
86
- selector: `script[src]:not([data-cdn-ignore])`,
87
- attribute: "src"
88
- },
89
- {
90
- selector: `source[src]:not([data-cdn-ignore])`,
91
- attribute: "src"
92
- },
93
- {
94
- selector: `link[rel="apple-touch-icon"]:not([data-cdn-ignore])`,
95
- attribute: "href"
96
- },
97
- {
98
- selector: `link[rel="icon"]:not([data-cdn-ignore])`,
99
- attribute: "href"
100
- },
101
- {
102
- selector: `link[rel="shortcut icon"]:not([data-cdn-ignore])`,
103
- attribute: "href"
104
- },
105
- {
106
- selector: `link[rel="stylesheet"]:not([data-cdn-ignore])`,
107
- attribute: "href"
108
- },
109
- {
110
- selector: `img[src]:not([data-cdn-ignore])`,
111
- attribute: "src"
112
- },
113
- {
114
- selector: `img[srcset]:not([data-cdn-ignore])`,
115
- attribute: "srcset",
116
- attributeParser(attr, transformFunction) {
117
- return attr.split(",").map((imgInfo) => imgInfo.replace(/([^ ]+)/, transformFunction)).join(",");
118
- }
119
- }
120
- ]
121
- };
122
- }
123
- export {
124
- CDNTransformer
1
+ import urlConverter_default from "./urlConverter.js";
2
+ import { HtmlAttributeStreamTransformer } from "./HtmlAttributeStreamTransformer.js";
3
+ import { merge, mergeWith, unionBy } from "lodash";
4
+
5
+ //#region src/CDNTransformer.ts
6
+ /**
7
+ * Handles merging objects that have TransformDefinition arrays
8
+ */
9
+ var OptionsMerger = class OptionsMerger {
10
+ static isTransformDefinition(a) {
11
+ return a != null && typeof a === "object" && "selector" in a && "attribute" in a && typeof a.selector === "string" && typeof a.selector === "string" && typeof a.attribute === "string";
12
+ }
13
+ static isTransformDefinitions(a) {
14
+ return Array.isArray(a) && a.length > 0 && OptionsMerger.isTransformDefinition(a[0]);
15
+ }
16
+ static mergeCustomizer = (objValue, srcValue) => {
17
+ if (OptionsMerger.isTransformDefinitions(objValue) && OptionsMerger.isTransformDefinitions(srcValue)) {
18
+ const result = unionBy(srcValue, objValue, (value) => `${value.selector} / ${value.attribute}`);
19
+ return result;
20
+ } else return void 0;
21
+ };
22
+ static merge(target, source1, source2, source3) {
23
+ return mergeWith(target, source1, source2, source3, OptionsMerger.mergeCustomizer);
24
+ }
125
25
  };
26
+ /**
27
+ * Wraps a node-trumpet Transform stream, w/ HTML as input and
28
+ * HTML as output. The output will have all non-absolute-URL
29
+ * attributes that identify CDN-able resources converted to
30
+ * use the given CDN URL.
31
+ */
32
+ var CDNTransformer = class CDNTransformer extends HtmlAttributeStreamTransformer {
33
+ cdnOptions;
34
+ constructor(cdnOptions) {
35
+ super(OptionsMerger.merge({}, CDNTransformer.#defaultHtmlAttributeStreamTransformerOptions, {
36
+ transformDefinitions: [],
37
+ transformFunction: (attribute) => this.#cdnifyAttribute(attribute)
38
+ }, { transformDefinitions: cdnOptions.transformDefinitions }));
39
+ this.cdnOptions = merge({ transformDefinitions: [] }, CDNTransformer.#defaultCdnOptions, cdnOptions);
40
+ if (typeof this.cdnOptions.cdnUrl !== "string") throw new Error(`Invalid cdnUrl specified.`);
41
+ }
42
+ #cdnifyAttribute(oldUrl) {
43
+ return this.cdnOptions.transformFunction(this.cdnOptions.cdnUrl, oldUrl, this.cdnOptions.bufferPath);
44
+ }
45
+ static #defaultCdnOptions = {
46
+ bufferPath: ".",
47
+ transformFunction: urlConverter_default
48
+ };
49
+ static defaultTransformFunction = CDNTransformer.#defaultCdnOptions.transformFunction;
50
+ static #defaultHtmlAttributeStreamTransformerOptions = {
51
+ attributeToMarkElementToBeIgnored: "data-cdn-ignore",
52
+ transformDefinitions: [
53
+ {
54
+ selector: `video[poster]:not([data-cdn-ignore])`,
55
+ attribute: "poster"
56
+ },
57
+ {
58
+ selector: `img[data-src]:not([data-cdn-ignore])`,
59
+ attribute: "data-src"
60
+ },
61
+ {
62
+ selector: `script[src]:not([data-cdn-ignore])`,
63
+ attribute: "src"
64
+ },
65
+ {
66
+ selector: `source[src]:not([data-cdn-ignore])`,
67
+ attribute: "src"
68
+ },
69
+ {
70
+ selector: `link[rel="apple-touch-icon"]:not([data-cdn-ignore])`,
71
+ attribute: "href"
72
+ },
73
+ {
74
+ selector: `link[rel="icon"]:not([data-cdn-ignore])`,
75
+ attribute: "href"
76
+ },
77
+ {
78
+ selector: `link[rel="shortcut icon"]:not([data-cdn-ignore])`,
79
+ attribute: "href"
80
+ },
81
+ {
82
+ selector: `link[rel="stylesheet"]:not([data-cdn-ignore])`,
83
+ attribute: "href"
84
+ },
85
+ {
86
+ selector: `img[src]:not([data-cdn-ignore])`,
87
+ attribute: "src"
88
+ },
89
+ {
90
+ selector: `img[srcset]:not([data-cdn-ignore])`,
91
+ attribute: "srcset",
92
+ attributeParser(attr, transformFunction) {
93
+ return attr.split(",").map((imgInfo) => imgInfo.replace(/([^ ]+)/, transformFunction)).join(",");
94
+ }
95
+ }
96
+ ]
97
+ };
98
+ };
99
+
100
+ //#endregion
101
+ export { CDNTransformer };
102
+ //# sourceMappingURL=CDNTransformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CDNTransformer.js","names":["a: unknown","value: HtmlAttributeStreamTransformer.TransformDefinition","target: T","source1: U","source2: V","source3: W","cdnOptions: CDNTransformerOptions","#defaultHtmlAttributeStreamTransformerOptions","attribute: string","#cdnifyAttribute","#defaultCdnOptions","oldUrl: string","urlConverter","attr: string","transformFunction: HtmlAttributeStreamTransformer.TransformFunction"],"sources":["../src/CDNTransformer.ts"],"sourcesContent":["import { unionBy, merge, mergeWith, type MergeWithCustomizer } from \"lodash\";\nimport urlConverter from \"./urlConverter.js\";\n\nimport * as HtmlAttributeStreamTransformer from \"./HtmlAttributeStreamTransformer.js\";\n\nexport type CDNTransformFunction = (\n cdnUrl: string,\n oldUrl: string,\n bufferPath: string,\n) => string;\n\nexport interface CDNTransformerOptions {\n cdnUrl: string;\n bufferPath?: string;\n\n transformDefinitions?: HtmlAttributeStreamTransformer.TransformDefinition[];\n transformFunction?: CDNTransformFunction;\n}\n\n/**\n * Handles merging objects that have TransformDefinition arrays\n */\nclass OptionsMerger {\n static isTransformDefinition(\n a: unknown,\n ): a is HtmlAttributeStreamTransformer.TransformDefinition {\n return (\n a != null &&\n typeof a === \"object\" &&\n \"selector\" in a &&\n \"attribute\" in a &&\n typeof a.selector === \"string\" &&\n typeof a.selector === \"string\" &&\n typeof a.attribute === \"string\"\n );\n }\n\n static isTransformDefinitions(\n a: unknown,\n ): a is HtmlAttributeStreamTransformer.TransformDefinition[] {\n return (\n Array.isArray(a) &&\n a.length > 0 &&\n OptionsMerger.isTransformDefinition(a[0])\n );\n }\n\n static mergeCustomizer: MergeWithCustomizer = (objValue, srcValue) => {\n if (\n OptionsMerger.isTransformDefinitions(objValue) &&\n OptionsMerger.isTransformDefinitions(srcValue)\n ) {\n const result = unionBy(\n srcValue,\n objValue, // reverse order to allow srcValue to take precedence\n (value: HtmlAttributeStreamTransformer.TransformDefinition) =>\n `${value.selector} / ${value.attribute}`,\n );\n\n return result;\n } else {\n return undefined;\n }\n };\n\n static merge<T, U, V, W>(\n target: T,\n source1: U,\n source2: V,\n source3: W,\n ): T & U & V & W {\n return mergeWith(\n target,\n source1,\n source2,\n source3,\n OptionsMerger.mergeCustomizer,\n );\n }\n}\n\n/**\n * Wraps a node-trumpet Transform stream, w/ HTML as input and\n * HTML as output. The output will have all non-absolute-URL\n * attributes that identify CDN-able resources converted to\n * use the given CDN URL.\n */\nexport class CDNTransformer extends HtmlAttributeStreamTransformer.HtmlAttributeStreamTransformer {\n public cdnOptions: Required<CDNTransformerOptions>;\n\n constructor(cdnOptions: CDNTransformerOptions) {\n super(\n OptionsMerger.merge(\n {},\n CDNTransformer.#defaultHtmlAttributeStreamTransformerOptions,\n {\n transformDefinitions: [],\n transformFunction: (attribute: string) =>\n this.#cdnifyAttribute(attribute),\n },\n {\n transformDefinitions: cdnOptions.transformDefinitions,\n },\n ),\n );\n\n this.cdnOptions = merge(\n {\n transformDefinitions: [],\n },\n CDNTransformer.#defaultCdnOptions,\n cdnOptions,\n );\n\n if (typeof this.cdnOptions.cdnUrl !== \"string\") {\n throw new Error(`Invalid cdnUrl specified.`);\n }\n }\n\n #cdnifyAttribute(oldUrl: string): string {\n return this.cdnOptions.transformFunction(\n this.cdnOptions.cdnUrl,\n oldUrl,\n this.cdnOptions.bufferPath,\n );\n }\n\n static #defaultCdnOptions = {\n bufferPath: \".\",\n transformFunction: urlConverter,\n } as const;\n\n public static defaultTransformFunction: CDNTransformFunction =\n CDNTransformer.#defaultCdnOptions.transformFunction;\n\n static #defaultHtmlAttributeStreamTransformerOptions = {\n attributeToMarkElementToBeIgnored: \"data-cdn-ignore\",\n\n // inspired by https://github.com/callumlocke/grunt-cdnify/blob/master/tasks/cdnify.js#L31\n transformDefinitions: [\n {\n selector: `video[poster]:not([data-cdn-ignore])`,\n attribute: \"poster\",\n },\n {\n selector: `img[data-src]:not([data-cdn-ignore])`,\n attribute: \"data-src\",\n },\n {\n selector: `script[src]:not([data-cdn-ignore])`,\n attribute: \"src\",\n },\n {\n selector: `source[src]:not([data-cdn-ignore])`,\n attribute: \"src\",\n },\n {\n selector: `link[rel=\"apple-touch-icon\"]:not([data-cdn-ignore])`,\n attribute: \"href\",\n },\n {\n selector: `link[rel=\"icon\"]:not([data-cdn-ignore])`,\n attribute: \"href\",\n },\n {\n selector: `link[rel=\"shortcut icon\"]:not([data-cdn-ignore])`,\n attribute: \"href\",\n },\n {\n selector: `link[rel=\"stylesheet\"]:not([data-cdn-ignore])`,\n attribute: \"href\",\n },\n {\n selector: `img[src]:not([data-cdn-ignore])`,\n attribute: \"src\",\n },\n {\n selector: `img[srcset]:not([data-cdn-ignore])`,\n attribute: \"srcset\",\n attributeParser(\n attr: string,\n transformFunction: HtmlAttributeStreamTransformer.TransformFunction,\n ): string {\n return attr\n .split(\",\")\n .map((imgInfo) => imgInfo.replace(/([^ ]+)/, transformFunction))\n .join(\",\");\n },\n },\n ],\n } as const;\n}\n"],"mappings":";;;;;;;;AAsBA,IAAM,gBAAN,MAAM,cAAc;CAClB,OAAO,sBACLA,GACyD;AACzD,SACE,KAAK,eACE,MAAM,YACb,cAAc,KACd,eAAe,YACR,EAAE,aAAa,mBACf,EAAE,aAAa,mBACf,EAAE,cAAc;CAE1B;CAED,OAAO,uBACLA,GAC2D;AAC3D,SACE,MAAM,QAAQ,EAAE,IAChB,EAAE,SAAS,KACX,cAAc,sBAAsB,EAAE,GAAG;CAE5C;CAED,OAAO,kBAAuC,CAAC,UAAU,aAAa;AACpE,MACE,cAAc,uBAAuB,SAAS,IAC9C,cAAc,uBAAuB,SAAS,EAC9C;GACA,MAAM,SAAS,QACb,UACA,UACA,CAACC,WACE,EAAE,MAAM,SAAS,KAAK,MAAM,UAAU,EAC1C;AAED,UAAO;EACR,MACC;CAEH;CAED,OAAO,MACLC,QACAC,SACAC,SACAC,SACe;AACf,SAAO,UACL,QACA,SACA,SACA,SACA,cAAc,gBACf;CACF;AACF;;;;;;;AAQD,IAAa,iBAAb,MAAa,sDAAqF;CAChG,AAAO;CAEP,YAAYC,YAAmC;AAC7C,QACE,cAAc,MACZ,CAAE,GACF,eAAeC,+CACf;GACE,sBAAsB,CAAE;GACxB,mBAAmB,CAACC,cAClB,KAAKC,iBAAiB,UAAU;EACnC,GACD,EACE,sBAAsB,WAAW,qBAClC,EACF,CACF;AAED,OAAK,aAAa,MAChB,EACE,sBAAsB,CAAE,EACzB,GACD,eAAeC,oBACf,WACD;AAED,aAAW,KAAK,WAAW,WAAW,SACpC,OAAM,IAAI,OAAO;CAEpB;CAED,iBAAiBC,QAAwB;AACvC,SAAO,KAAK,WAAW,kBACrB,KAAK,WAAW,QAChB,QACA,KAAK,WAAW,WACjB;CACF;CAED,OAAOD,qBAAqB;EAC1B,YAAY;EACZ,mBAAmBE;CACpB;CAED,OAAc,2BACZ,eAAeF,mBAAmB;CAEpC,OAAOH,gDAAgD;EACrD,mCAAmC;EAGnC,sBAAsB;GACpB;IACE,WAAW;IACX,WAAW;GACZ;GACD;IACE,WAAW;IACX,WAAW;GACZ;GACD;IACE,WAAW;IACX,WAAW;GACZ;GACD;IACE,WAAW;IACX,WAAW;GACZ;GACD;IACE,WAAW;IACX,WAAW;GACZ;GACD;IACE,WAAW;IACX,WAAW;GACZ;GACD;IACE,WAAW;IACX,WAAW;GACZ;GACD;IACE,WAAW;IACX,WAAW;GACZ;GACD;IACE,WAAW;IACX,WAAW;GACZ;GACD;IACE,WAAW;IACX,WAAW;IACX,gBACEM,MACAC,mBACQ;AACR,YAAO,KACJ,MAAM,IAAI,CACV,IAAI,CAAC,YAAY,QAAQ,QAAQ,WAAW,kBAAkB,CAAC,CAC/D,KAAK,IAAI;IACb;GACF;EACF;CACF;AACF"}
@@ -1,33 +1,37 @@
1
1
  import HtmlTransformer from "./HtmlTransformer.js";
2
- export interface HtmlAttributeStreamTransformerOptions {
3
- transformDefinitions: TransformDefinition[];
4
- transformFunction: TransformFunction;
5
- attributeToMarkElementToBeIgnored?: string;
2
+
3
+ //#region src/HtmlAttributeStreamTransformer.d.ts
4
+ interface HtmlAttributeStreamTransformerOptions {
5
+ transformDefinitions: TransformDefinition[];
6
+ transformFunction: TransformFunction;
7
+ attributeToMarkElementToBeIgnored?: string;
6
8
  }
7
- export interface TransformDefinition {
8
- selector: string;
9
- attribute: string;
10
- attributeParser?: undefined | ((oldAttribute: string, transformFunction: TransformFunction) => string);
9
+ interface TransformDefinition {
10
+ selector: string;
11
+ attribute: string;
12
+ attributeParser?: undefined | ((oldAttribute: string, transformFunction: TransformFunction) => string);
11
13
  }
12
- export type TransformFunction = (oldAttribute: string) => string;
13
- export interface AttributeParser {
14
- (oldAttribute: string, transformFunction: TransformFunction): string;
14
+ type TransformFunction = (oldAttribute: string) => string;
15
+ interface AttributeParser {
16
+ (oldAttribute: string, transformFunction: TransformFunction): string;
15
17
  }
16
- export interface AttributeParsers {
17
- [index: string]: AttributeParser;
18
+ interface AttributeParsers {
19
+ [index: string]: AttributeParser;
18
20
  }
19
21
  /**
20
- * Wraps a node-trumpet Transform stream, w/ HTML as input and
21
- * HTML as output. The output will have all non-absolute-URL
22
- * attributes that identify CDN-able resources converted to
23
- * use the given CDN URL.
24
- */
25
- export declare class HtmlAttributeStreamTransformer extends HtmlTransformer {
26
- options: HtmlAttributeStreamTransformerOptions;
27
- condensedTransformOptions: TransformDefinition[];
28
- constructor(options: HtmlAttributeStreamTransformerOptions);
29
- static attributeParsers: AttributeParsers;
30
- protected applyTransforms(): void;
31
- private processTransforms;
22
+ * Wraps a node-trumpet Transform stream, w/ HTML as input and
23
+ * HTML as output. The output will have all non-absolute-URL
24
+ * attributes that identify CDN-able resources converted to
25
+ * use the given CDN URL.
26
+ */
27
+ declare class HtmlAttributeStreamTransformer extends HtmlTransformer {
28
+ options: HtmlAttributeStreamTransformerOptions;
29
+ condensedTransformOptions: TransformDefinition[];
30
+ constructor(options: HtmlAttributeStreamTransformerOptions);
31
+ static attributeParsers: AttributeParsers;
32
+ protected applyTransforms(): void;
33
+ private processTransforms;
32
34
  }
35
+ //#endregion
36
+ export { AttributeParser, AttributeParsers, HtmlAttributeStreamTransformer, HtmlAttributeStreamTransformerOptions, TransformDefinition, TransformFunction };
33
37
  //# sourceMappingURL=HtmlAttributeStreamTransformer.d.ts.map
@@ -1,75 +1,67 @@
1
- import { groupBy } from "lodash";
2
1
  import HtmlTransformer from "./HtmlTransformer.js";
3
- class HtmlAttributeStreamTransformer extends HtmlTransformer {
4
- constructor(options) {
5
- super();
6
- this.options = options;
7
- this.processTransforms();
8
- this.applyTransforms();
9
- }
10
- condensedTransformOptions = [];
11
- static attributeParsers = {
12
- default: (attr, transformFunction) => transformFunction(attr)
13
- };
14
- applyTransforms() {
15
- this.condensedTransformOptions.forEach((settings) => {
16
- const selector = settings.selector;
17
- const attribute = settings.attribute;
18
- const parser = settings.attributeParser;
19
- this.stream.selectAll(selector, (elem) => {
20
- const oldAttributeValue = elem.getAttribute(attribute);
21
- if (typeof oldAttributeValue === "string") {
22
- const newAttributeValue = parser && parser(oldAttributeValue, this.options.transformFunction);
23
- if (newAttributeValue && newAttributeValue !== oldAttributeValue) {
24
- elem.setAttribute(attribute, newAttributeValue);
25
- }
26
- }
27
- });
28
- });
29
- const { attributeToMarkElementToBeIgnored } = this.options;
30
- if (attributeToMarkElementToBeIgnored) {
31
- this.stream.selectAll(
32
- `[${attributeToMarkElementToBeIgnored}]`,
33
- (elem) => {
34
- elem.removeAttribute(attributeToMarkElementToBeIgnored);
35
- }
36
- );
37
- }
38
- }
39
- processTransforms() {
40
- this.options.transformDefinitions.forEach((option) => {
41
- if (!option.attributeParser) {
42
- option.attributeParser = HtmlAttributeStreamTransformer.attributeParsers["default"];
43
- }
44
- if (typeof option.selector !== "string") {
45
- throw new Error(`Invalid selector specified.`);
46
- }
47
- if (typeof option.attribute !== "string") {
48
- throw new Error(`Invalid attribute specified.`);
49
- }
50
- if (!(option.attributeParser instanceof Function)) {
51
- throw new Error("Invalid attributeParser specified.");
52
- }
53
- });
54
- const groupedTransformOptions = groupBy(
55
- this.options.transformDefinitions,
56
- (obj) => {
57
- return [obj.attribute, obj.attributeParser];
58
- }
59
- );
60
- this.condensedTransformOptions = Object.values(groupedTransformOptions).map(
61
- (likeTransformOptions) => {
62
- const attribute = likeTransformOptions[0].attribute;
63
- const attributeParser = likeTransformOptions[0].attributeParser;
64
- return {
65
- attribute,
66
- attributeParser,
67
- selector: likeTransformOptions.map((likeTransformOption) => likeTransformOption.selector).join(", ")
68
- };
69
- }
70
- );
71
- }
72
- }
73
- export {
74
- HtmlAttributeStreamTransformer
2
+ import { groupBy } from "lodash";
3
+
4
+ //#region src/HtmlAttributeStreamTransformer.ts
5
+ /**
6
+ * Wraps a node-trumpet Transform stream, w/ HTML as input and
7
+ * HTML as output. The output will have all non-absolute-URL
8
+ * attributes that identify CDN-able resources converted to
9
+ * use the given CDN URL.
10
+ */
11
+ var HtmlAttributeStreamTransformer = class HtmlAttributeStreamTransformer extends HtmlTransformer {
12
+ condensedTransformOptions = [];
13
+ constructor(options) {
14
+ super();
15
+ this.options = options;
16
+ this.processTransforms();
17
+ this.applyTransforms();
18
+ }
19
+ static attributeParsers = { default: (attr, transformFunction) => transformFunction(attr) };
20
+ applyTransforms() {
21
+ this.condensedTransformOptions.forEach((settings) => {
22
+ const selector = settings.selector;
23
+ const attribute = settings.attribute;
24
+ const parser = settings.attributeParser;
25
+ this.stream.selectAll(selector, (elem) => {
26
+ const oldAttributeValue = elem.getAttribute(attribute);
27
+ if (typeof oldAttributeValue === "string") {
28
+ const newAttributeValue = parser && parser(oldAttributeValue, this.options.transformFunction);
29
+ if (newAttributeValue && newAttributeValue !== oldAttributeValue) elem.setAttribute(attribute, newAttributeValue);
30
+ }
31
+ });
32
+ });
33
+ const { attributeToMarkElementToBeIgnored } = this.options;
34
+ if (attributeToMarkElementToBeIgnored) this.stream.selectAll(`[${attributeToMarkElementToBeIgnored}]`, (elem) => {
35
+ elem.removeAttribute(attributeToMarkElementToBeIgnored);
36
+ });
37
+ }
38
+ processTransforms() {
39
+ this.options.transformDefinitions.forEach((option) => {
40
+ if (!option.attributeParser) option.attributeParser = HtmlAttributeStreamTransformer.attributeParsers["default"];
41
+ if (typeof option.selector !== "string") throw new Error(`Invalid selector specified.`);
42
+ if (typeof option.attribute !== "string") throw new Error(`Invalid attribute specified.`);
43
+ if (!(option.attributeParser instanceof Function)) throw new Error("Invalid attributeParser specified.");
44
+ });
45
+ /**
46
+ * As a performance enhancement, we can condense the list of transformDefinitions such that
47
+ * selectors with the same attribute and attributeParser can be combined into a single,
48
+ * comma-delimited CSS selector.
49
+ */
50
+ const groupedTransformOptions = groupBy(this.options.transformDefinitions, (obj) => {
51
+ return [obj.attribute, obj.attributeParser];
52
+ });
53
+ this.condensedTransformOptions = Object.values(groupedTransformOptions).map((likeTransformOptions) => {
54
+ const attribute = likeTransformOptions[0].attribute;
55
+ const attributeParser = likeTransformOptions[0].attributeParser;
56
+ return {
57
+ attribute,
58
+ attributeParser,
59
+ selector: likeTransformOptions.map((likeTransformOption) => likeTransformOption.selector).join(", ")
60
+ };
61
+ });
62
+ }
75
63
  };
64
+
65
+ //#endregion
66
+ export { HtmlAttributeStreamTransformer };
67
+ //# sourceMappingURL=HtmlAttributeStreamTransformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HtmlAttributeStreamTransformer.js","names":["options: HtmlAttributeStreamTransformerOptions"],"sources":["../src/HtmlAttributeStreamTransformer.ts"],"sourcesContent":["import { groupBy } from \"lodash\";\nimport HtmlTransformer from \"./HtmlTransformer.js\";\n\nexport interface HtmlAttributeStreamTransformerOptions {\n transformDefinitions: TransformDefinition[];\n transformFunction: TransformFunction;\n attributeToMarkElementToBeIgnored?: string;\n}\n\nexport interface TransformDefinition {\n selector: string;\n attribute: string;\n attributeParser?:\n | undefined\n | ((oldAttribute: string, transformFunction: TransformFunction) => string);\n}\n\nexport type TransformFunction = (oldAttribute: string) => string;\n\nexport interface AttributeParser {\n (oldAttribute: string, transformFunction: TransformFunction): string;\n}\n\nexport interface AttributeParsers {\n [index: string]: AttributeParser;\n}\n\n/**\n * Wraps a node-trumpet Transform stream, w/ HTML as input and\n * HTML as output. The output will have all non-absolute-URL\n * attributes that identify CDN-able resources converted to\n * use the given CDN URL.\n */\nexport class HtmlAttributeStreamTransformer extends HtmlTransformer {\n public condensedTransformOptions: TransformDefinition[] = [];\n\n constructor(public options: HtmlAttributeStreamTransformerOptions) {\n super();\n\n this.processTransforms();\n\n this.applyTransforms();\n }\n\n static attributeParsers: AttributeParsers = {\n default: (attr, transformFunction) => transformFunction(attr),\n };\n\n protected applyTransforms(): void {\n this.condensedTransformOptions.forEach((settings) => {\n const selector = settings.selector;\n const attribute = settings.attribute;\n const parser = settings.attributeParser;\n\n this.stream.selectAll(selector, (elem) => {\n const oldAttributeValue = elem.getAttribute(attribute);\n\n // Check that the attribute is set (which should always be the case) and the\n // typeof=string, which will be false in the case of empty attributes (which\n // cause getAttribute() to return the boolean true)\n if (typeof oldAttributeValue === \"string\") {\n const newAttributeValue =\n parser && parser(oldAttributeValue, this.options.transformFunction);\n if (newAttributeValue && newAttributeValue !== oldAttributeValue) {\n elem.setAttribute(attribute, newAttributeValue);\n }\n }\n });\n });\n\n // Run cleanup transform last\n const { attributeToMarkElementToBeIgnored } = this.options;\n if (attributeToMarkElementToBeIgnored) {\n this.stream.selectAll(\n `[${attributeToMarkElementToBeIgnored}]`,\n (elem) => {\n elem.removeAttribute(attributeToMarkElementToBeIgnored);\n },\n );\n }\n }\n\n private processTransforms(): void {\n this.options.transformDefinitions.forEach((option) => {\n if (!option.attributeParser) {\n option.attributeParser =\n HtmlAttributeStreamTransformer.attributeParsers[\"default\"];\n }\n\n if (typeof option.selector !== \"string\") {\n throw new Error(`Invalid selector specified.`);\n }\n\n if (typeof option.attribute !== \"string\") {\n throw new Error(`Invalid attribute specified.`);\n }\n\n if (!(option.attributeParser instanceof Function)) {\n throw new Error(\"Invalid attributeParser specified.\");\n }\n });\n\n /**\n * As a performance enhancement, we can condense the list of transformDefinitions such that\n * selectors with the same attribute and attributeParser can be combined into a single,\n * comma-delimited CSS selector.\n */\n const groupedTransformOptions = groupBy(\n this.options.transformDefinitions,\n (obj) => {\n return [obj.attribute, obj.attributeParser];\n },\n );\n\n this.condensedTransformOptions = Object.values(groupedTransformOptions).map(\n (likeTransformOptions) => {\n const attribute = likeTransformOptions[0]!.attribute;\n const attributeParser = likeTransformOptions[0]!.attributeParser;\n\n return {\n attribute,\n attributeParser,\n selector: likeTransformOptions\n .map((likeTransformOption) => likeTransformOption.selector)\n .join(\", \"),\n };\n },\n );\n }\n}\n"],"mappings":";;;;;;;;;;AAiCA,IAAa,iCAAb,MAAa,uCAAuC,gBAAgB;CAClE,AAAO,4BAAmD,CAAE;CAE5D,YAAmBA,SAAgD;AACjE,SAAO;EADU;AAGjB,OAAK,mBAAmB;AAExB,OAAK,iBAAiB;CACvB;CAED,OAAO,mBAAqC,EAC1C,SAAS,CAAC,MAAM,sBAAsB,kBAAkB,KAAK,CAC9D;CAED,AAAU,kBAAwB;AAChC,OAAK,0BAA0B,QAAQ,CAAC,aAAa;GACnD,MAAM,WAAW,SAAS;GAC1B,MAAM,YAAY,SAAS;GAC3B,MAAM,SAAS,SAAS;AAExB,QAAK,OAAO,UAAU,UAAU,CAAC,SAAS;IACxC,MAAM,oBAAoB,KAAK,aAAa,UAAU;AAKtD,eAAW,sBAAsB,UAAU;KACzC,MAAM,oBACJ,UAAU,OAAO,mBAAmB,KAAK,QAAQ,kBAAkB;AACrE,SAAI,qBAAqB,sBAAsB,kBAC7C,MAAK,aAAa,WAAW,kBAAkB;IAElD;GACF,EAAC;EACH,EAAC;EAGF,MAAM,EAAE,mCAAmC,GAAG,KAAK;AACnD,MAAI,kCACF,MAAK,OAAO,WACT,GAAG,kCAAkC,IACtC,CAAC,SAAS;AACR,QAAK,gBAAgB,kCAAkC;EACxD,EACF;CAEJ;CAED,AAAQ,oBAA0B;AAChC,OAAK,QAAQ,qBAAqB,QAAQ,CAAC,WAAW;AACpD,QAAK,OAAO,gBACV,QAAO,kBACL,+BAA+B,iBAAiB;AAGpD,cAAW,OAAO,aAAa,SAC7B,OAAM,IAAI,OAAO;AAGnB,cAAW,OAAO,cAAc,SAC9B,OAAM,IAAI,OAAO;AAGnB,SAAM,OAAO,2BAA2B,UACtC,OAAM,IAAI,MAAM;EAEnB,EAAC;;;;;;EAOF,MAAM,0BAA0B,QAC9B,KAAK,QAAQ,sBACb,CAAC,QAAQ;AACP,UAAO,CAAC,IAAI,WAAW,IAAI,eAAgB;EAC5C,EACF;AAED,OAAK,4BAA4B,OAAO,OAAO,wBAAwB,CAAC,IACtE,CAAC,yBAAyB;GACxB,MAAM,YAAY,qBAAqB,GAAI;GAC3C,MAAM,kBAAkB,qBAAqB,GAAI;AAEjD,UAAO;IACL;IACA;IACA,UAAU,qBACP,IAAI,CAAC,wBAAwB,oBAAoB,SAAS,CAC1D,KAAK,KAAK;GACd;EACF,EACF;CACF;AACF"}
@@ -1,15 +1,19 @@
1
- import { type Trumpet } from "@gofunky/trumpet";
2
- export type TrumpetTransformStream = Trumpet;
3
- export default class HtmlTransformer {
4
- private transformStream;
5
- constructor();
6
- /**
7
- * Get the underlying transform stream
8
- */
9
- get stream(): Trumpet;
10
- /**
11
- * Get a promise to the complete output Buffer (alternative API to dealing with stream)
12
- */
13
- get outputBufferPromise(): Promise<Buffer>;
1
+ import { Trumpet } from "@gofunky/trumpet";
2
+
3
+ //#region src/HtmlTransformer.d.ts
4
+ type TrumpetTransformStream = Trumpet;
5
+ declare class HtmlTransformer {
6
+ private transformStream;
7
+ constructor();
8
+ /**
9
+ * Get the underlying transform stream
10
+ */
11
+ get stream(): Trumpet;
12
+ /**
13
+ * Get a promise to the complete output Buffer (alternative API to dealing with stream)
14
+ */
15
+ get outputBufferPromise(): Promise<Buffer>;
14
16
  }
17
+ //#endregion
18
+ export { TrumpetTransformStream, HtmlTransformer as default };
15
19
  //# sourceMappingURL=HtmlTransformer.d.ts.map
@@ -1,23 +1,26 @@
1
1
  import trumpet from "@gofunky/trumpet";
2
2
  import streamToPromise from "stream-to-promise";
3
- class HtmlTransformer {
4
- transformStream;
5
- constructor() {
6
- this.transformStream = trumpet();
7
- }
8
- /**
9
- * Get the underlying transform stream
10
- */
11
- get stream() {
12
- return this.transformStream;
13
- }
14
- /**
15
- * Get a promise to the complete output Buffer (alternative API to dealing with stream)
16
- */
17
- get outputBufferPromise() {
18
- return streamToPromise(this.stream);
19
- }
20
- }
21
- export {
22
- HtmlTransformer as default
3
+
4
+ //#region src/HtmlTransformer.ts
5
+ var HtmlTransformer = class {
6
+ transformStream;
7
+ constructor() {
8
+ this.transformStream = trumpet();
9
+ }
10
+ /**
11
+ * Get the underlying transform stream
12
+ */
13
+ get stream() {
14
+ return this.transformStream;
15
+ }
16
+ /**
17
+ * Get a promise to the complete output Buffer (alternative API to dealing with stream)
18
+ */
19
+ get outputBufferPromise() {
20
+ return streamToPromise(this.stream);
21
+ }
23
22
  };
23
+
24
+ //#endregion
25
+ export { HtmlTransformer as default };
26
+ //# sourceMappingURL=HtmlTransformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HtmlTransformer.js","names":[],"sources":["../src/HtmlTransformer.ts"],"sourcesContent":["import trumpet, { type Trumpet } from \"@gofunky/trumpet\";\nimport streamToPromise from \"stream-to-promise\";\n\nexport type TrumpetTransformStream = Trumpet;\n\nexport default class HtmlTransformer {\n private transformStream: TrumpetTransformStream;\n\n constructor(/*public inputPath: string*/) {\n this.transformStream = trumpet();\n }\n\n /**\n * Get the underlying transform stream\n */\n get stream(): Trumpet {\n return this.transformStream;\n }\n\n /**\n * Get a promise to the complete output Buffer (alternative API to dealing with stream)\n */\n get outputBufferPromise(): Promise<Buffer> {\n return streamToPromise(this.stream);\n }\n}\n"],"mappings":";;;;AAKA,IAAqB,kBAArB,MAAqC;CACnC,AAAQ;CAER,cAA0C;AACxC,OAAK,kBAAkB,SAAS;CACjC;;;;CAKD,IAAI,SAAkB;AACpB,SAAO,KAAK;CACb;;;;CAKD,IAAI,sBAAuC;AACzC,SAAO,gBAAgB,KAAK,OAAO;CACpC;AACF"}
package/dist/cdnify.d.ts CHANGED
@@ -1,10 +1,13 @@
1
- import { type CDNTransformerOptions } from "./CDNTransformer.js";
2
- export interface CdnifyOptions extends CDNTransformerOptions {
3
- buffer: string | Buffer;
1
+ import { CDNTransformerOptions } from "./CDNTransformer.js";
2
+
3
+ //#region src/cdnify.d.ts
4
+ interface CdnifyOptions extends CDNTransformerOptions {
5
+ buffer: string | Buffer;
4
6
  }
5
7
  /**
6
- * Alternative wrapper for simple Promise-based use of library (as opposed to transform stream)
7
- */
8
- export declare function cdnify(options: CdnifyOptions): Promise<Buffer>;
9
- export default cdnify;
8
+ * Alternative wrapper for simple Promise-based use of library (as opposed to transform stream)
9
+ */
10
+ declare function cdnify(options: CdnifyOptions): Promise<Buffer>;
11
+ //#endregion
12
+ export { CdnifyOptions, cdnify, cdnify as default };
10
13
  //# sourceMappingURL=cdnify.d.ts.map
package/dist/cdnify.js CHANGED
@@ -1,17 +1,18 @@
1
- import {
2
- CDNTransformer
3
- } from "./CDNTransformer.js";
1
+ import { CDNTransformer } from "./CDNTransformer.js";
4
2
  import streamifier from "streamifier";
3
+
4
+ //#region src/cdnify.ts
5
+ /**
6
+ * Alternative wrapper for simple Promise-based use of library (as opposed to transform stream)
7
+ */
5
8
  function cdnify(options) {
6
- if (typeof options.buffer !== "string") {
7
- options.buffer = options.buffer.toString();
8
- }
9
- const cdnTransformer = new CDNTransformer(options);
10
- streamifier.createReadStream(options.buffer).pipe(cdnTransformer.stream);
11
- return cdnTransformer.outputBufferPromise;
9
+ if (typeof options.buffer !== "string") options.buffer = options.buffer.toString();
10
+ const cdnTransformer = new CDNTransformer(options);
11
+ streamifier.createReadStream(options.buffer).pipe(cdnTransformer.stream);
12
+ return cdnTransformer.outputBufferPromise;
12
13
  }
13
14
  var cdnify_default = cdnify;
14
- export {
15
- cdnify,
16
- cdnify_default as default
17
- };
15
+
16
+ //#endregion
17
+ export { cdnify, cdnify_default as default };
18
+ //# sourceMappingURL=cdnify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdnify.js","names":["options: CdnifyOptions"],"sources":["../src/cdnify.ts"],"sourcesContent":["import {\n CDNTransformer,\n type CDNTransformerOptions,\n} from \"./CDNTransformer.js\";\n\nimport streamifier from \"streamifier\";\n\nexport interface CdnifyOptions extends CDNTransformerOptions {\n buffer: string | Buffer;\n}\n\n/**\n * Alternative wrapper for simple Promise-based use of library (as opposed to transform stream)\n */\nexport function cdnify(options: CdnifyOptions): Promise<Buffer> {\n if (typeof options.buffer !== \"string\") {\n options.buffer = options.buffer.toString();\n }\n\n const cdnTransformer = new CDNTransformer(options);\n\n streamifier.createReadStream(options.buffer).pipe(cdnTransformer.stream);\n\n return cdnTransformer.outputBufferPromise;\n}\n\nexport default cdnify;\n"],"mappings":";;;;;;;AAcA,SAAgB,OAAOA,SAAyC;AAC9D,YAAW,QAAQ,WAAW,SAC5B,SAAQ,SAAS,QAAQ,OAAO,UAAU;CAG5C,MAAM,iBAAiB,IAAI,eAAe;AAE1C,aAAY,iBAAiB,QAAQ,OAAO,CAAC,KAAK,eAAe,OAAO;AAExE,QAAO,eAAe;AACvB;AAED,qBAAe"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./cdnify.js";
2
- export * from "./CDNTransformer.js";
3
- //# sourceMappingURL=index.d.ts.map
1
+ import { CDNTransformFunction, CDNTransformer, CDNTransformerOptions } from "./CDNTransformer.js";
2
+ import { CdnifyOptions, cdnify } from "./cdnify.js";
3
+ export { CDNTransformFunction, CDNTransformer, CDNTransformerOptions, CdnifyOptions, cdnify };
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
- export * from "./cdnify.js";
2
- export * from "./CDNTransformer.js";
1
+ import { CDNTransformer } from "./CDNTransformer.js";
2
+ import { cdnify } from "./cdnify.js";
3
+
4
+ export { CDNTransformer, cdnify };
@@ -1,6 +1,8 @@
1
+ //#region src/urlConverter.d.ts
1
2
  /**
2
- * Resolve oldUrl against pathOldUrlIsRelativeTo, and then prepend newUrlBase
3
- */
3
+ * Resolve oldUrl against pathOldUrlIsRelativeTo, and then prepend newUrlBase
4
+ */
4
5
  declare const _default: (newUrlBase: string, oldUrl: string, pathOldUrlIsRelativeTo?: string) => string;
5
- export default _default;
6
+ //#endregion
7
+ export { _default as default };
6
8
  //# sourceMappingURL=urlConverter.d.ts.map
@@ -1,30 +1,29 @@
1
1
  import url from "node:url";
2
2
  import path from "node:path";
3
+
4
+ //#region src/urlConverter.ts
3
5
  function isLocalPath(filePath) {
4
- return typeof filePath === "string" && filePath.length > 0 && filePath.indexOf("//") === -1 && filePath.indexOf("data:") !== 0;
6
+ return typeof filePath === "string" && filePath.length > 0 && filePath.indexOf("//") === -1 && filePath.indexOf("data:") !== 0;
5
7
  }
8
+ /**
9
+ * Resolve oldUrl against pathOldUrlIsRelativeTo, and then prepend newUrlBase
10
+ */
6
11
  var urlConverter_default = (newUrlBase, oldUrl, pathOldUrlIsRelativeTo) => {
7
- if (!isLocalPath(oldUrl)) {
8
- return oldUrl;
9
- } else {
10
- oldUrl = oldUrl.trim();
11
- let relativePath = ".";
12
- if (pathOldUrlIsRelativeTo) {
13
- const isDirAlready = pathOldUrlIsRelativeTo.endsWith("/");
14
- const fileDirName = isDirAlready ? pathOldUrlIsRelativeTo : path.dirname(pathOldUrlIsRelativeTo) + "/";
15
- relativePath = url.resolve(fileDirName, oldUrl);
16
- } else {
17
- relativePath = oldUrl;
18
- }
19
- if (relativePath.startsWith("/")) {
20
- relativePath = relativePath.slice(1);
21
- }
22
- if (!newUrlBase.endsWith("/")) {
23
- newUrlBase += "/";
24
- }
25
- return url.resolve(newUrlBase, relativePath);
26
- }
27
- };
28
- export {
29
- urlConverter_default as default
12
+ if (!isLocalPath(oldUrl)) return oldUrl;
13
+ else {
14
+ oldUrl = oldUrl.trim();
15
+ let relativePath = ".";
16
+ if (pathOldUrlIsRelativeTo) {
17
+ const isDirAlready = pathOldUrlIsRelativeTo.endsWith("/");
18
+ const fileDirName = isDirAlready ? pathOldUrlIsRelativeTo : path.dirname(pathOldUrlIsRelativeTo) + "/";
19
+ relativePath = url.resolve(fileDirName, oldUrl);
20
+ } else relativePath = oldUrl;
21
+ if (relativePath.startsWith("/")) relativePath = relativePath.slice(1);
22
+ if (!newUrlBase.endsWith("/")) newUrlBase += "/";
23
+ return url.resolve(newUrlBase, relativePath);
24
+ }
30
25
  };
26
+
27
+ //#endregion
28
+ export { urlConverter_default as default };
29
+ //# sourceMappingURL=urlConverter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urlConverter.js","names":["filePath: string","newUrlBase: string","oldUrl: string","pathOldUrlIsRelativeTo?: string"],"sources":["../src/urlConverter.ts"],"sourcesContent":["import url from \"node:url\";\nimport path from \"node:path\";\n\nfunction isLocalPath(filePath: string): boolean {\n return (\n typeof filePath === \"string\" &&\n filePath.length > 0 &&\n filePath.indexOf(\"//\") === -1 &&\n filePath.indexOf(\"data:\") !== 0\n );\n}\n\n/**\n * Resolve oldUrl against pathOldUrlIsRelativeTo, and then prepend newUrlBase\n */\nexport default (\n newUrlBase: string,\n oldUrl: string,\n pathOldUrlIsRelativeTo?: string,\n): string => {\n if (!isLocalPath(oldUrl)) {\n return oldUrl;\n } else {\n oldUrl = oldUrl.trim();\n let relativePath = \".\";\n\n if (pathOldUrlIsRelativeTo) {\n const isDirAlready = pathOldUrlIsRelativeTo.endsWith(\"/\");\n const fileDirName = isDirAlready\n ? pathOldUrlIsRelativeTo\n : path.dirname(pathOldUrlIsRelativeTo) + \"/\";\n relativePath = url.resolve(fileDirName, oldUrl);\n } else {\n relativePath = oldUrl;\n }\n\n // When resolving against the CDN URL, we should always use a relative URL.\n //\n // e.g. http://somecdn.com/cdn/ + /article/some.css => http://somecdn.com/cdn/article/some.css\n // and *NOT*\n // http://somecdn.com/cdn/ + /article/some.css => http://somecdn.com/article/some.css\n //\n if (relativePath.startsWith(\"/\")) {\n relativePath = relativePath.slice(1);\n }\n\n if (!newUrlBase.endsWith(\"/\")) {\n newUrlBase += \"/\";\n }\n\n return url.resolve(newUrlBase, relativePath);\n }\n};\n"],"mappings":";;;;AAGA,SAAS,YAAYA,UAA2B;AAC9C,eACS,aAAa,YACpB,SAAS,SAAS,KAClB,SAAS,QAAQ,KAAK,KAAK,MAC3B,SAAS,QAAQ,QAAQ,KAAK;AAEjC;;;;AAKD,2BAAe,CACbC,YACAC,QACAC,2BACW;AACX,MAAK,YAAY,OAAO,CACtB,QAAO;MACF;AACL,WAAS,OAAO,MAAM;EACtB,IAAI,eAAe;AAEnB,MAAI,wBAAwB;GAC1B,MAAM,eAAe,uBAAuB,SAAS,IAAI;GACzD,MAAM,cAAc,eAChB,yBACA,KAAK,QAAQ,uBAAuB,GAAG;AAC3C,kBAAe,IAAI,QAAQ,aAAa,OAAO;EAChD,MACC,gBAAe;AASjB,MAAI,aAAa,WAAW,IAAI,CAC9B,gBAAe,aAAa,MAAM,EAAE;AAGtC,OAAK,WAAW,SAAS,IAAI,CAC3B,eAAc;AAGhB,SAAO,IAAI,QAAQ,YAAY,aAAa;CAC7C;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altano/html-cdnify",
3
- "version": "3.0.5",
3
+ "version": "4.0.1",
4
4
  "description": "Transform the relative URLs in your HTML markup (e.g. scripts, stylesheets, images) to use your CDN URL.",
5
5
  "keywords": [
6
6
  "cdn",
@@ -27,6 +27,7 @@
27
27
  "files": [
28
28
  "assets/logo.png",
29
29
  "dist/**/*.js",
30
+ "dist/**/*.js.map",
30
31
  "dist/**/*.d.ts"
31
32
  ],
32
33
  "dependencies": {
@@ -36,22 +37,22 @@
36
37
  "streamifier": "^0.1.1"
37
38
  },
38
39
  "devDependencies": {
39
- "@arethetypeswrong/cli": "^0.15.4",
40
+ "@arethetypeswrong/cli": "^0.17.4",
40
41
  "@types/lodash": "^4.14.202",
41
42
  "@types/node": "^22.13.10",
42
43
  "@types/stream-to-promise": "^2.2.4",
43
44
  "@types/streamifier": "^0.1.2",
44
- "@vitest/coverage-v8": "^3.0.9",
45
+ "@vitest/coverage-v8": "^3.1.4",
45
46
  "depcheck": "^1.4.7",
46
- "eslint": "^9.22.0",
47
- "prettier": "^3.3.3",
47
+ "eslint": "^9.23.0",
48
+ "prettier": "^3.5.3",
49
+ "tsdown": "^0.12.9",
48
50
  "typescript": "^5.8.2",
49
- "vite": "^6.2.3",
50
- "vitest": "^3.0.9",
51
- "@altano/tsconfig": "0.0.0",
52
- "@altano/vitest-plugins": "1.0.0",
53
- "@altano/build-config": "0.0.0",
54
- "@altano/testing": "0.0.0"
51
+ "vite": "^6.2.6",
52
+ "vitest": "^3.1.4",
53
+ "@altano/build-config": "0.0.1",
54
+ "@altano/testing": "0.0.1",
55
+ "@altano/tsconfig": "0.0.1"
55
56
  },
56
57
  "engines": {
57
58
  "node": ">=5.10.1"
@@ -60,9 +61,8 @@
60
61
  "access": "public"
61
62
  },
62
63
  "scripts": {
63
- "build": "tsup --config build-config/tsup.config.node.ts",
64
- "build:types": "tsc --project tsconfig.declarations.json",
65
- "check:exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
64
+ "build": "tsdown --config ../build-config/tsdown.config.node.ts",
65
+ "check:exports": "attw --pack . --profile esm-only --quiet",
66
66
  "check:types:src": "tsc --noEmit",
67
67
  "check:types:test": "tsc --noEmit --project ./tests/tsconfig.json",
68
68
  "check:unused-dependencies": "depcheck",