ya-struct 0.0.10 → 0.0.12
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/lib/index.d.ts +2 -1
- package/dist/lib/index.js +3 -1
- package/dist/lib/layout.js +44 -44
- package/dist/lib/parser.d.ts +7 -1
- package/dist/lib/parser.js +6 -0
- package/dist/lib/tests/compile-and-compare.vibe.d.ts +30 -0
- package/dist/lib/tests/compile-and-compare.vibe.js +221 -0
- package/dist/lib/types/array.js +1 -0
- package/dist/lib/types/string.js +1 -0
- package/dist/lib/types/struct.js +1 -0
- package/package.json +12 -7
- package/.editorconfig +0 -8
- package/.github/workflows/ci.yml +0 -23
- package/.github/workflows/npm-publish.yml +0 -28
- package/eslint.config.js +0 -127
- package/lib/bit-buffer.ts +0 -70
- package/lib/common.ts +0 -30
- package/lib/index.ts +0 -21
- package/lib/layout.ts +0 -286
- package/lib/parser.ts +0 -88
- package/lib/types/array.ts +0 -90
- package/lib/types/c-types.ts +0 -222
- package/lib/types/index.ts +0 -122
- package/lib/types/integer.ts +0 -160
- package/lib/types/pointer.ts +0 -27
- package/lib/types/string.ts +0 -56
- package/lib/types/struct.ts +0 -146
- package/lib/types/value.ts +0 -8
- package/package.npm.json +0 -25
- package/samples/basic.ts +0 -40
- package/test/c-structs.ts +0 -399
- package/test/compile-util.ts +0 -92
- package/test/nested-structs.ts +0 -78
- package/tsconfig.json +0 -11
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { define } from "./parser.js";
|
|
2
2
|
import { types } from "./types/index.js";
|
|
3
|
+
import { compileAndCompare } from "./tests/compile-and-compare.vibe.js";
|
|
3
4
|
import type { TAbi, TCompiler, TDataModel, TEndianness } from "./common.js";
|
|
4
|
-
export { define, types };
|
|
5
|
+
export { define, types, compileAndCompare };
|
|
5
6
|
export type { TAbi, TEndianness, TCompiler, TDataModel };
|
package/dist/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { define } from "./parser.js";
|
|
2
2
|
import { types } from "./types/index.js";
|
|
3
|
+
import { compileAndCompare } from "./tests/compile-and-compare.vibe.js";
|
|
3
4
|
|
|
4
5
|
/*import type {
|
|
5
6
|
TAbi,
|
|
@@ -10,7 +11,8 @@ import { types } from "./types/index.js";
|
|
|
10
11
|
|
|
11
12
|
export {
|
|
12
13
|
define,
|
|
13
|
-
types
|
|
14
|
+
types,
|
|
15
|
+
compileAndCompare
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
/*export type {
|
package/dist/lib/layout.js
CHANGED
|
@@ -42,12 +42,12 @@ import nodeUtil from "node:util";
|
|
|
42
42
|
|
|
43
43
|
const pointerSizeInBitsByDataModel = ({ dataModel }/*: { dataModel: TAbi["dataModel"] }*/)/*: number*/ => {
|
|
44
44
|
switch (dataModel) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
case "LP64":
|
|
46
|
+
return 64;
|
|
47
|
+
case "ILP32":
|
|
48
|
+
return 32;
|
|
49
|
+
default:
|
|
50
|
+
throw Error(`unsupported data model "${dataModel}" for pointer size determination`);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
|
|
@@ -82,53 +82,53 @@ const layoutStruct = ({
|
|
|
82
82
|
|
|
83
83
|
if (!definition.packed) {
|
|
84
84
|
switch (normalizedField.type) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
break;
|
|
85
|
+
case "integer":
|
|
86
|
+
case "float": {
|
|
87
|
+
const sizeInBits = normalizedField.sizeInBits;
|
|
88
|
+
|
|
89
|
+
if (abi.compiler === "gcc" && abi.dataModel === "ILP32" && sizeInBits === 64) {
|
|
90
|
+
// special handling for gcc 64-bit integers on ILP32 data model (alignment to 32 bits)
|
|
91
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: 32 });
|
|
92
|
+
} else {
|
|
93
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: sizeInBits });
|
|
97
94
|
}
|
|
98
|
-
case "array": {
|
|
99
95
|
|
|
100
|
-
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "array": {
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
const { sizeInBits } = layout({ definition: normalizedField.elementType, abi, currentOffsetInBits: 0 });
|
|
100
|
+
// TODO: this is probably not sufficient for all cases
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: 32 });
|
|
108
|
-
} else {
|
|
109
|
-
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: sizeInBits });
|
|
110
|
-
}
|
|
102
|
+
// eslint-disable-next-line no-use-before-define
|
|
103
|
+
const { sizeInBits } = layout({ definition: normalizedField.elementType, abi, currentOffsetInBits: 0 });
|
|
111
104
|
|
|
112
|
-
|
|
105
|
+
if (abi.compiler === "gcc" && abi.dataModel === "ILP32" && sizeInBits === 64) {
|
|
106
|
+
// special handling for gcc 64-bit integers on ILP32 data model (alignment to 32 bits)
|
|
107
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: 32 });
|
|
108
|
+
} else {
|
|
109
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: sizeInBits });
|
|
113
110
|
}
|
|
114
|
-
case "struct": {
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case "struct": {
|
|
119
115
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
case "string": {
|
|
123
|
-
// no special alignment needed
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
case "pointer": {
|
|
127
|
-
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: pointerSizeInBits });
|
|
128
|
-
break;
|
|
116
|
+
if (currentOffsetInBits % 64 !== 0) {
|
|
117
|
+
throw Error("nested struct alignment handling not implemented yet");
|
|
129
118
|
}
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case "string": {
|
|
123
|
+
// no special alignment needed
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case "pointer": {
|
|
127
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: pointerSizeInBits });
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
default:
|
|
131
|
+
throw Error(`unsupported field type for struct layout: ${nodeUtil.inspect(field.definition)}`);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
package/dist/lib/parser.d.ts
CHANGED
|
@@ -19,7 +19,12 @@ type FieldValue<T extends TFieldType> = T extends {
|
|
|
19
19
|
} ? StructValue<F & readonly {
|
|
20
20
|
name: string;
|
|
21
21
|
definition: TFieldType;
|
|
22
|
-
}[]> :
|
|
22
|
+
}[]> : T extends {
|
|
23
|
+
type: "c-type";
|
|
24
|
+
cType: "float" | "double" | "long double";
|
|
25
|
+
} ? number : T extends {
|
|
26
|
+
type: "c-type";
|
|
27
|
+
} ? bigint : never;
|
|
23
28
|
type StructValue<F extends readonly {
|
|
24
29
|
name: string;
|
|
25
30
|
definition: TFieldType;
|
|
@@ -49,3 +54,4 @@ declare const define: <const T extends TFieldType>({ definition }: {
|
|
|
49
54
|
}) => TParser<T>;
|
|
50
55
|
};
|
|
51
56
|
export { define };
|
|
57
|
+
export type { TParser, };
|
package/dist/lib/parser.js
CHANGED
|
@@ -13,6 +13,8 @@ import { createStructParser } from "./types/struct.js";
|
|
|
13
13
|
? FieldValue<E & TFieldType>[] :
|
|
14
14
|
T extends { type: "struct"; fields: infer F }
|
|
15
15
|
? StructValue<F & readonly { name: string; definition: TFieldType }[]> :
|
|
16
|
+
T extends { type: "c-type"; cType: "float" | "double" | "long double" } ? number :
|
|
17
|
+
T extends { type: "c-type" } ? bigint :
|
|
16
18
|
never;*/
|
|
17
19
|
|
|
18
20
|
/*type StructValue<
|
|
@@ -86,3 +88,7 @@ const define = /*<const T extends TFieldType>*/({ definition }/*: { definition:
|
|
|
86
88
|
export {
|
|
87
89
|
define
|
|
88
90
|
};
|
|
91
|
+
|
|
92
|
+
/*export type {
|
|
93
|
+
TParser,
|
|
94
|
+
};*/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TAbi } from "../common.js";
|
|
2
|
+
import type { TFieldType } from "../types/index.js";
|
|
3
|
+
type TLayoutError = {
|
|
4
|
+
type: "size-mismatch";
|
|
5
|
+
fieldPath: string;
|
|
6
|
+
expectedSizeInBits: number;
|
|
7
|
+
actualSizeInBits: number;
|
|
8
|
+
} | {
|
|
9
|
+
type: "offset-mismatch";
|
|
10
|
+
fieldPath: string;
|
|
11
|
+
expectedOffsetInBits: number;
|
|
12
|
+
actualOffsetInBits: number;
|
|
13
|
+
};
|
|
14
|
+
type TCompileAndCompareResult = {
|
|
15
|
+
layoutErrors: TLayoutError[];
|
|
16
|
+
};
|
|
17
|
+
declare const compileAndCompare: ({ structDefinition, abi, globalCode, cStructName, compileAndRun }: {
|
|
18
|
+
structDefinition: Extract<TFieldType, {
|
|
19
|
+
type: "struct";
|
|
20
|
+
}>;
|
|
21
|
+
abi: TAbi;
|
|
22
|
+
globalCode: string;
|
|
23
|
+
cStructName: string;
|
|
24
|
+
compileAndRun: ({ sourceCode }: {
|
|
25
|
+
sourceCode: string;
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
output: string;
|
|
28
|
+
}>;
|
|
29
|
+
}) => Promise<TCompileAndCompareResult>;
|
|
30
|
+
export { compileAndCompare };
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/*import type { TAbi } from "../common.ts";*/
|
|
2
|
+
/*import type { TLayoutedField } from "../layout.ts";*/
|
|
3
|
+
import { define } from "../parser.js";
|
|
4
|
+
/*import type { TFieldType } from "../types/index.ts";*/
|
|
5
|
+
|
|
6
|
+
/*type TLayoutError = {
|
|
7
|
+
type: "size-mismatch",
|
|
8
|
+
fieldPath: string;
|
|
9
|
+
expectedSizeInBits: number;
|
|
10
|
+
actualSizeInBits: number;
|
|
11
|
+
} | {
|
|
12
|
+
type: "offset-mismatch",
|
|
13
|
+
fieldPath: string;
|
|
14
|
+
expectedOffsetInBits: number;
|
|
15
|
+
actualOffsetInBits: number;
|
|
16
|
+
};*/
|
|
17
|
+
|
|
18
|
+
/*type TCompileAndCompareResult = {
|
|
19
|
+
layoutErrors: TLayoutError[];
|
|
20
|
+
};*/
|
|
21
|
+
|
|
22
|
+
/*type TFlatField = {
|
|
23
|
+
fieldPath: string;
|
|
24
|
+
offsetInBits: number;
|
|
25
|
+
sizeInBits: number;
|
|
26
|
+
isStruct: boolean;
|
|
27
|
+
};*/
|
|
28
|
+
|
|
29
|
+
/*type TStructLayoutedFields =
|
|
30
|
+
(TLayoutedField & { type: "struct" })["fields"];*/
|
|
31
|
+
|
|
32
|
+
const flattenLayout = ({
|
|
33
|
+
fields,
|
|
34
|
+
parentPath
|
|
35
|
+
}/*: {
|
|
36
|
+
fields: TStructLayoutedFields;
|
|
37
|
+
parentPath: string;
|
|
38
|
+
}*/)/*: TFlatField[]*/ => {
|
|
39
|
+
return fields.flatMap((field) => {
|
|
40
|
+
const fieldPath = parentPath
|
|
41
|
+
? `${parentPath}.${field.name}`
|
|
42
|
+
: field.name;
|
|
43
|
+
|
|
44
|
+
const isStruct = field.definition.type === "struct";
|
|
45
|
+
|
|
46
|
+
const entry/*: TFlatField*/ = {
|
|
47
|
+
fieldPath,
|
|
48
|
+
offsetInBits: field.definition.offsetInBits,
|
|
49
|
+
sizeInBits: field.definition.sizeInBits,
|
|
50
|
+
isStruct,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (isStruct) {
|
|
54
|
+
return [
|
|
55
|
+
entry,
|
|
56
|
+
...flattenLayout({
|
|
57
|
+
fields: field.definition.fields,
|
|
58
|
+
parentPath: fieldPath,
|
|
59
|
+
}),
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return [entry];
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const generateSourceCode = ({
|
|
68
|
+
globalCode,
|
|
69
|
+
cStructName,
|
|
70
|
+
flatFields,
|
|
71
|
+
}/*: {
|
|
72
|
+
globalCode: string;
|
|
73
|
+
cStructName: string;
|
|
74
|
+
flatFields: TFlatField[];
|
|
75
|
+
}*/) => {
|
|
76
|
+
|
|
77
|
+
const printStatements = flatFields.map((f, idx) => {
|
|
78
|
+
if (f.isStruct) {
|
|
79
|
+
const offsetExpr =
|
|
80
|
+
`offsetof(struct ${cStructName}, ${f.fieldPath}) * CHAR_BIT`;
|
|
81
|
+
const sizeExpr =
|
|
82
|
+
`sizeof(((struct ${cStructName}*)0)->${f.fieldPath}) * CHAR_BIT`;
|
|
83
|
+
|
|
84
|
+
return ` printf("%zu %zu\\n", `
|
|
85
|
+
+ `(size_t)(${offsetExpr}), (size_t)(${sizeExpr}));`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Use memory scanning to detect actual bit offset and size.
|
|
89
|
+
// This works for both regular fields and bitfields.
|
|
90
|
+
return ` {
|
|
91
|
+
struct ${cStructName} __s${idx};
|
|
92
|
+
memset(&__s${idx}, 0, sizeof(__s${idx}));
|
|
93
|
+
memset(&__s${idx}.${f.fieldPath}, 0xFF, sizeof(__s${idx}.${f.fieldPath}));
|
|
94
|
+
unsigned char *__p${idx} = (unsigned char *)&__s${idx};
|
|
95
|
+
size_t __off${idx} = 0, __sz${idx} = 0;
|
|
96
|
+
int __found${idx} = 0;
|
|
97
|
+
for (size_t __i = 0; __i < sizeof(struct ${cStructName}) * CHAR_BIT; __i++) {
|
|
98
|
+
if (__p${idx}[__i / CHAR_BIT] & (1u << (__i % CHAR_BIT))) {
|
|
99
|
+
if (!__found${idx}) { __off${idx} = __i; __found${idx} = 1; }
|
|
100
|
+
__sz${idx}++;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
printf("%zu %zu\\n", __off${idx}, __sz${idx});
|
|
104
|
+
}`;
|
|
105
|
+
}).join("\n");
|
|
106
|
+
|
|
107
|
+
return `#include <stdio.h>
|
|
108
|
+
#include <stddef.h>
|
|
109
|
+
#include <limits.h>
|
|
110
|
+
#include <string.h>
|
|
111
|
+
${globalCode}
|
|
112
|
+
|
|
113
|
+
int main(void) {
|
|
114
|
+
${printStatements}
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const parseCOutput = ({
|
|
121
|
+
output,
|
|
122
|
+
}/*: {
|
|
123
|
+
output: string;
|
|
124
|
+
}*/)/*: { offset: number; size: number }[]*/ => {
|
|
125
|
+
return output.trim().split("\n").map((line) => {
|
|
126
|
+
const parts = line.trim().split(" ");
|
|
127
|
+
return {
|
|
128
|
+
offset: parseInt(parts[0], 10),
|
|
129
|
+
size: parseInt(parts[1], 10),
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const compareLayouts = ({
|
|
135
|
+
flatFields,
|
|
136
|
+
cFields,
|
|
137
|
+
}/*: {
|
|
138
|
+
flatFields: TFlatField[];
|
|
139
|
+
cFields: { offset: number; size: number }[];
|
|
140
|
+
}*/)/*: TLayoutError[]*/ => {
|
|
141
|
+
return flatFields.flatMap((field, idx) => {
|
|
142
|
+
const cField = cFields[idx];
|
|
143
|
+
if (!cField) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const sizeMismatch/*: TLayoutError[]*/ =
|
|
148
|
+
cField.size === field.sizeInBits
|
|
149
|
+
? []
|
|
150
|
+
: [{
|
|
151
|
+
type: "size-mismatch" /*as const*/,
|
|
152
|
+
fieldPath: field.fieldPath,
|
|
153
|
+
expectedSizeInBits: cField.size,
|
|
154
|
+
actualSizeInBits: field.sizeInBits,
|
|
155
|
+
}];
|
|
156
|
+
|
|
157
|
+
const offsetMismatch/*: TLayoutError[]*/ =
|
|
158
|
+
cField.offset === field.offsetInBits
|
|
159
|
+
? []
|
|
160
|
+
: [{
|
|
161
|
+
type: "offset-mismatch" /*as const*/,
|
|
162
|
+
fieldPath: field.fieldPath,
|
|
163
|
+
expectedOffsetInBits: cField.offset,
|
|
164
|
+
actualOffsetInBits: field.offsetInBits,
|
|
165
|
+
}];
|
|
166
|
+
|
|
167
|
+
return [...sizeMismatch, ...offsetMismatch];
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const compileAndCompare = async ({
|
|
172
|
+
structDefinition,
|
|
173
|
+
abi,
|
|
174
|
+
|
|
175
|
+
globalCode,
|
|
176
|
+
cStructName,
|
|
177
|
+
|
|
178
|
+
compileAndRun
|
|
179
|
+
}/*: {
|
|
180
|
+
structDefinition: Extract<TFieldType, { type: "struct" }>;
|
|
181
|
+
abi: TAbi;
|
|
182
|
+
|
|
183
|
+
globalCode: string;
|
|
184
|
+
cStructName: string;
|
|
185
|
+
|
|
186
|
+
compileAndRun: ({ sourceCode }: { sourceCode: string }) => Promise<{
|
|
187
|
+
output: string;
|
|
188
|
+
}>;
|
|
189
|
+
}*/)/*: Promise<TCompileAndCompareResult>*/ => {
|
|
190
|
+
|
|
191
|
+
const def = define({ definition: structDefinition });
|
|
192
|
+
const parser = def.parser({ abi });
|
|
193
|
+
const layoutResult = parser.layout;
|
|
194
|
+
|
|
195
|
+
if (layoutResult.type !== "struct") {
|
|
196
|
+
throw Error("expected struct layout");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const flatFields = flattenLayout({
|
|
200
|
+
fields: layoutResult.fields,
|
|
201
|
+
parentPath: "",
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
const sourceCode = generateSourceCode({
|
|
205
|
+
globalCode,
|
|
206
|
+
cStructName,
|
|
207
|
+
flatFields,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const { output } = await compileAndRun({ sourceCode });
|
|
211
|
+
|
|
212
|
+
const cFields = parseCOutput({ output });
|
|
213
|
+
|
|
214
|
+
const layoutErrors = compareLayouts({ flatFields, cFields });
|
|
215
|
+
|
|
216
|
+
return { layoutErrors };
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export {
|
|
220
|
+
compileAndCompare
|
|
221
|
+
};
|
package/dist/lib/types/array.js
CHANGED
|
@@ -43,6 +43,7 @@ const createArrayParser = ({
|
|
|
43
43
|
for (let i = 0; i < length; i += 1) {
|
|
44
44
|
const fieldData = data.subarray(i * elementSizeInBytes, (i + 1) * elementSizeInBytes);
|
|
45
45
|
const fieldValue = fieldParser.parse({ data: fieldData, offsetInBits: 0 });
|
|
46
|
+
// eslint-disable-next-line fp/no-mutating-methods -- performance
|
|
46
47
|
result.push(fieldValue);
|
|
47
48
|
}
|
|
48
49
|
|
package/dist/lib/types/string.js
CHANGED
package/dist/lib/types/struct.js
CHANGED
|
@@ -98,6 +98,7 @@ const createStructParser = ({
|
|
|
98
98
|
sizeInBits: field.definition.sizeInBits
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
+
// eslint-disable-next-line immutable/no-mutation -- performance
|
|
101
102
|
result[field.name] = fieldParser.parse({ data: fieldData, offsetInBits: fieldOffsetInBits });
|
|
102
103
|
});
|
|
103
104
|
|
package/package.json
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.12",
|
|
3
3
|
"name": "ya-struct",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Yet Another Node.js Structure API",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"main": "dist/lib/index.js",
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "rm -rf dist/ && deno-node-build --root . --out dist/ --entry lib/index.ts",
|
|
9
12
|
"test": "c8 --reporter lcov --reporter html --reporter text --all --src lib/ mocha test/**/*.ts",
|
|
10
|
-
"lint": "eslint ."
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"type-check": "tsc --noEmit",
|
|
15
|
+
"update-deps": "npm-check-updates -u"
|
|
11
16
|
},
|
|
12
17
|
"dependencies": {},
|
|
13
18
|
"devDependencies": {
|
|
14
|
-
"@eslint/js": "^
|
|
19
|
+
"@eslint/js": "^10.0.1",
|
|
20
|
+
"@k13engineering/eslint-rules": "^0.0.5",
|
|
15
21
|
"@k13engineering/releasetool": "^0.0.5",
|
|
16
22
|
"@types/mocha": "^10.0.10",
|
|
17
|
-
"@types/node": "^25.0
|
|
18
|
-
"c8": "^
|
|
23
|
+
"@types/node": "^25.6.0",
|
|
24
|
+
"c8": "^11.0.0",
|
|
19
25
|
"deno-node": "^0.0.12",
|
|
20
|
-
"eslint": "^9.39.2",
|
|
21
26
|
"mocha": "^11.7.5",
|
|
22
27
|
"tmp-promise": "^3.0.3",
|
|
23
|
-
"typescript
|
|
28
|
+
"typescript": "^6.0.3"
|
|
24
29
|
},
|
|
25
30
|
"repository": {
|
|
26
31
|
"type": "git",
|
package/.editorconfig
DELETED
package/.github/workflows/ci.yml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on: [push, pull_request]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
ci:
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
name: Continous integration tests
|
|
9
|
-
steps:
|
|
10
|
-
- uses: actions/checkout@v4
|
|
11
|
-
- uses: actions/setup-node@v4
|
|
12
|
-
with:
|
|
13
|
-
node-version: '24'
|
|
14
|
-
- name: Install libc6-dev-i386
|
|
15
|
-
run: sudo apt-get update && sudo apt-get install -y libc6-dev-i386
|
|
16
|
-
- name: Install dependencies
|
|
17
|
-
run: npm ci
|
|
18
|
-
- name: Build
|
|
19
|
-
run: npm run build
|
|
20
|
-
- name: Run tests
|
|
21
|
-
run: npm run test
|
|
22
|
-
- name: Verify code with linter
|
|
23
|
-
run: npm run lint
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
name: Publish Package to npmjs
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
tags:
|
|
5
|
-
- '*'
|
|
6
|
-
|
|
7
|
-
permissions:
|
|
8
|
-
id-token: write # Required for OIDC
|
|
9
|
-
contents: read
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
publish:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
permissions:
|
|
15
|
-
contents: read
|
|
16
|
-
id-token: write
|
|
17
|
-
steps:
|
|
18
|
-
- uses: actions/checkout@v4
|
|
19
|
-
# Setup .npmrc file to publish to npm
|
|
20
|
-
- uses: actions/setup-node@v4
|
|
21
|
-
with:
|
|
22
|
-
node-version: '24'
|
|
23
|
-
registry-url: 'https://registry.npmjs.org'
|
|
24
|
-
- run: npm ci
|
|
25
|
-
- run: npm run build
|
|
26
|
-
- run: node node_modules/.bin/releasetool merge --local-package-json package.json --npm-package-json package.npm.json --output package.json
|
|
27
|
-
- run: node node_modules/.bin/releasetool patch-version --package-json package.json --package-version ${{ github.ref_name }}
|
|
28
|
-
- run: npm publish
|
package/eslint.config.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/* c8 ignore start */
|
|
2
|
-
import eslint from "@eslint/js";
|
|
3
|
-
import tseslint from "typescript-eslint";
|
|
4
|
-
|
|
5
|
-
export default tseslint.config(
|
|
6
|
-
{
|
|
7
|
-
ignores: [
|
|
8
|
-
"dist/**/*"
|
|
9
|
-
]
|
|
10
|
-
},
|
|
11
|
-
eslint.configs.recommended,
|
|
12
|
-
...tseslint.configs.recommended,
|
|
13
|
-
{
|
|
14
|
-
rules: {
|
|
15
|
-
"global-require": "off",
|
|
16
|
-
"quote-props": ["warn", "consistent-as-needed"],
|
|
17
|
-
|
|
18
|
-
"quotes": ["error", "double", {
|
|
19
|
-
allowTemplateLiterals: true,
|
|
20
|
-
}],
|
|
21
|
-
|
|
22
|
-
"no-plusplus": "error",
|
|
23
|
-
"no-nested-ternary": "error",
|
|
24
|
-
"no-multiple-empty-lines": "error",
|
|
25
|
-
"no-inline-comments": "error",
|
|
26
|
-
"no-lonely-if": "error",
|
|
27
|
-
"no-array-constructor": "error",
|
|
28
|
-
"no-delete-var": "error",
|
|
29
|
-
"no-param-reassign": "error",
|
|
30
|
-
"no-return-assign": "error",
|
|
31
|
-
"no-import-assign": "error",
|
|
32
|
-
"no-multi-assign": "error",
|
|
33
|
-
"keyword-spacing": "error",
|
|
34
|
-
|
|
35
|
-
"max-len": ["warn", {
|
|
36
|
-
code: 140,
|
|
37
|
-
}],
|
|
38
|
-
|
|
39
|
-
"max-params": ["error", 4],
|
|
40
|
-
"max-statements": ["error", 15],
|
|
41
|
-
"no-loss-of-precision": "error",
|
|
42
|
-
"no-unreachable-loop": "error",
|
|
43
|
-
"require-atomic-updates": "error",
|
|
44
|
-
"complexity": ["error", 4],
|
|
45
|
-
|
|
46
|
-
"max-statements-per-line": ["error", {
|
|
47
|
-
max: 1,
|
|
48
|
-
}],
|
|
49
|
-
|
|
50
|
-
"no-tabs": "error",
|
|
51
|
-
"no-underscore-dangle": "error",
|
|
52
|
-
"no-negated-condition": "error",
|
|
53
|
-
"no-use-before-define": "error",
|
|
54
|
-
|
|
55
|
-
"no-shadow": "off",
|
|
56
|
-
"@typescript-eslint/no-shadow": "error",
|
|
57
|
-
|
|
58
|
-
"no-labels": "error",
|
|
59
|
-
"no-throw-literal": "error",
|
|
60
|
-
"default-case": "error",
|
|
61
|
-
"default-case-last": "error",
|
|
62
|
-
"no-caller": "error",
|
|
63
|
-
"no-eval": "error",
|
|
64
|
-
"no-implied-eval": "error",
|
|
65
|
-
"no-new": "error",
|
|
66
|
-
"no-new-func": "error",
|
|
67
|
-
"no-new-object": "error",
|
|
68
|
-
"no-new-wrappers": "error",
|
|
69
|
-
"no-useless-concat": "error",
|
|
70
|
-
|
|
71
|
-
"no-unused-vars": "off",
|
|
72
|
-
"@typescript-eslint/no-unused-vars": ["error", {
|
|
73
|
-
ignoreRestSiblings: true,
|
|
74
|
-
}],
|
|
75
|
-
|
|
76
|
-
"array-bracket-newline": ["error", "consistent"],
|
|
77
|
-
"func-names": ["error", "never"],
|
|
78
|
-
|
|
79
|
-
"func-style": ["error", "expression", {
|
|
80
|
-
allowArrowFunctions: true,
|
|
81
|
-
}],
|
|
82
|
-
|
|
83
|
-
"max-depth": ["error", 4],
|
|
84
|
-
"arrow-parens": "error",
|
|
85
|
-
"no-confusing-arrow": "error",
|
|
86
|
-
"prefer-const": "error",
|
|
87
|
-
"rest-spread-spacing": ["error", "never"],
|
|
88
|
-
"template-curly-spacing": ["error", "never"],
|
|
89
|
-
"prefer-rest-params": "error",
|
|
90
|
-
"prefer-spread": "error",
|
|
91
|
-
"prefer-template": "error",
|
|
92
|
-
"object-shorthand": ["error", "properties"],
|
|
93
|
-
"no-var": "error",
|
|
94
|
-
"no-useless-computed-key": "error",
|
|
95
|
-
"array-callback-return": "error",
|
|
96
|
-
"consistent-return": "error",
|
|
97
|
-
"dot-notation": "error",
|
|
98
|
-
"eqeqeq": "error",
|
|
99
|
-
"no-eq-null": "error",
|
|
100
|
-
"no-implicit-coercion": "error",
|
|
101
|
-
"no-multi-spaces": "error",
|
|
102
|
-
"no-proto": "error",
|
|
103
|
-
"yoda": "error",
|
|
104
|
-
"indent": ["error", 2, { SwitchCase: 1 }],
|
|
105
|
-
"object-curly-spacing": ["error", "always"],
|
|
106
|
-
|
|
107
|
-
"object-curly-newline": ["error", {
|
|
108
|
-
consistent: true,
|
|
109
|
-
multiline: true,
|
|
110
|
-
}],
|
|
111
|
-
|
|
112
|
-
"space-before-blocks": "error",
|
|
113
|
-
"space-before-function-paren": ["error", "always"],
|
|
114
|
-
"spaced-comment": "error",
|
|
115
|
-
"no-whitespace-before-property": "error",
|
|
116
|
-
|
|
117
|
-
"brace-style": ["error", "1tbs", {
|
|
118
|
-
allowSingleLine: false,
|
|
119
|
-
}],
|
|
120
|
-
|
|
121
|
-
"eol-last": ["error", "always"],
|
|
122
|
-
"func-call-spacing": ["error", "never"],
|
|
123
|
-
"semi": ["error", "always"],
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
);
|
|
127
|
-
/* c8 ignore stop */
|