Initialize capstone 2
commit
e13d022e26
@ -0,0 +1,620 @@
|
||||
{
|
||||
"info": {
|
||||
"_postman_id": "536fbbd5-057a-493f-b5ff-814a3a93a6a7",
|
||||
"name": "Capstone 2",
|
||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
||||
"_exporter_id": "30192105"
|
||||
},
|
||||
"item": [
|
||||
{
|
||||
"name": "checkEmail",
|
||||
"protocolProfileBehavior": {
|
||||
"disableBodyPruning": true
|
||||
},
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"email\" : \"naruto@mail.com\"\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/users/checkEmail",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"users",
|
||||
"checkEmail"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "register",
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"email\" : \"sasuke@mail.com\",\r\n \"password\" : \"sasuke\"\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/users/register",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"users",
|
||||
"register"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "login",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"email\" : \"naruto@mail.com\",\r\n \"password\" : \"naruto\"\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/users/login",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"users",
|
||||
"login"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "create a product",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYTgzOWUxYjE0ZTYyNTk3OTY5ZSIsImVtYWlsIjoiYWRtaW5AbWFpbC5jb20iLCJpc0FkbWluIjp0cnVlLCJpYXQiOjE3MDQ1MjU1NjZ9.UIQfNiHYXWzGE6-gxWNdo7dI6MqYvlIqmNP-hznMp5w",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"name\" : \"Kirby and the Forgotten Land\",\r\n \"description\" : \"Kirby and the Forgotten Land[b] is a 2022 platform video game developed by HAL Laboratory and published by Nintendo for the Nintendo Switch. It is the thirteenth mainline installment in the Kirby series, as well as the first game in the series in full 3D, excluding spin-offs. The player controls Kirby in an adventure through the titular forgotten land called the New World to rescue Waddle Dees kidnapped by the ferocious Beast Pack. To complete each stage to save the Waddle Dees, Kirby can use a wide range of copy abilities to help battle enemies and progress.\",\r\n \"price\" : 2495,\r\n \"inventory\" : 600\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/create",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"create"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "retrieve all products",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OWFiODRjNDkxM2I4NzFlMWFlNzdjZCIsImVtYWlsIjoiYWRtaW5AbWFpbC5jb20iLCJpc0FkbWluIjp0cnVlLCJpYXQiOjE3MDQ3MTI5ODR9.yGegMImaE8fmsTAZE47JFIchOD0u6HfS_RRxY3qyQTc",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/retrieve-all",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"retrieve-all"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "retrieve all active products",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/active",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"active"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "search product",
|
||||
"protocolProfileBehavior": {
|
||||
"disableBodyPruning": true
|
||||
},
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"query\" : \"Kart\"\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/search",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"search"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "update product",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYTgzOWUxYjE0ZTYyNTk3OTY5ZSIsImVtYWlsIjoiYWRtaW5AbWFpbC5jb20iLCJpc0FkbWluIjp0cnVlLCJpYXQiOjE3MDQ1Mjc3MzJ9.WALTs2qRrzzwYn-aYb5-S5VMxITNOf8N2UEZCywrfMY",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "PUT",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"name\" : \"Pokemon Legends: Arceus\",\r\n \"price\" : 2495\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/6598ffaa9cb57b3e6a9e8422",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"6598ffaa9cb57b3e6a9e8422"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "archive product",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYTgzOWUxYjE0ZTYyNTk3OTY5ZSIsImVtYWlsIjoiYWRtaW5AbWFpbC5jb20iLCJpc0FkbWluIjp0cnVlLCJpYXQiOjE3MDQ1Mjc3MzJ9.WALTs2qRrzzwYn-aYb5-S5VMxITNOf8N2UEZCywrfMY",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "PUT",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/6598ffaa9cb57b3e6a9e8422/archive",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"6598ffaa9cb57b3e6a9e8422",
|
||||
"archive"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "activate product",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYTgzOWUxYjE0ZTYyNTk3OTY5ZSIsImVtYWlsIjoiYWRtaW5AbWFpbC5jb20iLCJpc0FkbWluIjp0cnVlLCJpYXQiOjE3MDQ1Mjc3MzJ9.WALTs2qRrzzwYn-aYb5-S5VMxITNOf8N2UEZCywrfMY",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "PUT",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/6598ffaa9cb57b3e6a9e8422/activate",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"6598ffaa9cb57b3e6a9e8422",
|
||||
"activate"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "create order/checkout",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYWIyOWUxYjE0ZTYyNTk3OTZhNCIsImVtYWlsIjoic2FzdWtlQG1haWwuY29tIiwiaXNBZG1pbiI6ZmFsc2UsImlhdCI6MTcwNDU1MDUzN30.yvUlEibQC_k30x8lbIArUDbHZxMa2SmxB5jsdj3NBJ8",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"orderedItems\": [\r\n {\r\n \"productId\" : \"6598ff169cb57b3e6a9e8420\",\r\n \"quantity\" : 1\r\n },\r\n {\r\n \"productId\" : \"6598ffaa9cb57b3e6a9e8422\",\r\n \"quantity\" : 1\r\n },\r\n {\r\n \"productId\" : \"659a31b4a5b6dafefb66f6a8\",\r\n \"quantity\" : 1\r\n }\r\n\r\n ]\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/create-order",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"create-order"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "retrieve current user details",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYWIyOWUxYjE0ZTYyNTk3OTZhNCIsImVtYWlsIjoic2FzdWtlQG1haWwuY29tIiwiaXNBZG1pbiI6ZmFsc2UsImlhdCI6MTcwNDU1MDUzN30.yvUlEibQC_k30x8lbIArUDbHZxMa2SmxB5jsdj3NBJ8",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "localhost:2024/users/details",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"users",
|
||||
"details"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "set user to admin",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OWFiODRjNDkxM2I4NzFlMWFlNzdjZCIsImVtYWlsIjoiYWRtaW5AbWFpbC5jb20iLCJpc0FkbWluIjp0cnVlLCJpYXQiOjE3MDQ3MTI5ODR9.yGegMImaE8fmsTAZE47JFIchOD0u6HfS_RRxY3qyQTc",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "PUT",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"userId\" : \"6597faa29e1b14e6259796a1\"\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/users/set-admin",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"users",
|
||||
"set-admin"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "retrieve current user orders",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYWIyOWUxYjE0ZTYyNTk3OTZhNCIsImVtYWlsIjoic2FzdWtlQG1haWwuY29tIiwiaXNBZG1pbiI6ZmFsc2UsImlhdCI6MTcwNDcxODc4NX0.l8Dwm7BTWEQSJLWYrZCHSaXJ9fxnk6XexzFMkULeTmE",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "localhost:2024/users/orders",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"users",
|
||||
"orders"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "get all orders",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OWFiODRjNDkxM2I4NzFlMWFlNzdjZCIsImVtYWlsIjoiYWRtaW5AbWFpbC5jb20iLCJpc0FkbWluIjp0cnVlLCJpYXQiOjE3MDQ3MTkyNDF9.Z1kf9FihABPI2zXOQCD5w8pUxNW7vOCu_G3X--2QgCY",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "localhost:2024/users/get-all-orders",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"users",
|
||||
"get-all-orders"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "add to cart",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYWEyOWUxYjE0ZTYyNTk3OTZhMSIsImVtYWlsIjoibmFydXRvQG1haWwuY29tIiwiaXNBZG1pbiI6ZmFsc2UsImlhdCI6MTcwNDgxMDAxMH0.akK5cCHqhI6ToWm9Lg0AAg2gTJqTBl140Ts63ITm6LY",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"productId\" : \"659a31b4a5b6dafefb66f6a8\",\r\n \"quantity\" : 2\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/add-to-cart",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"add-to-cart"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "change quantity",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYWEyOWUxYjE0ZTYyNTk3OTZhMSIsImVtYWlsIjoibmFydXRvQG1haWwuY29tIiwiaXNBZG1pbiI6ZmFsc2UsImlhdCI6MTcwNDgxMDU5NX0.yw6p6ePvqFtAPXQtAZDcdgEx3nNRm-DJYajOdGbnemM",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\r\n \"productId\" : \"6598ffaa9cb57b3e6a9e8422\",\r\n \"quantity\" : 14\r\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/update-quantity",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"update-quantity"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "remove prooduct from cart",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYWEyOWUxYjE0ZTYyNTk3OTZhMSIsImVtYWlsIjoibmFydXRvQG1haWwuY29tIiwiaXNBZG1pbiI6ZmFsc2UsImlhdCI6MTcwNDgxMDU5NX0.yw6p6ePvqFtAPXQtAZDcdgEx3nNRm-DJYajOdGbnemM",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "DELETE",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/remove/6598ffaa9cb57b3e6a9e8422",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"remove",
|
||||
"6598ffaa9cb57b3e6a9e8422"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "view cart",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1OTdmYWEyOWUxYjE0ZTYyNTk3OTZhMSIsImVtYWlsIjoibmFydXRvQG1haWwuY29tIiwiaXNBZG1pbiI6ZmFsc2UsImlhdCI6MTcwNDg4OTgyOX0.sPHkX2JjJOY6_MbDkFUxyTWJ8u04Gt_GXf8xTfALA-w",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "localhost:2024/products/view-my-cart",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "2024",
|
||||
"path": [
|
||||
"products",
|
||||
"view-my-cart"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
const jwt = require("jsonwebtoken");
|
||||
const secret = `Dr!stR4ng3`;
|
||||
|
||||
|
||||
module.exports.createAccessToken = (user) => {
|
||||
const data = {
|
||||
id: user._id,
|
||||
email: user.email,
|
||||
isAdmin: user.isAdmin
|
||||
}
|
||||
|
||||
return jwt.sign(data, secret, {});
|
||||
|
||||
}
|
||||
|
||||
|
||||
// token verification
|
||||
module.exports.verify = (request, response, next) => {
|
||||
let token = request.headers.authorization;
|
||||
if(token === undefined){
|
||||
return response.send("No token provided!")
|
||||
}else{
|
||||
token = token.slice(7, token.length);
|
||||
jwt.verify(token, secret, (err, decodedToken) => {
|
||||
if(err){
|
||||
return response.send({
|
||||
auth: "Failed",
|
||||
message: err.message
|
||||
})
|
||||
}else{
|
||||
request.user = decodedToken;
|
||||
next();
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// To verify admin
|
||||
module.exports.verifyAdmin = (request, response, next) => {
|
||||
if(request.user.isAdmin){
|
||||
next();
|
||||
}else{
|
||||
return response.send({
|
||||
auth: "Failed",
|
||||
message: "Action Forbidden, user must be admin!"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// To verify non-admin
|
||||
module.exports.verifyNonAdmin = (request, response, next) => {
|
||||
if(!request.user.isAdmin){
|
||||
next();
|
||||
}else{
|
||||
return response.send({
|
||||
auth: "Failed",
|
||||
message: "Action Forbidden!"
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,377 @@
|
||||
const User = require("../models/User.js");
|
||||
const Product = require("../models/Product.js");
|
||||
const Order = require("../models/Order.js");
|
||||
const auth = require("../auth.js");
|
||||
const {verify, verifyAdmin} = auth;
|
||||
|
||||
|
||||
// Controllers
|
||||
|
||||
// create product controller
|
||||
module.exports.createProduct = async (req, res) => {
|
||||
try {
|
||||
const { name, price, description, inventory } = req.body;
|
||||
|
||||
// Create a new product instance
|
||||
const product = new Product({
|
||||
name,
|
||||
price,
|
||||
description,
|
||||
inventory,
|
||||
});
|
||||
|
||||
// Save the product to the database
|
||||
await product.save();
|
||||
|
||||
res.status(201).json({ message: 'Product created successfully', product });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error creating product' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// retrieve all products controller
|
||||
module.exports.getAllProducts = async (req, res) => {
|
||||
try {
|
||||
// Fetch all products from the database
|
||||
const products = await Product.find();
|
||||
|
||||
res.json(products);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error retrieving products' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// retrieve all active products controller
|
||||
exports.getAllActiveProducts = async (req, res) => {
|
||||
try {
|
||||
const products = await Product.find({ isActive: true });
|
||||
|
||||
res.json(products);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error retrieving active products' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// search products controller
|
||||
exports.searchProducts = async (req, res) => {
|
||||
try {
|
||||
const { query } = req.body;
|
||||
|
||||
// Build the search query using case-insensitive regex
|
||||
const regex = new RegExp(escapeRegex(query), 'i');
|
||||
|
||||
const products = await Product.find({
|
||||
$or: [
|
||||
{ name: regex },
|
||||
// Add more fields to search if needed
|
||||
],
|
||||
});
|
||||
|
||||
res.json(products);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error searching products' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Helper function to escape special characters in the search query
|
||||
function escapeRegex(text) {
|
||||
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
||||
}
|
||||
|
||||
|
||||
// update product controller
|
||||
exports.updateProduct = async (req, res) => {
|
||||
try {
|
||||
const { productId } = req.params;
|
||||
const { name, price, description, inventory } = req.body;
|
||||
|
||||
// Find the product to update
|
||||
const product = await Product.findByIdAndUpdate(productId, {
|
||||
name,
|
||||
price,
|
||||
description,
|
||||
isActive,
|
||||
inventory,
|
||||
}, { new: true });
|
||||
|
||||
if (!product) {
|
||||
return res.status(404).json({ message: 'Product not found' });
|
||||
}
|
||||
|
||||
res.json({ message: 'Product updated successfully', product });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error updating product' });
|
||||
}
|
||||
};
|
||||
|
||||
// archive product controller
|
||||
exports.archiveProduct = async (req, res) => {
|
||||
try {
|
||||
const { productId } = req.params;
|
||||
|
||||
// Find the product to archive
|
||||
const product = await Product.findById(productId);
|
||||
|
||||
if (!product) {
|
||||
return res.status(404).json({ message: 'Product not found' });
|
||||
}else if (product.isActive === false){
|
||||
return res.status(404).json({ message: 'Product already archived' });
|
||||
}
|
||||
|
||||
product.isActive = false;
|
||||
|
||||
await product.save();
|
||||
|
||||
res.json({ message: 'Product archived successfully' });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error archiving product' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// activate product controller
|
||||
exports.activateProduct = async (req, res) => {
|
||||
try {
|
||||
const { productId } = req.params;
|
||||
|
||||
// Find the product to archive
|
||||
const product = await Product.findById(productId);
|
||||
|
||||
if (!product) {
|
||||
return res.status(404).json({ message: 'Product not found' });
|
||||
}else if (product.isActive === true){
|
||||
return res.status(404).json({ message: 'Product already active' });
|
||||
}
|
||||
|
||||
product.isActive = true;
|
||||
|
||||
await product.save();
|
||||
|
||||
res.json({ message: 'Product activated successfully' });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error activating product' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Controller to create an order || check-out
|
||||
exports.createOrder = async (req, res, next) => {
|
||||
try {
|
||||
let cartItems = req.body.orderedItems;
|
||||
|
||||
// Fetch product prices from the database
|
||||
await Product.find({ _id: { $in: cartItems.map(item => item.productId) } }).then( result => {
|
||||
for (i = 0 ; i < result.length; i++) {
|
||||
cartItems[i].price = result[i].price;
|
||||
}
|
||||
});
|
||||
|
||||
// Create the order with retrieved prices
|
||||
const newOrder = new Order({
|
||||
userId: req.user.id,
|
||||
products: cartItems,
|
||||
totalAmount: calculateTotalPrice(cartItems)
|
||||
});
|
||||
|
||||
// Save the order and update inventory
|
||||
await newOrder.save();
|
||||
await updateProductInventory(cartItems);
|
||||
|
||||
|
||||
// Update User orders
|
||||
await User.findById(req.user.id).then( result => {
|
||||
|
||||
const newOrderUserUpdate = {
|
||||
products: cartItems,
|
||||
totalAmount: calculateTotalPrice(cartItems),
|
||||
purchasedOn : new Date()
|
||||
}
|
||||
|
||||
result.orders.push(newOrderUserUpdate);
|
||||
|
||||
result.save();
|
||||
})
|
||||
|
||||
|
||||
|
||||
res.status(201).json({ message: 'Order created successfully', newOrder });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error creating order' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Helper functions for calculating total price and updating inventory
|
||||
function calculateTotalPrice(cartItems) {
|
||||
return cartItems.reduce((total, item) => {
|
||||
const itemPrice = Number(item.price); // Ensure price is a number
|
||||
const itemQuantity = Number(item.quantity); // Ensure quantity is a number
|
||||
return total + (itemPrice * itemQuantity);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
async function updateProductInventory(cartItems) {
|
||||
try {
|
||||
await Promise.all(
|
||||
cartItems.map(async item => {
|
||||
const product = await Product.findById(item.productId);
|
||||
|
||||
if (!product) {
|
||||
throw new Error(`Product not found: ${item.productId}`);
|
||||
}
|
||||
|
||||
// Ensure quantity doesn't go below zero
|
||||
const newQuantity = Math.max(0, product.inventory - item.quantity);
|
||||
|
||||
product.inventory = newQuantity;
|
||||
await product.save();
|
||||
})
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error updating product quantities:', error);
|
||||
// Handle the error appropriately (e.g., rollback order creation)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// My Cart
|
||||
|
||||
exports.addProductToCart = async (req, res) => {
|
||||
try {
|
||||
const { productId, quantity } = req.body;
|
||||
|
||||
// Find the user
|
||||
const user = await User.findById(req.user.id);
|
||||
|
||||
// Check if the cart array exists
|
||||
if (!user.myCart) {
|
||||
user.myCart = [];
|
||||
}
|
||||
|
||||
const existingItemIndex = user.myCart.findIndex(item => item.productId === productId);
|
||||
|
||||
if (existingItemIndex !== -1) {
|
||||
// Update quantity of existing item
|
||||
user.myCart[existingItemIndex].quantity += quantity;
|
||||
} else {
|
||||
if (quantity <= 0) {
|
||||
return res.json({ message: 'Provide valid quantity' });
|
||||
}
|
||||
// Add new item to cart
|
||||
const product = await Product.findById(productId);
|
||||
user.myCart.push({
|
||||
productId,
|
||||
name: product.name,
|
||||
quantity
|
||||
});
|
||||
}
|
||||
|
||||
await user.save(); // Save the updated user with cart items
|
||||
|
||||
res.json({ message: 'Product added to cart successfully' });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error adding product to cart' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.updateProductQuantity = async (req, res) => {
|
||||
try {
|
||||
const { productId, quantity } = req.body;
|
||||
|
||||
// Find the user
|
||||
const user = await User.findById(req.user.id);
|
||||
|
||||
if (!user.myCart) {
|
||||
return res.status(400).json({ message: 'Cart is empty' });
|
||||
}
|
||||
|
||||
const itemIndex = user.myCart.findIndex(item => item.productId === productId);
|
||||
|
||||
if (itemIndex === -1) {
|
||||
return res.status(404).json({ message: 'Product not found in cart' });
|
||||
}
|
||||
|
||||
// Validate quantity (e.g., must be positive, not exceed available inventory)
|
||||
if (quantity <= 0) {
|
||||
return res.status(400).json({ message: 'Quantity must be greater than zero' });
|
||||
}
|
||||
|
||||
// Update quantity in the cart
|
||||
user.myCart[itemIndex].quantity = quantity;
|
||||
|
||||
await user.save(); // Save the updated cart
|
||||
|
||||
res.json({ message: 'Product quantity updated successfully' });
|
||||
console.log(user.myCart);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error updating product quantity' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.removeProductFromCart = async (req, res) => {
|
||||
try {
|
||||
const productId = req.params.productId;
|
||||
const user = await User.findById(req.user.id);
|
||||
const existingItemIndex = user.myCart.findIndex(item => item.productId === productId);
|
||||
|
||||
let x = await User.findByIdAndUpdate(
|
||||
req.user.id,
|
||||
{
|
||||
$pull: { myCart: { productId } }
|
||||
},
|
||||
{ new: true } // Return the updated user document
|
||||
).exec();
|
||||
|
||||
if (existingItemIndex <= 0) {
|
||||
res.json({ message: 'Product not in cart' });
|
||||
}else{
|
||||
res.json({ message: 'Product removed from cart successfully' });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error removing product from cart' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.getCartDetails = async (req, res) => {
|
||||
try {
|
||||
const user = await User.findById(req.user.id);
|
||||
|
||||
if (!user || !user.myCart || user.myCart.length < 0) {
|
||||
return res.json({ cartItems: [], totalPrice: 0 }); // Handle empty cart
|
||||
}
|
||||
|
||||
const cartItems = user.myCart;
|
||||
let totalPrice = 0;
|
||||
|
||||
for (const item of cartItems) {
|
||||
const findItemPrice = await Product.findById(item.productId);
|
||||
const subtotal = findItemPrice.price * item.quantity;
|
||||
totalPrice += subtotal;
|
||||
item.price = findItemPrice.price;
|
||||
|
||||
// Add subtotal to the item object for clarity in response
|
||||
item.subtotal = subtotal;
|
||||
}
|
||||
|
||||
res.json({ cartItems, totalPrice });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error fetching cart details' });
|
||||
}
|
||||
};
|
@ -0,0 +1,139 @@
|
||||
const User = require("../models/User.js");
|
||||
const Product = require("../models/Product.js");
|
||||
const Order = require("../models/Order.js");
|
||||
const bcrypt = require("bcrypt");
|
||||
const auth = require("../auth.js");
|
||||
const {verify, verifyAdmin} = auth;
|
||||
|
||||
// Controllers
|
||||
|
||||
// Check email controller
|
||||
module.exports.checkEmailExists = (request, response, next) => {
|
||||
let reqBody = request.body;
|
||||
|
||||
User.find({email : reqBody.email})
|
||||
.then(result => {
|
||||
if(result.length > 0){
|
||||
return response.send(`User already exist!`);
|
||||
}else{
|
||||
next();
|
||||
}
|
||||
})
|
||||
.catch(error => response.send("Error occurred!"));
|
||||
}
|
||||
|
||||
// Register user controller
|
||||
module.exports.registerUser = (request, response) => {
|
||||
const reqBody = request.body;
|
||||
|
||||
const newUser = new User({
|
||||
email: reqBody.email,
|
||||
password: bcrypt.hashSync(reqBody.password, 10)
|
||||
})
|
||||
|
||||
newUser.save().then(save => {
|
||||
return response.send(`${reqBody.email} is now registered!`)
|
||||
}).catch(error => {
|
||||
return response.send("Error encountered during registration!");
|
||||
})
|
||||
}
|
||||
|
||||
// Login controller
|
||||
module.exports.loginUser = (request, response) => {
|
||||
const reqBody = request.body;
|
||||
|
||||
User.findOne({email : reqBody.email}).then(result => {
|
||||
if(result === null) {
|
||||
return response.send((`Email does not exist. Register first before logging in!`));
|
||||
}else{
|
||||
|
||||
const isPasswordCorrect = bcrypt.compareSync(reqBody.password, result.password);
|
||||
|
||||
if(isPasswordCorrect){
|
||||
|
||||
const token = auth.createAccessToken(result);
|
||||
|
||||
return response.send({accessToken: token});
|
||||
|
||||
}else{
|
||||
return response.send(`You incorrect password. Please try again!`);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// get current user details controller.
|
||||
exports.getCurrentUserDetails = async (req, res) => {
|
||||
try {
|
||||
const user = await User.findById(req.user.id, 'email');
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({ message: 'User not found' });
|
||||
}
|
||||
|
||||
res.json(user);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error fetching user details' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// set user to admin controller.
|
||||
exports.setUserAsAdmin = async (req, res) => {
|
||||
try {
|
||||
const { userId } = req.body;
|
||||
|
||||
// Find the user to update
|
||||
const user = await User.findById(userId);
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({ message: 'User not found' });
|
||||
}else if(user.isAdmin === true) {
|
||||
return res.status(404).json({ message: 'User already an Admin' });
|
||||
}
|
||||
|
||||
// Set the user's isAdmin property to true
|
||||
user.isAdmin = true;
|
||||
|
||||
// Save the updated user
|
||||
await user.save();
|
||||
|
||||
res.json({ message: 'User set as admin successfully' });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error setting user as admin' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// get current user orders controller.
|
||||
exports.getCurrentUserOrders = async (req, res) => {
|
||||
try {
|
||||
const user = await User.findById(req.user.id, 'orders');
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({ message: 'User not found' });
|
||||
}
|
||||
|
||||
res.json(user);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error fetching orders' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// retrieve all orders controller
|
||||
module.exports.getAllOrders = async (req, res) => {
|
||||
try {
|
||||
// Fetch all products from the database
|
||||
const orders = await Order.find();
|
||||
|
||||
res.json(orders);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error retrieving Orders' });
|
||||
}
|
||||
};
|
@ -0,0 +1,35 @@
|
||||
const express = require("express");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const userRoutes = require("./routes/userRoutes.js");
|
||||
const productRoutes = require("./routes/productRoutes.js");
|
||||
const cors = require("cors");
|
||||
|
||||
const port = 2024;
|
||||
|
||||
const app = express();
|
||||
|
||||
mongoose.connect('mongodb+srv://admin:admin@b330juan.sxv2kqg.mongodb.net/Capstone-2?retryWrites=true&w=majority');
|
||||
|
||||
let connect = mongoose.connection;
|
||||
|
||||
connect.on("error", console.error.bind(console, "Connection error!"));
|
||||
|
||||
connect.once("open", () => {
|
||||
console.log("Connected with the Database!");
|
||||
});
|
||||
|
||||
|
||||
// Middlewares
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({extended : true}));
|
||||
app.use(cors());
|
||||
app.use("/users", userRoutes);
|
||||
app.use("/products", productRoutes);
|
||||
|
||||
|
||||
|
||||
// run the server to a specific port:
|
||||
app.listen(port, () => {
|
||||
console.log(`API is now online on port ${port}!`);
|
||||
})
|
@ -0,0 +1,34 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
|
||||
const orderSchema = new mongoose.Schema({
|
||||
userId: {
|
||||
type: String
|
||||
},
|
||||
products : [
|
||||
{
|
||||
productId: {
|
||||
type: String,
|
||||
required: [true, "Product id is required!"]
|
||||
},
|
||||
quantity : {
|
||||
type : Number,
|
||||
default : 1
|
||||
},
|
||||
price:{
|
||||
type: Number
|
||||
}
|
||||
}
|
||||
],
|
||||
totalAmount: {
|
||||
type: Number,
|
||||
},
|
||||
purchasedOn : {
|
||||
type: Date,
|
||||
default : new Date()
|
||||
}
|
||||
})
|
||||
|
||||
const Order = mongoose.model("orders", orderSchema);
|
||||
|
||||
module.exports = Order;
|
@ -0,0 +1,33 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
|
||||
const productSchema = new mongoose.Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: [true, "Product name is required!"]
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: [true, "Description is required!"]
|
||||
},
|
||||
price: {
|
||||
type: Number,
|
||||
required: [true, "Price is required!"]
|
||||
},
|
||||
isActive: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
createdOn : {
|
||||
type: Date,
|
||||
default : new Date()
|
||||
},
|
||||
inventory: {
|
||||
type: Number,
|
||||
default: 1
|
||||
}
|
||||
})
|
||||
|
||||
const Product = mongoose.model("products", productSchema);
|
||||
|
||||
module.exports = Product;
|
@ -0,0 +1,27 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
|
||||
const userSchema = new mongoose.Schema({
|
||||
email: {
|
||||
type: String,
|
||||
required: [true, "Email is required!"]
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
required: [true, "Password is required!"]
|
||||
},
|
||||
isAdmin: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
orders: {
|
||||
type: Array
|
||||
},
|
||||
myCart: {
|
||||
type: Array
|
||||
}
|
||||
})
|
||||
|
||||
const User = mongoose.model("users", userSchema);
|
||||
|
||||
module.exports = User;
|
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../color-support/bin.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../color-support/bin.js" "$@"
|
||||
fi
|
@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\color-support\bin.js" %*
|
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../color-support/bin.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../color-support/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../color-support/bin.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../color-support/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../mime/cli.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../mime/cli.js" "$@"
|
||||
fi
|
@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\mime\cli.js" %*
|
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../mime/cli.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../mime/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../mime/cli.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../mime/cli.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../mkdirp/bin/cmd.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../mkdirp/bin/cmd.js" "$@"
|
||||
fi
|
@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\mkdirp\bin\cmd.js" %*
|
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../mkdirp/bin/cmd.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" "$@"
|
||||
else
|
||||
exec node "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" "$@"
|
||||
fi
|
@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\@mapbox\node-pre-gyp\bin\node-pre-gyp" %*
|
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../nopt/bin/nopt.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../nopt/bin/nopt.js" "$@"
|
||||
fi
|
@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\nopt\bin\nopt.js" %*
|
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../nopt/bin/nopt.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../nopt/bin/nopt.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../nopt/bin/nopt.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../nopt/bin/nopt.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../rimraf/bin.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../rimraf/bin.js" "$@"
|
||||
fi
|
@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\rimraf\bin.js" %*
|
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../rimraf/bin.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../rimraf/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../rimraf/bin.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../rimraf/bin.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*|*MINGW*|*MSYS*)
|
||||
if command -v cygpath > /dev/null 2>&1; then
|
||||
basedir=`cygpath -w "$basedir"`
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../semver/bin/semver.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../semver/bin/semver.js" "$@"
|
||||
fi
|
@ -0,0 +1,17 @@
|
||||
@ECHO off
|
||||
GOTO start
|
||||
:find_dp0
|
||||
SET dp0=%~dp0
|
||||
EXIT /b
|
||||
:start
|
||||
SETLOCAL
|
||||
CALL :find_dp0
|
||||
|
||||
IF EXIST "%dp0%\node.exe" (
|
||||
SET "_prog=%dp0%\node.exe"
|
||||
) ELSE (
|
||||
SET "_prog=node"
|
||||
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
)
|
||||
|
||||
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\semver\bin\semver.js" %*
|
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
}
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../semver/bin/semver.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
exit $ret
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,510 @@
|
||||
# node-pre-gyp changelog
|
||||
|
||||
## 1.0.11
|
||||
- Fixes dependabot alert [CVE-2021-44906](https://nvd.nist.gov/vuln/detail/CVE-2021-44906)
|
||||
|
||||
## 1.0.10
|
||||
- Upgraded minimist to 1.2.6 to address dependabot alert [CVE-2021-44906](https://nvd.nist.gov/vuln/detail/CVE-2021-44906)
|
||||
|
||||
## 1.0.9
|
||||
- Upgraded node-fetch to 2.6.7 to address [CVE-2022-0235](https://www.cve.org/CVERecord?id=CVE-2022-0235)
|
||||
- Upgraded detect-libc to 2.0.0 to use non-blocking NodeJS(>=12) Report API
|
||||
|
||||
## 1.0.8
|
||||
- Downgraded npmlog to maintain node v10 and v8 support (https://github.com/mapbox/node-pre-gyp/pull/624)
|
||||
|
||||
## 1.0.7
|
||||
- Upgraded nyc and npmlog to address https://github.com/advisories/GHSA-93q8-gq69-wqmw
|
||||
|
||||
## 1.0.6
|
||||
- Added node v17 to the internal node releases listing
|
||||
- Upgraded various dependencies declared in package.json to latest major versions (node-fetch from 2.6.1 to 2.6.5, npmlog from 4.1.2 to 5.01, semver from 7.3.4 to 7.3.5, and tar from 6.1.0 to 6.1.11)
|
||||
- Fixed bug in `staging_host` parameter (https://github.com/mapbox/node-pre-gyp/pull/590)
|
||||
|
||||
|
||||
## 1.0.5
|
||||
- Fix circular reference warning with node >= v14
|
||||
|
||||
## 1.0.4
|
||||
- Added node v16 to the internal node releases listing
|
||||
|
||||
## 1.0.3
|
||||
- Improved support configuring s3 uploads (solves https://github.com/mapbox/node-pre-gyp/issues/571)
|
||||
- New options added in https://github.com/mapbox/node-pre-gyp/pull/576: 'bucket', 'region', and `s3ForcePathStyle`
|
||||
|
||||
## 1.0.2
|
||||
- Fixed regression in proxy support (https://github.com/mapbox/node-pre-gyp/issues/572)
|
||||
|
||||
## 1.0.1
|
||||
- Switched from mkdirp@1.0.4 to make-dir@3.1.0 to avoid this bug: https://github.com/isaacs/node-mkdirp/issues/31
|
||||
|
||||
## 1.0.0
|
||||
- Module is now name-spaced at `@mapbox/node-pre-gyp` and the original `node-pre-gyp` is deprecated.
|
||||
- New: support for staging and production s3 targets (see README.md)
|
||||
- BREAKING: no longer supporting `node_pre_gyp_accessKeyId` & `node_pre_gyp_secretAccessKey`, use `AWS_ACCESS_KEY_ID` & `AWS_SECRET_ACCESS_KEY` instead to authenticate against s3 for `info`, `publish`, and `unpublish` commands.
|
||||
- Dropped node v6 support, added node v14 support
|
||||
- Switched tests to use mapbox-owned bucket for testing
|
||||
- Added coverage tracking and linting with eslint
|
||||
- Added back support for symlinks inside the tarball
|
||||
- Upgraded all test apps to N-API/node-addon-api
|
||||
- New: support for staging and production s3 targets (see README.md)
|
||||
- Added `node_pre_gyp_s3_host` env var which has priority over the `--s3_host` option or default.
|
||||
- Replaced needle with node-fetch
|
||||
- Added proxy support for node-fetch
|
||||
- Upgraded to mkdirp@1.x
|
||||
|
||||
## 0.17.0
|
||||
- Got travis + appveyor green again
|
||||
- Added support for more node versions
|
||||
|
||||
## 0.16.0
|
||||
|
||||
- Added Node 15 support in the local database (https://github.com/mapbox/node-pre-gyp/pull/520)
|
||||
|
||||
## 0.15.0
|
||||
|
||||
- Bump dependency on `mkdirp` from `^0.5.1` to `^0.5.3` (https://github.com/mapbox/node-pre-gyp/pull/492)
|
||||
- Bump dependency on `needle` from `^2.2.1` to `^2.5.0` (https://github.com/mapbox/node-pre-gyp/pull/502)
|
||||
- Added Node 14 support in the local database (https://github.com/mapbox/node-pre-gyp/pull/501)
|
||||
|
||||
## 0.14.0
|
||||
|
||||
- Defer modules requires in napi.js (https://github.com/mapbox/node-pre-gyp/pull/434)
|
||||
- Bump dependency on `tar` from `^4` to `^4.4.2` (https://github.com/mapbox/node-pre-gyp/pull/454)
|
||||
- Support extracting compiled binary from local offline mirror (https://github.com/mapbox/node-pre-gyp/pull/459)
|
||||
- Added Node 13 support in the local database (https://github.com/mapbox/node-pre-gyp/pull/483)
|
||||
|
||||
## 0.13.0
|
||||
|
||||
- Added Node 12 support in the local database (https://github.com/mapbox/node-pre-gyp/pull/449)
|
||||
|
||||
## 0.12.0
|
||||
|
||||
- Fixed double-build problem with node v10 (https://github.com/mapbox/node-pre-gyp/pull/428)
|
||||
- Added node 11 support in the local database (https://github.com/mapbox/node-pre-gyp/pull/422)
|
||||
|
||||
## 0.11.0
|
||||
|
||||
- Fixed double-install problem with node v10
|
||||
- Significant N-API improvements (https://github.com/mapbox/node-pre-gyp/pull/405)
|
||||
|
||||
## 0.10.3
|
||||
|
||||
- Now will use `request` over `needle` if request is installed. By default `needle` is used for `https`. This should unbreak proxy support that regressed in v0.9.0
|
||||
|
||||
## 0.10.2
|
||||
|
||||
- Fixed rc/deep-extent security vulnerability
|
||||
- Fixed broken reinstall script do to incorrectly named get_best_napi_version
|
||||
|
||||
## 0.10.1
|
||||
|
||||
- Fix needle error event (@medns)
|
||||
|
||||
## 0.10.0
|
||||
|
||||
- Allow for a single-level module path when packing @allenluce (https://github.com/mapbox/node-pre-gyp/pull/371)
|
||||
- Log warnings instead of errors when falling back @xzyfer (https://github.com/mapbox/node-pre-gyp/pull/366)
|
||||
- Add Node.js v10 support to tests (https://github.com/mapbox/node-pre-gyp/pull/372)
|
||||
- Remove retire.js from CI (https://github.com/mapbox/node-pre-gyp/pull/372)
|
||||
- Remove support for Node.js v4 due to [EOL on April 30th, 2018](https://github.com/nodejs/Release/blob/7dd52354049cae99eed0e9fe01345b0722a86fde/schedule.json#L14)
|
||||
- Update appveyor tests to install default NPM version instead of NPM v2.x for all Windows builds (https://github.com/mapbox/node-pre-gyp/pull/375)
|
||||
|
||||
## 0.9.1
|
||||
|
||||
- Fixed regression (in v0.9.0) with support for http redirects @allenluce (https://github.com/mapbox/node-pre-gyp/pull/361)
|
||||
|
||||
## 0.9.0
|
||||
|
||||
- Switched from using `request` to `needle` to reduce size of module deps (https://github.com/mapbox/node-pre-gyp/pull/350)
|
||||
|
||||
## 0.8.0
|
||||
|
||||
- N-API support (@inspiredware)
|
||||
|
||||
## 0.7.1
|
||||
|
||||
- Upgraded to tar v4.x
|
||||
|
||||
## 0.7.0
|
||||
|
||||
- Updated request and hawk (#347)
|
||||
- Dropped node v0.10.x support
|
||||
|
||||
## 0.6.40
|
||||
|
||||
- Improved error reporting if an install fails
|
||||
|
||||
## 0.6.39
|
||||
|
||||
- Support for node v9
|
||||
- Support for versioning on `{libc}` to allow binaries to work on non-glic linux systems like alpine linux
|
||||
|
||||
|
||||
## 0.6.38
|
||||
|
||||
- Maintaining compatibility (for v0.6.x series) with node v0.10.x
|
||||
|
||||
## 0.6.37
|
||||
|
||||
- Solved one part of #276: now now deduce the node ABI from the major version for node >= 2 even when not stored in the abi_crosswalk.json
|
||||
- Fixed docs to avoid mentioning the deprecated and dangerous `prepublish` in package.json (#291)
|
||||
- Add new node versions to crosswalk
|
||||
- Ported tests to use tape instead of mocha
|
||||
- Got appveyor tests passing by downgrading npm and node-gyp
|
||||
|
||||
## 0.6.36
|
||||
|
||||
- Removed the running of `testbinary` during install. Because this was regressed for so long, it is too dangerous to re-enable by default. Developers needing validation can call `node-pre-gyp testbinary` directory.
|
||||
- Fixed regression in v0.6.35 for electron installs (now skipping binary validation which is not yet supported for electron)
|
||||
|
||||
## 0.6.35
|
||||
|
||||
- No longer recommending `npm ls` in `prepublish` (#291)
|
||||
- Fixed testbinary command (#283) @szdavid92
|
||||
|
||||
## 0.6.34
|
||||
|
||||
- Added new node versions to crosswalk, including v8
|
||||
- Upgraded deps to latest versions, started using `^` instead of `~` for all deps.
|
||||
|
||||
## 0.6.33
|
||||
|
||||
- Improved support for yarn
|
||||
|
||||
## 0.6.32
|
||||
|
||||
- Honor npm configuration for CA bundles (@heikkipora)
|
||||
- Add node-pre-gyp and npm versions to user agent (@addaleax)
|
||||
- Updated various deps
|
||||
- Add known node version for v7.x
|
||||
|
||||
## 0.6.31
|
||||
|
||||
- Updated various deps
|
||||
|
||||
## 0.6.30
|
||||
|
||||
- Update to npmlog@4.x and semver@5.3.x
|
||||
- Add known node version for v6.5.0
|
||||
|
||||
## 0.6.29
|
||||
|
||||
- Add known node versions for v0.10.45, v0.12.14, v4.4.4, v5.11.1, and v6.1.0
|
||||
|
||||
## 0.6.28
|
||||
|
||||
- Now more verbose when remote binaries are not available. This is needed since npm is increasingly more quiet by default
|
||||
and users need to know why builds are falling back to source compiles that might then error out.
|
||||
|
||||
## 0.6.27
|
||||
|
||||
- Add known node version for node v6
|
||||
- Stopped bundling dependencies
|
||||
- Documented method for module authors to avoid bundling node-pre-gyp
|
||||
- See https://github.com/mapbox/node-pre-gyp/tree/master#configuring for details
|
||||
|
||||
## 0.6.26
|
||||
|
||||
- Skip validation for nw runtime (https://github.com/mapbox/node-pre-gyp/pull/181) via @fleg
|
||||
|
||||
## 0.6.25
|
||||
|
||||
- Improved support for auto-detection of electron runtime in `node-pre-gyp.find()`
|
||||
- Pull request from @enlight - https://github.com/mapbox/node-pre-gyp/pull/187
|
||||
- Add known node version for 4.4.1 and 5.9.1
|
||||
|
||||
## 0.6.24
|
||||
|
||||
- Add known node version for 5.8.0, 5.9.0, and 4.4.0.
|
||||
|
||||
## 0.6.23
|
||||
|
||||
- Add known node version for 0.10.43, 0.12.11, 4.3.2, and 5.7.1.
|
||||
|
||||
## 0.6.22
|
||||
|
||||
- Add known node version for 4.3.1, and 5.7.0.
|
||||
|
||||
## 0.6.21
|
||||
|
||||
- Add known node version for 0.10.42, 0.12.10, 4.3.0, and 5.6.0.
|
||||
|
||||
## 0.6.20
|
||||
|
||||
- Add known node version for 4.2.5, 4.2.6, 5.4.0, 5.4.1,and 5.5.0.
|
||||
|
||||
## 0.6.19
|
||||
|
||||
- Add known node version for 4.2.4
|
||||
|
||||
## 0.6.18
|
||||
|
||||
- Add new known node versions for 0.10.x, 0.12.x, 4.x, and 5.x
|
||||
|
||||
## 0.6.17
|
||||
|
||||
- Re-tagged to fix packaging problem of `Error: Cannot find module 'isarray'`
|
||||
|
||||
## 0.6.16
|
||||
|
||||
- Added known version in crosswalk for 5.1.0.
|
||||
|
||||
## 0.6.15
|
||||
|
||||
- Upgraded tar-pack (https://github.com/mapbox/node-pre-gyp/issues/182)
|
||||
- Support custom binary hosting mirror (https://github.com/mapbox/node-pre-gyp/pull/170)
|
||||
- Added known version in crosswalk for 4.2.2.
|
||||
|
||||
## 0.6.14
|
||||
|
||||
- Added node 5.x version
|
||||
|
||||
## 0.6.13
|
||||
|
||||
- Added more known node 4.x versions
|
||||
|
||||
## 0.6.12
|
||||
|
||||
- Added support for [Electron](http://electron.atom.io/). Just pass the `--runtime=electron` flag when building/installing. Thanks @zcbenz
|
||||
|
||||
## 0.6.11
|
||||
|
||||
- Added known node and io.js versions including more 3.x and 4.x versions
|
||||
|
||||
## 0.6.10
|
||||
|
||||
- Added known node and io.js versions including 3.x and 4.x versions
|
||||
- Upgraded `tar` dep
|
||||
|
||||
## 0.6.9
|
||||
|
||||
- Upgraded `rc` dep
|
||||
- Updated known io.js version: v2.4.0
|
||||
|
||||
## 0.6.8
|
||||
|
||||
- Upgraded `semver` and `rimraf` deps
|
||||
- Updated known node and io.js versions
|
||||
|
||||
## 0.6.7
|
||||
|
||||
- Fixed `node_abi` versions for io.js 1.1.x -> 1.8.x (should be 43, but was stored as 42) (refs https://github.com/iojs/build/issues/94)
|
||||
|
||||
## 0.6.6
|
||||
|
||||
- Updated with known io.js 2.0.0 version
|
||||
|
||||
## 0.6.5
|
||||
|
||||
- Now respecting `npm_config_node_gyp` (https://github.com/npm/npm/pull/4887)
|
||||
- Updated to semver@4.3.2
|
||||
- Updated known node v0.12.x versions and io.js 1.x versions.
|
||||
|
||||
## 0.6.4
|
||||
|
||||
- Improved support for `io.js` (@fengmk2)
|
||||
- Test coverage improvements (@mikemorris)
|
||||
- Fixed support for `--dist-url` that regressed in 0.6.3
|
||||
|
||||
## 0.6.3
|
||||
|
||||
- Added support for passing raw options to node-gyp using `--` separator. Flags passed after
|
||||
the `--` to `node-pre-gyp configure` will be passed directly to gyp while flags passed
|
||||
after the `--` will be passed directly to make/visual studio.
|
||||
- Added `node-pre-gyp configure` command to be able to call `node-gyp configure` directly
|
||||
- Fix issue with require validation not working on windows 7 (@edgarsilva)
|
||||
|
||||
## 0.6.2
|
||||
|
||||
- Support for io.js >= v1.0.2
|
||||
- Deferred require of `request` and `tar` to help speed up command line usage of `node-pre-gyp`.
|
||||
|
||||
## 0.6.1
|
||||
|
||||
- Fixed bundled `tar` version
|
||||
|
||||
## 0.6.0
|
||||
|
||||
- BREAKING: node odd releases like v0.11.x now use `major.minor.patch` for `{node_abi}` instead of `NODE_MODULE_VERSION` (#124)
|
||||
- Added support for `toolset` option in versioning. By default is an empty string but `--toolset` can be passed to publish or install to select alternative binaries that target a custom toolset like C++11. For example to target Visual Studio 2014 modules like node-sqlite3 use `--toolset=v140`.
|
||||
- Added support for `--no-rollback` option to request that a failed binary test does not remove the binary module leaves it in place.
|
||||
- Added support for `--update-binary` option to request an existing binary be re-installed and the check for a valid local module be skipped.
|
||||
- Added support for passing build options from `npm` through `node-pre-gyp` to `node-gyp`: `--nodedir`, `--disturl`, `--python`, and `--msvs_version`
|
||||
|
||||
## 0.5.31
|
||||
|
||||
- Added support for deducing node_abi for node.js runtime from previous release if the series is even
|
||||
- Added support for --target=0.10.33
|
||||
|
||||
## 0.5.30
|
||||
|
||||
- Repackaged with latest bundled deps
|
||||
|
||||
## 0.5.29
|
||||
|
||||
- Added support for semver `build`.
|
||||
- Fixed support for downloading from urls that include `+`.
|
||||
|
||||
## 0.5.28
|
||||
|
||||
- Now reporting unix style paths only in reveal command
|
||||
|
||||
## 0.5.27
|
||||
|
||||
- Fixed support for auto-detecting s3 bucket name when it contains `.` - @taavo
|
||||
- Fixed support for installing when path contains a `'` - @halfdan
|
||||
- Ported tests to mocha
|
||||
|
||||
## 0.5.26
|
||||
|
||||
- Fix node-webkit support when `--target` option is not provided
|
||||
|
||||
## 0.5.25
|
||||
|
||||
- Fix bundling of deps
|
||||
|
||||
## 0.5.24
|
||||
|
||||
- Updated ABI crosswalk to incldue node v0.10.30 and v0.10.31
|
||||
|
||||
## 0.5.23
|
||||
|
||||
- Added `reveal` command. Pass no options to get all versioning data as json. Pass a second arg to grab a single versioned property value
|
||||
- Added support for `--silent` (shortcut for `--loglevel=silent`)
|
||||
|
||||
## 0.5.22
|
||||
|
||||
- Fixed node-webkit versioning name (NOTE: node-webkit support still experimental)
|
||||
|
||||
## 0.5.21
|
||||
|
||||
- New package to fix `shasum check failed` error with v0.5.20
|
||||
|
||||
## 0.5.20
|
||||
|
||||
- Now versioning node-webkit binaries based on major.minor.patch - assuming no compatible ABI across versions (#90)
|
||||
|
||||
## 0.5.19
|
||||
|
||||
- Updated to know about more node-webkit releases
|
||||
|
||||
## 0.5.18
|
||||
|
||||
- Updated to know about more node-webkit releases
|
||||
|
||||
## 0.5.17
|
||||
|
||||
- Updated to know about node v0.10.29 release
|
||||
|
||||
## 0.5.16
|
||||
|
||||
- Now supporting all aws-sdk configuration parameters (http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html) (#86)
|
||||
|
||||
## 0.5.15
|
||||
|
||||
- Fixed installation of windows packages sub directories on unix systems (#84)
|
||||
|
||||
## 0.5.14
|
||||
|
||||
- Finished support for cross building using `--target_platform` option (#82)
|
||||
- Now skipping binary validation on install if target arch/platform do not match the host.
|
||||
- Removed multi-arch validing for OS X since it required a FAT node.js binary
|
||||
|
||||
## 0.5.13
|
||||
|
||||
- Fix problem in 0.5.12 whereby the wrong versions of mkdirp and semver where bundled.
|
||||
|
||||
## 0.5.12
|
||||
|
||||
- Improved support for node-webkit (@Mithgol)
|
||||
|
||||
## 0.5.11
|
||||
|
||||
- Updated target versions listing
|
||||
|
||||
## 0.5.10
|
||||
|
||||
- Fixed handling of `-debug` flag passed directory to node-pre-gyp (#72)
|
||||
- Added optional second arg to `node_pre_gyp.find` to customize the default versioning options used to locate the runtime binary
|
||||
- Failed install due to `testbinary` check failure no longer leaves behind binary (#70)
|
||||
|
||||
## 0.5.9
|
||||
|
||||
- Fixed regression in `testbinary` command causing installs to fail on windows with 0.5.7 (#60)
|
||||
|
||||
## 0.5.8
|
||||
|
||||
- Started bundling deps
|
||||
|
||||
## 0.5.7
|
||||
|
||||
- Fixed the `testbinary` check, which is used to determine whether to re-download or source compile, to work even in complex dependency situations (#63)
|
||||
- Exposed the internal `testbinary` command in node-pre-gyp command line tool
|
||||
- Fixed minor bug so that `fallback_to_build` option is always respected
|
||||
|
||||
## 0.5.6
|
||||
|
||||
- Added support for versioning on the `name` value in `package.json` (#57).
|
||||
- Moved to using streams for reading tarball when publishing (#52)
|
||||
|
||||
## 0.5.5
|
||||
|
||||
- Improved binary validation that also now works with node-webkit (@Mithgol)
|
||||
- Upgraded test apps to work with node v0.11.x
|
||||
- Improved test coverage
|
||||
|
||||
## 0.5.4
|
||||
|
||||
- No longer depends on external install of node-gyp for compiling builds.
|
||||
|
||||
## 0.5.3
|
||||
|
||||
- Reverted fix for debian/nodejs since it broke windows (#45)
|
||||
|
||||
## 0.5.2
|
||||
|
||||
- Support for debian systems where the node binary is named `nodejs` (#45)
|
||||
- Added `bin/node-pre-gyp.cmd` to be able to run command on windows locally (npm creates an .npm automatically when globally installed)
|
||||
- Updated abi-crosswalk with node v0.10.26 entry.
|
||||
|
||||
## 0.5.1
|
||||
|
||||
- Various minor bug fixes, several improving windows support for publishing.
|
||||
|
||||
## 0.5.0
|
||||
|
||||
- Changed property names in `binary` object: now required are `module_name`, `module_path`, and `host`.
|
||||
- Now `module_path` supports versioning, which allows developers to opt-in to using a versioned install path (#18).
|
||||
- Added `remote_path` which also supports versioning.
|
||||
- Changed `remote_uri` to `host`.
|
||||
|
||||
## 0.4.2
|
||||
|
||||
- Added support for `--target` flag to request cross-compile against a specific node/node-webkit version.
|
||||
- Added preliminary support for node-webkit
|
||||
- Fixed support for `--target_arch` option being respected in all cases.
|
||||
|
||||
## 0.4.1
|
||||
|
||||
- Fixed exception when only stderr is available in binary test (@bendi / #31)
|
||||
|
||||
## 0.4.0
|
||||
|
||||
- Enforce only `https:` based remote publishing access.
|
||||
- Added `node-pre-gyp info` command to display listing of published binaries
|
||||
- Added support for changing the directory node-pre-gyp should build in with the `-C/--directory` option.
|
||||
- Added support for S3 prefixes.
|
||||
|
||||
## 0.3.1
|
||||
|
||||
- Added `unpublish` command.
|
||||
- Fixed module path construction in tests.
|
||||
- Added ability to disable falling back to build behavior via `npm install --fallback-to-build=false` which overrides setting in a depedencies package.json `install` target.
|
||||
|
||||
## 0.3.0
|
||||
|
||||
- Support for packaging all files in `module_path` directory - see `app4` for example
|
||||
- Added `testpackage` command.
|
||||
- Changed `clean` command to only delete `.node` not entire `build` directory since node-gyp will handle that.
|
||||
- `.node` modules must be in a folder of there own since tar-pack will remove everything when it unpacks.
|
@ -0,0 +1,27 @@
|
||||
Copyright (c), Mapbox
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of node-pre-gyp nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -0,0 +1,742 @@
|
||||
# @mapbox/node-pre-gyp
|
||||
|
||||
#### @mapbox/node-pre-gyp makes it easy to publish and install Node.js C++ addons from binaries
|
||||
|
||||
[![Build Status](https://travis-ci.com/mapbox/node-pre-gyp.svg?branch=master)](https://travis-ci.com/mapbox/node-pre-gyp)
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/3nxewb425y83c0gv)](https://ci.appveyor.com/project/Mapbox/node-pre-gyp)
|
||||
|
||||
`@mapbox/node-pre-gyp` stands between [npm](https://github.com/npm/npm) and [node-gyp](https://github.com/Tootallnate/node-gyp) and offers a cross-platform method of binary deployment.
|
||||
|
||||
### Special note on previous package
|
||||
|
||||
On Feb 9th, 2021 `@mapbox/node-pre-gyp@1.0.0` was [released](./CHANGELOG.md). Older, unscoped versions that are not part of the `@mapbox` org are deprecated and only `@mapbox/node-pre-gyp` will see updates going forward. To upgrade to the new package do:
|
||||
|
||||
```
|
||||
npm uninstall node-pre-gyp --save
|
||||
npm install @mapbox/node-pre-gyp --save
|
||||
```
|
||||
|
||||
### Features
|
||||
|
||||
- A command line tool called `node-pre-gyp` that can install your package's C++ module from a binary.
|
||||
- A variety of developer targeted commands for packaging, testing, and publishing binaries.
|
||||
- A JavaScript module that can dynamically require your installed binary: `require('@mapbox/node-pre-gyp').find`
|
||||
|
||||
For a hello world example of a module packaged with `node-pre-gyp` see <https://github.com/springmeyer/node-addon-example> and [the wiki ](https://github.com/mapbox/node-pre-gyp/wiki/Modules-using-node-pre-gyp) for real world examples.
|
||||
|
||||
## Credits
|
||||
|
||||
- The module is modeled after [node-gyp](https://github.com/Tootallnate/node-gyp) by [@Tootallnate](https://github.com/Tootallnate)
|
||||
- Motivation for initial development came from [@ErisDS](https://github.com/ErisDS) and the [Ghost Project](https://github.com/TryGhost/Ghost).
|
||||
- Development is sponsored by [Mapbox](https://www.mapbox.com/)
|
||||
|
||||
## FAQ
|
||||
|
||||
See the [Frequently Ask Questions](https://github.com/mapbox/node-pre-gyp/wiki/FAQ).
|
||||
|
||||
## Depends
|
||||
|
||||
- Node.js >= node v8.x
|
||||
|
||||
## Install
|
||||
|
||||
`node-pre-gyp` is designed to be installed as a local dependency of your Node.js C++ addon and accessed like:
|
||||
|
||||
./node_modules/.bin/node-pre-gyp --help
|
||||
|
||||
But you can also install it globally:
|
||||
|
||||
npm install @mapbox/node-pre-gyp -g
|
||||
|
||||
## Usage
|
||||
|
||||
### Commands
|
||||
|
||||
View all possible commands:
|
||||
|
||||
node-pre-gyp --help
|
||||
|
||||
- clean - Remove the entire folder containing the compiled .node module
|
||||
- install - Install pre-built binary for module
|
||||
- reinstall - Run "clean" and "install" at once
|
||||
- build - Compile the module by dispatching to node-gyp or nw-gyp
|
||||
- rebuild - Run "clean" and "build" at once
|
||||
- package - Pack binary into tarball
|
||||
- testpackage - Test that the staged package is valid
|
||||
- publish - Publish pre-built binary
|
||||
- unpublish - Unpublish pre-built binary
|
||||
- info - Fetch info on published binaries
|
||||
|
||||
You can also chain commands:
|
||||
|
||||
node-pre-gyp clean build unpublish publish info
|
||||
|
||||
### Options
|
||||
|
||||
Options include:
|
||||
|
||||
- `-C/--directory`: run the command in this directory
|
||||
- `--build-from-source`: build from source instead of using pre-built binary
|
||||
- `--update-binary`: reinstall by replacing previously installed local binary with remote binary
|
||||
- `--runtime=node-webkit`: customize the runtime: `node`, `electron` and `node-webkit` are the valid options
|
||||
- `--fallback-to-build`: fallback to building from source if pre-built binary is not available
|
||||
- `--target=0.4.0`: Pass the target node or node-webkit version to compile against
|
||||
- `--target_arch=ia32`: Pass the target arch and override the host `arch`. Any value that is [supported by Node.js](https://nodejs.org/api/os.html#osarch) is valid.
|
||||
- `--target_platform=win32`: Pass the target platform and override the host `platform`. Valid values are `linux`, `darwin`, `win32`, `sunos`, `freebsd`, `openbsd`, and `aix`.
|
||||
|
||||
Both `--build-from-source` and `--fallback-to-build` can be passed alone or they can provide values. You can pass `--fallback-to-build=false` to override the option as declared in package.json. In addition to being able to pass `--build-from-source` you can also pass `--build-from-source=myapp` where `myapp` is the name of your module.
|
||||
|
||||
For example: `npm install --build-from-source=myapp`. This is useful if:
|
||||
|
||||
- `myapp` is referenced in the package.json of a larger app and therefore `myapp` is being installed as a dependency with `npm install`.
|
||||
- The larger app also depends on other modules installed with `node-pre-gyp`
|
||||
- You only want to trigger a source compile for `myapp` and the other modules.
|
||||
|
||||
### Configuring
|
||||
|
||||
This is a guide to configuring your module to use node-pre-gyp.
|
||||
|
||||
#### 1) Add new entries to your `package.json`
|
||||
|
||||
- Add `@mapbox/node-pre-gyp` to `dependencies`
|
||||
- Add `aws-sdk` as a `devDependency`
|
||||
- Add a custom `install` script
|
||||
- Declare a `binary` object
|
||||
|
||||
This looks like:
|
||||
|
||||
```js
|
||||
"dependencies" : {
|
||||
"@mapbox/node-pre-gyp": "1.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"aws-sdk": "2.x"
|
||||
}
|
||||
"scripts": {
|
||||
"install": "node-pre-gyp install --fallback-to-build"
|
||||
},
|
||||
"binary": {
|
||||
"module_name": "your_module",
|
||||
"module_path": "./lib/binding/",
|
||||
"host": "https://your_module.s3-us-west-1.amazonaws.com"
|
||||
}
|
||||
```
|
||||
|
||||
For a full example see [node-addon-examples's package.json](https://github.com/springmeyer/node-addon-example/blob/master/package.json).
|
||||
|
||||
Let's break this down:
|
||||
|
||||
- Dependencies need to list `node-pre-gyp`
|
||||
- Your devDependencies should list `aws-sdk` so that you can run `node-pre-gyp publish` locally or a CI system. We recommend using `devDependencies` only since `aws-sdk` is large and not needed for `node-pre-gyp install` since it only uses http to fetch binaries
|
||||
- Your `scripts` section should override the `install` target with `"install": "node-pre-gyp install --fallback-to-build"`. This allows node-pre-gyp to be used instead of the default npm behavior of always source compiling with `node-gyp` directly.
|
||||
- Your package.json should contain a `binary` section describing key properties you provide to allow node-pre-gyp to package optimally. They are detailed below.
|
||||
|
||||
Note: in the past we recommended putting `@mapbox/node-pre-gyp` in the `bundledDependencies`, but we no longer recommend this. In the past there were npm bugs (with node versions 0.10.x) that could lead to node-pre-gyp not being available at the right time during install (unless we bundled). This should no longer be the case. Also, for a time we recommended using `"preinstall": "npm install @mapbox/node-pre-gyp"` as an alternative method to avoid needing to bundle. But this did not behave predictably across all npm versions - see https://github.com/mapbox/node-pre-gyp/issues/260 for the details. So we do not recommend using `preinstall` to install `@mapbox/node-pre-gyp`. More history on this at https://github.com/strongloop/fsevents/issues/157#issuecomment-265545908.
|
||||
|
||||
##### The `binary` object has three required properties
|
||||
|
||||
###### module_name
|
||||
|
||||
The name of your native node module. This value must:
|
||||
|
||||
- Match the name passed to [the NODE_MODULE macro](http://nodejs.org/api/addons.html#addons_hello_world)
|
||||
- Must be a valid C variable name (e.g. it cannot contain `-`)
|
||||
- Should not include the `.node` extension.
|
||||
|
||||
###### module_path
|
||||
|
||||
The location your native module is placed after a build. This should be an empty directory without other Javascript files. This entire directory will be packaged in the binary tarball. When installing from a remote package this directory will be overwritten with the contents of the tarball.
|
||||
|
||||
Note: This property supports variables based on [Versioning](#versioning).
|
||||
|
||||
###### host
|
||||
|
||||
A url to the remote location where you've published tarball binaries (must be `https` not `http`).
|
||||
|
||||
It is highly recommended that you use Amazon S3. The reasons are:
|
||||
|
||||
- Various node-pre-gyp commands like `publish` and `info` only work with an S3 host.
|
||||
- S3 is a very solid hosting platform for distributing large files.
|
||||
- We provide detail documentation for using [S3 hosting](#s3-hosting) with node-pre-gyp.
|
||||
|
||||
Why then not require S3? Because while some applications using node-pre-gyp need to distribute binaries as large as 20-30 MB, others might have very small binaries and might wish to store them in a GitHub repo. This is not recommended, but if an author really wants to host in a non-S3 location then it should be possible.
|
||||
|
||||
It should also be mentioned that there is an optional and entirely separate npm module called [node-pre-gyp-github](https://github.com/bchr02/node-pre-gyp-github) which is intended to complement node-pre-gyp and be installed along with it. It provides the ability to store and publish your binaries within your repositories GitHub Releases if you would rather not use S3 directly. Installation and usage instructions can be found [here](https://github.com/bchr02/node-pre-gyp-github), but the basic premise is that instead of using the ```node-pre-gyp publish``` command you would use ```node-pre-gyp-github publish```.
|
||||
|
||||
##### The `binary` object other optional S3 properties
|
||||
|
||||
If you are not using a standard s3 path like `bucket_name.s3(.-)region.amazonaws.com`, you might get an error on `publish` because node-pre-gyp extracts the region and bucket from the `host` url. For example, you may have an on-premises s3-compatible storage server, or may have configured a specific dns redirecting to an s3 endpoint. In these cases, you can explicitly set the `region` and `bucket` properties to tell node-pre-gyp to use these values instead of guessing from the `host` property. The following values can be used in the `binary` section:
|
||||
|
||||
###### host
|
||||
|
||||
The url to the remote server root location (must be `https` not `http`).
|
||||
|
||||
###### bucket
|
||||
|
||||
The bucket name where your tarball binaries should be located.
|
||||
|
||||
###### region
|
||||
|
||||
Your S3 server region.
|
||||
|
||||
###### s3ForcePathStyle
|
||||
|
||||
Set `s3ForcePathStyle` to true if the endpoint url should not be prefixed with the bucket name. If false (default), the server endpoint would be constructed as `bucket_name.your_server.com`.
|
||||
|
||||
##### The `binary` object has optional properties
|
||||
|
||||
###### remote_path
|
||||
|
||||
It **is recommended** that you customize this property. This is an extra path to use for publishing and finding remote tarballs. The default value for `remote_path` is `""` meaning that if you do not provide it then all packages will be published at the base of the `host`. It is recommended to provide a value like `./{name}/v{version}` to help organize remote packages in the case that you choose to publish multiple node addons to the same `host`.
|
||||
|
||||
Note: This property supports variables based on [Versioning](#versioning).
|
||||
|
||||
###### package_name
|
||||
|
||||
It is **not recommended** to override this property unless you are also overriding the `remote_path`. This is the versioned name of the remote tarball containing the binary `.node` module and any supporting files you've placed inside the `module_path` directory. Unless you specify `package_name` in your `package.json` then it defaults to `{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz` which allows your binary to work across node versions, platforms, and architectures. If you are using `remote_path` that is also versioned by `./{module_name}/v{version}` then you could remove these variables from the `package_name` and just use: `{node_abi}-{platform}-{arch}.tar.gz`. Then your remote tarball will be looked up at, for example, `https://example.com/your-module/v0.1.0/node-v11-linux-x64.tar.gz`.
|
||||
|
||||
Avoiding the version of your module in the `package_name` and instead only embedding in a directory name can be useful when you want to make a quick tag of your module that does not change any C++ code. In this case you can just copy binaries to the new version behind the scenes like:
|
||||
|
||||
```sh
|
||||
aws s3 sync --acl public-read s3://mapbox-node-binary/sqlite3/v3.0.3/ s3://mapbox-node-binary/sqlite3/v3.0.4/
|
||||
```
|
||||
|
||||
Note: This property supports variables based on [Versioning](#versioning).
|
||||
|
||||
#### 2) Add a new target to binding.gyp
|
||||
|
||||
`node-pre-gyp` calls out to `node-gyp` to compile the module and passes variables along like [module_name](#module_name) and [module_path](#module_path).
|
||||
|
||||
A new target must be added to `binding.gyp` that moves the compiled `.node` module from `./build/Release/module_name.node` into the directory specified by `module_path`.
|
||||
|
||||
Add a target like this at the end of your `targets` list:
|
||||
|
||||
```js
|
||||
{
|
||||
"target_name": "action_after_build",
|
||||
"type": "none",
|
||||
"dependencies": [ "<(module_name)" ],
|
||||
"copies": [
|
||||
{
|
||||
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
|
||||
"destination": "<(module_path)"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
For a full example see [node-addon-example's binding.gyp](https://github.com/springmeyer/node-addon-example/blob/2ff60a8ded7f042864ad21db00c3a5a06cf47075/binding.gyp).
|
||||
|
||||
#### 3) Dynamically require your `.node`
|
||||
|
||||
Inside the main js file that requires your addon module you are likely currently doing:
|
||||
|
||||
```js
|
||||
var binding = require('../build/Release/binding.node');
|
||||
```
|
||||
|
||||
or:
|
||||
|
||||
```js
|
||||
var bindings = require('./bindings')
|
||||
```
|
||||
|
||||
Change those lines to:
|
||||
|
||||
```js
|
||||
var binary = require('@mapbox/node-pre-gyp');
|
||||
var path = require('path');
|
||||
var binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json')));
|
||||
var binding = require(binding_path);
|
||||
```
|
||||
|
||||
For a full example see [node-addon-example's index.js](https://github.com/springmeyer/node-addon-example/blob/2ff60a8ded7f042864ad21db00c3a5a06cf47075/index.js#L1-L4)
|
||||
|
||||
#### 4) Build and package your app
|
||||
|
||||
Now build your module from source:
|
||||
|
||||
npm install --build-from-source
|
||||
|
||||
The `--build-from-source` tells `node-pre-gyp` to not look for a remote package and instead dispatch to node-gyp to build.
|
||||
|
||||
Now `node-pre-gyp` should now also be installed as a local dependency so the command line tool it offers can be found at `./node_modules/.bin/node-pre-gyp`.
|
||||
|
||||
#### 5) Test
|
||||
|
||||
Now `npm test` should work just as it did before.
|
||||
|
||||
#### 6) Publish the tarball
|
||||
|
||||
Then package your app:
|
||||
|
||||
./node_modules/.bin/node-pre-gyp package
|
||||
|
||||
Once packaged, now you can publish:
|
||||
|
||||
./node_modules/.bin/node-pre-gyp publish
|
||||
|
||||
Currently the `publish` command pushes your binary to S3. This requires:
|
||||
|
||||
- You have installed `aws-sdk` with `npm install aws-sdk`
|
||||
- You have created a bucket already.
|
||||
- The `host` points to an S3 http or https endpoint.
|
||||
- You have configured node-pre-gyp to read your S3 credentials (see [S3 hosting](#s3-hosting) for details).
|
||||
|
||||
You can also host your binaries elsewhere. To do this requires:
|
||||
|
||||
- You manually publish the binary created by the `package` command to an `https` endpoint
|
||||
- Ensure that the `host` value points to your custom `https` endpoint.
|
||||
|
||||
#### 7) Automate builds
|
||||
|
||||
Now you need to publish builds for all the platforms and node versions you wish to support. This is best automated.
|
||||
|
||||
- See [Appveyor Automation](#appveyor-automation) for how to auto-publish builds on Windows.
|
||||
- See [Travis Automation](#travis-automation) for how to auto-publish builds on OS X and Linux.
|
||||
|
||||
#### 8) You're done!
|
||||
|
||||
Now publish your module to the npm registry. Users will now be able to install your module from a binary.
|
||||
|
||||
What will happen is this:
|
||||
|
||||
1. `npm install <your package>` will pull from the npm registry
|
||||
2. npm will run the `install` script which will call out to `node-pre-gyp`
|
||||
3. `node-pre-gyp` will fetch the binary `.node` module and unpack in the right place
|
||||
4. Assuming that all worked, you are done
|
||||
|
||||
If a a binary was not available for a given platform and `--fallback-to-build` was used then `node-gyp rebuild` will be called to try to source compile the module.
|
||||
|
||||
#### 9) One more option
|
||||
|
||||
It may be that you want to work with two s3 buckets, one for staging and one for production; this
|
||||
arrangement makes it less likely to accidentally overwrite a production binary. It also allows the production
|
||||
environment to have more restrictive permissions than staging while still enabling publishing when
|
||||
developing and testing.
|
||||
|
||||
The binary.host property can be set at execution time. In order to do so all of the following conditions
|
||||
must be true.
|
||||
|
||||
- binary.host is falsey or not present
|
||||
- binary.staging_host is not empty
|
||||
- binary.production_host is not empty
|
||||
|
||||
If any of these checks fail then the operation will not perform execution time determination of the s3 target.
|
||||
|
||||
If the command being executed is either "publish" or "unpublish" then the default is set to `binary.staging_host`. In all other cases
|
||||
the default is `binary.production_host`.
|
||||
|
||||
The command-line options `--s3_host=staging` or `--s3_host=production` override the default. If `s3_host`
|
||||
is present and not `staging` or `production` an exception is thrown.
|
||||
|
||||
This allows installing from staging by specifying `--s3_host=staging`. And it requires specifying
|
||||
`--s3_option=production` in order to publish to, or unpublish from, production, making accidental errors less likely.
|
||||
|
||||
## Node-API Considerations
|
||||
|
||||
[Node-API](https://nodejs.org/api/n-api.html#n_api_node_api), which was previously known as N-API, is an ABI-stable alternative to previous technologies such as [nan](https://github.com/nodejs/nan) which are tied to a specific Node runtime engine. Node-API is Node runtime engine agnostic and guarantees modules created today will continue to run, without changes, into the future.
|
||||
|
||||
Using `node-pre-gyp` with Node-API projects requires a handful of additional configuration values and imposes some additional requirements.
|
||||
|
||||
The most significant difference is that an Node-API module can be coded to target multiple Node-API versions. Therefore, an Node-API module must declare in its `package.json` file which Node-API versions the module is designed to run against. In addition, since multiple builds may be required for a single module, path and file names must be specified in way that avoids naming conflicts.
|
||||
|
||||
### The `napi_versions` array property
|
||||
|
||||
A Node-API module must declare in its `package.json` file, the Node-API versions the module is intended to support. This is accomplished by including an `napi-versions` array property in the `binary` object. For example:
|
||||
|
||||
```js
|
||||
"binary": {
|
||||
"module_name": "your_module",
|
||||
"module_path": "your_module_path",
|
||||
"host": "https://your_bucket.s3-us-west-1.amazonaws.com",
|
||||
"napi_versions": [1,3]
|
||||
}
|
||||
```
|
||||
|
||||
If the `napi_versions` array property is *not* present, `node-pre-gyp` operates as it always has. Including the `napi_versions` array property instructs `node-pre-gyp` that this is a Node-API module build.
|
||||
|
||||
When the `napi_versions` array property is present, `node-pre-gyp` fires off multiple operations, one for each of the Node-API versions in the array. In the example above, two operations are initiated, one for Node-API version 1 and second for Node-API version 3. How this version number is communicated is described next.
|
||||
|
||||
### The `napi_build_version` value
|
||||
|
||||
For each of the Node-API module operations `node-pre-gyp` initiates, it ensures that the `napi_build_version` is set appropriately.
|
||||
|
||||
This value is of importance in two areas:
|
||||
|
||||
1. The C/C++ code which needs to know against which Node-API version it should compile.
|
||||
2. `node-pre-gyp` itself which must assign appropriate path and file names to avoid collisions.
|
||||
|
||||
### Defining `NAPI_VERSION` for the C/C++ code
|
||||
|
||||
The `napi_build_version` value is communicated to the C/C++ code by adding this code to the `binding.gyp` file:
|
||||
|
||||
```
|
||||
"defines": [
|
||||
"NAPI_VERSION=<(napi_build_version)",
|
||||
]
|
||||
```
|
||||
|
||||
This ensures that `NAPI_VERSION`, an integer value, is declared appropriately to the C/C++ code for each build.
|
||||
|
||||
> Note that earlier versions of this document recommended defining the symbol `NAPI_BUILD_VERSION`. `NAPI_VERSION` is preferred because it used by the Node-API C/C++ headers to configure the specific Node-API versions being requested.
|
||||
|
||||
### Path and file naming requirements in `package.json`
|
||||
|
||||
Since `node-pre-gyp` fires off multiple operations for each request, it is essential that path and file names be created in such a way as to avoid collisions. This is accomplished by imposing additional path and file naming requirements.
|
||||
|
||||
Specifically, when performing Node-API builds, the `{napi_build_version}` text configuration value *must* be present in the `module_path` property. In addition, the `{napi_build_version}` text configuration value *must* be present in either the `remote_path` or `package_name` property. (No problem if it's in both.)
|
||||
|
||||
Here's an example:
|
||||
|
||||
```js
|
||||
"binary": {
|
||||
"module_name": "your_module",
|
||||
"module_path": "./lib/binding/napi-v{napi_build_version}",
|
||||
"remote_path": "./{module_name}/v{version}/{configuration}/",
|
||||
"package_name": "{platform}-{arch}-napi-v{napi_build_version}.tar.gz",
|
||||
"host": "https://your_bucket.s3-us-west-1.amazonaws.com",
|
||||
"napi_versions": [1,3]
|
||||
}
|
||||
```
|
||||
|
||||
## Supporting both Node-API and NAN builds
|
||||
|
||||
You may have a legacy native add-on that you wish to continue supporting for those versions of Node that do not support Node-API, as you add Node-API support for later Node versions. This can be accomplished by specifying the `node_napi_label` configuration value in the package.json `binary.package_name` property.
|
||||
|
||||
Placing the configuration value `node_napi_label` in the package.json `binary.package_name` property instructs `node-pre-gyp` to build all viable Node-API binaries supported by the current Node instance. If the current Node instance does not support Node-API, `node-pre-gyp` will request a traditional, non-Node-API build.
|
||||
|
||||
The configuration value `node_napi_label` is set by `node-pre-gyp` to the type of build created, `napi` or `node`, and the version number. For Node-API builds, the string contains the Node-API version nad has values like `napi-v3`. For traditional, non-Node-API builds, the string contains the ABI version with values like `node-v46`.
|
||||
|
||||
Here's how the `binary` configuration above might be changed to support both Node-API and NAN builds:
|
||||
|
||||
```js
|
||||
"binary": {
|
||||
"module_name": "your_module",
|
||||
"module_path": "./lib/binding/{node_napi_label}",
|
||||
"remote_path": "./{module_name}/v{version}/{configuration}/",
|
||||
"package_name": "{platform}-{arch}-{node_napi_label}.tar.gz",
|
||||
"host": "https://your_bucket.s3-us-west-1.amazonaws.com",
|
||||
"napi_versions": [1,3]
|
||||
}
|
||||
```
|
||||
|
||||
The C/C++ symbol `NAPI_VERSION` can be used to distinguish Node-API and non-Node-API builds. The value of `NAPI_VERSION` is set to the integer Node-API version for Node-API builds and is set to `0` for non-Node-API builds.
|
||||
|
||||
For example:
|
||||
|
||||
```C
|
||||
#if NAPI_VERSION
|
||||
// Node-API code goes here
|
||||
#else
|
||||
// NAN code goes here
|
||||
#endif
|
||||
```
|
||||
|
||||
### Two additional configuration values
|
||||
|
||||
The following two configuration values, which were implemented in previous versions of `node-pre-gyp`, continue to exist, but have been replaced by the `node_napi_label` configuration value described above.
|
||||
|
||||
1. `napi_version` If Node-API is supported by the currently executing Node instance, this value is the Node-API version number supported by Node. If Node-API is not supported, this value is an empty string.
|
||||
|
||||
2. `node_abi_napi` If the value returned for `napi_version` is non empty, this value is `'napi'`. If the value returned for `napi_version` is empty, this value is the value returned for `node_abi`.
|
||||
|
||||
These values are present for use in the `binding.gyp` file and may be used as `{napi_version}` and `{node_abi_napi}` for text substituion in the `binary` properties of the `package.json` file.
|
||||
|
||||
## S3 Hosting
|
||||
|
||||
You can host wherever you choose but S3 is cheap, `node-pre-gyp publish` expects it, and S3 can be integrated well with [Travis.ci](http://travis-ci.org) to automate builds for OS X and Ubuntu, and with [Appveyor](http://appveyor.com) to automate builds for Windows. Here is an approach to do this:
|
||||
|
||||
First, get setup locally and test the workflow:
|
||||
|
||||
#### 1) Create an S3 bucket
|
||||
|
||||
And have your **key** and **secret key** ready for writing to the bucket.
|
||||
|
||||
It is recommended to create a IAM user with a policy that only gives permissions to the specific bucket you plan to publish to. This can be done in the [IAM console](https://console.aws.amazon.com/iam/) by: 1) adding a new user, 2) choosing `Attach User Policy`, 3) Using the `Policy Generator`, 4) selecting `Amazon S3` for the service, 5) adding the actions: `DeleteObject`, `GetObject`, `GetObjectAcl`, `ListBucket`, `HeadBucket`, `PutObject`, `PutObjectAcl`, 6) adding an ARN of `arn:aws:s3:::bucket/*` (replacing `bucket` with your bucket name), and finally 7) clicking `Add Statement` and saving the policy. It should generate a policy like:
|
||||
|
||||
```js
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Sid": "objects",
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:PutObject",
|
||||
"s3:GetObjectAcl",
|
||||
"s3:GetObject",
|
||||
"s3:DeleteObject",
|
||||
"s3:PutObjectAcl"
|
||||
],
|
||||
"Resource": "arn:aws:s3:::your-bucket-name/*"
|
||||
},
|
||||
{
|
||||
"Sid": "bucket",
|
||||
"Effect": "Allow",
|
||||
"Action": "s3:ListBucket",
|
||||
"Resource": "arn:aws:s3:::your-bucket-name"
|
||||
},
|
||||
{
|
||||
"Sid": "buckets",
|
||||
"Effect": "Allow",
|
||||
"Action": "s3:HeadBucket",
|
||||
"Resource": "*"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### 2) Install node-pre-gyp
|
||||
|
||||
Either install it globally:
|
||||
|
||||
npm install node-pre-gyp -g
|
||||
|
||||
Or put the local version on your PATH
|
||||
|
||||
export PATH=`pwd`/node_modules/.bin/:$PATH
|
||||
|
||||
#### 3) Configure AWS credentials
|
||||
|
||||
It is recommended to configure the AWS JS SDK v2 used internally by `node-pre-gyp` by setting these environment variables:
|
||||
|
||||
- AWS_ACCESS_KEY_ID
|
||||
- AWS_SECRET_ACCESS_KEY
|
||||
|
||||
But also you can also use the `Shared Config File` mentioned [in the AWS JS SDK v2 docs](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/configuring-the-jssdk.html)
|
||||
|
||||
#### 4) Package and publish your build
|
||||
|
||||
Install the `aws-sdk`:
|
||||
|
||||
npm install aws-sdk
|
||||
|
||||
Then publish:
|
||||
|
||||
node-pre-gyp package publish
|
||||
|
||||
Note: if you hit an error like `Hostname/IP doesn't match certificate's altnames` it may mean that you need to provide the `region` option in your config.
|
||||
|
||||
## Appveyor Automation
|
||||
|
||||
[Appveyor](http://www.appveyor.com/) can build binaries and publish the results per commit and supports:
|
||||
|
||||
- Windows Visual Studio 2013 and related compilers
|
||||
- Both 64 bit (x64) and 32 bit (x86) build configurations
|
||||
- Multiple Node.js versions
|
||||
|
||||
For an example of doing this see [node-sqlite3's appveyor.yml](https://github.com/mapbox/node-sqlite3/blob/master/appveyor.yml).
|
||||
|
||||
Below is a guide to getting set up:
|
||||
|
||||
#### 1) Create a free Appveyor account
|
||||
|
||||
Go to https://ci.appveyor.com/signup/free and sign in with your GitHub account.
|
||||
|
||||
#### 2) Create a new project
|
||||
|
||||
Go to https://ci.appveyor.com/projects/new and select the GitHub repo for your module
|
||||
|
||||
#### 3) Add appveyor.yml and push it
|
||||
|
||||
Once you have committed an `appveyor.yml` ([appveyor.yml reference](http://www.appveyor.com/docs/appveyor-yml)) to your GitHub repo and pushed it AppVeyor should automatically start building your project.
|
||||
|
||||
#### 4) Create secure variables
|
||||
|
||||
Encrypt your S3 AWS keys by going to <https://ci.appveyor.com/tools/encrypt> and hitting the `encrypt` button.
|
||||
|
||||
Then paste the result into your `appveyor.yml`
|
||||
|
||||
```yml
|
||||
environment:
|
||||
AWS_ACCESS_KEY_ID:
|
||||
secure: Dn9HKdLNYvDgPdQOzRq/DqZ/MPhjknRHB1o+/lVU8MA=
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
secure: W1rwNoSnOku1r+28gnoufO8UA8iWADmL1LiiwH9IOkIVhDTNGdGPJqAlLjNqwLnL
|
||||
```
|
||||
|
||||
NOTE: keys are per account but not per repo (this is difference than Travis where keys are per repo but not related to the account used to encrypt them).
|
||||
|
||||
#### 5) Hook up publishing
|
||||
|
||||
Just put `node-pre-gyp package publish` in your `appveyor.yml` after `npm install`.
|
||||
|
||||
#### 6) Publish when you want
|
||||
|
||||
You might wish to publish binaries only on a specific commit. To do this you could borrow from the [Travis CI idea of commit keywords](http://about.travis-ci.org/docs/user/how-to-skip-a-build/) and add special handling for commit messages with `[publish binary]`:
|
||||
|
||||
SET CM=%APPVEYOR_REPO_COMMIT_MESSAGE%
|
||||
if not "%CM%" == "%CM:[publish binary]=%" node-pre-gyp --msvs_version=2013 publish
|
||||
|
||||
If your commit message contains special characters (e.g. `&`) this method might fail. An alternative is to use PowerShell, which gives you additional possibilities, like ignoring case by using `ToLower()`:
|
||||
|
||||
ps: if($env:APPVEYOR_REPO_COMMIT_MESSAGE.ToLower().Contains('[publish binary]')) { node-pre-gyp --msvs_version=2013 publish }
|
||||
|
||||
Remember this publishing is not the same as `npm publish`. We're just talking about the binary module here and not your entire npm package.
|
||||
|
||||
## Travis Automation
|
||||
|
||||
[Travis](https://travis-ci.org/) can push to S3 after a successful build and supports both:
|
||||
|
||||
- Ubuntu Precise and OS X (64 bit)
|
||||
- Multiple Node.js versions
|
||||
|
||||
For an example of doing this see [node-add-example's .travis.yml](https://github.com/springmeyer/node-addon-example/blob/2ff60a8ded7f042864ad21db00c3a5a06cf47075/.travis.yml).
|
||||
|
||||
Note: if you need 32 bit binaries, this can be done from a 64 bit Travis machine. See [the node-sqlite3 scripts for an example of doing this](https://github.com/mapbox/node-sqlite3/blob/bae122aa6a2b8a45f6b717fab24e207740e32b5d/scripts/build_against_node.sh#L54-L74).
|
||||
|
||||
Below is a guide to getting set up:
|
||||
|
||||
#### 1) Install the Travis gem
|
||||
|
||||
gem install travis
|
||||
|
||||
#### 2) Create secure variables
|
||||
|
||||
Make sure you run this command from within the directory of your module.
|
||||
|
||||
Use `travis-encrypt` like:
|
||||
|
||||
travis encrypt AWS_ACCESS_KEY_ID=${node_pre_gyp_accessKeyId}
|
||||
travis encrypt AWS_SECRET_ACCESS_KEY=${node_pre_gyp_secretAccessKey}
|
||||
|
||||
Then put those values in your `.travis.yml` like:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
global:
|
||||
- secure: F+sEL/v56CzHqmCSSES4pEyC9NeQlkoR0Gs/ZuZxX1ytrj8SKtp3MKqBj7zhIclSdXBz4Ev966Da5ctmcTd410p0b240MV6BVOkLUtkjZJyErMBOkeb8n8yVfSoeMx8RiIhBmIvEn+rlQq+bSFis61/JkE9rxsjkGRZi14hHr4M=
|
||||
- secure: o2nkUQIiABD139XS6L8pxq3XO5gch27hvm/gOdV+dzNKc/s2KomVPWcOyXNxtJGhtecAkABzaW8KHDDi5QL1kNEFx6BxFVMLO8rjFPsMVaBG9Ks6JiDQkkmrGNcnVdxI/6EKTLHTH5WLsz8+J7caDBzvKbEfTux5EamEhxIWgrI=
|
||||
```
|
||||
|
||||
More details on Travis encryption at http://about.travis-ci.org/docs/user/encryption-keys/.
|
||||
|
||||
#### 3) Hook up publishing
|
||||
|
||||
Just put `node-pre-gyp package publish` in your `.travis.yml` after `npm install`.
|
||||
|
||||
##### OS X publishing
|
||||
|
||||
If you want binaries for OS X in addition to linux you can enable [multi-os for Travis](http://docs.travis-ci.com/user/multi-os/#Setting-.travis.yml)
|
||||
|
||||
Use a configuration like:
|
||||
|
||||
```yml
|
||||
|
||||
language: cpp
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- NODE_VERSION="4"
|
||||
- NODE_VERSION="6"
|
||||
|
||||
before_install:
|
||||
- rm -rf ~/.nvm/ && git clone --depth 1 https://github.com/creationix/nvm.git ~/.nvm
|
||||
- source ~/.nvm/nvm.sh
|
||||
- nvm install $NODE_VERSION
|
||||
- nvm use $NODE_VERSION
|
||||
```
|
||||
|
||||
See [Travis OS X Gotchas](#travis-os-x-gotchas) for why we replace `language: node_js` and `node_js:` sections with `language: cpp` and a custom matrix.
|
||||
|
||||
Also create platform specific sections for any deps that need install. For example if you need libpng:
|
||||
|
||||
```yml
|
||||
- if [ $(uname -s) == 'Linux' ]; then apt-get install libpng-dev; fi;
|
||||
- if [ $(uname -s) == 'Darwin' ]; then brew install libpng; fi;
|
||||
```
|
||||
|
||||
For detailed multi-OS examples see [node-mapnik](https://github.com/mapnik/node-mapnik/blob/master/.travis.yml) and [node-sqlite3](https://github.com/mapbox/node-sqlite3/blob/master/.travis.yml).
|
||||
|
||||
##### Travis OS X Gotchas
|
||||
|
||||
First, unlike the Travis Linux machines, the OS X machines do not put `node-pre-gyp` on PATH by default. To do so you will need to:
|
||||
|
||||
```sh
|
||||
export PATH=$(pwd)/node_modules/.bin:${PATH}
|
||||
```
|
||||
|
||||
Second, the OS X machines do not support using a matrix for installing different Node.js versions. So you need to bootstrap the installation of Node.js in a cross platform way.
|
||||
|
||||
By doing:
|
||||
|
||||
```yml
|
||||
env:
|
||||
matrix:
|
||||
- NODE_VERSION="4"
|
||||
- NODE_VERSION="6"
|
||||
|
||||
before_install:
|
||||
- rm -rf ~/.nvm/ && git clone --depth 1 https://github.com/creationix/nvm.git ~/.nvm
|
||||
- source ~/.nvm/nvm.sh
|
||||
- nvm install $NODE_VERSION
|
||||
- nvm use $NODE_VERSION
|
||||
```
|
||||
|
||||
You can easily recreate the previous behavior of this matrix:
|
||||
|
||||
```yml
|
||||
node_js:
|
||||
- "4"
|
||||
- "6"
|
||||
```
|
||||
|
||||
#### 4) Publish when you want
|
||||
|
||||
You might wish to publish binaries only on a specific commit. To do this you could borrow from the [Travis CI idea of commit keywords](http://about.travis-ci.org/docs/user/how-to-skip-a-build/) and add special handling for commit messages with `[publish binary]`:
|
||||
|
||||
COMMIT_MESSAGE=$(git log --format=%B --no-merges -n 1 | tr -d '\n')
|
||||
if [[ ${COMMIT_MESSAGE} =~ "[publish binary]" ]]; then node-pre-gyp publish; fi;
|
||||
|
||||
Then you can trigger new binaries to be built like:
|
||||
|
||||
git commit -a -m "[publish binary]"
|
||||
|
||||
Or, if you don't have any changes to make simply run:
|
||||
|
||||
git commit --allow-empty -m "[publish binary]"
|
||||
|
||||
WARNING: if you are working in a pull request and publishing binaries from there then you will want to avoid double publishing when Travis CI builds both the `push` and `pr`. You only want to run the publish on the `push` commit. See https://github.com/Project-OSRM/node-osrm/blob/8eb837abe2e2e30e595093d16e5354bc5c573575/scripts/is_pr_merge.sh which is called from https://github.com/Project-OSRM/node-osrm/blob/8eb837abe2e2e30e595093d16e5354bc5c573575/scripts/publish.sh for an example of how to do this.
|
||||
|
||||
Remember this publishing is not the same as `npm publish`. We're just talking about the binary module here and not your entire npm package. To automate the publishing of your entire package to npm on Travis see http://about.travis-ci.org/docs/user/deployment/npm/
|
||||
|
||||
# Versioning
|
||||
|
||||
The `binary` properties of `module_path`, `remote_path`, and `package_name` support variable substitution. The strings are evaluated by `node-pre-gyp` depending on your system and any custom build flags you passed.
|
||||
|
||||
- `node_abi`: The node C++ `ABI` number. This value is available in Javascript as `process.versions.modules` as of [`>= v0.10.4 >= v0.11.7`](https://github.com/joyent/node/commit/ccabd4a6fa8a6eb79d29bc3bbe9fe2b6531c2d8e) and in C++ as the `NODE_MODULE_VERSION` define much earlier. For versions of Node before this was available we fallback to the V8 major and minor version.
|
||||
- `platform` matches node's `process.platform` like `linux`, `darwin`, and `win32` unless the user passed the `--target_platform` option to override.
|
||||
- `arch` matches node's `process.arch` like `x64` or `ia32` unless the user passes the `--target_arch` option to override.
|
||||
- `libc` matches `require('detect-libc').family` like `glibc` or `musl` unless the user passes the `--target_libc` option to override.
|
||||
- `configuration` - Either 'Release' or 'Debug' depending on if `--debug` is passed during the build.
|
||||
- `module_name` - the `binary.module_name` attribute from `package.json`.
|
||||
- `version` - the semver `version` value for your module from `package.json` (NOTE: ignores the `semver.build` property).
|
||||
- `major`, `minor`, `patch`, and `prelease` match the individual semver values for your module's `version`
|
||||
- `build` - the sevmer `build` value. For example it would be `this.that` if your package.json `version` was `v1.0.0+this.that`
|
||||
- `prerelease` - the semver `prerelease` value. For example it would be `alpha.beta` if your package.json `version` was `v1.0.0-alpha.beta`
|
||||
|
||||
|
||||
The options are visible in the code at <https://github.com/mapbox/node-pre-gyp/blob/612b7bca2604508d881e1187614870ba19a7f0c5/lib/util/versioning.js#L114-L127>
|
||||
|
||||
# Download binary files from a mirror
|
||||
|
||||
S3 is broken in China for the well known reason.
|
||||
|
||||
Using the `npm` config argument: `--{module_name}_binary_host_mirror` can download binary files through a mirror, `-` in `module_name` will be replaced with `_`.
|
||||
|
||||
e.g.: Install [v8-profiler](https://www.npmjs.com/package/v8-profiler) from `npm`.
|
||||
|
||||
```bash
|
||||
$ npm install v8-profiler --profiler_binary_host_mirror=https://npm.taobao.org/mirrors/node-inspector/
|
||||
```
|
||||
|
||||
e.g.: Install [canvas-prebuilt](https://www.npmjs.com/package/canvas-prebuilt) from `npm`.
|
||||
|
||||
```bash
|
||||
$ npm install canvas-prebuilt --canvas_prebuilt_binary_host_mirror=https://npm.taobao.org/mirrors/canvas-prebuilt/
|
||||
```
|
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
require('../lib/main');
|
@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
node "%~dp0\node-pre-gyp" %*
|
@ -0,0 +1,10 @@
|
||||
# Contributing
|
||||
|
||||
|
||||
### Releasing a new version:
|
||||
|
||||
- Ensure tests are passing on travis and appveyor
|
||||
- Run `node scripts/abi_crosswalk.js` and commit any changes
|
||||
- Update the changelog
|
||||
- Tag a new release like: `git tag -a v0.6.34 -m "tagging v0.6.34" && git push --tags`
|
||||
- Run `npm publish`
|
@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = build;
|
||||
|
||||
exports.usage = 'Attempts to compile the module by dispatching to node-gyp or nw-gyp';
|
||||
|
||||
const napi = require('./util/napi.js');
|
||||
const compile = require('./util/compile.js');
|
||||
const handle_gyp_opts = require('./util/handle_gyp_opts.js');
|
||||
const configure = require('./configure.js');
|
||||
|
||||
function do_build(gyp, argv, callback) {
|
||||
handle_gyp_opts(gyp, argv, (err, result) => {
|
||||
let final_args = ['build'].concat(result.gyp).concat(result.pre);
|
||||
if (result.unparsed.length > 0) {
|
||||
final_args = final_args.
|
||||
concat(['--']).
|
||||
concat(result.unparsed);
|
||||
}
|
||||
if (!err && result.opts.napi_build_version) {
|
||||
napi.swap_build_dir_in(result.opts.napi_build_version);
|
||||
}
|
||||
compile.run_gyp(final_args, result.opts, (err2) => {
|
||||
if (result.opts.napi_build_version) {
|
||||
napi.swap_build_dir_out(result.opts.napi_build_version);
|
||||
}
|
||||
return callback(err2);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function build(gyp, argv, callback) {
|
||||
|
||||
// Form up commands to pass to node-gyp:
|
||||
// We map `node-pre-gyp build` to `node-gyp configure build` so that we do not
|
||||
// trigger a clean and therefore do not pay the penalty of a full recompile
|
||||
if (argv.length && (argv.indexOf('rebuild') > -1)) {
|
||||
argv.shift(); // remove `rebuild`
|
||||
// here we map `node-pre-gyp rebuild` to `node-gyp rebuild` which internally means
|
||||
// "clean + configure + build" and triggers a full recompile
|
||||
compile.run_gyp(['clean'], {}, (err3) => {
|
||||
if (err3) return callback(err3);
|
||||
configure(gyp, argv, (err4) => {
|
||||
if (err4) return callback(err4);
|
||||
return do_build(gyp, argv, callback);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return do_build(gyp, argv, callback);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = clean;
|
||||
|
||||
exports.usage = 'Removes the entire folder containing the compiled .node module';
|
||||
|
||||
const rm = require('rimraf');
|
||||
const exists = require('fs').exists || require('path').exists;
|
||||
const versioning = require('./util/versioning.js');
|
||||
const napi = require('./util/napi.js');
|
||||
const path = require('path');
|
||||
|
||||
function clean(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
const opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
|
||||
const to_delete = opts.module_path;
|
||||
if (!to_delete) {
|
||||
return callback(new Error('module_path is empty, refusing to delete'));
|
||||
} else if (path.normalize(to_delete) === path.normalize(process.cwd())) {
|
||||
return callback(new Error('module_path is not set, refusing to delete'));
|
||||
} else {
|
||||
exists(to_delete, (found) => {
|
||||
if (found) {
|
||||
if (!gyp.opts.silent_clean) console.log('[' + package_json.name + '] Removing "%s"', to_delete);
|
||||
return rm(to_delete, callback);
|
||||
}
|
||||
return callback();
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = configure;
|
||||
|
||||
exports.usage = 'Attempts to configure node-gyp or nw-gyp build';
|
||||
|
||||
const napi = require('./util/napi.js');
|
||||
const compile = require('./util/compile.js');
|
||||
const handle_gyp_opts = require('./util/handle_gyp_opts.js');
|
||||
|
||||
function configure(gyp, argv, callback) {
|
||||
handle_gyp_opts(gyp, argv, (err, result) => {
|
||||
let final_args = result.gyp.concat(result.pre);
|
||||
// pull select node-gyp configure options out of the npm environ
|
||||
const known_gyp_args = ['dist-url', 'python', 'nodedir', 'msvs_version'];
|
||||
known_gyp_args.forEach((key) => {
|
||||
const val = gyp.opts[key] || gyp.opts[key.replace('-', '_')];
|
||||
if (val) {
|
||||
final_args.push('--' + key + '=' + val);
|
||||
}
|
||||
});
|
||||
// --ensure=false tell node-gyp to re-install node development headers
|
||||
// but it is only respected by node-gyp install, so we have to call install
|
||||
// as a separate step if the user passes it
|
||||
if (gyp.opts.ensure === false) {
|
||||
const install_args = final_args.concat(['install', '--ensure=false']);
|
||||
compile.run_gyp(install_args, result.opts, (err2) => {
|
||||
if (err2) return callback(err2);
|
||||
if (result.unparsed.length > 0) {
|
||||
final_args = final_args.
|
||||
concat(['--']).
|
||||
concat(result.unparsed);
|
||||
}
|
||||
compile.run_gyp(['configure'].concat(final_args), result.opts, (err3) => {
|
||||
return callback(err3);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if (result.unparsed.length > 0) {
|
||||
final_args = final_args.
|
||||
concat(['--']).
|
||||
concat(result.unparsed);
|
||||
}
|
||||
compile.run_gyp(['configure'].concat(final_args), result.opts, (err4) => {
|
||||
if (!err4 && result.opts.napi_build_version) {
|
||||
napi.swap_build_dir_out(result.opts.napi_build_version);
|
||||
}
|
||||
return callback(err4);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = info;
|
||||
|
||||
exports.usage = 'Lists all published binaries (requires aws-sdk)';
|
||||
|
||||
const log = require('npmlog');
|
||||
const versioning = require('./util/versioning.js');
|
||||
const s3_setup = require('./util/s3_setup.js');
|
||||
|
||||
function info(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
const opts = versioning.evaluate(package_json, gyp.opts);
|
||||
const config = {};
|
||||
s3_setup.detect(opts, config);
|
||||
const s3 = s3_setup.get_s3(config);
|
||||
const s3_opts = {
|
||||
Bucket: config.bucket,
|
||||
Prefix: config.prefix
|
||||
};
|
||||
s3.listObjects(s3_opts, (err, meta) => {
|
||||
if (err && err.code === 'NotFound') {
|
||||
return callback(new Error('[' + package_json.name + '] Not found: https://' + s3_opts.Bucket + '.s3.amazonaws.com/' + config.prefix));
|
||||
} else if (err) {
|
||||
return callback(err);
|
||||
} else {
|
||||
log.verbose(JSON.stringify(meta, null, 1));
|
||||
if (meta && meta.Contents) {
|
||||
meta.Contents.forEach((obj) => {
|
||||
console.log(obj.Key);
|
||||
});
|
||||
} else {
|
||||
console.error('[' + package_json.name + '] No objects found at https://' + s3_opts.Bucket + '.s3.amazonaws.com/' + config.prefix);
|
||||
}
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
}
|
@ -0,0 +1,235 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = install;
|
||||
|
||||
exports.usage = 'Attempts to install pre-built binary for module';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const log = require('npmlog');
|
||||
const existsAsync = fs.exists || path.exists;
|
||||
const versioning = require('./util/versioning.js');
|
||||
const napi = require('./util/napi.js');
|
||||
const makeDir = require('make-dir');
|
||||
// for fetching binaries
|
||||
const fetch = require('node-fetch');
|
||||
const tar = require('tar');
|
||||
|
||||
let npgVersion = 'unknown';
|
||||
try {
|
||||
// Read own package.json to get the current node-pre-pyp version.
|
||||
const ownPackageJSON = fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8');
|
||||
npgVersion = JSON.parse(ownPackageJSON).version;
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
function place_binary(uri, targetDir, opts, callback) {
|
||||
log.http('GET', uri);
|
||||
|
||||
// Try getting version info from the currently running npm.
|
||||
const envVersionInfo = process.env.npm_config_user_agent ||
|
||||
'node ' + process.version;
|
||||
|
||||
const sanitized = uri.replace('+', '%2B');
|
||||
const requestOpts = {
|
||||
uri: sanitized,
|
||||
headers: {
|
||||
'User-Agent': 'node-pre-gyp (v' + npgVersion + ', ' + envVersionInfo + ')'
|
||||
},
|
||||
follow_max: 10
|
||||
};
|
||||
|
||||
if (opts.cafile) {
|
||||
try {
|
||||
requestOpts.ca = fs.readFileSync(opts.cafile);
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
} else if (opts.ca) {
|
||||
requestOpts.ca = opts.ca;
|
||||
}
|
||||
|
||||
const proxyUrl = opts.proxy ||
|
||||
process.env.http_proxy ||
|
||||
process.env.HTTP_PROXY ||
|
||||
process.env.npm_config_proxy;
|
||||
let agent;
|
||||
if (proxyUrl) {
|
||||
const ProxyAgent = require('https-proxy-agent');
|
||||
agent = new ProxyAgent(proxyUrl);
|
||||
log.http('download', 'proxy agent configured using: "%s"', proxyUrl);
|
||||
}
|
||||
|
||||
fetch(sanitized, { agent })
|
||||
.then((res) => {
|
||||
if (!res.ok) {
|
||||
throw new Error(`response status ${res.status} ${res.statusText} on ${sanitized}`);
|
||||
}
|
||||
const dataStream = res.body;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let extractions = 0;
|
||||
const countExtractions = (entry) => {
|
||||
extractions += 1;
|
||||
log.info('install', 'unpacking %s', entry.path);
|
||||
};
|
||||
|
||||
dataStream.pipe(extract(targetDir, countExtractions))
|
||||
.on('error', (e) => {
|
||||
reject(e);
|
||||
});
|
||||
dataStream.on('end', () => {
|
||||
resolve(`extracted file count: ${extractions}`);
|
||||
});
|
||||
dataStream.on('error', (e) => {
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
})
|
||||
.then((text) => {
|
||||
log.info(text);
|
||||
callback();
|
||||
})
|
||||
.catch((e) => {
|
||||
log.error(`install ${e.message}`);
|
||||
callback(e);
|
||||
});
|
||||
}
|
||||
|
||||
function extract(to, onentry) {
|
||||
return tar.extract({
|
||||
cwd: to,
|
||||
strip: 1,
|
||||
onentry
|
||||
});
|
||||
}
|
||||
|
||||
function extract_from_local(from, targetDir, callback) {
|
||||
if (!fs.existsSync(from)) {
|
||||
return callback(new Error('Cannot find file ' + from));
|
||||
}
|
||||
log.info('Found local file to extract from ' + from);
|
||||
|
||||
// extract helpers
|
||||
let extractCount = 0;
|
||||
function countExtractions(entry) {
|
||||
extractCount += 1;
|
||||
log.info('install', 'unpacking ' + entry.path);
|
||||
}
|
||||
function afterExtract(err) {
|
||||
if (err) return callback(err);
|
||||
if (extractCount === 0) {
|
||||
return callback(new Error('There was a fatal problem while extracting the tarball'));
|
||||
}
|
||||
log.info('tarball', 'done parsing tarball');
|
||||
callback();
|
||||
}
|
||||
|
||||
fs.createReadStream(from).pipe(extract(targetDir, countExtractions))
|
||||
.on('close', afterExtract)
|
||||
.on('error', afterExtract);
|
||||
}
|
||||
|
||||
function do_build(gyp, argv, callback) {
|
||||
const args = ['rebuild'].concat(argv);
|
||||
gyp.todo.push({ name: 'build', args: args });
|
||||
process.nextTick(callback);
|
||||
}
|
||||
|
||||
function print_fallback_error(err, opts, package_json) {
|
||||
const fallback_message = ' (falling back to source compile with node-gyp)';
|
||||
let full_message = '';
|
||||
if (err.statusCode !== undefined) {
|
||||
// If we got a network response it but failed to download
|
||||
// it means remote binaries are not available, so let's try to help
|
||||
// the user/developer with the info to debug why
|
||||
full_message = 'Pre-built binaries not found for ' + package_json.name + '@' + package_json.version;
|
||||
full_message += ' and ' + opts.runtime + '@' + (opts.target || process.versions.node) + ' (' + opts.node_abi + ' ABI, ' + opts.libc + ')';
|
||||
full_message += fallback_message;
|
||||
log.warn('Tried to download(' + err.statusCode + '): ' + opts.hosted_tarball);
|
||||
log.warn(full_message);
|
||||
log.http(err.message);
|
||||
} else {
|
||||
// If we do not have a statusCode that means an unexpected error
|
||||
// happened and prevented an http response, so we output the exact error
|
||||
full_message = 'Pre-built binaries not installable for ' + package_json.name + '@' + package_json.version;
|
||||
full_message += ' and ' + opts.runtime + '@' + (opts.target || process.versions.node) + ' (' + opts.node_abi + ' ABI, ' + opts.libc + ')';
|
||||
full_message += fallback_message;
|
||||
log.warn(full_message);
|
||||
log.warn('Hit error ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// install
|
||||
//
|
||||
function install(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
const source_build = gyp.opts['build-from-source'] || gyp.opts.build_from_source;
|
||||
const update_binary = gyp.opts['update-binary'] || gyp.opts.update_binary;
|
||||
const should_do_source_build = source_build === package_json.name || (source_build === true || source_build === 'true');
|
||||
if (should_do_source_build) {
|
||||
log.info('build', 'requesting source compile');
|
||||
return do_build(gyp, argv, callback);
|
||||
} else {
|
||||
const fallback_to_build = gyp.opts['fallback-to-build'] || gyp.opts.fallback_to_build;
|
||||
let should_do_fallback_build = fallback_to_build === package_json.name || (fallback_to_build === true || fallback_to_build === 'true');
|
||||
// but allow override from npm
|
||||
if (process.env.npm_config_argv) {
|
||||
const cooked = JSON.parse(process.env.npm_config_argv).cooked;
|
||||
const match = cooked.indexOf('--fallback-to-build');
|
||||
if (match > -1 && cooked.length > match && cooked[match + 1] === 'false') {
|
||||
should_do_fallback_build = false;
|
||||
log.info('install', 'Build fallback disabled via npm flag: --fallback-to-build=false');
|
||||
}
|
||||
}
|
||||
let opts;
|
||||
try {
|
||||
opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
|
||||
} catch (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
opts.ca = gyp.opts.ca;
|
||||
opts.cafile = gyp.opts.cafile;
|
||||
|
||||
const from = opts.hosted_tarball;
|
||||
const to = opts.module_path;
|
||||
const binary_module = path.join(to, opts.module_name + '.node');
|
||||
existsAsync(binary_module, (found) => {
|
||||
if (!update_binary) {
|
||||
if (found) {
|
||||
console.log('[' + package_json.name + '] Success: "' + binary_module + '" already installed');
|
||||
console.log('Pass --update-binary to reinstall or --build-from-source to recompile');
|
||||
return callback();
|
||||
}
|
||||
log.info('check', 'checked for "' + binary_module + '" (not found)');
|
||||
}
|
||||
|
||||
makeDir(to).then(() => {
|
||||
const fileName = from.startsWith('file://') && from.slice('file://'.length);
|
||||
if (fileName) {
|
||||
extract_from_local(fileName, to, after_place);
|
||||
} else {
|
||||
place_binary(from, to, opts, after_place);
|
||||
}
|
||||
}).catch((err) => {
|
||||
after_place(err);
|
||||
});
|
||||
|
||||
function after_place(err) {
|
||||
if (err && should_do_fallback_build) {
|
||||
print_fallback_error(err, opts, package_json);
|
||||
return do_build(gyp, argv, callback);
|
||||
} else if (err) {
|
||||
return callback(err);
|
||||
} else {
|
||||
console.log('[' + package_json.name + '] Success: "' + binary_module + '" is installed via remote');
|
||||
return callback();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Set the title.
|
||||
*/
|
||||
|
||||
process.title = 'node-pre-gyp';
|
||||
|
||||
const node_pre_gyp = require('../');
|
||||
const log = require('npmlog');
|
||||
|
||||
/**
|
||||
* Process and execute the selected commands.
|
||||
*/
|
||||
|
||||
const prog = new node_pre_gyp.Run({ argv: process.argv });
|
||||
let completed = false;
|
||||
|
||||
if (prog.todo.length === 0) {
|
||||
if (~process.argv.indexOf('-v') || ~process.argv.indexOf('--version')) {
|
||||
console.log('v%s', prog.version);
|
||||
process.exit(0);
|
||||
} else if (~process.argv.indexOf('-h') || ~process.argv.indexOf('--help')) {
|
||||
console.log('%s', prog.usage());
|
||||
process.exit(0);
|
||||
}
|
||||
console.log('%s', prog.usage());
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// if --no-color is passed
|
||||
if (prog.opts && Object.hasOwnProperty.call(prog, 'color') && !prog.opts.color) {
|
||||
log.disableColor();
|
||||
}
|
||||
|
||||
log.info('it worked if it ends with', 'ok');
|
||||
log.verbose('cli', process.argv);
|
||||
log.info('using', process.title + '@%s', prog.version);
|
||||
log.info('using', 'node@%s | %s | %s', process.versions.node, process.platform, process.arch);
|
||||
|
||||
|
||||
/**
|
||||
* Change dir if -C/--directory was passed.
|
||||
*/
|
||||
|
||||
const dir = prog.opts.directory;
|
||||
if (dir) {
|
||||
const fs = require('fs');
|
||||
try {
|
||||
const stat = fs.statSync(dir);
|
||||
if (stat.isDirectory()) {
|
||||
log.info('chdir', dir);
|
||||
process.chdir(dir);
|
||||
} else {
|
||||
log.warn('chdir', dir + ' is not a directory');
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
log.warn('chdir', dir + ' is not a directory');
|
||||
} else {
|
||||
log.warn('chdir', 'error during chdir() "%s"', e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function run() {
|
||||
const command = prog.todo.shift();
|
||||
if (!command) {
|
||||
// done!
|
||||
completed = true;
|
||||
log.info('ok');
|
||||
return;
|
||||
}
|
||||
|
||||
// set binary.host when appropriate. host determines the s3 target bucket.
|
||||
const target = prog.setBinaryHostProperty(command.name);
|
||||
if (target && ['install', 'publish', 'unpublish', 'info'].indexOf(command.name) >= 0) {
|
||||
log.info('using binary.host: ' + prog.package_json.binary.host);
|
||||
}
|
||||
|
||||
prog.commands[command.name](command.args, function(err) {
|
||||
if (err) {
|
||||
log.error(command.name + ' error');
|
||||
log.error('stack', err.stack);
|
||||
errorMessage();
|
||||
log.error('not ok');
|
||||
console.log(err.message);
|
||||
return process.exit(1);
|
||||
}
|
||||
const args_array = [].slice.call(arguments, 1);
|
||||
if (args_array.length) {
|
||||
console.log.apply(console, args_array);
|
||||
}
|
||||
// now run the next command in the queue
|
||||
process.nextTick(run);
|
||||
});
|
||||
}
|
||||
|
||||
process.on('exit', (code) => {
|
||||
if (!completed && !code) {
|
||||
log.error('Completion callback never invoked!');
|
||||
errorMessage();
|
||||
process.exit(6);
|
||||
}
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
log.error('UNCAUGHT EXCEPTION');
|
||||
log.error('stack', err.stack);
|
||||
errorMessage();
|
||||
process.exit(7);
|
||||
});
|
||||
|
||||
function errorMessage() {
|
||||
// copied from npm's lib/util/error-handler.js
|
||||
const os = require('os');
|
||||
log.error('System', os.type() + ' ' + os.release());
|
||||
log.error('command', process.argv.map(JSON.stringify).join(' '));
|
||||
log.error('cwd', process.cwd());
|
||||
log.error('node -v', process.version);
|
||||
log.error(process.title + ' -v', 'v' + prog.package.version);
|
||||
}
|
||||
|
||||
// start running the given commands!
|
||||
run();
|
@ -0,0 +1,309 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
// load mocking control function for accessing s3 via https. the function is a noop always returning
|
||||
// false if not mocking.
|
||||
exports.mockS3Http = require('./util/s3_setup').get_mockS3Http();
|
||||
exports.mockS3Http('on');
|
||||
const mocking = exports.mockS3Http('get');
|
||||
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const nopt = require('nopt');
|
||||
const log = require('npmlog');
|
||||
log.disableProgress();
|
||||
const napi = require('./util/napi.js');
|
||||
|
||||
const EE = require('events').EventEmitter;
|
||||
const inherits = require('util').inherits;
|
||||
const cli_commands = [
|
||||
'clean',
|
||||
'install',
|
||||
'reinstall',
|
||||
'build',
|
||||
'rebuild',
|
||||
'package',
|
||||
'testpackage',
|
||||
'publish',
|
||||
'unpublish',
|
||||
'info',
|
||||
'testbinary',
|
||||
'reveal',
|
||||
'configure'
|
||||
];
|
||||
const aliases = {};
|
||||
|
||||
// differentiate node-pre-gyp's logs from npm's
|
||||
log.heading = 'node-pre-gyp';
|
||||
|
||||
if (mocking) {
|
||||
log.warn(`mocking s3 to ${process.env.node_pre_gyp_mock_s3}`);
|
||||
}
|
||||
|
||||
// this is a getter to avoid circular reference warnings with node v14.
|
||||
Object.defineProperty(exports, 'find', {
|
||||
get: function() {
|
||||
return require('./pre-binding').find;
|
||||
},
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
// in the following, "my_module" is using node-pre-gyp to
|
||||
// prebuild and install pre-built binaries. "main_module"
|
||||
// is using "my_module".
|
||||
//
|
||||
// "bin/node-pre-gyp" invokes Run() without a path. the
|
||||
// expectation is that the working directory is the package
|
||||
// root "my_module". this is true because in all cases npm is
|
||||
// executing a script in the context of "my_module".
|
||||
//
|
||||
// "pre-binding.find()" is executed by "my_module" but in the
|
||||
// context of "main_module". this is because "main_module" is
|
||||
// executing and requires "my_module" which is then executing
|
||||
// "pre-binding.find()" via "node-pre-gyp.find()", so the working
|
||||
// directory is that of "main_module".
|
||||
//
|
||||
// that's why "find()" must pass the path to package.json.
|
||||
//
|
||||
function Run({ package_json_path = './package.json', argv }) {
|
||||
this.package_json_path = package_json_path;
|
||||
this.commands = {};
|
||||
|
||||
const self = this;
|
||||
cli_commands.forEach((command) => {
|
||||
self.commands[command] = function(argvx, callback) {
|
||||
log.verbose('command', command, argvx);
|
||||
return require('./' + command)(self, argvx, callback);
|
||||
};
|
||||
});
|
||||
|
||||
this.parseArgv(argv);
|
||||
|
||||
// this is set to true after the binary.host property was set to
|
||||
// either staging_host or production_host.
|
||||
this.binaryHostSet = false;
|
||||
}
|
||||
inherits(Run, EE);
|
||||
exports.Run = Run;
|
||||
const proto = Run.prototype;
|
||||
|
||||
/**
|
||||
* Export the contents of the package.json.
|
||||
*/
|
||||
|
||||
proto.package = require('../package.json');
|
||||
|
||||
/**
|
||||
* nopt configuration definitions
|
||||
*/
|
||||
|
||||
proto.configDefs = {
|
||||
help: Boolean, // everywhere
|
||||
arch: String, // 'configure'
|
||||
debug: Boolean, // 'build'
|
||||
directory: String, // bin
|
||||
proxy: String, // 'install'
|
||||
loglevel: String // everywhere
|
||||
};
|
||||
|
||||
/**
|
||||
* nopt shorthands
|
||||
*/
|
||||
|
||||
proto.shorthands = {
|
||||
release: '--no-debug',
|
||||
C: '--directory',
|
||||
debug: '--debug',
|
||||
j: '--jobs',
|
||||
silent: '--loglevel=silent',
|
||||
silly: '--loglevel=silly',
|
||||
verbose: '--loglevel=verbose'
|
||||
};
|
||||
|
||||
/**
|
||||
* expose the command aliases for the bin file to use.
|
||||
*/
|
||||
|
||||
proto.aliases = aliases;
|
||||
|
||||
/**
|
||||
* Parses the given argv array and sets the 'opts', 'argv',
|
||||
* 'command', and 'package_json' properties.
|
||||
*/
|
||||
|
||||
proto.parseArgv = function parseOpts(argv) {
|
||||
this.opts = nopt(this.configDefs, this.shorthands, argv);
|
||||
this.argv = this.opts.argv.remain.slice();
|
||||
const commands = this.todo = [];
|
||||
|
||||
// create a copy of the argv array with aliases mapped
|
||||
argv = this.argv.map((arg) => {
|
||||
// is this an alias?
|
||||
if (arg in this.aliases) {
|
||||
arg = this.aliases[arg];
|
||||
}
|
||||
return arg;
|
||||
});
|
||||
|
||||
// process the mapped args into "command" objects ("name" and "args" props)
|
||||
argv.slice().forEach((arg) => {
|
||||
if (arg in this.commands) {
|
||||
const args = argv.splice(0, argv.indexOf(arg));
|
||||
argv.shift();
|
||||
if (commands.length > 0) {
|
||||
commands[commands.length - 1].args = args;
|
||||
}
|
||||
commands.push({ name: arg, args: [] });
|
||||
}
|
||||
});
|
||||
if (commands.length > 0) {
|
||||
commands[commands.length - 1].args = argv.splice(0);
|
||||
}
|
||||
|
||||
|
||||
// if a directory was specified package.json is assumed to be relative
|
||||
// to it.
|
||||
let package_json_path = this.package_json_path;
|
||||
if (this.opts.directory) {
|
||||
package_json_path = path.join(this.opts.directory, package_json_path);
|
||||
}
|
||||
|
||||
this.package_json = JSON.parse(fs.readFileSync(package_json_path));
|
||||
|
||||
// expand commands entries for multiple napi builds
|
||||
this.todo = napi.expand_commands(this.package_json, this.opts, commands);
|
||||
|
||||
// support for inheriting config env variables from npm
|
||||
const npm_config_prefix = 'npm_config_';
|
||||
Object.keys(process.env).forEach((name) => {
|
||||
if (name.indexOf(npm_config_prefix) !== 0) return;
|
||||
const val = process.env[name];
|
||||
if (name === npm_config_prefix + 'loglevel') {
|
||||
log.level = val;
|
||||
} else {
|
||||
// add the user-defined options to the config
|
||||
name = name.substring(npm_config_prefix.length);
|
||||
// avoid npm argv clobber already present args
|
||||
// which avoids problem of 'npm test' calling
|
||||
// script that runs unique npm install commands
|
||||
if (name === 'argv') {
|
||||
if (this.opts.argv &&
|
||||
this.opts.argv.remain &&
|
||||
this.opts.argv.remain.length) {
|
||||
// do nothing
|
||||
} else {
|
||||
this.opts[name] = val;
|
||||
}
|
||||
} else {
|
||||
this.opts[name] = val;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (this.opts.loglevel) {
|
||||
log.level = this.opts.loglevel;
|
||||
}
|
||||
log.resume();
|
||||
};
|
||||
|
||||
/**
|
||||
* allow the binary.host property to be set at execution time.
|
||||
*
|
||||
* for this to take effect requires all the following to be true.
|
||||
* - binary is a property in package.json
|
||||
* - binary.host is falsey
|
||||
* - binary.staging_host is not empty
|
||||
* - binary.production_host is not empty
|
||||
*
|
||||
* if any of the previous checks fail then the function returns an empty string
|
||||
* and makes no changes to package.json's binary property.
|
||||
*
|
||||
*
|
||||
* if command is "publish" then the default is set to "binary.staging_host"
|
||||
* if command is not "publish" the the default is set to "binary.production_host"
|
||||
*
|
||||
* if the command-line option '--s3_host' is set to "staging" or "production" then
|
||||
* "binary.host" is set to the specified "staging_host" or "production_host". if
|
||||
* '--s3_host' is any other value an exception is thrown.
|
||||
*
|
||||
* if '--s3_host' is not present then "binary.host" is set to the default as above.
|
||||
*
|
||||
* this strategy was chosen so that any command other than "publish" or "unpublish" uses "production"
|
||||
* as the default without requiring any command-line options but that "publish" and "unpublish" require
|
||||
* '--s3_host production_host' to be specified in order to *really* publish (or unpublish). publishing
|
||||
* to staging can be done freely without worrying about disturbing any production releases.
|
||||
*/
|
||||
proto.setBinaryHostProperty = function(command) {
|
||||
if (this.binaryHostSet) {
|
||||
return this.package_json.binary.host;
|
||||
}
|
||||
const p = this.package_json;
|
||||
// don't set anything if host is present. it must be left blank to trigger this.
|
||||
if (!p || !p.binary || p.binary.host) {
|
||||
return '';
|
||||
}
|
||||
// and both staging and production must be present. errors will be reported later.
|
||||
if (!p.binary.staging_host || !p.binary.production_host) {
|
||||
return '';
|
||||
}
|
||||
let target = 'production_host';
|
||||
if (command === 'publish' || command === 'unpublish') {
|
||||
target = 'staging_host';
|
||||
}
|
||||
// the environment variable has priority over the default or the command line. if
|
||||
// either the env var or the command line option are invalid throw an error.
|
||||
const npg_s3_host = process.env.node_pre_gyp_s3_host;
|
||||
if (npg_s3_host === 'staging' || npg_s3_host === 'production') {
|
||||
target = `${npg_s3_host}_host`;
|
||||
} else if (this.opts['s3_host'] === 'staging' || this.opts['s3_host'] === 'production') {
|
||||
target = `${this.opts['s3_host']}_host`;
|
||||
} else if (this.opts['s3_host'] || npg_s3_host) {
|
||||
throw new Error(`invalid s3_host ${this.opts['s3_host'] || npg_s3_host}`);
|
||||
}
|
||||
|
||||
p.binary.host = p.binary[target];
|
||||
this.binaryHostSet = true;
|
||||
|
||||
return p.binary.host;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the usage instructions for node-pre-gyp.
|
||||
*/
|
||||
|
||||
proto.usage = function usage() {
|
||||
const str = [
|
||||
'',
|
||||
' Usage: node-pre-gyp <command> [options]',
|
||||
'',
|
||||
' where <command> is one of:',
|
||||
cli_commands.map((c) => {
|
||||
return ' - ' + c + ' - ' + require('./' + c).usage;
|
||||
}).join('\n'),
|
||||
'',
|
||||
'node-pre-gyp@' + this.version + ' ' + path.resolve(__dirname, '..'),
|
||||
'node@' + process.versions.node
|
||||
].join('\n');
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
* Version number getter.
|
||||
*/
|
||||
|
||||
Object.defineProperty(proto, 'version', {
|
||||
get: function() {
|
||||
return this.package.version;
|
||||
},
|
||||
enumerable: true
|
||||
});
|
@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = _package;
|
||||
|
||||
exports.usage = 'Packs binary (and enclosing directory) into locally staged tarball';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const log = require('npmlog');
|
||||
const versioning = require('./util/versioning.js');
|
||||
const napi = require('./util/napi.js');
|
||||
const existsAsync = fs.exists || path.exists;
|
||||
const makeDir = require('make-dir');
|
||||
const tar = require('tar');
|
||||
|
||||
function readdirSync(dir) {
|
||||
let list = [];
|
||||
const files = fs.readdirSync(dir);
|
||||
|
||||
files.forEach((file) => {
|
||||
const stats = fs.lstatSync(path.join(dir, file));
|
||||
if (stats.isDirectory()) {
|
||||
list = list.concat(readdirSync(path.join(dir, file)));
|
||||
} else {
|
||||
list.push(path.join(dir, file));
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
function _package(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
const opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
|
||||
const from = opts.module_path;
|
||||
const binary_module = path.join(from, opts.module_name + '.node');
|
||||
existsAsync(binary_module, (found) => {
|
||||
if (!found) {
|
||||
return callback(new Error('Cannot package because ' + binary_module + ' missing: run `node-pre-gyp rebuild` first'));
|
||||
}
|
||||
const tarball = opts.staged_tarball;
|
||||
const filter_func = function(entry) {
|
||||
const basename = path.basename(entry);
|
||||
if (basename.length && basename[0] !== '.') {
|
||||
console.log('packing ' + entry);
|
||||
return true;
|
||||
} else {
|
||||
console.log('skipping ' + entry);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
makeDir(path.dirname(tarball)).then(() => {
|
||||
let files = readdirSync(from);
|
||||
const base = path.basename(from);
|
||||
files = files.map((file) => {
|
||||
return path.join(base, path.relative(from, file));
|
||||
});
|
||||
tar.create({
|
||||
portable: false,
|
||||
gzip: true,
|
||||
filter: filter_func,
|
||||
file: tarball,
|
||||
cwd: path.dirname(from)
|
||||
}, files, (err2) => {
|
||||
if (err2) console.error('[' + package_json.name + '] ' + err2.message);
|
||||
else log.info('package', 'Binary staged at "' + tarball + '"');
|
||||
return callback(err2);
|
||||
});
|
||||
}).catch((err) => {
|
||||
return callback(err);
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
const npg = require('..');
|
||||
const versioning = require('../lib/util/versioning.js');
|
||||
const napi = require('../lib/util/napi.js');
|
||||
const existsSync = require('fs').existsSync || require('path').existsSync;
|
||||
const path = require('path');
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
exports.usage = 'Finds the require path for the node-pre-gyp installed module';
|
||||
|
||||
exports.validate = function(package_json, opts) {
|
||||
versioning.validate_config(package_json, opts);
|
||||
};
|
||||
|
||||
exports.find = function(package_json_path, opts) {
|
||||
if (!existsSync(package_json_path)) {
|
||||
throw new Error(package_json_path + 'does not exist');
|
||||
}
|
||||
const prog = new npg.Run({ package_json_path, argv: process.argv });
|
||||
prog.setBinaryHostProperty();
|
||||
const package_json = prog.package_json;
|
||||
|
||||
versioning.validate_config(package_json, opts);
|
||||
let napi_build_version;
|
||||
if (napi.get_napi_build_versions(package_json, opts)) {
|
||||
napi_build_version = napi.get_best_napi_build_version(package_json, opts);
|
||||
}
|
||||
opts = opts || {};
|
||||
if (!opts.module_root) opts.module_root = path.dirname(package_json_path);
|
||||
const meta = versioning.evaluate(package_json, opts, napi_build_version);
|
||||
return meta.module;
|
||||
};
|
@ -0,0 +1,81 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = publish;
|
||||
|
||||
exports.usage = 'Publishes pre-built binary (requires aws-sdk)';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const log = require('npmlog');
|
||||
const versioning = require('./util/versioning.js');
|
||||
const napi = require('./util/napi.js');
|
||||
const s3_setup = require('./util/s3_setup.js');
|
||||
const existsAsync = fs.exists || path.exists;
|
||||
const url = require('url');
|
||||
|
||||
function publish(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
const opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
|
||||
const tarball = opts.staged_tarball;
|
||||
existsAsync(tarball, (found) => {
|
||||
if (!found) {
|
||||
return callback(new Error('Cannot publish because ' + tarball + ' missing: run `node-pre-gyp package` first'));
|
||||
}
|
||||
|
||||
log.info('publish', 'Detecting s3 credentials');
|
||||
const config = {};
|
||||
s3_setup.detect(opts, config);
|
||||
const s3 = s3_setup.get_s3(config);
|
||||
|
||||
const key_name = url.resolve(config.prefix, opts.package_name);
|
||||
const s3_opts = {
|
||||
Bucket: config.bucket,
|
||||
Key: key_name
|
||||
};
|
||||
log.info('publish', 'Authenticating with s3');
|
||||
log.info('publish', config);
|
||||
|
||||
log.info('publish', 'Checking for existing binary at ' + opts.hosted_path);
|
||||
s3.headObject(s3_opts, (err, meta) => {
|
||||
if (meta) log.info('publish', JSON.stringify(meta));
|
||||
if (err && err.code === 'NotFound') {
|
||||
// we are safe to publish because
|
||||
// the object does not already exist
|
||||
log.info('publish', 'Preparing to put object');
|
||||
const s3_put_opts = {
|
||||
ACL: 'public-read',
|
||||
Body: fs.createReadStream(tarball),
|
||||
Key: key_name,
|
||||
Bucket: config.bucket
|
||||
};
|
||||
log.info('publish', 'Putting object', s3_put_opts.ACL, s3_put_opts.Bucket, s3_put_opts.Key);
|
||||
try {
|
||||
s3.putObject(s3_put_opts, (err2, resp) => {
|
||||
log.info('publish', 'returned from putting object');
|
||||
if (err2) {
|
||||
log.info('publish', 's3 putObject error: "' + err2 + '"');
|
||||
return callback(err2);
|
||||
}
|
||||
if (resp) log.info('publish', 's3 putObject response: "' + JSON.stringify(resp) + '"');
|
||||
log.info('publish', 'successfully put object');
|
||||
console.log('[' + package_json.name + '] published to ' + opts.hosted_path);
|
||||
return callback();
|
||||
});
|
||||
} catch (err3) {
|
||||
log.info('publish', 's3 putObject error: "' + err3 + '"');
|
||||
return callback(err3);
|
||||
}
|
||||
} else if (err) {
|
||||
log.info('publish', 's3 headObject error: "' + err + '"');
|
||||
return callback(err);
|
||||
} else {
|
||||
log.error('publish', 'Cannot publish over existing version');
|
||||
log.error('publish', "Update the 'version' field in package.json and try again");
|
||||
log.error('publish', 'If the previous version was published in error see:');
|
||||
log.error('publish', '\t node-pre-gyp unpublish');
|
||||
return callback(new Error('Failed publishing to ' + opts.hosted_path));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = rebuild;
|
||||
|
||||
exports.usage = 'Runs "clean" and "build" at once';
|
||||
|
||||
const napi = require('./util/napi.js');
|
||||
|
||||
function rebuild(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
let commands = [
|
||||
{ name: 'clean', args: [] },
|
||||
{ name: 'build', args: ['rebuild'] }
|
||||
];
|
||||
commands = napi.expand_commands(package_json, gyp.opts, commands);
|
||||
for (let i = commands.length; i !== 0; i--) {
|
||||
gyp.todo.unshift(commands[i - 1]);
|
||||
}
|
||||
process.nextTick(callback);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = rebuild;
|
||||
|
||||
exports.usage = 'Runs "clean" and "install" at once';
|
||||
|
||||
const napi = require('./util/napi.js');
|
||||
|
||||
function rebuild(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
let installArgs = [];
|
||||
const napi_build_version = napi.get_best_napi_build_version(package_json, gyp.opts);
|
||||
if (napi_build_version != null) installArgs = [napi.get_command_arg(napi_build_version)];
|
||||
gyp.todo.unshift(
|
||||
{ name: 'clean', args: [] },
|
||||
{ name: 'install', args: installArgs }
|
||||
);
|
||||
process.nextTick(callback);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = reveal;
|
||||
|
||||
exports.usage = 'Reveals data on the versioned binary';
|
||||
|
||||
const versioning = require('./util/versioning.js');
|
||||
const napi = require('./util/napi.js');
|
||||
|
||||
function unix_paths(key, val) {
|
||||
return val && val.replace ? val.replace(/\\/g, '/') : val;
|
||||
}
|
||||
|
||||
function reveal(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
const opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
|
||||
let hit = false;
|
||||
// if a second arg is passed look to see
|
||||
// if it is a known option
|
||||
// console.log(JSON.stringify(gyp.opts,null,1))
|
||||
const remain = gyp.opts.argv.remain[gyp.opts.argv.remain.length - 1];
|
||||
if (remain && Object.hasOwnProperty.call(opts, remain)) {
|
||||
console.log(opts[remain].replace(/\\/g, '/'));
|
||||
hit = true;
|
||||
}
|
||||
// otherwise return all options as json
|
||||
if (!hit) {
|
||||
console.log(JSON.stringify(opts, unix_paths, 2));
|
||||
}
|
||||
return callback();
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = testbinary;
|
||||
|
||||
exports.usage = 'Tests that the binary.node can be required';
|
||||
|
||||
const path = require('path');
|
||||
const log = require('npmlog');
|
||||
const cp = require('child_process');
|
||||
const versioning = require('./util/versioning.js');
|
||||
const napi = require('./util/napi.js');
|
||||
|
||||
function testbinary(gyp, argv, callback) {
|
||||
const args = [];
|
||||
const options = {};
|
||||
let shell_cmd = process.execPath;
|
||||
const package_json = gyp.package_json;
|
||||
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
const opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
|
||||
// skip validation for runtimes we don't explicitly support (like electron)
|
||||
if (opts.runtime &&
|
||||
opts.runtime !== 'node-webkit' &&
|
||||
opts.runtime !== 'node') {
|
||||
return callback();
|
||||
}
|
||||
const nw = (opts.runtime && opts.runtime === 'node-webkit');
|
||||
// ensure on windows that / are used for require path
|
||||
const binary_module = opts.module.replace(/\\/g, '/');
|
||||
if ((process.arch !== opts.target_arch) ||
|
||||
(process.platform !== opts.target_platform)) {
|
||||
let msg = 'skipping validation since host platform/arch (';
|
||||
msg += process.platform + '/' + process.arch + ')';
|
||||
msg += ' does not match target (';
|
||||
msg += opts.target_platform + '/' + opts.target_arch + ')';
|
||||
log.info('validate', msg);
|
||||
return callback();
|
||||
}
|
||||
if (nw) {
|
||||
options.timeout = 5000;
|
||||
if (process.platform === 'darwin') {
|
||||
shell_cmd = 'node-webkit';
|
||||
} else if (process.platform === 'win32') {
|
||||
shell_cmd = 'nw.exe';
|
||||
} else {
|
||||
shell_cmd = 'nw';
|
||||
}
|
||||
const modulePath = path.resolve(binary_module);
|
||||
const appDir = path.join(__dirname, 'util', 'nw-pre-gyp');
|
||||
args.push(appDir);
|
||||
args.push(modulePath);
|
||||
log.info('validate', "Running test command: '" + shell_cmd + ' ' + args.join(' ') + "'");
|
||||
cp.execFile(shell_cmd, args, options, (err, stdout, stderr) => {
|
||||
// check for normal timeout for node-webkit
|
||||
if (err) {
|
||||
if (err.killed === true && err.signal && err.signal.indexOf('SIG') > -1) {
|
||||
return callback();
|
||||
}
|
||||
const stderrLog = stderr.toString();
|
||||
log.info('stderr', stderrLog);
|
||||
if (/^\s*Xlib:\s*extension\s*"RANDR"\s*missing\s*on\s*display\s*":\d+\.\d+"\.\s*$/.test(stderrLog)) {
|
||||
log.info('RANDR', 'stderr contains only RANDR error, ignored');
|
||||
return callback();
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
return callback();
|
||||
});
|
||||
return;
|
||||
}
|
||||
args.push('--eval');
|
||||
args.push("require('" + binary_module.replace(/'/g, '\'') + "')");
|
||||
log.info('validate', "Running test command: '" + shell_cmd + ' ' + args.join(' ') + "'");
|
||||
cp.execFile(shell_cmd, args, options, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
return callback(err, { stdout: stdout, stderr: stderr });
|
||||
}
|
||||
return callback();
|
||||
});
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = testpackage;
|
||||
|
||||
exports.usage = 'Tests that the staged package is valid';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const log = require('npmlog');
|
||||
const existsAsync = fs.exists || path.exists;
|
||||
const versioning = require('./util/versioning.js');
|
||||
const napi = require('./util/napi.js');
|
||||
const testbinary = require('./testbinary.js');
|
||||
const tar = require('tar');
|
||||
const makeDir = require('make-dir');
|
||||
|
||||
function testpackage(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
const opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
|
||||
const tarball = opts.staged_tarball;
|
||||
existsAsync(tarball, (found) => {
|
||||
if (!found) {
|
||||
return callback(new Error('Cannot test package because ' + tarball + ' missing: run `node-pre-gyp package` first'));
|
||||
}
|
||||
const to = opts.module_path;
|
||||
function filter_func(entry) {
|
||||
log.info('install', 'unpacking [' + entry.path + ']');
|
||||
}
|
||||
|
||||
makeDir(to).then(() => {
|
||||
tar.extract({
|
||||
file: tarball,
|
||||
cwd: to,
|
||||
strip: 1,
|
||||
onentry: filter_func
|
||||
}).then(after_extract, callback);
|
||||
}).catch((err) => {
|
||||
return callback(err);
|
||||
});
|
||||
|
||||
function after_extract() {
|
||||
testbinary(gyp, argv, (err) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
} else {
|
||||
console.log('[' + package_json.name + '] Package appears valid');
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = unpublish;
|
||||
|
||||
exports.usage = 'Unpublishes pre-built binary (requires aws-sdk)';
|
||||
|
||||
const log = require('npmlog');
|
||||
const versioning = require('./util/versioning.js');
|
||||
const napi = require('./util/napi.js');
|
||||
const s3_setup = require('./util/s3_setup.js');
|
||||
const url = require('url');
|
||||
|
||||
function unpublish(gyp, argv, callback) {
|
||||
const package_json = gyp.package_json;
|
||||
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
const opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
|
||||
const config = {};
|
||||
s3_setup.detect(opts, config);
|
||||
const s3 = s3_setup.get_s3(config);
|
||||
const key_name = url.resolve(config.prefix, opts.package_name);
|
||||
const s3_opts = {
|
||||
Bucket: config.bucket,
|
||||
Key: key_name
|
||||
};
|
||||
s3.headObject(s3_opts, (err, meta) => {
|
||||
if (err && err.code === 'NotFound') {
|
||||
console.log('[' + package_json.name + '] Not found: https://' + s3_opts.Bucket + '.s3.amazonaws.com/' + s3_opts.Key);
|
||||
return callback();
|
||||
} else if (err) {
|
||||
return callback(err);
|
||||
} else {
|
||||
log.info('unpublish', JSON.stringify(meta));
|
||||
s3.deleteObject(s3_opts, (err2, resp) => {
|
||||
if (err2) return callback(err2);
|
||||
log.info(JSON.stringify(resp));
|
||||
console.log('[' + package_json.name + '] Success: removed https://' + s3_opts.Bucket + '.s3.amazonaws.com/' + s3_opts.Key);
|
||||
return callback();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,93 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const win = process.platform === 'win32';
|
||||
const existsSync = fs.existsSync || path.existsSync;
|
||||
const cp = require('child_process');
|
||||
|
||||
// try to build up the complete path to node-gyp
|
||||
/* priority:
|
||||
- node-gyp on ENV:npm_config_node_gyp (https://github.com/npm/npm/pull/4887)
|
||||
- node-gyp on NODE_PATH
|
||||
- node-gyp inside npm on NODE_PATH (ignore on iojs)
|
||||
- node-gyp inside npm beside node exe
|
||||
*/
|
||||
function which_node_gyp() {
|
||||
let node_gyp_bin;
|
||||
if (process.env.npm_config_node_gyp) {
|
||||
try {
|
||||
node_gyp_bin = process.env.npm_config_node_gyp;
|
||||
if (existsSync(node_gyp_bin)) {
|
||||
return node_gyp_bin;
|
||||
}
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
try {
|
||||
const node_gyp_main = require.resolve('node-gyp'); // eslint-disable-line node/no-missing-require
|
||||
node_gyp_bin = path.join(path.dirname(
|
||||
path.dirname(node_gyp_main)),
|
||||
'bin/node-gyp.js');
|
||||
if (existsSync(node_gyp_bin)) {
|
||||
return node_gyp_bin;
|
||||
}
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
if (process.execPath.indexOf('iojs') === -1) {
|
||||
try {
|
||||
const npm_main = require.resolve('npm'); // eslint-disable-line node/no-missing-require
|
||||
node_gyp_bin = path.join(path.dirname(
|
||||
path.dirname(npm_main)),
|
||||
'node_modules/node-gyp/bin/node-gyp.js');
|
||||
if (existsSync(node_gyp_bin)) {
|
||||
return node_gyp_bin;
|
||||
}
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
const npm_base = path.join(path.dirname(
|
||||
path.dirname(process.execPath)),
|
||||
'lib/node_modules/npm/');
|
||||
node_gyp_bin = path.join(npm_base, 'node_modules/node-gyp/bin/node-gyp.js');
|
||||
if (existsSync(node_gyp_bin)) {
|
||||
return node_gyp_bin;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.run_gyp = function(args, opts, callback) {
|
||||
let shell_cmd = '';
|
||||
const cmd_args = [];
|
||||
if (opts.runtime && opts.runtime === 'node-webkit') {
|
||||
shell_cmd = 'nw-gyp';
|
||||
if (win) shell_cmd += '.cmd';
|
||||
} else {
|
||||
const node_gyp_path = which_node_gyp();
|
||||
if (node_gyp_path) {
|
||||
shell_cmd = process.execPath;
|
||||
cmd_args.push(node_gyp_path);
|
||||
} else {
|
||||
shell_cmd = 'node-gyp';
|
||||
if (win) shell_cmd += '.cmd';
|
||||
}
|
||||
}
|
||||
const final_args = cmd_args.concat(args);
|
||||
const cmd = cp.spawn(shell_cmd, final_args, { cwd: undefined, env: process.env, stdio: [0, 1, 2] });
|
||||
cmd.on('error', (err) => {
|
||||
if (err) {
|
||||
return callback(new Error("Failed to execute '" + shell_cmd + ' ' + final_args.join(' ') + "' (" + err + ')'));
|
||||
}
|
||||
callback(null, opts);
|
||||
});
|
||||
cmd.on('close', (code) => {
|
||||
if (code && code !== 0) {
|
||||
return callback(new Error("Failed to execute '" + shell_cmd + ' ' + final_args.join(' ') + "' (" + code + ')'));
|
||||
}
|
||||
callback(null, opts);
|
||||
});
|
||||
};
|
@ -0,0 +1,102 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = handle_gyp_opts;
|
||||
|
||||
const versioning = require('./versioning.js');
|
||||
const napi = require('./napi.js');
|
||||
|
||||
/*
|
||||
|
||||
Here we gather node-pre-gyp generated options (from versioning) and pass them along to node-gyp.
|
||||
|
||||
We massage the args and options slightly to account for differences in what commands mean between
|
||||
node-pre-gyp and node-gyp (e.g. see the difference between "build" and "rebuild" below)
|
||||
|
||||
Keep in mind: the values inside `argv` and `gyp.opts` below are different depending on whether
|
||||
node-pre-gyp is called directory, or if it is called in a `run-script` phase of npm.
|
||||
|
||||
We also try to preserve any command line options that might have been passed to npm or node-pre-gyp.
|
||||
But this is fairly difficult without passing way to much through. For example `gyp.opts` contains all
|
||||
the process.env and npm pushes a lot of variables into process.env which node-pre-gyp inherits. So we have
|
||||
to be very selective about what we pass through.
|
||||
|
||||
For example:
|
||||
|
||||
`npm install --build-from-source` will give:
|
||||
|
||||
argv == [ 'rebuild' ]
|
||||
gyp.opts.argv == { remain: [ 'install' ],
|
||||
cooked: [ 'install', '--fallback-to-build' ],
|
||||
original: [ 'install', '--fallback-to-build' ] }
|
||||
|
||||
`./bin/node-pre-gyp build` will give:
|
||||
|
||||
argv == []
|
||||
gyp.opts.argv == { remain: [ 'build' ],
|
||||
cooked: [ 'build' ],
|
||||
original: [ '-C', 'test/app1', 'build' ] }
|
||||
|
||||
*/
|
||||
|
||||
// select set of node-pre-gyp versioning info
|
||||
// to share with node-gyp
|
||||
const share_with_node_gyp = [
|
||||
'module',
|
||||
'module_name',
|
||||
'module_path',
|
||||
'napi_version',
|
||||
'node_abi_napi',
|
||||
'napi_build_version',
|
||||
'node_napi_label'
|
||||
];
|
||||
|
||||
function handle_gyp_opts(gyp, argv, callback) {
|
||||
|
||||
// Collect node-pre-gyp specific variables to pass to node-gyp
|
||||
const node_pre_gyp_options = [];
|
||||
// generate custom node-pre-gyp versioning info
|
||||
const napi_build_version = napi.get_napi_build_version_from_command_args(argv);
|
||||
const opts = versioning.evaluate(gyp.package_json, gyp.opts, napi_build_version);
|
||||
share_with_node_gyp.forEach((key) => {
|
||||
const val = opts[key];
|
||||
if (val) {
|
||||
node_pre_gyp_options.push('--' + key + '=' + val);
|
||||
} else if (key === 'napi_build_version') {
|
||||
node_pre_gyp_options.push('--' + key + '=0');
|
||||
} else {
|
||||
if (key !== 'napi_version' && key !== 'node_abi_napi')
|
||||
return callback(new Error('Option ' + key + ' required but not found by node-pre-gyp'));
|
||||
}
|
||||
});
|
||||
|
||||
// Collect options that follow the special -- which disables nopt parsing
|
||||
const unparsed_options = [];
|
||||
let double_hyphen_found = false;
|
||||
gyp.opts.argv.original.forEach((opt) => {
|
||||
if (double_hyphen_found) {
|
||||
unparsed_options.push(opt);
|
||||
}
|
||||
if (opt === '--') {
|
||||
double_hyphen_found = true;
|
||||
}
|
||||
});
|
||||
|
||||
// We try respect and pass through remaining command
|
||||
// line options (like --foo=bar) to node-gyp
|
||||
const cooked = gyp.opts.argv.cooked;
|
||||
const node_gyp_options = [];
|
||||
cooked.forEach((value) => {
|
||||
if (value.length > 2 && value.slice(0, 2) === '--') {
|
||||
const key = value.slice(2);
|
||||
const val = cooked[cooked.indexOf(value) + 1];
|
||||
if (val && val.indexOf('--') === -1) { // handle '--foo=bar' or ['--foo','bar']
|
||||
node_gyp_options.push('--' + key + '=' + val);
|
||||
} else { // pass through --foo
|
||||
node_gyp_options.push(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const result = { 'opts': opts, 'gyp': node_gyp_options, 'pre': node_pre_gyp_options, 'unparsed': unparsed_options };
|
||||
return callback(null, result);
|
||||
}
|
@ -0,0 +1,205 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
const versionArray = process.version
|
||||
.substr(1)
|
||||
.replace(/-.*$/, '')
|
||||
.split('.')
|
||||
.map((item) => {
|
||||
return +item;
|
||||
});
|
||||
|
||||
const napi_multiple_commands = [
|
||||
'build',
|
||||
'clean',
|
||||
'configure',
|
||||
'package',
|
||||
'publish',
|
||||
'reveal',
|
||||
'testbinary',
|
||||
'testpackage',
|
||||
'unpublish'
|
||||
];
|
||||
|
||||
const napi_build_version_tag = 'napi_build_version=';
|
||||
|
||||
module.exports.get_napi_version = function() {
|
||||
// returns the non-zero numeric napi version or undefined if napi is not supported.
|
||||
// correctly supporting target requires an updated cross-walk
|
||||
let version = process.versions.napi; // can be undefined
|
||||
if (!version) { // this code should never need to be updated
|
||||
if (versionArray[0] === 9 && versionArray[1] >= 3) version = 2; // 9.3.0+
|
||||
else if (versionArray[0] === 8) version = 1; // 8.0.0+
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
module.exports.get_napi_version_as_string = function(target) {
|
||||
// returns the napi version as a string or an empty string if napi is not supported.
|
||||
const version = module.exports.get_napi_version(target);
|
||||
return version ? '' + version : '';
|
||||
};
|
||||
|
||||
module.exports.validate_package_json = function(package_json, opts) { // throws Error
|
||||
|
||||
const binary = package_json.binary;
|
||||
const module_path_ok = pathOK(binary.module_path);
|
||||
const remote_path_ok = pathOK(binary.remote_path);
|
||||
const package_name_ok = pathOK(binary.package_name);
|
||||
const napi_build_versions = module.exports.get_napi_build_versions(package_json, opts, true);
|
||||
const napi_build_versions_raw = module.exports.get_napi_build_versions_raw(package_json);
|
||||
|
||||
if (napi_build_versions) {
|
||||
napi_build_versions.forEach((napi_build_version)=> {
|
||||
if (!(parseInt(napi_build_version, 10) === napi_build_version && napi_build_version > 0)) {
|
||||
throw new Error('All values specified in napi_versions must be positive integers.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (napi_build_versions && (!module_path_ok || (!remote_path_ok && !package_name_ok))) {
|
||||
throw new Error('When napi_versions is specified; module_path and either remote_path or ' +
|
||||
"package_name must contain the substitution string '{napi_build_version}`.");
|
||||
}
|
||||
|
||||
if ((module_path_ok || remote_path_ok || package_name_ok) && !napi_build_versions_raw) {
|
||||
throw new Error("When the substitution string '{napi_build_version}` is specified in " +
|
||||
'module_path, remote_path, or package_name; napi_versions must also be specified.');
|
||||
}
|
||||
|
||||
if (napi_build_versions && !module.exports.get_best_napi_build_version(package_json, opts) &&
|
||||
module.exports.build_napi_only(package_json)) {
|
||||
throw new Error(
|
||||
'The Node-API version of this Node instance is ' + module.exports.get_napi_version(opts ? opts.target : undefined) + '. ' +
|
||||
'This module supports Node-API version(s) ' + module.exports.get_napi_build_versions_raw(package_json) + '. ' +
|
||||
'This Node instance cannot run this module.');
|
||||
}
|
||||
|
||||
if (napi_build_versions_raw && !napi_build_versions && module.exports.build_napi_only(package_json)) {
|
||||
throw new Error(
|
||||
'The Node-API version of this Node instance is ' + module.exports.get_napi_version(opts ? opts.target : undefined) + '. ' +
|
||||
'This module supports Node-API version(s) ' + module.exports.get_napi_build_versions_raw(package_json) + '. ' +
|
||||
'This Node instance cannot run this module.');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function pathOK(path) {
|
||||
return path && (path.indexOf('{napi_build_version}') !== -1 || path.indexOf('{node_napi_label}') !== -1);
|
||||
}
|
||||
|
||||
module.exports.expand_commands = function(package_json, opts, commands) {
|
||||
const expanded_commands = [];
|
||||
const napi_build_versions = module.exports.get_napi_build_versions(package_json, opts);
|
||||
commands.forEach((command)=> {
|
||||
if (napi_build_versions && command.name === 'install') {
|
||||
const napi_build_version = module.exports.get_best_napi_build_version(package_json, opts);
|
||||
const args = napi_build_version ? [napi_build_version_tag + napi_build_version] : [];
|
||||
expanded_commands.push({ name: command.name, args: args });
|
||||
} else if (napi_build_versions && napi_multiple_commands.indexOf(command.name) !== -1) {
|
||||
napi_build_versions.forEach((napi_build_version)=> {
|
||||
const args = command.args.slice();
|
||||
args.push(napi_build_version_tag + napi_build_version);
|
||||
expanded_commands.push({ name: command.name, args: args });
|
||||
});
|
||||
} else {
|
||||
expanded_commands.push(command);
|
||||
}
|
||||
});
|
||||
return expanded_commands;
|
||||
};
|
||||
|
||||
module.exports.get_napi_build_versions = function(package_json, opts, warnings) { // opts may be undefined
|
||||
const log = require('npmlog');
|
||||
let napi_build_versions = [];
|
||||
const supported_napi_version = module.exports.get_napi_version(opts ? opts.target : undefined);
|
||||
// remove duplicates, verify each napi version can actaully be built
|
||||
if (package_json.binary && package_json.binary.napi_versions) {
|
||||
package_json.binary.napi_versions.forEach((napi_version) => {
|
||||
const duplicated = napi_build_versions.indexOf(napi_version) !== -1;
|
||||
if (!duplicated && supported_napi_version && napi_version <= supported_napi_version) {
|
||||
napi_build_versions.push(napi_version);
|
||||
} else if (warnings && !duplicated && supported_napi_version) {
|
||||
log.info('This Node instance does not support builds for Node-API version', napi_version);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (opts && opts['build-latest-napi-version-only']) {
|
||||
let latest_version = 0;
|
||||
napi_build_versions.forEach((napi_version) => {
|
||||
if (napi_version > latest_version) latest_version = napi_version;
|
||||
});
|
||||
napi_build_versions = latest_version ? [latest_version] : [];
|
||||
}
|
||||
return napi_build_versions.length ? napi_build_versions : undefined;
|
||||
};
|
||||
|
||||
module.exports.get_napi_build_versions_raw = function(package_json) {
|
||||
const napi_build_versions = [];
|
||||
// remove duplicates
|
||||
if (package_json.binary && package_json.binary.napi_versions) {
|
||||
package_json.binary.napi_versions.forEach((napi_version) => {
|
||||
if (napi_build_versions.indexOf(napi_version) === -1) {
|
||||
napi_build_versions.push(napi_version);
|
||||
}
|
||||
});
|
||||
}
|
||||
return napi_build_versions.length ? napi_build_versions : undefined;
|
||||
};
|
||||
|
||||
module.exports.get_command_arg = function(napi_build_version) {
|
||||
return napi_build_version_tag + napi_build_version;
|
||||
};
|
||||
|
||||
module.exports.get_napi_build_version_from_command_args = function(command_args) {
|
||||
for (let i = 0; i < command_args.length; i++) {
|
||||
const arg = command_args[i];
|
||||
if (arg.indexOf(napi_build_version_tag) === 0) {
|
||||
return parseInt(arg.substr(napi_build_version_tag.length), 10);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
module.exports.swap_build_dir_out = function(napi_build_version) {
|
||||
if (napi_build_version) {
|
||||
const rm = require('rimraf');
|
||||
rm.sync(module.exports.get_build_dir(napi_build_version));
|
||||
fs.renameSync('build', module.exports.get_build_dir(napi_build_version));
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.swap_build_dir_in = function(napi_build_version) {
|
||||
if (napi_build_version) {
|
||||
const rm = require('rimraf');
|
||||
rm.sync('build');
|
||||
fs.renameSync(module.exports.get_build_dir(napi_build_version), 'build');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.get_build_dir = function(napi_build_version) {
|
||||
return 'build-tmp-napi-v' + napi_build_version;
|
||||
};
|
||||
|
||||
module.exports.get_best_napi_build_version = function(package_json, opts) {
|
||||
let best_napi_build_version = 0;
|
||||
const napi_build_versions = module.exports.get_napi_build_versions(package_json, opts);
|
||||
if (napi_build_versions) {
|
||||
const our_napi_version = module.exports.get_napi_version(opts ? opts.target : undefined);
|
||||
napi_build_versions.forEach((napi_build_version)=> {
|
||||
if (napi_build_version > best_napi_build_version &&
|
||||
napi_build_version <= our_napi_version) {
|
||||
best_napi_build_version = napi_build_version;
|
||||
}
|
||||
});
|
||||
}
|
||||
return best_napi_build_version === 0 ? undefined : best_napi_build_version;
|
||||
};
|
||||
|
||||
module.exports.build_napi_only = function(package_json) {
|
||||
return package_json.binary && package_json.binary.package_name &&
|
||||
package_json.binary.package_name.indexOf('{node_napi_label}') === -1;
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Node-webkit-based module test</title>
|
||||
<script>
|
||||
function nwModuleTest(){
|
||||
var util = require('util');
|
||||
var moduleFolder = require('nw.gui').App.argv[0];
|
||||
try {
|
||||
require(moduleFolder);
|
||||
} catch(e) {
|
||||
if( process.platform !== 'win32' ){
|
||||
util.log('nw-pre-gyp error:');
|
||||
util.log(e.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
process.exit(0);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="nwModuleTest()">
|
||||
<h1>Node-webkit-based module test</h1>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"main": "index.html",
|
||||
"name": "nw-pre-gyp-module-test",
|
||||
"description": "Node-webkit-based module test.",
|
||||
"version": "0.0.1",
|
||||
"window": {
|
||||
"show": false
|
||||
}
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
const url = require('url');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports.detect = function(opts, config) {
|
||||
const to = opts.hosted_path;
|
||||
const uri = url.parse(to);
|
||||
config.prefix = (!uri.pathname || uri.pathname === '/') ? '' : uri.pathname.replace('/', '');
|
||||
if (opts.bucket && opts.region) {
|
||||
config.bucket = opts.bucket;
|
||||
config.region = opts.region;
|
||||
config.endpoint = opts.host;
|
||||
config.s3ForcePathStyle = opts.s3ForcePathStyle;
|
||||
} else {
|
||||
const parts = uri.hostname.split('.s3');
|
||||
const bucket = parts[0];
|
||||
if (!bucket) {
|
||||
return;
|
||||
}
|
||||
if (!config.bucket) {
|
||||
config.bucket = bucket;
|
||||
}
|
||||
if (!config.region) {
|
||||
const region = parts[1].slice(1).split('.')[0];
|
||||
if (region === 'amazonaws') {
|
||||
config.region = 'us-east-1';
|
||||
} else {
|
||||
config.region = region;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.get_s3 = function(config) {
|
||||
|
||||
if (process.env.node_pre_gyp_mock_s3) {
|
||||
// here we're mocking. node_pre_gyp_mock_s3 is the scratch directory
|
||||
// for the mock code.
|
||||
const AWSMock = require('mock-aws-s3');
|
||||
const os = require('os');
|
||||
|
||||
AWSMock.config.basePath = `${os.tmpdir()}/mock`;
|
||||
|
||||
const s3 = AWSMock.S3();
|
||||
|
||||
// wrapped callback maker. fs calls return code of ENOENT but AWS.S3 returns
|
||||
// NotFound.
|
||||
const wcb = (fn) => (err, ...args) => {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
err.code = 'NotFound';
|
||||
}
|
||||
return fn(err, ...args);
|
||||
};
|
||||
|
||||
return {
|
||||
listObjects(params, callback) {
|
||||
return s3.listObjects(params, wcb(callback));
|
||||
},
|
||||
headObject(params, callback) {
|
||||
return s3.headObject(params, wcb(callback));
|
||||
},
|
||||
deleteObject(params, callback) {
|
||||
return s3.deleteObject(params, wcb(callback));
|
||||
},
|
||||
putObject(params, callback) {
|
||||
return s3.putObject(params, wcb(callback));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// if not mocking then setup real s3.
|
||||
const AWS = require('aws-sdk');
|
||||
|
||||
AWS.config.update(config);
|
||||
const s3 = new AWS.S3();
|
||||
|
||||
// need to change if additional options need to be specified.
|
||||
return {
|
||||
listObjects(params, callback) {
|
||||
return s3.listObjects(params, callback);
|
||||
},
|
||||
headObject(params, callback) {
|
||||
return s3.headObject(params, callback);
|
||||
},
|
||||
deleteObject(params, callback) {
|
||||
return s3.deleteObject(params, callback);
|
||||
},
|
||||
putObject(params, callback) {
|
||||
return s3.putObject(params, callback);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
// function to get the mocking control function. if not mocking it returns a no-op.
|
||||
//
|
||||
// if mocking it sets up the mock http interceptors that use the mocked s3 file system
|
||||
// to fulfill reponses.
|
||||
module.exports.get_mockS3Http = function() {
|
||||
let mock_s3 = false;
|
||||
if (!process.env.node_pre_gyp_mock_s3) {
|
||||
return () => mock_s3;
|
||||
}
|
||||
|
||||
const nock = require('nock');
|
||||
// the bucket used for testing, as addressed by https.
|
||||
const host = 'https://mapbox-node-pre-gyp-public-testing-bucket.s3.us-east-1.amazonaws.com';
|
||||
const mockDir = process.env.node_pre_gyp_mock_s3 + '/mapbox-node-pre-gyp-public-testing-bucket';
|
||||
|
||||
// function to setup interceptors. they are "turned off" by setting mock_s3 to false.
|
||||
const mock_http = () => {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function get(uri, requestBody) {
|
||||
const filepath = path.join(mockDir, uri.replace('%2B', '+'));
|
||||
|
||||
try {
|
||||
fs.accessSync(filepath, fs.constants.R_OK);
|
||||
} catch (e) {
|
||||
return [404, 'not found\n'];
|
||||
}
|
||||
|
||||
// the mock s3 functions just write to disk, so just read from it.
|
||||
return [200, fs.createReadStream(filepath)];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
return nock(host)
|
||||
.persist()
|
||||
.get(() => mock_s3) // mock any uri for s3 when true
|
||||
.reply(get);
|
||||
};
|
||||
|
||||
// setup interceptors. they check the mock_s3 flag to determine whether to intercept.
|
||||
mock_http(nock, host, mockDir);
|
||||
// function to turn matching all requests to s3 on/off.
|
||||
const mockS3Http = (action) => {
|
||||
const previous = mock_s3;
|
||||
if (action === 'off') {
|
||||
mock_s3 = false;
|
||||
} else if (action === 'on') {
|
||||
mock_s3 = true;
|
||||
} else if (action !== 'get') {
|
||||
throw new Error(`illegal action for setMockHttp ${action}`);
|
||||
}
|
||||
return previous;
|
||||
};
|
||||
|
||||
// call mockS3Http with the argument
|
||||
// - 'on' - turn it on
|
||||
// - 'off' - turn it off (used by fetch.test.js so it doesn't interfere with redirects)
|
||||
// - 'get' - return true or false for 'on' or 'off'
|
||||
return mockS3Http;
|
||||
};
|
||||
|
||||
|
||||
|
@ -0,0 +1,335 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
const path = require('path');
|
||||
const semver = require('semver');
|
||||
const url = require('url');
|
||||
const detect_libc = require('detect-libc');
|
||||
const napi = require('./napi.js');
|
||||
|
||||
let abi_crosswalk;
|
||||
|
||||
// This is used for unit testing to provide a fake
|
||||
// ABI crosswalk that emulates one that is not updated
|
||||
// for the current version
|
||||
if (process.env.NODE_PRE_GYP_ABI_CROSSWALK) {
|
||||
abi_crosswalk = require(process.env.NODE_PRE_GYP_ABI_CROSSWALK);
|
||||
} else {
|
||||
abi_crosswalk = require('./abi_crosswalk.json');
|
||||
}
|
||||
|
||||
const major_versions = {};
|
||||
Object.keys(abi_crosswalk).forEach((v) => {
|
||||
const major = v.split('.')[0];
|
||||
if (!major_versions[major]) {
|
||||
major_versions[major] = v;
|
||||
}
|
||||
});
|
||||
|
||||
function get_electron_abi(runtime, target_version) {
|
||||
if (!runtime) {
|
||||
throw new Error('get_electron_abi requires valid runtime arg');
|
||||
}
|
||||
if (typeof target_version === 'undefined') {
|
||||
// erroneous CLI call
|
||||
throw new Error('Empty target version is not supported if electron is the target.');
|
||||
}
|
||||
// Electron guarantees that patch version update won't break native modules.
|
||||
const sem_ver = semver.parse(target_version);
|
||||
return runtime + '-v' + sem_ver.major + '.' + sem_ver.minor;
|
||||
}
|
||||
module.exports.get_electron_abi = get_electron_abi;
|
||||
|
||||
function get_node_webkit_abi(runtime, target_version) {
|
||||
if (!runtime) {
|
||||
throw new Error('get_node_webkit_abi requires valid runtime arg');
|
||||
}
|
||||
if (typeof target_version === 'undefined') {
|
||||
// erroneous CLI call
|
||||
throw new Error('Empty target version is not supported if node-webkit is the target.');
|
||||
}
|
||||
return runtime + '-v' + target_version;
|
||||
}
|
||||
module.exports.get_node_webkit_abi = get_node_webkit_abi;
|
||||
|
||||
function get_node_abi(runtime, versions) {
|
||||
if (!runtime) {
|
||||
throw new Error('get_node_abi requires valid runtime arg');
|
||||
}
|
||||
if (!versions) {
|
||||
throw new Error('get_node_abi requires valid process.versions object');
|
||||
}
|
||||
const sem_ver = semver.parse(versions.node);
|
||||
if (sem_ver.major === 0 && sem_ver.minor % 2) { // odd series
|
||||
// https://github.com/mapbox/node-pre-gyp/issues/124
|
||||
return runtime + '-v' + versions.node;
|
||||
} else {
|
||||
// process.versions.modules added in >= v0.10.4 and v0.11.7
|
||||
// https://github.com/joyent/node/commit/ccabd4a6fa8a6eb79d29bc3bbe9fe2b6531c2d8e
|
||||
return versions.modules ? runtime + '-v' + (+versions.modules) :
|
||||
'v8-' + versions.v8.split('.').slice(0, 2).join('.');
|
||||
}
|
||||
}
|
||||
module.exports.get_node_abi = get_node_abi;
|
||||
|
||||
function get_runtime_abi(runtime, target_version) {
|
||||
if (!runtime) {
|
||||
throw new Error('get_runtime_abi requires valid runtime arg');
|
||||
}
|
||||
if (runtime === 'node-webkit') {
|
||||
return get_node_webkit_abi(runtime, target_version || process.versions['node-webkit']);
|
||||
} else if (runtime === 'electron') {
|
||||
return get_electron_abi(runtime, target_version || process.versions.electron);
|
||||
} else {
|
||||
if (runtime !== 'node') {
|
||||
throw new Error("Unknown Runtime: '" + runtime + "'");
|
||||
}
|
||||
if (!target_version) {
|
||||
return get_node_abi(runtime, process.versions);
|
||||
} else {
|
||||
let cross_obj;
|
||||
// abi_crosswalk generated with ./scripts/abi_crosswalk.js
|
||||
if (abi_crosswalk[target_version]) {
|
||||
cross_obj = abi_crosswalk[target_version];
|
||||
} else {
|
||||
const target_parts = target_version.split('.').map((i) => { return +i; });
|
||||
if (target_parts.length !== 3) { // parse failed
|
||||
throw new Error('Unknown target version: ' + target_version);
|
||||
}
|
||||
/*
|
||||
The below code tries to infer the last known ABI compatible version
|
||||
that we have recorded in the abi_crosswalk.json when an exact match
|
||||
is not possible. The reasons for this to exist are complicated:
|
||||
|
||||
- We support passing --target to be able to allow developers to package binaries for versions of node
|
||||
that are not the same one as they are running. This might also be used in combination with the
|
||||
--target_arch or --target_platform flags to also package binaries for alternative platforms
|
||||
- When --target is passed we can't therefore determine the ABI (process.versions.modules) from the node
|
||||
version that is running in memory
|
||||
- So, therefore node-pre-gyp keeps an "ABI crosswalk" (lib/util/abi_crosswalk.json) to be able to look
|
||||
this info up for all versions
|
||||
- But we cannot easily predict what the future ABI will be for released versions
|
||||
- And node-pre-gyp needs to be a `bundledDependency` in apps that depend on it in order to work correctly
|
||||
by being fully available at install time.
|
||||
- So, the speed of node releases and the bundled nature of node-pre-gyp mean that a new node-pre-gyp release
|
||||
need to happen for every node.js/io.js/node-webkit/nw.js/atom-shell/etc release that might come online if
|
||||
you want the `--target` flag to keep working for the latest version
|
||||
- Which is impractical ^^
|
||||
- Hence the below code guesses about future ABI to make the need to update node-pre-gyp less demanding.
|
||||
|
||||
In practice then you can have a dependency of your app like `node-sqlite3` that bundles a `node-pre-gyp` that
|
||||
only knows about node v0.10.33 in the `abi_crosswalk.json` but target node v0.10.34 (which is assumed to be
|
||||
ABI compatible with v0.10.33).
|
||||
|
||||
TODO: use semver module instead of custom version parsing
|
||||
*/
|
||||
const major = target_parts[0];
|
||||
let minor = target_parts[1];
|
||||
let patch = target_parts[2];
|
||||
// io.js: yeah if node.js ever releases 1.x this will break
|
||||
// but that is unlikely to happen: https://github.com/iojs/io.js/pull/253#issuecomment-69432616
|
||||
if (major === 1) {
|
||||
// look for last release that is the same major version
|
||||
// e.g. we assume io.js 1.x is ABI compatible with >= 1.0.0
|
||||
while (true) {
|
||||
if (minor > 0) --minor;
|
||||
if (patch > 0) --patch;
|
||||
const new_iojs_target = '' + major + '.' + minor + '.' + patch;
|
||||
if (abi_crosswalk[new_iojs_target]) {
|
||||
cross_obj = abi_crosswalk[new_iojs_target];
|
||||
console.log('Warning: node-pre-gyp could not find exact match for ' + target_version);
|
||||
console.log('Warning: but node-pre-gyp successfully choose ' + new_iojs_target + ' as ABI compatible target');
|
||||
break;
|
||||
}
|
||||
if (minor === 0 && patch === 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (major >= 2) {
|
||||
// look for last release that is the same major version
|
||||
if (major_versions[major]) {
|
||||
cross_obj = abi_crosswalk[major_versions[major]];
|
||||
console.log('Warning: node-pre-gyp could not find exact match for ' + target_version);
|
||||
console.log('Warning: but node-pre-gyp successfully choose ' + major_versions[major] + ' as ABI compatible target');
|
||||
}
|
||||
} else if (major === 0) { // node.js
|
||||
if (target_parts[1] % 2 === 0) { // for stable/even node.js series
|
||||
// look for the last release that is the same minor release
|
||||
// e.g. we assume node 0.10.x is ABI compatible with >= 0.10.0
|
||||
while (--patch > 0) {
|
||||
const new_node_target = '' + major + '.' + minor + '.' + patch;
|
||||
if (abi_crosswalk[new_node_target]) {
|
||||
cross_obj = abi_crosswalk[new_node_target];
|
||||
console.log('Warning: node-pre-gyp could not find exact match for ' + target_version);
|
||||
console.log('Warning: but node-pre-gyp successfully choose ' + new_node_target + ' as ABI compatible target');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cross_obj) {
|
||||
throw new Error('Unsupported target version: ' + target_version);
|
||||
}
|
||||
// emulate process.versions
|
||||
const versions_obj = {
|
||||
node: target_version,
|
||||
v8: cross_obj.v8 + '.0',
|
||||
// abi_crosswalk uses 1 for node versions lacking process.versions.modules
|
||||
// process.versions.modules added in >= v0.10.4 and v0.11.7
|
||||
modules: cross_obj.node_abi > 1 ? cross_obj.node_abi : undefined
|
||||
};
|
||||
return get_node_abi(runtime, versions_obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports.get_runtime_abi = get_runtime_abi;
|
||||
|
||||
const required_parameters = [
|
||||
'module_name',
|
||||
'module_path',
|
||||
'host'
|
||||
];
|
||||
|
||||
function validate_config(package_json, opts) {
|
||||
const msg = package_json.name + ' package.json is not node-pre-gyp ready:\n';
|
||||
const missing = [];
|
||||
if (!package_json.main) {
|
||||
missing.push('main');
|
||||
}
|
||||
if (!package_json.version) {
|
||||
missing.push('version');
|
||||
}
|
||||
if (!package_json.name) {
|
||||
missing.push('name');
|
||||
}
|
||||
if (!package_json.binary) {
|
||||
missing.push('binary');
|
||||
}
|
||||
const o = package_json.binary;
|
||||
if (o) {
|
||||
required_parameters.forEach((p) => {
|
||||
if (!o[p] || typeof o[p] !== 'string') {
|
||||
missing.push('binary.' + p);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (missing.length >= 1) {
|
||||
throw new Error(msg + 'package.json must declare these properties: \n' + missing.join('\n'));
|
||||
}
|
||||
if (o) {
|
||||
// enforce https over http
|
||||
const protocol = url.parse(o.host).protocol;
|
||||
if (protocol === 'http:') {
|
||||
throw new Error("'host' protocol (" + protocol + ") is invalid - only 'https:' is accepted");
|
||||
}
|
||||
}
|
||||
napi.validate_package_json(package_json, opts);
|
||||
}
|
||||
|
||||
module.exports.validate_config = validate_config;
|
||||
|
||||
function eval_template(template, opts) {
|
||||
Object.keys(opts).forEach((key) => {
|
||||
const pattern = '{' + key + '}';
|
||||
while (template.indexOf(pattern) > -1) {
|
||||
template = template.replace(pattern, opts[key]);
|
||||
}
|
||||
});
|
||||
return template;
|
||||
}
|
||||
|
||||
// url.resolve needs single trailing slash
|
||||
// to behave correctly, otherwise a double slash
|
||||
// may end up in the url which breaks requests
|
||||
// and a lacking slash may not lead to proper joining
|
||||
function fix_slashes(pathname) {
|
||||
if (pathname.slice(-1) !== '/') {
|
||||
return pathname + '/';
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
|
||||
// remove double slashes
|
||||
// note: path.normalize will not work because
|
||||
// it will convert forward to back slashes
|
||||
function drop_double_slashes(pathname) {
|
||||
return pathname.replace(/\/\//g, '/');
|
||||
}
|
||||
|
||||
function get_process_runtime(versions) {
|
||||
let runtime = 'node';
|
||||
if (versions['node-webkit']) {
|
||||
runtime = 'node-webkit';
|
||||
} else if (versions.electron) {
|
||||
runtime = 'electron';
|
||||
}
|
||||
return runtime;
|
||||
}
|
||||
|
||||
module.exports.get_process_runtime = get_process_runtime;
|
||||
|
||||
const default_package_name = '{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz';
|
||||
const default_remote_path = '';
|
||||
|
||||
module.exports.evaluate = function(package_json, options, napi_build_version) {
|
||||
options = options || {};
|
||||
validate_config(package_json, options); // options is a suitable substitute for opts in this case
|
||||
const v = package_json.version;
|
||||
const module_version = semver.parse(v);
|
||||
const runtime = options.runtime || get_process_runtime(process.versions);
|
||||
const opts = {
|
||||
name: package_json.name,
|
||||
configuration: options.debug ? 'Debug' : 'Release',
|
||||
debug: options.debug,
|
||||
module_name: package_json.binary.module_name,
|
||||
version: module_version.version,
|
||||
prerelease: module_version.prerelease.length ? module_version.prerelease.join('.') : '',
|
||||
build: module_version.build.length ? module_version.build.join('.') : '',
|
||||
major: module_version.major,
|
||||
minor: module_version.minor,
|
||||
patch: module_version.patch,
|
||||
runtime: runtime,
|
||||
node_abi: get_runtime_abi(runtime, options.target),
|
||||
node_abi_napi: napi.get_napi_version(options.target) ? 'napi' : get_runtime_abi(runtime, options.target),
|
||||
napi_version: napi.get_napi_version(options.target), // non-zero numeric, undefined if unsupported
|
||||
napi_build_version: napi_build_version || '',
|
||||
node_napi_label: napi_build_version ? 'napi-v' + napi_build_version : get_runtime_abi(runtime, options.target),
|
||||
target: options.target || '',
|
||||
platform: options.target_platform || process.platform,
|
||||
target_platform: options.target_platform || process.platform,
|
||||
arch: options.target_arch || process.arch,
|
||||
target_arch: options.target_arch || process.arch,
|
||||
libc: options.target_libc || detect_libc.familySync() || 'unknown',
|
||||
module_main: package_json.main,
|
||||
toolset: options.toolset || '', // address https://github.com/mapbox/node-pre-gyp/issues/119
|
||||
bucket: package_json.binary.bucket,
|
||||
region: package_json.binary.region,
|
||||
s3ForcePathStyle: package_json.binary.s3ForcePathStyle || false
|
||||
};
|
||||
// support host mirror with npm config `--{module_name}_binary_host_mirror`
|
||||
// e.g.: https://github.com/node-inspector/v8-profiler/blob/master/package.json#L25
|
||||
// > npm install v8-profiler --profiler_binary_host_mirror=https://npm.taobao.org/mirrors/node-inspector/
|
||||
const validModuleName = opts.module_name.replace('-', '_');
|
||||
const host = process.env['npm_config_' + validModuleName + '_binary_host_mirror'] || package_json.binary.host;
|
||||
opts.host = fix_slashes(eval_template(host, opts));
|
||||
opts.module_path = eval_template(package_json.binary.module_path, opts);
|
||||
// now we resolve the module_path to ensure it is absolute so that binding.gyp variables work predictably
|
||||
if (options.module_root) {
|
||||
// resolve relative to known module root: works for pre-binding require
|
||||
opts.module_path = path.join(options.module_root, opts.module_path);
|
||||
} else {
|
||||
// resolve relative to current working directory: works for node-pre-gyp commands
|
||||
opts.module_path = path.resolve(opts.module_path);
|
||||
}
|
||||
opts.module = path.join(opts.module_path, opts.module_name + '.node');
|
||||
opts.remote_path = package_json.binary.remote_path ? drop_double_slashes(fix_slashes(eval_template(package_json.binary.remote_path, opts))) : default_remote_path;
|
||||
const package_name = package_json.binary.package_name ? package_json.binary.package_name : default_package_name;
|
||||
opts.package_name = eval_template(package_name, opts);
|
||||
opts.staged_tarball = path.join('build/stage', opts.remote_path, opts.package_name);
|
||||
opts.hosted_path = url.resolve(opts.host, opts.remote_path);
|
||||
opts.hosted_tarball = url.resolve(opts.hosted_path, opts.package_name);
|
||||
return opts;
|
||||
};
|
@ -0,0 +1,62 @@
|
||||
{
|
||||
"name": "@mapbox/node-pre-gyp",
|
||||
"description": "Node.js native addon binary install tool",
|
||||
"version": "1.0.11",
|
||||
"keywords": [
|
||||
"native",
|
||||
"addon",
|
||||
"module",
|
||||
"c",
|
||||
"c++",
|
||||
"bindings",
|
||||
"binary"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"author": "Dane Springmeyer <dane@mapbox.com>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mapbox/node-pre-gyp.git"
|
||||
},
|
||||
"bin": "./bin/node-pre-gyp",
|
||||
"main": "./lib/node-pre-gyp.js",
|
||||
"dependencies": {
|
||||
"detect-libc": "^2.0.0",
|
||||
"https-proxy-agent": "^5.0.0",
|
||||
"make-dir": "^3.1.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"nopt": "^5.0.0",
|
||||
"npmlog": "^5.0.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"semver": "^7.3.5",
|
||||
"tar": "^6.1.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mapbox/cloudfriend": "^5.1.0",
|
||||
"@mapbox/eslint-config-mapbox": "^3.0.0",
|
||||
"aws-sdk": "^2.1087.0",
|
||||
"codecov": "^3.8.3",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"mock-aws-s3": "^4.0.2",
|
||||
"nock": "^12.0.3",
|
||||
"node-addon-api": "^4.3.0",
|
||||
"nyc": "^15.1.0",
|
||||
"tape": "^5.5.2",
|
||||
"tar-fs": "^2.1.1"
|
||||
},
|
||||
"nyc": {
|
||||
"all": true,
|
||||
"skip-full": false,
|
||||
"exclude": [
|
||||
"test/**"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "nyc --all --include index.js --include lib/ npm test",
|
||||
"upload-coverage": "nyc report --reporter json && codecov --clear --flags=unit --file=./coverage/coverage-final.json",
|
||||
"lint": "eslint bin/node-pre-gyp lib/*js lib/util/*js test/*js scripts/*js",
|
||||
"fix": "npm run lint -- --fix",
|
||||
"update-crosswalk": "node scripts/abi_crosswalk.js",
|
||||
"test": "tape test/*test.js"
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
Copyright (c) 2014 Dmitry Tsvettsikh
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
@ -0,0 +1,4 @@
|
||||
import mod from "./index.js";
|
||||
|
||||
export default mod;
|
||||
export const saslprep = mod.saslprep;
|
@ -0,0 +1,4 @@
|
||||
/// <reference types="node" />
|
||||
declare const _default: Buffer;
|
||||
export default _default;
|
||||
//# sourceMappingURL=code-points-data.d.ts.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"code-points-data.d.ts","sourceRoot":"","sources":["../src/code-points-data.ts"],"names":[],"mappings":";;AAEA,wBAKE"}
|
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const zlib_1 = require("zlib");
|
||||
exports.default = (0, zlib_1.gunzipSync)(Buffer.from('H4sIAAAAAAACA+3dTYgcWR0A8FfTnekQ47aCkBxiZpYV8RhwYQM7bA/ksoLgSRD0IOSiePAkLrowvWSF4CkHEW856MlTQHA9RKZ1ZJODsEcVcTOyhxUEbXdXtpPp1PNVV39Uz4czEyaTVOb3G6a7XtWrr/devX49/+qekG2Go7Aa2jHGyozG+Dmrzi2mP/xb/zMhLI+WlRm2byubm2h0ivVi7BYzusVjuNkt1l9uFWsutWL8OP4rzV9KeXdsKx1HFhbSc6vIG0fKBZ14UNfLFS6FRrGRtXh98ZvphL/x4uLV/IOzaat/vlikv/TixavxR8PQitfPpKNbffXSwgtr8fV07GX+L1967urwg5W0/t0LV37y/oWFlQtX8ping7reXE3LT680r9yPKyn/3Vn64SwdVs6m/KN0yHrp9D+RvXsqpe6MSia5mH6LSog//Xq/++O74YVTjfDFWK2VIuNSemiPppphcVYeyzcudKqFMiq6cs3vVkrzlcnE0mxeZ1Jf2ZXsSvk8TmRZWYdpalydxd5bc8eUkt1wlEbtqTVLr8XQLFpKMb+dpr9SbSOt4ozTgXUq8+Ihm8cTt0shtCvT6dwao6sxPf5ydmU208/Z0yH8IZtlvZi3e5fG12yn3PLSdPvnQ7vsK9rxyKpqevzFZGVfu3YHezvbnbvit9Xdm5fGbf/MZ7PuuNrTjLJnaofH7gm0h+VKU/g/tdUocrer3cO4yOcuycGoyLrba6Ta+lrlnkZ5ntvWCrfV39wLTuNg9QvsvHb37P8BAGCP0eNTOH5szf154JmnNQIcn7b+FziyAfX4eWnn+C6Lm4M0mj31ubkViiDV4WLvs56qN54xGS3HWER5su6nQtZubl9tcY/4atbr9e5kWewew/g2a8fdy2Yaa97+pgQAAAAAAIBHtt+dYmWwaN/byI5g/9PYVfMvb4YvvDpOLJxvFgueP9VbPXh8/yCZViZxNYATaejmDQAAAACgfjJ/3QUA4JD3Px1InT+5PtQCAAAAAAAAAKD2xP8BAAAAAAAAoP7E/wEAAAAAAACg/sT/AQAAAAAAAKD+xP8BAAAAAAAAoP7E/wEAAAAAAACg/sT/AQAAAAAAAKD+xP8BAAAAAAAAoP7E/wEAAAAAAACg/sT/AQAAAAAAAKD+xP8BAAAAAAAAoP6G6+khVCgSAAAAAAAAAKidYQjLYVfNcPSyAE+dhQsnvAAq59/VHAAAAAAAAOCJmv8E/w4HiLqf3nWuWCB1pe0esg/pT3sKd+m4XjhpFpZH3/1THTcU6cfRLnrHf3ZNPZs+bf9rwPuIUPYAWb+j/Zy0EaAxAAAAAADwrPJ1IMBenu6ea99M+0W/17wCAAAAAAAAnGRLm8oA4JnQUAQAAAAAAAAAUHvi/wAAAAAAAABQf+L/AAAAAAAAAFB/4v8AAAAAAAAAUH/i/wAAAAAAAABQf+L/AAAAAAAAAFB/4v8AAAAAAAAAUH/i/wAAAAAAAABQf+L/AAAAAAAAAFB/4v8AAAAAAAAAUH/i/wAAAAAAAABQf+L/AAAAAAAAAFB/jdX0ECsUCQAAAAAAAADUTiMCAAAAAAAAAHU3VAQAAAAAAAAAUH8hLNf1uwsWbhT/uWBzUEx/ei1Nxc001VqrnN2wuRjCK3G4HuNgtuJoSVj17Q9QyBQBAAAAAAAAHMKpuJ4/+Otc5L2XZi8dJlQ/LCPXhc4keJ9UI9uFre3rDfY9uoXZPQBFHL34HSWWm8sx5rH83d967IfZMRZHHG/2Qi8MFnbscXnhnzHei5NND8P2bW2OT3G8vFeebBHbz9dGEf5jDt+fK4/mTve1bnwndsNL92+mE/75xhs/yz65Ed/ZbP29SP96oxvCDxrxcjj333R262/d6X6tG66lYy/z/+rtMn83nHvv9nfOv/dw4+pvspCl4v7+1npa/nHvtbSvjSJ/mf79/VuLC7N03LiW8o/SMU8ldO+jPOul1OVQ3vVwK+TZqBLCt3/RXvveS7eaD0L8YyhrJeV/cC0WGTdD1hzlCo2H98vzK9a+963V7qRVTeaNa+ZGpWp+N62jSmOetJD8dn67fB4n8nzchG7n4+os2tcgzLWUQVg70rta8lE7nqW7IW710v7eDsV1F7e6433njYfd9j9Gl2KIveptMePVamOXQuhXO5tUk6Pv+kiPX43T7/3YevDy4MN+HLw8CHPX6OqOOwKe73z0+pnf3rvT6pX76j/SUU7/3UjqX5r7ZW7PdZU8Vq2id+29Pphdh3n1Tqp/t0aXaWVOPnsFGre+waRdpKf/TK+7fiX3bOWluVeJg77AAPNDwr37fwAA2GP0+BSOHwcn6/231ghwfPr6X+DIBtTj582d47s8LD3xMeYktt+YHXHe6XQuH9P4Nu+H3ctmGmve/qYEAAAAAACAR7bfnWJlsGgSNNoM54tPZ23EI4vYzPY1/fzq1ud/GP/01jjx8P2tYsG7DzrrB4/vHySTz5YB+n8AAAAAgJrJ/XEXAIDHEf/2yXUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgGdABAAAAAAAAADqbqgIAAAAAAAAAKD2hv8DWK79UBhoBgA=', 'base64'));
|
||||
//# sourceMappingURL=code-points-data.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"code-points-data.js","sourceRoot":"","sources":["../src/code-points-data.ts"],"names":[],"mappings":";;AAAA,+BAAkC;AAElC,kBAAe,IAAA,iBAAU,EACvB,MAAM,CAAC,IAAI,CACT,0nFAA0nF,EAC1nF,QAAQ,CACT,CACF,CAAC"}
|
@ -0,0 +1,7 @@
|
||||
export declare const unassigned_code_points: Set<number>;
|
||||
export declare const commonly_mapped_to_nothing: Set<number>;
|
||||
export declare const non_ASCII_space_characters: Set<number>;
|
||||
export declare const prohibited_characters: Set<number>;
|
||||
export declare const bidirectional_r_al: Set<number>;
|
||||
export declare const bidirectional_l: Set<number>;
|
||||
//# sourceMappingURL=code-points-src.d.ts.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"code-points-src.d.ts","sourceRoot":"","sources":["../src/code-points-src.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB,aA6YjC,CAAC;AAMH,eAAO,MAAM,0BAA0B,aAIrC,CAAC;AAMH,eAAO,MAAM,0BAA0B,aASrC,CAAC;AAMH,eAAO,MAAM,qBAAqB,aA6GhC,CAAC;AAMH,eAAO,MAAM,kBAAkB,aAmC7B,CAAC;AAMH,eAAO,MAAM,eAAe,aAyW1B,CAAC"}
|
@ -0,0 +1,881 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.bidirectional_l = exports.bidirectional_r_al = exports.prohibited_characters = exports.non_ASCII_space_characters = exports.commonly_mapped_to_nothing = exports.unassigned_code_points = void 0;
|
||||
const util_1 = require("./util");
|
||||
exports.unassigned_code_points = new Set([
|
||||
0x0221,
|
||||
...(0, util_1.range)(0x0234, 0x024f),
|
||||
...(0, util_1.range)(0x02ae, 0x02af),
|
||||
...(0, util_1.range)(0x02ef, 0x02ff),
|
||||
...(0, util_1.range)(0x0350, 0x035f),
|
||||
...(0, util_1.range)(0x0370, 0x0373),
|
||||
...(0, util_1.range)(0x0376, 0x0379),
|
||||
...(0, util_1.range)(0x037b, 0x037d),
|
||||
...(0, util_1.range)(0x037f, 0x0383),
|
||||
0x038b,
|
||||
0x038d,
|
||||
0x03a2,
|
||||
0x03cf,
|
||||
...(0, util_1.range)(0x03f7, 0x03ff),
|
||||
0x0487,
|
||||
0x04cf,
|
||||
...(0, util_1.range)(0x04f6, 0x04f7),
|
||||
...(0, util_1.range)(0x04fa, 0x04ff),
|
||||
...(0, util_1.range)(0x0510, 0x0530),
|
||||
...(0, util_1.range)(0x0557, 0x0558),
|
||||
0x0560,
|
||||
0x0588,
|
||||
...(0, util_1.range)(0x058b, 0x0590),
|
||||
0x05a2,
|
||||
0x05ba,
|
||||
...(0, util_1.range)(0x05c5, 0x05cf),
|
||||
...(0, util_1.range)(0x05eb, 0x05ef),
|
||||
...(0, util_1.range)(0x05f5, 0x060b),
|
||||
...(0, util_1.range)(0x060d, 0x061a),
|
||||
...(0, util_1.range)(0x061c, 0x061e),
|
||||
0x0620,
|
||||
...(0, util_1.range)(0x063b, 0x063f),
|
||||
...(0, util_1.range)(0x0656, 0x065f),
|
||||
...(0, util_1.range)(0x06ee, 0x06ef),
|
||||
0x06ff,
|
||||
0x070e,
|
||||
...(0, util_1.range)(0x072d, 0x072f),
|
||||
...(0, util_1.range)(0x074b, 0x077f),
|
||||
...(0, util_1.range)(0x07b2, 0x0900),
|
||||
0x0904,
|
||||
...(0, util_1.range)(0x093a, 0x093b),
|
||||
...(0, util_1.range)(0x094e, 0x094f),
|
||||
...(0, util_1.range)(0x0955, 0x0957),
|
||||
...(0, util_1.range)(0x0971, 0x0980),
|
||||
0x0984,
|
||||
...(0, util_1.range)(0x098d, 0x098e),
|
||||
...(0, util_1.range)(0x0991, 0x0992),
|
||||
0x09a9,
|
||||
0x09b1,
|
||||
...(0, util_1.range)(0x09b3, 0x09b5),
|
||||
...(0, util_1.range)(0x09ba, 0x09bb),
|
||||
0x09bd,
|
||||
...(0, util_1.range)(0x09c5, 0x09c6),
|
||||
...(0, util_1.range)(0x09c9, 0x09ca),
|
||||
...(0, util_1.range)(0x09ce, 0x09d6),
|
||||
...(0, util_1.range)(0x09d8, 0x09db),
|
||||
0x09de,
|
||||
...(0, util_1.range)(0x09e4, 0x09e5),
|
||||
...(0, util_1.range)(0x09fb, 0x0a01),
|
||||
...(0, util_1.range)(0x0a03, 0x0a04),
|
||||
...(0, util_1.range)(0x0a0b, 0x0a0e),
|
||||
...(0, util_1.range)(0x0a11, 0x0a12),
|
||||
0x0a29,
|
||||
0x0a31,
|
||||
0x0a34,
|
||||
0x0a37,
|
||||
...(0, util_1.range)(0x0a3a, 0x0a3b),
|
||||
0x0a3d,
|
||||
...(0, util_1.range)(0x0a43, 0x0a46),
|
||||
...(0, util_1.range)(0x0a49, 0x0a4a),
|
||||
...(0, util_1.range)(0x0a4e, 0x0a58),
|
||||
0x0a5d,
|
||||
...(0, util_1.range)(0x0a5f, 0x0a65),
|
||||
...(0, util_1.range)(0x0a75, 0x0a80),
|
||||
0x0a84,
|
||||
0x0a8c,
|
||||
0x0a8e,
|
||||
0x0a92,
|
||||
0x0aa9,
|
||||
0x0ab1,
|
||||
0x0ab4,
|
||||
...(0, util_1.range)(0x0aba, 0x0abb),
|
||||
0x0ac6,
|
||||
0x0aca,
|
||||
...(0, util_1.range)(0x0ace, 0x0acf),
|
||||
...(0, util_1.range)(0x0ad1, 0x0adf),
|
||||
...(0, util_1.range)(0x0ae1, 0x0ae5),
|
||||
...(0, util_1.range)(0x0af0, 0x0b00),
|
||||
0x0b04,
|
||||
...(0, util_1.range)(0x0b0d, 0x0b0e),
|
||||
...(0, util_1.range)(0x0b11, 0x0b12),
|
||||
0x0b29,
|
||||
0x0b31,
|
||||
...(0, util_1.range)(0x0b34, 0x0b35),
|
||||
...(0, util_1.range)(0x0b3a, 0x0b3b),
|
||||
...(0, util_1.range)(0x0b44, 0x0b46),
|
||||
...(0, util_1.range)(0x0b49, 0x0b4a),
|
||||
...(0, util_1.range)(0x0b4e, 0x0b55),
|
||||
...(0, util_1.range)(0x0b58, 0x0b5b),
|
||||
0x0b5e,
|
||||
...(0, util_1.range)(0x0b62, 0x0b65),
|
||||
...(0, util_1.range)(0x0b71, 0x0b81),
|
||||
0x0b84,
|
||||
...(0, util_1.range)(0x0b8b, 0x0b8d),
|
||||
0x0b91,
|
||||
...(0, util_1.range)(0x0b96, 0x0b98),
|
||||
0x0b9b,
|
||||
0x0b9d,
|
||||
...(0, util_1.range)(0x0ba0, 0x0ba2),
|
||||
...(0, util_1.range)(0x0ba5, 0x0ba7),
|
||||
...(0, util_1.range)(0x0bab, 0x0bad),
|
||||
0x0bb6,
|
||||
...(0, util_1.range)(0x0bba, 0x0bbd),
|
||||
...(0, util_1.range)(0x0bc3, 0x0bc5),
|
||||
0x0bc9,
|
||||
...(0, util_1.range)(0x0bce, 0x0bd6),
|
||||
...(0, util_1.range)(0x0bd8, 0x0be6),
|
||||
...(0, util_1.range)(0x0bf3, 0x0c00),
|
||||
0x0c04,
|
||||
0x0c0d,
|
||||
0x0c11,
|
||||
0x0c29,
|
||||
0x0c34,
|
||||
...(0, util_1.range)(0x0c3a, 0x0c3d),
|
||||
0x0c45,
|
||||
0x0c49,
|
||||
...(0, util_1.range)(0x0c4e, 0x0c54),
|
||||
...(0, util_1.range)(0x0c57, 0x0c5f),
|
||||
...(0, util_1.range)(0x0c62, 0x0c65),
|
||||
...(0, util_1.range)(0x0c70, 0x0c81),
|
||||
0x0c84,
|
||||
0x0c8d,
|
||||
0x0c91,
|
||||
0x0ca9,
|
||||
0x0cb4,
|
||||
...(0, util_1.range)(0x0cba, 0x0cbd),
|
||||
0x0cc5,
|
||||
0x0cc9,
|
||||
...(0, util_1.range)(0x0cce, 0x0cd4),
|
||||
...(0, util_1.range)(0x0cd7, 0x0cdd),
|
||||
0x0cdf,
|
||||
...(0, util_1.range)(0x0ce2, 0x0ce5),
|
||||
...(0, util_1.range)(0x0cf0, 0x0d01),
|
||||
0x0d04,
|
||||
0x0d0d,
|
||||
0x0d11,
|
||||
0x0d29,
|
||||
...(0, util_1.range)(0x0d3a, 0x0d3d),
|
||||
...(0, util_1.range)(0x0d44, 0x0d45),
|
||||
0x0d49,
|
||||
...(0, util_1.range)(0x0d4e, 0x0d56),
|
||||
...(0, util_1.range)(0x0d58, 0x0d5f),
|
||||
...(0, util_1.range)(0x0d62, 0x0d65),
|
||||
...(0, util_1.range)(0x0d70, 0x0d81),
|
||||
0x0d84,
|
||||
...(0, util_1.range)(0x0d97, 0x0d99),
|
||||
0x0db2,
|
||||
0x0dbc,
|
||||
...(0, util_1.range)(0x0dbe, 0x0dbf),
|
||||
...(0, util_1.range)(0x0dc7, 0x0dc9),
|
||||
...(0, util_1.range)(0x0dcb, 0x0dce),
|
||||
0x0dd5,
|
||||
0x0dd7,
|
||||
...(0, util_1.range)(0x0de0, 0x0df1),
|
||||
...(0, util_1.range)(0x0df5, 0x0e00),
|
||||
...(0, util_1.range)(0x0e3b, 0x0e3e),
|
||||
...(0, util_1.range)(0x0e5c, 0x0e80),
|
||||
0x0e83,
|
||||
...(0, util_1.range)(0x0e85, 0x0e86),
|
||||
0x0e89,
|
||||
...(0, util_1.range)(0x0e8b, 0x0e8c),
|
||||
...(0, util_1.range)(0x0e8e, 0x0e93),
|
||||
0x0e98,
|
||||
0x0ea0,
|
||||
0x0ea4,
|
||||
0x0ea6,
|
||||
...(0, util_1.range)(0x0ea8, 0x0ea9),
|
||||
0x0eac,
|
||||
0x0eba,
|
||||
...(0, util_1.range)(0x0ebe, 0x0ebf),
|
||||
0x0ec5,
|
||||
0x0ec7,
|
||||
...(0, util_1.range)(0x0ece, 0x0ecf),
|
||||
...(0, util_1.range)(0x0eda, 0x0edb),
|
||||
...(0, util_1.range)(0x0ede, 0x0eff),
|
||||
0x0f48,
|
||||
...(0, util_1.range)(0x0f6b, 0x0f70),
|
||||
...(0, util_1.range)(0x0f8c, 0x0f8f),
|
||||
0x0f98,
|
||||
0x0fbd,
|
||||
...(0, util_1.range)(0x0fcd, 0x0fce),
|
||||
...(0, util_1.range)(0x0fd0, 0x0fff),
|
||||
0x1022,
|
||||
0x1028,
|
||||
0x102b,
|
||||
...(0, util_1.range)(0x1033, 0x1035),
|
||||
...(0, util_1.range)(0x103a, 0x103f),
|
||||
...(0, util_1.range)(0x105a, 0x109f),
|
||||
...(0, util_1.range)(0x10c6, 0x10cf),
|
||||
...(0, util_1.range)(0x10f9, 0x10fa),
|
||||
...(0, util_1.range)(0x10fc, 0x10ff),
|
||||
...(0, util_1.range)(0x115a, 0x115e),
|
||||
...(0, util_1.range)(0x11a3, 0x11a7),
|
||||
...(0, util_1.range)(0x11fa, 0x11ff),
|
||||
0x1207,
|
||||
0x1247,
|
||||
0x1249,
|
||||
...(0, util_1.range)(0x124e, 0x124f),
|
||||
0x1257,
|
||||
0x1259,
|
||||
...(0, util_1.range)(0x125e, 0x125f),
|
||||
0x1287,
|
||||
0x1289,
|
||||
...(0, util_1.range)(0x128e, 0x128f),
|
||||
0x12af,
|
||||
0x12b1,
|
||||
...(0, util_1.range)(0x12b6, 0x12b7),
|
||||
0x12bf,
|
||||
0x12c1,
|
||||
...(0, util_1.range)(0x12c6, 0x12c7),
|
||||
0x12cf,
|
||||
0x12d7,
|
||||
0x12ef,
|
||||
0x130f,
|
||||
0x1311,
|
||||
...(0, util_1.range)(0x1316, 0x1317),
|
||||
0x131f,
|
||||
0x1347,
|
||||
...(0, util_1.range)(0x135b, 0x1360),
|
||||
...(0, util_1.range)(0x137d, 0x139f),
|
||||
...(0, util_1.range)(0x13f5, 0x1400),
|
||||
...(0, util_1.range)(0x1677, 0x167f),
|
||||
...(0, util_1.range)(0x169d, 0x169f),
|
||||
...(0, util_1.range)(0x16f1, 0x16ff),
|
||||
0x170d,
|
||||
...(0, util_1.range)(0x1715, 0x171f),
|
||||
...(0, util_1.range)(0x1737, 0x173f),
|
||||
...(0, util_1.range)(0x1754, 0x175f),
|
||||
0x176d,
|
||||
0x1771,
|
||||
...(0, util_1.range)(0x1774, 0x177f),
|
||||
...(0, util_1.range)(0x17dd, 0x17df),
|
||||
...(0, util_1.range)(0x17ea, 0x17ff),
|
||||
0x180f,
|
||||
...(0, util_1.range)(0x181a, 0x181f),
|
||||
...(0, util_1.range)(0x1878, 0x187f),
|
||||
...(0, util_1.range)(0x18aa, 0x1dff),
|
||||
...(0, util_1.range)(0x1e9c, 0x1e9f),
|
||||
...(0, util_1.range)(0x1efa, 0x1eff),
|
||||
...(0, util_1.range)(0x1f16, 0x1f17),
|
||||
...(0, util_1.range)(0x1f1e, 0x1f1f),
|
||||
...(0, util_1.range)(0x1f46, 0x1f47),
|
||||
...(0, util_1.range)(0x1f4e, 0x1f4f),
|
||||
0x1f58,
|
||||
0x1f5a,
|
||||
0x1f5c,
|
||||
0x1f5e,
|
||||
...(0, util_1.range)(0x1f7e, 0x1f7f),
|
||||
0x1fb5,
|
||||
0x1fc5,
|
||||
...(0, util_1.range)(0x1fd4, 0x1fd5),
|
||||
0x1fdc,
|
||||
...(0, util_1.range)(0x1ff0, 0x1ff1),
|
||||
0x1ff5,
|
||||
0x1fff,
|
||||
...(0, util_1.range)(0x2053, 0x2056),
|
||||
...(0, util_1.range)(0x2058, 0x205e),
|
||||
...(0, util_1.range)(0x2064, 0x2069),
|
||||
...(0, util_1.range)(0x2072, 0x2073),
|
||||
...(0, util_1.range)(0x208f, 0x209f),
|
||||
...(0, util_1.range)(0x20b2, 0x20cf),
|
||||
...(0, util_1.range)(0x20eb, 0x20ff),
|
||||
...(0, util_1.range)(0x213b, 0x213c),
|
||||
...(0, util_1.range)(0x214c, 0x2152),
|
||||
...(0, util_1.range)(0x2184, 0x218f),
|
||||
...(0, util_1.range)(0x23cf, 0x23ff),
|
||||
...(0, util_1.range)(0x2427, 0x243f),
|
||||
...(0, util_1.range)(0x244b, 0x245f),
|
||||
0x24ff,
|
||||
...(0, util_1.range)(0x2614, 0x2615),
|
||||
0x2618,
|
||||
...(0, util_1.range)(0x267e, 0x267f),
|
||||
...(0, util_1.range)(0x268a, 0x2700),
|
||||
0x2705,
|
||||
...(0, util_1.range)(0x270a, 0x270b),
|
||||
0x2728,
|
||||
0x274c,
|
||||
0x274e,
|
||||
...(0, util_1.range)(0x2753, 0x2755),
|
||||
0x2757,
|
||||
...(0, util_1.range)(0x275f, 0x2760),
|
||||
...(0, util_1.range)(0x2795, 0x2797),
|
||||
0x27b0,
|
||||
...(0, util_1.range)(0x27bf, 0x27cf),
|
||||
...(0, util_1.range)(0x27ec, 0x27ef),
|
||||
...(0, util_1.range)(0x2b00, 0x2e7f),
|
||||
0x2e9a,
|
||||
...(0, util_1.range)(0x2ef4, 0x2eff),
|
||||
...(0, util_1.range)(0x2fd6, 0x2fef),
|
||||
...(0, util_1.range)(0x2ffc, 0x2fff),
|
||||
0x3040,
|
||||
...(0, util_1.range)(0x3097, 0x3098),
|
||||
...(0, util_1.range)(0x3100, 0x3104),
|
||||
...(0, util_1.range)(0x312d, 0x3130),
|
||||
0x318f,
|
||||
...(0, util_1.range)(0x31b8, 0x31ef),
|
||||
...(0, util_1.range)(0x321d, 0x321f),
|
||||
...(0, util_1.range)(0x3244, 0x3250),
|
||||
...(0, util_1.range)(0x327c, 0x327e),
|
||||
...(0, util_1.range)(0x32cc, 0x32cf),
|
||||
0x32ff,
|
||||
...(0, util_1.range)(0x3377, 0x337a),
|
||||
...(0, util_1.range)(0x33de, 0x33df),
|
||||
0x33ff,
|
||||
...(0, util_1.range)(0x4db6, 0x4dff),
|
||||
...(0, util_1.range)(0x9fa6, 0x9fff),
|
||||
...(0, util_1.range)(0xa48d, 0xa48f),
|
||||
...(0, util_1.range)(0xa4c7, 0xabff),
|
||||
...(0, util_1.range)(0xd7a4, 0xd7ff),
|
||||
...(0, util_1.range)(0xfa2e, 0xfa2f),
|
||||
...(0, util_1.range)(0xfa6b, 0xfaff),
|
||||
...(0, util_1.range)(0xfb07, 0xfb12),
|
||||
...(0, util_1.range)(0xfb18, 0xfb1c),
|
||||
0xfb37,
|
||||
0xfb3d,
|
||||
0xfb3f,
|
||||
0xfb42,
|
||||
0xfb45,
|
||||
...(0, util_1.range)(0xfbb2, 0xfbd2),
|
||||
...(0, util_1.range)(0xfd40, 0xfd4f),
|
||||
...(0, util_1.range)(0xfd90, 0xfd91),
|
||||
...(0, util_1.range)(0xfdc8, 0xfdcf),
|
||||
...(0, util_1.range)(0xfdfd, 0xfdff),
|
||||
...(0, util_1.range)(0xfe10, 0xfe1f),
|
||||
...(0, util_1.range)(0xfe24, 0xfe2f),
|
||||
...(0, util_1.range)(0xfe47, 0xfe48),
|
||||
0xfe53,
|
||||
0xfe67,
|
||||
...(0, util_1.range)(0xfe6c, 0xfe6f),
|
||||
0xfe75,
|
||||
...(0, util_1.range)(0xfefd, 0xfefe),
|
||||
0xff00,
|
||||
...(0, util_1.range)(0xffbf, 0xffc1),
|
||||
...(0, util_1.range)(0xffc8, 0xffc9),
|
||||
...(0, util_1.range)(0xffd0, 0xffd1),
|
||||
...(0, util_1.range)(0xffd8, 0xffd9),
|
||||
...(0, util_1.range)(0xffdd, 0xffdf),
|
||||
0xffe7,
|
||||
...(0, util_1.range)(0xffef, 0xfff8),
|
||||
...(0, util_1.range)(0x10000, 0x102ff),
|
||||
0x1031f,
|
||||
...(0, util_1.range)(0x10324, 0x1032f),
|
||||
...(0, util_1.range)(0x1034b, 0x103ff),
|
||||
...(0, util_1.range)(0x10426, 0x10427),
|
||||
...(0, util_1.range)(0x1044e, 0x1cfff),
|
||||
...(0, util_1.range)(0x1d0f6, 0x1d0ff),
|
||||
...(0, util_1.range)(0x1d127, 0x1d129),
|
||||
...(0, util_1.range)(0x1d1de, 0x1d3ff),
|
||||
0x1d455,
|
||||
0x1d49d,
|
||||
...(0, util_1.range)(0x1d4a0, 0x1d4a1),
|
||||
...(0, util_1.range)(0x1d4a3, 0x1d4a4),
|
||||
...(0, util_1.range)(0x1d4a7, 0x1d4a8),
|
||||
0x1d4ad,
|
||||
0x1d4ba,
|
||||
0x1d4bc,
|
||||
0x1d4c1,
|
||||
0x1d4c4,
|
||||
0x1d506,
|
||||
...(0, util_1.range)(0x1d50b, 0x1d50c),
|
||||
0x1d515,
|
||||
0x1d51d,
|
||||
0x1d53a,
|
||||
0x1d53f,
|
||||
0x1d545,
|
||||
...(0, util_1.range)(0x1d547, 0x1d549),
|
||||
0x1d551,
|
||||
...(0, util_1.range)(0x1d6a4, 0x1d6a7),
|
||||
...(0, util_1.range)(0x1d7ca, 0x1d7cd),
|
||||
...(0, util_1.range)(0x1d800, 0x1fffd),
|
||||
...(0, util_1.range)(0x2a6d7, 0x2f7ff),
|
||||
...(0, util_1.range)(0x2fa1e, 0x2fffd),
|
||||
...(0, util_1.range)(0x30000, 0x3fffd),
|
||||
...(0, util_1.range)(0x40000, 0x4fffd),
|
||||
...(0, util_1.range)(0x50000, 0x5fffd),
|
||||
...(0, util_1.range)(0x60000, 0x6fffd),
|
||||
...(0, util_1.range)(0x70000, 0x7fffd),
|
||||
...(0, util_1.range)(0x80000, 0x8fffd),
|
||||
...(0, util_1.range)(0x90000, 0x9fffd),
|
||||
...(0, util_1.range)(0xa0000, 0xafffd),
|
||||
...(0, util_1.range)(0xb0000, 0xbfffd),
|
||||
...(0, util_1.range)(0xc0000, 0xcfffd),
|
||||
...(0, util_1.range)(0xd0000, 0xdfffd),
|
||||
0xe0000,
|
||||
...(0, util_1.range)(0xe0002, 0xe001f),
|
||||
...(0, util_1.range)(0xe0080, 0xefffd),
|
||||
]);
|
||||
exports.commonly_mapped_to_nothing = new Set([
|
||||
0x00ad, 0x034f, 0x1806, 0x180b, 0x180c, 0x180d, 0x200b, 0x200c, 0x200d,
|
||||
0x2060, 0xfe00, 0xfe01, 0xfe02, 0xfe03, 0xfe04, 0xfe05, 0xfe06, 0xfe07,
|
||||
0xfe08, 0xfe09, 0xfe0a, 0xfe0b, 0xfe0c, 0xfe0d, 0xfe0e, 0xfe0f, 0xfeff,
|
||||
]);
|
||||
exports.non_ASCII_space_characters = new Set([
|
||||
0x00a0, 0x1680,
|
||||
0x2000, 0x2001, 0x2002,
|
||||
0x2003, 0x2004,
|
||||
0x2005, 0x2006,
|
||||
0x2007, 0x2008,
|
||||
0x2009, 0x200a,
|
||||
0x200b, 0x202f,
|
||||
0x205f, 0x3000,
|
||||
]);
|
||||
exports.prohibited_characters = new Set([
|
||||
...exports.non_ASCII_space_characters,
|
||||
...(0, util_1.range)(0, 0x001f),
|
||||
0x007f,
|
||||
...(0, util_1.range)(0x0080, 0x009f),
|
||||
0x06dd,
|
||||
0x070f,
|
||||
0x180e,
|
||||
0x200c,
|
||||
0x200d,
|
||||
0x2028,
|
||||
0x2029,
|
||||
0x2060,
|
||||
0x2061,
|
||||
0x2062,
|
||||
0x2063,
|
||||
...(0, util_1.range)(0x206a, 0x206f),
|
||||
0xfeff,
|
||||
...(0, util_1.range)(0xfff9, 0xfffc),
|
||||
...(0, util_1.range)(0x1d173, 0x1d17a),
|
||||
...(0, util_1.range)(0xe000, 0xf8ff),
|
||||
...(0, util_1.range)(0xf0000, 0xffffd),
|
||||
...(0, util_1.range)(0x100000, 0x10fffd),
|
||||
...(0, util_1.range)(0xfdd0, 0xfdef),
|
||||
...(0, util_1.range)(0xfffe, 0xffff),
|
||||
...(0, util_1.range)(0x1fffe, 0x1ffff),
|
||||
...(0, util_1.range)(0x2fffe, 0x2ffff),
|
||||
...(0, util_1.range)(0x3fffe, 0x3ffff),
|
||||
...(0, util_1.range)(0x4fffe, 0x4ffff),
|
||||
...(0, util_1.range)(0x5fffe, 0x5ffff),
|
||||
...(0, util_1.range)(0x6fffe, 0x6ffff),
|
||||
...(0, util_1.range)(0x7fffe, 0x7ffff),
|
||||
...(0, util_1.range)(0x8fffe, 0x8ffff),
|
||||
...(0, util_1.range)(0x9fffe, 0x9ffff),
|
||||
...(0, util_1.range)(0xafffe, 0xaffff),
|
||||
...(0, util_1.range)(0xbfffe, 0xbffff),
|
||||
...(0, util_1.range)(0xcfffe, 0xcffff),
|
||||
...(0, util_1.range)(0xdfffe, 0xdffff),
|
||||
...(0, util_1.range)(0xefffe, 0xeffff),
|
||||
...(0, util_1.range)(0x10fffe, 0x10ffff),
|
||||
...(0, util_1.range)(0xd800, 0xdfff),
|
||||
0xfff9,
|
||||
0xfffa,
|
||||
0xfffb,
|
||||
0xfffc,
|
||||
0xfffd,
|
||||
...(0, util_1.range)(0x2ff0, 0x2ffb),
|
||||
0x0340,
|
||||
0x0341,
|
||||
0x200e,
|
||||
0x200f,
|
||||
0x202a,
|
||||
0x202b,
|
||||
0x202c,
|
||||
0x202d,
|
||||
0x202e,
|
||||
0x206a,
|
||||
0x206b,
|
||||
0x206c,
|
||||
0x206d,
|
||||
0x206e,
|
||||
0x206f,
|
||||
0xe0001,
|
||||
...(0, util_1.range)(0xe0020, 0xe007f),
|
||||
]);
|
||||
exports.bidirectional_r_al = new Set([
|
||||
0x05be,
|
||||
0x05c0,
|
||||
0x05c3,
|
||||
...(0, util_1.range)(0x05d0, 0x05ea),
|
||||
...(0, util_1.range)(0x05f0, 0x05f4),
|
||||
0x061b,
|
||||
0x061f,
|
||||
...(0, util_1.range)(0x0621, 0x063a),
|
||||
...(0, util_1.range)(0x0640, 0x064a),
|
||||
...(0, util_1.range)(0x066d, 0x066f),
|
||||
...(0, util_1.range)(0x0671, 0x06d5),
|
||||
0x06dd,
|
||||
...(0, util_1.range)(0x06e5, 0x06e6),
|
||||
...(0, util_1.range)(0x06fa, 0x06fe),
|
||||
...(0, util_1.range)(0x0700, 0x070d),
|
||||
0x0710,
|
||||
...(0, util_1.range)(0x0712, 0x072c),
|
||||
...(0, util_1.range)(0x0780, 0x07a5),
|
||||
0x07b1,
|
||||
0x200f,
|
||||
0xfb1d,
|
||||
...(0, util_1.range)(0xfb1f, 0xfb28),
|
||||
...(0, util_1.range)(0xfb2a, 0xfb36),
|
||||
...(0, util_1.range)(0xfb38, 0xfb3c),
|
||||
0xfb3e,
|
||||
...(0, util_1.range)(0xfb40, 0xfb41),
|
||||
...(0, util_1.range)(0xfb43, 0xfb44),
|
||||
...(0, util_1.range)(0xfb46, 0xfbb1),
|
||||
...(0, util_1.range)(0xfbd3, 0xfd3d),
|
||||
...(0, util_1.range)(0xfd50, 0xfd8f),
|
||||
...(0, util_1.range)(0xfd92, 0xfdc7),
|
||||
...(0, util_1.range)(0xfdf0, 0xfdfc),
|
||||
...(0, util_1.range)(0xfe70, 0xfe74),
|
||||
...(0, util_1.range)(0xfe76, 0xfefc),
|
||||
]);
|
||||
exports.bidirectional_l = new Set([
|
||||
...(0, util_1.range)(0x0041, 0x005a),
|
||||
...(0, util_1.range)(0x0061, 0x007a),
|
||||
0x00aa,
|
||||
0x00b5,
|
||||
0x00ba,
|
||||
...(0, util_1.range)(0x00c0, 0x00d6),
|
||||
...(0, util_1.range)(0x00d8, 0x00f6),
|
||||
...(0, util_1.range)(0x00f8, 0x0220),
|
||||
...(0, util_1.range)(0x0222, 0x0233),
|
||||
...(0, util_1.range)(0x0250, 0x02ad),
|
||||
...(0, util_1.range)(0x02b0, 0x02b8),
|
||||
...(0, util_1.range)(0x02bb, 0x02c1),
|
||||
...(0, util_1.range)(0x02d0, 0x02d1),
|
||||
...(0, util_1.range)(0x02e0, 0x02e4),
|
||||
0x02ee,
|
||||
0x037a,
|
||||
0x0386,
|
||||
...(0, util_1.range)(0x0388, 0x038a),
|
||||
0x038c,
|
||||
...(0, util_1.range)(0x038e, 0x03a1),
|
||||
...(0, util_1.range)(0x03a3, 0x03ce),
|
||||
...(0, util_1.range)(0x03d0, 0x03f5),
|
||||
...(0, util_1.range)(0x0400, 0x0482),
|
||||
...(0, util_1.range)(0x048a, 0x04ce),
|
||||
...(0, util_1.range)(0x04d0, 0x04f5),
|
||||
...(0, util_1.range)(0x04f8, 0x04f9),
|
||||
...(0, util_1.range)(0x0500, 0x050f),
|
||||
...(0, util_1.range)(0x0531, 0x0556),
|
||||
...(0, util_1.range)(0x0559, 0x055f),
|
||||
...(0, util_1.range)(0x0561, 0x0587),
|
||||
0x0589,
|
||||
0x0903,
|
||||
...(0, util_1.range)(0x0905, 0x0939),
|
||||
...(0, util_1.range)(0x093d, 0x0940),
|
||||
...(0, util_1.range)(0x0949, 0x094c),
|
||||
0x0950,
|
||||
...(0, util_1.range)(0x0958, 0x0961),
|
||||
...(0, util_1.range)(0x0964, 0x0970),
|
||||
...(0, util_1.range)(0x0982, 0x0983),
|
||||
...(0, util_1.range)(0x0985, 0x098c),
|
||||
...(0, util_1.range)(0x098f, 0x0990),
|
||||
...(0, util_1.range)(0x0993, 0x09a8),
|
||||
...(0, util_1.range)(0x09aa, 0x09b0),
|
||||
0x09b2,
|
||||
...(0, util_1.range)(0x09b6, 0x09b9),
|
||||
...(0, util_1.range)(0x09be, 0x09c0),
|
||||
...(0, util_1.range)(0x09c7, 0x09c8),
|
||||
...(0, util_1.range)(0x09cb, 0x09cc),
|
||||
0x09d7,
|
||||
...(0, util_1.range)(0x09dc, 0x09dd),
|
||||
...(0, util_1.range)(0x09df, 0x09e1),
|
||||
...(0, util_1.range)(0x09e6, 0x09f1),
|
||||
...(0, util_1.range)(0x09f4, 0x09fa),
|
||||
...(0, util_1.range)(0x0a05, 0x0a0a),
|
||||
...(0, util_1.range)(0x0a0f, 0x0a10),
|
||||
...(0, util_1.range)(0x0a13, 0x0a28),
|
||||
...(0, util_1.range)(0x0a2a, 0x0a30),
|
||||
...(0, util_1.range)(0x0a32, 0x0a33),
|
||||
...(0, util_1.range)(0x0a35, 0x0a36),
|
||||
...(0, util_1.range)(0x0a38, 0x0a39),
|
||||
...(0, util_1.range)(0x0a3e, 0x0a40),
|
||||
...(0, util_1.range)(0x0a59, 0x0a5c),
|
||||
0x0a5e,
|
||||
...(0, util_1.range)(0x0a66, 0x0a6f),
|
||||
...(0, util_1.range)(0x0a72, 0x0a74),
|
||||
0x0a83,
|
||||
...(0, util_1.range)(0x0a85, 0x0a8b),
|
||||
0x0a8d,
|
||||
...(0, util_1.range)(0x0a8f, 0x0a91),
|
||||
...(0, util_1.range)(0x0a93, 0x0aa8),
|
||||
...(0, util_1.range)(0x0aaa, 0x0ab0),
|
||||
...(0, util_1.range)(0x0ab2, 0x0ab3),
|
||||
...(0, util_1.range)(0x0ab5, 0x0ab9),
|
||||
...(0, util_1.range)(0x0abd, 0x0ac0),
|
||||
0x0ac9,
|
||||
...(0, util_1.range)(0x0acb, 0x0acc),
|
||||
0x0ad0,
|
||||
0x0ae0,
|
||||
...(0, util_1.range)(0x0ae6, 0x0aef),
|
||||
...(0, util_1.range)(0x0b02, 0x0b03),
|
||||
...(0, util_1.range)(0x0b05, 0x0b0c),
|
||||
...(0, util_1.range)(0x0b0f, 0x0b10),
|
||||
...(0, util_1.range)(0x0b13, 0x0b28),
|
||||
...(0, util_1.range)(0x0b2a, 0x0b30),
|
||||
...(0, util_1.range)(0x0b32, 0x0b33),
|
||||
...(0, util_1.range)(0x0b36, 0x0b39),
|
||||
...(0, util_1.range)(0x0b3d, 0x0b3e),
|
||||
0x0b40,
|
||||
...(0, util_1.range)(0x0b47, 0x0b48),
|
||||
...(0, util_1.range)(0x0b4b, 0x0b4c),
|
||||
0x0b57,
|
||||
...(0, util_1.range)(0x0b5c, 0x0b5d),
|
||||
...(0, util_1.range)(0x0b5f, 0x0b61),
|
||||
...(0, util_1.range)(0x0b66, 0x0b70),
|
||||
0x0b83,
|
||||
...(0, util_1.range)(0x0b85, 0x0b8a),
|
||||
...(0, util_1.range)(0x0b8e, 0x0b90),
|
||||
...(0, util_1.range)(0x0b92, 0x0b95),
|
||||
...(0, util_1.range)(0x0b99, 0x0b9a),
|
||||
0x0b9c,
|
||||
...(0, util_1.range)(0x0b9e, 0x0b9f),
|
||||
...(0, util_1.range)(0x0ba3, 0x0ba4),
|
||||
...(0, util_1.range)(0x0ba8, 0x0baa),
|
||||
...(0, util_1.range)(0x0bae, 0x0bb5),
|
||||
...(0, util_1.range)(0x0bb7, 0x0bb9),
|
||||
...(0, util_1.range)(0x0bbe, 0x0bbf),
|
||||
...(0, util_1.range)(0x0bc1, 0x0bc2),
|
||||
...(0, util_1.range)(0x0bc6, 0x0bc8),
|
||||
...(0, util_1.range)(0x0bca, 0x0bcc),
|
||||
0x0bd7,
|
||||
...(0, util_1.range)(0x0be7, 0x0bf2),
|
||||
...(0, util_1.range)(0x0c01, 0x0c03),
|
||||
...(0, util_1.range)(0x0c05, 0x0c0c),
|
||||
...(0, util_1.range)(0x0c0e, 0x0c10),
|
||||
...(0, util_1.range)(0x0c12, 0x0c28),
|
||||
...(0, util_1.range)(0x0c2a, 0x0c33),
|
||||
...(0, util_1.range)(0x0c35, 0x0c39),
|
||||
...(0, util_1.range)(0x0c41, 0x0c44),
|
||||
...(0, util_1.range)(0x0c60, 0x0c61),
|
||||
...(0, util_1.range)(0x0c66, 0x0c6f),
|
||||
...(0, util_1.range)(0x0c82, 0x0c83),
|
||||
...(0, util_1.range)(0x0c85, 0x0c8c),
|
||||
...(0, util_1.range)(0x0c8e, 0x0c90),
|
||||
...(0, util_1.range)(0x0c92, 0x0ca8),
|
||||
...(0, util_1.range)(0x0caa, 0x0cb3),
|
||||
...(0, util_1.range)(0x0cb5, 0x0cb9),
|
||||
0x0cbe,
|
||||
...(0, util_1.range)(0x0cc0, 0x0cc4),
|
||||
...(0, util_1.range)(0x0cc7, 0x0cc8),
|
||||
...(0, util_1.range)(0x0cca, 0x0ccb),
|
||||
...(0, util_1.range)(0x0cd5, 0x0cd6),
|
||||
0x0cde,
|
||||
...(0, util_1.range)(0x0ce0, 0x0ce1),
|
||||
...(0, util_1.range)(0x0ce6, 0x0cef),
|
||||
...(0, util_1.range)(0x0d02, 0x0d03),
|
||||
...(0, util_1.range)(0x0d05, 0x0d0c),
|
||||
...(0, util_1.range)(0x0d0e, 0x0d10),
|
||||
...(0, util_1.range)(0x0d12, 0x0d28),
|
||||
...(0, util_1.range)(0x0d2a, 0x0d39),
|
||||
...(0, util_1.range)(0x0d3e, 0x0d40),
|
||||
...(0, util_1.range)(0x0d46, 0x0d48),
|
||||
...(0, util_1.range)(0x0d4a, 0x0d4c),
|
||||
0x0d57,
|
||||
...(0, util_1.range)(0x0d60, 0x0d61),
|
||||
...(0, util_1.range)(0x0d66, 0x0d6f),
|
||||
...(0, util_1.range)(0x0d82, 0x0d83),
|
||||
...(0, util_1.range)(0x0d85, 0x0d96),
|
||||
...(0, util_1.range)(0x0d9a, 0x0db1),
|
||||
...(0, util_1.range)(0x0db3, 0x0dbb),
|
||||
0x0dbd,
|
||||
...(0, util_1.range)(0x0dc0, 0x0dc6),
|
||||
...(0, util_1.range)(0x0dcf, 0x0dd1),
|
||||
...(0, util_1.range)(0x0dd8, 0x0ddf),
|
||||
...(0, util_1.range)(0x0df2, 0x0df4),
|
||||
...(0, util_1.range)(0x0e01, 0x0e30),
|
||||
...(0, util_1.range)(0x0e32, 0x0e33),
|
||||
...(0, util_1.range)(0x0e40, 0x0e46),
|
||||
...(0, util_1.range)(0x0e4f, 0x0e5b),
|
||||
...(0, util_1.range)(0x0e81, 0x0e82),
|
||||
0x0e84,
|
||||
...(0, util_1.range)(0x0e87, 0x0e88),
|
||||
0x0e8a,
|
||||
0x0e8d,
|
||||
...(0, util_1.range)(0x0e94, 0x0e97),
|
||||
...(0, util_1.range)(0x0e99, 0x0e9f),
|
||||
...(0, util_1.range)(0x0ea1, 0x0ea3),
|
||||
0x0ea5,
|
||||
0x0ea7,
|
||||
...(0, util_1.range)(0x0eaa, 0x0eab),
|
||||
...(0, util_1.range)(0x0ead, 0x0eb0),
|
||||
...(0, util_1.range)(0x0eb2, 0x0eb3),
|
||||
0x0ebd,
|
||||
...(0, util_1.range)(0x0ec0, 0x0ec4),
|
||||
0x0ec6,
|
||||
...(0, util_1.range)(0x0ed0, 0x0ed9),
|
||||
...(0, util_1.range)(0x0edc, 0x0edd),
|
||||
...(0, util_1.range)(0x0f00, 0x0f17),
|
||||
...(0, util_1.range)(0x0f1a, 0x0f34),
|
||||
0x0f36,
|
||||
0x0f38,
|
||||
...(0, util_1.range)(0x0f3e, 0x0f47),
|
||||
...(0, util_1.range)(0x0f49, 0x0f6a),
|
||||
0x0f7f,
|
||||
0x0f85,
|
||||
...(0, util_1.range)(0x0f88, 0x0f8b),
|
||||
...(0, util_1.range)(0x0fbe, 0x0fc5),
|
||||
...(0, util_1.range)(0x0fc7, 0x0fcc),
|
||||
0x0fcf,
|
||||
...(0, util_1.range)(0x1000, 0x1021),
|
||||
...(0, util_1.range)(0x1023, 0x1027),
|
||||
...(0, util_1.range)(0x1029, 0x102a),
|
||||
0x102c,
|
||||
0x1031,
|
||||
0x1038,
|
||||
...(0, util_1.range)(0x1040, 0x1057),
|
||||
...(0, util_1.range)(0x10a0, 0x10c5),
|
||||
...(0, util_1.range)(0x10d0, 0x10f8),
|
||||
0x10fb,
|
||||
...(0, util_1.range)(0x1100, 0x1159),
|
||||
...(0, util_1.range)(0x115f, 0x11a2),
|
||||
...(0, util_1.range)(0x11a8, 0x11f9),
|
||||
...(0, util_1.range)(0x1200, 0x1206),
|
||||
...(0, util_1.range)(0x1208, 0x1246),
|
||||
0x1248,
|
||||
...(0, util_1.range)(0x124a, 0x124d),
|
||||
...(0, util_1.range)(0x1250, 0x1256),
|
||||
0x1258,
|
||||
...(0, util_1.range)(0x125a, 0x125d),
|
||||
...(0, util_1.range)(0x1260, 0x1286),
|
||||
0x1288,
|
||||
...(0, util_1.range)(0x128a, 0x128d),
|
||||
...(0, util_1.range)(0x1290, 0x12ae),
|
||||
0x12b0,
|
||||
...(0, util_1.range)(0x12b2, 0x12b5),
|
||||
...(0, util_1.range)(0x12b8, 0x12be),
|
||||
0x12c0,
|
||||
...(0, util_1.range)(0x12c2, 0x12c5),
|
||||
...(0, util_1.range)(0x12c8, 0x12ce),
|
||||
...(0, util_1.range)(0x12d0, 0x12d6),
|
||||
...(0, util_1.range)(0x12d8, 0x12ee),
|
||||
...(0, util_1.range)(0x12f0, 0x130e),
|
||||
0x1310,
|
||||
...(0, util_1.range)(0x1312, 0x1315),
|
||||
...(0, util_1.range)(0x1318, 0x131e),
|
||||
...(0, util_1.range)(0x1320, 0x1346),
|
||||
...(0, util_1.range)(0x1348, 0x135a),
|
||||
...(0, util_1.range)(0x1361, 0x137c),
|
||||
...(0, util_1.range)(0x13a0, 0x13f4),
|
||||
...(0, util_1.range)(0x1401, 0x1676),
|
||||
...(0, util_1.range)(0x1681, 0x169a),
|
||||
...(0, util_1.range)(0x16a0, 0x16f0),
|
||||
...(0, util_1.range)(0x1700, 0x170c),
|
||||
...(0, util_1.range)(0x170e, 0x1711),
|
||||
...(0, util_1.range)(0x1720, 0x1731),
|
||||
...(0, util_1.range)(0x1735, 0x1736),
|
||||
...(0, util_1.range)(0x1740, 0x1751),
|
||||
...(0, util_1.range)(0x1760, 0x176c),
|
||||
...(0, util_1.range)(0x176e, 0x1770),
|
||||
...(0, util_1.range)(0x1780, 0x17b6),
|
||||
...(0, util_1.range)(0x17be, 0x17c5),
|
||||
...(0, util_1.range)(0x17c7, 0x17c8),
|
||||
...(0, util_1.range)(0x17d4, 0x17da),
|
||||
0x17dc,
|
||||
...(0, util_1.range)(0x17e0, 0x17e9),
|
||||
...(0, util_1.range)(0x1810, 0x1819),
|
||||
...(0, util_1.range)(0x1820, 0x1877),
|
||||
...(0, util_1.range)(0x1880, 0x18a8),
|
||||
...(0, util_1.range)(0x1e00, 0x1e9b),
|
||||
...(0, util_1.range)(0x1ea0, 0x1ef9),
|
||||
...(0, util_1.range)(0x1f00, 0x1f15),
|
||||
...(0, util_1.range)(0x1f18, 0x1f1d),
|
||||
...(0, util_1.range)(0x1f20, 0x1f45),
|
||||
...(0, util_1.range)(0x1f48, 0x1f4d),
|
||||
...(0, util_1.range)(0x1f50, 0x1f57),
|
||||
0x1f59,
|
||||
0x1f5b,
|
||||
0x1f5d,
|
||||
...(0, util_1.range)(0x1f5f, 0x1f7d),
|
||||
...(0, util_1.range)(0x1f80, 0x1fb4),
|
||||
...(0, util_1.range)(0x1fb6, 0x1fbc),
|
||||
0x1fbe,
|
||||
...(0, util_1.range)(0x1fc2, 0x1fc4),
|
||||
...(0, util_1.range)(0x1fc6, 0x1fcc),
|
||||
...(0, util_1.range)(0x1fd0, 0x1fd3),
|
||||
...(0, util_1.range)(0x1fd6, 0x1fdb),
|
||||
...(0, util_1.range)(0x1fe0, 0x1fec),
|
||||
...(0, util_1.range)(0x1ff2, 0x1ff4),
|
||||
...(0, util_1.range)(0x1ff6, 0x1ffc),
|
||||
0x200e,
|
||||
0x2071,
|
||||
0x207f,
|
||||
0x2102,
|
||||
0x2107,
|
||||
...(0, util_1.range)(0x210a, 0x2113),
|
||||
0x2115,
|
||||
...(0, util_1.range)(0x2119, 0x211d),
|
||||
0x2124,
|
||||
0x2126,
|
||||
0x2128,
|
||||
...(0, util_1.range)(0x212a, 0x212d),
|
||||
...(0, util_1.range)(0x212f, 0x2131),
|
||||
...(0, util_1.range)(0x2133, 0x2139),
|
||||
...(0, util_1.range)(0x213d, 0x213f),
|
||||
...(0, util_1.range)(0x2145, 0x2149),
|
||||
...(0, util_1.range)(0x2160, 0x2183),
|
||||
...(0, util_1.range)(0x2336, 0x237a),
|
||||
0x2395,
|
||||
...(0, util_1.range)(0x249c, 0x24e9),
|
||||
...(0, util_1.range)(0x3005, 0x3007),
|
||||
...(0, util_1.range)(0x3021, 0x3029),
|
||||
...(0, util_1.range)(0x3031, 0x3035),
|
||||
...(0, util_1.range)(0x3038, 0x303c),
|
||||
...(0, util_1.range)(0x3041, 0x3096),
|
||||
...(0, util_1.range)(0x309d, 0x309f),
|
||||
...(0, util_1.range)(0x30a1, 0x30fa),
|
||||
...(0, util_1.range)(0x30fc, 0x30ff),
|
||||
...(0, util_1.range)(0x3105, 0x312c),
|
||||
...(0, util_1.range)(0x3131, 0x318e),
|
||||
...(0, util_1.range)(0x3190, 0x31b7),
|
||||
...(0, util_1.range)(0x31f0, 0x321c),
|
||||
...(0, util_1.range)(0x3220, 0x3243),
|
||||
...(0, util_1.range)(0x3260, 0x327b),
|
||||
...(0, util_1.range)(0x327f, 0x32b0),
|
||||
...(0, util_1.range)(0x32c0, 0x32cb),
|
||||
...(0, util_1.range)(0x32d0, 0x32fe),
|
||||
...(0, util_1.range)(0x3300, 0x3376),
|
||||
...(0, util_1.range)(0x337b, 0x33dd),
|
||||
...(0, util_1.range)(0x33e0, 0x33fe),
|
||||
...(0, util_1.range)(0x3400, 0x4db5),
|
||||
...(0, util_1.range)(0x4e00, 0x9fa5),
|
||||
...(0, util_1.range)(0xa000, 0xa48c),
|
||||
...(0, util_1.range)(0xac00, 0xd7a3),
|
||||
...(0, util_1.range)(0xd800, 0xfa2d),
|
||||
...(0, util_1.range)(0xfa30, 0xfa6a),
|
||||
...(0, util_1.range)(0xfb00, 0xfb06),
|
||||
...(0, util_1.range)(0xfb13, 0xfb17),
|
||||
...(0, util_1.range)(0xff21, 0xff3a),
|
||||
...(0, util_1.range)(0xff41, 0xff5a),
|
||||
...(0, util_1.range)(0xff66, 0xffbe),
|
||||
...(0, util_1.range)(0xffc2, 0xffc7),
|
||||
...(0, util_1.range)(0xffca, 0xffcf),
|
||||
...(0, util_1.range)(0xffd2, 0xffd7),
|
||||
...(0, util_1.range)(0xffda, 0xffdc),
|
||||
...(0, util_1.range)(0x10300, 0x1031e),
|
||||
...(0, util_1.range)(0x10320, 0x10323),
|
||||
...(0, util_1.range)(0x10330, 0x1034a),
|
||||
...(0, util_1.range)(0x10400, 0x10425),
|
||||
...(0, util_1.range)(0x10428, 0x1044d),
|
||||
...(0, util_1.range)(0x1d000, 0x1d0f5),
|
||||
...(0, util_1.range)(0x1d100, 0x1d126),
|
||||
...(0, util_1.range)(0x1d12a, 0x1d166),
|
||||
...(0, util_1.range)(0x1d16a, 0x1d172),
|
||||
...(0, util_1.range)(0x1d183, 0x1d184),
|
||||
...(0, util_1.range)(0x1d18c, 0x1d1a9),
|
||||
...(0, util_1.range)(0x1d1ae, 0x1d1dd),
|
||||
...(0, util_1.range)(0x1d400, 0x1d454),
|
||||
...(0, util_1.range)(0x1d456, 0x1d49c),
|
||||
...(0, util_1.range)(0x1d49e, 0x1d49f),
|
||||
0x1d4a2,
|
||||
...(0, util_1.range)(0x1d4a5, 0x1d4a6),
|
||||
...(0, util_1.range)(0x1d4a9, 0x1d4ac),
|
||||
...(0, util_1.range)(0x1d4ae, 0x1d4b9),
|
||||
0x1d4bb,
|
||||
...(0, util_1.range)(0x1d4bd, 0x1d4c0),
|
||||
...(0, util_1.range)(0x1d4c2, 0x1d4c3),
|
||||
...(0, util_1.range)(0x1d4c5, 0x1d505),
|
||||
...(0, util_1.range)(0x1d507, 0x1d50a),
|
||||
...(0, util_1.range)(0x1d50d, 0x1d514),
|
||||
...(0, util_1.range)(0x1d516, 0x1d51c),
|
||||
...(0, util_1.range)(0x1d51e, 0x1d539),
|
||||
...(0, util_1.range)(0x1d53b, 0x1d53e),
|
||||
...(0, util_1.range)(0x1d540, 0x1d544),
|
||||
0x1d546,
|
||||
...(0, util_1.range)(0x1d54a, 0x1d550),
|
||||
...(0, util_1.range)(0x1d552, 0x1d6a3),
|
||||
...(0, util_1.range)(0x1d6a8, 0x1d7c9),
|
||||
...(0, util_1.range)(0x20000, 0x2a6d6),
|
||||
...(0, util_1.range)(0x2f800, 0x2fa1d),
|
||||
...(0, util_1.range)(0xf0000, 0xffffd),
|
||||
...(0, util_1.range)(0x100000, 0x10fffd),
|
||||
]);
|
||||
//# sourceMappingURL=code-points-src.js.map
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=generate-code-points.d.ts.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"generate-code-points.d.ts","sourceRoot":"","sources":["../src/generate-code-points.ts"],"names":[],"mappings":""}
|
@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const zlib_1 = require("zlib");
|
||||
const sparse_bitfield_1 = __importDefault(require("sparse-bitfield"));
|
||||
const codePoints = __importStar(require("./code-points-src"));
|
||||
const unassigned_code_points = (0, sparse_bitfield_1.default)();
|
||||
const commonly_mapped_to_nothing = (0, sparse_bitfield_1.default)();
|
||||
const non_ascii_space_characters = (0, sparse_bitfield_1.default)();
|
||||
const prohibited_characters = (0, sparse_bitfield_1.default)();
|
||||
const bidirectional_r_al = (0, sparse_bitfield_1.default)();
|
||||
const bidirectional_l = (0, sparse_bitfield_1.default)();
|
||||
function traverse(bits, src) {
|
||||
for (const code of src.keys()) {
|
||||
bits.set(code, true);
|
||||
}
|
||||
const buffer = bits.toBuffer();
|
||||
return Buffer.concat([createSize(buffer), buffer]);
|
||||
}
|
||||
function createSize(buffer) {
|
||||
const buf = Buffer.alloc(4);
|
||||
buf.writeUInt32BE(buffer.length);
|
||||
return buf;
|
||||
}
|
||||
const memory = [];
|
||||
memory.push(traverse(unassigned_code_points, codePoints.unassigned_code_points), traverse(commonly_mapped_to_nothing, codePoints.commonly_mapped_to_nothing), traverse(non_ascii_space_characters, codePoints.non_ASCII_space_characters), traverse(prohibited_characters, codePoints.prohibited_characters), traverse(bidirectional_r_al, codePoints.bidirectional_r_al), traverse(bidirectional_l, codePoints.bidirectional_l));
|
||||
process.stdout.write(`import { gunzipSync } from 'zlib';
|
||||
|
||||
export default gunzipSync(
|
||||
Buffer.from(
|
||||
'${(0, zlib_1.gzipSync)(Buffer.concat(memory), { level: 9 }).toString('base64')}',
|
||||
'base64'
|
||||
)
|
||||
);
|
||||
`);
|
||||
//# sourceMappingURL=generate-code-points.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"generate-code-points.js","sourceRoot":"","sources":["../src/generate-code-points.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAgC;AAChC,sEAAuC;AACvC,8DAAgD;AAEhD,MAAM,sBAAsB,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAC1C,MAAM,0BAA0B,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAC9C,MAAM,0BAA0B,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAC9C,MAAM,qBAAqB,GAAG,IAAA,yBAAQ,GAAE,CAAC;AACzC,MAAM,kBAAkB,GAAG,IAAA,yBAAQ,GAAE,CAAC;AACtC,MAAM,eAAe,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAMnC,SAAS,QAAQ,CAAC,IAA+B,EAAE,GAAgB;IACjE,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;QAC7B,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KACtB;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,UAAU,CAAC,MAAc;IAChC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5B,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,MAAM,GAAa,EAAE,CAAC;AAE5B,MAAM,CAAC,IAAI,CACT,QAAQ,CAAC,sBAAsB,EAAE,UAAU,CAAC,sBAAsB,CAAC,EACnE,QAAQ,CAAC,0BAA0B,EAAE,UAAU,CAAC,0BAA0B,CAAC,EAC3E,QAAQ,CAAC,0BAA0B,EAAE,UAAU,CAAC,0BAA0B,CAAC,EAC3E,QAAQ,CAAC,qBAAqB,EAAE,UAAU,CAAC,qBAAqB,CAAC,EACjE,QAAQ,CAAC,kBAAkB,EAAE,UAAU,CAAC,kBAAkB,CAAC,EAC3D,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC,eAAe,CAAC,CACtD,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB;;;;OAIK,IAAA,eAAQ,EAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;;;;CAItE,CACA,CAAC"}
|
@ -0,0 +1,10 @@
|
||||
declare function saslprep(input: string, opts?: {
|
||||
allowUnassigned?: boolean;
|
||||
}): string;
|
||||
declare namespace saslprep {
|
||||
export var saslprep: typeof import(".");
|
||||
var _a: typeof import(".");
|
||||
export { _a as default };
|
||||
}
|
||||
export = saslprep;
|
||||
//# sourceMappingURL=index.d.ts.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA2DA,iBAAS,QAAQ,CACf,KAAK,EAAE,MAAM,EACb,IAAI,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAO,GACvC,MAAM,CAuFR;kBA1FQ,QAAQ;;;;;AA8FjB,SAAS,QAAQ,CAAC"}
|
@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
const memory_code_points_1 = require("./memory-code-points");
|
||||
const mapping2space = memory_code_points_1.non_ASCII_space_characters;
|
||||
const mapping2nothing = memory_code_points_1.commonly_mapped_to_nothing;
|
||||
const getCodePoint = (character) => character.codePointAt(0);
|
||||
const first = (x) => x[0];
|
||||
const last = (x) => x[x.length - 1];
|
||||
function toCodePoints(input) {
|
||||
const codepoints = [];
|
||||
const size = input.length;
|
||||
for (let i = 0; i < size; i += 1) {
|
||||
const before = input.charCodeAt(i);
|
||||
if (before >= 0xd800 && before <= 0xdbff && size > i + 1) {
|
||||
const next = input.charCodeAt(i + 1);
|
||||
if (next >= 0xdc00 && next <= 0xdfff) {
|
||||
codepoints.push((before - 0xd800) * 0x400 + next - 0xdc00 + 0x10000);
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
codepoints.push(before);
|
||||
}
|
||||
return codepoints;
|
||||
}
|
||||
function saslprep(input, opts = {}) {
|
||||
if (typeof input !== 'string') {
|
||||
throw new TypeError('Expected string.');
|
||||
}
|
||||
if (input.length === 0) {
|
||||
return '';
|
||||
}
|
||||
const mapped_input = toCodePoints(input)
|
||||
.map((character) => (mapping2space.get(character) ? 0x20 : character))
|
||||
.filter((character) => !mapping2nothing.get(character));
|
||||
const normalized_input = String.fromCodePoint
|
||||
.apply(null, mapped_input)
|
||||
.normalize('NFKC');
|
||||
const normalized_map = toCodePoints(normalized_input);
|
||||
const hasProhibited = normalized_map.some((character) => memory_code_points_1.prohibited_characters.get(character));
|
||||
if (hasProhibited) {
|
||||
throw new Error('Prohibited character, see https://tools.ietf.org/html/rfc4013#section-2.3');
|
||||
}
|
||||
if (opts.allowUnassigned !== true) {
|
||||
const hasUnassigned = normalized_map.some((character) => memory_code_points_1.unassigned_code_points.get(character));
|
||||
if (hasUnassigned) {
|
||||
throw new Error('Unassigned code point, see https://tools.ietf.org/html/rfc4013#section-2.5');
|
||||
}
|
||||
}
|
||||
const hasBidiRAL = normalized_map.some((character) => memory_code_points_1.bidirectional_r_al.get(character));
|
||||
const hasBidiL = normalized_map.some((character) => memory_code_points_1.bidirectional_l.get(character));
|
||||
if (hasBidiRAL && hasBidiL) {
|
||||
throw new Error('String must not contain RandALCat and LCat at the same time,' +
|
||||
' see https://tools.ietf.org/html/rfc3454#section-6');
|
||||
}
|
||||
const isFirstBidiRAL = memory_code_points_1.bidirectional_r_al.get(getCodePoint(first(normalized_input)));
|
||||
const isLastBidiRAL = memory_code_points_1.bidirectional_r_al.get(getCodePoint(last(normalized_input)));
|
||||
if (hasBidiRAL && !(isFirstBidiRAL && isLastBidiRAL)) {
|
||||
throw new Error('Bidirectional RandALCat character must be the first and the last' +
|
||||
' character of the string, see https://tools.ietf.org/html/rfc3454#section-6');
|
||||
}
|
||||
return normalized_input;
|
||||
}
|
||||
saslprep.saslprep = saslprep;
|
||||
saslprep.default = saslprep;
|
||||
module.exports = saslprep;
|
||||
//# sourceMappingURL=index.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6DAO8B;AAQ9B,MAAM,aAAa,GAAG,+CAA0B,CAAC;AAMjD,MAAM,eAAe,GAAG,+CAA0B,CAAC;AAGnD,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;AACrE,MAAM,KAAK,GAAG,CAA2B,CAAI,EAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,MAAM,IAAI,GAAG,CAA2B,CAAI,EAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAO5E,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;IAE1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE;QAChC,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEnC,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE;YACxD,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAErC,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE;gBACpC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;gBACrE,CAAC,IAAI,CAAC,CAAC;gBACP,SAAS;aACV;SACF;QAED,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KACzB;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAKD,SAAS,QAAQ,CACf,KAAa,EACb,OAAsC,EAAE;IAExC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,SAAS,CAAC,kBAAkB,CAAC,CAAC;KACzC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,OAAO,EAAE,CAAC;KACX;IAGD,MAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC;SAErC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;SAErE,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAG1D,MAAM,gBAAgB,GAAG,MAAM,CAAC,aAAa;SAC1C,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC;SACzB,SAAS,CAAC,MAAM,CAAC,CAAC;IAErB,MAAM,cAAc,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC;IAGtD,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACtD,0CAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,CACrC,CAAC;IAEF,IAAI,aAAa,EAAE;QACjB,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;KACH;IAGD,IAAI,IAAI,CAAC,eAAe,KAAK,IAAI,EAAE;QACjC,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACtD,2CAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,CACtC,CAAC;QAEF,IAAI,aAAa,EAAE;YACjB,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;SACH;KACF;IAID,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACnD,uCAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,CAClC,CAAC;IAEF,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACjD,oCAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAC/B,CAAC;IAIF,IAAI,UAAU,IAAI,QAAQ,EAAE;QAC1B,MAAM,IAAI,KAAK,CACb,8DAA8D;YAC5D,oDAAoD,CACvD,CAAC;KACH;IAQD,MAAM,cAAc,GAAG,uCAAkB,CAAC,GAAG,CAC3C,YAAY,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAE,CACvC,CAAC;IACF,MAAM,aAAa,GAAG,uCAAkB,CAAC,GAAG,CAC1C,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAE,CACtC,CAAC;IAEF,IAAI,UAAU,IAAI,CAAC,CAAC,cAAc,IAAI,aAAa,CAAC,EAAE;QACpD,MAAM,IAAI,KAAK,CACb,kEAAkE;YAChE,6EAA6E,CAChF,CAAC;KACH;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC;AAC5B,iBAAS,QAAQ,CAAC"}
|
@ -0,0 +1,8 @@
|
||||
import bitfield from 'sparse-bitfield';
|
||||
export declare const unassigned_code_points: bitfield.BitFieldInstance;
|
||||
export declare const commonly_mapped_to_nothing: bitfield.BitFieldInstance;
|
||||
export declare const non_ASCII_space_characters: bitfield.BitFieldInstance;
|
||||
export declare const prohibited_characters: bitfield.BitFieldInstance;
|
||||
export declare const bidirectional_r_al: bitfield.BitFieldInstance;
|
||||
export declare const bidirectional_l: bitfield.BitFieldInstance;
|
||||
//# sourceMappingURL=memory-code-points.d.ts.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"memory-code-points.d.ts","sourceRoot":"","sources":["../src/memory-code-points.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAkBvC,eAAO,MAAM,sBAAsB,2BAAS,CAAC;AAC7C,eAAO,MAAM,0BAA0B,2BAAS,CAAC;AACjD,eAAO,MAAM,0BAA0B,2BAAS,CAAC;AACjD,eAAO,MAAM,qBAAqB,2BAAS,CAAC;AAC5C,eAAO,MAAM,kBAAkB,2BAAS,CAAC;AACzC,eAAO,MAAM,eAAe,2BAAS,CAAC"}
|
@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.bidirectional_l = exports.bidirectional_r_al = exports.prohibited_characters = exports.non_ASCII_space_characters = exports.commonly_mapped_to_nothing = exports.unassigned_code_points = void 0;
|
||||
const sparse_bitfield_1 = __importDefault(require("sparse-bitfield"));
|
||||
const code_points_data_1 = __importDefault(require("./code-points-data"));
|
||||
let offset = 0;
|
||||
function read() {
|
||||
const size = code_points_data_1.default.readUInt32BE(offset);
|
||||
offset += 4;
|
||||
const codepoints = code_points_data_1.default.slice(offset, offset + size);
|
||||
offset += size;
|
||||
return (0, sparse_bitfield_1.default)({ buffer: codepoints });
|
||||
}
|
||||
exports.unassigned_code_points = read();
|
||||
exports.commonly_mapped_to_nothing = read();
|
||||
exports.non_ASCII_space_characters = read();
|
||||
exports.prohibited_characters = read();
|
||||
exports.bidirectional_r_al = read();
|
||||
exports.bidirectional_l = read();
|
||||
//# sourceMappingURL=memory-code-points.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"memory-code-points.js","sourceRoot":"","sources":["../src/memory-code-points.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAuC;AACvC,0EAAwC;AAExC,IAAI,MAAM,GAAG,CAAC,CAAC;AAKf,SAAS,IAAI;IACX,MAAM,IAAI,GAAG,0BAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,IAAI,CAAC,CAAC;IAEZ,MAAM,UAAU,GAAG,0BAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IACvD,MAAM,IAAI,IAAI,CAAC;IAEf,OAAO,IAAA,yBAAQ,EAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;AAC1C,CAAC;AAEY,QAAA,sBAAsB,GAAG,IAAI,EAAE,CAAC;AAChC,QAAA,0BAA0B,GAAG,IAAI,EAAE,CAAC;AACpC,QAAA,0BAA0B,GAAG,IAAI,EAAE,CAAC;AACpC,QAAA,qBAAqB,GAAG,IAAI,EAAE,CAAC;AAC/B,QAAA,kBAAkB,GAAG,IAAI,EAAE,CAAC;AAC5B,QAAA,eAAe,GAAG,IAAI,EAAE,CAAC"}
|
@ -0,0 +1,2 @@
|
||||
export declare function range(from: number, to: number): number[];
|
||||
//# sourceMappingURL=util.d.ts.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAGA,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxD"}
|
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.range = void 0;
|
||||
function range(from, to) {
|
||||
const list = new Array(to - from + 1);
|
||||
for (let i = 0; i < list.length; i += 1) {
|
||||
list[i] = from + i;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
exports.range = range;
|
||||
//# sourceMappingURL=util.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAGA,SAAgB,KAAK,CAAC,IAAY,EAAE,EAAU;IAE5C,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;IAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QACvC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;KACpB;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AARD,sBAQC"}
|
@ -0,0 +1,83 @@
|
||||
{
|
||||
"name": "@mongodb-js/saslprep",
|
||||
"description": "SASLprep: Stringprep Profile for User Names and Passwords, rfc4013",
|
||||
"keywords": [
|
||||
"sasl",
|
||||
"saslprep",
|
||||
"stringprep",
|
||||
"rfc4013",
|
||||
"4013"
|
||||
],
|
||||
"author": "Dmitry Tsvettsikh <me@reklatsmasters.com>",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"bugs": {
|
||||
"url": "https://jira.mongodb.org/projects/COMPASS/issues",
|
||||
"email": "compass@mongodb.com"
|
||||
},
|
||||
"homepage": "https://github.com/mongodb-js/devtools-shared/tree/main/packages/saslprep",
|
||||
"version": "1.1.1",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mongodb-js/devtools-shared.git"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"import": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/.esm-wrapper.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"gen-code-points": "ts-node src/generate-code-points.ts > src/code-points-data.ts",
|
||||
"bootstrap": "npm run compile",
|
||||
"prepublishOnly": "npm run compile",
|
||||
"compile": "npm run gen-code-points && tsc -p tsconfig.json && gen-esm-wrapper . ./dist/.esm-wrapper.mjs",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"eslint": "eslint",
|
||||
"prettier": "prettier",
|
||||
"lint": "npm run eslint . && npm run prettier -- --check .",
|
||||
"depcheck": "depcheck",
|
||||
"check": "npm run typecheck && npm run lint && npm run depcheck",
|
||||
"check-ci": "npm run check",
|
||||
"test": "mocha",
|
||||
"test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
|
||||
"test-watch": "npm run test -- --watch",
|
||||
"test-ci": "npm run test-cov",
|
||||
"reformat": "npm run prettier -- --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"sparse-bitfield": "^3.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mongodb-js/eslint-config-devtools": "0.9.10",
|
||||
"@mongodb-js/mocha-config-devtools": "^1.0.2",
|
||||
"@mongodb-js/prettier-config-devtools": "^1.0.1",
|
||||
"@mongodb-js/tsconfig-devtools": "^1.0.1",
|
||||
"@types/chai": "^4.2.21",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/node": "^17.0.35",
|
||||
"@types/sinon-chai": "^3.2.5",
|
||||
"@types/sparse-bitfield": "^3.0.1",
|
||||
"chai": "^4.3.6",
|
||||
"depcheck": "^1.4.1",
|
||||
"eslint": "^7.25.0",
|
||||
"gen-esm-wrapper": "^1.1.0",
|
||||
"mocha": "^8.4.0",
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^2.3.2",
|
||||
"sinon": "^9.2.3",
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"gitHead": "d12c5bfb1e14343bd5d218a390c4ef3214037e2d"
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
# saslprep
|
||||
|
||||
_Note: This is a fork of the original [`saslprep`](https://www.npmjs.com/package/saslprep) npm package
|
||||
and provides equivalent functionality._
|
||||
|
||||
Stringprep Profile for User Names and Passwords, [rfc4013](https://tools.ietf.org/html/rfc4013)
|
||||
|
||||
### Usage
|
||||
|
||||
```js
|
||||
const saslprep = require('@mongodb-js/saslprep');
|
||||
|
||||
saslprep('password\u00AD'); // password
|
||||
saslprep('password\u0007'); // Error: prohibited character
|
||||
```
|
||||
|
||||
### API
|
||||
|
||||
##### `saslprep(input: String, opts: Options): String`
|
||||
|
||||
Normalize user name or password.
|
||||
|
||||
##### `Options.allowUnassigned: bool`
|
||||
|
||||
A special behavior for unassigned code points, see https://tools.ietf.org/html/rfc4013#section-2.5. Disabled by default.
|
||||
|
||||
## License
|
||||
|
||||
MIT, 2017-2019 (c) Dmitriy Tsvettsikh
|
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE
|
@ -0,0 +1,15 @@
|
||||
# Installation
|
||||
> `npm install --save @types/node`
|
||||
|
||||
# Summary
|
||||
This package contains type definitions for node (https://nodejs.org/).
|
||||
|
||||
# Details
|
||||
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
|
||||
|
||||
### Additional Details
|
||||
* Last updated: Sat, 30 Dec 2023 00:22:50 GMT
|
||||
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)
|
||||
|
||||
# Credits
|
||||
These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [Alberto Schiabel](https://github.com/jkomyno), [Alvis HT Tang](https://github.com/alvis), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [Chigozirim C.](https://github.com/smac89), [David Junger](https://github.com/touffy), [Deividas Bakanas](https://github.com/DeividasBakanas), [Eugene Y. Q. Shen](https://github.com/eyqs), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Huw](https://github.com/hoo29), [Kelvin Jin](https://github.com/kjin), [Klaus Meinhardt](https://github.com/ajafff), [Lishude](https://github.com/islishude), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [Mohsen Azimi](https://github.com/mohsen1), [Nicolas Even](https://github.com/n-e), [Nikita Galkin](https://github.com/galkin), [Parambir Singh](https://github.com/parambirs), [Sebastian Silbermann](https://github.com/eps1lon), [Thomas den Hollander](https://github.com/ThomasdenH), [Wilco Bakker](https://github.com/WilcoBakker), [wwwy3y3](https://github.com/wwwy3y3), [Samuel Ainsworth](https://github.com/samuela), [Kyle Uehlein](https://github.com/kuehlein), [Thanik Bhongbhibhat](https://github.com/bhongy), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), [ExE Boss](https://github.com/ExE-Boss), [Piotr Błażejewicz](https://github.com/peterblazejewicz), [Anna Henningsen](https://github.com/addaleax), [Victor Perin](https://github.com/victorperin), [Yongsheng Zhang](https://github.com/ZYSzys), [NodeJS Contributors](https://github.com/NodeJS), [Linus Unnebäck](https://github.com/LinusU), [wafuwafu13](https://github.com/wafuwafu13), [Matteo Collina](https://github.com/mcollina), and [Dmitry Semigradsky](https://github.com/Semigradsky).
|
@ -0,0 +1,996 @@
|
||||
/**
|
||||
* The `node:assert` module provides a set of assertion functions for verifying
|
||||
* invariants.
|
||||
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/assert.js)
|
||||
*/
|
||||
declare module "assert" {
|
||||
/**
|
||||
* An alias of {@link ok}.
|
||||
* @since v0.5.9
|
||||
* @param value The input that is checked for being truthy.
|
||||
*/
|
||||
function assert(value: unknown, message?: string | Error): asserts value;
|
||||
namespace assert {
|
||||
/**
|
||||
* Indicates the failure of an assertion. All errors thrown by the `node:assert`module will be instances of the `AssertionError` class.
|
||||
*/
|
||||
class AssertionError extends Error {
|
||||
/**
|
||||
* Set to the `actual` argument for methods such as {@link assert.strictEqual()}.
|
||||
*/
|
||||
actual: unknown;
|
||||
/**
|
||||
* Set to the `expected` argument for methods such as {@link assert.strictEqual()}.
|
||||
*/
|
||||
expected: unknown;
|
||||
/**
|
||||
* Set to the passed in operator value.
|
||||
*/
|
||||
operator: string;
|
||||
/**
|
||||
* Indicates if the message was auto-generated (`true`) or not.
|
||||
*/
|
||||
generatedMessage: boolean;
|
||||
/**
|
||||
* Value is always `ERR_ASSERTION` to show that the error is an assertion error.
|
||||
*/
|
||||
code: "ERR_ASSERTION";
|
||||
constructor(options?: {
|
||||
/** If provided, the error message is set to this value. */
|
||||
message?: string | undefined;
|
||||
/** The `actual` property on the error instance. */
|
||||
actual?: unknown | undefined;
|
||||
/** The `expected` property on the error instance. */
|
||||
expected?: unknown | undefined;
|
||||
/** The `operator` property on the error instance. */
|
||||
operator?: string | undefined;
|
||||
/** If provided, the generated stack trace omits frames before this function. */
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
stackStartFn?: Function | undefined;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This feature is deprecated and will be removed in a future version.
|
||||
* Please consider using alternatives such as the `mock` helper function.
|
||||
* @since v14.2.0, v12.19.0
|
||||
* @deprecated Deprecated
|
||||
*/
|
||||
class CallTracker {
|
||||
/**
|
||||
* The wrapper function is expected to be called exactly `exact` times. If the
|
||||
* function has not been called exactly `exact` times when `tracker.verify()` is called, then `tracker.verify()` will throw an
|
||||
* error.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert';
|
||||
*
|
||||
* // Creates call tracker.
|
||||
* const tracker = new assert.CallTracker();
|
||||
*
|
||||
* function func() {}
|
||||
*
|
||||
* // Returns a function that wraps func() that must be called exact times
|
||||
* // before tracker.verify().
|
||||
* const callsfunc = tracker.calls(func);
|
||||
* ```
|
||||
* @since v14.2.0, v12.19.0
|
||||
* @param [fn='A no-op function']
|
||||
* @param [exact=1]
|
||||
* @return that wraps `fn`.
|
||||
*/
|
||||
calls(exact?: number): () => void;
|
||||
calls<Func extends (...args: any[]) => any>(fn?: Func, exact?: number): Func;
|
||||
/**
|
||||
* Example:
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert';
|
||||
*
|
||||
* const tracker = new assert.CallTracker();
|
||||
*
|
||||
* function func() {}
|
||||
* const callsfunc = tracker.calls(func);
|
||||
* callsfunc(1, 2, 3);
|
||||
*
|
||||
* assert.deepStrictEqual(tracker.getCalls(callsfunc),
|
||||
* [{ thisArg: undefined, arguments: [1, 2, 3] }]);
|
||||
* ```
|
||||
* @since v18.8.0, v16.18.0
|
||||
* @param fn
|
||||
* @return An Array with all the calls to a tracked function.
|
||||
*/
|
||||
getCalls(fn: Function): CallTrackerCall[];
|
||||
/**
|
||||
* The arrays contains information about the expected and actual number of calls of
|
||||
* the functions that have not been called the expected number of times.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert';
|
||||
*
|
||||
* // Creates call tracker.
|
||||
* const tracker = new assert.CallTracker();
|
||||
*
|
||||
* function func() {}
|
||||
*
|
||||
* // Returns a function that wraps func() that must be called exact times
|
||||
* // before tracker.verify().
|
||||
* const callsfunc = tracker.calls(func, 2);
|
||||
*
|
||||
* // Returns an array containing information on callsfunc()
|
||||
* console.log(tracker.report());
|
||||
* // [
|
||||
* // {
|
||||
* // message: 'Expected the func function to be executed 2 time(s) but was
|
||||
* // executed 0 time(s).',
|
||||
* // actual: 0,
|
||||
* // expected: 2,
|
||||
* // operator: 'func',
|
||||
* // stack: stack trace
|
||||
* // }
|
||||
* // ]
|
||||
* ```
|
||||
* @since v14.2.0, v12.19.0
|
||||
* @return An Array of objects containing information about the wrapper functions returned by `calls`.
|
||||
*/
|
||||
report(): CallTrackerReportInformation[];
|
||||
/**
|
||||
* Reset calls of the call tracker.
|
||||
* If a tracked function is passed as an argument, the calls will be reset for it.
|
||||
* If no arguments are passed, all tracked functions will be reset.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert';
|
||||
*
|
||||
* const tracker = new assert.CallTracker();
|
||||
*
|
||||
* function func() {}
|
||||
* const callsfunc = tracker.calls(func);
|
||||
*
|
||||
* callsfunc();
|
||||
* // Tracker was called once
|
||||
* assert.strictEqual(tracker.getCalls(callsfunc).length, 1);
|
||||
*
|
||||
* tracker.reset(callsfunc);
|
||||
* assert.strictEqual(tracker.getCalls(callsfunc).length, 0);
|
||||
* ```
|
||||
* @since v18.8.0, v16.18.0
|
||||
* @param fn a tracked function to reset.
|
||||
*/
|
||||
reset(fn?: Function): void;
|
||||
/**
|
||||
* Iterates through the list of functions passed to `tracker.calls()` and will throw an error for functions that
|
||||
* have not been called the expected number of times.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert';
|
||||
*
|
||||
* // Creates call tracker.
|
||||
* const tracker = new assert.CallTracker();
|
||||
*
|
||||
* function func() {}
|
||||
*
|
||||
* // Returns a function that wraps func() that must be called exact times
|
||||
* // before tracker.verify().
|
||||
* const callsfunc = tracker.calls(func, 2);
|
||||
*
|
||||
* callsfunc();
|
||||
*
|
||||
* // Will throw an error since callsfunc() was only called once.
|
||||
* tracker.verify();
|
||||
* ```
|
||||
* @since v14.2.0, v12.19.0
|
||||
*/
|
||||
verify(): void;
|
||||
}
|
||||
interface CallTrackerCall {
|
||||
thisArg: object;
|
||||
arguments: unknown[];
|
||||
}
|
||||
interface CallTrackerReportInformation {
|
||||
message: string;
|
||||
/** The actual number of times the function was called. */
|
||||
actual: number;
|
||||
/** The number of times the function was expected to be called. */
|
||||
expected: number;
|
||||
/** The name of the function that is wrapped. */
|
||||
operator: string;
|
||||
/** A stack trace of the function. */
|
||||
stack: object;
|
||||
}
|
||||
type AssertPredicate = RegExp | (new() => object) | ((thrown: unknown) => boolean) | object | Error;
|
||||
/**
|
||||
* Throws an `AssertionError` with the provided error message or a default
|
||||
* error message. If the `message` parameter is an instance of an `Error` then
|
||||
* it will be thrown instead of the `AssertionError`.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.fail();
|
||||
* // AssertionError [ERR_ASSERTION]: Failed
|
||||
*
|
||||
* assert.fail('boom');
|
||||
* // AssertionError [ERR_ASSERTION]: boom
|
||||
*
|
||||
* assert.fail(new TypeError('need array'));
|
||||
* // TypeError: need array
|
||||
* ```
|
||||
*
|
||||
* Using `assert.fail()` with more than two arguments is possible but deprecated.
|
||||
* See below for further details.
|
||||
* @since v0.1.21
|
||||
* @param [message='Failed']
|
||||
*/
|
||||
function fail(message?: string | Error): never;
|
||||
/** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
|
||||
function fail(
|
||||
actual: unknown,
|
||||
expected: unknown,
|
||||
message?: string | Error,
|
||||
operator?: string,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
stackStartFn?: Function,
|
||||
): never;
|
||||
/**
|
||||
* Tests if `value` is truthy. It is equivalent to`assert.equal(!!value, true, message)`.
|
||||
*
|
||||
* If `value` is not truthy, an `AssertionError` is thrown with a `message`property set equal to the value of the `message` parameter. If the `message`parameter is `undefined`, a default
|
||||
* error message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
|
||||
* If no arguments are passed in at all `message` will be set to the string:`` 'No value argument passed to `assert.ok()`' ``.
|
||||
*
|
||||
* Be aware that in the `repl` the error message will be different to the one
|
||||
* thrown in a file! See below for further details.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.ok(true);
|
||||
* // OK
|
||||
* assert.ok(1);
|
||||
* // OK
|
||||
*
|
||||
* assert.ok();
|
||||
* // AssertionError: No value argument passed to `assert.ok()`
|
||||
*
|
||||
* assert.ok(false, 'it\'s false');
|
||||
* // AssertionError: it's false
|
||||
*
|
||||
* // In the repl:
|
||||
* assert.ok(typeof 123 === 'string');
|
||||
* // AssertionError: false == true
|
||||
*
|
||||
* // In a file (e.g. test.js):
|
||||
* assert.ok(typeof 123 === 'string');
|
||||
* // AssertionError: The expression evaluated to a falsy value:
|
||||
* //
|
||||
* // assert.ok(typeof 123 === 'string')
|
||||
*
|
||||
* assert.ok(false);
|
||||
* // AssertionError: The expression evaluated to a falsy value:
|
||||
* //
|
||||
* // assert.ok(false)
|
||||
*
|
||||
* assert.ok(0);
|
||||
* // AssertionError: The expression evaluated to a falsy value:
|
||||
* //
|
||||
* // assert.ok(0)
|
||||
* ```
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* // Using `assert()` works the same:
|
||||
* assert(0);
|
||||
* // AssertionError: The expression evaluated to a falsy value:
|
||||
* //
|
||||
* // assert(0)
|
||||
* ```
|
||||
* @since v0.1.21
|
||||
*/
|
||||
function ok(value: unknown, message?: string | Error): asserts value;
|
||||
/**
|
||||
* **Strict assertion mode**
|
||||
*
|
||||
* An alias of {@link strictEqual}.
|
||||
*
|
||||
* **Legacy assertion mode**
|
||||
*
|
||||
* > Stability: 3 - Legacy: Use {@link strictEqual} instead.
|
||||
*
|
||||
* Tests shallow, coercive equality between the `actual` and `expected` parameters
|
||||
* using the [`==` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality). `NaN` is specially handled
|
||||
* and treated as being identical if both sides are `NaN`.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert';
|
||||
*
|
||||
* assert.equal(1, 1);
|
||||
* // OK, 1 == 1
|
||||
* assert.equal(1, '1');
|
||||
* // OK, 1 == '1'
|
||||
* assert.equal(NaN, NaN);
|
||||
* // OK
|
||||
*
|
||||
* assert.equal(1, 2);
|
||||
* // AssertionError: 1 == 2
|
||||
* assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
|
||||
* // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
|
||||
* ```
|
||||
*
|
||||
* If the values are not equal, an `AssertionError` is thrown with a `message`property set equal to the value of the `message` parameter. If the `message`parameter is undefined, a default
|
||||
* error message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
|
||||
* @since v0.1.21
|
||||
*/
|
||||
function equal(actual: unknown, expected: unknown, message?: string | Error): void;
|
||||
/**
|
||||
* **Strict assertion mode**
|
||||
*
|
||||
* An alias of {@link notStrictEqual}.
|
||||
*
|
||||
* **Legacy assertion mode**
|
||||
*
|
||||
* > Stability: 3 - Legacy: Use {@link notStrictEqual} instead.
|
||||
*
|
||||
* Tests shallow, coercive inequality with the [`!=` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality). `NaN` is
|
||||
* specially handled and treated as being identical if both sides are `NaN`.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert';
|
||||
*
|
||||
* assert.notEqual(1, 2);
|
||||
* // OK
|
||||
*
|
||||
* assert.notEqual(1, 1);
|
||||
* // AssertionError: 1 != 1
|
||||
*
|
||||
* assert.notEqual(1, '1');
|
||||
* // AssertionError: 1 != '1'
|
||||
* ```
|
||||
*
|
||||
* If the values are equal, an `AssertionError` is thrown with a `message`property set equal to the value of the `message` parameter. If the `message`parameter is undefined, a default error
|
||||
* message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
|
||||
* @since v0.1.21
|
||||
*/
|
||||
function notEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
||||
/**
|
||||
* **Strict assertion mode**
|
||||
*
|
||||
* An alias of {@link deepStrictEqual}.
|
||||
*
|
||||
* **Legacy assertion mode**
|
||||
*
|
||||
* > Stability: 3 - Legacy: Use {@link deepStrictEqual} instead.
|
||||
*
|
||||
* Tests for deep equality between the `actual` and `expected` parameters. Consider
|
||||
* using {@link deepStrictEqual} instead. {@link deepEqual} can have
|
||||
* surprising results.
|
||||
*
|
||||
* _Deep equality_ means that the enumerable "own" properties of child objects
|
||||
* are also recursively evaluated by the following rules.
|
||||
* @since v0.1.21
|
||||
*/
|
||||
function deepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
||||
/**
|
||||
* **Strict assertion mode**
|
||||
*
|
||||
* An alias of {@link notDeepStrictEqual}.
|
||||
*
|
||||
* **Legacy assertion mode**
|
||||
*
|
||||
* > Stability: 3 - Legacy: Use {@link notDeepStrictEqual} instead.
|
||||
*
|
||||
* Tests for any deep inequality. Opposite of {@link deepEqual}.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert';
|
||||
*
|
||||
* const obj1 = {
|
||||
* a: {
|
||||
* b: 1,
|
||||
* },
|
||||
* };
|
||||
* const obj2 = {
|
||||
* a: {
|
||||
* b: 2,
|
||||
* },
|
||||
* };
|
||||
* const obj3 = {
|
||||
* a: {
|
||||
* b: 1,
|
||||
* },
|
||||
* };
|
||||
* const obj4 = { __proto__: obj1 };
|
||||
*
|
||||
* assert.notDeepEqual(obj1, obj1);
|
||||
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
||||
*
|
||||
* assert.notDeepEqual(obj1, obj2);
|
||||
* // OK
|
||||
*
|
||||
* assert.notDeepEqual(obj1, obj3);
|
||||
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
||||
*
|
||||
* assert.notDeepEqual(obj1, obj4);
|
||||
* // OK
|
||||
* ```
|
||||
*
|
||||
* If the values are deeply equal, an `AssertionError` is thrown with a`message` property set equal to the value of the `message` parameter. If the`message` parameter is undefined, a default
|
||||
* error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
|
||||
* instead of the `AssertionError`.
|
||||
* @since v0.1.21
|
||||
*/
|
||||
function notDeepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
||||
/**
|
||||
* Tests strict equality between the `actual` and `expected` parameters as
|
||||
* determined by [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.strictEqual(1, 2);
|
||||
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
||||
* //
|
||||
* // 1 !== 2
|
||||
*
|
||||
* assert.strictEqual(1, 1);
|
||||
* // OK
|
||||
*
|
||||
* assert.strictEqual('Hello foobar', 'Hello World!');
|
||||
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
||||
* // + actual - expected
|
||||
* //
|
||||
* // + 'Hello foobar'
|
||||
* // - 'Hello World!'
|
||||
* // ^
|
||||
*
|
||||
* const apples = 1;
|
||||
* const oranges = 2;
|
||||
* assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`);
|
||||
* // AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2
|
||||
*
|
||||
* assert.strictEqual(1, '1', new TypeError('Inputs are not identical'));
|
||||
* // TypeError: Inputs are not identical
|
||||
* ```
|
||||
*
|
||||
* If the values are not strictly equal, an `AssertionError` is thrown with a`message` property set equal to the value of the `message` parameter. If the`message` parameter is undefined, a
|
||||
* default error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
|
||||
* instead of the `AssertionError`.
|
||||
* @since v0.1.21
|
||||
*/
|
||||
function strictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
||||
/**
|
||||
* Tests strict inequality between the `actual` and `expected` parameters as
|
||||
* determined by [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.notStrictEqual(1, 2);
|
||||
* // OK
|
||||
*
|
||||
* assert.notStrictEqual(1, 1);
|
||||
* // AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to:
|
||||
* //
|
||||
* // 1
|
||||
*
|
||||
* assert.notStrictEqual(1, '1');
|
||||
* // OK
|
||||
* ```
|
||||
*
|
||||
* If the values are strictly equal, an `AssertionError` is thrown with a`message` property set equal to the value of the `message` parameter. If the`message` parameter is undefined, a
|
||||
* default error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
|
||||
* instead of the `AssertionError`.
|
||||
* @since v0.1.21
|
||||
*/
|
||||
function notStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
||||
/**
|
||||
* Tests for deep equality between the `actual` and `expected` parameters.
|
||||
* "Deep" equality means that the enumerable "own" properties of child objects
|
||||
* are recursively evaluated also by the following rules.
|
||||
* @since v1.2.0
|
||||
*/
|
||||
function deepStrictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
||||
/**
|
||||
* Tests for deep strict inequality. Opposite of {@link deepStrictEqual}.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
|
||||
* // OK
|
||||
* ```
|
||||
*
|
||||
* If the values are deeply and strictly equal, an `AssertionError` is thrown
|
||||
* with a `message` property set equal to the value of the `message` parameter. If
|
||||
* the `message` parameter is undefined, a default error message is assigned. If
|
||||
* the `message` parameter is an instance of an `Error` then it will be thrown
|
||||
* instead of the `AssertionError`.
|
||||
* @since v1.2.0
|
||||
*/
|
||||
function notDeepStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
||||
/**
|
||||
* Expects the function `fn` to throw an error.
|
||||
*
|
||||
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
||||
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
|
||||
* a validation object where each property will be tested for strict deep equality,
|
||||
* or an instance of error where each property will be tested for strict deep
|
||||
* equality including the non-enumerable `message` and `name` properties. When
|
||||
* using an object, it is also possible to use a regular expression, when
|
||||
* validating against a string property. See below for examples.
|
||||
*
|
||||
* If specified, `message` will be appended to the message provided by the`AssertionError` if the `fn` call fails to throw or in case the error validation
|
||||
* fails.
|
||||
*
|
||||
* Custom validation object/error instance:
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* const err = new TypeError('Wrong value');
|
||||
* err.code = 404;
|
||||
* err.foo = 'bar';
|
||||
* err.info = {
|
||||
* nested: true,
|
||||
* baz: 'text',
|
||||
* };
|
||||
* err.reg = /abc/i;
|
||||
*
|
||||
* assert.throws(
|
||||
* () => {
|
||||
* throw err;
|
||||
* },
|
||||
* {
|
||||
* name: 'TypeError',
|
||||
* message: 'Wrong value',
|
||||
* info: {
|
||||
* nested: true,
|
||||
* baz: 'text',
|
||||
* },
|
||||
* // Only properties on the validation object will be tested for.
|
||||
* // Using nested objects requires all properties to be present. Otherwise
|
||||
* // the validation is going to fail.
|
||||
* },
|
||||
* );
|
||||
*
|
||||
* // Using regular expressions to validate error properties:
|
||||
* assert.throws(
|
||||
* () => {
|
||||
* throw err;
|
||||
* },
|
||||
* {
|
||||
* // The `name` and `message` properties are strings and using regular
|
||||
* // expressions on those will match against the string. If they fail, an
|
||||
* // error is thrown.
|
||||
* name: /^TypeError$/,
|
||||
* message: /Wrong/,
|
||||
* foo: 'bar',
|
||||
* info: {
|
||||
* nested: true,
|
||||
* // It is not possible to use regular expressions for nested properties!
|
||||
* baz: 'text',
|
||||
* },
|
||||
* // The `reg` property contains a regular expression and only if the
|
||||
* // validation object contains an identical regular expression, it is going
|
||||
* // to pass.
|
||||
* reg: /abc/i,
|
||||
* },
|
||||
* );
|
||||
*
|
||||
* // Fails due to the different `message` and `name` properties:
|
||||
* assert.throws(
|
||||
* () => {
|
||||
* const otherErr = new Error('Not found');
|
||||
* // Copy all enumerable properties from `err` to `otherErr`.
|
||||
* for (const [key, value] of Object.entries(err)) {
|
||||
* otherErr[key] = value;
|
||||
* }
|
||||
* throw otherErr;
|
||||
* },
|
||||
* // The error's `message` and `name` properties will also be checked when using
|
||||
* // an error as validation object.
|
||||
* err,
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* Validate instanceof using constructor:
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.throws(
|
||||
* () => {
|
||||
* throw new Error('Wrong value');
|
||||
* },
|
||||
* Error,
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* Validate error message using [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions):
|
||||
*
|
||||
* Using a regular expression runs `.toString` on the error object, and will
|
||||
* therefore also include the error name.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.throws(
|
||||
* () => {
|
||||
* throw new Error('Wrong value');
|
||||
* },
|
||||
* /^Error: Wrong value$/,
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* Custom error validation:
|
||||
*
|
||||
* The function must return `true` to indicate all internal validations passed.
|
||||
* It will otherwise fail with an `AssertionError`.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.throws(
|
||||
* () => {
|
||||
* throw new Error('Wrong value');
|
||||
* },
|
||||
* (err) => {
|
||||
* assert(err instanceof Error);
|
||||
* assert(/value/.test(err));
|
||||
* // Avoid returning anything from validation functions besides `true`.
|
||||
* // Otherwise, it's not clear what part of the validation failed. Instead,
|
||||
* // throw an error about the specific validation that failed (as done in this
|
||||
* // example) and add as much helpful debugging information to that error as
|
||||
* // possible.
|
||||
* return true;
|
||||
* },
|
||||
* 'unexpected error',
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* `error` cannot be a string. If a string is provided as the second
|
||||
* argument, then `error` is assumed to be omitted and the string will be used for`message` instead. This can lead to easy-to-miss mistakes. Using the same
|
||||
* message as the thrown error message is going to result in an`ERR_AMBIGUOUS_ARGUMENT` error. Please read the example below carefully if using
|
||||
* a string as the second argument gets considered:
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* function throwingFirst() {
|
||||
* throw new Error('First');
|
||||
* }
|
||||
*
|
||||
* function throwingSecond() {
|
||||
* throw new Error('Second');
|
||||
* }
|
||||
*
|
||||
* function notThrowing() {}
|
||||
*
|
||||
* // The second argument is a string and the input function threw an Error.
|
||||
* // The first case will not throw as it does not match for the error message
|
||||
* // thrown by the input function!
|
||||
* assert.throws(throwingFirst, 'Second');
|
||||
* // In the next example the message has no benefit over the message from the
|
||||
* // error and since it is not clear if the user intended to actually match
|
||||
* // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.
|
||||
* assert.throws(throwingSecond, 'Second');
|
||||
* // TypeError [ERR_AMBIGUOUS_ARGUMENT]
|
||||
*
|
||||
* // The string is only used (as message) in case the function does not throw:
|
||||
* assert.throws(notThrowing, 'Second');
|
||||
* // AssertionError [ERR_ASSERTION]: Missing expected exception: Second
|
||||
*
|
||||
* // If it was intended to match for the error message do this instead:
|
||||
* // It does not throw because the error messages match.
|
||||
* assert.throws(throwingSecond, /Second$/);
|
||||
*
|
||||
* // If the error message does not match, an AssertionError is thrown.
|
||||
* assert.throws(throwingFirst, /Second$/);
|
||||
* // AssertionError [ERR_ASSERTION]
|
||||
* ```
|
||||
*
|
||||
* Due to the confusing error-prone notation, avoid a string as the second
|
||||
* argument.
|
||||
* @since v0.1.21
|
||||
*/
|
||||
function throws(block: () => unknown, message?: string | Error): void;
|
||||
function throws(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
|
||||
/**
|
||||
* Asserts that the function `fn` does not throw an error.
|
||||
*
|
||||
* Using `assert.doesNotThrow()` is actually not useful because there
|
||||
* is no benefit in catching an error and then rethrowing it. Instead, consider
|
||||
* adding a comment next to the specific code path that should not throw and keep
|
||||
* error messages as expressive as possible.
|
||||
*
|
||||
* When `assert.doesNotThrow()` is called, it will immediately call the `fn`function.
|
||||
*
|
||||
* If an error is thrown and it is the same type as that specified by the `error`parameter, then an `AssertionError` is thrown. If the error is of a
|
||||
* different type, or if the `error` parameter is undefined, the error is
|
||||
* propagated back to the caller.
|
||||
*
|
||||
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
||||
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), or a validation
|
||||
* function. See {@link throws} for more details.
|
||||
*
|
||||
* The following, for instance, will throw the `TypeError` because there is no
|
||||
* matching error type in the assertion:
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.doesNotThrow(
|
||||
* () => {
|
||||
* throw new TypeError('Wrong value');
|
||||
* },
|
||||
* SyntaxError,
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* However, the following will result in an `AssertionError` with the message
|
||||
* 'Got unwanted exception...':
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.doesNotThrow(
|
||||
* () => {
|
||||
* throw new TypeError('Wrong value');
|
||||
* },
|
||||
* TypeError,
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* If an `AssertionError` is thrown and a value is provided for the `message`parameter, the value of `message` will be appended to the `AssertionError` message:
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.doesNotThrow(
|
||||
* () => {
|
||||
* throw new TypeError('Wrong value');
|
||||
* },
|
||||
* /Wrong value/,
|
||||
* 'Whoops',
|
||||
* );
|
||||
* // Throws: AssertionError: Got unwanted exception: Whoops
|
||||
* ```
|
||||
* @since v0.1.21
|
||||
*/
|
||||
function doesNotThrow(block: () => unknown, message?: string | Error): void;
|
||||
function doesNotThrow(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
|
||||
/**
|
||||
* Throws `value` if `value` is not `undefined` or `null`. This is useful when
|
||||
* testing the `error` argument in callbacks. The stack trace contains all frames
|
||||
* from the error passed to `ifError()` including the potential new frames for`ifError()` itself.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.ifError(null);
|
||||
* // OK
|
||||
* assert.ifError(0);
|
||||
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0
|
||||
* assert.ifError('error');
|
||||
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'
|
||||
* assert.ifError(new Error());
|
||||
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error
|
||||
*
|
||||
* // Create some random error frames.
|
||||
* let err;
|
||||
* (function errorFrame() {
|
||||
* err = new Error('test error');
|
||||
* })();
|
||||
*
|
||||
* (function ifErrorFrame() {
|
||||
* assert.ifError(err);
|
||||
* })();
|
||||
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
|
||||
* // at ifErrorFrame
|
||||
* // at errorFrame
|
||||
* ```
|
||||
* @since v0.1.97
|
||||
*/
|
||||
function ifError(value: unknown): asserts value is null | undefined;
|
||||
/**
|
||||
* Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
|
||||
* calls the function and awaits the returned promise to complete. It will then
|
||||
* check that the promise is rejected.
|
||||
*
|
||||
* If `asyncFn` is a function and it throws an error synchronously,`assert.rejects()` will return a rejected `Promise` with that error. If the
|
||||
* function does not return a promise, `assert.rejects()` will return a rejected`Promise` with an `ERR_INVALID_RETURN_VALUE` error. In both cases the error
|
||||
* handler is skipped.
|
||||
*
|
||||
* Besides the async nature to await the completion behaves identically to {@link throws}.
|
||||
*
|
||||
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
||||
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
|
||||
* an object where each property will be tested for, or an instance of error where
|
||||
* each property will be tested for including the non-enumerable `message` and`name` properties.
|
||||
*
|
||||
* If specified, `message` will be the message provided by the `AssertionError` if the `asyncFn` fails to reject.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* await assert.rejects(
|
||||
* async () => {
|
||||
* throw new TypeError('Wrong value');
|
||||
* },
|
||||
* {
|
||||
* name: 'TypeError',
|
||||
* message: 'Wrong value',
|
||||
* },
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* await assert.rejects(
|
||||
* async () => {
|
||||
* throw new TypeError('Wrong value');
|
||||
* },
|
||||
* (err) => {
|
||||
* assert.strictEqual(err.name, 'TypeError');
|
||||
* assert.strictEqual(err.message, 'Wrong value');
|
||||
* return true;
|
||||
* },
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.rejects(
|
||||
* Promise.reject(new Error('Wrong value')),
|
||||
* Error,
|
||||
* ).then(() => {
|
||||
* // ...
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* `error` cannot be a string. If a string is provided as the second
|
||||
* argument, then `error` is assumed to be omitted and the string will be used for`message` instead. This can lead to easy-to-miss mistakes. Please read the
|
||||
* example in {@link throws} carefully if using a string as the second
|
||||
* argument gets considered.
|
||||
* @since v10.0.0
|
||||
*/
|
||||
function rejects(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
|
||||
function rejects(
|
||||
block: (() => Promise<unknown>) | Promise<unknown>,
|
||||
error: AssertPredicate,
|
||||
message?: string | Error,
|
||||
): Promise<void>;
|
||||
/**
|
||||
* Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
|
||||
* calls the function and awaits the returned promise to complete. It will then
|
||||
* check that the promise is not rejected.
|
||||
*
|
||||
* If `asyncFn` is a function and it throws an error synchronously,`assert.doesNotReject()` will return a rejected `Promise` with that error. If
|
||||
* the function does not return a promise, `assert.doesNotReject()` will return a
|
||||
* rejected `Promise` with an `ERR_INVALID_RETURN_VALUE` error. In both cases
|
||||
* the error handler is skipped.
|
||||
*
|
||||
* Using `assert.doesNotReject()` is actually not useful because there is little
|
||||
* benefit in catching a rejection and then rejecting it again. Instead, consider
|
||||
* adding a comment next to the specific code path that should not reject and keep
|
||||
* error messages as expressive as possible.
|
||||
*
|
||||
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
||||
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), or a validation
|
||||
* function. See {@link throws} for more details.
|
||||
*
|
||||
* Besides the async nature to await the completion behaves identically to {@link doesNotThrow}.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* await assert.doesNotReject(
|
||||
* async () => {
|
||||
* throw new TypeError('Wrong value');
|
||||
* },
|
||||
* SyntaxError,
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
|
||||
* .then(() => {
|
||||
* // ...
|
||||
* });
|
||||
* ```
|
||||
* @since v10.0.0
|
||||
*/
|
||||
function doesNotReject(
|
||||
block: (() => Promise<unknown>) | Promise<unknown>,
|
||||
message?: string | Error,
|
||||
): Promise<void>;
|
||||
function doesNotReject(
|
||||
block: (() => Promise<unknown>) | Promise<unknown>,
|
||||
error: AssertPredicate,
|
||||
message?: string | Error,
|
||||
): Promise<void>;
|
||||
/**
|
||||
* Expects the `string` input to match the regular expression.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.match('I will fail', /pass/);
|
||||
* // AssertionError [ERR_ASSERTION]: The input did not match the regular ...
|
||||
*
|
||||
* assert.match(123, /pass/);
|
||||
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
||||
*
|
||||
* assert.match('I will pass', /pass/);
|
||||
* // OK
|
||||
* ```
|
||||
*
|
||||
* If the values do not match, or if the `string` argument is of another type than`string`, an `AssertionError` is thrown with a `message` property set equal
|
||||
* to the value of the `message` parameter. If the `message` parameter is
|
||||
* undefined, a default error message is assigned. If the `message` parameter is an
|
||||
* instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
||||
* @since v13.6.0, v12.16.0
|
||||
*/
|
||||
function match(value: string, regExp: RegExp, message?: string | Error): void;
|
||||
/**
|
||||
* Expects the `string` input not to match the regular expression.
|
||||
*
|
||||
* ```js
|
||||
* import assert from 'node:assert/strict';
|
||||
*
|
||||
* assert.doesNotMatch('I will fail', /fail/);
|
||||
* // AssertionError [ERR_ASSERTION]: The input was expected to not match the ...
|
||||
*
|
||||
* assert.doesNotMatch(123, /pass/);
|
||||
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
||||
*
|
||||
* assert.doesNotMatch('I will pass', /different/);
|
||||
* // OK
|
||||
* ```
|
||||
*
|
||||
* If the values do match, or if the `string` argument is of another type than`string`, an `AssertionError` is thrown with a `message` property set equal
|
||||
* to the value of the `message` parameter. If the `message` parameter is
|
||||
* undefined, a default error message is assigned. If the `message` parameter is an
|
||||
* instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
||||
* @since v13.6.0, v12.16.0
|
||||
*/
|
||||
function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
|
||||
const strict:
|
||||
& Omit<
|
||||
typeof assert,
|
||||
| "equal"
|
||||
| "notEqual"
|
||||
| "deepEqual"
|
||||
| "notDeepEqual"
|
||||
| "ok"
|
||||
| "strictEqual"
|
||||
| "deepStrictEqual"
|
||||
| "ifError"
|
||||
| "strict"
|
||||
>
|
||||
& {
|
||||
(value: unknown, message?: string | Error): asserts value;
|
||||
equal: typeof strictEqual;
|
||||
notEqual: typeof notStrictEqual;
|
||||
deepEqual: typeof deepStrictEqual;
|
||||
notDeepEqual: typeof notDeepStrictEqual;
|
||||
// Mapped types and assertion functions are incompatible?
|
||||
// TS2775: Assertions require every name in the call target
|
||||
// to be declared with an explicit type annotation.
|
||||
ok: typeof ok;
|
||||
strictEqual: typeof strictEqual;
|
||||
deepStrictEqual: typeof deepStrictEqual;
|
||||
ifError: typeof ifError;
|
||||
strict: typeof strict;
|
||||
};
|
||||
}
|
||||
export = assert;
|
||||
}
|
||||
declare module "node:assert" {
|
||||
import assert = require("assert");
|
||||
export = assert;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
declare module "assert/strict" {
|
||||
import { strict } from "node:assert";
|
||||
export = strict;
|
||||
}
|
||||
declare module "node:assert/strict" {
|
||||
import { strict } from "node:assert";
|
||||
export = strict;
|
||||
}
|
@ -0,0 +1,539 @@
|
||||
/**
|
||||
* We strongly discourage the use of the `async_hooks` API.
|
||||
* Other APIs that can cover most of its use cases include:
|
||||
*
|
||||
* * `AsyncLocalStorage` tracks async context
|
||||
* * `process.getActiveResourcesInfo()` tracks active resources
|
||||
*
|
||||
* The `node:async_hooks` module provides an API to track asynchronous resources.
|
||||
* It can be accessed using:
|
||||
*
|
||||
* ```js
|
||||
* import async_hooks from 'node:async_hooks';
|
||||
* ```
|
||||
* @experimental
|
||||
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/async_hooks.js)
|
||||
*/
|
||||
declare module "async_hooks" {
|
||||
/**
|
||||
* ```js
|
||||
* import { executionAsyncId } from 'node:async_hooks';
|
||||
* import fs from 'node:fs';
|
||||
*
|
||||
* console.log(executionAsyncId()); // 1 - bootstrap
|
||||
* const path = '.';
|
||||
* fs.open(path, 'r', (err, fd) => {
|
||||
* console.log(executionAsyncId()); // 6 - open()
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* The ID returned from `executionAsyncId()` is related to execution timing, not
|
||||
* causality (which is covered by `triggerAsyncId()`):
|
||||
*
|
||||
* ```js
|
||||
* const server = net.createServer((conn) => {
|
||||
* // Returns the ID of the server, not of the new connection, because the
|
||||
* // callback runs in the execution scope of the server's MakeCallback().
|
||||
* async_hooks.executionAsyncId();
|
||||
*
|
||||
* }).listen(port, () => {
|
||||
* // Returns the ID of a TickObject (process.nextTick()) because all
|
||||
* // callbacks passed to .listen() are wrapped in a nextTick().
|
||||
* async_hooks.executionAsyncId();
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* Promise contexts may not get precise `executionAsyncIds` by default.
|
||||
* See the section on `promise execution tracking`.
|
||||
* @since v8.1.0
|
||||
* @return The `asyncId` of the current execution context. Useful to track when something calls.
|
||||
*/
|
||||
function executionAsyncId(): number;
|
||||
/**
|
||||
* Resource objects returned by `executionAsyncResource()` are most often internal
|
||||
* Node.js handle objects with undocumented APIs. Using any functions or properties
|
||||
* on the object is likely to crash your application and should be avoided.
|
||||
*
|
||||
* Using `executionAsyncResource()` in the top-level execution context will
|
||||
* return an empty object as there is no handle or request object to use,
|
||||
* but having an object representing the top-level can be helpful.
|
||||
*
|
||||
* ```js
|
||||
* import { open } from 'node:fs';
|
||||
* import { executionAsyncId, executionAsyncResource } from 'node:async_hooks';
|
||||
*
|
||||
* console.log(executionAsyncId(), executionAsyncResource()); // 1 {}
|
||||
* open(new URL(import.meta.url), 'r', (err, fd) => {
|
||||
* console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* This can be used to implement continuation local storage without the
|
||||
* use of a tracking `Map` to store the metadata:
|
||||
*
|
||||
* ```js
|
||||
* import { createServer } from 'node:http';
|
||||
* import {
|
||||
* executionAsyncId,
|
||||
* executionAsyncResource,
|
||||
* createHook,
|
||||
* } from 'async_hooks';
|
||||
* const sym = Symbol('state'); // Private symbol to avoid pollution
|
||||
*
|
||||
* createHook({
|
||||
* init(asyncId, type, triggerAsyncId, resource) {
|
||||
* const cr = executionAsyncResource();
|
||||
* if (cr) {
|
||||
* resource[sym] = cr[sym];
|
||||
* }
|
||||
* },
|
||||
* }).enable();
|
||||
*
|
||||
* const server = createServer((req, res) => {
|
||||
* executionAsyncResource()[sym] = { state: req.url };
|
||||
* setTimeout(function() {
|
||||
* res.end(JSON.stringify(executionAsyncResource()[sym]));
|
||||
* }, 100);
|
||||
* }).listen(3000);
|
||||
* ```
|
||||
* @since v13.9.0, v12.17.0
|
||||
* @return The resource representing the current execution. Useful to store data within the resource.
|
||||
*/
|
||||
function executionAsyncResource(): object;
|
||||
/**
|
||||
* ```js
|
||||
* const server = net.createServer((conn) => {
|
||||
* // The resource that caused (or triggered) this callback to be called
|
||||
* // was that of the new connection. Thus the return value of triggerAsyncId()
|
||||
* // is the asyncId of "conn".
|
||||
* async_hooks.triggerAsyncId();
|
||||
*
|
||||
* }).listen(port, () => {
|
||||
* // Even though all callbacks passed to .listen() are wrapped in a nextTick()
|
||||
* // the callback itself exists because the call to the server's .listen()
|
||||
* // was made. So the return value would be the ID of the server.
|
||||
* async_hooks.triggerAsyncId();
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* Promise contexts may not get valid `triggerAsyncId`s by default. See
|
||||
* the section on `promise execution tracking`.
|
||||
* @return The ID of the resource responsible for calling the callback that is currently being executed.
|
||||
*/
|
||||
function triggerAsyncId(): number;
|
||||
interface HookCallbacks {
|
||||
/**
|
||||
* Called when a class is constructed that has the possibility to emit an asynchronous event.
|
||||
* @param asyncId a unique ID for the async resource
|
||||
* @param type the type of the async resource
|
||||
* @param triggerAsyncId the unique ID of the async resource in whose execution context this async resource was created
|
||||
* @param resource reference to the resource representing the async operation, needs to be released during destroy
|
||||
*/
|
||||
init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
|
||||
/**
|
||||
* When an asynchronous operation is initiated or completes a callback is called to notify the user.
|
||||
* The before callback is called just before said callback is executed.
|
||||
* @param asyncId the unique identifier assigned to the resource about to execute the callback.
|
||||
*/
|
||||
before?(asyncId: number): void;
|
||||
/**
|
||||
* Called immediately after the callback specified in before is completed.
|
||||
* @param asyncId the unique identifier assigned to the resource which has executed the callback.
|
||||
*/
|
||||
after?(asyncId: number): void;
|
||||
/**
|
||||
* Called when a promise has resolve() called. This may not be in the same execution id
|
||||
* as the promise itself.
|
||||
* @param asyncId the unique id for the promise that was resolve()d.
|
||||
*/
|
||||
promiseResolve?(asyncId: number): void;
|
||||
/**
|
||||
* Called after the resource corresponding to asyncId is destroyed
|
||||
* @param asyncId a unique ID for the async resource
|
||||
*/
|
||||
destroy?(asyncId: number): void;
|
||||
}
|
||||
interface AsyncHook {
|
||||
/**
|
||||
* Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
|
||||
*/
|
||||
enable(): this;
|
||||
/**
|
||||
* Disable the callbacks for a given AsyncHook instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disabled it will not be called again until enabled.
|
||||
*/
|
||||
disable(): this;
|
||||
}
|
||||
/**
|
||||
* Registers functions to be called for different lifetime events of each async
|
||||
* operation.
|
||||
*
|
||||
* The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the
|
||||
* respective asynchronous event during a resource's lifetime.
|
||||
*
|
||||
* All callbacks are optional. For example, if only resource cleanup needs to
|
||||
* be tracked, then only the `destroy` callback needs to be passed. The
|
||||
* specifics of all functions that can be passed to `callbacks` is in the `Hook Callbacks` section.
|
||||
*
|
||||
* ```js
|
||||
* import { createHook } from 'node:async_hooks';
|
||||
*
|
||||
* const asyncHook = createHook({
|
||||
* init(asyncId, type, triggerAsyncId, resource) { },
|
||||
* destroy(asyncId) { },
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* The callbacks will be inherited via the prototype chain:
|
||||
*
|
||||
* ```js
|
||||
* class MyAsyncCallbacks {
|
||||
* init(asyncId, type, triggerAsyncId, resource) { }
|
||||
* destroy(asyncId) {}
|
||||
* }
|
||||
*
|
||||
* class MyAddedCallbacks extends MyAsyncCallbacks {
|
||||
* before(asyncId) { }
|
||||
* after(asyncId) { }
|
||||
* }
|
||||
*
|
||||
* const asyncHook = async_hooks.createHook(new MyAddedCallbacks());
|
||||
* ```
|
||||
*
|
||||
* Because promises are asynchronous resources whose lifecycle is tracked
|
||||
* via the async hooks mechanism, the `init()`, `before()`, `after()`, and`destroy()` callbacks _must not_ be async functions that return promises.
|
||||
* @since v8.1.0
|
||||
* @param callbacks The `Hook Callbacks` to register
|
||||
* @return Instance used for disabling and enabling hooks
|
||||
*/
|
||||
function createHook(callbacks: HookCallbacks): AsyncHook;
|
||||
interface AsyncResourceOptions {
|
||||
/**
|
||||
* The ID of the execution context that created this async event.
|
||||
* @default executionAsyncId()
|
||||
*/
|
||||
triggerAsyncId?: number | undefined;
|
||||
/**
|
||||
* Disables automatic `emitDestroy` when the object is garbage collected.
|
||||
* This usually does not need to be set (even if `emitDestroy` is called
|
||||
* manually), unless the resource's `asyncId` is retrieved and the
|
||||
* sensitive API's `emitDestroy` is called with it.
|
||||
* @default false
|
||||
*/
|
||||
requireManualDestroy?: boolean | undefined;
|
||||
}
|
||||
/**
|
||||
* The class `AsyncResource` is designed to be extended by the embedder's async
|
||||
* resources. Using this, users can easily trigger the lifetime events of their
|
||||
* own resources.
|
||||
*
|
||||
* The `init` hook will trigger when an `AsyncResource` is instantiated.
|
||||
*
|
||||
* The following is an overview of the `AsyncResource` API.
|
||||
*
|
||||
* ```js
|
||||
* import { AsyncResource, executionAsyncId } from 'node:async_hooks';
|
||||
*
|
||||
* // AsyncResource() is meant to be extended. Instantiating a
|
||||
* // new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
||||
* // async_hook.executionAsyncId() is used.
|
||||
* const asyncResource = new AsyncResource(
|
||||
* type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false },
|
||||
* );
|
||||
*
|
||||
* // Run a function in the execution context of the resource. This will
|
||||
* // * establish the context of the resource
|
||||
* // * trigger the AsyncHooks before callbacks
|
||||
* // * call the provided function `fn` with the supplied arguments
|
||||
* // * trigger the AsyncHooks after callbacks
|
||||
* // * restore the original execution context
|
||||
* asyncResource.runInAsyncScope(fn, thisArg, ...args);
|
||||
*
|
||||
* // Call AsyncHooks destroy callbacks.
|
||||
* asyncResource.emitDestroy();
|
||||
*
|
||||
* // Return the unique ID assigned to the AsyncResource instance.
|
||||
* asyncResource.asyncId();
|
||||
*
|
||||
* // Return the trigger ID for the AsyncResource instance.
|
||||
* asyncResource.triggerAsyncId();
|
||||
* ```
|
||||
*/
|
||||
class AsyncResource {
|
||||
/**
|
||||
* AsyncResource() is meant to be extended. Instantiating a
|
||||
* new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
||||
* async_hook.executionAsyncId() is used.
|
||||
* @param type The type of async event.
|
||||
* @param triggerAsyncId The ID of the execution context that created
|
||||
* this async event (default: `executionAsyncId()`), or an
|
||||
* AsyncResourceOptions object (since v9.3.0)
|
||||
*/
|
||||
constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions);
|
||||
/**
|
||||
* Binds the given function to the current execution context.
|
||||
* @since v14.8.0, v12.19.0
|
||||
* @param fn The function to bind to the current execution context.
|
||||
* @param type An optional name to associate with the underlying `AsyncResource`.
|
||||
*/
|
||||
static bind<Func extends (this: ThisArg, ...args: any[]) => any, ThisArg>(
|
||||
fn: Func,
|
||||
type?: string,
|
||||
thisArg?: ThisArg,
|
||||
): Func;
|
||||
/**
|
||||
* Binds the given function to execute to this `AsyncResource`'s scope.
|
||||
* @since v14.8.0, v12.19.0
|
||||
* @param fn The function to bind to the current `AsyncResource`.
|
||||
*/
|
||||
bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
||||
/**
|
||||
* Call the provided function with the provided arguments in the execution context
|
||||
* of the async resource. This will establish the context, trigger the AsyncHooks
|
||||
* before callbacks, call the function, trigger the AsyncHooks after callbacks, and
|
||||
* then restore the original execution context.
|
||||
* @since v9.6.0
|
||||
* @param fn The function to call in the execution context of this async resource.
|
||||
* @param thisArg The receiver to be used for the function call.
|
||||
* @param args Optional arguments to pass to the function.
|
||||
*/
|
||||
runInAsyncScope<This, Result>(
|
||||
fn: (this: This, ...args: any[]) => Result,
|
||||
thisArg?: This,
|
||||
...args: any[]
|
||||
): Result;
|
||||
/**
|
||||
* Call all `destroy` hooks. This should only ever be called once. An error will
|
||||
* be thrown if it is called more than once. This **must** be manually called. If
|
||||
* the resource is left to be collected by the GC then the `destroy` hooks will
|
||||
* never be called.
|
||||
* @return A reference to `asyncResource`.
|
||||
*/
|
||||
emitDestroy(): this;
|
||||
/**
|
||||
* @return The unique `asyncId` assigned to the resource.
|
||||
*/
|
||||
asyncId(): number;
|
||||
/**
|
||||
* @return The same `triggerAsyncId` that is passed to the `AsyncResource` constructor.
|
||||
*/
|
||||
triggerAsyncId(): number;
|
||||
}
|
||||
/**
|
||||
* This class creates stores that stay coherent through asynchronous operations.
|
||||
*
|
||||
* While you can create your own implementation on top of the `node:async_hooks`module, `AsyncLocalStorage` should be preferred as it is a performant and memory
|
||||
* safe implementation that involves significant optimizations that are non-obvious
|
||||
* to implement.
|
||||
*
|
||||
* The following example uses `AsyncLocalStorage` to build a simple logger
|
||||
* that assigns IDs to incoming HTTP requests and includes them in messages
|
||||
* logged within each request.
|
||||
*
|
||||
* ```js
|
||||
* import http from 'node:http';
|
||||
* import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
*
|
||||
* const asyncLocalStorage = new AsyncLocalStorage();
|
||||
*
|
||||
* function logWithId(msg) {
|
||||
* const id = asyncLocalStorage.getStore();
|
||||
* console.log(`${id !== undefined ? id : '-'}:`, msg);
|
||||
* }
|
||||
*
|
||||
* let idSeq = 0;
|
||||
* http.createServer((req, res) => {
|
||||
* asyncLocalStorage.run(idSeq++, () => {
|
||||
* logWithId('start');
|
||||
* // Imagine any chain of async operations here
|
||||
* setImmediate(() => {
|
||||
* logWithId('finish');
|
||||
* res.end();
|
||||
* });
|
||||
* });
|
||||
* }).listen(8080);
|
||||
*
|
||||
* http.get('http://localhost:8080');
|
||||
* http.get('http://localhost:8080');
|
||||
* // Prints:
|
||||
* // 0: start
|
||||
* // 1: start
|
||||
* // 0: finish
|
||||
* // 1: finish
|
||||
* ```
|
||||
*
|
||||
* Each instance of `AsyncLocalStorage` maintains an independent storage context.
|
||||
* Multiple instances can safely exist simultaneously without risk of interfering
|
||||
* with each other's data.
|
||||
* @since v13.10.0, v12.17.0
|
||||
*/
|
||||
class AsyncLocalStorage<T> {
|
||||
/**
|
||||
* Binds the given function to the current execution context.
|
||||
* @since v19.8.0
|
||||
* @experimental
|
||||
* @param fn The function to bind to the current execution context.
|
||||
* @return A new function that calls `fn` within the captured execution context.
|
||||
*/
|
||||
static bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
||||
/**
|
||||
* Captures the current execution context and returns a function that accepts a
|
||||
* function as an argument. Whenever the returned function is called, it
|
||||
* calls the function passed to it within the captured context.
|
||||
*
|
||||
* ```js
|
||||
* const asyncLocalStorage = new AsyncLocalStorage();
|
||||
* const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot());
|
||||
* const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore()));
|
||||
* console.log(result); // returns 123
|
||||
* ```
|
||||
*
|
||||
* AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple
|
||||
* async context tracking purposes, for example:
|
||||
*
|
||||
* ```js
|
||||
* class Foo {
|
||||
* #runInAsyncScope = AsyncLocalStorage.snapshot();
|
||||
*
|
||||
* get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); }
|
||||
* }
|
||||
*
|
||||
* const foo = asyncLocalStorage.run(123, () => new Foo());
|
||||
* console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123
|
||||
* ```
|
||||
* @since v19.8.0
|
||||
* @experimental
|
||||
* @return A new function with the signature `(fn: (...args) : R, ...args) : R`.
|
||||
*/
|
||||
static snapshot(): <R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R;
|
||||
/**
|
||||
* Disables the instance of `AsyncLocalStorage`. All subsequent calls
|
||||
* to `asyncLocalStorage.getStore()` will return `undefined` until`asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again.
|
||||
*
|
||||
* When calling `asyncLocalStorage.disable()`, all current contexts linked to the
|
||||
* instance will be exited.
|
||||
*
|
||||
* Calling `asyncLocalStorage.disable()` is required before the`asyncLocalStorage` can be garbage collected. This does not apply to stores
|
||||
* provided by the `asyncLocalStorage`, as those objects are garbage collected
|
||||
* along with the corresponding async resources.
|
||||
*
|
||||
* Use this method when the `asyncLocalStorage` is not in use anymore
|
||||
* in the current process.
|
||||
* @since v13.10.0, v12.17.0
|
||||
* @experimental
|
||||
*/
|
||||
disable(): void;
|
||||
/**
|
||||
* Returns the current store.
|
||||
* If called outside of an asynchronous context initialized by
|
||||
* calling `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()`, it
|
||||
* returns `undefined`.
|
||||
* @since v13.10.0, v12.17.0
|
||||
*/
|
||||
getStore(): T | undefined;
|
||||
/**
|
||||
* Runs a function synchronously within a context and returns its
|
||||
* return value. The store is not accessible outside of the callback function.
|
||||
* The store is accessible to any asynchronous operations created within the
|
||||
* callback.
|
||||
*
|
||||
* The optional `args` are passed to the callback function.
|
||||
*
|
||||
* If the callback function throws an error, the error is thrown by `run()` too.
|
||||
* The stacktrace is not impacted by this call and the context is exited.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```js
|
||||
* const store = { id: 2 };
|
||||
* try {
|
||||
* asyncLocalStorage.run(store, () => {
|
||||
* asyncLocalStorage.getStore(); // Returns the store object
|
||||
* setTimeout(() => {
|
||||
* asyncLocalStorage.getStore(); // Returns the store object
|
||||
* }, 200);
|
||||
* throw new Error();
|
||||
* });
|
||||
* } catch (e) {
|
||||
* asyncLocalStorage.getStore(); // Returns undefined
|
||||
* // The error will be caught here
|
||||
* }
|
||||
* ```
|
||||
* @since v13.10.0, v12.17.0
|
||||
*/
|
||||
run<R>(store: T, callback: () => R): R;
|
||||
run<R, TArgs extends any[]>(store: T, callback: (...args: TArgs) => R, ...args: TArgs): R;
|
||||
/**
|
||||
* Runs a function synchronously outside of a context and returns its
|
||||
* return value. The store is not accessible within the callback function or
|
||||
* the asynchronous operations created within the callback. Any `getStore()`call done within the callback function will always return `undefined`.
|
||||
*
|
||||
* The optional `args` are passed to the callback function.
|
||||
*
|
||||
* If the callback function throws an error, the error is thrown by `exit()` too.
|
||||
* The stacktrace is not impacted by this call and the context is re-entered.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```js
|
||||
* // Within a call to run
|
||||
* try {
|
||||
* asyncLocalStorage.getStore(); // Returns the store object or value
|
||||
* asyncLocalStorage.exit(() => {
|
||||
* asyncLocalStorage.getStore(); // Returns undefined
|
||||
* throw new Error();
|
||||
* });
|
||||
* } catch (e) {
|
||||
* asyncLocalStorage.getStore(); // Returns the same object or value
|
||||
* // The error will be caught here
|
||||
* }
|
||||
* ```
|
||||
* @since v13.10.0, v12.17.0
|
||||
* @experimental
|
||||
*/
|
||||
exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R;
|
||||
/**
|
||||
* Transitions into the context for the remainder of the current
|
||||
* synchronous execution and then persists the store through any following
|
||||
* asynchronous calls.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```js
|
||||
* const store = { id: 1 };
|
||||
* // Replaces previous store with the given store object
|
||||
* asyncLocalStorage.enterWith(store);
|
||||
* asyncLocalStorage.getStore(); // Returns the store object
|
||||
* someAsyncOperation(() => {
|
||||
* asyncLocalStorage.getStore(); // Returns the same object
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* This transition will continue for the _entire_ synchronous execution.
|
||||
* This means that if, for example, the context is entered within an event
|
||||
* handler subsequent event handlers will also run within that context unless
|
||||
* specifically bound to another context with an `AsyncResource`. That is why`run()` should be preferred over `enterWith()` unless there are strong reasons
|
||||
* to use the latter method.
|
||||
*
|
||||
* ```js
|
||||
* const store = { id: 1 };
|
||||
*
|
||||
* emitter.on('my-event', () => {
|
||||
* asyncLocalStorage.enterWith(store);
|
||||
* });
|
||||
* emitter.on('my-event', () => {
|
||||
* asyncLocalStorage.getStore(); // Returns the same object
|
||||
* });
|
||||
*
|
||||
* asyncLocalStorage.getStore(); // Returns undefined
|
||||
* emitter.emit('my-event');
|
||||
* asyncLocalStorage.getStore(); // Returns the same object
|
||||
* ```
|
||||
* @since v13.11.0, v12.17.0
|
||||
* @experimental
|
||||
*/
|
||||
enterWith(store: T): void;
|
||||
}
|
||||
}
|
||||
declare module "node:async_hooks" {
|
||||
export * from "async_hooks";
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,415 @@
|
||||
/**
|
||||
* The `node:console` module provides a simple debugging console that is similar to
|
||||
* the JavaScript console mechanism provided by web browsers.
|
||||
*
|
||||
* The module exports two specific components:
|
||||
*
|
||||
* * A `Console` class with methods such as `console.log()`, `console.error()`, and`console.warn()` that can be used to write to any Node.js stream.
|
||||
* * A global `console` instance configured to write to `process.stdout` and `process.stderr`. The global `console` can be used without calling`require('node:console')`.
|
||||
*
|
||||
* _**Warning**_: The global console object's methods are neither consistently
|
||||
* synchronous like the browser APIs they resemble, nor are they consistently
|
||||
* asynchronous like all other Node.js streams. See the `note on process I/O` for
|
||||
* more information.
|
||||
*
|
||||
* Example using the global `console`:
|
||||
*
|
||||
* ```js
|
||||
* console.log('hello world');
|
||||
* // Prints: hello world, to stdout
|
||||
* console.log('hello %s', 'world');
|
||||
* // Prints: hello world, to stdout
|
||||
* console.error(new Error('Whoops, something bad happened'));
|
||||
* // Prints error message and stack trace to stderr:
|
||||
* // Error: Whoops, something bad happened
|
||||
* // at [eval]:5:15
|
||||
* // at Script.runInThisContext (node:vm:132:18)
|
||||
* // at Object.runInThisContext (node:vm:309:38)
|
||||
* // at node:internal/process/execution:77:19
|
||||
* // at [eval]-wrapper:6:22
|
||||
* // at evalScript (node:internal/process/execution:76:60)
|
||||
* // at node:internal/main/eval_string:23:3
|
||||
*
|
||||
* const name = 'Will Robinson';
|
||||
* console.warn(`Danger ${name}! Danger!`);
|
||||
* // Prints: Danger Will Robinson! Danger!, to stderr
|
||||
* ```
|
||||
*
|
||||
* Example using the `Console` class:
|
||||
*
|
||||
* ```js
|
||||
* const out = getStreamSomehow();
|
||||
* const err = getStreamSomehow();
|
||||
* const myConsole = new console.Console(out, err);
|
||||
*
|
||||
* myConsole.log('hello world');
|
||||
* // Prints: hello world, to out
|
||||
* myConsole.log('hello %s', 'world');
|
||||
* // Prints: hello world, to out
|
||||
* myConsole.error(new Error('Whoops, something bad happened'));
|
||||
* // Prints: [Error: Whoops, something bad happened], to err
|
||||
*
|
||||
* const name = 'Will Robinson';
|
||||
* myConsole.warn(`Danger ${name}! Danger!`);
|
||||
* // Prints: Danger Will Robinson! Danger!, to err
|
||||
* ```
|
||||
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/console.js)
|
||||
*/
|
||||
declare module "console" {
|
||||
import console = require("node:console");
|
||||
export = console;
|
||||
}
|
||||
declare module "node:console" {
|
||||
import { InspectOptions } from "node:util";
|
||||
global {
|
||||
// This needs to be global to avoid TS2403 in case lib.dom.d.ts is present in the same build
|
||||
interface Console {
|
||||
Console: console.ConsoleConstructor;
|
||||
/**
|
||||
* `console.assert()` writes a message if `value` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) or omitted. It only
|
||||
* writes a message and does not otherwise affect execution. The output always
|
||||
* starts with `"Assertion failed"`. If provided, `message` is formatted using `util.format()`.
|
||||
*
|
||||
* If `value` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), nothing happens.
|
||||
*
|
||||
* ```js
|
||||
* console.assert(true, 'does nothing');
|
||||
*
|
||||
* console.assert(false, 'Whoops %s work', 'didn\'t');
|
||||
* // Assertion failed: Whoops didn't work
|
||||
*
|
||||
* console.assert();
|
||||
* // Assertion failed
|
||||
* ```
|
||||
* @since v0.1.101
|
||||
* @param value The value tested for being truthy.
|
||||
* @param message All arguments besides `value` are used as error message.
|
||||
*/
|
||||
assert(value: any, message?: string, ...optionalParams: any[]): void;
|
||||
/**
|
||||
* When `stdout` is a TTY, calling `console.clear()` will attempt to clear the
|
||||
* TTY. When `stdout` is not a TTY, this method does nothing.
|
||||
*
|
||||
* The specific operation of `console.clear()` can vary across operating systems
|
||||
* and terminal types. For most Linux operating systems, `console.clear()`operates similarly to the `clear` shell command. On Windows, `console.clear()`will clear only the output in the
|
||||
* current terminal viewport for the Node.js
|
||||
* binary.
|
||||
* @since v8.3.0
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Maintains an internal counter specific to `label` and outputs to `stdout` the
|
||||
* number of times `console.count()` has been called with the given `label`.
|
||||
*
|
||||
* ```js
|
||||
* > console.count()
|
||||
* default: 1
|
||||
* undefined
|
||||
* > console.count('default')
|
||||
* default: 2
|
||||
* undefined
|
||||
* > console.count('abc')
|
||||
* abc: 1
|
||||
* undefined
|
||||
* > console.count('xyz')
|
||||
* xyz: 1
|
||||
* undefined
|
||||
* > console.count('abc')
|
||||
* abc: 2
|
||||
* undefined
|
||||
* > console.count()
|
||||
* default: 3
|
||||
* undefined
|
||||
* >
|
||||
* ```
|
||||
* @since v8.3.0
|
||||
* @param [label='default'] The display label for the counter.
|
||||
*/
|
||||
count(label?: string): void;
|
||||
/**
|
||||
* Resets the internal counter specific to `label`.
|
||||
*
|
||||
* ```js
|
||||
* > console.count('abc');
|
||||
* abc: 1
|
||||
* undefined
|
||||
* > console.countReset('abc');
|
||||
* undefined
|
||||
* > console.count('abc');
|
||||
* abc: 1
|
||||
* undefined
|
||||
* >
|
||||
* ```
|
||||
* @since v8.3.0
|
||||
* @param [label='default'] The display label for the counter.
|
||||
*/
|
||||
countReset(label?: string): void;
|
||||
/**
|
||||
* The `console.debug()` function is an alias for {@link log}.
|
||||
* @since v8.0.0
|
||||
*/
|
||||
debug(message?: any, ...optionalParams: any[]): void;
|
||||
/**
|
||||
* Uses `util.inspect()` on `obj` and prints the resulting string to `stdout`.
|
||||
* This function bypasses any custom `inspect()` function defined on `obj`.
|
||||
* @since v0.1.101
|
||||
*/
|
||||
dir(obj: any, options?: InspectOptions): void;
|
||||
/**
|
||||
* This method calls `console.log()` passing it the arguments received.
|
||||
* This method does not produce any XML formatting.
|
||||
* @since v8.0.0
|
||||
*/
|
||||
dirxml(...data: any[]): void;
|
||||
/**
|
||||
* Prints to `stderr` with newline. Multiple arguments can be passed, with the
|
||||
* first used as the primary message and all additional used as substitution
|
||||
* values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to `util.format()`).
|
||||
*
|
||||
* ```js
|
||||
* const code = 5;
|
||||
* console.error('error #%d', code);
|
||||
* // Prints: error #5, to stderr
|
||||
* console.error('error', code);
|
||||
* // Prints: error 5, to stderr
|
||||
* ```
|
||||
*
|
||||
* If formatting elements (e.g. `%d`) are not found in the first string then `util.inspect()` is called on each argument and the resulting string
|
||||
* values are concatenated. See `util.format()` for more information.
|
||||
* @since v0.1.100
|
||||
*/
|
||||
error(message?: any, ...optionalParams: any[]): void;
|
||||
/**
|
||||
* Increases indentation of subsequent lines by spaces for `groupIndentation`length.
|
||||
*
|
||||
* If one or more `label`s are provided, those are printed first without the
|
||||
* additional indentation.
|
||||
* @since v8.5.0
|
||||
*/
|
||||
group(...label: any[]): void;
|
||||
/**
|
||||
* An alias for {@link group}.
|
||||
* @since v8.5.0
|
||||
*/
|
||||
groupCollapsed(...label: any[]): void;
|
||||
/**
|
||||
* Decreases indentation of subsequent lines by spaces for `groupIndentation`length.
|
||||
* @since v8.5.0
|
||||
*/
|
||||
groupEnd(): void;
|
||||
/**
|
||||
* The `console.info()` function is an alias for {@link log}.
|
||||
* @since v0.1.100
|
||||
*/
|
||||
info(message?: any, ...optionalParams: any[]): void;
|
||||
/**
|
||||
* Prints to `stdout` with newline. Multiple arguments can be passed, with the
|
||||
* first used as the primary message and all additional used as substitution
|
||||
* values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to `util.format()`).
|
||||
*
|
||||
* ```js
|
||||
* const count = 5;
|
||||
* console.log('count: %d', count);
|
||||
* // Prints: count: 5, to stdout
|
||||
* console.log('count:', count);
|
||||
* // Prints: count: 5, to stdout
|
||||
* ```
|
||||
*
|
||||
* See `util.format()` for more information.
|
||||
* @since v0.1.100
|
||||
*/
|
||||
log(message?: any, ...optionalParams: any[]): void;
|
||||
/**
|
||||
* Try to construct a table with the columns of the properties of `tabularData`(or use `properties`) and rows of `tabularData` and log it. Falls back to just
|
||||
* logging the argument if it can't be parsed as tabular.
|
||||
*
|
||||
* ```js
|
||||
* // These can't be parsed as tabular data
|
||||
* console.table(Symbol());
|
||||
* // Symbol()
|
||||
*
|
||||
* console.table(undefined);
|
||||
* // undefined
|
||||
*
|
||||
* console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }]);
|
||||
* // ┌─────────┬─────┬─────┐
|
||||
* // │ (index) │ a │ b │
|
||||
* // ├─────────┼─────┼─────┤
|
||||
* // │ 0 │ 1 │ 'Y' │
|
||||
* // │ 1 │ 'Z' │ 2 │
|
||||
* // └─────────┴─────┴─────┘
|
||||
*
|
||||
* console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ['a']);
|
||||
* // ┌─────────┬─────┐
|
||||
* // │ (index) │ a │
|
||||
* // ├─────────┼─────┤
|
||||
* // │ 0 │ 1 │
|
||||
* // │ 1 │ 'Z' │
|
||||
* // └─────────┴─────┘
|
||||
* ```
|
||||
* @since v10.0.0
|
||||
* @param properties Alternate properties for constructing the table.
|
||||
*/
|
||||
table(tabularData: any, properties?: readonly string[]): void;
|
||||
/**
|
||||
* Starts a timer that can be used to compute the duration of an operation. Timers
|
||||
* are identified by a unique `label`. Use the same `label` when calling {@link timeEnd} to stop the timer and output the elapsed time in
|
||||
* suitable time units to `stdout`. For example, if the elapsed
|
||||
* time is 3869ms, `console.timeEnd()` displays "3.869s".
|
||||
* @since v0.1.104
|
||||
* @param [label='default']
|
||||
*/
|
||||
time(label?: string): void;
|
||||
/**
|
||||
* Stops a timer that was previously started by calling {@link time} and
|
||||
* prints the result to `stdout`:
|
||||
*
|
||||
* ```js
|
||||
* console.time('bunch-of-stuff');
|
||||
* // Do a bunch of stuff.
|
||||
* console.timeEnd('bunch-of-stuff');
|
||||
* // Prints: bunch-of-stuff: 225.438ms
|
||||
* ```
|
||||
* @since v0.1.104
|
||||
* @param [label='default']
|
||||
*/
|
||||
timeEnd(label?: string): void;
|
||||
/**
|
||||
* For a timer that was previously started by calling {@link time}, prints
|
||||
* the elapsed time and other `data` arguments to `stdout`:
|
||||
*
|
||||
* ```js
|
||||
* console.time('process');
|
||||
* const value = expensiveProcess1(); // Returns 42
|
||||
* console.timeLog('process', value);
|
||||
* // Prints "process: 365.227ms 42".
|
||||
* doExpensiveProcess2(value);
|
||||
* console.timeEnd('process');
|
||||
* ```
|
||||
* @since v10.7.0
|
||||
* @param [label='default']
|
||||
*/
|
||||
timeLog(label?: string, ...data: any[]): void;
|
||||
/**
|
||||
* Prints to `stderr` the string `'Trace: '`, followed by the `util.format()` formatted message and stack trace to the current position in the code.
|
||||
*
|
||||
* ```js
|
||||
* console.trace('Show me');
|
||||
* // Prints: (stack trace will vary based on where trace is called)
|
||||
* // Trace: Show me
|
||||
* // at repl:2:9
|
||||
* // at REPLServer.defaultEval (repl.js:248:27)
|
||||
* // at bound (domain.js:287:14)
|
||||
* // at REPLServer.runBound [as eval] (domain.js:300:12)
|
||||
* // at REPLServer.<anonymous> (repl.js:412:12)
|
||||
* // at emitOne (events.js:82:20)
|
||||
* // at REPLServer.emit (events.js:169:7)
|
||||
* // at REPLServer.Interface._onLine (readline.js:210:10)
|
||||
* // at REPLServer.Interface._line (readline.js:549:8)
|
||||
* // at REPLServer.Interface._ttyWrite (readline.js:826:14)
|
||||
* ```
|
||||
* @since v0.1.104
|
||||
*/
|
||||
trace(message?: any, ...optionalParams: any[]): void;
|
||||
/**
|
||||
* The `console.warn()` function is an alias for {@link error}.
|
||||
* @since v0.1.100
|
||||
*/
|
||||
warn(message?: any, ...optionalParams: any[]): void;
|
||||
// --- Inspector mode only ---
|
||||
/**
|
||||
* This method does not display anything unless used in the inspector.
|
||||
* Starts a JavaScript CPU profile with an optional label.
|
||||
*/
|
||||
profile(label?: string): void;
|
||||
/**
|
||||
* This method does not display anything unless used in the inspector.
|
||||
* Stops the current JavaScript CPU profiling session if one has been started and prints the report to the Profiles panel of the inspector.
|
||||
*/
|
||||
profileEnd(label?: string): void;
|
||||
/**
|
||||
* This method does not display anything unless used in the inspector.
|
||||
* Adds an event with the label `label` to the Timeline panel of the inspector.
|
||||
*/
|
||||
timeStamp(label?: string): void;
|
||||
}
|
||||
/**
|
||||
* The `console` module provides a simple debugging console that is similar to the
|
||||
* JavaScript console mechanism provided by web browsers.
|
||||
*
|
||||
* The module exports two specific components:
|
||||
*
|
||||
* * A `Console` class with methods such as `console.log()`, `console.error()` and`console.warn()` that can be used to write to any Node.js stream.
|
||||
* * A global `console` instance configured to write to `process.stdout` and `process.stderr`. The global `console` can be used without calling`require('console')`.
|
||||
*
|
||||
* _**Warning**_: The global console object's methods are neither consistently
|
||||
* synchronous like the browser APIs they resemble, nor are they consistently
|
||||
* asynchronous like all other Node.js streams. See the `note on process I/O` for
|
||||
* more information.
|
||||
*
|
||||
* Example using the global `console`:
|
||||
*
|
||||
* ```js
|
||||
* console.log('hello world');
|
||||
* // Prints: hello world, to stdout
|
||||
* console.log('hello %s', 'world');
|
||||
* // Prints: hello world, to stdout
|
||||
* console.error(new Error('Whoops, something bad happened'));
|
||||
* // Prints error message and stack trace to stderr:
|
||||
* // Error: Whoops, something bad happened
|
||||
* // at [eval]:5:15
|
||||
* // at Script.runInThisContext (node:vm:132:18)
|
||||
* // at Object.runInThisContext (node:vm:309:38)
|
||||
* // at node:internal/process/execution:77:19
|
||||
* // at [eval]-wrapper:6:22
|
||||
* // at evalScript (node:internal/process/execution:76:60)
|
||||
* // at node:internal/main/eval_string:23:3
|
||||
*
|
||||
* const name = 'Will Robinson';
|
||||
* console.warn(`Danger ${name}! Danger!`);
|
||||
* // Prints: Danger Will Robinson! Danger!, to stderr
|
||||
* ```
|
||||
*
|
||||
* Example using the `Console` class:
|
||||
*
|
||||
* ```js
|
||||
* const out = getStreamSomehow();
|
||||
* const err = getStreamSomehow();
|
||||
* const myConsole = new console.Console(out, err);
|
||||
*
|
||||
* myConsole.log('hello world');
|
||||
* // Prints: hello world, to out
|
||||
* myConsole.log('hello %s', 'world');
|
||||
* // Prints: hello world, to out
|
||||
* myConsole.error(new Error('Whoops, something bad happened'));
|
||||
* // Prints: [Error: Whoops, something bad happened], to err
|
||||
*
|
||||
* const name = 'Will Robinson';
|
||||
* myConsole.warn(`Danger ${name}! Danger!`);
|
||||
* // Prints: Danger Will Robinson! Danger!, to err
|
||||
* ```
|
||||
* @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/console.js)
|
||||
*/
|
||||
namespace console {
|
||||
interface ConsoleConstructorOptions {
|
||||
stdout: NodeJS.WritableStream;
|
||||
stderr?: NodeJS.WritableStream | undefined;
|
||||
ignoreErrors?: boolean | undefined;
|
||||
colorMode?: boolean | "auto" | undefined;
|
||||
inspectOptions?: InspectOptions | undefined;
|
||||
/**
|
||||
* Set group indentation
|
||||
* @default 2
|
||||
*/
|
||||
groupIndentation?: number | undefined;
|
||||
}
|
||||
interface ConsoleConstructor {
|
||||
prototype: Console;
|
||||
new(stdout: NodeJS.WritableStream, stderr?: NodeJS.WritableStream, ignoreErrors?: boolean): Console;
|
||||
new(options: ConsoleConstructorOptions): Console;
|
||||
}
|
||||
}
|
||||
var console: Console;
|
||||
}
|
||||
export = globalThis.console;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/** @deprecated since v6.3.0 - use constants property exposed by the relevant module instead. */
|
||||
declare module "constants" {
|
||||
import { constants as osConstants, SignalConstants } from "node:os";
|
||||
import { constants as cryptoConstants } from "node:crypto";
|
||||
import { constants as fsConstants } from "node:fs";
|
||||
|
||||
const exp:
|
||||
& typeof osConstants.errno
|
||||
& typeof osConstants.priority
|
||||
& SignalConstants
|
||||
& typeof cryptoConstants
|
||||
& typeof fsConstants;
|
||||
export = exp;
|
||||
}
|
||||
|
||||
declare module "node:constants" {
|
||||
import constants = require("constants");
|
||||
export = constants;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue