quickbundle 0.0.0-next-71fed0b → 0.0.0-next-750bdbd
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 +91 -36
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { helpers, termost } from 'termost';
|
|
2
2
|
import { readFile as readFile$1 } from 'node:fs/promises';
|
|
3
|
-
import process from 'node:process';
|
|
3
|
+
import process, { chdir } from 'node:process';
|
|
4
4
|
import { watch as watch$1, rollup } from 'rollup';
|
|
5
|
-
import { join } from 'node:path';
|
|
5
|
+
import { join, dirname, basename } from 'node:path';
|
|
6
6
|
import { createRequire } from 'node:module';
|
|
7
7
|
import { swc } from 'rollup-plugin-swc3';
|
|
8
8
|
import externals from 'rollup-plugin-node-externals';
|
|
@@ -11,8 +11,13 @@ import url from '@rollup/plugin-url';
|
|
|
11
11
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
12
12
|
import json from '@rollup/plugin-json';
|
|
13
13
|
import commonjs from '@rollup/plugin-commonjs';
|
|
14
|
+
import os from 'node:os';
|
|
15
|
+
import { writeFileSync } from 'node:fs';
|
|
14
16
|
import { gzipSize } from 'gzip-size';
|
|
15
17
|
|
|
18
|
+
var name = "quickbundle";
|
|
19
|
+
var version = "0.0.0-next-750bdbd";
|
|
20
|
+
|
|
16
21
|
const CWD = process.cwd();
|
|
17
22
|
|
|
18
23
|
const readFile = readFile$1;
|
|
@@ -99,7 +104,7 @@ const createConfigurations = (options = {
|
|
|
99
104
|
buildableExport.source && buildableExport.types && createTypesConfig({
|
|
100
105
|
source: buildableExport.source,
|
|
101
106
|
types: buildableExport.types
|
|
102
|
-
})
|
|
107
|
+
}, options)
|
|
103
108
|
].filter(Boolean);
|
|
104
109
|
});
|
|
105
110
|
};
|
|
@@ -175,15 +180,15 @@ const getBuildableExports = ({ standalone })=>{
|
|
|
175
180
|
}
|
|
176
181
|
return output;
|
|
177
182
|
};
|
|
178
|
-
const getPlugins = (
|
|
183
|
+
const getPlugins = (customPlugins, options)=>{
|
|
179
184
|
return [
|
|
180
|
-
externals({
|
|
185
|
+
!options.standalone && externals({
|
|
181
186
|
builtins: true,
|
|
182
187
|
deps: true,
|
|
183
188
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
189
|
+
* As they're not installed consumer side, `devDependencies` are declared as internal dependencies (via the `false` value)
|
|
190
|
+
* and bundled into the dist if and only if imported and not listed as `peerDependencies` (otherwise, they're considered external).
|
|
191
|
+
*/ devDeps: false,
|
|
187
192
|
optDeps: true,
|
|
188
193
|
peerDeps: true
|
|
189
194
|
}),
|
|
@@ -191,7 +196,7 @@ const getPlugins = (...customPlugins)=>{
|
|
|
191
196
|
url(),
|
|
192
197
|
json(),
|
|
193
198
|
...customPlugins
|
|
194
|
-
];
|
|
199
|
+
].filter(Boolean);
|
|
195
200
|
};
|
|
196
201
|
const createMainConfig = (entryPoints, options)=>{
|
|
197
202
|
const { minification, sourceMaps } = options;
|
|
@@ -215,13 +220,16 @@ const createMainConfig = (entryPoints, options)=>{
|
|
|
215
220
|
return {
|
|
216
221
|
input: entryPoints.source,
|
|
217
222
|
output,
|
|
218
|
-
plugins: getPlugins(
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
223
|
+
plugins: getPlugins([
|
|
224
|
+
nodeResolve(),
|
|
225
|
+
swc({
|
|
226
|
+
minify: minification,
|
|
227
|
+
sourceMaps
|
|
228
|
+
})
|
|
229
|
+
], options)
|
|
222
230
|
};
|
|
223
231
|
};
|
|
224
|
-
const createTypesConfig = (entryPoints)=>{
|
|
232
|
+
const createTypesConfig = (entryPoints, options)=>{
|
|
225
233
|
return {
|
|
226
234
|
input: entryPoints.source,
|
|
227
235
|
output: [
|
|
@@ -229,23 +237,25 @@ const createTypesConfig = (entryPoints)=>{
|
|
|
229
237
|
file: entryPoints.types
|
|
230
238
|
}
|
|
231
239
|
],
|
|
232
|
-
plugins: getPlugins(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
240
|
+
plugins: getPlugins([
|
|
241
|
+
nodeResolve({
|
|
242
|
+
/**
|
|
243
|
+
* The `exports` conditional fields definition order is important in the `package.json file`.
|
|
244
|
+
* To be resolved first, `types` field must always come first in the package.json exports definition.
|
|
245
|
+
* @see https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing.
|
|
246
|
+
*/ exportConditions: [
|
|
247
|
+
"types"
|
|
248
|
+
]
|
|
249
|
+
}),
|
|
250
|
+
dts({
|
|
251
|
+
compilerOptions: {
|
|
252
|
+
incremental: false
|
|
253
|
+
},
|
|
254
|
+
respectExternal: true
|
|
255
|
+
})
|
|
256
|
+
], options)
|
|
246
257
|
};
|
|
247
258
|
};
|
|
248
|
-
createConfigurations();
|
|
249
259
|
|
|
250
260
|
const createWatchCommand = (program)=>{
|
|
251
261
|
return createCommand(program, {
|
|
@@ -277,15 +287,15 @@ const build = async (configurations)=>{
|
|
|
277
287
|
];
|
|
278
288
|
const promises = [];
|
|
279
289
|
for (const outputEntry of outputEntries){
|
|
280
|
-
const
|
|
281
|
-
if (!
|
|
290
|
+
const outputFilePath = outputEntry.file ?? outputEntry.dir;
|
|
291
|
+
if (!outputFilePath) {
|
|
282
292
|
throw new Error("Misconfigured file entry point. Make sure to define an `import`, `require`, or `default` field.");
|
|
283
293
|
}
|
|
284
294
|
promises.push(new Promise((resolve, reject)=>{
|
|
285
295
|
bundle.write(outputEntry).then(()=>{
|
|
286
296
|
resolve({
|
|
287
297
|
elapsedTime: Date.now() - initialTime,
|
|
288
|
-
|
|
298
|
+
filePath: outputFilePath
|
|
289
299
|
});
|
|
290
300
|
}).catch((reason)=>{
|
|
291
301
|
reject(reason);
|
|
@@ -298,6 +308,47 @@ const build = async (configurations)=>{
|
|
|
298
308
|
return output;
|
|
299
309
|
};
|
|
300
310
|
|
|
311
|
+
const createCompileCommand = (program)=>{
|
|
312
|
+
return program.command({
|
|
313
|
+
name: "compile",
|
|
314
|
+
description: "Compiles the source code into a self-contained executable"
|
|
315
|
+
}).task({
|
|
316
|
+
async handler () {
|
|
317
|
+
const osType = os.type();
|
|
318
|
+
const isWindowsOS = osType === "Windows_NT";
|
|
319
|
+
const isMacOS = osType === "Darwin";
|
|
320
|
+
const items = await build(createConfigurations({
|
|
321
|
+
minification: true,
|
|
322
|
+
sourceMaps: false,
|
|
323
|
+
standalone: true
|
|
324
|
+
}));
|
|
325
|
+
for (const { filePath } of items){
|
|
326
|
+
chdir(dirname(filePath));
|
|
327
|
+
const fileName = basename(filePath);
|
|
328
|
+
const blobFileName = `${fileName}.blob`;
|
|
329
|
+
const executableFileName = `hello${isWindowsOS ? ".exe" : ""}`;
|
|
330
|
+
const seaConfigFileName = `${fileName}.sea-config.json`;
|
|
331
|
+
writeFileSync(seaConfigFileName, JSON.stringify({
|
|
332
|
+
disableExperimentalSEAWarning: true,
|
|
333
|
+
main: fileName,
|
|
334
|
+
output: blobFileName,
|
|
335
|
+
useCodeCache: false,
|
|
336
|
+
useSnapshot: false
|
|
337
|
+
}), "utf-8");
|
|
338
|
+
await helpers.exec(`node --experimental-sea-config ${seaConfigFileName}`);
|
|
339
|
+
await helpers.exec(`node -e "require('fs').copyFileSync(process.execPath, '${executableFileName}')"`);
|
|
340
|
+
if (isMacOS) {
|
|
341
|
+
await helpers.exec(`codesign --remove-signature ${executableFileName}`);
|
|
342
|
+
}
|
|
343
|
+
await helpers.exec(`npx postject ${executableFileName} NODE_SEA_BLOB ${blobFileName} --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 ${isMacOS ? "--macho-segment-name NODE_SEA" : ""}`);
|
|
344
|
+
if (isMacOS) {
|
|
345
|
+
await helpers.exec(`codesign --sign - ${executableFileName}`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
};
|
|
351
|
+
|
|
301
352
|
const createBuildCommand = (program)=>{
|
|
302
353
|
return createCommand(program, {
|
|
303
354
|
name: "build",
|
|
@@ -330,7 +381,7 @@ const createBuildCommand = (program)=>{
|
|
|
330
381
|
].map((message, index)=>{
|
|
331
382
|
return index === 0 ? message : ` ${message}`;
|
|
332
383
|
}).join("\n"), {
|
|
333
|
-
label: `${item.
|
|
384
|
+
label: `${item.filePath} (took ${item.elapsedTime}ms)`,
|
|
334
385
|
type: "information"
|
|
335
386
|
});
|
|
336
387
|
});
|
|
@@ -342,7 +393,7 @@ const createBuildCommand = (program)=>{
|
|
|
342
393
|
};
|
|
343
394
|
const computeBundleSize = async (buildOutput)=>{
|
|
344
395
|
const computeFileSize = async (buildItemOutput)=>{
|
|
345
|
-
const content = await readFile(buildItemOutput.
|
|
396
|
+
const content = await readFile(buildItemOutput.filePath);
|
|
346
397
|
const gzSize = await gzipSize(content);
|
|
347
398
|
return {
|
|
348
399
|
...buildItemOutput,
|
|
@@ -358,9 +409,13 @@ const formatSize = (bytes)=>{
|
|
|
358
409
|
};
|
|
359
410
|
|
|
360
411
|
const createProgram = (...commandBuilders)=>{
|
|
361
|
-
const program = termost(
|
|
412
|
+
const program = termost({
|
|
413
|
+
name,
|
|
414
|
+
description: "The zero-configuration transpiler and bundler for the web",
|
|
415
|
+
version
|
|
416
|
+
});
|
|
362
417
|
for (const commandBuilder of commandBuilders){
|
|
363
418
|
commandBuilder(program);
|
|
364
419
|
}
|
|
365
420
|
};
|
|
366
|
-
createProgram(createBuildCommand, createWatchCommand);
|
|
421
|
+
createProgram(createBuildCommand, createWatchCommand, createCompileCommand);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quickbundle",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-750bdbd",
|
|
4
4
|
"description": "The zero-configuration transpiler and bundler for the web",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ayoub Adib",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@types/node": "22.9.0"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
|
-
"build": "rollup --config ./
|
|
68
|
-
"watch": "rollup --watch --config ./
|
|
67
|
+
"build": "rollup --config ./bundler.config.ts --configPlugin rollup-plugin-swc3",
|
|
68
|
+
"watch": "rollup --watch --config ./bundler.config.ts --configPlugin rollup-plugin-swc3"
|
|
69
69
|
}
|
|
70
70
|
}
|