Skip to content

Commit

Permalink
build: refactor build option parser
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 19, 2024
1 parent 50ee02d commit 6b2cb3e
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"script/*.js",
"script/*.d.ts",
"docs/",
"docs-raw/",
"doc-unminified/",
"test/unit/compat/",
"test/bench/"
]
Expand Down
16 changes: 5 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ build-tmp-napi-v*
test.js
.cache/
test/typings-compatibility/
/script/*.js
/script/*.mjs
/script/*js
/script/*.d.ts
/script/*.d.mts
/script/*.js.map
/script/*.mjs.map
/script/*/*.js
/script/*/*.mjs
/script/*/*.d.ts
/script/*/*.js.map
/script/*.d.*ts
/script/*js.map
tsconfig.tsbuildinfo
tsconfig.esm.tsbuildinfo
/docs-raw
tsconfig.*.tsbuildinfo
/doc-unminified
.DS_Store
.idea
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/docs/
/docs-raw
/doc-unminified
/lib
/prebuilds
/node_modules
Expand Down
15 changes: 14 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@
"mochaExplorer.nodeArgv": [
"--expose-gc"
],
"mochaExplorer.debuggerConfig": "JS-Attach"
"mochaExplorer.debuggerConfig": "JS-Attach",
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/.cache": true,
"**/script/*.js": true,
"**/script/*.mjs": true,
"**/script/*.js.map": true,
"**/script/*.mjs.map": true,
"**/script/*.d.ts": true,
"**/script/*.d.mts": true,
"**/script/*.tsbuildinfo": true,
}
}
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,30 @@ build_from_source=true
When building from source, you can also specify additional build options in a
`.npmrc` file in your project:

### Available Build Options

<details>
<summary>Available Build Options</summary>
<summary>👉🏻 Options</summary>

#### Draft support

By default `libzmq` is built with support for `Draft` patterns (e.g.
`server-client`, `radio-dish`, `scatter-gather`). If you want to build `libzmq`
without support for `Draft`, you can specify the following in `.npmrc`:

```
```ini
zmq_draft=false
```

#### Not Synchronous Resolve

If you want to send/receive on the socket immediately, you can specify the
following in `.npmrc`:

```ini
zmq_no_sync_resolve="true"
```

#### Shared library support

If you want to link against a shared ZeroMQ library installed on your system,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
],
"scripts": {
"install": "(npm run build.js || echo ok) && aminya-node-gyp-build --build-from-source",
"clean": "shx rm -rf ./build ./lib/ ./prebuilds ./script/*.js ./script/*.js.map ./script/*.d.ts ./script/*.tsbuildinfo",
"clean": "shx rm -rf ./build ./lib/ ./prebuilds ./script/*.js ./script/*.mjs ./script/*.js.map ./script/*.mjs.map ./script/*.d.ts ./script/*.d.mts ./script/*.cjs ./scripts/*.cjs.map ./scripts/*.d.cts ./script/*.tsbuildinfo",
"clean.release": "shx rm -rf ./build/Release",
"clean.temp": "shx rm -rf ./tmp && shx mkdir -p ./tmp",
"build.library": "tsc -p ./src/tsconfig.json",
"build.script": "tsc -p ./script/tsconfig.json && tsc -p ./script/tsconfig.esm.json",
"build.script": "tsc -p ./script/tsconfig.esm.json && tsc -p ./script/tsconfig.json",
"build.js": "run-p build.script build.library",
"build.doc": "typedoc --options ./typedoc.json && minify-all -s docs-raw -d docs --jsCompressor terser",
"build.doc": "typedoc --options ./typedoc.json && minify-all -s docs-unminified -d docs --jsCompressor terser && shx rm -rf docs-unminified",
"deploy.doc": "run-s build.doc && gh-pages --dist \"./docs\"",
"build.prebuild": "run-s build.js && node ./script/prebuild.mjs",
"build.native": "node-gyp configure --release && node-gyp configure --release -- -f compile_commands_json && node-gyp build --release",
Expand Down
24 changes: 1 addition & 23 deletions script/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {dirname} from "path"
import {existsSync, writeFileSync} from "fs"
import {mkdir, cd, exec, find, mv} from "shelljs"
import {toBool, toString} from "./utils.js"

const root = dirname(__dirname)

Expand All @@ -13,29 +14,6 @@ type Options = {
macosx_deployment_target?: string
}

function toBool(value: string | undefined): boolean | undefined {
switch (value) {
case "true":
case "1":
return true
case "false":
case "0":
return false
default:
return undefined
}
}

function toString(value: string | undefined): string | undefined {
switch (value) {
case undefined:
case "":
return undefined
default:
return value
}
}

function parseOptions(): Options {
return {
zmq_shared: toBool(process.env.npm_config_zmq_shared) ?? false,
Expand Down
12 changes: 2 additions & 10 deletions script/prebuild.mts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import {execaCommandSync} from "execa"
import * as buildUtils from "./utils.js"
const {toString} = buildUtils

type Options = {
arch: string
}

function toString(value: string | undefined): string | undefined {
switch (value) {
case undefined:
case "":
return undefined
default:
return value
}
}

function parserOptions(): Options {
return {
arch: toString(process.env.npm_config_arch) ?? process.arch,
Expand Down
2 changes: 1 addition & 1 deletion script/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"moduleResolution": "node"
},
"include": ["./**/*.mts"],
"exclude": []
"exclude": ["./**/*.d.mts"]
}
12 changes: 9 additions & 3 deletions script/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./"
"outDir": "./",
},
"include": ["./**/*.ts"],
"exclude": []
"include": [
"./**/*.ts",
"./**/*.cts"
],
"exclude": [
"./**/*.d.ts",
"./**/*.d.cts"
]
}
25 changes: 25 additions & 0 deletions script/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export function toBool(value: string | undefined): boolean | undefined {
switch (value) {
case "true":
case "1":
return true
case "false":
case "0":
return false
case undefined:
case "":
return undefined
default:
throw new Error(`Invalid boolean value: ${value}`)
}
}

export function toString(value: string | undefined): string | undefined {
switch (value) {
case undefined:
case "":
return undefined
default:
return value
}
}
1 change: 1 addition & 0 deletions tsconfig.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"exclude": [
"script/**/*",
"test/**/*",
"build/**/*",
"examples/**/*",
"src/errors.ts",
"src/util.ts"
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"target": "es2020",
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
"types": [
"node",
"mocha"
Expand Down
2 changes: 1 addition & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "zeromq.js",
"entryPoints": ["./src/index.ts"],
"tsconfig": "./tsconfig.docs.json",
"out": "docs-raw",
"out": "docs-unminified",
"excludePrivate": true,
"excludeExternals": false,
"exclude": [
Expand Down

0 comments on commit 6b2cb3e

Please sign in to comment.