UNPKG

9.37 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../src/prepack-node.js"],"names":["createStatistics","options","gc","global","profile","undefined","SerializerStatistics","Date","now","process","memoryUsage","heapUsed","prepackStdin","defaultOptions","processSerializedCode","printDiagnostics","sourceMapFilename","inputSourceMapFilename","stdin","setEncoding","resume","on","code","fs","readFile","mapErr","sourceMap","console","warn","filename","serialized","success","filePath","fileContents","sourceMapContents","err","FatalError","error","stack","exit","prepackFile","callback","fileErrorHandler","fileErr","_sourceMap","prepackFileSync","filenames","sourceFiles","map","readFileSync","_e","debugInFilePath","debugOutFilePath","debuggerConfigArgs","ioWrapper","FileIOWrapper","debugChannel","DebugChannel","sourcemaps"],"mappings":";;;;;;;;;;;;;;AAcA;;AACA;;AAEA;;AAEA;;AACA;;AAEA;;AAEA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AA1BA;;;;;;;;;AASA;;;AAmBA,SAASA,gBAAT,CAA0BC,OAA1B,EAAmD;AACjD,MAAIC,KAAKC,OAAOD,EAAhB,CADiD,CAC7B;;AACpB,SAAOD,QAAQG,OAAR,KAAoBC,SAApB,GACH,IAAIC,gCAAJ,CACE,MAAMC,KAAKC,GAAL,EADR,EAEE,MAAM;AACJ,QAAIN,EAAJ,EAAQA;AACR,WAAOO,QAAQC,WAAR,GAAsBC,QAA7B;AACD,GALH,EAME,CAAC,CAACT,EANJ,CADG,GASH,IAAII,gCAAJ,EATJ;AAUD;;AAEM,SAASM,YAAT,CACLX,UAA0BY,uBADrB,EAELC,qBAFK,EAGLC,gBAHK,EAIoB;AACzB,MAAIC,oBAAoBf,QAAQgB,sBAAR,IAAkC,EAA1D;AACAR,UAAQS,KAAR,CAAcC,WAAd,CAA0B,MAA1B;AACAV,UAAQS,KAAR,CAAcE,MAAd;AACAX,UAAQS,KAAR,CAAcG,EAAd,CAAiB,MAAjB,EAAyB,UAASC,IAAT,EAAe;AACtCC,gBAAGC,QAAH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AQmD,gBAAR,KAA6B/C,SAA1E,EAAqF;AACnF,QAAIJ,QAAQoD,kBAAR,KAA+BhD,SAAnC,EAA8CJ,QAAQoD,kBAAR,GAA6B,EAA7B;AAE9C,QAAIC,YAAY,IAAIC,4BAAJ,CAAkB,KAAlB,EAAyBtD,QAAQkD,eAAjC,EAAkDlD,QAAQmD,gBAA1D,CAAhB;AACAnD,YAAQoD,kBAAR,CAA2BG,YAA3B,GAA0C,IAAIC,0BAAJ,CAAiBH,SAAjB,CAA1C;AACArD,YAAQoD,kBAAR,CAA2BK,UAA3B,GAAwCX,WAAxC;AACD;;AACD,SAAO,uCAAeA,WAAf,EAA4B9C,OAA5B,EAAqCA,QAAQoD,kBAA7C,EAAiErD,iBAAiBC,OAAjB,CAAjE,CAAP;AACD","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/*\n Prepack API functions that require Node as the execution environment for Prepack.\n */\n\n/* @flow */\nimport { defaultOptions } from \"./options\";\nimport { FatalError } from \"./errors.js\";\nimport { type PrepackOptions } from \"./prepack-options\";\nimport { prepackSources } from \"./prepack-standalone.js\";\nimport { type SourceMap } from \"./types.js\";\nimport { DebugChannel } from \"./debugger/server/channel/DebugChannel.js\";\nimport { FileIOWrapper } from \"./debugger/common/channel/FileIOWrapper.js\";\nimport { type SerializedResult } from \"./serializer/types.js\";\nimport { SerializerStatistics } from \"./serializer/statistics.js\";\n\nimport fs from \"fs\";\n\nexport * from \"./prepack-standalone\";\n\nfunction createStatistics(options: PrepackOptions) {\n let gc = global.gc; // eslint-disable-line no-undef\n return options.profile !== undefined\n ? new SerializerStatistics(\n () => Date.now(),\n () => {\n if (gc) gc();\n return process.memoryUsage().heapUsed;\n },\n !!gc\n )\n : new SerializerStatistics();\n}\n\nexport function prepackStdin(\n options: PrepackOptions = defaultOptions,\n processSerializedCode: SerializedResult => void,\n printDiagnostics: boolean => boolean\n): void | SerializedResult {\n let sourceMapFilename = options.inputSourceMapFilename || \"\";\n process.stdin.setEncoding(\"utf8\");\n process.stdin.resume();\n process.stdin.on(\"data\", function(code) {\n fs.readFile(sourceMapFilename, \"utf8\", function(mapErr, sourceMap = \"\") {\n if (mapErr) {\n //if no sourcemap was provided we silently ignore\n if (sourceMapFilename !== \"\") console.warn(`No sourcemap found at ${sourceMapFilename}.`);\n }\n let filename = \"no-filename-specified\";\n let serialized;\n let success;\n try {\n serialized = prepackSources(\n [{ filePath: filename, fileContents: code, sourceMapContents: sourceMap }],\n options,\n undefined,\n createStatistics(options)\n );\n processSerializedCode(serialized);\n success = printDiagnostics(false);\n } catch (err) {\n printDiagnostics(err instanceof FatalError);\n if (!(err instanceof FatalError)) {\n // if it is not a FatalError, it means prepack failed, and we should display the Prepack stack trace.\n console.error(err.stack);\n }\n success = false;\n }\n if (!success) process.exit(1);\n });\n });\n}\n\nexport function prepackFile(\n filename: string,\n options: PrepackOptions = defaultOptions,\n callback: (any, ?{ code: string, map?: SourceMap }) => void,\n fileErrorHandler?: (err: ?Error) => void\n): void {\n let sourceMapFilename =\n options.inputSourceMapFilename !== undefined ? options.inputSourceMapFilename : filename + \".map\";\n fs.readFile(filename, \"utf8\", function(fileErr, code) {\n if (fileErr) {\n if (fileErrorHandler) fileErrorHandler(fileErr);\n return;\n }\n fs.readFile(sourceMapFilename, \"utf8\", function(mapErr, _sourceMap) {\n let sourceMap = _sourceMap;\n if (mapErr) {\n console.warn(`No sourcemap found at ${sourceMapFilename}.`);\n sourceMap = \"\";\n }\n let serialized;\n try {\n serialized = prepackSources(\n [{ filePath: filename, fileContents: code, sourceMapContents: sourceMap }],\n options,\n undefined,\n createStatistics(options)\n );\n } catch (err) {\n callback(err, null);\n return;\n }\n callback(null, serialized);\n });\n });\n}\n\nexport function prepackFileSync(filenames: Array<string>, options: PrepackOptions = defaultOptions): SerializedResult {\n const sourceFiles = filenames.map(filename => {\n let code = fs.readFileSync(filename, \"utf8\");\n let sourceMap = \"\";\n let sourceMapFilename =\n options.inputSourceMapFilename !== undefined ? options.inputSourceMapFilename : filename + \".map\";\n try {\n sourceMap = fs.readFileSync(sourceMapFilename, \"utf8\");\n } catch (_e) {\n if (options.inputSourceMapFilename !== undefined) console.warn(`No sourcemap found at ${sourceMapFilename}.`);\n }\n return { filePath: filename, fileContents: code, sourceMapContents: sourceMap };\n });\n\n // The existence of debug[In/Out]FilePath represents the desire to use the debugger.\n if (options.debugInFilePath !== undefined && options.debugOutFilePath !== undefined) {\n if (options.debuggerConfigArgs === undefined) options.debuggerConfigArgs = {};\n\n let ioWrapper = new FileIOWrapper(false, options.debugInFilePath, options.debugOutFilePath);\n options.debuggerConfigArgs.debugChannel = new DebugChannel(ioWrapper);\n options.debuggerConfigArgs.sourcemaps = sourceFiles;\n }\n return prepackSources(sourceFiles, options, options.debuggerConfigArgs, createStatistics(options));\n}\n"],"file":"prepack-node.js"}
\No newline at end of file