Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:functional-jslib/fjl into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
elycruz committed Jun 1, 2024
2 parents 9d184f1 + 7cb936f commit abab433
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 89 deletions.
6 changes: 4 additions & 2 deletions .puppeteerrc.cjs → .puppeteerrc.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const path = require('path');
import path from 'path';

module.exports = {
const __dirname = path.dirname(new URL(import.meta.url).pathname);

export default {
// args: ['--disable-setuid-sandbox', '--no-sandbox'],
headless: true,
cacheDirectory: path.join(path.resolve(__dirname), './.cache')
Expand Down
4 changes: 2 additions & 2 deletions jest-puppeteer.config.js → jest-puppeteer.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const packageJson = require('./package.json');
import packageJson from './package.json';

module.exports = {
export default {
executablePath: process.env?.PUPPETEER_EXE_PATH, // Browser executable path
server: {
command: packageJson.mockServerCommand,
Expand Down
10 changes: 6 additions & 4 deletions jest.config.js → jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const path = require('path'),
testMatch = [
import path from 'path';

const testMatch = [
'**/(tests|src)/**/*@(.test|_test|.spec).@(ts|js)',
'**/tests/**/test-*.@(ts|js)',
],
transform = {
'\\.ts$': 'ts-jest'
}
},
__dirname = path.dirname(new URL(import.meta.url).pathname)
;

module.exports = {
export default {
preset: 'ts-jest',
collectCoverage: true,
testEnvironment: 'node',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const
import path from "node:path";
import {ioSpawn} from '../utils/index.mjs';

path = require('path'),

{log, error} = console,
const {log, error} = console,

{ioSpawn} = require('../utils'),
__dirname = path.dirname(new URL(import.meta.url).pathname),

repoRoot = path.join(__dirname, '../../'),

taskGroupSeparator = '---------------------------\n\n'

;

/**
Expand Down
3 changes: 0 additions & 3 deletions node_scripts/utils/index.js

This file was deleted.

1 change: 1 addition & 0 deletions node_scripts/utils/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ioUtils.mjs';
25 changes: 8 additions & 17 deletions node_scripts/utils/ioUtils.js → node_scripts/utils/ioUtils.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const
fs = require('fs'),
os = require('os'),
child_process = require('child_process'),
{exec, spawn} = child_process,
{log, warn} = console,
import fs from 'fs';
import os from 'os';
import { exec, spawn } from 'child_process';

npmCmd = os.platform().indexOf('win') === 0 ? 'npm.cmd' : 'npm',
const {log, warn} = console;

export const npmCmd = os.platform().indexOf('win') === 0 ? 'npm.cmd' : 'npm',

ioExec = (cmd, options) => new Promise((resolve, reject) => {
const p = exec(cmd, options, (err, stdout, stderr) => {
Expand Down Expand Up @@ -53,14 +52,6 @@ const
})
;

module.exports = {
ioExec,
ioFileExists,
canWriteFileIo,
canReadFileIo,
canReadAndExistsFileIo,
canReadAndWriteFileIo,
ioPassTailThroughAndContinue: ioExecuteAndPassThrough,
ioSpawn,
npmCmd
export {
ioExecuteAndPassThrough as ioPassTailThroughAndContinue,
};
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
"scripts": {
"build": "rollup --config rollup.config.mjs",
"eslint": "eslint -c .eslintrc.json .",
"link-packages": "node node_scripts/tasks/link-packages.js",
"link-packages": "node node_scripts/tasks/link-packages.mjs",
"lint": "pnpm eslint",
"lintfix": "pnpm eslint --fix",
"lint-staged": "lint-staged",
"prepare": "husky",
"test": "jest -c jest.config.js",
"test:fjl": "jest -c jest.config.js --selectProjects fjl",
"test:fjl-filter": "jest --c jest.config.js --selectProjects fjl-filter",
"test:fjl-inputfilter": "jest -c jest.config.js --selectProjects fjl-inputfilter",
"test:fjl-validator": "jest -c jest.config.js --selectProjects fjl-validator",
"test:fjl-validator-recaptcha": "jest -c jest.config.js --selectProjects fjl-validator-recaptcha",
"test:staged": "jest -c jest.config.js --bail --findRelatedTests"
"test": "jest -c jest.config.mjs",
"test:fjl": "jest -c jest.config.mjs --selectProjects fjl",
"test:fjl-filter": "jest --c jest.config.mjs --selectProjects fjl-filter",
"test:fjl-inputfilter": "jest -c jest.config.mjs --selectProjects fjl-inputfilter",
"test:fjl-validator": "jest -c jest.config.mjs --selectProjects fjl-validator",
"test:fjl-validator-recaptcha": "jest -c jest.config.mjs --selectProjects fjl-validator-recaptcha",
"test:staged": "jest -c jest.config.mjs --bail --findRelatedTests"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/**
* Created by elydelacruz on 6/10/16.
* @module fjlValidatorReCaptcha
* @recaptchaVersion v2
* @reference see below:
* @see https://developers.google.com/recaptcha/docs/
* @see https://developers.google.com/recaptcha/docs/verify
* @todo Request handlers should be separated out from inlined definitions
*/
const https = require('https'),
querystring = require('querystring'),
{getErrorMsgByKey: getErrorMessageByKey, toValidationResult, toValidationOptions} = require('fjl-validator'),
{assign, assignDeep, isEmpty, defineEnumProps} = require('fjl');
import https from 'https';
import querystring from 'querystring';
import { getErrorMsgByKey as getErrorMessageByKey, toValidationResult, toValidationOptions } from 'fjl-validator';
import { assign, assignDeep, isEmpty, defineEnumProps } from 'fjl';

/**
* @memberOf module:fjlValidatorReCaptcha
Expand Down Expand Up @@ -258,7 +257,7 @@ const MISSING_INPUT_SECRET = 'missing-input-secret',
$reCaptchaValidatorV2 = (options) =>
(value) => reCaptchaIOValidator(options, value);

module.exports = {
export {
MISSING_INPUT_SECRET,
MISSING_INPUT_RESPONSE,
INVALID_INPUT_RESPONSE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,25 @@
* @script
* @standalone
*/
import path from "node:path";
import express from 'express';
import helmet from 'helmet';
import session from 'express-session';
import compression from 'compression';
import bodyParser from 'body-parser';
import { log, jsonClone } from 'fjl';
import { reCaptchaIOValidator } from '../src';

// If 'NODE_ENV' not set, set it
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'dev';
}
import { appSessionSecret, mockServerPort as port } from '../../../package.json';

const isDevEnv = process.env.NODE_ENV.toLowerCase().indexOf('dev') === 0;
const __dirname = path.dirname(new URL(import.meta.url).pathname);

// If dev mode load local environment config
if (isDevEnv) {
require('dotenv').config();
}
const isDevEnv = (process.env.NODE_ENV ?? 'dev').toLowerCase().includes('dev');

// Preliminaries
const {appSessionSecret = 'Supercalifragilisticexpialidocious'} = process.env,
{mockServerPort: port} = require('../../../package'),
express = require('express'),
helmet = require('helmet'),
session = require('express-session'),
compression = require('compression'),
bodyParser = require('body-parser'),
router = new express.Router(),
const router = new express.Router(),
app = express();

const {log, jsonClone} = require('fjl');

const {reCaptchaIOValidator} = require('../src/index');

// Security features
// @see https://expressjs.com/en/advanced/best-practice-security.html#use-helmet
app.use(helmet());
Expand Down
29 changes: 14 additions & 15 deletions packages/fjl-validator-recaptcha/tests/test-reCaptchaValidator.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
const {
reCaptchaIOValidator,
toReCaptchaValidatorOptions,
toReCaptchaTestValue,
MISSING_INPUT_SECRET,
MISSING_INPUT_RESPONSE
} = require('../src/index'),

{log, error, runHasPropTypes} = require('./utils'),
packageJson = require('../package.json'),
puppeteerConfig = require('../../../.puppeteerrc.cjs'),
puppeteer = require('puppeteer'),
{waitFor} = require('./utils');
import {
reCaptchaIOValidator,
toReCaptchaValidatorOptions,
toReCaptchaTestValue,
MISSING_INPUT_SECRET,
MISSING_INPUT_RESPONSE
} from '../src/index';

import { mockServerPort } from '../../../package.json';
import { log, error, runHasPropTypes } from './utils';
import packageJson from '../package.json';
import puppeteerConfig from '../../../.puppeteerrc';
import puppeteer from 'puppeteer';
import { waitFor } from './utils';

const {recaptchaKeys} = packageJson,
{mockServerPort} = require('../../../package.json'),

unhandledHandler = e => {
console.error(e);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {log, error, peek, range} = require('fjl');
import { log, error, peek, range } from 'fjl';

const

Expand Down Expand Up @@ -39,4 +39,4 @@ const

;

module.exports = {log, error, peek, jsonClone, genRan, genRanChar, genRanStr, runHasPropTypes, runHasPropOfType, waitFor};
export {log, error, peek, jsonClone, genRan, genRanChar, genRanStr, runHasPropTypes, runHasPropOfType, waitFor};
7 changes: 3 additions & 4 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import path from 'node:path';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';

const

__dirname = path.dirname(new URL(import.meta.url).pathname),
const __dirname = path.dirname(new URL(import.meta.url).pathname),

{log, error} = console,

Expand Down Expand Up @@ -85,7 +83,8 @@ await Promise.all(projectNames.map(projectName => {

// Delete files in 'dist/' paths for each project
return fs.readdir(distPath)
.then(files => files.map(file => {
.catch(() => [])
.then(files => files?.map(file => {
const filePath = path.join(distPath, file);
const projectPath = `./${filePath.split(__dirname)[1]}`;
return fs.rm(filePath, {recursive: true})
Expand Down

0 comments on commit abab433

Please sign in to comment.