-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript + Tests + Namespaced npm package #7
Conversation
rollup has so much trouble with |
wait why is the main export a bundle |
dist tree getting a bit hairy
|
hell is empty and all the devils are here 👍 |
maybe hoping this gets fixed here nodejs/readable-stream#348 |
When I |
|
why no ci |
CI avalanche lol |
cool, just needs coverage tweaks |
I've created MetaMask/metamask-module-template#19 as an updated baseline for the CI workflow we're using here—once that's merged we can update this workflow to have a similar shape. I've also created #8, #9, #10, and #11, factoring out some of the extra changes from this PR. We can rebase this and drop those files to keep this changeset focused. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few initial comments—I'll check it out locally as well.
jest.config.js
Outdated
const merge = require('merge'); | ||
const tsPreset = require('ts-jest/jest-preset'); | ||
|
||
module.exports = merge.recursive(tsPreset, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manually merging our config with the preset, is that necessary? Looking at the configuration docs for ts-jest, the preset
key can be used.[1] Merging this manually also complicates this process as we both now have an extra dependency and a resolution process (i.e. how does merge.recursive
work? how many levels does it do? how does it treat the arrays?) to manage.
If we can get away with using preset: 'ts-jest'
, let use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this came from an earlier point where there were two presets, so i had to merge the presets manually. not needed any more 👍
package.json
Outdated
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/kumavis/post-message-stream.git" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file will need to be updated to keep some of the original metadata, that's still useful. I've updated it in #11.
}, | ||
"bugs": { | ||
"url": "https://github.com/kumavis/post-message-stream/issues" | ||
"@types/readable-stream": "^2.3.9", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this to the devDependencies and export Node.js types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readable-stream
is better because its semantically versioned, node ships breaking changes with its builtins
(if i understood)
tsconfig.json
Outdated
"allowJs": true, | ||
"allowSyntheticDefaultImports": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is allowJs
enabled? I noticed below we're also listing "./src/**/*.js"
as included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figure this out locally, we're not currently reading these files. See #7 (comment) for context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the js has been removed, this is no longer needed 👍
"build:compile": "yarn build:compile:esm && yarn build:compile:cjs", | ||
"build:compile:esm": "tsc --module ES6 --outDir ./dist/esm", | ||
"build:compile:cjs": "tsc --module UMD --outDir ./dist/cjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this locally, I'm not sure I follow what having two builds is for? Could we ship only the CommonJS version?
I'm also confused by the naming here, though maybe it's a typo: build:compile:cjs
is outputting UMD to the /cjs
? Should that be outputting CJS instead?
We could move these into tsconfig(.*).json
files, e.g.:
@@ -21,8 +21,8 @@
"build": "yarn run build:clean && yarn run build:compile && yarn run build:bundle",
"build:clean": "rm -rf ./dist && mkdir -p ./dist/esm && mkdir -p ./dist/cjs",
"build:compile": "yarn build:compile:esm && yarn build:compile:cjs",
- "build:compile:esm": "tsc --module ES6 --outDir ./dist/esm",
- "build:compile:cjs": "tsc --module UMD --outDir ./dist/cjs",
+ "build:compile:esm": "tsc --project tsconfig.es2015.json",
+ "build:compile:cjs": "tsc --project tsconfig.json",
"build:bundle": "browserify --standalone PostMessageStream ./dist/cjs/index.js > ./dist/bundle.js"
},
"license": "MIT",
With two config files: tsconfig.json
and tsconfig.es2015.json
:
@@ -4,17 +4,15 @@
"declaration": true,
"sourceMap": true,
"strict": true,
- "target": "es5",
+ "target": "ES5",
+ "module": "CommonJS",
"lib": [
"DOM",
"ES2016"
],
- "outDir": "./dist",
- "allowJs": true,
- "allowSyntheticDefaultImports": true
+ "outDir": "./dist/cjs"
},
"include": [
- "./src/**/*.ts",
- "./src/**/*.js"
+ "./src/**/*.ts"
]
-}
\ No newline at end of file
+}
@@ -0,0 +1,7 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "target": "ES2015",
+ "module": "ES2015"
+ }
+}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- i think we should build for both (cjs+esm), the ecosystem (node v14, agoric, etc) is trying to get everyone on to esm
- this setup is intended to be a hybrid package https://2ality.com/2019/10/hybrid-npm-packages.html
- umd includes cjs with little overhead, so figured why not. can go either way
- i like moving the config into project files 👍
package.json
Outdated
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "yarn build && yarn testOnly", | ||
"testOnly": "jest --runInBand", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the --runInBand
flag here?
"testOnly": "jest --runInBand", | |
"testOnly": "jest", |
The tests seem to pass without it, and the docs suggest it is a niche use case:
--runInBand, -i Run all tests serially in the current process
(rather than creating a worker pool of child
processes that run tests). This is sometimes
useful for debugging, but such use cases are
pretty rare. [boolean]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this reduces threads to 1 and is recommended for CI (also allows debugging with ndb)
package.json
Outdated
"jest": "^26.4.2", | ||
"merge": "^1.2.1", | ||
"ts-jest": "^26.3.0", | ||
"ts-node": "^9.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to remove this from the list, I don't think we're using it anywhere
|
10a6e73
to
ac44225
Compare
dan asked about compiling in parallel https://github.com/kimmobrunfeldt/concurrently |
I converted this to draft as I'm going to split up the work over a few different PRs. I will likely use the tests written here. |
Actually, I'll just close it. |
based on the metamask repo template, but halp test not passing