quickbundle 0.12.0 → 0.15.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/LICENSE +21 -0
- package/README.md +18 -1
- package/bin/bundler/bundler.d.ts +5 -8
- package/bin/bundler/bundler.js +88 -117
- package/bin/bundler/index.js +1 -6
- package/bin/bundler/package.d.ts +9 -9
- package/bin/bundler/package.js +20 -29
- package/bin/bundler/plugins.d.ts +1 -3
- package/bin/bundler/plugins.js +25 -56
- package/bin/bundler/typescript.d.ts +5 -9
- package/bin/bundler/typescript.js +65 -144
- package/bin/helpers.d.ts +3 -4
- package/bin/helpers.js +47 -9
- package/bin/program/commands/build.d.ts +1 -3
- package/bin/program/commands/build.js +69 -105
- package/bin/program/commands/watch.d.ts +1 -3
- package/bin/program/commands/watch.js +71 -95
- package/bin/program/index.js +10 -13
- package/bin/program/types.d.ts +1 -1
- package/bin/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -9
|
@@ -1,154 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
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
|
-
: function (o, v) {
|
|
37
|
-
o["default"] = v;
|
|
38
|
-
});
|
|
39
|
-
var __importStar =
|
|
40
|
-
(this && this.__importStar) ||
|
|
41
|
-
function (mod) {
|
|
42
|
-
if (mod && mod.__esModule) return mod;
|
|
43
|
-
var result = {};
|
|
44
|
-
if (mod != null)
|
|
45
|
-
for (var k in mod)
|
|
46
|
-
if (
|
|
47
|
-
k !== "default" &&
|
|
48
|
-
Object.prototype.hasOwnProperty.call(mod, k)
|
|
49
|
-
)
|
|
50
|
-
__createBinding(result, mod, k);
|
|
51
|
-
__setModuleDefault(result, mod);
|
|
52
|
-
return result;
|
|
53
|
-
};
|
|
54
|
-
var __awaiter =
|
|
55
|
-
(this && this.__awaiter) ||
|
|
56
|
-
function (thisArg, _arguments, P, generator) {
|
|
57
|
-
function adopt(value) {
|
|
58
|
-
return value instanceof P
|
|
59
|
-
? value
|
|
60
|
-
: new P(function (resolve) {
|
|
61
|
-
resolve(value);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65
|
-
function fulfilled(value) {
|
|
66
|
-
try {
|
|
67
|
-
step(generator.next(value));
|
|
68
|
-
} catch (e) {
|
|
69
|
-
reject(e);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function rejected(value) {
|
|
73
|
-
try {
|
|
74
|
-
step(generator["throw"](value));
|
|
75
|
-
} catch (e) {
|
|
76
|
-
reject(e);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function step(result) {
|
|
80
|
-
result.done
|
|
81
|
-
? resolve(result.value)
|
|
82
|
-
: adopt(result.value).then(fulfilled, rejected);
|
|
83
|
-
}
|
|
84
|
-
step(
|
|
85
|
-
(generator = generator.apply(thisArg, _arguments || [])).next()
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
};
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
89
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90
|
-
exports.hasTypeScript =
|
|
91
|
-
exports.generateTypeScriptDeclaration =
|
|
92
|
-
exports.getTypeScriptConfiguration =
|
|
93
|
-
void 0;
|
|
35
|
+
exports.hasTypeScript = exports.generateTypeScriptDeclaration = exports.getTypeScriptConfiguration = void 0;
|
|
94
36
|
const path_1 = require("path");
|
|
95
37
|
const termost_1 = require("termost");
|
|
96
38
|
const constants_1 = require("../constants");
|
|
97
|
-
const getTypeScriptConfiguration = () =>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
? "esnext"
|
|
119
|
-
: (_a = ts.ScriptTarget[target]) === null || _a === void 0
|
|
120
|
-
? void 0
|
|
121
|
-
: _a.toLowerCase();
|
|
122
|
-
const hasJsxRuntime =
|
|
123
|
-
jsx !== undefined &&
|
|
124
|
-
[ts.JsxEmit["ReactJSX"], ts.JsxEmit["ReactJSXDev"]].includes(
|
|
125
|
-
jsx
|
|
126
|
-
);
|
|
127
|
-
return {
|
|
128
|
-
target: esbuildTarget,
|
|
129
|
-
jsxImportSource,
|
|
130
|
-
hasJsxRuntime,
|
|
131
|
-
};
|
|
132
|
-
} catch (error) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
39
|
+
const getTypeScriptConfiguration = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
var _a;
|
|
41
|
+
try {
|
|
42
|
+
const ts = yield Promise.resolve().then(() => __importStar(require("typescript")));
|
|
43
|
+
const { jsx, jsxImportSource, target } = ts.parseJsonConfigFileContent(require((0, path_1.resolve)(constants_1.CWD, "tsconfig.json")), ts.sys, constants_1.CWD).options;
|
|
44
|
+
const esbuildTarget = !target ||
|
|
45
|
+
[ts.ScriptTarget.ESNext, ts.ScriptTarget.Latest].includes(target)
|
|
46
|
+
? "esnext"
|
|
47
|
+
: (_a = ts.ScriptTarget[target]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
48
|
+
const hasJsxRuntime = jsx !== undefined &&
|
|
49
|
+
[ts.JsxEmit["ReactJSX"], ts.JsxEmit["ReactJSXDev"]].includes(jsx);
|
|
50
|
+
return {
|
|
51
|
+
target: esbuildTarget,
|
|
52
|
+
jsxImportSource,
|
|
53
|
+
hasJsxRuntime,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
136
60
|
exports.getTypeScriptConfiguration = getTypeScriptConfiguration;
|
|
137
|
-
const generateTypeScriptDeclaration = (outfile) =>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
throw new Error(`Type generation failed:\n${error}`);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
61
|
+
const generateTypeScriptDeclaration = (outfile) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
const outdir = (0, path_1.dirname)(outfile);
|
|
63
|
+
try {
|
|
64
|
+
yield termost_1.helpers.exec(`tsc --declaration --emitDeclarationOnly --incremental --removeComments false --outDir ${outdir}`, { cwd: constants_1.CWD });
|
|
65
|
+
return outdir;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new Error(`Type generation failed:\n${error}`);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
150
71
|
exports.generateTypeScriptDeclaration = generateTypeScriptDeclaration;
|
|
151
72
|
const hasTypeScript = (tsConfig) => {
|
|
152
|
-
|
|
73
|
+
return Boolean(tsConfig);
|
|
153
74
|
};
|
|
154
75
|
exports.hasTypeScript = hasTypeScript;
|
package/bin/helpers.d.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { readFile as fsReadFile } from "fs";
|
|
3
3
|
export declare const readFile: typeof fsReadFile.__promisify__;
|
|
4
4
|
export declare const resolveModulePath: (path: string) => boolean;
|
|
5
|
-
export declare function assert(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
): asserts condition;
|
|
5
|
+
export declare function assert(condition: unknown, message: string): asserts condition;
|
|
6
|
+
export declare const getAvailablePortFrom: (port: number) => Promise<number>;
|
|
7
|
+
export declare const openBrowser: (filename: string) => void;
|
package/bin/helpers.js
CHANGED
|
@@ -1,21 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assert = exports.resolveModulePath = exports.readFile = void 0;
|
|
12
|
+
exports.openBrowser = exports.getAvailablePortFrom = exports.assert = exports.resolveModulePath = exports.readFile = void 0;
|
|
4
13
|
const util_1 = require("util");
|
|
5
14
|
const fs_1 = require("fs");
|
|
15
|
+
const net_1 = require("net");
|
|
16
|
+
const child_process_1 = require("child_process");
|
|
6
17
|
const constants_1 = require("./constants");
|
|
7
18
|
exports.readFile = (0, util_1.promisify)(fs_1.readFile);
|
|
8
19
|
const resolveModulePath = (path) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
try {
|
|
21
|
+
return Boolean(require.resolve(path, { paths: [constants_1.CWD] }));
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
14
26
|
};
|
|
15
27
|
exports.resolveModulePath = resolveModulePath;
|
|
16
28
|
function assert(condition, message) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
if (!condition) {
|
|
30
|
+
throw new Error(message);
|
|
31
|
+
}
|
|
20
32
|
}
|
|
21
33
|
exports.assert = assert;
|
|
34
|
+
const getAvailablePortFrom = (port) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
const server = (0, net_1.createServer)();
|
|
37
|
+
server.listen(port);
|
|
38
|
+
server.on("listening", () => server.close(() => resolve(port)));
|
|
39
|
+
server.on("error", () => {
|
|
40
|
+
server.listen(++port);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
exports.getAvailablePortFrom = getAvailablePortFrom;
|
|
45
|
+
const openBrowser = (filename) => {
|
|
46
|
+
const bins = {
|
|
47
|
+
darwin: "open",
|
|
48
|
+
linux: "xdg-open",
|
|
49
|
+
};
|
|
50
|
+
const { platform } = process;
|
|
51
|
+
if (platform !== "darwin" && platform !== "linux") {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!(0, fs_1.existsSync)(filename)) {
|
|
55
|
+
throw new Error(`Unable to find ${filename}.\nPotential solutions:\n1. Create the missing file\n2. Edit the serve entrypoint to match an existing html file`);
|
|
56
|
+
}
|
|
57
|
+
(0, child_process_1.spawn)(bins[platform], [filename]);
|
|
58
|
+
};
|
|
59
|
+
exports.openBrowser = openBrowser;
|
|
@@ -1,44 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
step(generator.next(value));
|
|
16
|
-
} catch (e) {
|
|
17
|
-
reject(e);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function rejected(value) {
|
|
21
|
-
try {
|
|
22
|
-
step(generator["throw"](value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function step(result) {
|
|
28
|
-
result.done
|
|
29
|
-
? resolve(result.value)
|
|
30
|
-
: adopt(result.value).then(fulfilled, rejected);
|
|
31
|
-
}
|
|
32
|
-
step(
|
|
33
|
-
(generator = generator.apply(thisArg, _arguments || [])).next()
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var __importDefault =
|
|
38
|
-
(this && this.__importDefault) ||
|
|
39
|
-
function (mod) {
|
|
40
|
-
return mod && mod.__esModule ? mod : { default: mod };
|
|
41
|
-
};
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
42
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
15
|
exports.createBuildCommand = void 0;
|
|
44
16
|
const gzip_size_1 = __importDefault(require("gzip-size"));
|
|
@@ -46,70 +18,62 @@ const termost_1 = require("termost");
|
|
|
46
18
|
const bundler_1 = require("../../bundler");
|
|
47
19
|
const helpers_1 = require("../../helpers");
|
|
48
20
|
const createBuildCommand = (program) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
});
|
|
21
|
+
program
|
|
22
|
+
.command({
|
|
23
|
+
name: "build",
|
|
24
|
+
description: "Build the source code (production mode)",
|
|
25
|
+
})
|
|
26
|
+
.task({
|
|
27
|
+
key: "outfiles",
|
|
28
|
+
label: "Bundle assets 📦",
|
|
29
|
+
handler(context) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const outfiles = yield (0, bundler_1.bundle)({
|
|
32
|
+
isFast: context.noCheck,
|
|
33
|
+
isProduction: true,
|
|
34
|
+
});
|
|
35
|
+
return outfiles.filter((outfile) => outfile !== null);
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
.task({
|
|
40
|
+
key: "sizes",
|
|
41
|
+
label: "Compute sizes 🔢",
|
|
42
|
+
handler(context) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
return yield calculateBundleSize(context.outfiles);
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
.task({
|
|
49
|
+
handler(context) {
|
|
50
|
+
const padding = context.sizes
|
|
51
|
+
.map((item) => item.raw)
|
|
52
|
+
.reduce((pad, currentRawSize) => {
|
|
53
|
+
return Math.max(pad, String(currentRawSize).length);
|
|
54
|
+
}, 0) + 2;
|
|
55
|
+
context.sizes.forEach((item) => {
|
|
56
|
+
termost_1.helpers.message([
|
|
57
|
+
`${item.raw.toString().padStart(padding)} B raw`,
|
|
58
|
+
`${item.gzip.toString().padStart(padding)} B gz`,
|
|
59
|
+
], {
|
|
60
|
+
label: item.filename,
|
|
61
|
+
type: "information",
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
});
|
|
98
66
|
};
|
|
99
67
|
exports.createBuildCommand = createBuildCommand;
|
|
100
|
-
const calculateBundleSize = (filenames) =>
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return yield Promise.all(
|
|
113
|
-
filenames.map((filename) => calculateFileSize(filename))
|
|
114
|
-
);
|
|
115
|
-
});
|
|
68
|
+
const calculateBundleSize = (filenames) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const calculateFileSize = (filename) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
const content = yield (0, helpers_1.readFile)(filename);
|
|
71
|
+
const gzSize = yield (0, gzip_size_1.default)(content);
|
|
72
|
+
return {
|
|
73
|
+
filename,
|
|
74
|
+
raw: content.byteLength,
|
|
75
|
+
gzip: gzSize,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
return yield Promise.all(filenames.map((filename) => calculateFileSize(filename)));
|
|
79
|
+
});
|