Skip to content

Commit

Permalink
feat(build)!: migrate to ESM build & switch to Vitest for ESM support (
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Apr 4, 2023
1 parent 44c80ab commit 308fc2e
Show file tree
Hide file tree
Showing 312 changed files with 5,933 additions and 6,989 deletions.
12 changes: 1 addition & 11 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_", "destructuredArrayIgnorePattern": "^_" }
]
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "destructuredArrayIgnorePattern": "^_" }]
},
"overrides": [
{
Expand All @@ -63,14 +60,7 @@
},
{
"files": ["integration/**", "helpers/**", "**/__tests__/**", "**/__mocks__/**", "**/__helpers__/**"],
"env": {
"jest": true
},
"rules": {
"jest/no-disabled-tests": "off",
"jest/no-standalone-expect": "off",
"jest/no-test-prefixes": "off",
"max-classes-per-file": "off",
"node/no-extraneous-require": "off",
"node/no-unpublished-require": "off",
"no-await-in-loop": "off",
Expand Down
28 changes: 0 additions & 28 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,4 @@
},
],
schedule: ['on Thursday'],
ignoreDeps: [
// ESM Only => https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-move-my-commonjs-project-to-esm
'byte-size',
'chalk',
'execa',
'file-url',
'find-up',
'globby',
'inquirer',
'is-stream',
'multimatch',
'new-github-release-url',
'node-fetch',
'normalize-newline',
'normalize-path',
'p-map',
'p-pipe',
'p-queue',
'p-reduce',
'pify',
'pnpm', // delay pnpm v8 until next major since it requires Node 16
'slash',
'temp-dir',
'load-json-file',
'tempy',
'write-json-file',
'write-pkg',
],
}
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ jobs:
- name: Run pnpm install dependencies
run: pnpm install

- run: pnpm run format:check
- run: pnpm run prettier:check
- run: pnpm run ci:lint

tests:
strategy:
fail-fast: false
matrix:
node: [14, 16, 18]
node: [16, 18]
platform: [ubuntu-latest]

name: 'Build & Unit Tests on Ubuntu / Node${{ matrix.node }}'
Expand Down Expand Up @@ -99,25 +99,25 @@ jobs:
- name: Run pnpm install dependencies
run: pnpm install

- name: Cache TypeScript and Jest
- name: Cache TypeScript and Vitest
uses: actions/cache@v3
with:
path: |
packages/*/lib
packages/*/tsconfig.tsbuildinfo
test/.jest-cache
key: ts-jest-${{ matrix.platform }}-${{ matrix.node }}-${{ github.run_id }}
restore-keys: ts-jest-${{ matrix.platform }}-${{ matrix.node }}-
node_modules/.vitest
key: vitest-${{ matrix.platform }}-${{ matrix.node }}-${{ github.run_id }}
restore-keys: vitest-${{ matrix.platform }}-${{ matrix.node }}-

- name: Run all workspace TSC builds
run: pnpm build:full

- name: Run Jest unit tests
- name: Run Vitest unit tests
if: |
!contains(github.event.head_commit.message, 'chore(release)')
run: pnpm jest:ci
run: pnpm test:coverage

- name: Upload Jest coverage to Codecov
- name: Upload test coverage to Codecov
uses: codecov/codecov-action@v3.1.1
if: |
contains(matrix.node, 18) &&
Expand Down
12 changes: 10 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"useTabs": false,
"tabWidth": 2,
"printWidth": 120,
"printWidth": 130,
"singleQuote": true,
"trailingComma": "es5"
"trailingComma": "es5",
"overrides": [
{
"files": ["**/*.spec.ts"],
"options": {
"printWidth": 160
}
}
]
}
16 changes: 7 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
{
"type": "node",
"request": "launch",
"name": "Jest Current Spec File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand", "${fileBasename}", "--config", "${workspaceFolder}/jest/jest.config.ts"],
"console": "internalConsole",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
"name": "Vitest - Debug Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}", "--no-threads"],
"smartStep": true,
"console": "integratedTerminal"
},
{
"name": "Version command debugger",
Expand Down
8 changes: 4 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
"problemMatcher": []
},
{
"label": "Run Jest Unit Tests (watch)",
"label": "Run Vitest Unit Tests (watch)",
"type": "shell",
"command": "npm run jest:watch",
"command": "npm run test",
"problemMatcher": []
},
{
"label": "Run Jest Test Coverage",
"label": "Run Vitest with Test Coverage",
"type": "shell",
"command": "npm run jest",
"command": "npm run test:coverage",
"problemMatcher": []
},
{
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ We'd love for you to contribute and to make this project even better than it is
- `pnpm format:write`
4. run a full TypeScript (TSC) build
- `pnpm build` OR `npx pnpm build`
5. add/run Jest unit tests (make sure to run the previous steps first):
- `pnpm jest` (full test coverage)
- `pnpm jest:watch` (watch mode)
5. add/run Vitest unit tests (make sure to run the previous steps first):
- `pnpm test` (watch mode)
- `pnpm test:coverage` (full test coverage)
6. If you did step 2 up to 5, then the final step would be the Pull Request... but wait! For readability purposes, we would like you to only submit the relevant pieces of code that you changed. We are basically asking you to do a Build and make sure there's no errors (Yes please) but to not include the produced `dist` folder. We just want to see the real changes, nothing else (but we still want to make sure it Builds before creating a PR).

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[![Actions Status](https://github.com/lerna-lite/lerna-lite/workflows/CI/badge.svg)](https://github.com/lerna-lite/lerna-lite/actions)
[![codecov](https://codecov.io/gh/lerna-lite/lerna-lite/branch/main/graph/badge.svg)](https://codecov.io/gh/lerna-lite/lerna-lite)
[![jest](https://jestjs.io/img/jest-badge.svg)](https://github.com/facebook/jest)
[![Vitest](https://img.shields.io/badge/tested%20with-vitest-fcc72b.svg?logo=vitest)](https://vitest.dev/)
[![NPM downloads](https://img.shields.io/npm/dm/@lerna-lite/cli)](https://www.npmjs.com/package/@lerna-lite/cli)
[![npm](https://img.shields.io/npm/v/@lerna-lite/cli.svg?logo=npm&logoColor=fff&label=npm)](https://www.npmjs.com/package/@lerna-lite/cli)

Expand Down Expand Up @@ -56,7 +56,7 @@ Lerna-Lite itself is now also using [pnpm workspaces](https://pnpm.io/workspaces
Here are some of the largest projects using the Lerna-Lite fork

<a href="https://github.com/facebook/jest">
<img src="https://jestjs.io/img/jest.png" width="25" height="25">
<img src="https://jestjs.io/img/vi.png" width="25" height="25">
Jest
</a>&nbsp; | &nbsp;
<a href="https://github.com/react-navigation/react-navigation">
Expand Down Expand Up @@ -298,9 +298,9 @@ If you wish to contribute to the project, please follow these steps:
- `pnpm install` OR `npx pnpm install`
3. run a full TypeScript (TSC) build
- `pnpm build` OR `npx pnpm build`
4. add/run Jest unit tests (make sure to run the previous steps first):
- `pnpm jest` (full test coverage)
- `pnpm jest:watch` (watch mode)
4. add/run Vitest unit tests (make sure to run the previous steps first):
- `pnpm test` (watch mode)
- `pnpm test:coverage` (full test coverage)
5. you can also troubleshoot/debug via the VSCode debugger launch configs that were setup for each command

## Troubleshooting
Expand Down
1 change: 1 addition & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'vitest/globals';
20 changes: 9 additions & 11 deletions helpers/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import execa from 'execa';
import { execa } from 'execa';
import path from 'path';
import { fileURLToPath } from 'url';

import lernaCLI from '../packages/cli/src/lerna-cli';
import lernaCLI from '../packages/cli/src/lerna-cli.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const LERNA_BIN = path.resolve(__dirname, '../packages/cli/src/cli.ts');

/**
Expand All @@ -13,17 +16,12 @@ const LERNA_BIN = path.resolve(__dirname, '../packages/cli/src/cli.ts');
* @return {Function} with partially-applied yargs config
*/
export function commandRunner(commandModule: any) {
/* eslint-disable import/no-dynamic-require, global-require */
/* eslint-disable global-require */
const cmd = commandModule.command.split(' ')[0];

return (cwd: string) => {
// create a _new_ yargs instance every time cwd changes to avoid singleton pollution
const cli = lernaCLI([], cwd)
.exitProcess(false)
.detectLocale(false)
.showHelpOnFail(false)
.wrap(null)
.command(commandModule);
const cli = lernaCLI([], cwd).exitProcess(false).detectLocale(false).showHelpOnFail(false).wrap(null).command(commandModule);

return (...args: string[]) =>
new Promise((resolve, reject) => {
Expand Down Expand Up @@ -64,7 +62,7 @@ export function commandRunner(commandModule: any) {
};
}

exports.cliRunner = function cliRunner(cwd: string, env: { [key: string]: string }) {
export function cliRunner(cwd: string, env: { [key: string]: string }) {
const opts = {
cwd,
env: Object.assign(
Expand All @@ -80,4 +78,4 @@ exports.cliRunner = function cliRunner(cwd: string, env: { [key: string]: string
};

return (...args: string[]) => execa('node', [LERNA_BIN].concat(args), opts);
};
}
15 changes: 8 additions & 7 deletions helpers/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import execa from 'execa';
import { execa } from 'execa';
import fileUrl from 'file-url';
import tempy from 'tempy';
import { temporaryDirectory } from 'tempy';
import fs from 'fs-extra';
import findUp from 'find-up';
import { findUp } from 'find-up';
import path from 'path';
import { gitAdd, gitCommit, gitInit } from './git';

import { gitAdd, gitCommit, gitInit } from './git/index.js';

export function cloneFixtureFactory(startDir: string) {
const initFixture = initFixtureFactory(startDir);

return (...args: any[]) =>
// @ts-ignore
initFixture(...args).then((cwd) => {
const repoDir = tempy.directory();
const repoDir = temporaryDirectory();
const repoUrl = fileUrl(repoDir, { resolve: false });

return execa('git', ['init', '--bare'], { cwd: repoDir })
Expand Down Expand Up @@ -42,7 +43,7 @@ export function copyFixture(targetDir: string, fixtureName: string, cwd: string)

export function initFixtureFactory(startDir: string) {
return (fixtureName: string, commitMessage: boolean | string = 'Init commit') => {
const cwd = tempy.directory();
const cwd = temporaryDirectory();
let chain: Promise<any> = Promise.resolve();

chain = chain.then(() => process.chdir(cwd));
Expand All @@ -60,7 +61,7 @@ export function initFixtureFactory(startDir: string) {

export function initNamedFixtureFactory(startDir: string) {
return (dirName: string, fixtureName: string, commitMessage: boolean | string = 'Init commit') => {
const cwd = path.join(tempy.directory(), dirName);
const cwd = path.join(temporaryDirectory(), dirName);
let chain: Promise<any> = Promise.resolve();

chain = chain.then(() => fs.ensureDir(cwd));
Expand Down
16 changes: 10 additions & 6 deletions helpers/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import execa from 'execa';
import os from 'os';
import { tempWrite } from '../../packages/version/src/utils/temp-write';
import { execa } from 'execa';
import os from 'node:os';
import path from 'path';
import cp from 'child_process';
import loadJsonFile from 'load-json-file';
import writeJsonFile from 'write-json-file';
import gitSHA from '../serializers/serialize-git-sha';
import { loadJsonFile } from 'load-json-file';
import { writeJsonFile } from 'write-json-file';
import { fileURLToPath } from 'url';

import { tempWrite } from '../../packages/version/src/utils/temp-write.js';
import gitSHA from '../serializers/serialize-git-sha.js';

// Contains all relevant git config (user, commit.gpgSign, etc)
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const TEMPLATE = path.resolve(__dirname, 'template');

export function getCommitMessage(cwd, format = '%B') {
Expand Down
15 changes: 7 additions & 8 deletions helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import normalizeNewline from 'normalize-newline';
import normalizePath from 'normalize-path';
import path from 'path';

import { Project } from '../packages/core/src/project';
import { Project } from '../packages/core/src/project/index.js';

/**
* Update lerna config inside a test case.
Expand All @@ -29,10 +29,9 @@ export function normalizeRelativeDir(testDir, filePath) {
return normalizePath(path.relative(testDir, filePath));
}

export * from './git';
export * from './fixtures';
export * from './npm';
export * from './cli';
export * from './fixtures';
export * from './logging-output';
export * from './pkg-matchers';
export * from './git/index.js';
export * from './fixtures.js';
export * from './npm/index.js';
export * from './cli.js';
export * from './logging-output.js';
export * from './pkg-matchers.js';
2 changes: 1 addition & 1 deletion helpers/logging-output.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import log from 'npmlog';

import { multiLineTrimRight } from './index';
import { multiLineTrimRight } from './index.js';

// clear logs between tests
afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions helpers/npm/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import globby from 'globby';
import loadJsonFile from 'load-json-file';
import { globby } from 'globby';
import { loadJsonFile } from 'load-json-file';

export function loadManifests(cwd) {
return globby(
Expand Down
4 changes: 4 additions & 0 deletions helpers/npm/set-npm-userconfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Overwrite npm userconfig to avoid test pollution
// https://docs.npmjs.com/misc/config#npmrc-files
Expand Down
1 change: 1 addition & 0 deletions helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0-test-only",
"description": "Private test helpers for the lerna-lite monorepo",
"main": "index.js",
"type": "module",
"private": true,
"license": "MIT"
}

0 comments on commit 308fc2e

Please sign in to comment.