feat(utils): Add jest-yaml-transform package.

This commit is contained in:
Gervwyk 2022-05-30 17:37:39 +02:00
parent ac9e07ef19
commit dd9dbe4989
4 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,7 @@
{
"exclude": [".*.test.js$", ".*/tests/.*", ".*/__mocks__/.*"],
"$schema": "http://json.schemastore.org/swcrc",
"module": {
"type": "commonjs"
}
}

View File

@ -0,0 +1,3 @@
# @lowdefy/jest-yaml-transform
A jest transformer for YAML based off: https://github.com/sumwatshade/jest-transform-yaml

View File

@ -0,0 +1,44 @@
{
"name": "@lowdefy/jest-yaml-transform",
"version": "4.0.0-alpha.12",
"licence": "Apache-2.0",
"description": "A Jest Transform for YAML.",
"main": "./dist/index.js",
"homepage": "https://lowdefy.com",
"keywords": [
"lowdefy",
"yaml",
"jest",
"jest-transform",
"jest-yaml-transform"
],
"bugs": {
"url": "https://github.com/lowdefy/lowdefy/issues"
},
"contributors": [
{
"name": "Gerrie van Wyk",
"url": "https://github.com/Gervwyk"
}
],
"repository": {
"type": "git",
"url": "https://github.com/lowdefy/lowdefy.git"
},
"scripts": {
"build": "yarn swc",
"clean": "rm -rf dist",
"prepare": "yarn build",
"swc": "swc src --out-dir dist --config-file ./.swcrc --delete-dir-on-start"
},
"dependencies": {
"@swc/cli": "0.1.57",
"@swc/core": "1.2.194",
"@swc/jest": "0.2.21",
"jest": "28.1.0",
"yaml": "2.1.1"
},
"publishConfig": {
"access": "public"
}
}

View File

@ -0,0 +1,34 @@
/*
Copyright 2020-2022 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import YAML from 'yaml';
import crypto from 'crypto';
function getCacheKey(fileData, filePath, options) {
const optionsString = typeof options === 'string' ? options : JSON.stringify(options);
return crypto.createHash('md5').update(fileData).update(optionsString).digest('hex');
}
function process(sourceText) {
return { code: `module.exports = ${JSON.stringify(YAML.parse(sourceText), null, '\t')}` };
}
const transformer = {
getCacheKey,
process,
};
export default transformer;