@markw65/monkeyc-optimizer 1.1.16 → 1.1.18
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/README.md +24 -11
- package/build/api.cjs +33 -33
- package/build/{chunk-TQHOJQYY.cjs → chunk-TM6GLTGC.cjs} +418 -220
- package/build/{chunk-VVIZ2ADY.cjs → chunk-YCLY27QH.cjs} +17 -6
- package/build/optimizer.cjs +19 -17
- package/build/sdk-util.cjs +14 -14
- package/build/src/optimizer.d.ts +12 -2
- package/build/src/worker-pool.d.ts +1 -1
- package/build/src/worker-task.d.ts +18 -3
- package/build/worker-pool.cjs +35 -0
- package/build/worker-thread.cjs +40 -0
- package/package.json +3 -1
- package/build/chunk-K32K3YD4.cjs +0 -145
- package/build/chunk-WIPYYCBN.cjs +0 -54
|
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_YCLY27QH_exports = {};
|
|
30
|
+
__export(chunk_YCLY27QH_exports, {
|
|
31
31
|
EnumTagsConst: () => EnumTagsConst,
|
|
32
32
|
LastTypeTag: () => LastTypeTag,
|
|
33
33
|
ObjectLikeTagsConst: () => ObjectLikeTagsConst,
|
|
@@ -114,7 +114,7 @@ __export(chunk_VVIZ2ADY_exports, {
|
|
|
114
114
|
visitorNode: () => visitorNode,
|
|
115
115
|
xml_util_exports: () => xml_util_exports
|
|
116
116
|
});
|
|
117
|
-
module.exports = __toCommonJS(
|
|
117
|
+
module.exports = __toCommonJS(chunk_YCLY27QH_exports);
|
|
118
118
|
var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
|
|
119
119
|
var import_prettier_plugin_monkeyc = require("@markw65/prettier-plugin-monkeyc");
|
|
120
120
|
var import_node_assert = __toESM(require("node:assert"));
|
|
@@ -23273,8 +23273,9 @@ async function optimizeProgram(filepath, devKey, output) {
|
|
|
23273
23273
|
if (/\.iq$/i.test(filepath)) {
|
|
23274
23274
|
return optimizePackage(filepath, devKey, output);
|
|
23275
23275
|
}
|
|
23276
|
+
const removeExt = (filepath2, ext) => path.join(path.dirname(filepath2), path.basename(filepath2, ext));
|
|
23276
23277
|
if (!output) {
|
|
23277
|
-
output =
|
|
23278
|
+
output = removeExt(filepath, ".prg") + ".opt.prg";
|
|
23278
23279
|
}
|
|
23279
23280
|
const xmlBytes = await fs4.readFile(filepath + ".debug.xml").catch(() => "");
|
|
23280
23281
|
const debugXml = xml_util_exports.parseXml(xmlBytes.toString());
|
|
@@ -23286,11 +23287,21 @@ async function optimizeProgram(filepath, devKey, output) {
|
|
|
23286
23287
|
debugXml,
|
|
23287
23288
|
key
|
|
23288
23289
|
);
|
|
23289
|
-
|
|
23290
|
+
const promises = [];
|
|
23291
|
+
promises.push(fs4.writeFile(output, buffer));
|
|
23290
23292
|
if (!(debugXml.body instanceof Error)) {
|
|
23291
23293
|
const contents = Buffer.from(xml_util_exports.writeXml(debugXml));
|
|
23292
|
-
|
|
23294
|
+
promises.push(fs4.writeFile(output + ".debug.xml", contents));
|
|
23293
23295
|
}
|
|
23296
|
+
const jsonIn = removeExt(filepath, ".prg");
|
|
23297
|
+
const jsonOut = removeExt(output, ".prg");
|
|
23298
|
+
promises.push(
|
|
23299
|
+
fs4.readFile(jsonIn + "-settings.json").then((data) => fs4.writeFile(jsonOut + "-settings.json", data)).catch(() => "")
|
|
23300
|
+
);
|
|
23301
|
+
promises.push(
|
|
23302
|
+
fs4.readFile(jsonIn + "-fit_contributions.json").then((data) => fs4.writeFile(jsonOut + "-fit_contributions.json", data)).catch(() => "")
|
|
23303
|
+
);
|
|
23304
|
+
await Promise.all(promises);
|
|
23294
23305
|
return { signature, output };
|
|
23295
23306
|
}
|
|
23296
23307
|
function optimizeProgramBuffer(filepath, view, debugXml, key) {
|
package/build/optimizer.cjs
CHANGED
|
@@ -18,27 +18,28 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var optimizer_exports = {};
|
|
20
20
|
__export(optimizer_exports, {
|
|
21
|
-
StateNodeAttributes: () =>
|
|
22
|
-
buildOptimizedProject: () =>
|
|
21
|
+
StateNodeAttributes: () => import_chunk_YCLY27QH.StateNodeAttributes,
|
|
22
|
+
buildOptimizedProject: () => import_chunk_TM6GLTGC.buildOptimizedProject,
|
|
23
23
|
copyRecursiveAsNeeded: () => import_chunk_IAUHYWVN.copyRecursiveAsNeeded,
|
|
24
|
-
defaultConfig: () =>
|
|
25
|
-
display: () =>
|
|
26
|
-
generateApiMirTests: () =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
defaultConfig: () => import_chunk_TM6GLTGC.defaultConfig,
|
|
25
|
+
display: () => import_chunk_YCLY27QH.display,
|
|
26
|
+
generateApiMirTests: () => import_chunk_TM6GLTGC.generateApiMirTests,
|
|
27
|
+
generateOneConfig: () => import_chunk_TM6GLTGC.generateOneConfig,
|
|
28
|
+
generateOptimizedProject: () => import_chunk_TM6GLTGC.generateOptimizedProject,
|
|
29
|
+
getConfig: () => import_chunk_TM6GLTGC.getConfig,
|
|
30
|
+
getProjectAnalysis: () => import_chunk_TM6GLTGC.getProjectAnalysis,
|
|
31
|
+
get_jungle: () => import_chunk_TM6GLTGC.get_jungle,
|
|
32
|
+
isErrorWithLocation: () => import_chunk_TM6GLTGC.isErrorWithLocation,
|
|
33
|
+
launchSimulator: () => import_chunk_TM6GLTGC.launchSimulator,
|
|
34
|
+
manifestProducts: () => import_chunk_TM6GLTGC.manifestProducts,
|
|
35
|
+
mctree: () => import_chunk_TM6GLTGC.mctree,
|
|
36
|
+
simulateProgram: () => import_chunk_TM6GLTGC.simulateProgram
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(optimizer_exports);
|
|
38
|
-
var
|
|
39
|
-
var
|
|
39
|
+
var import_chunk_TM6GLTGC = require("./chunk-TM6GLTGC.cjs");
|
|
40
|
+
var import_chunk_YCLY27QH = require("./chunk-YCLY27QH.cjs");
|
|
40
41
|
var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
|
|
41
|
-
(0,
|
|
42
|
+
(0, import_chunk_TM6GLTGC.init_optimizer)();
|
|
42
43
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
44
|
0 && (module.exports = {
|
|
44
45
|
StateNodeAttributes,
|
|
@@ -47,6 +48,7 @@ var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
|
|
|
47
48
|
defaultConfig,
|
|
48
49
|
display,
|
|
49
50
|
generateApiMirTests,
|
|
51
|
+
generateOneConfig,
|
|
50
52
|
generateOptimizedProject,
|
|
51
53
|
getConfig,
|
|
52
54
|
getProjectAnalysis,
|
package/build/sdk-util.cjs
CHANGED
|
@@ -18,23 +18,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var sdk_util_exports = {};
|
|
20
20
|
__export(sdk_util_exports, {
|
|
21
|
-
SectionKinds: () =>
|
|
22
|
-
appSupport: () =>
|
|
23
|
-
connectiq: () =>
|
|
24
|
-
getDeviceInfo: () =>
|
|
25
|
-
getFunctionDocumentation: () =>
|
|
26
|
-
getLanguages: () =>
|
|
27
|
-
getSdkPath: () =>
|
|
28
|
-
isWin: () =>
|
|
29
|
-
optimizeProgram: () =>
|
|
30
|
-
readPrg: () =>
|
|
31
|
-
readPrgWithOffsets: () =>
|
|
32
|
-
xmlUtil: () =>
|
|
21
|
+
SectionKinds: () => import_chunk_YCLY27QH.SectionKinds,
|
|
22
|
+
appSupport: () => import_chunk_YCLY27QH.appSupport,
|
|
23
|
+
connectiq: () => import_chunk_YCLY27QH.connectiq,
|
|
24
|
+
getDeviceInfo: () => import_chunk_YCLY27QH.getDeviceInfo,
|
|
25
|
+
getFunctionDocumentation: () => import_chunk_YCLY27QH.getFunctionDocumentation,
|
|
26
|
+
getLanguages: () => import_chunk_YCLY27QH.getLanguages,
|
|
27
|
+
getSdkPath: () => import_chunk_YCLY27QH.getSdkPath,
|
|
28
|
+
isWin: () => import_chunk_YCLY27QH.isWin,
|
|
29
|
+
optimizeProgram: () => import_chunk_YCLY27QH.optimizeProgram,
|
|
30
|
+
readPrg: () => import_chunk_YCLY27QH.readPrg,
|
|
31
|
+
readPrgWithOffsets: () => import_chunk_YCLY27QH.readPrgWithOffsets,
|
|
32
|
+
xmlUtil: () => import_chunk_YCLY27QH.xml_util_exports
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(sdk_util_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_chunk_YCLY27QH = require("./chunk-YCLY27QH.cjs");
|
|
36
36
|
var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
|
|
37
|
-
(0,
|
|
37
|
+
(0, import_chunk_YCLY27QH.init_sdk_util)();
|
|
38
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
39
|
0 && (module.exports = {
|
|
40
40
|
SectionKinds,
|
package/build/src/optimizer.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { mctree } from "@markw65/prettier-plugin-monkeyc";
|
|
2
|
-
import { get_jungle, JungleBuildDependencies, JungleError, JungleResourceMap, ResolvedJungle, Target } from "./jungles";
|
|
2
|
+
import { get_jungle, JungleBuildDependencies, JungleError, JungleQualifier, JungleResourceMap, ResolvedJungle, Target } from "./jungles";
|
|
3
3
|
import { launchSimulator, simulateProgram } from "./launch";
|
|
4
4
|
import { manifestProducts } from "./manifest";
|
|
5
|
-
import { BuildConfig, FilesToOptimizeMap, ProgramStateAnalysis } from "./optimizer-types";
|
|
5
|
+
import { BuildConfig, FilesToOptimizeMap, ProgramState, ProgramStateAnalysis } from "./optimizer-types";
|
|
6
6
|
import { xmlUtil } from "./sdk-util";
|
|
7
7
|
import { TypeMap } from "./type-flow/interp";
|
|
8
8
|
import { copyRecursiveAsNeeded } from "./util";
|
|
@@ -80,6 +80,16 @@ export declare type Analysis = {
|
|
|
80
80
|
state: ProgramStateAnalysis;
|
|
81
81
|
typeMap?: TypeMap | null | undefined;
|
|
82
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* @param {BuildConfig} config
|
|
85
|
+
* @param {*} buildConfig
|
|
86
|
+
* @param {string[]} dependencyFiles
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
export declare function generateOneConfig(buildConfig: JungleQualifier, manifestXML: xmlUtil.Document, dependencyFiles: string[], config: BuildConfig): Promise<{
|
|
90
|
+
hasTests: boolean;
|
|
91
|
+
diagnostics: ProgramState["diagnostics"];
|
|
92
|
+
}>;
|
|
83
93
|
export declare function getProjectAnalysis(targets: Target[], analysis: PreAnalysis | null, manifestXML: xmlUtil.Document, options: BuildConfig): Promise<Analysis | PreAnalysis>;
|
|
84
94
|
/**
|
|
85
95
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { WorkerTask, WorkerTaskResult } from "./worker-task";
|
|
2
|
-
export declare function startPool(parallelism?: number):
|
|
2
|
+
export declare function startPool(parallelism?: number): boolean;
|
|
3
3
|
export declare function stopPool(): void;
|
|
4
4
|
export declare function runTaskInPool<T extends WorkerTask>(task: T): Promise<WorkerTaskResult<T>>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { JungleQualifier } from "./jungles";
|
|
1
2
|
import { BuildConfig } from "./optimizer";
|
|
3
|
+
import { xmlUtil } from "./sdk-util";
|
|
2
4
|
interface BaseNode {
|
|
3
5
|
type: string;
|
|
4
6
|
data: unknown;
|
|
@@ -10,13 +12,22 @@ interface BuildOptimizedProject extends BaseNode {
|
|
|
10
12
|
options: BuildConfig;
|
|
11
13
|
};
|
|
12
14
|
}
|
|
15
|
+
interface GenerateOneConfig extends BaseNode {
|
|
16
|
+
type: "generateOneConfig";
|
|
17
|
+
data: {
|
|
18
|
+
buildConfig: JungleQualifier;
|
|
19
|
+
manifestXML: xmlUtil.Document;
|
|
20
|
+
dependencyFiles: string[];
|
|
21
|
+
config: BuildConfig;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
13
24
|
interface GenerateOptimizedProject extends BaseNode {
|
|
14
25
|
type: "generateOptimizedProject";
|
|
15
26
|
data: {
|
|
16
27
|
options: BuildConfig;
|
|
17
28
|
};
|
|
18
29
|
}
|
|
19
|
-
export declare type WorkerTask = BuildOptimizedProject | GenerateOptimizedProject;
|
|
30
|
+
export declare type WorkerTask = BuildOptimizedProject | GenerateOptimizedProject | GenerateOneConfig;
|
|
20
31
|
export declare const workerTaskHandlers: {
|
|
21
32
|
readonly buildOptimizedProject: (data: BuildOptimizedProject["data"]) => Promise<{
|
|
22
33
|
exe: string;
|
|
@@ -28,17 +39,21 @@ export declare const workerTaskHandlers: {
|
|
|
28
39
|
}>;
|
|
29
40
|
readonly generateOptimizedProject: (data: GenerateOptimizedProject["data"]) => Promise<{
|
|
30
41
|
jungleFiles: string | undefined;
|
|
31
|
-
xml:
|
|
42
|
+
xml: xmlUtil.Document;
|
|
32
43
|
program: string;
|
|
33
44
|
hasTests: boolean;
|
|
34
45
|
diagnostics?: undefined;
|
|
35
46
|
} | {
|
|
36
47
|
jungleFiles: string;
|
|
37
|
-
xml:
|
|
48
|
+
xml: xmlUtil.Document;
|
|
38
49
|
program: string;
|
|
39
50
|
hasTests: boolean;
|
|
40
51
|
diagnostics: Record<string, import("./optimizer-types").Diagnostic[]>;
|
|
41
52
|
}>;
|
|
53
|
+
readonly generateOneConfig: (data: GenerateOneConfig["data"]) => Promise<{
|
|
54
|
+
hasTests: boolean;
|
|
55
|
+
diagnostics: Record<string, import("./optimizer-types").Diagnostic[]> | undefined;
|
|
56
|
+
}>;
|
|
42
57
|
};
|
|
43
58
|
declare type RemovePromise<T> = T extends Promise<infer U> ? U : T;
|
|
44
59
|
export declare type WorkerTaskResult<T> = T extends WorkerTask ? RemovePromise<ReturnType<typeof workerTaskHandlers[T["type"]]>> : never;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var worker_pool_exports = {};
|
|
20
|
+
__export(worker_pool_exports, {
|
|
21
|
+
runTaskInPool: () => import_chunk_TM6GLTGC.runTaskInPool,
|
|
22
|
+
startPool: () => import_chunk_TM6GLTGC.startPool,
|
|
23
|
+
stopPool: () => import_chunk_TM6GLTGC.stopPool
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(worker_pool_exports);
|
|
26
|
+
var import_chunk_TM6GLTGC = require("./chunk-TM6GLTGC.cjs");
|
|
27
|
+
var import_chunk_YCLY27QH = require("./chunk-YCLY27QH.cjs");
|
|
28
|
+
var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
|
|
29
|
+
(0, import_chunk_TM6GLTGC.init_worker_pool)();
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
runTaskInPool,
|
|
33
|
+
startPool,
|
|
34
|
+
stopPool
|
|
35
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var worker_thread_exports = {};
|
|
20
|
+
__export(worker_thread_exports, {
|
|
21
|
+
default: () => worker_thread_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(worker_thread_exports);
|
|
24
|
+
var import_chunk_TM6GLTGC = require("./chunk-TM6GLTGC.cjs");
|
|
25
|
+
var import_chunk_YCLY27QH = require("./chunk-YCLY27QH.cjs");
|
|
26
|
+
var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
|
|
27
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
28
|
+
var require_worker_thread = (0, import_chunk_IAUHYWVN.__commonJS)({
|
|
29
|
+
"src/worker-thread.ts"() {
|
|
30
|
+
(0, import_chunk_TM6GLTGC.init_worker_task)();
|
|
31
|
+
if (import_node_worker_threads.parentPort) {
|
|
32
|
+
import_node_worker_threads.parentPort.on("message", async (task) => {
|
|
33
|
+
return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_TM6GLTGC.performTask)(task));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
var worker_thread_default = require_worker_thread();
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markw65/monkeyc-optimizer",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.18",
|
|
5
5
|
"description": "Source to source optimizer for Garmin Monkey C code",
|
|
6
6
|
"main": "build/optimizer.cjs",
|
|
7
7
|
"types": "build/src/optimizer.d.ts",
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
"build/util.cjs",
|
|
36
36
|
"build/sdk-util.cjs",
|
|
37
37
|
"build/api.cjs",
|
|
38
|
+
"build/worker-thread.cjs",
|
|
39
|
+
"build/worker-pool.cjs",
|
|
38
40
|
"build/chunk-*.cjs",
|
|
39
41
|
"build/src/**/*.d.ts"
|
|
40
42
|
],
|
package/build/chunk-K32K3YD4.cjs
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var chunk_K32K3YD4_exports = {};
|
|
30
|
-
__export(chunk_K32K3YD4_exports, {
|
|
31
|
-
runTaskInPool: () => runTaskInPool,
|
|
32
|
-
startPool: () => startPool,
|
|
33
|
-
stopPool: () => stopPool
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(chunk_K32K3YD4_exports);
|
|
36
|
-
var import_chunk_WIPYYCBN = require("./chunk-WIPYYCBN.cjs");
|
|
37
|
-
var import_node_async_hooks = require("node:async_hooks");
|
|
38
|
-
var import_node_events = require("node:events");
|
|
39
|
-
var import_node_worker_threads = require("node:worker_threads");
|
|
40
|
-
var os = __toESM(require("node:os"));
|
|
41
|
-
(0, import_chunk_WIPYYCBN.init_worker_task)();
|
|
42
|
-
var kTaskInfo = Symbol("kTaskInfo");
|
|
43
|
-
var kWorkerFreedEvent = Symbol("kWorkerFreedEvent");
|
|
44
|
-
var WorkerPoolTaskInfo = class extends import_node_async_hooks.AsyncResource {
|
|
45
|
-
constructor(callback) {
|
|
46
|
-
super("WorkerPoolTaskInfo");
|
|
47
|
-
this.callback = callback;
|
|
48
|
-
}
|
|
49
|
-
done(err, result) {
|
|
50
|
-
this.runInAsyncScope(this.callback, null, err, result);
|
|
51
|
-
this.emitDestroy();
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var WorkerPool = class extends import_node_events.EventEmitter {
|
|
55
|
-
constructor(numThreads) {
|
|
56
|
-
super();
|
|
57
|
-
this.numThreads = numThreads;
|
|
58
|
-
this.numThreads = numThreads;
|
|
59
|
-
this.workers = [];
|
|
60
|
-
this.freeWorkers = [];
|
|
61
|
-
this.tasks = [];
|
|
62
|
-
for (let i = 0; i < numThreads; i++)
|
|
63
|
-
this.addNewWorker();
|
|
64
|
-
this.on(kWorkerFreedEvent, () => {
|
|
65
|
-
if (this.tasks.length > 0) {
|
|
66
|
-
const { task, callback } = this.tasks.shift();
|
|
67
|
-
this.runTask(task, callback);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
workers;
|
|
72
|
-
freeWorkers;
|
|
73
|
-
tasks;
|
|
74
|
-
addNewWorker() {
|
|
75
|
-
const worker = new import_node_worker_threads.Worker(
|
|
76
|
-
//new URL("worker-thread.cjs", import.meta.url)
|
|
77
|
-
`${__dirname}/worker-thread.cjs`
|
|
78
|
-
);
|
|
79
|
-
worker.on("message", (result) => {
|
|
80
|
-
worker[kTaskInfo].done(null, result);
|
|
81
|
-
worker[kTaskInfo] = null;
|
|
82
|
-
this.freeWorkers.push(worker);
|
|
83
|
-
this.emit(kWorkerFreedEvent);
|
|
84
|
-
});
|
|
85
|
-
worker.on("error", (err) => {
|
|
86
|
-
if (worker[kTaskInfo])
|
|
87
|
-
worker[kTaskInfo].done(err, null);
|
|
88
|
-
else
|
|
89
|
-
this.emit("error", err);
|
|
90
|
-
this.workers.splice(this.workers.indexOf(worker), 1);
|
|
91
|
-
this.addNewWorker();
|
|
92
|
-
});
|
|
93
|
-
this.workers.push(worker);
|
|
94
|
-
this.freeWorkers.push(worker);
|
|
95
|
-
this.emit(kWorkerFreedEvent);
|
|
96
|
-
}
|
|
97
|
-
runTask(task, callback) {
|
|
98
|
-
const worker = this.freeWorkers.pop();
|
|
99
|
-
if (!worker) {
|
|
100
|
-
this.tasks.push({ task, callback });
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
worker[kTaskInfo] = new WorkerPoolTaskInfo(callback);
|
|
104
|
-
worker.postMessage(task);
|
|
105
|
-
}
|
|
106
|
-
close() {
|
|
107
|
-
for (const worker of this.workers)
|
|
108
|
-
worker.terminate();
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
var pool = null;
|
|
112
|
-
function startPool(parallelism) {
|
|
113
|
-
if (!pool) {
|
|
114
|
-
const workers = Math.ceil(parallelism ?? os.cpus().length / 4);
|
|
115
|
-
if (workers > 1) {
|
|
116
|
-
pool = new WorkerPool(workers);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function stopPool() {
|
|
121
|
-
if (pool) {
|
|
122
|
-
pool.close();
|
|
123
|
-
pool = null;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function runTaskInPool(task) {
|
|
127
|
-
const p = pool;
|
|
128
|
-
if (p) {
|
|
129
|
-
return new Promise(
|
|
130
|
-
(resolve, reject) => p.runTask(task, (err, result) => {
|
|
131
|
-
if (err)
|
|
132
|
-
reject(err);
|
|
133
|
-
else
|
|
134
|
-
resolve(result);
|
|
135
|
-
})
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
return (0, import_chunk_WIPYYCBN.performTask)(task);
|
|
139
|
-
}
|
|
140
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
141
|
-
0 && (module.exports = {
|
|
142
|
-
runTaskInPool,
|
|
143
|
-
startPool,
|
|
144
|
-
stopPool
|
|
145
|
-
});
|
package/build/chunk-WIPYYCBN.cjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var chunk_WIPYYCBN_exports = {};
|
|
20
|
-
__export(chunk_WIPYYCBN_exports, {
|
|
21
|
-
init_worker_task: () => init_worker_task,
|
|
22
|
-
performTask: () => performTask
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(chunk_WIPYYCBN_exports);
|
|
25
|
-
var import_chunk_TQHOJQYY = require("./chunk-TQHOJQYY.cjs");
|
|
26
|
-
var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
|
|
27
|
-
async function performTask(task) {
|
|
28
|
-
const type = task.type;
|
|
29
|
-
const handler = Object.prototype.hasOwnProperty.call(workerTaskHandlers, type) && workerTaskHandlers[type];
|
|
30
|
-
if (!handler) {
|
|
31
|
-
throw new Error(`Invalid task type ${type}`);
|
|
32
|
-
}
|
|
33
|
-
return handler(task.data);
|
|
34
|
-
}
|
|
35
|
-
var workerTaskHandlers;
|
|
36
|
-
var init_worker_task = (0, import_chunk_IAUHYWVN.__esm)({
|
|
37
|
-
"src/worker-task.ts"() {
|
|
38
|
-
"use strict";
|
|
39
|
-
(0, import_chunk_TQHOJQYY.init_optimizer)();
|
|
40
|
-
workerTaskHandlers = {
|
|
41
|
-
buildOptimizedProject(data) {
|
|
42
|
-
return (0, import_chunk_TQHOJQYY.buildOptimizedProject)(data.product, data.options);
|
|
43
|
-
},
|
|
44
|
-
generateOptimizedProject(data) {
|
|
45
|
-
return (0, import_chunk_TQHOJQYY.generateOptimizedProject)(data.options);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
-
0 && (module.exports = {
|
|
52
|
-
init_worker_task,
|
|
53
|
-
performTask
|
|
54
|
-
});
|