From d2266bc01b01380e25f4c9be79fb346497ef1fbf Mon Sep 17 00:00:00 2001 From: lp0ql <59675400+lp0ql@users.noreply.github.com> Date: Fri, 27 Jun 2025 16:11:09 +0900 Subject: [PATCH 1/3] Refactor to class-based management; fixes #197 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit クラスベースの実装にリファクタし、同時にissue-197が解消しました。 --- projects/nextjs-appdir/lib/$path.ts | 2 +- projects/nextjs-appdir/out/lib/basic/$path.ts | 2 +- .../nextjs-appdir/out/lib/ignore/$path.ts | 2 +- .../nextjs-appdir/out/lib/static/$path.ts | 2 +- .../src/out/lib/basic/$path.ts | 2 +- .../src/out/lib/ignore/$path.ts | 2 +- .../src/out/lib/static/$path.ts | 2 +- projects/nextjs-src-appdir/src/utils/$path.ts | 2 +- projects/nextjs-stable-appdir/lib/$path.ts | 2 +- .../out/lib/basic/$path.ts | 2 +- .../out/lib/ignore/$path.ts | 2 +- .../out/lib/static/$path.ts | 2 +- src/parseAppDir.ts | 287 +++++++++++------- 13 files changed, 187 insertions(+), 124 deletions(-) diff --git a/projects/nextjs-appdir/lib/$path.ts b/projects/nextjs-appdir/lib/$path.ts index 4dd6069..d81eb38 100644 --- a/projects/nextjs-appdir/lib/$path.ts +++ b/projects/nextjs-appdir/lib/$path.ts @@ -55,7 +55,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-appdir/out/lib/basic/$path.ts b/projects/nextjs-appdir/out/lib/basic/$path.ts index 3c5d192..ed91546 100644 --- a/projects/nextjs-appdir/out/lib/basic/$path.ts +++ b/projects/nextjs-appdir/out/lib/basic/$path.ts @@ -55,7 +55,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-appdir/out/lib/ignore/$path.ts b/projects/nextjs-appdir/out/lib/ignore/$path.ts index cbbbee3..18a4b7d 100644 --- a/projects/nextjs-appdir/out/lib/ignore/$path.ts +++ b/projects/nextjs-appdir/out/lib/ignore/$path.ts @@ -55,7 +55,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-appdir/out/lib/static/$path.ts b/projects/nextjs-appdir/out/lib/static/$path.ts index bb1865e..f227591 100644 --- a/projects/nextjs-appdir/out/lib/static/$path.ts +++ b/projects/nextjs-appdir/out/lib/static/$path.ts @@ -55,7 +55,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-src-appdir/src/out/lib/basic/$path.ts b/projects/nextjs-src-appdir/src/out/lib/basic/$path.ts index eb414b8..e2939c3 100644 --- a/projects/nextjs-src-appdir/src/out/lib/basic/$path.ts +++ b/projects/nextjs-src-appdir/src/out/lib/basic/$path.ts @@ -51,7 +51,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-src-appdir/src/out/lib/ignore/$path.ts b/projects/nextjs-src-appdir/src/out/lib/ignore/$path.ts index 7c9a883..a7a9183 100644 --- a/projects/nextjs-src-appdir/src/out/lib/ignore/$path.ts +++ b/projects/nextjs-src-appdir/src/out/lib/ignore/$path.ts @@ -51,7 +51,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-src-appdir/src/out/lib/static/$path.ts b/projects/nextjs-src-appdir/src/out/lib/static/$path.ts index ef402f1..fa0e019 100644 --- a/projects/nextjs-src-appdir/src/out/lib/static/$path.ts +++ b/projects/nextjs-src-appdir/src/out/lib/static/$path.ts @@ -51,7 +51,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-src-appdir/src/utils/$path.ts b/projects/nextjs-src-appdir/src/utils/$path.ts index 295dba4..1794782 100644 --- a/projects/nextjs-src-appdir/src/utils/$path.ts +++ b/projects/nextjs-src-appdir/src/utils/$path.ts @@ -51,7 +51,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-stable-appdir/lib/$path.ts b/projects/nextjs-stable-appdir/lib/$path.ts index 632057c..105f4cb 100644 --- a/projects/nextjs-stable-appdir/lib/$path.ts +++ b/projects/nextjs-stable-appdir/lib/$path.ts @@ -53,7 +53,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-stable-appdir/out/lib/basic/$path.ts b/projects/nextjs-stable-appdir/out/lib/basic/$path.ts index 3b0b85e..ecaa0b6 100644 --- a/projects/nextjs-stable-appdir/out/lib/basic/$path.ts +++ b/projects/nextjs-stable-appdir/out/lib/basic/$path.ts @@ -53,7 +53,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-stable-appdir/out/lib/ignore/$path.ts b/projects/nextjs-stable-appdir/out/lib/ignore/$path.ts index d05df11..616b447 100644 --- a/projects/nextjs-stable-appdir/out/lib/ignore/$path.ts +++ b/projects/nextjs-stable-appdir/out/lib/ignore/$path.ts @@ -53,7 +53,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/projects/nextjs-stable-appdir/out/lib/static/$path.ts b/projects/nextjs-stable-appdir/out/lib/static/$path.ts index 0ef898f..c970ad9 100644 --- a/projects/nextjs-stable-appdir/out/lib/static/$path.ts +++ b/projects/nextjs-stable-appdir/out/lib/static/$path.ts @@ -53,7 +53,7 @@ export const pagesPath = { 'ccc': { $url: (url?: { hash?: string }) => ({ pathname: '/aaa/[...bbb]/ccc' as const, query: { bbb }, hash: url?.hash, path: `/aaa/${bbb?.join('/')}/ccc${buildSuffix(url)}` }) } - }), + }) }, 'x': { _y: (y: string | number) => ({ diff --git a/src/parseAppDir.ts b/src/parseAppDir.ts index 3765081..6dc946c 100644 --- a/src/parseAppDir.ts +++ b/src/parseAppDir.ts @@ -5,6 +5,7 @@ import type { Slugs } from './parsePagesDir'; import { parseQueryFromTS } from './parseQueryFromTS'; import { replaceWithUnderscore } from './replaceWithUnderscore'; +const PAGE_FILE_NAMES = ['page.tsx', 'page.jsx', 'page.js']; export const createMethods = ( indent: string, importName: string | undefined, @@ -25,13 +26,155 @@ export const createMethods = ( .replace(/\[\[?\.\.\.(.*?)\]\]?/g, `\${$1?.join('/')}`) .replace(/\[(.*?)\]/g, `\${$1}`)}\${buildSuffix(url)}\` })`; +class OutputObject { + /** + * This key is like [slug], not _slug + */ + private objectKey: string; + private parentObject: OutputObject | undefined; + private importName: string | undefined; + private hasPage: boolean = false; + readonly children: OutputObject[] = []; + + get slug(): string | null { + if (!(this.objectKey.startsWith('[') && this.objectKey.endsWith(']'))) return null; + const slug = this.objectKey.replace(/[.[\]]/g, ''); + if (slug === undefined || slug === '') { + return null; + } + return slug; + } + + /** Slugs of this object and all its parents */ + get slugs(): string[] { + const parentSlugs = this.parentObject?.slugs ?? []; + if (this.slug === null) return parentSlugs; + return [...parentSlugs, this.slug]; + } + + private setImportNameIfUndefined(importName: string | undefined) { + if (this.importName === undefined) { + this.importName = importName; + } + } + + private setHasPage() { + this.hasPage = true; + } + + constructor(args: { objectKey: string; parentObject: OutputObject | undefined }) { + this.objectKey = args.objectKey; + this.parentObject = args.parentObject; + } + + private createOrGetExistChildObject( + args: Omit[0], 'parentObject'>, + ): OutputObject { + const childObject = this.children.find((child) => child.objectKey === args.objectKey); + if (childObject !== undefined) { + return childObject; + } else { + const newChildObject = new OutputObject({ ...args, parentObject: this }); + this.children.push(newChildObject); + return newChildObject; + } + } + + get ParentObjects(): OutputObject[] { + if (this.parentObject === undefined) return []; + return [...this.parentObject.ParentObjects, this.parentObject]; + } + + get isRoot(): boolean { + return this.parentObject === undefined; + } + + get objectPath(): string { + return OutputObject.objectPath( + [ + ...this.ParentObjects.filter((parent) => !parent.isRoot).map((parent) => parent.objectKey), + this.objectKey, + ].join('/'), + ); + } + + static objectPath(path: string) { + return OutputObject.ignoreRouteGroupPath(path); + } + + static ignoreRouteGroupPath(path: string) { + return path + .split('/') + .filter((path) => !(path.startsWith('(') && path.endsWith(')'))) + .join('/'); + } + + static ignoreParallelRoutePath(path: string) { + return path + .split('/') + .filter((path) => !path.startsWith('@')) + .join('/'); + } + + static url(path: string) { + return OutputObject.ignoreRouteGroupPath(OutputObject.ignoreParallelRoutePath(path)); + } + + get url(): string { + return OutputObject.url(this.objectPath); + } + + registerPage(args: { directoryRelativePath: string; importName: string | undefined }) { + const splitTargetFileObjectPath = OutputObject.objectPath(args.directoryRelativePath) + .split('/') + .filter((path) => path !== ''); + const splitThisObjectPath = this.objectPath.split('/').filter((path) => path !== ''); + + const nextObjectKey = splitTargetFileObjectPath.find((path, index) => { + return splitThisObjectPath[index] !== path; + }); + + if (nextObjectKey === undefined) { + this.setHasPage(); + this.setImportNameIfUndefined(args.importName); + return; + } + + const nextObject = this.createOrGetExistChildObject({ objectKey: nextObjectKey }); + nextObject.registerPage(args); + } + + toText(): string { + const indent = ' '.repeat(this.ParentObjects.length); + const isRoot = this.ParentObjects.length === 0; + const thisLevelTextBody = this.hasPage + ? createMethods(indent, this.importName, this.slugs, `${this.isRoot ? '' : '/'}${this.url}`) + : null; + + const childrenTexts = this.children + .sort() + .map((child) => child.toText()) + .filter((text) => text !== ''); + + const childrenTextWithThisLevelText = [...childrenTexts, thisLevelTextBody].filter( + (text) => text !== null, + ); + + const bodyText = childrenTextWithThisLevelText.join(',\n'); + const isNullable = this.objectKey.startsWith('[['); + const objectKey = + this.slug === null ? `'${replaceWithUnderscore(this.objectKey)}'` : `_${this.slug}`; + + return `${indent}${isRoot ? '' : `${objectKey}:`} ${this.slug === null ? `{\n${bodyText}\n${indent}}` : `(${this.slug}${isNullable ? '?' : ''}: ${/\[\./.test(this.objectKey) ? 'string[]' : 'string | number'}) => ({\n${bodyText}\n${indent}})`}`; + } +} + export const parseAppDir = ( input: string, output: string, ignorePath: string | undefined, ): { imports: string[]; text: string } => { const ig = createIg(ignorePath); - const pageFileNames = ['page.tsx', 'page.jsx', 'page.js']; const imports: string[] = []; const getImportName = (file: string) => { const result = parseQueryFromTS(output, file); @@ -42,119 +185,39 @@ export const parseAppDir = ( } }; - const createPathObjString = ( - targetDir: string, - parentIndent: string, - url: string, - slugs: Slugs, - text: string, - methodsOfIndexTsFile?: string, - ) => { - const indent = ` ${parentIndent}`; - const props: string[] = fs - .readdirSync(targetDir) - .filter((file) => - [ - !isIgnored(ig, ignorePath, targetDir, file), - fs.statSync(path.posix.join(targetDir, file)).isDirectory(), - ].every(Boolean), - ) - .sort() - .map((file) => { - const newSlugs = [...slugs]; - const target = path.posix.join(targetDir, file); - if (file.startsWith('(') && file.endsWith(')')) { - const indexFile = fs.readdirSync(target).find((name) => pageFileNames.includes(name)); - return createPathObjString( - target, - indent.slice(2), - url, - newSlugs, - '<% props %>', - indexFile && - createMethods( - indent.slice(2), - getImportName(path.posix.join(target, indexFile)), - newSlugs, - url, - ), - ); - } - - const isParallelRoute = file.startsWith('@'); - const newUrl = isParallelRoute ? url : `${url}/${file}`; - - let valFn = `${indent}'${replaceWithUnderscore(file)}': {\n<% next %>\n${indent}}`; - - if (file.startsWith('[') && file.endsWith(']')) { - const slug = file.replace(/[.[\]]/g, ''); - valFn = `${indent}${`_${slug}`}: (${slug}${file.startsWith('[[') ? '?' : ''}: ${ - /\[\./.test(file) ? 'string[]' : 'string | number' - }) => ({\n<% next %>\n${indent}})`; - newSlugs.push(slug); - } - - const indexFile = fs.readdirSync(target).find((name) => pageFileNames.includes(name)); - - return createPathObjString( - target, - indent, - newUrl, - newSlugs, - valFn.replace('<% next %>', '<% props %>'), - indexFile && - createMethods( - indent, - getImportName(path.posix.join(target, indexFile)), - newSlugs, - newUrl, - ), - ); - }) - .filter(Boolean); - - const joinedProps = props - .reduce((accumulator, current) => { - const last = accumulator[accumulator.length - 1]; - - if (last !== undefined) { - const [a, ...b] = last.split('\n'); - const [x, ...y] = current.split('\n'); - - if (a === x) { - y.pop(); - const z = y.pop(); - const merged = [a, ...y, `${z},`, ...b].join('\n'); - return [...accumulator.slice(0, -1), merged]; - } - } - - return [...accumulator, current]; - }, []) - .join(',\n'); - - return text.replace( - '<% props %>', - `${joinedProps}${ - methodsOfIndexTsFile ? `${props.length ? ',\n' : ''}${methodsOfIndexTsFile}` : '' - }`, - ); - }; + // init root directory object + const outputObject = new OutputObject({ + objectKey: '/', + parentObject: undefined, + }); - const rootIndexFile = fs.readdirSync(input).find((name) => pageFileNames.includes(name)); - const rootIndent = ''; - let rootMethods; + const scanDirectoryRecursively = (targetDirectoryPath: string) => { + if (!fs.statSync(targetDirectoryPath).isDirectory()) { + throw new Error(`${targetDirectoryPath} is not a directory`); + } - if (rootIndexFile) { - rootMethods = createMethods( - rootIndent, - getImportName(path.posix.join(input, rootIndexFile)), - [], - '/', - ); - } + const filteredThisDirectoryItems = fs.readdirSync(targetDirectoryPath).filter((item) => { + return !isIgnored(ig, ignorePath, targetDirectoryPath, item); + }); + + const pageFile = filteredThisDirectoryItems.find((item) => PAGE_FILE_NAMES.includes(item)); + if (pageFile) { + outputObject.registerPage({ + directoryRelativePath: path.relative(input, targetDirectoryPath), + importName: getImportName(path.posix.join(targetDirectoryPath, pageFile)), + }); + } + + filteredThisDirectoryItems.forEach((item) => { + const subDirectoryPath = path.posix.join(targetDirectoryPath, item); + if (fs.statSync(subDirectoryPath).isDirectory()) { + scanDirectoryRecursively(subDirectoryPath); + } + }); + }; + scanDirectoryRecursively(input); - const text = createPathObjString(input, rootIndent, '', [], '<% props %>', rootMethods); + const result = outputObject.toText().trim().slice(2).slice(0, -2); - return { imports, text }; + return { imports, text: result }; }; From 1c4b1a037199beeb9906a3e76e137659c8f82f6c Mon Sep 17 00:00:00 2001 From: lp0ql <59675400+lp0ql@users.noreply.github.com> Date: Sat, 28 Jun 2025 17:52:06 +0900 Subject: [PATCH 2/3] add test case for issue 197 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit テストパターンの追加と期待値の修正を行いました。 --- projects/nextjs-appdir/app/(group2)/blog/analytics/page.tsx | 0 projects/nextjs-appdir/app/(group2)/blog/page.tsx | 0 projects/nextjs-appdir/lib/$path.ts | 6 +++++- projects/nextjs-appdir/out/lib/basic/$path.ts | 6 +++++- projects/nextjs-appdir/out/lib/ignore/$path.ts | 6 +++++- projects/nextjs-appdir/out/lib/static/$path.ts | 6 +++++- .../src/app/(group2)/blog/analytics/page.tsx | 0 projects/nextjs-src-appdir/src/app/(group2)/blog/page.tsx | 0 projects/nextjs-src-appdir/src/out/lib/basic/$path.ts | 6 +++++- projects/nextjs-src-appdir/src/out/lib/ignore/$path.ts | 6 +++++- projects/nextjs-src-appdir/src/out/lib/static/$path.ts | 6 +++++- projects/nextjs-src-appdir/src/utils/$path.ts | 6 +++++- .../app/(group2)/blog/analytics/page.tsx | 0 projects/nextjs-stable-appdir/app/(group2)/blog/page.tsx | 0 projects/nextjs-stable-appdir/lib/$path.ts | 6 +++++- projects/nextjs-stable-appdir/out/lib/basic/$path.ts | 6 +++++- projects/nextjs-stable-appdir/out/lib/ignore/$path.ts | 6 +++++- projects/nextjs-stable-appdir/out/lib/static/$path.ts | 6 +++++- 18 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 projects/nextjs-appdir/app/(group2)/blog/analytics/page.tsx create mode 100644 projects/nextjs-appdir/app/(group2)/blog/page.tsx create mode 100644 projects/nextjs-src-appdir/src/app/(group2)/blog/analytics/page.tsx create mode 100644 projects/nextjs-src-appdir/src/app/(group2)/blog/page.tsx create mode 100644 projects/nextjs-stable-appdir/app/(group2)/blog/analytics/page.tsx create mode 100644 projects/nextjs-stable-appdir/app/(group2)/blog/page.tsx diff --git a/projects/nextjs-appdir/app/(group2)/blog/analytics/page.tsx b/projects/nextjs-appdir/app/(group2)/blog/analytics/page.tsx new file mode 100644 index 0000000..e69de29 diff --git a/projects/nextjs-appdir/app/(group2)/blog/page.tsx b/projects/nextjs-appdir/app/(group2)/blog/page.tsx new file mode 100644 index 0000000..e69de29 diff --git a/projects/nextjs-appdir/lib/$path.ts b/projects/nextjs-appdir/lib/$path.ts index d81eb38..5403834 100644 --- a/projects/nextjs-appdir/lib/$path.ts +++ b/projects/nextjs-appdir/lib/$path.ts @@ -48,7 +48,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-appdir/out/lib/basic/$path.ts b/projects/nextjs-appdir/out/lib/basic/$path.ts index ed91546..277dfc3 100644 --- a/projects/nextjs-appdir/out/lib/basic/$path.ts +++ b/projects/nextjs-appdir/out/lib/basic/$path.ts @@ -48,7 +48,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-appdir/out/lib/ignore/$path.ts b/projects/nextjs-appdir/out/lib/ignore/$path.ts index 18a4b7d..4d58184 100644 --- a/projects/nextjs-appdir/out/lib/ignore/$path.ts +++ b/projects/nextjs-appdir/out/lib/ignore/$path.ts @@ -48,7 +48,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-appdir/out/lib/static/$path.ts b/projects/nextjs-appdir/out/lib/static/$path.ts index f227591..0aa334e 100644 --- a/projects/nextjs-appdir/out/lib/static/$path.ts +++ b/projects/nextjs-appdir/out/lib/static/$path.ts @@ -48,7 +48,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-src-appdir/src/app/(group2)/blog/analytics/page.tsx b/projects/nextjs-src-appdir/src/app/(group2)/blog/analytics/page.tsx new file mode 100644 index 0000000..e69de29 diff --git a/projects/nextjs-src-appdir/src/app/(group2)/blog/page.tsx b/projects/nextjs-src-appdir/src/app/(group2)/blog/page.tsx new file mode 100644 index 0000000..e69de29 diff --git a/projects/nextjs-src-appdir/src/out/lib/basic/$path.ts b/projects/nextjs-src-appdir/src/out/lib/basic/$path.ts index e2939c3..f3a22c8 100644 --- a/projects/nextjs-src-appdir/src/out/lib/basic/$path.ts +++ b/projects/nextjs-src-appdir/src/out/lib/basic/$path.ts @@ -44,7 +44,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-src-appdir/src/out/lib/ignore/$path.ts b/projects/nextjs-src-appdir/src/out/lib/ignore/$path.ts index a7a9183..9661ad5 100644 --- a/projects/nextjs-src-appdir/src/out/lib/ignore/$path.ts +++ b/projects/nextjs-src-appdir/src/out/lib/ignore/$path.ts @@ -44,7 +44,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-src-appdir/src/out/lib/static/$path.ts b/projects/nextjs-src-appdir/src/out/lib/static/$path.ts index fa0e019..fb66c53 100644 --- a/projects/nextjs-src-appdir/src/out/lib/static/$path.ts +++ b/projects/nextjs-src-appdir/src/out/lib/static/$path.ts @@ -44,7 +44,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-src-appdir/src/utils/$path.ts b/projects/nextjs-src-appdir/src/utils/$path.ts index 1794782..1c4edf9 100644 --- a/projects/nextjs-src-appdir/src/utils/$path.ts +++ b/projects/nextjs-src-appdir/src/utils/$path.ts @@ -44,7 +44,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-stable-appdir/app/(group2)/blog/analytics/page.tsx b/projects/nextjs-stable-appdir/app/(group2)/blog/analytics/page.tsx new file mode 100644 index 0000000..e69de29 diff --git a/projects/nextjs-stable-appdir/app/(group2)/blog/page.tsx b/projects/nextjs-stable-appdir/app/(group2)/blog/page.tsx new file mode 100644 index 0000000..e69de29 diff --git a/projects/nextjs-stable-appdir/lib/$path.ts b/projects/nextjs-stable-appdir/lib/$path.ts index 105f4cb..e742c42 100644 --- a/projects/nextjs-stable-appdir/lib/$path.ts +++ b/projects/nextjs-stable-appdir/lib/$path.ts @@ -46,7 +46,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-stable-appdir/out/lib/basic/$path.ts b/projects/nextjs-stable-appdir/out/lib/basic/$path.ts index ecaa0b6..9d80d7b 100644 --- a/projects/nextjs-stable-appdir/out/lib/basic/$path.ts +++ b/projects/nextjs-stable-appdir/out/lib/basic/$path.ts @@ -46,7 +46,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-stable-appdir/out/lib/ignore/$path.ts b/projects/nextjs-stable-appdir/out/lib/ignore/$path.ts index 616b447..34da8a9 100644 --- a/projects/nextjs-stable-appdir/out/lib/ignore/$path.ts +++ b/projects/nextjs-stable-appdir/out/lib/ignore/$path.ts @@ -46,7 +46,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ diff --git a/projects/nextjs-stable-appdir/out/lib/static/$path.ts b/projects/nextjs-stable-appdir/out/lib/static/$path.ts index c970ad9..ec71c09 100644 --- a/projects/nextjs-stable-appdir/out/lib/static/$path.ts +++ b/projects/nextjs-stable-appdir/out/lib/static/$path.ts @@ -46,7 +46,11 @@ export const pagesPath = { _fuga: (fuga?: string[]) => ({ $url: (url?: { hash?: string }) => ({ pathname: '/blog/hoge/[[...fuga]]' as const, query: { fuga }, hash: url?.hash, path: `/blog/hoge/${fuga?.join('/')}${buildSuffix(url)}` }) }) - } + }, + 'analytics': { + $url: (url?: { hash?: string }) => ({ pathname: '/blog/analytics' as const, hash: url?.hash, path: `/blog/analytics${buildSuffix(url)}` }) + }, + $url: (url?: { hash?: string }) => ({ pathname: '/blog' as const, hash: url?.hash, path: `/blog${buildSuffix(url)}` }) }, 'aaa': { _bbb: (bbb: string[]) => ({ From ea52cb69c216f05a71a148045ce86df9fbd831f0 Mon Sep 17 00:00:00 2001 From: lp0ql <59675400+lp0ql@users.noreply.github.com> Date: Sat, 28 Jun 2025 19:30:18 +0900 Subject: [PATCH 3/3] Revert variable renames --- src/parseAppDir.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parseAppDir.ts b/src/parseAppDir.ts index 6dc946c..8933af8 100644 --- a/src/parseAppDir.ts +++ b/src/parseAppDir.ts @@ -217,7 +217,7 @@ export const parseAppDir = ( }; scanDirectoryRecursively(input); - const result = outputObject.toText().trim().slice(2).slice(0, -2); + const text = outputObject.toText().trim().slice(2).slice(0, -2); - return { imports, text: result }; + return { imports, text }; };