@matrixai/typescript-demo-lib
Advanced tools
Comparing version 1.1.2 to 1.2.0
#!/usr/bin/env node | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (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; | ||
}; | ||
@@ -16,34 +26,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const os = __importStar(require("os")); | ||
const process_1 = __importDefault(require("process")); | ||
const uuid_1 = require("uuid"); | ||
const Library_1 = __importDefault(require("../lib/Library")); | ||
const NumPair_1 = __importDefault(require("../lib/NumPair")); | ||
const uuid_1 = require("uuid"); | ||
const test_workers_1 = __importDefault(require("../lib/workers/test-workers")); | ||
const test_level_1 = __importDefault(require("../lib/test-level")); | ||
const test_utp_native_1 = __importDefault(require("../lib/test-utp-native")); | ||
function main(argv = process_1.default.argv) { | ||
var _a, _b, _c; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// Print out command-line arguments | ||
argv = argv.slice(2); // Removing prepended file paths. | ||
process_1.default.stdout.write('[' + argv.slice(0, 2).toString() + ']\n'); | ||
// Create a new Library with the value someParam = 'new library' | ||
// And print it out | ||
const l = new Library_1.default('new library'); | ||
process_1.default.stdout.write(l.someParam + '\n'); | ||
// Generate and print a uuid (universally unique identifier) | ||
process_1.default.stdout.write(uuid_1.v4() + '\n'); | ||
// Add the first two command-line args and print the result | ||
// default to using 0 | ||
const nums = new NumPair_1.default(parseInt((_a = argv[0]) !== null && _a !== void 0 ? _a : 0), parseInt((_b = argv[1]) !== null && _b !== void 0 ? _b : 0)); | ||
const sum = nums.num1 + nums.num2; | ||
process_1.default.stdout.write(nums.num1 + ' + ' + nums.num2 + ' = ' + sum + '\n'); | ||
// Testing native modules | ||
const dir = (_c = argv[2]) !== null && _c !== void 0 ? _c : '/tmp'; | ||
yield test_level_1.default(dir); | ||
yield test_workers_1.default(); | ||
yield test_utp_native_1.default(); | ||
process_1.default.exitCode = 0; | ||
return process_1.default.exitCode; | ||
}); | ||
const test_workers_1 = __importDefault(require("../lib/workers/test-workers")); | ||
const test_fd_lock_1 = require("../lib/test-fd-lock"); | ||
const utils_1 = require("../utils"); | ||
async function main(argv = process_1.default.argv) { | ||
// Print out command-line arguments | ||
argv = argv.slice(2); // Removing prepended file paths. | ||
process_1.default.stdout.write('[' + argv.slice(0, 2).toString() + ']\n'); | ||
// Create a new Library with the value someParam = 'new library' | ||
// And print it out | ||
const l = new Library_1.default('new library'); | ||
process_1.default.stdout.write(l.someParam + '\n'); | ||
// Generate and print a uuid (universally unique identifier) | ||
process_1.default.stdout.write((0, uuid_1.v4)() + '\n'); | ||
// Add the first two command-line args and print the result | ||
// default to using 0 | ||
const nums = new NumPair_1.default(parseInt(argv[0] ?? 0), parseInt(argv[1] ?? 0)); | ||
const sum = nums.num1 + nums.num2; | ||
process_1.default.stdout.write(nums.num1 + ' + ' + nums.num2 + ' = ' + sum + '\n'); | ||
// Testing native modules | ||
const dir = argv[2] ?? os.tmpdir(); | ||
await (0, test_level_1.default)(dir); | ||
await (0, test_workers_1.default)(); | ||
await (0, test_utp_native_1.default)(); | ||
process_1.default.stdout.write(utils_1.version + '\n'); | ||
process_1.default.stdout.write(utils_1.test.toString() + '\n'); | ||
// Testing fd-lock | ||
await (0, test_fd_lock_1.testFdLock)(dir); | ||
process_1.default.exitCode = 0; | ||
return process_1.default.exitCode; | ||
} | ||
@@ -50,0 +64,0 @@ if (require.main === module) { |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -15,18 +6,16 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path_1 = __importDefault(require("path")); | ||
const process_1 = __importDefault(require("process")); | ||
const level_1 = __importDefault(require("level")); | ||
const process_1 = __importDefault(require("process")); | ||
const path_1 = __importDefault(require("path")); | ||
// Level tests. | ||
function testLevel(dir) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
process_1.default.stdout.write('lets test some levelDB\n'); | ||
const db = level_1.default(path_1.default.join(dir, 'levelDB')); | ||
const key = 'hello'; | ||
const value = 'Level!'; | ||
yield db.put(key, value); | ||
process_1.default.stdout.write(key + ' ' + (yield db.get(key)) + '\n'); | ||
process_1.default.stdout.write('\n'); | ||
}); | ||
async function testLevel(dir) { | ||
process_1.default.stdout.write('lets test some levelDB\n'); | ||
const db = (0, level_1.default)(path_1.default.join(dir, 'levelDB')); | ||
const key = 'hello'; | ||
const value = 'Level!'; | ||
await db.put(key, value); | ||
process_1.default.stdout.write(key + ' ' + (await db.get(key)) + '\n'); | ||
process_1.default.stdout.write('\n'); | ||
} | ||
exports.default = testLevel; | ||
//# sourceMappingURL=test-level.js.map |
@@ -1,2 +0,2 @@ | ||
declare function testUptNative(): Promise<void>; | ||
export default testUptNative; | ||
declare function testUtpNative(): Promise<void>; | ||
export default testUtpNative; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -17,25 +8,23 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const utils_1 = require("../utils"); | ||
function testUptNative() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// upt-native tests | ||
process.stdout.write('Lets test utp-native.\n'); | ||
const server = utp_native_1.default.createServer((socket) => { | ||
socket.pipe(socket); | ||
async function testUtpNative() { | ||
// Utp-native tests | ||
process.stdout.write('Lets test utp-native.\n'); | ||
const server = utp_native_1.default.createServer((socket) => { | ||
socket.pipe(socket); | ||
}); | ||
server.listen(() => { | ||
const socket = utp_native_1.default.connect(server.address().port); | ||
socket.write('hello UTP!!\n'); | ||
socket.end(); | ||
socket.on('data', (data) => { | ||
process.stdout.write('echo: ' + data + '\n'); | ||
}); | ||
server.listen(() => { | ||
const socket = utp_native_1.default.connect(server.address().port); | ||
socket.write('hello UTP!!\n'); | ||
socket.end(); | ||
socket.on('data', (data) => { | ||
process.stdout.write('echo: ' + data + '\n'); | ||
}); | ||
socket.on('end', () => { | ||
process.stdout.write('ended\n'); | ||
server.close(); | ||
}); | ||
socket.on('end', () => { | ||
process.stdout.write('ended\n'); | ||
server.close(); | ||
}); | ||
yield utils_1.sleep(2000); | ||
}); | ||
await (0, utils_1.sleep)(2000); | ||
} | ||
exports.default = testUptNative; | ||
exports.default = testUtpNative; | ||
//# sourceMappingURL=test-utp-native.js.map |
@@ -21,11 +21,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -35,22 +26,19 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//testing worker threads. | ||
const os = __importStar(require("os")); | ||
const process_1 = __importDefault(require("process")); | ||
const threads_1 = require("threads"); | ||
const process_1 = __importDefault(require("process")); | ||
const os = __importStar(require("os")); | ||
function testWorkers() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
process_1.default.stdout.write('Lets test workers.\n'); | ||
const coreCount = os.cpus().length; | ||
const pool = threads_1.Pool(() => threads_1.spawn(new threads_1.Worker('./worker')), coreCount); | ||
for (let i = 0; i < coreCount; i++) { | ||
pool.queue((hellower) => __awaiter(this, void 0, void 0, function* () { | ||
process_1.default.stdout.write((yield hellower.helloWorld()) + '\n'); | ||
})); | ||
} | ||
yield pool.completed(); | ||
process_1.default.stdout.write('\n'); | ||
yield pool.terminate(); | ||
}); | ||
async function testWorkers() { | ||
process_1.default.stdout.write('Lets test workers.\n'); | ||
const coreCount = os.cpus().length; | ||
const pool = (0, threads_1.Pool)(() => (0, threads_1.spawn)(new threads_1.Worker('./worker')), coreCount); | ||
for (let i = 0; i < coreCount; i++) { | ||
pool.queue(async (hellower) => { | ||
process_1.default.stdout.write((await hellower.helloWorld()) + '\n'); | ||
}); | ||
} | ||
await pool.completed(); | ||
process_1.default.stdout.write('\n'); | ||
await pool.terminate(); | ||
} | ||
exports.default = testWorkers; | ||
//# sourceMappingURL=test-workers.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const worker_1 = require("threads/worker"); | ||
worker_1.expose({ | ||
(0, worker_1.expose)({ | ||
helloWorld() { | ||
@@ -6,0 +6,0 @@ return 'Hello Worker!'; |
@@ -0,2 +1,4 @@ | ||
import { test } from './test.json'; | ||
import { version } from '../package.json'; | ||
declare function sleep(ms: number): Promise<unknown>; | ||
export { sleep }; | ||
export { sleep, version, test }; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sleep = void 0; | ||
function sleep(ms) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield new Promise((r) => setTimeout(r, ms)); | ||
}); | ||
exports.test = exports.version = exports.sleep = void 0; | ||
const test_json_1 = require("./test.json"); | ||
Object.defineProperty(exports, "test", { enumerable: true, get: function () { return test_json_1.test; } }); | ||
// @ts-ignore package.json is outside rootDir | ||
const package_json_1 = require("../package.json"); | ||
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return package_json_1.version; } }); | ||
async function sleep(ms) { | ||
return await new Promise((r) => setTimeout(r, ms)); | ||
} | ||
exports.sleep = sleep; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@matrixai/typescript-demo-lib", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"bin": { | ||
@@ -20,2 +20,5 @@ "typescript-demo-lib": "dist/bin/typescript-demo-lib.js" | ||
"node_modules/utp-native/**/*", | ||
"node_modules/fd-lock/**/*" | ||
], | ||
"scripts": [ | ||
"dist/lib/workers/worker.js" | ||
@@ -25,3 +28,3 @@ ] | ||
"scripts": { | ||
"build": "tsc -p ./tsconfig.build.json", | ||
"build": "rm -r ./dist || true; tsc -p ./tsconfig.build.json", | ||
"ts-node": "ts-node -r tsconfig-paths/register", | ||
@@ -31,4 +34,4 @@ "test": "jest", | ||
"lintfix": "eslint '{src,tests}/**/*.{js,ts}' --fix", | ||
"docs": "typedoc --out ./docs src && touch ./docs/.nojekyll", | ||
"typescript-demo-lib": "ts-node -r tsconfig-paths/register src/bin/typescript-demo-lib.ts" | ||
"docs": "rm -r ./docs || true; typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src && touch ./docs/.nojekyll", | ||
"typescript-demo-lib": "ts-node -r tsconfig-paths/register --transpile-only src/bin/typescript-demo-lib.ts" | ||
}, | ||
@@ -39,7 +42,8 @@ "dependencies": { | ||
"utp-native": "^2.5.3", | ||
"uuid": "^8.3.0" | ||
"uuid": "^8.3.0", | ||
"fd-lock": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^13.13.1", | ||
"@types/jest": "^27.0.2", | ||
"@types/node": "^14.14.35", | ||
"@typescript-eslint/eslint-plugin": "^4.12.0", | ||
@@ -49,8 +53,10 @@ "@typescript-eslint/parser": "^4.12.0", | ||
"eslint-config-prettier": "^7.1.0", | ||
"eslint-plugin-import": "^2.25.2", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"jest": "^26.6.3", | ||
"jest": "^27.2.5", | ||
"jest-mock-process": "^1.4.0", | ||
"node-gyp-build": "4.2.3", | ||
"pkg": "5.3.0", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.4.4", | ||
"ts-jest": "^27.0.5", | ||
"ts-node": "^9.1.1", | ||
@@ -57,0 +63,0 @@ "tsconfig-paths": "^3.9.0", |
@@ -31,3 +31,5 @@ # TypeScript-Demo-Lib | ||
```sh | ||
docker load --input "$(nix-build ./release.nix --attr docker)" | ||
loaded="$(docker load --input "$(nix-build ./release.nix --attr docker)")" | ||
image="$(cut -d' ' -f3 <<< "$loaded")" | ||
docker run -it "$image" | ||
``` | ||
@@ -85,20 +87,2 @@ | ||
#### VSCode Path Aliases | ||
VSCode cannot follow path aliases in our tests due to | ||
https://github.com/microsoft/vscode/issues/94474. | ||
To resolve this, add `./tests/**/*` into the `tsconfig` `include` section: | ||
```json | ||
"include": [ | ||
"./src/**/*", | ||
"./tests/**/*' | ||
] | ||
``` | ||
This will however make `tsc` build the `tests` into the `dist` output. | ||
**Therefore this fix should only be done in your own workspace, do not commit or push this change up.** | ||
### Native Module Toolchain | ||
@@ -105,0 +89,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
37017
5
18
35
247
168
1
1
+ Addedfd-lock@^1.2.0
+ Addedfd-lock@1.2.0(transitive)
+ Addednapi-macros@2.2.2(transitive)