react-native start 运行流程

时间:2022-02-08 16:37:59

在CMD下键入

C:\Node_JS\MyAwesomeProject>react-native start

运行流程:

C:\Users\Grart\AppData\Roaming\npm\react-native.cmd

C:\Users\Grart\AppData\Roaming\npm\node_modules\react-native-cli\index.js

cli.run();

C:\Node_JS\MyAwesomeProject\node_modules\react-native\cli.js

module.exports = require('./local-cli/cli.js');

C:\Node_JS\MyAwesomeProject\node_modules\react-native\local-cli\cli.js

module.exports = {

run: run,

init: init,

};

react-native start 运行流程

C:\Node_JS\MyAwesomeProject\node_modules\react-native\private-cli\src\server\server.js

C:\Node_JS\MyAwesomeProject\node_modules\react-native\private-cli\src\server\runServer.js

function getAppMiddleware(args, config) {

………………………...

return ReactPackager.middleware({

nonPersistent: args.nonPersistent,

projectRoots: args.projectRoots,

blacklistRE: config.getBlacklistRE(),

cacheVersion: '3',

transformModulePath: transformerPath,

assetRoots: args.assetRoots,

assetExts: ['png', 'jpeg', 'jpg'],

resetCache: args.resetCache || args['reset-cache'],

polyfillModuleNames: [

require.resolve(

'../../../Libraries/JavaScriptAppEngine/polyfills/document.js'

),

],

verbose: args.verbose,

});

}

C:\Node_JS\MyAwesomeProject\node_modules\react-native\packager\react-packager\index.js

function createServer(options) {

// the debug module is configured globally, we need to enable debugging

// *before* requiring any packages that use `debug` for logging

if (options.verbose) {

enableDebug();

}

startSocketInterface();

var Server = require('./src/Server');

return new Server(omit(options, ['verbose']));

}

C:\Node_JS\MyAwesomeProject\node_modules\react-native\packager\react-packager\src\Server\index.js

function processRequest(req, res, next) {

…………

const building = this._bundles[optionsJson] || this.buildBundle(options);

this._bundles[optionsJson] = building;

building.then(……

)

…………

}

C:\Node_JS\MyAwesomeProject\node_modules\react-native\packager\react-packager\src\Bundler\index.js

function bundle(main, runModule, sourceMapUrl, isDev, platform) {

const bundle = new Bundle(sourceMapUrl);

const findEventId = Activity.startEvent('find dependencies');

let transformEventId;

return this.getDependencies(main, isDev, platform)

.then(………………

.………………..

}

function getDependencies(main, isDev, platform) {

return this._resolver.getDependencies(main, { dev: isDev, platform });

}

C:\Node_JS\MyAwesomeProject\node_modules\react-native\packager\react-packager\src\DependencyResolver\index.js

HasteDependencyResolver.prototype.getDependencies = function(main, options) {

var opts = getDependenciesValidateOpts(options);

return this._depGraph.getDependencies(main, opts.platform)

.then(

resolutionResponse => {

this._getPolyfillDependencies(opts.dev).reverse().forEach(

polyfill => resolutionResponse.prependDependency(polyfill)

);

return resolutionResponse.finalize();

}

);

};

C:\Node_JS\MyAwesomeProject\node_modules\react-native\packager\react-packager\src\DependencyResolver\DependencyGraph\index

getDependencies(entryPath, platform) {

console.log('call DependencyGraph entryPath='+entryPath);

return this.load()

.then(

() => {

platform = this._getRequestPlatform(entryPath, platform);

const absPath = this._getAbsolutePath(entryPath);

const req = new ResolutionRequest({

platform,

entryPath: absPath,

deprecatedAssetMap: this._deprecatedAssetMap,

hasteMap: this._hasteMap,

helpers: this._helpers,

moduleCache: this._moduleCache,

fastfs: this._fastfs,

});

const response = new ResolutionResponse();

console.log('call ResolutionRequest');

return Promise.all([

req.getOrderedDependencies(response),

req.getAsyncDependencies(response),

]).then(() => response);

}

);

}

C:\Node_JS\MyAwesomeProject\node_modules\react-native\packager\react-packager\src\DependencyResolver\DependencyGraph\ResolutionRequest.js

getOrderedDependencies(response) {….

resolveDependency(fromModule, toModuleName) {….

_resolveNodeDependency(fromModule, toModuleName) {….

_loadAsFile(potentialModulePath, fromModule, toModule) {….

  this._fastfs.fileExists(potentialModulePath)