Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"@testing-library/user-event": "13.5.0",
"@tsconfig/node14": "1.0.3",
"@types/babel__helper-plugin-utils": "7.10.0",
"@types/babel__register": "7.17.0",
"@types/chrome-remote-interface": "0.30.0",
"@types/circular-dependency-plugin": "5.0.5",
"@types/copy-webpack-plugin": "6.4.0",
Expand All @@ -135,6 +136,7 @@
"@types/express": "4.17.2",
"@types/fs-extra": "8.0.1",
"@types/glob": "7.1.1",
"@types/graphviz": "0.0.34",
"@types/gulp": "4.0.9",
"@types/gulp-babel": "6.1.30",
"@types/gulp-cache": "0.4.5",
Expand All @@ -161,6 +163,7 @@
"@types/scheduler": "0.16.2",
"@types/semver": "^6.2.0",
"@types/tmp": "0.2.0",
"@types/webpack-bundle-analyzer": "4.4.3",
"@types/webpack-dev-middleware": "4.1.0",
"@types/webpack-env": "1.16.0",
"@types/webpack-hot-middleware": "2.25.6",
Expand Down Expand Up @@ -193,6 +196,7 @@
"danger": "^11.0.0",
"dedent": "0.7.0",
"del": "6.0.0",
"dotparser": "1.1.1",
"enhanced-resolve": "5.8.2",
"enquirer": "2.3.6",
"enzyme": "3.10.0",
Expand All @@ -215,9 +219,11 @@
"extract-comments": "1.1.0",
"file-loader": "6.2.0",
"fork-ts-checker-webpack-plugin": "6.1.0",
"find-free-port": "2.0.0",
"fs-extra": "8.1.0",
"geckodriver": "3.0.2",
"glob": "7.2.0",
"graphviz": "0.0.9",
"gulp": "4.0.2",
"gulp-babel": "8.0.0",
"gulp-cache": "1.1.3",
Expand Down
7 changes: 7 additions & 0 deletions scripts/api-extractor/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.scripts.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["*"]
}
13 changes: 8 additions & 5 deletions scripts/babel/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const isNodeCaller = caller => {
return caller && (caller.name === '@babel/register' || caller.name === 'babel-jest');
/** @typedef {import('@babel/core').TransformOptions['caller']} Caller */

const isNodeCaller = (/** @type {Caller}*/ caller) => {
return Boolean(caller && (caller.name === '@babel/register' || caller.name === 'babel-jest'));
};
const isDistCaller = caller => {
const isDistCaller = (/** @type {Caller}*/ caller) => {
return !!(caller && caller.name === 'babel-gulp');
};
const supportsESM = caller => {
const supportsESM = (/** @type {Caller}*/ caller) => {
// @ts-expect-error - TODO: caller.useESModules api doesn't exists (types/implementation), is this a bug? https://babeljs.io/docs/en/options#caller
return !!((caller && caller.name === 'babel-loader') || caller.useESModules);
};

module.exports = api => {
module.exports = (/** @type {import('@babel/core').ConfigAPI} */ api) => {
const isDistBundle = api.caller(isDistCaller);
const isNode = api.caller(isNodeCaller);
const useESModules = !isNode && api.caller(supportsESM);
Expand Down
1 change: 0 additions & 1 deletion scripts/babel/register.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore - @babel/register doesn't ship types
require('@babel/register')({
extensions: ['.js', '.ts', '.tsx'],
ignore: [/node_modules/],
Expand Down
7 changes: 7 additions & 0 deletions scripts/babel/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.scripts.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["*"]
}
27 changes: 19 additions & 8 deletions scripts/dependency-graph-generator/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
const graphviz = require('graphviz');
const parser = require('dotparser');
const readFileSync = require('fs').readFileSync;
const spawnSync = require('child_process').spawnSync;
const findGitRoot = require('../monorepo/index').findGitRoot;
const getDependencies = require('../monorepo/index').getDependencies;
const parser = /** @type {typeof import('dotparser')['default']}*/ (/** @type {unknown} */ (require('dotparser')));
const { readFileSync } = require('fs');
const { spawnSync } = require('child_process');
const path = require('path');
const yargs = require('yargs');

/** @typedef {import('yargs').Arguments<{root:string;'include-dev'?:string;'graphviz-path'?:string}>} CliArgs */

const { findGitRoot, getDependencies } = require('../monorepo');

const dotFilePath = path.resolve(__dirname, 'repo-graph.dot');
/**
* @type {string[]}
*/
let ignoreDevDependencies = [];

/**
* Pick a package in the repository and generate its dependency graph
*
* For this utility to work you will actually need to install graphviz on your machine
* http://www.graphviz.org
* @param {CliArgs} argv
*/
async function main(argv) {
if (!argv.root) {
Expand Down Expand Up @@ -81,8 +88,9 @@ function _parseDotFile(pathToDotFile) {
const items = parsed[0].children;
items.forEach(item => {
if (item.type === 'node_stmt') {
graph.addNode(item.node_id.id);
graph.addNode(String(item.node_id.id));
} else {
// @ts-expect-error - edge_list doesn't exist on type definition - is this a bug ?
graph.addEdge(item.edge_list[0].id, item.edge_list[1].id, { dir: 'forward' });
}
});
Expand Down Expand Up @@ -130,8 +138,11 @@ function _getSubTree(graph, rootPackage) {
* @param {string} node id of the node
*/
function _getEdgesAndChildren(graph, node) {
/** @type any[] */
const edges = [];
/** @type any[] */
const children = [];
// @ts-expect-error - edges prop doesn't exist on typings - wrong typings ?
graph.edges.forEach(edge => {
if (ignoreDevDependencies.includes(edge.nodeOne.id) || ignoreDevDependencies.includes(edge.nodeTwo.id)) {
return;
Expand All @@ -146,7 +157,7 @@ function _getEdgesAndChildren(graph, node) {
return { edges, children };
}

require('yargs')
yargs
.scriptName('dependency-graph-generator')
.usage('$0 [args]')
.command(
Expand All @@ -168,7 +179,7 @@ require('yargs')
description: 'The path to graphviz which needs to be installed, required for windows users',
});
},
async argv => await main(argv),
async argv => await main(/** @type {CliArgs}*/ (argv)),
)
.demand('root')
.help().argv;
7 changes: 7 additions & 0 deletions scripts/dependency-graph-generator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.scripts.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["*"]
}
3 changes: 1 addition & 2 deletions scripts/jest/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @ts-check
const lernaAlias = require('../lernaAliasNorthstar');
const findGitRoot = require('../monorepo/findGitRoot');

module.exports = customConfig => ({
module.exports = (/** @type {import('@jest/types').Config.InitialOptions} */ customConfig) => ({
coverageDirectory: './coverage/',
coverageReporters: ['json', 'lcov'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
Expand Down
2 changes: 1 addition & 1 deletion scripts/jest/jest-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class JestReporter extends DefaultReporter {
super(...args);

this._isLoggingError = false;
this.log = message => {
this.log = (/** @type {string} */ message) => {
if (this._isLoggingError) {
process.stderr.write(message + '\n');
} else {
Expand Down
10 changes: 5 additions & 5 deletions scripts/jest/jest-resources.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// @ts-check

const fs = require('fs-extra');
const path = require('path');
const merge = require('../tasks/merge');
const resolve = require('resolve');
const { resolveCwd } = require('just-scripts');
const { findRepoDeps } = require('../monorepo/index');

const merge = require('../tasks/merge');
const { findRepoDeps } = require('../monorepo');
const findConfig = require('../find-config');

const packageJsonPath = findConfig('package.json');
const packageJsonPath = findConfig('package.json') ?? '';
const packageRoot = path.dirname(packageJsonPath);

const jestAliases = () => {
// Get deps of the current package within the repo
const packageDeps = findRepoDeps();

/** @type {Record<string,string>} */
const aliases = {};

for (const { packageJson } of packageDeps) {
Expand Down
5 changes: 5 additions & 0 deletions scripts/jest/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const consoleError = console.error;
console.error = customError.bind(null, 'error');
console.warn = customError.bind(null, 'warn');

/**
*
* @param {string} type
* @param {any[]} args
*/
function customError(type, ...args) {
if (type === 'warn') {
consoleWarn(...args);
Expand Down
7 changes: 7 additions & 0 deletions scripts/jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.scripts.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": ["*"]
}
43 changes: 43 additions & 0 deletions scripts/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ const chalk = require('chalk');
const isProduction = process.argv.indexOf('--production') > -1;
const isVerbose = process.argv.indexOf('--verbose') > -1;

/**
*
* @param {string} packageName
* @param {string} task
*/
module.exports.logStartTask = (packageName, task) => {
console.log(`${getTimePrefix(packageName)} Starting: ${chalk.cyan(task)}`);
};

/**
*
* @param {string} packageName
* @param {string} task
* @param {number} startTime
* @param {string} errorMessage
*/
module.exports.logEndTask = (packageName, task, startTime, errorMessage) => {
console.log(
`${getTimePrefix(packageName)} ${getPassFail(errorMessage === undefined)}: ${chalk.cyan(task)} (${getDuration(
Expand All @@ -15,12 +27,22 @@ module.exports.logEndTask = (packageName, task, startTime, errorMessage) => {
);
};

/**
*
* @param {unknown} taskStatus
*/
module.exports.logStatus = taskStatus => {
if (isProduction || isVerbose) {
console.log(' ' + taskStatus);
}
};

/**
*
* @param {string} packageName
* @param {boolean} passed
* @param {number} startTime
*/
module.exports.logEndBuild = (packageName, passed, startTime) => {
console.log();
console.log(
Expand All @@ -43,19 +65,40 @@ module.exports.logEndBuild = (packageName, passed, startTime) => {
);
};

/**
*
* @param {number} startTime
* @returns
*/
function getDuration(startTime) {
let duration = new Date().getTime() - startTime;

return chalk.yellow(formatTime(duration));
}

/**
*
* @param {boolean} passed
* @returns
*/
function getPassFail(passed) {
return passed ? chalk.green('Pass') : chalk.red('Error');
}

/**
*
* @param {string} packageName
* @returns
*/
function getTimePrefix(packageName) {
return `[${chalk.magenta(packageName)} ${chalk.gray(new Date().toLocaleTimeString([], { hour12: false }))}]`;
}

/**
*
* @param {number} milliseconds
* @returns
*/
function formatTime(milliseconds) {
if (milliseconds >= 1000) {
return milliseconds / 1000 + 's';
Expand Down
3 changes: 0 additions & 3 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
"connect-history-api-fallback": "^1.3.0",
"doctoc": "^2.0.1",
"doctrine": "^3.0.0",
"dotparser": "^1.0.0",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

moved to root package.json (single version policy)

"find-free-port": "~2.0.0",
"graphviz": "^0.0.9",
"inquirer": "^7.3.3",
"lerna-alias": "^3.0.3-0",
"lerna-dependency-graph": "^1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion scripts/tasks/api-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function apiExtractor() {
}
},
onConfigLoaded: config => {
if (!isUsingTsSolutionConfigs) {
if (!(isUsingTsSolutionConfigs && tsConfig)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/tasks/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function parseModule(args: Arguments & { module?: string | string[] }) {
);
}

acc[outputType] = true;
acc[outputType as keyof JustArgs['module']] = true;

return acc;
},
Expand Down
10 changes: 7 additions & 3 deletions scripts/tasks/babel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { transformAsync } from '@babel/core';
import { BabelFileResult, transformAsync } from '@babel/core';
import * as glob from 'glob';
import fs from 'fs';
import { logger } from 'just-task';
Expand All @@ -20,7 +20,7 @@ export async function babel() {
const codeBuffer = await fs.promises.readFile(filePath);
const sourceCode = codeBuffer.toString().replace(EOL_REGEX, '\n');

const result = await transformAsync(sourceCode, {
const result = (await transformAsync(sourceCode, {
ast: false,
sourceMaps: true,

Expand All @@ -32,7 +32,7 @@ export async function babel() {
filename: filePath,

sourceFileName: path.basename(filename),
});
})) /* Bad `transformAsync` types. it can be null only if 2nd param is null(config)*/ as NonNullableRecord<BabelFileResult>;
const resultCode = addSourceMappingUrl(result.code, path.basename(filename) + '.map');

if (resultCode === sourceCode) {
Expand All @@ -48,3 +48,7 @@ export async function babel() {
await fs.promises.writeFile(sourceMapFile, JSON.stringify(result.map));
}
}

type NonNullableRecord<T> = {
[P in keyof T]-?: NonNullable<T[P]>;
};
Loading