Skip to content

Commit df88761

Browse files
authored
chore: Update yarn setup to cover all packages in the repository (#1875)
1 parent 8cc2199 commit df88761

File tree

8 files changed

+48
-41
lines changed

8 files changed

+48
-41
lines changed

integration/cjs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
},
1414
"engines": {
1515
"node": ">=18"
16-
}
16+
},
17+
"sideEffects": false
1718
}

integration/esm/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
},
1515
"engines": {
1616
"node": ">=18"
17-
}
17+
},
18+
"sideEffects": false
1819
}

internals/hoist-peer-dependencies/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
},
1010
"dependencies": {
1111
"type-fest": "^5.1.0"
12-
}
12+
},
13+
"sideEffects": false
1314
}

internals/isolate-monorepo-package/package.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@
22
"name": "isolate-monorepo-package",
33
"version": "1.0.0",
44
"private": true,
5-
"author": "Simon Boudrias <admin@simonboudrias.com>",
6-
"license": "MIT",
7-
"repository": {
8-
"type": "git",
9-
"url": "https://github.com/SBoudrias/Inquirer.js.git"
10-
},
115
"sideEffects": false,
12-
"files": [
13-
"dist"
14-
],
156
"description": "Tool for testing package isolation in Yarn workspace monorepo",
167
"type": "module",
178
"bin": "./src/bin.ts",
@@ -31,9 +22,5 @@
3122
},
3223
"engines": {
3324
"node": ">=22.3.0"
34-
},
35-
"publishConfig": {
36-
"access": "public",
37-
"bin": "./dist/bin.js"
3825
}
3926
}

internals/tsconfig/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
},
99
"engines": {
1010
"node": ">=18"
11-
}
11+
},
12+
"sideEffects": false
1213
}

internals/tsconfig/tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
"lib": ["es2023"],
55
"skipLibCheck": false,
66
"esModuleInterop": true,
7-
8-
//========== Use filename extension .ts in imports ==========
97
"allowImportingTsExtensions": true,
10-
// Only needed if compiling to JavaScript
11-
"rewriteRelativeImportExtensions": true // from .ts to .js
8+
"rewriteRelativeImportExtensions": true
129
}
1310
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"prepare": "husky && turbo tsc attw",
5959
"prepack": "find packages/* -maxdepth 1 -type f -name 'README*' -exec sed -i '' -e 's/utm_source=github/utm_source=npmjs/g' {} + && find packages/* -maxdepth 1 -type f -name package.json -exec sh -c 'jq \".devDependencies |= with_entries(select(.value != \\\"workspace:*\\\"))\" \"$1\" > \"$1.tmp\" && mv \"$1.tmp\" \"$1\"' _ {} \\;",
6060
"postpack": "git restore packages/*/package.json packages/*/README.md",
61-
"setup": "node ./tools/setup-packages.ts && prettier --write .",
61+
"setup": "node ./tools/setup-packages.ts && prettier --write . --log-level=silent",
6262
"pretest": "yarn tsc && oxlint && prettier --check . && eslint .",
6363
"test": "vitest --run packages && turbo test",
6464
"tsc": "turbo tsc && tsc -p tsconfig.json"

tools/setup-packages.ts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ function readFile(filepath: string) {
1616
}
1717

1818
function readJSONFile<T>(filepath: string): Promise<T> {
19-
return readFile(filepath).then(JSON.parse);
19+
return readFile(filepath)
20+
.then(JSON.parse)
21+
.catch((error: unknown) => {
22+
console.error(`Error reading ${filepath}: ${error}`);
23+
throw error;
24+
});
2025
}
2126

2227
function fileExists(filepath: string) {
@@ -36,7 +41,7 @@ const versions: Record<string, string> = {};
3641
const rootPkg = await readJSONFile<TshyPackageJson>(
3742
path.join(import.meta.dirname, '../package.json'),
3843
);
39-
const paths = await globby(['packages/**/package.json', '!**/node_modules']);
44+
const paths = await globby(['*/*/package.json', '!**/node_modules']);
4045

4146
const packages = await Promise.all(
4247
paths.map(async (pkgPath: string): Promise<[string, TshyPackageJson]> => {
@@ -53,33 +58,47 @@ for (const [pkgPath, pkg] of packages) {
5358
const dir = path.dirname(pkgPath);
5459
fixPeerDeps(path.resolve(path.join(dir)));
5560

56-
const isTS = await fileExists(path.join(dir, 'src/index.ts'));
61+
const isTS =
62+
(await fileExists(path.join(dir, 'src/index.ts'))) ||
63+
(await fileExists(path.join(dir, 'tsconfig.json')));
5764
const hasReadme = await fileExists(path.join(dir, 'README.md'));
65+
const isPrivate = pkg.private === true;
5866

59-
// Replicate configs that should always be the same.
60-
pkg.engines = rootPkg.engines;
61-
pkg.author = rootPkg.author;
62-
pkg.license = rootPkg.license;
63-
pkg.repository = rootPkg.repository;
64-
pkg.keywords = [...new Set([...(rootPkg.keywords ?? []), ...(pkg.keywords ?? [])])];
65-
pkg.sideEffects = pkg.sideEffects ?? false;
66-
pkg.publishConfig = { access: 'public' };
67-
68-
if (hasReadme) {
69-
const repoPath = dir.split('/').slice(-2).join('/');
70-
pkg.homepage = `https://github.com/SBoudrias/Inquirer.js/blob/main/${repoPath}/README.md`;
67+
pkg.sideEffects ??= false;
68+
69+
// Replicate configs that should always be the same on public package.
70+
if (!isPrivate) {
71+
pkg.author = rootPkg.author;
72+
pkg.license = rootPkg.license;
73+
pkg.repository = rootPkg.repository;
74+
pkg.keywords = [...new Set([...(rootPkg.keywords ?? []), ...(pkg.keywords ?? [])])];
75+
pkg.publishConfig = { access: 'public' };
76+
77+
if (hasReadme) {
78+
const repoPath = dir.split('/').slice(-2).join('/');
79+
pkg.homepage = `https://github.com/SBoudrias/Inquirer.js/blob/main/${repoPath}/README.md`;
80+
}
81+
} else {
82+
// Remove publishing metadata for private packages
83+
delete pkg.author;
84+
delete pkg.license;
85+
delete pkg.repository;
86+
delete pkg.keywords;
87+
delete pkg.homepage;
88+
delete pkg.publishConfig;
89+
delete pkg.files;
7190
}
7291

73-
if (isTS) {
92+
if (isTS && !isPrivate) {
7493
pkg.files = ['dist'];
7594

76-
pkg.devDependencies = pkg.devDependencies ?? {};
95+
pkg.devDependencies ??= {};
7796
pkg.devDependencies['tshy'] = versions['tshy'];
7897

79-
pkg.tshy = pkg.tshy ?? {};
98+
pkg.tshy ??= {};
8099
pkg.tshy.exclude = ['src/**/*.test.ts'];
81100

82-
pkg.scripts = pkg.scripts ?? {};
101+
pkg.scripts ??= {};
83102
pkg.scripts['tsc'] = 'tshy';
84103

85104
// Only set attw if the package is using commonjs

0 commit comments

Comments
 (0)