quickbundle 0.0.0-next-180c331 → 0.0.0-next-ed1776f
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/index.mjs +51 -27
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { helpers, termost } from 'termost';
|
|
2
|
-
import { readFile as readFile$1 } from 'node:fs/promises';
|
|
2
|
+
import { readFile as readFile$1, writeFile, rm } from 'node:fs/promises';
|
|
3
3
|
import process, { chdir } from 'node:process';
|
|
4
4
|
import { watch as watch$1, rollup } from 'rollup';
|
|
5
5
|
import { join, dirname, basename } from 'node:path';
|
|
@@ -12,11 +12,10 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
|
12
12
|
import json from '@rollup/plugin-json';
|
|
13
13
|
import commonjs from '@rollup/plugin-commonjs';
|
|
14
14
|
import os from 'node:os';
|
|
15
|
-
import { writeFileSync } from 'node:fs';
|
|
16
15
|
import { gzipSize } from 'gzip-size';
|
|
17
16
|
|
|
18
17
|
var name = "quickbundle";
|
|
19
|
-
var version = "0.0.0-next-
|
|
18
|
+
var version = "0.0.0-next-ed1776f";
|
|
20
19
|
|
|
21
20
|
const CWD = process.cwd();
|
|
22
21
|
|
|
@@ -123,13 +122,17 @@ const getBuildableExports = ({ standalone })=>{
|
|
|
123
122
|
const bin = PKG.bin;
|
|
124
123
|
const name = PKG.name;
|
|
125
124
|
const source = PKG.source;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
if (isRecord(bin)) {
|
|
126
|
+
return Object.entries(bin).map((data)=>({
|
|
127
|
+
bin: data[0],
|
|
128
|
+
require: data[1],
|
|
129
|
+
source
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
return [
|
|
131
133
|
{
|
|
132
|
-
bin
|
|
134
|
+
// For scoped packages and if the `bin` is defined with a string value, the [scope name is discarded](the scope name is discarded when creating a binary) when creating a binary.
|
|
135
|
+
bin: name.replace(/^(@.*?\/)/, ""),
|
|
133
136
|
require: bin,
|
|
134
137
|
source
|
|
135
138
|
}
|
|
@@ -140,7 +143,7 @@ const getBuildableExports = ({ standalone })=>{
|
|
|
140
143
|
* Following the [package entry-point specification](https://nodejs.org/api/packages.html#package-entry-points),
|
|
141
144
|
* whenever an export object is defined, it take precedence over other classical entry-point fields
|
|
142
145
|
* (such as main, module, and types defined at the root package.json level).
|
|
143
|
-
*/ if (PKG.main
|
|
146
|
+
*/ if (PKG.main || PKG.module || PKG.types || !PKG.exports) {
|
|
144
147
|
throw new Error("Invalid package entry points contract. Use the recommended [`exports` field](https://nodejs.org/api/packages.html#package-entry-points) instead and, for TypeScript-based projects, update the `tsconfig.json` file to resolve it properly (`moduleResolution` must be set to `Bundler` (or `NodeNext`)).");
|
|
145
148
|
}
|
|
146
149
|
const buildableExportFields = [
|
|
@@ -323,28 +326,44 @@ const createCompileCommand = (program)=>{
|
|
|
323
326
|
name: "compile",
|
|
324
327
|
description: "Compiles the source code into a self-contained executable"
|
|
325
328
|
}).task({
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
|
|
329
|
+
key: "osType",
|
|
330
|
+
label: "Get context",
|
|
331
|
+
handler () {
|
|
332
|
+
const type = os.type();
|
|
333
|
+
return type === "Windows_NT" ? "windows" : type === "Darwin" ? "macos" : "linux";
|
|
334
|
+
}
|
|
335
|
+
}).task({
|
|
336
|
+
key: "config",
|
|
337
|
+
label: "Create configuration",
|
|
338
|
+
handler () {
|
|
339
|
+
return createConfiguration({
|
|
331
340
|
minification: true,
|
|
332
341
|
sourceMaps: false,
|
|
333
342
|
standalone: true
|
|
334
343
|
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
344
|
+
}
|
|
345
|
+
}).task({
|
|
346
|
+
label: "Build",
|
|
347
|
+
async handler ({ config }) {
|
|
348
|
+
await build(config);
|
|
349
|
+
}
|
|
350
|
+
}).task({
|
|
351
|
+
label ({ config }) {
|
|
352
|
+
const binaries = config.metadata.map(({ bin })=>{
|
|
353
|
+
if (!bin) return undefined;
|
|
354
|
+
return `\`${bin}\``;
|
|
355
|
+
}).filter(Boolean).join(", ");
|
|
356
|
+
return `Compile ${binaries}`;
|
|
357
|
+
},
|
|
358
|
+
async handler ({ config, osType }) {
|
|
359
|
+
for (const { bin, require: filePath } of config.metadata){
|
|
360
|
+
if (!filePath || !bin) continue;
|
|
340
361
|
chdir(dirname(filePath));
|
|
341
362
|
const fileName = basename(filePath);
|
|
342
363
|
const blobFileName = `${fileName}.blob`;
|
|
343
|
-
|
|
344
|
-
* TODO: split with several tasks
|
|
345
|
-
*/ const executableFileName = `${bin}${isWindowsOS ? ".exe" : ""}`;
|
|
364
|
+
const executableFileName = `${bin}${osType === "windows" ? ".exe" : ""}`;
|
|
346
365
|
const seaConfigFileName = `${fileName}.sea-config.json`;
|
|
347
|
-
|
|
366
|
+
await writeFile(seaConfigFileName, JSON.stringify({
|
|
348
367
|
disableExperimentalSEAWarning: true,
|
|
349
368
|
main: fileName,
|
|
350
369
|
output: blobFileName,
|
|
@@ -353,13 +372,18 @@ const createCompileCommand = (program)=>{
|
|
|
353
372
|
}), "utf-8");
|
|
354
373
|
await helpers.exec(`node --experimental-sea-config ${seaConfigFileName}`);
|
|
355
374
|
await helpers.exec(`node -e "require('fs').copyFileSync(process.execPath, '${executableFileName}')"`);
|
|
356
|
-
if (
|
|
375
|
+
if (osType === "macos") {
|
|
357
376
|
await helpers.exec(`codesign --remove-signature ${executableFileName}`);
|
|
358
377
|
}
|
|
359
|
-
await helpers.exec(`npx postject ${executableFileName} NODE_SEA_BLOB ${blobFileName} --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 ${
|
|
360
|
-
if (
|
|
378
|
+
await helpers.exec(`npx postject ${executableFileName} NODE_SEA_BLOB ${blobFileName} --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 ${osType === "macos" ? "--macho-segment-name NODE_SEA" : ""}`);
|
|
379
|
+
if (osType === "macos") {
|
|
361
380
|
await helpers.exec(`codesign --sign - ${executableFileName}`);
|
|
362
381
|
}
|
|
382
|
+
await Promise.all([
|
|
383
|
+
blobFileName,
|
|
384
|
+
seaConfigFileName
|
|
385
|
+
].map(async (file)=>rm(file)));
|
|
386
|
+
chdir(CWD);
|
|
363
387
|
}
|
|
364
388
|
}
|
|
365
389
|
});
|