Socket
Socket
Sign inDemoInstall

@skills17/task-config

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@skills17/task-config - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

lib/index.browser.d.ts

30

lib/Config.d.ts

@@ -14,16 +14,3 @@ import { TestRun } from '@skills17/test-result';

private groups;
private configPath?;
/**
* Detect the path of the config.json file.
* First, try it from the current file.
* If that can't be found which is the case when installed using a symlink, try it from the cwd.
*/
private static detectPath;
/**
* Detect the path of the config.json file synchronously.
* First, try it from the current file.
* If that can't be found which is the case when installed using a symlink, try it from the cwd.
*/
private static detectPathSync;
/**
* Load groups from the config.json file and create instances of @skills17/test-result

@@ -37,18 +24,6 @@ *

*
* @param fileContent Config file content
* @param config Config object
*/
private initConfigFromFile;
load(config: any): void;
/**
* Load the configuration from a file
*
* @param configPath Path of the config.json file, will be determined automatically if omitted
*/
loadFromFile(configPath?: string): Promise<void>;
/**
* Load the configuration from a file synchronously
*
* @param configPath Path of the config.json file, will be determined automatically if omitted
*/
loadFromFileSync(configPath?: string): void;
/**
* Create a new test run instance from @skills17/test-result for the current config

@@ -65,3 +40,2 @@ */

isLocalHistoryEnabled(): boolean;
getProjectRoot(): string;
}

@@ -8,16 +8,4 @@ "use strict";

var _path = _interopRequireDefault(require("path"));
var _fs = _interopRequireWildcard(require("fs"));
var _findUp = _interopRequireDefault(require("find-up"));
var _testResult = require("@skills17/test-result");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Config {

@@ -40,50 +28,3 @@ source = ['./src/**'];

groups = [];
/**
* Detect the path of the config.json file.
* First, try it from the current file.
* If that can't be found which is the case when installed using a symlink, try it from the cwd.
*/
static async detectPath() {
let configPath = await (0, _findUp.default)('config.json', {
cwd: __dirname
});
if (!configPath) {
configPath = await (0, _findUp.default)('config.json', {
cwd: process.cwd()
});
}
if (!configPath) {
throw new Error('Config file does not exist');
}
return configPath;
}
/**
* Detect the path of the config.json file synchronously.
* First, try it from the current file.
* If that can't be found which is the case when installed using a symlink, try it from the cwd.
*/
static detectPathSync() {
let configPath = _findUp.default.sync('config.json', {
cwd: __dirname
});
if (!configPath) {
configPath = _findUp.default.sync('config.json', {
cwd: process.cwd()
});
}
if (!configPath) {
throw new Error('Config file does not exist');
}
return configPath;
}
/**
* Load groups from the config.json file and create instances of @skills17/test-result

@@ -94,3 +35,2 @@ *

loadGroups(groups) {

@@ -128,9 +68,9 @@ return groups.map((groupConfig, groupIndex) => {

*
* @param fileContent Config file content
* @param config Config object
*/
initConfigFromFile(fileContent) {
const config = JSON.parse(fileContent); // set config
load(config) {
// eslint-disable-line
// set config
this.id = config.id;

@@ -150,29 +90,2 @@ this.type = config.type;

/**
* Load the configuration from a file
*
* @param configPath Path of the config.json file, will be determined automatically if omitted
*/
async loadFromFile(configPath) {
this.configPath = configPath ?? (await Config.detectPath()); // load json file
const fileContent = await _fs.promises.readFile(this.configPath);
this.initConfigFromFile(fileContent.toString());
}
/**
* Load the configuration from a file synchronously
*
* @param configPath Path of the config.json file, will be determined automatically if omitted
*/
loadFromFileSync(configPath) {
this.configPath = configPath ?? Config.detectPathSync(); // load json file
const fileContent = _fs.default.readFileSync(this.configPath);
this.initConfigFromFile(fileContent.toString());
}
/**
* Create a new test run instance from @skills17/test-result for the current config

@@ -220,12 +133,4 @@ */

getProjectRoot() {
if (!this.configPath) {
throw new Error('getProjectRoot() can only be called on a loaded config instance');
}
return _path.default.dirname(this.configPath);
}
}
exports.default = Config;

@@ -1,2 +0,2 @@

export { default } from './Config';
export { default } from './NodeConfig';
export { default as Points } from './types/Points';

@@ -3,0 +3,0 @@ export { default as RawGroup } from './types/RawGroup';

@@ -9,3 +9,3 @@ "use strict";

get: function () {
return _Config.default;
return _NodeConfig.default;
}

@@ -38,3 +38,3 @@ });

var _Config = _interopRequireDefault(require("./Config"));
var _NodeConfig = _interopRequireDefault(require("./NodeConfig"));

@@ -41,0 +41,0 @@ var _Points = _interopRequireDefault(require("./types/Points"));

{
"name": "@skills17/task-config",
"version": "2.0.1",
"version": "2.1.0",
"description": "Parses and validates a task configuration file.",
"main": "lib/index.js",
"browser": "lib/index.browser.js",
"files": [

@@ -7,0 +8,0 @@ "lib"

@@ -9,2 +9,3 @@ # skills17/task-config

- [Usage](#usage)
- [Browser](#browser)
- [Configuration](#configuration)

@@ -54,2 +55,21 @@ - [License](#license)

### Browser
It is also possible to use this library in a browser.
Webpack and other bundlers should automatically pick the correct files.
If you are not using a bundler, make sure to use the `lib/index.browser.js` file.
Since the browser does not have access to the filesytem, it cannot load the `config.json` automatically.
Instead, you have to pass the configuration object directly to the load method:
```typescript
import Config from '@skills17/task-config';
const config = new Config();
await config.load({ points: { defaultPoints: 2 }, groups: [ /* ... */ ] });
```
From then on, the same methods can be used as within a node environment, except the `getProjectRoot()`
method is not available.
## Configuration

@@ -56,0 +76,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc