diff --git a/package-lock.json b/package-lock.json index b0b3c0e9f962f..3d91b3938d2eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7230,12 +7230,6 @@ "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", "dev": true }, - "node_modules/@types/copyfiles": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@types/copyfiles/-/copyfiles-2.4.1.tgz", - "integrity": "sha512-v2JLxXeWUeWYWVo3/tlpxqiDCvgewSvf58HHjHYNaCi0lAthhRQ7jz8InxGzJsrMbWmWkYaxBO+BEtKjBU4ebw==", - "dev": true - }, "node_modules/@types/cron": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/@types/cron/-/cron-1.7.3.tgz", @@ -18583,78 +18577,6 @@ "node": ">=0.10.0" } }, - "node_modules/copyfiles": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/copyfiles/-/copyfiles-2.4.1.tgz", - "integrity": "sha512-fereAvAvxDrQDOXybk3Qu3dPbOoKoysFMWtkY3mv5BsL8//OSZVL5DCLYqgRfY5cWirgRzlC+WSrxp6Bo3eNZg==", - "dependencies": { - "glob": "^7.0.5", - "minimatch": "^3.0.3", - "mkdirp": "^1.0.4", - "noms": "0.0.0", - "through2": "^2.0.1", - "untildify": "^4.0.0", - "yargs": "^16.1.0" - }, - "bin": { - "copyfiles": "copyfiles", - "copyup": "copyfiles" - } - }, - "node_modules/copyfiles/node_modules/cliui": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", - "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, - "node_modules/copyfiles/node_modules/get-caller-file": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "engines": { - "node": "6.* || 8.* || >= 10.*" - } - }, - "node_modules/copyfiles/node_modules/mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", - "bin": { - "mkdirp": "bin/cmd.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/copyfiles/node_modules/y18n": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", - "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "engines": { - "node": ">=10" - } - }, - "node_modules/copyfiles/node_modules/yargs": { - "version": "16.2.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", - "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", - "dependencies": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.0", - "y18n": "^5.0.5", - "yargs-parser": "^20.2.2" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/core-js": { "version": "3.25.1", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.25.1.tgz", @@ -36997,31 +36919,6 @@ "node": ">=4" } }, - "node_modules/noms": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/noms/-/noms-0.0.0.tgz", - "integrity": "sha512-lNDU9VJaOPxUmXcLb+HQFeUgQQPtMI24Gt6hgfuMHRJgMRHMF/qZ4HJD3GDru4sSw9IQl2jPjAYnQrdIeLbwow==", - "dependencies": { - "inherits": "^2.0.1", - "readable-stream": "~1.0.31" - } - }, - "node_modules/noms/node_modules/isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==" - }, - "node_modules/noms/node_modules/readable-stream": { - "version": "1.0.34", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", - "integrity": "sha512-ok1qVCJuRkNmvebYikljxJA/UEsKwLl2nI1OmaqAu4/UE+h0wKCHok4XkL/gvi39OacXvw59RJUOFUkDib2rHg==", - "dependencies": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.1", - "isarray": "0.0.1", - "string_decoder": "~0.10.x" - } - }, "node_modules/nopt": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/nopt/-/nopt-6.0.0.tgz", @@ -47849,14 +47746,6 @@ "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", "dev": true }, - "node_modules/untildify": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", - "integrity": "sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==", - "engines": { - "node": ">=8" - } - }, "node_modules/update-browserslist-db": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.7.tgz", @@ -52632,7 +52521,7 @@ "@oclif/command": "^1.5.18", "@oclif/errors": "^1.2.2", "change-case": "^4.1.1", - "copyfiles": "^2.1.1", + "fast-glob": "^3.2.5", "inquirer": "^7.0.1", "n8n-core": "~0.134.0", "n8n-workflow": "~0.116.0", @@ -52648,7 +52537,6 @@ "devDependencies": { "@n8n_io/eslint-config": "", "@oclif/dev-cli": "^1.22.2", - "@types/copyfiles": "^2.1.1", "@types/express": "^4.17.6", "@types/inquirer": "^6.5.0", "@types/node": "^16.11.22", @@ -58256,12 +58144,6 @@ "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", "dev": true }, - "@types/copyfiles": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@types/copyfiles/-/copyfiles-2.4.1.tgz", - "integrity": "sha512-v2JLxXeWUeWYWVo3/tlpxqiDCvgewSvf58HHjHYNaCi0lAthhRQ7jz8InxGzJsrMbWmWkYaxBO+BEtKjBU4ebw==", - "dev": true - }, "@types/cron": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/@types/cron/-/cron-1.7.3.tgz", @@ -67610,61 +67492,6 @@ } } }, - "copyfiles": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/copyfiles/-/copyfiles-2.4.1.tgz", - "integrity": "sha512-fereAvAvxDrQDOXybk3Qu3dPbOoKoysFMWtkY3mv5BsL8//OSZVL5DCLYqgRfY5cWirgRzlC+WSrxp6Bo3eNZg==", - "requires": { - "glob": "^7.0.5", - "minimatch": "^3.0.3", - "mkdirp": "^1.0.4", - "noms": "0.0.0", - "through2": "^2.0.1", - "untildify": "^4.0.0", - "yargs": "^16.1.0" - }, - "dependencies": { - "cliui": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", - "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", - "requires": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, - "get-caller-file": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" - }, - "mkdirp": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", - "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" - }, - "y18n": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", - "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==" - }, - "yargs": { - "version": "16.2.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", - "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", - "requires": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.0", - "y18n": "^5.0.5", - "yargs-parser": "^20.2.2" - } - } - } - }, "core-js": { "version": "3.25.1", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.25.1.tgz", @@ -81904,14 +81731,13 @@ "@oclif/command": "^1.5.18", "@oclif/dev-cli": "^1.22.2", "@oclif/errors": "^1.2.2", - "@types/copyfiles": "^2.1.1", "@types/express": "^4.17.6", "@types/inquirer": "^6.5.0", "@types/node": "^16.11.22", "@types/tmp": "^0.2.0", "@types/vorpal": "^1.11.0", "change-case": "^4.1.1", - "copyfiles": "^2.1.1", + "fast-glob": "^3.2.5", "inquirer": "^7.0.1", "n8n-core": "~0.134.0", "n8n-workflow": "~0.116.0", @@ -82695,33 +82521,6 @@ } } }, - "noms": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/noms/-/noms-0.0.0.tgz", - "integrity": "sha512-lNDU9VJaOPxUmXcLb+HQFeUgQQPtMI24Gt6hgfuMHRJgMRHMF/qZ4HJD3GDru4sSw9IQl2jPjAYnQrdIeLbwow==", - "requires": { - "inherits": "^2.0.1", - "readable-stream": "~1.0.31" - }, - "dependencies": { - "isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==" - }, - "readable-stream": { - "version": "1.0.34", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", - "integrity": "sha512-ok1qVCJuRkNmvebYikljxJA/UEsKwLl2nI1OmaqAu4/UE+h0wKCHok4XkL/gvi39OacXvw59RJUOFUkDib2rHg==", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.1", - "isarray": "0.0.1", - "string_decoder": "~0.10.x" - } - } - } - }, "nopt": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/nopt/-/nopt-6.0.0.tgz", @@ -91230,11 +91029,6 @@ } } }, - "untildify": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", - "integrity": "sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==" - }, "update-browserslist-db": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.7.tgz", diff --git a/packages/node-dev/commands/build.ts b/packages/node-dev/commands/build.ts index 97eaa2ceddb1e..548cd0e56af66 100644 --- a/packages/node-dev/commands/build.ts +++ b/packages/node-dev/commands/build.ts @@ -44,7 +44,7 @@ export class Build extends Command { const outputDirectory = await buildFiles(options); - this.log(`The nodes got build and saved into the following folder:\n${outputDirectory}`); + this.log(`The nodes got built and saved into the following folder:\n${outputDirectory}`); } catch (error) { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access this.log(`\nGOT ERROR: "${error.message}"`); diff --git a/packages/node-dev/package.json b/packages/node-dev/package.json index a7a79943611ac..e75c1fd64297e 100644 --- a/packages/node-dev/package.json +++ b/packages/node-dev/package.json @@ -48,7 +48,6 @@ "devDependencies": { "@n8n_io/eslint-config": "", "@oclif/dev-cli": "^1.22.2", - "@types/copyfiles": "^2.1.1", "@types/express": "^4.17.6", "@types/inquirer": "^6.5.0", "@types/node": "^16.11.22", @@ -59,7 +58,7 @@ "@oclif/command": "^1.5.18", "@oclif/errors": "^1.2.2", "change-case": "^4.1.1", - "copyfiles": "^2.1.1", + "fast-glob": "^3.2.5", "inquirer": "^7.0.1", "n8n-core": "~0.134.0", "n8n-workflow": "~0.116.0", diff --git a/packages/node-dev/src/Build.ts b/packages/node-dev/src/Build.ts index 2450cc1858650..99b907f1c0c4c 100644 --- a/packages/node-dev/src/Build.ts +++ b/packages/node-dev/src/Build.ts @@ -1,40 +1,26 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -import { ChildProcess, spawn } from 'child_process'; - -import { readFile as fsReadFile } from 'fs/promises'; -import { write as fsWrite } from 'fs'; - -import { join } from 'path'; -import { file } from 'tmp-promise'; -import { promisify } from 'util'; +import glob from 'fast-glob'; +import { spawn } from 'child_process'; +import { copyFile, mkdir, readFile, writeFile } from 'fs/promises'; +import { join, dirname, resolve as resolvePath } from 'path'; +import { file as tmpFile } from 'tmp-promise'; import { UserSettings } from 'n8n-core'; -// eslint-disable-next-line import/no-cycle import { IBuildOptions } from '.'; -// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires -const copyfiles = require('copyfiles'); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const fsReadFileAsync = promisify(fsReadFile); -const fsWriteAsync = promisify(fsWrite); - /** * 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 */ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export async function createCustomTsconfig() { // Get path to simple tsconfig file which should be used for build - const tsconfigPath = join(__dirname, '../../src/tsconfig-build.json'); + const tsconfigPath = join(dirname(require.resolve('n8n-node-dev/src')), 'tsconfig-build.json'); // Read the tsconfig file - const tsConfigString = await fsReadFile(tsconfigPath, { encoding: 'utf8' }); + const tsConfigString = await readFile(tsconfigPath, { encoding: 'utf8' }); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const tsConfig = JSON.parse(tsConfigString); @@ -47,10 +33,8 @@ export async function createCustomTsconfig() { tsConfig.include = newIncludeFiles; // Write new custom tsconfig file - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - // eslint-disable-next-line @typescript-eslint/unbound-method - const { fd, path, cleanup } = await file(); - await fsWriteAsync(fd, Buffer.from(JSON.stringify(tsConfig, null, 2), 'utf8')); + const { path, cleanup } = await tmpFile(); + await writeFile(path, JSON.stringify(tsConfig, null, 2)); return { path, @@ -60,43 +44,37 @@ export async function createCustomTsconfig() { /** * Builds and copies credentials and nodes - * - * @export - * @param {IBuildOptions} [options] Options to overwrite default behaviour - * @returns {Promise} */ -export async function buildFiles(options?: IBuildOptions): Promise { - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, no-param-reassign - options = options || {}; - - let typescriptPath; - - // Check for OS to designate correct tsc path - if (process.platform === 'win32') { - typescriptPath = '../../node_modules/TypeScript/lib/tsc'; - } else { - typescriptPath = '../../node_modules/.bin/tsc'; - } - const tscPath = join(__dirname, typescriptPath); - +export async function buildFiles({ + destinationFolder = UserSettings.getUserN8nFolderCustomExtensionPath(), + watch, +}: IBuildOptions): Promise { + const tscPath = join(dirname(require.resolve('typescript')), 'tsc'); const tsconfigData = await createCustomTsconfig(); - const outputDirectory = - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - options.destinationFolder || UserSettings.getUserN8nFolderCustomExtensionPath(); + await Promise.all( + ['*.svg', '*.png', '*.node.json'].map(async (filenamePattern) => { + const files = await glob(`**/${filenamePattern}`); + for (const file of files) { + const src = resolvePath(process.cwd(), file); + const dest = resolvePath(destinationFolder, file); + await mkdir(dirname(dest), { recursive: true }); + await copyFile(src, dest); + } + }), + ); // Supply a node base path so that it finds n8n-core and n8n-workflow const nodeModulesPath = join(__dirname, '../../node_modules/'); let buildCommand = `${tscPath} --p ${ tsconfigData.path - } --outDir ${outputDirectory} --rootDir ${process.cwd()} --baseUrl ${nodeModulesPath}`; - if (options.watch === true) { + } --outDir ${destinationFolder} --rootDir ${process.cwd()} --baseUrl ${nodeModulesPath}`; + if (watch) { buildCommand += ' --watch'; } - let buildProcess: ChildProcess; try { - buildProcess = spawn('node', buildCommand.split(' '), { + const buildProcess = spawn('node', buildCommand.split(' '), { windowsVerbatimArguments: true, cwd: process.cwd(), }); @@ -110,8 +88,10 @@ export async function buildFiles(options?: IBuildOptions): Promise { // Make sure that the child process gets also always terminated // when the main process does - process.on('exit', () => { - buildProcess.kill(); + process.on('exit', () => buildProcess.kill()); + + await new Promise((resolve) => { + buildProcess.on('exit', resolve); }); } catch (error) { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment @@ -122,26 +102,11 @@ export async function buildFiles(options?: IBuildOptions): Promise { errorMessage = `${errorMessage}\nGot following output:\n${error.stdout}`; } - // Remove the tmp tsconfig file - // eslint-disable-next-line @typescript-eslint/no-floating-promises - tsconfigData.cleanup(); - throw new Error(errorMessage); + } finally { + // Remove the tmp tsconfig file + await tsconfigData.cleanup(); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - return new Promise((resolve, reject) => { - ['*.png', '*.node.json'].forEach((filenamePattern) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - copyfiles([join(process.cwd(), `./${filenamePattern}`), outputDirectory], { up: true }, () => - resolve(outputDirectory), - ); - }); - // eslint-disable-next-line @typescript-eslint/no-unused-vars - buildProcess.on('exit', (code) => { - // Remove the tmp tsconfig file - // eslint-disable-next-line @typescript-eslint/no-floating-promises - tsconfigData.cleanup(); - }); - }); + return destinationFolder; } diff --git a/packages/node-dev/src/tsconfig-build.json b/packages/node-dev/src/tsconfig-build.json index 717db8387a94d..f8b53671269f8 100644 --- a/packages/node-dev/src/tsconfig-build.json +++ b/packages/node-dev/src/tsconfig-build.json @@ -1,10 +1,18 @@ { - "extends": "../../tsconfig.json", "compilerOptions": { + "strict": true, + "module": "commonjs", + "moduleResolution": "node", + "target": "es2019", + "lib": ["es2019", "es2020"], "importHelpers": true, + "esModuleInterop": true, + "declaration": true, + "incremental": true, + "sourceMap": true }, "include": [ - "*.credentials.ts", - "*.node.ts" + "**/*.credentials.ts", + "**/*.node.ts" ] }