@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.
- package/dist/cjs/index.js +8 -58
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +18 -92
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/esm/index.js +9 -59
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +9 -60
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +18 -91
- package/dist/esm/index.native.js.map +2 -2
- package/dist/esm/index.native.mjs +145 -0
- package/dist/esm/index.native.mjs.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -15
- package/src/__tests__/index.test.ts +12 -36
- package/src/index.ts +10 -131
- package/types/index.d.ts +1 -10
- package/types/index.d.ts.map +1 -1
package/src/index.ts
CHANGED
|
@@ -10,31 +10,19 @@ import type {
|
|
|
10
10
|
} from '@babel/types'
|
|
11
11
|
|
|
12
12
|
export interface FullySpecifiedOptions {
|
|
13
|
-
ensureFileExists:
|
|
14
|
-
| boolean
|
|
15
|
-
| {
|
|
16
|
-
/**
|
|
17
|
-
* If you're doing a non-in-place transformation (for example, outputting `.mjs` from `.js`) with `ensureFileExists` enabled, it's possible that the transform will be incorrect due to the imported file is not transformed and written into place yet (for example, we have `foo.js` and `bar.js` and we're transforming them into `foo.mjs` and `bar.mjs` respectively, in `bar.js` we have `import { ... } from './foo.js'` which we expect to be transformed into `import { ... } from './foo.mjs'`, but if `foo.mjs` is not transformed and written yet, it will be transformed into `import { ... } from './foo.js'` because `foo.mjs` can't be found at that time).
|
|
18
|
-
*
|
|
19
|
-
* To solve this, you can set this option to `'.mjs'` to force the extension to be transformed into that specified extension.
|
|
20
|
-
*/
|
|
21
|
-
forceExtension?: string
|
|
22
|
-
}
|
|
13
|
+
ensureFileExists: boolean
|
|
23
14
|
esExtensionDefault: string
|
|
24
15
|
/** List of all extensions which we try to find. */
|
|
25
16
|
tryExtensions: Array<string>
|
|
26
17
|
/** List of extensions that can run in Node.js or in the Browser. */
|
|
27
18
|
esExtensions: Array<string>
|
|
28
|
-
/** List of packages that also should be transformed with this plugin. */
|
|
29
|
-
includePackages: Array<string>
|
|
30
19
|
}
|
|
31
20
|
|
|
32
21
|
const DEFAULT_OPTIONS = {
|
|
33
|
-
ensureFileExists:
|
|
34
|
-
esExtensionDefault: '.
|
|
35
|
-
tryExtensions: ['.js'
|
|
36
|
-
esExtensions: ['.
|
|
37
|
-
includePackages: [],
|
|
22
|
+
ensureFileExists: true,
|
|
23
|
+
esExtensionDefault: '.mjs',
|
|
24
|
+
tryExtensions: ['.js'],
|
|
25
|
+
esExtensions: ['.mjs'],
|
|
38
26
|
}
|
|
39
27
|
|
|
40
28
|
export default function FullySpecified(
|
|
@@ -165,19 +153,6 @@ function getFullySpecifiedModuleSpecifier(
|
|
|
165
153
|
const fileExt = extname(filePath)
|
|
166
154
|
const fileDir = dirname(filePath)
|
|
167
155
|
|
|
168
|
-
const { includePackages } = options
|
|
169
|
-
|
|
170
|
-
let packageData: PackageImportData | null = null
|
|
171
|
-
if (!isLocalFile(originalModuleSpecifier)) {
|
|
172
|
-
if (includePackages.some((name) => originalModuleSpecifier.startsWith(name))) {
|
|
173
|
-
packageData = getPackageData(originalModuleSpecifier, filePath)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (!(packageData && packageData.isDeepImport)) {
|
|
177
|
-
return null
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
156
|
const isDirectory = isLocalDirectory(resolve(fileDir, originalModuleSpecifier))
|
|
182
157
|
|
|
183
158
|
const currentModuleExtension = extname(originalModuleSpecifier)
|
|
@@ -188,7 +163,6 @@ function getFullySpecifiedModuleSpecifier(
|
|
|
188
163
|
moduleSpecifier: originalModuleSpecifier,
|
|
189
164
|
filenameDirectory: fileDir,
|
|
190
165
|
filenameExtension: fileExt,
|
|
191
|
-
packageData,
|
|
192
166
|
currentModuleExtension,
|
|
193
167
|
isDirectory,
|
|
194
168
|
tryExtensions,
|
|
@@ -197,70 +171,11 @@ function getFullySpecifiedModuleSpecifier(
|
|
|
197
171
|
ensureFileExists,
|
|
198
172
|
})
|
|
199
173
|
|
|
200
|
-
if (targetModule === false
|
|
174
|
+
if (targetModule === false) {
|
|
201
175
|
return null
|
|
202
176
|
}
|
|
203
177
|
|
|
204
|
-
return targetModule
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Data about how a package is being imported.
|
|
209
|
-
*/
|
|
210
|
-
type PackageImportData = {
|
|
211
|
-
/**
|
|
212
|
-
* Indicates whether the import from the package is a deep import.
|
|
213
|
-
*
|
|
214
|
-
* Example:
|
|
215
|
-
*
|
|
216
|
-
* * `import { foo } from '@org/package'` -> `isDeepImport: false`
|
|
217
|
-
* * `import { foo } from '@org/package/lib/foo'` -> `isDeepImport: true`
|
|
218
|
-
*/
|
|
219
|
-
isDeepImport: boolean
|
|
220
|
-
/**
|
|
221
|
-
* The resolved absolute path of the exact file being imported. This will always be a file path (such as `<project>/node_modules/my-pkg/dist/index.js`), not just a directory path.
|
|
222
|
-
*/
|
|
223
|
-
modulePath: string
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Given a module specifier and the file path of the source file which imports that module, returns the package data of that module if it can be found.
|
|
228
|
-
*/
|
|
229
|
-
function getPackageData(
|
|
230
|
-
/** The module specifier, e.g.: `@org/package/lib/someTool`. */
|
|
231
|
-
moduleSpecifier: string,
|
|
232
|
-
/** The file path of the source file which imports that module. */
|
|
233
|
-
filePath?: string
|
|
234
|
-
): PackageImportData | null {
|
|
235
|
-
try {
|
|
236
|
-
const modulePath = require.resolve(moduleSpecifier, {
|
|
237
|
-
paths: filePath ? [filePath] : [],
|
|
238
|
-
})
|
|
239
|
-
const parts = modulePath.split('/')
|
|
240
|
-
|
|
241
|
-
let packageDir = ''
|
|
242
|
-
for (let i = parts.length; i >= 0; i--) {
|
|
243
|
-
const dir = dirname(parts.slice(0, i).join('/'))
|
|
244
|
-
if (existsSync(`${dir}/package.json`)) {
|
|
245
|
-
packageDir = dir
|
|
246
|
-
break
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
if (!packageDir) {
|
|
250
|
-
throw new Error(`no package dir`)
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const packageJson = JSON.parse(readFileSync(`${packageDir}/package.json`).toString())
|
|
254
|
-
|
|
255
|
-
const isDeepImport = !moduleSpecifier.endsWith(packageJson.name)
|
|
256
|
-
return { isDeepImport, modulePath }
|
|
257
|
-
} catch (e) {}
|
|
258
|
-
|
|
259
|
-
return null
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function isLocalFile(moduleSpecifier: string) {
|
|
263
|
-
return moduleSpecifier.startsWith('.') || moduleSpecifier.startsWith('/')
|
|
178
|
+
return targetModule
|
|
264
179
|
}
|
|
265
180
|
|
|
266
181
|
function isLocalDirectory(absoluteDirectory: string) {
|
|
@@ -270,7 +185,6 @@ function isLocalDirectory(absoluteDirectory: string) {
|
|
|
270
185
|
function evaluateTargetModule({
|
|
271
186
|
moduleSpecifier,
|
|
272
187
|
currentModuleExtension,
|
|
273
|
-
packageData,
|
|
274
188
|
isDirectory,
|
|
275
189
|
filenameDirectory,
|
|
276
190
|
filenameExtension,
|
|
@@ -279,20 +193,6 @@ function evaluateTargetModule({
|
|
|
279
193
|
esExtensionDefault,
|
|
280
194
|
ensureFileExists,
|
|
281
195
|
}) {
|
|
282
|
-
if (packageData) {
|
|
283
|
-
if (
|
|
284
|
-
packageData.modulePath.endsWith('index.js') &&
|
|
285
|
-
!moduleSpecifier.endsWith('index.js')
|
|
286
|
-
) {
|
|
287
|
-
moduleSpecifier = `${moduleSpecifier}/index`
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return {
|
|
291
|
-
module: moduleSpecifier + esExtensionDefault,
|
|
292
|
-
extension: esExtensionDefault,
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
196
|
if (currentModuleExtension && !esExtensions.includes(currentModuleExtension)) {
|
|
297
197
|
return false
|
|
298
198
|
}
|
|
@@ -312,36 +212,15 @@ function evaluateTargetModule({
|
|
|
312
212
|
const targetFile = resolve(filenameDirectory, moduleSpecifier)
|
|
313
213
|
|
|
314
214
|
if (ensureFileExists) {
|
|
315
|
-
// 1. try first with same extension
|
|
316
|
-
if (
|
|
317
|
-
esExtensions.includes(filenameExtension) &&
|
|
318
|
-
existsSync(targetFile + filenameExtension)
|
|
319
|
-
) {
|
|
320
|
-
return {
|
|
321
|
-
module: moduleSpecifier + (ensureFileExists.forceExtension || filenameExtension),
|
|
322
|
-
extension: filenameExtension,
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// 2. then try with all others
|
|
327
215
|
for (const extension of tryExtensions) {
|
|
328
216
|
if (existsSync(targetFile + extension)) {
|
|
329
|
-
return
|
|
330
|
-
module: moduleSpecifier + (ensureFileExists.forceExtension || extension),
|
|
331
|
-
extension,
|
|
332
|
-
}
|
|
217
|
+
return moduleSpecifier + esExtensionDefault
|
|
333
218
|
}
|
|
334
219
|
}
|
|
335
220
|
} else if (esExtensions.includes(filenameExtension)) {
|
|
336
|
-
return
|
|
337
|
-
module: moduleSpecifier + filenameExtension,
|
|
338
|
-
extension: filenameExtension,
|
|
339
|
-
}
|
|
221
|
+
return moduleSpecifier + esExtensionDefault
|
|
340
222
|
} else {
|
|
341
|
-
return
|
|
342
|
-
module: moduleSpecifier + esExtensionDefault,
|
|
343
|
-
extension: esExtensionDefault,
|
|
344
|
-
}
|
|
223
|
+
return moduleSpecifier + esExtensionDefault
|
|
345
224
|
}
|
|
346
225
|
|
|
347
226
|
return false
|
package/types/index.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import type { ConfigAPI, PluginObj } from '@babel/core';
|
|
2
2
|
export interface FullySpecifiedOptions {
|
|
3
|
-
ensureFileExists: boolean
|
|
4
|
-
/**
|
|
5
|
-
* If you're doing a non-in-place transformation (for example, outputting `.mjs` from `.js`) with `ensureFileExists` enabled, it's possible that the transform will be incorrect due to the imported file is not transformed and written into place yet (for example, we have `foo.js` and `bar.js` and we're transforming them into `foo.mjs` and `bar.mjs` respectively, in `bar.js` we have `import { ... } from './foo.js'` which we expect to be transformed into `import { ... } from './foo.mjs'`, but if `foo.mjs` is not transformed and written yet, it will be transformed into `import { ... } from './foo.js'` because `foo.mjs` can't be found at that time).
|
|
6
|
-
*
|
|
7
|
-
* To solve this, you can set this option to `'.mjs'` to force the extension to be transformed into that specified extension.
|
|
8
|
-
*/
|
|
9
|
-
forceExtension?: string;
|
|
10
|
-
};
|
|
3
|
+
ensureFileExists: boolean;
|
|
11
4
|
esExtensionDefault: string;
|
|
12
5
|
/** List of all extensions which we try to find. */
|
|
13
6
|
tryExtensions: Array<string>;
|
|
14
7
|
/** List of extensions that can run in Node.js or in the Browser. */
|
|
15
8
|
esExtensions: Array<string>;
|
|
16
|
-
/** List of packages that also should be transformed with this plugin. */
|
|
17
|
-
includePackages: Array<string>;
|
|
18
9
|
}
|
|
19
10
|
export default function FullySpecified(api: ConfigAPI, rawOptions: FullySpecifiedOptions): PluginObj;
|
|
20
11
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAY,SAAS,EAAc,MAAM,aAAa,CAAA;AAQ7E,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAY,SAAS,EAAc,MAAM,aAAa,CAAA;AAQ7E,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,EAAE,OAAO,CAAA;IACzB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,mDAAmD;IACnD,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC5B,oEAAoE;IACpE,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAC5B;AASD,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,GAAG,EAAE,SAAS,EACd,UAAU,EAAE,qBAAqB,GAChC,SAAS,CAgGX"}
|