Skip to content

Commit

Permalink
Merge b6c438f into 266f314
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoBrusa committed May 31, 2023
2 parents 266f314 + b6c438f commit d535297
Show file tree
Hide file tree
Showing 53 changed files with 528 additions and 792 deletions.
7 changes: 7 additions & 0 deletions .changeset/eight-bats-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'modular-scripts': major
'@modular-scripts/workspace-resolver': major
---

Modular's workspace resolver now ignores a workspace if covered by a
.modularignore or .gitignore (.modularignore overrides .gitignore)
7 changes: 7 additions & 0 deletions .changeset/moody-mayflies-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'modular-scripts': major
---

Standardized lint and typecheck commands to bring them in line with other
modular selective behaviour. Now lints and typechecks non-modular packages by
default
7 changes: 7 additions & 0 deletions .changeset/spotty-hornets-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'create-modular-react-app': major
'eslint-config-modular-app': major
'modular-scripts': major
---

Dropped Node 14 support, added Node 20 support. Changed target to ES2017
4 changes: 0 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ packages/sample-esbuild-app
packages/sample-view
packages/sample-package

# created by tests in modular-views.macro
packages/view-1
packages/view-2

# Build output
/packages/**/build/
/packages/**/dist-cjs/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
node-version: ['14.18.0', '16.x', '18.x']
node-version: ['16.x', '18.x', '20.x']
yarn-version: ['1.22.19', '3.5.0']
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3.3.0
with:
node-version: '14.18.0'
node-version: '18.x'
registry-url: https://registry.npmjs.org/
cache: 'yarn'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3.3.0
with:
node-version: '14.18.0'
node-version: '18.x'
cache: 'yarn'

- name: 'Install Dependencies'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fail-fast: false
matrix:
os: [windows-latest]
node-version: ['14.18.0', '16.x', '18.x']
node-version: ['16.x', '18.x', '20.x']

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
node-version: ['14.18.0', '16.x', '18.x']
node-version: ['16.x', '18.x', '20.x']

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js 14
- name: Use Node.js 18
uses: actions/setup-node@v3.3.0
with:
node-version: 14
node-version: 18
cache: 'yarn'
- name: Install Dependencies
run: yarn --frozen-lockfile
Expand Down
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ packages/sample-renamable-depending-package
# example app
packages/esbuild-app

# created by tests in modular-views.macro
packages/view-1
packages/view-2
packages/scoped
packages/node-env-app


# Build output
/packages/*/build/
/packages/*/dist-cjs/
Expand Down
Empty file added .modularignore
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "non-modular-typecheckable",
"private": false,
"scripts": {
"typecheck": "echo 'non-modular-typecheckable was typechecked'"
},
"files": [
"dist",
"src"
],
"license": "UNLICENSED",
"main": "./dist/index.js",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import add from '../index';

test('it should add two numbers', () => {
expect(add(1, 2)).toBe(3);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function add(a: number, b: number): number {
return a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"include": ["src"],
"compilerOptions": {
"target": "es2018",
"outDir": "dist",
"lib": ["dom", "esnext"],
"declaration": true,
"moduleResolution": "node",
"sourceMap": true,
"strict": true,
"esModuleInterop": true
}
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = (api) => {
{
targets: {
// TODO: can we get this to read from package.json somehow..?
node: '14',
node: '16',
},
},
],
Expand Down
79 changes: 41 additions & 38 deletions docs/commands/lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,73 @@ parent: Commands
title: modular lint
---

# `modular lint [options] [regexes...]`

`modular lint` without arguments or options will check the diff between the
current branch and your remote origin default branch (i.e. `master` or `main`)
and only lint the `.ts`, `.tsx`, `.js`, `.jsx` files that have changes. When in
CI without arguments or options or when the `--all` option is provided, it will
lint the entire codebase. When `--staged` is provided, it will only lint the
files staged on git.

Alternatively, when it is invoked with one or more selective options
(`--packages`, `--ancestors`, `--descendants` or `--changed`), it will lint all
the source code files in the provided `--packages`, optionally agumenting the
set of packages by adding their ancestors (`--ancestors`), their descendants
# `modular lint [options] [packages...]`

`modular lint` without arguments or options will lint all modular packages in
the repository, and run any `lint` scripts specified in the `package.json` of
any non-modular packages.

`--diff` will check the diff between the current branch and your remote origin
default branch (i.e. `master` or `main`) and only lint the `.ts`, `.tsx`, `.js`,
`.jsx` files that have changes. When `--staged` is provided, it will only lint
the files staged on git.

Alternatively, when it is invoked with one or more selective options (packages
provided, `--ancestors`, `--descendants` or `--changed`), it will lint all the
source code files in the provided packages, optionally agumenting the set of
packages by adding their ancestors (`--ancestors`), their descendants
(`--descendants`) or the files that have changed (`--changed`), calculated
comparing the current state of the git repository with the branch specified by
`--compareBranch` or, if `--compareBranch` is not set, with the default branch.
Non modular packages will also be linted if they have a `lint` script specified
in their `package.json`.

It uses your project eslint config to lint and jest runner to report on the lint
status of each file (`PASS` or `FAIL`). If a file has a lint warning, the
command will be marked as failed, with printed eslint errors for each
warning/error.

## Default behaviour

`modular lint` without arguments or options will:
## Default behavior

- default to lint the `git diff` between the current branch and the remote
origin's default branch when not in CI
- default to lint everything (essentially like `--all`) when in CI
`modular lint` without arguments or options will lint all packages in the
repository, and run any `lint` scripts specified in the `package.json` of any
non-modular packages.

## Options:
### Lint Unique Options:

`--all`: Lints the entire codebase (not compatible with `--staged` and with the
Selective Options)

`--staged`: Lints only files staged on git (not compatible with `--all` and with
the Selective Options)
These options are unique to the lint command and differ to other Modular command
options.

`--fix`: Allows eslint to fix the errors and warnings that do not require manual
intervention wherever possible. Restages any fixed files that were previously
staged when used in combination with `--staged`.
staged when used in combination with `--staged`. Can be combined with any other
option.

`--includeNonModular`: Allows modular to run the `lint` script of non Modular
packages included in the selection, if one is provided in the package's
package.json
`--compareBranch <branch>`: Specify the comparison branch used to determine
which files have changed when using the `changed` or `diff` option. If this
option is used without `changed` or `diff`, the command will fail.

### Selective Options
The following options are not compatible with selective options, and cannot be
combined with each other.

`--packages [packages...]`: A list of one or more packages to lint. Can be
combined with all the other selective options.
`--staged`: Lints only files staged on git

`--ancestors`: Take the packages specified via `--packages` or `--changed` and
`--diff`: Lints only files that have changed compared to the default branch or
branch specified with `--compareBranch`

`--regex [regexes...]`: A list of one or more regexes to select files to lint.

### Selective Options

`--ancestors`: Take the packages specified with the command or `--changed` and
add their ancestors (i.e. the packages that have a direct or indirect dependency
on them) to the lint list.

`--descendants`: Take the packages specified via `--packages` or `--changed` and
`--descendants`: Take the packages specified with the command or `--changed` and
add their descendants (i.e. the packages they directly or indirectly depend on)
to the lint list.

`--changed`: Add all the packages whose workspaces contain files that have
changed, calculated comparing the current state of the git repository with the
branch specified by `compareBranch` or, if `compareBranch` is not set, with the
default branch.

`--compareBranch <branch>`: Specify the comparison branch used to determine
which files have changed when using the `changed` option. If this option is used
without `changed`, the command will fail.
82 changes: 39 additions & 43 deletions docs/commands/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@ title: modular test

Search workspaces based on their `name` field in the `package.json` and test:

- Modular packages, according to their respective `modular.type`. In this case,
- Modular packages (packages with a `modular` field in their `package.json`).
`modular test` will act as an opinionated wrapper around
[`jest`](https://jestjs.io/), which comes with out-of-the-box configuration.
- Non-Modular packages (i.e. packages without a `modular` configuration), only
if they have a `test`
[`jest`](https://jestjs.io/), with a predefined Modular configuration.
- Non-Modular packages (packages without a `modular` field in their
`package.json`), only if they have a `test`
[script](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#scripts),
by running `yarn test` on the package's
[workspace](https://classic.yarnpkg.com/en/docs/cli/workspace).

When the `[packages...]` argument is empty and no selective option has been
specified (for example when running `yarn modular test`), tests will be run for
all testable packages in the repo. When the `[packages...]` argument contains
one or more non-existing package name, the non-existing packages will be ignored
without an error. If any package or selective option have been defined but
Modular can't find any package to test, Modular will warn on `stdout` and exit
with code `0`.

Test order is unspecified by design, so please don't rely on the assumption that
certain tests will run before others, that Modular tests will run before
non-Modular tests, or that they will run sequentially. An exception to this,
valid only for Modular tests (that are run by Jest), is when
[the `--runinband` option is specified](https://jestjs.io/docs/cli#--runinband).
specified (ie `yarn modular test`), all packages will be tested. When the
`[packages...]` argument contains one or more non-existing package name, the
non-existing packages will be ignored without an error. If Modular can't find
any package to test, Modular will warn on `stdout` and exit with code `0`.

Test order is unspecified, so don't rely on Modular to run certain tests before
others, that Modular tests will run before non-Modular tests, or that they will
run sequentially unless running Modular tests with
[the `--runinband` option](https://jestjs.io/docs/cli#--runinband).

## Configuration

Expand All @@ -46,20 +43,16 @@ This contains the setup for tests corresponding to

### Arguments

`[packages ...]`: List of packages to test. Can be combined with multiple
selective options (`--ancestors`, `--descendants`, `--changed` and `--regex`).
Modular will generate a list of regular expressions that satisfies all options
passed which are then passed to Jest. The tests will run in non-predictable
order. When `packages` is empty and no selective options have been specified
(for example when running `yarn modular test`), all tests in the monorepo will
be executed. When `packages` contains one or more non-existing package name, the
non-existing packages will be ignored without an error. If any package or
selective option have been defined but the final set of regular expressions is
empty, Modular will write a message to `stdout` and exit with code `0`.
`[packages ...]`: Packages to test. Can be combined with multiple selective
options (`--ancestors`, `--descendants`, `--changed` and `--regex`). Modular
will pass a list of regular expressions that satisfies all options to Jest.

### Test Unique Options:

### Modular-specific options
These options are unique to the test command and differ to other Modular command
options.

`--bypass`: Bypass Modular selective behaviour and flags, and send all provided
`--bypass`: Bypass Modular selective behavior and flags, and send all provided
flags and options directly to the Jest process with Modular configuration.
Useful when running `modular test` from IntelliJ.

Expand All @@ -68,6 +61,24 @@ of babel + ts-jest. Brings significant performance improvements, but ignores
ts-config in favour of its own configuration file,
[.swcrc](https://swc.rs/docs/configuration/swcrc).

`--debug`: Add the `--inspect-brk` option to the Node.js process executing Jest
to allow a debugger to be attached to the running process. For more information,
[see the Node.js debugging guide](https://nodejs.org/en/docs/guides/debugging-getting-started/).

`--compareBranch <branch>`: Specify the comparison branch used to determine
which files have changed when using the `changed` option. If this option is used
without `changed`, the command will fail.

`--verbose`: Activate debug logging. Useful to see which packages have been
selected and which regular expression and arguments have been passed to the
underlying Jest process.

`--regex <regexes...>`: Select all the test files matching the specified regular
expressions. When combined with selective options, it will run all tests
matching the selective options, and tests that match the regexes provided.

### Selective Options

`--ancestors`: Take the packages specified by the user via arguments or options
and add their ancestors (i.e. the packages that have a direct or indirect
dependency on them) to the test list.
Expand All @@ -82,21 +93,6 @@ calculated comparing the current state of the git repository with the branch
specified by `compareBranch` or, if `compareBranch` is not set, with the default
branch.

`--debug`: Add the `--inspect-brk` option to the Node.js process executing Jest
to allow a debugger to be attached to the running process. For more information,
[see the Node.js debugging guide](https://nodejs.org/en/docs/guides/debugging-getting-started/).

`--compareBranch <branch>`: Specify the comparison branch used to determine
which files have changed when using the `changed` option. If this option is used
without `changed`, the command will fail.

`--regex <regexes...>`: Select all the test files matching the specified regular
expressions. Can be combined with all the other selective options.

`--verbose`: Activate debug logging. Useful to see which packages have been
selected and which regular expression and arguments have been passed to the
underlying Jest process.

### Jest CLI Options

`modular test` additionally supports passing
Expand Down

0 comments on commit d535297

Please sign in to comment.