@expo/metro-config
Advanced tools
Comparing version 0.19.0-canary-20241008-90b13ad to 1.0.0-canary-20241018-4f8243a
@@ -120,2 +120,3 @@ "use strict"; | ||
// the function returns here. Discovered when typing `BabelNode`. | ||
// @ts-expect-error: see https://github.com/facebook/react-native/blob/401991c3f073bf734ee04f9220751c227d2abd31/packages/react-native-babel-transformer/src/index.js#L220-L224 | ||
return { ast: null }; | ||
@@ -122,0 +123,0 @@ } |
@@ -273,4 +273,4 @@ "use strict"; | ||
// Custom: These are passed to `getCacheKey` and ensure invalidation when the version changes. | ||
unstable_renameRequire: false, | ||
// @ts-expect-error: not on type. | ||
unstable_renameRequire: false, | ||
postcssHash: (0, postcss_1.getPostcssConfigHash)(projectRoot), | ||
@@ -294,2 +294,3 @@ browserslistHash: pkg.browserslist | ||
assetPlugins: getAssetPlugins(projectRoot), | ||
hermesParser: true, | ||
getTransformOptions: async () => ({ | ||
@@ -296,0 +297,0 @@ transform: { |
@@ -8,3 +8,2 @@ "use strict"; | ||
const paths_1 = require("@expo/config/paths"); | ||
const assert_1 = __importDefault(require("assert")); | ||
const fs_1 = __importDefault(require("fs")); | ||
@@ -51,9 +50,2 @@ const glob_1 = require("glob"); | ||
exports.globAllPackageJsonPaths = globAllPackageJsonPaths; | ||
function getWorkspacePackagesArray({ workspaces }) { | ||
if (Array.isArray(workspaces)) { | ||
return workspaces; | ||
} | ||
(0, assert_1.default)(workspaces?.packages, 'Could not find a `workspaces` object in the root package.json'); | ||
return workspaces.packages; | ||
} | ||
/** | ||
@@ -65,9 +57,8 @@ * @param workspaceProjectRoot root file path for a yarn workspace. | ||
try { | ||
const rootPackageJsonFilePath = path_1.default.join(workspaceProjectRoot, 'package.json'); | ||
// Could throw if package.json is invalid. | ||
const rootPackageJson = readJsonFile(rootPackageJsonFilePath); | ||
// Extract the "packages" array or use "workspaces" as packages array (yarn workspaces spec). | ||
const packages = getWorkspacePackagesArray(rootPackageJson); | ||
const workspaceGlobs = (0, paths_1.getMetroWorkspaceGlobs)(workspaceProjectRoot); | ||
if (!workspaceGlobs?.length) | ||
return []; | ||
// Glob all package.json files and return valid paths. | ||
return globAllPackageJsonPaths(workspaceProjectRoot, packages); | ||
return globAllPackageJsonPaths(workspaceProjectRoot, workspaceGlobs); | ||
} | ||
@@ -91,3 +82,3 @@ catch { | ||
const packages = resolveAllWorkspacePackageJsonPaths(workspaceRoot); | ||
if (!packages.length) { | ||
if (!packages?.length) { | ||
return []; | ||
@@ -94,0 +85,0 @@ } |
@@ -111,3 +111,2 @@ "use strict"; | ||
code, | ||
// @ts-expect-error: typed incorrectly upstream | ||
lineCount: 1, | ||
@@ -114,0 +113,0 @@ map: [], |
@@ -19,3 +19,3 @@ /** | ||
serverRoot: string; | ||
sourceUrl: string | undefined; | ||
sourceUrl?: string | null; | ||
splitChunks: boolean; | ||
@@ -22,0 +22,0 @@ skipWrapping: boolean; |
@@ -17,3 +17,3 @@ /** | ||
serverRoot: string; | ||
sourceUrl: string | undefined; | ||
sourceUrl?: string | null; | ||
skipWrapping: boolean; | ||
@@ -20,0 +20,0 @@ computedAsyncModulePaths: Record<string, string> | null; |
@@ -26,2 +26,3 @@ /** | ||
readonly reconcile?: ReconcileTransformSettings; | ||
readonly reactServerReference?: string; | ||
readonly reactClientReference?: string; | ||
@@ -66,3 +67,3 @@ readonly expoDomComponentReference?: string; | ||
collectDependenciesOptions: CollectDependenciesOptions; | ||
unstable_dependencyMapReservedName?: string; | ||
unstable_dependencyMapReservedName?: string | null; | ||
optimizationSizeLimit?: number; | ||
@@ -69,0 +70,0 @@ unstable_disableNormalizePseudoGlobals?: boolean; |
@@ -155,5 +155,3 @@ "use strict"; | ||
sortDependencies(dependencies, value.dependencies); | ||
const { ast: wrappedAst } = JsFileWrapping_1.default.wrapModule(ast, reconcile.importDefault, reconcile.importAll, dependencyMapName, reconcile.globalPrefix, | ||
// @ts-expect-error: not on type yet... | ||
reconcile.unstable_renameRequire === false); | ||
const { ast: wrappedAst } = JsFileWrapping_1.default.wrapModule(ast, reconcile.importDefault, reconcile.importAll, dependencyMapName, reconcile.globalPrefix, reconcile.unstable_renameRequire === false); | ||
const reserved = []; | ||
@@ -160,0 +158,0 @@ if (reconcile.unstable_dependencyMapReservedName != null) { |
@@ -189,4 +189,4 @@ "use strict"; | ||
runBeforeMainModule: serializerConfig?.getModulesRunBeforeMainModule?.(path_1.default.relative(this.options.projectRoot, entryFile)) ?? [], | ||
runModule: !this.isVendor && !this.isAsync, | ||
modulesOnly: this.preModules.size === 0, | ||
runModule: this.options.runModule && !this.isVendor && !this.isAsync, | ||
modulesOnly: this.options.modulesOnly || this.preModules.size === 0, | ||
platform: this.getPlatform(), | ||
@@ -335,2 +335,15 @@ baseUrl: (0, baseJSBundle_1.getBaseUrlOption)(this.graph, this.options), | ||
].filter((value) => typeof value === 'string'), | ||
reactServerReferences: [ | ||
...new Set([...this.deps] | ||
.map((module) => { | ||
return module.output.map((output) => { | ||
if ('reactServerReference' in output.data && | ||
typeof output.data.reactServerReference === 'string') { | ||
return output.data.reactServerReference; | ||
} | ||
return undefined; | ||
}); | ||
}) | ||
.flat()), | ||
].filter((value) => typeof value === 'string'), | ||
}, | ||
@@ -337,0 +350,0 @@ source: jsCode.code, |
@@ -11,2 +11,3 @@ export type SerialAsset = { | ||
paths?: Record<string, Record<string, string>>; | ||
reactServerReferences?: string[]; | ||
reactClientReferences?: string[]; | ||
@@ -13,0 +14,0 @@ expoDomComponentReferences?: string[]; |
@@ -48,2 +48,6 @@ "use strict"; | ||
const buildClientReferenceRequire = template_1.default.statement(`module.exports = require('react-server-dom-webpack/server').createClientModuleProxy(FILE_PATH);`); | ||
const buildStringRef = template_1.default.statement(`module.exports = FILE_PATH;`); | ||
const buildStaticObjectRef = template_1.default.statement( | ||
// Matches the `ImageSource` type from React Native: https://reactnative.dev/docs/image#source | ||
`module.exports = { uri: FILE_PATH, width: WIDTH, height: HEIGHT };`); | ||
async function transform({ filename, options, }, assetRegistryPath, assetDataPlugins) { | ||
@@ -57,5 +61,11 @@ options ??= options || { | ||
const isExport = options.publicPath.includes('?export_path='); | ||
const isReactServer = options.customTransformOptions?.environment === 'react-server'; | ||
const isServerEnv = isReactServer || options.customTransformOptions?.environment === 'node'; | ||
const absolutePath = node_path_1.default.resolve(options.projectRoot, filename); | ||
if (options.customTransformOptions?.environment === 'react-server') { | ||
const clientReference = node_url_1.default.pathToFileURL(absolutePath).href; | ||
const getClientReference = () => isReactServer ? node_url_1.default.pathToFileURL(absolutePath).href : undefined; | ||
if (options.platform !== 'web' && | ||
// NOTE(EvanBacon): There may be value in simply evaluating assets on the server. | ||
// Here, we're passing the info back to the client so the multi-resolution asset can be evaluated and downloaded. | ||
isReactServer) { | ||
const clientReference = getClientReference(); | ||
return { | ||
@@ -78,4 +88,38 @@ ast: { | ||
: options.publicPath); | ||
if (isServerEnv || options.platform === 'web') { | ||
const type = !data.type ? '' : `.${data.type}`; | ||
const assetPath = !isExport | ||
? data.httpServerLocation + '/' + data.name + type | ||
: data.httpServerLocation.replace(/\.\.\//g, '_') + '/' + data.name + type; | ||
// If size data is known then it should be passed back to ensure the correct dimensions are used. | ||
if (data.width != null || data.height != null) { | ||
return { | ||
ast: { | ||
...t.file(t.program([ | ||
buildStaticObjectRef({ | ||
FILE_PATH: JSON.stringify(assetPath), | ||
WIDTH: data.width != null ? t.numericLiteral(data.width) : t.buildUndefinedNode(), | ||
HEIGHT: data.height != null ? t.numericLiteral(data.height) : t.buildUndefinedNode(), | ||
}), | ||
])), | ||
errors: [], | ||
}, | ||
reactClientReference: getClientReference(), | ||
}; | ||
} | ||
// Use single string references outside of client-side React Native. | ||
// module.exports = "/foo/bar.png"; | ||
return { | ||
ast: { | ||
...t.file(t.program([buildStringRef({ FILE_PATH: JSON.stringify(assetPath) })])), | ||
errors: [], | ||
}, | ||
reactClientReference: getClientReference(), | ||
}; | ||
} | ||
return { | ||
ast: (0, util_1.generateAssetCodeFileAst)(assetRegistryPath, data), | ||
ast: { | ||
...(0, util_1.generateAssetCodeFileAst)(assetRegistryPath, data), | ||
errors: [], | ||
}, | ||
}; | ||
@@ -82,0 +126,0 @@ } |
@@ -255,3 +255,2 @@ "use strict"; | ||
applyUseStrictDirective(ast); | ||
// @ts-expect-error: Not on types yet (Metro 0.80). | ||
const unstable_renameRequire = config.unstable_renameRequire; | ||
@@ -324,3 +323,2 @@ // Disable all Metro single-file optimizations when full-graph optimization will be used. | ||
// future. | ||
// @ts-expect-error: Not on types yet (Metro 0.80.9). | ||
unstable_renameRequire === false)); | ||
@@ -391,2 +389,3 @@ } | ||
hasCjsExports: file.hasCjsExports, | ||
reactServerReference: file.reactServerReference, | ||
reactClientReference: file.reactClientReference, | ||
@@ -455,2 +454,3 @@ expoDomComponentReference: file.expoDomComponentReference, | ||
hasCjsExports: transformResult.metadata?.hasCjsExports, | ||
reactServerReference: transformResult.metadata?.reactServerReference, | ||
reactClientReference: transformResult.metadata?.reactClientReference, | ||
@@ -457,0 +457,0 @@ expoDomComponentReference: transformResult.metadata?.expoDomComponentReference, |
{ | ||
"name": "@expo/metro-config", | ||
"version": "0.19.0-canary-20241008-90b13ad", | ||
"version": "1.0.0-canary-20241018-4f8243a", | ||
"description": "A Metro config for running React Native projects with the Metro bundler", | ||
@@ -41,5 +41,5 @@ "main": "build/ExpoMetroConfig.js", | ||
"@babel/types": "^7.20.0", | ||
"@expo/config": "10.0.0-canary-20241008-90b13ad", | ||
"@expo/env": "0.3.1-canary-20241008-90b13ad", | ||
"@expo/json-file": "8.4.0-canary-20241008-90b13ad", | ||
"@expo/config": "10.0.0-canary-20241018-4f8243a", | ||
"@expo/env": "0.3.1-canary-20241018-4f8243a", | ||
"@expo/json-file": "8.4.0-canary-20241018-4f8243a", | ||
"@expo/spawn-async": "^1.7.2", | ||
@@ -60,3 +60,3 @@ "chalk": "^4.1.0", | ||
"dedent": "^1.5.3", | ||
"expo-module-scripts": "3.6.0-canary-20241008-90b13ad", | ||
"expo-module-scripts": "3.6.0-canary-20241018-4f8243a", | ||
"sass": "^1.60.0" | ||
@@ -67,3 +67,3 @@ }, | ||
}, | ||
"gitHead": "90b13ad9d0dd3469556ac776d8b74643375b1d97" | ||
"gitHead": "4f8243a009855c0cb389307401fb6b1fc9ce03b9" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
457814
6467
+ Added@expo/config@10.0.0-canary-20241018-4f8243a(transitive)
+ Added@expo/config-plugins@8.1.0-canary-20241018-4f8243a(transitive)
+ Added@expo/config-types@52.0.0-canary-20241018-4f8243a(transitive)
+ Added@expo/env@0.3.1-canary-20241018-4f8243a(transitive)
+ Added@expo/json-file@8.4.0-canary-20241018-4f8243a(transitive)
+ Added@expo/plist@0.1.4-canary-20241018-4f8243a(transitive)
+ Addedresolve-workspace-root@2.0.0(transitive)
- Removed@expo/config@10.0.0-canary-20241008-90b13ad(transitive)
- Removed@expo/config-plugins@8.1.0-canary-20241008-90b13ad(transitive)
- Removed@expo/config-types@52.0.0-canary-20241008-90b13ad(transitive)
- Removed@expo/env@0.3.1-canary-20241008-90b13ad(transitive)
- Removed@expo/json-file@8.4.0-canary-20241008-90b13ad(transitive)
- Removed@expo/plist@0.1.4-canary-20241008-90b13ad(transitive)
- Removedresolve-workspace-root@1.0.1(transitive)