@atlaspack/optimizer-htmlnano 2.14.5-canary.137 → 2.14.5-canary.139

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaspack/optimizer-htmlnano
2
2
 
3
+ ## 2.14.21
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @atlaspack/plugin@2.14.21
9
+
3
10
  ## 2.14.20
4
11
 
5
12
  ### Patch Changes
@@ -0,0 +1,3 @@
1
+ import { Optimizer } from '@atlaspack/plugin';
2
+ declare const _default: Optimizer<unknown, unknown>;
3
+ export default _default;
@@ -34,6 +34,8 @@ function _path() {
34
34
  }
35
35
  var _svgMappings = require("./svgMappings");
36
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
+ // @ts-expect-error TS2724
38
+ // @ts-expect-error TS7016
37
39
  var _default = exports.default = new (_plugin().Optimizer)({
38
40
  async loadConfig({
39
41
  config,
@@ -59,20 +61,10 @@ var _default = exports.default = new (_plugin().Optimizer)({
59
61
  if (typeof contents !== 'string') {
60
62
  throw new Error('HTMLNanoOptimizer: Only string contents are currently supported');
61
63
  }
62
-
63
- // $FlowFixMe
64
64
  const clonedConfig = config || {};
65
-
66
- // $FlowFixMe
67
65
  const presets = _htmlnano().default.presets;
68
- // $FlowFixMe
69
- const preset =
70
- // $FlowFixMe
71
- typeof clonedConfig.preset === 'string' ? presets[clonedConfig.preset] : {};
72
- // $FlowFixMe
66
+ const preset = typeof clonedConfig.preset === 'string' ? presets[clonedConfig.preset] : {};
73
67
  delete clonedConfig.preset;
74
-
75
- // $FlowFixMe
76
68
  const htmlNanoConfig = {
77
69
  // Inline <script> and <style> elements, and style attributes are already
78
70
  // minified before they are re-inserted by the packager.
@@ -109,15 +101,15 @@ var _default = exports.default = new (_plugin().Optimizer)({
109
101
  // skipConfigLoading: true,
110
102
  };
111
103
 
112
- // $FlowFixMe
113
104
  let plugins = [(0, _htmlnano().default)(htmlNanoConfig)];
114
105
 
115
- // $FlowFixMe
106
+ // @ts-expect-error TS18046
116
107
  if (htmlNanoConfig.minifySvg !== false) {
117
108
  plugins.unshift(mapSVG);
118
109
  }
119
110
  return {
120
111
  contents: (await (0, _posthtml().default)(plugins).process(contents, {
112
+ // @ts-expect-error TS2353
121
113
  xmlMode: bundle.type === 'xhtml',
122
114
  closingSingleTag: bundle.type === 'xhtml' ? 'slash' : undefined
123
115
  })).html
@@ -129,7 +121,6 @@ var _default = exports.default = new (_plugin().Optimizer)({
129
121
  function mapSVG(node, inSVG = false) {
130
122
  if (Array.isArray(node)) {
131
123
  for (let i = 0; i < node.length; i++) {
132
- // $FlowFixMe
133
124
  node[i] = mapSVG(node[i], inSVG);
134
125
  }
135
126
  } else if (node && typeof node === 'object') {
@@ -0,0 +1,6 @@
1
+ export declare const SVG_TAG_NAMES: {
2
+ [key: string]: string;
3
+ };
4
+ export declare const SVG_ATTRS: {
5
+ [key: string]: string;
6
+ };
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.SVG_TAG_NAMES = exports.SVG_ATTRS = void 0;
7
7
  // Based on parse5: https://github.com/inikulin/parse5/blob/252819607421a5741cf745bb60c404f023531b0d/packages/parse5/lib/common/foreign-content.js#L54
8
+
8
9
  const SVG_TAG_NAMES = exports.SVG_TAG_NAMES = {
9
10
  altglyph: 'altGlyph',
10
11
  altglyphdef: 'altGlyphDef',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/optimizer-htmlnano",
3
- "version": "2.14.5-canary.137+069de478e",
3
+ "version": "2.14.5-canary.139+d2fd84977",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,18 +9,22 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
- "main": "lib/HTMLNanoOptimizer.js",
13
- "source": "src/HTMLNanoOptimizer.js",
12
+ "main": "./lib/HTMLNanoOptimizer.js",
13
+ "source": "./src/HTMLNanoOptimizer.ts",
14
+ "types": "./lib/HTMLNanoOptimizer.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
17
18
  "dependencies": {
18
- "@atlaspack/plugin": "2.14.5-canary.137+069de478e",
19
+ "@atlaspack/plugin": "2.14.5-canary.139+d2fd84977",
19
20
  "htmlnano": "^2.0.0",
20
21
  "nullthrows": "^1.1.1",
21
22
  "posthtml": "^0.16.5",
22
23
  "svgo": "^2.4.0"
23
24
  },
24
25
  "type": "commonjs",
25
- "gitHead": "069de478e64fb5889f6f2ce023eb510782767fbd"
26
- }
26
+ "scripts": {
27
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
28
+ },
29
+ "gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
30
+ }
@@ -1,13 +1,14 @@
1
- // @flow strict-local
1
+ // @ts-expect-error TS2724
2
2
  import type {PostHTMLNode} from 'posthtml';
3
3
 
4
+ // @ts-expect-error TS7016
4
5
  import htmlnano from 'htmlnano';
5
6
  import {Optimizer} from '@atlaspack/plugin';
6
7
  import posthtml from 'posthtml';
7
8
  import path from 'path';
8
9
  import {SVG_ATTRS, SVG_TAG_NAMES} from './svgMappings';
9
10
 
10
- export default (new Optimizer({
11
+ export default new Optimizer({
11
12
  async loadConfig({config, options}) {
12
13
  let userConfig = await config.getConfigFrom(
13
14
  path.join(options.projectRoot, 'index.html'),
@@ -39,22 +40,16 @@ export default (new Optimizer({
39
40
  );
40
41
  }
41
42
 
42
- // $FlowFixMe
43
- const clonedConfig: {} = config || {};
43
+ const clonedConfig: Record<any, any> = config || {};
44
44
 
45
- // $FlowFixMe
46
45
  const presets = htmlnano.presets;
47
- // $FlowFixMe
48
- const preset: {} =
49
- // $FlowFixMe
46
+ const preset: Record<any, any> =
50
47
  typeof clonedConfig.preset === 'string'
51
48
  ? presets[clonedConfig.preset]
52
49
  : {};
53
- // $FlowFixMe
54
50
  delete clonedConfig.preset;
55
51
 
56
- // $FlowFixMe
57
- const htmlNanoConfig: mixed = {
52
+ const htmlNanoConfig: unknown = {
58
53
  // Inline <script> and <style> elements, and style attributes are already
59
54
  // minified before they are re-inserted by the packager.
60
55
  minifyJs: false,
@@ -92,10 +87,9 @@ export default (new Optimizer({
92
87
  // skipConfigLoading: true,
93
88
  };
94
89
 
95
- // $FlowFixMe
96
90
  let plugins = [htmlnano(htmlNanoConfig)];
97
91
 
98
- // $FlowFixMe
92
+ // @ts-expect-error TS18046
99
93
  if (htmlNanoConfig.minifySvg !== false) {
100
94
  plugins.unshift(mapSVG);
101
95
  }
@@ -103,13 +97,14 @@ export default (new Optimizer({
103
97
  return {
104
98
  contents: (
105
99
  await posthtml(plugins).process(contents, {
100
+ // @ts-expect-error TS2353
106
101
  xmlMode: bundle.type === 'xhtml',
107
102
  closingSingleTag: bundle.type === 'xhtml' ? 'slash' : undefined,
108
103
  })
109
104
  ).html,
110
105
  };
111
106
  },
112
- }): Optimizer<mixed, mixed>);
107
+ }) as Optimizer<unknown, unknown>;
113
108
 
114
109
  // HTML tags and attributes are case insensitive. The HTML transformer normalizes them so it can
115
110
  // more easily process any case. But SVGO requires case sensitive tags and attributes to work correctly.
@@ -120,7 +115,6 @@ function mapSVG(
120
115
  ) {
121
116
  if (Array.isArray(node)) {
122
117
  for (let i = 0; i < node.length; i++) {
123
- // $FlowFixMe
124
118
  node[i] = mapSVG(node[i], inSVG);
125
119
  }
126
120
  } else if (node && typeof node === 'object') {
@@ -1,7 +1,8 @@
1
- // @flow
2
1
  // Based on parse5: https://github.com/inikulin/parse5/blob/252819607421a5741cf745bb60c404f023531b0d/packages/parse5/lib/common/foreign-content.js#L54
3
2
 
4
- export const SVG_TAG_NAMES: {|[string]: string|} = {
3
+ export const SVG_TAG_NAMES: {
4
+ [key: string]: string;
5
+ } = {
5
6
  altglyph: 'altGlyph',
6
7
  altglyphdef: 'altGlyphDef',
7
8
  altglyphitem: 'altGlyphItem',
@@ -40,7 +41,9 @@ export const SVG_TAG_NAMES: {|[string]: string|} = {
40
41
  textpath: 'textPath',
41
42
  };
42
43
 
43
- export const SVG_ATTRS: {|[string]: string|} = {
44
+ export const SVG_ATTRS: {
45
+ [key: string]: string;
46
+ } = {
44
47
  attributename: 'attributeName',
45
48
  attributetype: 'attributeType',
46
49
  basefrequency: 'baseFrequency',
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }