webext-schema
Advanced tools
Comparing version 1.5.3 to 2.0.0-a.1
12
index.js
/** | ||
* index.js | ||
*/ | ||
'use strict'; | ||
/* api */ | ||
const { Schema } = require('./modules/schema'); | ||
const { logErr, throwErr } = require('./modules/common'); | ||
const { parseCommand } = require('./modules/update'); | ||
const process = require('process'); | ||
import { Schema } from './modules/schema.js'; | ||
import { logErr, throwErr } from './modules/common.js'; | ||
import { parseCommand } from './modules/update.js'; | ||
import process from 'process'; | ||
@@ -17,4 +17,4 @@ /* process */ | ||
module.exports = { | ||
export { | ||
Schema | ||
}; |
/** | ||
* common.js | ||
*/ | ||
'use strict'; | ||
/* constants */ | ||
@@ -15,3 +15,3 @@ const TYPE_FROM = 8; | ||
*/ | ||
const throwErr = e => { | ||
export const throwErr = e => { | ||
throw e; | ||
@@ -26,3 +26,3 @@ }; | ||
*/ | ||
const logErr = e => { | ||
export const logErr = e => { | ||
console.error(e); | ||
@@ -38,3 +38,3 @@ return false; | ||
*/ | ||
const logWarn = msg => { | ||
export const logWarn = msg => { | ||
msg && console.warn(msg); | ||
@@ -50,3 +50,3 @@ return false; | ||
*/ | ||
const logMsg = msg => { | ||
export const logMsg = msg => { | ||
msg && console.log(msg); | ||
@@ -62,3 +62,3 @@ return msg; | ||
*/ | ||
const getType = o => | ||
export const getType = o => | ||
Object.prototype.toString.call(o).slice(TYPE_FROM, TYPE_TO); | ||
@@ -72,3 +72,3 @@ | ||
*/ | ||
const isObjectNotEmpty = o => { | ||
export const isObjectNotEmpty = o => { | ||
const items = /Object/i.test(getType(o)) && Object.keys(o); | ||
@@ -84,3 +84,3 @@ return !!(items && items.length); | ||
*/ | ||
const isString = o => typeof o === 'string' || o instanceof String; | ||
export const isString = o => typeof o === 'string' || o instanceof String; | ||
@@ -94,3 +94,3 @@ /** | ||
*/ | ||
const stringifyPositiveInt = (i, zero = false) => | ||
export const stringifyPositiveInt = (i, zero = false) => | ||
Number.isSafeInteger(i) && ((zero && i >= 0) || i > 0) ? `${i}` : null; | ||
@@ -105,3 +105,3 @@ | ||
*/ | ||
const escapeChar = (str, re) => | ||
export const escapeChar = (str, re) => | ||
isString(str) && re && re.global ? str.replace(re, (m, c) => `\\${c}`) : null; | ||
@@ -115,3 +115,3 @@ | ||
*/ | ||
const stripHtmlTags = v => { | ||
export const stripHtmlTags = v => { | ||
while (/^\n*<(?:[^>]+:)?[^>]+?>|<\/(?:[^>]+:)?[^>]+>\n*$/.test(v)) { | ||
@@ -125,14 +125,1 @@ v = v.replace(/^\n*<(?:[^>]+:)?[^>]+?>/, '') | ||
}; | ||
module.exports = { | ||
escapeChar, | ||
getType, | ||
isObjectNotEmpty, | ||
isString, | ||
logErr, | ||
logMsg, | ||
logWarn, | ||
stringifyPositiveInt, | ||
stripHtmlTags, | ||
throwErr | ||
}; |
/** | ||
* constants.js | ||
*/ | ||
'use strict'; | ||
/* api */ | ||
const os = require('os'); | ||
import os from 'os'; | ||
/* constants */ | ||
const CHAR = 'utf8'; | ||
const DIR_HOME = os.homedir(); | ||
const INDENT = 2; | ||
const IS_BE = os.endianness() === 'BE'; | ||
const IS_LE = os.endianness() === 'LE'; | ||
const IS_MAC = os.platform() === 'darwin'; | ||
const IS_WIN = os.platform() === 'win32'; | ||
module.exports = { | ||
CHAR, DIR_HOME, INDENT, IS_BE, IS_LE, IS_MAC, IS_WIN | ||
}; | ||
export const CHAR = 'utf8'; | ||
export const DIR_HOME = os.homedir(); | ||
export const INDENT = 2; | ||
export const IS_BE = os.endianness() === 'BE'; | ||
export const IS_LE = os.endianness() === 'LE'; | ||
export const IS_MAC = os.platform() === 'darwin'; | ||
export const IS_WIN = os.platform() === 'win32'; |
/** | ||
* file-util.js | ||
*/ | ||
'use strict'; | ||
/* api */ | ||
const { URL, fileURLToPath } = require('url'); | ||
const { getType, isString } = require('./common'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { promises: fsPromise } = fs; | ||
import { IS_WIN } from './constant.js'; | ||
import { URL, fileURLToPath } from 'url'; | ||
import { getType, isString } from './common.js'; | ||
import fs, { promises as fsPromise } from 'fs'; | ||
import path from 'path'; | ||
/* constants */ | ||
const { IS_WIN } = require('./constant'); | ||
const MASK_BIT = 0o111; | ||
@@ -25,3 +24,3 @@ const PERM_DIR = 0o777; | ||
*/ | ||
const convertUriToFilePath = uri => { | ||
export const convertUriToFilePath = uri => { | ||
if (!isString(uri)) { | ||
@@ -44,3 +43,3 @@ throw new TypeError(`Expected String but got ${getType(uri)}.`); | ||
*/ | ||
const getAbsPath = file => { | ||
export const getAbsPath = file => { | ||
if (!isString(file)) { | ||
@@ -59,3 +58,3 @@ throw new TypeError(`Expected String but got ${getType(file)}.`); | ||
*/ | ||
const getStat = file => | ||
export const getStat = file => | ||
isString(file) && fs.existsSync(file) ? fs.statSync(file) : null; | ||
@@ -69,3 +68,3 @@ | ||
*/ | ||
const isDir = dir => { | ||
export const isDir = dir => { | ||
const stat = getStat(dir); | ||
@@ -82,3 +81,3 @@ return stat ? stat.isDirectory() : false; | ||
*/ | ||
const isSubDir = (dir, baseDir) => | ||
export const isSubDir = (dir, baseDir) => | ||
isDir(dir) && isDir(baseDir) && dir.startsWith(baseDir); | ||
@@ -92,3 +91,3 @@ | ||
*/ | ||
const isFile = file => { | ||
export const isFile = file => { | ||
const stat = getStat(file); | ||
@@ -107,3 +106,3 @@ return stat ? stat.isFile() : false; | ||
*/ | ||
const isExecutable = (file, mask = MASK_BIT) => { | ||
export const isExecutable = (file, mask = MASK_BIT) => { | ||
let res; | ||
@@ -124,3 +123,3 @@ const stat = getStat(file); | ||
*/ | ||
const getFileTimestamp = file => { | ||
export const getFileTimestamp = file => { | ||
const stat = getStat(file); | ||
@@ -137,3 +136,3 @@ return stat ? stat.mtime.getTime() : 0; | ||
*/ | ||
const getFileNameFromFilePath = (file, subst = SUBST) => { | ||
export const getFileNameFromFilePath = (file, subst = SUBST) => { | ||
let name; | ||
@@ -154,3 +153,3 @@ if (isString(file) && isFile(file) && | ||
*/ | ||
const removeDir = (dir, baseDir) => { | ||
export const removeDir = (dir, baseDir) => { | ||
if (isDir(dir)) { | ||
@@ -180,3 +179,3 @@ if (!isSubDir(dir, baseDir)) { | ||
*/ | ||
const removeDirectory = async (dir, baseDir) => { | ||
export const removeDirectory = async (dir, baseDir) => { | ||
await removeDir(dir, baseDir); | ||
@@ -192,3 +191,3 @@ }; | ||
*/ | ||
const createDirectory = async (dir, mode = PERM_DIR) => { | ||
export const createDirectory = async (dir, mode = PERM_DIR) => { | ||
if (!isString(dir)) { | ||
@@ -220,3 +219,3 @@ throw new TypeError(`Expected String but got ${getType(dir)}.`); | ||
*/ | ||
const createFile = async (file, value, opt = { | ||
export const createFile = async (file, value, opt = { | ||
encoding: null, flag: 'w', mode: PERM_FILE | ||
@@ -247,3 +246,3 @@ }) => { | ||
*/ | ||
const readFile = async (file, opt = { encoding: null, flag: 'r' }) => { | ||
export const readFile = async (file, opt = { encoding: null, flag: 'r' }) => { | ||
if (!isFile(file)) { | ||
@@ -255,18 +254,1 @@ throw new Error(`${file} is not a file.`); | ||
}; | ||
module.exports = { | ||
convertUriToFilePath, | ||
createDirectory, | ||
createFile, | ||
getAbsPath, | ||
getFileNameFromFilePath, | ||
getFileTimestamp, | ||
getStat, | ||
isDir, | ||
isExecutable, | ||
isFile, | ||
isSubDir, | ||
removeDir, | ||
removeDirectory, | ||
readFile | ||
}; |
/** | ||
* schema.js | ||
*/ | ||
'use strict'; | ||
/* api */ | ||
const { getType, isObjectNotEmpty, isString } = require('./common'); | ||
const camelize = require('camelize'); | ||
const decamelize = require('decamelize'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const sinon = require('sinon'); | ||
import { CHAR } from './constant.js'; | ||
import { convertUriToFilePath } from './file-util.js'; | ||
import { getType, isObjectNotEmpty, isString } from './common.js'; | ||
import camelize from 'camelize'; | ||
import decamelize from 'decamelize'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import sinon from 'sinon'; | ||
/* constants */ | ||
const { CHAR } = require('./constant'); | ||
class Schema { | ||
export class Schema { | ||
/** | ||
@@ -270,5 +269,4 @@ * construct | ||
const fileName = this._channel === 'mail' ? 'mailext.json' : 'webext.json'; | ||
const file = path.resolve( | ||
path.join(__dirname, '../', 'schemas', this._channel, fileName) | ||
); | ||
const dirName = path.dirname(convertUriToFilePath(import.meta.url)); | ||
const file = path.join(dirName, '../', 'schemas', this._channel, fileName); | ||
const content = fs.readFileSync(file, { | ||
@@ -383,5 +381,1 @@ encoding: CHAR, | ||
} | ||
module.exports = { | ||
Schema | ||
}; |
/** | ||
* update.js | ||
*/ | ||
'use strict'; | ||
/* api */ | ||
const { URL } = require('url'); | ||
const JSON5 = require('json5'); | ||
const { createFile } = require('./file-util'); | ||
const { getType, isString, throwErr } = require('./common'); | ||
const { version } = require('../package.json'); | ||
const commander = require('commander'); | ||
const fetch = require('node-fetch'); | ||
const path = require('path'); | ||
const process = require('process'); | ||
import { CHAR, INDENT } from './constant.js'; | ||
import { URL } from 'url'; | ||
import JSON5 from 'json5'; | ||
import { createFile } from './file-util.js'; | ||
import { getType, isString, throwErr } from './common.js'; | ||
import commander from 'commander'; | ||
import fetch from 'node-fetch'; | ||
import path from 'path'; | ||
import process from 'process'; | ||
/* constants */ | ||
const { CHAR, INDENT } = require('./constant'); | ||
const DIR_CWD = process.cwd(); | ||
const PERM_FILE = 0o644; | ||
const ESR_VER = 91; | ||
export const ESR_VER = 91; | ||
@@ -28,3 +27,3 @@ /** | ||
*/ | ||
const fetchText = async url => { | ||
export const fetchText = async url => { | ||
if (!isString(url)) { | ||
@@ -48,3 +47,3 @@ throw new TypeError(`Expected String but got ${getType(url)}.`); | ||
*/ | ||
const getChannelUrl = channel => { | ||
export const getChannelUrl = channel => { | ||
let dir; | ||
@@ -77,3 +76,3 @@ switch (channel) { | ||
*/ | ||
const getSchemaData = async (file, baseUrl) => { | ||
export const getSchemaData = async (file, baseUrl) => { | ||
if (!isString(file)) { | ||
@@ -99,3 +98,3 @@ throw new TypeError(`Expected String but got ${getType(file)}.`); | ||
*/ | ||
const getFileList = async baseUrl => { | ||
export const getFileList = async baseUrl => { | ||
if (!isString(baseUrl)) { | ||
@@ -126,3 +125,3 @@ throw new TypeError(`Expected String but got ${getType(baseUrl)}.`); | ||
*/ | ||
const getAllSchemaData = async baseUrl => { | ||
export const getAllSchemaData = async baseUrl => { | ||
if (!isString(baseUrl)) { | ||
@@ -146,3 +145,3 @@ throw new TypeError(`Expected String but got ${getType(baseUrl)}.`); | ||
*/ | ||
const getListedSchemaData = async (baseUrl, arr) => { | ||
export const getListedSchemaData = async (baseUrl, arr) => { | ||
if (!isString(baseUrl)) { | ||
@@ -167,3 +166,3 @@ throw new TypeError(`Expected String but got ${getType(baseUrl)}.`); | ||
*/ | ||
const getMailExtSchemaData = async baseUrl => { | ||
export const getMailExtSchemaData = async baseUrl => { | ||
if (!isString(baseUrl)) { | ||
@@ -193,3 +192,3 @@ throw new TypeError(`Expected String but got ${getType(baseUrl)}.`); | ||
*/ | ||
const createUnifiedSchema = async channel => { | ||
export const createUnifiedSchema = async channel => { | ||
const channelUrl = getChannelUrl(channel); | ||
@@ -238,3 +237,3 @@ const schema = {}; | ||
*/ | ||
const saveSchemaFile = async (channel, info) => { | ||
export const saveSchemaFile = async (channel, info) => { | ||
if (!isString(channel)) { | ||
@@ -263,3 +262,3 @@ throw new TypeError(`Expected String but got ${getType(channel)}.`); | ||
*/ | ||
const updateSchemas = (cmdOpts = {}) => { | ||
export const updateSchemas = (cmdOpts = {}) => { | ||
const { channel, info } = cmdOpts; | ||
@@ -287,7 +286,7 @@ const func = []; | ||
*/ | ||
const parseCommand = args => { | ||
export const parseCommand = args => { | ||
const reg = /^(?:(?:--)?help|-[h|v]|--version|u(?:pdate)?)$/; | ||
if (Array.isArray(args) && args.some(arg => reg.test(arg))) { | ||
commander.exitOverride(); | ||
commander.version(version, '-v, --version'); | ||
commander.version(process.env.npm_package_version, '-v, --version'); | ||
commander.command('update').alias('u').description('update schemas') | ||
@@ -297,24 +296,8 @@ .option('-c, --channel <name>', 'specify the release channel') | ||
.action(updateSchemas); | ||
try { | ||
commander.parse(args); | ||
} catch (e) { | ||
// fail through | ||
} | ||
commander.parse(args); | ||
} | ||
}; | ||
module.exports = { | ||
ESR_VER, | ||
commander, | ||
createUnifiedSchema, | ||
fetchText, | ||
getAllSchemaData, | ||
getChannelUrl, | ||
getFileList, | ||
getListedSchemaData, | ||
getMailExtSchemaData, | ||
getSchemaData, | ||
parseCommand, | ||
saveSchemaFile, | ||
updateSchemas | ||
export { | ||
commander | ||
}; |
@@ -13,6 +13,7 @@ { | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"lint": "eslint --fix .", | ||
"start": "node index", | ||
"test": "nyc --reporter=text mocha test/*.test.js --exit", | ||
"test": "c8 --reporter=text mocha test/*.test.js --exit", | ||
"update": "node index update -i", | ||
@@ -27,9 +28,10 @@ "update:beta": "node index update -c beta -i", | ||
"camelize": "^1.0.0", | ||
"commander": "^8.1.0", | ||
"commander": "^8.2.0", | ||
"decamelize": "^5.0.0", | ||
"json5": "^2.2.0", | ||
"node-fetch": "^2.6.2", | ||
"node-fetch": "^3.0.0", | ||
"sinon": "^11.1.2" | ||
}, | ||
"devDependencies": { | ||
"c8": "^7.9.0", | ||
"chai": "^4.3.4", | ||
@@ -39,9 +41,9 @@ "eslint": "^7.32.0", | ||
"eslint-plugin-import": "^2.24.2", | ||
"eslint-plugin-jsdoc": "^36.0.8", | ||
"eslint-plugin-jsdoc": "^36.1.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"mocha": "^9.1.1", | ||
"nyc": "^15.1.0" | ||
"nock": "^13.1.3" | ||
}, | ||
"version": "1.5.3" | ||
"version": "2.0.0-a.1" | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4786465
15
Yes
10
92177
1
3
+ Addeddata-uri-to-buffer@4.0.1(transitive)
+ Addedfetch-blob@3.2.0(transitive)
+ Addedformdata-polyfill@4.0.10(transitive)
+ Addednode-domexception@1.0.0(transitive)
+ Addednode-fetch@3.3.2(transitive)
+ Addedweb-streams-polyfill@3.3.3(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
Updatedcommander@^8.2.0
Updatednode-fetch@^3.0.0