@tochii/build 2.0.4 → 2.2.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.
@@ -0,0 +1,203 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkTWFEYLU4js = require('./chunk-TWFEYLU4.js');
4
+
5
+ // src/load.ts
6
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
7
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
8
+ var _joycon = require('joycon'); var _joycon2 = _interopRequireDefault(_joycon);
9
+ var _bundlerequire = require('bundle-require');
10
+ var joycon = new (0, _joycon2.default)();
11
+ var loadJson = async (filepath) => {
12
+ try {
13
+ return _chunkTWFEYLU4js.jsoncParse.call(void 0, await _fs2.default.promises.readFile(filepath, "utf8"));
14
+ } catch (error) {
15
+ if (error instanceof Error) {
16
+ throw new Error(
17
+ `Failed to parse ${_path2.default.relative(process.cwd(), filepath)}: ${error.message}`
18
+ );
19
+ } else {
20
+ throw error;
21
+ }
22
+ }
23
+ };
24
+ var jsonLoader = {
25
+ test: /\.json$/,
26
+ load(filepath) {
27
+ return loadJson(filepath);
28
+ }
29
+ };
30
+ joycon.addLoader(jsonLoader);
31
+ async function loadTsupConfig(cwd, configFile) {
32
+ const configJoycon = new (0, _joycon2.default)();
33
+ const configPath = await configJoycon.resolve({
34
+ files: configFile ? [configFile] : [
35
+ "tsup.config.ts",
36
+ "tsup.config.cts",
37
+ "tsup.config.mts",
38
+ "tsup.config.js",
39
+ "tsup.config.cjs",
40
+ "tsup.config.mjs",
41
+ "tsup.config.json",
42
+ "package.json"
43
+ ],
44
+ cwd,
45
+ stopDir: _path2.default.parse(cwd).root,
46
+ packageKey: "tsup"
47
+ });
48
+ if (configPath) {
49
+ if (configPath.endsWith(".json")) {
50
+ let data = await loadJson(configPath);
51
+ if (configPath.endsWith("package.json")) {
52
+ data = data.tsup;
53
+ }
54
+ if (data) {
55
+ return { path: configPath, data };
56
+ }
57
+ return {};
58
+ }
59
+ const config = await _bundlerequire.bundleRequire.call(void 0, {
60
+ filepath: configPath
61
+ });
62
+ return {
63
+ path: configPath,
64
+ data: config.mod.tsup || config.mod.default || config.mod
65
+ };
66
+ }
67
+ return {};
68
+ }
69
+ async function loadPkg(cwd, clearCache = false) {
70
+ if (clearCache) {
71
+ joycon.clearCache();
72
+ }
73
+ const { data } = await joycon.load(["package.json"], cwd, _path2.default.dirname(cwd));
74
+ return data || {};
75
+ }
76
+ async function getProductionDeps(cwd, clearCache = false) {
77
+ const data = await loadPkg(cwd, clearCache);
78
+ const deps = Array.from(
79
+ /* @__PURE__ */ new Set([
80
+ ...Object.keys(data.dependencies || {}),
81
+ ...Object.keys(data.peerDependencies || {})
82
+ ])
83
+ );
84
+ return deps;
85
+ }
86
+ async function getAllDepsHash(cwd) {
87
+ const data = await loadPkg(cwd, true);
88
+ return JSON.stringify({
89
+ ...data.dependencies,
90
+ ...data.peerDependencies,
91
+ ...data.devDependencies
92
+ });
93
+ }
94
+
95
+ // src/log.ts
96
+ var _util = require('util'); var _util2 = _interopRequireDefault(_util);
97
+ var _worker_threads = require('worker_threads');
98
+ var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
99
+ var colorize = (type, data, onlyImportant = false) => {
100
+ if (onlyImportant && (type === "info" || type === "success")) return data;
101
+ const color = type === "info" ? "blue" : type === "error" ? "red" : type === "warn" ? "yellow" : "green";
102
+ return _picocolors2.default[color](data);
103
+ };
104
+ var makeLabel = (name, input, type) => {
105
+ return [
106
+ name && `${_picocolors2.default.dim("[")}${name.toUpperCase()}${_picocolors2.default.dim("]")}`,
107
+ colorize(type, input.toUpperCase())
108
+ ].filter(Boolean).join(" ");
109
+ };
110
+ var silent = false;
111
+ function setSilent(isSilent) {
112
+ silent = !!isSilent;
113
+ }
114
+ function getSilent() {
115
+ return silent;
116
+ }
117
+ var createLogger = (name) => {
118
+ return {
119
+ setName(_name) {
120
+ name = _name;
121
+ },
122
+ success(label, ...args) {
123
+ return this.log(label, "success", ...args);
124
+ },
125
+ info(label, ...args) {
126
+ return this.log(label, "info", ...args);
127
+ },
128
+ error(label, ...args) {
129
+ return this.log(label, "error", ...args);
130
+ },
131
+ warn(label, ...args) {
132
+ return this.log(label, "warn", ...args);
133
+ },
134
+ log(label, type, ...data) {
135
+ const args = [
136
+ makeLabel(name, label, type),
137
+ ...data.map((item) => colorize(type, item, true))
138
+ ];
139
+ switch (type) {
140
+ case "error": {
141
+ if (!_worker_threads.isMainThread) {
142
+ _optionalChain([_worker_threads.parentPort, 'optionalAccess', _ => _.postMessage, 'call', _2 => _2({
143
+ type: "error",
144
+ text: _util2.default.format(...args)
145
+ })]);
146
+ return;
147
+ }
148
+ return console.error(...args);
149
+ }
150
+ default:
151
+ if (silent) return;
152
+ if (!_worker_threads.isMainThread) {
153
+ _optionalChain([_worker_threads.parentPort, 'optionalAccess', _3 => _3.postMessage, 'call', _4 => _4({
154
+ type: "log",
155
+ text: _util2.default.format(...args)
156
+ })]);
157
+ return;
158
+ }
159
+ console.log(...args);
160
+ }
161
+ }
162
+ };
163
+ };
164
+
165
+ // src/lib/report-size.ts
166
+
167
+ var prettyBytes = (bytes) => {
168
+ if (bytes === 0) return "0 B";
169
+ const unit = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
170
+ const exp = Math.floor(Math.log(bytes) / Math.log(1024));
171
+ return `${(bytes / 1024 ** exp).toFixed(2)} ${unit[exp]}`;
172
+ };
173
+ var getLengthOfLongestString = (strings) => {
174
+ return strings.reduce((max, str) => {
175
+ return Math.max(max, str.length);
176
+ }, 0);
177
+ };
178
+ var padRight = (str, maxLength) => {
179
+ return str + " ".repeat(maxLength - str.length);
180
+ };
181
+ var reportSize = (logger, format, files) => {
182
+ const filenames = Object.keys(files);
183
+ const maxLength = getLengthOfLongestString(filenames) + 1;
184
+ for (const name of filenames) {
185
+ logger.success(
186
+ format,
187
+ `${_picocolors2.default.bold(padRight(name, maxLength))}${_picocolors2.default.green(
188
+ prettyBytes(files[name])
189
+ )}`
190
+ );
191
+ }
192
+ };
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+ exports.loadTsupConfig = loadTsupConfig; exports.loadPkg = loadPkg; exports.getProductionDeps = getProductionDeps; exports.getAllDepsHash = getAllDepsHash; exports.setSilent = setSilent; exports.getSilent = getSilent; exports.createLogger = createLogger; exports.reportSize = reportSize;
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _chunkGZSSIGNCjs = require('./chunk-GZSSIGNC.js');
5
+ require('./chunk-BYH4XDRH.js');
6
+
7
+
8
+ var _chunkJZ25TPTYjs = require('./chunk-JZ25TPTY.js');
9
+ require('./chunk-TWFEYLU4.js');
10
+
11
+ // src/cli-default.ts
12
+ _chunkGZSSIGNCjs.main.call(void 0, ).catch(_chunkJZ25TPTYjs.handleError);
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkGZSSIGNCjs = require('./chunk-GZSSIGNC.js');
4
+ require('./chunk-BYH4XDRH.js');
5
+ require('./chunk-TWFEYLU4.js');
6
+
7
+
8
+ exports.main = _chunkGZSSIGNCjs.main;
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _chunkGZSSIGNCjs = require('./chunk-GZSSIGNC.js');
5
+ require('./chunk-BYH4XDRH.js');
6
+
7
+
8
+ var _chunkJZ25TPTYjs = require('./chunk-JZ25TPTY.js');
9
+ require('./chunk-TWFEYLU4.js');
10
+
11
+ // src/cli-node.ts
12
+ _chunkGZSSIGNCjs.main.call(void 0, {
13
+ skipNodeModulesBundle: true
14
+ }).catch(_chunkJZ25TPTYjs.handleError);