@altano/html-cdnify 3.0.5 → 4.0.0
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/dist/CDNTransformer.d.ts +22 -17
- package/dist/CDNTransformer.js +101 -124
- package/dist/HtmlAttributeStreamTransformer.d.ts +29 -26
- package/dist/HtmlAttributeStreamTransformer.js +65 -73
- package/dist/HtmlTransformer.d.ts +17 -14
- package/dist/HtmlTransformer.js +23 -20
- package/dist/cdnify.d.ts +11 -7
- package/dist/cdnify.js +14 -13
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -2
- package/dist/urlConverter.d.ts +5 -4
- package/dist/urlConverter.js +23 -24
- package/package.json +13 -14
package/dist/CDNTransformer.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { CDNTransformFunction, CDNTransformer, CDNTransformerOptions };
|
|
21
26
|
//# sourceMappingURL=CDNTransformer.d.ts.map
|
package/dist/CDNTransformer.js
CHANGED
|
@@ -1,125 +1,102 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
import HtmlTransformer from "./HtmlTransformer.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/HtmlAttributeStreamTransformer.d.ts
|
|
4
|
+
interface HtmlAttributeStreamTransformerOptions {
|
|
5
|
+
transformDefinitions: TransformDefinition[];
|
|
6
|
+
transformFunction: TransformFunction;
|
|
7
|
+
attributeToMarkElementToBeIgnored?: string;
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
interface TransformDefinition {
|
|
10
|
+
selector: string;
|
|
11
|
+
attribute: string;
|
|
12
|
+
attributeParser?: undefined | ((oldAttribute: string, transformFunction: TransformFunction) => string);
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
type TransformFunction = (oldAttribute: string) => string;
|
|
15
|
+
interface AttributeParser {
|
|
16
|
+
(oldAttribute: string, transformFunction: TransformFunction): string;
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
interface AttributeParsers {
|
|
19
|
+
[index: string]: AttributeParser;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
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;
|
|
34
|
+
} //#endregion
|
|
35
|
+
export { AttributeParser, AttributeParsers, HtmlAttributeStreamTransformer, HtmlAttributeStreamTransformerOptions, TransformDefinition, TransformFunction };
|
|
33
36
|
//# sourceMappingURL=HtmlAttributeStreamTransformer.d.ts.map
|
|
@@ -1,75 +1,67 @@
|
|
|
1
|
-
import { groupBy } from "lodash";
|
|
2
1
|
import HtmlTransformer from "./HtmlTransformer.js";
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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>;
|
|
16
|
+
} //#endregion
|
|
17
|
+
export { TrumpetTransformStream, HtmlTransformer as default };
|
|
15
18
|
//# sourceMappingURL=HtmlTransformer.d.ts.map
|
package/dist/HtmlTransformer.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import trumpet from "@gofunky/trumpet";
|
|
2
2
|
import streamToPromise from "stream-to-promise";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
package/dist/cdnify.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { CdnifyOptions, cdnify, cdnify as default };
|
|
10
14
|
//# 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { cdnify, cdnify_default as default };
|
|
18
|
+
//# sourceMappingURL=cdnify.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
package/dist/urlConverter.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
//#region src/urlConverter.d.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const _default: (newUrlBase: string, oldUrl: string, pathOldUrlIsRelativeTo?: string) => string;
|
|
5
|
-
export default
|
|
3
|
+
* Resolve oldUrl against pathOldUrlIsRelativeTo, and then prepend newUrlBase
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: (newUrlBase: string, oldUrl: string, pathOldUrlIsRelativeTo?: string) => string; //#endregion
|
|
6
|
+
export { _default as default };
|
|
6
7
|
//# sourceMappingURL=urlConverter.d.ts.map
|
package/dist/urlConverter.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/html-cdnify",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
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",
|
|
@@ -36,22 +36,22 @@
|
|
|
36
36
|
"streamifier": "^0.1.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@arethetypeswrong/cli": "^0.
|
|
39
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
40
40
|
"@types/lodash": "^4.14.202",
|
|
41
41
|
"@types/node": "^22.13.10",
|
|
42
42
|
"@types/stream-to-promise": "^2.2.4",
|
|
43
43
|
"@types/streamifier": "^0.1.2",
|
|
44
|
-
"@vitest/coverage-v8": "^3.
|
|
44
|
+
"@vitest/coverage-v8": "^3.1.4",
|
|
45
45
|
"depcheck": "^1.4.7",
|
|
46
|
-
"eslint": "^9.
|
|
47
|
-
"prettier": "^3.
|
|
46
|
+
"eslint": "^9.23.0",
|
|
47
|
+
"prettier": "^3.5.3",
|
|
48
|
+
"tsdown": "^0.12.3",
|
|
48
49
|
"typescript": "^5.8.2",
|
|
49
|
-
"vite": "^6.2.
|
|
50
|
-
"vitest": "^3.
|
|
51
|
-
"@altano/
|
|
52
|
-
"@altano/
|
|
53
|
-
"@altano/
|
|
54
|
-
"@altano/testing": "0.0.0"
|
|
50
|
+
"vite": "^6.2.6",
|
|
51
|
+
"vitest": "^3.1.4",
|
|
52
|
+
"@altano/build-config": "0.0.1",
|
|
53
|
+
"@altano/testing": "0.0.1",
|
|
54
|
+
"@altano/tsconfig": "0.0.1"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=5.10.1"
|
|
@@ -60,9 +60,8 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
|
-
"build": "
|
|
64
|
-
"
|
|
65
|
-
"check:exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
|
|
63
|
+
"build": "tsdown --config ../build-config/tsdown.config.node.ts",
|
|
64
|
+
"check:exports": "attw --pack . --profile esm-only --quiet",
|
|
66
65
|
"check:types:src": "tsc --noEmit",
|
|
67
66
|
"check:types:test": "tsc --noEmit --project ./tests/tsconfig.json",
|
|
68
67
|
"check:unused-dependencies": "depcheck",
|