@tamagui/babel-plugin-fully-specified 1.101.7 → 1.102.1
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 +98 -74
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.native.js +98 -121
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/esm/index.js +97 -79
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +105 -91
- package/dist/esm/index.native.js +97 -121
- package/dist/esm/index.native.js.map +2 -2
- package/package.json +6 -4
- package/src/__tests__/__snapshots__/index.test.ts.snap +21 -0
- package/src/__tests__/fixtures/force-extension/bar.js +1 -0
- package/src/__tests__/fixtures/force-extension/foo.js +1 -0
- package/src/__tests__/fixtures/multiple-extensions-exists/modules/module.cjs +2 -0
- package/src/__tests__/fixtures/multiple-extensions-exists/modules/module.js +2 -0
- package/src/__tests__/fixtures/multiple-extensions-exists/modules/module.mjs +4 -0
- package/src/__tests__/fixtures/multiple-extensions-exists/test.mjs +2 -0
- package/src/__tests__/fixtures/sample-project-1/modules/cjs-module.cjs +2 -0
- package/src/__tests__/fixtures/sample-project-1/modules/module.mjs +4 -0
- package/src/__tests__/fixtures/sample-project-1/node_modules/@my-org/my-pkg/lib/exampleFunction.js +3 -0
- package/src/__tests__/fixtures/sample-project-1/node_modules/@my-org/my-pkg/lib/index.js +1 -0
- package/src/__tests__/fixtures/sample-project-1/node_modules/@my-org/my-pkg/package.json +4 -0
- package/src/__tests__/fixtures/sample-project-1/node_modules/README.md +1 -0
- package/src/__tests__/fixtures/sample-project-1/test.mjs +13 -0
- package/src/__tests__/index.test.ts +139 -0
- package/src/index.ts +220 -140
- package/types/index.d.ts +14 -21
- package/types/index.d.ts.map +1 -1
package/src/index.ts
CHANGED
|
@@ -1,168 +1,242 @@
|
|
|
1
1
|
import { existsSync, readFileSync, lstatSync } from 'node:fs'
|
|
2
2
|
import { resolve, extname, dirname } from 'node:path'
|
|
3
|
-
import {
|
|
4
|
-
importDeclaration,
|
|
5
|
-
exportNamedDeclaration,
|
|
6
|
-
exportAllDeclaration,
|
|
7
|
-
stringLiteral,
|
|
8
|
-
} from '@babel/types'
|
|
9
3
|
|
|
10
|
-
import type { ConfigAPI, NodePath, PluginPass } from '@babel/core'
|
|
4
|
+
import type { ConfigAPI, NodePath, PluginObj, PluginPass } from '@babel/core'
|
|
11
5
|
import type {
|
|
12
|
-
ImportSpecifier,
|
|
13
|
-
ImportDeclaration,
|
|
14
6
|
ExportAllDeclaration,
|
|
15
|
-
StringLiteral,
|
|
16
|
-
ExportSpecifier,
|
|
17
|
-
ExportDeclaration,
|
|
18
7
|
ExportNamedDeclaration,
|
|
8
|
+
Import,
|
|
9
|
+
ImportDeclaration,
|
|
19
10
|
} from '@babel/types'
|
|
20
11
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
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
|
+
}
|
|
50
23
|
esExtensionDefault: string
|
|
24
|
+
/** List of all extensions which we try to find. */
|
|
51
25
|
tryExtensions: Array<string>
|
|
26
|
+
/** List of extensions that can run in Node.js or in the Browser. */
|
|
52
27
|
esExtensions: Array<string>
|
|
28
|
+
/** List of packages that also should be transformed with this plugin. */
|
|
53
29
|
includePackages: Array<string>
|
|
54
30
|
}
|
|
55
31
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
}: PluginPass
|
|
32
|
+
const DEFAULT_OPTIONS = {
|
|
33
|
+
ensureFileExists: false,
|
|
34
|
+
esExtensionDefault: '.js',
|
|
35
|
+
tryExtensions: ['.js', '.mjs', '.cjs'],
|
|
36
|
+
esExtensions: ['.js', '.mjs', '.cjs'],
|
|
37
|
+
includePackages: [],
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default function FullySpecified(
|
|
41
|
+
api: ConfigAPI,
|
|
42
|
+
rawOptions: FullySpecifiedOptions
|
|
43
|
+
): PluginObj {
|
|
44
|
+
api.assertVersion(7)
|
|
45
|
+
|
|
46
|
+
const options = { ...DEFAULT_OPTIONS, ...rawOptions }
|
|
47
|
+
|
|
48
|
+
/** For `import ... from '...'`. */
|
|
49
|
+
const importDeclarationVisitor = (
|
|
50
|
+
path: NodePath<ImportDeclaration>,
|
|
51
|
+
state: PluginPass
|
|
78
52
|
) => {
|
|
79
|
-
const
|
|
53
|
+
const filePath = state.file.opts.filename
|
|
54
|
+
if (!filePath) return // cannot determine file path therefore cannot proceed
|
|
55
|
+
|
|
56
|
+
const { node } = path
|
|
57
|
+
if (node.importKind === 'type') return // is a type-only import, skip
|
|
58
|
+
|
|
59
|
+
const originalModuleSpecifier = node.source.value
|
|
60
|
+
const fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(
|
|
61
|
+
originalModuleSpecifier,
|
|
62
|
+
{
|
|
63
|
+
filePath,
|
|
64
|
+
options,
|
|
65
|
+
}
|
|
66
|
+
)
|
|
80
67
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
68
|
+
if (fullySpecifiedModuleSpecifier) {
|
|
69
|
+
node.source.value = fullySpecifiedModuleSpecifier
|
|
83
70
|
}
|
|
71
|
+
}
|
|
84
72
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
73
|
+
/** For `export ... from '...'`. */
|
|
74
|
+
const exportDeclarationVisitor = (
|
|
75
|
+
path: NodePath<ExportNamedDeclaration> | NodePath<ExportAllDeclaration>,
|
|
76
|
+
state: PluginPass
|
|
77
|
+
) => {
|
|
78
|
+
const filePath = state.file.opts.filename
|
|
79
|
+
if (!filePath) return // cannot determine file path therefore cannot proceed
|
|
90
80
|
|
|
91
|
-
const {
|
|
92
|
-
|
|
81
|
+
const { node } = path
|
|
82
|
+
if (node.exportKind === 'type') return // is a type-only export, skip
|
|
93
83
|
|
|
94
|
-
|
|
84
|
+
const source = node.source
|
|
85
|
+
if (!source) return // is not a re-export, skip
|
|
95
86
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
const originalModuleSpecifier = source.value
|
|
88
|
+
const fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(
|
|
89
|
+
originalModuleSpecifier,
|
|
90
|
+
{
|
|
91
|
+
filePath,
|
|
92
|
+
options,
|
|
99
93
|
}
|
|
94
|
+
)
|
|
100
95
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
96
|
+
if (fullySpecifiedModuleSpecifier) {
|
|
97
|
+
source.value = fullySpecifiedModuleSpecifier
|
|
104
98
|
}
|
|
99
|
+
}
|
|
105
100
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
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
|
-
})
|
|
101
|
+
/** For dynamic `import()`s. */
|
|
102
|
+
const importVisitor = (path: NodePath<Import>, state) => {
|
|
103
|
+
const filePath = state.file.opts.filename
|
|
104
|
+
if (!filePath) return // cannot determine file path therefore cannot proceed
|
|
123
105
|
|
|
124
|
-
|
|
125
|
-
|
|
106
|
+
const parent = path.parent
|
|
107
|
+
if (parent.type !== 'CallExpression') {
|
|
108
|
+
return // we expect the usage of `import` is a call to it, e.g.: `import('...')`, other usages are not supported
|
|
126
109
|
}
|
|
127
110
|
|
|
128
|
-
const
|
|
111
|
+
const firstArgOfImportCall = parent.arguments[0]
|
|
112
|
+
if (firstArgOfImportCall.type !== 'StringLiteral') {
|
|
113
|
+
return // we expect the first argument of `import` to be a string, e.g.: `import('./myModule')`, other types are not supported
|
|
114
|
+
}
|
|
129
115
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
116
|
+
const originalModuleSpecifier = firstArgOfImportCall.value
|
|
117
|
+
const fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(
|
|
118
|
+
originalModuleSpecifier,
|
|
119
|
+
{
|
|
120
|
+
filePath,
|
|
121
|
+
options,
|
|
122
|
+
}
|
|
133
123
|
)
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
124
|
|
|
137
|
-
|
|
138
|
-
|
|
125
|
+
if (fullySpecifiedModuleSpecifier) {
|
|
126
|
+
firstArgOfImportCall.value = fullySpecifiedModuleSpecifier
|
|
127
|
+
}
|
|
128
|
+
}
|
|
139
129
|
|
|
140
130
|
return {
|
|
141
131
|
name: 'babel-plugin-fully-specified',
|
|
142
132
|
visitor: {
|
|
143
|
-
ImportDeclaration:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
}),
|
|
133
|
+
ImportDeclaration: importDeclarationVisitor,
|
|
134
|
+
ExportNamedDeclaration: exportDeclarationVisitor,
|
|
135
|
+
ExportAllDeclaration: exportDeclarationVisitor,
|
|
136
|
+
Import: importVisitor,
|
|
158
137
|
},
|
|
159
138
|
}
|
|
160
139
|
}
|
|
161
140
|
|
|
162
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Returns a fully specified [module specifier](https://tc39.es/ecma262/multipage/ecmascript-language-scripts-and-modules.html#prod-ModuleSpecifier) (or `null` if it can't be determined or shouldn't be transformed).
|
|
143
|
+
*/
|
|
144
|
+
function getFullySpecifiedModuleSpecifier(
|
|
145
|
+
/**
|
|
146
|
+
* The original module specifier in the code.
|
|
147
|
+
*
|
|
148
|
+
* For example, `'./foo'` for `import { foo } from './foo'`.
|
|
149
|
+
*/
|
|
150
|
+
originalModuleSpecifier: string,
|
|
151
|
+
{
|
|
152
|
+
filePath,
|
|
153
|
+
options,
|
|
154
|
+
}: {
|
|
155
|
+
/**
|
|
156
|
+
* The absolute file path of the file being transformed.
|
|
157
|
+
*
|
|
158
|
+
* Normally this can be obtained from the 2nd parameter in a visitor function (often named as `state`): `state.file.opts.filename`.
|
|
159
|
+
*/
|
|
160
|
+
filePath: string
|
|
161
|
+
/** Options that users pass to babel-plugin-fully-specified. */
|
|
162
|
+
options: FullySpecifiedOptions
|
|
163
|
+
}
|
|
164
|
+
): string | null {
|
|
165
|
+
const fileExt = extname(filePath)
|
|
166
|
+
const fileDir = dirname(filePath)
|
|
167
|
+
|
|
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
|
+
const isDirectory = isLocalDirectory(resolve(fileDir, originalModuleSpecifier))
|
|
182
|
+
|
|
183
|
+
const currentModuleExtension = extname(originalModuleSpecifier)
|
|
184
|
+
|
|
185
|
+
const { tryExtensions, esExtensions, esExtensionDefault, ensureFileExists } = options
|
|
186
|
+
|
|
187
|
+
const targetModule = evaluateTargetModule({
|
|
188
|
+
moduleSpecifier: originalModuleSpecifier,
|
|
189
|
+
filenameDirectory: fileDir,
|
|
190
|
+
filenameExtension: fileExt,
|
|
191
|
+
packageData,
|
|
192
|
+
currentModuleExtension,
|
|
193
|
+
isDirectory,
|
|
194
|
+
tryExtensions,
|
|
195
|
+
esExtensions,
|
|
196
|
+
esExtensionDefault,
|
|
197
|
+
ensureFileExists,
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
if (targetModule === false || currentModuleExtension === targetModule.extension) {
|
|
201
|
+
return null
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return targetModule.module
|
|
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 {
|
|
163
235
|
try {
|
|
164
|
-
const
|
|
165
|
-
|
|
236
|
+
const modulePath = require.resolve(moduleSpecifier, {
|
|
237
|
+
paths: filePath ? [filePath] : [],
|
|
238
|
+
})
|
|
239
|
+
const parts = modulePath.split('/')
|
|
166
240
|
|
|
167
241
|
let packageDir = ''
|
|
168
242
|
for (let i = parts.length; i >= 0; i--) {
|
|
@@ -178,15 +252,15 @@ function getPackageData<PackageData>(module: string) {
|
|
|
178
252
|
|
|
179
253
|
const packageJson = JSON.parse(readFileSync(`${packageDir}/package.json`).toString())
|
|
180
254
|
|
|
181
|
-
const
|
|
182
|
-
return {
|
|
255
|
+
const isDeepImport = !moduleSpecifier.endsWith(packageJson.name)
|
|
256
|
+
return { isDeepImport, modulePath }
|
|
183
257
|
} catch (e) {}
|
|
184
258
|
|
|
185
259
|
return null
|
|
186
260
|
}
|
|
187
261
|
|
|
188
|
-
function isLocalFile(
|
|
189
|
-
return
|
|
262
|
+
function isLocalFile(moduleSpecifier: string) {
|
|
263
|
+
return moduleSpecifier.startsWith('.') || moduleSpecifier.startsWith('/')
|
|
190
264
|
}
|
|
191
265
|
|
|
192
266
|
function isLocalDirectory(absoluteDirectory: string) {
|
|
@@ -194,7 +268,7 @@ function isLocalDirectory(absoluteDirectory: string) {
|
|
|
194
268
|
}
|
|
195
269
|
|
|
196
270
|
function evaluateTargetModule({
|
|
197
|
-
|
|
271
|
+
moduleSpecifier,
|
|
198
272
|
currentModuleExtension,
|
|
199
273
|
packageData,
|
|
200
274
|
isDirectory,
|
|
@@ -206,12 +280,15 @@ function evaluateTargetModule({
|
|
|
206
280
|
ensureFileExists,
|
|
207
281
|
}) {
|
|
208
282
|
if (packageData) {
|
|
209
|
-
if (
|
|
210
|
-
|
|
283
|
+
if (
|
|
284
|
+
packageData.modulePath.endsWith('index.js') &&
|
|
285
|
+
!moduleSpecifier.endsWith('index.js')
|
|
286
|
+
) {
|
|
287
|
+
moduleSpecifier = `${moduleSpecifier}/index`
|
|
211
288
|
}
|
|
212
289
|
|
|
213
290
|
return {
|
|
214
|
-
module:
|
|
291
|
+
module: moduleSpecifier + esExtensionDefault,
|
|
215
292
|
extension: esExtensionDefault,
|
|
216
293
|
}
|
|
217
294
|
}
|
|
@@ -225,14 +302,14 @@ function evaluateTargetModule({
|
|
|
225
302
|
!existsSync(
|
|
226
303
|
resolve(
|
|
227
304
|
filenameDirectory,
|
|
228
|
-
currentModuleExtension ?
|
|
305
|
+
currentModuleExtension ? moduleSpecifier : moduleSpecifier + esExtensionDefault
|
|
229
306
|
)
|
|
230
307
|
)
|
|
231
308
|
) {
|
|
232
|
-
|
|
309
|
+
moduleSpecifier = `${moduleSpecifier}/index`
|
|
233
310
|
}
|
|
234
311
|
|
|
235
|
-
const targetFile = resolve(filenameDirectory,
|
|
312
|
+
const targetFile = resolve(filenameDirectory, moduleSpecifier)
|
|
236
313
|
|
|
237
314
|
if (ensureFileExists) {
|
|
238
315
|
// 1. try first with same extension
|
|
@@ -241,7 +318,7 @@ function evaluateTargetModule({
|
|
|
241
318
|
existsSync(targetFile + filenameExtension)
|
|
242
319
|
) {
|
|
243
320
|
return {
|
|
244
|
-
module:
|
|
321
|
+
module: moduleSpecifier + (ensureFileExists.forceExtension || filenameExtension),
|
|
245
322
|
extension: filenameExtension,
|
|
246
323
|
}
|
|
247
324
|
}
|
|
@@ -249,17 +326,20 @@ function evaluateTargetModule({
|
|
|
249
326
|
// 2. then try with all others
|
|
250
327
|
for (const extension of tryExtensions) {
|
|
251
328
|
if (existsSync(targetFile + extension)) {
|
|
252
|
-
return {
|
|
329
|
+
return {
|
|
330
|
+
module: moduleSpecifier + (ensureFileExists.forceExtension || extension),
|
|
331
|
+
extension,
|
|
332
|
+
}
|
|
253
333
|
}
|
|
254
334
|
}
|
|
255
335
|
} else if (esExtensions.includes(filenameExtension)) {
|
|
256
336
|
return {
|
|
257
|
-
module:
|
|
337
|
+
module: moduleSpecifier + filenameExtension,
|
|
258
338
|
extension: filenameExtension,
|
|
259
339
|
}
|
|
260
340
|
} else {
|
|
261
341
|
return {
|
|
262
|
-
module:
|
|
342
|
+
module: moduleSpecifier + esExtensionDefault,
|
|
263
343
|
extension: esExtensionDefault,
|
|
264
344
|
}
|
|
265
345
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
import type { ConfigAPI,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
makeNodes: (path: PathDeclaration) => Array<PathDeclaration>;
|
|
12
|
-
ensureFileExists: boolean;
|
|
1
|
+
import type { ConfigAPI, PluginObj } from '@babel/core';
|
|
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
|
+
};
|
|
13
11
|
esExtensionDefault: string;
|
|
12
|
+
/** List of all extensions which we try to find. */
|
|
14
13
|
tryExtensions: Array<string>;
|
|
14
|
+
/** List of extensions that can run in Node.js or in the Browser. */
|
|
15
15
|
esExtensions: Array<string>;
|
|
16
|
+
/** List of packages that also should be transformed with this plugin. */
|
|
16
17
|
includePackages: Array<string>;
|
|
17
18
|
}
|
|
18
|
-
export default function FullySpecified(api: ConfigAPI,
|
|
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 {};
|
|
19
|
+
export default function FullySpecified(api: ConfigAPI, rawOptions: FullySpecifiedOptions): PluginObj;
|
|
27
20
|
//# 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":"
|
|
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,EACZ,OAAO,GACP;QACE;;;;WAIG;QACH,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB,CAAA;IACL,kBAAkB,EAAE,MAAM,CAAA;IAC1B,mDAAmD;IACnD,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC5B,oEAAoE;IACpE,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC3B,yEAAyE;IACzE,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAC/B;AAUD,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,GAAG,EAAE,SAAS,EACd,UAAU,EAAE,qBAAqB,GAChC,SAAS,CAgGX"}
|