Skip to content

Commit 4c57751

Browse files
authored
Move condition to build the package to a script (#647)
For local development we want to build the package before running install, this will save hassle with fresh clones of the repository and on `mono clean`/`npm run clean`. The check we did was a Unix only check within the if-statement with `test`. Move the check and execution of `npm run build` to a new Node.js file so it runs on any Operating System. Fixes #646
1 parent fc9f2fd commit 4c57751

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bump: "patch"
3+
type: "fix"
4+
---
5+
6+
Fix error on Microsoft Windows machines on install. The AppSignal extension still won't install on Windows, but now it won't cause an error while checking a development mode condition if it should build the TypeScript package.

packages/nodejs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"postclean": "npm run clean:ext",
3838
"clean": "rimraf dist coverage build",
3939
"clean:ext": "rimraf ext/appsignal-agent ext/libappsignal.a ext/appsignal.* ext/*.tar.gz ext/*.report",
40-
"preinstall": "if test -d src; then npm run build; fi",
40+
"preinstall": "node scripts/extension/prebuild.js",
4141
"install": "node scripts/extension/extension.js",
4242
"link:npm": "npm link",
4343
"link:yarn": "yarn link",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require("fs")
2+
const childProcess = require("child_process")
3+
4+
function build() {
5+
return new Promise((resolve, reject) => {
6+
childProcess.exec("npm run build", error => {
7+
if (error) {
8+
return reject(error)
9+
} else {
10+
return resolve()
11+
}
12+
})
13+
})
14+
}
15+
16+
function run() {
17+
// Build the package if it is the local development version that still has
18+
// the `src` directory. It won't run in the shipped version where the `src`
19+
// directory is not available.
20+
if (fs.existsSync("src")) {
21+
return build().catch(error => {
22+
console.error(
23+
"Something went wrong while building the @appsignal/nodejs package: ",
24+
error
25+
)
26+
})
27+
}
28+
}
29+
30+
run()

0 commit comments

Comments
 (0)