miqro 6.2.12 → 6.2.13
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/build/esm/src/common/arguments.d.ts +2 -0
- package/build/esm/src/common/arguments.js +31 -1
- package/build/esm/src/common/fs.d.ts +6 -0
- package/build/esm/src/common/fs.js +69 -0
- package/build/esm/src/common/help.d.ts +1 -1
- package/build/esm/src/common/help.js +1 -0
- package/build/esm/src/common/jsx.js +22 -22
- package/build/esm/src/inflate/inflate-sea.js +6 -2
- package/build/esm/src/inflate/inflate.d.ts +2 -1
- package/build/esm/src/inflate/inflate.js +2 -2
- package/build/esm/src/inflate/setup-http.d.ts +1 -1
- package/build/esm/src/inflate/setup-http.js +125 -89
- package/build/esm/src/main.js +13 -5
- package/build/esm/src/services/app.d.ts +1 -0
- package/build/esm/src/services/app.js +3 -1
- package/build/lib.cjs +302 -193
- package/package.json +1 -1
- package/src/common/arguments.ts +34 -1
- package/src/common/fs.ts +65 -0
- package/src/common/help.ts +1 -0
- package/src/common/jsx.ts +22 -22
- package/src/inflate/inflate-sea.ts +6 -2
- package/src/inflate/inflate.ts +3 -2
- package/src/inflate/setup-http.ts +127 -91
- package/src/main.ts +13 -5
- package/src/services/app.ts +4 -1
package/package.json
CHANGED
package/src/common/arguments.ts
CHANGED
|
@@ -27,6 +27,7 @@ interface MiqroJSON {
|
|
|
27
27
|
https?: boolean;
|
|
28
28
|
serverOptions?: ServerOptions;
|
|
29
29
|
httpsRedirect?: number;
|
|
30
|
+
inflateParallel?: number;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
const MiqroJSONSchema: Schema<MiqroJSON> = {
|
|
@@ -41,7 +42,8 @@ const MiqroJSONSchema: Schema<MiqroJSON> = {
|
|
|
41
42
|
editor: "boolean?",
|
|
42
43
|
https: "boolean?",
|
|
43
44
|
serverOptions: "any?",
|
|
44
|
-
httpsRedirect: "number?"
|
|
45
|
+
httpsRedirect: "number?",
|
|
46
|
+
inflateParallel: "number?"
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
|
|
@@ -86,6 +88,7 @@ export interface Arguments {
|
|
|
86
88
|
https: boolean;
|
|
87
89
|
serverOptions: ServerOptions;
|
|
88
90
|
httpsRedirect?: number;
|
|
91
|
+
inflateParallel?: number;
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
/**
|
|
@@ -97,6 +100,7 @@ export function parseArguments(): Arguments {
|
|
|
97
100
|
|
|
98
101
|
const args = cluster.isPrimary ? process.argv.slice(2, process.argv.length) : process.argv.slice(3, process.argv.length);
|
|
99
102
|
const flags: {
|
|
103
|
+
inflateParallel: number | null;
|
|
100
104
|
httpsRedirect: number | null;
|
|
101
105
|
https: boolean | null;
|
|
102
106
|
serverOptions: ServerOptions;
|
|
@@ -123,6 +127,7 @@ export function parseArguments(): Arguments {
|
|
|
123
127
|
inflateDir?: string | null;
|
|
124
128
|
hotreload?: boolean | null;
|
|
125
129
|
} = {
|
|
130
|
+
inflateParallel: null,
|
|
126
131
|
httpsRedirect: null,
|
|
127
132
|
https: null,
|
|
128
133
|
serverOptions: {},
|
|
@@ -466,6 +471,27 @@ export function parseArguments(): Arguments {
|
|
|
466
471
|
services.push(args[i + 1]);
|
|
467
472
|
i++;
|
|
468
473
|
continue;
|
|
474
|
+
case "--inflate-parallel":
|
|
475
|
+
if (args[i + 1] === undefined) {
|
|
476
|
+
console.error("bad arguments. service directory not provided.");
|
|
477
|
+
console.error(usage);
|
|
478
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
479
|
+
}
|
|
480
|
+
if (typeof args[i + 1] !== "string") {
|
|
481
|
+
console.error("bad arguments. --inflate-parallel must be a number.");
|
|
482
|
+
console.error(usage);
|
|
483
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
484
|
+
} else {
|
|
485
|
+
const cParallel = parseInt(String(args[i + 1]), 10);
|
|
486
|
+
if (isNaN(cParallel)) {
|
|
487
|
+
console.error("bad arguments. --inflate-parallel must be a number.");
|
|
488
|
+
console.error(usage);
|
|
489
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
490
|
+
}
|
|
491
|
+
flags.inflateParallel = cParallel;
|
|
492
|
+
}
|
|
493
|
+
i++;
|
|
494
|
+
continue;
|
|
469
495
|
case "--inflate-dir":
|
|
470
496
|
if (flags.inflateDir !== null && flags.compile === null) {
|
|
471
497
|
console.error("bad arguments. --inflate-dir already set.");
|
|
@@ -571,6 +597,12 @@ export function parseArguments(): Arguments {
|
|
|
571
597
|
flags.editor = miqroRC.editor;
|
|
572
598
|
}
|
|
573
599
|
}
|
|
600
|
+
|
|
601
|
+
if (flags.inflateParallel === null) {
|
|
602
|
+
if (miqroRC.inflateParallel !== undefined) {
|
|
603
|
+
flags.inflateParallel = miqroRC.inflateParallel;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
574
606
|
}
|
|
575
607
|
|
|
576
608
|
flags.editor = flags.editor ? flags.editor : false;
|
|
@@ -670,6 +702,7 @@ export function parseArguments(): Arguments {
|
|
|
670
702
|
}
|
|
671
703
|
|
|
672
704
|
return {
|
|
705
|
+
inflateParallel: flags.inflateParallel ? flags.inflateParallel : undefined,
|
|
673
706
|
name: flags.name ? flags.name : undefined,
|
|
674
707
|
browser: flags.browser !== null ? flags.browser : undefined,
|
|
675
708
|
logFile: flags.logFile !== null ? flags.logFile : undefined,
|
package/src/common/fs.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mkdir, rmdir, unlink, writeFile } from "node:fs";
|
|
1
2
|
import { basename, extname } from "node:path";
|
|
2
3
|
|
|
3
4
|
export function describeFilePath(filePath: string) {
|
|
@@ -15,3 +16,67 @@ export function describeFilePath(filePath: string) {
|
|
|
15
16
|
filePath
|
|
16
17
|
};
|
|
17
18
|
}
|
|
19
|
+
|
|
20
|
+
export async function mkdirASync(path: string, options?: Partial<{ recursive: true; }>) {
|
|
21
|
+
return new Promise<void>((resolve, reject) => {
|
|
22
|
+
try {
|
|
23
|
+
mkdir(path, options, (err) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
reject(err);
|
|
26
|
+
} else {
|
|
27
|
+
resolve();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function writeFileASync(path: string, body?) {
|
|
37
|
+
return new Promise<void>((resolve, reject) => {
|
|
38
|
+
try {
|
|
39
|
+
writeFile(path, body, (err) => {
|
|
40
|
+
if (err) {
|
|
41
|
+
reject(err);
|
|
42
|
+
} else {
|
|
43
|
+
resolve();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
} catch (e) {
|
|
47
|
+
reject(e);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function rmdirASync(path: string) {
|
|
53
|
+
return new Promise<void>((resolve, reject) => {
|
|
54
|
+
try {
|
|
55
|
+
rmdir(path, (err) => {
|
|
56
|
+
if (err) {
|
|
57
|
+
reject(err);
|
|
58
|
+
} else {
|
|
59
|
+
resolve();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} catch (e) {
|
|
63
|
+
reject(e);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function unlinkASync(path: string) {
|
|
69
|
+
return new Promise<void>((resolve, reject) => {
|
|
70
|
+
try {
|
|
71
|
+
unlink(path, (err) => {
|
|
72
|
+
if (err) {
|
|
73
|
+
reject(err);
|
|
74
|
+
} else {
|
|
75
|
+
resolve();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
} catch (e) {
|
|
79
|
+
reject(e);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
package/src/common/help.ts
CHANGED
|
@@ -44,6 +44,7 @@ export const help = `
|
|
|
44
44
|
--https-key\n\tpoint to a server.key file for https.
|
|
45
45
|
--https-cert\n\tpoint to a server.cert file for https.
|
|
46
46
|
--https-redirect\n\tserves an aditional http server that redirects to https. it needs a port number.
|
|
47
|
+
--inflate-parallel\n\tsets the max parallel esbuild instances. defaults to 1.
|
|
47
48
|
|
|
48
49
|
==environment variables==
|
|
49
50
|
|
package/src/common/jsx.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { Runtime } from "@miqro/jsx";
|
|
|
2
2
|
import { createNodeRuntime } from "@miqro/jsx-node";
|
|
3
3
|
import { basename, dirname, extname, relative, resolve } from "node:path";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { mkdirSync, readFileSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
5
|
import { Request, Response, CORSOptions, Logger, APIRoute } from "@miqro/core";
|
|
7
6
|
import { Parser, Schema } from "@miqro/parser";
|
|
8
7
|
import { APIRouteSchema, SessionHandlerOptionsSchema } from "@miqro/core";
|
|
@@ -17,6 +16,7 @@ import { getAsset, initAsset, validateAsset } from "./assets.js";
|
|
|
17
16
|
import { calculateChecksumFromBuffer } from "./checksum.js";
|
|
18
17
|
import { HandlerWithOptionsSchema, RouteOptionsSchema } from "@miqro/core/build/types.js";
|
|
19
18
|
import { Migration } from "@miqro/query";
|
|
19
|
+
import { mkdirASync, rmdirASync, unlinkASync, writeFileASync } from "./fs.js";
|
|
20
20
|
|
|
21
21
|
let jsxJSBuffer: null | Buffer = null; // Buffer.from(getAsset("jsx.dom.js"));
|
|
22
22
|
let jsxJSBufferChecksumPromise: null | Promise<string> = null; // calculateChecksumFromBuffer(jsxJSBuffer);
|
|
@@ -70,11 +70,11 @@ export async function inflateJSX(inFile: string, options: InflateOptions): Promi
|
|
|
70
70
|
try {
|
|
71
71
|
|
|
72
72
|
if (!options.embemedJSX) {
|
|
73
|
-
|
|
73
|
+
await mkdirASync(tmpBuildDir, {
|
|
74
74
|
recursive: true
|
|
75
75
|
});
|
|
76
|
-
|
|
77
|
-
//
|
|
76
|
+
await writeFileASync(inFileTmp, browserJSXGlobals(inFile, false, options.useExport));
|
|
77
|
+
//await writeFileASync(inFileTmp, browserJSXGlobals(relative(tmpBuildDir, inFile), false));
|
|
78
78
|
logger?.trace("inflating [%s] from [%s]. to change the import folder set JSX_TMP", relative(cwd(), inFile), dirname(relative(JSX_TMP_DIR, inFileTmp)));
|
|
79
79
|
const { outputFiles: [{ contents }] } = await esBuild({
|
|
80
80
|
...DEFAULT_ESOPTION,
|
|
@@ -84,17 +84,17 @@ export async function inflateJSX(inFile: string, options: InflateOptions): Promi
|
|
|
84
84
|
});
|
|
85
85
|
if (CLEAR_JSX_CACHE) {
|
|
86
86
|
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
await unlinkASync(inFileTmp);
|
|
88
|
+
await rmdirASync(tmpBuildDir);
|
|
89
89
|
}
|
|
90
90
|
return contents;
|
|
91
91
|
} else {
|
|
92
|
-
|
|
92
|
+
await mkdirASync(tmpBuildDir, {
|
|
93
93
|
recursive: true
|
|
94
94
|
});
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
//
|
|
95
|
+
//await writeFileASync(jsxJSPath, Buffer.from(getAsset("jsx-dom-bundle")));
|
|
96
|
+
await writeFileASync(inFileTmp, browserJSXGlobals(inFile, jsxJSPath));
|
|
97
|
+
//await writeFileASync(inFileTmp, browserJSXGlobals(relative(tmpBuildDir, inFile), relative(tmpBuildDir, jsxJSPath)));
|
|
98
98
|
logger?.trace("inflating [%s] from [%s] with jsx.js embedded. to change the import folder set JSX_TMP", relative(cwd(), inFile), dirname(relative(JSX_TMP_DIR, inFileTmp)));
|
|
99
99
|
const { outputFiles: [{ contents }] } = await esBuild({
|
|
100
100
|
...DEFAULT_ESOPTION,
|
|
@@ -104,9 +104,9 @@ export async function inflateJSX(inFile: string, options: InflateOptions): Promi
|
|
|
104
104
|
});
|
|
105
105
|
if (CLEAR_JSX_CACHE) {
|
|
106
106
|
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
|
|
107
|
+
await unlinkASync(inFileTmp);
|
|
108
|
+
//await unlinkASync(jsxJSPath);
|
|
109
|
+
await rmdirASync(tmpBuildDir);
|
|
110
110
|
}
|
|
111
111
|
return contents;
|
|
112
112
|
}
|
|
@@ -116,9 +116,9 @@ export async function inflateJSX(inFile: string, options: InflateOptions): Promi
|
|
|
116
116
|
if (options.embemedJSX) {
|
|
117
117
|
if (CLEAR_JSX_CACHE) {
|
|
118
118
|
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
|
|
119
|
+
await unlinkASync(inFileTmp);
|
|
120
|
+
//await unlinkASync(jsxJSPath);
|
|
121
|
+
await rmdirASync(tmpBuildDir);
|
|
122
122
|
} else {
|
|
123
123
|
//console.error("errors on: " + tmpBuildDir);
|
|
124
124
|
logger?.error("error with: %s", inFileTmp);
|
|
@@ -489,11 +489,11 @@ export async function importJSXFile(inFile: string, logger?: Logger | Console):
|
|
|
489
489
|
//const inFileTmp = resolve(tmpBuildDir, basename(inFile) + ".mjs");
|
|
490
490
|
const inFileTmp = resolve(tmpBuildDir, basename(inFile) + ".cjs");
|
|
491
491
|
//const logger = getLogger(`${SERVER_IDENTIFIER}_JSX`);
|
|
492
|
-
|
|
492
|
+
await mkdirASync(tmpBuildDir, {
|
|
493
493
|
recursive: true
|
|
494
494
|
});
|
|
495
495
|
try {
|
|
496
|
-
|
|
496
|
+
await writeFileASync(inFileTmp, inflatedCode);
|
|
497
497
|
assertGlobalTampered();
|
|
498
498
|
logger?.trace("importing [%s] from [%s]. to change the import folder set JSX_TMP", relative(cwd(), inFile), dirname(relative(JSX_TMP_DIR, inFileTmp)));
|
|
499
499
|
logger?.debug("importing [%s]", relative(cwd(), inFile));
|
|
@@ -501,8 +501,8 @@ export async function importJSXFile(inFile: string, logger?: Logger | Console):
|
|
|
501
501
|
assertGlobalTampered();
|
|
502
502
|
if (CLEAR_JSX_CACHE) {
|
|
503
503
|
logger?.trace("clearing cache at [%s]. to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
504
|
-
|
|
505
|
-
|
|
504
|
+
await unlinkASync(inFileTmp);
|
|
505
|
+
await rmdirASync(tmpBuildDir);
|
|
506
506
|
}
|
|
507
507
|
return module.default;
|
|
508
508
|
} catch (e) {
|
|
@@ -510,8 +510,8 @@ export async function importJSXFile(inFile: string, logger?: Logger | Console):
|
|
|
510
510
|
logger?.error("error with2: " + inFile);
|
|
511
511
|
if (CLEAR_JSX_CACHE) {
|
|
512
512
|
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
513
|
-
|
|
514
|
-
|
|
513
|
+
await unlinkASync(inFileTmp);
|
|
514
|
+
await rmdirASync(tmpBuildDir);
|
|
515
515
|
} else {
|
|
516
516
|
//console.error("errors on: " + tmpBuildDir);
|
|
517
517
|
logger?.error("error with: %s", inFileTmp);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Logger } from "@miqro/core";
|
|
2
|
-
import { chmodSync, constants, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { chmodSync, constants, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
4
4
|
import { cwd, platform } from "node:process";
|
|
5
5
|
|
|
6
6
|
import { RouteFileMap, StaticFileMap } from "./setup-http.js";
|
|
7
|
-
import { getAuthConfigPath, getCORSConfigPath, getDBConfigPath, getErrorConfigPath, getMiddlewareConfigPath, getMigrationsPath, getServerConfigPath, getServicePath, getWSConfigPath } from "../common/paths.js";
|
|
7
|
+
import { getAuthConfigPath, getCORSConfigPath, getDBConfigPath, getErrorConfigPath, getMiddlewareConfigPath, getMigrationsPath, getMiqroJSONPath, getServerConfigPath, getServicePath, getWSConfigPath } from "../common/paths.js";
|
|
8
8
|
import { getAsset } from "../common/assets.js";
|
|
9
9
|
import { migration } from "@miqro/query";
|
|
10
10
|
import { esBuild } from "../common/esbuild.js";
|
|
@@ -119,6 +119,10 @@ main().catch(e=>console.error(e));
|
|
|
119
119
|
platform: "node",
|
|
120
120
|
outfile: join(inflateDir, "sea", "app.bundle.cjs")
|
|
121
121
|
});
|
|
122
|
+
const miqroRCPath = getMiqroJSONPath();
|
|
123
|
+
if (miqroRCPath) {
|
|
124
|
+
writeFile(logger, join(inflateDir, "miqro.json"), readFileSync(miqroRCPath));
|
|
125
|
+
}
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
export async function inflateServiceForSea(logger: Logger, inflateDir: string, service: string, servicePath: string/*, serviceMigrations: string[]*/, serviceRouteFileMap: RouteFileMap, serviceStaticFileMap: StaticFileMap) {
|
package/src/inflate/inflate.ts
CHANGED
|
@@ -22,9 +22,10 @@ export interface InflateAppOptions {
|
|
|
22
22
|
hotreload?: boolean;
|
|
23
23
|
port: string;
|
|
24
24
|
serverInterface: ServerInterface;
|
|
25
|
+
inflateParallel?: number;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export async function inflateApp({ serverInterface, logger, hotreload, services/*, dbManager*/, inflateDir, inflateSea/*, editor, inflateTests*/, port }: InflateAppOptions): Promise<[Router, InflateError[] | null, RouteFileMap, WSConfig[]/*, ServerConfigMap*/, LogConfigMap]> {
|
|
28
|
+
export async function inflateApp({ inflateParallel, serverInterface, logger, hotreload, services/*, dbManager*/, inflateDir, inflateSea/*, editor, inflateTests*/, port }: InflateAppOptions): Promise<[Router, InflateError[] | null, RouteFileMap, WSConfig[]/*, ServerConfigMap*/, LogConfigMap]> {
|
|
28
29
|
logger.trace("inflateApp");
|
|
29
30
|
const errors: InflateError[] = [];
|
|
30
31
|
//const migrations: string[] = [];
|
|
@@ -69,7 +70,7 @@ export async function inflateApp({ serverInterface, logger, hotreload, services/
|
|
|
69
70
|
|
|
70
71
|
await setupLogConfig(logger, servicePath, service, logConfigMap, inflateSea ? inflateDir : false, errors);
|
|
71
72
|
|
|
72
|
-
router.use(await setupHTTPRouter(serverInterface, logger, hotreload ? hotreload : false, servicePath, service, serviceRouteFileMap, serviceStaticFileMap, inflateDir, inflateSea, errors));
|
|
73
|
+
router.use(await setupHTTPRouter(serverInterface, logger, hotreload ? hotreload : false, servicePath, service, serviceRouteFileMap, serviceStaticFileMap, inflateDir, inflateSea, errors, inflateParallel));
|
|
73
74
|
routeFileMap = {
|
|
74
75
|
...routeFileMap,
|
|
75
76
|
...serviceRouteFileMap
|