Skip to content

Commit 0b34482

Browse files
authored
Pavel/add check types on prepack (#47)
* Fix types directive in package json; Add a command to check if types path is defined correctly * Adjust lefthook config to exclude check-types.js file * Adjust lefthook config * test lefthook commit * Revert test lefthook commit
1 parent 695b688 commit 0b34482

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

check-types.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
// Load package.json
5+
const packageJsonPath = path.join(__dirname, 'package.json');
6+
const packageJson = require(packageJsonPath);
7+
8+
// Get the "types" field from package.json
9+
const typesFilePath = packageJson.types;
10+
11+
if (!typesFilePath) {
12+
console.error('The "types" field is not defined in package.json.');
13+
process.exit(1);
14+
}
15+
16+
// Resolve the full path to the types file
17+
const typesFileFullPath = path.resolve(__dirname, typesFilePath);
18+
19+
// Check if the file exists
20+
fs.access(typesFileFullPath, fs.constants.F_OK, (err) => {
21+
if (err) {
22+
console.error(`The types file '${typesFileFullPath}' does not exist.`);
23+
process.exit(1);
24+
} else {
25+
console.log(`The types file '${typesFileFullPath}' exists.`);
26+
}
27+
});

lefthook.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ pre-commit:
22
parallel: true
33
commands:
44
lint:
5-
files: git diff --name-only @{push}
5+
files: git diff --cached --name-only
66
glob: "*.{js,ts,jsx,tsx}"
77
run: npx eslint {files}
88
types:
9-
files: git diff --name-only @{push}
10-
glob: "*.{js,ts, jsx, tsx}"
11-
run: npx tsc --noEmit
9+
files: git diff --cached --name-only
10+
glob: "*.{ts,tsx}"
11+
run: npx tsc --noEmit

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@eppo/react-native-sdk",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Eppo React Native SDK",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
7-
"types": "lib/typescript/src/index.d.ts",
7+
"types": "lib/typescript/index.d.ts",
88
"react-native": "src/index",
99
"source": "src/index",
1010
"files": [
@@ -31,9 +31,10 @@
3131
"test": "jest",
3232
"typecheck": "tsc --noEmit",
3333
"lint": "eslint \"**/*.{js,ts,tsx}\"",
34-
"prepack": "bob build && cp -r package.json lib",
34+
"prepack": "bob build && cp -r package.json lib && yarn check-types",
3535
"example": "yarn --cwd example",
36-
"bootstrap": "yarn example && yarn install"
36+
"bootstrap": "yarn example && yarn install",
37+
"check-types": "node ./check-types.js"
3738
},
3839
"keywords": [
3940
"react-native",
@@ -146,4 +147,4 @@
146147
]
147148
]
148149
}
149-
}
150+
}

0 commit comments

Comments
 (0)