1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | var _exportNames = {
|
7 | prepackStdin: true,
|
8 | prepackFile: true,
|
9 | prepackFileSync: true
|
10 | };
|
11 | exports.prepackStdin = prepackStdin;
|
12 | exports.prepackFile = prepackFile;
|
13 | exports.prepackFileSync = prepackFileSync;
|
14 |
|
15 | var _options = require("./options");
|
16 |
|
17 | var _errors = require("./errors.js");
|
18 |
|
19 | var _prepackStandalone = require("./prepack-standalone.js");
|
20 |
|
21 | var _DebugChannel = require("./debugger/server/channel/DebugChannel.js");
|
22 |
|
23 | var _FileIOWrapper = require("./debugger/common/channel/FileIOWrapper.js");
|
24 |
|
25 | var _statistics = require("./serializer/statistics.js");
|
26 |
|
27 | var _fs = _interopRequireDefault(require("fs"));
|
28 |
|
29 | var _prepackStandalone2 = require("./prepack-standalone");
|
30 |
|
31 | Object.keys(_prepackStandalone2).forEach(function (key) {
|
32 | if (key === "default" || key === "__esModule") return;
|
33 | if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
34 | Object.defineProperty(exports, key, {
|
35 | enumerable: true,
|
36 | get: function () {
|
37 | return _prepackStandalone2[key];
|
38 | }
|
39 | });
|
40 | });
|
41 |
|
42 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | function createStatistics(options) {
|
57 | let gc = global.gc;
|
58 |
|
59 | return options.profile !== undefined ? new _statistics.SerializerStatistics(() => Date.now(), () => {
|
60 | if (gc) gc();
|
61 | return process.memoryUsage().heapUsed;
|
62 | }, !!gc) : new _statistics.SerializerStatistics();
|
63 | }
|
64 |
|
65 | function prepackStdin(options = _options.defaultOptions, processSerializedCode, printDiagnostics) {
|
66 | let sourceMapFilename = options.inputSourceMapFilename || "";
|
67 | process.stdin.setEncoding("utf8");
|
68 | process.stdin.resume();
|
69 | process.stdin.on("data", function (code) {
|
70 | _fs.default.readFile(sourceMapFilename, "utf8", function (mapErr, sourceMap = "") {
|
71 | if (mapErr) {
|
72 |
|
73 | if (sourceMapFilename !== "") console.warn(`No sourcemap found at ${sourceMapFilename}.`);
|
74 | }
|
75 |
|
76 | let filename = "no-filename-specified";
|
77 | let serialized;
|
78 | let success;
|
79 |
|
80 | try {
|
81 | serialized = (0, _prepackStandalone.prepackSources)([{
|
82 | filePath: filename,
|
83 | fileContents: code,
|
84 | sourceMapContents: sourceMap
|
85 | }], options, undefined, createStatistics(options));
|
86 | processSerializedCode(serialized);
|
87 | success = printDiagnostics(false);
|
88 | } catch (err) {
|
89 | printDiagnostics(err instanceof _errors.FatalError);
|
90 |
|
91 | if (!(err instanceof _errors.FatalError)) {
|
92 |
|
93 | console.error(err.stack);
|
94 | }
|
95 |
|
96 | success = false;
|
97 | }
|
98 |
|
99 | if (!success) process.exit(1);
|
100 | });
|
101 | });
|
102 | }
|
103 |
|
104 | function prepackFile(filename, options = _options.defaultOptions, callback, fileErrorHandler) {
|
105 | let sourceMapFilename = options.inputSourceMapFilename !== undefined ? options.inputSourceMapFilename : filename + ".map";
|
106 |
|
107 | _fs.default.readFile(filename, "utf8", function (fileErr, code) {
|
108 | if (fileErr) {
|
109 | if (fileErrorHandler) fileErrorHandler(fileErr);
|
110 | return;
|
111 | }
|
112 |
|
113 | _fs.default.readFile(sourceMapFilename, "utf8", function (mapErr, _sourceMap) {
|
114 | let sourceMap = _sourceMap;
|
115 |
|
116 | if (mapErr) {
|
117 | console.warn(`No sourcemap found at ${sourceMapFilename}.`);
|
118 | sourceMap = "";
|
119 | }
|
120 |
|
121 | let serialized;
|
122 |
|
123 | try {
|
124 | serialized = (0, _prepackStandalone.prepackSources)([{
|
125 | filePath: filename,
|
126 | fileContents: code,
|
127 | sourceMapContents: sourceMap
|
128 | }], options, undefined, createStatistics(options));
|
129 | } catch (err) {
|
130 | callback(err, null);
|
131 | return;
|
132 | }
|
133 |
|
134 | callback(null, serialized);
|
135 | });
|
136 | });
|
137 | }
|
138 |
|
139 | function prepackFileSync(filenames, options = _options.defaultOptions) {
|
140 | const sourceFiles = filenames.map(filename => {
|
141 | let code = _fs.default.readFileSync(filename, "utf8");
|
142 |
|
143 | let sourceMap = "";
|
144 | let sourceMapFilename = options.inputSourceMapFilename !== undefined ? options.inputSourceMapFilename : filename + ".map";
|
145 |
|
146 | try {
|
147 | sourceMap = _fs.default.readFileSync(sourceMapFilename, "utf8");
|
148 | } catch (_e) {
|
149 | if (options.inputSourceMapFilename !== undefined) console.warn(`No sourcemap found at ${sourceMapFilename}.`);
|
150 | }
|
151 |
|
152 | return {
|
153 | filePath: filename,
|
154 | fileContents: code,
|
155 | sourceMapContents: sourceMap
|
156 | };
|
157 | });
|
158 |
|
159 | if (options.debugInFilePath !== undefined && options.debugOutFilePath !== undefined) {
|
160 | if (options.debuggerConfigArgs === undefined) options.debuggerConfigArgs = {};
|
161 | let ioWrapper = new _FileIOWrapper.FileIOWrapper(false, options.debugInFilePath, options.debugOutFilePath);
|
162 | options.debuggerConfigArgs.debugChannel = new _DebugChannel.DebugChannel(ioWrapper);
|
163 | options.debuggerConfigArgs.sourcemaps = sourceFiles;
|
164 | }
|
165 |
|
166 | return (0, _prepackStandalone.prepackSources)(sourceFiles, options, options.debuggerConfigArgs, createStatistics(options));
|
167 | }
|
168 |
|
\ | No newline at end of file |