@tamagui/babel-plugin-fully-specified 2.7.7-1788328229285 → 3.0.0-beta.1091.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/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@tamagui/babel-plugin-fully-specified",
3
- "version": "2.7.7-1788328229285",
3
+ "version": "3.0.0-beta.1091.1",
4
4
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
5
  "license": "MIT",
6
6
  "source": "src/index.ts",
7
+ "types": "./types/index.d.ts",
7
8
  "files": [
8
9
  "src",
9
10
  "types",
@@ -33,6 +34,7 @@
33
34
  "access": "public"
34
35
  },
35
36
  "scripts": {
37
+ "build": "tamagui-build",
36
38
  "test": "vitest --run"
37
39
  },
38
40
  "dependencies": {
@@ -40,7 +42,7 @@
40
42
  },
41
43
  "devDependencies": {
42
44
  "@babel/types": "^7.25.4",
43
- "vitest": "4.0.4"
45
+ "vitest": "4.1.0"
44
46
  },
45
47
  "repository": {
46
48
  "type": "git",
@@ -3,81 +3,90 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 })
7
- },
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) &&
12
- key !== except &&
13
- __defProp(to, key, {
14
- get: () => from[key],
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
16
- })
17
- return to
6
+ for (var name in all) __defProp(target, name, { get: all[name], enumerable: true })
7
+ }
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if ((from && typeof from === 'object') || typeof from === 'function') {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
15
+ })
18
16
  }
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', { value: !0 }), mod)
17
+ return to
18
+ }
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', { value: true }), mod)
20
20
  var commonjs_exports = {}
21
21
  __export(commonjs_exports, {
22
22
  default: () => fullySpecifyCommonJS,
23
23
  })
24
24
  module.exports = __toCommonJS(commonjs_exports)
25
- var import_node_fs = require('node:fs'),
26
- import_node_path = require('node:path')
25
+ var import_node_fs = require('node:fs')
26
+ var import_node_path = require('node:path')
27
27
  function fullySpecifyCommonJS(api, options) {
28
- return (
29
- api.assertVersion(7),
30
- {
31
- name: 'babel-plugin-fully-specified-cjs',
32
- visitor: {
33
- CallExpression(path, state) {
34
- if (
35
- path.get('callee').isIdentifier({ name: 'require' }) &&
36
- path.node.arguments.length === 1
37
- ) {
38
- const arg = path.node.arguments[0]
39
- if (arg.type === 'StringLiteral') {
40
- let moduleSpecifier = arg.value
41
- if (moduleSpecifier.startsWith('.') || moduleSpecifier.startsWith('/')) {
42
- const filePath = state.file.opts.filename
43
- if (!filePath) return
44
- const fileDir = (0, import_node_path.dirname)(filePath),
45
- cjsExtension = options.esExtensionDefault || '.cjs',
46
- jsExtension = '.js'
47
- if (!(0, import_node_path.extname)(moduleSpecifier)) {
48
- const resolvedPath = (0, import_node_path.resolve)(
49
- fileDir,
50
- moduleSpecifier
28
+ api.assertVersion(7)
29
+ return {
30
+ name: 'babel-plugin-fully-specified-cjs',
31
+ visitor: {
32
+ CallExpression(path, state) {
33
+ const callee = path.get('callee')
34
+ if (
35
+ callee.isIdentifier({ name: 'require' }) &&
36
+ path.node.arguments.length === 1
37
+ ) {
38
+ const arg = path.node.arguments[0]
39
+ if (arg.type === 'StringLiteral') {
40
+ let moduleSpecifier = arg.value
41
+ if (moduleSpecifier.startsWith('.') || moduleSpecifier.startsWith('/')) {
42
+ const filePath = state.file.opts.filename
43
+ if (!filePath) return
44
+ const fileDir = (0, import_node_path.dirname)(filePath)
45
+ const cjsExtension = options.esExtensionDefault || '.cjs'
46
+ const jsExtension = '.js'
47
+ const specifierExtension = (0, import_node_path.extname)(moduleSpecifier)
48
+ const hasModuleExtension = [
49
+ '.js',
50
+ '.cjs',
51
+ '.mjs',
52
+ '.json',
53
+ '.node',
54
+ ].includes(specifierExtension)
55
+ if (!hasModuleExtension) {
56
+ const resolvedPath = (0, import_node_path.resolve)(
57
+ fileDir,
58
+ moduleSpecifier
59
+ )
60
+ let newModuleSpecifier = moduleSpecifier
61
+ if (isLocalDirectory(resolvedPath)) {
62
+ const indexPath = (0, import_node_path.resolve)(
63
+ resolvedPath,
64
+ 'index' + jsExtension
51
65
  )
52
- let newModuleSpecifier = moduleSpecifier
53
- if (isLocalDirectory(resolvedPath)) {
54
- const indexPath = (0, import_node_path.resolve)(
55
- resolvedPath,
56
- 'index' + jsExtension
57
- )
58
- if ((0, import_node_fs.existsSync)(indexPath)) {
59
- ;(newModuleSpecifier.endsWith('/') || (newModuleSpecifier += '/'),
60
- (newModuleSpecifier += 'index' + cjsExtension),
61
- (arg.value = newModuleSpecifier))
62
- return
66
+ if ((0, import_node_fs.existsSync)(indexPath)) {
67
+ if (!newModuleSpecifier.endsWith('/')) {
68
+ newModuleSpecifier += '/'
63
69
  }
64
- }
65
- if (
66
- (0, import_node_fs.existsSync)(resolvedPath + jsExtension) ||
67
- (0, import_node_fs.existsSync)(resolvedPath + cjsExtension)
68
- ) {
69
- ;((newModuleSpecifier += cjsExtension),
70
- (arg.value = newModuleSpecifier))
70
+ newModuleSpecifier += 'index' + cjsExtension
71
+ arg.value = newModuleSpecifier
71
72
  return
72
73
  }
73
74
  }
75
+ if (
76
+ (0, import_node_fs.existsSync)(resolvedPath + jsExtension) ||
77
+ (0, import_node_fs.existsSync)(resolvedPath + cjsExtension)
78
+ ) {
79
+ newModuleSpecifier += cjsExtension
80
+ arg.value = newModuleSpecifier
81
+ return
82
+ }
74
83
  }
75
84
  }
76
85
  }
77
- },
86
+ }
78
87
  },
79
- }
80
- )
88
+ },
89
+ }
81
90
  }
82
91
  function isLocalDirectory(absolutePath) {
83
92
  return (
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/commonjs.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsC,oBACtC,mBAA0C;AAE3B,SAAR,qBACL,KACA,SAGiB;AACjB,aAAI,cAAc,CAAC,GAEZ;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,eAAe,MAAM,OAAO;AAG1B,YAFe,KAAK,IAAI,QAAQ,EAGvB,aAAa,EAAE,MAAM,UAAU,CAAC,KACvC,KAAK,KAAK,UAAU,WAAW,GAC/B;AACA,gBAAM,MAAM,KAAK,KAAK,UAAU,CAAC;AACjC,cAAI,IAAI,SAAS,iBAAiB;AAChC,gBAAI,kBAAkB,IAAI;AAG1B,gBAAI,gBAAgB,WAAW,GAAG,KAAK,gBAAgB,WAAW,GAAG,GAAG;AACtE,oBAAM,WAAW,MAAM,KAAK,KAAK;AACjC,kBAAI,CAAC,SAAU;AAEf,oBAAM,cAAU,0BAAQ,QAAQ,GAC1B,eAAe,QAAQ,sBAAsB,QAC7C,cAAc;AAGpB,kBAAI,KAAC,0BAAQ,eAAe,GAAG;AAC7B,sBAAM,mBAAe,0BAAQ,SAAS,eAAe;AACrD,oBAAI,qBAAqB;AAGzB,oBAAI,iBAAiB,YAAY,GAAG;AAClC,wBAAM,gBAAY,0BAAQ,cAAc,UAAU,WAAW;AAC7D,0BAAI,2BAAW,SAAS,GAAG;AAEzB,oBAAK,mBAAmB,SAAS,GAAG,MAClC,sBAAsB,MAExB,sBAAsB,UAAU,cAChC,IAAI,QAAQ;AACZ;AAAA,kBACF;AAAA,gB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AG;AAClC,wBAAM,gBAAY,0BAAQ,cAAc,UAAU,WAAW;AAC7D,0BAAI,2BAAW,SAAS,GAAG;AAEzB,wBAAI,CAAC,mBAAmB,SAAS,GAAG,GAAG;AACrC,4CAAsB;AAAA,oBACxB;AACA,0CAAsB,UAAU;AAChC,wBAAI,QAAQ;AACZ;AAAA,kBACF;AAAA,gBACF;AAGA,wBACE,2BAAW,eAAe,WAAW,SACrC,2BAAW,eAAe,YAAY,GACtC;AACA,wCAAsB;AACtB,sBAAI,QAAQ;AACZ;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,iBAAiB,cAA+B;AACvD,aAAO,2BAAW,YAAY,SAAK,0BAAU,YAAY,EAAE,YAAY;AACzE;",
5
5
  "names": []
6
6
  }
@@ -1,55 +1,64 @@
1
1
  import { existsSync, lstatSync } from 'node:fs'
2
2
  import { dirname, extname, resolve } from 'node:path'
3
3
  function fullySpecifyCommonJS(api, options) {
4
- return (
5
- api.assertVersion(7),
6
- {
7
- name: 'babel-plugin-fully-specified-cjs',
8
- visitor: {
9
- CallExpression(path, state) {
10
- if (
11
- path.get('callee').isIdentifier({
12
- name: 'require',
13
- }) &&
14
- path.node.arguments.length === 1
15
- ) {
16
- const arg = path.node.arguments[0]
17
- if (arg.type === 'StringLiteral') {
18
- let moduleSpecifier = arg.value
19
- if (moduleSpecifier.startsWith('.') || moduleSpecifier.startsWith('/')) {
20
- const filePath = state.file.opts.filename
21
- if (!filePath) return
22
- const fileDir = dirname(filePath),
23
- cjsExtension = options.esExtensionDefault || '.cjs',
24
- jsExtension = '.js'
25
- if (!extname(moduleSpecifier)) {
26
- const resolvedPath = resolve(fileDir, moduleSpecifier)
27
- let newModuleSpecifier = moduleSpecifier
28
- if (isLocalDirectory(resolvedPath)) {
29
- const indexPath = resolve(resolvedPath, 'index' + jsExtension)
30
- if (existsSync(indexPath)) {
31
- ;(newModuleSpecifier.endsWith('/') || (newModuleSpecifier += '/'),
32
- (newModuleSpecifier += 'index' + cjsExtension),
33
- (arg.value = newModuleSpecifier))
34
- return
4
+ api.assertVersion(7)
5
+ return {
6
+ name: 'babel-plugin-fully-specified-cjs',
7
+ visitor: {
8
+ CallExpression(path, state) {
9
+ const callee = path.get('callee')
10
+ if (
11
+ callee.isIdentifier({
12
+ name: 'require',
13
+ }) &&
14
+ path.node.arguments.length === 1
15
+ ) {
16
+ const arg = path.node.arguments[0]
17
+ if (arg.type === 'StringLiteral') {
18
+ let moduleSpecifier = arg.value
19
+ if (moduleSpecifier.startsWith('.') || moduleSpecifier.startsWith('/')) {
20
+ const filePath = state.file.opts.filename
21
+ if (!filePath) return
22
+ const fileDir = dirname(filePath)
23
+ const cjsExtension = options.esExtensionDefault || '.cjs'
24
+ const jsExtension = '.js'
25
+ const specifierExtension = extname(moduleSpecifier)
26
+ const hasModuleExtension = [
27
+ '.js',
28
+ '.cjs',
29
+ '.mjs',
30
+ '.json',
31
+ '.node',
32
+ ].includes(specifierExtension)
33
+ if (!hasModuleExtension) {
34
+ const resolvedPath = resolve(fileDir, moduleSpecifier)
35
+ let newModuleSpecifier = moduleSpecifier
36
+ if (isLocalDirectory(resolvedPath)) {
37
+ const indexPath = resolve(resolvedPath, 'index' + jsExtension)
38
+ if (existsSync(indexPath)) {
39
+ if (!newModuleSpecifier.endsWith('/')) {
40
+ newModuleSpecifier += '/'
35
41
  }
36
- }
37
- if (
38
- existsSync(resolvedPath + jsExtension) ||
39
- existsSync(resolvedPath + cjsExtension)
40
- ) {
41
- ;((newModuleSpecifier += cjsExtension),
42
- (arg.value = newModuleSpecifier))
42
+ newModuleSpecifier += 'index' + cjsExtension
43
+ arg.value = newModuleSpecifier
43
44
  return
44
45
  }
45
46
  }
47
+ if (
48
+ existsSync(resolvedPath + jsExtension) ||
49
+ existsSync(resolvedPath + cjsExtension)
50
+ ) {
51
+ newModuleSpecifier += cjsExtension
52
+ arg.value = newModuleSpecifier
53
+ return
54
+ }
46
55
  }
47
56
  }
48
57
  }
49
- },
58
+ }
50
59
  },
51
- }
52
- )
60
+ },
61
+ }
53
62
  }
54
63
  function isLocalDirectory(absolutePath) {
55
64
  return existsSync(absolutePath) && lstatSync(absolutePath).isDirectory()
@@ -1 +1 @@
1
- {"version":3,"names":["existsSync","lstatSync","dirname","extname","resolve","fullySpecifyCommonJS","api","options","assertVersion","name","visitor","CallExpression","path","state","get","isIdentifier","node","arguments","length","arg","type","moduleSpecifier","value","startsWith","filePath","file","opts","filename","fileDir","cjsExtension","esExtensionDefault","jsExtension","resolvedPath","newModuleSpecifier","isLocalDirectory","indexPath","endsWith","filePathWithJs","absolutePath","isDirectory"],"sources":["../../src/commonjs.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,EAAYC,SAAA,QAAiB;AACtC,SAASC,OAAA,EAASC,OAAA,EAASC,OAAA,QAAe;AAE3B,SAARC,qBACLC,GAAA,EACAC,OAAA,EAGiB;EACjB,OAAAD,GAAA,CAAIE,aAAA,CAAc,CAAC,GAEZ;IACLC,IAAA,EAAM;IACNC,OAAA,EAAS;MACPC,eAAeC,IAAA,EAAMC,KAAA,EAAO;QAG1B,IAFeD,IAAA,CAAKE,GAAA,CAAI,QAAQ,EAGvBC,YAAA,CAAa;UAAEN,IAAA,EAAM;QAAU,CAAC,KACvCG,IAAA,CAAKI,IAAA,CAAKC,SAAA,CAAUC,MAAA,KAAW,GAC/B;UACA,MAAMC,GAAA,GAAMP,IAAA,CAAKI,IAAA,CAAKC,SAAA,CAAU,CAAC;UACjC,IAAIE,GAAA,CAAIC,IAAA,KAAS,iBAAiB;YAChC,IAAIC,eAAA,GAAkBF,GAAA,CAAIG,KAAA;YAG1B,IAAID,eAAA,CAAgBE,UAAA,CAAW,GAAG,KAAKF,eAAA,CAAgBE,UAAA,CAAW,GAAG,GAAG;cACtE,MAAMC,QAAA,GAAWX,KAAA,CAAMY,IAAA,CAAKC,IAAA,CAAKC,QAAA;cACjC,IAAI,CAACH,QAAA,EAAU;cAEf,MAAMI,OAAA,GAAU1B,OAAA,CAAQsB,QAAQ;gBAC1BK,YAAA,GAAetB,OAAA,CAAQuB,kBAAA,IAAsB;gBAC7CC,WAAA,GAAc;cAGpB,IAAI,CAAC5B,OAAA,CAAQkB,eAAe,GAAG;gBAC7B,MAAMW,YAAA,GAAe5B,OAAA,CAAQwB,OAAA,EAASP,eAAe;gBACrD,IAAIY,kBAAA,GAAqBZ,eAAA;gBAGzB,IAAIa,gBAAA,CAAiBF,YAAY,GAAG;kBAClC,MAAMG,SAAA,GAAY/B,OAAA,CAAQ4B,YAAA,EAAc,UAAUD,WAAW;kBAC7D,IAAI/B,UAAA,CAAWmC,SAAS,GAAG;oBAEpBF,kBAAA,CAAmBG,QAAA,CAAS,GAAG,MAClCH,kBAAA,IAAsB,MAExBA,kBAAA,IAAsB,UAAUJ,YAAA,EAChCV,GAAA,CAAIG,KAAA,GAAQW,kBAAA;oBACZ;kBACF;gBACF;gBAGA,MAAMI,cAAA,GAAiBL,YAAA,GAAeD,WAAA;gBACtC,IAAI/B,UAAA,CAAWqC,cAAc,GAAG;kBAC9BJ,kBAAA,IAAsBJ,YAAA,EACtBV,GAAA,CAAIG,KAAA,GAAQW,kBAAA;kBACZ;gBACF;cACF;YACF;UACF;QACF;MACF;IACF;EACF;AACF;AAEA,SAASC,iBAAiBI,YAAA,EAA+B;EACvD,OAAOtC,UAAA,CAAWsC,YAAY,KAAKrC,SAAA,CAAUqC,YAAY,EAAEC,WAAA,CAAY;AACzE","ignoreList":[]}
1
+ {"version":3,"names":["existsSync","lstatSync","dirname","extname","resolve","fullySpecifyCommonJS","api","options","assertVersion","name","visitor","CallExpression","path","state","callee","get","isIdentifier","node","arguments","length","arg","type","moduleSpecifier","value","startsWith","filePath","file","opts","filename","fileDir","cjsExtension","esExtensionDefault","jsExtension","specifierExtension","hasModuleExtension","includes","resolvedPath","newModuleSpecifier","isLocalDirectory","indexPath","endsWith","absolutePath","isDir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kBAAA,GAAqBf,eAAA;gBAGzB,IAAIgB,gBAAA,CAAiBF,YAAY,GAAG;kBAClC,MAAMG,SAAA,GAAYnC,OAAA,CAAQgC,YAAA,EAAc,UAAUJ,WAAW;kBAC7D,IAAIhC,UAAA,CAAWuC,SAAS,GAAG;oBAEzB,IAAI,CAACF,kBAAA,CAAmBG,QAAA,CAAS,GAAG,GAAG;sBACrCH,kBAAA,IAAsB;oBACxB;oBACAA,kBAAA,IAAsB,UAAUP,YAAA;oBAChCV,GAAA,CAAIG,KAAA,GAAQc,kBAAA;oBACZ;kBACF;gBACF;gBAGA,IACErC,UAAA,CAAWoC,YAAA,GAAeJ,WAAW,KACrChC,UAAA,CAAWoC,YAAA,GAAeN,YAAY,GACtC;kBACAO,kBAAA,IAAsBP,YAAA;kBACtBV,GAAA,CAAIG,KAAA,GAAQc,kBAAA;kBACZ;gBACF;cACF;YACF;UACF;QACF;MACF;IACF;EACF;AACF;AAEA,SAASC,iBAAiBG,YAAA,EAA+B;EACvD,OAAOzC,UAAA,CAAWyC,YAAY,KAAKxC,SAAA,CAAUwC,YAAY,EAAEC,WAAA,CAAY;AACzE","ignoreList":[]}
package/src/commonjs.ts CHANGED
@@ -32,8 +32,17 @@ export default function fullySpecifyCommonJS(
32
32
  const cjsExtension = options.esExtensionDefault || '.cjs'
33
33
  const jsExtension = '.js'
34
34
 
35
- // Check if moduleSpecifier already has an extension
36
- if (!extname(moduleSpecifier)) {
35
+ // Check if moduleSpecifier already has a module extension. extname alone
36
+ // is wrong here: dotted basenames like ./foo.generated have no extension.
37
+ const specifierExtension = extname(moduleSpecifier)
38
+ const hasModuleExtension = [
39
+ '.js',
40
+ '.cjs',
41
+ '.mjs',
42
+ '.json',
43
+ '.node',
44
+ ].includes(specifierExtension)
45
+ if (!hasModuleExtension) {
37
46
  const resolvedPath = resolve(fileDir, moduleSpecifier)
38
47
  let newModuleSpecifier = moduleSpecifier
39
48
 
@@ -0,0 +1,5 @@
1
+ export default function fullySpecifyCommonJS(api: any, options: {
2
+ esExtensionDefault: string;
3
+ }): babel.PluginObj;
4
+
5
+ //# sourceMappingURL=commonjs.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAGA,eAAe,SAAS,qBACtB,UACA,SAAS;CACP;IAED,MAAM",
3
+ "names": [],
4
+ "sources": [
5
+ "src/commonjs.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "import { existsSync, lstatSync } from 'node:fs'\nimport { dirname, extname, resolve } from 'node:path'\n\nexport default function fullySpecifyCommonJS(\n api: any,\n options: {\n esExtensionDefault: string\n }\n): babel.PluginObj {\n api.assertVersion(7)\n\n return {\n name: 'babel-plugin-fully-specified-cjs',\n visitor: {\n CallExpression(path, state) {\n const callee = path.get('callee')\n\n if (\n callee.isIdentifier({ name: 'require' }) &&\n path.node.arguments.length === 1\n ) {\n const arg = path.node.arguments[0]\n if (arg.type === 'StringLiteral') {\n let moduleSpecifier = arg.value\n\n // Skip built-in modules and node_modules\n if (moduleSpecifier.startsWith('.') || moduleSpecifier.startsWith('/')) {\n const filePath = state.file.opts.filename\n if (!filePath) return // Cannot determine file path\n\n const fileDir = dirname(filePath)\n const cjsExtension = options.esExtensionDefault || '.cjs'\n const jsExtension = '.js'\n\n // Check if moduleSpecifier already has a module extension. extname alone\n // is wrong here: dotted basenames like ./foo.generated have no extension.\n const specifierExtension = extname(moduleSpecifier)\n const hasModuleExtension = [\n '.js',\n '.cjs',\n '.mjs',\n '.json',\n '.node',\n ].includes(specifierExtension)\n if (!hasModuleExtension) {\n const resolvedPath = resolve(fileDir, moduleSpecifier)\n let newModuleSpecifier = moduleSpecifier\n\n // Check if the moduleSpecifier is a directory with an index.cjs file\n if (isLocalDirectory(resolvedPath)) {\n const indexPath = resolve(resolvedPath, 'index' + jsExtension)\n if (existsSync(indexPath)) {\n // Append '/' if not present\n if (!newModuleSpecifier.endsWith('/')) {\n newModuleSpecifier += '/'\n }\n newModuleSpecifier += 'index' + cjsExtension\n arg.value = newModuleSpecifier\n return\n }\n }\n\n // Check if source file exists (try .js first, then target extension)\n if (\n existsSync(resolvedPath + jsExtension) ||\n existsSync(resolvedPath + cjsExtension)\n ) {\n newModuleSpecifier += cjsExtension\n arg.value = newModuleSpecifier\n return\n }\n }\n }\n }\n }\n },\n },\n } satisfies babel.PluginObj\n}\n\nfunction isLocalDirectory(absolutePath: string): boolean {\n return existsSync(absolutePath) && lstatSync(absolutePath).isDirectory()\n}\n"
10
+ ]
11
+ }
@@ -0,0 +1,14 @@
1
+ import type { ConfigAPI, PluginObj } from "@babel/core";
2
+ export interface FullySpecifiedOptions {
3
+ ensureFileExists: boolean;
4
+ esExtensionDefault: string;
5
+ /** List of all extensions which we try to find. */
6
+ tryExtensions: Array<string>;
7
+ /** List of extensions that can run in Node.js or in the Browser. */
8
+ esExtensions: Array<string>;
9
+ /** Convert process.env.XYZ to import.meta.env.XYZ */
10
+ convertProcessEnvToImportMetaEnv?: boolean;
11
+ }
12
+ export default function FullySpecified(api: ConfigAPI, rawOptions?: Partial<FullySpecifiedOptions>): PluginObj;
13
+
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAGA,cAAc,WAAqB,iBAA6B;AAUhE,iBAAiB,sBAAsB;CACrC;CACA;;CAEA,eAAe;;CAEf,cAAc;;CAEd;;AAWF,eAAe,SAAS,eACtB,KAAK,WACL,aAAY,QAAQ,yBACnB",
3
+ "names": [],
4
+ "sources": [
5
+ "src/index.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "import { existsSync, lstatSync } from 'node:fs'\nimport { dirname, extname, resolve } from 'node:path'\n\nimport type { ConfigAPI, NodePath, PluginObj, PluginPass } from '@babel/core'\nimport * as t from '@babel/types'\nimport type {\n ExportAllDeclaration,\n ExportNamedDeclaration,\n Import,\n ImportDeclaration,\n MemberExpression,\n} from '@babel/types'\n\nexport interface FullySpecifiedOptions {\n ensureFileExists: boolean\n esExtensionDefault: string\n /** List of all extensions which we try to find. */\n tryExtensions: Array<string>\n /** List of extensions that can run in Node.js or in the Browser. */\n esExtensions: Array<string>\n /** Convert process.env.XYZ to import.meta.env.XYZ */\n convertProcessEnvToImportMetaEnv?: boolean\n}\n\nconst DEFAULT_OPTIONS = {\n ensureFileExists: true,\n esExtensionDefault: '.mjs',\n tryExtensions: ['.js'],\n esExtensions: ['.mjs'],\n convertProcessEnvToImportMetaEnv: false,\n} satisfies FullySpecifiedOptions\n\nexport default function FullySpecified(\n api: ConfigAPI,\n rawOptions: Partial<FullySpecifiedOptions> = {}\n): PluginObj {\n api.assertVersion(7)\n\n const options = normalizeOptions(rawOptions)\n\n /** For `import ... from '...'`. */\n const importDeclarationVisitor = (\n path: NodePath<ImportDeclaration>,\n state: PluginPass\n ) => {\n const filePath = state.file.opts.filename\n if (!filePath) return // cannot determine file path therefore cannot proceed\n\n const { node } = path\n if (node.importKind === 'type') return // is a type-only import, skip\n\n const originalModuleSpecifier = node.source.value\n const fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(\n originalModuleSpecifier,\n {\n filePath,\n options,\n }\n )\n\n if (fullySpecifiedModuleSpecifier) {\n node.source.value = fullySpecifiedModuleSpecifier\n }\n }\n\n /** For `export ... from '...'`. */\n const exportDeclarationVisitor = (\n path: NodePath<ExportNamedDeclaration> | NodePath<ExportAllDeclaration>,\n state: PluginPass\n ) => {\n const filePath = state.file.opts.filename\n if (!filePath) return // cannot determine file path therefore cannot proceed\n\n const { node } = path\n if (node.exportKind === 'type') return // is a type-only export, skip\n\n const source = node.source\n if (!source) return // is not a re-export, skip\n\n const originalModuleSpecifier = source.value\n const fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(\n originalModuleSpecifier,\n {\n filePath,\n options,\n }\n )\n\n if (fullySpecifiedModuleSpecifier) {\n source.value = fullySpecifiedModuleSpecifier\n }\n }\n\n /** For dynamic `import()`s. */\n const importVisitor = (path: NodePath<Import>, state) => {\n const filePath = state.file.opts.filename\n if (!filePath) return // cannot determine file path therefore cannot proceed\n\n const parent = path.parent\n if (parent.type !== 'CallExpression') {\n return // we expect the usage of `import` is a call to it, e.g.: `import('...')`, other usages are not supported\n }\n\n const firstArgOfImportCall = parent.arguments[0]\n if (firstArgOfImportCall.type !== 'StringLiteral') {\n return // we expect the first argument of `import` to be a string, e.g.: `import('./myModule')`, other types are not supported\n }\n\n const originalModuleSpecifier = firstArgOfImportCall.value\n const fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(\n originalModuleSpecifier,\n {\n filePath,\n options,\n }\n )\n\n if (fullySpecifiedModuleSpecifier) {\n firstArgOfImportCall.value = fullySpecifiedModuleSpecifier\n }\n }\n\n /** For converting process.env to import.meta.env */\n const memberExpressionVisitor = (path: NodePath<MemberExpression>) => {\n if (!options.convertProcessEnvToImportMetaEnv) return\n\n const { node } = path\n\n // Check if this is process.env.SOMETHING\n if (\n node.object.type === 'MemberExpression' &&\n node.object.object.type === 'Identifier' &&\n node.object.object.name === 'process' &&\n node.object.property.type === 'Identifier' &&\n node.object.property.name === 'env'\n ) {\n // Skip process.env.NODE_ENV - leave it as is\n if (node.property.type === 'Identifier' && node.property.name === 'NODE_ENV') {\n return\n }\n\n // Replace process.env with import.meta.env\n node.object = t.memberExpression(\n t.metaProperty(t.identifier('import'), t.identifier('meta')),\n t.identifier('env')\n )\n }\n }\n\n return {\n name: 'babel-plugin-fully-specified',\n visitor: {\n ImportDeclaration: importDeclarationVisitor,\n ExportNamedDeclaration: exportDeclarationVisitor,\n ExportAllDeclaration: exportDeclarationVisitor,\n Import: importVisitor,\n MemberExpression: memberExpressionVisitor,\n },\n }\n}\n\nfunction normalizeOptions(\n rawOptions: Partial<FullySpecifiedOptions>\n): FullySpecifiedOptions {\n const options = { ...DEFAULT_OPTIONS, ...rawOptions }\n\n if (\n rawOptions.esExtensionDefault &&\n !rawOptions.tryExtensions &&\n rawOptions.esExtensionDefault !== DEFAULT_OPTIONS.esExtensionDefault\n ) {\n options.tryExtensions = [\n rawOptions.esExtensionDefault,\n ...DEFAULT_OPTIONS.tryExtensions.filter(\n (extension) => extension !== rawOptions.esExtensionDefault\n ),\n ]\n }\n\n return options\n}\n\n/**\n * 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).\n */\nfunction getFullySpecifiedModuleSpecifier(\n /**\n * The original module specifier in the code.\n *\n * For example, `'./foo'` for `import { foo } from './foo'`.\n */\n originalModuleSpecifier: string,\n {\n filePath,\n options,\n }: {\n /**\n * The absolute file path of the file being transformed.\n *\n * Normally this can be obtained from the 2nd parameter in a visitor function (often named as `state`): `state.file.opts.filename`.\n */\n filePath: string\n /** Options that users pass to babel-plugin-fully-specified. */\n options: FullySpecifiedOptions\n }\n): string | null {\n const fileExt = extname(filePath)\n const fileDir = dirname(filePath)\n\n const isDirectory = isLocalDirectory(resolve(fileDir, originalModuleSpecifier))\n\n const currentModuleExtension = extname(originalModuleSpecifier)\n\n const { tryExtensions, esExtensions, esExtensionDefault, ensureFileExists } = options\n\n const targetModule = evaluateTargetModule({\n moduleSpecifier: originalModuleSpecifier,\n filenameDirectory: fileDir,\n filenameExtension: fileExt,\n currentModuleExtension,\n isDirectory,\n tryExtensions,\n esExtensions,\n esExtensionDefault,\n ensureFileExists,\n })\n\n if (targetModule === false) {\n return null\n }\n\n return targetModule\n}\n\nfunction isLocalDirectory(absoluteDirectory: string) {\n return existsSync(absoluteDirectory) && lstatSync(absoluteDirectory).isDirectory()\n}\n\nfunction evaluateTargetModule({\n moduleSpecifier,\n currentModuleExtension,\n isDirectory,\n filenameDirectory,\n filenameExtension,\n tryExtensions,\n esExtensions,\n esExtensionDefault,\n ensureFileExists,\n}: any): string | false {\n const targetFile = resolve(filenameDirectory, moduleSpecifier)\n\n if (ensureFileExists) {\n for (const extension of tryExtensions) {\n if (existsSync(targetFile + extension)) {\n return moduleSpecifier + esExtensionDefault\n }\n }\n\n if (currentModuleExtension && !esExtensions.includes(currentModuleExtension)) {\n return false\n }\n\n if (isDirectory) {\n const indexModuleSpecifier = `${moduleSpecifier.replace(/\\/$/, '')}/index`\n const indexTargetFile = resolve(filenameDirectory, indexModuleSpecifier)\n\n for (const extension of tryExtensions) {\n if (existsSync(indexTargetFile + extension)) {\n return indexModuleSpecifier + esExtensionDefault\n }\n }\n }\n } else if (esExtensions.includes(filenameExtension)) {\n return moduleSpecifier + esExtensionDefault\n } else {\n return moduleSpecifier + esExtensionDefault\n }\n\n return false\n}\n"
10
+ ]
11
+ }