@mirascript/mirascript 0.1.38 → 0.1.40

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.
Files changed (39) hide show
  1. package/dist/{chunk-SEZII6RI.js → chunk-GBWG7BQZ.js} +6 -5
  2. package/dist/chunk-GBWG7BQZ.js.map +6 -0
  3. package/dist/{chunk-C6YXWSTI.js → chunk-SXCYD4OW.js} +34 -28
  4. package/dist/chunk-SXCYD4OW.js.map +6 -0
  5. package/dist/compiler/worker.js +1 -1
  6. package/dist/helpers/constants.d.ts +1 -1
  7. package/dist/helpers/constants.d.ts.map +1 -1
  8. package/dist/helpers/utils.d.ts +3 -3
  9. package/dist/helpers/utils.d.ts.map +1 -1
  10. package/dist/index.js +180 -6
  11. package/dist/index.js.map +2 -2
  12. package/dist/subtle.js +64 -7
  13. package/dist/subtle.js.map +2 -2
  14. package/dist/vm/types/extern.d.ts +9 -2
  15. package/dist/vm/types/extern.d.ts.map +1 -1
  16. package/package.json +5 -15
  17. package/src/helpers/constants.ts +1 -1
  18. package/src/helpers/utils.ts +2 -2
  19. package/src/vm/operations/helpers.ts +4 -4
  20. package/src/vm/operations/utils.ts +11 -11
  21. package/src/vm/types/extern.ts +23 -11
  22. package/cli.js +0 -3
  23. package/dist/chunk-C6YXWSTI.js.map +0 -6
  24. package/dist/chunk-HGARNCSR.js +0 -74
  25. package/dist/chunk-HGARNCSR.js.map +0 -6
  26. package/dist/chunk-RQRTM6AH.js +0 -188
  27. package/dist/chunk-RQRTM6AH.js.map +0 -6
  28. package/dist/chunk-SEZII6RI.js.map +0 -6
  29. package/dist/cli/execute.d.ts +0 -4
  30. package/dist/cli/execute.d.ts.map +0 -1
  31. package/dist/cli/index.d.ts +0 -9
  32. package/dist/cli/index.d.ts.map +0 -1
  33. package/dist/cli/index.js +0 -165
  34. package/dist/cli/index.js.map +0 -6
  35. package/dist/cli/print.d.ts +0 -4
  36. package/dist/cli/print.d.ts.map +0 -1
  37. package/src/cli/execute.ts +0 -40
  38. package/src/cli/index.ts +0 -89
  39. package/src/cli/print.ts +0 -57
package/dist/cli/index.js DELETED
@@ -1,165 +0,0 @@
1
- import {
2
- compile,
3
- compileSync
4
- } from "../chunk-RQRTM6AH.js";
5
- import "../chunk-HGARNCSR.js";
6
- import {
7
- configCheckpoint,
8
- createVmContext,
9
- debug_print,
10
- operations_exports,
11
- panic
12
- } from "../chunk-C6YXWSTI.js";
13
- import {
14
- PositiveInfinity,
15
- isNaN,
16
- serialize,
17
- serializeBoolean,
18
- serializeNil,
19
- serializeNumber
20
- } from "../chunk-SEZII6RI.js";
21
-
22
- // src/cli/index.ts
23
- import { readFile, stat } from "node:fs/promises";
24
- import { pathToFileURL } from "node:url";
25
- import { InvalidArgumentError, program } from "@commander-js/extra-typings";
26
-
27
- // src/cli/execute.ts
28
- import styles2 from "ansi-styles";
29
- import supportsColor2 from "supports-color";
30
-
31
- // src/cli/print.ts
32
- import styles from "ansi-styles";
33
- import supportsColor from "supports-color";
34
- var noColor = !supportsColor.stdout;
35
- var options = {
36
- maxDepth: 3,
37
- serializeNil: noColor ? void 0 : () => styles.gray.open + serializeNil() + styles.gray.close,
38
- serializeBoolean: noColor ? void 0 : (v) => styles.blue.open + serializeBoolean(v) + styles.blue.close,
39
- serializeNumber: noColor ? void 0 : (v) => styles.yellow.open + serializeNumber(v) + styles.yellow.close,
40
- serializeStringQuote: noColor ? void 0 : (v, open) => {
41
- const q = styles.dim.open + v + styles.dim.close;
42
- if (open) {
43
- return styles.green.open + q;
44
- } else {
45
- return q + styles.green.close;
46
- }
47
- },
48
- serializeStringEscape: noColor ? void 0 : (v) => styles.bold.open + v + styles.bold.close,
49
- serializePropName: noColor ? void 0 : (v) => styles.whiteBright.open + String(v) + styles.whiteBright.close,
50
- serializeFunction: noColor ? operations_exports.$ToString : (v) => styles.cyan.open + operations_exports.$ToString(v) + styles.cyan.close,
51
- serializeModule: noColor ? (v, depth, options2) => {
52
- return operations_exports.$ToString(v) + " " + options2.serializeRecord(v.value, depth, options2);
53
- } : (v, depth, options2) => {
54
- return styles.magenta.open + operations_exports.$ToString(v) + styles.magenta.close + " " + options2.serializeRecord(v.value, depth, options2);
55
- }
56
- };
57
- function print(value, depth = 3) {
58
- if (value === void 0) {
59
- if (noColor) return "<uninitialized>";
60
- return styles.gray.open + "<uninitialized>" + styles.gray.close;
61
- }
62
- return serialize(value, { ...options, maxDepth: depth });
63
- }
64
-
65
- // src/cli/execute.ts
66
- panic.serializer = debug_print.serializer = (arg, format) => {
67
- if (format === "%o" || format === "%O" || !format) {
68
- return print(arg);
69
- }
70
- return null;
71
- };
72
- async function execute(script, template, variables, fileName) {
73
- try {
74
- const f = await compile(script, { input_mode: template ? "Template" : "Script", sourceMap: true, fileName });
75
- const r = f(createVmContext(variables));
76
- if (template) {
77
- console.log(r);
78
- } else {
79
- console.log(print(r));
80
- }
81
- } catch (ex) {
82
- const { stack } = ex;
83
- if (supportsColor2.stderr) {
84
- console.error(styles2.red.open + stack + styles2.red.close);
85
- } else {
86
- console.error(stack);
87
- }
88
- process.exitCode = 2;
89
- }
90
- }
91
-
92
- // src/cli/index.ts
93
- import pkg from "#package.json" with { type: "json" };
94
- var DEFAULT_TIMEOUT = 3e3;
95
- var cli_default = program.name(pkg.name.split("/").pop()).version(pkg.version).description(pkg.description).option(
96
- "-v, --variable <key=value>",
97
- "设置全局变量,可以多次使用",
98
- (v, p) => {
99
- p = { ...p };
100
- const i = v.indexOf("=");
101
- if (i < 0) {
102
- p[v] = true;
103
- } else {
104
- const key = v.slice(0, i).trim();
105
- const value = v.slice(i + 1).trim();
106
- try {
107
- const pv = compileSync(`return (${value});`)();
108
- p[key] = pv ?? value;
109
- } catch {
110
- p[key] = value;
111
- }
112
- }
113
- return p;
114
- },
115
- {}
116
- ).option("-t, --template", "使用模板模式").option(
117
- "--timeout <ms>",
118
- "脚本执行超时时间(毫秒,0 表示不超时)",
119
- (v) => {
120
- const ms = Number.parseFloat(v);
121
- if (isNaN(ms) || ms < 0) {
122
- throw new InvalidArgumentError("超时时间必须是非负整数");
123
- }
124
- return ms;
125
- },
126
- DEFAULT_TIMEOUT
127
- ).option("--no-template", "使用脚本模式").option("-e, --eval <script>", "要执行的脚本").argument("[script]", "要执行的脚本文件路径(如果提供了 -e 则忽略此参数)").action(async (script, opt) => {
128
- configCheckpoint(opt.timeout || PositiveInfinity);
129
- if (opt.eval != null) {
130
- const template = !!opt.template;
131
- await execute(opt.eval, template, opt.variable, template ? "eval.miratpl" : "eval.mira");
132
- return;
133
- }
134
- if (script) {
135
- try {
136
- const s = await stat(script);
137
- if (!s.isFile()) {
138
- console.error(`脚本路径不是文件: ${script}`);
139
- process.exitCode = 2;
140
- return;
141
- }
142
- } catch (ex) {
143
- if (ex.code === "ENOENT") {
144
- console.error(`脚本文件不存在: ${script}`);
145
- process.exitCode = 2;
146
- } else if (ex.code === "EACCES") {
147
- console.error(`权限不足: ${ex.message}`);
148
- process.exitCode = 3;
149
- } else {
150
- console.error(`无法访问脚本文件: ${ex.message}`);
151
- process.exitCode = 1;
152
- }
153
- return;
154
- }
155
- const context = await readFile(script, "utf8");
156
- const template = opt.template ?? script.endsWith(".miratpl");
157
- await execute(context, template, opt.variable, pathToFileURL(script).href);
158
- return;
159
- }
160
- program.help({ error: true });
161
- });
162
- export {
163
- cli_default as default
164
- };
165
- //# sourceMappingURL=index.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/cli/index.ts", "../../src/cli/execute.ts", "../../src/cli/print.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,UAAU,YAAY;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB,eAAe;;;ACF9C,OAAOA,aAAY;AACnB,OAAOC,oBAAmB;;;ACF1B,OAAO,YAAY;AACnB,OAAO,mBAAmB;AAW1B,IAAM,UAAU,CAAC,cAAc;AAE/B,IAAM,UAAqC;AAAA,EACvC,UAAU;AAAA,EACV,cAAc,UA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ACA;AAAA,IACJ;AACA,UAAM,UAAU,MAAM,SAAS,QAAQ,MAAM;AAC7C,UAAM,WAAW,IAAI,YAAY,OAAO,SAAS,UAAU;AAC3D,UAAM,QAAQ,SAAS,UAAU,IAAI,UAAU,cAAc,MAAM,EAAE,IAAI;AACzE;AAAA,EACJ;AACA,UAAQ,KAAK,EAAE,OAAO,KAAK,CAAC;AAChC,CAAC;",
5
- "names": ["styles", "supportsColor", "options", "supportsColor", "styles"]
6
- }
@@ -1,4 +0,0 @@
1
- import type { VmAny } from '../vm/index.js';
2
- /** 序列化值 */
3
- export declare function print(value: VmAny, depth?: number): string;
4
- //# sourceMappingURL=print.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"print.d.ts","sourceRoot":"","sources":["../../src/cli/print.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,KAAK,EAAY,MAAM,gBAAgB,CAAC;AAuCtD,WAAW;AACX,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,SAAI,GAAG,MAAM,CAMrD"}
@@ -1,40 +0,0 @@
1
- /* eslint-disable no-console */
2
- import styles from 'ansi-styles';
3
- import supportsColor from 'supports-color';
4
- import { compile } from '../index.js';
5
- import { createVmContext, type VmValue } from '../vm/index.js';
6
- import { debug_print, panic } from '../vm/lib/global/debug.js';
7
- import { print } from './print.js';
8
-
9
- panic.serializer = debug_print.serializer = (arg, format) => {
10
- if (format === '%o' || format === '%O' || !format) {
11
- return print(arg);
12
- }
13
- return null;
14
- };
15
-
16
- /** 执行脚本 */
17
- export async function execute(
18
- script: string,
19
- template: boolean,
20
- variables: Record<string, VmValue>,
21
- fileName: string,
22
- ): Promise<void> {
23
- try {
24
- const f = await compile(script, { input_mode: template ? 'Template' : 'Script', sourceMap: true, fileName });
25
- const r = f(createVmContext(variables));
26
- if (template) {
27
- console.log(r);
28
- } else {
29
- console.log(print(r));
30
- }
31
- } catch (ex) {
32
- const { stack } = ex as Error;
33
- if (supportsColor.stderr) {
34
- console.error(styles.red.open + stack + styles.red.close);
35
- } else {
36
- console.error(stack);
37
- }
38
- process.exitCode = 2;
39
- }
40
- }
package/src/cli/index.ts DELETED
@@ -1,89 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { readFile, stat } from 'node:fs/promises';
3
- import { pathToFileURL } from 'node:url';
4
- import { InvalidArgumentError, program } from '@commander-js/extra-typings';
5
- import { execute } from './execute.js';
6
- import { isNaN, PositiveInfinity } from '../helpers/utils.js';
7
- import pkg from '#package.json' with { type: 'json' };
8
- import { compileSync } from '../compiler/index.js';
9
- import { configCheckpoint, type VmValue } from '../vm/index.js';
10
-
11
- const DEFAULT_TIMEOUT = 3000;
12
-
13
- export default program
14
- .name(pkg.name.split('/').pop()!)
15
- .version(pkg.version)
16
- .description(pkg.description)
17
- .option(
18
- '-v, --variable <key=value>',
19
- '设置全局变量,可以多次使用',
20
- (v, p) => {
21
- p = { ...p };
22
- const i = v.indexOf('=');
23
- if (i < 0) {
24
- p[v] = true;
25
- } else {
26
- const key = v.slice(0, i).trim();
27
- const value = v.slice(i + 1).trim();
28
- try {
29
- const pv = compileSync(`return (${value});`)();
30
- p[key] = pv ?? value;
31
- } catch {
32
- p[key] = value;
33
- }
34
- }
35
- return p;
36
- },
37
- {} as Record<string, VmValue>,
38
- )
39
- .option('-t, --template', '使用模板模式')
40
- .option(
41
- '--timeout <ms>',
42
- '脚本执行超时时间(毫秒,0 表示不超时)',
43
- (v) => {
44
- const ms = Number.parseFloat(v);
45
- if (isNaN(ms) || ms < 0) {
46
- throw new InvalidArgumentError('超时时间必须是非负整数');
47
- }
48
- return ms;
49
- },
50
- DEFAULT_TIMEOUT,
51
- )
52
- .option('--no-template', '使用脚本模式')
53
- .option('-e, --eval <script>', '要执行的脚本')
54
- .argument('[script]', '要执行的脚本文件路径(如果提供了 -e 则忽略此参数)')
55
- .action(async (script, opt) => {
56
- configCheckpoint(opt.timeout || PositiveInfinity);
57
- if (opt.eval != null) {
58
- const template = !!opt.template;
59
- await execute(opt.eval, template, opt.variable, template ? 'eval.miratpl' : 'eval.mira');
60
- return;
61
- }
62
- if (script) {
63
- try {
64
- const s = await stat(script);
65
- if (!s.isFile()) {
66
- console.error(`脚本路径不是文件: ${script}`);
67
- process.exitCode = 2;
68
- return;
69
- }
70
- } catch (ex) {
71
- if ((ex as NodeJS.ErrnoException).code === 'ENOENT') {
72
- console.error(`脚本文件不存在: ${script}`);
73
- process.exitCode = 2;
74
- } else if ((ex as NodeJS.ErrnoException).code === 'EACCES') {
75
- console.error(`权限不足: ${(ex as NodeJS.ErrnoException).message}`);
76
- process.exitCode = 3;
77
- } else {
78
- console.error(`无法访问脚本文件: ${(ex as NodeJS.ErrnoException).message}`);
79
- process.exitCode = 1;
80
- }
81
- return;
82
- }
83
- const context = await readFile(script, 'utf8');
84
- const template = opt.template ?? script.endsWith('.miratpl');
85
- await execute(context, template, opt.variable, pathToFileURL(script).href);
86
- return;
87
- }
88
- program.help({ error: true });
89
- });
package/src/cli/print.ts DELETED
@@ -1,57 +0,0 @@
1
- import styles from 'ansi-styles';
2
- import supportsColor from 'supports-color';
3
- import {
4
- serialize,
5
- serializeNumber,
6
- serializeBoolean,
7
- serializeNil,
8
- type SerializeOptions,
9
- operations,
10
- } from '../subtle.js';
11
- import type { VmAny, VmRecord } from '../vm/index.js';
12
-
13
- const noColor = !supportsColor.stdout;
14
-
15
- const options: Partial<SerializeOptions> = {
16
- maxDepth: 3,
17
- serializeNil: noColor ? undefined : () => styles.gray.open + serializeNil() + styles.gray.close,
18
- serializeBoolean: noColor ? undefined : (v) => styles.blue.open + serializeBoolean(v) + styles.blue.close,
19
- serializeNumber: noColor ? undefined : (v) => styles.yellow.open + serializeNumber(v) + styles.yellow.close,
20
- serializeStringQuote: noColor
21
- ? undefined
22
- : (v, open) => {
23
- const q = styles.dim.open + v + styles.dim.close;
24
- if (open) {
25
- return styles.green.open + q;
26
- } else {
27
- return q + styles.green.close;
28
- }
29
- },
30
- serializeStringEscape: noColor ? undefined : (v) => styles.bold.open + v + styles.bold.close,
31
- serializePropName: noColor ? undefined : (v) => styles.whiteBright.open + String(v) + styles.whiteBright.close,
32
- serializeFunction: noColor
33
- ? operations.$ToString
34
- : (v) => styles.cyan.open + operations.$ToString(v) + styles.cyan.close,
35
- serializeModule: noColor
36
- ? (v, depth, options) => {
37
- return operations.$ToString(v) + ' ' + options.serializeRecord(v.value as VmRecord, depth, options);
38
- }
39
- : (v, depth, options) => {
40
- return (
41
- styles.magenta.open +
42
- operations.$ToString(v) +
43
- styles.magenta.close +
44
- ' ' +
45
- options.serializeRecord(v.value as VmRecord, depth, options)
46
- );
47
- },
48
- };
49
-
50
- /** 序列化值 */
51
- export function print(value: VmAny, depth = 3): string {
52
- if (value === undefined) {
53
- if (noColor) return '<uninitialized>';
54
- return styles.gray.open + '<uninitialized>' + styles.gray.close;
55
- }
56
- return serialize(value, { ...options, maxDepth: depth });
57
- }