-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: import with .js and .jsx file extensions (#56)
- Loading branch information
Showing
13 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-env node */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const config = require('../baseEslintConfig')(__dirname) | ||
|
||
module.exports = { | ||
...config, | ||
rules: { | ||
...config.rules, | ||
'import/extensions': [ | ||
2, | ||
'ignorePackages', | ||
{ | ||
ts: 'never', | ||
tsx: 'never', | ||
}, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'bar' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare const content: 'yes' | ||
|
||
export default content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'foo.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'foo.jsx' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'foo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// import relative | ||
import './tsImportee.js' | ||
import './tsxImportee.jsx' | ||
import './dtsImportee.js' | ||
import './dtsImportee.jsx' | ||
import './foo' | ||
import './foo.js' | ||
import './foo.jsx' | ||
import './bar' | ||
|
||
// import using tsconfig.json path mapping | ||
import '#/tsImportee.js' | ||
import '#/tsxImportee.jsx' | ||
import '#/dtsImportee.js' | ||
import '#/dtsImportee.jsx' | ||
import '#/foo' | ||
import '#/foo.js' | ||
import '#/foo.jsx' | ||
import '#/bar' | ||
|
||
// import using tsconfig.json base url | ||
import 'tsImportee.js' | ||
import 'tsxImportee.jsx' | ||
import 'dtsImportee.js' | ||
import 'dtsImportee.jsx' | ||
import 'foo' | ||
import 'foo.js' | ||
import 'foo.jsx' | ||
import 'bar' | ||
|
||
// import from node_module | ||
import 'typescript/lib/typescript.js' | ||
import 'dummy.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* eslint-env node */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
|
||
const path = require('path') | ||
const assert = require('assert') | ||
|
||
const { resolve } = require('../../') | ||
|
||
const config = { | ||
project: path.join(__dirname, 'tsconfig.json'), | ||
} | ||
|
||
const file = path.join(__dirname, 'index.ts') | ||
|
||
function assertResolve(id, relativePath) { | ||
const filePath = path.join(__dirname, relativePath) | ||
assert.deepStrictEqual(resolve(id, file, config), { | ||
found: true, | ||
path: filePath, | ||
}) | ||
assert.deepStrictEqual( | ||
resolve(id, file, { ...config, alwaysTryTypes: true }), | ||
{ found: true, path: filePath }, | ||
) | ||
} | ||
|
||
// import relative | ||
|
||
assertResolve('./tsImportee.js', 'tsImportee.ts') | ||
|
||
assertResolve('./tsxImportee.jsx', 'tsxImportee.tsx') | ||
|
||
assertResolve('./dtsImportee.js', 'dtsImportee.d.ts') | ||
|
||
assertResolve('./dtsImportee.jsx', 'dtsImportee.d.ts') | ||
|
||
assertResolve('./foo', 'foo/index.ts') | ||
|
||
assertResolve('./foo.js', 'foo.js/index.ts') | ||
|
||
assertResolve('./foo.jsx', 'foo.jsx/index.ts') | ||
|
||
assertResolve('./bar', 'bar/index.tsx') | ||
|
||
// import using tsconfig.json path mapping | ||
|
||
assertResolve('#/tsImportee.js', 'tsImportee.ts') | ||
|
||
assertResolve('#/tsxImportee.jsx', 'tsxImportee.tsx') | ||
|
||
assertResolve('#/dtsImportee.js', 'dtsImportee.d.ts') | ||
|
||
assertResolve('#/dtsImportee.jsx', 'dtsImportee.d.ts') | ||
|
||
assertResolve('#/foo', 'foo/index.ts') | ||
|
||
assertResolve('#/foo.js', 'foo.js/index.ts') | ||
|
||
assertResolve('#/foo.jsx', 'foo.jsx/index.ts') | ||
|
||
assertResolve('#/bar', 'bar/index.tsx') | ||
|
||
// import using tsconfig.json base url | ||
|
||
assertResolve('tsImportee.js', 'tsImportee.ts') | ||
|
||
assertResolve('tsxImportee.jsx', 'tsxImportee.tsx') | ||
|
||
assertResolve('dtsImportee.js', 'dtsImportee.d.ts') | ||
|
||
assertResolve('dtsImportee.jsx', 'dtsImportee.d.ts') | ||
|
||
assertResolve('foo', 'foo/index.ts') | ||
|
||
assertResolve('foo.js', 'foo.js/index.ts') | ||
|
||
assertResolve('foo.jsx', 'foo.jsx/index.ts') | ||
|
||
assertResolve('bar', 'bar/index.tsx') | ||
|
||
// import from node_module | ||
|
||
assertResolve( | ||
'typescript/lib/typescript.js', | ||
'../../node_modules/typescript/lib/typescript.js', | ||
) | ||
|
||
assertResolve('dummy.js', '../../node_modules/dummy.js/index.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'tsImportee.ts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "react", | ||
"baseUrl": "./", | ||
"paths": { | ||
"#/*": ["*"] | ||
} | ||
}, | ||
"includes": ["./**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'tsxImportee.tsx' |