Skip to content

Commit

Permalink
ESM & TypeScript 4.4 wip (#16)
Browse files Browse the repository at this point in the history
* ESM & TypeScript 4.4 wip

* clean & fix scripts (dist copy

* 0.13.5

* 0.15.1

* use script for cjs file

* 0.15.2

* fix unit tests

* 0.15.3

* Enable VM ESM loading for sidecar-dump util (#17)

* 0.15.4

* code clean

* fix pack testing & typo

* 0.15.5

* fix import url under windows

* 0.15.6

* use es6 for pack testing

* 0.15.7

* test

* 0.15.8

* fix windows file url path

* clean

* 0.15.9

* clean

* 0.15.10
  • Loading branch information
huan committed Sep 4, 2021
1 parent e0f11f8 commit 6f76ec1
Show file tree
Hide file tree
Showing 140 changed files with 927 additions and 752 deletions.
File renamed without changes.
62 changes: 13 additions & 49 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ jobs:
- ubuntu-latest
# - macos-latest
- windows-latest
node: [10, 11, 12, 13, 14, 15, 16]
node:
- 14
- 16
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install
Expand All @@ -35,13 +39,16 @@ jobs:
- ubuntu-latest
# - macos-latest
- windows-latest
node: [14, 16]
node:
- 16
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
cache: 'npm'
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install
Expand All @@ -52,51 +59,6 @@ jobs:
- name: Pack Testing
run: ./scripts/npm-pack-testing.sh

publishGitHub:
if: github.event_name == 'pushXXX' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/v'))
name: Publish to GitHub Packages
needs: [build, pack]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
registry-url: https://npm.pkg.github.com/

- name: Install Dependencies
run: npm install

- name: Generate Version
run: ./scripts/generate-version.sh

- name: Set Publish Config
run: ./scripts/package-publish-config-tag.sh

- name: Build Dist
run: npm run dist

- name: Check Branch
id: check-branch
run: |
if [[ ${{ github.ref }} =~ ^refs/heads/(main|v[0-9]+\.[0-9]+.*)$ ]]; then
echo ::set-output name=match::true
fi # See: https://stackoverflow.com/a/58869470/1123955
- name: Is A Publish Branch
if: steps.check-branch.outputs.match == 'true'
run: |
NAME=$(npx pkg-jq -r .name)
VERSION=$(npx pkg-jq -r .version)
if npx version-exists "$NAME" "$VERSION"
then echo "$NAME@$VERSION exists on NPM, skipped."
else npm publish
fi
env:
NODE_AUTH_TOKEN: ${{ github.token }}
- name: Is Not A Publish Branch
if: steps.check-branch.outputs.match != 'true'
run: echo 'Not A Publish Branch'

publish:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/v'))
name: Publish to NPM
Expand All @@ -106,8 +68,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
registry-url: https://registry.npmjs.org/
cache: 'npm'
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install
Expand Down
4 changes: 0 additions & 4 deletions .npmignore

This file was deleted.

8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,7 @@ I have another NPM module named [ffi-adapter](https://github.com/huan/ffi-adapte

Learn more about FFI from its examples at <https://github.com/huan/ffi-adapter/tree/master/tests/fixtures/library>

##

## Badge

[![Powered by Sidecar](https://img.shields.io/badge/Powered%20By-Sidecar-brightgreen.svg)](https://github.com/huan/sidecar)

Expand All @@ -582,7 +581,10 @@ You can visit them at [Sidecar Demos](https://github.com/wechaty/sidecar-demos)

## History

### Master
### Master v0.15

1. ES Modules support ([#17](https://github.com/huan/sidecar/issues/17))
1. TypeScript version 4.4

### v0.14

Expand Down
81 changes: 0 additions & 81 deletions bin/post-install.js

This file was deleted.

25 changes: 14 additions & 11 deletions bin/sidecar-dump.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env node --experimental-vm-modules
/**
* https://github.com/huan/sidecar
*
Expand All @@ -16,26 +16,29 @@ import {
run,
subcommands,
} from 'cmd-ts'
import {
REGISTER_INSTANCE,
} from 'ts-node'
// import {
// REGISTER_INSTANCE,
// } from 'ts-node'

import { VERSION } from '../src/version'
import { log } from '../src/config'
import { VERSION } from '../src/version.js'
// import { log } from '../src/config.js'

import {
metadata,
source,
} from '../src/dump/mod'
} from '../src/dump/mod.js'

/**
* Check ts-node loaded or not
* See: https://github.com/TypeStrong/ts-node/blob/5643ad64cf39ee0dfa2a9323e8d1dd9f400e5884/src/index.ts#L54-L68
*
* Update:
* - Huan(202109): We enable ESM
*/
if (!process[REGISTER_INSTANCE]) {
log.verbose('sidecar-dump', 'Loading `ts-node/register`...')
require('ts-node/register')
}
// if (!process[REGISTER_INSTANCE]) {
// log.verbose('sidecar-dump', 'Loading `ts-node/register`...')
// require('ts-node/register')
// }

const sidecarDump = subcommands({
name: 'sidecar-dump',
Expand Down
10 changes: 10 additions & 0 deletions commonjs/code-root.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path')

const codeRoot = path.join(
__dirname,
'..',
)

module.exports = {
codeRoot,
}
1 change: 1 addition & 0 deletions commonjs/code-root.cjs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const codeRoot: string
9 changes: 9 additions & 0 deletions commonjs/code-root.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env -S ts-node --project tsconfig.cjs.json

import { test } from 'tstest'

import { codeRoot } from './code-root.cjs'

test('CJS: codeRoot()', async t => {
t.ok(codeRoot, 'should exist codeRoot')
})
1 change: 1 addition & 0 deletions commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "commonjs" }
6 changes: 3 additions & 3 deletions examples/archive/raw-events/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { log } from 'brolog'

import { SidecarFridaPayload } from './schema'
import type { SidecarFridaPayload } from './schema.js'

log.level('verbose')
log.verbose('Agent', 'Entered')
Expand Down Expand Up @@ -42,8 +42,8 @@ Interceptor.attach(
MT_ADDR,
{
onEnter: args => {
log.silly('Agent', 'Interceptor.attach() onEnter(%s)', args[0].readUtf8String())
const content = args[0].readUtf8String()
log.silly('Agent', 'Interceptor.attach() onEnter(%s)', args[0]!.readUtf8String())
const content = args[0]!.readUtf8String()
const payload: SidecarFridaPayload = {
args: {
0: content,
Expand Down
2 changes: 1 addition & 1 deletion examples/archive/raw-events/frida.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from 'frida'
export {
export type {
ScriptMessageHandler,
ScriptDestroyedHandler,
} from 'frida/dist/script'
8 changes: 4 additions & 4 deletions examples/archive/raw-events/messaging-sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { EventEmitter } from 'events'
import { log } from 'brolog'

import * as frida from './frida'
import { SidecarFridaPayload } from './schema'
import { loadAgentSource } from './load-agent-source'
import type { SidecarFridaPayload } from './schema.js'
import { loadAgentSource } from './load-agent-source.js'

class MessagingSidecar extends EventEmitter {

Expand Down Expand Up @@ -44,7 +44,7 @@ class MessagingSidecar extends EventEmitter {
throw new Error('stop() this.script is undefined!')
}

await this.script.exports.init()
await this.script.exports['init']!()
}

public async stop () {
Expand Down Expand Up @@ -125,7 +125,7 @@ class MessagingSidecar extends EventEmitter {
log.verbose('MessagingSidecar', 'mo(%s)', content)

try {
await this.script!.exports.mo('MessagingSidebar: new messsage send by script.exports.mo()')
await this.script!.exports['mo']!('MessagingSidebar: new messsage send by script.exports.mo()')
} catch (e) {
console.error(e)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/archive/raw-events/sidecar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from 'brolog'

import { MessagingSidecar } from './messaging-sidecar'
import { MessagingSidecar } from './messaging-sidecar.js'

log.level('verbose')

Expand Down
4 changes: 2 additions & 2 deletions examples/archive/raw/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Interceptor.attach(
MT_ADDR,
{
onEnter: args => {
log.verbose('Agent', 'Interceptor.attach() onEnter(%s)', args[0].readUtf8String())
log.verbose('Agent', 'Interceptor.attach() onEnter(%s)', args[0]!.readUtf8String())
send({
payload: {
content: args[0].readUtf8String(),
content: args[0]!.readUtf8String(),
},
type: 'MT_MESSAGE',
})
Expand Down
4 changes: 2 additions & 2 deletions examples/archive/raw/clean.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
import type {
Session,
Script,
} from './frida'
} from './frida.js'
import { log } from 'brolog'

function clean (
Expand Down
2 changes: 1 addition & 1 deletion examples/archive/raw/frida.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from 'frida'
export {
export type {
ScriptMessageHandler,
ScriptDestroyedHandler,
} from 'frida/dist/script'
2 changes: 1 addition & 1 deletion examples/archive/raw/script-destroyed-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScriptDestroyedHandler } from './frida'
import type { ScriptDestroyedHandler } from './frida.js'
import { log } from 'brolog'

const scriptDestroyedHandler: ScriptDestroyedHandler = () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/archive/raw/script-message-handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ScriptMessageHandler,
MessageType,
} from './frida'
} from './frida.js'
import { log } from 'brolog'

const scriptMessageHandler: ScriptMessageHandler = (message, data) => {
Expand Down
Loading

0 comments on commit 6f76ec1

Please sign in to comment.