@neon-rs/manifest 0.0.2 → 0.0.4
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/lib/abstract.cjs +85 -0
- package/lib/abstract.d.cts +25 -0
- package/lib/cache/cache.cjs +2 -0
- package/lib/cache/cache.d.cts +9 -0
- package/lib/cache/npm/legacy.cjs +116 -0
- package/lib/cache/npm/legacy.d.cts +1 -0
- package/lib/cache/npm/manifest.cjs +76 -0
- package/lib/cache/npm/manifest.d.cts +26 -0
- package/lib/cache/npm/npm.cjs +136 -0
- package/lib/cache/npm/npm.d.cts +17 -0
- package/lib/cache/npm/package.cjs +114 -0
- package/lib/cache/npm/package.d.cts +19 -0
- package/lib/cache/npm.cjs +308 -0
- package/lib/cache/npm.d.cts +31 -0
- package/lib/cache.cjs +2 -0
- package/lib/cache.d.cts +5 -0
- package/lib/change.cjs +48 -0
- package/lib/change.d.cts +49 -0
- package/lib/index.cjs +3 -574
- package/lib/index.d.cts +1 -64
- package/lib/index.d.mts +1 -1
- package/lib/index.mjs +1 -1
- package/lib/library/legacy.cjs +110 -0
- package/lib/library/legacy.d.cts +1 -0
- package/lib/library/library.cjs +143 -0
- package/lib/library/library.d.cts +31 -0
- package/lib/library/neon.cjs +11 -0
- package/lib/library/neon.d.cts +4 -0
- package/lib/neon.cjs +11 -0
- package/lib/neon.d.cts +4 -0
- package/lib/platform.cjs +31 -3
- package/lib/platform.d.cts +3 -1
- package/lib/platform.d.mts +1 -1
- package/lib/platform.mjs +1 -1
- package/lib/util.cjs +92 -0
- package/lib/util.d.cts +25 -0
- package/package.json +22 -9
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeLibraryCfg = void 0;
|
|
4
|
+
const platform_cjs_1 = require("../platform.cjs");
|
|
5
|
+
const util_cjs_1 = require("../util.cjs");
|
|
6
|
+
const neon_cjs_1 = require("./neon.cjs");
|
|
7
|
+
function assertIsLibraryV1(json) {
|
|
8
|
+
(0, util_cjs_1.assertIsObject)(json, "neon");
|
|
9
|
+
for (const key in json) {
|
|
10
|
+
const value = json[key];
|
|
11
|
+
if (!(0, platform_cjs_1.isRustTarget)(key)) {
|
|
12
|
+
throw new TypeError(`target table key ${key} is not a valid Rust target`);
|
|
13
|
+
}
|
|
14
|
+
if (typeof value !== 'string') {
|
|
15
|
+
throw new TypeError(`target table value ${value} is not a string`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function normalizeLibraryCfg(json) {
|
|
20
|
+
(0, neon_cjs_1.assertHasNeonCfg)(json);
|
|
21
|
+
// V5 format: {
|
|
22
|
+
// type: 'library',
|
|
23
|
+
// org: string,
|
|
24
|
+
// platforms: PlatformFamily,
|
|
25
|
+
// load?: string | undefined
|
|
26
|
+
// }
|
|
27
|
+
if ('type' in json.neon && json.neon.type === 'library') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
// V4 format: {
|
|
31
|
+
// neon: {
|
|
32
|
+
// type: 'source',
|
|
33
|
+
// org: string,
|
|
34
|
+
// platforms: PlatformFamily,
|
|
35
|
+
// load?: string | undefined
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
if ('type' in json.neon && 'platforms' in json.neon) {
|
|
39
|
+
json.neon.type = 'library';
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
// V3 format: {
|
|
43
|
+
// neon: {
|
|
44
|
+
// type: 'source',
|
|
45
|
+
// org: string,
|
|
46
|
+
// targets: PlatformFamily
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
if ('type' in json.neon) {
|
|
50
|
+
const org = json.neon['org'];
|
|
51
|
+
const targets = json.neon['targets'];
|
|
52
|
+
(0, platform_cjs_1.assertIsPlatformFamily)(targets, "neon.targets");
|
|
53
|
+
json.neon = {
|
|
54
|
+
type: 'library',
|
|
55
|
+
org,
|
|
56
|
+
platforms: targets
|
|
57
|
+
};
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
// V2 format: {
|
|
61
|
+
// neon: {
|
|
62
|
+
// org: string,
|
|
63
|
+
// targets: { Node => Rust }
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
|
+
if ('org' in json.neon) {
|
|
67
|
+
const platforms = json.neon['targets'];
|
|
68
|
+
(0, platform_cjs_1.assertIsPlatformMap)(platforms, "neon.targets");
|
|
69
|
+
json.neon = {
|
|
70
|
+
type: 'library',
|
|
71
|
+
org: json.neon.org,
|
|
72
|
+
platforms
|
|
73
|
+
};
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
// V1 format: {
|
|
77
|
+
// neon: {
|
|
78
|
+
// targets: { Rust => fully-qualified package name }
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
const targets = json.neon['targets'];
|
|
82
|
+
assertIsLibraryV1(targets);
|
|
83
|
+
json.neon = upgradeLibraryV1(targets);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
exports.normalizeLibraryCfg = normalizeLibraryCfg;
|
|
87
|
+
function upgradeLibraryV1(object) {
|
|
88
|
+
function splitSwap([key, value]) {
|
|
89
|
+
if (!/^@.*\//.test(value)) {
|
|
90
|
+
throw new TypeError(`expected namespaced npm package name, found ${value}`);
|
|
91
|
+
}
|
|
92
|
+
const pkg = value.split('/')[1];
|
|
93
|
+
(0, platform_cjs_1.assertIsNodePlatform)(pkg);
|
|
94
|
+
(0, platform_cjs_1.assertIsRustTarget)(key);
|
|
95
|
+
return [pkg, key];
|
|
96
|
+
}
|
|
97
|
+
const entries = Object.entries(object).map(splitSwap);
|
|
98
|
+
const orgs = new Set(Object.values(object).map(v => v.split('/')[0]));
|
|
99
|
+
if (orgs.size === 0) {
|
|
100
|
+
throw new Error("empty target table");
|
|
101
|
+
}
|
|
102
|
+
else if (orgs.size > 1) {
|
|
103
|
+
throw new Error(`multiple npm orgs found: ${orgs}`);
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
type: 'library',
|
|
107
|
+
org: [...orgs][0],
|
|
108
|
+
platforms: Object.fromEntries(entries)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeLibraryCfg(json: object): boolean;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LibraryManifest = exports.SCHEMA_VERSION = void 0;
|
|
4
|
+
const platform_cjs_1 = require("../platform.cjs");
|
|
5
|
+
const neon_cjs_1 = require("./neon.cjs");
|
|
6
|
+
const util_cjs_1 = require("../util.cjs");
|
|
7
|
+
const legacy_cjs_1 = require("./legacy.cjs");
|
|
8
|
+
const npm_cjs_1 = require("../cache/npm/npm.cjs");
|
|
9
|
+
function assertIsLibraryCfg(json) {
|
|
10
|
+
(0, util_cjs_1.assertHasProps)(['type', 'org', 'platforms'], json, "neon");
|
|
11
|
+
if (json.type !== 'library') {
|
|
12
|
+
throw new TypeError(`expected "neon.type" property to be "library", found ${json.type}`);
|
|
13
|
+
}
|
|
14
|
+
if (typeof json.org !== 'string') {
|
|
15
|
+
throw new TypeError(`expected "neon.org" to be a string, found ${json.org}`);
|
|
16
|
+
}
|
|
17
|
+
(0, platform_cjs_1.assertIsPlatformFamily)(json.platforms, "neon.platforms");
|
|
18
|
+
if ('load' in json) {
|
|
19
|
+
if (typeof json.load !== 'string' && typeof json.load !== 'undefined') {
|
|
20
|
+
throw new TypeError(`expected "neon.load" to be a string, found ${json.load}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function assertHasLibraryCfg(json) {
|
|
25
|
+
(0, neon_cjs_1.assertHasNeonCfg)(json);
|
|
26
|
+
assertIsLibraryCfg(json.neon);
|
|
27
|
+
}
|
|
28
|
+
exports.SCHEMA_VERSION = 5;
|
|
29
|
+
// The source manifest is the source of truth for all Neon
|
|
30
|
+
// project metadata. This means you never need to go searching
|
|
31
|
+
// for any other files to query the Neon project's metadata.
|
|
32
|
+
// (Some data is replicated in the binary manifests, however,
|
|
33
|
+
// since they are independently published in npm.)
|
|
34
|
+
class LibraryManifest extends util_cjs_1.AbstractManifest {
|
|
35
|
+
constructor(dir, json) {
|
|
36
|
+
super(json);
|
|
37
|
+
this.dir = dir;
|
|
38
|
+
this._normalized = (0, legacy_cjs_1.normalizeLibraryCfg)(this._json);
|
|
39
|
+
this._updatedPlatforms = false;
|
|
40
|
+
assertHasLibraryCfg(this._json);
|
|
41
|
+
this._sourceJSON = this._json;
|
|
42
|
+
this._expandedPlatforms = (0, platform_cjs_1.expandPlatformFamily)(this._sourceJSON.neon.platforms);
|
|
43
|
+
this._cacheCfg = ('org' in this._sourceJSON.neon) ? new npm_cjs_1.NPMCacheCfg(this) : null;
|
|
44
|
+
}
|
|
45
|
+
hasUnsavedChanges() {
|
|
46
|
+
return this._normalized ||
|
|
47
|
+
this._updatedPlatforms ||
|
|
48
|
+
!!(this._cacheCfg && this._cacheCfg.hasUnsavedChanges());
|
|
49
|
+
}
|
|
50
|
+
static async load(dir = process.cwd()) {
|
|
51
|
+
return new LibraryManifest(dir, await (0, util_cjs_1.readManifest)(dir));
|
|
52
|
+
}
|
|
53
|
+
async saveChanges(log) {
|
|
54
|
+
if (!this.hasUnsavedChanges()) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
await this.save(log);
|
|
58
|
+
if (this._cacheCfg) {
|
|
59
|
+
await this._cacheCfg.saveChanges(log);
|
|
60
|
+
}
|
|
61
|
+
this._normalized = false;
|
|
62
|
+
this._updatedPlatforms = false;
|
|
63
|
+
}
|
|
64
|
+
get preamble() {
|
|
65
|
+
return this._json;
|
|
66
|
+
}
|
|
67
|
+
cfg() {
|
|
68
|
+
return this._sourceJSON.neon;
|
|
69
|
+
}
|
|
70
|
+
allPlatforms() {
|
|
71
|
+
return this._expandedPlatforms;
|
|
72
|
+
}
|
|
73
|
+
async addTargetPair(pair) {
|
|
74
|
+
const { node, rust } = pair;
|
|
75
|
+
if (this._expandedPlatforms[node] === rust) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this._expandedPlatforms[node] = rust;
|
|
79
|
+
if (this._cacheCfg) {
|
|
80
|
+
this._cacheCfg.setPlatformTarget(node, rust);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async addNodePlatform(platform) {
|
|
84
|
+
const targets = (0, platform_cjs_1.node2Rust)(platform);
|
|
85
|
+
if (targets.length > 1) {
|
|
86
|
+
throw new Error(`multiple Rust targets found for Node platform ${platform}; please specify one of ${targets.join(', ')}`);
|
|
87
|
+
}
|
|
88
|
+
await this.addTargetPair({ node: platform, rust: targets[0] });
|
|
89
|
+
}
|
|
90
|
+
async addRustTarget(target) {
|
|
91
|
+
await this.addTargetPair({ node: (0, platform_cjs_1.rust2Node)(target), rust: target });
|
|
92
|
+
}
|
|
93
|
+
filterChanges(family) {
|
|
94
|
+
let changes = Object.create(null);
|
|
95
|
+
for (const [key, value] of Object.entries(family)) {
|
|
96
|
+
const node = key;
|
|
97
|
+
const rust = value;
|
|
98
|
+
if (this._expandedPlatforms[node] === rust) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
changes[node] = rust;
|
|
102
|
+
}
|
|
103
|
+
return changes;
|
|
104
|
+
}
|
|
105
|
+
async addPlatforms(map) {
|
|
106
|
+
let changes = this.filterChanges(map);
|
|
107
|
+
for (const [key, value] of Object.entries(changes)) {
|
|
108
|
+
const node = key;
|
|
109
|
+
const rust = value;
|
|
110
|
+
if (this._cacheCfg) {
|
|
111
|
+
await this._cacheCfg.setPlatformTarget(node, rust);
|
|
112
|
+
}
|
|
113
|
+
this._expandedPlatforms[node] = rust;
|
|
114
|
+
}
|
|
115
|
+
return changes;
|
|
116
|
+
}
|
|
117
|
+
async addPlatformPreset(preset) {
|
|
118
|
+
const platformsSrc = this.cfg().platforms;
|
|
119
|
+
if (typeof platformsSrc === 'string') {
|
|
120
|
+
this.cfg().platforms = [platformsSrc, preset];
|
|
121
|
+
await this.addPlatforms((0, platform_cjs_1.expandPlatformFamily)(preset));
|
|
122
|
+
}
|
|
123
|
+
else if (Array.isArray(platformsSrc)) {
|
|
124
|
+
platformsSrc.push(preset);
|
|
125
|
+
await this.addPlatforms((0, platform_cjs_1.expandPlatformFamily)(preset));
|
|
126
|
+
}
|
|
127
|
+
// Edge case: an empty object can be treated like an empty array
|
|
128
|
+
else if (Object.keys(platformsSrc).length === 0) {
|
|
129
|
+
this.cfg().platforms = [];
|
|
130
|
+
await this.addPlatformPreset(preset);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const added = await this.addPlatforms((0, platform_cjs_1.expandPlatformFamily)(preset));
|
|
134
|
+
Object.assign(platformsSrc, added);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
updatePlatforms() {
|
|
138
|
+
if (this._cacheCfg && this._cacheCfg.updatePlatforms(this)) {
|
|
139
|
+
this._updatedPlatforms = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.LibraryManifest = LibraryManifest;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PlatformFamily, PlatformMap, PlatformPreset, NodePlatform, RustTarget, TargetPair } from "../platform.cjs";
|
|
2
|
+
import { AbstractManifest, Preamble } from "../util.cjs";
|
|
3
|
+
export interface LibraryCfg {
|
|
4
|
+
type: "library";
|
|
5
|
+
org: string;
|
|
6
|
+
platforms: PlatformFamily;
|
|
7
|
+
load?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const SCHEMA_VERSION = 5;
|
|
10
|
+
export declare class LibraryManifest extends AbstractManifest {
|
|
11
|
+
private _sourceJSON;
|
|
12
|
+
private _expandedPlatforms;
|
|
13
|
+
private _cacheCfg;
|
|
14
|
+
private _normalized;
|
|
15
|
+
private _updatedPlatforms;
|
|
16
|
+
readonly dir: string;
|
|
17
|
+
constructor(dir: string, json: Preamble);
|
|
18
|
+
hasUnsavedChanges(): boolean;
|
|
19
|
+
static load(dir?: string): Promise<LibraryManifest>;
|
|
20
|
+
saveChanges(log: (msg: string) => void): Promise<void>;
|
|
21
|
+
get preamble(): Preamble;
|
|
22
|
+
cfg(): LibraryCfg;
|
|
23
|
+
allPlatforms(): PlatformMap;
|
|
24
|
+
addTargetPair(pair: TargetPair): Promise<void>;
|
|
25
|
+
addNodePlatform(platform: NodePlatform): Promise<void>;
|
|
26
|
+
addRustTarget(target: RustTarget): Promise<void>;
|
|
27
|
+
private filterChanges;
|
|
28
|
+
private addPlatforms;
|
|
29
|
+
addPlatformPreset(preset: PlatformPreset): Promise<void>;
|
|
30
|
+
updatePlatforms(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertHasNeonCfg = void 0;
|
|
4
|
+
const util_cjs_1 = require("../util.cjs");
|
|
5
|
+
function assertHasNeonCfg(json) {
|
|
6
|
+
if (!('neon' in json)) {
|
|
7
|
+
throw new TypeError('property "neon" not found');
|
|
8
|
+
}
|
|
9
|
+
(0, util_cjs_1.assertIsObject)(json.neon, "neon");
|
|
10
|
+
}
|
|
11
|
+
exports.assertHasNeonCfg = assertHasNeonCfg;
|
package/lib/neon.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertHasNeonCfg = void 0;
|
|
4
|
+
const util_cjs_1 = require("./util.cjs");
|
|
5
|
+
function assertHasNeonCfg(json) {
|
|
6
|
+
if (!('neon' in json)) {
|
|
7
|
+
throw new TypeError('property "neon" not found');
|
|
8
|
+
}
|
|
9
|
+
(0, util_cjs_1.assertIsObject)(json.neon, "neon");
|
|
10
|
+
}
|
|
11
|
+
exports.assertHasNeonCfg = assertHasNeonCfg;
|
package/lib/neon.d.cts
ADDED
package/lib/platform.cjs
CHANGED
|
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.rust2Node = exports.node2Rust = exports.
|
|
6
|
+
exports.rust2Node = exports.node2Rust = exports.describeTarget = exports.expandPlatformFamily = exports.expandPlatformPreset = exports.assertIsPlatformFamily = exports.assertIsPlatformMap = exports.assertIsPlatformPreset = exports.isPlatformPreset = exports.assertIsNodePlatform = exports.isNodePlatform = exports.assertIsRustTarget = exports.isRustTarget = void 0;
|
|
7
7
|
const rust_json_1 = __importDefault(require("../data/rust.json"));
|
|
8
8
|
const node_json_1 = __importDefault(require("../data/node.json"));
|
|
9
9
|
const preset_json_1 = __importDefault(require("../data/preset.json"));
|
|
10
|
+
const util_cjs_1 = require("./util.cjs");
|
|
10
11
|
function isRustTarget(x) {
|
|
11
12
|
return (typeof x === 'string') && (x in rust_json_1.default);
|
|
12
13
|
}
|
|
@@ -37,6 +38,33 @@ function assertIsPlatformPreset(x) {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
exports.assertIsPlatformPreset = assertIsPlatformPreset;
|
|
41
|
+
function assertIsPlatformMap(json, path) {
|
|
42
|
+
(0, util_cjs_1.assertIsObject)(json, path);
|
|
43
|
+
for (const key in json) {
|
|
44
|
+
const value = json[key];
|
|
45
|
+
if (!isNodePlatform(key)) {
|
|
46
|
+
throw new TypeError(`platform table key ${key} is not a valid Node platform`);
|
|
47
|
+
}
|
|
48
|
+
if (typeof value !== 'string' || !isRustTarget(value)) {
|
|
49
|
+
throw new TypeError(`platform table value ${value} is not a valid Rust target`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.assertIsPlatformMap = assertIsPlatformMap;
|
|
54
|
+
function assertIsPlatformFamily(json, path) {
|
|
55
|
+
if (typeof json === 'string') {
|
|
56
|
+
assertIsPlatformPreset(json);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(json)) {
|
|
60
|
+
for (const elt of json) {
|
|
61
|
+
assertIsPlatformPreset(elt);
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
assertIsPlatformMap(json, path);
|
|
66
|
+
}
|
|
67
|
+
exports.assertIsPlatformFamily = assertIsPlatformFamily;
|
|
40
68
|
function lookupPlatformPreset(key) {
|
|
41
69
|
return preset_json_1.default[key];
|
|
42
70
|
}
|
|
@@ -59,7 +87,7 @@ function expandPlatformFamily(family) {
|
|
|
59
87
|
: family;
|
|
60
88
|
}
|
|
61
89
|
exports.expandPlatformFamily = expandPlatformFamily;
|
|
62
|
-
function
|
|
90
|
+
function describeTarget(target) {
|
|
63
91
|
const node = rust_json_1.default[target];
|
|
64
92
|
if (!isNodePlatform(node)) {
|
|
65
93
|
throw new Error(`Rust target ${target} not supported`);
|
|
@@ -77,7 +105,7 @@ function getTargetDescriptor(target) {
|
|
|
77
105
|
llvm: nodeDescriptor.llvm
|
|
78
106
|
};
|
|
79
107
|
}
|
|
80
|
-
exports.
|
|
108
|
+
exports.describeTarget = describeTarget;
|
|
81
109
|
function node2Rust(target) {
|
|
82
110
|
return node_json_1.default[target].llvm.map(rt => {
|
|
83
111
|
assertIsRustTarget(rt);
|
package/lib/platform.d.cts
CHANGED
|
@@ -10,6 +10,8 @@ export declare function assertIsNodePlatform(x: unknown): asserts x is NodePlatf
|
|
|
10
10
|
export type PlatformPreset = keyof (typeof PRESET);
|
|
11
11
|
export declare function isPlatformPreset(x: unknown): x is PlatformPreset;
|
|
12
12
|
export declare function assertIsPlatformPreset(x: unknown): asserts x is PlatformPreset;
|
|
13
|
+
export declare function assertIsPlatformMap(json: unknown, path: string): asserts json is PlatformMap;
|
|
14
|
+
export declare function assertIsPlatformFamily(json: unknown, path: string): asserts json is PlatformFamily;
|
|
13
15
|
export type TargetPair = {
|
|
14
16
|
node: NodePlatform;
|
|
15
17
|
rust: RustTarget;
|
|
@@ -27,6 +29,6 @@ export type PlatformDescriptor = {
|
|
|
27
29
|
abi: string | null;
|
|
28
30
|
llvm: RustTarget[];
|
|
29
31
|
};
|
|
30
|
-
export declare function
|
|
32
|
+
export declare function describeTarget(target: RustTarget): PlatformDescriptor;
|
|
31
33
|
export declare function node2Rust(target: NodePlatform): RustTarget[];
|
|
32
34
|
export declare function rust2Node(target: RustTarget): NodePlatform;
|
package/lib/platform.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { RustTarget, isRustTarget, assertIsRustTarget, NodePlatform, isNodePlatform, assertIsNodePlatform, PlatformPreset, isPlatformPreset, assertIsPlatformPreset, TargetPair, PlatformMap, PlatformFamily, expandPlatformPreset, expandPlatformFamily, PlatformDescriptor,
|
|
1
|
+
export { RustTarget, isRustTarget, assertIsRustTarget, NodePlatform, isNodePlatform, assertIsNodePlatform, PlatformPreset, isPlatformPreset, assertIsPlatformPreset, TargetPair, PlatformMap, assertIsPlatformMap, PlatformFamily, assertIsPlatformFamily, expandPlatformPreset, expandPlatformFamily, PlatformDescriptor, describeTarget, node2Rust, rust2Node } from './platform.cjs';
|
package/lib/platform.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { isRustTarget, assertIsRustTarget, isNodePlatform, assertIsNodePlatform, isPlatformPreset, assertIsPlatformPreset, expandPlatformPreset, expandPlatformFamily,
|
|
1
|
+
export { isRustTarget, assertIsRustTarget, isNodePlatform, assertIsNodePlatform, isPlatformPreset, assertIsPlatformPreset, assertIsPlatformMap, assertIsPlatformFamily, expandPlatformPreset, expandPlatformFamily, describeTarget, node2Rust, rust2Node } from './platform.cjs';
|
package/lib/util.cjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.AbstractManifest = exports.readManifest = exports.assertHasProps = exports.assertIsObject = void 0;
|
|
27
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
28
|
+
const path = __importStar(require("node:path"));
|
|
29
|
+
function assertIsObject(json, path) {
|
|
30
|
+
if (!json || typeof json !== 'object') {
|
|
31
|
+
throw new TypeError(`expected "${path}" property to be an object, found ${json}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.assertIsObject = assertIsObject;
|
|
35
|
+
// Idea thanks to https://www.lucaspaganini.com/academy/assertion-functions-typescript-narrowing-5
|
|
36
|
+
function assertHasProps(keys, json, path) {
|
|
37
|
+
assertIsObject(json, path);
|
|
38
|
+
for (const key of keys) {
|
|
39
|
+
if (!(key in json)) {
|
|
40
|
+
throw new TypeError(`property "${path}.${key}" not found`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.assertHasProps = assertHasProps;
|
|
45
|
+
async function readManifest(dir) {
|
|
46
|
+
dir = dir ?? process.cwd();
|
|
47
|
+
const json = JSON.parse(await fs.readFile(path.join(dir, "package.json"), { encoding: 'utf8' }));
|
|
48
|
+
assertIsPreamble(json);
|
|
49
|
+
return json;
|
|
50
|
+
}
|
|
51
|
+
exports.readManifest = readManifest;
|
|
52
|
+
function assertIsPreamble(json) {
|
|
53
|
+
if (!json || typeof json !== 'object' || Array.isArray(json)) {
|
|
54
|
+
throw new TypeError(`expected Neon package manifest, found ${json}`);
|
|
55
|
+
}
|
|
56
|
+
if (!('version' in json) || typeof json.version !== 'string') {
|
|
57
|
+
throw new TypeError('valid "version" string not found in Neon package manifest');
|
|
58
|
+
}
|
|
59
|
+
if (!('name' in json) || typeof json.name !== 'string') {
|
|
60
|
+
throw new TypeError('valid "name" string not found in Neon package manifest');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const OPTIONAL_KEYS = [
|
|
64
|
+
'author', 'repository', 'keywords', 'bugs', 'homepage', 'license', 'engines'
|
|
65
|
+
];
|
|
66
|
+
class AbstractManifest {
|
|
67
|
+
constructor(json) {
|
|
68
|
+
this._json = json;
|
|
69
|
+
}
|
|
70
|
+
get name() { return this._json.name; }
|
|
71
|
+
set name(value) { this._json.name = value; }
|
|
72
|
+
get version() { return this._json.version; }
|
|
73
|
+
set version(value) { this._json.version = value; }
|
|
74
|
+
get description() { return this._json.description ?? ""; }
|
|
75
|
+
async save(log) {
|
|
76
|
+
await fs.writeFile(path.join(this.dir, "package.json"), JSON.stringify(this._json, null, 2), { encoding: 'utf8' });
|
|
77
|
+
}
|
|
78
|
+
stringify() {
|
|
79
|
+
return JSON.stringify(this._json);
|
|
80
|
+
}
|
|
81
|
+
toJSON() {
|
|
82
|
+
return JSON.parse(JSON.stringify(this._json));
|
|
83
|
+
}
|
|
84
|
+
copyOptionalKeys(target) {
|
|
85
|
+
for (const key of OPTIONAL_KEYS) {
|
|
86
|
+
if (key in this._json) {
|
|
87
|
+
target[key] = this._json[key];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.AbstractManifest = AbstractManifest;
|
package/lib/util.d.cts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare function assertIsObject(json: unknown, path: string): asserts json is object;
|
|
2
|
+
export declare function assertHasProps<K extends string>(keys: ReadonlyArray<K>, json: unknown, path: string): asserts json is Record<K, unknown>;
|
|
3
|
+
export declare function readManifest(dir?: string | undefined): Promise<Preamble>;
|
|
4
|
+
export type Preamble = {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
optionalDependencies?: Record<string, string> | undefined;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
export declare abstract class AbstractManifest {
|
|
11
|
+
protected _json: Preamble;
|
|
12
|
+
abstract readonly dir: string;
|
|
13
|
+
constructor(json: Preamble);
|
|
14
|
+
get name(): string;
|
|
15
|
+
set name(value: string);
|
|
16
|
+
get version(): string;
|
|
17
|
+
set version(value: string);
|
|
18
|
+
get description(): string;
|
|
19
|
+
save(log: (msg: string) => void): Promise<void>;
|
|
20
|
+
stringify(): string;
|
|
21
|
+
toJSON(): unknown;
|
|
22
|
+
copyOptionalKeys(target: {
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}): void;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neon-rs/manifest",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"description": "",
|
|
4
|
+
"version": "0.0.4",
|
|
5
|
+
"description": "Library for working with Neon package configuration.",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"import": {
|
|
@@ -13,22 +13,30 @@
|
|
|
13
13
|
"types": "./lib/index.d.cts",
|
|
14
14
|
"default": "./lib/index.cjs"
|
|
15
15
|
}
|
|
16
|
+
},
|
|
17
|
+
"./platform": {
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./lib/platform.d.mts",
|
|
20
|
+
"default": "./lib/platform.mjs"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./lib/platform.d.cts",
|
|
24
|
+
"default": "./lib/platform.cjs"
|
|
25
|
+
}
|
|
16
26
|
}
|
|
17
27
|
},
|
|
18
28
|
"types": "./lib/index.d.cts",
|
|
19
29
|
"main": "./lib/index.cjs",
|
|
20
30
|
"files": [
|
|
21
|
-
"lib
|
|
22
|
-
"lib
|
|
23
|
-
"lib/**/*.mjs",
|
|
24
|
-
"lib/**/*.d.mts",
|
|
25
|
-
"lib/**/*.js",
|
|
26
|
-
"lib/**/*.d.ts",
|
|
31
|
+
"lib/*.?({c,m}){t,j}s",
|
|
32
|
+
"lib/!(test)/**/*",
|
|
27
33
|
"data/**/*.json"
|
|
28
34
|
],
|
|
29
35
|
"scripts": {
|
|
30
36
|
"dist": "tsc",
|
|
31
|
-
"
|
|
37
|
+
"pretest": "npm run dist",
|
|
38
|
+
"test": "mocha",
|
|
39
|
+
"prepack": "npm run dist"
|
|
32
40
|
},
|
|
33
41
|
"keywords": [
|
|
34
42
|
"Neon",
|
|
@@ -43,8 +51,13 @@
|
|
|
43
51
|
"homepage": "https://github.com/dherman/neon-rs#readme",
|
|
44
52
|
"devDependencies": {
|
|
45
53
|
"@tsconfig/node16": "^16.1.1",
|
|
54
|
+
"@types/chai": "^4.3.12",
|
|
46
55
|
"@types/jscodeshift": "^0.11.11",
|
|
56
|
+
"@types/mocha": "^10.0.6",
|
|
47
57
|
"@types/node": "^20.11.10",
|
|
58
|
+
"chai": "^4.4.1",
|
|
59
|
+
"create-temp-directory": "^2.4.0",
|
|
60
|
+
"mocha": "^10.3.0",
|
|
48
61
|
"typescript": "^5.3.3"
|
|
49
62
|
},
|
|
50
63
|
"dependencies": {
|