mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 21:37:32 -08:00
🐛 Fix that n8n-node-dev did not build correctly
This commit is contained in:
parent
d337cbd805
commit
efc16dbc73
|
@ -46,6 +46,7 @@
|
|||
"@oclif/dev-cli": "^1.22.2",
|
||||
"@types/inquirer": "^6.5.0",
|
||||
"@types/node": "^10.10.1",
|
||||
"@types/tmp": "^0.1.0",
|
||||
"@types/vorpal": "^1.11.0",
|
||||
"tslint": "^5.17.0"
|
||||
},
|
||||
|
@ -58,6 +59,7 @@
|
|||
"n8n-workflow": "^0.11.0",
|
||||
"replace-in-file": "^4.1.0",
|
||||
"request": "^2.88.0",
|
||||
"tmp-promise": "^2.0.2",
|
||||
"typescript": "~3.5.2"
|
||||
},
|
||||
"jest": {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
"lib": [
|
||||
"es2017"
|
||||
],
|
||||
"types": [
|
||||
"node"
|
||||
],
|
||||
"types": [],
|
||||
"module": "commonjs",
|
||||
"importHelpers": true,
|
||||
"noImplicitAny": true,
|
||||
|
@ -18,8 +16,8 @@
|
|||
"sourceMap": true
|
||||
},
|
||||
"include": [
|
||||
"../*.credentials.ts",
|
||||
"../*.node.ts"
|
||||
"*.credentials.ts",
|
||||
"*.node.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
|
|
Loading…
Reference in a new issue