This commit is contained in:
Elizabeth Craig 2023-09-05 12:54:59 -07:00 коммит произвёл GitHub
Родитель cb692eef7c
Коммит 855bedee10
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
37 изменённых файлов: 271 добавлений и 489 удалений

Просмотреть файл

@ -1,21 +1,22 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: [
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended", // [Has to be last] this does prettier as part of the linting
"prettier" // disable rules that are redundant with prettier
],
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
rules: {
"ignorePatterns": ["**/node_modules/**", "**/lib/**", "**/*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-explicit-any": "off",
@ -27,6 +28,6 @@ module.exports = {
"import/namespace": "off",
"import/order": "warn",
"import/no-unresolved": "off",
"import/default": "off",
},
};
"import/default": "off"
}
}

12
.github/workflows/CI.yml поставляемый
Просмотреть файл

@ -8,19 +8,20 @@ on:
jobs:
build:
name: Run on node ${{ matrix.node-version }} and ${{ matrix.os }}
name: Run on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12, 14]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v3
- name: Check out code
uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version-file: .nvmrc
- name: yarn
run: yarn --frozen-lockfile
@ -34,5 +35,6 @@ jobs:
- run: yarn build
- run: yarn lint
- run: yarn format:check
- run: yarn test

11
.github/workflows/release.yml поставляемый
Просмотреть файл

@ -11,22 +11,19 @@ jobs:
# This environment contains secrets needed for publishing
environment: release
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v3
- name: Check out code
uses: actions/checkout@v3
with:
# Fetch all history (required for publishing which looks at history)
fetch-depth: 0
# Don't save creds in the git config (so it's easier to override later)
persist-credentials: false
- name: Use Node.js ${{ matrix.node-version }}
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version-file: .nvmrc
- run: yarn

1
.nvmrc Normal file
Просмотреть файл

@ -0,0 +1 @@
14

17
.prettierrc Normal file
Просмотреть файл

@ -0,0 +1,17 @@
{
"endOfLine": "auto",
"overrides": [
{
"files": "*.md",
"options": {
"proseWrap": "always"
}
},
{
"files": "*.json5",
"options": {
"parser": "json"
}
}
]
}

Просмотреть файл

@ -1,16 +0,0 @@
module.exports = {
overrides: [
{
files: "*.md",
options: {
proseWrap: "always",
},
},
{
files: "*.json5",
options: {
parser: "json",
},
},
],
};

11
beachball.config.js Normal file
Просмотреть файл

@ -0,0 +1,11 @@
// @ts-check
/** @type {import('beachball').BeachballConfig} */
module.exports = {
groupChanges: true,
ignorePatterns: [
"**/jest.config.js",
"**/src/__fixtures__/**",
"**/src/__tests__/**",
],
scope: ["!packages/utils-test/__fixtures__/*"],
};

Просмотреть файл

@ -0,0 +1,46 @@
{
"changes": [
{
"type": "minor",
"comment": "Require Node 14; add downlevel syntax compilation to ES2020 for Node 14",
"packageName": "backfill",
"email": "elcraig@microsoft.com",
"dependentChangeType": "patch"
},
{
"type": "minor",
"comment": "Require Node 14; add downlevel syntax compilation to ES2020 for Node 14",
"packageName": "backfill-cache",
"email": "elcraig@microsoft.com",
"dependentChangeType": "patch"
},
{
"type": "minor",
"comment": "Require Node 14; add downlevel syntax compilation to ES2020 for Node 14",
"packageName": "backfill-config",
"email": "elcraig@microsoft.com",
"dependentChangeType": "patch"
},
{
"type": "minor",
"comment": "Require Node 14; add downlevel syntax compilation to ES2020 for Node 14",
"packageName": "backfill-hasher",
"email": "elcraig@microsoft.com",
"dependentChangeType": "patch"
},
{
"type": "minor",
"comment": "Require Node 14; add downlevel syntax compilation to ES2020 for Node 14",
"packageName": "backfill-logger",
"email": "elcraig@microsoft.com",
"dependentChangeType": "patch"
},
{
"type": "minor",
"comment": "Require Node 14; add downlevel syntax compilation to ES2020 for Node 14",
"packageName": "backfill-utils-dotenv",
"email": "elcraig@microsoft.com",
"dependentChangeType": "patch"
}
]
}

Просмотреть файл

@ -12,6 +12,7 @@
"change": "beachball change",
"checkchange": "beachball check",
"format": "prettier --write .",
"format:check": "prettier --check .",
"postinstall": "yarn update-project-references",
"lerna": "lerna",
"lint": "eslint --fix . --ext .ts",
@ -37,7 +38,6 @@
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"execa": "^5.0.0",
"husky": "^7.0.4",
"lerna": "^4.0.0",
@ -49,11 +49,8 @@
"syncpack": "8.4.11",
"typescript": "~4.1.2"
},
"beachball": {
"groupChanges": true,
"scope": [
"!packages/utils-test/__fixtures__/*"
]
"engines": {
"node": ">=14"
},
"lint-staged": {
"**/package.json": [
@ -64,7 +61,8 @@
"prettier --write"
],
"**/*.ts": [
"eslint --fix"
"eslint --fix",
"prettier --write"
]
},
"syncpack": {

Просмотреть файл

@ -43,5 +43,8 @@
"ts-jest": "^25.5.1",
"ts-mockito": "^2.6.1",
"typescript": "~4.1.2"
},
"engines": {
"node": ">=14"
}
}

Просмотреть файл

@ -1,7 +1,10 @@
{
"extends": "backfill-utils-tsconfig/tsconfig.default.json",
"include": ["src/**/*", "typings/*"],
"compilerOptions": { "rootDir": "src", "outDir": "lib" },
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"references": [
{ "path": "../cache" },
{ "path": "../config" },

3
packages/cache/package.json поставляемый
Просмотреть файл

@ -37,5 +37,8 @@
"jest": "^25.5.4",
"ts-jest": "^25.5.1",
"typescript": "~4.1.2"
},
"engines": {
"node": ">=14"
}
}

Просмотреть файл

@ -40,12 +40,12 @@ describe("getCacheStorage", () => {
await storage.fetch(hash);
// Wait 1ms to make sure the file modification time changes.
// Wait 2ms to make sure the file modification time changes.
// WHY: hashFile uses the file modification time to determine if the hash
// needs to be recomputed. The filesystems typically used by Mac and Linux
// record these times at 1ns resolution, but NTFS uses 100ns resolution.
// So sometimes the test would fail on Windows if it ran too quickly.
await new Promise((resolve) => setTimeout(resolve, 1));
await new Promise((resolve) => setTimeout(resolve, 2));
fs.writeFileSync(path.join(dir, "Changing"), "changing content now");
await storage.put(hash, ["**/*"]);

6
packages/cache/tsconfig.json поставляемый
Просмотреть файл

@ -1,8 +1,10 @@
{
"extends": "backfill-utils-tsconfig/tsconfig.default.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"lib": [],
"compilerOptions": { "rootDir": "src", "outDir": "lib" },
"references": [
{ "path": "../config" },
{ "path": "../logger" },

Просмотреть файл

@ -29,5 +29,8 @@
"jest": "^25.5.4",
"ts-jest": "^25.5.1",
"typescript": "~4.1.2"
},
"engines": {
"node": ">=14"
}
}

Просмотреть файл

@ -1,6 +1,9 @@
{
"extends": "backfill-utils-tsconfig/tsconfig.default.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"compilerOptions": { "rootDir": "src", "outDir": "lib" },
"references": [{ "path": "../logger" }, { "path": "../utils-test" }]
}

Просмотреть файл

@ -31,5 +31,8 @@
"jest": "^25.5.4",
"ts-jest": "^25.5.1",
"typescript": "~4.1.2"
},
"engines": {
"node": ">=14"
}
}

Просмотреть файл

@ -1,7 +1,10 @@
{
"extends": "backfill-utils-tsconfig/tsconfig.default.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"compilerOptions": { "rootDir": "src", "outDir": "lib" },
"references": [
{ "path": "../config" },
{ "path": "../logger" },

Просмотреть файл

@ -24,5 +24,8 @@
"@types/node": "^14.18.36",
"backfill-utils-tsconfig": "*",
"typescript": "~4.1.2"
},
"engines": {
"node": ">=14"
}
}

Просмотреть файл

@ -1,10 +1,9 @@
{
"extends": "backfill-utils-tsconfig/tsconfig.default.json",
"include": ["src"],
"compilerOptions": {
"esModuleInterop": true,
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"references": []
}

Просмотреть файл

@ -1,5 +0,0 @@
**/*
!lib/**/*
lib/**/__tests__/*
lib/**/*.d.ts.map
!bin/**/*

Просмотреть файл

@ -1,6 +1,9 @@
{
"extends": "backfill-utils-tsconfig/tsconfig.default.json",
"exclude": ["lib"],
"compilerOptions": { "rootDir": "src", "outDir": "lib" },
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"references": [{ "path": "../backfill" }]
}

Просмотреть файл

@ -1,5 +0,0 @@
**/*
!lib/**/*
lib/**/__tests__/*
lib/**/*.d.ts.map
!bin/**/*

Просмотреть файл

@ -1,6 +1,9 @@
{
"extends": "backfill-utils-tsconfig/tsconfig.default.json",
"exclude": ["lib"],
"compilerOptions": { "rootDir": "src", "outDir": "lib" },
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"references": [{ "path": "../backfill" }, { "path": "../sample-dependency" }]
}

Просмотреть файл

@ -23,5 +23,8 @@
"@types/node": "^14.18.36",
"backfill-utils-tsconfig": "*",
"typescript": "~4.1.2"
},
"engines": {
"node": ">=14"
}
}

Просмотреть файл

@ -1,6 +1,9 @@
{
"extends": "backfill-utils-tsconfig/tsconfig.default.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"compilerOptions": { "rootDir": "src", "outDir": "lib" },
"references": []
}

Просмотреть файл

@ -1,5 +0,0 @@
**/*
!lib/**/*
lib/**/__tests__/*
lib/**/*.d.ts.map
!bin/**/*

Просмотреть файл

@ -1,230 +0,0 @@
{
"name": "backfill-utils-test",
"entries": [
{
"date": "Tue, 05 Sep 2023 19:33:16 GMT",
"tag": "backfill-utils-test_v5.1.3",
"version": "5.1.3",
"comments": {
"none": [
{
"author": "elcraig@microsoft.com",
"package": "backfill-utils-test",
"commit": "7d9dc77bc01070d0e805cd74b15bef16281f28a1",
"comment": "Unpin devDependencies"
}
]
}
},
{
"date": "Fri, 30 Dec 2022 05:14:35 GMT",
"tag": "backfill-utils-test_v5.1.3",
"version": "5.1.3",
"comments": {
"none": [
{
"author": "email not defined",
"package": "backfill-utils-test",
"commit": "96510e9fba86065f54a7ae47408a5646629502db",
"comment": "Update devDependency @types/node to v14.18.36"
}
]
}
},
{
"date": "Thu, 08 Dec 2022 02:52:13 GMT",
"tag": "backfill-utils-test_v5.1.3",
"version": "5.1.3",
"comments": {
"patch": [
{
"author": "renovate@whitesourcesoftware.com",
"package": "backfill-utils-test",
"commit": "db3823d3762dcf07ef2868b8f7facfda5a57f928",
"comment": "Update dependency execa to v5"
}
]
}
},
{
"date": "Thu, 08 Dec 2022 02:38:15 GMT",
"tag": "backfill-utils-test_v5.1.2",
"version": "5.1.2",
"comments": {
"none": [
{
"author": "elcraig@microsoft.com",
"package": "backfill-utils-test",
"commit": "8933334a222411ce6811ebd1460c84c5f9b97cbf",
"comment": "Update package.json ordering with prettier-package-json"
}
]
}
},
{
"date": "Thu, 08 Dec 2022 02:23:52 GMT",
"tag": "backfill-utils-test_v5.1.2",
"version": "5.1.2",
"comments": {
"none": [
{
"author": "renovate@whitesourcesoftware.com",
"package": "backfill-utils-test",
"commit": "not available",
"comment": "Update @types devDependencies"
}
]
}
},
{
"date": "Thu, 08 Dec 2022 02:23:21 GMT",
"tag": "backfill-utils-test_v5.1.2",
"version": "5.1.2",
"comments": {
"none": [
{
"author": "renovate@whitesourcesoftware.com",
"package": "backfill-utils-test",
"commit": "3c69db3d2f49ab2adc0c9191e69355b6569f08b2",
"comment": "Update @types devDependencies"
}
]
}
},
{
"date": "Thu, 08 Dec 2022 01:16:15 GMT",
"tag": "backfill-utils-test_v5.1.2",
"version": "5.1.2",
"comments": {
"none": [
{
"author": "renovate@whitesourcesoftware.com",
"package": "backfill-utils-test",
"commit": "31c81223403c163d5078d7a9764ffa69c943ac41",
"comment": "Update devDependency @types/jest to v25.2.3"
}
]
}
},
{
"date": "Thu, 08 Dec 2022 00:58:32 GMT",
"tag": "backfill-utils-test_v5.1.2",
"version": "5.1.2",
"comments": {
"none": [
{
"author": "email not defined",
"package": "backfill-utils-test",
"commit": "080fb1aa0570751e1e4d0429c1eb40e449621d4d",
"comment": "Pin devDependencies"
}
]
}
},
{
"date": "Tue, 27 Apr 2021 09:06:13 GMT",
"tag": "backfill-utils-test_v5.1.2",
"version": "5.1.2",
"comments": {
"patch": [
{
"comment": "Bump @types/node from 13.13.35 to 14.14.41",
"author": "ronald.ndirangu@gmail.com",
"commit": "0e5a9db6edf7bfaa421cf1bb4c02a893ddd2b9d4",
"package": "backfill-utils-test"
}
]
}
},
{
"date": "Tue, 27 Apr 2021 08:32:03 GMT",
"tag": "backfill-utils-test_v5.1.1",
"version": "5.1.1",
"comments": {
"patch": [
{
"comment": "Bump @types/fs-extra from 8.0.1 to 9.0.11",
"author": "ronald.ndirangu@gmail.com",
"commit": "b1c0dd5f4da27ba00feee8a52f0145bdb868da5f",
"package": "backfill-utils-test"
}
]
}
},
{
"date": "Tue, 01 Dec 2020 09:45:24 GMT",
"tag": "backfill-utils-test_v5.1.0",
"version": "5.1.0",
"comments": {
"none": [
{
"comment": "Bump @types/node from 13.13.4 to 14.14.10",
"author": "bewegger@microsoft.com",
"commit": "14c6fa19134dd63317ba440ea47d94f357fc0921",
"package": "backfill-utils-test"
}
]
}
},
{
"date": "Tue, 01 Dec 2020 09:43:25 GMT",
"tag": "backfill-utils-test_v5.1.0",
"version": "5.1.0",
"comments": {
"minor": [
{
"comment": "Bump typescript from 3.7.4 to 4.1.2",
"author": "bewegger@microsoft.com",
"commit": "d6b3b5f327b5f803eeea7b5b8d2b18343892314c",
"package": "backfill-utils-test"
}
]
}
},
{
"date": "Tue, 01 Dec 2020 09:13:42 GMT",
"tag": "backfill-utils-test_v5.0.3",
"version": "5.0.3",
"comments": {
"patch": [
{
"comment": "Run Prettier 2.2.0",
"author": "bewegger@microsoft.com",
"commit": "facba7cd274f1d5b834d87d208f0293f7069ad53",
"package": "backfill-utils-test"
}
]
}
},
{
"date": "Tue, 01 Dec 2020 09:06:20 GMT",
"tag": "backfill-utils-test_v5.0.2",
"version": "5.0.2",
"comments": {
"patch": [
{
"comment": "Bump find-up from 4.1.0 to 5.0.0",
"author": "bewegger@microsoft.com",
"commit": "e80d070bca453869e6fb9136ceb8687c4cf4fa2f",
"package": "backfill-utils-test"
}
]
}
},
{
"date": "Wed, 18 Nov 2020 10:47:24 GMT",
"tag": "backfill-utils-test_v5.0.1",
"version": "5.0.1",
"comments": {
"patch": [
{
"comment": "fix phantom dependencies",
"author": "vincent.bailly@microsoft.com",
"commit": "6222d2d1f8c25f6cc4a2c3c7a6d5a0b807ae07d2",
"package": "backfill-utils-test"
}
]
}
}
]
}

Просмотреть файл

@ -1,61 +0,0 @@
# Change Log - backfill-utils-test
This log was last generated on Thu, 08 Dec 2022 02:52:13 GMT and should not be manually modified.
<!-- Start content -->
## 5.1.3
Thu, 08 Dec 2022 02:52:13 GMT
### Patches
- Update dependency execa to v5 (renovate@whitesourcesoftware.com)
## 5.1.2
Tue, 27 Apr 2021 09:06:13 GMT
### Patches
- Bump @types/node from 13.13.35 to 14.14.41 (ronald.ndirangu@gmail.com)
## 5.1.1
Tue, 27 Apr 2021 08:32:03 GMT
### Patches
- Bump @types/fs-extra from 8.0.1 to 9.0.11 (ronald.ndirangu@gmail.com)
## 5.1.0
Tue, 01 Dec 2020 09:43:25 GMT
### Minor changes
- Bump typescript from 3.7.4 to 4.1.2 (bewegger@microsoft.com)
## 5.0.3
Tue, 01 Dec 2020 09:13:42 GMT
### Patches
- Run Prettier 2.2.0 (bewegger@microsoft.com)
## 5.0.2
Tue, 01 Dec 2020 09:06:20 GMT
### Patches
- Bump find-up from 4.1.0 to 5.0.0 (bewegger@microsoft.com)
## 5.0.1
Wed, 18 Nov 2020 10:47:24 GMT
### Patches
- fix phantom dependencies (vincent.bailly@microsoft.com)

Просмотреть файл

@ -1,4 +1,5 @@
{
"private": true,
"name": "backfill-utils-test",
"version": "5.1.3",
"description": "Shared testing infrastructure code for Backfill",

Просмотреть файл

@ -1,6 +1,9 @@
{
"extends": "backfill-utils-tsconfig/tsconfig.default.json",
"exclude": ["__fixtures__", "lib"],
"compilerOptions": { "rootDir": "src", "outDir": "lib" },
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": ["src"],
"references": []
}

Просмотреть файл

@ -1,5 +0,0 @@
**/*
!lib/**/*
lib/**/__tests__/*
lib/**/*.d.ts.map
!bin/**/*

Просмотреть файл

@ -1,20 +0,0 @@
{
"name": "backfill-utils-tsconfig",
"entries": [
{
"date": "Thu, 08 Dec 2022 02:38:15 GMT",
"tag": "backfill-utils-tsconfig_v5.0.0",
"version": "5.0.0",
"comments": {
"none": [
{
"author": "elcraig@microsoft.com",
"package": "backfill-utils-tsconfig",
"commit": "8933334a222411ce6811ebd1460c84c5f9b97cbf",
"comment": "Update package.json ordering with prettier-package-json"
}
]
}
}
]
}

Просмотреть файл

@ -1,4 +1,5 @@
{
"private": true,
"name": "backfill-utils-tsconfig",
"version": "5.0.0",
"description": "Shared tsconfig.json for Backfill",

Просмотреть файл

@ -5,15 +5,16 @@
"declarationMap": true,
"inlineSourceMap": true,
"inlineSources": false,
"jsx": "react",
"module": "commonjs",
"target": "ES2020",
"lib": ["ES2020"],
"esModuleInterop": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "lib",
"preserveWatchOutput": true,
"rootDir": "src",
"strict": true,
"target": "esnext"
"skipLibCheck": true,
"preserveWatchOutput": true,
"baseUrl": ".",
"types": ["node", "jest"]
}
}

Просмотреть файл

@ -1,44 +1,63 @@
// @ts-check
const execa = require("execa");
const path = require("path");
const fs = require("fs");
const prettier = require("prettier");
const merge = require("lodash.merge");
const resolveFrom = require("resolve-from");
const jju = require("jju");
function getTSConfigPath(location) {
return path.join(process.cwd(), location, "tsconfig.json");
/**
* @typedef {{ path: string }} Reference
* @typedef {{
* extends?: string;
* compilerOptions?: Record<string, any>;
* references?: Reference[];
* }} TSConfig Parsed tsconfig.json contents
* @typedef {{
* filePath: string;
* content: string;
* config: TSConfig;
* }} TSConfigInfo tsconfig.json with file path, original content, and parsed content
*/
/** Repo root */
const root = path.resolve(__dirname, "..");
/** @type {Record<string, TSConfig>} Cache of tsconfig "extends" values */
const extendsCache = {};
function getTSConfigPath(packageLocation) {
return path.join(root, packageLocation, "tsconfig.json");
}
function isTSPackage(location) {
return fs.existsSync(getTSConfigPath(location));
function isTSPackage(packageLocation) {
return fs.existsSync(getTSConfigPath(packageLocation));
}
/**
* Read a tsconfig.json file, resolving and merging the "extends" config.
* @param {string} filePath Path to tsconfig.json
* @returns {TSConfigInfo}
*/
function getTSConfig(filePath) {
const config = fs.existsSync(filePath)
? JSON.parse(fs.readFileSync(filePath).toString())
: {};
const content = fs.existsSync(filePath)
? fs.readFileSync(filePath, "utf8")
: "";
// Parse with jju to allow comments
/** @type {TSConfig} */
let config = content ? jju.parse(content) : {};
if (config.extends) {
return merge(
getTSConfig(resolveFrom(path.dirname(filePath), config.extends)),
config
);
} else {
return config;
if (!extendsCache[config.extends]) {
const extendsPath = resolveFrom(path.dirname(filePath), config.extends);
extendsCache[config.extends] = getTSConfig(extendsPath).config;
}
config = merge(extendsCache[config.extends], config);
}
}
function isCompositeEnabled(location) {
const configPath = getTSConfigPath(location);
const config = getTSConfig(configPath);
return Boolean(config.compilerOptions && config.compilerOptions.composite);
return { filePath, config, content };
}
function getAbsoluteLocation(location, posix = false) {
if (posix) {
return path.posix.join(process.cwd(), location);
} else {
return path.join(process.cwd(), location);
}
return posix ? path.posix.join(root, location) : path.join(root, location);
}
function getRelativeLocation(fromLocation, toLocation, posix = false) {
@ -48,55 +67,65 @@ function getRelativeLocation(fromLocation, toLocation, posix = false) {
);
}
function updateTSConfig(path, options) {
const config = fs.existsSync(path)
? JSON.parse(fs.readFileSync(path).toString())
: {};
prettier.resolveConfig(path).then((prettierOptions) =>
fs.writeFileSync(
path,
prettier.format(
JSON.stringify({
...config,
...options,
}),
{
...prettierOptions,
parser: "json",
}
)
)
/**
* @param {TSConfigInfo} param0
* @param {TSConfig} mergeConfig
*/
async function updateTSConfig({ filePath, content }, mergeConfig) {
// Use the original config (without expanded extends) for updating
const newConfig = { ...jju.parse(content), ...mergeConfig };
// Preserve formatting when updating
const newContent = jju.update(content, newConfig, {
mode: "cjson",
quote_keys: true,
});
const prettierOptions = await prettier.resolveConfig(filePath);
fs.writeFileSync(
filePath,
prettier.format(newContent, {
...prettierOptions,
parser: "json",
})
);
}
function pathCompare(a, b) {
if (a.path < b.path) {
return -1;
} else if (a.path > b.path) {
return 1;
} else {
return 0;
/**
* @param {YarnWorkspaceInfo} workspaceInfo
*/
async function updateTSReferences(workspaceInfo) {
// Read the tsconfigs for each package
const packageTSConfigs = /** @type {Record<String, TSConfigInfo>} */ ({});
for (const [name, { location }] of Object.entries(workspaceInfo)) {
if (isTSPackage(location)) {
packageTSConfigs[name] = getTSConfig(getTSConfigPath(location));
}
}
// Update the tsconfigs with references
for (const [name, info] of Object.entries(workspaceInfo)) {
if (!packageTSConfigs[name]) {
continue;
}
const { location, workspaceDependencies } = info;
const references = workspaceDependencies
.filter((dep) => packageTSConfigs[dep]?.config.compilerOptions?.composite)
.map((dep) => ({
path: getRelativeLocation(location, workspaceInfo[dep].location, true),
}))
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
await updateTSConfig(packageTSConfigs[name], { references });
}
}
function updateTSReferences(workspaceInfo) {
Object.keys(workspaceInfo)
.map((key) => workspaceInfo[key])
.filter(({ location }) => isTSPackage(location))
.forEach(({ location, workspaceDependencies }) => {
updateTSConfig(getTSConfigPath(location), {
references: workspaceDependencies
.map((dependency) => workspaceInfo[dependency].location)
.filter(isTSPackage)
.filter(isCompositeEnabled)
.map((workspaceLocation) => ({
path: getRelativeLocation(location, workspaceLocation, true),
}))
.sort(pathCompare),
});
});
}
/**
* @typedef {Record<string, {
* location: string;
* workspaceDependencies: string[];
* }>} YarnWorkspaceInfo
* @type {YarnWorkspaceInfo}
*/
const workspaceInfo = JSON.parse(
execa
.sync("yarn", ["--silent", "workspaces", "info"])
@ -104,4 +133,7 @@ const workspaceInfo = JSON.parse(
.trim()
);
updateTSReferences(workspaceInfo);
updateTSReferences(workspaceInfo).catch((err) => {
console.error(err.stack || err);
process.exit(1);
});

Просмотреть файл

@ -3260,13 +3260,6 @@ eslint-plugin-import@^2.27.5:
semver "^6.3.0"
tsconfig-paths "^3.14.1"
eslint-plugin-prettier@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz#651cbb88b1dab98bfd42f017a12fa6b2d993f94b"
integrity sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==
dependencies:
prettier-linter-helpers "^1.0.0"
eslint-scope@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
@ -3524,11 +3517,6 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
fast-diff@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
fast-glob@^3.2.9:
version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
@ -5059,7 +5047,7 @@ jest@^25.5.4:
jju@^1.4.0, jju@~1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/jju/-/jju-1.4.0.tgz#a3abe2718af241a2b2904f84a625970f389ae32a"
integrity sha1-o6vicYryQaKykE+EpiWXDzia4yo=
integrity sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==
js-sdsl@^4.1.4:
version "4.2.0"
@ -6520,13 +6508,6 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=
prettier-linter-helpers@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
dependencies:
fast-diff "^1.1.2"
prettier-package-json@^2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/prettier-package-json/-/prettier-package-json-2.8.0.tgz#70aba2b4f7aeb4e294ae2191fb64b7d8fdea0398"