{"id":21531900,"url":"https://github.com/matrixai/typescript-demo-lib","last_synced_at":"2025-07-05T05:03:22.512Z","repository":{"id":37486463,"uuid":"262218282","full_name":"MatrixAI/TypeScript-Demo-Lib","owner":"MatrixAI","description":"TypeScript Library Demo Project using Nix https://matrix.ai","archived":false,"fork":false,"pushed_at":"2023-06-28T09:14:16.000Z","size":1070,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":6,"default_branch":"staging","last_synced_at":"2025-04-08T23:13:26.414Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatrixAI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-08T03:31:20.000Z","updated_at":"2023-10-05T00:08:39.000Z","dependencies_parsed_at":"2025-04-10T00:31:02.103Z","dependency_job_id":null,"html_url":"https://github.com/MatrixAI/TypeScript-Demo-Lib","commit_stats":null,"previous_names":[],"tags_count":48,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2FTypeScript-Demo-Lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2FTypeScript-Demo-Lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2FTypeScript-Demo-Lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2FTypeScript-Demo-Lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatrixAI","download_url":"https://codeload.github.com/MatrixAI/TypeScript-Demo-Lib/tar.gz/refs/heads/staging","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248135567,"owners_count":21053710,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T02:18:05.381Z","updated_at":"2025-04-10T00:32:13.167Z","avatar_url":"https://github.com/MatrixAI.png","language":"Nix","readme":"# TypeScript-Demo-Lib\n\nstaging:[![pipeline status](https://gitlab.com/MatrixAI/open-source/TypeScript-Demo-Lib/badges/staging/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/TypeScript-Demo-Lib/commits/staging)\nmaster:[![pipeline status](https://gitlab.com/MatrixAI/open-source/TypeScript-Demo-Lib/badges/master/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/TypeScript-Demo-Lib/commits/master)\n\n## Installation\n\nNote that JavaScript libraries are not packaged in Nix. Only JavaScript applications are.\n\nBuilding the package:\n\n```sh\nnix-build -E '(import ./pkgs.nix {}).callPackage ./default.nix {}'\n```\n\nBuilding the releases:\n\n```sh\nnix-build ./release.nix --attr application\nnix-build ./release.nix --attr docker\nnix-build ./release.nix --attr package.linux.x64.elf\nnix-build ./release.nix --attr package.windows.x64.exe\nnix-build ./release.nix --attr package.macos.x64.macho\n```\n\nInstall into Nix user profile:\n\n```sh\nnix-env -f ./release.nix --install --attr application\n```\n\nInstall into Docker:\n\n```sh\nloaded=\"$(docker load --input \"$(nix-build ./release.nix --attr docker)\")\"\nimage=\"$(cut -d' ' -f3 \u003c\u003c\u003c \"$loaded\")\"\ndocker run -it \"$image\"\n```\n\n## Development\n\nRun `nix-shell`, and once you're inside, you can use:\n\n```sh\n# install (or reinstall packages from package.json)\nnpm install\n# build the dist\nnpm run build\n# run the repl (this allows you to import from ./src)\nnpm run ts-node\n# run the tests\nnpm run test\n# lint the source code\nnpm run lint\n# automatically fix the source\nnpm run lintfix\n```\n\n### Calling Executables\n\nWhen calling executables in development, use this style:\n\n```\nnpm run typescript-demo-lib -- p1 p2 p3\n```\n\nThe `--` is necessary to make `npm` understand that the parameters are for your own executable, and not parameters to `npm`.\n\n### Using the REPL\n\n```\n$ npm run ts-node\n\u003e import fs from 'fs';\n\u003e fs\n\u003e import { Library } from '@';\n\u003e Library\n\u003e import Library as Library2 from './src/lib/Library';\n```\n\nYou can also create test files in `./src`, and run them with `npm run ts-node ./src/test.ts`.\n\nThis allows you to test individual pieces of typescript code, and it makes it easier when doing large scale architecting of TypeScript code.\n\n### Path Aliases\n\nDue to https://github.com/microsoft/TypeScript/issues/10866, you cannot use path aliases without a bundler like Webpack to further transform the generated JavaScript code in order to resolve the path aliases. Because this is a simple library demonstration, there's no need to use a bundler. In fact, for such libraries, it is far more efficient to not bundle the code.\n\nHowever, we have left the path alias configuration in `tsconfig.json`, `jest.config.js` and in the tests we are making use of the `@` alias.\n\n### Local Package Linking\n\nWhen developing on multiple NPM packages, it can be easier to use `npm link` so that changes are immediately reflected rather than repeatedly publishing packages. To do this, you need to use `npm link`. After linking a local directory, you need to provide `tsconfig.json` paths so TypeScript compiler can find the right files.\n\nFor example when linking `@matrixai/db` located in `../js-db`:\n\n```sh\nnpm link ../js-db\n```\n\nYou would need to add these paths to `tsconfig.json`:\n\n```\n  \"paths\": {\n    \"@\": [\"index\"],\n    \"@/*\": [\"*\"],\n    \"@matrixai/db\": [\"../node_modules/@matrixai/db/src\"],\n    \"@matrixai/db/*\": [\"../node_modules/@matrixai/db/src/*\"]\n  },\n```\n\n### Native Module Toolchain\n\nThere are some nuances when packaging with native modules.\nIncluded native modules are level witch include leveldown and utp-native.\n\nIf a module is not set to public then pkg defaults to including it as bytecode.\nTo avoid this breaking with the `--no-bytecode` flag we need to add `--public-packages \"*\"`\n\n#### leveldown\n\nTo get leveldown to work with pkg we need to include the prebuilds with the executable.\nafter building with pkg you need to copy from `node_modules/leveldown/prebuilds` -\u003e `path_to_executable/prebuilds`\nYou only need to include the prebuilds for the arch you are targeting. e.g. for linux-x64 you need `prebuild/linux-x64`.\n\nThe folder structure for the executable should look like this.\n- linux_executable_elf\n- prebuilds\n  - linux-x64\n    - (node files)\n\n#### utp-native\n\nIncluding utp-native is simpler, you just need to add it as an asset for pkg.\nAdd the following lines to the package.json.\n```json\n\"pkg\": {\n    \"assets\": \"node_modules/utp-native/**/*\"\n  }\n```\n\n#### threads.js\n\nTo make sure that the worker threads work properly you need to include the compiled worker scripts as an asset.\nThis can be fixed by adding the following to `package.json`\n\n```json\n\"pkg\": {\n    \"assets\": \"dist/bin/worker.js\"\n  }\n```\n\nIf you need to include multiple assets then add them as an array.\n\n```json\n\"pkg\": {\n    \"assets\": [\n      \"node_modules/utp-native/**/*\",\n      \"dist/bin/worker.js\"\n    ]\n  }\n```\n\n### Docs Generation\n\n```sh\nnpm run docs\n```\n\nSee the docs at: https://matrixai.github.io/TypeScript-Demo-Lib/\n\n### Publishing\n\nPublishing is handled automatically by the staging pipeline.\n\nPrerelease:\n\n```sh\n# npm login\nnpm version prepatch --preid alpha # premajor/preminor/prepatch\ngit push --follow-tags\n```\n\nRelease:\n\n```sh\n# npm login\nnpm version patch # major/minor/patch\ngit push --follow-tags\n```\n\nManually:\n\n```sh\n# npm login\nnpm version patch # major/minor/patch\nnpm run build\nnpm publish --access public\ngit push\ngit push --tags\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixai%2Ftypescript-demo-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatrixai%2Ftypescript-demo-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixai%2Ftypescript-demo-lib/lists"}