mirror of
https://github.com/knex/knex.git
synced 2025-06-26 22:00:25 +00:00
Additional lint checks before publishing (#5459)
This commit is contained in:
parent
5caf526c27
commit
9a6c5ba62f
@ -10,11 +10,12 @@ module.exports = {
|
||||
'plugin:import/warnings',
|
||||
'prettier',
|
||||
],
|
||||
plugins: ['import', 'mocha-no-only'],
|
||||
plugins: ['prettier', 'import', 'mocha-no-only'],
|
||||
rules: {
|
||||
'mocha-no-only/mocha-no-only': ['error'],
|
||||
'no-unused-vars': [warning, { vars: 'all', args: 'none' }],
|
||||
'no-console': 'off',
|
||||
'no-empty': 'off',
|
||||
'no-var': 2,
|
||||
'no-debugger': warning,
|
||||
'prefer-const': warning,
|
||||
|
11
bin/cli.js
11
bin/cli.js
@ -218,7 +218,7 @@ function invoke() {
|
||||
.action(async (name) => {
|
||||
try {
|
||||
const opts = commander.opts();
|
||||
const instance = await initKnex(env, opts, true); // Skip config check, we don't really care about client when creating migrations
|
||||
const instance = await initKnex(env, opts, true); // Skip config check, we don't really care about client when creating migrations
|
||||
const ext = getMigrationExtension(env, opts);
|
||||
const configOverrides = { extension: ext };
|
||||
|
||||
@ -233,7 +233,7 @@ function invoke() {
|
||||
success(color.green(`Created Migration: ${name}`));
|
||||
})
|
||||
.catch(exit);
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
exit(err);
|
||||
}
|
||||
});
|
||||
@ -397,7 +397,8 @@ function invoke() {
|
||||
}
|
||||
|
||||
if (opts.timestampFilenamePrefix) {
|
||||
configOverrides.timestampFilenamePrefix = opts.timestampFilenamePrefix;
|
||||
configOverrides.timestampFilenamePrefix =
|
||||
opts.timestampFilenamePrefix;
|
||||
}
|
||||
|
||||
instance.seed
|
||||
@ -406,9 +407,9 @@ function invoke() {
|
||||
success(color.green(`Created seed file: ${name}`));
|
||||
})
|
||||
.catch(exit);
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
exit(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
commander
|
||||
|
@ -120,7 +120,9 @@ class SchemaCompiler_PG extends SchemaCompiler {
|
||||
|
||||
refreshMaterializedView(viewName, concurrently = false) {
|
||||
this.pushQuery({
|
||||
sql: `refresh materialized view${concurrently ? " concurrently" : ""} ${this.formatter.wrap(viewName)}`,
|
||||
sql: `refresh materialized view${
|
||||
concurrently ? ' concurrently' : ''
|
||||
} ${this.formatter.wrap(viewName)}`,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ knex.ColumnBuilder = {
|
||||
},
|
||||
};
|
||||
|
||||
knex.TableBuilder = {
|
||||
knex.TableBuilder = {
|
||||
extend: function (methodName, fn) {
|
||||
TableBuilder.extend(methodName, fn);
|
||||
},
|
||||
|
@ -41,7 +41,9 @@ class MigrationGenerator {
|
||||
|
||||
_getNewMigrationName(name) {
|
||||
if (name[0] === '-') name = name.slice(1);
|
||||
return yyyymmddhhmmss() + '_' + name + '.' + this.config.extension.split('-')[0];
|
||||
return (
|
||||
yyyymmddhhmmss() + '_' + name + '.' + this.config.extension.split('-')[0]
|
||||
);
|
||||
}
|
||||
|
||||
_getNewMigrationPath(name) {
|
||||
|
@ -97,9 +97,10 @@ class SchemaBuilder extends EventEmitter {
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
SchemaBuilder.extend = (methodName, fn) => {
|
||||
if (Object.prototype.hasOwnProperty.call(SchemaBuilder.prototype, methodName)) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(SchemaBuilder.prototype, methodName)
|
||||
) {
|
||||
throw new Error(
|
||||
`Can't extend SchemaBuilder with existing method ('${methodName}').`
|
||||
);
|
||||
|
@ -88,9 +88,10 @@ ColumnBuilder.prototype.notNull = ColumnBuilder.prototype.notNullable =
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
ColumnBuilder.extend = (methodName, fn) => {
|
||||
if (Object.prototype.hasOwnProperty.call(ColumnBuilder.prototype, methodName)) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(ColumnBuilder.prototype, methodName)
|
||||
) {
|
||||
throw new Error(
|
||||
`Can't extend ColumnBuilder with existing method ('${methodName}').`
|
||||
);
|
||||
|
@ -361,9 +361,10 @@ AlterMethods.dropColumn = AlterMethods.dropColumns = function () {
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
TableBuilder.extend = (methodName, fn) => {
|
||||
if (Object.prototype.hasOwnProperty.call(TableBuilder.prototype, methodName)) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(TableBuilder.prototype, methodName)
|
||||
) {
|
||||
throw new Error(
|
||||
`Can't extend TableBuilder with existing method ('${methodName}').`
|
||||
);
|
||||
|
@ -79,7 +79,6 @@ const AlterMethods = {
|
||||
|
||||
helpers.addQueryContext(ViewBuilder);
|
||||
|
||||
|
||||
ViewBuilder.extend = (methodName, fn) => {
|
||||
if (Object.prototype.hasOwnProperty.call(ViewBuilder.prototype, methodName)) {
|
||||
throw new Error(
|
||||
|
12
package.json
12
package.json
@ -13,10 +13,11 @@
|
||||
"build:ts": "tsc",
|
||||
"build:gitignore": "node scripts/update_gitignore_for_tsc_output.js run",
|
||||
"format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
|
||||
"format:check-difference": "prettier --list-different \"{lib,bin,scripts,test}/**/*.js\"",
|
||||
"debug:test": "mocha --inspect-brk --exit -t 0 test/all-tests-suite.js",
|
||||
"debug:tape": "node --inspect-brk test/tape/index.js",
|
||||
"coveralls": "nyc report --reporter=lcov",
|
||||
"lint": "eslint \"lib/**/*.js\" \"test/**/*.js\"",
|
||||
"lint": "eslint \"lib/**/*.js\" \"test/**/*.js\" \"bin/**/*.js\"",
|
||||
"lint:types": "tsd && dtslint types",
|
||||
"lint:everything": "npm run lint:types && npm run lint",
|
||||
"test:unit": "npm run test:unit-only && npm run test:cli",
|
||||
@ -57,7 +58,7 @@
|
||||
"stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 5 -B 60 -- '- STATS '",
|
||||
"stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop",
|
||||
"prepare": "husky install && npm run clean && npm run build",
|
||||
"prepublishOnly": "npm run clean && npm run build"
|
||||
"prepublishOnly": "npm run format:check-difference && npm run lint && npm run clean && npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"colorette": "2.0.19",
|
||||
@ -114,10 +115,11 @@
|
||||
"coveralls": "^3.1.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"dtslint": "4.2.1",
|
||||
"eslint": "^8.13.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint": "^8.32.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-mocha-no-only": "^1.1.1",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"husky": "^8.0.1",
|
||||
"jake": "^10.8.5",
|
||||
"JSONStream": "^1.3.5",
|
||||
@ -130,7 +132,7 @@
|
||||
"oracledb": "^5.4.0",
|
||||
"pg": "^8.8.0",
|
||||
"pg-query-stream": "^4.2.4",
|
||||
"prettier": "2.6.2",
|
||||
"prettier": "2.8.3",
|
||||
"rimraf": "^3.0.2",
|
||||
"sinon": "^15.0.1",
|
||||
"sinon-chai": "^3.7.0",
|
||||
|
@ -1,29 +1,31 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require("child_process");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
function main() {
|
||||
const repoDir = path.dirname(__dirname)
|
||||
const gitDir = path.join(repoDir, '.git')
|
||||
const gitDirExists = doesDirectoryExist(gitDir)
|
||||
const repoDir = path.dirname(__dirname);
|
||||
const gitDir = path.join(repoDir, '.git');
|
||||
const gitDirExists = doesDirectoryExist(gitDir);
|
||||
if (!gitDirExists) {
|
||||
console.log("No .git directory detected so can not clean 'lib/'. Exiting.")
|
||||
process.exit(0)
|
||||
console.log("No .git directory detected so can not clean 'lib/'. Exiting.");
|
||||
process.exit(0);
|
||||
}
|
||||
console.log("Cleaning 'lib/' of outputted files from Typescript compilation ...")
|
||||
const cmd = 'git clean -f -X lib/'
|
||||
const output = execSync(cmd, { cwd: repoDir })
|
||||
console.log(output.toString('utf8'))
|
||||
console.log('Done')
|
||||
console.log(
|
||||
"Cleaning 'lib/' of outputted files from Typescript compilation ..."
|
||||
);
|
||||
const cmd = 'git clean -f -X lib/';
|
||||
const output = execSync(cmd, { cwd: repoDir });
|
||||
console.log(output.toString('utf8'));
|
||||
console.log('Done');
|
||||
}
|
||||
|
||||
function doesDirectoryExist(p) {
|
||||
if (fs.existsSync(p)) {
|
||||
return fs.lstatSync(p).isDirectory()
|
||||
return fs.lstatSync(p).isDirectory();
|
||||
}
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
|
||||
main()
|
||||
main();
|
||||
|
@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Directory constants
|
||||
const scriptDirectory = __dirname
|
||||
const repoDirectory = path.join(scriptDirectory, '..')
|
||||
const libDirectory = path.join(repoDirectory, 'lib')
|
||||
const scriptDirectory = __dirname;
|
||||
const repoDirectory = path.join(scriptDirectory, '..');
|
||||
const libDirectory = path.join(repoDirectory, 'lib');
|
||||
|
||||
const helpText = `
|
||||
Helper script to update lib/.gitignore for all .js files from .ts files.
|
||||
@ -19,7 +19,7 @@ Helper script to update lib/.gitignore for all .js files from .ts files.
|
||||
|
||||
NOTES FOR USAGE:
|
||||
1. This script is tested to work on Ubuntu 18.04 LTS.
|
||||
`
|
||||
`;
|
||||
|
||||
const gitignoreHeader = `# DO NOT EDIT, GENERATED BY: scripts/update_gitignore_for_tsc_output.js
|
||||
|
||||
@ -30,57 +30,61 @@ const gitignoreHeader = `# DO NOT EDIT, GENERATED BY: scripts/update_gitignore_f
|
||||
**/*.js.map
|
||||
|
||||
# Do not include .js files from .ts files
|
||||
`
|
||||
`;
|
||||
|
||||
function main(cliCommand) {
|
||||
if (cliCommand === 'run') {
|
||||
console.log('Generating lib/.gitignore ...')
|
||||
console.log('Generating lib/.gitignore ...');
|
||||
|
||||
// Find all .ts files in lib/
|
||||
const directoriesToProcess = [libDirectory]
|
||||
const tsFiles = []
|
||||
const directoriesToProcess = [libDirectory];
|
||||
const tsFiles = [];
|
||||
while (directoriesToProcess.length > 0) {
|
||||
const directory = directoriesToProcess.pop()
|
||||
const directory = directoriesToProcess.pop();
|
||||
if (!fs.existsSync(directory)) {
|
||||
throw new Error("Directory doesn't exist:", directory)
|
||||
throw new Error("Directory doesn't exist:", directory);
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(directory)
|
||||
const files = fs.readdirSync(directory);
|
||||
files.forEach((file) => {
|
||||
const filename = path.join(directory, file)
|
||||
const stat = fs.lstatSync(filename)
|
||||
const filename = path.join(directory, file);
|
||||
const stat = fs.lstatSync(filename);
|
||||
if (stat.isDirectory()) {
|
||||
directoriesToProcess.push(filename)
|
||||
directoriesToProcess.push(filename);
|
||||
} else if (filename.endsWith('.ts') && !filename.endsWith('.d.ts')) {
|
||||
tsFiles.push(filename)
|
||||
console.log('Found .ts file:', filename)
|
||||
tsFiles.push(filename);
|
||||
console.log('Found .ts file:', filename);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Get paths of .js files to ignore
|
||||
const jsFilesToIgnore = tsFiles.map((filepath) => {
|
||||
// Cuts off `${libDirectory}/`
|
||||
const relativeTsPath = filepath.slice(libDirectory.length + 1)
|
||||
const relativeTsPath = filepath.slice(libDirectory.length + 1);
|
||||
// Swaps .ts for .js file ending
|
||||
const relativeJsPath = relativeTsPath.slice(0, relativeTsPath.length - 3) + '.js'
|
||||
const relativeJsPath =
|
||||
relativeTsPath.slice(0, relativeTsPath.length - 3) + '.js';
|
||||
// Always use POSIX-style path separators - .gitignore requires it
|
||||
return relativeJsPath.split(path.sep).join(path.posix.sep);
|
||||
})
|
||||
const jsFilesToIgnoreString = jsFilesToIgnore.join('\n')
|
||||
const libGitignorePath = path.join(libDirectory, '.gitignore')
|
||||
fs.writeFileSync(libGitignorePath, gitignoreHeader + jsFilesToIgnoreString + '\n')
|
||||
console.log('DONE')
|
||||
});
|
||||
const jsFilesToIgnoreString = jsFilesToIgnore.join('\n');
|
||||
const libGitignorePath = path.join(libDirectory, '.gitignore');
|
||||
fs.writeFileSync(
|
||||
libGitignorePath,
|
||||
gitignoreHeader + jsFilesToIgnoreString + '\n'
|
||||
);
|
||||
console.log('DONE');
|
||||
} else if (['help', '--help', '-h', undefined].includes(cliCommand)) {
|
||||
console.log(helpText)
|
||||
console.log(helpText);
|
||||
} else {
|
||||
console.log(`Unsupported command: ${cliCommand}`)
|
||||
console.log("Try running with 'help' to see supported commands.")
|
||||
process.exit(1)
|
||||
console.log(`Unsupported command: ${cliCommand}`);
|
||||
console.log("Try running with 'help' to see supported commands.");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Main script logic
|
||||
const cliCommand = process.argv[2]
|
||||
const cliCommand = process.argv[2];
|
||||
// Start the bash app's main function
|
||||
main(cliCommand)
|
||||
main(cliCommand);
|
||||
|
@ -66,9 +66,9 @@ describe('Oracle', () => {
|
||||
const sql = compiler.insert();
|
||||
expect(sql.sql).to.eql(
|
||||
'begin execute immediate \'insert into "fakeTable" ("value1", "value2", "value3", "value4") values ' +
|
||||
'(:1, :2, :3, :4)\' using ?, ?, ?, ?; ' +
|
||||
'execute immediate \'insert into "fakeTable" ("value1", "value2", "value3", "value4") values ' +
|
||||
'(:1, DEFAULT, DEFAULT, DEFAULT)\' using ?;end;'
|
||||
"(:1, :2, :3, :4)' using ?, ?, ?, ?; " +
|
||||
'execute immediate \'insert into "fakeTable" ("value1", "value2", "value3", "value4") values ' +
|
||||
"(:1, DEFAULT, DEFAULT, DEFAULT)' using ?;end;"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -27,19 +27,18 @@ describe('Oracledb dialect', () => {
|
||||
|
||||
describe('#4869 inserting Buffer', async () => {
|
||||
it('.toSQL().toNative() generates correct sql and bindings for INSERT of Buffer', async () => {
|
||||
const b = Buffer.from('hello', 'utf-8')
|
||||
const query = knex('table1').insert({ value: b })
|
||||
const queryObj = query.toSQL().toNative()
|
||||
const b = Buffer.from('hello', 'utf-8');
|
||||
const query = knex('table1').insert({ value: b });
|
||||
const queryObj = query.toSQL().toNative();
|
||||
// Ensure we have two bindings, before fix for #4869 there would only have been one due
|
||||
// to silent dropping of the Buffer.
|
||||
expect(queryObj.bindings.length).to.eql(2)
|
||||
expect(queryObj.bindings.length).to.eql(2);
|
||||
expect(queryObj).to.eql({
|
||||
sql: 'insert into "table1" ("value") values (:1) returning "value" into :2',
|
||||
bindings: [b, { type: 2019, dir: 3003 }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const child_process = require("child_process");
|
||||
const child_process = require('child_process');
|
||||
const rimrafSync = require('rimraf').sync;
|
||||
|
||||
function assertExec(cmd, desc) {
|
||||
@ -11,9 +11,7 @@ function assertExec(cmd, desc) {
|
||||
let stderr = '';
|
||||
let stdout = '';
|
||||
const bin = child_process.exec(cmd);
|
||||
bin.on('error', (msg, code) =>
|
||||
reject(Error(desc + ' FAIL. ' + stderr))
|
||||
);
|
||||
bin.on('error', (msg, code) => reject(Error(desc + ' FAIL. ' + stderr)));
|
||||
bin.on('cmdEnd', (cmd) => resolve({ cmd, stdout, stderr }));
|
||||
bin.on('stdout', (data) => (stdout += data.toString()));
|
||||
bin.on('stderr', (data) => (stderr += data.toString()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user