@voidzero-dev/vite-plus-core 0.1.12-alpha.2 → 0.1.13-alpha.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/dist/rolldown/cli.mjs +1 -1
- package/dist/rolldown/config.mjs +1 -1
- package/dist/rolldown/experimental-index.mjs +1 -1
- package/dist/rolldown/index.mjs +1 -1
- package/dist/rolldown/parallel-plugin-worker.mjs +1 -1
- package/dist/rolldown/parse-ast-index.mjs +1 -1
- package/dist/rolldown/shared/{parse-8FR1cSLd.mjs → parse-BhVn_3w_.mjs} +1 -1
- package/dist/rolldown/utils-index.d.mts +1 -1
- package/dist/rolldown/utils-index.mjs +4 -4
- package/dist/tsdown/{build-CpOl_krN-DrIRjiqJ.js → build-CoLhkNXE-DtR1EaBG.js} +154 -109
- package/dist/tsdown/{build-B1oBkI4C-Bj4wFOdV.js → build-dhDyu66J-DxSssGzc.js} +2 -2
- package/dist/tsdown/{debug-C4FmgzkJ-BcERCViE.js → debug-C4FmgzkJ-Co4tnxmE.js} +2 -2
- package/dist/tsdown/{detect-J1_Vd1yf-BnOcNWHf.js → detect-DN3DXXYt-BiiMP_XL.js} +2 -8
- package/dist/tsdown/{dist-DceV6s_v.js → dist-BWGgEAtQ.js} +12 -12
- package/dist/tsdown/{dist-CtF_Stv5.js → dist-dJp148cE.js} +3 -3
- package/dist/tsdown/index-types.d.ts +49 -8
- package/dist/tsdown/index.js +4 -4
- package/dist/tsdown/{main-4fHWraTN.js → main-JovZVvCY.js} +114 -133
- package/dist/tsdown/run.js +5 -5
- package/package.json +11 -11
- package/dist/tsdown/index-node-Bpsmc0eX-CRDsfhY9.js +0 -249
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import util from "node:util";
|
|
2
|
-
import cp$1 from "node:child_process";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import fs from "node:fs/promises";
|
|
5
|
-
import os from "node:os";
|
|
6
|
-
import zlib from "node:zlib";
|
|
7
|
-
//#region ../../node_modules/.pnpm/tsdown@0.21.2_@arethetypeswrong+core@0.18.2_@tsdown+css@0.21.2_@tsdown+exe@0.21.2_@type_059aa640a91d945cefc9d8c8db7a9cd0/node_modules/tsdown/dist/index-node-Bpsmc0eX.mjs
|
|
8
|
-
/** @type {import('../index.d.ts').pack} */
|
|
9
|
-
async function pack(dir, opts) {
|
|
10
|
-
const packageManager = opts?.packageManager ?? "npm";
|
|
11
|
-
let command = `${packageManager} pack`;
|
|
12
|
-
if (packageManager === "bun") command = command.replace("bun", "bun pm");
|
|
13
|
-
const packDestination = opts?.destination ?? dir;
|
|
14
|
-
if (opts?.destination) switch (packageManager) {
|
|
15
|
-
case "yarn":
|
|
16
|
-
command += ` --out \"${path.join(packDestination, "package.tgz")}\"`;
|
|
17
|
-
break;
|
|
18
|
-
case "bun":
|
|
19
|
-
command += ` --destination \"${packDestination}\"`;
|
|
20
|
-
break;
|
|
21
|
-
default:
|
|
22
|
-
command += ` --pack-destination \"${packDestination}\"`;
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
if (opts?.ignoreScripts) switch (packageManager) {
|
|
26
|
-
case "pnpm":
|
|
27
|
-
command += " --config.ignore-scripts=true";
|
|
28
|
-
break;
|
|
29
|
-
case "yarn": break;
|
|
30
|
-
default:
|
|
31
|
-
command += " --ignore-scripts";
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
const output = await util.promisify(cp$1.exec)(command, { cwd: dir });
|
|
35
|
-
const tarballFile = await fs.readdir(packDestination).then((files) => {
|
|
36
|
-
return files.find((file) => file.endsWith(".tgz") && output.stdout.includes(file));
|
|
37
|
-
});
|
|
38
|
-
if (!tarballFile) if (output.stdout.startsWith("yarn pack v1")) throw new Error(`Yarn 1 is not supported to pack files. Command output:\n${JSON.stringify(output, null, 2)}`);
|
|
39
|
-
else throw new Error(`Failed to find packed tarball file in ${packDestination}. Command output:\n${JSON.stringify(output, null, 2)}`);
|
|
40
|
-
return path.join(packDestination, tarballFile);
|
|
41
|
-
}
|
|
42
|
-
async function getTempPackDir() {
|
|
43
|
-
const tempDir = os.tmpdir() + path.sep;
|
|
44
|
-
const tempPackDir = await fs.mkdtemp(tempDir + "publint-pack-");
|
|
45
|
-
return await fs.realpath(tempPackDir);
|
|
46
|
-
}
|
|
47
|
-
/** @type {import('../index.d.ts').packAsJson} */
|
|
48
|
-
async function packAsJson(dir, opts) {
|
|
49
|
-
const packageManager = opts?.packageManager ?? "npm";
|
|
50
|
-
if (packageManager === "bun") throw new Error("`packAsJson` is not supported for `bun`");
|
|
51
|
-
let command = `${packageManager} pack --json`;
|
|
52
|
-
const supportsDryRun = packageManager === "npm" || packageManager === "yarn";
|
|
53
|
-
/** @type {string | undefined} */
|
|
54
|
-
let packDestination;
|
|
55
|
-
if (supportsDryRun) command += " --dry-run";
|
|
56
|
-
else {
|
|
57
|
-
packDestination = await getTempPackDir();
|
|
58
|
-
command += ` --pack-destination ${packDestination}`;
|
|
59
|
-
}
|
|
60
|
-
if (opts?.ignoreScripts) switch (packageManager) {
|
|
61
|
-
case "pnpm":
|
|
62
|
-
command += " --config.ignore-scripts=true";
|
|
63
|
-
break;
|
|
64
|
-
case "yarn": break;
|
|
65
|
-
default:
|
|
66
|
-
command += " --ignore-scripts";
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
let { stdout } = await util.promisify(cp$1.exec)(command, { cwd: dir });
|
|
70
|
-
try {
|
|
71
|
-
stdout = stdout.trim();
|
|
72
|
-
if (packageManager === "pnpm") stdout = fixPnpmStdout(stdout);
|
|
73
|
-
else if (packageManager === "yarn") stdout = fixYarnStdout(stdout);
|
|
74
|
-
return JSON.parse(stdout);
|
|
75
|
-
} finally {
|
|
76
|
-
if (!supportsDryRun && packDestination) await fs.rm(packDestination, { recursive: true });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @param {string} stdout
|
|
81
|
-
*/
|
|
82
|
-
function fixPnpmStdout(stdout) {
|
|
83
|
-
if (stdout.startsWith("{")) return stdout;
|
|
84
|
-
const usualStartIndex = /\{\s*"name"/.exec(stdout)?.index;
|
|
85
|
-
if (usualStartIndex != null) return stdout.slice(usualStartIndex);
|
|
86
|
-
const firstBraceIndex = stdout.indexOf("{");
|
|
87
|
-
if (firstBraceIndex !== -1) return stdout.slice(firstBraceIndex);
|
|
88
|
-
return stdout;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* @param {string} stdout
|
|
92
|
-
*/
|
|
93
|
-
function fixYarnStdout(stdout) {
|
|
94
|
-
const lines = stdout.split("\n");
|
|
95
|
-
let fixedStdout = "[";
|
|
96
|
-
for (const line of lines) if (line) fixedStdout += line + ",";
|
|
97
|
-
if (fixedStdout[fixedStdout.length - 1] === ",") fixedStdout = fixedStdout.slice(0, -1);
|
|
98
|
-
fixedStdout += "]";
|
|
99
|
-
return fixedStdout;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* @param {ReadableStream<Uint8Array>} readableStream
|
|
103
|
-
* @returns {Promise<ArrayBuffer>}
|
|
104
|
-
*/
|
|
105
|
-
async function readableStreamToArrayBuffer(readableStream) {
|
|
106
|
-
return await new Response(readableStream).arrayBuffer();
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* @param {ArrayBuffer} buffer
|
|
110
|
-
* @returns {import('../index.d.ts').TarballFile[]}
|
|
111
|
-
*/
|
|
112
|
-
function parseTar(buffer) {
|
|
113
|
-
const decoder = new TextDecoder();
|
|
114
|
-
/** @type {import('../index.d.ts').TarballFile[]} */
|
|
115
|
-
const files = [];
|
|
116
|
-
let offset = 0;
|
|
117
|
-
while (offset < buffer.byteLength) {
|
|
118
|
-
const type = read(buffer, decoder, offset + 156, 1);
|
|
119
|
-
if (type === "\0") break;
|
|
120
|
-
const size = parseInt(read(buffer, decoder, offset + 124, 12), 8);
|
|
121
|
-
if (type === "0") {
|
|
122
|
-
const name = read(buffer, decoder, offset, 100).split("\0", 1)[0];
|
|
123
|
-
const data = new Uint8Array(buffer, offset + 512, size);
|
|
124
|
-
files.push({
|
|
125
|
-
name,
|
|
126
|
-
data
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
offset += 512 + Math.ceil(size / 512) * 512;
|
|
130
|
-
}
|
|
131
|
-
return files;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* @param {ArrayBuffer} buffer
|
|
135
|
-
* @param {TextDecoder} decoder
|
|
136
|
-
* @param {number} offset
|
|
137
|
-
* @param {number} length
|
|
138
|
-
*/
|
|
139
|
-
function read(buffer, decoder, offset, length) {
|
|
140
|
-
const view = new Uint8Array(buffer, offset, length);
|
|
141
|
-
return decoder.decode(view);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* @param {import('../index.d.ts').TarballFile[]} files
|
|
145
|
-
*/
|
|
146
|
-
function getFilesRootDir(files) {
|
|
147
|
-
return files.length ? files[0].name.split("/")[0] : "package";
|
|
148
|
-
}
|
|
149
|
-
/** @type {import('../index.d.ts').unpack} */
|
|
150
|
-
async function unpack(tarball) {
|
|
151
|
-
/** @type {ArrayBuffer} */
|
|
152
|
-
let buffer;
|
|
153
|
-
if (tarball instanceof ReadableStream) buffer = await readableStreamToArrayBuffer(tarball.pipeThrough(new DecompressionStream("gzip")));
|
|
154
|
-
else {
|
|
155
|
-
const nodeBuffer = await util.promisify(zlib.gunzip)(tarball);
|
|
156
|
-
buffer = nodeBuffer.buffer.slice(nodeBuffer.byteOffset, nodeBuffer.byteOffset + nodeBuffer.byteLength);
|
|
157
|
-
}
|
|
158
|
-
const files = parseTar(buffer);
|
|
159
|
-
return {
|
|
160
|
-
files,
|
|
161
|
-
rootDir: getFilesRootDir(files)
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
/** @type {import('../index.d.ts').packAsList} */
|
|
165
|
-
async function packAsList(dir, opts) {
|
|
166
|
-
const packageManager = opts?.packageManager ?? "npm";
|
|
167
|
-
try {
|
|
168
|
-
return await packAsListWithJson(dir, packageManager, opts?.ignoreScripts);
|
|
169
|
-
} catch {
|
|
170
|
-
return await packAsListWithPack(dir, packageManager, opts?.ignoreScripts);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* NOTE: only exported for tests
|
|
175
|
-
* @internal
|
|
176
|
-
* @param {string} dir
|
|
177
|
-
* @param {NonNullable<import('../index.d.ts').PackAsListOptions['packageManager']>} packageManager
|
|
178
|
-
* @param {import('../index.d.ts').PackAsListOptions['ignoreScripts']} ignoreScripts
|
|
179
|
-
* @returns {Promise<string[]>}
|
|
180
|
-
*/
|
|
181
|
-
async function packAsListWithJson(dir, packageManager, ignoreScripts) {
|
|
182
|
-
const stdoutJson = await packAsJson(dir, {
|
|
183
|
-
packageManager,
|
|
184
|
-
ignoreScripts
|
|
185
|
-
});
|
|
186
|
-
switch (packageManager) {
|
|
187
|
-
case "npm": return parseNpmPackJson(stdoutJson);
|
|
188
|
-
case "yarn": return parseYarnPackJson(stdoutJson);
|
|
189
|
-
case "pnpm": return parsePnpmPackJson(stdoutJson);
|
|
190
|
-
default: return [];
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* NOTE: only exported for tests
|
|
195
|
-
* @internal
|
|
196
|
-
* @param {string} dir
|
|
197
|
-
* @param {NonNullable<import('../index.d.ts').PackAsListOptions['packageManager']>} packageManager
|
|
198
|
-
* @param {import('../index.d.ts').PackAsListOptions['ignoreScripts']} ignoreScripts
|
|
199
|
-
* @returns {Promise<string[]>}
|
|
200
|
-
*/
|
|
201
|
-
async function packAsListWithPack(dir, packageManager, ignoreScripts) {
|
|
202
|
-
const destination = await getTempPackDir();
|
|
203
|
-
const tarballPath = await pack(dir, {
|
|
204
|
-
packageManager,
|
|
205
|
-
ignoreScripts,
|
|
206
|
-
destination
|
|
207
|
-
});
|
|
208
|
-
try {
|
|
209
|
-
const nodeBuffer = await fs.readFile(tarballPath);
|
|
210
|
-
const { files, rootDir } = await unpack(nodeBuffer.buffer.slice(nodeBuffer.byteOffset, nodeBuffer.byteOffset + nodeBuffer.byteLength));
|
|
211
|
-
return files.map((file) => file.name.slice(rootDir.length + 1));
|
|
212
|
-
} finally {
|
|
213
|
-
await fs.rm(destination, { recursive: true });
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* @param {any} stdoutJson
|
|
218
|
-
* @returns {string[]}
|
|
219
|
-
*/
|
|
220
|
-
function parseNpmPackJson(stdoutJson) {
|
|
221
|
-
return stdoutJson[0].files.map((file) => file.path);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* @param {any} stdoutJson
|
|
225
|
-
* @returns {string[]}
|
|
226
|
-
*/
|
|
227
|
-
function parseYarnPackJson(stdoutJson) {
|
|
228
|
-
const files = [];
|
|
229
|
-
for (const value of stdoutJson) if (value.location) files.push(value.location);
|
|
230
|
-
return files;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* @param {any} stdoutJson
|
|
234
|
-
* @returns {string[]}
|
|
235
|
-
*/
|
|
236
|
-
function parsePnpmPackJson(stdoutJson) {
|
|
237
|
-
return stdoutJson.files.map((file) => file.path);
|
|
238
|
-
}
|
|
239
|
-
/** @type {import('../index.d.ts').getPackDirectory} */
|
|
240
|
-
async function getPackDirectory(dir, packageManager) {
|
|
241
|
-
if (packageManager === "pnpm") try {
|
|
242
|
-
const pkgJsonPath = path.resolve(dir, "package.json");
|
|
243
|
-
const pkgJsonData = JSON.parse(await fs.readFile(pkgJsonPath, "utf-8"));
|
|
244
|
-
if (pkgJsonData.publishConfig?.directory) return path.resolve(dir, pkgJsonData.publishConfig.directory);
|
|
245
|
-
} catch {}
|
|
246
|
-
return dir;
|
|
247
|
-
}
|
|
248
|
-
//#endregion
|
|
249
|
-
export { getPackDirectory, pack, packAsJson, packAsList, unpack };
|