Skip to content
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

feat(create-jest): Add npm init / yarn create initialiser #14453

Merged
merged 28 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
30e957f
feat(create-jest): Add `npm init` / `yarn create` initialiser
dj-stormtrooper Aug 27, 2023
5b580b1
fix: Updated `yarn.lock`
dj-stormtrooper Aug 27, 2023
e804edb
feat: Add typescript API
dj-stormtrooper Aug 27, 2023
546db25
fix: Prettier error
dj-stormtrooper Aug 27, 2023
e503b28
Merge branch 'main' of github.com:dj-stormtrooper/jest into feat/crea…
dj-stormtrooper Aug 30, 2023
0ffab46
feat: Move config initialisation logic to `create-jest` package
dj-stormtrooper Aug 30, 2023
df988bf
fix: Eslint errors
dj-stormtrooper Aug 30, 2023
92db787
feat: Add `rootDir` to `create-jest` CLI API
dj-stormtrooper Aug 30, 2023
66384ac
fix: Typesafe values operators for `create-jest` package
dj-stormtrooper Aug 30, 2023
e8d2043
fix: Extra diff
dj-stormtrooper Aug 30, 2023
d160788
fix: Remove redundant file
dj-stormtrooper Aug 30, 2023
c9b4ecb
Update packages/create-jest/src/runCreate.ts
dj-stormtrooper Aug 31, 2023
b126c72
fix: Shortcut for nullable values check
dj-stormtrooper Aug 31, 2023
7b366be
chore: Add `create-jest` to typecheck tests configuration
dj-stormtrooper Aug 31, 2023
0e9aed8
fix: Remove unnecessary type declaration
dj-stormtrooper Aug 31, 2023
48b3d1d
fix: Remove unnecessary `local` check
dj-stormtrooper Aug 31, 2023
bbae051
fix: Remove `bin` from exports
dj-stormtrooper Aug 31, 2023
0b4ea0f
fix: Remove extra CLI interface
dj-stormtrooper Aug 31, 2023
8fe5b8d
fix: Restore `bin` export
dj-stormtrooper Aug 31, 2023
810fec8
Merge branch 'feat/create-jest-package' of github.com:dj-stormtrooper…
dj-stormtrooper Aug 31, 2023
513ad24
fix: New package name in error message
dj-stormtrooper Sep 2, 2023
dedea5f
docs: Add `create-jest` usage
dj-stormtrooper Sep 2, 2023
8ae6c55
fix: More generic error message for malformed json in `create-jest`
dj-stormtrooper Sep 2, 2023
8ca2c6a
Merge branch 'main' into feat/create-jest-package
dj-stormtrooper Sep 7, 2023
77adb36
docs: Add `create-jest` to the changelog
dj-stormtrooper Sep 7, 2023
0dcf317
Update packages/create-jest/src/generateConfigFile.ts
SimenB Sep 7, 2023
cc0e430
purdy
SimenB Sep 7, 2023
9e3ddfa
strict
SimenB Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/create-jest/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**/__mocks__/**
**/__tests__/**
__typetests__
src
tsconfig.json
tsconfig.tsbuildinfo
api-extractor.json
.eslintcache
11 changes: 11 additions & 0 deletions packages/create-jest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# create-jest

> Getting started with Jest with a single command

```bash
npm init jest@latest
# Or for Yarn
yarn create jest
# Or for pnpm
pnpm dlx create-jest
```
13 changes: 13 additions & 0 deletions packages/create-jest/bin/create-jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const importLocal = require('import-local');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. import-local is not included in dependencies list?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not so sure if import-local is needed in this case. It does not make sense installing create-jest locally. To be honest, I don’t understand what import-local does ;D So it can be I missed something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with removing that, local installation indeed seems strange in this case


if (!importLocal(__filename)) {
require('jest-cli').run(['--init']);
}
31 changes: 31 additions & 0 deletions packages/create-jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "create-jest",
"description": "Create a new Jest project",
"version": "29.6.4",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
"directory": "packages/create-jest"
},
"license": "MIT",
"bin": "./bin/create-jest.js",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"exports": {
".": {
"types": "./build/index.d.ts",
"default": "./build/index.js"
},
"./package.json": "./package.json",
"./bin/create-jest": "./bin/create-jest.js"
SimenB marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {
"jest-cli": "workspace:^"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that the whole Jest with all its dependencies will be pulled? Or? I would expect the create- package to be a lightweight script. Did I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it makes sense to move the whole logic to the new package and deprecate the --init flag in Jest 30?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that the whole Jest with all its dependencies will be pulled? Or? I would expect the create- package to be a lightweight script. Did I miss something?

I was thinking about standardised global wrapper for the initialisation (adapter for npx jest --init). For this purpose whole jest-cli is not necessary indeed.

Perhaps it makes sense to move the whole logic to the new package and deprecate the --init flag in Jest 30?

Sounds fine, or maybe we can reverse the dependencies and use create-jest inside jest-cli to keep the API the same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case create-jest would get shipped with jest. I was thinking a new package like @jest/init could be introduced, but that requires major release as well. Other question, is there a need to have the --init command if create-jest gets introduced? By the way, moving the whole --init logic to create-jest would make jest leaner (e.g. only create-jest would ship prompts as dependency, if I didn’t miss something).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more idea, I think for now it would be fine to copy the code to create-jest and in jest-cli it could be marked with // TODO Remove in Jest 30 comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. It can reused, I agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To summarize: in addition to this

  • This PR will move the entirety of the --init command implementation into this new package
  • jest-cli will then have a dependency on create-jest, and delegate to it when jest --init is called
  • A separate PR will be prepared for v30 (I'll add it to the milestone so we don't forget) which deprecates --init and removes the dependency

we are also adding [rootPath] to JS and CLI API, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are also adding [rootPath] to JS and CLI API, right?

How do you feel? I find it useful, but can be implemented later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that's fine. --init will default to process.cwd(), but I do think it makes sense as part of the API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel? I find it useful, but can be implemented later.

I also find it useful, makes sense to do it here I think, it's not that hard

},
"engines": {
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
},
"publishConfig": {
"access": "public"
}
}
10 changes: 10 additions & 0 deletions packages/create-jest/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {run as runCLI} from 'jest-cli';

export const run = (): Promise<void> => runCLI(['--init']);
9 changes: 9 additions & 0 deletions packages/create-jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
},
"include": ["./src/**/*"],
"references": [{"path": "../jest-cli"}]
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8021,6 +8021,16 @@ __metadata:
languageName: node
linkType: hard

"create-jest@workspace:packages/create-jest":
version: 0.0.0-use.local
resolution: "create-jest@workspace:packages/create-jest"
dependencies:
jest-cli: "workspace:^"
bin:
create-jest: ./bin/create-jest.js
languageName: unknown
linkType: soft

"create-require@npm:^1.1.0":
version: 1.1.1
resolution: "create-require@npm:1.1.1"
Expand Down