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
Copy file name to clipboardexpand all lines: README.md
+66-2
Original file line number
Diff line number
Diff line change
@@ -73,13 +73,13 @@ $ npm run ts-node
73
73
74
74
You can also create test files in `./src`, and run them with `npm run ts-node ./src/test.ts`.
75
75
76
-
This allows you to test individual pieces of typescript code and it makes it easier when doing large scale rearchitecting of TypeScript code.
76
+
This allows you to test individual pieces of typescript code, and it makes it easier when doing large scale architecting of TypeScript code.
77
77
78
78
### Path Aliases
79
79
80
80
Due to https://github.com/microsoft/TypeScript/issues/10866, you cannot use path aliases without a bundler like Webpack to further transform the generated JavaScript code in order to resolve the path aliases. Because this is a simple library demonstration, there's no need to use a bundler. In fact, for such libraries, it is far more efficient to not bundle the code.
81
81
82
-
However we have left the path alias configuration in `tsconfig.json`, `jest.config.js` and in the tests we are making use of the `@` alias.
82
+
However, we have left the path alias configuration in `tsconfig.json`, `jest.config.js` and in the tests we are making use of the `@` alias.
83
83
84
84
#### VSCode Path Aliases
85
85
@@ -99,6 +99,70 @@ This will however make `tsc` build the `tests` into the `dist` output.
99
99
100
100
**Therefore this fix should only be done in your own workspace, do not commit or push this change up.**
101
101
102
+
### Native Module Toolchain
103
+
104
+
There are some nuances when packaging with native modules.
105
+
Included native modules are level witch include leveldown and utp-native.
106
+
107
+
If a module is not set to public then pkg defaults to including it as bytecode.
108
+
To avoid this breaking with the `--no-bytecode` flag we need to add `--public-packages "*"`
109
+
110
+
#### leveldown
111
+
112
+
To get leveldown to work with pkg we need to include the prebuilds with the executable.
113
+
after building with pkg you need to copy from `node_modules/leveldown/prebuilds` -> `path_to_executable/prebuilds`
114
+
You only need to include the prebuilds for the arch you are targeting. e.g. for linux-x64 you need `prebuild/linux-x64`.
115
+
116
+
The folder structure for the executable should look like this.
117
+
- linux_executable_elf
118
+
- prebuilds
119
+
- linux-x64
120
+
- (node files)
121
+
122
+
#### utp-native
123
+
124
+
Including utp-native is simpler, you just need to add it as an asset for pkg.
125
+
Add the following lines to the package.json.
126
+
```json
127
+
"pkg": {
128
+
"assets": "node_modules/utp-native/**/*"
129
+
}
130
+
```
131
+
132
+
#### threads.js
133
+
134
+
To make sure that the worker threads work properly you need to include the compiled worker scripts as an asset.
135
+
This can be fixed by adding the following to `package.json`
136
+
137
+
```json
138
+
"pkg": {
139
+
"assets": "dist/bin/worker.js"
140
+
}
141
+
```
142
+
143
+
If you need to include multiple assets then add them as an array.
144
+
145
+
```json
146
+
"pkg": {
147
+
"assets": [
148
+
"node_modules/utp-native/**/*",
149
+
"dist/bin/worker.js"
150
+
]
151
+
}
152
+
```
153
+
154
+
#### Integration into Nix
155
+
156
+
Nix build uses node2nix to create the dependencies of the node modules. this does a fairly good job of detecting dependencies but with native modules it may fail to detect CLI tools like `node-gyp-build`.
157
+
158
+
To ensure the proper dependencies exist while building we need to bring in these utilities during the build:
0 commit comments