@mui/internal-babel-plugin-resolve-imports 2.0.7-canary.8 → 3.0.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/index.js +22 -11
- package/package.json +24 -15
- package/resolve.d.ts +2 -2
- package/index.test.js +0 -111
- package/tsconfig.json +0 -19
- package/vite.config.mts +0 -8
package/LICENSE
CHANGED
package/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
|
|
2
3
|
/// <reference path="./resolve.d.ts" />
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import * as nodePath from 'node:path';
|
|
6
|
+
import resolve from 'resolve/sync.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
|
-
* @
|
|
9
|
+
* @template {import('@babel/core').types.Node | null} [T=import('@babel/core').types.Node]
|
|
10
|
+
* @typedef {import('@babel/core').NodePath<T>} NodePath
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -32,11 +34,11 @@ function pathToNodeImportSpecifier(importPath) {
|
|
|
32
34
|
*/
|
|
33
35
|
|
|
34
36
|
/**
|
|
35
|
-
* @param {babel} file
|
|
37
|
+
* @param {import('@babel/core').PluginAPI} file
|
|
36
38
|
* @param {Options} options
|
|
37
|
-
* @returns {babel.
|
|
39
|
+
* @returns {import('@babel/core').PluginObject}
|
|
38
40
|
*/
|
|
39
|
-
|
|
41
|
+
export default function plugin({ types: t }, { outExtension }) {
|
|
40
42
|
/** @type {Map<string, string>} */
|
|
41
43
|
const cache = new Map();
|
|
42
44
|
const extensions = ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx'];
|
|
@@ -44,12 +46,18 @@ module.exports = function plugin({ types: t }, { outExtension }) {
|
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
*
|
|
47
|
-
* @param {
|
|
48
|
-
* @param {babel.PluginPass} state
|
|
49
|
+
* @param {NodePath<import('@babel/core').types.StringLiteral>} importSource
|
|
50
|
+
* @param {import('@babel/core').PluginPass} state
|
|
49
51
|
*/
|
|
50
52
|
function doResolve(importSource, state) {
|
|
51
53
|
const importedPath = importSource.node.value;
|
|
52
54
|
|
|
55
|
+
const importExt = nodePath.extname(importedPath);
|
|
56
|
+
// ignore if the import already has a desired extension or if it is a css import.
|
|
57
|
+
if (extensionsSet.has(importExt) || importExt === '.css') {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
53
61
|
if (!importedPath.startsWith('.')) {
|
|
54
62
|
// Only handle relative imports
|
|
55
63
|
return;
|
|
@@ -95,8 +103,11 @@ module.exports = function plugin({ types: t }, { outExtension }) {
|
|
|
95
103
|
return {
|
|
96
104
|
visitor: {
|
|
97
105
|
TSImportType(path, state) {
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
// Babel 7 keeps the specifier in `argument`, Babel 8 renamed it to `source`.
|
|
107
|
+
const source = path.node.source ? path.get('source') : path.get('argument');
|
|
108
|
+
if (source.isStringLiteral()) {
|
|
109
|
+
doResolve(source, state);
|
|
110
|
+
}
|
|
100
111
|
},
|
|
101
112
|
CallExpression(path, state) {
|
|
102
113
|
const callee = path.get('callee');
|
|
@@ -129,4 +140,4 @@ module.exports = function plugin({ types: t }, { outExtension }) {
|
|
|
129
140
|
},
|
|
130
141
|
},
|
|
131
142
|
};
|
|
132
|
-
}
|
|
143
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-babel-plugin-resolve-imports",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1-canary.0",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "Babel plugin that resolves import specifiers to their actual output file.",
|
|
6
|
+
"license": "MIT",
|
|
6
7
|
"main": "./index.js",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": "./index.js"
|
|
@@ -12,27 +13,35 @@
|
|
|
12
13
|
"url": "git+https://github.com/mui/mui-public.git",
|
|
13
14
|
"directory": "packages/babel-plugin-resolve-imports"
|
|
14
15
|
},
|
|
15
|
-
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"resolve": "^1.22.
|
|
17
|
+
"resolve": "^1.22.12"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@babel/core": "
|
|
21
|
-
"@babel/plugin-syntax-typescript": "
|
|
22
|
-
"@babel/preset-typescript": "
|
|
23
|
-
"@types/
|
|
24
|
-
"@types/
|
|
25
|
-
"@types/
|
|
26
|
-
"
|
|
27
|
-
"babel-plugin-tester": "^12.0.0",
|
|
28
|
-
"chai": "^4.5.0"
|
|
20
|
+
"@babel/core": "8.0.5",
|
|
21
|
+
"@babel/plugin-syntax-typescript": "8.0.1",
|
|
22
|
+
"@babel/preset-typescript": "8.0.1",
|
|
23
|
+
"@types/chai": "5.2.3",
|
|
24
|
+
"@types/node": "22.20.2",
|
|
25
|
+
"@types/resolve": "1.20.6",
|
|
26
|
+
"babel-plugin-tester": "12.0.0"
|
|
29
27
|
},
|
|
30
28
|
"peerDependencies": {
|
|
31
|
-
"@babel/core": "
|
|
29
|
+
"@babel/core": "^8.0.0"
|
|
32
30
|
},
|
|
33
31
|
"publishConfig": {
|
|
34
32
|
"access": "public"
|
|
35
33
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
34
|
+
"type": "module",
|
|
35
|
+
"files": [
|
|
36
|
+
"index.js",
|
|
37
|
+
"resolve.d.ts",
|
|
38
|
+
"README.md"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=22.12.0"
|
|
42
|
+
},
|
|
43
|
+
"gitSha": "764e3b3cfc14293e74e93f3413609025f502bab9",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"typescript": "tsc -noEmit"
|
|
46
|
+
}
|
|
38
47
|
}
|
package/resolve.d.ts
CHANGED
package/index.test.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { pluginTester } from 'babel-plugin-tester';
|
|
4
|
-
import plugin from './index';
|
|
5
|
-
|
|
6
|
-
const fixturePath = path.resolve(__dirname, './__fixtures__');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Reads the output fixture and normalizes line endings
|
|
10
|
-
* @param {string} fixture
|
|
11
|
-
* @param {string} file
|
|
12
|
-
* @returns {string}
|
|
13
|
-
*/
|
|
14
|
-
function readOutputFixtureSync(fixture, file) {
|
|
15
|
-
// babel hardcodes the linefeed to \n and can add extra newlines
|
|
16
|
-
return normalizeQuotesAndWhitespace(
|
|
17
|
-
fs
|
|
18
|
-
.readFileSync(path.join(fixturePath, fixture, file), { encoding: 'utf8' })
|
|
19
|
-
.replace(/\r?\n/g, '\n'),
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Normalize string quotes and whitespace for comparison
|
|
25
|
-
* @param {string} str
|
|
26
|
-
* @returns {string}
|
|
27
|
-
*/
|
|
28
|
-
function normalizeQuotesAndWhitespace(str) {
|
|
29
|
-
return str
|
|
30
|
-
.trim()
|
|
31
|
-
.replace(/["']/g, "'") // Convert all quotes to single quotes for comparison
|
|
32
|
-
.replace(/\s+\n/g, '\n'); // Normalize whitespace before line breaks
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
pluginTester({
|
|
36
|
-
plugin,
|
|
37
|
-
pluginName: 'resolve-imports',
|
|
38
|
-
filepath: __filename,
|
|
39
|
-
formatResult: (r) => normalizeQuotesAndWhitespace(r),
|
|
40
|
-
|
|
41
|
-
tests: [
|
|
42
|
-
{
|
|
43
|
-
title: 'basic js imports',
|
|
44
|
-
pluginOptions: {
|
|
45
|
-
outExtension: '.js',
|
|
46
|
-
},
|
|
47
|
-
fixture: path.join(fixturePath, 'basic-js-imports', 'input.js'),
|
|
48
|
-
output: readOutputFixtureSync('basic-js-imports', 'output.js'),
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
title: 'typescript imports',
|
|
52
|
-
pluginOptions: {
|
|
53
|
-
outExtension: '.js',
|
|
54
|
-
},
|
|
55
|
-
babelOptions: {
|
|
56
|
-
plugins: [['@babel/plugin-syntax-typescript']],
|
|
57
|
-
},
|
|
58
|
-
fixture: path.join(fixturePath, 'typescript-imports', 'input.ts'),
|
|
59
|
-
output: readOutputFixtureSync('typescript-imports', 'output.ts'),
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
title: 'index resolution',
|
|
63
|
-
pluginOptions: {
|
|
64
|
-
outExtension: '.js',
|
|
65
|
-
},
|
|
66
|
-
fixture: path.join(fixturePath, 'index-resolution', 'input.js'),
|
|
67
|
-
output: readOutputFixtureSync('index-resolution', 'output.js'),
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
title: 'nested paths',
|
|
71
|
-
pluginOptions: {
|
|
72
|
-
outExtension: '.js',
|
|
73
|
-
},
|
|
74
|
-
fixture: path.join(fixturePath, 'nested-paths', 'input.js'),
|
|
75
|
-
output: readOutputFixtureSync('nested-paths', 'output.js'),
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
title: 'different output extension',
|
|
79
|
-
pluginOptions: {
|
|
80
|
-
outExtension: '.mjs',
|
|
81
|
-
},
|
|
82
|
-
fixture: path.join(fixturePath, 'different-extension', 'input.js'),
|
|
83
|
-
output: readOutputFixtureSync('different-extension', 'output.js'),
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
title: 'no output extension',
|
|
87
|
-
pluginOptions: {},
|
|
88
|
-
fixture: path.join(fixturePath, 'no-extension', 'input.js'),
|
|
89
|
-
output: readOutputFixtureSync('no-extension', 'output.js'),
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
title: 'non-relative imports',
|
|
93
|
-
pluginOptions: {
|
|
94
|
-
outExtension: '.js',
|
|
95
|
-
},
|
|
96
|
-
fixture: path.join(fixturePath, 'non-relative-imports', 'input.js'),
|
|
97
|
-
output: readOutputFixtureSync('non-relative-imports', 'output.js'),
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
title: 'declaration files',
|
|
101
|
-
pluginOptions: {
|
|
102
|
-
outExtension: '.js',
|
|
103
|
-
},
|
|
104
|
-
babelOptions: {
|
|
105
|
-
plugins: [['@babel/plugin-syntax-typescript', { dts: true }]],
|
|
106
|
-
},
|
|
107
|
-
fixture: path.join(fixturePath, 'declaration-files', 'input.d.ts'),
|
|
108
|
-
output: readOutputFixtureSync('declaration-files', 'output.d.ts'),
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"allowJs": true,
|
|
7
|
-
"checkJs": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"resolveJsonModule": true,
|
|
12
|
-
"isolatedModules": true,
|
|
13
|
-
"outDir": "./build",
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
"composite": true
|
|
16
|
-
},
|
|
17
|
-
"include": ["."],
|
|
18
|
-
"exclude": ["node_modules", "build", "__fixtures__"]
|
|
19
|
-
}
|