classnames-minifier 0.2.0 → 0.2.2
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.
|
@@ -20,15 +20,28 @@ class ClassnamesMinifier {
|
|
|
20
20
|
else {
|
|
21
21
|
const manifestDir = path_1.default.join(config.cacheDir, "ncm-meta");
|
|
22
22
|
const manifestPath = path_1.default.join(manifestDir, "manifest.json");
|
|
23
|
+
let distCleared = false;
|
|
23
24
|
if (config.cacheDir) {
|
|
24
|
-
(0, validateDist_1.default)(config, manifestPath);
|
|
25
|
+
const errors = (0, validateDist_1.default)(config, manifestPath);
|
|
26
|
+
if (errors) {
|
|
27
|
+
if (!config.disableDistDeletion) {
|
|
28
|
+
(0, rmDist_1.default)(config.distDir, errors);
|
|
29
|
+
distCleared = true;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log(`classnames-minifier: ${errors}"disableDistDeletion" option was set to true`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
const { freedNamesPolicy = "transmit", blockLimit = 100000 } = config.experimental || {};
|
|
27
37
|
if (freedNamesPolicy === "block" &&
|
|
28
38
|
this.converterMinified.freeClasses.length > blockLimit &&
|
|
29
39
|
config.distDir) {
|
|
40
|
+
distCleared = true;
|
|
30
41
|
(0, rmDist_1.default)(config.distDir, `Freed names exceeds the limit (${blockLimit})`);
|
|
31
|
-
|
|
42
|
+
}
|
|
43
|
+
if (distCleared) {
|
|
44
|
+
this.converterMinified.reset();
|
|
32
45
|
}
|
|
33
46
|
if (!fs_1.default.existsSync(manifestDir))
|
|
34
47
|
fs_1.default.mkdirSync(manifestDir, { recursive: true });
|
|
@@ -22,8 +22,8 @@ declare class ConverterMinified {
|
|
|
22
22
|
private currentLoopLength;
|
|
23
23
|
private nameMap;
|
|
24
24
|
constructor({ cacheDir, prefix, reservedNames, experimental }: Config);
|
|
25
|
-
|
|
26
|
-
private
|
|
25
|
+
reset: () => void;
|
|
26
|
+
private invalidateCache;
|
|
27
27
|
private generateClassName;
|
|
28
28
|
private getTargetClassName;
|
|
29
29
|
getLocalIdent({ resourcePath }: LoaderContext<any>, _localIdent: string, origName: string): string;
|
|
@@ -78,15 +78,18 @@ class ConverterMinified {
|
|
|
78
78
|
this.nextLoopEndsWith = 26;
|
|
79
79
|
this.currentLoopLength = 0;
|
|
80
80
|
this.nameMap = [0];
|
|
81
|
-
this.
|
|
81
|
+
this.reset = () => {
|
|
82
82
|
this.dirtyСache = {};
|
|
83
83
|
this.freeClasses = [];
|
|
84
84
|
this.lastIndex = 0;
|
|
85
85
|
this.nextLoopEndsWith = 26;
|
|
86
86
|
this.currentLoopLength = 0;
|
|
87
87
|
this.nameMap = [0];
|
|
88
|
+
if (this.cacheDir) {
|
|
89
|
+
this.invalidateCache(this.cacheDir);
|
|
90
|
+
}
|
|
88
91
|
};
|
|
89
|
-
this.
|
|
92
|
+
this.invalidateCache = (cacheDir) => {
|
|
90
93
|
this.cacheDir = cacheDir;
|
|
91
94
|
if (!(0, fs_1.existsSync)(cacheDir))
|
|
92
95
|
(0, fs_1.mkdirSync)(cacheDir, { recursive: true });
|
|
@@ -94,6 +97,9 @@ class ConverterMinified {
|
|
|
94
97
|
if (cachedFiles.length) {
|
|
95
98
|
console.log("classnames-minifier: Restoring pairs of classes...");
|
|
96
99
|
}
|
|
100
|
+
else {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
97
103
|
const usedClassNames = [];
|
|
98
104
|
const dirtyСache = {};
|
|
99
105
|
let prevLastIndex = 0;
|
|
@@ -142,7 +148,7 @@ class ConverterMinified {
|
|
|
142
148
|
this.reservedNames = reservedNames;
|
|
143
149
|
this.freedNamesPolicy = (experimental === null || experimental === void 0 ? void 0 : experimental.freedNamesPolicy) || "transmit";
|
|
144
150
|
if (cacheDir)
|
|
145
|
-
this.
|
|
151
|
+
this.invalidateCache(path_1.default.join(cacheDir, "ncm"));
|
|
146
152
|
}
|
|
147
153
|
generateClassName() {
|
|
148
154
|
const symbolsCount = 62;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const validKeys = ["prefix", "reservedNames", "cacheDir", "distDir", "disableDistDeletion"];
|
|
3
|
+
const validKeys = ["prefix", "reservedNames", "cacheDir", "distDir", "disableDistDeletion", "experimental"];
|
|
4
4
|
const validateIsObject = (config) => {
|
|
5
5
|
if (!config)
|
|
6
6
|
return false;
|
package/dist/lib/validateDist.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const configuration_1 = require("./constants/configuration");
|
|
8
|
-
const rmDist_1 = __importDefault(require("./rmDist"));
|
|
9
8
|
const readManifest = (manifestPath) => {
|
|
10
9
|
try {
|
|
11
10
|
const prevData = fs_1.default.readFileSync(manifestPath, { encoding: "utf-8" });
|
|
@@ -52,13 +51,6 @@ const validateDist = (pluginOptions, manifestPath) => {
|
|
|
52
51
|
else {
|
|
53
52
|
configurationError = `Can not find the package cache manifest at ${manifestPath}\n`;
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
if (!disableDistDeletion) {
|
|
57
|
-
(0, rmDist_1.default)(distDir, configurationError);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
console.log(`classnames-minifier: ${configurationError}"disableDistDeletion" option was set to true`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
54
|
+
return configurationError;
|
|
63
55
|
};
|
|
64
56
|
exports.default = validateDist;
|
package/package.json
CHANGED