Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polish isomorphic path module #36521

Merged
merged 5 commits into from Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/next/lib/constants.ts
@@ -1,6 +1,4 @@
import path from '../shared/lib/isomorphic/path'

const { join } = path
import { join } from '../shared/lib/isomorphic/path'

export const NEXT_PROJECT_ROOT = join(__dirname, '..', '..')
export const NEXT_PROJECT_ROOT_DIST = join(NEXT_PROJECT_ROOT, 'dist')
Expand Down
4 changes: 1 addition & 3 deletions packages/next/server/base-server.ts
Expand Up @@ -17,7 +17,7 @@ import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plug
import type { BaseNextRequest, BaseNextResponse } from './base-http'
import type { PayloadOptions } from './send-payload'

import pathMod from '../shared/lib/isomorphic/path'
import { join, resolve } from '../shared/lib/isomorphic/path'
import { parse as parseQs } from 'querystring'
import { format as formatUrl, parse as parseUrl } from 'url'
import { getRedirectStatus } from '../lib/load-custom-routes'
Expand Down Expand Up @@ -66,8 +66,6 @@ import { PrerenderManifest } from '../build'
import { ImageConfigComplete } from '../shared/lib/image-config'
import { replaceBasePath } from './router-utils'

const { join, resolve } = pathMod

export type FindComponentsResult = {
components: LoadComponentsReturnType
query: NextParsedUrlQuery
Expand Down
4 changes: 1 addition & 3 deletions packages/next/server/normalize-page-path.ts
@@ -1,8 +1,6 @@
import path from '../shared/lib/isomorphic/path'
import { posix } from '../shared/lib/isomorphic/path'
import { isDynamicRoute } from '../shared/lib/router/utils'

const { posix } = path

export { normalizePathSep, denormalizePagePath } from './denormalize-page-path'

export function normalizePagePath(page: string): string {
Expand Down
3 changes: 3 additions & 0 deletions packages/next/shared/lib/isomorphic/path.d.ts
@@ -0,0 +1,3 @@
import m from 'path'

export = m
12 changes: 12 additions & 0 deletions packages/next/shared/lib/isomorphic/path.js
@@ -0,0 +1,12 @@
/**
* This module is for next.js server internal usage of path module.
* It will use native path module for nodejs runtime.
* It will use path-browserify polyfill for edge runtime.
*/

const path =
process.env.NEXT_RUNTIME === 'edge'
? require('next/dist/compiled/path-browserify')
: require('path')

module.exports = path
6 changes: 0 additions & 6 deletions packages/next/shared/lib/isomorphic/path.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/next/types/misc.d.ts
Expand Up @@ -340,11 +340,6 @@ declare module 'next/dist/compiled/process' {
export = m
}

declare module 'next/dist/compiled/path-browserify' {
import m from 'path'
export = m
}

declare module 'pnp-webpack-plugin' {
import webpack from 'webpack4'

Expand Down