classnames-minifier 0.0.0-experimental-88c1611 → 0.0.0-experimental-7dbcd07
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/cjs/ClassnamesMinifier.d.ts +1 -0
- package/dist/cjs/ClassnamesMinifier.js +16 -1
- package/dist/cjs/lib/validateDist.js +1 -1
- package/dist/esm/ClassnamesMinifier.d.ts +1 -0
- package/dist/esm/ClassnamesMinifier.js +1 -1
- package/dist/esm/lib/ConverterMinified.js +131 -135
- package/dist/esm/lib/classnames-minifier-preloader.js +1 -1
- package/dist/esm/lib/validateDist.js +5 -4
- package/package.json +1 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { LoaderContext } from "webpack";
|
|
2
2
|
import type { Config } from "./lib/types/plugin";
|
|
3
3
|
import ConverterMinified from "./lib/ConverterMinified";
|
|
4
|
+
export * from "./lib/types/plugin";
|
|
4
5
|
declare class ClassnamesMinifier {
|
|
5
6
|
converterMinified: ConverterMinified;
|
|
6
7
|
constructor(config: Config);
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
@@ -10,6 +24,7 @@ const validateConfig_1 = __importDefault(require("./lib/validateConfig"));
|
|
|
10
24
|
const ConverterMinified_1 = __importDefault(require("./lib/ConverterMinified"));
|
|
11
25
|
const validateDist_1 = __importDefault(require("./lib/validateDist"));
|
|
12
26
|
const removeDist_1 = __importDefault(require("./lib/removeDist"));
|
|
27
|
+
__exportStar(require("./lib/types/plugin"), exports);
|
|
13
28
|
class ClassnamesMinifier {
|
|
14
29
|
constructor(config) {
|
|
15
30
|
(0, validateConfig_1.default)(config);
|
|
@@ -57,7 +72,7 @@ class ClassnamesMinifier {
|
|
|
57
72
|
}
|
|
58
73
|
if (!fs_1.default.existsSync(manifestDir))
|
|
59
74
|
fs_1.default.mkdirSync(manifestDir, { recursive: true });
|
|
60
|
-
fs_1.default.writeFileSync(manifestPath, JSON.stringify(
|
|
75
|
+
fs_1.default.writeFileSync(manifestPath, JSON.stringify({ ...config, version: configuration_1.CODE_VERSION }), { encoding: "utf-8" });
|
|
61
76
|
}
|
|
62
77
|
}
|
|
63
78
|
get getLocalIdent() {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { LoaderContext } from "webpack";
|
|
2
2
|
import type { Config } from "./lib/types/plugin";
|
|
3
3
|
import ConverterMinified from "./lib/ConverterMinified";
|
|
4
|
+
export * from "./lib/types/plugin";
|
|
4
5
|
declare class ClassnamesMinifier {
|
|
5
6
|
converterMinified: ConverterMinified;
|
|
6
7
|
constructor(config: Config);
|
|
@@ -5,8 +5,8 @@ import validateConfig from "./lib/validateConfig";
|
|
|
5
5
|
import ConverterMinified from "./lib/ConverterMinified";
|
|
6
6
|
import validateDist from "./lib/validateDist";
|
|
7
7
|
import removeDist from "./lib/removeDist";
|
|
8
|
+
export * from "./lib/types/plugin";
|
|
8
9
|
class ClassnamesMinifier {
|
|
9
|
-
converterMinified;
|
|
10
10
|
constructor(config) {
|
|
11
11
|
validateConfig(config);
|
|
12
12
|
this.converterMinified = new ConverterMinified(config);
|
|
@@ -2,153 +2,149 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync } from "fs";
|
|
|
2
2
|
import { v4 as uuidv4 } from "uuid";
|
|
3
3
|
import path from "path";
|
|
4
4
|
class ConverterMinified {
|
|
5
|
-
cacheDir;
|
|
6
|
-
prefix;
|
|
7
|
-
reservedNames;
|
|
8
|
-
syncFreedNames;
|
|
9
|
-
symbols = [
|
|
10
|
-
"a",
|
|
11
|
-
"b",
|
|
12
|
-
"c",
|
|
13
|
-
"d",
|
|
14
|
-
"e",
|
|
15
|
-
"f",
|
|
16
|
-
"g",
|
|
17
|
-
"h",
|
|
18
|
-
"i",
|
|
19
|
-
"j",
|
|
20
|
-
"k",
|
|
21
|
-
"l",
|
|
22
|
-
"m",
|
|
23
|
-
"n",
|
|
24
|
-
"o",
|
|
25
|
-
"p",
|
|
26
|
-
"q",
|
|
27
|
-
"r",
|
|
28
|
-
"s",
|
|
29
|
-
"t",
|
|
30
|
-
"u",
|
|
31
|
-
"v",
|
|
32
|
-
"w",
|
|
33
|
-
"x",
|
|
34
|
-
"y",
|
|
35
|
-
"z",
|
|
36
|
-
"A",
|
|
37
|
-
"B",
|
|
38
|
-
"C",
|
|
39
|
-
"D",
|
|
40
|
-
"E",
|
|
41
|
-
"F",
|
|
42
|
-
"G",
|
|
43
|
-
"H",
|
|
44
|
-
"I",
|
|
45
|
-
"J",
|
|
46
|
-
"K",
|
|
47
|
-
"L",
|
|
48
|
-
"M",
|
|
49
|
-
"N",
|
|
50
|
-
"O",
|
|
51
|
-
"P",
|
|
52
|
-
"Q",
|
|
53
|
-
"R",
|
|
54
|
-
"S",
|
|
55
|
-
"T",
|
|
56
|
-
"U",
|
|
57
|
-
"V",
|
|
58
|
-
"W",
|
|
59
|
-
"X",
|
|
60
|
-
"Y",
|
|
61
|
-
"Z",
|
|
62
|
-
"0",
|
|
63
|
-
"1",
|
|
64
|
-
"2",
|
|
65
|
-
"3",
|
|
66
|
-
"4",
|
|
67
|
-
"5",
|
|
68
|
-
"6",
|
|
69
|
-
"7",
|
|
70
|
-
"8",
|
|
71
|
-
"9",
|
|
72
|
-
];
|
|
73
|
-
dirtyСache = {};
|
|
74
|
-
freeClasses = [];
|
|
75
|
-
lastIndex = 0;
|
|
76
|
-
nextLoopEndsWith = 26;
|
|
77
|
-
currentLoopLength = 0;
|
|
78
|
-
nameMap = [0];
|
|
79
5
|
constructor({ cacheDir, prefix = "", reservedNames = [], experimental }) {
|
|
80
|
-
this.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
6
|
+
this.symbols = [
|
|
7
|
+
"a",
|
|
8
|
+
"b",
|
|
9
|
+
"c",
|
|
10
|
+
"d",
|
|
11
|
+
"e",
|
|
12
|
+
"f",
|
|
13
|
+
"g",
|
|
14
|
+
"h",
|
|
15
|
+
"i",
|
|
16
|
+
"j",
|
|
17
|
+
"k",
|
|
18
|
+
"l",
|
|
19
|
+
"m",
|
|
20
|
+
"n",
|
|
21
|
+
"o",
|
|
22
|
+
"p",
|
|
23
|
+
"q",
|
|
24
|
+
"r",
|
|
25
|
+
"s",
|
|
26
|
+
"t",
|
|
27
|
+
"u",
|
|
28
|
+
"v",
|
|
29
|
+
"w",
|
|
30
|
+
"x",
|
|
31
|
+
"y",
|
|
32
|
+
"z",
|
|
33
|
+
"A",
|
|
34
|
+
"B",
|
|
35
|
+
"C",
|
|
36
|
+
"D",
|
|
37
|
+
"E",
|
|
38
|
+
"F",
|
|
39
|
+
"G",
|
|
40
|
+
"H",
|
|
41
|
+
"I",
|
|
42
|
+
"J",
|
|
43
|
+
"K",
|
|
44
|
+
"L",
|
|
45
|
+
"M",
|
|
46
|
+
"N",
|
|
47
|
+
"O",
|
|
48
|
+
"P",
|
|
49
|
+
"Q",
|
|
50
|
+
"R",
|
|
51
|
+
"S",
|
|
52
|
+
"T",
|
|
53
|
+
"U",
|
|
54
|
+
"V",
|
|
55
|
+
"W",
|
|
56
|
+
"X",
|
|
57
|
+
"Y",
|
|
58
|
+
"Z",
|
|
59
|
+
"0",
|
|
60
|
+
"1",
|
|
61
|
+
"2",
|
|
62
|
+
"3",
|
|
63
|
+
"4",
|
|
64
|
+
"5",
|
|
65
|
+
"6",
|
|
66
|
+
"7",
|
|
67
|
+
"8",
|
|
68
|
+
"9",
|
|
69
|
+
];
|
|
87
70
|
this.dirtyСache = {};
|
|
88
71
|
this.freeClasses = [];
|
|
89
72
|
this.lastIndex = 0;
|
|
90
73
|
this.nextLoopEndsWith = 26;
|
|
91
74
|
this.currentLoopLength = 0;
|
|
92
75
|
this.nameMap = [0];
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
cachedFiles.forEach((file) => {
|
|
112
|
-
const filePath = path.join(cacheDir, file);
|
|
113
|
-
const dirtyCacheFile = readFileSync(filePath, { encoding: "utf8" });
|
|
114
|
-
const [resourcePath, lastIndex, ...classnames] = dirtyCacheFile.split(",");
|
|
115
|
-
if (lastIndex && +lastIndex > prevLastIndex)
|
|
116
|
-
prevLastIndex = +lastIndex;
|
|
117
|
-
if (existsSync(resourcePath)) {
|
|
118
|
-
const cachedMatchings = classnames.reduce((acc, cur) => {
|
|
119
|
-
const [origClass, newClass] = cur.split("=");
|
|
120
|
-
acc[origClass] = newClass;
|
|
121
|
-
if (!usedClassNames.includes(newClass)) {
|
|
122
|
-
usedClassNames.push(newClass);
|
|
123
|
-
}
|
|
124
|
-
return acc;
|
|
125
|
-
}, {});
|
|
126
|
-
dirtyСache[resourcePath] = {
|
|
127
|
-
cachePath: filePath,
|
|
128
|
-
matchings: cachedMatchings,
|
|
129
|
-
type: "old",
|
|
130
|
-
};
|
|
76
|
+
this.reset = () => {
|
|
77
|
+
this.dirtyСache = {};
|
|
78
|
+
this.freeClasses = [];
|
|
79
|
+
this.lastIndex = 0;
|
|
80
|
+
this.nextLoopEndsWith = 26;
|
|
81
|
+
this.currentLoopLength = 0;
|
|
82
|
+
this.nameMap = [0];
|
|
83
|
+
if (this.cacheDir) {
|
|
84
|
+
this.invalidateCache(this.cacheDir);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
this.invalidateCache = (cacheDir) => {
|
|
88
|
+
this.cacheDir = cacheDir;
|
|
89
|
+
if (!existsSync(cacheDir))
|
|
90
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
91
|
+
const cachedFiles = readdirSync(cacheDir);
|
|
92
|
+
if (cachedFiles.length) {
|
|
93
|
+
console.log("classnames-minifier: Restoring pairs of classes...");
|
|
131
94
|
}
|
|
132
95
|
else {
|
|
133
|
-
|
|
96
|
+
return;
|
|
134
97
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
98
|
+
const usedClassNames = [];
|
|
99
|
+
const dirtyСache = {};
|
|
100
|
+
let prevLastIndex = 0;
|
|
101
|
+
cachedFiles.forEach((file) => {
|
|
102
|
+
const filePath = path.join(cacheDir, file);
|
|
103
|
+
const dirtyCacheFile = readFileSync(filePath, { encoding: "utf8" });
|
|
104
|
+
const [resourcePath, lastIndex, ...classnames] = dirtyCacheFile.split(",");
|
|
105
|
+
if (lastIndex && +lastIndex > prevLastIndex)
|
|
106
|
+
prevLastIndex = +lastIndex;
|
|
107
|
+
if (existsSync(resourcePath)) {
|
|
108
|
+
const cachedMatchings = classnames.reduce((acc, cur) => {
|
|
109
|
+
const [origClass, newClass] = cur.split("=");
|
|
110
|
+
acc[origClass] = newClass;
|
|
111
|
+
if (!usedClassNames.includes(newClass)) {
|
|
112
|
+
usedClassNames.push(newClass);
|
|
113
|
+
}
|
|
114
|
+
return acc;
|
|
115
|
+
}, {});
|
|
116
|
+
dirtyСache[resourcePath] = {
|
|
117
|
+
cachePath: filePath,
|
|
118
|
+
matchings: cachedMatchings,
|
|
119
|
+
type: "old",
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
rmSync(filePath);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
for (let i = 0; i <= prevLastIndex; i++) {
|
|
127
|
+
const newClass = this.generateClassName();
|
|
128
|
+
this.lastIndex += 1;
|
|
129
|
+
const usedClassNameIndex = usedClassNames.indexOf(newClass);
|
|
130
|
+
if (usedClassNameIndex !== -1) {
|
|
131
|
+
usedClassNames.splice(usedClassNameIndex, 1);
|
|
132
|
+
}
|
|
133
|
+
else if (!this.reservedNames.includes(newClass)) {
|
|
134
|
+
this.freeClasses.push(newClass);
|
|
135
|
+
}
|
|
142
136
|
}
|
|
143
|
-
|
|
144
|
-
|
|
137
|
+
if (cachedFiles.length) {
|
|
138
|
+
console.log("classnames-minifier: Pairs restored");
|
|
145
139
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.
|
|
151
|
-
|
|
140
|
+
this.dirtyСache = dirtyСache;
|
|
141
|
+
};
|
|
142
|
+
this.prefix = prefix;
|
|
143
|
+
this.reservedNames = reservedNames;
|
|
144
|
+
this.syncFreedNames = Boolean(experimental === null || experimental === void 0 ? void 0 : experimental.syncFreedNames);
|
|
145
|
+
if (cacheDir)
|
|
146
|
+
this.invalidateCache(path.join(cacheDir, "ncm"));
|
|
147
|
+
}
|
|
152
148
|
generateClassName() {
|
|
153
149
|
const symbolsCount = 62;
|
|
154
150
|
if (this.lastIndex >= this.nextLoopEndsWith) {
|
|
@@ -8,7 +8,7 @@ export default function (source, map, meta) {
|
|
|
8
8
|
*/
|
|
9
9
|
if (cache && cache.matchings) {
|
|
10
10
|
cache.matchings = maybeClassesList
|
|
11
|
-
? Object.fromEntries(Object.entries(cache.matchings).filter(([key]) => maybeClassesList
|
|
11
|
+
? Object.fromEntries(Object.entries(cache.matchings).filter(([key]) => maybeClassesList === null || maybeClassesList === void 0 ? void 0 : maybeClassesList.includes(`.${key}`)))
|
|
12
12
|
: {};
|
|
13
13
|
}
|
|
14
14
|
this.callback(null, source, map, meta);
|
|
@@ -10,6 +10,7 @@ const readManifest = (manifestPath) => {
|
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
const validateDist = (pluginOptions, manifestPath) => {
|
|
13
|
+
var _a, _b, _c;
|
|
13
14
|
const { cacheDir, distDir, prefix, reservedNames, distDeletionPolicy, checkDistFreshness } = pluginOptions;
|
|
14
15
|
if (!cacheDir || !distDir) {
|
|
15
16
|
console.log("classnames-minifier: Failed to check the dist folder because cacheDir or distDir is not specified");
|
|
@@ -28,9 +29,9 @@ const validateDist = (pluginOptions, manifestPath) => {
|
|
|
28
29
|
if (prevData.distDir !== distDir) {
|
|
29
30
|
configDiffMessages.push(`Different "distDir": "${prevData.distDir}" -> "${distDir}"`);
|
|
30
31
|
}
|
|
31
|
-
if (prevData.reservedNames
|
|
32
|
-
prevData.reservedNames
|
|
33
|
-
configDiffMessages.push(`Different "reservedNames": "${prevData.reservedNames
|
|
32
|
+
if (((_a = prevData.reservedNames) === null || _a === void 0 ? void 0 : _a.length) !== (reservedNames === null || reservedNames === void 0 ? void 0 : reservedNames.length) ||
|
|
33
|
+
((_b = prevData.reservedNames) === null || _b === void 0 ? void 0 : _b.some((name) => !(reservedNames === null || reservedNames === void 0 ? void 0 : reservedNames.includes(name))))) {
|
|
34
|
+
configDiffMessages.push(`Different "reservedNames": "${(_c = prevData.reservedNames) === null || _c === void 0 ? void 0 : _c.join(", ")}" -> "${reservedNames === null || reservedNames === void 0 ? void 0 : reservedNames.join(", ")}"`);
|
|
34
35
|
}
|
|
35
36
|
if (prevData.version !== CODE_VERSION) {
|
|
36
37
|
configDiffMessages.push(`Different package version: "${prevData.version}" -> "${CODE_VERSION}"`);
|
|
@@ -42,7 +43,7 @@ const validateDist = (pluginOptions, manifestPath) => {
|
|
|
42
43
|
configurationError = `Changes found in package configuration: \n${configDiffMessages.map((message) => `- ${message};\n`).join("")}`;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
else if (!checkDistFreshness
|
|
46
|
+
else if (!(checkDistFreshness === null || checkDistFreshness === void 0 ? void 0 : checkDistFreshness())) {
|
|
46
47
|
configurationError = `Can not find the package cache manifest at ${manifestPath}\n`;
|
|
47
48
|
}
|
|
48
49
|
return configurationError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "classnames-minifier",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-7dbcd07",
|
|
4
4
|
"description": "Library for configuring style modules to generate compressed classes",
|
|
5
5
|
"main": "dist/cjs/ClassnamesMinifier.js",
|
|
6
6
|
"module": "dist/esm/ClassnamesMinifier.mjs",
|
|
@@ -22,12 +22,6 @@
|
|
|
22
22
|
"import": "./dist/esm/ClassnamesMinifier.mjs",
|
|
23
23
|
"require": "./dist/cjs/ClassnamesMinifier.js",
|
|
24
24
|
"default": "./dist/esm/ClassnamesMinifier.mjs"
|
|
25
|
-
},
|
|
26
|
-
"./types": {
|
|
27
|
-
"types": "./dist/cjs/lib/types/plugin.d.ts",
|
|
28
|
-
"import": "./dist/esm/lib/types/plugin.d.ts",
|
|
29
|
-
"require": "./dist/cjs/lib/types/plugin.d.ts",
|
|
30
|
-
"default": "./dist/esm/lib/types/plugin.d.ts"
|
|
31
25
|
}
|
|
32
26
|
},
|
|
33
27
|
"keywords": [
|