Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
17420c78
Unverified
Commit
17420c78
authored
Jul 28, 2020
by
Jean Helou
Committed by
GitHub
Jul 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improves baseUrl resolution in typescript monorepos (#13542)
parent
fdfc508a
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
180 additions
and
1 deletion
+180
-1
webpack-config.ts
packages/next/build/webpack-config.ts
+4
-1
api.ts
...gration/typescript-workspaces-paths/packages/lib/a/api.ts
+5
-0
api.ts
...gration/typescript-workspaces-paths/packages/lib/b/api.ts
+4
-0
b-only.ts
...tion/typescript-workspaces-paths/packages/lib/b/b-only.ts
+4
-0
alias-to-d-ts.d.ts
...rkspaces-paths/packages/www/components/alias-to-d-ts.d.ts
+1
-0
alias-to-d-ts.tsx
...orkspaces-paths/packages/www/components/alias-to-d-ts.tsx
+4
-0
hello.tsx
...script-workspaces-paths/packages/www/components/hello.tsx
+5
-0
world.tsx
...script-workspaces-paths/packages/www/components/world.tsx
+5
-0
next.config.js
...n/typescript-workspaces-paths/packages/www/next.config.js
+23
-0
alias-to-d-ts.tsx
...ipt-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx
+10
-0
basic-alias.tsx
...cript-workspaces-paths/packages/www/pages/basic-alias.tsx
+9
-0
resolve-fallback.tsx
...-workspaces-paths/packages/www/pages/resolve-fallback.tsx
+5
-0
resolve-order.tsx
...ipt-workspaces-paths/packages/www/pages/resolve-order.tsx
+5
-0
single-alias.tsx
...ript-workspaces-paths/packages/www/pages/single-alias.tsx
+9
-0
index.test.js
...pescript-workspaces-paths/packages/www/test/index.test.js
+51
-0
tsconfig.json
...on/typescript-workspaces-paths/packages/www/tsconfig.json
+6
-0
tsconfig.json
test/integration/typescript-workspaces-paths/tsconfig.json
+30
-0
No files found.
packages/next/build/webpack-config.ts
View file @
17420c78
...
@@ -15,6 +15,7 @@ import {
...
@@ -15,6 +15,7 @@ import {
}
from
'../lib/constants'
}
from
'../lib/constants'
import
{
fileExists
}
from
'../lib/file-exists'
import
{
fileExists
}
from
'../lib/file-exists'
import
{
resolveRequest
}
from
'../lib/resolve-request'
import
{
resolveRequest
}
from
'../lib/resolve-request'
import
{
getTypeScriptConfiguration
}
from
'../lib/typescript/getTypeScriptConfiguration'
import
{
import
{
CLIENT_STATIC_FILES_RUNTIME_MAIN
,
CLIENT_STATIC_FILES_RUNTIME_MAIN
,
CLIENT_STATIC_FILES_RUNTIME_POLYFILLS
,
CLIENT_STATIC_FILES_RUNTIME_POLYFILLS
,
...
@@ -261,7 +262,9 @@ export default async function getBaseWebpackConfig(
...
@@ -261,7 +262,9 @@ export default async function getBaseWebpackConfig(
let
jsConfig
let
jsConfig
// jsconfig is a subset of tsconfig
// jsconfig is a subset of tsconfig
if
(
useTypeScript
)
{
if
(
useTypeScript
)
{
jsConfig
=
parseJsonFile
(
tsConfigPath
)
const
ts
=
(
await
import
(
typeScriptPath
))
as
typeof
import
(
'typescript'
)
const
tsConfig
=
await
getTypeScriptConfiguration
(
ts
,
tsConfigPath
)
jsConfig
=
{
compilerOptions
:
tsConfig
.
options
}
}
}
const
jsConfigPath
=
path
.
join
(
dir
,
'jsconfig.json'
)
const
jsConfigPath
=
path
.
join
(
dir
,
'jsconfig.json'
)
...
...
test/integration/typescript-workspaces-paths/packages/lib/a/api.ts
0 → 100644
View file @
17420c78
//this line uses typescript specific syntax
//to demonstrate that transpilation occurs
export
type
API
=
()
=>
string
const
api
:
API
=
()
=>
'Hello from a'
export
default
api
test/integration/typescript-workspaces-paths/packages/lib/b/api.ts
0 → 100644
View file @
17420c78
import
{
API
}
from
'@lib/api'
const
b
:
API
=
()
=>
'Hello from b'
export
default
b
test/integration/typescript-workspaces-paths/packages/lib/b/b-only.ts
0 → 100644
View file @
17420c78
import
{
API
}
from
'@lib/api'
const
b
:
API
=
()
=>
'Hello from only b'
export
default
b
test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.d.ts
0 → 100644
View file @
17420c78
export
default
()
=>
any
test/integration/typescript-workspaces-paths/packages/www/components/alias-to-d-ts.tsx
0 → 100644
View file @
17420c78
const
Named
=
()
=>
{
return
<>
Not aliased to d.ts file
</>
}
export
default
Named
test/integration/typescript-workspaces-paths/packages/www/components/hello.tsx
0 → 100644
View file @
17420c78
import
React
from
'react'
export
function
Hello
()
{
return
<>
Hello
</>
}
test/integration/typescript-workspaces-paths/packages/www/components/world.tsx
0 → 100644
View file @
17420c78
import
React
from
'react'
export
function
World
():
JSX
.
Element
{
return
<>
World
</>
}
test/integration/typescript-workspaces-paths/packages/www/next.config.js
0 → 100644
View file @
17420c78
const
path
=
require
(
'path'
)
module
.
exports
=
{
webpack
:
function
(
config
,
{
defaultLoaders
})
{
const
resolvedBaseUrl
=
path
.
resolve
(
config
.
context
,
'../../'
)
config
.
module
.
rules
=
[
...
config
.
module
.
rules
,
{
test
:
/
\.(
tsx|ts|js|mjs|jsx
)
$/
,
include
:
[
resolvedBaseUrl
],
use
:
defaultLoaders
.
babel
,
exclude
:
(
excludePath
)
=>
{
return
/node_modules/
.
test
(
excludePath
)
},
},
]
return
config
},
onDemandEntries
:
{
// Make sure entries are not getting disposed.
maxInactiveAge
:
1000
*
60
*
60
,
},
}
test/integration/typescript-workspaces-paths/packages/www/pages/alias-to-d-ts.tsx
0 → 100644
View file @
17420c78
import
React
from
'react'
import
NotAliasedToDTS
from
'd-ts-alias'
export
default
function
HelloPage
():
JSX
.
Element
{
return
(
<
div
>
<
NotAliasedToDTS
/>
</
div
>
)
}
test/integration/typescript-workspaces-paths/packages/www/pages/basic-alias.tsx
0 → 100644
View file @
17420c78
import
React
from
'react'
import
{
World
}
from
'@c/world'
export
default
function
HelloPage
():
JSX
.
Element
{
return
(
<
div
>
<
World
/>
</
div
>
)
}
test/integration/typescript-workspaces-paths/packages/www/pages/resolve-fallback.tsx
0 → 100644
View file @
17420c78
import
React
from
'react'
import
api
from
'@lib/b-only'
export
default
function
ResolveOrder
():
JSX
.
Element
{
return
<
div
>
{
api
()
}
</
div
>
}
test/integration/typescript-workspaces-paths/packages/www/pages/resolve-order.tsx
0 → 100644
View file @
17420c78
import
React
from
'react'
import
api
from
'@lib/api'
export
default
function
ResolveOrder
():
JSX
.
Element
{
return
<
div
>
{
api
()
}
</
div
>
}
test/integration/typescript-workspaces-paths/packages/www/pages/single-alias.tsx
0 → 100644
View file @
17420c78
import
{
Hello
}
from
'@mycomponent'
export
default
function
SingleAlias
()
{
return
(
<
div
>
<
Hello
/>
</
div
>
)
}
test/integration/typescript-workspaces-paths/packages/www/test/index.test.js
0 → 100644
View file @
17420c78
/* eslint-env jest */
import
{
join
}
from
'path'
import
cheerio
from
'cheerio'
import
{
renderViaHTTP
,
findPort
,
launchApp
,
killApp
}
from
'next-test-utils'
jest
.
setTimeout
(
1000
*
60
*
2
)
const
appDir
=
join
(
__dirname
,
'..'
)
let
appPort
let
app
async
function
get
$
(
path
,
query
)
{
const
html
=
await
renderViaHTTP
(
appPort
,
path
,
query
)
return
cheerio
.
load
(
html
)
}
describe
(
'TypeScript Features'
,
()
=>
{
describe
(
'default behavior'
,
()
=>
{
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
,
{})
})
afterAll
(()
=>
killApp
(
app
))
it
(
'should alias components'
,
async
()
=>
{
const
$
=
await
get
$
(
'/basic-alias'
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/World/
)
})
it
(
'should resolve the first item in the array first'
,
async
()
=>
{
const
$
=
await
get
$
(
'/resolve-order'
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello from a/
)
})
it
(
'should resolve the second item in as a fallback'
,
async
()
=>
{
const
$
=
await
get
$
(
'/resolve-fallback'
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello from only b/
)
})
it
(
'should resolve a single matching alias'
,
async
()
=>
{
const
$
=
await
get
$
(
'/single-alias'
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello/
)
})
it
(
'should not resolve to .d.ts files'
,
async
()
=>
{
const
$
=
await
get
$
(
'/alias-to-d-ts'
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Not aliased to d
\.
ts file/
)
})
})
})
test/integration/typescript-workspaces-paths/packages/www/tsconfig.json
0 → 100644
View file @
17420c78
/*
This
is
a
single
line
comment
to
check
if
that
works
*/
{
"extends"
:
"../../tsconfig.json"
,
"exclude"
:
[
"node_modules"
],
"include"
:
[
"next-env.d.ts"
,
"components"
,
"pages"
]
}
test/integration/typescript-workspaces-paths/tsconfig.json
0 → 100644
View file @
17420c78
/*
This
is
a
single
line
comment
to
check
if
that
works
*/
{
"compilerOptions"
:
{
"baseUrl"
:
"."
,
"paths"
:
{
"isomorphic-unfetch"
:
[
"packages/www/types/unfetch.d.ts"
],
"@c/*"
:
[
"packages/www/components/*"
],
"@lib/*"
:
[
"packages/lib/a/*"
,
"packages/lib/b/*"
],
"@mycomponent"
:
[
"packages/www/components/hello.tsx"
],
"d-ts-alias"
:
[
"packages/www/components/alias-to-d-ts.d.ts"
,
"packages/www/components/alias-to-d-ts.tsx"
]
//
This
is
a
single
line
comment
to
check
if
that
works
},
"esModuleInterop"
:
true
,
"module"
:
"esnext"
,
"jsx"
:
"preserve"
,
"target"
:
"es5"
,
"lib"
:
[
"dom"
,
"dom.iterable"
,
"esnext"
],
"allowJs"
:
true
,
"skipLibCheck"
:
true
,
"strict"
:
true
,
"forceConsistentCasingInFileNames"
:
true
,
"noEmit"
:
true
,
"moduleResolution"
:
"node"
,
"resolveJsonModule"
:
true
,
"isolatedModules"
:
true
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment