You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document aims to help you get started with `pkg` developemnt.
4
+
5
+
## Release Process
6
+
7
+
In order to create release just run the command:
8
+
9
+
```bash
10
+
npm run release
11
+
```
12
+
13
+
This command will start an interactive process that will guide you through the release process using [release-it](https://github.com/release-it/release-it)
14
+
15
+
## Testing
16
+
17
+
Before running tests ensure you have build the project by running:
18
+
19
+
```bash
20
+
npm run build
21
+
```
22
+
23
+
> [!NOTE]
24
+
> Remember to run again `npm run build` after changing source code (everything inside `lib` folder).
25
+
26
+
Than you can use the following command to run tests:
-`<target>` is the node target the test will use when creating executables, can be `nodeXX` (like `node20`) or `host` (uses host node version as target).
33
+
-`[no-npm | only-npm | all]` to specify which tests to run. `no-npm` will run tests that don't require npm, `only-npm` will run against some specific npm modules, and `all` will run all tests.
34
+
-`<flavor>` to use when you want to run only tests matching a specific pattern. Example: `node test/test.js all test-99-*`. You can also set this by using `FLAVOR` environment variable.
35
+
36
+
Each test is located inside `test` directory into a dedicated folder named following the pattern `test-XX-*`. The `XX` is a number that represents the order the tests will run.
37
+
38
+
When running `node test/test.js all`, based on the options, each test will be run consecutively by running `main.js` file inside the test folder.
39
+
40
+
### Example test
41
+
42
+
Create a directory named `test-XX-<name>` and inside it create a `main.js` file with the following content:
43
+
44
+
```javascript
45
+
#!/usr/bin/env node
46
+
47
+
'use strict';
48
+
49
+
constassert=require('assert');
50
+
constutils=require('../utils.js');
51
+
52
+
assert(!module.parent);
53
+
assert(__dirname===process.cwd());
54
+
55
+
constinput='./test-x-index';
56
+
57
+
constnewcomers= [
58
+
'test-x-index-linux',
59
+
'test-x-index-macos',
60
+
'test-x-index-win.exe',
61
+
];
62
+
63
+
constbefore=utils.filesBefore(newcomers);
64
+
65
+
utils.pkg.sync([input], { stdio:'inherit' });
66
+
67
+
utils.filesAfter(before, newcomers);
68
+
```
69
+
70
+
Explaining the code above:
71
+
72
+
-`assert(!module.parent);` ensures the script is being run directly.
73
+
-`assert(__dirname === process.cwd());` ensures the script is being run from the correct directory.
74
+
-`utils.filesBefore(newcomers);` get current files in the directory.
75
+
-`utils.pkg.sync([input], { stdio: 'inherit' });` runs `pkg` passing input file as only argument.
76
+
-`utils.filesAfter(before, newcomers);` checks if the output files were created correctly and cleans up the directory to the original state.
77
+
78
+
### Special tests
79
+
80
+
-`test-79-npm`: It's the only test runned when using `only-npm`. It install and tests all node modules listed inside that dir and verifies if they are working correctly.
81
+
-`test-42-fetch-all`: Foreach known node version verifies there is a patch existing for it using pkg-fetch.
82
+
-`test-46-multi-arch`: Tries to cross-compile a binary for all known architectures.
0 commit comments