@tamagui/babel-plugin-fully-specified 1.98.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/dist/cjs/index.js +159 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/cjs/index.native.js +237 -0
- package/dist/cjs/index.native.js.map +6 -0
- package/dist/esm/index.js +150 -0
- package/dist/esm/index.js.map +6 -0
- package/dist/esm/index.mjs +154 -0
- package/dist/esm/index.native.js +222 -0
- package/dist/esm/index.native.js.map +6 -0
- package/package.json +32 -0
- package/src/index.ts +268 -0
- package/types/index.d.ts +27 -0
- package/types/index.d.ts.map +1 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
__export(src_exports, {
|
|
17
|
+
default: () => FullySpecified
|
|
18
|
+
});
|
|
19
|
+
module.exports = __toCommonJS(src_exports);
|
|
20
|
+
var import_node_fs = require("node:fs"), import_node_path = require("node:path"), import_types = require("@babel/types");
|
|
21
|
+
const makeDeclaration = ({
|
|
22
|
+
declaration,
|
|
23
|
+
makeNodes,
|
|
24
|
+
ensureFileExists = !1,
|
|
25
|
+
esExtensionDefault = ".js",
|
|
26
|
+
// List of all extensions which we try to find
|
|
27
|
+
tryExtensions = [".js", ".mjs", ".cjs"],
|
|
28
|
+
// List of extensions that can run in Node.js or in the Browser
|
|
29
|
+
esExtensions = [".js", ".mjs", ".cjs"],
|
|
30
|
+
// List of packages that also should be transformed with this plugin
|
|
31
|
+
includePackages = []
|
|
32
|
+
}) => (path, {
|
|
33
|
+
file: {
|
|
34
|
+
opts: { filename }
|
|
35
|
+
}
|
|
36
|
+
}) => {
|
|
37
|
+
const { source } = path.node;
|
|
38
|
+
if (!source || !filename)
|
|
39
|
+
return;
|
|
40
|
+
const { exportKind, importKind } = path.node;
|
|
41
|
+
if (exportKind === "type" || importKind === "type")
|
|
42
|
+
return;
|
|
43
|
+
const { value } = source, module2 = value;
|
|
44
|
+
let packageData = null;
|
|
45
|
+
if (!isLocalFile(module2) && (includePackages.some((name) => module2.startsWith(name)) && (packageData = getPackageData(module2)), !(packageData && packageData.hasPath)))
|
|
46
|
+
return;
|
|
47
|
+
const filenameExtension = (0, import_node_path.extname)(filename), filenameDirectory = (0, import_node_path.dirname)(filename), isDirectory = isLocalDirectory((0, import_node_path.resolve)(filenameDirectory, module2)), currentModuleExtension = (0, import_node_path.extname)(module2), targetModule = evaluateTargetModule({
|
|
48
|
+
module: module2,
|
|
49
|
+
filenameDirectory,
|
|
50
|
+
filenameExtension,
|
|
51
|
+
packageData,
|
|
52
|
+
currentModuleExtension,
|
|
53
|
+
isDirectory,
|
|
54
|
+
tryExtensions,
|
|
55
|
+
esExtensions,
|
|
56
|
+
esExtensionDefault,
|
|
57
|
+
ensureFileExists
|
|
58
|
+
});
|
|
59
|
+
if (targetModule === !1 || currentModuleExtension === targetModule.extension)
|
|
60
|
+
return;
|
|
61
|
+
const nodes = makeNodes(path);
|
|
62
|
+
path.replaceWith(
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
declaration.apply(null, [...nodes, (0, import_types.stringLiteral)(targetModule.module)])
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
function FullySpecified(api, options) {
|
|
68
|
+
return api.assertVersion(7), {
|
|
69
|
+
name: "babel-plugin-fully-specified",
|
|
70
|
+
visitor: {
|
|
71
|
+
ImportDeclaration: makeDeclaration({
|
|
72
|
+
...options,
|
|
73
|
+
declaration: import_types.importDeclaration,
|
|
74
|
+
makeNodes: ({ node: { specifiers } }) => [specifiers]
|
|
75
|
+
}),
|
|
76
|
+
ExportNamedDeclaration: makeDeclaration({
|
|
77
|
+
...options,
|
|
78
|
+
declaration: import_types.exportNamedDeclaration,
|
|
79
|
+
makeNodes: ({ node: { declaration, specifiers } }) => [declaration, specifiers]
|
|
80
|
+
}),
|
|
81
|
+
ExportAllDeclaration: makeDeclaration({
|
|
82
|
+
...options,
|
|
83
|
+
declaration: import_types.exportAllDeclaration,
|
|
84
|
+
makeNodes: () => []
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function getPackageData(module2) {
|
|
90
|
+
try {
|
|
91
|
+
const packagePath = require.resolve(module2), parts = packagePath.split("/");
|
|
92
|
+
let packageDir = "";
|
|
93
|
+
for (let i = parts.length; i >= 0; i--) {
|
|
94
|
+
const dir = (0, import_node_path.dirname)(parts.slice(0, i).join("/"));
|
|
95
|
+
if ((0, import_node_fs.existsSync)(`${dir}/package.json`)) {
|
|
96
|
+
packageDir = dir;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!packageDir)
|
|
101
|
+
throw new Error("no package dir");
|
|
102
|
+
const packageJson = JSON.parse((0, import_node_fs.readFileSync)(`${packageDir}/package.json`).toString());
|
|
103
|
+
return { hasPath: !module2.endsWith(packageJson.name), packagePath };
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
function isLocalFile(module2) {
|
|
109
|
+
return module2.startsWith(".") || module2.startsWith("/");
|
|
110
|
+
}
|
|
111
|
+
function isLocalDirectory(absoluteDirectory) {
|
|
112
|
+
return (0, import_node_fs.existsSync)(absoluteDirectory) && (0, import_node_fs.lstatSync)(absoluteDirectory).isDirectory();
|
|
113
|
+
}
|
|
114
|
+
function evaluateTargetModule({
|
|
115
|
+
module: module2,
|
|
116
|
+
currentModuleExtension,
|
|
117
|
+
packageData,
|
|
118
|
+
isDirectory,
|
|
119
|
+
filenameDirectory,
|
|
120
|
+
filenameExtension,
|
|
121
|
+
tryExtensions,
|
|
122
|
+
esExtensions,
|
|
123
|
+
esExtensionDefault,
|
|
124
|
+
ensureFileExists
|
|
125
|
+
}) {
|
|
126
|
+
if (packageData)
|
|
127
|
+
return packageData.packagePath.endsWith("index.js") && !module2.endsWith("index.js") && (module2 = `${module2}/index`), {
|
|
128
|
+
module: module2 + esExtensionDefault,
|
|
129
|
+
extension: esExtensionDefault
|
|
130
|
+
};
|
|
131
|
+
if (currentModuleExtension && !esExtensions.includes(currentModuleExtension))
|
|
132
|
+
return !1;
|
|
133
|
+
isDirectory && !(0, import_node_fs.existsSync)(
|
|
134
|
+
(0, import_node_path.resolve)(
|
|
135
|
+
filenameDirectory,
|
|
136
|
+
currentModuleExtension ? module2 : module2 + esExtensionDefault
|
|
137
|
+
)
|
|
138
|
+
) && (module2 = `${module2}/index`);
|
|
139
|
+
const targetFile = (0, import_node_path.resolve)(filenameDirectory, module2);
|
|
140
|
+
if (ensureFileExists) {
|
|
141
|
+
if (esExtensions.includes(filenameExtension) && (0, import_node_fs.existsSync)(targetFile + filenameExtension))
|
|
142
|
+
return {
|
|
143
|
+
module: module2 + filenameExtension,
|
|
144
|
+
extension: filenameExtension
|
|
145
|
+
};
|
|
146
|
+
for (const extension of tryExtensions)
|
|
147
|
+
if ((0, import_node_fs.existsSync)(targetFile + extension))
|
|
148
|
+
return { module: module2 + ".mjs", extension };
|
|
149
|
+
} else
|
|
150
|
+
return esExtensions.includes(filenameExtension) ? {
|
|
151
|
+
module: module2 + filenameExtension,
|
|
152
|
+
extension: filenameExtension
|
|
153
|
+
} : {
|
|
154
|
+
module: module2 + esExtensionDefault,
|
|
155
|
+
extension: esExtensionDefault
|
|
156
|
+
};
|
|
157
|
+
return !1;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoD,oBACpD,mBAA0C,sBAC1C,eAKO;AAgDP,MAAM,kBAAkB,CAAC;AAAA,EACvB;AAAA,EACA;AAAA,EACA,mBAAmB;AAAA,EACnB,qBAAqB;AAAA;AAAA,EAGrB,gBAAgB,CAAC,OAAO,QAAQ,MAAM;AAAA;AAAA,EAGtC,eAAe,CAAC,OAAO,QAAQ,MAAM;AAAA;AAAA,EAGrC,kBAAkB,CAAC;AACrB,MACS,CACL,MACA;AAAA,EACE,MAAM;AAAA,IACJ,MAAM,EAAE,SAAS;AAAA,EACnB;AACF,MACG;AACH,QAAM,EAAE,OAAO,IAAI,KAAK;AAExB,MAAI,CAAC,UAAU,CAAC;AACd;AAGF,QAAM,EAAE,YAAY,WAAW,IAAI,KAAK;AAExC,MADmB,eAAe,UAAU,eAAe;AAEzD;AAGF,QAAM,EAAE,MAAM,IAAI,QACZA,UAAS;AAEf,MAAI,cAAkC;AAEtC,MAAI,CAAC,YAAYA,OAAM,MACjB,gBAAgB,KAAK,CAAC,SAASA,QAAO,WAAW,IAAI,CAAC,MACxD,cAAc,eAAeA,OAAM,IAGjC,EAAE,eAAe,YAAY;AAC/B;AAIJ,QAAM,wBAAoB,0BAAQ,QAAQ,GACpC,wBAAoB,0BAAQ,QAAQ,GACpC,cAAc,qBAAiB,0BAAQ,mBAAmBA,OAAM,CAAC,GAEjE,6BAAyB,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;AAAO,WAAI,aAAa,SAAS,iBAAiB,IACzC;AAAA,MACL,QAAQA,UAAS;AAAA,MACjB,WAAW;AAAA,IACb,IAEO;AAAA,MACL,QAAQA,UAAS;AAAA,MACjB,WAAW;AAAA,IACb;AAGF,SAAO;AACT;",
|
|
5
|
+
"names": ["module"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
__export(src_exports, {
|
|
18
|
+
default: () => FullySpecified
|
|
19
|
+
});
|
|
20
|
+
module.exports = __toCommonJS(src_exports);
|
|
21
|
+
var import_node_fs = require("node:fs"), import_node_path = require("node:path"), import_types = require("@babel/types");
|
|
22
|
+
function _array_like_to_array(arr, len) {
|
|
23
|
+
(len == null || len > arr.length) && (len = arr.length);
|
|
24
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
25
|
+
arr2[i] = arr[i];
|
|
26
|
+
return arr2;
|
|
27
|
+
}
|
|
28
|
+
function _array_without_holes(arr) {
|
|
29
|
+
if (Array.isArray(arr))
|
|
30
|
+
return _array_like_to_array(arr);
|
|
31
|
+
}
|
|
32
|
+
function _define_property(obj, key, value) {
|
|
33
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
34
|
+
value,
|
|
35
|
+
enumerable: !0,
|
|
36
|
+
configurable: !0,
|
|
37
|
+
writable: !0
|
|
38
|
+
}) : obj[key] = value, obj;
|
|
39
|
+
}
|
|
40
|
+
function _iterable_to_array(iter) {
|
|
41
|
+
if (typeof Symbol < "u" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
42
|
+
return Array.from(iter);
|
|
43
|
+
}
|
|
44
|
+
function _non_iterable_spread() {
|
|
45
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
46
|
+
}
|
|
47
|
+
function _object_spread(target) {
|
|
48
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
49
|
+
var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
|
|
50
|
+
typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
51
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
52
|
+
}))), ownKeys2.forEach(function(key) {
|
|
53
|
+
_define_property(target, key, source[key]);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
function ownKeys(object, enumerableOnly) {
|
|
59
|
+
var keys = Object.keys(object);
|
|
60
|
+
if (Object.getOwnPropertySymbols) {
|
|
61
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
62
|
+
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
63
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
64
|
+
})), keys.push.apply(keys, symbols);
|
|
65
|
+
}
|
|
66
|
+
return keys;
|
|
67
|
+
}
|
|
68
|
+
function _object_spread_props(target, source) {
|
|
69
|
+
return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
70
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
71
|
+
}), target;
|
|
72
|
+
}
|
|
73
|
+
function _to_consumable_array(arr) {
|
|
74
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
75
|
+
}
|
|
76
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
77
|
+
if (o) {
|
|
78
|
+
if (typeof o == "string")
|
|
79
|
+
return _array_like_to_array(o, minLen);
|
|
80
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
81
|
+
if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set")
|
|
82
|
+
return Array.from(n);
|
|
83
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
84
|
+
return _array_like_to_array(o, minLen);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
var makeDeclaration = function(param) {
|
|
88
|
+
var declaration = param.declaration, makeNodes = param.makeNodes, _param_ensureFileExists = param.ensureFileExists, ensureFileExists = _param_ensureFileExists === void 0 ? !1 : _param_ensureFileExists, _param_esExtensionDefault = param.esExtensionDefault, esExtensionDefault = _param_esExtensionDefault === void 0 ? ".js" : _param_esExtensionDefault, _param_tryExtensions = param.tryExtensions, tryExtensions = _param_tryExtensions === void 0 ? [
|
|
89
|
+
".js",
|
|
90
|
+
".mjs",
|
|
91
|
+
".cjs"
|
|
92
|
+
] : _param_tryExtensions, _param_esExtensions = param.esExtensions, esExtensions = _param_esExtensions === void 0 ? [
|
|
93
|
+
".js",
|
|
94
|
+
".mjs",
|
|
95
|
+
".cjs"
|
|
96
|
+
] : _param_esExtensions, _param_includePackages = param.includePackages, includePackages = _param_includePackages === void 0 ? [] : _param_includePackages;
|
|
97
|
+
return function(path, param2) {
|
|
98
|
+
var _param_file = param2.file, filename = _param_file.opts.filename, source = path.node.source;
|
|
99
|
+
if (!(!source || !filename)) {
|
|
100
|
+
var _path_node = path.node, exportKind = _path_node.exportKind, importKind = _path_node.importKind, isTypeOnly = exportKind === "type" || importKind === "type";
|
|
101
|
+
if (!isTypeOnly) {
|
|
102
|
+
var value = source.value, module2 = value, packageData = null;
|
|
103
|
+
if (!(!isLocalFile(module2) && (includePackages.some(function(name) {
|
|
104
|
+
return module2.startsWith(name);
|
|
105
|
+
}) && (packageData = getPackageData(module2)), !(packageData && packageData.hasPath)))) {
|
|
106
|
+
var filenameExtension = (0, import_node_path.extname)(filename), filenameDirectory = (0, import_node_path.dirname)(filename), isDirectory = isLocalDirectory((0, import_node_path.resolve)(filenameDirectory, module2)), currentModuleExtension = (0, import_node_path.extname)(module2), targetModule = evaluateTargetModule({
|
|
107
|
+
module: module2,
|
|
108
|
+
filenameDirectory,
|
|
109
|
+
filenameExtension,
|
|
110
|
+
packageData,
|
|
111
|
+
currentModuleExtension,
|
|
112
|
+
isDirectory,
|
|
113
|
+
tryExtensions,
|
|
114
|
+
esExtensions,
|
|
115
|
+
esExtensionDefault,
|
|
116
|
+
ensureFileExists
|
|
117
|
+
});
|
|
118
|
+
if (!(targetModule === !1 || currentModuleExtension === targetModule.extension)) {
|
|
119
|
+
var nodes = makeNodes(path);
|
|
120
|
+
path.replaceWith(
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
declaration.apply(null, _to_consumable_array(nodes).concat([
|
|
123
|
+
(0, import_types.stringLiteral)(targetModule.module)
|
|
124
|
+
]))
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
function FullySpecified(api, options) {
|
|
133
|
+
return api.assertVersion(7), {
|
|
134
|
+
name: "babel-plugin-fully-specified",
|
|
135
|
+
visitor: {
|
|
136
|
+
ImportDeclaration: makeDeclaration(_object_spread_props(_object_spread({}, options), {
|
|
137
|
+
declaration: import_types.importDeclaration,
|
|
138
|
+
makeNodes: function(param) {
|
|
139
|
+
var specifiers = param.node.specifiers;
|
|
140
|
+
return [
|
|
141
|
+
specifiers
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
})),
|
|
145
|
+
ExportNamedDeclaration: makeDeclaration(_object_spread_props(_object_spread({}, options), {
|
|
146
|
+
declaration: import_types.exportNamedDeclaration,
|
|
147
|
+
makeNodes: function(param) {
|
|
148
|
+
var _param_node = param.node, declaration = _param_node.declaration, specifiers = _param_node.specifiers;
|
|
149
|
+
return [
|
|
150
|
+
declaration,
|
|
151
|
+
specifiers
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
})),
|
|
155
|
+
ExportAllDeclaration: makeDeclaration(_object_spread_props(_object_spread({}, options), {
|
|
156
|
+
declaration: import_types.exportAllDeclaration,
|
|
157
|
+
makeNodes: function() {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
}))
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function getPackageData(module2) {
|
|
165
|
+
try {
|
|
166
|
+
for (var packagePath = require.resolve(module2), parts = packagePath.split("/"), packageDir = "", i = parts.length; i >= 0; i--) {
|
|
167
|
+
var dir = (0, import_node_path.dirname)(parts.slice(0, i).join("/"));
|
|
168
|
+
if ((0, import_node_fs.existsSync)("".concat(dir, "/package.json"))) {
|
|
169
|
+
packageDir = dir;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (!packageDir)
|
|
174
|
+
throw new Error("no package dir");
|
|
175
|
+
var packageJson = JSON.parse((0, import_node_fs.readFileSync)("".concat(packageDir, "/package.json")).toString()), hasPath = !module2.endsWith(packageJson.name);
|
|
176
|
+
return {
|
|
177
|
+
hasPath,
|
|
178
|
+
packagePath
|
|
179
|
+
};
|
|
180
|
+
} catch {
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
function isLocalFile(module2) {
|
|
185
|
+
return module2.startsWith(".") || module2.startsWith("/");
|
|
186
|
+
}
|
|
187
|
+
function isLocalDirectory(absoluteDirectory) {
|
|
188
|
+
return (0, import_node_fs.existsSync)(absoluteDirectory) && (0, import_node_fs.lstatSync)(absoluteDirectory).isDirectory();
|
|
189
|
+
}
|
|
190
|
+
function evaluateTargetModule(param) {
|
|
191
|
+
var module2 = param.module, currentModuleExtension = param.currentModuleExtension, packageData = param.packageData, isDirectory = param.isDirectory, filenameDirectory = param.filenameDirectory, filenameExtension = param.filenameExtension, tryExtensions = param.tryExtensions, esExtensions = param.esExtensions, esExtensionDefault = param.esExtensionDefault, ensureFileExists = param.ensureFileExists;
|
|
192
|
+
if (packageData)
|
|
193
|
+
return packageData.packagePath.endsWith("index.js") && !module2.endsWith("index.js") && (module2 = "".concat(module2, "/index")), {
|
|
194
|
+
module: module2 + esExtensionDefault,
|
|
195
|
+
extension: esExtensionDefault
|
|
196
|
+
};
|
|
197
|
+
if (currentModuleExtension && !esExtensions.includes(currentModuleExtension))
|
|
198
|
+
return !1;
|
|
199
|
+
isDirectory && !(0, import_node_fs.existsSync)((0, import_node_path.resolve)(filenameDirectory, currentModuleExtension ? module2 : module2 + esExtensionDefault)) && (module2 = "".concat(module2, "/index"));
|
|
200
|
+
var targetFile = (0, import_node_path.resolve)(filenameDirectory, module2);
|
|
201
|
+
if (ensureFileExists) {
|
|
202
|
+
if (esExtensions.includes(filenameExtension) && (0, import_node_fs.existsSync)(targetFile + filenameExtension))
|
|
203
|
+
return {
|
|
204
|
+
module: module2 + filenameExtension,
|
|
205
|
+
extension: filenameExtension
|
|
206
|
+
};
|
|
207
|
+
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
|
208
|
+
try {
|
|
209
|
+
for (var _iterator = tryExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
210
|
+
var extension = _step.value;
|
|
211
|
+
if ((0, import_node_fs.existsSync)(targetFile + extension))
|
|
212
|
+
return {
|
|
213
|
+
module: module2 + ".mjs",
|
|
214
|
+
extension
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
} catch (err) {
|
|
218
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
219
|
+
} finally {
|
|
220
|
+
try {
|
|
221
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
222
|
+
} finally {
|
|
223
|
+
if (_didIteratorError)
|
|
224
|
+
throw _iteratorError;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} else
|
|
228
|
+
return esExtensions.includes(filenameExtension) ? {
|
|
229
|
+
module: module2 + filenameExtension,
|
|
230
|
+
extension: filenameExtension
|
|
231
|
+
} : {
|
|
232
|
+
module: module2 + esExtensionDefault,
|
|
233
|
+
extension: esExtensionDefault
|
|
234
|
+
};
|
|
235
|
+
return !1;
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/babel-plugin-fully-specified/src/index.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA,qBAAoD,oBACpD,mBAA0C,sBAC1C,eAKO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDP,IAAMA,kBAAkB,SAAA,OAAA;MACtBC,cAAAA,MAAAA,aACAC,YAAAA,MAAAA,WAAAA,0BAAAA,MACAC,kBAAAA,mBAAAA,4BAAAA,SAAmB,KAAA,yBAAA,4BAAA,MACnBC,oBAAAA,qBAAAA,8BAAAA,SAAqB,QAAA,2BAAA,uBAAA,MAGrBC,eAAAA,gBAAAA,yBAAAA,SA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AAA,UAAA,QAAA,UAAA,OAAA;;YAAA;gBAAA;;;EAKP;AAAO,WAAI9B,aAAakE,SAAS9C,iBAAAA,IACxB;MACLR,QAAQA,UAASQ;MACjBU,WAAWV;IACb,IAEO;MACLR,QAAQA,UAASd;MACjBgC,WAAWhC;IACb;AAGF,SAAO;AACT;",
|
|
5
|
+
"names": ["makeDeclaration", "declaration", "makeNodes", "ensureFileExists", "esExtensionDefault", "tryExtensions", "esExtensions", "includePackages", "path", "file", "filename", "opts", "source", "node", "exportKind", "importKind", "isTypeOnly", "value", "module", "packageData", "isLocalFile", "some", "name", "startsWith", "getPackageData", "hasPath", "filenameExtension", "extname", "filenameDirectory", "dirname", "isDirectory", "isLocalDirectory", "resolve", "currentModuleExtension", "targetModule", "evaluateTargetModule", "extension", "nodes", "replaceWith", "apply", "stringLiteral", "api", "options", "assertVersion", "visitor", "ImportDeclaration", "importDeclaration", "specifiers", "ExportNamedDeclaration", "exportNamedDeclaration", "ExportAllDeclaration", "exportAllDeclaration", "packagePath", "require", "parts", "split", "packageDir", "i", "length", "dir", "slice", "join", "existsSync", "Error", "packageJson", "JSON", "parse", "readFileSync", "toString", "endsWith", "absoluteDirectory", "lstatSync", "includes", "targetFile"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { existsSync, readFileSync, lstatSync } from "node:fs";
|
|
2
|
+
import { resolve, extname, dirname } from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
importDeclaration,
|
|
5
|
+
exportNamedDeclaration,
|
|
6
|
+
exportAllDeclaration,
|
|
7
|
+
stringLiteral
|
|
8
|
+
} from "@babel/types";
|
|
9
|
+
const makeDeclaration = ({
|
|
10
|
+
declaration,
|
|
11
|
+
makeNodes,
|
|
12
|
+
ensureFileExists = !1,
|
|
13
|
+
esExtensionDefault = ".js",
|
|
14
|
+
// List of all extensions which we try to find
|
|
15
|
+
tryExtensions = [".js", ".mjs", ".cjs"],
|
|
16
|
+
// List of extensions that can run in Node.js or in the Browser
|
|
17
|
+
esExtensions = [".js", ".mjs", ".cjs"],
|
|
18
|
+
// List of packages that also should be transformed with this plugin
|
|
19
|
+
includePackages = []
|
|
20
|
+
}) => (path, {
|
|
21
|
+
file: {
|
|
22
|
+
opts: { filename }
|
|
23
|
+
}
|
|
24
|
+
}) => {
|
|
25
|
+
const { source } = path.node;
|
|
26
|
+
if (!source || !filename)
|
|
27
|
+
return;
|
|
28
|
+
const { exportKind, importKind } = path.node;
|
|
29
|
+
if (exportKind === "type" || importKind === "type")
|
|
30
|
+
return;
|
|
31
|
+
const { value } = source, module = value;
|
|
32
|
+
let packageData = null;
|
|
33
|
+
if (!isLocalFile(module) && (includePackages.some((name) => module.startsWith(name)) && (packageData = getPackageData(module)), !(packageData && packageData.hasPath)))
|
|
34
|
+
return;
|
|
35
|
+
const filenameExtension = extname(filename), filenameDirectory = dirname(filename), isDirectory = isLocalDirectory(resolve(filenameDirectory, module)), currentModuleExtension = extname(module), targetModule = evaluateTargetModule({
|
|
36
|
+
module,
|
|
37
|
+
filenameDirectory,
|
|
38
|
+
filenameExtension,
|
|
39
|
+
packageData,
|
|
40
|
+
currentModuleExtension,
|
|
41
|
+
isDirectory,
|
|
42
|
+
tryExtensions,
|
|
43
|
+
esExtensions,
|
|
44
|
+
esExtensionDefault,
|
|
45
|
+
ensureFileExists
|
|
46
|
+
});
|
|
47
|
+
if (targetModule === !1 || currentModuleExtension === targetModule.extension)
|
|
48
|
+
return;
|
|
49
|
+
const nodes = makeNodes(path);
|
|
50
|
+
path.replaceWith(
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
declaration.apply(null, [...nodes, stringLiteral(targetModule.module)])
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
function FullySpecified(api, options) {
|
|
56
|
+
return api.assertVersion(7), {
|
|
57
|
+
name: "babel-plugin-fully-specified",
|
|
58
|
+
visitor: {
|
|
59
|
+
ImportDeclaration: makeDeclaration({
|
|
60
|
+
...options,
|
|
61
|
+
declaration: importDeclaration,
|
|
62
|
+
makeNodes: ({ node: { specifiers } }) => [specifiers]
|
|
63
|
+
}),
|
|
64
|
+
ExportNamedDeclaration: makeDeclaration({
|
|
65
|
+
...options,
|
|
66
|
+
declaration: exportNamedDeclaration,
|
|
67
|
+
makeNodes: ({ node: { declaration, specifiers } }) => [declaration, specifiers]
|
|
68
|
+
}),
|
|
69
|
+
ExportAllDeclaration: makeDeclaration({
|
|
70
|
+
...options,
|
|
71
|
+
declaration: exportAllDeclaration,
|
|
72
|
+
makeNodes: () => []
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function getPackageData(module) {
|
|
78
|
+
try {
|
|
79
|
+
const packagePath = require.resolve(module), parts = packagePath.split("/");
|
|
80
|
+
let packageDir = "";
|
|
81
|
+
for (let i = parts.length; i >= 0; i--) {
|
|
82
|
+
const dir = dirname(parts.slice(0, i).join("/"));
|
|
83
|
+
if (existsSync(`${dir}/package.json`)) {
|
|
84
|
+
packageDir = dir;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!packageDir)
|
|
89
|
+
throw new Error("no package dir");
|
|
90
|
+
const packageJson = JSON.parse(readFileSync(`${packageDir}/package.json`).toString());
|
|
91
|
+
return { hasPath: !module.endsWith(packageJson.name), packagePath };
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
function isLocalFile(module) {
|
|
97
|
+
return module.startsWith(".") || module.startsWith("/");
|
|
98
|
+
}
|
|
99
|
+
function isLocalDirectory(absoluteDirectory) {
|
|
100
|
+
return existsSync(absoluteDirectory) && lstatSync(absoluteDirectory).isDirectory();
|
|
101
|
+
}
|
|
102
|
+
function evaluateTargetModule({
|
|
103
|
+
module,
|
|
104
|
+
currentModuleExtension,
|
|
105
|
+
packageData,
|
|
106
|
+
isDirectory,
|
|
107
|
+
filenameDirectory,
|
|
108
|
+
filenameExtension,
|
|
109
|
+
tryExtensions,
|
|
110
|
+
esExtensions,
|
|
111
|
+
esExtensionDefault,
|
|
112
|
+
ensureFileExists
|
|
113
|
+
}) {
|
|
114
|
+
if (packageData)
|
|
115
|
+
return packageData.packagePath.endsWith("index.js") && !module.endsWith("index.js") && (module = `${module}/index`), {
|
|
116
|
+
module: module + esExtensionDefault,
|
|
117
|
+
extension: esExtensionDefault
|
|
118
|
+
};
|
|
119
|
+
if (currentModuleExtension && !esExtensions.includes(currentModuleExtension))
|
|
120
|
+
return !1;
|
|
121
|
+
isDirectory && !existsSync(
|
|
122
|
+
resolve(
|
|
123
|
+
filenameDirectory,
|
|
124
|
+
currentModuleExtension ? module : module + esExtensionDefault
|
|
125
|
+
)
|
|
126
|
+
) && (module = `${module}/index`);
|
|
127
|
+
const targetFile = resolve(filenameDirectory, module);
|
|
128
|
+
if (ensureFileExists) {
|
|
129
|
+
if (esExtensions.includes(filenameExtension) && existsSync(targetFile + filenameExtension))
|
|
130
|
+
return {
|
|
131
|
+
module: module + filenameExtension,
|
|
132
|
+
extension: filenameExtension
|
|
133
|
+
};
|
|
134
|
+
for (const extension of tryExtensions)
|
|
135
|
+
if (existsSync(targetFile + extension))
|
|
136
|
+
return { module: module + ".mjs", extension };
|
|
137
|
+
} else
|
|
138
|
+
return esExtensions.includes(filenameExtension) ? {
|
|
139
|
+
module: module + filenameExtension,
|
|
140
|
+
extension: filenameExtension
|
|
141
|
+
} : {
|
|
142
|
+
module: module + esExtensionDefault,
|
|
143
|
+
extension: esExtensionDefault
|
|
144
|
+
};
|
|
145
|
+
return !1;
|
|
146
|
+
}
|
|
147
|
+
export {
|
|
148
|
+
FullySpecified as default
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"mappings": "AAAA,SAAS,YAAY,cAAc,iBAAiB;AACp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BAA2B;AACnD,SAAO,WAAW,iBAAiB,KAAK,UAAU,iBAAiB,EAAE,YAAY;AACnF;AAEA,SAAS,qBAAqB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAG;AACD,MAAI;AACF,WAAI,YAAY,YAAY,SAAS,UAAU,KAAK,CAAC,OAAO,SAAS,UAAU,MAC7E,SAAS,GAAG,MAAM,WAGb;AAAA,MACL,QAAQ,SAAS;AAAA,MACjB,WAAW;AAAA,IACb;AAGF,MAAI,0BAA0B,CAAC,aAAa,SAAS,sBAAsB;AACzE,WAAO;AAGT,EACE,eACA,CAAC;AAAA,IACC;AAAA,MACE;AAAA,MACA,yBAAyB,SAAS,SAAS;AAAA,IAC7C;AAAA,EACF,MAEA,SAAS,GAAG,MAAM;AAGpB,QAAM,aAAa,QAAQ,mBAAmB,MAAM;AAEpD,MAAI,kBAAkB;AAEpB,QACE,aAAa,SAAS,iBAAiB,KACvC,WAAW,aAAa,iBAAiB;AAEzC,aAAO;AAAA,QACL,QAAQ,SAAS;AAAA,QACjB,WAAW;AAAA,MACb;AAIF,eAAW,aAAa;AACtB,UAAI,WAAW,aAAa,SAAS;AACnC,eAAO,EAAE,QAAQ,SAAS,QAAQ,UAAU;AAAA,EAGlD;AAAO,WAAI,aAAa,SAAS,iBAAiB,IACzC;AAAA,MACL,QAAQ,SAAS;AAAA,MACjB,WAAW;AAAA,IACb,IAEO;AAAA,MACL,QAAQ,SAAS;AAAA,MACjB,WAAW;AAAA,IACb;AAGF,SAAO;AACT;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { existsSync, readFileSync, lstatSync } from "node:fs";
|
|
2
|
+
import { resolve, extname, dirname } from "node:path";
|
|
3
|
+
import { importDeclaration, exportNamedDeclaration, exportAllDeclaration, stringLiteral } from "@babel/types";
|
|
4
|
+
const makeDeclaration = ({
|
|
5
|
+
declaration,
|
|
6
|
+
makeNodes,
|
|
7
|
+
ensureFileExists = !1,
|
|
8
|
+
esExtensionDefault = ".js",
|
|
9
|
+
// List of all extensions which we try to find
|
|
10
|
+
tryExtensions = [".js", ".mjs", ".cjs"],
|
|
11
|
+
// List of extensions that can run in Node.js or in the Browser
|
|
12
|
+
esExtensions = [".js", ".mjs", ".cjs"],
|
|
13
|
+
// List of packages that also should be transformed with this plugin
|
|
14
|
+
includePackages = []
|
|
15
|
+
}) => (path, {
|
|
16
|
+
file: {
|
|
17
|
+
opts: {
|
|
18
|
+
filename
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}) => {
|
|
22
|
+
const {
|
|
23
|
+
source
|
|
24
|
+
} = path.node;
|
|
25
|
+
if (!source || !filename) return;
|
|
26
|
+
const {
|
|
27
|
+
exportKind,
|
|
28
|
+
importKind
|
|
29
|
+
} = path.node;
|
|
30
|
+
if (exportKind === "type" || importKind === "type") return;
|
|
31
|
+
const {
|
|
32
|
+
value
|
|
33
|
+
} = source,
|
|
34
|
+
module = value;
|
|
35
|
+
let packageData = null;
|
|
36
|
+
if (!isLocalFile(module) && (includePackages.some(name => module.startsWith(name)) && (packageData = getPackageData(module)), !(packageData && packageData.hasPath))) return;
|
|
37
|
+
const filenameExtension = extname(filename),
|
|
38
|
+
filenameDirectory = dirname(filename),
|
|
39
|
+
isDirectory = isLocalDirectory(resolve(filenameDirectory, module)),
|
|
40
|
+
currentModuleExtension = extname(module),
|
|
41
|
+
targetModule = evaluateTargetModule({
|
|
42
|
+
module,
|
|
43
|
+
filenameDirectory,
|
|
44
|
+
filenameExtension,
|
|
45
|
+
packageData,
|
|
46
|
+
currentModuleExtension,
|
|
47
|
+
isDirectory,
|
|
48
|
+
tryExtensions,
|
|
49
|
+
esExtensions,
|
|
50
|
+
esExtensionDefault,
|
|
51
|
+
ensureFileExists
|
|
52
|
+
});
|
|
53
|
+
if (targetModule === !1 || currentModuleExtension === targetModule.extension) return;
|
|
54
|
+
const nodes = makeNodes(path);
|
|
55
|
+
path.replaceWith(
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
declaration.apply(null, [...nodes, stringLiteral(targetModule.module)]));
|
|
58
|
+
};
|
|
59
|
+
function FullySpecified(api, options) {
|
|
60
|
+
return api.assertVersion(7), {
|
|
61
|
+
name: "babel-plugin-fully-specified",
|
|
62
|
+
visitor: {
|
|
63
|
+
ImportDeclaration: makeDeclaration({
|
|
64
|
+
...options,
|
|
65
|
+
declaration: importDeclaration,
|
|
66
|
+
makeNodes: ({
|
|
67
|
+
node: {
|
|
68
|
+
specifiers
|
|
69
|
+
}
|
|
70
|
+
}) => [specifiers]
|
|
71
|
+
}),
|
|
72
|
+
ExportNamedDeclaration: makeDeclaration({
|
|
73
|
+
...options,
|
|
74
|
+
declaration: exportNamedDeclaration,
|
|
75
|
+
makeNodes: ({
|
|
76
|
+
node: {
|
|
77
|
+
declaration,
|
|
78
|
+
specifiers
|
|
79
|
+
}
|
|
80
|
+
}) => [declaration, specifiers]
|
|
81
|
+
}),
|
|
82
|
+
ExportAllDeclaration: makeDeclaration({
|
|
83
|
+
...options,
|
|
84
|
+
declaration: exportAllDeclaration,
|
|
85
|
+
makeNodes: () => []
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function getPackageData(module) {
|
|
91
|
+
try {
|
|
92
|
+
const packagePath = require.resolve(module),
|
|
93
|
+
parts = packagePath.split("/");
|
|
94
|
+
let packageDir = "";
|
|
95
|
+
for (let i = parts.length; i >= 0; i--) {
|
|
96
|
+
const dir = dirname(parts.slice(0, i).join("/"));
|
|
97
|
+
if (existsSync(`${dir}/package.json`)) {
|
|
98
|
+
packageDir = dir;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!packageDir) throw new Error("no package dir");
|
|
103
|
+
const packageJson = JSON.parse(readFileSync(`${packageDir}/package.json`).toString());
|
|
104
|
+
return {
|
|
105
|
+
hasPath: !module.endsWith(packageJson.name),
|
|
106
|
+
packagePath
|
|
107
|
+
};
|
|
108
|
+
} catch {}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
function isLocalFile(module) {
|
|
112
|
+
return module.startsWith(".") || module.startsWith("/");
|
|
113
|
+
}
|
|
114
|
+
function isLocalDirectory(absoluteDirectory) {
|
|
115
|
+
return existsSync(absoluteDirectory) && lstatSync(absoluteDirectory).isDirectory();
|
|
116
|
+
}
|
|
117
|
+
function evaluateTargetModule({
|
|
118
|
+
module,
|
|
119
|
+
currentModuleExtension,
|
|
120
|
+
packageData,
|
|
121
|
+
isDirectory,
|
|
122
|
+
filenameDirectory,
|
|
123
|
+
filenameExtension,
|
|
124
|
+
tryExtensions,
|
|
125
|
+
esExtensions,
|
|
126
|
+
esExtensionDefault,
|
|
127
|
+
ensureFileExists
|
|
128
|
+
}) {
|
|
129
|
+
if (packageData) return packageData.packagePath.endsWith("index.js") && !module.endsWith("index.js") && (module = `${module}/index`), {
|
|
130
|
+
module: module + esExtensionDefault,
|
|
131
|
+
extension: esExtensionDefault
|
|
132
|
+
};
|
|
133
|
+
if (currentModuleExtension && !esExtensions.includes(currentModuleExtension)) return !1;
|
|
134
|
+
isDirectory && !existsSync(resolve(filenameDirectory, currentModuleExtension ? module : module + esExtensionDefault)) && (module = `${module}/index`);
|
|
135
|
+
const targetFile = resolve(filenameDirectory, module);
|
|
136
|
+
if (ensureFileExists) {
|
|
137
|
+
if (esExtensions.includes(filenameExtension) && existsSync(targetFile + filenameExtension)) return {
|
|
138
|
+
module: module + filenameExtension,
|
|
139
|
+
extension: filenameExtension
|
|
140
|
+
};
|
|
141
|
+
for (const extension of tryExtensions) if (existsSync(targetFile + extension)) return {
|
|
142
|
+
module: module + ".mjs",
|
|
143
|
+
extension
|
|
144
|
+
};
|
|
145
|
+
} else return esExtensions.includes(filenameExtension) ? {
|
|
146
|
+
module: module + filenameExtension,
|
|
147
|
+
extension: filenameExtension
|
|
148
|
+
} : {
|
|
149
|
+
module: module + esExtensionDefault,
|
|
150
|
+
extension: esExtensionDefault
|
|
151
|
+
};
|
|
152
|
+
return !1;
|
|
153
|
+
}
|
|
154
|
+
export { FullySpecified as default };
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { existsSync, readFileSync, lstatSync } from "node:fs";
|
|
2
|
+
import { resolve, extname, dirname } from "node:path";
|
|
3
|
+
import { importDeclaration, exportNamedDeclaration, exportAllDeclaration, stringLiteral } from "@babel/types";
|
|
4
|
+
function _array_like_to_array(arr, len) {
|
|
5
|
+
(len == null || len > arr.length) && (len = arr.length);
|
|
6
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
7
|
+
arr2[i] = arr[i];
|
|
8
|
+
return arr2;
|
|
9
|
+
}
|
|
10
|
+
function _array_without_holes(arr) {
|
|
11
|
+
if (Array.isArray(arr))
|
|
12
|
+
return _array_like_to_array(arr);
|
|
13
|
+
}
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
16
|
+
value,
|
|
17
|
+
enumerable: !0,
|
|
18
|
+
configurable: !0,
|
|
19
|
+
writable: !0
|
|
20
|
+
}) : obj[key] = value, obj;
|
|
21
|
+
}
|
|
22
|
+
function _iterable_to_array(iter) {
|
|
23
|
+
if (typeof Symbol < "u" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
24
|
+
return Array.from(iter);
|
|
25
|
+
}
|
|
26
|
+
function _non_iterable_spread() {
|
|
27
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
28
|
+
}
|
|
29
|
+
function _object_spread(target) {
|
|
30
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
31
|
+
var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
|
|
32
|
+
typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
33
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
34
|
+
}))), ownKeys2.forEach(function(key) {
|
|
35
|
+
_define_property(target, key, source[key]);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
40
|
+
function ownKeys(object, enumerableOnly) {
|
|
41
|
+
var keys = Object.keys(object);
|
|
42
|
+
if (Object.getOwnPropertySymbols) {
|
|
43
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
44
|
+
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
45
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
46
|
+
})), keys.push.apply(keys, symbols);
|
|
47
|
+
}
|
|
48
|
+
return keys;
|
|
49
|
+
}
|
|
50
|
+
function _object_spread_props(target, source) {
|
|
51
|
+
return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
52
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
53
|
+
}), target;
|
|
54
|
+
}
|
|
55
|
+
function _to_consumable_array(arr) {
|
|
56
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
57
|
+
}
|
|
58
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
59
|
+
if (o) {
|
|
60
|
+
if (typeof o == "string")
|
|
61
|
+
return _array_like_to_array(o, minLen);
|
|
62
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
63
|
+
if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set")
|
|
64
|
+
return Array.from(n);
|
|
65
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
66
|
+
return _array_like_to_array(o, minLen);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
var makeDeclaration = function(param) {
|
|
70
|
+
var declaration = param.declaration, makeNodes = param.makeNodes, _param_ensureFileExists = param.ensureFileExists, ensureFileExists = _param_ensureFileExists === void 0 ? !1 : _param_ensureFileExists, _param_esExtensionDefault = param.esExtensionDefault, esExtensionDefault = _param_esExtensionDefault === void 0 ? ".js" : _param_esExtensionDefault, _param_tryExtensions = param.tryExtensions, tryExtensions = _param_tryExtensions === void 0 ? [
|
|
71
|
+
".js",
|
|
72
|
+
".mjs",
|
|
73
|
+
".cjs"
|
|
74
|
+
] : _param_tryExtensions, _param_esExtensions = param.esExtensions, esExtensions = _param_esExtensions === void 0 ? [
|
|
75
|
+
".js",
|
|
76
|
+
".mjs",
|
|
77
|
+
".cjs"
|
|
78
|
+
] : _param_esExtensions, _param_includePackages = param.includePackages, includePackages = _param_includePackages === void 0 ? [] : _param_includePackages;
|
|
79
|
+
return function(path, param2) {
|
|
80
|
+
var _param_file = param2.file, filename = _param_file.opts.filename, source = path.node.source;
|
|
81
|
+
if (!(!source || !filename)) {
|
|
82
|
+
var _path_node = path.node, exportKind = _path_node.exportKind, importKind = _path_node.importKind, isTypeOnly = exportKind === "type" || importKind === "type";
|
|
83
|
+
if (!isTypeOnly) {
|
|
84
|
+
var value = source.value, module = value, packageData = null;
|
|
85
|
+
if (!(!isLocalFile(module) && (includePackages.some(function(name) {
|
|
86
|
+
return module.startsWith(name);
|
|
87
|
+
}) && (packageData = getPackageData(module)), !(packageData && packageData.hasPath)))) {
|
|
88
|
+
var filenameExtension = extname(filename), filenameDirectory = dirname(filename), isDirectory = isLocalDirectory(resolve(filenameDirectory, module)), currentModuleExtension = extname(module), targetModule = evaluateTargetModule({
|
|
89
|
+
module,
|
|
90
|
+
filenameDirectory,
|
|
91
|
+
filenameExtension,
|
|
92
|
+
packageData,
|
|
93
|
+
currentModuleExtension,
|
|
94
|
+
isDirectory,
|
|
95
|
+
tryExtensions,
|
|
96
|
+
esExtensions,
|
|
97
|
+
esExtensionDefault,
|
|
98
|
+
ensureFileExists
|
|
99
|
+
});
|
|
100
|
+
if (!(targetModule === !1 || currentModuleExtension === targetModule.extension)) {
|
|
101
|
+
var nodes = makeNodes(path);
|
|
102
|
+
path.replaceWith(
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
declaration.apply(null, _to_consumable_array(nodes).concat([
|
|
105
|
+
stringLiteral(targetModule.module)
|
|
106
|
+
]))
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
function FullySpecified(api, options) {
|
|
115
|
+
return api.assertVersion(7), {
|
|
116
|
+
name: "babel-plugin-fully-specified",
|
|
117
|
+
visitor: {
|
|
118
|
+
ImportDeclaration: makeDeclaration(_object_spread_props(_object_spread({}, options), {
|
|
119
|
+
declaration: importDeclaration,
|
|
120
|
+
makeNodes: function(param) {
|
|
121
|
+
var specifiers = param.node.specifiers;
|
|
122
|
+
return [
|
|
123
|
+
specifiers
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
})),
|
|
127
|
+
ExportNamedDeclaration: makeDeclaration(_object_spread_props(_object_spread({}, options), {
|
|
128
|
+
declaration: exportNamedDeclaration,
|
|
129
|
+
makeNodes: function(param) {
|
|
130
|
+
var _param_node = param.node, declaration = _param_node.declaration, specifiers = _param_node.specifiers;
|
|
131
|
+
return [
|
|
132
|
+
declaration,
|
|
133
|
+
specifiers
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
})),
|
|
137
|
+
ExportAllDeclaration: makeDeclaration(_object_spread_props(_object_spread({}, options), {
|
|
138
|
+
declaration: exportAllDeclaration,
|
|
139
|
+
makeNodes: function() {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
}))
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function getPackageData(module) {
|
|
147
|
+
try {
|
|
148
|
+
for (var packagePath = require.resolve(module), parts = packagePath.split("/"), packageDir = "", i = parts.length; i >= 0; i--) {
|
|
149
|
+
var dir = dirname(parts.slice(0, i).join("/"));
|
|
150
|
+
if (existsSync("".concat(dir, "/package.json"))) {
|
|
151
|
+
packageDir = dir;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (!packageDir)
|
|
156
|
+
throw new Error("no package dir");
|
|
157
|
+
var packageJson = JSON.parse(readFileSync("".concat(packageDir, "/package.json")).toString()), hasPath = !module.endsWith(packageJson.name);
|
|
158
|
+
return {
|
|
159
|
+
hasPath,
|
|
160
|
+
packagePath
|
|
161
|
+
};
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
function isLocalFile(module) {
|
|
167
|
+
return module.startsWith(".") || module.startsWith("/");
|
|
168
|
+
}
|
|
169
|
+
function isLocalDirectory(absoluteDirectory) {
|
|
170
|
+
return existsSync(absoluteDirectory) && lstatSync(absoluteDirectory).isDirectory();
|
|
171
|
+
}
|
|
172
|
+
function evaluateTargetModule(param) {
|
|
173
|
+
var module = param.module, currentModuleExtension = param.currentModuleExtension, packageData = param.packageData, isDirectory = param.isDirectory, filenameDirectory = param.filenameDirectory, filenameExtension = param.filenameExtension, tryExtensions = param.tryExtensions, esExtensions = param.esExtensions, esExtensionDefault = param.esExtensionDefault, ensureFileExists = param.ensureFileExists;
|
|
174
|
+
if (packageData)
|
|
175
|
+
return packageData.packagePath.endsWith("index.js") && !module.endsWith("index.js") && (module = "".concat(module, "/index")), {
|
|
176
|
+
module: module + esExtensionDefault,
|
|
177
|
+
extension: esExtensionDefault
|
|
178
|
+
};
|
|
179
|
+
if (currentModuleExtension && !esExtensions.includes(currentModuleExtension))
|
|
180
|
+
return !1;
|
|
181
|
+
isDirectory && !existsSync(resolve(filenameDirectory, currentModuleExtension ? module : module + esExtensionDefault)) && (module = "".concat(module, "/index"));
|
|
182
|
+
var targetFile = resolve(filenameDirectory, module);
|
|
183
|
+
if (ensureFileExists) {
|
|
184
|
+
if (esExtensions.includes(filenameExtension) && existsSync(targetFile + filenameExtension))
|
|
185
|
+
return {
|
|
186
|
+
module: module + filenameExtension,
|
|
187
|
+
extension: filenameExtension
|
|
188
|
+
};
|
|
189
|
+
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
|
190
|
+
try {
|
|
191
|
+
for (var _iterator = tryExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
192
|
+
var extension = _step.value;
|
|
193
|
+
if (existsSync(targetFile + extension))
|
|
194
|
+
return {
|
|
195
|
+
module: module + ".mjs",
|
|
196
|
+
extension
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
} catch (err) {
|
|
200
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
201
|
+
} finally {
|
|
202
|
+
try {
|
|
203
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
204
|
+
} finally {
|
|
205
|
+
if (_didIteratorError)
|
|
206
|
+
throw _iteratorError;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
} else
|
|
210
|
+
return esExtensions.includes(filenameExtension) ? {
|
|
211
|
+
module: module + filenameExtension,
|
|
212
|
+
extension: filenameExtension
|
|
213
|
+
} : {
|
|
214
|
+
module: module + esExtensionDefault,
|
|
215
|
+
extension: esExtensionDefault
|
|
216
|
+
};
|
|
217
|
+
return !1;
|
|
218
|
+
}
|
|
219
|
+
export {
|
|
220
|
+
FullySpecified as default
|
|
221
|
+
};
|
|
222
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/babel-plugin-fully-specified/src/index.ts"],
|
|
4
|
+
"mappings": "AAAA,SAASA,YAAYC,cAA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iBAAAA;AAExB,aAAO;QACLR,QAAQA,SAASQ;QACjBO,WAAWP;MACb;QAIG,4BAAA,IAAA,oBAAA,IAAA,iBAAA;;AAAL,eAAK,YAAmBrB,cAAAA,OAAAA,QAAAA,EAAAA,GAAnB,OAAA,EAAA,6BAAA,QAAA,UAAA,KAAA,GAAA,OAAA,4BAAA,IAAkC;AAAlC,YAAM4B,YAAN,MAAA;AACH,YAAI3C,WAAWyE,aAAa9B,SAAAA;AAC1B,iBAAO;YAAEf,QAAQA,SAAS;YAAQe;UAAU;MAEhD;;AAJK,0BAAA,IAAA,iBAAA;;;SAAA,6BAAA,UAAA,UAAA,QAAA,UAAA,OAAA;;YAAA;gBAAA;;;EAKP;AAAO,WAAI3B,aAAawD,SAASpC,iBAAAA,IACxB;MACLR,QAAQA,SAASQ;MACjBO,WAAWP;IACb,IAEO;MACLR,QAAQA,SAASd;MACjB6B,WAAW7B;IACb;AAGF,SAAO;AACT;",
|
|
5
|
+
"names": ["existsSync", "readFileSync", "lstatSync", "resolve", "extname", "dirname", "importDeclaration", "exportNamedDeclaration", "exportAllDeclaration", "stringLiteral", "makeDeclaration", "declaration", "makeNodes", "ensureFileExists", "esExtensionDefault", "tryExtensions", "esExtensions", "includePackages", "path", "file", "filename", "opts", "source", "node", "exportKind", "importKind", "isTypeOnly", "value", "module", "packageData", "isLocalFile", "some", "name", "startsWith", "getPackageData", "hasPath", "filenameExtension", "filenameDirectory", "isDirectory", "isLocalDirectory", "currentModuleExtension", "targetModule", "evaluateTargetModule", "extension", "nodes", "replaceWith", "apply", "api", "options", "assertVersion", "visitor", "ImportDeclaration", "specifiers", "ExportNamedDeclaration", "ExportAllDeclaration", "packagePath", "require", "parts", "split", "packageDir", "i", "length", "dir", "slice", "join", "Error", "packageJson", "JSON", "parse", "toString", "endsWith", "absoluteDirectory", "includes", "targetFile"]
|
|
6
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/babel-plugin-fully-specified",
|
|
3
|
+
"version": "1.98.0",
|
|
4
|
+
"source": "src/index.ts",
|
|
5
|
+
"types": "./types/index.d.ts",
|
|
6
|
+
"main": "dist/cjs",
|
|
7
|
+
"module": "dist/esm",
|
|
8
|
+
"files": [
|
|
9
|
+
"src",
|
|
10
|
+
"types",
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "node ../build/tamagui-build.js",
|
|
19
|
+
"watch": "node ../build/tamagui-build.js --watch",
|
|
20
|
+
"lint": "../../node_modules/.bin/biome check src",
|
|
21
|
+
"lint:fix": "../../node_modules/.bin/biome check --apply-unsafe src",
|
|
22
|
+
"clean": "node ../build/tamagui-build.js clean",
|
|
23
|
+
"clean:build": "node ../build/tamagui-build.js clean:build"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@babel/core": "^7.23.3"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@babel/types": "^7.23.3"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14"
|
|
32
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { existsSync, readFileSync, lstatSync } from 'node:fs'
|
|
2
|
+
import { resolve, extname, dirname } from 'node:path'
|
|
3
|
+
import {
|
|
4
|
+
importDeclaration,
|
|
5
|
+
exportNamedDeclaration,
|
|
6
|
+
exportAllDeclaration,
|
|
7
|
+
stringLiteral,
|
|
8
|
+
} from '@babel/types'
|
|
9
|
+
|
|
10
|
+
import type { ConfigAPI, NodePath, PluginPass } from '@babel/core'
|
|
11
|
+
import type {
|
|
12
|
+
ImportSpecifier,
|
|
13
|
+
ImportDeclaration,
|
|
14
|
+
ExportAllDeclaration,
|
|
15
|
+
StringLiteral,
|
|
16
|
+
ExportSpecifier,
|
|
17
|
+
ExportDeclaration,
|
|
18
|
+
ExportNamedDeclaration,
|
|
19
|
+
} from '@babel/types'
|
|
20
|
+
|
|
21
|
+
type ImportDeclarationFunc = (
|
|
22
|
+
specifiers: Array<ImportSpecifier>,
|
|
23
|
+
source: StringLiteral
|
|
24
|
+
) => ImportDeclaration
|
|
25
|
+
|
|
26
|
+
type ExportNamedDeclarationFunc = (
|
|
27
|
+
declaration?: ExportDeclaration,
|
|
28
|
+
specifiers?: Array<ExportSpecifier>,
|
|
29
|
+
source?: StringLiteral
|
|
30
|
+
) => ExportNamedDeclaration
|
|
31
|
+
|
|
32
|
+
type ExportAllDeclarationFunc = (source: StringLiteral) => ExportAllDeclaration
|
|
33
|
+
|
|
34
|
+
type PathDeclaration = NodePath & {
|
|
35
|
+
node: ImportDeclaration & ExportNamedDeclaration & ExportAllDeclaration
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type PackageData = {
|
|
39
|
+
hasPath: boolean
|
|
40
|
+
packagePath: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface FullySpecifiedOptions {
|
|
44
|
+
declaration:
|
|
45
|
+
| ImportDeclarationFunc
|
|
46
|
+
| ExportNamedDeclarationFunc
|
|
47
|
+
| ExportAllDeclarationFunc
|
|
48
|
+
makeNodes: (path: PathDeclaration) => Array<PathDeclaration>
|
|
49
|
+
ensureFileExists: boolean
|
|
50
|
+
esExtensionDefault: string
|
|
51
|
+
tryExtensions: Array<string>
|
|
52
|
+
esExtensions: Array<string>
|
|
53
|
+
includePackages: Array<string>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const makeDeclaration = ({
|
|
57
|
+
declaration,
|
|
58
|
+
makeNodes,
|
|
59
|
+
ensureFileExists = false,
|
|
60
|
+
esExtensionDefault = '.js',
|
|
61
|
+
|
|
62
|
+
// List of all extensions which we try to find
|
|
63
|
+
tryExtensions = ['.js', '.mjs', '.cjs'],
|
|
64
|
+
|
|
65
|
+
// List of extensions that can run in Node.js or in the Browser
|
|
66
|
+
esExtensions = ['.js', '.mjs', '.cjs'],
|
|
67
|
+
|
|
68
|
+
// List of packages that also should be transformed with this plugin
|
|
69
|
+
includePackages = [],
|
|
70
|
+
}: FullySpecifiedOptions) => {
|
|
71
|
+
return (
|
|
72
|
+
path: PathDeclaration,
|
|
73
|
+
{
|
|
74
|
+
file: {
|
|
75
|
+
opts: { filename },
|
|
76
|
+
},
|
|
77
|
+
}: PluginPass
|
|
78
|
+
) => {
|
|
79
|
+
const { source } = path.node
|
|
80
|
+
|
|
81
|
+
if (!source || !filename) {
|
|
82
|
+
return // stop here
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const { exportKind, importKind } = path.node
|
|
86
|
+
const isTypeOnly = exportKind === 'type' || importKind === 'type'
|
|
87
|
+
if (isTypeOnly) {
|
|
88
|
+
return // stop here
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const { value } = source
|
|
92
|
+
const module = value as string
|
|
93
|
+
|
|
94
|
+
let packageData: PackageData | null = null
|
|
95
|
+
|
|
96
|
+
if (!isLocalFile(module)) {
|
|
97
|
+
if (includePackages.some((name) => module.startsWith(name))) {
|
|
98
|
+
packageData = getPackageData(module)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!(packageData && packageData.hasPath)) {
|
|
102
|
+
return // stop here
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const filenameExtension = extname(filename)
|
|
107
|
+
const filenameDirectory = dirname(filename)
|
|
108
|
+
const isDirectory = isLocalDirectory(resolve(filenameDirectory, module))
|
|
109
|
+
|
|
110
|
+
const currentModuleExtension = extname(module)
|
|
111
|
+
const targetModule = evaluateTargetModule({
|
|
112
|
+
module,
|
|
113
|
+
filenameDirectory,
|
|
114
|
+
filenameExtension,
|
|
115
|
+
packageData,
|
|
116
|
+
currentModuleExtension,
|
|
117
|
+
isDirectory,
|
|
118
|
+
tryExtensions,
|
|
119
|
+
esExtensions,
|
|
120
|
+
esExtensionDefault,
|
|
121
|
+
ensureFileExists,
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
if (targetModule === false || currentModuleExtension === targetModule.extension) {
|
|
125
|
+
return // stop here
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const nodes = makeNodes(path)
|
|
129
|
+
|
|
130
|
+
path.replaceWith(
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
declaration.apply(null, [...nodes, stringLiteral(targetModule.module)])
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export default function FullySpecified(api: ConfigAPI, options: FullySpecifiedOptions) {
|
|
138
|
+
api.assertVersion(7)
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
name: 'babel-plugin-fully-specified',
|
|
142
|
+
visitor: {
|
|
143
|
+
ImportDeclaration: makeDeclaration({
|
|
144
|
+
...options,
|
|
145
|
+
declaration: importDeclaration,
|
|
146
|
+
makeNodes: ({ node: { specifiers } }) => [specifiers],
|
|
147
|
+
}),
|
|
148
|
+
ExportNamedDeclaration: makeDeclaration({
|
|
149
|
+
...options,
|
|
150
|
+
declaration: exportNamedDeclaration,
|
|
151
|
+
makeNodes: ({ node: { declaration, specifiers } }) => [declaration, specifiers],
|
|
152
|
+
}),
|
|
153
|
+
ExportAllDeclaration: makeDeclaration({
|
|
154
|
+
...options,
|
|
155
|
+
declaration: exportAllDeclaration,
|
|
156
|
+
makeNodes: () => [],
|
|
157
|
+
}),
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function getPackageData<PackageData>(module: string) {
|
|
163
|
+
try {
|
|
164
|
+
const packagePath = require.resolve(module)
|
|
165
|
+
const parts = packagePath.split('/')
|
|
166
|
+
|
|
167
|
+
let packageDir = ''
|
|
168
|
+
for (let i = parts.length; i >= 0; i--) {
|
|
169
|
+
const dir = dirname(parts.slice(0, i).join('/'))
|
|
170
|
+
if (existsSync(`${dir}/package.json`)) {
|
|
171
|
+
packageDir = dir
|
|
172
|
+
break
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (!packageDir) {
|
|
176
|
+
throw new Error(`no package dir`)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const packageJson = JSON.parse(readFileSync(`${packageDir}/package.json`).toString())
|
|
180
|
+
|
|
181
|
+
const hasPath = !module.endsWith(packageJson.name)
|
|
182
|
+
return { hasPath, packagePath }
|
|
183
|
+
} catch (e) {}
|
|
184
|
+
|
|
185
|
+
return null
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function isLocalFile(module: string) {
|
|
189
|
+
return module.startsWith('.') || module.startsWith('/')
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function isLocalDirectory(absoluteDirectory: string) {
|
|
193
|
+
return existsSync(absoluteDirectory) && lstatSync(absoluteDirectory).isDirectory()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function evaluateTargetModule({
|
|
197
|
+
module,
|
|
198
|
+
currentModuleExtension,
|
|
199
|
+
packageData,
|
|
200
|
+
isDirectory,
|
|
201
|
+
filenameDirectory,
|
|
202
|
+
filenameExtension,
|
|
203
|
+
tryExtensions,
|
|
204
|
+
esExtensions,
|
|
205
|
+
esExtensionDefault,
|
|
206
|
+
ensureFileExists,
|
|
207
|
+
}) {
|
|
208
|
+
if (packageData) {
|
|
209
|
+
if (packageData.packagePath.endsWith('index.js') && !module.endsWith('index.js')) {
|
|
210
|
+
module = `${module}/index`
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
module: module + esExtensionDefault,
|
|
215
|
+
extension: esExtensionDefault,
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (currentModuleExtension && !esExtensions.includes(currentModuleExtension)) {
|
|
220
|
+
return false
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (
|
|
224
|
+
isDirectory &&
|
|
225
|
+
!existsSync(
|
|
226
|
+
resolve(
|
|
227
|
+
filenameDirectory,
|
|
228
|
+
currentModuleExtension ? module : module + esExtensionDefault
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
) {
|
|
232
|
+
module = `${module}/index`
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const targetFile = resolve(filenameDirectory, module)
|
|
236
|
+
|
|
237
|
+
if (ensureFileExists) {
|
|
238
|
+
// 1. try first with same extension
|
|
239
|
+
if (
|
|
240
|
+
esExtensions.includes(filenameExtension) &&
|
|
241
|
+
existsSync(targetFile + filenameExtension)
|
|
242
|
+
) {
|
|
243
|
+
return {
|
|
244
|
+
module: module + filenameExtension,
|
|
245
|
+
extension: filenameExtension,
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// 2. then try with all others
|
|
250
|
+
for (const extension of tryExtensions) {
|
|
251
|
+
if (existsSync(targetFile + extension)) {
|
|
252
|
+
return { module: module + '.mjs', extension }
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} else if (esExtensions.includes(filenameExtension)) {
|
|
256
|
+
return {
|
|
257
|
+
module: module + filenameExtension,
|
|
258
|
+
extension: filenameExtension,
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
return {
|
|
262
|
+
module: module + esExtensionDefault,
|
|
263
|
+
extension: esExtensionDefault,
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return false
|
|
268
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ConfigAPI, NodePath, PluginPass } from '@babel/core';
|
|
2
|
+
import type { ImportSpecifier, ImportDeclaration, ExportAllDeclaration, StringLiteral, ExportSpecifier, ExportDeclaration, ExportNamedDeclaration } from '@babel/types';
|
|
3
|
+
type ImportDeclarationFunc = (specifiers: Array<ImportSpecifier>, source: StringLiteral) => ImportDeclaration;
|
|
4
|
+
type ExportNamedDeclarationFunc = (declaration?: ExportDeclaration, specifiers?: Array<ExportSpecifier>, source?: StringLiteral) => ExportNamedDeclaration;
|
|
5
|
+
type ExportAllDeclarationFunc = (source: StringLiteral) => ExportAllDeclaration;
|
|
6
|
+
type PathDeclaration = NodePath & {
|
|
7
|
+
node: ImportDeclaration & ExportNamedDeclaration & ExportAllDeclaration;
|
|
8
|
+
};
|
|
9
|
+
interface FullySpecifiedOptions {
|
|
10
|
+
declaration: ImportDeclarationFunc | ExportNamedDeclarationFunc | ExportAllDeclarationFunc;
|
|
11
|
+
makeNodes: (path: PathDeclaration) => Array<PathDeclaration>;
|
|
12
|
+
ensureFileExists: boolean;
|
|
13
|
+
esExtensionDefault: string;
|
|
14
|
+
tryExtensions: Array<string>;
|
|
15
|
+
esExtensions: Array<string>;
|
|
16
|
+
includePackages: Array<string>;
|
|
17
|
+
}
|
|
18
|
+
export default function FullySpecified(api: ConfigAPI, options: FullySpecifiedOptions): {
|
|
19
|
+
name: string;
|
|
20
|
+
visitor: {
|
|
21
|
+
ImportDeclaration: (path: PathDeclaration, { file: { opts: { filename }, }, }: PluginPass) => void;
|
|
22
|
+
ExportNamedDeclaration: (path: PathDeclaration, { file: { opts: { filename }, }, }: PluginPass) => void;
|
|
23
|
+
ExportAllDeclaration: (path: PathDeclaration, { file: { opts: { filename }, }, }: PluginPass) => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,cAAc,CAA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