Skip to content

Commit 1daa454

Browse files
runspiredgitKrystan
authored andcommitted
chore: More upgrades to monorepo tooling (#9753)
* chore: update files array for types when needed * chore: improve detection of test apps * better guard * better guard * better guard * fix
1 parent 67aab98 commit 1daa454

File tree

6 files changed

+55
-54
lines changed

6 files changed

+55
-54
lines changed

internal-tooling/.gitignore

-34
This file was deleted.

internal-tooling/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ in tsconfig.json for any other workspace package specified by package.json
2323
as a dependency, peer-dependency, or dev-dependency.
2424

2525
Will also ensure the proper settings for composite etc. are in use.
26+
27+
For packages that should emit types (any non-test app package) it will
28+
ensure that the declarationDir is added to the files array in package.json.

internal-tooling/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"@pnpm/find-workspace-packages": "6.0.9",
2424
"@pnpm/logger": "1000.0.0"
2525
},
26+
"engines": {
27+
"node": ">= 18.20.7"
28+
},
2629
"volta": {
2730
"extends": "../package.json"
2831
}

internal-tooling/src/-utils.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ export async function getPackageJson({ packageDir, packagesDir }: { packageDir:
3434
return { file: packageJsonFile, pkg, path: packageJsonPath, nicePath: path.join(packageDir, 'package.json') };
3535
}
3636

37+
export async function runPrettier() {
38+
const root = await getMonorepoRoot();
39+
const childProcess = Bun.spawn(['bun', 'lint:prettier:fix'], {
40+
env: process.env,
41+
cwd: root,
42+
stdout: 'inherit',
43+
stderr: 'inherit',
44+
});
45+
await childProcess.exited;
46+
}
47+
3748
type PkgJsonFile = {
3849
name: string;
3950
version: string;
@@ -91,6 +102,11 @@ interface BaseProjectPackage {
91102
tsconfigFile: BunFile;
92103
pkgPath: string;
93104
tsconfigPath: string;
105+
isRoot: boolean;
106+
isPrivate: boolean;
107+
isTooling: boolean;
108+
isConfig: boolean;
109+
isTest: boolean;
94110
pkg: PkgJsonFile;
95111
save: (editStatus: { pkgEdited: boolean; configEdited: Boolean }) => Promise<void>;
96112
}
@@ -138,13 +154,14 @@ export async function walkPackages(
138154
const dir = await getMonorepoRoot();
139155
const packages = await collectAllPackages(dir);
140156
const projects = new Map<string, ProjectPackageWithTsConfig>();
157+
const TestDir = path.join(dir, 'tests');
141158

142159
for (const [name, project] of packages) {
143160
if (config.excludeRoot && name === 'root') continue;
144161
if (config.excludePrivate && project.manifest.private) continue;
145162
if (config.excludeTooling && name === '@warp-drive/internal-tooling') continue;
146163
if (config.excludeConfig && name === '@warp-drive/config') continue;
147-
if (config.excludeTests && project.dir === 'tests') continue;
164+
if (config.excludeTests && project.dir.startsWith(TestDir)) continue;
148165

149166
const pkgPath = path.join(project.dir, 'package.json');
150167
const tsconfigPath = path.join(project.dir, 'tsconfig.json');
@@ -162,6 +179,11 @@ export async function walkPackages(
162179
pkgPath,
163180
hasTsConfig,
164181
tsconfigPath,
182+
isRoot: name === 'root',
183+
isPrivate: project.manifest.private ?? false,
184+
isTooling: name === '@warp-drive/internal-tooling',
185+
isConfig: name === '@warp-drive/config',
186+
isTest: project.dir.startsWith(TestDir),
165187
pkg,
166188
tsconfig,
167189
save: async ({ pkgEdited, configEdited }: { pkgEdited: boolean; configEdited: Boolean }) => {

internal-tooling/src/sync-references.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import debug from 'debug';
44
import path from 'path';
55
import chalk from 'chalk';
6-
import { walkPackages, type ProjectPackage, type ProjectPackageWithTsConfig, type TsConfigFile } from './-utils';
6+
import {
7+
runPrettier,
8+
walkPackages,
9+
type ProjectPackage,
10+
type ProjectPackageWithTsConfig,
11+
type TsConfigFile,
12+
} from './-utils';
713

814
const log = debug('wd:sync-references');
915

@@ -195,8 +201,9 @@ async function main() {
195201
log(
196202
`\n\t${chalk.gray('=').repeat(60)}\n\t\t${chalk.magentaBright('@warp-drive/')}${chalk.greenBright('internal-tooling')} Sync TypeScript References\n\t${chalk.gray('=').repeat(60)}\n\n\t\t${chalk.gray(`Syncing Project References`)}\n\n`
197203
);
204+
let anyFileEdited = false;
198205

199-
walkPackages(async (project: ProjectPackage, projects: Map<string, ProjectPackage>) => {
206+
await walkPackages(async (project: ProjectPackage, projects: Map<string, ProjectPackage>) => {
200207
log(`\t📦 Syncing ${project.pkg.name}`);
201208
let pkgEdited = false;
202209
let tsconfigEdited = false;
@@ -231,6 +238,17 @@ async function main() {
231238
log(`\t\t🔧 Added paths hash to tsconfig.json`);
232239
}
233240

241+
if (!project.isTest) {
242+
if (!project.pkg.files?.includes(tsconfig.compilerOptions!.declarationDir!)) {
243+
project.pkg.files ??= [];
244+
project.pkg.files.push(tsconfig.compilerOptions!.declarationDir!);
245+
pkgEdited = true;
246+
log(
247+
`\t\t🔧 Added types output directory "${tsconfig.compilerOptions.declarationDir}" to files in package.json`
248+
);
249+
}
250+
}
251+
234252
for (const name of referenced) {
235253
const relProject = projects.get(name);
236254
if (!relProject) {
@@ -262,8 +280,13 @@ async function main() {
262280
}
263281
}
264282

265-
await project.save({ pkgEdited, configEdited: tsconfigEdited });
283+
if (pkgEdited || tsconfigEdited) {
284+
anyFileEdited = true;
285+
await project.save({ pkgEdited, configEdited: tsconfigEdited });
286+
}
266287
});
288+
289+
if (anyFileEdited) await runPrettier();
267290
}
268291

269292
main();

warp-drive-packages/core/README.md

-16
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,6 @@ rich application &mdash; letting you ship better experiences more quickly withou
5050

5151
<br>
5252

53-
## Quick Links
54-
55-
- [Installation](#installation)
56-
- [API Docs](https://api.emberjs.com/ember-data/release)
57-
- [Guides](./guides/index.md)
58-
- [Build Config](./packages/build-config/README.md)
59-
- [Ember Compatibility](#compatibility)
60-
- [The Big List of Versions](#the-big-list-of-versions)
61-
- [Contributing](./CONTRIBUTING.md)
62-
- [Community & Help](https://emberjs.com/community)
63-
- [RFCs](https://github.com/emberjs/rfcs/labels/T-ember-data)
64-
- [Team](https://emberjs.com/team)
65-
- [Blog](https://emberjs.com/blog)
66-
67-
<br>
68-
6953
## Installation
7054

7155
```sh

0 commit comments

Comments
 (0)