jaredpalmer / tsdx Goto Github PK
View Code? Open in Web Editor NEWZero-config CLI for TypeScript package development
Home Page: https://tsdx.io
License: MIT License
Zero-config CLI for TypeScript package development
Home Page: https://tsdx.io
License: MIT License
Yeah that could work. I kinda prefer a prompt here cuz I can never remember the flags
Originally posted by @jaredpalmer in #5 (comment)
error is printed in the console, but the template is copied over to the existing directory
no files are copied over
I like having spec files right next to the source files.
Currently this is not achievable. Can we get a support for this style of filesystem organisation?
Tried dropping TSDX into an existing library, and got this:
> [email protected] build /Users/jasonetco/dev/actions-toolkit
> tsdx build
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
at assertPath (path.js:39:11)
at Object.resolve (path.js:1088:7)
at Object.exports.resolveApp (/Users/jasonetco/dev/actions-toolkit/node_modules/tsdx/dist/utils.js:19:27)
at Object.createRollupConfig (/Users/jasonetco/dev/actions-toolkit/node_modules/tsdx/dist/createRollupConfig.js:29:24)
at createBuildConfigs (/Users/jasonetco/dev/actions-toolkit/node_modules/tsdx/dist/index.js:30:30)
at prog.command.describe.action (/Users/jasonetco/dev/actions-toolkit/node_modules/tsdx/dist/index.js:130:37)
at Sade.parse (/Users/jasonetco/dev/actions-toolkit/node_modules/sade/lib/index.js:153:56)
at Object.<anonymous> (/Users/jasonetco/dev/actions-toolkit/node_modules/tsdx/dist/index.js:168:6)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
After some ๐ค, turns out it was expecting a "source"
property in my package.json
.
A handy-dandy error like:
Hey you need a `source` property in your package.json, pointing to the entrypoint of your library
Software | Version(s) |
---|---|
TSDX | v0.0.25 |
I'm following the README instructions, and it seems like they're geared towards tsdx
being an NPM script in an existing project?
$ cd ~/dev
$ yarn tsdx create my-lib
yarn run v1.13.0
error Couldn't find a package.json file in "/Users/jasonetco/dev"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I also tried yarn global add tsdx
and then running tsdx create my-lib
:
Error: /Users/jasonetco/dev/package.json: ENOENT: no such file or directory, open '/Users/jasonetco/dev/package.json'
This even happens when I run tsdx --version
.
I could be misunderstanding the tool, but I'm guessing this should scaffold out the folder? Not sure why it's trying to read an existing package.json
.
Software | Version(s) |
---|---|
npm/Yarn | npm: 6.4.1 yarn: 1.13.0 |
Operating System | MacOS Mojave |
rollup 1.0 was released in december: rollup/rollup#2293
including dynamic imports, which i want
any considerations that have held you back that we should think about?
After installing tsdx globally and creating a new project I ran npm test
and it prompts the following to console:
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\dev\hidash
13 files checked.
testMatch: C:/dev/hidash/test/**\?(*.)(spec|test).{ts,tsx} - 0 matches
testPathIgnorePatterns: \\node_modules\\ - 13 matches
testRegex: - 0 matches
Pattern: - 0 matches
Also when filtering for blah.test.ts
manually it won't show up.
To get the default test to run and pass after installing out of the box.
Software | Version(s) |
---|---|
TSDX | 0.5.4 |
TypeScript | as bundled |
Browser | (not involved) |
npm | 6.7.0 |
Operating System | Windows 10 |
$ npx tsdx create tsdx-test
$ cd tsdx-test && npm test
> [email protected] test /Users/jasonetco/dev/tsdx-test
> tsdx test
โ Validation Error:
Module /Users/jasonetco/dev/tsdx-test/node_modules/tsdx/node_modules/ts-jest in the transform option was not found.
<rootDir> is: /Users/jasonetco/dev/tsdx-test
Configuration Documentation:
https://jestjs.io/docs/configuration.html
npm ERR! Test failed. See above for more details.
Every module has its own .d.ts
module
Bundle the typedefs into a single .d.ts
module
process.env.*
transpiles as is
declared variable with prefix TLDX_*
transpiles to its values. Other vars transpiles as is
if .env
contents:
TLDX_KEY=key
KEY=blah-blah
then process.env.TLDX_KEY
transpiles to key
and process.env.KEY
transpiles to process.env.KEY
This is for my team. We building the package with opt-in features and some client-specific keys. Also, CRA and @vue/cli have this feature too.
tsdx create is just another cli command. However, it shares almost zero code with the other commands and in fact makes things harder for them since certain values like paths.js
are all undefined.
Split out the creation script into a separate package or isolate the code so that it does not interfere or cause headaches throughout the rest of the codebase
create-ts-project
package. Thanks to the create
prefix, it will work with yarn create
. So people will be able to enter yarn create ts-project
(instead of using npx).Errbody.
When running npx tsdx create myapp
, the installation fails with the error:
โ Created myapp
โ Failed to install dependencies
TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object
at validateString (internal/validators.js:125:11)
at normalizeSpawnArguments (child_process.js:399:3)
at Object.spawn (child_process.js:532:38)
at Object.module.exports [as default] (/Users/james.quigley/.npm/_npx/49155/lib/node_modules/tsdx/node_modules/execa/index.js:205:26)
at prog.version.command.describe.action (/Users/james.quigley/.npm/_npx/49155/lib/node_modules/tsdx/dist/index.js:172:30)
Should successfully generate the full template, install deps, etc.
Seems like a type error. Can investigate more later unless someone beats me to it
Software | Version(s) |
---|---|
TSDX | 0.5.0 |
TypeScript | |
Browser | |
npm/Yarn | 6.9/1.15.2 |
Operating System | MacOS Mojave |
My code isn't getting bundled because tsdx treats everything as external modules, the resulting bundle only contains the compiled index.ts
file.
My files shouldn't be treated as external modules.
Could it be something related to the external
function? https://github.com/palmerhq/tsdx/blob/v0.5.7/src/utils.ts#L19
I'm getting the following warning for all my .ts
files (except the root index.ts
file):
No name was provided for external module 'C:/xyz/xyz/xyz/xyz.ts' in output.globals โ guessing 'xyz_ts'
Software | Version(s) |
---|---|
TSDX | 0.5.7 |
TypeScript | 3.4.5 |
Browser | Chrome Version 74.0.3729.131 |
npm/Yarn | Node v10.11.0, npm 6.4.1 |
Operating System | Windows 10 |
tsdx
yarn test will report error:
TypeError: xxx.default is not a constructor
when import a class created by tsdx
and try to instance it.
reproduction:
tsdx
tsdx create mylib-a
class
// mylib-a/src/index.ts
export default class MyLibA {}
yarn build
tsdx
called mylib-b
mylib-a
to mylib-b/src/
mylib-a
in mylib-b/test/blah.test.ts
import MyLibA from '../src/mylib-a';
// this line is error when `yarn test`
// TypeError: xxx.default is not a constructor
const instance = new MyLibA();
If I don't use default
to export class:
export class MyLibA {}
And import like this:
import { MyLibA } from ...;
Everything will be ok, but it is just a workaround.
Software | Version(s) |
---|---|
TSDX | ^0.5.6 |
TypeScript | ^3.4.5 |
Browser | - |
npm/Yarn | [email protected] |
Operating System | macOS Mojave version 10.14.4 (18E226) |
See https://www.npmjs.com/package/rollup-plugin-prettier
We would run this on the dev builds so end consumers have an easier time debugging.
Use gluegun or oclif to clean stuff up (again)
eslint and prettier are the basic tools for any repo these days. You've got the issue for eslint, so I've thought I'd open up one for prettier too.
Skipping one of the module formats causes a warning about an unhandled promise rejection due to an invalid rollup config.
> tsdx build --format cjs,es
(node:94549) UnhandledPromiseRejectionWarning: Error: You must supply an options object to rollup
at getInputOptions$1 (/Users/jake/Desktop/mylib/node_modules/rollup/dist/rollup.js:18675:15)
at Object.rollup (/Users/jake/Desktop/mylib/node_modules/rollup/dist/rollup.js:18732:30)
at asyncro_1.default.map (/Users/jake/Desktop/mylib/node_modules/tsdx/dist/index.js:293:41)
at Array.map (<anonymous>)
at Object.n [as map] (/Users/jake/Desktop/mylib/node_modules/asyncro/dist/asyncro.js:1:100)
at prog.command.describe.option.example.option.example.option.example.option.example.action (/Users/jake/Desktop/mylib/node_modules/tsdx/dist/index.js:292:43)
(node:94549) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:94549) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
โ Creating entry file 3.5 secs
As far as I can tell, the build still succeeds though so this isn't a huge issue.
Ideally, the build would run without any warnings.
One possible solution would be to filter falsey values from the createBuildConfigs
call: #77
Thanks for the work you put into this!
Software | Version(s) |
---|---|
TSDX | 0.5.5 |
TypeScript | 3.4.5 |
Browser | Chrome |
npm/Yarn | npm 6.4.1 |
Operating System | MacOS 10.13.6 |
This was technically added in 0.3.0, but needs documentation. Additionally, we need to think through dev/prod builds for each output and if that is what people actually want or nah.
When running npx tsdx create mylib
, the installation fails with the error:
โ Created mylib
ร Failed to install dependencies
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
at assertPath (path.js:39:11)
at Object.normalize (path.js:285:5)
at parseNonShell (C:\Users\kevin\AppData\Roaming\npm-cache\_npx\12552\node_modules\tsdx\node_modules\execa\node_modules\cross-spawn\lib\parse.js:54:31)
at Function.parse [as _parse] (C:\Users\kevin\AppData\Roaming\npm-cache\_npx\12552\node_modules\tsdx\node_modules\execa\node_modules\cross-spawn\lib\parse.js:122:49)
at handleArgs (C:\Users\kevin\AppData\Roaming\npm-cache\_npx\12552\node_modules\tsdx\node_modules\execa\index.js:41:23)
at Object.module.exports [as default] (C:\Users\kevin\AppData\Roaming\npm-cache\_npx\12552\node_modules\tsdx\node_modules\execa\index.js:199:17)
at prog.version.command.describe.action (C:\Users\kevin\AppData\Roaming\npm-cache\_npx\12552\node_modules\tsdx\dist\index.js:172:30)
Should successfully generate the full template, install deps, etc.
I tried poking around in the code and can see that it's failing on
await execa(getInstallArgs(getInstallCmd(), deps));
As far as I can tell, it's trying to run via yarn on my machine.
Software | Version(s) |
---|---|
TSDX | 0.5.0 |
TypeScript | |
Browser | |
npm/Yarn | 6.4.1/1.13.0 |
Operating System | Windows 10 Pro (1809) |
nil
error code minification like React (https://reactjs.org/docs/error-decoder.html/) see also https://reactjs.org/blog/2016/07/11/introducing-reacts-error-code-system.html
develop babel plugin/macro to record and hash invariants and append new ones to an errors file. develop a small hosting solution to send people there.
tsdx users
I have an existing project that uses microbundle and I wanted to give this project a shot.
When I run tsdx build
I get this error, but the outputted dist
folder seems fine.
โฏ npx tsdx build
โ Creating entry file 2.1 secs
(node:7935) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'find' of undefined
at then.then (/home/z0al/x/github/stash/packages/core/node_modules/rollup-plugin-size-snapshot/dist/treeshakeWithRollup.js:67:36)
(node:7935) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7935) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
No errors
Software | Version(s) |
---|---|
TSDX | 0.5.4 |
TypeScript | 3.4.5 |
Browser | N/A |
npm/Yarn | npm |
Operating System | Debian/Linux |
When I run tsdx create mylib
I receive the following error:
Error: ENOENT: no such file or directory, stat '/usr/local/lib/node_modules/tsdx/templates/basic'
I'm not sure,I haven't gotten it to work yet ๐
N/A
I have seen other similar errors reported and they were marked as closed. Not sure why I'm having this issue.
Software | Version(s) |
---|---|
TSDX | 0.5.3 |
TypeScript | 3.4.5 |
Browser | Google Chrome |
npm/Yarn | 6.9.0 |
Operating System | 10.14.4 |
currently we bundle single files, named per environment/module format.
to support code splitting (which is the default behavior of Rollup v1 which we just upgraded to) we'll have to evolve this to a folder format with multiple files.
right now this https://github.com/sw-yx/react-netlify-identity-widget/blob/master/src/index.tsx#L8 doesnt produce a separate bundle for me :(
code splitting support.
as above
all users, partiuclarly React users, who want to offer code splitting as a feature
no change
i'm unsure what existing priorities this may conflict with for you.
~/dev/tsdx-test
$ npx tsdx create mylib
/Users/jasonetco/dev/tsdx-test/package.json: ENOENT: no such file or directory, open '/Users/jasonetco/dev/tsdx-test/package.json'
~/dev/tsdx-test
$ npm i -g tsdx
...
+ [email protected]
added 940 packages from 512 contributors in 24.628s
~/dev/tsdx-test took 25s 254ms
$ tsdx create mylib
โ Failed to create mylib
Error: ENOENT: no such file or directory, stat '/Users/jasonetco/.nvm/versions/node/v10.13.0/lib/node_modules/tsdx/template'
Possibly relates to #2
Software | Version(s) |
---|---|
TSDX | v0.0.25 |
Is not possible to use it with scss and module
Be able to use it as CRA
scss file: helloWorld.module.scss
ts: import style from "./helloWorld.module.scss"
Have a look on CRA and see how it works
All the developer that want to create a library with multiple modules and have support of scss
despite the recent improvements, tsdx still scaffolds to something like this:
{
"name": "podcats",
"version": "0.1.5",
"main": "dist/index.js",
"umd:main": "dist/podcats.umd.production.js",
"module": "dist/podcats.es.production.js",
"typings": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test"
},
"devDependencies": {
"@types/jest": "^23.3.13",
"tsdx": "^0.3.0",
"typescript": "^3.2.4",
}
}
in particular, i believe that "main": "dist/index.js",
is invalid.
as a result, the library builds, but when it is required into other apps, node resolution fails to find the library.
i may be wrong but i think it should point to "main": "dist/index.js",
The rollup output is wayyyyyy too verbose. Need to make it concise.
Currently the scaffolded package.json looks like this:
{
"source": "src/index.ts",
"main": "index.js",
"umd:main": "dist/podcats.umd.production.js",
"module": "dist/podcats.es.production.js",
"typings": "dist/index.d.ts",
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test"
},
"devDependencies": {
// etc
}
}
when i publish to npm, nothing in the dist
folder gets included. this could partially be because of the .gitignore (in which case we should add an .npmignore?) but i think the "main": "index.js",
line is also a problem. I'm quite inexperienced at this so i'm not sure how to fix but i'm sure you can.
i can just type 'yarn publish' at the root level and it "just works"
fix "main" field?
Software | Version(s) |
---|---|
TSDX | 0.2.5 |
TypeScript | 3.2.4 |
Browser | chrome |
System:
OS: macOS High Sierra 10.13.4
CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
Memory: 127.70 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 11.0.0 - /usr/local/bin/node
Yarn: 1.12.1 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Browsers:
Chrome: 71.0.3578.98
Safari: 11.1
Libraries should be using tslib
to eliminate duplicate code.
Also need "importHelpers": true
in the tsconfig.json
๐ In trying out this tool, I wanted to leave some general notes for you. Feel free to close this issue right away, or use it to spawn further issues - totally up to you.
Tiny thing in the generated package.json
:
Would be cool to supe up the bootstrap logs:
Adding some emojis, maybe some color?
โก๏ธ Bootstrapping new project...
๐ฆ Installing dependencies...
โ
Success! TSDX just bootstrapped a brand new project for you. To get started, run:
cd my-lib
yarn start
Potentially add a linter - its a hot topic, and I'm not sure how opinionated you want this tool to be. Maybe a section in the README? I mention it because to me, "out of the box" includes a linter - but it may not to other people so ๐คทโโ๏ธ
Generated README is a little bare which is totally fine, but it could be nice to add something like this: https://github.com/jasonetco/stub-template#readme
Now, off to try using it with a real project...
Thank you for this project!
I'm not sure if I missed or didn't understand something, but when choosing the react
template, react
& react-dom
are added as dev dependencies. When you then try to use a hook inside your library, you get a react-invalid-hook-call
error. It works fine when removing them as dev dependencies and running yarn
again.
Example:
export const Thing = () => {
const [fooBar, setFooBar] = React.useState('foo');
return (
<div onClick={() => setFooBar('bar')}>
the snozzberries taste like {fooBar}
</div>
);
};
I would expect the template to enable me to use hooks.
No idea if "just removing the dev dependencies" is the proper solution. It at least worked for me.
Software | Version(s) |
---|---|
TSDX | 0.5.4 |
TypeScript | 3.4.5 |
Browser | Chrome 74.0.3729.108 |
npm/Yarn | Yarn 1.12.3 |
Operating System | MacOS 10.14.4 |
npx tsdx -v
returns tsdx, 0.0.0
proper version
Software | Version(s) |
---|---|
TSDX | 0.3.0 |
TypeScript | 3.x |
Browser | chrome |
OS: macOS High Sierra 10.13.4
Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
Yarn: 1.12.1 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.13.0/bin/npm
here is my repo i'm working on https://github.com/sw-yx/react-netlify-identity-widget/tree/rollupProductionIssue
if you:
yarn build
yarn link
cd example
yarn && yarn link "react-netlify-identity"
yarn start
you will see this error:
however if you change the package.json to use the development versions:
it works!!
to me this indicates a rollup config issue.
the production output should work the same as development output
i think this could be a terser bug. or a setting that is incompatible with React.
here is the offending unexpected token - prettified for easier reading
i'm not sure what rollup setting caused this but it definitely only exists in the production build.
Software | Version(s) |
---|---|
TSDX | 0.3.4 |
TypeScript | 3.4.4 |
Browser | chrome |
npm/Yarn | yarn |
Operating System | osx |
When I set experimentalDecorators to true in tsconfig.json it works ok for files in "src", but it doesn't work for files in "test" (vscode marks decorators in red, but it works ok when running 'test')
When experimentalDecorators is set to true in tsconfig.json it should also be for vscode test files
Add a tsconfig.json file to the tests folder:
{
"extends": "../tsconfig.json",
"include": ["."]
}
with any other overrides that might be needed to make tests work and make jest use that one.
Libs that use experimental decorators
N/A
N/A
if i have a package named "react-netlify-identity-widget" and i run tsdx build on it, the package.json has these fields:
"umd:main": "dist/react-netlify-identity-widget.umd.production.js",
"module": "dist/react-netlify-identity-widget.es.production.js",
however the filenames are camelcase: reactNetlifyIdentityWidget.cjs.production.js
files should match up.
i'm actually not sure where the camelcasing pops up. took a quick look thru the code and couldnt find it.
maybe the super simple solution is to also camelcase the package.json naming. but probably the right solution is to preserve kebab case everywhere
Running tsdx create without having Yarn installed results in an error like this:
% npx tsdx create edzif-zz
โ Created edzif-zz
โ Failed to install dependencies
Error: spawn yarn ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
% yarn
zsh: command not found: yarn
tsdx's documentation could be read like it works with "plain npm", and thus I had expected it to work just having node
tsdx create
should work without Yarn.N/A
Software | Version(s) |
---|---|
TSDX | latest (using npx) |
TypeScript | N/A |
Browser | N/A |
npm/Yarn | 6.9.0 |
Operating System | macOS "Mojave" 14.4.0 |
No standardized commit messages or release process for created libraries.
yarn commit
with prompts and linting + yarn release
Something like conventional commits + git-cz + semantic release.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.