react-native-builder-bob 0.25.0-next.1 → 0.25.0-next.3
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/lib/babel.js +3 -3
- package/lib/babel.js.map +1 -1
- package/package.json +2 -2
package/lib/babel.js
CHANGED
|
@@ -20,12 +20,12 @@ const isDirectory = filename => {
|
|
|
20
20
|
return exists;
|
|
21
21
|
};
|
|
22
22
|
const isModule = (filename, ext) => {
|
|
23
|
-
const exts = ['ts', 'tsx', ext];
|
|
23
|
+
const exts = ['.js', '.ts', '.jsx', '.tsx', ext];
|
|
24
24
|
|
|
25
25
|
// Metro won't resolve these extensions if explicit extension is provided
|
|
26
26
|
// So we can't add extension to these files
|
|
27
|
-
const
|
|
28
|
-
return exts.some(ext => isFile(`${filename}.${ext}`) &&
|
|
27
|
+
const platforms = ['native', 'android', 'ios', 'windows', 'macos', 'visionos', 'web', 'tv', 'android.tv', 'ios.tv'];
|
|
28
|
+
return exts.some(ext => isFile(`${filename}.${ext}`) && platforms.every(platform => !isFile(`${filename}.${platform}.${ext}`)));
|
|
29
29
|
};
|
|
30
30
|
const isTypeImport = node => 'importKind' in node && node.importKind === 'type' || 'exportKind' in node && node.exportKind === 'type';
|
|
31
31
|
const assertFilename = filename => {
|
package/lib/babel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel.js","names":["_fs","_interopRequireDefault","require","_path","obj","__esModule","default","isFile","filename","exists","fs","lstatSync","throwIfNoEntry","isDirectory","isModule","ext","exts","
|
|
1
|
+
{"version":3,"file":"babel.js","names":["_fs","_interopRequireDefault","require","_path","obj","__esModule","default","isFile","filename","exists","fs","lstatSync","throwIfNoEntry","isDirectory","isModule","ext","exts","platforms","some","every","platform","isTypeImport","node","importKind","exportKind","assertFilename","Error","_default","api","alias","extension","assertVersion","aliasImports","state","source","value","root","cwd","key","Object","entries","startsWith","resolved","path","relative","dirname","resolve","replace","addExtension","join","name","visitor","ImportDeclaration","ExportNamedDeclaration","ExportAllDeclaration"],"sources":["../src/babel.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport type { ConfigAPI, NodePath, PluginObj, PluginPass } from '@babel/core';\nimport type {\n ImportDeclaration,\n ExportAllDeclaration,\n ExportNamedDeclaration,\n} from '@babel/types';\n\ntype Options = {\n alias?: Record<string, string>;\n extension?: 'cjs' | 'mjs';\n};\n\nconst isFile = (filename: string): boolean => {\n const exists =\n fs.lstatSync(filename, { throwIfNoEntry: false })?.isFile() ?? false;\n\n return exists;\n};\n\nconst isDirectory = (filename: string): boolean => {\n const exists =\n fs.lstatSync(filename, { throwIfNoEntry: false })?.isDirectory() ?? false;\n\n return exists;\n};\n\nconst isModule = (filename: string, ext: string): boolean => {\n const exts = ['.js', '.ts', '.jsx', '.tsx', ext];\n\n // Metro won't resolve these extensions if explicit extension is provided\n // So we can't add extension to these files\n const platforms = [\n 'native',\n 'android',\n 'ios',\n 'windows',\n 'macos',\n 'visionos',\n 'web',\n 'tv',\n 'android.tv',\n 'ios.tv',\n ];\n\n return exts.some(\n (ext) =>\n isFile(`${filename}.${ext}`) &&\n platforms.every((platform) => !isFile(`${filename}.${platform}.${ext}`))\n );\n};\n\nconst isTypeImport = (\n node: ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration\n) =>\n ('importKind' in node && node.importKind === 'type') ||\n ('exportKind' in node && node.exportKind === 'type');\n\nconst assertFilename: (\n filename: string | null | undefined\n) => asserts filename is string = (filename) => {\n if (filename == null) {\n throw new Error(\"Couldn't find a filename for the current file.\");\n }\n};\n\nexport default function (\n api: ConfigAPI,\n { alias, extension }: Options\n): PluginObj {\n api.assertVersion(7);\n\n function aliasImports(\n {\n node,\n }: NodePath<\n ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration\n >,\n state: PluginPass\n ) {\n if (\n alias == null ||\n // Skip type imports as they'll be removed\n isTypeImport(node) ||\n // Skip imports without a source\n !node.source?.value\n ) {\n return;\n }\n\n assertFilename(state.filename);\n\n const root = state.cwd;\n const source = node.source.value;\n\n for (const [key, value] of Object.entries(alias)) {\n if (source === key || source.startsWith(`${key}/`)) {\n const resolved = value.startsWith('.')\n ? path.relative(\n path.dirname(state.filename),\n path.resolve(root, value)\n )\n : value;\n\n node.source.value = source.replace(key, resolved);\n return;\n }\n }\n }\n\n function addExtension(\n {\n node,\n }: NodePath<\n ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration\n >,\n state: PluginPass\n ) {\n if (\n extension == null ||\n // Skip type imports as they'll be removed\n isTypeImport(node) ||\n // Skip non-relative imports\n !node.source?.value.startsWith('.')\n ) {\n return;\n }\n\n assertFilename(state.filename);\n\n // Skip folder imports\n const filename = path.resolve(\n path.dirname(state.filename),\n node.source.value\n );\n\n // Replace .ts extension with .js if file with extension is explicitly imported\n if (isFile(filename)) {\n node.source.value = node.source.value.replace(/\\.tsx?$/, `.${extension}`);\n return;\n }\n\n // Add extension if .ts file or file with extension exists\n if (isModule(filename, extension)) {\n node.source.value += `.${extension}`;\n return;\n }\n\n // Expand folder imports to index and add extension\n if (\n isDirectory(filename) &&\n isModule(path.join(filename, 'index'), extension)\n ) {\n node.source.value = node.source.value.replace(\n /\\/?$/,\n `/index.${extension}`\n );\n return;\n }\n }\n\n return {\n name: '@builder-bob/babel-plugin',\n visitor: {\n ImportDeclaration(path, state) {\n aliasImports(path, state);\n addExtension(path, state);\n },\n ExportNamedDeclaration(path, state) {\n aliasImports(path, state);\n addExtension(path, state);\n },\n ExportAllDeclaration(path, state) {\n aliasImports(path, state);\n addExtension(path, state);\n },\n },\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAwB,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAaxB,MAAMG,MAA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AE;QAChCD,YAAY,CAACW,IAAI,EAAEV,KAAK,CAAC;QACzBe,YAAY,CAACL,IAAI,EAAEV,KAAK,CAAC;MAC3B;IACF;EACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-builder-bob",
|
|
3
|
-
"version": "0.25.0-next.
|
|
3
|
+
"version": "0.25.0-next.3",
|
|
4
4
|
"description": "CLI to build JavaScript files for React Native libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"concurrently": "^7.2.2",
|
|
81
81
|
"jest": "^29.7.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "e2d7072fb03e6daa12a97bbab350e0f177ccc656"
|
|
84
84
|
}
|