Skip to content

Commit

Permalink
build: eslint 9 activation
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Sep 3, 2024
1 parent 78185d0 commit 766272a
Show file tree
Hide file tree
Showing 344 changed files with 7,082 additions and 5,460 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.*
/playground
node_modules
!.eslintrc
!.travis.yml
!.prettierrc.yml
!.gitignore
!.github
!.gitattributes
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
experimentalTernaries: true
32 changes: 24 additions & 8 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import scopes from "@commitlint/config-lerna-scopes";
import fs from "node:fs/promises";
import { glob } from "glob";
const pkg = await fs
.readFile("./package.json", { encoding: "utf8" })
.then((data) => JSON.parse(data));

console.log(pkg.workspaces);

const packages = await glob(
pkg.workspaces.map((pattern) => `${pattern}/package.json`),
).then((files) =>
Promise.all(
files.map((file) =>
fs
.readFile(file, { encoding: "utf8" })
.then((data) => JSON.parse(data))
.then((pkg) => pkg.name.replace("@nikitajs/", "")),
),
),
);

export default {
extends: [
"@commitlint/config-conventional",
"@commitlint/config-lerna-scopes",
],
extends: ["@commitlint/config-conventional"],
rules: {
"scope-enum": async (ctx) => [
"scope-enum": async () => [
2,
"always",
[
...(await scopes.utils.getPackages(ctx)),
// Insert custom scopes below:
...packages,
// Custom scopes
"release",
],
],
Expand Down
16 changes: 16 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import globals from "globals";
import js from "@eslint/js";
import mocha from "eslint-plugin-mocha";
import prettier from "eslint-plugin-prettier/recommended";

export default [
{
ignores: ["**/node_modules/", "docs/**", "extra/**"],
},
{
languageOptions: { globals: { ...globals.node } },
},
js.configs.recommended,
mocha.configs.flat.recommended,
prettier,
];
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/config-lerna-scopes": "^19.0.0",
"@eslint/js": "^9.9.1",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^9.9.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-prettier": "^5.2.1",
"glob": "^11.0.0",
"husky": "^9.1.1",
"lerna": "^8.1.6"
"lerna": "^8.1.6",
"prettier": "^3.3.3"
},
"scripts": {
"compile": "lerna run compile",
"clean": "lerna run clean",
"docs:clean": "cd docs/website && yarn clean",
"docs:develop": "cd docs/website && yarn develop",
"lint": "lerna run lint",
"lint:check": "eslint",
"lint:fix": "eslint --fix",
"test": "lerna run test",
"test:local": "lerna run test:local",
"goodies:incus:macos": "./packages/incus/assets/multipass.sh",
Expand Down
12 changes: 0 additions & 12 deletions packages/core/.eslintrc

This file was deleted.

55 changes: 30 additions & 25 deletions packages/core/env/chown/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@

import path from 'node:path';
import dedent from 'dedent';
import runner from '@nikitajs/incus-runner';
const __dirname = new URL( '.', import.meta.url).pathname
import path from "node:path";
import dedent from "dedent";
import runner from "@nikitajs/incus-runner";
const __dirname = new URL(".", import.meta.url).pathname;

runner({
cwd: '/nikita/packages/core',
container: 'nikita-core-chown',
logdir: path.resolve(__dirname, './logs'),
cwd: "/nikita/packages/core",
container: "nikita-core-chown",
logdir: path.resolve(__dirname, "./logs"),
cluster: {
containers: {
'nikita-core-chown': {
image: 'images:almalinux/8',
"nikita-core-chown": {
image: "images:almalinux/8",
properties: {
'environment.NIKITA_TEST_MODULE': '/nikita/packages/core/env/chown/test.coffee',
'raw.idmap': parseInt(process.env['NIKITA_INCUS_IN_VAGRANT']) ? 'both 1000 0' : `uid ${process.getuid()} 0\ngid ${process.getgid()} 0`
"environment.NIKITA_TEST_MODULE":
"/nikita/packages/core/env/chown/test.coffee",
"raw.idmap":
parseInt(process.env["NIKITA_INCUS_IN_VAGRANT"]) ? "both 1000 0" : (
`uid ${process.getuid()} 0\ngid ${process.getgid()} 0`
),
},
disk: {
nikitadir: {
path: '/nikita',
source: process.env['NIKITA_HOME'] || path.join(__dirname, '../../../../')
}
path: "/nikita",
source:
process.env["NIKITA_HOME"] ||
path.join(__dirname, "../../../../"),
},
},
ssh: {
enabled: true
}
}
enabled: true,
},
},
},
provision_container: async function({config}) {
provision_container: async function ({ config }) {
await this.incus.exec({
$header: 'Node.js',
$header: "Node.js",
container: config.container,
command: dedent`
if command -v node ; then exit 42; fi
Expand All @@ -39,10 +44,10 @@ runner({
nvm install 22
`,
trap: true,
code: [0, 42]
code: [0, 42],
});
await this.incus.exec({
$header: 'SSH keys',
$header: "SSH keys",
container: config.container,
command: dedent`
mkdir -p /root/.ssh && chmod 700 /root/.ssh
Expand All @@ -51,8 +56,8 @@ runner({
cat /root/.ssh/id_ed25519.pub > /root/.ssh/authorized_keys
fi
`,
trap: true
trap: true,
});
}
}
},
},
});
67 changes: 36 additions & 31 deletions packages/core/env/ssh/index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@

import path from 'node:path';
import dedent from 'dedent';
import runner from '@nikitajs/incus-runner';
const __dirname = new URL( '.', import.meta.url).pathname
import path from "node:path";
import dedent from "dedent";
import runner from "@nikitajs/incus-runner";
const __dirname = new URL(".", import.meta.url).pathname;

runner({
cwd: '/nikita/packages/core',
container: 'nikita-core-ssh',
logdir: path.resolve(__dirname, './logs'),
cwd: "/nikita/packages/core",
container: "nikita-core-ssh",
logdir: path.resolve(__dirname, "./logs"),
test_user: 1234,
cluster: {
containers: {
'nikita-core-ssh': {
image: 'images:almalinux/8',
"nikita-core-ssh": {
image: "images:almalinux/8",
properties: {
'environment.NIKITA_TEST_MODULE': '/nikita/packages/core/env/ssh/test.coffee',
'environment.HOME': '/home/source', // Fix, Incus doesnt set HOME with --user
'raw.idmap': process.env['NIKITA_INCUS_IN_VAGRANT'] ? 'both 1000 1234' : `both ${process.getuid()} 1234`
"environment.NIKITA_TEST_MODULE":
"/nikita/packages/core/env/ssh/test.coffee",
"environment.HOME": "/home/source", // Fix, Incus doesnt set HOME with --user
"raw.idmap":
process.env["NIKITA_INCUS_IN_VAGRANT"] ?
"both 1000 1234"
: `both ${process.getuid()} 1234`,
},
disk: {
nikitadir: {
path: '/nikita',
source: process.env['NIKITA_HOME'] || path.join(__dirname, '../../../../')
}
path: "/nikita",
source:
process.env["NIKITA_HOME"] ||
path.join(__dirname, "../../../../"),
},
},
ssh: {
enabled: true
}
}
enabled: true,
},
},
},
provision_container: async function({config}) {
provision_container: async function ({ config }) {
await this.incus.exec({
$header: 'Dependencies',
$header: "Dependencies",
container: config.container,
command: dedent`
# nvm require the tar commands
yum install -y tar
`
`,
});
await this.incus.exec({
$header: 'User `source`',
$header: "User `source`",
container: config.container,
command: dedent`
if ! id -u 1234 ; then
Expand All @@ -51,10 +56,10 @@ runner({
fi
chown -R source /home/source/
`,
trap: true
trap: true,
});
await this.incus.exec({
$header: 'Node.js',
$header: "Node.js",
container: config.container,
command: dedent`
if command -v node ; then exit 42; fi
Expand All @@ -63,12 +68,12 @@ runner({
nvm install 22
`,
user: 1234,
shell: 'bash',
shell: "bash",
trap: true,
code: [0, 42]
code: [0, 42],
});
await this.incus.exec({
$header: 'User `target`',
$header: "User `target`",
container: config.container,
command: dedent`
if ! id -u 1235; then
Expand All @@ -81,8 +86,8 @@ runner({
fi
chown -R target /home/target/
`,
trap: true
trap: true,
});
}
}
},
},
});
50 changes: 29 additions & 21 deletions packages/core/lib/actions/assert/index.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,64 @@

// Dependencies
import utils from '@nikitajs/core/utils';
import definitions from "./schema.json" with { type: "json" };
import utils from "@nikitajs/core/utils";
// Schema
// import definitions from "./schema.json" with { type: "json" };
import { readFile } from "node:fs/promises";
const definitions = JSON.parse(
await readFile(new URL("./schema.json", import.meta.url), "utf8"),
);

// Action
export default {
hooks: {
on_action: function(action) {
on_action: function (action) {
action.handler = ((handler) =>
async function({config}) {
async function ({ config }) {
let result = await this.call({
$raw_output: true,
$handler: handler
$handler: handler,
});
if (!Array.isArray(result)) {
result = [result];
}
if (!config.strict) {
result = result.map(function(res) {
result = result.map(function (res) {
switch (typeof res) {
case 'undefined':
case "undefined":
return false;
case 'boolean':
case "boolean":
return !!res;
case 'number':
case "number":
return !!res;
case 'string':
case "string":
return !!res.length;
case 'object':
case "object":
if (Buffer.isBuffer(res)) {
return !!res.length;
} else if (res === null) {
return false;
} else {
return !!Object.keys(res).length;
}
case 'function':
throw utils.error('NIKITA_ASSERT_INVALID_OUTPUT', ['assertion does not accept functions']);
case "function":
throw utils.error("NIKITA_ASSERT_INVALID_OUTPUT", [
"assertion does not accept functions",
]);
}
});
}
result = !result.some((res) =>
!config.not ? res !== true : res === true
!config.not ? res !== true : res === true,
);
if (result !== true) {
throw utils.error('NIKITA_ASSERT_UNTRUE', ['assertion did not validate,', `got ${JSON.stringify(result)}`]);
throw utils.error("NIKITA_ASSERT_UNTRUE", [
"assertion did not validate,",
`got ${JSON.stringify(result)}`,
]);
}
}
)(action.handler);
}
})(action.handler);
},
},
metadata: {
definitions: definitions
}
definitions: definitions,
},
};
Loading

0 comments on commit 766272a

Please sign in to comment.