Skip to content

Commit ec82741

Browse files
jhubbardsfmjameswh
andauthored
fix: update create-package to recursively find package.json and tsconfig.json files during sample creation (#1089)
Co-authored-by: James Watkins-Harvey <mjameswh@gmail.com>
1 parent 1ddd669 commit ec82741

File tree

5 files changed

+89
-47
lines changed

5 files changed

+89
-47
lines changed

package-lock.json

Lines changed: 81 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/create-project/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"chalk-template": "^0.4.0",
2525
"commander": "^9.3.0",
2626
"dedent": "^0.7.0",
27-
"glob": "^8.0.3",
27+
"glob": "^9.3.2",
2828
"got": "^12.1.0",
2929
"prompts": "^2.4.2",
3030
"tar": "^6.1.13",

packages/create-project/src/helpers/install.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Modified from: https://github.com/vercel/next.js/blob/2425f4703c4c6164cecfdb6aa8f80046213f0cc6/packages/create-next-app/helpers/install.ts
22
import { readFile, writeFile } from 'node:fs/promises';
3-
3+
import { glob } from 'glob';
44
import { spawn } from './subprocess.js';
55
import { isUrlOk } from './samples.js';
6-
import { getErrorCode } from './get-error-code.js';
76

87
interface InstallArgs {
98
root: string;
@@ -38,25 +37,14 @@ export async function updateNodeVersion({ root }: InstallArgs): Promise<void> {
3837

3938
if (currentNodeVersion >= minimumValidVersion && currentNodeVersion !== versionAlreadyInPackageJson) {
4039
const packageName = `@tsconfig/node${currentNodeVersion}`;
41-
const fileName = `${root}/package.json`;
4240

4341
const packageExists = await isUrlOk(`https://registry.npmjs.org/${packageName}`);
4442
if (packageExists) {
45-
let fileString = (await readFile(fileName)).toString();
46-
await writeFile(fileName, fileString.replace(`@tsconfig/node${versionAlreadyInPackageJson}`, packageName));
47-
48-
const tsconfigJson = `${root}/tsconfig.json`;
49-
50-
try {
51-
fileString = (await readFile(tsconfigJson)).toString();
52-
await writeFile(tsconfigJson, fileString.replace(`@tsconfig/node${versionAlreadyInPackageJson}`, packageName));
53-
} catch (error) {
54-
const code = getErrorCode(error);
43+
const fileNames = await glob([`${root}/**/package.json`, `${root}/**/tsconfig.json`]);
5544

56-
// If the file doesn't exist, that's fine
57-
if (code !== 'ENOENT') {
58-
throw error;
59-
}
45+
for (const fileName of fileNames) {
46+
const fileString = (await readFile(fileName)).toString();
47+
await writeFile(fileName, fileString.replace(`@tsconfig/node${versionAlreadyInPackageJson}`, packageName));
6048
}
6149
}
6250

packages/create-project/src/helpers/strip-snip-comments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import path from 'node:path';
22
import { readFile, writeFile } from 'node:fs/promises';
3-
import glob from 'glob'; // eslint-disable-line import/no-named-as-default
3+
import { sync } from 'glob';
44

55
export async function stripSnipComments(root: string): Promise<void> {
6-
const files = glob.sync('**/*.ts', { cwd: root });
6+
const files = sync('**/*.ts', { cwd: root });
77
await Promise.all(
88
files.map(async (file) => {
99
const filePath = path.join(root, file);

packages/test/src/integration-tests.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import path from 'node:path';
33
import v8 from 'node:v8';
44
import { readFileSync } from 'node:fs';
5-
import * as grpc from '@grpc/grpc-js';
65
import asyncRetry from 'async-retry';
76
import anyTest, { Implementation, TestFn } from 'ava';
87
import dedent from 'dedent';

0 commit comments

Comments
 (0)