Skip to content

Commit fe0f759

Browse files
committed
fix: changed package.json to match tsconfig build options. ran build
1 parent 5dd2c13 commit fe0f759

12 files changed

+178
-45
lines changed

lib/index.d.ts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
declare const _default: {
2+
rules: {
3+
'no-aliased-imports': {
4+
meta: {
5+
type: string;
6+
fixable: string;
7+
hasSuggestions: boolean;
8+
schema: {
9+
type: string;
10+
properties: {
11+
aliases: {
12+
type: string;
13+
items: {
14+
type: string;
15+
properties: {
16+
prefix: {
17+
type: string;
18+
};
19+
target: {
20+
type: string;
21+
};
22+
};
23+
required: string[];
24+
};
25+
default: {
26+
prefix: string;
27+
target: string;
28+
}[];
29+
};
30+
includeFolders: {
31+
type: string;
32+
items: {
33+
type: string;
34+
};
35+
default: string[];
36+
};
37+
autoFix: {
38+
type: string;
39+
};
40+
};
41+
additionalProperties: boolean;
42+
}[];
43+
messages: {
44+
noAlias: string;
45+
noAliasNoAutofix: string;
46+
};
47+
};
48+
defaultOptions: {
49+
aliases: {
50+
prefix: string;
51+
target: string;
52+
}[];
53+
includeFolders: string[];
54+
autoFix: boolean;
55+
}[];
56+
create(context: any): {
57+
importDeclaration(node: any): void;
58+
};
59+
};
60+
};
61+
};
62+
export default _default;
63+
//# sourceMappingURL=index.d.ts.map

lib/index.d.ts.map

+1
Original file line numberDiff line numberDiff line change

lib/index.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/no-aliased-imports.d.ts

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
1-
export {};
1+
export declare const noAliasedImportsInSrcRule: {
2+
meta: {
3+
type: string;
4+
fixable: string;
5+
hasSuggestions: boolean;
6+
schema: {
7+
type: string;
8+
properties: {
9+
aliases: {
10+
type: string;
11+
items: {
12+
type: string;
13+
properties: {
14+
prefix: {
15+
type: string;
16+
};
17+
target: {
18+
type: string;
19+
};
20+
};
21+
required: string[];
22+
};
23+
default: {
24+
prefix: string;
25+
target: string;
26+
}[];
27+
};
28+
includeFolders: {
29+
type: string;
30+
items: {
31+
type: string;
32+
};
33+
default: string[];
34+
};
35+
autoFix: {
36+
type: string;
37+
};
38+
};
39+
additionalProperties: boolean;
40+
}[];
41+
messages: {
42+
noAlias: string;
43+
noAliasNoAutofix: string;
44+
};
45+
};
46+
defaultOptions: {
47+
aliases: {
48+
prefix: string;
49+
target: string;
50+
}[];
51+
includeFolders: string[];
52+
autoFix: boolean;
53+
}[];
54+
create(context: any): {
55+
importDeclaration(node: any): void;
56+
};
57+
};
258
//# sourceMappingURL=no-aliased-imports.d.ts.map

lib/rules/no-aliased-imports.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

lib/rules/no-aliased-imports.js

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/no-aliased-imports.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tsbuildinfo

+1-1
Large diffs are not rendered by default.

package.json

+6-14
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,14 @@
99
"url": "https://github.com/MatrixAI/js-logger.git"
1010
},
1111
"type": "module",
12-
"main": "index.js",
12+
"main": "./lib/index.js",
13+
"types": "./lib/index.d.ts",
1314
"exports": {
14-
"./package.json": "./package.json",
15-
".": {
16-
"types": "./dist/index.d.ts",
17-
"import": "./dist/index.js"
18-
},
19-
"./*.js": {
20-
"types": "./dist/*.d.ts",
21-
"import": "./dist/*.js"
22-
},
23-
"./*": "./dist/*"
24-
},
25-
"imports": {
26-
"#*": "./dist/*"
15+
"import": "./lib/index.js",
16+
"require": "./lib/index.cjs",
17+
"types": "./lib/index.d.ts"
2718
},
19+
"./package.json": "./package.json",
2820
"scripts": {
2921
"prepare": "tsc -p ./tsconfig.build.json",
3022
"build": "shx rm -rf ./dist && tsc -p ./tsconfig.build.json",

src/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { noAliasedImportsRule } from './rules/no-aliased-imports.js';
2+
3+
export default {
4+
rules: {
5+
'no-aliased-imports': noAliasedImportsRule,
6+
},
7+
};

src/rules/no-aliased-imports.ts

+26-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path';
22

3-
module.exports = {
3+
export const noAliasedImportsRule = {
44
meta: {
55
type: 'suggestion',
66
fixable: 'code',
@@ -37,8 +37,10 @@ module.exports = {
3737
},
3838
],
3939
messages: {
40-
noAlias: 'Use relative import instead of alias import in src files "{{ aliasImport }}".',
41-
noAliasNoAutofix: 'Use relative import instead of alias import in src files "{{ aliasImport }}" (auto-fix is disabled - enable in config if desired.)',
40+
noAlias:
41+
'Use relative import instead of alias import in src files "{{ aliasImport }}".',
42+
noAliasNoAutofix:
43+
'Use relative import instead of alias import in src files "{{ aliasImport }}" (auto-fix is disabled - enable in config if desired.)',
4244
},
4345
},
4446
// Provide defaults if none are given
@@ -50,46 +52,50 @@ module.exports = {
5052
},
5153
],
5254
create(context) {
53-
const options = context.options[0] || {};
54-
const {
55-
aliases,
56-
includeFolders,
57-
autoFix,
58-
} = options;
55+
const options = context.options[0] || {};
56+
const { aliases, includeFolders, autoFix } = options;
5957
return {
60-
ImportDeclaration(node) {
58+
importDeclaration(node) {
6159
const importPath = node.source.value;
6260

6361
// The absolute path of the current file being linted
6462
const filename = context.getFilename();
6563

6664
// 1) Check if the file is in one of the "includeFolders"
6765
const isInIncludedFolder = includeFolders.some((folder) => {
68-
return filename.includes(`${path.sep}${folder}${path.sep}`)
69-
|| filename.endsWith(`${path.sep}${folder}`);
66+
return (
67+
filename.includes(`${path.sep}${folder}${path.sep}`) ||
68+
filename.endsWith(`${path.sep}${folder}`)
69+
);
7070
// ^ endsWith check so that if 'src' is the last part of the path, it still matches
7171
});
7272

7373
// File is not in any of the included folders, so skip
74-
if (!isInIncludedFolder) { return; }
74+
if (!isInIncludedFolder) {
75+
return;
76+
}
7577

7678
// 2) Check if the import path starts with any of the alias prefixes
77-
const matchedAlias = aliases.find((aliasObj) => importPath.startsWith(aliasObj.prefix));
79+
const matchedAlias = aliases.find((aliasObj) =>
80+
importPath.startsWith(aliasObj.prefix),
81+
);
7882

79-
// doesn't match any alias prefix, so skip
80-
if (matchedAlias == null) { return; }
83+
// Doesn't match any alias prefix, so skip
84+
if (matchedAlias == null) {
85+
return;
86+
}
8187

8288
// For example: prefix = '#' => target = 'src'
8389
const { prefix, target } = matchedAlias;
8490

85-
// localPart is the substring after the alias prefix
91+
// LocalPart is the substring after the alias prefix
8692
// e.g. `#db/utils.js` => `db/utils.js`
87-
const localPart = importPath.slice(prefix.length);
93+
const localPart = importPath.slice(prefix.length);
8894

8995
// 3) Build the absolute path to the *real* file
9096
// e.g. => <PROJECT_ROOT>/src/db/utils.js
9197
// or if alias is { prefix: '@', target: 'lib' } => <PROJECT_ROOT>/lib/db/utils.js
92-
const projectRoot = context.cwd;
98+
const projectRoot = context.cwd;
9399
const absoluteImportPath = path.join(projectRoot, target, localPart);
94100

95101
// 4) Compute the relative path from the current file
@@ -104,7 +110,7 @@ module.exports = {
104110
? (fixer) => {
105111
return fixer.replaceTextRange(
106112
[node.source.range[0], node.source.range[1]],
107-
`'${relativePath}'`
113+
`'${relativePath}'`,
108114
);
109115
}
110116
: null;

0 commit comments

Comments
 (0)