build: improved publish script, fixed imports/exports, added note about private repo
This commit is contained in:
parent
e02763dcdd
commit
ffafb3e5db
10 changed files with 60 additions and 24 deletions
1
.npmrc
Normal file
1
.npmrc
Normal file
|
@ -0,0 +1 @@
|
|||
@mtcute:registry=https://npm.tei.su
|
12
README.md
12
README.md
|
@ -25,6 +25,18 @@ Work-in-progress library for MTProto in TypeScript.
|
|||
> If you encounter errors related to storage, either
|
||||
> reset your storage by removing the file, or fix it manually.
|
||||
|
||||
## Installation
|
||||
|
||||
MTCute is currently only published in my private NPM registry.
|
||||
|
||||
You can install it by running:
|
||||
|
||||
```bash
|
||||
npm config set --location project @mtcute:registry https://npm.tei.su
|
||||
|
||||
npm install @mtcute/node # or any other package
|
||||
```
|
||||
|
||||
## Setting up for development:
|
||||
|
||||
```bash
|
||||
|
|
|
@ -4,5 +4,4 @@ import { randomBytes } from 'crypto'
|
|||
/** @internal */
|
||||
export const _defaultCryptoProviderFactory = () => new NodeCryptoProvider()
|
||||
|
||||
/** @internal */
|
||||
export const _randomBytes = randomBytes
|
||||
|
|
|
@ -4,7 +4,6 @@ import { typedArrayToBuffer } from '../buffer-utils'
|
|||
/** @internal */
|
||||
export const _defaultCryptoProviderFactory = () => new ForgeCryptoProvider()
|
||||
|
||||
/** @internal */
|
||||
export function _randomBytes(size: number): Buffer {
|
||||
const ret = new Uint8Array(size)
|
||||
crypto.getRandomValues(ret)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"name": "@mtcute/crypto-node",
|
||||
"version": "1.0.0",
|
||||
"description": "Native crypto implementation for NodeJS",
|
||||
"author": "Alisa Sireneva <me@tei.su>",
|
||||
"main": "src/index.ts",
|
||||
"private": true,
|
||||
"license": "LGPL-3.0",
|
||||
|
|
|
@ -10,9 +10,11 @@ import {
|
|||
tl,
|
||||
throttle,
|
||||
Logger,
|
||||
TlBinaryReader,
|
||||
TlReaderMap,
|
||||
TlWriterMap,
|
||||
} from '@mtcute/core'
|
||||
import sqlite3 from 'better-sqlite3'
|
||||
import { TlBinaryReader, TlReaderMap, TlWriterMap } from '../tl-runtime'
|
||||
|
||||
// todo: add testMode to "self"
|
||||
|
||||
|
|
9
packages/tl-runtime/README.md
Normal file
9
packages/tl-runtime/README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# @mtcute/tl-runtime
|
||||
|
||||
This package contains runtime for TL (de-)serialization.
|
||||
It only contains binary reader and writer implementations,
|
||||
and is used by `@mtcute/core`.
|
||||
|
||||
`@mtcute/tl-utils` on the other hand has utilities like codegen
|
||||
and schema manipulation, which is only needed at runtime if you
|
||||
are patching the schema (which is a rare case anyways).
|
|
@ -4,8 +4,7 @@
|
|||
"outDir": "./dist"
|
||||
},
|
||||
"include": [
|
||||
"./src/reader.ts",
|
||||
"./src/writer.ts",
|
||||
"./src",
|
||||
],
|
||||
"typedocOptions": {
|
||||
"name": "@mtcute/tl-runtime",
|
||||
|
@ -14,8 +13,7 @@
|
|||
"listInvalidSymbolLinks": true,
|
||||
"excludePrivate": true,
|
||||
"entryPoints": [
|
||||
"./src/reader.ts",
|
||||
"./src/writer.ts"
|
||||
"./src/index.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
3
packages/tl-utils/README.md
Normal file
3
packages/tl-utils/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# @mtcute/tl-utils
|
||||
|
||||
This package contains utilities for TL schema parsing and manipulation.
|
|
@ -20,13 +20,11 @@ function publishSinglePackage(name) {
|
|||
'binary/rsa-keys.js',
|
||||
'binary/writer.d.ts',
|
||||
'binary/writer.js',
|
||||
'errors.d.ts',
|
||||
'errors.js',
|
||||
'index.d.ts',
|
||||
'index.js',
|
||||
'raw-errors.json',
|
||||
'raw-schema.d.ts',
|
||||
'raw-schema.json',
|
||||
'mtp-schema.json',
|
||||
'api-schema.json',
|
||||
'package.json',
|
||||
'README.md',
|
||||
]
|
||||
|
@ -39,7 +37,7 @@ function publishSinglePackage(name) {
|
|||
} else {
|
||||
// build ts
|
||||
cp.execSync(
|
||||
'yarn run ' + (name === 'crypto-node' ? 'build-ts' : 'build'),
|
||||
'pnpm run ' + (name === 'crypto-node' ? 'build-ts' : 'build'),
|
||||
{
|
||||
cwd: dir,
|
||||
stdio: 'inherit',
|
||||
|
@ -56,15 +54,9 @@ function publishSinglePackage(name) {
|
|||
content = content.replace('/// <reference types="node" />', '')
|
||||
}
|
||||
|
||||
if (content.match(/@mtcute\/[a-z]+\/src/)) {
|
||||
if (content.match(/@mtcute\/[a-z-]+\/src/)) {
|
||||
changed = true
|
||||
content = content.replace(/(@mtcute\/[a-z]+)\/src/g, '$1')
|
||||
}
|
||||
|
||||
if (content.trim().match(/^export {};?$/)) {
|
||||
// no public exports, we can safely remove this module
|
||||
changed = false
|
||||
fs.unlinkSync(f)
|
||||
content = content.replace(/(@mtcute\/[a-z-]+)\/src/g, '$1')
|
||||
}
|
||||
|
||||
if (changed) fs.writeFileSync(f, content)
|
||||
|
@ -75,9 +67,9 @@ function publishSinglePackage(name) {
|
|||
let content = fs.readFileSync(f, 'utf8')
|
||||
let changed = false
|
||||
|
||||
if (content.match(/@mtcute\/[a-z]+\/src/)) {
|
||||
if (content.match(/@mtcute\/[a-z-]+\/src/)) {
|
||||
changed = true
|
||||
content = content.replace(/(@mtcute\/[a-z]+)\/src/g, '$1')
|
||||
content = content.replace(/(@mtcute\/[a-z-]+)\/src/g, '$1')
|
||||
}
|
||||
|
||||
if (changed) fs.writeFileSync(f, content)
|
||||
|
@ -192,9 +184,28 @@ function publishSinglePackage(name) {
|
|||
throw new Error(`${name}'s package.json does not contain "main"`)
|
||||
|
||||
// since "src" is compiled to "dist", we need to remove that prefix
|
||||
packJson.main = packJson.main.replace(/^(?:\.\/)?src\//, '')
|
||||
packJson.main = packJson.main
|
||||
.replace(/^(?:\.\/)?src\//, '')
|
||||
.replace(/\.ts$/, '.js')
|
||||
packJson.private = false
|
||||
|
||||
function replaceWorkspaceDependencies(field) {
|
||||
if (packJson[field]) {
|
||||
const dependencies = packJson[field]
|
||||
for (const name of Object.keys(dependencies)) {
|
||||
const value = dependencies[name]
|
||||
if (value.startsWith('workspace:')) {
|
||||
dependencies[name] = value.replace('workspace:', '')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
replaceWorkspaceDependencies('dependencies')
|
||||
replaceWorkspaceDependencies('devDependencies')
|
||||
replaceWorkspaceDependencies('peerDependencies')
|
||||
replaceWorkspaceDependencies('optionalDependencies')
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'dist/package.json'),
|
||||
JSON.stringify(packJson, null, 4)
|
||||
|
@ -225,7 +236,7 @@ function publishSinglePackage(name) {
|
|||
console.log('[i] Publishing %s', name)
|
||||
|
||||
// publish to npm
|
||||
cp.execSync('yarn publish', {
|
||||
cp.execSync('npm publish', {
|
||||
cwd: dir,
|
||||
stdio: 'inherit',
|
||||
})
|
||||
|
@ -243,6 +254,7 @@ if (require.main === module) {
|
|||
if (arg === 'all') {
|
||||
for (const f of fs.readdirSync(path.join(__dirname, '../packages'))) {
|
||||
if (LOCAL.indexOf(f) > -1) continue
|
||||
if (f[0] === '.') continue
|
||||
|
||||
publishSinglePackage(f)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue