npm package diff
Package: @forge/bundler
Versions: 6.1.4-next.0 - 6.1.4-next.1
File: package/out/typescript.js
Index: package/out/typescript.js
===================================================================
--- package/out/typescript.js
+++ package/out/typescript.js
@@ -9,8 +9,10 @@
const cli_shared_1 = require("@forge/cli-shared");
const common_1 = require("./common");
const dependencies_1 = require("./dependencies");
const text_1 = require("./text");
+const types_1 = require("./types");
+const metadata_1 = require("./metadata");
const COPY_DEPENDENCIES_OPTIONS = {
exclude: ['@forge/react', '@forge/bridge']
};
class TypeScriptBundler {
@@ -24,31 +26,68 @@
processArgs.push('--rootDir', path_1.default.join(args.appDirectory, common_1.SOURCE_DIR));
if (args.watchMode) {
processArgs.push('--watch');
}
+ else {
+ processArgs.push('--listFiles');
+ }
processArgs.push('--outDir', outputDir);
let tsc = 'tsc';
const appTsc = path_1.default.join(args.appDirectory, common_1.NODE_MODULES_DIR, '.bin', 'tsc');
if ((0, fs_1.existsSync)(appTsc)) {
tsc = appTsc;
}
return (0, cross_spawn_1.default)(tsc, processArgs, { stdio: ['ignore', 'pipe', 'inherit'] });
}
- async getResult(args, outputDir) {
- return { outputDir, metadata: {} };
+ isListedFile(line) {
+ line = line.trim();
+ if (line.length === 0) {
+ return null;
+ }
+ if (!line.match(/^\/.+\.[cm]?[jt]sx?$/)) {
+ return null;
+ }
+ return line;
}
+ isAppFile(line) {
+ if (!this.isListedFile(line)) {
+ return null;
+ }
+ if (line.includes('node_modules/')) {
+ return null;
+ }
+ return line;
+ }
+ async getResult(args, outputDir, output) {
+ let metadata;
+ if (output) {
+ const files = [];
+ for (const line of output.split('\n')) {
+ const filePath = this.isAppFile(line);
+ if (filePath) {
+ files.push(filePath);
+ }
+ }
+ metadata = await (0, metadata_1.getMetadata)(this.logger, files);
+ }
+ else {
+ metadata = (0, types_1.emptyMetadata)();
+ }
+ return { outputDir, metadata };
+ }
async bundle(args) {
const outputDir = (0, common_1.getOutputDir)(args);
await (0, dependencies_1.copyProductionDependencies)(args.appDirectory, outputDir, COPY_DEPENDENCIES_OPTIONS);
const compiler = this.runTypeScript(args, outputDir);
- const output = [];
- compiler.stdout.on('data', (data) => output.push(data));
+ let output = '';
+ compiler.stdout.on('data', (data) => (output += data.toString()));
return new Promise((resolve, reject) => compiler.on('exit', async (code) => {
try {
if (code !== 0) {
- throw new cli_shared_1.BundlerTSError(text_1.Text.typescriptError(output));
+ const errors = output.split('\n').filter((line) => !this.isListedFile(line));
+ throw new cli_shared_1.BundlerTSError(text_1.Text.typescriptError(errors));
}
- const result = await this.getResult(args, outputDir);
+ const result = await this.getResult(args, outputDir, output);
resolve(result);
}
catch (e) {
reject(e);