diff --git a/README.md b/README.md index 80c17d4..5c5cea7 100644 --- a/README.md +++ b/README.md @@ -9,60 +9,69 @@ This is a part of [Node3D](https://github.com/node-3d) project. npm i addon-tools-raub ``` -This module contains numerous helpers for Node.js **NAPI** -addons and dependency packages. On this page, helper scripts -are described. For details on **addon-tools.hpp** and some +This module contains helpers for Node.js **NAPI** addons and dependency packages. +On this page, helper scripts are described. For details on **addon-tools.hpp** and some additional snippets follow the links below. -**Docs**: -* [include/addon-tools.hpp](doc/addon-tools.md) - - Macro shortcuts for C++ addons using **NAPI**. -* [Es5 Class Wrapping](doc/class-wrapping.md) - - An alternative, lightweight native class-defining mechanism for addons. -* [Snippets](doc/snippets.md) - - Some repetitive bits of code for addons. +## include/addon-tools.hpp + +Macro shortcuts for C++ addons using **NAPI**. +See [docs inside the folder](/include). + +Example of an addon method definition: + +``` +// hpp: +#include +DBG_EXPORT JS_METHOD(doSomething); +// cpp: +DBG_EXPORT JS_METHOD(doSomething) { NAPI_ENV; + LET_INT32_ARG(0, param0); + std::cout << "param0: " << param0 << std::endl; + RET_UNDEFINED; +} +``` ## index.js -> NOTE: peer dependency `node-addon-api` is required for this helper. - Main exports for cross-platform addon configuration. -See [TypeScript definitions](/index.d.ts) with comments. +See the [TypeScript definitions](/index.d.ts) with comments. +> NOTE: the peer dependency `node-addon-api` is used by this helper. -## download.js +Example for an ADDON's **index.js**: -Downloads a file into the memory, **HTTP** or **HTTPS**. -See [TypeScript definitions](/download.d.ts) with comments. +``` + const { bin } = require('addon-tools-raub'); + const core = require(`./${bin}/ADDON`); // uses the platform-specific ADDON.node +``` +Example for **binding.gyp**: -## cpbin.js - -Downloads a file into the memory, **HTTP** or **HTTPS**. -See [TypeScript definitions](/cpbin.d.ts) with comments. - - -## install.js - -> NOTE: peer dependency `adm-zip` is required for this helper. - -Downloads and unzips the platform specific binary for the calling package. -See [TypeScript definitions](/install.d.ts) with comments. - - -## writable-buffer.js - -A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams) -stream buffer. -See [TypeScript definitions](/writable-buffer.d.ts) with comments. +``` + 'include_dirs': [ + ' Promise; - * export default cpbin; - * ``` - * It is useful for development builds. Use it in your **src/package.json**: - * ``` - * "scripts": { - * * "build": "node-gyp rebuild && node -e \"require('addon-tools-raub/cpbin')('ADDON')\"" - * }, - * ``` - * Here ADDON should be replaced with the name of your addon, without `.node` extension. - */ - const cpbin: (name: string) => Promise; - export = cpbin; -} diff --git a/download.d.ts b/download.d.ts deleted file mode 100644 index 8f6c31d..0000000 --- a/download.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -declare module "addon-tools-raub/download" { - /** - * Download to memory - * Accepts an **URL**, and returns an in-memory file Buffer, - * when the file is loaded. Use for small files, as the whole - * file will be loaded into memory at once. - * - * ``` - * download(srcUrl).then(data => useData(data), err => emit('error', err)); - * ``` - * or - * ``` - * const data = await download(srcUrl); - * useData(data); - * ``` - */ - const download: (url: string) => Promise; - export = download; -} diff --git a/doc/addon-tools.md b/include/README.md similarity index 100% rename from doc/addon-tools.md rename to include/README.md diff --git a/doc/class-wrapping.md b/include/class-wrapping.md similarity index 100% rename from doc/class-wrapping.md rename to include/class-wrapping.md diff --git a/include/index.js b/include/index.js new file mode 100644 index 0000000..1deb7a0 --- /dev/null +++ b/include/index.js @@ -0,0 +1,51 @@ +'use strict'; + +let napi = null; +try { + napi = require('node-addon-api'); +} catch (ex) { + // do nothing +} + +const nameWindows = 'windows'; +const platformAndArch = `${process.platform}-${process.arch}`; + +const platformNames = { + 'win32-x64': nameWindows, + 'linux-x64': 'linux', + 'darwin-x64': 'osx', + 'linux-arm64': 'aarch64', +}; + +const platformName = platformNames[platformAndArch] || platformAndArch; + +const isWindows = platformName === nameWindows; + +const rootPath = __dirname.replace(/\\/g, '/'); + + +const napiInclude = napi ? napi.include_dir.replace(/\\/g, '/') : ''; +const thisInclude = `${rootPath}/include`; +const includePath = `${napiInclude} ${thisInclude}`; + + +const paths = (dir) => { + dir = dir.replace(/\\/g, '/'); + + const bin = `${dir}/bin-${platformName}`; + const include = `${dir}/include`; + + if (isWindows) { + process.env.path = `${bin};${process.env.path ? `${process.env.path}` : ''}`; + } + + return { bin, include }; +}; + + +module.exports = { + paths, + bin: `bin-${platformName}`, + platform: platformName, + include: includePath, +}; diff --git a/test/index.test.js b/include/index.test.js similarity index 95% rename from test/index.test.js rename to include/index.test.js index 64b6bfc..d6e3385 100644 --- a/test/index.test.js +++ b/include/index.test.js @@ -1,6 +1,6 @@ 'use strict'; -const tools = require('..'); +const tools = require('.'); describe('index.js', () => { diff --git a/doc/snippets.md b/include/snippets.md similarity index 100% rename from doc/snippets.md rename to include/snippets.md diff --git a/index.js b/index.js index 1deb7a0..3069b99 100644 --- a/index.js +++ b/index.js @@ -1,51 +1,3 @@ 'use strict'; -let napi = null; -try { - napi = require('node-addon-api'); -} catch (ex) { - // do nothing -} - -const nameWindows = 'windows'; -const platformAndArch = `${process.platform}-${process.arch}`; - -const platformNames = { - 'win32-x64': nameWindows, - 'linux-x64': 'linux', - 'darwin-x64': 'osx', - 'linux-arm64': 'aarch64', -}; - -const platformName = platformNames[platformAndArch] || platformAndArch; - -const isWindows = platformName === nameWindows; - -const rootPath = __dirname.replace(/\\/g, '/'); - - -const napiInclude = napi ? napi.include_dir.replace(/\\/g, '/') : ''; -const thisInclude = `${rootPath}/include`; -const includePath = `${napiInclude} ${thisInclude}`; - - -const paths = (dir) => { - dir = dir.replace(/\\/g, '/'); - - const bin = `${dir}/bin-${platformName}`; - const include = `${dir}/include`; - - if (isWindows) { - process.env.path = `${bin};${process.env.path ? `${process.env.path}` : ''}`; - } - - return { bin, include }; -}; - - -module.exports = { - paths, - bin: `bin-${platformName}`, - platform: platformName, - include: includePath, -}; +module.exports = require('./index'); diff --git a/install.d.ts b/install.d.ts deleted file mode 100644 index e0b9136..0000000 --- a/install.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -declare module "addon-tools-raub/install" { - /** - * Install binaries - * Downloads and unzips the platform specific binary for the calling package. - * To use it, create a new script for your package, which may as well be named - * **install.js**, with the following content: - * ``` - * 'use strict'; - * const install = require('addon-tools-raub/install'); - * const prefix = 'https://github.com/USER/ADDON-NAME/releases/download'; - * const tag = 'v1.0.0'; - * install(`${prefix}/${tag}`); - * ``` - * * `prefix` - the constant base part of the download url. - * * `tag` - the version-dependent part of the url. - * ``` - * "scripts": { - * "postinstall": "node install" - * }, - * ``` - */ - const install: (folder: string) => void; - export = install; -} diff --git a/package-lock.json b/package-lock.json index 6f8ed42..baa039b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,16 @@ { "name": "addon-tools-raub", - "version": "6.3.0", + "version": "7.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "addon-tools-raub", - "version": "6.3.0", + "version": "7.0.0", "license": "MIT", "devDependencies": { - "adm-zip": "^0.5.10", - "eslint": "^8.30.0", - "eslint-plugin-jest": "^27.1.7", + "eslint": "^8.31.0", + "eslint-plugin-jest": "^27.2.0", "eslint-plugin-node": "^11.1.0", "jest": "^29.3.1", "node-addon-api": "^5.0.0", @@ -22,13 +21,9 @@ "npm": ">=8.19.2" }, "peerDependencies": { - "adm-zip": "^0.5.10", "node-addon-api": "^5.0.0" }, "peerDependenciesMeta": { - "adm-zip": { - "optional": true - }, "node-addon-api": { "optional": true } @@ -1314,13 +1309,13 @@ "dev": true }, "node_modules/@typescript-eslint/scope-manager": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.47.1.tgz", - "integrity": "sha512-9hsFDsgUwrdOoW1D97Ewog7DYSHaq4WKuNs0LHF9RiCmqB0Z+XRR4Pf7u7u9z/8CciHuJ6yxNws1XznI3ddjEw==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.48.0.tgz", + "integrity": "sha512-0AA4LviDtVtZqlyUQnZMVHydDATpD9SAX/RC5qh6cBd3xmyWvmXYF+WT1oOmxkeMnWDlUVTwdODeucUnjz3gow==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.47.1", - "@typescript-eslint/visitor-keys": "5.47.1" + "@typescript-eslint/types": "5.48.0", + "@typescript-eslint/visitor-keys": "5.48.0" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -1331,9 +1326,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.47.1.tgz", - "integrity": "sha512-CmALY9YWXEpwuu6377ybJBZdtSAnzXLSQcxLSqSQSbC7VfpMu/HLVdrnVJj7ycI138EHqocW02LPJErE35cE9A==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.48.0.tgz", + "integrity": "sha512-UTe67B0Ypius0fnEE518NB2N8gGutIlTojeTg4nt0GQvikReVkurqxd2LvYa9q9M5MQ6rtpNyWTBxdscw40Xhw==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -1344,13 +1339,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.47.1.tgz", - "integrity": "sha512-4+ZhFSuISAvRi2xUszEj0xXbNTHceV9GbH9S8oAD2a/F9SW57aJNQVOCxG8GPfSWH/X4eOPdMEU2jYVuWKEpWA==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.48.0.tgz", + "integrity": "sha512-7pjd94vvIjI1zTz6aq/5wwE/YrfIyEPLtGJmRfyNR9NYIW+rOvzzUv3Cmq2hRKpvt6e9vpvPUQ7puzX7VSmsEw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.47.1", - "@typescript-eslint/visitor-keys": "5.47.1", + "@typescript-eslint/types": "5.48.0", + "@typescript-eslint/visitor-keys": "5.48.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -1371,16 +1366,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.47.1.tgz", - "integrity": "sha512-l90SdwqfmkuIVaREZ2ykEfCezepCLxzWMo5gVfcJsJCaT4jHT+QjgSkYhs5BMQmWqE9k3AtIfk4g211z/sTMVw==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.48.0.tgz", + "integrity": "sha512-x2jrMcPaMfsHRRIkL+x96++xdzvrdBCnYRd5QiW5Wgo1OB4kDYPbC1XjWP/TNqlfK93K/lUL92erq5zPLgFScQ==", "dev": true, "dependencies": { "@types/json-schema": "^7.0.9", "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.47.1", - "@typescript-eslint/types": "5.47.1", - "@typescript-eslint/typescript-estree": "5.47.1", + "@typescript-eslint/scope-manager": "5.48.0", + "@typescript-eslint/types": "5.48.0", + "@typescript-eslint/typescript-estree": "5.48.0", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0", "semver": "^7.3.7" @@ -1419,12 +1414,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.47.1.tgz", - "integrity": "sha512-rF3pmut2JCCjh6BLRhNKdYjULMb1brvoaiWDlHfLNVgmnZ0sBVJrs3SyaKE1XoDDnJuAx/hDQryHYmPUuNq0ig==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.48.0.tgz", + "integrity": "sha512-5motVPz5EgxQ0bHjut3chzBkJ3Z3sheYVcSwS5BpHZpLqSptSmELNtGixmgj65+rIfhvtQTz5i9OP2vtzdDH7Q==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.47.1", + "@typescript-eslint/types": "5.48.0", "eslint-visitor-keys": "^3.3.0" }, "engines": { @@ -1456,15 +1451,6 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, - "node_modules/adm-zip": { - "version": "0.5.10", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.10.tgz", - "integrity": "sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==", - "dev": true, - "engines": { - "node": ">=6.0" - } - }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -5698,29 +5684,29 @@ "dev": true }, "@typescript-eslint/scope-manager": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.47.1.tgz", - "integrity": "sha512-9hsFDsgUwrdOoW1D97Ewog7DYSHaq4WKuNs0LHF9RiCmqB0Z+XRR4Pf7u7u9z/8CciHuJ6yxNws1XznI3ddjEw==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.48.0.tgz", + "integrity": "sha512-0AA4LviDtVtZqlyUQnZMVHydDATpD9SAX/RC5qh6cBd3xmyWvmXYF+WT1oOmxkeMnWDlUVTwdODeucUnjz3gow==", "dev": true, "requires": { - "@typescript-eslint/types": "5.47.1", - "@typescript-eslint/visitor-keys": "5.47.1" + "@typescript-eslint/types": "5.48.0", + "@typescript-eslint/visitor-keys": "5.48.0" } }, "@typescript-eslint/types": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.47.1.tgz", - "integrity": "sha512-CmALY9YWXEpwuu6377ybJBZdtSAnzXLSQcxLSqSQSbC7VfpMu/HLVdrnVJj7ycI138EHqocW02LPJErE35cE9A==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.48.0.tgz", + "integrity": "sha512-UTe67B0Ypius0fnEE518NB2N8gGutIlTojeTg4nt0GQvikReVkurqxd2LvYa9q9M5MQ6rtpNyWTBxdscw40Xhw==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.47.1.tgz", - "integrity": "sha512-4+ZhFSuISAvRi2xUszEj0xXbNTHceV9GbH9S8oAD2a/F9SW57aJNQVOCxG8GPfSWH/X4eOPdMEU2jYVuWKEpWA==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.48.0.tgz", + "integrity": "sha512-7pjd94vvIjI1zTz6aq/5wwE/YrfIyEPLtGJmRfyNR9NYIW+rOvzzUv3Cmq2hRKpvt6e9vpvPUQ7puzX7VSmsEw==", "dev": true, "requires": { - "@typescript-eslint/types": "5.47.1", - "@typescript-eslint/visitor-keys": "5.47.1", + "@typescript-eslint/types": "5.48.0", + "@typescript-eslint/visitor-keys": "5.48.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -5729,16 +5715,16 @@ } }, "@typescript-eslint/utils": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.47.1.tgz", - "integrity": "sha512-l90SdwqfmkuIVaREZ2ykEfCezepCLxzWMo5gVfcJsJCaT4jHT+QjgSkYhs5BMQmWqE9k3AtIfk4g211z/sTMVw==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.48.0.tgz", + "integrity": "sha512-x2jrMcPaMfsHRRIkL+x96++xdzvrdBCnYRd5QiW5Wgo1OB4kDYPbC1XjWP/TNqlfK93K/lUL92erq5zPLgFScQ==", "dev": true, "requires": { "@types/json-schema": "^7.0.9", "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.47.1", - "@typescript-eslint/types": "5.47.1", - "@typescript-eslint/typescript-estree": "5.47.1", + "@typescript-eslint/scope-manager": "5.48.0", + "@typescript-eslint/types": "5.48.0", + "@typescript-eslint/typescript-estree": "5.48.0", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0", "semver": "^7.3.7" @@ -5763,12 +5749,12 @@ } }, "@typescript-eslint/visitor-keys": { - "version": "5.47.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.47.1.tgz", - "integrity": "sha512-rF3pmut2JCCjh6BLRhNKdYjULMb1brvoaiWDlHfLNVgmnZ0sBVJrs3SyaKE1XoDDnJuAx/hDQryHYmPUuNq0ig==", + "version": "5.48.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.48.0.tgz", + "integrity": "sha512-5motVPz5EgxQ0bHjut3chzBkJ3Z3sheYVcSwS5BpHZpLqSptSmELNtGixmgj65+rIfhvtQTz5i9OP2vtzdDH7Q==", "dev": true, "requires": { - "@typescript-eslint/types": "5.47.1", + "@typescript-eslint/types": "5.48.0", "eslint-visitor-keys": "^3.3.0" } }, @@ -5785,12 +5771,6 @@ "dev": true, "requires": {} }, - "adm-zip": { - "version": "0.5.10", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.10.tgz", - "integrity": "sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==", - "dev": true - }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", diff --git a/package.json b/package.json index b1c5eb9..a353f08 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "Luis Blanco ", "name": "addon-tools-raub", - "version": "6.3.0", + "version": "7.0.0", "description": "Helpers for Node.js addons and dependency packages", "license": "MIT", "main": "index.js", @@ -19,18 +19,11 @@ ], "files": [ "include", - "cpbin.js", - "cpbin.d.ts", - "download.js", - "download.d.ts", - "index.js", - "index.d.ts", - "install.js", - "install.d.ts", "utils.js", "utils.d.ts", - "writable-buffer.js", - "writable-buffer.d.ts", + "index.js", + "index.d.ts", + "utils", "LICENSE", "package.json", "README.md" @@ -41,44 +34,25 @@ }, "scripts": { "eslint": "eslint .", - "test": "jest --coverage=false --watch", - "test-ci": "jest --ci --runInBand --coverage=false --forceExit --detectOpenHandles", - "test-coverage": "rm -rf doc/jest && jest --coverage --silent", - "test-build": "cd test && node-gyp rebuild && cd .." - }, - "jest": { - "moduleFileExtensions": [ - "js" - ], - "testMatch": [ - "**/*.test.js" - ], - "coverageDirectory": "doc/jest", - "coverageReporters": [ - "lcov" - ], - "collectCoverageFrom": [ - "**/*.js", - "!**/*.test.js" - ] + "test": "jest --coverage=false --watch --config=conf/jest.json", + "test-ci": "jest --ci --runInBand --coverage=false --forceExit --detectOpenHandles --config=conf/jest.json", + "test-coverage": "rm -rf doc/jest && jest --coverage --silent --config=conf/jest.json", + "test-build": "cd test-addon && node-gyp rebuild -j max --silent && cd .." }, "repository": { "type": "git", "url": "https://github.com/node-3d/addon-tools-raub.git" }, "peerDependencies": { - "adm-zip": "^0.5.10", "node-addon-api": "^5.0.0" }, "peerDependenciesMeta": { - "adm-zip": { "optional": true }, "node-addon-api": { "optional": true } }, "devDependencies": { - "adm-zip": "^0.5.10", - "eslint-plugin-jest": "^27.1.7", + "eslint-plugin-jest": "^27.2.0", "eslint-plugin-node": "^11.1.0", - "eslint": "^8.30.0", + "eslint": "^8.31.0", "jest": "^29.3.1", "node-addon-api": "^5.0.0", "typescript": "^4.9.4" diff --git a/test/binding.gyp b/test-addon/binding.gyp similarity index 100% rename from test/binding.gyp rename to test-addon/binding.gyp diff --git a/test-addon/build/Release/obj/test/test.node.recipe b/test-addon/build/Release/obj/test/test.node.recipe new file mode 100644 index 0000000..189694d --- /dev/null +++ b/test-addon/build/Release/obj/test/test.node.recipe @@ -0,0 +1,11 @@ + + + + + C:\_projects\addon-tools-raub\test\build\Release\test.node + + + + + + \ No newline at end of file diff --git a/test-addon/build/Release/obj/test/test.obj b/test-addon/build/Release/obj/test/test.obj new file mode 100644 index 0000000..e1239b9 Binary files /dev/null and b/test-addon/build/Release/obj/test/test.obj differ diff --git a/test-addon/build/Release/obj/test/test.tlog/CL.command.1.tlog b/test-addon/build/Release/obj/test/test.tlog/CL.command.1.tlog new file mode 100644 index 0000000..2f6a89d Binary files /dev/null and b/test-addon/build/Release/obj/test/test.tlog/CL.command.1.tlog differ diff --git a/test-addon/build/Release/obj/test/test.tlog/CL.read.1.tlog b/test-addon/build/Release/obj/test/test.tlog/CL.read.1.tlog new file mode 100644 index 0000000..eb8a726 Binary files /dev/null and b/test-addon/build/Release/obj/test/test.tlog/CL.read.1.tlog differ diff --git a/test-addon/build/Release/obj/test/test.tlog/CL.write.1.tlog b/test-addon/build/Release/obj/test/test.tlog/CL.write.1.tlog new file mode 100644 index 0000000..d02062b Binary files /dev/null and b/test-addon/build/Release/obj/test/test.tlog/CL.write.1.tlog differ diff --git a/test-addon/build/Release/obj/test/test.tlog/link.command.1.tlog b/test-addon/build/Release/obj/test/test.tlog/link.command.1.tlog new file mode 100644 index 0000000..8c767ab Binary files /dev/null and b/test-addon/build/Release/obj/test/test.tlog/link.command.1.tlog differ diff --git a/test-addon/build/Release/obj/test/test.tlog/link.read.1.tlog b/test-addon/build/Release/obj/test/test.tlog/link.read.1.tlog new file mode 100644 index 0000000..c9d88d2 Binary files /dev/null and b/test-addon/build/Release/obj/test/test.tlog/link.read.1.tlog differ diff --git a/test-addon/build/Release/obj/test/test.tlog/link.write.1.tlog b/test-addon/build/Release/obj/test/test.tlog/link.write.1.tlog new file mode 100644 index 0000000..d14a285 Binary files /dev/null and b/test-addon/build/Release/obj/test/test.tlog/link.write.1.tlog differ diff --git a/test-addon/build/Release/obj/test/test.tlog/test.lastbuildstate b/test-addon/build/Release/obj/test/test.tlog/test.lastbuildstate new file mode 100644 index 0000000..f5f7862 --- /dev/null +++ b/test-addon/build/Release/obj/test/test.tlog/test.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v142:VCToolArchitecture=Native64Bit:VCToolsVersion=14.28.29910:TargetPlatformVersion=10.0.19041.0: +Release|x64|C:\_projects\addon-tools-raub\test\build\| diff --git a/test-addon/build/Release/obj/test/win_delay_load_hook.obj b/test-addon/build/Release/obj/test/win_delay_load_hook.obj new file mode 100644 index 0000000..ed5fe02 Binary files /dev/null and b/test-addon/build/Release/obj/test/win_delay_load_hook.obj differ diff --git a/test-addon/build/Release/test.node b/test-addon/build/Release/test.node new file mode 100644 index 0000000..f43da94 Binary files /dev/null and b/test-addon/build/Release/test.node differ diff --git a/test-addon/build/Release/test.pdb b/test-addon/build/Release/test.pdb new file mode 100644 index 0000000..b620a74 Binary files /dev/null and b/test-addon/build/Release/test.pdb differ diff --git a/test-addon/build/binding.sln b/test-addon/build/binding.sln new file mode 100644 index 0000000..debc5b2 --- /dev/null +++ b/test-addon/build/binding.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2015 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcxproj", "{CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Release|x64 = Release|x64 + Debug|x64 = Debug|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}.Release|x64.ActiveCfg = Release|x64 + {CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}.Release|x64.Build.0 = Release|x64 + {CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}.Debug|x64.ActiveCfg = Debug|x64 + {CA6D0C46-51F8-CCC5-FA71-4D2E9A260624}.Debug|x64.Build.0 = Debug|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/test-addon/build/config.gypi b/test-addon/build/config.gypi new file mode 100644 index 0000000..f691f33 --- /dev/null +++ b/test-addon/build/config.gypi @@ -0,0 +1,397 @@ +# Do not edit. File was generated by node-gyp's "configure" step +{ + "target_defaults": { + "cflags": [], + "default_configuration": "Release", + "defines": [], + "include_dirs": [], + "libraries": [], + "msbuild_toolset": "v142", + "msvs_windows_target_platform_version": "10.0.19041.0" + }, + "variables": { + "asan": 0, + "coverage": "false", + "dcheck_always_on": 0, + "debug_nghttp2": "false", + "debug_node": "false", + "enable_lto": "false", + "enable_pgo_generate": "false", + "enable_pgo_use": "false", + "error_on_warn": "false", + "force_dynamic_crt": 0, + "host_arch": "x64", + "icu_data_in": "..\\..\\deps\\icu-tmp\\icudt71l.dat", + "icu_endianness": "l", + "icu_gyp_path": "tools/icu/icu-generic.gyp", + "icu_path": "deps/icu-small", + "icu_small": "false", + "icu_ver_major": "71", + "is_debug": 0, + "libdir": "lib", + "llvm_version": "0.0", + "napi_build_version": "8", + "nasm_version": "2.15", + "node_byteorder": "little", + "node_debug_lib": "false", + "node_enable_d8": "false", + "node_fipsinstall": "false", + "node_install_corepack": "true", + "node_install_npm": "true", + "node_library_files": [ + "lib/_http_agent.js", + "lib/_http_client.js", + "lib/_http_common.js", + "lib/_http_incoming.js", + "lib/_http_outgoing.js", + "lib/_http_server.js", + "lib/_stream_duplex.js", + "lib/_stream_passthrough.js", + "lib/_stream_readable.js", + "lib/_stream_transform.js", + "lib/_stream_wrap.js", + "lib/_stream_writable.js", + "lib/_tls_common.js", + "lib/_tls_wrap.js", + "lib/assert.js", + "lib/assert/strict.js", + "lib/async_hooks.js", + "lib/buffer.js", + "lib/child_process.js", + "lib/cluster.js", + "lib/console.js", + "lib/constants.js", + "lib/crypto.js", + "lib/dgram.js", + "lib/diagnostics_channel.js", + "lib/dns.js", + "lib/dns/promises.js", + "lib/domain.js", + "lib/events.js", + "lib/fs.js", + "lib/fs/promises.js", + "lib/http.js", + "lib/http2.js", + "lib/https.js", + "lib/inspector.js", + "lib/internal/abort_controller.js", + "lib/internal/assert.js", + "lib/internal/assert/assertion_error.js", + "lib/internal/assert/calltracker.js", + "lib/internal/assert/snapshot.js", + "lib/internal/async_hooks.js", + "lib/internal/blob.js", + "lib/internal/blocklist.js", + "lib/internal/bootstrap/browser.js", + "lib/internal/bootstrap/loaders.js", + "lib/internal/bootstrap/node.js", + "lib/internal/bootstrap/switches/does_not_own_process_state.js", + "lib/internal/bootstrap/switches/does_own_process_state.js", + "lib/internal/bootstrap/switches/is_main_thread.js", + "lib/internal/bootstrap/switches/is_not_main_thread.js", + "lib/internal/buffer.js", + "lib/internal/child_process.js", + "lib/internal/child_process/serialization.js", + "lib/internal/cli_table.js", + "lib/internal/cluster/child.js", + "lib/internal/cluster/primary.js", + "lib/internal/cluster/round_robin_handle.js", + "lib/internal/cluster/shared_handle.js", + "lib/internal/cluster/utils.js", + "lib/internal/cluster/worker.js", + "lib/internal/console/constructor.js", + "lib/internal/console/global.js", + "lib/internal/constants.js", + "lib/internal/crypto/aes.js", + "lib/internal/crypto/certificate.js", + "lib/internal/crypto/cfrg.js", + "lib/internal/crypto/cipher.js", + "lib/internal/crypto/diffiehellman.js", + "lib/internal/crypto/ec.js", + "lib/internal/crypto/hash.js", + "lib/internal/crypto/hashnames.js", + "lib/internal/crypto/hkdf.js", + "lib/internal/crypto/keygen.js", + "lib/internal/crypto/keys.js", + "lib/internal/crypto/mac.js", + "lib/internal/crypto/pbkdf2.js", + "lib/internal/crypto/random.js", + "lib/internal/crypto/rsa.js", + "lib/internal/crypto/scrypt.js", + "lib/internal/crypto/sig.js", + "lib/internal/crypto/util.js", + "lib/internal/crypto/webcrypto.js", + "lib/internal/crypto/x509.js", + "lib/internal/debugger/inspect.js", + "lib/internal/debugger/inspect_client.js", + "lib/internal/debugger/inspect_repl.js", + "lib/internal/dgram.js", + "lib/internal/dns/callback_resolver.js", + "lib/internal/dns/promises.js", + "lib/internal/dns/utils.js", + "lib/internal/dtrace.js", + "lib/internal/encoding.js", + "lib/internal/error_serdes.js", + "lib/internal/errors.js", + "lib/internal/event_target.js", + "lib/internal/fixed_queue.js", + "lib/internal/freelist.js", + "lib/internal/freeze_intrinsics.js", + "lib/internal/fs/cp/cp-sync.js", + "lib/internal/fs/cp/cp.js", + "lib/internal/fs/dir.js", + "lib/internal/fs/promises.js", + "lib/internal/fs/read_file_context.js", + "lib/internal/fs/rimraf.js", + "lib/internal/fs/streams.js", + "lib/internal/fs/sync_write_stream.js", + "lib/internal/fs/utils.js", + "lib/internal/fs/watchers.js", + "lib/internal/heap_utils.js", + "lib/internal/histogram.js", + "lib/internal/http.js", + "lib/internal/http2/compat.js", + "lib/internal/http2/core.js", + "lib/internal/http2/util.js", + "lib/internal/idna.js", + "lib/internal/inspector_async_hook.js", + "lib/internal/js_stream_socket.js", + "lib/internal/legacy/processbinding.js", + "lib/internal/linkedlist.js", + "lib/internal/main/check_syntax.js", + "lib/internal/main/environment.js", + "lib/internal/main/eval_stdin.js", + "lib/internal/main/eval_string.js", + "lib/internal/main/inspect.js", + "lib/internal/main/mksnapshot.js", + "lib/internal/main/print_help.js", + "lib/internal/main/prof_process.js", + "lib/internal/main/repl.js", + "lib/internal/main/run_main_module.js", + "lib/internal/main/test_runner.js", + "lib/internal/main/watch_mode.js", + "lib/internal/main/worker_thread.js", + "lib/internal/modules/cjs/helpers.js", + "lib/internal/modules/cjs/loader.js", + "lib/internal/modules/esm/assert.js", + "lib/internal/modules/esm/create_dynamic_module.js", + "lib/internal/modules/esm/fetch_module.js", + "lib/internal/modules/esm/formats.js", + "lib/internal/modules/esm/get_format.js", + "lib/internal/modules/esm/handle_process_exit.js", + "lib/internal/modules/esm/initialize_import_meta.js", + "lib/internal/modules/esm/load.js", + "lib/internal/modules/esm/loader.js", + "lib/internal/modules/esm/module_job.js", + "lib/internal/modules/esm/module_map.js", + "lib/internal/modules/esm/package_config.js", + "lib/internal/modules/esm/resolve.js", + "lib/internal/modules/esm/translators.js", + "lib/internal/modules/package_json_reader.js", + "lib/internal/modules/run_main.js", + "lib/internal/net.js", + "lib/internal/options.js", + "lib/internal/per_context/domexception.js", + "lib/internal/per_context/messageport.js", + "lib/internal/per_context/primordials.js", + "lib/internal/perf/event_loop_delay.js", + "lib/internal/perf/event_loop_utilization.js", + "lib/internal/perf/nodetiming.js", + "lib/internal/perf/observe.js", + "lib/internal/perf/performance.js", + "lib/internal/perf/performance_entry.js", + "lib/internal/perf/resource_timing.js", + "lib/internal/perf/timerify.js", + "lib/internal/perf/usertiming.js", + "lib/internal/perf/utils.js", + "lib/internal/policy/manifest.js", + "lib/internal/policy/sri.js", + "lib/internal/priority_queue.js", + "lib/internal/process/esm_loader.js", + "lib/internal/process/execution.js", + "lib/internal/process/per_thread.js", + "lib/internal/process/policy.js", + "lib/internal/process/pre_execution.js", + "lib/internal/process/promises.js", + "lib/internal/process/report.js", + "lib/internal/process/signal.js", + "lib/internal/process/task_queues.js", + "lib/internal/process/warning.js", + "lib/internal/process/worker_thread_only.js", + "lib/internal/promise_hooks.js", + "lib/internal/querystring.js", + "lib/internal/readline/callbacks.js", + "lib/internal/readline/emitKeypressEvents.js", + "lib/internal/readline/interface.js", + "lib/internal/readline/promises.js", + "lib/internal/readline/utils.js", + "lib/internal/repl.js", + "lib/internal/repl/await.js", + "lib/internal/repl/history.js", + "lib/internal/repl/utils.js", + "lib/internal/socket_list.js", + "lib/internal/socketaddress.js", + "lib/internal/source_map/prepare_stack_trace.js", + "lib/internal/source_map/source_map.js", + "lib/internal/source_map/source_map_cache.js", + "lib/internal/stream_base_commons.js", + "lib/internal/streams/add-abort-signal.js", + "lib/internal/streams/buffer_list.js", + "lib/internal/streams/compose.js", + "lib/internal/streams/destroy.js", + "lib/internal/streams/duplex.js", + "lib/internal/streams/duplexify.js", + "lib/internal/streams/end-of-stream.js", + "lib/internal/streams/from.js", + "lib/internal/streams/lazy_transform.js", + "lib/internal/streams/legacy.js", + "lib/internal/streams/operators.js", + "lib/internal/streams/passthrough.js", + "lib/internal/streams/pipeline.js", + "lib/internal/streams/readable.js", + "lib/internal/streams/state.js", + "lib/internal/streams/transform.js", + "lib/internal/streams/utils.js", + "lib/internal/streams/writable.js", + "lib/internal/structured_clone.js", + "lib/internal/test/binding.js", + "lib/internal/test/transfer.js", + "lib/internal/test_runner/harness.js", + "lib/internal/test_runner/runner.js", + "lib/internal/test_runner/tap_stream.js", + "lib/internal/test_runner/test.js", + "lib/internal/test_runner/utils.js", + "lib/internal/timers.js", + "lib/internal/tls/secure-context.js", + "lib/internal/tls/secure-pair.js", + "lib/internal/trace_events_async_hooks.js", + "lib/internal/tty.js", + "lib/internal/url.js", + "lib/internal/util.js", + "lib/internal/util/colors.js", + "lib/internal/util/comparisons.js", + "lib/internal/util/debuglog.js", + "lib/internal/util/inspect.js", + "lib/internal/util/inspector.js", + "lib/internal/util/iterable_weak_map.js", + "lib/internal/util/parse_args/parse_args.js", + "lib/internal/util/parse_args/utils.js", + "lib/internal/util/types.js", + "lib/internal/v8/startup_snapshot.js", + "lib/internal/v8_prof_polyfill.js", + "lib/internal/v8_prof_processor.js", + "lib/internal/validators.js", + "lib/internal/vm/module.js", + "lib/internal/wasm_web_api.js", + "lib/internal/watch_mode/files_watcher.js", + "lib/internal/watchdog.js", + "lib/internal/webstreams/adapters.js", + "lib/internal/webstreams/compression.js", + "lib/internal/webstreams/encoding.js", + "lib/internal/webstreams/queuingstrategies.js", + "lib/internal/webstreams/readablestream.js", + "lib/internal/webstreams/transfer.js", + "lib/internal/webstreams/transformstream.js", + "lib/internal/webstreams/util.js", + "lib/internal/webstreams/writablestream.js", + "lib/internal/worker.js", + "lib/internal/worker/io.js", + "lib/internal/worker/js_transferable.js", + "lib/module.js", + "lib/net.js", + "lib/os.js", + "lib/path.js", + "lib/path/posix.js", + "lib/path/win32.js", + "lib/perf_hooks.js", + "lib/process.js", + "lib/punycode.js", + "lib/querystring.js", + "lib/readline.js", + "lib/readline/promises.js", + "lib/repl.js", + "lib/stream.js", + "lib/stream/consumers.js", + "lib/stream/promises.js", + "lib/stream/web.js", + "lib/string_decoder.js", + "lib/sys.js", + "lib/test.js", + "lib/timers.js", + "lib/timers/promises.js", + "lib/tls.js", + "lib/trace_events.js", + "lib/tty.js", + "lib/url.js", + "lib/util.js", + "lib/util/types.js", + "lib/v8.js", + "lib/vm.js", + "lib/wasi.js", + "lib/worker_threads.js", + "lib/zlib.js" + ], + "node_module_version": 108, + "node_no_browser_globals": "false", + "node_prefix": "/usr/local", + "node_release_urlbase": "https://nodejs.org/download/release/", + "node_shared": "false", + "node_shared_brotli": "false", + "node_shared_cares": "false", + "node_shared_http_parser": "false", + "node_shared_libuv": "false", + "node_shared_nghttp2": "false", + "node_shared_nghttp3": "false", + "node_shared_ngtcp2": "false", + "node_shared_openssl": "false", + "node_shared_zlib": "false", + "node_tag": "", + "node_target_type": "executable", + "node_use_bundled_v8": "true", + "node_use_dtrace": "false", + "node_use_etw": "true", + "node_use_node_code_cache": "true", + "node_use_node_snapshot": "true", + "node_use_openssl": "true", + "node_use_v8_platform": "true", + "node_with_ltcg": "true", + "node_without_node_options": "false", + "openssl_is_fips": "false", + "openssl_quic": "true", + "ossfuzz": "false", + "shlib_suffix": "so.108", + "target_arch": "x64", + "v8_enable_31bit_smis_on_64bit_arch": 0, + "v8_enable_gdbjit": 0, + "v8_enable_hugepage": 0, + "v8_enable_i18n_support": 1, + "v8_enable_inspector": 1, + "v8_enable_javascript_promise_hooks": 1, + "v8_enable_lite_mode": 0, + "v8_enable_object_print": 1, + "v8_enable_pointer_compression": 0, + "v8_enable_shared_ro_heap": 1, + "v8_enable_short_builtin_calls": 1, + "v8_enable_webassembly": 1, + "v8_no_strict_aliasing": 1, + "v8_optimized_debug": 1, + "v8_promise_internal_field_count": 1, + "v8_random_seed": 0, + "v8_trace_maps": 0, + "v8_use_siphash": 1, + "want_separate_host_toolset": 0, + "nodedir": "C:\\Users\\Luis\\AppData\\Local\\node-gyp\\Cache\\18.12.1", + "standalone_static_library": 1, + "msbuild_path": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe", + "cache": "C:\\Users\\Luis\\AppData\\Local\\npm-cache", + "globalconfig": "C:\\Program Files\\nodejs\\etc\\npmrc", + "global_prefix": "C:\\Program Files\\nodejs", + "init_module": "C:\\Users\\Luis\\.npm-init.js", + "local_prefix": "C:\\_projects\\addon-tools-raub", + "metrics_registry": "https://registry.npmjs.org/", + "node_gyp": "C:\\Users\\Luis\\AppData\\Roaming\\nvm\\v18.12.1\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js", + "prefix": "C:\\Program Files\\nodejs", + "userconfig": "C:\\Users\\Luis\\.npmrc", + "user_agent": "npm/8.19.2 node/v18.12.1 win32 x64 workspaces/false" + } +} diff --git a/test-addon/build/test.vcxproj b/test-addon/build/test.vcxproj new file mode 100644 index 0000000..77cafc8 --- /dev/null +++ b/test-addon/build/test.vcxproj @@ -0,0 +1,148 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {CA6D0C46-51F8-CCC5-FA71-4D2E9A260624} + Win32Proj + test + true + x64 + 10.0.19041.0 + + + + DynamicLibrary + + + v142 + + + + + + + + + + $(ExecutablePath);$(MSBuildProjectDirectory)\..\bin\;$(MSBuildProjectDirectory)\..\bin\ + true + $(Configuration)\obj\$(ProjectName)\ + false + true + $(SolutionDir)$(Configuration)\ + .node + .node + .node + .node + $(ProjectName) + $(OutDir)\$(ProjectName).node + + + + C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\include\node;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\src;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\config;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\openssl\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\uv\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\zlib;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\v8\include;..\..\node_modules\node-addon-api;C:\_projects\addon-tools-raub\include;%(AdditionalIncludeDirectories) + /Zc:__cplusplus -std:c++17 /O2 /Oy /GL /GF /Gm- /std:c++17 /EHa-s-c- /MT /GS /Gy /GR- /Gd %(AdditionalOptions) + EnableFastChecks + true + OldStyle + 4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings) + false + false + true + false + Disabled + NotUsing + NODE_GYP_MODULE_NAME=test;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;UNICODE;_UNICODE;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;_WIN32;BUILDING_NODE_EXTENSION;HOST_BINARY="node.exe";DEBUG;_DEBUG;V8_ENABLE_CHECKS;%(PreprocessorDefinitions) + MultiThreadedDebug + true + true + false + Level3 + true + + + /LTCG:INCREMENTAL %(AdditionalOptions) + + + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;"C:\\Users\\Luis\\AppData\\Local\\node-gyp\\Cache\\18.12.1\\x64\\node.lib" + /LTCG:INCREMENTAL /OPT:REF /OPT:ICF /LTCG /ignore:4199 %(AdditionalOptions) + node.exe;%(DelayLoadDLLs) + true + true + true + $(OutDir)$(ProjectName).node + true + .node + MachineX64 + + + C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\include\node;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\src;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\config;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\openssl\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\uv\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\zlib;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\v8\include;..\..\node_modules\node-addon-api;C:\_projects\addon-tools-raub\include;%(AdditionalIncludeDirectories) + NODE_GYP_MODULE_NAME=test;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;UNICODE;_UNICODE;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;_WIN32;BUILDING_NODE_EXTENSION;HOST_BINARY="node.exe";DEBUG;_DEBUG;V8_ENABLE_CHECKS;%(PreprocessorDefinitions);%(PreprocessorDefinitions) + + + + + C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\include\node;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\src;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\config;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\openssl\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\uv\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\zlib;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\v8\include;..\..\node_modules\node-addon-api;C:\_projects\addon-tools-raub\include;%(AdditionalIncludeDirectories) + /Zc:__cplusplus -std:c++17 /O2 /Oy /GL /GF /Gm- /std:c++17 /EHa-s-c- /MT /GS /Gy /GR- /Gd %(AdditionalOptions) + true + OldStyle + 4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings) + false + Speed + true + AnySuitable + true + true + true + Full + NotUsing + NODE_GYP_MODULE_NAME=test;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;UNICODE;_UNICODE;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;_WIN32;BUILDING_NODE_EXTENSION;HOST_BINARY="node.exe";%(PreprocessorDefinitions) + MultiThreaded + false + true + true + false + Level3 + true + + + /LTCG:INCREMENTAL %(AdditionalOptions) + + + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;"C:\\Users\\Luis\\AppData\\Local\\node-gyp\\Cache\\18.12.1\\x64\\node.lib" + /LTCG:INCREMENTAL /OPT:REF /OPT:ICF /LTCG /ignore:4199 %(AdditionalOptions) + node.exe;%(DelayLoadDLLs) + true + true + true + $(OutDir)$(ProjectName).node + true + .node + MachineX64 + + + C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\include\node;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\src;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\config;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\openssl\openssl\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\uv\include;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\zlib;C:\Users\Luis\AppData\Local\node-gyp\Cache\18.12.1\deps\v8\include;..\..\node_modules\node-addon-api;C:\_projects\addon-tools-raub\include;%(AdditionalIncludeDirectories) + NODE_GYP_MODULE_NAME=test;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;UNICODE;_UNICODE;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;_WIN32;BUILDING_NODE_EXTENSION;HOST_BINARY="node.exe";%(PreprocessorDefinitions);%(PreprocessorDefinitions) + + + + + + + + $(IntDir)\test.obj + + + + + + + diff --git a/test-addon/build/test.vcxproj.filters b/test-addon/build/test.vcxproj.filters new file mode 100644 index 0000000..4aded21 --- /dev/null +++ b/test-addon/build/test.vcxproj.filters @@ -0,0 +1,58 @@ + + + + + {739DB09A-CC57-A953-A6CF-F64FA08E4FA7} + + + {7B735499-E5DD-1C2B-6C26-70023832A1CF} + + + {E9F714C1-DA89-54E2-60CF-39FEB20BF756} + + + {5215B9C8-08C9-9B12-A4BC-6B55FF1672C0} + + + {F852EB63-437C-846A-220F-8D9ED6DAEC1D} + + + {D51E5808-912B-5C70-4BB7-475D1DBFA067} + + + {1B85D12A-9F9C-E0A8-F82E-74864675B527} + + + {68329104-0883-3C95-6BC9-C46F7BFC39D9} + + + {56DF7A98-063D-FB9D-485C-089023B4C16A} + + + {741E0E76-39B2-B1AB-9FA1-F1A20B16F295} + + + {56DF7A98-063D-FB9D-485C-089023B4C16A} + + + {77348C0E-2034-7791-74D5-63C077DF5A3B} + + + {8CDEE807-BC53-E450-C8B8-4DEBB66742D4} + + + {739DB09A-CC57-A953-A6CF-F64FA08E4FA7} + + + + + .. + + + C:\Users\Luis\AppData\Roaming\nvm\v18.12.1\node_modules\npm\node_modules\node-gyp\src + + + .. + + + diff --git a/test/hpp-arg-array-str.test.js b/test-addon/hpp-arg-array-str.test.js similarity index 100% rename from test/hpp-arg-array-str.test.js rename to test-addon/hpp-arg-array-str.test.js diff --git a/test/hpp-arg-array.test.js b/test-addon/hpp-arg-array.test.js similarity index 100% rename from test/hpp-arg-array.test.js rename to test-addon/hpp-arg-array.test.js diff --git a/test/hpp-arg-bool.test.js b/test-addon/hpp-arg-bool.test.js similarity index 100% rename from test/hpp-arg-bool.test.js rename to test-addon/hpp-arg-bool.test.js diff --git a/test/hpp-arg-double.test.js b/test-addon/hpp-arg-double.test.js similarity index 100% rename from test/hpp-arg-double.test.js rename to test-addon/hpp-arg-double.test.js diff --git a/test/hpp-arg-ext.test.js b/test-addon/hpp-arg-ext.test.js similarity index 100% rename from test/hpp-arg-ext.test.js rename to test-addon/hpp-arg-ext.test.js diff --git a/test/hpp-arg-float.test.js b/test-addon/hpp-arg-float.test.js similarity index 100% rename from test/hpp-arg-float.test.js rename to test-addon/hpp-arg-float.test.js diff --git a/test/hpp-arg-int.test.js b/test-addon/hpp-arg-int.test.js similarity index 100% rename from test/hpp-arg-int.test.js rename to test-addon/hpp-arg-int.test.js diff --git a/test/hpp-arg-obj.test.js b/test-addon/hpp-arg-obj.test.js similarity index 100% rename from test/hpp-arg-obj.test.js rename to test-addon/hpp-arg-obj.test.js diff --git a/test/hpp-arg-offs.test.js b/test-addon/hpp-arg-offs.test.js similarity index 100% rename from test/hpp-arg-offs.test.js rename to test-addon/hpp-arg-offs.test.js diff --git a/test/hpp-arg-str.test.js b/test-addon/hpp-arg-str.test.js similarity index 100% rename from test/hpp-arg-str.test.js rename to test-addon/hpp-arg-str.test.js diff --git a/test/hpp-arg-uint.test.js b/test-addon/hpp-arg-uint.test.js similarity index 100% rename from test/hpp-arg-uint.test.js rename to test-addon/hpp-arg-uint.test.js diff --git a/test/hpp-arg.test.js b/test-addon/hpp-arg.test.js similarity index 100% rename from test/hpp-arg.test.js rename to test-addon/hpp-arg.test.js diff --git a/test/test.cpp b/test-addon/test.cpp similarity index 100% rename from test/test.cpp rename to test-addon/test.cpp diff --git a/utils.d.ts b/utils.d.ts index 0b4d03b..267d194 100644 --- a/utils.d.ts +++ b/utils.d.ts @@ -1,10 +1,87 @@ -import type { Stats } from 'fs'; +import type { Writable } from 'stream'; declare module "addon-tools-raub/utils" { + /** + * Install binaries + * Downloads and unzips the platform specific binary for the calling package. + * To use it, create a new script for your package, which may as well be named + * **install.js**, with the following content: + * ``` + * 'use strict'; + * const install = require('addon-tools-raub/install'); + * const prefix = 'https://github.com/USER/ADDON-NAME/releases/download'; + * const tag = 'v1.0.0'; + * install(`${prefix}/${tag}`); + * ``` + * * `prefix` - the constant base part of the download url. + * * `tag` - the version-dependent part of the url. + * ``` + * "scripts": { + * "postinstall": "node install" + * }, + * ``` + */ + export const install: (folder: string) => void; + + + /** + * Copy binary + * Copies the addon binary from `src/build/Release` to the platform folder. + * ``` + * declare const cpbin: (name: string) => Promise; + * export default cpbin; + * ``` + * It is useful for development builds. Use it in your **src/package.json**: + * ``` + * "scripts": { + * * "build": "node-gyp rebuild && node -e \"require('addon-tools-raub/cpbin')('ADDON')\"" + * }, + * ``` + * Here ADDON should be replaced with the name of your addon, without `.node` extension. + */ + export const cpbin: (name: string) => Promise; + + + /** + * Download to memory + * Accepts an **URL**, and returns an in-memory file Buffer, + * when the file is loaded. Use for small files, as the whole + * file will be loaded into memory at once. + * + * ``` + * download(srcUrl).then(data => useData(data), err => emit('error', err)); + * ``` + * or + * ``` + * const data = await download(srcUrl); + * useData(data); + * ``` + */ + export const download: (url: string) => Promise; + /** * (async) Read a file * Reads a whole file to string, NOT A Buffer */ + + + /** + * WritableBuffer + * A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams) + * stream buffer, that is stored in-memory and can be fully + * obtained when writing was finished. It is equivalent to stream-writing + * a temporary file and then reading it into a `Buffer`. + */ + export class WritableBuffer extends Writable { + constructor(); + /** + * Get the downloaded data + * Use `stream.get()` to obtain the data when writing was finished + */ + get(): Buffer; + } + + export const read: (name: string) => Promise; /** @@ -101,5 +178,4 @@ declare module "addon-tools-raub/utils" { * Must be a file, not a folder. Just `fs.unlink`. */ export const rm: (name: string) => Promise; - } diff --git a/utils.js b/utils.js index deafcb1..e5f268a 100644 --- a/utils.js +++ b/utils.js @@ -1,195 +1,3 @@ 'use strict'; -const fs = require('fs'); - -// (async) Reads a whole file to string, NOT A Buffer -const read = (name) => new Promise( - (res, rej) => fs.readFile( - name, - (err, data) => (err ? rej(err) : res(data.toString())) - ) -); - - -// (async) Write a file -const write = (name, text) => new Promise( - (res, rej) => fs.writeFile(name, text, (err) => (err ? rej(err) : res())) -); - - -// (async) Copy a file -const copy = async (src, dest) => { - try { - await new Promise( - (res, rej) => fs.copyFile(src, dest, (err) => (err ? rej(err) : res())) - ); - } catch (e) { - if (e.code !== 'EBUSY') { - console.warn('WARNING\n', e); - } - } -}; - - -// (async) Check if a file/folder exists -const exists = (name) => new Promise( - (res) => fs.access( - name, - fs.constants.F_OK, - (err) => res(err ? false : true) - ) -); - - -// (async) Create an empty folder -const mkdir = async (name) => { - if (await exists(name)) { - return; - } - return new Promise( - (res, rej) => fs.mkdir(name, (err) => (err ? rej(err) : res())) - ); -}; - - -// (async) Get status on a file -const stat = (name) => new Promise( - (res, rej) => fs.stat(name, (err, stats) => (err ? rej(err) : res(stats))) -); - - -// (async) Check if the path is a folder -const isDir = async (name) => (await stat(name)).isDirectory(); - - -// (async) Check if the path is a file -const isFile = async (name) => (await stat(name)).isFile(); - - -// Cut the path one folder up -const dirUp = (dir) => dir.replace(/\\/g, '/').split('/').slice(0, -1).join('/'); - - -// (async) Like `mkdir -p`, makes sure a directory exists -const ensuredir = async (dir) => { - if (await exists(dir) && await isDir(dir)) { - return; - } - await ensuredir(dirUp(dir)); - await mkdir(dir); -}; - - -// (async) Copy a file, `dest` folder is created if needed -const copysafe = async (src, dest) => { - await ensuredir(dirUp(dest)); - await copy(src, dest); -}; - - -// (async) Get file/folder names of the 1st level -const readdir = (name) => new Promise( - (res, rej) => fs.readdir( - name, - (err, dirents) => (err ? rej(err) : res(dirents)) - ) -); - - -// (async) Get folder paths (concatenated with input) of the 1st level -const subdirs = async (name) => { - const all = await readdir(name); - const mapped = await Promise.all(all.map((d) => isDir(`${name}/${d}`))); - return all.filter((_, i) => mapped[i]); -}; - - -// (async) Get file paths (concatenated with input) of the 1st level -const subfiles = async (name) => { - const all = await readdir(name); - const mapped = await Promise.all(all.map((d) => isFile(`${name}/${d}`))); - return all.filter((_, i) => mapped[i]).map((f) => `${name}/${f}`); -}; - - -// (async) Get all nested files recursively -// Folder paths are omitted by default -// Order is: shallow-to-deep, each subdirectory lists dirs-then-files. -const traverse = async (name, showDirs = false) => { - const dirs = []; - const stack = [name]; - while (stack.length) { - const dir = stack.pop(); - dirs.push(dir); - (await subdirs(dir)).forEach((d) => stack.push(`${dir}/${d}`)); - } - return (showDirs ? dirs : []).concat( - ...(await Promise.all(dirs.map(subfiles))) - ); -}; - - -// (async) Copy a folder with all the contained files -const copyall = async (src, dest) => { - const files = (await traverse(src, true)).reverse(); - while (files.length) { - const target = files.pop(); - const dir = await isDir(target); - if (dir) { - await mkdir(target.replace(src, dest)); - } else { - await copy(target, target.replace(src, dest)); - } - } -}; - - -// (async) Like `rm -rf`, removes everything recursively -const rmdir = async (name) => { - if (!await exists(name)) { - return; - } - const paths = await traverse(name, true); - while (paths.length) { - const target = paths.pop(); - const dir = await isDir(target); - await new Promise( - (res, rej) => fs[dir ? 'rmdir' : 'unlink']( - target, - (err) => (err ? rej(err) : res()) - ) - ); - } -}; - - -// (async) Remove a file. Must be a file, not a folder. Just `fs.unlink`. -const rm = async (name) => { - if (!await exists(name)) { - return; - } - await new Promise( - (res, rej) => fs.unlink(name, (err) => (err ? rej(err) : res())) - ); -}; - -module.exports = { - read, - write, - copy, - exists, - mkdir, - stat, - isDir, - isFile, - dirUp, - ensuredir, - copysafe, - readdir, - subdirs, - subfiles, - traverse, - copyall, - rmdir, - rm, -}; +module.exports = require('./utils'); diff --git a/utils/action-version.js b/utils/action-version.js new file mode 100644 index 0000000..81f4f10 --- /dev/null +++ b/utils/action-version.js @@ -0,0 +1,6 @@ +'use strict'; + + +module.exports = { + actionVersion: () => console.log(`version=${process.env.npm_package_version}`), +}; diff --git a/utils/action-zip.js b/utils/action-zip.js new file mode 100644 index 0000000..baee77d --- /dev/null +++ b/utils/action-zip.js @@ -0,0 +1,20 @@ +'use strict'; + +const util = require('node:util'); +const exec = util.promisify(require('node:child_process').exec); + +const { platform, bin } = require('..'); + + +const actionZip = async () => { + try { + await exec(`cd ${bin} && tar -acf ../${platform}.zip *`); + console.log(`zip=${platform}.zip`); + } catch (error) { + console.error(error); + process.exit(-1); + } +}; + + +module.exports = { actionZip }; diff --git a/cpbin.js b/utils/cpbin.js similarity index 78% rename from cpbin.js rename to utils/cpbin.js index 7088c58..0976ba6 100644 --- a/cpbin.js +++ b/utils/cpbin.js @@ -1,10 +1,10 @@ 'use strict'; -const { copy, exists, mkdir, rm } = require('./utils'); -const { bin } = require('.'); +const { copy, exists, mkdir, rm } = require('./files'); +const { bin } = require('..'); -module.exports = async (name) => { +const cpbin = async (name) => { const srcDir = process.cwd().replace(/\\/g, '/'); if (!await exists(`${srcDir}/build/Release/${name}.node`) ) { @@ -27,3 +27,5 @@ module.exports = async (name) => { console.log(`The binary "${name}.node" was copied to "${bin}".`); }; + +module.exports = { cpbin }; diff --git a/download.js b/utils/download.js similarity index 71% rename from download.js rename to utils/download.js index baafed1..6bbe41d 100644 --- a/download.js +++ b/utils/download.js @@ -1,15 +1,15 @@ 'use strict'; -const https = require('https'); -const http = require('http'); +const https = require('node:https'); +const http = require('node:http'); -const WritableBuffer = require('./writable-buffer'); +const { WritableBuffer } = require('./writable-buffer'); const protocols = { http, https }; -const download = async (url, count = 1) => { +const downloadRecursive = async (url, count = 1) => { url = url.toLowerCase(); const stream = new WritableBuffer(); @@ -23,7 +23,7 @@ const download = async (url, count = 1) => { // Handle redirects if ([301, 302, 303, 307].includes(response.statusCode)) { if (count < 5) { - return download(response.headers.location, count + 1); + return downloadRecursive(response.headers.location, count + 1); } console.log(url); throw new Error('Error: Too many redirects.'); @@ -43,4 +43,6 @@ const download = async (url, count = 1) => { }); }; -module.exports = (url) => download(url); +const download = (url) => downloadRecursive(url); + +module.exports = { download }; diff --git a/utils/files.js b/utils/files.js new file mode 100644 index 0000000..987faee --- /dev/null +++ b/utils/files.js @@ -0,0 +1,196 @@ +'use strict'; + +const fs = require('node:fs'); + + +// (async) Reads a whole file to string, NOT A Buffer +const read = (name) => new Promise( + (res, rej) => fs.readFile( + name, + (err, data) => (err ? rej(err) : res(data.toString())) + ) +); + + +// (async) Write a file +const write = (name, text) => new Promise( + (res, rej) => fs.writeFile(name, text, (err) => (err ? rej(err) : res())) +); + + +// (async) Copy a file +const copy = async (src, dest) => { + try { + await new Promise( + (res, rej) => fs.copyFile(src, dest, (err) => (err ? rej(err) : res())) + ); + } catch (e) { + if (e.code !== 'EBUSY') { + console.warn('WARNING\n', e); + } + } +}; + + +// (async) Check if a file/folder exists +const exists = (name) => new Promise( + (res) => fs.access( + name, + fs.constants.F_OK, + (err) => res(err ? false : true) + ) +); + + +// (async) Create an empty folder +const mkdir = async (name) => { + if (await exists(name)) { + return; + } + return new Promise( + (res, rej) => fs.mkdir(name, (err) => (err ? rej(err) : res())) + ); +}; + + +// (async) Get status on a file +const stat = (name) => new Promise( + (res, rej) => fs.stat(name, (err, stats) => (err ? rej(err) : res(stats))) +); + + +// (async) Check if the path is a folder +const isDir = async (name) => (await stat(name)).isDirectory(); + + +// (async) Check if the path is a file +const isFile = async (name) => (await stat(name)).isFile(); + + +// Cut the path one folder up +const dirUp = (dir) => dir.replace(/\\/g, '/').split('/').slice(0, -1).join('/'); + + +// (async) Like `mkdir -p`, makes sure a directory exists +const ensuredir = async (dir) => { + if (await exists(dir) && await isDir(dir)) { + return; + } + await ensuredir(dirUp(dir)); + await mkdir(dir); +}; + + +// (async) Copy a file, `dest` folder is created if needed +const copysafe = async (src, dest) => { + await ensuredir(dirUp(dest)); + await copy(src, dest); +}; + + +// (async) Get file/folder names of the 1st level +const readdir = (name) => new Promise( + (res, rej) => fs.readdir( + name, + (err, dirents) => (err ? rej(err) : res(dirents)) + ) +); + + +// (async) Get folder paths (concatenated with input) of the 1st level +const subdirs = async (name) => { + const all = await readdir(name); + const mapped = await Promise.all(all.map((d) => isDir(`${name}/${d}`))); + return all.filter((_, i) => mapped[i]); +}; + + +// (async) Get file paths (concatenated with input) of the 1st level +const subfiles = async (name) => { + const all = await readdir(name); + const mapped = await Promise.all(all.map((d) => isFile(`${name}/${d}`))); + return all.filter((_, i) => mapped[i]).map((f) => `${name}/${f}`); +}; + + +// (async) Get all nested files recursively +// Folder paths are omitted by default +// Order is: shallow-to-deep, each subdirectory lists dirs-then-files. +const traverse = async (name, showDirs = false) => { + const dirs = []; + const stack = [name]; + while (stack.length) { + const dir = stack.pop(); + dirs.push(dir); + (await subdirs(dir)).forEach((d) => stack.push(`${dir}/${d}`)); + } + return (showDirs ? dirs : []).concat( + ...(await Promise.all(dirs.map(subfiles))) + ); +}; + + +// (async) Copy a folder with all the contained files +const copyall = async (src, dest) => { + const files = (await traverse(src, true)).reverse(); + while (files.length) { + const target = files.pop(); + const dir = await isDir(target); + if (dir) { + await mkdir(target.replace(src, dest)); + } else { + await copy(target, target.replace(src, dest)); + } + } +}; + + +// (async) Like `rm -rf`, removes everything recursively +const rmdir = async (name) => { + if (!await exists(name)) { + return; + } + const paths = await traverse(name, true); + while (paths.length) { + const target = paths.pop(); + const dir = await isDir(target); + await new Promise( + (res, rej) => fs[dir ? 'rmdir' : 'unlink']( + target, + (err) => (err ? rej(err) : res()) + ) + ); + } +}; + + +// (async) Remove a file. Must be a file, not a folder. Just `fs.unlink`. +const rm = async (name) => { + if (!await exists(name)) { + return; + } + await new Promise( + (res, rej) => fs.unlink(name, (err) => (err ? rej(err) : res())) + ); +}; + +module.exports = { + read, + write, + copy, + exists, + mkdir, + stat, + isDir, + isFile, + dirUp, + ensuredir, + copysafe, + readdir, + subdirs, + subfiles, + traverse, + copyall, + rmdir, + rm, +}; diff --git a/utils/index.js b/utils/index.js new file mode 100644 index 0000000..208b408 --- /dev/null +++ b/utils/index.js @@ -0,0 +1,12 @@ +'use strict'; + + +module.exports = { + ...require('action-version'), + ...require('action-zip'), + ...require('cpbin'), + ...require('download'), + ...require('files'), + ...require('install'), + ...require('writable-buffer'), +}; \ No newline at end of file diff --git a/install.js b/utils/install.js similarity index 54% rename from install.js rename to utils/install.js index 546a1dd..c840e9a 100644 --- a/install.js +++ b/utils/install.js @@ -1,19 +1,12 @@ 'use strict'; -const https = require('https'); -const http = require('http'); -const fs = require('fs'); +const https = require('node:https'); +const http = require('node:http'); +const util = require('node:util'); +const exec = util.promisify(require('node:child_process').exec); -let AdmZip = null; -try { - AdmZip = require('adm-zip'); -} catch (ex) { - console.error('The `install` script requires `adm-zip` module to be installed.'); - process.exit(1); -} - -const { bin, platform } = require('.'); -const { mkdir, rm } = require('./utils'); +const { bin, platform } = require('..'); +const { mkdir, rmdir, rm } = require('./files'); const protocols = { http, https }; @@ -26,7 +19,7 @@ const onError = (msg) => { const zipPath = `${bin}/${bin}.zip`; -const install = async (url, count = 1) => { +const installRecursive = async (url, count = 1) => { try { const proto = protocols[url.match(/^https?/)[0]]; @@ -39,7 +32,7 @@ const install = async (url, count = 1) => { // Handle redirects if ([301, 302, 303, 307].includes(response.statusCode)) { if (count < 5) { - return install(response.headers.location, count + 1); + return installRecursive(response.headers.location, count + 1); } console.log(url); throw new Error('Error: Too many redirects.'); @@ -51,27 +44,21 @@ const install = async (url, count = 1) => { throw new Error(`Response status was ${response.statusCode}`); } + await rmdir(bin); await mkdir(bin); - await new Promise((res, rej) => { - const zipWriter = fs.createWriteStream(zipPath); - zipWriter.on('error', (err) => rej(err)); - zipWriter.on('finish', () => res()); - response.pipe(zipWriter); - }); - - const zip = new AdmZip(zipPath); - zip.extractAllTo(bin, true); + await exec(`tar -xzvf ${platform}.zip --directory ${bin}`); await rm(zipPath); - } catch (ex) { onError(ex.message); } }; -module.exports = (folder) => { +const install = (folder) => { const url = `${folder}/${platform}.zip`; - install(url).then(); + installRecursive(url).then(); }; + +module.exports = { install }; diff --git a/utils/utils.test.js b/utils/utils.test.js new file mode 100644 index 0000000..17ff106 --- /dev/null +++ b/utils/utils.test.js @@ -0,0 +1,19 @@ +'use strict'; + +const utils = require('.'); + + +describe('utils.js', () => { + const methods = [ + 'install', 'cpbin', 'download', 'read', 'write', 'copy', 'exists', + 'mkdir', 'stat', 'isDir', 'isFile', 'dirUp', 'ensuredir', 'copysafe', + 'readdir', 'subdirs', 'subfiles', 'traverse', 'copyall', + 'rmdir', 'rm', 'WritableBuffer', + ]; + + methods.forEach((name) => { + it('is a function', () => { + expect(typeof utils[name]).toBe('function'); + }); + }); +}); diff --git a/writable-buffer.js b/utils/writable-buffer.js similarity index 92% rename from writable-buffer.js rename to utils/writable-buffer.js index d02f71b..6ffcc72 100644 --- a/writable-buffer.js +++ b/utils/writable-buffer.js @@ -1,6 +1,6 @@ 'use strict'; -const { Writable } = require('stream'); +const { Writable } = require('node:stream'); const CHUNK_SIZE = 1024; @@ -53,4 +53,4 @@ class WritableBuffer extends Writable { } } -module.exports = WritableBuffer; +module.exports = { WritableBuffer }; diff --git a/writable-buffer.d.ts b/writable-buffer.d.ts deleted file mode 100644 index 59b6610..0000000 --- a/writable-buffer.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { Writable } from 'stream'; - - -declare module "addon-tools-raub/writable-buffer" { - /** - * WritableBuffer - * A [Writable](https://nodejs.org/api/stream.html#stream_writable_streams) - * stream buffer, that is stored in-memory and can be fully - * obtained when writing was finished. It is equivalent to stream-writing - * a temporary file and then reading it into a `Buffer`. - */ - export class WritableBuffer extends Writable { - constructor(); - /** - * Get the downloaded data - * Use `stream.get()` to obtain the data when writing was finished - */ - get(): Buffer; - } - - export = WritableBuffer; -}