Skip to content

Commit

Permalink
fix(configuration): extensions now explicitly required as in webpack
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed Jan 10, 2024
1 parent 1153f89 commit b9863bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions configuration/rspack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default (development: boolean): RspackOptions => {
plugins: getPlugins(development, getPublicPath()),
resolve: {
modules: getRoots(),
extensions: ['...', '.tsx', '.ts', '.jsx'], // "..." means to extend from the default extensions
},
module: {
// Matched from bottom to top!
Expand Down
14 changes: 14 additions & 0 deletions test/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -977,3 +977,17 @@ test('Can import fonts.', async () => {
const mainJsContents = contentsForFilesMatching('*.js', dist)[0].contents
expect(mainJsContents).toContain('.woff2')
})

test('Absolute imports can be used.', async () => {
const { dist } = prepare([
packageJson('absolute'),
file('index.jsx', `import { greeting } from 'hello/world'; console.log(greeting)`),
file('hello/world.jsx', 'export const greeting = "HEY"'),
])

await build(false)

const mainJsContents = contentsForFilesMatching('*.js', dist)[0].contents

expect(mainJsContents).toContain('HEY')
})
34 changes: 33 additions & 1 deletion test/typescript.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { existsSync } from 'fs'
import { test, expect, vi } from 'vitest'
import { environment, prepare, packageJson, file, writeFile, readFile } from 'jest-fixture'
import {
environment,
prepare,
packageJson,
file,
writeFile,
readFile,
contentsForFilesMatching,
} from 'jest-fixture'
import { build, configure } from '../index'

environment('typescript')
Expand Down Expand Up @@ -42,3 +50,27 @@ test('Build with typescript errors fails.', async () => {
),
).toBe(true)
})

test('Absolute imports can be used in TypeScript.', async () => {
const { dist } = prepare([
packageJson('typescript-absolute'),
file('index.tsx', `import { greeting } from 'hello/world'; console.log(greeting)`),
file('hello/world.tsx', 'export const greeting = "HEY"'),
])

writeFile(
'node_modules/papua/configuration/.prettierignore',
readFile('../../../configuration/.prettierignore'),
)
writeFile(
'node_modules/papua/configuration/template.html',
readFile('../../../configuration/template.html'),
)

await configure() // Required for tsconfig.json
await build(false)

const mainJsContents = contentsForFilesMatching('*.js', dist)[0].contents

expect(mainJsContents).toContain('HEY')
})

0 comments on commit b9863bf

Please sign in to comment.