fix: move file helpers to new node-utils package

This commit is contained in:
Sam Tolmay 2020-10-23 13:18:38 +02:00
parent 1159ac71e7
commit 0a6ef8d09b
27 changed files with 149 additions and 26 deletions

27
.pnp.js generated
View File

@ -58,6 +58,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
"name": "@lowdefy/layout",
"reference": "workspace:packages/layout"
},
{
"name": "@lowdefy/node-utils",
"reference": "workspace:packages/nodeUtils"
},
{
"name": "@lowdefy/nunjucks",
"reference": "workspace:packages/nunjucks"
@ -84,6 +88,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@lowdefy/helpers", ["workspace:packages/helpers"]],
["@lowdefy/layout", ["workspace:packages/layout"]],
["@lowdefy/lowdefy", ["workspace:."]],
["@lowdefy/node-utils", ["workspace:packages/nodeUtils"]],
["@lowdefy/nunjucks", ["workspace:packages/nunjucks"]],
["@lowdefy/operators", ["workspace:packages/operators"]],
["@lowdefy/renderer", ["workspace:packages/renderer"]]
@ -3670,6 +3675,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@babel/core", "npm:7.12.3"],
["@babel/preset-env", "virtual:4a7337632ff6e9ee5a1c45a62a9ff4cc325a9367b21424babda93e269fe01b671e885bc41bdeebafb83c81f2a8eebbf0102043354a4e58905f61c8c3387cda1e#npm:7.12.1"],
["@lowdefy/helpers", "workspace:packages/helpers"],
["@lowdefy/node-utils", "workspace:packages/nodeUtils"],
["@lowdefy/nunjucks", "workspace:packages/nunjucks"],
["ajv", "npm:6.12.6"],
["axios", "npm:0.20.0"],
@ -3771,6 +3777,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@babel/core", "npm:7.12.3"],
["@babel/preset-env", "virtual:4a7337632ff6e9ee5a1c45a62a9ff4cc325a9367b21424babda93e269fe01b671e885bc41bdeebafb83c81f2a8eebbf0102043354a4e58905f61c8c3387cda1e#npm:7.12.1"],
["@lowdefy/helpers", "workspace:packages/helpers"],
["@lowdefy/node-utils", "workspace:packages/nodeUtils"],
["apollo-server", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:2.18.2"],
["apollo-server-testing", "virtual:7fa6405098723f150ab741c1e73c906de11a676b4cc641bac8b3397ea2dd6efbb913e72a780932220533241b442cc586b41b26c7b5ac786de486992cd2db054c#npm:2.18.2"],
["babel-jest", "virtual:4a7337632ff6e9ee5a1c45a62a9ff4cc325a9367b21424babda93e269fe01b671e885bc41bdeebafb83c81f2a8eebbf0102043354a4e58905f61c8c3387cda1e#npm:26.5.2"],
@ -3797,8 +3804,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["jest", "npm:26.5.3"],
["jest-diff", "npm:26.5.2"],
["lodash.merge", "npm:4.6.2"],
["query-string", "npm:6.13.6"],
["rimraf", "npm:3.0.2"]
["query-string", "npm:6.13.6"]
],
"linkType": "SOFT",
}]
@ -3863,6 +3869,23 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
"linkType": "SOFT",
}]
]],
["@lowdefy/node-utils", [
["workspace:packages/nodeUtils", {
"packageLocation": "./packages/nodeUtils/",
"packageDependencies": [
["@lowdefy/node-utils", "workspace:packages/nodeUtils"],
["@babel/cli", "virtual:4a7337632ff6e9ee5a1c45a62a9ff4cc325a9367b21424babda93e269fe01b671e885bc41bdeebafb83c81f2a8eebbf0102043354a4e58905f61c8c3387cda1e#npm:7.12.1"],
["@babel/core", "npm:7.12.3"],
["@babel/preset-env", "virtual:4a7337632ff6e9ee5a1c45a62a9ff4cc325a9367b21424babda93e269fe01b671e885bc41bdeebafb83c81f2a8eebbf0102043354a4e58905f61c8c3387cda1e#npm:7.12.1"],
["@lowdefy/helpers", "workspace:packages/helpers"],
["babel-jest", "virtual:4a7337632ff6e9ee5a1c45a62a9ff4cc325a9367b21424babda93e269fe01b671e885bc41bdeebafb83c81f2a8eebbf0102043354a4e58905f61c8c3387cda1e#npm:26.5.2"],
["jest", "npm:26.5.3"],
["jest-diff", "npm:26.5.2"],
["rimraf", "npm:3.0.2"]
],
"linkType": "SOFT",
}]
]],
["@lowdefy/nunjucks", [
["workspace:packages/nunjucks", {
"packageLocation": "./packages/nunjucks/",

View File

@ -29,6 +29,7 @@
},
"dependencies": {
"@lowdefy/helpers": "1.1.0",
"@lowdefy/node-utils": "1.0.0",
"@lowdefy/nunjucks": "1.0.0",
"ajv": "6.12.6",
"axios": "0.20.0",

View File

@ -14,7 +14,8 @@
limitations under the License.
*/
import { get, getFileExtension, getFileSubExtension, type } from '@lowdefy/helpers';
import { get, type } from '@lowdefy/helpers';
import { getFileExtension, getFileSubExtension } from '@lowdefy/node-utils';
import { nunjucksFunction } from '@lowdefy/nunjucks';
import JSON5 from 'json5';
import YAML from 'js-yaml';

View File

@ -14,7 +14,7 @@
limitations under the License.
*/
import { cleanDirectory } from '@lowdefy/helpers';
import { cleanDirectory } from '@lowdefy/node-utils';
async function cleanOutputDirectory({ context }) {
return cleanDirectory(context.outputDirectory);

View File

@ -14,10 +14,10 @@
limitations under the License.
*/
import { cleanDirectory } from '@lowdefy/helpers';
import { cleanDirectory } from '@lowdefy/node-utils';
import cleanOutputDirectory from './cleanOutputDirectory';
jest.mock('@lowdefy/helpers', () => {
jest.mock('@lowdefy/node-utils', () => {
return {
cleanDirectory: jest.fn(),
};

View File

@ -15,7 +15,7 @@
*/
import path from 'path';
import { writeFile } from '@lowdefy/helpers';
import { writeFile } from '@lowdefy/node-utils';
class FileSetter {
constructor({ baseDirectory }) {

View File

@ -16,7 +16,8 @@
import JSON5 from 'json5';
import YAML from 'js-yaml';
import { getFileExtension, readFile, type } from '@lowdefy/helpers';
import { type } from '@lowdefy/helpers';
import { getFileExtension, readFile } from '@lowdefy/node-utils';
async function getJsonFile(filePath) {
const file = await readFile(filePath);

View File

@ -15,7 +15,7 @@
*/
import path from 'path';
import { readFile } from '@lowdefy/helpers';
import { readFile } from '@lowdefy/node-utils';
import createCacheKey from './createCacheKey';
function createFetchMetaCache({ cacheDirectory }) {

View File

@ -15,7 +15,7 @@
*/
import path from 'path';
import { writeFile } from '@lowdefy/helpers';
import { writeFile } from '@lowdefy/node-utils';
import createCacheKey from './createCacheKey';
function createWriteMetaCache({ cacheDirectory }) {

View File

@ -29,6 +29,7 @@
},
"dependencies": {
"@lowdefy/helpers": "1.1.0",
"@lowdefy/node-utils": "1.0.0",
"apollo-server": "2.18.2",
"dataloader": "2.0.0",
"graphql": "15.3.0",

View File

@ -14,7 +14,7 @@
limitations under the License.
*/
import { readFile } from '@lowdefy/helpers';
import { readFile } from '@lowdefy/node-utils';
import { ConfigurationError } from '../context/errors';
async function readJsonFile({ filePath }) {

View File

@ -31,8 +31,7 @@
},
"dependencies": {
"lodash.merge": "4.6.2",
"query-string": "6.13.6",
"rimraf": "3.0.2"
"query-string": "6.13.6"
},
"devDependencies": {
"@babel/cli": "7.12.1",

View File

@ -15,12 +15,9 @@
*/
import applyArrayIndices from './applyArrayIndices';
import cleanDirectory from './cleanDirectory';
import get from './get';
import getFileExtension, { getFileSubExtension } from './getFileExtension';
import mergeObjects from './mergeObjects';
import omit from './omit';
import readFile from './readFile';
import serializer from './serializer';
import set from './set';
import stableStringify from './stableStringify';
@ -28,17 +25,12 @@ import swap from './swap';
import type from './type';
import unset from './unset';
import urlQuery from './urlQuery';
import writeFile from './writeFile';
export {
applyArrayIndices,
cleanDirectory,
get,
getFileExtension,
getFileSubExtension,
mergeObjects,
omit,
readFile,
serializer,
set,
stableStringify,
@ -46,5 +38,4 @@ export {
type,
unset,
urlQuery,
writeFile,
};

View File

@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "12",
"esmodules": true
}
}
]
]
}

View File

@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: ['src/**/*.js'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/test/'],
coverageReporters: ['lcov', 'text', 'clover'],
errorOnDeprecated: true,
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/'],
};

View File

@ -0,0 +1,44 @@
{
"name": "@lowdefy/node-utils",
"version": "1.0.0",
"licence": "Apache-2.0",
"description": "",
"homepage": "https://lowdefy.com",
"bugs": {
"url": "https://github.com/lowdefy/lowdefy/issues"
},
"contributors": [
{
"name": "Sam Tolmay",
"url": "https://github.com/SamTolmay"
},
{
"name": "Gerrie van Wyk",
"url": "https://github.com/Gervwyk"
}
],
"repository": {
"type": "git",
"url": "https://github.com/lowdefy/lowdefy.git"
},
"main": "dist/index.js",
"scripts": {
"build": "babel src --out-dir dist",
"test": "jest --coverage",
"prepare": "yarn build",
"prepublishOnly": "yarn build",
"npm-publish": "npm publish --access public"
},
"dependencies": {
"@lowdefy/helpers": "1.1.0",
"rimraf": "3.0.2"
},
"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.3",
"@babel/preset-env": "7.12.1",
"babel-jest": "26.5.2",
"jest": "26.5.3",
"jest-diff": "26.5.2"
}
}

View File

@ -0,0 +1,22 @@
/*
Copyright 2020 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 cleanDirectory from './cleanDirectory';
import getFileExtension, { getFileSubExtension } from './getFileExtension';
import readFile from './readFile';
import writeFile from './writeFile';
export { cleanDirectory, getFileExtension, getFileSubExtension, readFile, writeFile };

View File

@ -17,7 +17,7 @@
import fs from 'fs';
import path from 'path';
import { promisify } from 'util';
import type from './type';
import { type } from '@lowdefy/helpers';
const readFilePromise = promisify(fs.readFile);

View File

@ -37,7 +37,7 @@ test('readFile error id filepath is not a string', async () => {
});
test('readFile errors if path is not already resolved', async () => {
await expect(readFile('./omit.test.js')).rejects.toThrow(
'Could not read file, file path was not resolved, received "./omit.test.js".'
await expect(readFile('./readFile/readFile.txt')).rejects.toThrow(
'Could not read file, file path was not resolved, received "./readFile/readFile.txt".'
);
});

View File

@ -2841,6 +2841,7 @@ __metadata:
"@babel/core": 7.12.3
"@babel/preset-env": 7.12.1
"@lowdefy/helpers": 1.1.0
"@lowdefy/node-utils": 1.0.0
"@lowdefy/nunjucks": 1.0.0
ajv: 6.12.6
axios: 0.20.0
@ -2932,6 +2933,7 @@ __metadata:
"@babel/core": 7.12.3
"@babel/preset-env": 7.12.1
"@lowdefy/helpers": 1.1.0
"@lowdefy/node-utils": 1.0.0
apollo-server: 2.18.2
apollo-server-testing: 2.18.2
babel-jest: 26.5.2
@ -2957,7 +2959,6 @@ __metadata:
jest-diff: 26.5.2
lodash.merge: 4.6.2
query-string: 6.13.6
rimraf: 3.0.2
languageName: unknown
linkType: soft
@ -3017,6 +3018,21 @@ __metadata:
languageName: unknown
linkType: soft
"@lowdefy/node-utils@1.0.0, @lowdefy/node-utils@workspace:packages/nodeUtils":
version: 0.0.0-use.local
resolution: "@lowdefy/node-utils@workspace:packages/nodeUtils"
dependencies:
"@babel/cli": 7.12.1
"@babel/core": 7.12.3
"@babel/preset-env": 7.12.1
"@lowdefy/helpers": 1.1.0
babel-jest: 26.5.2
jest: 26.5.3
jest-diff: 26.5.2
rimraf: 3.0.2
languageName: unknown
linkType: soft
"@lowdefy/nunjucks@1.0.0, @lowdefy/nunjucks@workspace:packages/nunjucks":
version: 0.0.0-use.local
resolution: "@lowdefy/nunjucks@workspace:packages/nunjucks"