mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
🐛 Fix that n8n-node-dev did not build correctly
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
import { join } from 'path';
|
||||
import { ChildProcess, spawn } from 'child_process';
|
||||
import {
|
||||
readFile as fsReadFile,
|
||||
write as fsWrite,
|
||||
} from 'fs';
|
||||
import { join } from 'path';
|
||||
import { file } from 'tmp-promise';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const fsReadFileAsync = promisify(fsReadFile);
|
||||
const fsWriteAsync = promisify(fsWrite);
|
||||
|
||||
import { IBuildOptions } from '.';
|
||||
|
||||
@@ -8,6 +17,41 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
|
||||
/**
|
||||
* Create a custom tsconfig file as tsc currently has no way to define a base
|
||||
* directory:
|
||||
* https://github.com/Microsoft/TypeScript/issues/25430
|
||||
*
|
||||
* @export
|
||||
* @returns
|
||||
*/
|
||||
export async function createCustomTsconfig () {
|
||||
|
||||
// Get path to simple tsconfig file which should be used for build
|
||||
const tsconfigPath = join(__dirname, '../../src/tsconfig-build.json');
|
||||
|
||||
// Read the tsconfi file
|
||||
const tsConfigString = await fsReadFileAsync(tsconfigPath, { encoding: 'utf8'}) as string;
|
||||
const tsConfig = JSON.parse(tsConfigString);
|
||||
|
||||
// Set absolute include paths
|
||||
const newIncludeFiles = [];
|
||||
for (const includeFile of tsConfig.include) {
|
||||
newIncludeFiles.push(join(process.cwd(), includeFile));
|
||||
}
|
||||
tsConfig.include = newIncludeFiles;
|
||||
|
||||
// Write new custom tsconfig file
|
||||
const { fd, path, cleanup } = await file();
|
||||
await fsWriteAsync(fd, Buffer.from(JSON.stringify(tsConfig, null, 2), 'utf8'));
|
||||
|
||||
return {
|
||||
path,
|
||||
cleanup,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds and copies credentials and nodes
|
||||
*
|
||||
@@ -21,12 +65,11 @@ export async function buildFiles (options?: IBuildOptions): Promise<string> {
|
||||
// Get the path of the TypeScript cli of this project
|
||||
const tscPath = join(__dirname, '../../node_modules/typescript/bin/tsc');
|
||||
|
||||
// Get path to simple tsconfig file which should be used for build
|
||||
const tsconfigPath = join(__dirname, '../../src/tsconfig-build.json');
|
||||
const tsconfigData = await createCustomTsconfig();
|
||||
|
||||
const outputDirectory = options.destinationFolder || UserSettings.getUserN8nFolderCustomExtensionPath();
|
||||
|
||||
let buildCommand = `${tscPath} --p ${tsconfigPath} --outDir ${outputDirectory}`;
|
||||
let buildCommand = `${tscPath} --p ${tsconfigData.path} --outDir ${outputDirectory} --rootDir ${process.cwd()}`;
|
||||
if (options.watch === true) {
|
||||
buildCommand += ' --watch';
|
||||
}
|
||||
@@ -52,11 +95,16 @@ export async function buildFiles (options?: IBuildOptions): Promise<string> {
|
||||
errorMessage = `${errorMessage}\nGot following output:\n${error.stdout}`;
|
||||
}
|
||||
|
||||
// Remove the tmp tsconfig file
|
||||
tsconfigData.cleanup();
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
buildProcess.on('exit', code => {
|
||||
// Remove the tmp tsconfig file
|
||||
tsconfigData.cleanup();
|
||||
resolve(outputDirectory);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user