@tamagui/babel-plugin-fully-specified 1.110.5 → 1.111.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.
@@ -1,45 +1,24 @@
1
- import { existsSync, readFileSync, lstatSync } from "node:fs";
1
+ import { existsSync, lstatSync } from "node:fs";
2
2
  import { resolve, extname, dirname } from "node:path";
3
- function _define_property(obj, key, value) {
4
- return key in obj ? Object.defineProperty(obj, key, {
5
- value,
6
- enumerable: !0,
7
- configurable: !0,
8
- writable: !0
9
- }) : obj[key] = value, obj;
10
- }
11
- function _object_spread(target) {
12
- for (var i = 1; i < arguments.length; i++) {
13
- var source = arguments[i] != null ? arguments[i] : {}, ownKeys = Object.keys(source);
14
- typeof Object.getOwnPropertySymbols == "function" && (ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
15
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
16
- }))), ownKeys.forEach(function(key) {
17
- _define_property(target, key, source[key]);
18
- });
19
- }
20
- return target;
21
- }
22
3
  var DEFAULT_OPTIONS = {
23
- ensureFileExists: !1,
24
- esExtensionDefault: ".js",
4
+ ensureFileExists: !0,
5
+ esExtensionDefault: ".mjs",
25
6
  tryExtensions: [
26
- ".js",
27
- ".mjs",
28
- ".cjs"
7
+ ".js"
29
8
  ],
30
9
  esExtensions: [
31
- ".js",
32
- ".mjs",
33
- ".cjs"
34
- ],
35
- includePackages: []
10
+ ".mjs"
11
+ ]
36
12
  };
37
13
  function FullySpecified(api, rawOptions) {
38
14
  api.assertVersion(7);
39
- var options = _object_spread({}, DEFAULT_OPTIONS, rawOptions), importDeclarationVisitor = function(path, state) {
15
+ var options = {
16
+ ...DEFAULT_OPTIONS,
17
+ ...rawOptions
18
+ }, importDeclarationVisitor = function(path, state) {
40
19
  var filePath = state.file.opts.filename;
41
20
  if (filePath) {
42
- var node = path.node;
21
+ var { node } = path;
43
22
  if (node.importKind !== "type") {
44
23
  var originalModuleSpecifier = node.source.value, fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, {
45
24
  filePath,
@@ -51,7 +30,7 @@ function FullySpecified(api, rawOptions) {
51
30
  }, exportDeclarationVisitor = function(path, state) {
52
31
  var filePath = state.file.opts.filename;
53
32
  if (filePath) {
54
- var node = path.node;
33
+ var { node } = path;
55
34
  if (node.exportKind !== "type") {
56
35
  var source = node.source;
57
36
  if (source) {
@@ -90,16 +69,10 @@ function FullySpecified(api, rawOptions) {
90
69
  };
91
70
  }
92
71
  function getFullySpecifiedModuleSpecifier(originalModuleSpecifier, param) {
93
- var filePath = param.filePath, options = param.options, fileExt = extname(filePath), fileDir = dirname(filePath), includePackages = options.includePackages, packageData = null;
94
- if (!isLocalFile(originalModuleSpecifier) && (includePackages.some(function(name) {
95
- return originalModuleSpecifier.startsWith(name);
96
- }) && (packageData = getPackageData(originalModuleSpecifier, filePath)), !(packageData && packageData.isDeepImport)))
97
- return null;
98
- var isDirectory = isLocalDirectory(resolve(fileDir, originalModuleSpecifier)), currentModuleExtension = extname(originalModuleSpecifier), tryExtensions = options.tryExtensions, esExtensions = options.esExtensions, esExtensionDefault = options.esExtensionDefault, ensureFileExists = options.ensureFileExists, targetModule = evaluateTargetModule({
72
+ var { filePath, options } = param, fileExt = extname(filePath), fileDir = dirname(filePath), isDirectory = isLocalDirectory(resolve(fileDir, originalModuleSpecifier)), currentModuleExtension = extname(originalModuleSpecifier), { tryExtensions, esExtensions, esExtensionDefault, ensureFileExists } = options, targetModule = evaluateTargetModule({
99
73
  moduleSpecifier: originalModuleSpecifier,
100
74
  filenameDirectory: fileDir,
101
75
  filenameExtension: fileExt,
102
- packageData,
103
76
  currentModuleExtension,
104
77
  isDirectory,
105
78
  tryExtensions,
@@ -107,64 +80,24 @@ function getFullySpecifiedModuleSpecifier(originalModuleSpecifier, param) {
107
80
  esExtensionDefault,
108
81
  ensureFileExists
109
82
  });
110
- return targetModule === !1 || currentModuleExtension === targetModule.extension ? null : targetModule.module;
111
- }
112
- function getPackageData(moduleSpecifier, filePath) {
113
- try {
114
- for (var modulePath = require.resolve(moduleSpecifier, {
115
- paths: filePath ? [
116
- filePath
117
- ] : []
118
- }), parts = modulePath.split("/"), packageDir = "", i = parts.length; i >= 0; i--) {
119
- var dir = dirname(parts.slice(0, i).join("/"));
120
- if (existsSync("".concat(dir, "/package.json"))) {
121
- packageDir = dir;
122
- break;
123
- }
124
- }
125
- if (!packageDir)
126
- throw new Error("no package dir");
127
- var packageJson = JSON.parse(readFileSync("".concat(packageDir, "/package.json")).toString()), isDeepImport = !moduleSpecifier.endsWith(packageJson.name);
128
- return {
129
- isDeepImport,
130
- modulePath
131
- };
132
- } catch {
133
- }
134
- return null;
135
- }
136
- function isLocalFile(moduleSpecifier) {
137
- return moduleSpecifier.startsWith(".") || moduleSpecifier.startsWith("/");
83
+ return targetModule === !1 ? null : targetModule;
138
84
  }
139
85
  function isLocalDirectory(absoluteDirectory) {
140
86
  return existsSync(absoluteDirectory) && lstatSync(absoluteDirectory).isDirectory();
141
87
  }
142
88
  function evaluateTargetModule(param) {
143
- var moduleSpecifier = param.moduleSpecifier, 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;
144
- if (packageData)
145
- return packageData.modulePath.endsWith("index.js") && !moduleSpecifier.endsWith("index.js") && (moduleSpecifier = "".concat(moduleSpecifier, "/index")), {
146
- module: moduleSpecifier + esExtensionDefault,
147
- extension: esExtensionDefault
148
- };
89
+ var { moduleSpecifier, currentModuleExtension, isDirectory, filenameDirectory, filenameExtension, tryExtensions, esExtensions, esExtensionDefault, ensureFileExists } = param;
149
90
  if (currentModuleExtension && !esExtensions.includes(currentModuleExtension))
150
91
  return !1;
151
- isDirectory && !existsSync(resolve(filenameDirectory, currentModuleExtension ? moduleSpecifier : moduleSpecifier + esExtensionDefault)) && (moduleSpecifier = "".concat(moduleSpecifier, "/index"));
92
+ isDirectory && !existsSync(resolve(filenameDirectory, currentModuleExtension ? moduleSpecifier : moduleSpecifier + esExtensionDefault)) && (moduleSpecifier = `${moduleSpecifier}/index`);
152
93
  var targetFile = resolve(filenameDirectory, moduleSpecifier);
153
94
  if (ensureFileExists) {
154
- if (esExtensions.includes(filenameExtension) && existsSync(targetFile + filenameExtension))
155
- return {
156
- module: moduleSpecifier + (ensureFileExists.forceExtension || filenameExtension),
157
- extension: filenameExtension
158
- };
159
95
  var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
160
96
  try {
161
97
  for (var _iterator = tryExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
162
98
  var extension = _step.value;
163
99
  if (existsSync(targetFile + extension))
164
- return {
165
- module: moduleSpecifier + (ensureFileExists.forceExtension || extension),
166
- extension
167
- };
100
+ return moduleSpecifier + esExtensionDefault;
168
101
  }
169
102
  } catch (err) {
170
103
  _didIteratorError = !0, _iteratorError = err;
@@ -176,13 +109,7 @@ function evaluateTargetModule(param) {
176
109
  throw _iteratorError;
177
110
  }
178
111
  }
179
- } else return esExtensions.includes(filenameExtension) ? {
180
- module: moduleSpecifier + filenameExtension,
181
- extension: filenameExtension
182
- } : {
183
- module: moduleSpecifier + esExtensionDefault,
184
- extension: esExtensionDefault
185
- };
112
+ } else return esExtensions.includes(filenameExtension), moduleSpecifier + esExtensionDefault;
186
113
  return !1;
187
114
  }
188
115
  export {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Users/n8/tamagui/code/packages/babel-plugin-fully-specified/src/index.ts"],
4
- "mappings": "AAAA,SAASA,YAAYC,cAAcC,iBAAiB;AACpD,SAASC,SAASC,SAASC,eAAe;;;;;;;;;;;;;;;;;;;;AA8B1C,IAAMC,kBAAkB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sD,mBAAmBD,eAAAA;AAE9C,MAAIjD,kBAAkB;AAEpB,QACEG,aAAaqE,SAASrB,iBAAAA,KACtB1D,WAAWgF,aAAatB,iBAAAA;AAExB,aAAO;QACLE,QAAQJ,mBAAmBjD,iBAAiB0E,kBAAkBvB;QAC9DC,WAAWD;MACb;QAIG,4BAAA,IAAA,oBAAA,IAAA,iBAAA;;AAAL,eAAK,YAAmBjD,cAAAA,OAAAA,QAAAA,EAAAA,GAAnB,OAAA,EAAA,6BAAA,QAAA,UAAA,KAAA,GAAA,OAAA,4BAAA,IAAkC;AAAlC,YAAMkD,YAAN,MAAA;AACH,YAAI3D,WAAWgF,aAAarB,SAAAA;AAC1B,iBAAO;YACLC,QAAQJ,mBAAmBjD,iBAAiB0E,kBAAkBtB;YAC9DA;UACF;MAEJ;;AAPK,0BAAA,IAAA,iBAAA;;;SAAA,6BAAA,UAAA,UAAA,QAAA,UAAA,OAAA;;YAAA;gBAAA;;;EAQP,MAAO,QAAIjD,aAAaqE,SAASrB,iBAAAA,IACxB;IACLE,QAAQJ,kBAAkBE;IAC1BC,WAAWD;EACb,IAEO;IACLE,QAAQJ,kBAAkBhD;IAC1BmD,WAAWnD;EACb;AAGF,SAAO;AACT;",
5
- "names": ["existsSync", "readFileSync", "lstatSync", "resolve", "extname", "dirname", "DEFAULT_OPTIONS", "ensureFileExists", "esExtensionDefault", "tryExtensions", "esExtensions", "includePackages", "api", "rawOptions", "assertVersion", "options", "importDeclarationVisitor", "path", "state", "filePath", "file", "opts", "filename", "node", "importKind", "originalModuleSpecifier", "source", "value", "fullySpecifiedModuleSpecifier", "getFullySpecifiedModuleSpecifier", "exportDeclarationVisitor", "exportKind", "importVisitor", "parent", "type", "firstArgOfImportCall", "arguments", "name", "visitor", "ImportDeclaration", "ExportNamedDeclaration", "ExportAllDeclaration", "Import", "fileExt", "fileDir", "packageData", "isLocalFile", "some", "startsWith", "getPackageData", "isDeepImport", "isDirectory", "isLocalDirectory", "currentModuleExtension", "targetModule", "evaluateTargetModule", "moduleSpecifier", "filenameDirectory", "filenameExtension", "extension", "module", "modulePath", "require", "paths", "parts", "split", "packageDir", "i", "length", "dir", "slice", "join", "Error", "packageJson", "JSON", "parse", "toString", "endsWith", "absoluteDirectory", "includes", "targetFile", "forceExtension"]
4
+ "mappings": "AAAA,SAASA,YAA0BC,iBAAiB;AACpD,SAASC,SAASC,SAASC,eAAe;AAmB1C,IAAMC,kBAAkB;EACtBC,kBAAkB;EAClBC,oBAAoB;EACpBC,eAAe;IAAC;;EAChBC,cAAc;IAAC;;AACjB;AAEe,SAAf,eACEC,KACAC,YAAiC;AAEjCD,MAAIE,cAAc,CAAA;AAElB,MAAMC,UAAU;IAAE,GAAGR;IAAiB,GAAGM;EAAW,GAG9CG,2BAA2B,SAC/BC,MACAC,OAAAA;AAEA,QAAMC,WAAWD,MAAME,KAAKC,KAAKC;AACjC,QAAKH,UAEL;UAAM,EAAEI,KAAI,IAAKN;AACjB,UAAIM,KAAKC,eAAe,QAExB;YAAMC,0BAA0BF,KAAKG,OAAOC,OACtCC,gCAAgCC,iCACpCJ,yBACA;UACEN;UACAJ;QACF,CAAA;AAGF,QAAIa,kCACFL,KAAKG,OAAOC,QAAQC;;;EAExB,GAGME,2BAA2B,SAC/Bb,MACAC,OAAAA;AAEA,QAAMC,WAAWD,MAAME,KAAKC,KAAKC;AACjC,QAAKH,UAEL;UAAM,EAAEI,KAAI,IAAKN;AACjB,UAAIM,KAAKQ,eAAe,QAExB;YAAML,SAASH,KAAKG;AACpB,YAAKA,QAEL;cAAMD,0BAA0BC,OAAOC,OACjCC,gCAAgCC,iCACpCJ,yBACA;YACEN;YACAJ;UACF,CAAA;AAGF,UAAIa,kCACFF,OAAOC,QAAQC;;;;EAEnB,GAGMI,gBAAgB,SAACf,MAAwBC,OAAAA;AAC7C,QAAMC,WAAWD,MAAME,KAAKC,KAAKC;AACjC,QAAKH,UAEL;UAAMc,SAAShB,KAAKgB;AACpB,UAAIA,OAAOC,SAAS,kBAI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AAE9C,MAAI1C,kBAAkB;QACf,4BAAA,IAAA,oBAAA,IAAA,iBAAA;;AAAL,eAAK,YAAmBE,cAAAA,OAAAA,QAAAA,EAAAA,GAAnB,OAAA,EAAA,6BAAA,QAAA,UAAA,KAAA,GAAA,OAAA,4BAAA,IAAkC;AAAlC,YAAM8C,YAAN,MAAA;AACH,YAAItD,WAAWqD,aAAaC,SAAAA;AAC1B,iBAAON,kBAAkBzC;MAE7B;;AAJK,0BAAA,IAAA,iBAAA;;;SAAA,6BAAA,UAAA,UAAA,QAAA,UAAA,OAAA;;YAAA;gBAAA;;;EAKP,MAAO,QAAIE,aAAa2C,SAASF,iBAAAA,GACxBF,kBAAkBzC;AAK3B,SAAO;AACT;",
5
+ "names": ["existsSync", "lstatSync", "resolve", "extname", "dirname", "DEFAULT_OPTIONS", "ensureFileExists", "esExtensionDefault", "tryExtensions", "esExtensions", "api", "rawOptions", "assertVersion", "options", "importDeclarationVisitor", "path", "state", "filePath", "file", "opts", "filename", "node", "importKind", "originalModuleSpecifier", "source", "value", "fullySpecifiedModuleSpecifier", "getFullySpecifiedModuleSpecifier", "exportDeclarationVisitor", "exportKind", "importVisitor", "parent", "type", "firstArgOfImportCall", "arguments", "name", "visitor", "ImportDeclaration", "ExportNamedDeclaration", "ExportAllDeclaration", "Import", "fileExt", "fileDir", "isDirectory", "isLocalDirectory", "currentModuleExtension", "targetModule", "evaluateTargetModule", "moduleSpecifier", "filenameDirectory", "filenameExtension", "absoluteDirectory", "includes", "targetFile", "extension"]
6
6
  }
@@ -0,0 +1,145 @@
1
+ import { existsSync, lstatSync } from "node:fs";
2
+ import { resolve, extname, dirname } from "node:path";
3
+ var DEFAULT_OPTIONS = {
4
+ ensureFileExists: !0,
5
+ esExtensionDefault: ".mjs",
6
+ tryExtensions: [".js"],
7
+ esExtensions: [".mjs"]
8
+ };
9
+ function FullySpecified(api, rawOptions) {
10
+ api.assertVersion(7);
11
+ var options = {
12
+ ...DEFAULT_OPTIONS,
13
+ ...rawOptions
14
+ },
15
+ importDeclarationVisitor = function (path, state) {
16
+ var filePath = state.file.opts.filename;
17
+ if (filePath) {
18
+ var {
19
+ node
20
+ } = path;
21
+ if (node.importKind !== "type") {
22
+ var originalModuleSpecifier = node.source.value,
23
+ fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, {
24
+ filePath,
25
+ options
26
+ });
27
+ fullySpecifiedModuleSpecifier && (node.source.value = fullySpecifiedModuleSpecifier);
28
+ }
29
+ }
30
+ },
31
+ exportDeclarationVisitor = function (path, state) {
32
+ var filePath = state.file.opts.filename;
33
+ if (filePath) {
34
+ var {
35
+ node
36
+ } = path;
37
+ if (node.exportKind !== "type") {
38
+ var source = node.source;
39
+ if (source) {
40
+ var originalModuleSpecifier = source.value,
41
+ fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, {
42
+ filePath,
43
+ options
44
+ });
45
+ fullySpecifiedModuleSpecifier && (source.value = fullySpecifiedModuleSpecifier);
46
+ }
47
+ }
48
+ }
49
+ },
50
+ importVisitor = function (path, state) {
51
+ var filePath = state.file.opts.filename;
52
+ if (filePath) {
53
+ var parent = path.parent;
54
+ if (parent.type === "CallExpression") {
55
+ var firstArgOfImportCall = parent.arguments[0];
56
+ if (firstArgOfImportCall.type === "StringLiteral") {
57
+ var originalModuleSpecifier = firstArgOfImportCall.value,
58
+ fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, {
59
+ filePath,
60
+ options
61
+ });
62
+ fullySpecifiedModuleSpecifier && (firstArgOfImportCall.value = fullySpecifiedModuleSpecifier);
63
+ }
64
+ }
65
+ }
66
+ };
67
+ return {
68
+ name: "babel-plugin-fully-specified",
69
+ visitor: {
70
+ ImportDeclaration: importDeclarationVisitor,
71
+ ExportNamedDeclaration: exportDeclarationVisitor,
72
+ ExportAllDeclaration: exportDeclarationVisitor,
73
+ Import: importVisitor
74
+ }
75
+ };
76
+ }
77
+ function getFullySpecifiedModuleSpecifier(originalModuleSpecifier, param) {
78
+ var {
79
+ filePath,
80
+ options
81
+ } = param,
82
+ fileExt = extname(filePath),
83
+ fileDir = dirname(filePath),
84
+ isDirectory = isLocalDirectory(resolve(fileDir, originalModuleSpecifier)),
85
+ currentModuleExtension = extname(originalModuleSpecifier),
86
+ {
87
+ tryExtensions,
88
+ esExtensions,
89
+ esExtensionDefault,
90
+ ensureFileExists
91
+ } = options,
92
+ targetModule = evaluateTargetModule({
93
+ moduleSpecifier: originalModuleSpecifier,
94
+ filenameDirectory: fileDir,
95
+ filenameExtension: fileExt,
96
+ currentModuleExtension,
97
+ isDirectory,
98
+ tryExtensions,
99
+ esExtensions,
100
+ esExtensionDefault,
101
+ ensureFileExists
102
+ });
103
+ return targetModule === !1 ? null : targetModule;
104
+ }
105
+ function isLocalDirectory(absoluteDirectory) {
106
+ return existsSync(absoluteDirectory) && lstatSync(absoluteDirectory).isDirectory();
107
+ }
108
+ function evaluateTargetModule(param) {
109
+ var {
110
+ moduleSpecifier,
111
+ currentModuleExtension,
112
+ isDirectory,
113
+ filenameDirectory,
114
+ filenameExtension,
115
+ tryExtensions,
116
+ esExtensions,
117
+ esExtensionDefault,
118
+ ensureFileExists
119
+ } = param;
120
+ if (currentModuleExtension && !esExtensions.includes(currentModuleExtension)) return !1;
121
+ isDirectory && !existsSync(resolve(filenameDirectory, currentModuleExtension ? moduleSpecifier : moduleSpecifier + esExtensionDefault)) && (moduleSpecifier = `${moduleSpecifier}/index`);
122
+ var targetFile = resolve(filenameDirectory, moduleSpecifier);
123
+ if (ensureFileExists) {
124
+ var _iteratorNormalCompletion = !0,
125
+ _didIteratorError = !1,
126
+ _iteratorError = void 0;
127
+ try {
128
+ for (var _iterator = tryExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
129
+ var extension = _step.value;
130
+ if (existsSync(targetFile + extension)) return moduleSpecifier + esExtensionDefault;
131
+ }
132
+ } catch (err) {
133
+ _didIteratorError = !0, _iteratorError = err;
134
+ } finally {
135
+ try {
136
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
137
+ } finally {
138
+ if (_didIteratorError) throw _iteratorError;
139
+ }
140
+ }
141
+ } else return esExtensions.includes(filenameExtension), moduleSpecifier + esExtensionDefault;
142
+ return !1;
143
+ }
144
+ export { FullySpecified as default };
145
+ //# sourceMappingURL=index.native.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["existsSync","lstatSync","resolve","extname","dirname","DEFAULT_OPTIONS","ensureFileExists","esExtensionDefault","tryExtensions","esExtensions","FullySpecified","api","rawOptions","assertVersion","options","importDeclarationVisitor","path","state","filePath","file","opts","filename","node","importKind","originalModuleSpecifier","source","value","fullySpecifiedModuleSpecifier","getFullySpecifiedModuleSpecifier","exportDeclarationVisitor","exportKind","importVisitor","parent","type","firstArgOfImportCall","arguments","name","visitor","ImportDeclaration","ExportNamedDeclaration","ExportAllDeclaration","Import","param","fileExt","fileDir","isDirectory","isLocalDirectory","currentModuleExtension","targetModule","evaluateTargetModule","moduleSpecifier","filenameDirectory","filenameExtension","absoluteDirectory","includes","targetFile","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","extension","err","return"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,EAA0BC,SAAA,QAAiB;AACpD,SAASC,OAAA,EAASC,OAAA,EAASC,OAAA,QAAe;AAmB1C,IAAAC,eAAM;EACJC,gBAAA,EAAkB;EAClBC,kBAAA,EAAoB;EACpBC,aAAA,EAAe,CACf,MACF;EAEeC,YAAR,GAIL,MAAI;AASF;AACA,SAAKC,cAAUA,CAAAC,GAAA,EAAAC,UAAA;EAEfD,GAAA,CAAAE,aAAa,EAAI;EACjB,IAAAC,OAAS;MAET,GAAAT,eAAM;MACgC,GACpCO;IAAA;IAAAG,wBACA,YAAAA,CAAAC,IAAA,EAAAC,KAAA;MAAA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AAA6C,QAAA,CAAAP,sBAAA,GACA;EACAF,WAAA,KAAA7C,UAAA,CAAAE,OAAA,CAAAiD,iBAAA,EAAAJ,sBAAA,GAAAG,eAAA,GAAAA,eAAA,GAAA3C,kBAAA,OAAA2C,eAAA,MAAAA,eAAA;EACA,IAAAK,UAAA,GAAArD,OAAA,CAAAiD,iBAAA,EAAAD,eAAA;EACA,IAAA5C,gBAAA;IACA,IAAAkD,yBAAA;MAAAC,iBAAA;MAAAC,cAAA;IACA;MACC,SAAAC,SAAA,GAAAnD,aAAA,CAAAoD,MAAA,CAAAC,QAAA,KAAAC,KAAA,IAAAN,yBAAA,IAAAM,KAAA,GAAAH,SAAA,CAAAI,IAAA,IAAAC,IAAA,GAAAR,yBAAA;QACG,IAAAS,SAAA,GAAAH,KAAA,CAAApC,KAA2B;QAC7B,IAAO1B,UAAA,CAAAuD,UAAA,GAAAU,SAAA,GAIP,OACAf,eAAC,GAAA3C,kBAAA;MACC;IAAA,EACE,OAAA2D,GAAA;MACAT,iBAAA,OAAAC,cAAyB,GAAAQ,GAAkB;IAC7C;MACF,IAEA;QAGI,CAAAV,yBAAqB,IAAAG,SAAA,CAAmBQ,MAAA,YAAeR,SAAA,CAAAQ,MAAA;MAEzD;QACF,IAAAV,iBAAwB,EAClB,MAAAC,cAAW;MACb;IAAyB;EAS/B,OAAO,OAAAjD,YAAA,CAAA6C,QAAA,CAAAF,iBAAA,GAAAF,eAAA,GAAA3C,kBAAA;EACT","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/babel-plugin-fully-specified",
3
- "version": "1.110.5",
3
+ "version": "1.111.0",
4
4
  "source": "src/index.ts",
5
5
  "types": "./types/index.d.ts",
6
6
  "main": "dist/cjs",
@@ -4,18 +4,3 @@ exports[`transforming actual files > multiple extensions exists 1`] = `
4
4
  "// Expected to be transformed to use the \`.mjs\` extension, which is same as this file.
5
5
  import { foo, bar } from \\"./modules/module.mjs\\";"
6
6
  `;
7
-
8
- exports[`transforming actual files > test 1`] = `
9
- "import foo, { bar } from \\"./modules/module.mjs\\";
10
- import { foo as foo2 } from \\"./modules/module.mjs\\";
11
- import * as someModule from \\"./modules/module.mjs\\";
12
- import { foo as cjsFoo } from \\"./modules/cjs-module.cjs\\";
13
-
14
- // Will not be transformed
15
- import { foo as packageFoo } from '@my-org/my-pkg';
16
-
17
- // These will be transformed if \`includePackages\` includes \`@my-org/my-pkg\`.
18
- import { someStuff } from \\"@my-org/my-pkg/lib/index.js\\";
19
- // import { someOtherStuff } from '@my-org/my-pkg/lib/index' // TODO: Fix me
20
- import { exampleFunction } from \\"@my-org/my-pkg/lib/exampleFunction.js\\";"
21
- `;
@@ -33,40 +33,40 @@ function getTransformResult(
33
33
  describe('local imports', () => {
34
34
  test('named import', () => {
35
35
  const example1 = "import { foo } from './foo'"
36
- expect(getTransformResult(example1)?.code).toBe('import { foo } from "./foo.js";')
36
+ expect(getTransformResult(example1)?.code).toBe('import { foo } from "./foo.mjs";')
37
37
 
38
38
  const example2 = "import { foo as bar } from './foo'"
39
39
  expect(getTransformResult(example2)?.code).toBe(
40
- 'import { foo as bar } from "./foo.js";'
40
+ 'import { foo as bar } from "./foo.mjs";'
41
41
  )
42
42
  })
43
43
 
44
44
  test('default import', () => {
45
45
  const example1 = "import defaultFoo from './foo'"
46
- expect(getTransformResult(example1)?.code).toBe('import defaultFoo from "./foo.js";')
46
+ expect(getTransformResult(example1)?.code).toBe('import defaultFoo from "./foo.mjs";')
47
47
 
48
48
  const example2 = "import defaultFoo, { foo } from './foo'"
49
49
  expect(getTransformResult(example2)?.code).toBe(
50
- 'import defaultFoo, { foo } from "./foo.js";'
50
+ 'import defaultFoo, { foo } from "./foo.mjs";'
51
51
  )
52
52
  })
53
53
 
54
54
  test('namespace import', () => {
55
55
  const example = "import * as fooModule from './foo'"
56
56
  expect(getTransformResult(example)?.code).toBe(
57
- 'import * as fooModule from "./foo.js";'
57
+ 'import * as fooModule from "./foo.mjs";'
58
58
  )
59
59
  })
60
60
 
61
61
  test('side effects only import', () => {
62
62
  const example = "import './foo'"
63
- expect(getTransformResult(example)?.code).toBe('import "./foo.js";')
63
+ expect(getTransformResult(example)?.code).toBe('import "./foo.mjs";')
64
64
  })
65
65
 
66
66
  test('dynamic import()', () => {
67
67
  const example = "const foo = await import('./foo')"
68
68
  expect(getTransformResult(example)?.code).toBe(
69
- 'const foo = await import("./foo.js");'
69
+ 'const foo = await import("./foo.mjs");'
70
70
  )
71
71
  })
72
72
  })
@@ -74,45 +74,33 @@ describe('local imports', () => {
74
74
  describe('local re-exports', () => {
75
75
  test('named', () => {
76
76
  const example1 = "export { foo } from './foo'"
77
- expect(getTransformResult(example1)?.code).toBe('export { foo } from "./foo.js";')
77
+ expect(getTransformResult(example1)?.code).toBe('export { foo } from "./foo.mjs";')
78
78
 
79
79
  const example2 = "export { foo as bar } from './foo'"
80
80
  expect(getTransformResult(example2)?.code).toBe(
81
- 'export { foo as bar } from "./foo.js";'
81
+ 'export { foo as bar } from "./foo.mjs";'
82
82
  )
83
83
  })
84
84
 
85
85
  test('default', () => {
86
86
  const example1 = "export { default as fooDefault } from './foo'"
87
87
  expect(getTransformResult(example1)?.code).toBe(
88
- 'export { default as fooDefault } from "./foo.js";'
88
+ 'export { default as fooDefault } from "./foo.mjs";'
89
89
  )
90
90
  })
91
91
 
92
92
  test('namespace', () => {
93
93
  const example1 = "export * as fooModule from './foo'"
94
94
  expect(getTransformResult(example1)?.code).toBe(
95
- 'export * as fooModule from "./foo.js";'
95
+ 'export * as fooModule from "./foo.mjs";'
96
96
  )
97
97
 
98
98
  const example2 = "export * from './foo'"
99
- expect(getTransformResult(example2)?.code).toBe('export * from "./foo.js";')
99
+ expect(getTransformResult(example2)?.code).toBe('export * from "./foo.mjs";')
100
100
  })
101
101
  })
102
102
 
103
103
  describe('transforming actual files', () => {
104
- test('test', () => {
105
- const { code } =
106
- transformFileSync(
107
- path.join(__dirname, 'fixtures', 'sample-project-1', 'test.mjs'),
108
- getTransformOptions({
109
- pluginOptions: { ensureFileExists: true, includePackages: ['@my-org/my-pkg'] },
110
- })
111
- ) || {}
112
-
113
- expect(code).toMatchSnapshot()
114
- })
115
-
116
104
  test('multiple extensions exists', () => {
117
105
  const { code } =
118
106
  transformFileSync(
@@ -124,16 +112,4 @@ describe('transforming actual files', () => {
124
112
 
125
113
  expect(code).toMatchSnapshot()
126
114
  })
127
-
128
- test('force extension', () => {
129
- const { code } =
130
- transformFileSync(
131
- path.join(__dirname, 'fixtures', 'force-extension', 'foo.js'),
132
- getTransformOptions({
133
- pluginOptions: { ensureFileExists: { forceExtension: '.mjs' } },
134
- })
135
- ) || {}
136
-
137
- expect(code).toBe('import { bar } from "./bar.mjs";')
138
- })
139
115
  })