Socket
Socket
Sign inDemoInstall

metro

Package Overview
Dependencies
Maintainers
2
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metro - npm Package Compare versions

Comparing version 0.80.9 to 0.80.10

src/integration_tests/basic_bundle/excluded_from_file_map.js

36

package.json
{
"name": "metro",
"version": "0.80.9",
"version": "0.80.10",
"description": "🚇 The JavaScript bundler for React Native.",

@@ -30,4 +30,5 @@ "main": "src/index.js",

"error-stack-parser": "^2.0.6",
"flow-enums-runtime": "^0.0.6",
"graceful-fs": "^4.2.4",
"hermes-parser": "0.20.1",
"hermes-parser": "0.23.0",
"image-size": "^1.0.2",

@@ -38,18 +39,17 @@ "invariant": "^2.2.4",

"lodash.throttle": "^4.1.1",
"metro-babel-transformer": "0.80.9",
"metro-cache": "0.80.9",
"metro-cache-key": "0.80.9",
"metro-config": "0.80.9",
"metro-core": "0.80.9",
"metro-file-map": "0.80.9",
"metro-resolver": "0.80.9",
"metro-runtime": "0.80.9",
"metro-source-map": "0.80.9",
"metro-symbolicate": "0.80.9",
"metro-transform-plugins": "0.80.9",
"metro-transform-worker": "0.80.9",
"metro-babel-transformer": "0.80.10",
"metro-cache": "0.80.10",
"metro-cache-key": "0.80.10",
"metro-config": "0.80.10",
"metro-core": "0.80.10",
"metro-file-map": "0.80.10",
"metro-resolver": "0.80.10",
"metro-runtime": "0.80.10",
"metro-source-map": "0.80.10",
"metro-symbolicate": "0.80.10",
"metro-transform-plugins": "0.80.10",
"metro-transform-worker": "0.80.10",
"mime-types": "^2.1.27",
"node-fetch": "^2.2.0",
"nullthrows": "^1.1.1",
"rimraf": "^3.0.2",
"serialize-error": "^2.1.0",

@@ -59,3 +59,3 @@ "source-map": "^0.5.6",

"throat": "^5.0.0",
"ws": "^7.5.1",
"ws": "^7.5.10",
"yargs": "^17.6.2"

@@ -72,4 +72,4 @@ },

"jest-snapshot-serializer-raw": "^1.2.0",
"metro-babel-register": "0.80.9",
"metro-memory-fs": "0.80.9",
"metro-babel-register": "0.80.10",
"metro-memory-fs": "0.80.10",
"mock-req": "^0.2.0",

@@ -76,0 +76,0 @@ "mock-res": "^0.6.0",

@@ -7,6 +7,2 @@ "use strict";

exports.default = coerceKeyValueArray;
var _querystring = _interopRequireDefault(require("querystring"));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
function coerceKeyValueArray(keyValueArray) {

@@ -21,5 +17,8 @@ const result = Object.create(null);

}
Object.assign(result, _querystring.default.parse(item));
const params = new URLSearchParams(item);
params.forEach((value, key) => {
result[key] = value;
});
}
return result;
}

@@ -38,2 +38,3 @@ "use strict";

sourceUrl: options.sourceUrl,
getSourceUrl: options.getSourceUrl,
}),

@@ -40,0 +41,0 @@ processModulesOptions

@@ -24,2 +24,3 @@ "use strict";

shouldAddToIgnoreList: options.shouldAddToIgnoreList,
getSourceUrl: options.getSourceUrl,
}),

@@ -26,0 +27,0 @@ name: path.basename(module.path),

@@ -8,3 +8,3 @@ "use strict";

isIgnored: options.shouldAddToIgnoreList(module),
path: module.path,
path: options?.getSourceUrl?.(module) ?? module.path,
source: options.excludeSource ? "" : getModuleSource(module),

@@ -11,0 +11,0 @@ };

@@ -22,2 +22,3 @@ "use strict";

shouldAddToIgnoreList: options.shouldAddToIgnoreList,
getSourceUrl: options.getSourceUrl,
});

@@ -24,0 +25,0 @@ sourceMapInfos.push(info);

"use strict";
const { sourceMapGenerator } = require("./sourceMapGenerator");
const {
sourceMapGenerator,
sourceMapGeneratorNonBlocking,
} = require("./sourceMapGenerator");
function sourceMapString(modules, options) {

@@ -9,2 +12,11 @@ return sourceMapGenerator(modules, options).toString(undefined, {

}
module.exports = sourceMapString;
async function sourceMapStringNonBlocking(modules, options) {
const generator = await sourceMapGeneratorNonBlocking(modules, options);
return generator.toString(undefined, {
excludeSource: options.excludeSource,
});
}
module.exports = {
sourceMapString,
sourceMapStringNonBlocking,
};

@@ -67,3 +67,3 @@ "use strict";

this._baseHash,
localPath,
path.sep === "/" ? localPath : localPath.replaceAll(path.sep, "/"),
customTransformOptions,

@@ -70,0 +70,0 @@ dev,

@@ -170,2 +170,9 @@ "use strict";

httpServer.listen(config.server.port, host, () => {
const { address, port, family } = httpServer.address();
config.reporter.update({
type: "server_listening",
address,
port,
family,
});
if (onReady) {

@@ -172,0 +179,0 @@ onReady(httpServer);

@@ -6,3 +6,7 @@ "use strict";

});
exports.asyncImportESM = exports.asyncImportCJS = void 0;
exports.asyncImportMaybeSyncESM =
exports.asyncImportMaybeSyncCJS =
exports.asyncImportESM =
exports.asyncImportCJS =
void 0;
Object.defineProperty(exports, "default", {

@@ -86,1 +90,5 @@ enumerable: true,

exports.asyncImportESM = asyncImportESM;
const asyncImportMaybeSyncCJS = require.unstable_importMaybeSync("./export-7");
exports.asyncImportMaybeSyncCJS = asyncImportMaybeSyncCJS;
const asyncImportMaybeSyncESM = require.unstable_importMaybeSync("./export-8");
exports.asyncImportMaybeSyncESM = asyncImportMaybeSyncESM;

@@ -17,2 +17,3 @@ "use strict";

resolver: {
blockList: [/excluded_from_file_map\.js$/],
useWatchman: false,

@@ -19,0 +20,0 @@ },

@@ -65,3 +65,6 @@ "use strict";

}
getQueueLength() {
return this._queue.length;
}
}
module.exports = BatchProcessor;

@@ -8,3 +8,5 @@ "use strict";

const getInlineSourceMappingURL = require("../DeltaBundler/Serializers/helpers/getInlineSourceMappingURL");
const sourceMapString = require("../DeltaBundler/Serializers/sourceMapString");
const {
sourceMapString,
} = require("../DeltaBundler/Serializers/sourceMapString");
const countLines = require("./countLines");

@@ -47,2 +49,3 @@ const nullthrows = require("nullthrows");

shouldAddToIgnoreList: options.shouldAddToIgnoreList,
getSourceUrl: options.getSourceUrl,
})

@@ -49,0 +52,0 @@ )

@@ -8,6 +8,8 @@ "use strict";

update(event) {
if (Object.prototype.toString.call(event.error) === "[object Error]") {
if (event.error instanceof Error) {
const { message, stack } = event.error;
event = Object.assign(event, {
message: event.error.message,
stack: event.error.stack,
error: serializeError(event.error),
message,
stack,
});

@@ -18,2 +20,27 @@ }

}
function serializeError(e, seen = new Set()) {
if (seen.has(e)) {
return {
message: "[circular]: " + e.message,
stack: e.stack,
};
}
seen.add(e);
const { message, stack, cause } = e;
const serialized = {
message,
stack,
};
if (e instanceof AggregateError) {
serialized.errors = [...e.errors]
.map((innerError) =>
innerError instanceof Error ? serializeError(innerError, seen) : null
)
.filter(Boolean);
}
if (cause instanceof Error) {
serialized.cause = serializeError(cause, seen);
}
return serialized;
}
module.exports = JsonReporter;
"use strict";
var _types = require("../shared/types.flow");
const parsePlatformFilePath = require("../node-haste/lib/parsePlatformFilePath");

@@ -53,2 +54,5 @@ const parseCustomResolverOptions = require("./parseCustomResolverOptions");

}),
sourcePaths:
_types.SourcePathsMode.cast(query.sourcePaths) ??
_types.SourcePathsMode.Absolute,
sourceUrl: jscSafeUrl.toJscSafeUrl(normalizedRequestUrl),

@@ -55,0 +59,0 @@ unstable_transformProfile: getTransformProfile(

@@ -100,2 +100,8 @@ /**

| {
type: 'server_listening';
port: number;
address: string;
family: string;
}
| {
type: 'transformer_load_started';

@@ -102,0 +108,0 @@ }

@@ -26,2 +26,3 @@ "use strict";

sourceUrl: options.sourceUrl,
sourcePaths: options.sourcePaths,
},

@@ -28,0 +29,0 @@ graphOptions: {

@@ -260,2 +260,5 @@ "use strict";

break;
case "unstable_set_interaction_status":
this._interactionStatus = event.status;
break;
}

@@ -268,2 +271,3 @@ }

)
.concat([this._interactionStatus])
.filter((str) => str != null)

@@ -270,0 +274,0 @@ .join("\n");

@@ -71,2 +71,17 @@ "use strict";

if (
callee.type === "MemberExpression" &&
callee.object.type === "Identifier" &&
callee.object.name === "require" &&
callee.property.type === "Identifier" &&
callee.property.name === "unstable_importMaybeSync" &&
!callee.computed &&
!path.scope.getBinding("require")
) {
processImportCall(path, state, {
asyncType: "maybeSync",
});
visited.add(path.node);
return;
}
if (
name != null &&

@@ -265,6 +280,17 @@ state.dependencyCalls.has(name) &&

const transformer = state.dependencyTransformer;
if (options.asyncType === "async") {
transformer.transformImportCall(path, dep, state);
} else {
transformer.transformPrefetch(path, dep, state);
switch (options.asyncType) {
case "async":
transformer.transformImportCall(path, dep, state);
break;
case "maybeSync":
transformer.transformImportMaybeSyncCall(path, dep, state);
break;
case "prefetch":
transformer.transformPrefetch(path, dep, state);
break;
case "weak":
throw new Error("Unreachable");
default:
options.asyncType;
throw new Error("Unreachable");
}

@@ -385,2 +411,8 @@ }

`);
const makeAsyncImportMaybeSyncTemplate = template.expression(`
require(ASYNC_REQUIRE_MODULE_PATH).unstable_importMaybeSync(MODULE_ID, DEPENDENCY_MAP.paths)
`);
const makeAsyncImportMaybeSyncTemplateWithName = template.expression(`
require(ASYNC_REQUIRE_MODULE_PATH).unstable_importMaybeSync(MODULE_ID, DEPENDENCY_MAP.paths, MODULE_NAME)
`);
const makeResolveWeakTemplate = template.expression(`

@@ -415,2 +447,20 @@ MODULE_ID

},
transformImportMaybeSyncCall(path, dependency, state) {
const makeNode = state.keepRequireNames
? makeAsyncImportMaybeSyncTemplateWithName
: makeAsyncImportMaybeSyncTemplate;
const opts = {
ASYNC_REQUIRE_MODULE_PATH: nullthrows(
state.asyncRequireModulePathStringLiteral
),
MODULE_ID: createModuleIDExpression(dependency, state),
DEPENDENCY_MAP: nullthrows(state.dependencyMapIdentifier),
...(state.keepRequireNames
? {
MODULE_NAME: createModuleNameLiteral(dependency),
}
: null),
};
path.replaceWith(makeNode(opts));
},
transformPrefetch(path, dependency, state) {

@@ -417,0 +467,0 @@ const makeNode = state.keepRequireNames

@@ -83,4 +83,4 @@ "use strict";

}
_getClosestPackage(filePath) {
const parsedPath = path.parse(filePath);
_getClosestPackage(absoluteModulePath) {
const parsedPath = path.parse(absoluteModulePath);
const root = parsedPath.root;

@@ -94,3 +94,6 @@ let dir = path.join(parsedPath.dir, parsedPath.base);

if (this._fileSystem.exists(candidate)) {
return candidate;
return {
packageJsonPath: candidate,
packageRelativePath: path.relative(dir, absoluteModulePath),
};
}

@@ -168,3 +171,4 @@ dir = path.dirname(dir);

return new ModuleCache({
getClosestPackage: (filePath) => this._getClosestPackage(filePath),
getClosestPackage: (absoluteModulePath) =>
this._getClosestPackage(absoluteModulePath),
});

@@ -171,0 +175,0 @@ }

@@ -17,3 +17,3 @@ "use strict";

getPackage: () =>
moduleCache.getPackageOf(this._projectRootFakeModule.path),
moduleCache.getPackageOf(this._projectRootFakeModule.path)?.pkg,
isHaste() {

@@ -101,4 +101,4 @@ throw new Error("not implemented");

getPackage: this._getPackage,
getPackageForModule: (modulePath) =>
this._getPackageForModule(fromModule, modulePath),
getPackageForModule: (absoluteModulePath) =>
this._getPackageForModule(absoluteModulePath),
},

@@ -164,11 +164,12 @@ dependency

};
_getPackageForModule = (fromModule, modulePath) => {
let pkg;
_getPackageForModule = (absolutePath) => {
let result;
try {
pkg = this._options.moduleCache.getPackageOf(modulePath);
result = this._options.moduleCache.getPackageOf(absolutePath);
} catch (e) {}
return pkg != null
return result != null
? {
rootPath: path.dirname(pkg.path),
packageJson: pkg.read(),
rootPath: path.dirname(result.pkg.path),
packageJson: result.pkg.read(),
packageRelativePath: result.packageRelativePath,
}

@@ -175,0 +176,0 @@ : null;

@@ -16,3 +16,3 @@ "use strict";

getPackage() {
return this._moduleCache.getPackageForModule(this);
return this._moduleCache.getPackageForModule(this)?.pkg;
}

@@ -19,0 +19,0 @@ invalidate() {}

@@ -10,3 +10,3 @@ "use strict";

this._packageCache = Object.create(null);
this._packagePathByModulePath = Object.create(null);
this._packagePathAndSubpathByModulePath = Object.create(null);
this._modulePathsByPackagePath = Object.create(null);

@@ -31,17 +31,29 @@ }

}
getPackageOf(modulePath) {
let packagePath = this._packagePathByModulePath[modulePath];
if (packagePath && this._packageCache[packagePath]) {
return this._packageCache[packagePath];
getPackageOf(absoluteModulePath) {
let packagePathAndSubpath =
this._packagePathAndSubpathByModulePath[absoluteModulePath];
if (
packagePathAndSubpath &&
this._packageCache[packagePathAndSubpath.packageJsonPath]
) {
return {
pkg: this._packageCache[packagePathAndSubpath.packageJsonPath],
packageRelativePath: packagePathAndSubpath.packageRelativePath,
};
}
packagePath = this._getClosestPackage(modulePath);
if (!packagePath) {
packagePathAndSubpath = this._getClosestPackage(absoluteModulePath);
if (!packagePathAndSubpath) {
return null;
}
this._packagePathByModulePath[modulePath] = packagePath;
const packagePath = packagePathAndSubpath.packageJsonPath;
this._packagePathAndSubpathByModulePath[absoluteModulePath] =
packagePathAndSubpath;
const modulePaths =
this._modulePathsByPackagePath[packagePath] ?? new Set();
modulePaths.add(modulePath);
modulePaths.add(absoluteModulePath);
this._modulePathsByPackagePath[packagePath] = modulePaths;
return this.getPackage(packagePath);
return {
pkg: this.getPackage(packagePath),
packageRelativePath: packagePathAndSubpath.packageRelativePath,
};
}

@@ -57,5 +69,7 @@ invalidate(filePath) {

}
if (this._packagePathByModulePath[filePath]) {
const packagePath = this._packagePathByModulePath[filePath];
delete this._packagePathByModulePath[filePath];
const packagePathAndSubpath =
this._packagePathAndSubpathByModulePath[filePath];
if (packagePathAndSubpath) {
const packagePath = packagePathAndSubpath.packageJsonPath;
delete this._packagePathAndSubpathByModulePath[filePath];
const modulePaths = this._modulePathsByPackagePath[packagePath];

@@ -72,3 +86,3 @@ if (modulePaths) {

for (const modulePath of modulePaths) {
delete this._packagePathByModulePath[modulePath];
delete this._packagePathAndSubpathByModulePath[modulePath];
}

@@ -75,0 +89,0 @@ modulePaths.clear();

"use strict";
var _types = require("./shared/types.flow");
const { getAsset } = require("./Assets");

@@ -11,3 +12,5 @@ const baseJSBundle = require("./DeltaBundler/Serializers/baseJSBundle");

const getRamBundleInfo = require("./DeltaBundler/Serializers/getRamBundleInfo");
const sourceMapString = require("./DeltaBundler/Serializers/sourceMapString");
const {
sourceMapStringNonBlocking,
} = require("./DeltaBundler/Serializers/sourceMapString");
const IncrementalBundler = require("./IncrementalBundler");

@@ -64,2 +67,18 @@ const ResourceNotFoundError = require("./IncrementalBundler/ResourceNotFoundError");

this._platforms = new Set(this._config.resolver.platforms);
this._allowedSuffixesForSourceRequests = [
...new Set(
[
...this._config.resolver.sourceExts,
...this._config.watcher.additionalExts,
...this._config.resolver.assetExts,
].map((ext) => "." + ext)
),
];
this._sourceRequestRoutingMap = [
["/[metro-project]/", path.resolve(this._config.projectRoot)],
...this._config.watchFolders.map((watchFolder, index) => [
`/[metro-watchFolders]/${index}/`,
path.resolve(watchFolder),
]),
];
this._isEnded = false;

@@ -133,2 +152,4 @@ this._createModuleId = config.serializer.createModuleIdFactory();

this._shouldAddModuleToIgnoreList(module),
getSourceUrl: (module) =>
this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
};

@@ -156,3 +177,3 @@ let bundleCode = null;

if (!bundleMap) {
bundleMap = sourceMapString(
bundleMap = await sourceMapStringNonBlocking(
[...prepend, ...this._getSortedModules(graph)],

@@ -163,2 +184,4 @@ {

shouldAddToIgnoreList: bundleOptions.shouldAddToIgnoreList,
getSourceUrl: (module) =>
this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
}

@@ -223,2 +246,4 @@ );

this._shouldAddModuleToIgnoreList(module),
getSourceUrl: (module) =>
this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
});

@@ -351,3 +376,3 @@ }

req.url = this._rewriteAndNormalizeUrl(req.url);
const urlObj = url.parse(req.url, true);
const urlObj = url.parse(decodeURI(req.url), true);
const { host } = req.headers;

@@ -403,5 +428,54 @@ debug(

} else {
next();
let handled = false;
for (const [pathnamePrefix, normalizedRootDir] of this
._sourceRequestRoutingMap) {
if (pathname.startsWith(pathnamePrefix)) {
const relativePathname = pathname.substr(pathnamePrefix.length);
await this._processSourceRequest(
relativePathname,
normalizedRootDir,
res
);
handled = true;
break;
}
}
if (!handled) {
next();
}
}
}
async _processSourceRequest(relativePathname, rootDir, res) {
if (
!this._allowedSuffixesForSourceRequests.some((suffix) =>
relativePathname.endsWith(suffix)
)
) {
res.writeHead(404);
res.end();
return;
}
const depGraph = await this._bundler.getBundler().getDependencyGraph();
const filePath = path.join(rootDir, relativePathname);
try {
depGraph.getSha1(filePath);
} catch {
res.writeHead(404);
res.end();
return;
}
const mimeType = mime.lookup(path.basename(relativePathname));
res.setHeader("Content-Type", mimeType);
const stream = fs.createReadStream(filePath);
stream.pipe(res);
stream.on("error", (error) => {
if (error.code === "ENOENT") {
res.writeHead(404);
res.end();
} else {
res.writeHead(500);
res.end();
}
});
}
_createRequestProcessor({

@@ -684,2 +758,4 @@ createStartEntry,

this._shouldAddModuleToIgnoreList(module),
getSourceUrl: (module) =>
this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
}

@@ -807,8 +883,13 @@ );

}
return sourceMapString([...prepend, ...this._getSortedModules(graph)], {
excludeSource: serializerOptions.excludeSource,
processModuleFilter: this._config.serializer.processModuleFilter,
shouldAddToIgnoreList: (module) =>
this._shouldAddModuleToIgnoreList(module),
});
return await sourceMapStringNonBlocking(
[...prepend, ...this._getSortedModules(graph)],
{
excludeSource: serializerOptions.excludeSource,
processModuleFilter: this._config.serializer.processModuleFilter,
shouldAddToIgnoreList: (module) =>
this._shouldAddModuleToIgnoreList(module),
getSourceUrl: (module) =>
this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
}
);
},

@@ -1070,2 +1151,3 @@ finish({ mres, result }) {

sourceUrl: null,
sourcePaths: _types.SourcePathsMode.Absolute,
};

@@ -1088,2 +1170,23 @@ _getServerRootDir() {

}
_getModuleSourceUrl(module, mode) {
switch (mode) {
case _types.SourcePathsMode.ServerUrl:
for (const [pathnamePrefix, normalizedRootDir] of this
._sourceRequestRoutingMap) {
if (module.path.startsWith(normalizedRootDir + path.sep)) {
const relativePath = module.path.slice(
normalizedRootDir.length + 1
);
const relativePathPosix = relativePath.split(path.sep).join("/");
return pathnamePrefix + encodeURI(relativePathPosix);
}
}
const modulePathPosix = module.path.split(path.sep).join("/");
return modulePathPosix.startsWith("/")
? encodeURI(modulePathPosix)
: "/" + encodeURI(modulePathPosix);
case _types.SourcePathsMode.Absolute:
return module.path;
}
}
}

@@ -1090,0 +1193,0 @@ function* zip(xs, ys) {

@@ -27,3 +27,3 @@ "use strict";

writeFns.push(async () => {
log("Writing bundle output to:", bundleOutput);
log(`Writing bundle output to: ${bundleOutput}`);
await writeFile(bundleOutput, bundle.code, encoding);

@@ -40,3 +40,3 @@ log("Done writing bundle output");

writeFns.push(async () => {
log("Writing sourcemap output to:", sourcemapOutput);
log(`Writing sourcemap output to: ${sourcemapOutput}`);
await writeFile(sourcemapOutput, map, null);

@@ -43,0 +43,0 @@ log("Done writing sourcemap output");

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.SourcePathsMode = void 0;
const SourcePathsMode = require("flow-enums-runtime")({
Absolute: "absolute",
ServerUrl: "url-server",
});
exports.SourcePathsMode = SourcePathsMode;

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc