Skip to content

Commit bd4937a

Browse files
committed
chore(deps): update dev dependencies
also re-format with print width 80
1 parent a65dedd commit bd4937a

File tree

3 files changed

+93
-28
lines changed

3 files changed

+93
-28
lines changed

index.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { join } from 'path';
22
import { Plugin } from 'rollup';
3-
import { CompilerOptions, findConfigFile, nodeModuleNameResolver, parseConfigFileTextToJson, sys } from 'typescript';
3+
import {
4+
CompilerOptions,
5+
findConfigFile,
6+
nodeModuleNameResolver,
7+
parseConfigFileTextToJson,
8+
sys,
9+
} from 'typescript';
410

511
export const typescriptPaths = ({
612
absolute = true,
@@ -14,9 +20,15 @@ export const typescriptPaths = ({
1420
return {
1521
name: 'resolve-typescript-paths',
1622
resolveId: (importee: string, importer?: string) => {
17-
const enabled = Boolean(compilerOptions.paths || (compilerOptions.baseUrl && nonRelative));
23+
const enabled = Boolean(
24+
compilerOptions.paths || (compilerOptions.baseUrl && nonRelative),
25+
);
1826

19-
if (typeof importer === 'undefined' || importee.startsWith('\0') || !enabled) {
27+
if (
28+
typeof importer === 'undefined' ||
29+
importee.startsWith('\0') ||
30+
!enabled
31+
) {
2032
return null;
2133
}
2234

@@ -34,7 +46,12 @@ export const typescriptPaths = ({
3446
return null; // never resolve relative modules, only non-relative
3547
}
3648

37-
const { resolvedModule } = nodeModuleNameResolver(importee, importer, compilerOptions, sys);
49+
const { resolvedModule } = nodeModuleNameResolver(
50+
importee,
51+
importer,
52+
compilerOptions,
53+
sys,
54+
);
3855

3956
if (!resolvedModule) {
4057
return null;
@@ -48,10 +65,14 @@ export const typescriptPaths = ({
4865

4966
const targetFileName = join(
5067
outDir,
51-
preserveExtensions ? resolvedFileName : resolvedFileName.replace(/\.tsx?$/i, '.js'),
68+
preserveExtensions
69+
? resolvedFileName
70+
: resolvedFileName.replace(/\.tsx?$/i, '.js'),
5271
);
5372

54-
const resolved = absolute ? sys.resolvePath(targetFileName) : targetFileName;
73+
const resolved = absolute
74+
? sys.resolvePath(targetFileName)
75+
: targetFileName;
5576

5677
return transform ? transform(resolved) : resolved;
5778
},

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"scripts": {
1111
"test": "npm run prepare && node test",
1212
"preversion": "npm test",
13-
"prepare": "tsc"
13+
"prepare": "rm -rf dist && tsc"
1414
},
1515
"author": "Simon Haenisch (https://github.com/simonhaenisch)",
1616
"repository": "simonhaenisch/rollup-plugin-typescript-paths",
@@ -24,17 +24,17 @@
2424
},
2525
"homepage": "https://github.com/simonhaenisch/rollup-plugin-typescript-paths#readme",
2626
"devDependencies": {
27-
"@types/node": "18.6.5",
28-
"prettier": "2.7.1",
29-
"prettier-plugin-organize-imports": "3.0.3",
30-
"rollup": "2.77.2",
31-
"typescript": "4.7.4"
27+
"@types/node": "18.16.18",
28+
"prettier": "2.8.8",
29+
"prettier-plugin-organize-imports": "3.2.2",
30+
"rollup": "2.79.1",
31+
"typescript": "5.1.3"
3232
},
3333
"peerDependencies": {
3434
"typescript": ">=3.4"
3535
},
3636
"prettier": {
37-
"printWidth": 120,
37+
"printWidth": 80,
3838
"singleQuote": true,
3939
"tabWidth": 2,
4040
"trailingComma": "all",

test/index.js

+59-15
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ const typescriptPaths = require('../dist').default;
66

77
const transform = (path) => path.replace(/\.js$/i, '.cjs.js');
88

9-
const plugin = typescriptPaths({ tsConfigPath: resolve(__dirname, 'tsconfig.json') });
9+
const plugin = typescriptPaths({
10+
tsConfigPath: resolve(__dirname, 'tsconfig.json'),
11+
});
1012

11-
const pluginNonAbs = typescriptPaths({ tsConfigPath: resolve(__dirname, 'tsconfig.json'), absolute: false });
13+
const pluginNonAbs = typescriptPaths({
14+
tsConfigPath: resolve(__dirname, 'tsconfig.json'),
15+
absolute: false,
16+
});
1217

13-
const pluginNonRelative = typescriptPaths({ tsConfigPath: resolve(__dirname, 'tsconfig.json'), nonRelative: true });
18+
const pluginNonRelative = typescriptPaths({
19+
tsConfigPath: resolve(__dirname, 'tsconfig.json'),
20+
nonRelative: true,
21+
});
1422

15-
const pluginTransform = typescriptPaths({ tsConfigPath: resolve(__dirname, 'tsconfig.json'), transform });
23+
const pluginTransform = typescriptPaths({
24+
tsConfigPath: resolve(__dirname, 'tsconfig.json'),
25+
transform,
26+
});
1627

1728
const pluginPreserveExtensions = typescriptPaths({
1829
tsConfigPath: resolve(__dirname, 'tsconfig.json'),
@@ -30,39 +41,72 @@ try {
3041
strictEqual(plugin.resolveId('\0@foobar', ''), null);
3142

3243
// resolves with non-wildcard paths
33-
strictEqual(plugin.resolveId('@foobar', ''), join(__dirname, 'foo', 'bar.js'));
34-
strictEqual(plugin.resolveId('@foobar-react', ''), join(__dirname, 'foo', 'bar-react.js'));
44+
strictEqual(
45+
plugin.resolveId('@foobar', ''),
46+
join(__dirname, 'foo', 'bar.js'),
47+
);
48+
strictEqual(
49+
plugin.resolveId('@foobar-react', ''),
50+
join(__dirname, 'foo', 'bar-react.js'),
51+
);
3552

3653
// resolves with wildcard paths
37-
strictEqual(plugin.resolveId('@bar/foo', ''), join(__dirname, 'bar', 'foo.js'));
54+
strictEqual(
55+
plugin.resolveId('@bar/foo', ''),
56+
join(__dirname, 'bar', 'foo.js'),
57+
);
3858

3959
// resolves from a directory with index file
4060
strictEqual(plugin.resolveId('@js', ''), join(__dirname, 'js', 'index.js'));
4161

4262
// resolves without an `@` prefix
43-
strictEqual(plugin.resolveId('bar/foo', ''), join(__dirname, 'bar', 'foo.js'));
63+
strictEqual(
64+
plugin.resolveId('bar/foo', ''),
65+
join(__dirname, 'bar', 'foo.js'),
66+
);
4467

4568
// resolves with a different importer
46-
strictEqual(plugin.resolveId('bar/foo', join(__dirname, 'foo', 'bar.ts')), join(__dirname, 'bar', 'foo.js'));
69+
strictEqual(
70+
plugin.resolveId('bar/foo', join(__dirname, 'foo', 'bar.ts')),
71+
join(__dirname, 'bar', 'foo.js'),
72+
);
4773

4874
// doesn't accidentally resolve relative paths that also have an alias
49-
strictEqual(plugin.resolveId('../bar/foo', join(__dirname, 'foo', 'bar.ts')), null);
75+
strictEqual(
76+
plugin.resolveId('../bar/foo', join(__dirname, 'foo', 'bar.ts')),
77+
null,
78+
);
5079

5180
// skips non-relative paths unless enabled
5281
strictEqual(plugin.resolveId('foo/bar', ''), null);
5382

5483
// resolves non-relative from baseUrl even if no path is matched
55-
strictEqual(pluginNonRelative.resolveId('foo/bar', ''), join(__dirname, 'foo', 'bar.js'));
84+
strictEqual(
85+
pluginNonRelative.resolveId('foo/bar', ''),
86+
join(__dirname, 'foo', 'bar.js'),
87+
);
5688

5789
// resolves as a relative path with option `absolute: false`
58-
strictEqual(pluginNonAbs.resolveId('@foobar', ''), join('test', 'foo', 'bar.js'));
90+
strictEqual(
91+
pluginNonAbs.resolveId('@foobar', ''),
92+
join('test', 'foo', 'bar.js'),
93+
);
5994

6095
// applies function from `transform` option
61-
strictEqual(pluginTransform.resolveId('@foobar', ''), join(__dirname, 'foo', 'bar.cjs.js'));
96+
strictEqual(
97+
pluginTransform.resolveId('@foobar', ''),
98+
join(__dirname, 'foo', 'bar.cjs.js'),
99+
);
62100

63101
// resolves including the file extension with option `preserveExtensions: true`
64-
strictEqual(pluginPreserveExtensions.resolveId('@foobar', ''), join(__dirname, 'foo', 'bar.ts'));
65-
strictEqual(pluginPreserveExtensions.resolveId('@foobar-react', ''), join(__dirname, 'foo', 'bar-react.tsx'));
102+
strictEqual(
103+
pluginPreserveExtensions.resolveId('@foobar', ''),
104+
join(__dirname, 'foo', 'bar.ts'),
105+
);
106+
strictEqual(
107+
pluginPreserveExtensions.resolveId('@foobar-react', ''),
108+
join(__dirname, 'foo', 'bar-react.tsx'),
109+
);
66110

67111
console.log('PASSED');
68112
} catch (error) {

0 commit comments

Comments
 (0)