napi-postinstall 0.1.0
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/LICENSE +21 -0
- package/README.md +130 -0
- package/lib/cli.d.ts +2 -0
- package/lib/cli.js +6 -0
- package/lib/cli.js.map +1 -0
- package/lib/constants.d.ts +3 -0
- package/lib/constants.js +10 -0
- package/lib/constants.js.map +1 -0
- package/lib/helpers.d.ts +11 -0
- package/lib/helpers.js +222 -0
- package/lib/helpers.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +154 -0
- package/lib/index.js.map +1 -0
- package/lib/target.d.ts +10 -0
- package/lib/target.js +56 -0
- package/lib/target.js.map +1 -0
- package/lib/types.d.ts +28 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/package.json +29 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021-present UnTS
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# napi-postinstall
|
2
|
+
|
3
|
+
[](https://github.com/un-ts/napi-postinstall/actions/workflows/ci.yml?query=branch%3Amain)
|
4
|
+
[](https://codecov.io/gh/un-ts/napi-postinstall)
|
5
|
+
[](https://github.com/plantain-00/type-coverage)
|
6
|
+
[](https://coderabbit.ai)
|
7
|
+
[](https://www.npmjs.com/package/napi-postinstall)
|
8
|
+
[](https://github.com/un-ts/napi-postinstall/releases)
|
9
|
+
|
10
|
+
[](https://conventionalcommits.org)
|
11
|
+
[](https://renovatebot.com)
|
12
|
+
[](https://standardjs.com)
|
13
|
+
[](https://github.com/prettier/prettier)
|
14
|
+
[](https://github.com/changesets/changesets)
|
15
|
+
|
16
|
+
The `postinstall` script helper for handling native bindings in legacy `npm` versions, this is a reimplementation of the [`node-install`][node-install] functionality from [`esbuild`][esbuild] for [`napi-rs`][napi-rs] ecosystem packages like [`rollup`][rollup], [`@swc/core`][swc-core] and [`unrs-resolver`][unrs-resolver].
|
17
|
+
|
18
|
+
For more details, please refer to the following issues:
|
19
|
+
|
20
|
+
- [npm/cli#4828](https://github.com/npm/cli/issues/4828) -- root cause
|
21
|
+
- [napi-rs/napi-rs#2569](https://github.com/napi-rs/napi-rs/issues/2569)
|
22
|
+
- [unrs/unrs-resolver#56](https://github.com/unrs/unrs-resolver/issues/56)
|
23
|
+
|
24
|
+
## TOC <!-- omit in toc -->
|
25
|
+
|
26
|
+
- [Usage](#usage)
|
27
|
+
- [Install](#install)
|
28
|
+
- [CLI](#cli)
|
29
|
+
- [API](#api)
|
30
|
+
- [Types](#types)
|
31
|
+
- [Example](#example)
|
32
|
+
- [Sponsors and Backers](#sponsors-and-backers)
|
33
|
+
- [Sponsors](#sponsors)
|
34
|
+
- [Backers](#backers)
|
35
|
+
- [Changelog](#changelog)
|
36
|
+
- [License](#license)
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
### Install
|
41
|
+
|
42
|
+
```sh
|
43
|
+
# pnpm
|
44
|
+
pnpm add napi-postinstall
|
45
|
+
|
46
|
+
# yarn
|
47
|
+
yarn add napi-postinstall
|
48
|
+
|
49
|
+
# npm
|
50
|
+
npm i napi-postinstall
|
51
|
+
|
52
|
+
# bun
|
53
|
+
bun add napi-postinstall
|
54
|
+
```
|
55
|
+
|
56
|
+
### CLI
|
57
|
+
|
58
|
+
```sh
|
59
|
+
napi-postinstall unrs-resolver #<napi-package-name>
|
60
|
+
```
|
61
|
+
|
62
|
+
You can put it into `scripts#postinstall` of your `package.json`:
|
63
|
+
|
64
|
+
```json
|
65
|
+
{
|
66
|
+
"scripts": {
|
67
|
+
"postinstall": "napi-postinstall unrs-resolver"
|
68
|
+
}
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
This will check and prepare the napi binding packages for you automatically.
|
73
|
+
|
74
|
+
### API
|
75
|
+
|
76
|
+
#### Types
|
77
|
+
|
78
|
+
```ts
|
79
|
+
export interface PackageJson {
|
80
|
+
name: string
|
81
|
+
version: string
|
82
|
+
}
|
83
|
+
|
84
|
+
export declare function checkAndPreparePackage(
|
85
|
+
packageNameOrPackageJson: PackageJson | string,
|
86
|
+
checkVersion?: boolean,
|
87
|
+
): Promise<void>
|
88
|
+
```
|
89
|
+
|
90
|
+
#### Example
|
91
|
+
|
92
|
+
```js
|
93
|
+
import { checkAndPreparePackage } from 'napi-postinstall'
|
94
|
+
|
95
|
+
checkAndPreparePackage('unrs-resolver' /* <napi-package-name> */)
|
96
|
+
```
|
97
|
+
|
98
|
+
## Sponsors and Backers
|
99
|
+
|
100
|
+
[](https://github.com/sponsors/JounQin)
|
101
|
+
|
102
|
+
### Sponsors
|
103
|
+
|
104
|
+
| 1stG | RxTS | UnTS |
|
105
|
+
| ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
106
|
+
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
|
107
|
+
|
108
|
+
### Backers
|
109
|
+
|
110
|
+
| 1stG | RxTS | UnTS |
|
111
|
+
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
112
|
+
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
|
113
|
+
|
114
|
+
## Changelog
|
115
|
+
|
116
|
+
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
|
117
|
+
|
118
|
+
## License
|
119
|
+
|
120
|
+
[MIT][] © [JounQin][]@[1stG.me][]
|
121
|
+
|
122
|
+
[node-install]: https://github.com/evanw/esbuild/blob/4475787eef4c4923b92b9fa37ebba1c88b9e1d9b/lib/npm/node-install.ts
|
123
|
+
[esbuild]: https://github.com/evanw/esbuild
|
124
|
+
[napi-rs]: https://github.com/napi-rs/napi-rs
|
125
|
+
[rollup]: https://github.com/rollup/rollup
|
126
|
+
[swc-core]: https://github.com/swc-project/swc
|
127
|
+
[unrs-resolver]: https://github.com/unrs/unrs-resolver
|
128
|
+
[1stG.me]: https://www.1stG.me
|
129
|
+
[JounQin]: https://GitHub.com/JounQin
|
130
|
+
[MIT]: http://opensource.org/licenses/MIT
|
package/lib/cli.d.ts
ADDED
package/lib/cli.js
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
const index_js_1 = require("./index.js");
|
5
|
+
void (0, index_js_1.checkAndPreparePackage)(process.argv[2], ['1', 'check', 'true', 'yes'].includes(process.argv[3]));
|
6
|
+
//# sourceMappingURL=cli.js.map
|
package/lib/cli.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,yCAAmD;AAEnD,KAAK,IAAA,iCAAsB,EACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EACf,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CACxD,CAAA"}
|
package/lib/constants.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
var _a;
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.LOG_PREFIX = exports.version = exports.name = exports.DEFAULT_NPM_REGISTRY = void 0;
|
5
|
+
const tslib_1 = require("tslib");
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
7
|
+
exports.DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org/';
|
8
|
+
_a = require(node_path_1.default.resolve(__dirname, '../package.json')), exports.name = _a.name, exports.version = _a.version;
|
9
|
+
exports.LOG_PREFIX = `[${exports.name}@${exports.version}] `;
|
10
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;;;AAAA,kEAA4B;AAIf,QAAA,oBAAoB,GAAG,6BAA6B,CAAA;AAEpD,KAAoB,OAAO,CACtC,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAC5B,EAFD,YAAI,YAAE,eAAO,cAEZ;AAEH,QAAA,UAAU,GAAG,IAAI,YAAI,IAAI,eAAO,IAAI,CAAA"}
|
package/lib/helpers.d.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
import { NapiInfo, PackageJson } from './types.js';
|
2
|
+
export declare function getGlobalNpmRegistry(): string;
|
3
|
+
export declare function removeRecursive(dir: string): void;
|
4
|
+
export declare function downloadedNodePath(name: string, subpath: string): string;
|
5
|
+
export declare function getNapiInfoFromPackageJson(packageJson: PackageJson, checkVersion: true): NapiInfo;
|
6
|
+
export declare function getNapiInfoFromPackageJson(packageJson: PackageJson, checkVersion?: boolean): NapiInfo & {
|
7
|
+
version?: string;
|
8
|
+
};
|
9
|
+
export declare function getNapiNativeTarget(): string[] | string;
|
10
|
+
export declare function getNapiNativeTargets(): string[];
|
11
|
+
export declare function getErrorMessage(err: unknown): string;
|
package/lib/helpers.js
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getGlobalNpmRegistry = getGlobalNpmRegistry;
|
4
|
+
exports.removeRecursive = removeRecursive;
|
5
|
+
exports.downloadedNodePath = downloadedNodePath;
|
6
|
+
exports.getNapiInfoFromPackageJson = getNapiInfoFromPackageJson;
|
7
|
+
exports.getNapiNativeTarget = getNapiNativeTarget;
|
8
|
+
exports.getNapiNativeTargets = getNapiNativeTargets;
|
9
|
+
exports.getErrorMessage = getErrorMessage;
|
10
|
+
const tslib_1 = require("tslib");
|
11
|
+
const node_child_process_1 = require("node:child_process");
|
12
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
13
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
14
|
+
const constants_js_1 = require("./constants.js");
|
15
|
+
const target_js_1 = require("./target.js");
|
16
|
+
function getGlobalNpmRegistry() {
|
17
|
+
try {
|
18
|
+
const registry = (0, node_child_process_1.execSync)('npm config get registry', {
|
19
|
+
encoding: 'utf8',
|
20
|
+
}).trim();
|
21
|
+
return registry.endsWith('/') ? registry : `${registry}/`;
|
22
|
+
}
|
23
|
+
catch (_a) {
|
24
|
+
return constants_js_1.DEFAULT_NPM_REGISTRY;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
function removeRecursive(dir) {
|
28
|
+
for (const entry of node_fs_1.default.readdirSync(dir)) {
|
29
|
+
const entryPath = node_path_1.default.join(dir, entry);
|
30
|
+
let stats;
|
31
|
+
try {
|
32
|
+
stats = node_fs_1.default.lstatSync(entryPath);
|
33
|
+
}
|
34
|
+
catch (_a) {
|
35
|
+
continue;
|
36
|
+
}
|
37
|
+
if (stats.isDirectory()) {
|
38
|
+
removeRecursive(entryPath);
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
node_fs_1.default.unlinkSync(entryPath);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
node_fs_1.default.rmdirSync(dir);
|
45
|
+
}
|
46
|
+
function downloadedNodePath(name, subpath) {
|
47
|
+
const pkgLibDir = node_path_1.default.dirname(require.resolve(name + '/package.json'));
|
48
|
+
return node_path_1.default.join(pkgLibDir, `${node_path_1.default.basename(subpath)}`);
|
49
|
+
}
|
50
|
+
function getNapiInfoFromPackageJson(packageJson, checkVersion) {
|
51
|
+
var _a, _b, _c, _d, _e, _f;
|
52
|
+
const { name, napi: napi_, optionalDependencies } = packageJson;
|
53
|
+
const targets = (_a = napi_ === null || napi_ === void 0 ? void 0 : napi_.targets) !== null && _a !== void 0 ? _a : (_b = napi_ === null || napi_ === void 0 ? void 0 : napi_.triples) === null || _b === void 0 ? void 0 : _b.additional;
|
54
|
+
if (!(targets === null || targets === void 0 ? void 0 : targets.length) || !optionalDependencies) {
|
55
|
+
throw new Error(`No \`napi.targets\` nor \`optionalDependencies\` field found in \`${name}\`'s \`package.json\`. Please ensure the package is built with NAPI support.`);
|
56
|
+
}
|
57
|
+
const napi = napi_;
|
58
|
+
napi.targets = targets;
|
59
|
+
let version;
|
60
|
+
for (const target of targets) {
|
61
|
+
const { platformArchABI } = (0, target_js_1.parseTriple)(target);
|
62
|
+
(_c = napi.binaryName) !== null && _c !== void 0 ? _c : (napi.binaryName = napi.name);
|
63
|
+
(_d = napi.packageName) !== null && _d !== void 0 ? _d : (napi.packageName = (_f = (_e = napi.package) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : name);
|
64
|
+
const pkg = `${napi.packageName}-${platformArchABI}`;
|
65
|
+
const packageVersion = optionalDependencies[pkg];
|
66
|
+
if (checkVersion && !packageVersion) {
|
67
|
+
throw new Error(`No version found for \`${name}\` with \`${pkg}\`.`);
|
68
|
+
}
|
69
|
+
if (version) {
|
70
|
+
if (version !== packageVersion) {
|
71
|
+
throw new Error(`Inconsistent package versions found for \`${name}\` with \`${pkg}\` v${packageVersion} vs v${version}.`);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
else if (packageVersion) {
|
75
|
+
version = packageVersion;
|
76
|
+
if (!checkVersion) {
|
77
|
+
break;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
return { napi, version };
|
82
|
+
}
|
83
|
+
function isMusl() {
|
84
|
+
let musl = false;
|
85
|
+
if (process.platform === 'linux') {
|
86
|
+
musl = isMuslFromFilesystem();
|
87
|
+
if (musl === null) {
|
88
|
+
musl = isMuslFromReport();
|
89
|
+
}
|
90
|
+
if (musl === null) {
|
91
|
+
musl = isMuslFromChildProcess();
|
92
|
+
}
|
93
|
+
}
|
94
|
+
return musl;
|
95
|
+
}
|
96
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-');
|
97
|
+
function isMuslFromFilesystem() {
|
98
|
+
try {
|
99
|
+
return node_fs_1.default.readFileSync('/usr/bin/ldd', 'utf8').includes('musl');
|
100
|
+
}
|
101
|
+
catch (_a) {
|
102
|
+
return null;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
function isMuslFromReport() {
|
106
|
+
let report = null;
|
107
|
+
if (typeof process.report.getReport === 'function') {
|
108
|
+
process.report.excludeNetwork = true;
|
109
|
+
report = process.report.getReport();
|
110
|
+
}
|
111
|
+
if (!report) {
|
112
|
+
return null;
|
113
|
+
}
|
114
|
+
if ('header' in report &&
|
115
|
+
report.header != null &&
|
116
|
+
typeof report.header === 'object' &&
|
117
|
+
'glibcVersionRuntime' in report.header &&
|
118
|
+
report.header.glibcVersionRuntime) {
|
119
|
+
return false;
|
120
|
+
}
|
121
|
+
return ('sharedObjects' in report &&
|
122
|
+
Array.isArray(report.sharedObjects) &&
|
123
|
+
report.sharedObjects.some(isFileMusl));
|
124
|
+
}
|
125
|
+
function isMuslFromChildProcess() {
|
126
|
+
try {
|
127
|
+
return (0, node_child_process_1.execSync)('ldd --version', { encoding: 'utf8' }).includes('musl');
|
128
|
+
}
|
129
|
+
catch (_a) {
|
130
|
+
return false;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
function getNapiNativeTarget() {
|
134
|
+
switch (process.platform) {
|
135
|
+
case 'android': {
|
136
|
+
if (process.arch === 'arm64') {
|
137
|
+
return 'android-arm64';
|
138
|
+
}
|
139
|
+
if (process.arch === 'arm') {
|
140
|
+
return 'android-arm-eabi';
|
141
|
+
}
|
142
|
+
break;
|
143
|
+
}
|
144
|
+
case 'win32': {
|
145
|
+
if (process.arch === 'x64') {
|
146
|
+
return 'win32-x64-msvc';
|
147
|
+
}
|
148
|
+
if (process.arch === 'ia32') {
|
149
|
+
return 'win32-ia32-msvc';
|
150
|
+
}
|
151
|
+
if (process.arch === 'arm64') {
|
152
|
+
return 'win32-arm64-msvc';
|
153
|
+
}
|
154
|
+
break;
|
155
|
+
}
|
156
|
+
case 'darwin': {
|
157
|
+
const targets = ['darwin-universal'];
|
158
|
+
if (process.arch === 'x64') {
|
159
|
+
targets.push('darwin-x64');
|
160
|
+
}
|
161
|
+
else if (process.arch === 'arm64') {
|
162
|
+
targets.push('darwin-arm64');
|
163
|
+
}
|
164
|
+
return targets;
|
165
|
+
}
|
166
|
+
case 'freebsd': {
|
167
|
+
if (process.arch === 'x64') {
|
168
|
+
return 'freebsd-x64';
|
169
|
+
}
|
170
|
+
if (process.arch === 'arm64') {
|
171
|
+
return 'freebsd-arm64';
|
172
|
+
}
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
case 'linux': {
|
176
|
+
if (process.arch === 'x64') {
|
177
|
+
if (isMusl()) {
|
178
|
+
return 'linux-x64-musl';
|
179
|
+
}
|
180
|
+
return 'linux-x64-gnu';
|
181
|
+
}
|
182
|
+
if (process.arch === 'arm64') {
|
183
|
+
if (isMusl()) {
|
184
|
+
return 'linux-arm64-musl';
|
185
|
+
}
|
186
|
+
return 'linux-arm64-gnu';
|
187
|
+
}
|
188
|
+
if (process.arch === 'arm') {
|
189
|
+
if (isMusl()) {
|
190
|
+
return 'linux-arm-musleabihf';
|
191
|
+
}
|
192
|
+
return 'linux-arm-gnueabihf';
|
193
|
+
}
|
194
|
+
if (process.arch === 'riscv64') {
|
195
|
+
if (isMusl()) {
|
196
|
+
return 'linux-riscv64-musl';
|
197
|
+
}
|
198
|
+
return 'linux-riscv64-gnu';
|
199
|
+
}
|
200
|
+
if (process.arch === 'ppc64') {
|
201
|
+
return 'linux-ppc64-gnu';
|
202
|
+
}
|
203
|
+
if (process.arch === 's390x') {
|
204
|
+
return 'linux-s390x-gnu';
|
205
|
+
}
|
206
|
+
break;
|
207
|
+
}
|
208
|
+
}
|
209
|
+
return [];
|
210
|
+
}
|
211
|
+
const WASI_TARGET = 'wasm32-wasi';
|
212
|
+
function getNapiNativeTargets() {
|
213
|
+
const targets = getNapiNativeTarget();
|
214
|
+
if (Array.isArray(targets)) {
|
215
|
+
return [...targets, WASI_TARGET];
|
216
|
+
}
|
217
|
+
return [targets, WASI_TARGET];
|
218
|
+
}
|
219
|
+
function getErrorMessage(err) {
|
220
|
+
return (err === null || err === void 0 ? void 0 : err.message) || String(err);
|
221
|
+
}
|
222
|
+
//# sourceMappingURL=helpers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;AAQA,oDASC;AAED,0CAgBC;AAED,gDAGC;AAUD,gEAkDC;AAiED,kDAmFC;AAID,oDAMC;AAED,0CAEC;;AAtQD,2DAA6C;AAC7C,8DAAmC;AACnC,kEAA4B;AAE5B,iDAAqD;AACrD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EAAE,CAAC;gBAC3B,IAAI,MAAM,EAAE,EAAE,CAAC;oBACb,OAAO,sBAAsB,CAAA;gBAC/B,CAAC;gBACD,OAAO,qBAAqB,CAAA;YAC9B,CAAC;YACD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC/B,IAAI,MAAM,EAAE,EAAE,CAAC;oBACb,OAAO,oBAAoB,CAAA;gBAC7B,CAAC;gBACD,OAAO,mBAAmB,CAAA;YAC5B,CAAC;YACD,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBAC7B,OAAO,iBAAiB,CAAA;YAC1B,CAAC;YACD,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBAC7B,OAAO,iBAAiB,CAAA;YAC1B,CAAC;YAED,MAAK;QACP,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAA;AACX,CAAC;AAED,MAAM,WAAW,GAAG,aAAa,CAAA;AAEjC,SAAgB,oBAAoB;IAClC,MAAM,OAAO,GAAG,mBAAmB,EAAE,CAAA;IACrC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,OAAO,EAAE,WAAW,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;AAC/B,CAAC;AAED,SAAgB,eAAe,CAAC,GAAY;IAC1C,OAAO,CAAC,GAAyB,aAAzB,GAAG,uBAAH,GAAG,CAAwB,OAAO,KAAI,MAAM,CAAC,GAAG,CAAC,CAAA;AAC3D,CAAC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.checkAndPreparePackage = checkAndPreparePackage;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
6
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
7
|
+
const node_https_1 = tslib_1.__importDefault(require("node:https"));
|
8
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
9
|
+
const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
|
10
|
+
const constants_js_1 = require("./constants.js");
|
11
|
+
const helpers_js_1 = require("./helpers.js");
|
12
|
+
function fetch(url) {
|
13
|
+
return new Promise((resolve, reject) => {
|
14
|
+
node_https_1.default
|
15
|
+
.get(url, res => {
|
16
|
+
if ((res.statusCode === 301 || res.statusCode === 302) &&
|
17
|
+
res.headers.location) {
|
18
|
+
fetch(res.headers.location).then(resolve, reject);
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
if (res.statusCode !== 200) {
|
22
|
+
return reject(new Error(`Server responded with ${res.statusCode}`));
|
23
|
+
}
|
24
|
+
const chunks = [];
|
25
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
26
|
+
res.on('end', () => resolve(Buffer.concat(chunks)));
|
27
|
+
})
|
28
|
+
.on('error', reject);
|
29
|
+
});
|
30
|
+
}
|
31
|
+
function extractFileFromTarGzip(buffer, subpath) {
|
32
|
+
try {
|
33
|
+
buffer = node_zlib_1.default.unzipSync(buffer);
|
34
|
+
}
|
35
|
+
catch (err) {
|
36
|
+
throw new Error(`Invalid gzip data in archive: ${(err === null || err === void 0 ? void 0 : err.message) || String(err)}`);
|
37
|
+
}
|
38
|
+
const str = (i, n) => String.fromCodePoint(...buffer.subarray(i, i + n)).replace(/\0.*$/, '');
|
39
|
+
let offset = 0;
|
40
|
+
subpath = `package/${subpath}`;
|
41
|
+
while (offset < buffer.length) {
|
42
|
+
const name = str(offset, 100);
|
43
|
+
const size = Number.parseInt(str(offset + 124, 12), 8);
|
44
|
+
offset += 512;
|
45
|
+
if (!Number.isNaN(size)) {
|
46
|
+
if (name === subpath) {
|
47
|
+
return buffer.subarray(offset, offset + size);
|
48
|
+
}
|
49
|
+
offset += (size + 511) & ~511;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
throw new Error(`Could not find ${JSON.stringify(subpath)} in archive`);
|
53
|
+
}
|
54
|
+
function isNpm() {
|
55
|
+
const { npm_config_user_agent } = process.env;
|
56
|
+
if (npm_config_user_agent) {
|
57
|
+
return /\bnpm\//.test(npm_config_user_agent);
|
58
|
+
}
|
59
|
+
return false;
|
60
|
+
}
|
61
|
+
function installUsingNPM(hostPkg, pkg, version, subpath, nodePath) {
|
62
|
+
const env = Object.assign(Object.assign({}, process.env), { npm_config_global: undefined });
|
63
|
+
const pkgDir = node_path_1.default.dirname(require.resolve(hostPkg + '/package.json'));
|
64
|
+
const installDir = node_path_1.default.join(pkgDir, 'npm-install');
|
65
|
+
node_fs_1.default.mkdirSync(installDir, { recursive: true });
|
66
|
+
try {
|
67
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(installDir, 'package.json'), '{}');
|
68
|
+
(0, node_child_process_1.execSync)(`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${version}`, { cwd: installDir, stdio: 'pipe', env });
|
69
|
+
try {
|
70
|
+
const newPath = node_path_1.default.resolve(pkgDir, hostPkg
|
71
|
+
.split('/')
|
72
|
+
.map(() => '..')
|
73
|
+
.join('/'), pkg);
|
74
|
+
node_fs_1.default.mkdirSync(newPath, { recursive: true });
|
75
|
+
node_fs_1.default.renameSync(node_path_1.default.join(installDir, 'node_modules', pkg), newPath);
|
76
|
+
}
|
77
|
+
catch (_a) {
|
78
|
+
node_fs_1.default.renameSync(node_path_1.default.join(installDir, 'node_modules', pkg, subpath), nodePath);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
finally {
|
82
|
+
try {
|
83
|
+
(0, helpers_js_1.removeRecursive)(installDir);
|
84
|
+
}
|
85
|
+
catch (_b) {
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
function downloadDirectlyFromNPM(pkg, version, subpath, nodePath) {
|
90
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
91
|
+
const url = `${(0, helpers_js_1.getGlobalNpmRegistry)()}${pkg}/-/${pkg.startsWith('@') ? pkg.split('/')[1] : pkg}-${version}.tgz`;
|
92
|
+
console.error(`${constants_js_1.LOG_PREFIX}Trying to download ${JSON.stringify(url)}`);
|
93
|
+
try {
|
94
|
+
node_fs_1.default.writeFileSync(nodePath, extractFileFromTarGzip(yield fetch(url), subpath));
|
95
|
+
}
|
96
|
+
catch (err) {
|
97
|
+
console.error(`${constants_js_1.LOG_PREFIX}Failed to download ${JSON.stringify(url)}: ${(0, helpers_js_1.getErrorMessage)(err)}`);
|
98
|
+
throw err;
|
99
|
+
}
|
100
|
+
});
|
101
|
+
}
|
102
|
+
function checkAndPreparePackage(packageNameOrPackageJson, checkVersion) {
|
103
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
104
|
+
const packageJson = typeof packageNameOrPackageJson === 'string'
|
105
|
+
? require(packageNameOrPackageJson + '/package.json')
|
106
|
+
: packageNameOrPackageJson;
|
107
|
+
const { napi, version: napiVersion } = (0, helpers_js_1.getNapiInfoFromPackageJson)(packageJson, checkVersion);
|
108
|
+
const { name, version, optionalDependencies } = packageJson;
|
109
|
+
if (checkVersion && version !== napiVersion) {
|
110
|
+
throw new Error(`Inconsistent package versions found for \`${name}\` v${version} vs \`${napi.packageName}\` v${napiVersion}.`);
|
111
|
+
}
|
112
|
+
const targets = (0, helpers_js_1.getNapiNativeTargets)();
|
113
|
+
for (const target of targets) {
|
114
|
+
const pkg = `${napi.packageName}-${target}`;
|
115
|
+
if (!optionalDependencies[pkg]) {
|
116
|
+
continue;
|
117
|
+
}
|
118
|
+
const binaryPrefix = napi.binaryName ? `${napi.binaryName}.` : '';
|
119
|
+
const subpath = `${binaryPrefix}${target}.node`;
|
120
|
+
try {
|
121
|
+
require.resolve(`${pkg}/${subpath}`);
|
122
|
+
break;
|
123
|
+
}
|
124
|
+
catch (_a) {
|
125
|
+
if (!isNpm()) {
|
126
|
+
console.error(`${constants_js_1.LOG_PREFIX}Failed to find package "${pkg}" on the file system
|
127
|
+
|
128
|
+
This can happen if you use the "--no-optional" flag. The "optionalDependencies"
|
129
|
+
package.json feature is used by ${name} to install the correct napi binary
|
130
|
+
for your current platform. This install script will now attempt to work around
|
131
|
+
this. If that fails, you need to remove the "--no-optional" flag to use ${name}.
|
132
|
+
`);
|
133
|
+
}
|
134
|
+
const nodePath = (0, helpers_js_1.downloadedNodePath)(name, subpath);
|
135
|
+
try {
|
136
|
+
console.error(`${constants_js_1.LOG_PREFIX}Trying to install package "${pkg}" using npm`);
|
137
|
+
installUsingNPM(name, pkg, version, subpath, nodePath);
|
138
|
+
break;
|
139
|
+
}
|
140
|
+
catch (err) {
|
141
|
+
console.error(`${constants_js_1.LOG_PREFIX}Failed to install package "${pkg}" using npm: ${(0, helpers_js_1.getErrorMessage)(err)}`);
|
142
|
+
try {
|
143
|
+
yield downloadDirectlyFromNPM(pkg, version, subpath, nodePath);
|
144
|
+
break;
|
145
|
+
}
|
146
|
+
catch (err) {
|
147
|
+
throw new Error(`Failed to install package "${pkg}": ${(0, helpers_js_1.getErrorMessage)(err)}`);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
});
|
153
|
+
}
|
154
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAoLA,wDAsFC;;AAxQD,2DAA6C;AAC7C,8DAAwB;AACxB,oEAA8B;AAC9B,kEAA4B;AAC5B,kEAA4B;AAE5B,iDAA2C;AAC3C,6CAOqB;AAMrB,SAAS,KAAK,CAAC,GAAW;IACxB,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,oBAAK;aACF,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;YACd,IACE,CAAC,GAAG,CAAC,UAAU,KAAK,GAAG,IAA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AE,CACrF,CAAA;oBAKD,IAAI,CAAC;wBACH,MAAM,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;wBAC9D,MAAK;oBACP,CAAC;oBAAC,OAAO,GAAG,EAAE,CAAC;wBACb,MAAM,IAAI,KAAK,CACb,8BAA8B,GAAG,MAAM,IAAA,4BAAe,EAAC,GAAG,CAAC,EAAE,CAC9D,CAAA;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CAAA"}
|
package/lib/target.d.ts
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
export type Platform = NodeJS.Platform | 'wasi' | 'wasm';
|
2
|
+
export type NodeJSArch = NodeJS.Architecture | 'universal' | 'wasm32' | 'x32';
|
3
|
+
export interface Target {
|
4
|
+
triple: string;
|
5
|
+
platformArchABI: string;
|
6
|
+
platform: Platform;
|
7
|
+
arch: NodeJSArch;
|
8
|
+
abi: string | null;
|
9
|
+
}
|
10
|
+
export declare function parseTriple(rawTriple: string): Target;
|
package/lib/target.js
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.parseTriple = parseTriple;
|
4
|
+
const CpuToNodeArch = {
|
5
|
+
x86_64: 'x64',
|
6
|
+
aarch64: 'arm64',
|
7
|
+
i686: 'ia32',
|
8
|
+
armv7: 'arm',
|
9
|
+
riscv64gc: 'riscv64',
|
10
|
+
powerpc64le: 'ppc64',
|
11
|
+
};
|
12
|
+
const SysToNodePlatform = {
|
13
|
+
linux: 'linux',
|
14
|
+
freebsd: 'freebsd',
|
15
|
+
darwin: 'darwin',
|
16
|
+
windows: 'win32',
|
17
|
+
};
|
18
|
+
function parseTriple(rawTriple) {
|
19
|
+
var _a, _b;
|
20
|
+
if (rawTriple === 'wasm32-wasi' ||
|
21
|
+
rawTriple === 'wasm32-wasi-preview1-threads' ||
|
22
|
+
rawTriple.startsWith('wasm32-wasip')) {
|
23
|
+
return {
|
24
|
+
triple: rawTriple,
|
25
|
+
platformArchABI: 'wasm32-wasi',
|
26
|
+
platform: 'wasi',
|
27
|
+
arch: 'wasm32',
|
28
|
+
abi: 'wasi',
|
29
|
+
};
|
30
|
+
}
|
31
|
+
const triple = rawTriple.endsWith('eabi')
|
32
|
+
? `${rawTriple.slice(0, -4)}-eabi`
|
33
|
+
: rawTriple;
|
34
|
+
const triples = triple.split('-');
|
35
|
+
let cpu;
|
36
|
+
let sys;
|
37
|
+
let abi = null;
|
38
|
+
if (triples.length === 2) {
|
39
|
+
;
|
40
|
+
[cpu, sys] = triples;
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
;
|
44
|
+
[cpu, , sys, abi = null] = triples;
|
45
|
+
}
|
46
|
+
const platform = (_a = SysToNodePlatform[sys]) !== null && _a !== void 0 ? _a : sys;
|
47
|
+
const arch = (_b = CpuToNodeArch[cpu]) !== null && _b !== void 0 ? _b : cpu;
|
48
|
+
return {
|
49
|
+
triple: rawTriple,
|
50
|
+
platformArchABI: abi ? `${platform}-${arch}-${abi}` : `${platform}-${arch}`,
|
51
|
+
platform,
|
52
|
+
arch,
|
53
|
+
abi,
|
54
|
+
};
|
55
|
+
}
|
56
|
+
//# sourceMappingURL=target.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"target.js","sourceRoot":"","sources":["../src/target.ts"],"names":[],"mappings":";;AA8CA,kCA0CC;AAlFD,MAAM,aAAa,GAA+B;IAChD,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,SAAS;IACpB,WAAW,EAAE,OAAO;CACrB,CAAA;AAED,MAAM,iBAAiB,GAA6B;IAClD,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,OAAO;CACjB,CAAA;AA0BD,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,GAAG;KACJ,CAAA;AACH,CAAC"}
|
package/lib/types.d.ts
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
export interface Napi {
|
2
|
+
binaryName?: string;
|
3
|
+
name?: string;
|
4
|
+
packageName?: string;
|
5
|
+
package?: {
|
6
|
+
name: string;
|
7
|
+
};
|
8
|
+
targets?: string[];
|
9
|
+
triples?: {
|
10
|
+
defaults?: boolean;
|
11
|
+
additional?: string[];
|
12
|
+
};
|
13
|
+
wasm?: {
|
14
|
+
browser?: {
|
15
|
+
fs?: boolean;
|
16
|
+
};
|
17
|
+
};
|
18
|
+
}
|
19
|
+
export interface NapiInfo {
|
20
|
+
napi: Napi;
|
21
|
+
version: string;
|
22
|
+
}
|
23
|
+
export interface PackageJson {
|
24
|
+
name: string;
|
25
|
+
version: string;
|
26
|
+
optionalDependencies?: Partial<Record<string, string>>;
|
27
|
+
napi?: Napi;
|
28
|
+
}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"name": "napi-postinstall",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"type": "commonjs",
|
5
|
+
"description": "The `postinstall` script helper for handling native bindings in legacy `npm` versions",
|
6
|
+
"repository": "git+https://github.com/un-ts/napi-postinstall.git",
|
7
|
+
"author": "JounQin <admin@1stg.me> (https://www.1stG.me)",
|
8
|
+
"funding": "https://opencollective.com/unts",
|
9
|
+
"license": "MIT",
|
10
|
+
"engines": {
|
11
|
+
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
|
12
|
+
},
|
13
|
+
"bin": {
|
14
|
+
"napi-postinstall": "./lib/cli.js"
|
15
|
+
},
|
16
|
+
"main": "./lib/index.js",
|
17
|
+
"types": "./lib/index.d.ts",
|
18
|
+
"exports": {
|
19
|
+
".": {
|
20
|
+
"types": "./lib/index.d.ts",
|
21
|
+
"default": "./lib/index.js"
|
22
|
+
},
|
23
|
+
"./package.json": "./package.json"
|
24
|
+
},
|
25
|
+
"files": [
|
26
|
+
"lib",
|
27
|
+
"!**/*.tsbuildinfo"
|
28
|
+
]
|
29
|
+
}
|