-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ESM wip * wip * wip * 0.27.1 * wip * wip * 0.27.2 * conect CJS to ESM, oh my god! * 0.27.3 * fix npm pack & smoke testing * ESM support done * 0.27.4
- Loading branch information
Showing
43 changed files
with
436 additions
and
214 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare const codeRoot: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
||
test('CJS: codeRoot()', async t => { | ||
t.ok(codeRoot, 'should exist codeRoot') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Huan(202108) | ||
* | ||
* Re-exporting namespace declarations in ES6 ambient declaration #4336 | ||
* https://github.com/microsoft/TypeScript/issues/4336 | ||
*/ | ||
|
||
/** | ||
* Huan(202108): I want to `declare namespace puppet {...}` | ||
* but it seemss the `export * from '../generated/...js` is not working | ||
* | ||
* So I export them on the top level, | ||
* then import them in another `puppet.js` file | ||
* with the `puppet` namespace | ||
* | ||
* This is because the ESM module system need to do the following things | ||
* when import a CJS module: | ||
* | ||
* ```ts | ||
* import pkg from './cjs-pkg' | ||
* const puppet = pkg['puppet'] | ||
* ``` | ||
*/ | ||
export * from '../generated/wechaty/puppet/base_pb' | ||
export * from '../generated/wechaty/puppet/contact_pb.js' | ||
export * from '../generated/wechaty/puppet/event_pb.js' | ||
export * from '../generated/wechaty/puppet/file_box_pb.js' | ||
export * from '../generated/wechaty/puppet/friendship_pb.js' | ||
export * from '../generated/wechaty/puppet/message_pb.js' | ||
export * from '../generated/wechaty/puppet/room_invitation_pb.js' | ||
export * from '../generated/wechaty/puppet/room_member_pb.js' | ||
export * from '../generated/wechaty/puppet/room_pb.js' | ||
export * from '../generated/wechaty/puppet/tag_pb.js' | ||
|
||
export * from '../generated/wechaty/puppet_grpc_pb.js' | ||
export * from '../generated/wechaty/puppet_pb.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const pkgs = [ | ||
'../generated/wechaty/puppet/base_pb.js', | ||
'../generated/wechaty/puppet/contact_pb.js', | ||
'../generated/wechaty/puppet/event_pb.js', | ||
'../generated/wechaty/puppet/file_box_pb.js', | ||
'../generated/wechaty/puppet/friendship_pb.js', | ||
'../generated/wechaty/puppet/message_pb.js', | ||
'../generated/wechaty/puppet/room_invitation_pb.js', | ||
'../generated/wechaty/puppet/room_member_pb.js', | ||
'../generated/wechaty/puppet/room_pb.js', | ||
'../generated/wechaty/puppet/tag_pb.js', | ||
|
||
'../generated/wechaty/puppet_grpc_pb.js', | ||
'../generated/wechaty/puppet_pb.js', | ||
] | ||
|
||
/** | ||
* Huan(202108): | ||
* if there's a "package.json" file in the `generated/` directory, | ||
* then all the files in the `generated/` directory will be treated as one module, | ||
* which means tht `require` each file under that directory will add methods to the same module. | ||
*/ | ||
// for (const pkg of pkgs) { | ||
// console.info('## pkg:', pkg) | ||
// const module = require(pkg) | ||
// console.info(Object.keys(module).length) | ||
// // OOPS! The output number above will be keep increasing | ||
// } | ||
|
||
module.exports = pkgs.reduce((acc, pkg) => ({ | ||
...acc, | ||
...require(pkg), | ||
}), {}) // Huan(202108): must provide a `{}` as the initial value, or it will be `[]` | ||
|
||
// for (const m of Object.keys(module.exports)) { | ||
// console.info(m) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env -S ts-node --project tsconfig.cjs.json | ||
|
||
import { test } from 'tstest' | ||
|
||
import * as puppet from './generated.js' | ||
|
||
test('CJS: "EventRequest"', async t => { | ||
t.ok(puppet.EventRequest, 'should export EventRequest') | ||
}) | ||
|
||
test('CJS: "PuppetService"', async t => { | ||
t.ok(puppet.PuppetService, 'should export PuppetSevice') | ||
}) | ||
|
||
test('CJS: "PuppetService"', async t => { | ||
const map: puppet.EventTypeMap = {} as any | ||
map.EVENT_TYPE_DIRTY = puppet.EventType.EVENT_TYPE_DIRTY | ||
t.equal(Object.keys(map).length, 1, 'should export type EventTypeMap') | ||
}) | ||
|
||
test('CJS: DingRequest', async t => { | ||
t.ok(puppet.DingRequest, 'should exists "DingRequest"') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "type": "commonjs" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * as puppet from './generated.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
puppet: require('./generated.js') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env -S ts-node --project tsconfig.cjs.json | ||
|
||
import { test } from 'tstest' | ||
|
||
import { puppet } from './puppet.js' | ||
|
||
test('CJS: EventRequest', async t => { | ||
t.ok(puppet.EventRequest, 'should export EventRequest') | ||
}) | ||
|
||
test('CJS: PuppetService', async t => { | ||
t.ok(puppet.PuppetService, 'should export PuppetSevice') | ||
}) | ||
|
||
test('CJS: EventTypeMap', async t => { | ||
const map: puppet.EventTypeMap = {} as any | ||
map.EVENT_TYPE_DIRTY = puppet.EventType.EVENT_TYPE_DIRTY | ||
t.equal(Object.keys(map).length, 1, 'should export type EventTypeMap') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.