storm-lua-minify 0.1.2 → 0.1.3
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/cli.js +2 -2
- package/dist/minifier.js +5 -1
- package/package.json +1 -1
- package/src/cli.ts +2 -2
- package/src/minifier.ts +5 -1
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ const commander_1 = require("commander");
|
|
|
10
10
|
const minifier_1 = require("./minifier");
|
|
11
11
|
const program = new commander_1.Command();
|
|
12
12
|
program
|
|
13
|
-
.version("0.1.
|
|
13
|
+
.version("0.1.3")
|
|
14
14
|
.description("A Lua minifier also outputs source map")
|
|
15
15
|
.option("-m, --module-like-lua", "require・dofileの動作を実際のLuaに近づけます");
|
|
16
16
|
program.parse(process.argv);
|
|
@@ -36,7 +36,7 @@ luaFiles.forEach((fileName) => {
|
|
|
36
36
|
name: parsedFileName.name,
|
|
37
37
|
ext: parsedFileName.ext + ".map",
|
|
38
38
|
});
|
|
39
|
-
map.add("\n--[[\n//# sourceMappingURL=" + mapFileName + "\n]]");
|
|
39
|
+
map.add("\n--[[\n//# sourceMappingURL=" + path_1.default.basename(mapFileName) + "\n]]");
|
|
40
40
|
const sourceAndMap = map.toStringWithSourceMap();
|
|
41
41
|
fs_1.default.writeFileSync(minFileName, sourceAndMap.code);
|
|
42
42
|
fs_1.default.writeFileSync(mapFileName, JSON.stringify(sourceAndMap.map));
|
package/dist/minifier.js
CHANGED
|
@@ -15,6 +15,7 @@ class Minifier {
|
|
|
15
15
|
moduleSourceText;
|
|
16
16
|
moduleSourceNode;
|
|
17
17
|
moduleAST;
|
|
18
|
+
moduleNameAndFileName;
|
|
18
19
|
dir;
|
|
19
20
|
entryModule;
|
|
20
21
|
mode;
|
|
@@ -25,6 +26,7 @@ class Minifier {
|
|
|
25
26
|
this.moduleSourceText = new Map();
|
|
26
27
|
this.moduleSourceNode = new Map();
|
|
27
28
|
this.moduleAST = new Map();
|
|
29
|
+
this.moduleNameAndFileName = new Map();
|
|
28
30
|
this.luaParseSettings = luaParseSettings;
|
|
29
31
|
this.mode = mode;
|
|
30
32
|
const pn = path_1.default.parse(entryFilePath);
|
|
@@ -65,6 +67,7 @@ class Minifier {
|
|
|
65
67
|
]);
|
|
66
68
|
});
|
|
67
69
|
}
|
|
70
|
+
this.moduleSourceText.forEach((v, k) => { const fileName = this.moduleNameAndFileName.get(k); fileName && sn.setSourceContent(fileName, v); });
|
|
68
71
|
return sn;
|
|
69
72
|
}
|
|
70
73
|
parseModule(moduleName) {
|
|
@@ -81,10 +84,11 @@ class Minifier {
|
|
|
81
84
|
const ast = luaparse_1.default.parse(code, this.luaParseSettings);
|
|
82
85
|
if ("globals" in ast) {
|
|
83
86
|
ast.globals?.map((v) => this.identifiersInUse.add(v.name));
|
|
84
|
-
const sourceNode = new ast2lua_1.MinifyFile(resolvePath, ast, this, this.mode).parse(
|
|
87
|
+
const sourceNode = new ast2lua_1.MinifyFile(resolvePath, ast, this, this.mode).parse(moduleName === this.entryModule);
|
|
85
88
|
this.moduleSourceText.set(moduleName, code);
|
|
86
89
|
this.moduleAST.set(moduleName, ast);
|
|
87
90
|
this.moduleSourceNode.set(moduleName, sourceNode);
|
|
91
|
+
this.moduleNameAndFileName.set(moduleName, resolvePath);
|
|
88
92
|
return sourceNode;
|
|
89
93
|
}
|
|
90
94
|
}
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { Minifier, MinifierMode } from "./minifier";
|
|
|
9
9
|
const program = new Command();
|
|
10
10
|
|
|
11
11
|
program
|
|
12
|
-
.version("0.1.
|
|
12
|
+
.version("0.1.3")
|
|
13
13
|
.description("A Lua minifier also outputs source map")
|
|
14
14
|
.option(
|
|
15
15
|
"-m, --module-like-lua",
|
|
@@ -44,7 +44,7 @@ luaFiles.forEach((fileName) => {
|
|
|
44
44
|
name: parsedFileName.name,
|
|
45
45
|
ext: parsedFileName.ext + ".map",
|
|
46
46
|
});
|
|
47
|
-
map.add("\n--[[\n//# sourceMappingURL=" + mapFileName + "\n]]");
|
|
47
|
+
map.add("\n--[[\n//# sourceMappingURL=" + path.basename(mapFileName) + "\n]]");
|
|
48
48
|
|
|
49
49
|
const sourceAndMap = map.toStringWithSourceMap();
|
|
50
50
|
|
package/src/minifier.ts
CHANGED
|
@@ -14,6 +14,7 @@ export class Minifier {
|
|
|
14
14
|
readonly moduleSourceText: Map<string, string>;
|
|
15
15
|
readonly moduleSourceNode: Map<string, SourceNode>;
|
|
16
16
|
readonly moduleAST: Map<string, Chunk>;
|
|
17
|
+
readonly moduleNameAndFileName: Map<string, string>;
|
|
17
18
|
readonly dir: string;
|
|
18
19
|
readonly entryModule: string;
|
|
19
20
|
readonly mode: MinifierMode;
|
|
@@ -29,6 +30,7 @@ export class Minifier {
|
|
|
29
30
|
this.moduleSourceText = new Map<string, string>();
|
|
30
31
|
this.moduleSourceNode = new Map<string, SourceNode>();
|
|
31
32
|
this.moduleAST = new Map<string, Chunk>();
|
|
33
|
+
this.moduleNameAndFileName = new Map<string, string>();
|
|
32
34
|
this.luaParseSettings = luaParseSettings;
|
|
33
35
|
this.mode = mode;
|
|
34
36
|
const pn = path.parse(entryFilePath);
|
|
@@ -78,6 +80,7 @@ export class Minifier {
|
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
|
|
83
|
+
this.moduleSourceText.forEach((v, k) => { const fileName = this.moduleNameAndFileName.get(k); fileName && sn.setSourceContent(fileName, v) });
|
|
81
84
|
return sn;
|
|
82
85
|
}
|
|
83
86
|
|
|
@@ -101,11 +104,12 @@ export class Minifier {
|
|
|
101
104
|
ast,
|
|
102
105
|
this,
|
|
103
106
|
this.mode
|
|
104
|
-
).parse(
|
|
107
|
+
).parse(moduleName === this.entryModule);
|
|
105
108
|
|
|
106
109
|
this.moduleSourceText.set(moduleName, code);
|
|
107
110
|
this.moduleAST.set(moduleName, ast);
|
|
108
111
|
this.moduleSourceNode.set(moduleName, sourceNode);
|
|
112
|
+
this.moduleNameAndFileName.set(moduleName, resolvePath);
|
|
109
113
|
return sourceNode;
|
|
110
114
|
}
|
|
111
115
|
}
|