Skip to content

Commit

Permalink
Remove absolute-path dependency
Browse files Browse the repository at this point in the history
Summary:
Replace `absolute-path` dependency in `metro` and `metro-resolver` with `path.isAbsolute`, which is [already load-bearing](https://cs.github.com/?q=repo%3Afacebook%2Fmetro+path.isAbsolute) in other source locations.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D43665373

fbshipit-source-id: f637c9b3f7cb0197425773d3c64dc34dcc493093
  • Loading branch information
huntie authored and facebook-github-bot committed Mar 1, 2023
1 parent eeb211f commit c0da607
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 13 deletions.
1 change: 0 additions & 1 deletion packages/metro-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
},
"dependencies": {
"absolute-path": "^0.0.0",
"invariant": "^2.2.4"
},
"license": "MIT",
Expand Down
7 changes: 3 additions & 4 deletions packages/metro-resolver/src/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
Result,
} from './types';

import isAbsolutePath from 'absolute-path';
import path from 'path';
import FailedToResolveNameError from './errors/FailedToResolveNameError';
import FailedToResolvePathError from './errors/FailedToResolvePathError';
Expand Down Expand Up @@ -51,7 +50,7 @@ function resolve(
);
}

if (isRelativeImport(moduleName) || isAbsolutePath(moduleName)) {
if (isRelativeImport(moduleName) || path.isAbsolute(moduleName)) {
return resolveModulePath(context, moduleName, platform);
}

Expand All @@ -65,7 +64,7 @@ function resolve(
const {originModulePath} = context;

const isDirectImport =
isRelativeImport(realModuleName) || isAbsolutePath(realModuleName);
isRelativeImport(realModuleName) || path.isAbsolute(realModuleName);

if (isDirectImport) {
// derive absolute path /.../node_modules/originModuleDir/realModuleName
Expand Down Expand Up @@ -149,7 +148,7 @@ function resolveModulePath(
toModuleName: string,
platform: string | null,
): Resolution {
const modulePath = isAbsolutePath(toModuleName)
const modulePath = path.isAbsolute(toModuleName)
? resolveWindowsPath(toModuleName)
: path.join(path.dirname(context.originModulePath), toModuleName);
const redirectedPath = context.redirectModulePath(modulePath);
Expand Down
1 change: 0 additions & 1 deletion packages/metro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@babel/template": "^7.0.0",
"@babel/traverse": "^7.20.0",
"@babel/types": "^7.20.0",
"absolute-path": "^0.0.0",
"accepts": "^1.3.7",
"async": "^3.2.2",
"chalk": "^4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/metro/src/node-haste/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import type ModuleCache from './ModuleCache';
import type Package from './Package';

const isAbsolutePath = require('absolute-path');
import path from 'path';

class Module {
path: string;
Expand All @@ -23,7 +23,7 @@ class Module {
_sourceCode: ?string;

constructor(file: string, moduleCache: ModuleCache) {
if (!isAbsolutePath(file)) {
if (!path.isAbsolute(file)) {
throw new Error('Expected file to be absolute path but got ' + file);
}

Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1373,11 +1373,6 @@ abort-controller@^3.0.0:
dependencies:
event-target-shim "^5.0.0"

absolute-path@^0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/absolute-path/-/absolute-path-0.0.0.tgz#a78762fbdadfb5297be99b15d35a785b2f095bf7"
integrity sha1-p4di+9rftSl76ZsV01p4Wy8JW/c=

accepts@^1.3.7:
version "1.3.7"
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd"
Expand Down

0 comments on commit c0da607

Please sign in to comment.