Skip to content

Commit

Permalink
Also search for _app file in src/pages
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Apr 2, 2023
1 parent 836ac70 commit 20421a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 44 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"@types/babel__generator": "^7.6.4",
"@types/babel__traverse": "^7.18.0",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/inquirer": "^9.0.0",
"@types/jest": "^29.2.4",
"@types/node": "^18.6.5",
Expand All @@ -61,7 +60,6 @@
"chalk": "^5.0.1",
"commander": "^9.4.0",
"fs-extra": "^10.1.0",
"glob": "^8.0.3",
"inquirer": "^9.1.0",
"ora": "^6.1.2",
"prettier": "^2.7.1"
Expand Down
1 change: 0 additions & 1 deletion src/misc/Filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from "path";
import fs from "fs/promises";
import { existsSync, lstatSync } from "fs";
import fsExtra from "fs-extra";
import glob from "glob";

export class Filesystem {
getParent(filepath: string): string {
Expand Down
21 changes: 18 additions & 3 deletions src/tasks/next/Next_AddRelayEnvironmentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,22 @@ export class Next_AddRelayEnvironmentProvider extends TaskBase {
async run(): Promise<void> {
const mainFilename = "_app" + (this.context.args.typescript ? ".tsx" : ".js");

const mainFile = this.context.env.rel(path.join("pages", mainFilename));
const possibleMainFileLocations = [path.join("pages", mainFilename), path.join("src", "pages", mainFilename)];

let mainFile: RelativePath | null = null;

for (const possibleMainFileLocation of possibleMainFileLocations) {
const file = this.context.env.rel(possibleMainFileLocation);

if (this.context.fs.exists(file.abs)) {
mainFile = file;
break;
}
}

if (!mainFile) {
throw new Error(`${mainFilename} could not be found`);
}

this.updateMessage(this.message + " in " + bold(mainFile.rel));

Expand Down Expand Up @@ -73,7 +88,7 @@ export class Next_AddRelayEnvironmentProvider extends TaskBase {
if (this.context.args.typescript) {
// Import RelayPageProps.
const relayTypesPath = Next_AddTypeHelpers.getRelayTypesPath(this.context);
const relayTypesImportPath = new RelativePath(mainFile.parentDirectory, removeExtension(relayTypesPath.abs));
const relayTypesImportPath = new RelativePath(mainFile!.parentDirectory, removeExtension(relayTypesPath.abs));

insertNamedImport(path, RELAY_PAGE_PROPS, relayTypesImportPath.rel);

Expand Down Expand Up @@ -106,7 +121,7 @@ export class Next_AddRelayEnvironmentProvider extends TaskBase {
insertNamedImport(path, "RecordSource", RELAY_RUNTIME_PACKAGE);

const relayEnvImportPath = new RelativePath(
mainFile.parentDirectory,
mainFile!.parentDirectory,
removeExtension(this.context.relayEnvFile.abs)
);

Expand Down
38 changes: 0 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,6 @@
dependencies:
"@types/node" "*"

"@types/glob@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==
dependencies:
"@types/minimatch" "*"
"@types/node" "*"

"@types/graceful-fs@^4.1.3":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"
Expand Down Expand Up @@ -736,11 +728,6 @@
expect "^29.0.0"
pretty-format "^29.0.0"

"@types/minimatch@*":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==

"@types/node@*", "@types/node@^18.6.5":
version "18.6.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.6.5.tgz#06caea822caf9e59d5034b695186ee74154d2802"
Expand Down Expand Up @@ -937,13 +924,6 @@ brace-expansion@^1.1.7:
balanced-match "^1.0.0"
concat-map "0.0.1"

brace-expansion@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"
integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==
dependencies:
balanced-match "^1.0.0"

braces@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
Expand Down Expand Up @@ -1366,17 +1346,6 @@ glob@^7.1.3, glob@^7.1.4:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^8.0.3:
version "8.0.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e"
integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^5.0.1"
once "^1.3.0"

globals@^11.1.0:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
Expand Down Expand Up @@ -2058,13 +2027,6 @@ minimatch@^3.0.4, minimatch@^3.1.1:
dependencies:
brace-expansion "^1.1.7"

minimatch@^5.0.1:
version "5.1.0"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.0.tgz#1717b464f4971b144f6aabe8f2d0b8e4511e09c7"
integrity sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==
dependencies:
brace-expansion "^2.0.1"

[email protected]:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
Expand Down

0 comments on commit 20421a1

Please sign in to comment.